-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path20181203.ts
More file actions
42 lines (35 loc) · 939 Bytes
/
20181203.ts
File metadata and controls
42 lines (35 loc) · 939 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
40
41
42
import Doodle from "./Doodle";
import { Point } from "./Point";
import { PointOscillator } from "./PointOscillator";
import { Colors } from "./Colors";
const screenSize = 128;
const pointCount = 1000;
export class DailyDoodle implements Doodle {
private pos: PointOscillator[] = [];
public init() {
for (let i = 0; i < pointCount; i++) {
this.pos.push(
new PointOscillator(
new Point(randPixel(), randPixel()),
new Point(randPixel(), randPixel())
)
);
}
}
public update() {
for (const po of this.pos) {
po.update();
}
}
public draw(ctx: CanvasRenderingContext2D) {
ctx.fillStyle = Colors.white;
ctx.fillRect(0, 0, screenSize, screenSize);
ctx.fillStyle = Colors.black;
for (const po of this.pos) {
ctx.fillRect(po.p.x, po.p.y, 1, 1);
}
}
}
function randPixel(): number {
return Math.floor(Math.random() * screenSize);
}