-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path20181211.ts
More file actions
47 lines (41 loc) · 1.44 KB
/
20181211.ts
File metadata and controls
47 lines (41 loc) · 1.44 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 { Colors } from "./Colors";
import { Point } from "./Point";
export class DailyDoodle implements Doodle {
public init() {
// nop
}
public update() {
// nop
}
public draw(ctx: CanvasRenderingContext2D) {
ctx.clearRect(0, 0, 128, 128);
ctx.beginPath();
ctx.strokeStyle = Colors.white;
for (let j = 0; j < 8; j++) {
const points = this.randomPolygon(new Point(64, 64), 10 * j);
ctx.moveTo(points[0].x, points[0].y);
for (let i = 1; i < points.length; i++) {
ctx.lineTo(points[i].x, points[i].y);
}
ctx.lineTo(points[0].x, points[0].y);
ctx.stroke();
}
}
private randomPolygon(cp: Point, r: number): Point[] {
const points: Point[] = [];
const wiggle = () => {
const dir = Math.random() * 10 > 5 ? -1 : 1;
return Math.floor(Math.random() * (r / 6) * dir);
};
points.push(new Point(cp.x - r + wiggle(), cp.y - r + wiggle()));
points.push(new Point(cp.x + wiggle(), cp.y - r + wiggle()));
points.push(new Point(cp.x + r + wiggle(), cp.y - r + wiggle()));
points.push(new Point(cp.x + r + wiggle(), cp.y + wiggle()));
points.push(new Point(cp.x + r + wiggle(), cp.y + r + wiggle()));
points.push(new Point(cp.x + wiggle(), cp.y + r + wiggle()));
points.push(new Point(cp.x - r + wiggle(), cp.y + r + wiggle()));
points.push(new Point(cp.x - r + wiggle(), cp.y + wiggle()));
return points;
}
}