Add boids by clicking
This commit is contained in:
parent
bc57e7c2ca
commit
e01f977903
18
index.mjs
18
index.mjs
|
@ -37,13 +37,23 @@ window.onresize = updateSize;
|
||||||
|
|
||||||
const activeBoids = [];
|
const activeBoids = [];
|
||||||
|
|
||||||
for (let i = 0; i < 300; ++i)
|
const addBoids = (pos, count) =>
|
||||||
{
|
{
|
||||||
|
for (let i = 0; i < count; ++i)
|
||||||
|
{
|
||||||
activeBoids.push({
|
activeBoids.push({
|
||||||
pos: new Vector(200 + (i % 2) * (-400), 0),
|
pos: pos.clone(),
|
||||||
vel: new Vector(Math.random() * 100, Math.random() * 100),
|
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 paused = false;
|
||||||
let lastTime = null;
|
let lastTime = null;
|
||||||
|
|
Loading…
Reference in New Issue