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 14ea371a6e8b67be77edd41fb577cae8452256b4
parent 7adacf3f0bea89d8d87f1de1ab4e173c9e1a0d7a
Author: Yuval Langer <yuval.langer@gmail.com>
Date:   Sat, 19 Mar 2022 22:48:17 +0200

Adapt canvas to window size.

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

diff --git a/html/the-dancing-polygon-screensaver/main.js b/html/the-dancing-polygon-screensaver/main.js @@ -174,10 +174,23 @@ Math.TAU = 2 * Math.PI; window.requestAnimationFrame(step) } + function resize_window() { + // https://stackoverflow.com/a/32119392 + + let canvas = document.getElementById('canvas'); + + canvas.width = window.innerWidth; + canvas.style.width = window.innerWidth; + canvas.height = window.innerHeight; + canvas.style.height = window.innerHeight; + } + function main() { let canvas = document.getElementById('canvas'); let ctx = canvas.getContext('2d'); + resize_window(); + polygons_vertices = [[ [canvas.width / 2, canvas.height / 3], [2 * canvas.width / 3, 2 * canvas.height / 3], @@ -190,6 +203,8 @@ Math.TAU = 2 * Math.PI; uniform_random_direction(), ].map(vertex => vertex.map(axis => pixels_per_step * axis)); + window.addEventListener('resize', resize_window) + window.requestAnimationFrame(step); }