org.generation5.bio
Class FlockingAgent

java.lang.Object
  extended byorg.generation5.bio.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
           
protected static double avoidW
           
protected static double centroidR
           
protected static double centroidW
           
protected static int cols
          The height of the flocking agent's world.
protected static double copyR
           
protected static double copyW
           
protected static double ddt
           
protected static double dt
           
protected static double minV
           
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
           
protected static double ny
           
protected  double positionX
          The x-position of this agent.
protected  double positionY
          The positionY-position of this agent.
protected static double randW
           
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
           
protected static double vAvoidR
           
protected static double vAvoidW
           
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)
           
protected static double dist(double x1, double y1, double x2, double y2)
           
protected static double dot(double x1, double y1, double x2, double y2)
           
static void initMisc(java.util.Random r, int rr, int cc, double va, double vaa, double mv)
           
static void initRadii(double cr, double ccr, double ar, double vr)
           
static void initTime(double t, double tt)
           
static void initWeights(double cw, double ccw, double aw, double vw, double rw)
           
protected static double len(double x, double y)
           
protected static void normalize(double x, double y)
           
 void render(java.awt.Graphics graphics, int sx, int sy)
           
static void setFlock(FlockingAgent[] flock)
           
 void update()
           
 
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

minV

protected static double minV

copyR

protected static double copyR

centroidR

protected static double centroidR

avoidR

protected static double avoidR

vAvoidR

protected static double vAvoidR

copyW

protected static double copyW

centroidW

protected static double centroidW

avoidW

protected static double avoidW

vAvoidW

protected static double vAvoidW

randW

protected static double randW

dt

protected static double dt

ddt

protected static double ddt

myFlock

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


nx

protected static double nx

ny

protected static double ny

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)

initRadii

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

initWeights

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

initTime

public static void initTime(double t,
                            double tt)

setFlock

public static void setFlock(FlockingAgent[] flock)

normalize

protected static void normalize(double x,
                                double y)

len

protected static double len(double x,
                            double y)

dist

protected static double dist(double x1,
                             double y1,
                             double x2,
                             double y2)

dot

protected static double dot(double x1,
                            double y1,
                            double x2,
                            double y2)

computeNewHeading

public void computeNewHeading(int self)
Parameters:
self -

update

public void update()

render

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

This documentation is part of the Generation5 JDK.