X-Git-Url: https://git.r.bdr.sh/rbdr/r.bdr.sh/blobdiff_plain/5054447d8d71e75c1684ed40314e517a28eb5be4..698a2748ccd5ac3d6be0155b3fbd10c6946c7502:/js/animation.js?ds=inline diff --git a/js/animation.js b/js/animation.js index 6a67699..ee43c54 100644 --- a/js/animation.js +++ b/js/animation.js @@ -1,7 +1,9 @@ (function () { + if (window.matchMedia(`(prefers-reduced-motion: reduce)`).matches === true) return; + var K = document.querySelector('canvas'), - { random: R, PI, cos: C, sin: S, floor, atan2: A } = Math, + { random: R, PI, cos: C, sin: S, atan2: A } = Math, id = p => p, spn = rad => p => ({ x: p.x + rad * C(l), @@ -15,21 +17,22 @@ a: R() * 2 * PI, c: r(100) })), H = [sqr, crc, hrt, chs, lch], P = [id, spn(5), spn(15)], - draw = H[r(H.length)], pos = P[r(P.length)] + draw = H[r(H.length)], pos = P[r(P.length)], + Z = 1 function r(x) { - return floor(R() * x) + return ~~(R() * x) } function sqr(i) { - var {x, y} = pos(i) - X.fillRect(x, y, z, z) + var p = pos(i) + X.fillRect(p.x, p.y, z, z) } function crc(i) { - var {x, y} = pos(i) + var p = pos(i) B() - X.arc(x, y, z / 2, 0, 2 * PI) + X.arc(p.x, p.y, z / 2, 0, 2 * PI) F() } @@ -83,8 +86,10 @@ i.c = (i.c + 2) % 101 } + canvas.addEventListener('click', () => {Z ? Z=0:(Z=1;frm())}) + function frm(t) { - requestAnimationFrame(frm) + if (Z) requestAnimationFrame(frm) var dt = t - l