-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path20181204.ts
More file actions
66 lines (56 loc) · 1.48 KB
/
20181204.ts
File metadata and controls
66 lines (56 loc) · 1.48 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
import Doodle from "./Doodle";
import { Colors } from "./Colors";
import { Point } from "./Point";
import { KochLine } from "./KochLine";
const screenSize = 128;
const frameCount = 30;
const genMax = 6;
export class DailyDoodle implements Doodle {
private lines: KochLine[] = [];
private frame: number = 0;
private gen: number = 0;
public init() {
this.lines.push(new KochLine(new Point(0, 64), new Point(screenSize, 64)));
}
public update() {
this.frame++;
if (this.frame >= frameCount) {
this.generate();
this.gen++;
if (this.gen >= genMax) {
this.gen = 0;
this.lines = [];
this.lines.push(
new KochLine(new Point(0, 64), new Point(screenSize, 64))
);
}
this.frame = 0;
}
}
public draw(ctx: CanvasRenderingContext2D) {
ctx.clearRect(0, 0, screenSize, screenSize);
for (const l of this.lines) {
ctx.beginPath();
ctx.strokeStyle = Colors.blue;
ctx.lineWidth = 2;
ctx.moveTo(l.start.x, l.start.y);
ctx.lineTo(l.end.x, l.end.y);
ctx.stroke();
}
}
private generate() {
const next: KochLine[] = [];
for (const l of this.lines) {
const a = l.kochA();
const b = l.kochB();
const c = l.kochC();
const d = l.kochD();
const e = l.kochE();
next.push(new KochLine(a, b));
next.push(new KochLine(b, c));
next.push(new KochLine(c, d));
next.push(new KochLine(d, e));
}
this.lines = next;
}
}