Computer Science · Simulator 056
Each bird (“boid”) follows three simple rules about its nearby neighbours only. There is no leader and no plan, yet the group swirls and flows like a real flock. Turn each rule up or down, release a predator, and see which behaviour each rule controls.
CollegeBeyond the syllabus: complex systems
Craig Reynolds' boids (1987) steer by three local rules, each a small force computed from neighbours within a vision radius:
Speeds are kept between a minimum and maximum, and the world wraps around. The order parameter (length of the average heading vector, from 0 = random to 1 = all aligned) measures how coordinated the flock is.
A predator adds a strong flee force for boids within its range, producing the splitting and re-forming seen in starling murmurations and fish schools. Lookups use a spatial grid so hundreds of boids stay fast.
An agent-based illustration, not a calibrated model of any species. Starting positions use a fixed seed.
Which single rule would you remove to make boids crash into each other, and which to make them never gather into groups?
Without separation, cohesion and alignment pull boids on top of each other, so they collide. Without cohesion (and with little alignment), nothing draws them together, so they stay spread out. Try each with the sliders.
Measuring order: the order parameter is the length of the average heading. Four boids heading east, east, north and south: the unit vectors add to (2, 0), length 2, divided by 4 gives 0.5.
All aligned: 1. Random headings: about 1/√N, so roughly 0.08 for 150 boids.
Cohesion: a boid whose neighbours are at (10, 20), (30, 0) and (20, 40) steers towards their centre, (20, 20).
How many neighbours? A vision radius of 50 px covers π × 50² ≈ 7 850 px² of the flat 800 × 500 view. With 150 boids spread evenly that is 150 × 7 850 / 400 000 ≈ 3 neighbours each, enough for local rules to link into a flock. With 400 boids it is about 8.
Start with 150 boids and alignment 1, then set alignment to 0 and watch the order drop towards 0.08.
Separation: steer away from neighbours that are too close. Alignment: match the average heading of neighbours. Cohesion: steer towards their average position.
No boid knows about the flock or follows a leader. Each one reacts only to a few nearby boids, yet the whole group moves as one.
In films and games to animate crowds, birds and fish, in robot swarms and drone shows, and in research on how real animals coordinate.