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

; Return the low 1-bits of :n
; For example if n = binary 10110111 = 183
;        then return binary      111 = 7
to low.ones :n
  output ashift (bitxor :n (:n+1)) -1
end
 
; :fibbinary should be a fibbinary value
; return the next larger fibbinary value
to fibbinary.next :fibbinary
  localmake "filled  bitor :fibbinary (ashift :fibbinary -1)
  localmake "mask    low.ones :filled
  output (bitor :fibbinary :mask) + 1
end
 
to fibonacci.word.fractal :steps
  localmake "step.length 5  ; length of each step
  localmake "fibbinary 0
  repeat :steps [
    forward :step.length
    if (bitand 1 :fibbinary) = 0 [
      ifelse (bitand repcount 1) = 1 [right 90] [left 90]
    ]
    make "fibbinary  fibbinary.next :fibbinary
  ]
end
 
setheading 0    ; initial line North
fibonacci.word.fractal 377