-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path20181118.ts
More file actions
80 lines (69 loc) · 1.64 KB
/
20181118.ts
File metadata and controls
80 lines (69 loc) · 1.64 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import Doodle from "./Doodle";
import { Point } from "./Point";
import { Colors } from "./Colors";
const screenSize = 128;
const gridCount = 16;
const gridSize = screenSize / gridCount;
const frameCount = 1;
export class DailyDoodle implements Doodle {
private cells: Point[];
private index: number;
private frame: number;
private colors: string[];
public init() {
this.cells = [];
this.colors = [
Colors.black,
Colors.darkBlue,
Colors.darkGrey,
Colors.darkPurple,
Colors.brown,
Colors.indigo,
Colors.darkGreen,
Colors.red,
Colors.orange,
Colors.pink,
Colors.yellow,
Colors.green,
Colors.blue,
Colors.peach,
Colors.lightGrey,
Colors.white
];
this.index = 0;
this.frame = 0;
for (let i = 0; i < gridCount * gridCount; i++) {
let r = i % gridCount;
const c = Math.floor(i / gridCount);
if (c % 2 === 1) {
r = gridCount - r;
}
const p = new Point(c, r);
this.cells.push(p);
}
}
public update() {
this.frame++;
if (this.frame >= frameCount) {
this.index++;
if (this.index >= gridCount * gridCount) {
this.index = 0;
}
this.frame = 0;
}
}
public draw(ctx: CanvasRenderingContext2D) {
ctx.clearRect(0, 0, screenSize, screenSize);
for (let i = 0; i < this.index; i++) {
ctx.fillStyle = this.colors[i % this.colors.length];
ctx.strokeStyle = "black";
ctx.lineWidth = 2;
ctx.fillRect(
this.cells[i].x * gridSize,
this.cells[i].y * gridSize,
gridSize,
gridSize
);
}
}
}