See 3d-viz branch for 3D simulation.
sudo apt-get install libglew-dev libglfw3-dev libglm-dev
make && ./flocksim
Inspired by a recent article published by National Geographic, What are birds doing when they fly in swarms? Scientists may now know.:
The team has learned that no matter how large the flock, each starling interacts with only seven neighbors, which might be as much as their brains can handle. The exact neighbors change from second to second, but the starlings don’t track these shifting alliances. They merely fly in the same direction as whichever seven birds are nearest, while staying close but not too close. Alignment, attraction, and avoidance: By plugging this trio of rules into a computer model, along with some basic aerodynamics, Charlotte Hemelrijk from the University of Groningen in the Netherlands created a virtual murmuration that resembled the real deal—and matched the data from Rome.
This showed that the starlings need no overarching plan, no leader, and no telepathic hive mind. They barely need to communicate at all. Through the simplest of interactions, playing out over distances of a few feet, the breathtaking, sky-spanning complexity of a murmuration emerges.
The implementation is based on the Boids algorithm to simulate flocking behavior. Boids are simulated with three core behaviors:
- Alignment: Each boid aligns its direction with neighbouring boids.
- Attraction: Each boid moves toward the center of mass of neighbouring boids.
- Avoidance: Each boid avoids collisions with nearby boids.
Each boid is represented as a triangle with colour given by its velocity. The boids appear to move in unison without any centralized control.

