I have been interested in the field known as Artificial Life for a number of years. One of the most beautiful findings of this field is a very simple algorithm known as boids, which models flocking behaviour in nature. This algorithm was invented by computer animator Craig Reynolds.
In 1996 I wrote an example of this algorithm as a Java applet, which continues to be quite popular.
The algorithm models the behaviour of flocking animals (eg. birds) by simple rules which describe only the behaviour of individuals. For a full explanation and an informative history of this algorithm see Craig Reynolds' boids page.
Briefly, the rules are:
If you would like to learn more about how these rules are implemented, I have written a programming explanation with accompanying pseudocode.
Here is my Java based example of the model:
A nicely laid out version of this is here , and for your viewing pleasure, a larger version is also available. Oh, and now one set at Coogee Beach.
You can also download the Java classes and a sample html file: Boids.tar.gz or Boids.zip
Todd Warner has made an implementation in Python based on the above pseudocode. It is available (under the GNU GPL) at http://www.dma.org/~tw/pyboids/.
Jeff Foster implement this flocking behaviour in Clojure. Yay functional programming!
An interesting parallel to this theory is that proposed by Richard Dawkins in The Selfish Gene. His theory, which he describes in the context of accounting for the evolution of pack behaviour, is as follows:
A simple strategy for a predator animal is to chase the closest prey animal in its vicinity. This is reasonable because it expends the least amount of effort for the predator.
Then a strategy for a prey individual is to try to keep as far away from predators as possible: if predators only attack the closest prey individuals, then all the others should be safe. You can consider each prey individual as having a "domain of danger" surrounding it. This is the area around it comprising the points around it to which it is the closest prey. For example, a lone individual would have a "domain of danger" which is a large circle around it, whereas each individual in a pack would have a small "domain of danger" around it. Then the strategy is to reduce the "domain of danger" as much as possible. This is achieved in the pack formation, where all the prey individuals try to stay together, each one of them selfishly trying to reduce its own "domain of danger". However, the individuals on the edges of the pack have a much greater "domain of danger" than those in the interior. Thus, the individuals on the edge of the pack try to move towards the interior of the pack, which moves other individuals to the edges.
This strategy correlates well with the boids rules. Each individual boid tries to move towards the centre of mass of the pack, which very simply implements the reduction of the "domain of danger". Of course, they cannot all move to the very centre: there is a limit to the closeness of individuals, such that they all have enough room to move. This is also implemented as a rule for Boids.
Copyright © 1995-2010 Conrad Parker <email@example.com>. Last modified Fri Apr 23 2010