-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
148 lines (119 loc) · 3.94 KB
/
index.js
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
function sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
function drawPolygon(ctx, polygonScreenEdges) {
for (let [[startX, startY], [endX, endY]] of polygonScreenEdges) {
ctx.beginPath();
ctx.moveTo(startX, startY);
ctx.lineTo(endX, endY);
ctx.stroke();
}
}
function example1(canvas, ctx) {
const _3Gon = new ConvexRegularNGon(3, 45, 50, 300);
const _4Gon = new ConvexRegularNGon(4, 45, 150, 300);
const _5Gon = new ConvexRegularNGon(5, 45, 250, 300);
const _6Gon = new ConvexRegularNGon(6, 45, 350, 300);
const _7Gon = new ConvexRegularNGon(7, 45, 450, 300);
const _8Gon = new ConvexRegularNGon(8, 45, 550, 300);
(async function () {
let angle = -(2 * Math.PI) / 360;
while (true) {
for (let i = 0; i < 360; i++) {
ctx.fillStyle = "#E2E2E2";
ctx.fillRect(0, 0, canvas.width, canvas.height);
drawPolygon(ctx, _3Gon.rotate(angle));
drawPolygon(ctx, _4Gon.rotate(angle));
drawPolygon(ctx, _5Gon.rotate(angle));
drawPolygon(ctx, _6Gon.rotate(angle));
drawPolygon(ctx, _7Gon.rotate(angle));
drawPolygon(ctx, _8Gon.rotate(angle));
await sleep(10);
}
}
})();
}
function example2(canvas, ctx) {
const _3Gon = new ConvexRegularNGon(3, 45, 50, 400);
const _4Gon = new ConvexRegularNGon(4, 45, 150, 400);
const _5Gon = new ConvexRegularNGon(5, 45, 250, 400);
const _6Gon = new ConvexRegularNGon(6, 45, 350, 400);
const _7Gon = new ConvexRegularNGon(7, 45, 450, 400);
const _8Gon = new ConvexRegularNGon(8, 45, 550, 400);
(async function () {
let angle = -(2 * Math.PI) / 360;
while (true) {
for (let i = 0; i < 360; i++) {
ctx.fillStyle = "#E2E2E2";
ctx.fillRect(0, 0, canvas.width, canvas.height);
let t = 0.5;
_3Gon.translate(0, t);
drawPolygon(ctx, _3Gon.rotate(angle));
t *= 0.6;
_4Gon.translate(0, t);
drawPolygon(ctx, _4Gon.rotate(angle));
t *= 0.7;
_5Gon.translate(0, t);
drawPolygon(ctx, _5Gon.rotate(angle));
t *= 0.7;
_6Gon.translate(0, t);
drawPolygon(ctx, _6Gon.rotate(angle));
t *= 0.7;
_7Gon.translate(0, t);
drawPolygon(ctx, _7Gon.rotate(angle));
t *= 0.7;
_8Gon.translate(0, t);
drawPolygon(ctx, _8Gon.rotate(angle));
await sleep(10);
}
}
})();
}
function example3(canvas, ctx) {
const _3Gon = new ConvexRegularNGon(3, 45, 50, 400);
const _4Gon = new ConvexRegularNGon(4, 45, 150, 400);
const _5Gon = new ConvexRegularNGon(5, 45, 250, 400);
const _6Gon = new ConvexRegularNGon(6, 45, 350, 400);
const _7Gon = new ConvexRegularNGon(7, 45, 450, 400);
const _8Gon = new ConvexRegularNGon(8, 45, 550, 400);
(async function () {
let angle = -(2 * Math.PI) / 360;
while (true) {
for (let i = 0; i < 360; i++) {
ctx.fillStyle = "#E2E2E2";
ctx.fillRect(0, 0, canvas.width, canvas.height);
let t = 0.5;
let scale = 0.998;
_3Gon.translate(0, t);
_3Gon.scale(scale);
drawPolygon(ctx, _3Gon.rotate(angle));
t *= 0.6;
_4Gon.translate(0, t);
_4Gon.scale(scale);
drawPolygon(ctx, _4Gon.rotate(angle));
t *= 0.7;
_5Gon.translate(0, t);
_5Gon.scale(scale);
drawPolygon(ctx, _5Gon.rotate(angle));
t *= 0.7;
_6Gon.translate(0, t);
_6Gon.scale(scale);
drawPolygon(ctx, _6Gon.rotate(angle));
t *= 0.7;
_7Gon.translate(0, t);
_7Gon.scale(scale);
drawPolygon(ctx, _7Gon.rotate(angle));
t *= 0.7;
_8Gon.translate(0, t);
_8Gon.scale(scale);
drawPolygon(ctx, _8Gon.rotate(angle));
await sleep(10);
}
}
})();
}
document.addEventListener("DOMContentLoaded", function () {
const canvas = document.getElementById("main-canvas");
const ctx = canvas.getContext("2d");
example1(canvas, ctx);
});