
The Fibonacci word may be represented as a fractal as described here:


(Clicking on the above website   (hal.archives-ouvertes.fr)    will leave a cookie.)



For F_wordm start with F_wordCharn=1
Draw a segment forward
If current F_wordChar is 0
Turn left if n is even
Turn right if n is odd
next n and iterate until end of F_word


Task

Create and display a fractal similar to Fig 1.


(Clicking on the above website   (hal.archives-ouvertes.fr)    will leave a cookie.)

 
\\ Fibonacci word/fractals
\\ 4/25/16 aev
fibword(n)={
my(f1="1",f2="0",fw,fwn,n2);
if(n<=4, n=5);n2=n-2;
for(i=1,n2, fw=Str(f2,f1); f1=f2;f2=fw;); fwn=#fw;
fw=Vecsmall(fw);
for(i=1,fwn,fw[i]-=48);
return(fw);
}
 
nextdir(n,d)={
my(dir=-1);
if(d==0, if(n%2==0, dir=0,dir=1)); \\0-left,1-right
return(dir);
}
 
plotfibofract(n,sz,len)={
my(fwv,fn,dr,px=10,py=420,x=0,y=-len,g2=0,
   ttl="Fibonacci word/fractal: n=");
plotinit(0); plotcolor(0,6); \\green 
plotscale(0, -sz,sz, -sz,sz);
plotmove(0, px,py);
fwv=fibword(n); fn=#fwv;
for(i=1,fn, 
    plotrline(0,x,y);
    dr=nextdir(i,fwv[i]);
    if(dr==-1, next);
    \\up
    if(g2==0, y=0; if(dr, x=len;g2=1, x=-len;g2=3); next);
    \\right
    if(g2==1, x=0; if(dr, y=len;g2=2, y=-len;g2=0); next);
    \\down
    if(g2==2, y=0; if(dr, x=-len;g2=3, x=len;g2=1); next);
    \\left
    if(g2==3, x=0; if(dr, y=-len;g2=0, y=len;g2=2); next);
   );\\fend i 
plotdraw([0,-sz,-sz]);
print(" *** ",ttl,n," sz=",sz," len=",len," fw-len=",fn);
 
}
 
{\\ Executing:
plotfibofract(11,430,20); \\ Fibofrac1.png
plotfibofract(21,430,2);  \\ Fibofrac2.png
}
 