From 6e239988877b3452b9e8025f730796303b0594e2 Mon Sep 17 00:00:00 2001 From: Ludwig Lehnert Date: Mon, 14 Apr 2025 21:40:53 +0200 Subject: [PATCH] made idle animation path finding --- src/routes/+page.svelte | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 652ddc8..3675e3a 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -50,32 +50,36 @@ return others; }); + let lidx: number = 0; const lineInterval = setInterval(() => { if (Math.random() < 0.7) return; + if (Math.random() < 0.05) lidx = chooseRandom(indices); - while (true) { - const lidx = chooseRandom(indices); - const ridx = chooseRandom(indices); - if (lidx === ridx) continue; + let iter = 0; + while (iter++ < 100) { + const nidx = chooseRandom(indices); + if (lidx === nidx) continue; const [lx, ly] = points[lidx]; - const [rx, ry] = points[ridx]; + const [rx, ry] = points[nidx]; const d = Math.sqrt( Math.pow(lx - rx, 2) + Math.pow(ly - ry, 2), ); - if (d > 0.4) continue; + if (d > 0.4 && Math.random() < 0.8) continue; - const line = document.getElementById(`${lidx}-${ridx}`); + const line = document.getElementById(`${lidx}-${nidx}`); if (!line) continue; line.setAttribute("opacity", "1"); setTimeout( () => line.setAttribute("opacity", "0"), - Math.random() * 4500, + Math.random() * 6000, ); + + lidx = nidx; break; } - }, 100); + }, 150); document.getElementById("stars")?.append(...stars);