made idle animation path finding

This commit is contained in:
Ludwig Lehnert 2025-04-14 21:40:53 +02:00
parent 75acef5630
commit 6e23998887

View File

@ -50,32 +50,36 @@
return others; return others;
}); });
let lidx: number = 0;
const lineInterval = setInterval(() => { const lineInterval = setInterval(() => {
if (Math.random() < 0.7) return; if (Math.random() < 0.7) return;
if (Math.random() < 0.05) lidx = chooseRandom(indices);
while (true) { let iter = 0;
const lidx = chooseRandom(indices); while (iter++ < 100) {
const ridx = chooseRandom(indices); const nidx = chooseRandom(indices);
if (lidx === ridx) continue; if (lidx === nidx) continue;
const [lx, ly] = points[lidx]; const [lx, ly] = points[lidx];
const [rx, ry] = points[ridx]; const [rx, ry] = points[nidx];
const d = Math.sqrt( const d = Math.sqrt(
Math.pow(lx - rx, 2) + Math.pow(ly - ry, 2), 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; if (!line) continue;
line.setAttribute("opacity", "1"); line.setAttribute("opacity", "1");
setTimeout( setTimeout(
() => line.setAttribute("opacity", "0"), () => line.setAttribute("opacity", "0"),
Math.random() * 4500, Math.random() * 6000,
); );
lidx = nidx;
break; break;
} }
}, 100); }, 150);
document.getElementById("stars")?.append(...stars); document.getElementById("stars")?.append(...stars);