|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objecttoxi.sim.automata.CAMatrix
public class CAMatrix
A 1D/2D Cellular Automata simulation matrix with flexible support of automata rules. The class provides accessors to the backing matrix arrays and utility methods to manipulate them.
Constructor Summary | |
---|---|
CAMatrix(int width)
Creates a new 1D instance of the given width. |
|
CAMatrix(int w,
int h)
Creates a new 2D instance of the given width & height. |
Method Summary | |
---|---|
CAMatrix |
addNoise(float probability)
|
CAMatrix |
addNoise(float probability,
int minState,
int maxState)
Adds noise to the matrix. |
CAMatrix |
drawBoxAt(int x,
int y,
int w,
int state)
Sets all matrix cells in a square around the given x,y coordinates to the requested state. |
int |
getGeneration()
|
int |
getHeight()
|
int |
getIndexFor(int x,
int y)
Computes the array index for the cell at x,y. |
int[] |
getMatrix()
|
MatrixEvolver |
getRule()
|
int[] |
getSwapBuffer()
|
int |
getWidth()
|
CAMatrix |
reset()
Clears the matrix and resets the generation counter. |
CAMatrix |
seedImage(int[] pixels,
int imgWidth,
int imgHeight)
Uses the given ARGB pixel array as seed mask for the matrix. |
CAMatrix |
setRule(CARule r)
Assigns the given rule as evaluator for this matrix. |
CAMatrix |
setStateAt(int x,
int y,
int state)
Sets the cell state at x,y. |
CAMatrix |
update()
Evolves the matrix to the next generation by applying one iteration of the assigned CARule implementation. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public CAMatrix(int width)
width
- public CAMatrix(int w, int h)
w
- h
- Method Detail |
---|
public CAMatrix addNoise(float probability)
public CAMatrix addNoise(float probability, int minState, int maxState)
probability
- minState
- maxState
-
public CAMatrix drawBoxAt(int x, int y, int w, int state)
x
- box center xy
- box center yw
- box widthstate
- target state
public final int getGeneration()
getGeneration
in interface EvolvableMatrix
public final int getHeight()
getHeight
in interface EvolvableMatrix
public final int getIndexFor(int x, int y)
x
- y
-
public final int[] getMatrix()
getMatrix
in interface EvolvableMatrix
public final MatrixEvolver getRule()
public final int[] getSwapBuffer()
getSwapBuffer
in interface EvolvableMatrix
public final int getWidth()
getWidth
in interface EvolvableMatrix
public CAMatrix reset()
public CAMatrix seedImage(int[] pixels, int imgWidth, int imgHeight)
pixels
- imgWidth
- imgHeight
-
public CAMatrix setRule(CARule r)
r
- rule implementation
public CAMatrix setStateAt(int x, int y, int state)
ArrayIndexOutOfBoundsException
is thrown.
x
- y
- state
-
public CAMatrix update()
CARule
implementation. If no rule is assigned, the
method does nothing.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |