org.jscience.computing.ai.artificiallife
Class FlockingAgent

java.lang.Object
  extended by org.jscience.computing.ai.artificiallife.FlockingAgent

public class FlockingAgent
extends java.lang.Object

Implements an agent that flocks with other similar agents. This code is based on Mike Miller's Java code conversion for The Computational Beauty of Nature by Gary William Flake. The code has been converted to the Generation5 SDK style and system (using Visualizable etc.).

See Also:
FlockingAgent

Field Summary
protected static double avoidR
          DOCUMENT ME!
protected static double avoidW
          DOCUMENT ME!
protected static double centroidR
          DOCUMENT ME!
protected static double centroidW
          DOCUMENT ME!
protected static int cols
          The height of the flocking agent's world.
protected static double copyR
          DOCUMENT ME!
protected static double copyW
          DOCUMENT ME!
protected static double ddt
          DOCUMENT ME!
protected static double dt
          DOCUMENT ME!
protected static double minV
          DOCUMENT ME!
protected static FlockingAgent[] myFlock
          The flock this agent is in.
protected  double nvx
          The x-velocity to be used in the next frame.
protected  double nvy
          The y-velocity to be used in the next frame.
protected static double nx
          DOCUMENT ME!
protected static double ny
          DOCUMENT ME!
protected  double positionX
          The x-position of this agent.
protected  double positionY
          The positionY-position of this agent.
protected static double randW
          DOCUMENT ME!
protected static java.util.Random rnd
          The random seed used to generate positional data.
protected static int rows
          The width of the flocking agent's world.
protected static double vAvoidA
          DOCUMENT ME!
protected static double vAvoidR
          DOCUMENT ME!
protected static double vAvoidW
          DOCUMENT ME!
protected static double viewA
          The viewing angle of the agent.
protected  double vx
          The x-velocity of this agent.
protected  double vy
          The y-velocity of this agent.
 
Constructor Summary
FlockingAgent()
          Creates a new instance of FlockingAgent.
 
Method Summary
 void computeNewHeading(int self)
          DOCUMENT ME!
protected static double dist(double x1, double y1, double x2, double y2)
          DOCUMENT ME!
protected static double dot(double x1, double y1, double x2, double y2)
          DOCUMENT ME!
static void initMisc(java.util.Random r, int rr, int cc, double va, double vaa, double mv)
          DOCUMENT ME!
static void initRadii(double cr, double ccr, double ar, double vr)
          DOCUMENT ME!
static void initTime(double t, double tt)
          DOCUMENT ME!
static void initWeights(double cw, double ccw, double aw, double vw, double rw)
          DOCUMENT ME!
protected static double len(double x, double y)
          DOCUMENT ME!
protected static void normalize(double x, double y)
          DOCUMENT ME!
 void render(java.awt.Graphics graphics, int sx, int sy)
          DOCUMENT ME!
static void setFlock(FlockingAgent[] flock)
          DOCUMENT ME!
 void update()
          DOCUMENT ME!
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

rnd

protected static java.util.Random rnd
The random seed used to generate positional data.


rows

protected static int rows
The width of the flocking agent's world.


cols

protected static int cols
The height of the flocking agent's world.


viewA

protected static double viewA
The viewing angle of the agent.


vAvoidA

protected static double vAvoidA
DOCUMENT ME!


minV

protected static double minV
DOCUMENT ME!


copyR

protected static double copyR
DOCUMENT ME!


centroidR

protected static double centroidR
DOCUMENT ME!


avoidR

protected static double avoidR
DOCUMENT ME!


vAvoidR

protected static double vAvoidR
DOCUMENT ME!


copyW

protected static double copyW
DOCUMENT ME!


centroidW

protected static double centroidW
DOCUMENT ME!


avoidW

protected static double avoidW
DOCUMENT ME!


vAvoidW

protected static double vAvoidW
DOCUMENT ME!


randW

protected static double randW
DOCUMENT ME!


dt

protected static double dt
DOCUMENT ME!


ddt

protected static double ddt
DOCUMENT ME!


myFlock

protected static FlockingAgent[] myFlock
The flock this agent is in.


nx

protected static double nx
DOCUMENT ME!


ny

protected static double ny
DOCUMENT ME!


positionX

protected double positionX
The x-position of this agent.


positionY

protected double positionY
The positionY-position of this agent.


vx

protected double vx
The x-velocity of this agent.


vy

protected double vy
The y-velocity of this agent.


nvx

protected double nvx
The x-velocity to be used in the next frame. Remember that the flocking agents are updated "simultaneously", so they should all have their new values computed using computeNewHeading, then all have them updated using update.


nvy

protected double nvy
The y-velocity to be used in the next frame. Remember that the flocking agents are updated "simultaneously", so they should all have their new values computed using computeNewHeading, then all have them updated using update.

Constructor Detail

FlockingAgent

public FlockingAgent()
Creates a new instance of FlockingAgent. Random values are automatically assigned to the positional and velocity variables.

Method Detail

initMisc

public static void initMisc(java.util.Random r,
                            int rr,
                            int cc,
                            double va,
                            double vaa,
                            double mv)
DOCUMENT ME!

Parameters:
r - DOCUMENT ME!
rr - DOCUMENT ME!
cc - DOCUMENT ME!
va - DOCUMENT ME!
vaa - DOCUMENT ME!
mv - DOCUMENT ME!

initRadii

public static void initRadii(double cr,
                             double ccr,
                             double ar,
                             double vr)
DOCUMENT ME!

Parameters:
cr - DOCUMENT ME!
ccr - DOCUMENT ME!
ar - DOCUMENT ME!
vr - DOCUMENT ME!

initWeights

public static void initWeights(double cw,
                               double ccw,
                               double aw,
                               double vw,
                               double rw)
DOCUMENT ME!

Parameters:
cw - DOCUMENT ME!
ccw - DOCUMENT ME!
aw - DOCUMENT ME!
vw - DOCUMENT ME!
rw - DOCUMENT ME!

initTime

public static void initTime(double t,
                            double tt)
DOCUMENT ME!

Parameters:
t - DOCUMENT ME!
tt - DOCUMENT ME!

setFlock

public static void setFlock(FlockingAgent[] flock)
DOCUMENT ME!

Parameters:
flock - DOCUMENT ME!

normalize

protected static void normalize(double x,
                                double y)
DOCUMENT ME!

Parameters:
x - DOCUMENT ME!
y - DOCUMENT ME!

len

protected static double len(double x,
                            double y)
DOCUMENT ME!

Parameters:
x - DOCUMENT ME!
y - DOCUMENT ME!
Returns:
DOCUMENT ME!

dist

protected static double dist(double x1,
                             double y1,
                             double x2,
                             double y2)
DOCUMENT ME!

Parameters:
x1 - DOCUMENT ME!
y1 - DOCUMENT ME!
x2 - DOCUMENT ME!
y2 - DOCUMENT ME!
Returns:
DOCUMENT ME!

dot

protected static double dot(double x1,
                            double y1,
                            double x2,
                            double y2)
DOCUMENT ME!

Parameters:
x1 - DOCUMENT ME!
y1 - DOCUMENT ME!
x2 - DOCUMENT ME!
y2 - DOCUMENT ME!
Returns:
DOCUMENT ME!

computeNewHeading

public void computeNewHeading(int self)
DOCUMENT ME!

Parameters:
self -

update

public void update()
DOCUMENT ME!


render

public void render(java.awt.Graphics graphics,
                   int sx,
                   int sy)
DOCUMENT ME!

Parameters:
graphics - DOCUMENT ME!
sx - DOCUMENT ME!
sy - DOCUMENT ME!