X-Git-Url: https://git.r.bdr.sh/rbdr/r.bdr.sh/blobdiff_plain/672c9cfeface5336603ed84b3a913870ab53b2c8..dc7dafd01da50b7a40b19dedc47aed18190fd97a:/js/animation.js diff --git a/js/animation.js b/js/animation.js index 71d5aa3..c131758 100644 --- a/js/animation.js +++ b/js/animation.js @@ -1,5 +1,7 @@ (function () { + if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) return + var K = document.querySelector('canvas'), { random: R, PI, cos: C, sin: S, atan2: A } = Math, id = p => p, @@ -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 ~~(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() } @@ -84,7 +87,7 @@ } function frm(t) { - requestAnimationFrame(frm) + if (Z) requestAnimationFrame(frm) var dt = t - l @@ -101,6 +104,7 @@ } } + K.addEventListener('click', () => (Z ? Z=0:(Z=1&&frm()))) frm() } )()