Math::PlanePath::FibonacciWordFractal -- turns by Fibonacci word bits
use Math::PlanePath::FibonacciWordFractal; my $path = Math::PlanePath::FibonacciWordFractal->new; my ($x, $y) = $path->n_to_xy (123);
This is an integer version of the Fibonacci word fractal by Alexis Monnerot-Dumaine. It makes turns controlled by by the "Fibonacci word" or "golden string" sequence
11 | 27-28-29 33-34-35 53-54-55 59-60-61 | | | | | | | | | 10 | 26 30-31-32 36 52 56-57-58 62 | | | | | 9 | 25-24 38-37 51-50 64-63 | | | | | 8 | 23 39 43-44-45 49 65 | | | | | | | 7 | 21-22 40-41-42 46-47-48 66-67 | | | 6 | 20 16-15-14 74-73-72 68 | | | | | | | 5 | 19-18-17 13 75 71-70-69 | | | 4 | 11-12 76-77 | | | 3 | 10 78 | | | 2 | 9--8 80-79 | | | 1 | 1--2--3 7 81 85-86-87 | | | | | | | Y=0 | 0 4--5--6 82-83-84 88-89-... +------------------------------------------------------- X=0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
A current direction up,down,left,right is maintained, initially up. The path goes one in that direction then if the Fibonacci word is 0 then turn to the left if N is even or to the right if N is odd. For example at N=0 draw up to N=1 and the Fibonacci word at N=0 is 0 and N even so change direction to the right (for the N=1 to N=2 segment).
N Fibonacci word --- -------------- 0 0 turn right 1 1 2 0 turn right 3 0 turn left 4 1 5 0 turn left 6 1
The result is self-similar blocks within the first quadrant (X>=0,Y>=0). New blocks extend from N values which are Fibonacci numbers. For example at N=21 begins a new block above, then N=34 a new block across, N=55 down, N=89 across again, etc.
The new blocks are a copy of the shape starting N=0, rotated and/or transposed according to the replication level mod 6,
level mod 6 new block ----------- --------- 0 transpose 1 rotate -90 2 transpose, rotate -90 3 transpose 4 rotate +90 5 transpose, rotate +90
The Fibonacci word sequence itself is in Sloane's OEIS as A003849, and A156596 is the odd/even 0s turned into turns 1 or 2 to give the turn sequence directly
http://oeis.org/A156596 A156596 - turn sequence, 0=straight, 1=right, 2=left A003849 - Fibonacci word sequence 0,1
See "FUNCTIONS" in Math::PlanePath for the behaviour common to all path classes.
$path = Math::PlanePath::FibonacciWordFractal->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 0 and if $n < 0 then the return is an empty list.
$n
$n < 0
Fractional positions give an X,Y position along a straight line between the integer positions.
$n = $path->xy_to_n ($x,$y)
Return the point number for coordinates $x,$y. If there's nothing at $x,$y then return undef.
$x,$y
undef
The curve visits an $x,$y twice for various points (all the "inside" points). In the current code the smaller of the two N values is returned. Is that the best way?
$n = $path->n_start()
Return 0, the first N in the path.
Math::PlanePath, Math::PlanePath::DragonCurve
Alexis Monnerot-Dumaine "The Fibonacci Word Fractal", February 2009
http://hal.archives-ouvertes.fr/hal-00367972_v1/ http://hal.archives-ouvertes.fr/docs/00/36/79/72/PDF/The_Fibonacci_word_fractal.pdf
Math::NumSeq::FibonacciWord
http://user42.tuxfamily.org/math-planepath/index.html
Copyright 2010, 2011 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.