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

 
int n = 18;
String f1 = "1";
String f2 = "0";
String f3;
 
 
void setup(){
  size(600,600);
  background(255);
  translate(10, 10);
  createSeries();
}
 
void createSeries(){
  for(int i=0; i<n; i++){
    f3 = f2+f1;
    f1 = f2;
    f2 = f3;
  }
  drawFractal();
}
 
void drawFractal(){
  char[] a = f3.toCharArray();
  for(int i=0; i<a.length; i++){
    if(a[i]=='0'){
      if(i%2==0){
        rotate(PI/2);
      }
      else{
        rotate(-PI/2);
      }
    }
    line(0,0,2,0);
    translate(2,0);
  }
}
 