]> git.r.bdr.sh - rbdr/r.bdr.sh/blame - js/animation.js
Remove some spaces
[rbdr/r.bdr.sh] / js / animation.js
CommitLineData
21b1c71d
RBR
1(function () {
2
3c30503b 3 var K = document.querySelector('canvas'),
94949070 4 { random: R, PI, cos: C, sin: S, floor, atan2: A } = Math,
06f7a18a
RBR
5 id = p => p,
6 spn = rad => p => ({
7 x: p.x + rad * C(l),
8 y: p.y + rad * S(l)
9 }),
e5d21bf4 10 X = K.getContext('2d'),
a487be1c
RBR
11 f = 24, l = 0, s = 1, z = 5 + r(10),
12 k = R() > 0.5, c = R() > 0.5,
0d1072c6 13 I = Array(r(10) + 6).fill().map(() => ({
a1bf86e5
RBR
14 x: r(64),
15 y: r(64),
16 a: R() * 2 * PI,
e5fa1fb8 17 c: r(100)
83c0fa69 18 })),
a487be1c
RBR
19 H = [sqr, crc, hrt, chs, lch], P = [id, spn(5), spn(15)],
20 draw = H[r(H.length)], pos = P[r(P.length)]
00bc4991 21
55ca9087
RBR
22 function r(x) {
23 return floor(R() * x)
24 }
25
26 function sqr(i) {
27
e5d21bf4
RBR
28 var {x, y} = pos(i)
29 X.fillRect(x, y, z, z)
55ca9087
RBR
30 }
31
32 function crc(i) {
33
e5d21bf4
RBR
34 var {x, y} = pos(i)
35 X.beginPath()
36 X.arc(x, y, z / 2, 0, 2 * PI)
37 X.fill()
55ca9087
RBR
38 }
39
40 function chs(i) {
41
e5d21bf4
RBR
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()
55ca9087
RBR
48 }
49
50 function lch(i) {
51
e5d21bf4
RBR
52 var {x, y} = pos(i)
53 X.beginPath()
54 X.lineWidth = 5
a20337ef 55 X.strokeStyle = `hsl(0,0%,${i.c}%)`
e5d21bf4
RBR
56 X.moveTo(x, y)
57 X.lineTo(x * 10 * C(i.a), y * 10 * S(i.a))
58 X.stroke()
55ca9087
RBR
59 }
60
61 function hrt(i) {
62
e5d21bf4
RBR
63 var {x, y} = pos(i)
64 X.fillRect(x, y, z, z)
55ca9087 65
e5d21bf4
RBR
66 X.beginPath()
67 X.arc(x + z / 2, y, z / 2, 0, 2 * PI, false)
68 X.fill()
69 X.closePath()
55ca9087 70
e5d21bf4
RBR
71 X.beginPath()
72 X.arc(x + z, y + z / 2, z / 2, 0, 2 * PI, false)
73 X.fill()
74 X.closePath()
55ca9087
RBR
75 }
76
77 function mov(i) {
78
e5d21bf4
RBR
79 i.x = i.x + s * C(i.a)
80 i.y = i.y + s * S(i.a)
55ca9087
RBR
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) {
e5fa1fb8 91 i.c = (i.c + 2) % 101
55ca9087
RBR
92 }
93
94 function frm(t) {
95
5099a2f6 96 requestAnimationFrame(frm)
55ca9087
RBR
97
98 var dt = t - l
99
100 if (dt > 1000 / f) {
e5d21bf4 101 k && X.clearRect(0, 0, 64, 64)
55ca9087 102 for (var i of I) {
a20337ef 103 X.fillStyle = `hsl(0,0%,${i.c}%)`
55ca9087 104 draw(i)
e5d21bf4 105 c && ucl(i)
55ca9087
RBR
106 mov(i)
107 }
108
109 l = t
110 }
111 }
21b1c71d 112
98bec09c 113 frm()
21b1c71d 114}
98bec09c 115)()