Adrian . Matías Quezada

Flocking

A bunch of drop-shaped cells in a black background

Boids: the behaviour birds and fish show in a group. They align their direction of movement with their partners, stay close to them, and avoid colliding. Three tiny rules — alignment, cohesion, separation — and a flock falls out of them without anyone being in charge.

Each cell drifts on a canvas, steers by those three rules summed into a single force, bumps off its neighbours as a solid body, and wraps around the edges of the world: leave on the right and you come back on the left.

It was written test-first. The specs in user-stories/ are literally the specification — "as a user I want to watch them follow flocking behaviour" is a file, written before the code that satisfies it — and they run on every push.

This started as the second version of Lulas, rewritten from scratch to make flocking easier to implement. It kept that name for years before being renamed to what it actually is.

It was paused for a while looking for a good Quadtree implementation: the neighbour lookup is O(n²), which is fine at fifty cells and stops being fine well before it gets interesting.