
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.)

fcn drawFibonacci(img,x,y,word){ // word is "01001010...", 75025 characters
   dx:=0; dy:=1; // turtle direction
   foreach i,c in ([1..].zip(word)){ // Walker.zip(list)-->Walker of zipped list
      a:=x; b:=y; x+=dx; y+=dy;
      img.line(a,b, x,y, 0x00ff00);
      if (c=="0"){
         dxy:=dx+dy;
	 if(i.isEven){ dx=(dx - dxy)%2; dy=(dxy - dy)%2; }// turn left
	 else 	     { dx=(dxy - dx)%2; dy=(dy - dxy)%2; }// turn right
      }
   }
}
 
img:=PPM(1050,1050);
fibWord:=L("1","0"); do(23){ fibWord.append(fibWord[-1] + fibWord[-2]); }
drawFibonacci(img,20,20,fibWord[-1]);
img.write(File("foo.ppm","wb"));