NAME
Math::PlanePath::MathImageCellularRule -- cellular automaton points for binary rule
SYNOPSIS
use Math::PlanePath::MathImageCellularRule;
my $path = Math::PlanePath::MathImageCellularRule->new (rule => 135);
my ($x, $y) = $path->n_to_xy (123);
DESCRIPTION
This is the patterns of Stephen Wolfram's bit-rule based cellular automaton
http://mathworld.wolfram.com/ElementaryCellularAutomaton.html
Points are numbered left to right in rows so for example rule => 30
is
51 52 53 54 55 56 57 58 59 60 61 62 9
44 45 46 47 48 49 50 8
32 33 34 35 36 37 38 39 40 41 42 43 7
27 28 29 30 31 6
18 19 20 21 22 23 24 25 26 5
14 15 16 17 4
8 9 10 11 12 13 3
5 6 7 2
2 3 4 1
1 <- Y=0
-9 -8 -7 -6 -5 -4 -3 -2 -1 X=0 1 2 3 4 5 6 7 8 9
The current implementation is not particularly efficient as it builds and holds onto the bit pattern for all rows up to the highest N or X,Y used. There's no doubt better ways to iterate, but this module does it in PlanePath style.
The automaton starts from a single point N=1 at the origin and grows into the rows above. The rule
parameter specifies what a set of 3 cells below will produce above. It's a value 0 to 255 inclusive used as bits,
cells below rule value
1,1,1 -> bit7
1,1,0 -> bit6
1,0,1 -> bit5
...
0,0,1 -> bit1
0,0,0 -> bit0
When cells 0,0,0 become 1, which means bit0 in rule
is 1, ie. an odd number, the off cells either side of the initial N=1 become all on infinitely to either side. When the 1,1,1 bit7 is a 0, ie. rule<128, they turn on and off in odd and even rows. Only the pyramid part -Y<=X<=Y is in the N numbering, but any infinite cells to the sides are included in the pattern calculation.
The full set of patterns can be seen at the Math World web page above. They range from simple to quite complex. For some the N=1 cell doesn't grow to anything at all, there's only that single point, for example rule 0 or rule 8. Some grow to mere straight lines such as rule 2 or rule 5. But others make columns or patterns with "quadratic" style stepping over 1 or 2 rows, or self-similar patterns such as the Sierpinski triangle. Some rule values even give complicated non-repeating patterns when there's feedback across from one half to the other, for example rule 30.
FUNCTIONS
See "FUNCTIONS" in Math::PlanePath for the behaviour common to all path classes.
$path = Math::PlanePath::MathImageCellularRule->new (rule => 123)
-
Create and return a new path object.
rule
should be an integer between 0 and 255 inclusive.A
rule
should be given always. There is a default, but it's secret and is likely to change. ($x,$y) = $path->n_to_xy ($n)
-
Return the X,Y coordinates of point number
$n
on the path. $n = $path->xy_to_n ($x,$y)
-
Return the point number for coordinates
$x,$y
.$x
and$y
are each rounded to the nearest integer, which has the effect of treating each cell as a square of side 1. If$x,$y
is outside the pyramid or on a skipped cell the return isundef
.
SEE ALSO
Math::PlanePath, Math::PlanePath::CellularRule54, Math::PlanePath::CellularRule190, Math::PlanePath::PyramidRows
http://mathworld.wolfram.com/ElementaryCellularAutomaton.html