-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path20181205.ts
More file actions
70 lines (61 loc) · 1.51 KB
/
20181205.ts
File metadata and controls
70 lines (61 loc) · 1.51 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
import Doodle from "./Doodle";
import { Point } from "./Point";
import { Triangle } from "./Triangle";
import { Colors } from "./Colors";
const screenSize = 128;
const frameCount = 30;
const genMax = 6;
export class DailyDoodle implements Doodle {
private triangles: Triangle[] = [];
private frame = 0;
private gen = 0;
public init() {
this.triangles.push(
new Triangle(
new Point(screenSize / 2, 0),
new Point(screenSize, screenSize),
new Point(0, screenSize)
)
);
}
public update() {
this.frame++;
if (this.frame >= frameCount) {
this.frame = 0;
this.gen++;
this.generate();
if (this.gen >= genMax) {
this.gen = 0;
this.triangles = [];
this.triangles.push(
new Triangle(
new Point(screenSize / 2, 0),
new Point(screenSize, screenSize),
new Point(0, screenSize)
)
);
}
}
}
public draw(ctx: CanvasRenderingContext2D) {
ctx.clearRect(0, 0, screenSize, screenSize);
ctx.fillStyle = Colors.red;
for (const t of this.triangles) {
ctx.beginPath();
ctx.moveTo(t.a.x, t.a.y);
ctx.lineTo(t.b.x, t.b.y);
ctx.lineTo(t.c.x, t.c.y);
ctx.lineTo(t.a.x, t.a.y);
ctx.fill();
}
}
private generate() {
const next: Triangle[] = [];
for (const t of this.triangles) {
next.push(t.topInside());
next.push(t.leftInside());
next.push(t.rightInside());
}
this.triangles = next;
}
}