Back in 1987 Craig Reynolds wrote his seminal paper Flocks, Herds, and Schools: A Distributed Behavioral Model. From applying a series of simple rules to a group of virtual birds (or Boids as Reynolds named them) the emergent behaviour of flocking arises.
The rules that update the birds (Boids) positions the virtual 3D world are as follows. (These images and descriptions come from Craig’s boids page).
Separation: steer to avoid crowding local flockmates
Alignment: steer towards the average heading of local flockmates
Cohesion: steer to move toward the average position of local flockmates
The “local flockmates” are a smaller group within the flock surrounding the current boid. Each boid only sees a small subset of the entire flock, yet when the rules are applied the entire flock acts as a whole. This is essentially what emergent behaviour means.
I have attempted boids simulations in the past, but the results never seemed to work out exactly as I wanted. Over the last few days I rewrote the boids code in Visions Of Chaos from scratch and am now getting some more realistic flocking behaviour emerging from only using the above rules.
Here is a quick sample with 2,500 boids. The “world” they live in is a cube with wrap-around edges, so you will see flocks exit one side and reappear at the other side. Must be watched full HD to see all the details.
Here is a more recent test run with 5,000 boids. Also a must see in HD.
And a final example with the boids confined to a rectangular room. The boids also leave fading trails behind them.