Flocking

Flocking birds, schooling fish, swarming bees, and conforming humans aren't necessarily following a leader. In this simulation boids (virtual birds) follow three simple rules:

Alignment: Turn as your nearest neighbors turns.

Cohesion: Turn to get closer to your nearest neighbor.

Separation: Turn away if too close.

Actually, there's a fourth rule:

when a predator comes, scatter.

Here's the procedure:

to flock
   find-flockmates
   if any? flockmates
   [ find-nearest-neighbor
      ifelse distance nearest-neighbor < minimum-separation
      [ separate ]
      [ align cohere ]
   ]
end

And a screen shot:

Description: Description: Description: C:\pearce\teaching\lectures\eco\flocking\index_files\image018.jpg