Package toxi.sim.automata
Class CAWolfram1D
java.lang.Object
toxi.sim.automata.CAWolfram1D
- All Implemented Interfaces:
CARule
,MatrixEvolver
An extended & customized implementation of 1D Wolfram automata, fully
compatible with the classic definition, yet supporting flexible kernel
sizes/rule systems and n-ary cell states.
The algorithm can be configured to automatically expire cells when they've
reached their maximum state/age. This is a varying behaviour to the
traditional CA approach, but can produce very interesting results.
-
Constructor Summary
ConstructorDescriptionCAWolfram1D
(int kernelWidth, boolean isTiling) CAWolfram1D
(int kernelWidth, int states, boolean isTiling) -
Method Summary
Modifier and TypeMethodDescriptionvoid
final int
final boolean[]
final BigInteger
int
boolean
boolean
isTiling()
void
void
setAutoExpire
(boolean isAutoexpire) Sets the auto expiration behaviour.setRuleArray
(boolean[] r) Updates the rules using the given array.setRuleID
(long id) setRuleID
(BigInteger id) Uses theBigInteger
value to define the new rules.void
setStateCount
(int num) void
setTiling
(boolean state)
-
Constructor Details
-
CAWolfram1D
public CAWolfram1D(int kernelWidth, boolean isTiling) -
CAWolfram1D
public CAWolfram1D(int kernelWidth, int states, boolean isTiling)
-
-
Method Details
-
evolve
- Specified by:
evolve
in interfaceMatrixEvolver
-
getNumRuleBits
public final int getNumRuleBits()- Returns:
- the number of rule bits used for the current kernel size.
-
getRuleArray
public final boolean[] getRuleArray()- Returns:
- the rules as boolean array.
-
getRuleAsBigInt
- Returns:
- the rules packed into a single
BigInteger
value.
-
getStateCount
public int getStateCount()- Specified by:
getStateCount
in interfaceCARule
-
isAutoExpire
public boolean isAutoExpire()- Specified by:
isAutoExpire
in interfaceCARule
- Returns:
- the isAutoexpire
-
isTiling
public boolean isTiling() -
randomize
public void randomize() -
setAutoExpire
public void setAutoExpire(boolean isAutoexpire) Sets the auto expiration behaviour.- Specified by:
setAutoExpire
in interfaceCARule
- Parameters:
isAutoexpire
- true, if cells expire automatically when their max. state is reached (i.e. state reverts back to 0)
-
setRuleArray
Updates the rules using the given array. The new array needs to be of the same size as the length returned bygetNumRuleBits()
.- Parameters:
r
- new rules- Returns:
- itself
-
setRuleID
Uses the
BigInteger
value to define the new rules. Only the lowest N bits of the value are used. The value of N depends on the current kernel size and can be queried viagetNumRuleBits()
. The top most bit used corresponds with the left most kernel window item.For example:
- kernelWidth = 1 -> number of bits 2*(4^1)=8
- kernelWidth = 2 -> number of bits 2*(4^2)=32
- kernelWidth = 3 -> number of bits 2*(4^2)=128
- Parameters:
id
-- Returns:
- itself
-
setRuleID
-
setStateCount
public void setStateCount(int num) - Specified by:
setStateCount
in interfaceCARule
-
setTiling
public void setTiling(boolean state)
-