How to resolve the algorithm Fibonacci word/fractal step by step in the zkl programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Fibonacci word/fractal step by step in the zkl programming language

Table of Contents

Problem Statement

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

Create and display a fractal similar to Fig 1. (Clicking on the above website   (hal.archives-ouvertes.fr)   will leave a cookie.)

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Fibonacci word/fractal step by step in the zkl programming language

Source code in the zkl programming language

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"));

  

You may also check:How to resolve the algorithm Leap year step by step in the Lua programming language
You may also check:How to resolve the algorithm Comma quibbling step by step in the CoffeeScript programming language
You may also check:How to resolve the algorithm Parsing/RPN calculator algorithm step by step in the Prolog programming language
You may also check:How to resolve the algorithm Trabb Pardo–Knuth algorithm step by step in the Fortran programming language
You may also check:How to resolve the algorithm Gauss-Jordan matrix inversion step by step in the M2000 Interpreter programming language