Add boids by clicking

This commit is contained in:
Mattéo Delabre 2020-05-04 18:46:26 +02:00
parent bc57e7c2ca
commit e01f977903
Signed by: matteo
GPG Key ID: AE3FBD02DC583ABB
1 changed files with 16 additions and 6 deletions

View File

@ -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;