-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path20181112.ts
More file actions
39 lines (33 loc) · 864 Bytes
/
20181112.ts
File metadata and controls
39 lines (33 loc) · 864 Bytes
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
import Doodle from "./Doodle";
const screenSize = 128;
export class DailyDoodle implements Doodle {
private angle: number;
private radius: number;
private radiusDir: number;
public init() {
this.angle = 0;
this.radius = 0;
this.radiusDir = 1;
}
public update() {
this.angle -= 0.11;
if (this.angle > 360) {
this.angle = 0;
}
this.radius += 0.5 * this.radiusDir;
if (this.radius > 10 || this.radius < 0) {
this.radiusDir *= -1;
}
}
public draw(ctx: CanvasRenderingContext2D) {
ctx.clearRect(0, 0, screenSize, screenSize);
ctx.fillStyle = "white";
for (let i = 0; i < screenSize; i++) {
const y = 64 + this.radius * Math.sin(i / 10 + this.angle);
ctx.fillRect(i, y, 1, 1);
for (let j = y; j < screenSize; j++) {
ctx.fillRect(i, j, 2, 2);
}
}
}
}