Add boids by clicking
This commit is contained in:
parent
bc57e7c2ca
commit
e01f977903
22
index.mjs
22
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;
|
||||
|
|
Loading…
Reference in New Issue