-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path20181119.ts
More file actions
47 lines (42 loc) · 1.05 KB
/
20181119.ts
File metadata and controls
47 lines (42 loc) · 1.05 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
import Doodle from "./Doodle";
import { RandomColor } from "./Colors";
import { drawHex } from "./Hex";
const screenSize = 128;
const countMax = 10;
const frameMax = 3;
export class DailyDoodle implements Doodle {
private count = 0;
private countDir = 1;
private frame = 0;
private colors: string[];
public init() {
this.colorReset();
}
public update() {
this.frame++;
if (this.frame >= frameMax) {
this.count += this.countDir;
if (this.count >= countMax || this.count < 0) {
this.countDir *= -1;
if (this.count < 0) {
this.colorReset();
}
}
this.frame = 0;
}
}
public draw(ctx: CanvasRenderingContext2D) {
ctx.clearRect(0, 0, screenSize, screenSize);
const radiusStep = Math.floor(100 / countMax);
for (let i = this.count; i >= 0; i--) {
ctx.fillStyle = this.colors[i];
drawHex(ctx, 64, 64, i * radiusStep);
}
}
private colorReset() {
this.colors = [];
for (let i = 0; i < countMax; i++) {
this.colors.push(RandomColor());
}
}
}