kaka.farm

Unnamed repository; edit this file 'description' to name the repository.
git clone https://kaka.farm/~git/kaka.farm
Log | Files | Refs | README

commit 72d6c2c82c888efa821e5fbf3cd0ad84f0ec3c60
parent 4acc0dcc01c500b8fc3e812951d27c4e0b730add
Author: Yuval Langer <yuval.langer@gmail.com>
Date:   Sat, 19 Mar 2022 22:57:51 +0200

Add reseting click event.

Diffstat:
Mhtml/the-dancing-polygon-screensaver/main.js | 17+++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/html/the-dancing-polygon-screensaver/main.js b/html/the-dancing-polygon-screensaver/main.js @@ -185,12 +185,7 @@ Math.TAU = 2 * Math.PI; canvas.style.height = window.innerHeight; } - function main() { - let canvas = document.getElementById('canvas'); - let ctx = canvas.getContext('2d'); - - resize_window(); - + function reset_world() { polygons_vertices = [[ [canvas.width / 2, canvas.height / 3], [2 * canvas.width / 3, 2 * canvas.height / 3], @@ -202,6 +197,16 @@ Math.TAU = 2 * Math.PI; uniform_random_direction(), uniform_random_direction(), ].map(vertex => vertex.map(axis => pixels_per_step * axis)); + } + + function main() { + let canvas = document.getElementById('canvas'); + let ctx = canvas.getContext('2d'); + + resize_window(); + reset_world(); + + canvas.addEventListener('click', reset_world); window.addEventListener('resize', resize_window)