Demonstration of flocking behavior. Full discussion of the implementation can be found in the Nature of Code book by Daniel Shiffman. The simulation is based on the research of Craig Reynolds, who used the term ‘boid’ to represent a bird-like object.
Flocking by p5.js Contributors and the Processing Foundation is licensed under CC BY-NC-SA 4.0.
Related Examples

Snowflakes falling on a black background.
Snowflakes
Animate snowfall.

Twenty white circles on a black background.
Shake Ball Bounce
Animate ball movement based on mobile device motion.

A pattern of multicolored circles connected by white lines, on a black background.
Connected Particles
Draw circles and connecting lines using the mouse.

A group of bird-like objects, represented by rainbow triangles, modeling flocking behavior.
Flocking
Simulate bird flocking behavior.