The Computational Beauty of Nature
Source code

boids

simulate a flock of android birds from Brooklyn

Full screen →

boids -help
  or
boids  [-width  integer]  [-height integer] [-num integer]
       [-steps integer] [-seed  integer]  [-angle  double]
       [-vangle  double]  [-rcopy  double] [-rcent double]
       [-rvoid double]  [-rviso  double]  [-wcopy  double]
       [-wcent  double]  [-wvoid  double]  [-wviso double]
       [-wrand double] [-dt double] [-ddt  double]  [-minv
       double] [-len integer] [-psdump] [-inv] [-mag inte-
       ger] [-term string]

Simulates a flock of boids according to rules that determine their individual behaviors as well as the “physics” of their universe. A boid greedily attempts to apply four rules with respect to its neighbors: It wants to fly in the same direction, be in the center of the local cluster of boids, avoid collisions with boids too close, and maintain a clear view ahead by skirting around others that block its view. Changing these rules can make the boids behave like birds, gnats, bees, fish, or magnetic particles.

Simulate a flock of boids according to rules that determine their individual behaviors as well as the ``physics'' of their universe. A boid greedily attempts to apply four rules with respect to its neighbors: it wants to fly in the same direction, be in the center of the local cluster of boids, avoid collisions with boids too close, and maintain a clear view ahead by skirting around others that block its view. Changing these rules can make the boids behave like birds, gnats, bees, fish, or magnetic particles. See the RULES section of the manual pages for more details.

Rules

All of the rules have a weight option and a radius option. The radius option specifies how close a boid need to be to another in order for the rule to be acted upon. The weight is used when combining all of the rules actions into a single new velocity vector.

The four rules can be simply described as follows:

Centering: move towards the center of any boids in my viewing area.

Copying: attempt to move in the average direction of that all boids that can be seen are moving in.

Avoidance: ``Please don't stand so close to me.'' Move away from any close flyers.

Visual: move in such a way that the bonehead obstructing your view no longer interferes.

The four rules are then normalized and added together to make the next velocity vector of the boid. All radii in the rules are in terms of pixels.

You may wish to try turning on and off different combinations of the rules to see how the boids' behaviors change. For example, if you turn off the avoidance rule, increase the centering radius and weight, and increase the viewing angle to nearly 360 degrees, then the boids will behave like a pack of wolves fighting over the center. Other changes can yield similar surprises.

Bugs

No sanity checks are performed to make sure that any of the options make sense.

Options

-widthWidth of the plot in pixels.640
-heightHeight of the plot in pixels.480
-numNumber of boids.20
-stepsNumber of simulated steps.100000000
-seedRandom seed for initial state.0
-angleNumber of viewing degrees.270.0
-vangleVisual avoidance angle.90.0
-rcopyRadius for copy vector.80.0
-rcentRadius for centroid vector.30.0
-rvoidRadius for avoidance vector.15.0
-rvisoRadius for visual avoidance vector.40.0
-wcopyWeight for copy vector.0.2
-wcentWeight for centroid vector.0.4
-wvoidWeight for avoidance vector.1.0
-wvisoWeight for visual avoidance vector.0.8
-wrandWeight for random vector.0.0
-dtTime-step increment.3.0
-ddtMomentum factor (0 < ddt < 1).0.95
-minvMinimum velocity.0.5
-lenTail length.20
-psdumpDump PS at the very end?False
-invInvert all colors?False
-magMagnification factor.1
-termHow to plot points.None

boids.c on GitHub