org.jscience.computing.ai.artificiallife
Class Flock

java.lang.Object
  extended by org.jscience.computing.ai.artificiallife.Flock
All Implemented Interfaces:
Steppable, Visualizable

public class Flock
extends java.lang.Object
implements Visualizable, Steppable

This class groups org.jscience.computing.ai.agents.FlockingAgent into one flock.

See Also:
org.jscience.computing.ai.agents.FlockingAgent

Field Summary
protected  java.awt.Color clrBackground
          The background of the flock.
protected  int cols
          The number of columns in the flocking world (this is equivalent to pixel width).
protected  FlockingAgent[] flock
          The actual flocking agent array.
protected  int numFlockingAgents
          The number of flocking agents in the flock.
protected  int rows
          The number of rows in the flocking world (this is equivalent to pixel height).
 
Constructor Summary
Flock(int fa, int cols, int rows)
          Create a new instance of Flock with size information.
 
Method Summary
 void doStep()
          Advance the boids world by one time-step.
 java.awt.Color getBackgroundColor()
          Retrieve the background color.
 void init()
          A standard initialization function.
static void main(java.lang.String[] args)
          A test function that writes the 640x480 boids world once every 10 time-steps for 250 iterations.
 void render(java.awt.Graphics g, int width, int height)
          Draw the boids world.
 void reset()
          Reset the flock (call init).
 void setBackgroundColor(java.awt.Color clr)
          Set the background color.
 void setWorldSize(int rows, int cols)
          Set the number of rows and columns in the world.
 void writeImage(java.lang.String s, int width, int height)
          Write an image of the boids world.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

rows

protected int rows
The number of rows in the flocking world (this is equivalent to pixel height).


cols

protected int cols
The number of columns in the flocking world (this is equivalent to pixel width).


numFlockingAgents

protected int numFlockingAgents
The number of flocking agents in the flock.


flock

protected FlockingAgent[] flock
The actual flocking agent array.


clrBackground

protected java.awt.Color clrBackground
The background of the flock.

Constructor Detail

Flock

public Flock(int fa,
             int cols,
             int rows)
Create a new instance of Flock with size information.

Parameters:
fa - The number of flocking agents to assign.
cols - The number of columns in the flocking world.
rows - The number of rows in the flocking world.
Method Detail

setWorldSize

public void setWorldSize(int rows,
                         int cols)
Set the number of rows and columns in the world.

Parameters:
rows - Number of rows in this world.
cols - Number of columns in this world.

init

public void init()
Description copied from interface: Steppable
A standard initialization function. This should be assumed to be a recurrable initialization procedure. Any one-off initializations should be done in the constructor.

Specified by:
init in interface Steppable

doStep

public void doStep()
Advance the boids world by one time-step.

Specified by:
doStep in interface Steppable

main

public static void main(java.lang.String[] args)
A test function that writes the 640x480 boids world once every 10 time-steps for 250 iterations.

Parameters:
args - the command line arguments

render

public void render(java.awt.Graphics g,
                   int width,
                   int height)
Draw the boids world. The boids are represented as arrows showing their direction.

Specified by:
render in interface Visualizable
Parameters:
g - the graphics context.
width - the width of the context.
height - the height of the context.

writeImage

public void writeImage(java.lang.String s,
                       int width,
                       int height)
Write an image of the boids world.

Specified by:
writeImage in interface Visualizable
Parameters:
s - the filename.
width - the width of the image.
height - the height of the image.

reset

public void reset()
Reset the flock (call init).

Specified by:
reset in interface Steppable
See Also:
init()

setBackgroundColor

public void setBackgroundColor(java.awt.Color clr)
Set the background color.

Parameters:
clr - the background color.

getBackgroundColor

public java.awt.Color getBackgroundColor()
Retrieve the background color.

Returns:
the background color in use.