INTelegance

Boids Flocking Algorithm

written January 2007

The Boids flocking algorithm, originally designed by Craig Reynolds, simulates steering of a leaderless flock of particles, or Boids. The steering is calculated by applying a series of rules to each Boid during each time step of the simulation. Each rule results in a vector (can be two or three dimensional, in my implementation it is just two). The sum of all resulting rule vectors is applied as the velocity. Each step the Boid's current velocity is applied to modify its position.

I designed this applet to be used in my film C. In the film, the boids are controlled in real time as the footage was shot.

In the implementation contained here, it is also possible to change the flocking behavior to a custom behavior I wrote. Under this behavior, each Boid tries to move towards the other Boid who's distance from the given Boid is closest to a preferred radius. Given this behavior, one Boid becomes singled out as the center as all others try to maintain a preferred distance from it.

View the source code

Read a high level Boids pseudocode description

Built with processing

This browser does not have a Java Plug-in.
Get the latest Java Plug-in here.

Controls:

click: create a new particle.
d: cause a particle to duplicate
m: toggle particles follow mouse.
s: toggle particles scatter vs flock
f: toggle particle flocking behavior
p: pause / unpause the simulation
c: clear the simulation