This model is an attempt to mimic the non-migratory flocking of birds as based on the 
"Boids" simulation by Craig Reynolds.

Each turtle (bird) calculates its heading by taking the weighted average of three

The first factor is COHESION, which is the heading directly towards the average
position of flockmates within their range of vision, set by the VISION slider. 
The bird will not move along this heading however; this heading is only one
factor in the average which will determine the final heading.

The second factor is SEPARATION, which keeps birds from getting too close to one
another.  If a bird is less than a certain distance from any of its neighbors,
set by the APART slider, it sets the value of this heading directly away from the
average position of the birds that are too close.

The third factor is ALIGNMENT.  This is the value of the average heading of
flockmates within their range of vision.  As the distance between a bird and its
neighbors decreases, the amount of weight that this heading gets in determining
the final heading increases by (APART)/(average distance of local flockmates). 
So, as birds get closer to each other, they align their headings more and more.

Every bird moves forward the same amount during each cycle of RUN.

First, determine the number of birds you want in the
simulation and set the NUMBER slider to that value.  Then click SETUP.  Click RUN
to run the simulation and SCATTER to reset the birds to random positions and

The default settings for the sliders will produce good flocking behavior. 
However, you should play with them to get variations.

APART controls how far apart birds want to stay from each other.  The default is

VISION is the distance that each bird can see 360 degrees around it.  The default
is 10.

TURNS is the maximum amount that a bird can turn per cycle of RUN.  The default
is 50 degrees.

The three sliders at the bottom, COHERE, SEPARATE, and ALIGN, control how much
relative weight each factor has in determining the final heading.  Defaults for
these are 3, 3, and 0.1 respectively.

Notice that the birds do not flock well when the value of TURNS is low.

Also, notice that each flock is dynamic.  A flock, once together, is not
guaranteed to keep all of its members.  Why do you think this is?

After running the model for a while, all of the birds have approximately the same
heading.  Why?

Central to the model is the observation that flocks form without a leader.

Would a different way of giving weight to the alignment heading produce V-shaped
or inverse-square-shaped flocks?  For example, substitute "apart / (mean1 *
mean1) for "apart / mean1" in run.

Notice how small the value of the ALIGN slider must be for successful flocking. 
Why do you think this is?

Play with the sliders at the bottom to see if you can get tighter flocks.

Will running the model for a long time produce a static flock?  Or will the birds
never settle down to an unchanging formation?  Remember, there are no random
functions in this model.

Can you get the birds to fly around obstacles?

What would happen if you gave the birds different velocities?  For example, you
could make birds that are not near other birds fly faster to catch up to the
flock.  Or, you could simulate the diminished air resistance that birds
experience when flying together by making them fly faster when in a group.


The flocks that appear in this model are
not determined in any way by a designated leader.  Rather, each bird is following
exactly the same set of rules from which apparent flocks emerge.

Information on Boids is available at: