diff --git a/index.mjs b/index.mjs index 882b24e..80e2ddc 100644 --- a/index.mjs +++ b/index.mjs @@ -37,13 +37,23 @@ window.onresize = updateSize; const activeBoids = []; -for (let i = 0; i < 300; ++i) +const addBoids = (pos, count) => { - activeBoids.push({ - pos: new Vector(200 + (i % 2) * (-400), 0), - vel: new Vector(Math.random() * 100, Math.random() * 100), - }); -} + for (let i = 0; i < count; ++i) + { + activeBoids.push({ + pos: pos.clone(), + vel: new Vector(Math.random(), Math.random()), + }); + } +}; + +boidsCanvas.onclick = ev => +{ + const pos = new Vector(ev.offsetX, ev.offsetY); + pos.sub(center); + addBoids(pos, 50); +}; let paused = false; let lastTime = null;