]>
Commit | Line | Data |
---|---|---|
1 | (function () { | |
2 | ||
3 | var K = document.querySelector('canvas'), | |
4 | { random: R, PI, cos: C, sin: S, floor, atan2: A } = Math, | |
5 | id = p => p, | |
6 | spn = rad => p => ({ | |
7 | x: p.x + rad * C(l), | |
8 | y: p.y + rad * S(l) | |
9 | }), | |
10 | X = K.getContext('2d'), | |
11 | f = 24, l = 0, s = 1, z = 5 + r(10), | |
12 | k = R() > 0.5, c = R() > 0.5, | |
13 | I = Array(r(10) + 6).fill().map(() => ({ | |
14 | x: r(64), | |
15 | y: r(64), | |
16 | a: R() * 2 * PI, | |
17 | c: r(100) | |
18 | })), | |
19 | H = [sqr, crc, hrt, chs, lch], P = [id, spn(5), spn(15)], | |
20 | draw = H[r(H.length)], pos = P[r(P.length)] | |
21 | ||
22 | function r(x) { | |
23 | return floor(R() * x) | |
24 | } | |
25 | ||
26 | function sqr(i) { | |
27 | ||
28 | var {x, y} = pos(i) | |
29 | X.fillRect(x, y, z, z) | |
30 | } | |
31 | ||
32 | function crc(i) { | |
33 | ||
34 | var {x, y} = pos(i) | |
35 | X.beginPath() | |
36 | X.arc(x, y, z / 2, 0, 2 * PI) | |
37 | X.fill() | |
38 | } | |
39 | ||
40 | function chs(i) { | |
41 | ||
42 | var {x, y} = pos(i) | |
43 | X.beginPath() | |
44 | X.moveTo(x, y) | |
45 | X.lineTo(x * 10 * C(i.a), y * 10 * S(i.a)) | |
46 | X.lineTo(r(64), r(64)) | |
47 | X.fill() | |
48 | } | |
49 | ||
50 | function lch(i) { | |
51 | ||
52 | var {x, y} = pos(i) | |
53 | X.beginPath() | |
54 | X.lineWidth = 5 | |
55 | X.strokeStyle = `hsl(0,0%,${i.c}%)` | |
56 | X.moveTo(x, y) | |
57 | X.lineTo(x * 10 * C(i.a), y * 10 * S(i.a)) | |
58 | X.stroke() | |
59 | } | |
60 | ||
61 | function hrt(i) { | |
62 | ||
63 | var {x, y} = pos(i) | |
64 | X.fillRect(x, y, z, z) | |
65 | ||
66 | X.beginPath() | |
67 | X.arc(x + z / 2, y, z / 2, 0, 2 * PI, false) | |
68 | X.fill() | |
69 | X.closePath() | |
70 | ||
71 | X.beginPath() | |
72 | X.arc(x + z, y + z / 2, z / 2, 0, 2 * PI, false) | |
73 | X.fill() | |
74 | X.closePath() | |
75 | } | |
76 | ||
77 | function mov(i) { | |
78 | ||
79 | i.x = i.x + s * C(i.a) | |
80 | i.y = i.y + s * S(i.a) | |
81 | ||
82 | if (i.x < 0 || i.x > 64) { | |
83 | i.a = A(S(i.a), -C(i.a)) | |
84 | } | |
85 | if (i.y < 0 || i.y > 64) { | |
86 | i.a = A(-S(i.a), C(i.a)) | |
87 | } | |
88 | } | |
89 | ||
90 | function ucl(i) { | |
91 | i.c = (i.c + 2) % 101 | |
92 | } | |
93 | ||
94 | function frm(t) { | |
95 | ||
96 | requestAnimationFrame(frm) | |
97 | ||
98 | var dt = t - l | |
99 | ||
100 | if (dt > 1000 / f) { | |
101 | k && X.clearRect(0, 0, 64, 64) | |
102 | for (var i of I) { | |
103 | X.fillStyle = `hsl(0,0%,${i.c}%)` | |
104 | draw(i) | |
105 | c && ucl(i) | |
106 | mov(i) | |
107 | } | |
108 | ||
109 | l = t | |
110 | } | |
111 | } | |
112 | ||
113 | frm() | |
114 | } | |
115 | )() |