|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.jscience.computing.ai.cellularautomaton.CellularAutomata
public abstract class CellularAutomata
This class provides the necessary functionality for simple 2-dimensional cellular automata. This class is not suitable for CAs that modify their world separately to their own states. See CellularAutomataLayered for this.
This class supports double-buffering to simulate synchronous updating of the CA world. See Conway's Life or Langton's Self-replicating loop as an example of this.
CellularAutomataLayered| Field Summary | |
|---|---|
protected int |
bufferPosition
The buffer position (only 0 or 1). |
protected int |
bufferSize
The size of the buffer (default = 1) |
protected int |
caSize
Size of the individual CA cells in pixels. |
protected int[][][] |
caWorld
The world array |
protected int |
caWorld_x
Width of the CA world |
protected int |
caWorld_y
Height of the CA world |
protected java.awt.Color |
clrBackground
Background colour |
protected java.awt.Color |
clrGrid
Colour of the grid, if used |
protected java.awt.Color[] |
clrWorld
World colour |
static int |
DOUBLE_BUFFERING
Double buffering |
protected boolean |
doubleBuffering
A quick way to ascertain whether double buffering is enabled |
protected boolean |
drawGrid
Toggle to draw a grid - note this does NOT expand CA cell sizes, so caSize must be set to 3 or higher |
static int |
ENCLOSED
Enclosed geometry. |
protected int |
geometryType
Geometry type. |
static int |
INFINITE
Infinite geometry (unsupported) |
static int |
TORODIAL
Torodial geometry. |
protected static int |
X_AXIS
Specifies translateGeometry(int,int) is to translate across the x-axis. |
protected static int |
Y_AXIS
Specifies translateGeometry(int,int) is to translate across the y-axis. |
| Constructor Summary | |
|---|---|
CellularAutomata()
Default constructor. |
|
CellularAutomata(int size_x,
int size_y)
Constructor with size initialization. |
|
CellularAutomata(int size_x,
int size_y,
int options)
Constructor with size initialization and setup options. |
|
| Method Summary | |
|---|---|
void |
clearWorld()
Clears the world. |
abstract void |
doStep()
This abstract function is where the main workings of the CA should take place. |
void |
drawGrid(boolean dg)
Set or reset the drawGrid flag. |
void |
flipBuffer()
This function must be called when using double-buffering to swap the buffers around. |
java.awt.Color |
getBackgroundColor()
Retrieve the background color. |
int |
getCASize()
Returns the CA size |
int |
getGeometry()
Retrieve the current geometry type |
int |
getSizeX()
Return the world x-size. |
int |
getSizeY()
Return the world y-size. |
int |
getWorldAt(int pos_x,
int pos_y)
Returns the pixel state at a given position. |
abstract void |
init()
This abstract function is where the initialization of the CA should take place. |
static void |
iterateCA(CellularAutomata ca,
int iterations,
int snapshot,
java.lang.String prefix,
int caSize)
This is a default testing method that many of the cellular automata main
methods use. |
static void |
iterateCA(CellularAutomata ca,
java.lang.String[] args)
This method calls iterateCA but with the parameters encoded as a
String array, ideally suited to be passed from the command-line. |
void |
render(java.awt.Graphics graphics,
int pw,
int ph)
This is the default function for drawing the CA world. |
void |
reset()
Reset the world. |
void |
setBackgroundColor(java.awt.Color back)
Set the background colour of the CA. |
void |
setCASize(int cas)
Sets the CA size. |
void |
setGeometry(int g)
Sets the geometry type. |
void |
setWorldAt(int pos_x,
int pos_y,
int s)
Sets the world at the given position to a given state. |
void |
setWorldAtEx(int pos_x,
int pos_y,
java.lang.String cellStates)
This function sets a group of cells according to a specially formatted string. |
void |
setWorldAtRelative(int pos_x,
int pos_y,
int ds)
Set the world state relative to its current state. |
void |
setWorldColors(java.awt.Color[] colors)
Similar to setWorldColour, but accepts an array of colours. |
void |
setWorldColour(int world,
java.awt.Color colour)
This function sets the various world colours used by the CA. |
void |
setWorldSize(int size_x,
int size_y)
Sets the world size. |
protected int |
translateGeometry(int pos,
int axis)
Translates a coordinate to the specified geometry. |
void |
writeImage(java.lang.String filename,
int width,
int height)
This default function writes a PNG image of the CA world. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int INFINITE
public static final int TORODIAL
public static final int ENCLOSED
public static final int DOUBLE_BUFFERING
protected static final int X_AXIS
translateGeometry(int,int) is to translate across the x-axis.
translateGeometry(int, int),
Constant Field Valuesprotected static final int Y_AXIS
translateGeometry(int,int) is to translate across the y-axis.
translateGeometry(int, int),
Constant Field Valuesprotected int[][][] caWorld
protected int caWorld_x
protected int caWorld_y
protected int geometryType
protected java.awt.Color clrBackground
protected java.awt.Color[] clrWorld
protected java.awt.Color clrGrid
protected int caSize
protected int bufferSize
protected boolean doubleBuffering
protected boolean drawGrid
protected int bufferPosition
| Constructor Detail |
|---|
public CellularAutomata()
public CellularAutomata(int size_x,
int size_y)
size_x - width of the worldsize_y - height of the world
public CellularAutomata(int size_x,
int size_y,
int options)
size_x - width of the worldsize_y - height of the worldoptions - possible additional options (such as double buffering)| Method Detail |
|---|
public int getSizeX()
caSizepublic int getSizeY()
caSize
public void setWorldSize(int size_x,
int size_y)
size_x - The new world size (width)size_y - The new world size (height)public void setCASize(int cas)
cas - cell size (in pixels)public int getCASize()
setCASize(int)public void drawGrid(boolean dg)
dg - true to draw the gridrender(Graphics,int,int)public void clearWorld()
public int getWorldAt(int pos_x,
int pos_y)
pos_x - x position of cell state to returnpos_y - y position of cell state to return
translateGeometry(int,int)
public void setWorldAt(int pos_x,
int pos_y,
int s)
pos_x - X-position of cell to setpos_y - Y-position of cell to sets - State to use
public void setWorldAtRelative(int pos_x,
int pos_y,
int ds)
pos_x - the x-position of the cell.pos_y - the y-position of the cell.ds - the delta value to add to the world state.
public void setWorldAtEx(int pos_x,
int pos_y,
java.lang.String cellStates)
"0,1,0;0,0,1;1,1,1". Row strings do not have to be of equal length,
but all positions are calculated according to the first cell.
pos_x - the x-position to start the group of cellspos_y - the y-position to start the group of cellscellStates - the specially formatted string
protected int translateGeometry(int pos,
int axis)
pos - The coordinateaxis - The axis to translate around
geometryType,
X_AXIS,
Y_AXISpublic void setGeometry(int g)
g - the geometry typepublic int getGeometry()
public abstract void doStep()
doStep in interface Steppablepublic abstract void init()
init in interface Steppablepublic void setBackgroundColor(java.awt.Color back)
back - the background colour to be usedsetWorldColour(int,Color)public java.awt.Color getBackgroundColor()
public void setWorldColour(int world,
java.awt.Color colour)
world - the state to setcolour - the colour to usepublic void setWorldColors(java.awt.Color[] colors)
colors - the array of colours to be used for the world states.Gradientpublic void flipBuffer()
init and
doStep.
public void render(java.awt.Graphics graphics,
int pw,
int ph)
caSize
large. The render function will also draw a grid, if requested.
render in interface Visualizablegraphics - the graphics contextpw - the width of the contextph - the height of the contextcaSize
public void writeImage(java.lang.String filename,
int width,
int height)
writeImage in interface Visualizablefilename - the filename to use for the imagewidth - the width of the imageheight - the height of the image
public static void iterateCA(CellularAutomata ca,
java.lang.String[] args)
iterateCA but with the parameters encoded as a
String array, ideally suited to be passed from the command-line.
ca - the CA class to useargs - the arguments to be used (see above)iterateCA(CellularAutomata,int,int,String,int)
public static void iterateCA(CellularAutomata ca,
int iterations,
int snapshot,
java.lang.String prefix,
int caSize)
main
methods use. It will iterate over a certain number of steps, writing snapshots
to disk.
ca - an instance of the cellular automata class.iterations - the total number of iterations.snapshot - the number of iterations before a snapshot is taken.prefix - the prefix to apply to the files.caSize - the size of the CA cells.public void reset()
init again.
reset in interface Steppable
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||