đĻ Boids â Emergent Collective Motion¶
This simulation implements Craig Reynolds' Boids model (1987): each agent follows three simple local rules, and complex flock-like motion emerges without any central control.
đ§ Idea¶
Every boid perceives only its nearby neighbours and applies three steering forces:
| Rule | Effect |
|---|---|
| Separation | Steer away from neighbours that are too close |
| Alignment | Match heading with nearby neighbours |
| Cohesion | Steer toward the average position of nearby neighbours |
No boid knows the shape of the flock. Yet the swarm self-organises into coherent, fluid formations â splitting around obstacles, merging again, and flowing like a living organism.
Comparison with Stigmergy Swarm¶
| Stigmergy (ants) | Boids (flocking) | |
|---|---|---|
| Communication | Indirect (pheromone) | Direct (local sensing) |
| Goal | Path optimisation | Collective motion |
| Memory | External (environment) | None (stateless) |
| Structure | Trails and networks | Dynamic formations |
Both models produce global order from local rules â but via fundamentally different coordination mechanisms.
đŧ Visualisation¶
The matplotlib window shows:
- Coloured dots â each boid, colour-coded by heading (HSV hue = flight angle) so aligned sub-flocks share a colour
- Faint trails â recent trajectory of each boid
- Dark background â simulates a night-sky aesthetic
The world is toroidal (wrap-around edges).
Press ESC to exit.
đ Connection to System Intelligence¶
- Regulation (R): The flock maintains cohesion (a target variable) without any explicit set-point
- Adaptive Capacity (A): When the flock is disrupted, it reforms dynamically â no recovery plan needed
- Emergent structure: Global formations are not prescribed by any individual rule
âļ Run¶
Experiment ideas¶
- Increase
W_SEPARATIONto 4.0 â the flock dissolves into loose gas - Decrease
R_COHESIONto 5.0 â many small sub-flocks instead of one - Set
NUM_BOIDS = 500for dramatic large-flock dynamics (slower) - Try
MAX_SPEED = 4.0for fast, chaotic motion