Walkers in a continuous space
One hundred and forty points wander over a space whose edges join up, and the space tells each one who is near it.
fewer than three walkers within reachthree or more within reach
Each walker is a MovingAgent. Every step it gets a small push in a random direction, the agent applies its own friction and top speed, and the ContinuousSpace moves it, wrapping it round when it crosses an edge because the boundary is periodic.
Then the space answers one question for each walker: which other walkers are within 32 units? A walker with three or more within that distance is drawn larger and in colour, with a line to each of them. Nothing steers the walkers towards one another, so groups appear and break up by chance.
The space keeps a spatial index (a quadtree), which is why the neighbour question stays quick as the number of walkers grows. A RandomScheduler runs the walkers in a new order every step.
Classes used
MovingAgent, ContinuousSpace (moveAgent, findNeighbors), RandomScheduler.
Source
This is example.js, the file this page runs.
Loading the source…