Math::PlanePath::BoxFractalQuarter -- growth of a 2-D cellular automaton
use Math::PlanePath::BoxFractalQuarter; my $path = Math::PlanePath::BoxFractalQuarter->new; my ($x, $y) = $path->n_to_xy (123);
In progress ...
This is the "box fractal" in a quarter of the plane. Cells are numbered by growth level and anti-clockwise within the level.
13 | ... 12 | 31 11 | 30 29 10 | 27 9 | 26 28 8 | 24 23 22 21 7 | 16 15 6 | 25 13 12 20 5 | 10 9 4 | 7 3 | 6 8 2 | 5 4 11 19 1 | 2 14 Y=0| 1 3 17 18 | +-------------------------------------------- X=0 1 2 3 4 5 6 7 8 9 10 11 12 13
In general each level always grows by 1 along the leading diagonal X=Y and travels into the sides with a sort of diamond shaped tree pattern.
Counting level 1 as the N=1 at the origin, level 2 as the next N=2, etc, the number of new cells added in a growth level is
levelcells(level) = 3^((count ternary 2s in level) - 1)
So level 1 has 3^(1-1)=1 cell, as does level 2 N=2. Then level 3 has 3^(2-1)=3 cells N=3,N=4,N=5 because 3=0b11 has two 1 bits in binary. The N start and end for a level is the cumulative total of those before it,
Nstart(level) = 1 + (levelcells(0) + ... + levelcells(level-1)) Nend(level) = levelcells(0) + ... + levelcells(level)
For example level 3 ends at N=(1+1+3)=5.
level Nstart levelcells Nend 1 1 1 1 2 2 1 2 3 3 3 5 4 6 1 6 5 7 3 9 6 10 3 12 7 13 9 21 8 22 1 22 9 23 3 25
For a power-of-2 level the Nstart sum is
Nstart(2^a) = 1 + (4^a-1)/3
For example level=4=2^2 starts at N=1+(4^2-1)/3=6, or level=8=2^3 starts N=1+(4^3-1)/3=22.
Further bits in the level value contribute powers-of-4 with a tripling for each bit above. So if the level number has bits a,b,c,d,etc in descending order,
level = 2^a + 2^b + 2^c + 2^d ... a>b>c>d... Nstart = 1 + (4^a-1)/3 + 4^b + 3 * 4^c + 3^2 * 4^d + ...
For example level=6 = 2^2+2^1 is Nstart = 1+(4^2-1)/3 + 4^1 = 10. Or level=7 = 2^2+2^1+2^0 is Nstart = 1+(4^2-1)/3 + 4^1 + 3*4^0 = 13.
The square shape growth up to a level 2^a repeats three times. For example a 5-cell "a" part,
| d d c c | d c | d d c c | * | a a b b | a b | a a b b +--------------------
The 2x2 square "a" repeats, pointing SE, NE and NW as "b", "c" and "d". This resulting 4x4 square then likewise repeats. The points in the path here are numbered by growth level rather than by this sort of replication, but the replication helps to see the structure of the pattern.
See "FUNCTIONS" in Math::PlanePath for behaviour common to all path classes.
$path = Math::PlanePath::BoxFractalQuarter->new ()
Create and return a new path object.
($x,$y) = $path->n_to_xy ($n)
Return the X,Y coordinates of point number $n on the path. Points begin at 1 and if $n < 0 then the return is an empty list.
$n
$n < 0
Math::PlanePath, Math::PlanePath::UlamWarburtonQuarter
http://user42.tuxfamily.org/math-planepath/index.html
Copyright 2012 Kevin Ryde
This file is part of Math-PlanePath.
Math-PlanePath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.
Math-PlanePath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Math-PlanePath. If not, see <http://www.gnu.org/licenses/>.
To install Math::PlanePath, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Math::PlanePath
CPAN shell
perl -MCPAN -e shell install Math::PlanePath
For more information on module installation, please visit the detailed CPAN module installation guide.