public class CellularAutomaton
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
GreasedRegion |
current
Returned directly by some methods, but you may want to change this at some other point.
|
Constructor and Description |
---|
CellularAutomaton()
Constructs a CellularAutomaton with an unfilled 64x64 GreasedRegion, that can be altered later via
current . |
CellularAutomaton(GreasedRegion current)
Stores a direct reference to
current as this object's current field, and initializes the other
necessary fields. |
CellularAutomaton(int width,
int height)
Constructs a CellularAutomaton with an unfilled GreasedRegion of the specified width and height, that can be
altered later via
current . |
Modifier and Type | Method and Description |
---|---|
CellularAutomaton |
remake(GreasedRegion next)
Re-initializes this CellularAutomaton using a different GreasedRegion as a basis.
|
GreasedRegion |
runBasicSmoothing()
Reduces the sharpness of corners by only considering a cell on if the previous version has 5 of the 9 cells in
the containing 3x3 area as "on." Typically, this method is run repeatedly.
|
GreasedRegion |
runDiagonalGapCleanup()
This takes the
current GreasedRegion and removes any cells that have a diagonal neighbor if that
neighbor cannot be accessed from shared orthogonal neighbors. |
GreasedRegion |
runGameOfLife()
Runs one step of the simulation called Conway's Game of Life, which has relatively simple rules:
Any "on" cell with fewer than two "on" neighbors becomes "off."
Any "on" cell with two or three "on" neighbors (no more than three) stays "on."
Any "on" cell with more than three "on" neighbors becomes "off."
Any "off" cell with exactly three "on" neighbors becomes "on."
These rules can bring about complex multi-step patterns in many cases, eventually stabilizing to predictable
patterns in most cases.
|
public GreasedRegion current
public CellularAutomaton()
current
.public CellularAutomaton(int width, int height)
current
.width
- the width of the CellularAutomatonheight
- the height of the CellularAutomatonpublic CellularAutomaton(GreasedRegion current)
current
as this object's current
field, and initializes the other
necessary fields.current
- a GreasedRegion that will be used directly; changes will be sharedpublic CellularAutomaton remake(GreasedRegion next)
next
, then this performs no allocations and simply sets the existing
contents. Otherwise, it makes one new 2D array and also has all 9 of the internal GreasedRegions adjust in size,
which involves some allocation. If next
is null, this does nothing and returns itself without changes.next
- a GreasedRegion to set this CellularAutomaton to read from and adjustpublic GreasedRegion runBasicSmoothing()
current
GreasedRegion that this will use for
any future calls to this, and changes to current will be used here.current
public GreasedRegion runGameOfLife()
current
public GreasedRegion runDiagonalGapCleanup()
current
GreasedRegion and removes any cells that have a diagonal neighbor if that
neighbor cannot be accessed from shared orthogonal neighbors. That is, if a 2x2 area contains two "off" cells
that are diagonally adjacent and contains two "on" cells that are diagonally adjacent, this sets that whole 2x2
area to "off."current
after orthogonally-inaccessible pairs of diagonal "on" cells are removedCopyright © Eben Howard 2012–2022. All rights reserved.