-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
57 lines (44 loc) · 1.6 KB
/
background.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
window.BackgroundService = (function(Char) {
var backgroundService = function (id) {
}
backgroundService.prototype.init = function (id) {
this.generateChars();
this.c = document.getElementById(id);
this.c.height = window.innerHeight;
this.c.width = window.innerWidth;
this.ctx = this.c.getContext("2d");
setInterval(this.$frame.bind(this),30);
}
backgroundService.prototype.generateChars = function () {
this.chars = [];
for(var i =0; i< 200;i++){
var char = new Char();
this.chars.push(char);
}
}
backgroundService.prototype.$frame = function () {
this.ctx.fillStyle='rgba(255,255,255,1)';
this.ctx.fillRect(0,0,window.innerWidth,window.innerHeight);
for(var i = 0; i < this.chars.length;i++){
this.chars[i].changePosition();
this.ctx.fillStyle = this.chars[i].color;
this.ctx.font = this.chars[i].fontSize + "px Arial";
this.ctx.fillText(this.chars[i].char, this.chars[i].position.x, this.chars[i].position.y);
}
}
backgroundService.prototype.start = function () {
console.log('start');
this.chars[0].run();
// for(var i = 0; i < this.chars.length;i++){
// this.chars[i].run();
// }
}
backgroundService.prototype.stop = function () {
console.log('stop');
this.chars[0].slowDown();
// for(var i = 0; i < this.chars.length;i++){
// this.chars[i].slowDown();
// }
}
return new backgroundService();
})(Char);