I recently discovered Boids, which is a simulation of bird murmurations developed by Craig Reynolds in the 80’s12. The simulation essentially boils down the interaction of the birds (known as ‘Boids’) into three rules12:

  • Separation
    • Birds should avoid colliding with nearby birds
  • Alignment
    • Birds should align themselves with nearby birds
  • Cohesion
    • Birds should move towards the centre of mass of nearby birds

Application of these three rules determines the next position and orientation for a given bird in the murmuration. I highly recommend reading the original publication as well as Craig’s personal website which provide further information and background on the simulation. I’ve added them as sources at the bottom. As an enthusiastic bird nerd, I thought this would be a fun project to have a go at using Rust.

The result was a murmuration sim where the user would be able to configure the separation, alignment and cohesion as they see fit.

lloids

Trails were added for artistic effect.

lloids

Debug information such as interaction radii to facilitate bug diagnosis.

lloids

The menu allows the user to cycle through the options using TAB and adjust the interaction gains using the arrow keys.

lloids

This was a fun project and I soon realised that there were some unexpected challenges such as handling the turning as a given boid approached the edge of the window.

If you want to have a play yourself all the code is available on my GitHub profile here.

References

  1. C. Reynolds - Flocks, herds and schools: A distributed behavioral model link  2

  2. Craig Reynolds - Boids, background and update link  2