-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.js
More file actions
42 lines (40 loc) · 1.12 KB
/
code.js
File metadata and controls
42 lines (40 loc) · 1.12 KB
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
export class Code {
constructor(stageHeight, startX, startY, words, xGap, order) {
this.x = startX;
this.maxY = stageHeight;
this.speed = 15;
this.count = 1;
this.fontSize = xGap;
this.order = order;
this.words = words;
this.len = this.words.length;
this.y = [];
for (let i = 0; i < this.len; i++) {
this.y[i] = startY;
}
}
draw(ctx, n) {
if (this.order <= n) {
if (this.y[this.count - 1] - this.y[this.count] > this.fontSize - 1) {
if (this.count < this.len) {
this.count += 1;
}
}
ctx.fillStyle = '#48DA72';
ctx.font = `italic bold ${this.fontSize}px Arial, sans-serif`;
ctx.shadowColor = 'green';
ctx.shadowBlur = 70;
for (let i = 0; i < this.count; i++) {
if (this.y[i] < this.maxY) {
const word =
this.words[i] === '.'
? this.words[Math.floor(Math.random() * this.len)]
: this.words[i];
this.y[i] += this.speed;
ctx.strokeText(word, this.x, this.y[i]);
ctx.fillText(word, this.x, this.y[i]);
}
}
}
}
}