org.generation5.demos
Class Wolfram1DCA

java.lang.Object
  extended byorg.generation5.bio.CellularAutomata
      extended byorg.generation5.demos.Wolfram1DCA
All Implemented Interfaces:
Steppable, Visualizable

public class Wolfram1DCA
extends CellularAutomata

Implements Wolfram's one-dimensional cellular automata. The class allows for a large neighbourhood size, and supports smooth scrolling of the rendered region.


Field Summary
protected  int initialState
          The initial state of the CA, either RANDOM or MIDPOINT.
static int MIDPOINT
          Start the CA with one mid point
protected  int neighbourSize
          The neighbourhood size.
static int RANDOM
          Start the CA with an random line
protected  long ruleSpecifier
          The rule specifier.
 
Fields inherited from class org.generation5.bio.CellularAutomata
bufferPosition, bufferSize, caSize, caWorld, caWorld_x, caWorld_y, clrBackground, clrGrid, clrWorld, DOUBLE_BUFFERING, doubleBuffering, drawGrid, ENCLOSED, geometryType, INFINITE, TORODIAL, X_AXIS, Y_AXIS
 
Constructor Summary
Wolfram1DCA()
          Default constructor.
Wolfram1DCA(int size_x, int size_y)
          Create an instance with world size information.
Wolfram1DCA(int size_x, int size_y, int initType)
          Create an instance with world size information as well as a starting state.
 
Method Summary
 void doStep()
          Advance the world by one timestep.
 int getInitialState()
          Retrieves the inital state type - either random or midpoint.
 long getRules()
          Return the rule specifier.
 void init()
          Initializes the 1D CA.
static void main(java.lang.String[] args)
           
 void render(java.awt.Graphics graphics, int pw, int ph)
          Renders the 1D cellular automata.
 void setInitialState(int initState)
          Set the initial world state.
 void setRules(int neighbours, long rule)
          Sets the neighbourhood size and the rule specifier.
 
Methods inherited from class org.generation5.bio.CellularAutomata
clearWorld, drawGrid, flipBuffer, getBackgroundColor, getCASize, getGeometry, getSizeX, getSizeY, getWorldAt, iterateCA, iterateCA, reset, setBackgroundColor, setCASize, setGeometry, setWorldAt, setWorldAtEx, setWorldAtRelative, setWorldColors, setWorldColour, setWorldSize, translateGeometry, writeImage
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

neighbourSize

protected int neighbourSize
The neighbourhood size.


ruleSpecifier

protected long ruleSpecifier
The rule specifier. This is a single digit number that encodes the rules.


initialState

protected int initialState
The initial state of the CA, either RANDOM or MIDPOINT.


RANDOM

public static int RANDOM
Start the CA with an random line


MIDPOINT

public static int MIDPOINT
Start the CA with one mid point

Constructor Detail

Wolfram1DCA

public Wolfram1DCA()
Default constructor.


Wolfram1DCA

public Wolfram1DCA(int size_x,
                   int size_y)
Create an instance with world size information.

Parameters:
size_x - the x-size of the world.
size_y - the y-size of the world.

Wolfram1DCA

public Wolfram1DCA(int size_x,
                   int size_y,
                   int initType)
Create an instance with world size information as well as a starting state.

Parameters:
size_x - the x-size of the world.
size_y - the y-size of the world.
initType - the initial state of the world, either RANDOM or MIDPOINT.
Method Detail

doStep

public void doStep()
Advance the world by one timestep. This means calculating one line of the CA.

Specified by:
doStep in interface Steppable
Specified by:
doStep in class CellularAutomata

getRules

public long getRules()
Return the rule specifier.

Returns:
the rule specifier.

setRules

public void setRules(int neighbours,
                     long rule)
Sets the neighbourhood size and the rule specifier.

Parameters:
neighbours - the neighbourhood size.
rule - the rule specifier.

getInitialState

public int getInitialState()
Retrieves the inital state type - either random or midpoint.

Returns:
returns either RANDOM or MIDPOINT.

setInitialState

public void setInitialState(int initState)
Set the initial world state.

Parameters:
initState - set to either RANDOM or MIDPOINT.

init

public void init()
Initializes the 1D CA.

Specified by:
init in interface Steppable
Specified by:
init in class CellularAutomata

render

public void render(java.awt.Graphics graphics,
                   int pw,
                   int ph)
Renders the 1D cellular automata. This overrides the usual render function to scroll the CA data once the number of timesteps is greater than the height of the rendering area.

Specified by:
render in interface Visualizable
Overrides:
render in class CellularAutomata
Parameters:
graphics - the graphics context.
pw - the width of the context.
ph - the height of the context.
See Also:
CellularAutomata.render(Graphics, int, int)

main

public static void main(java.lang.String[] args)
Parameters:
args - the command-line arguments to pass to iterateCA.

This documentation is part of the Generation5 JDK.