Home
Projects
  Software
  Downloads
  Links
  Authors
  Contact Us

 

 

 

Flocking by Mike

My VisualBots simulation is based on Craig Reynolds's flocking model called Boids. The model has been widely used to simulate coordinated animal motion such as bird flocks and fish schools. Boids has been the basis for computer animated special effects in movies, as in the 1992 film Batman Returns, where bat swarms and flocks of penguins were simulated. One of the interesting aspects of the Boids model is that realistic looking flocking behavior emerges spontaneously as a result of rules acted out at the individual level without a "central command" coordinator or leader. It is widely accepted that real birds flock using an individual-based, decentralized behavior model as well.

The rules behind Boids are simple. Each member of the flock determines its own movements by considering four "steering behaviors" that are a function of the position, speed and heading of its surrounding flock mates and obstacles:

  1. Separation: turn to avoid crowding local flock mates
  2. Alignment: turn towards the average heading of local flock mates
  3. Cohesion: turn to move toward the average position of local flock mates
  4. External Avoidance: turn to avoid any obstacles

My simulation consists of two loops - one for calculating each Bot's steering behavior (the "sensing" loop) and the other to move each Bot accordingly (the "action" loop). An outline of the algorithm in pseudo code is shown below. The composite behavior referred to in the outline is the turn angle computed by combining the turn angles from the four steering behaviors. In computing the composite behavior, some steering behaviors should take precedence over others, for example, obstacle avoidance should be given the highest priority to avoid death by smashing into a wall or window. My simulation introduces an obstacle in the form of the position of mouse icon on the Screen display. This gives the observer a chance to interact with the simulation. The following pseudo code gives an idea of how the simulation proceeds.

For each Time Step Do the Following....
    For Each Bot In Bots ("sensing" loop)
        Identify local flock mates and obstacles
        Calculate four steering behaviors
        Calculate composite behavior
        Store composite behavior into Bot memory
    Next Bot
    For Each Bot In Bots ("action" loop)
        Turn according to the stored composite behavior
        Move to next position
    Next Bot
Next Time Step

A few other comments on the algorithm....I used the GroupNear method of the Bot object to collect local flock mates within a certain radius. The method returns a Group object which contains the local flock mates. The Group object has methods to calculate average direction and position of its members. Also, there is a good reason for needing two inner loops instead of just one. For each time step, the composite steering behavior of all Bots needs to be calculated and stored BEFORE any Bot is allowed to move. Using two inner loops synchronizes the Bots, allowing all to sense the local environment at the same instance, and then to simultaneously react to that sense. In order to store each Bot's composite steering behavior calculated in the sensing loop for use in the action loop, the composite behavior is stored using the Tags method of the Bot object. Any number of Tag objects can be added in order to attach information to each Bot - in essence serving as a Bot memory.

Below is a screenshot showing a flock avoiding the mouse icon:

References:

Craig Reynolds, "Flocks, Herds, and Schools: A Distributed Behavioral Model",
Proceedings of SIGGRAPH '87, in Computer Graphics volume 21, number 4, July
1987,pp 25-34.

Back to projects main page       <<prev project       next project>>

 

 
 
Home Projects Software Downloads Authors Links Contact Us
Copyright ©   This sited last updated Jan 05, 2008