From: Ruben Beltran del Rio Date: Tue, 13 Feb 2024 22:08:10 +0000 (+0100) Subject: Use 64px for animation X-Git-Url: https://git.r.bdr.sh/rbdr/r.bdr.sh/commitdiff_plain/e99de7cc171b341527a6a71d643e1d81783f83eb?ds=sidebyside Use 64px for animation --- diff --git a/_layout.html b/_layout.html index 1f3f9ee..5c87f0b 100644 --- a/_layout.html +++ b/_layout.html @@ -19,7 +19,7 @@

- + r.bdr.sh

diff --git a/js/animation.js b/js/animation.js index e0a543f..fc6246e 100644 --- a/js/animation.js +++ b/js/animation.js @@ -10,8 +10,8 @@ var clear = !!(Math.random() > 0.5); var changeColor = !!(Math.random() > 0.5); var items = Array(rand(10) + 6).fill(null).map(() => ({ - x: rand(100), - y: rand(100), + x: rand(64), + y: rand(64), angle: Math.random() * 2 * Math.PI, color: Array(3).fill(rand(256)) })); @@ -44,7 +44,7 @@ context.beginPath(); context.moveTo(p.x, p.y); context.lineTo(p.x * 10 * Math.cos(item.angle), p.y * 10 * Math.sin(item.angle)); - context.lineTo(rand(100), rand(100)); + context.lineTo(rand(64), rand(64)); context.fill(); } @@ -101,11 +101,11 @@ item.x = item.x + speed * Math.cos(item.angle); item.y = item.y + speed * Math.sin(item.angle); - if (item.x < 0 || item.x > 100) { + if (item.x < 0 || item.x > 64) { item.angle = Math.atan2(Math.sin(item.angle), -Math.cos(item.angle)) } - if (item.y < 0 || item.y > 100) { + if (item.y < 0 || item.y > 64) { item.angle = Math.atan2(-Math.sin(item.angle), Math.cos(item.angle)) } } @@ -125,7 +125,7 @@ var delta = time - lastFrame; if (delta > 1000 / fps) { - clear && context.clearRect(0, 0, 100, 100); + clear && context.clearRect(0, 0, 64, 64); for (var item of items) { context.fillStyle = `rgb(${item.color.join(',')})`; draw(item);