The Fibonacci word is a sequence of binary strings defined as:
- \$F_0 = \$
0
- \$F_1 = \$
01
- \$F_n = F_{n-1} F_{n-2}\$
The first few Fibonacci words are:
0
01
010
01001
01001010
0100101001001
010010100100101001010
...
Each of these strings is a prefix of the next, so they are all prefixes of the single infinite word \$F_\infty\$ =
010010100100101001010010010100100101001010010010100101001001010010010100101001001010010010100101001...
(The definition above is borrowed from this sandbox challenge by pxeger.)
Now we can define a fractal curve based on the Fibonacci words.
Starting from some point on the plane, for each digit at position \$k\$ of the Fibonacci word \$F_\infty\$:
- Draw a segment with length \$1\$ forward,
- If the digit is \$0\$:
- Turn 90° to the left if \$k\$ is even,
- Turn 90° to the right if \$k\$ is odd.
This is called the Fibonacci word fractal.
For example, the first 21 digits in \$F_\infty\$ are 010010100100101001010
, which would give the following shape:
┌
│ ┌─┐
└─┘ │
┌┘
│
└┐
┌─┐ │
│ └─┘
To be clearer, let's mark the starting point by ^
, and replace the other chars by its corresponding digit in the Fibonacci word:
0
1 010
010 1
00
1
00
010 1
^ 010
Here are some more steps of the Fibonacci word fractals, taken from Wikipedia:
Task and rules
Given a non-negative integer \$n\$, draw at least \$n\$ steps of the infinite Fibonacci word fractal.
You may draw more steps than \$n\$. But the extra steps should still belong to the infinite Fibonacci word fractal.
Or alternatively, you may take no input, and draw every step of the infinite Fibonacci word fractal (as an animation, or an infinite sequence of outputs).
You may output as either ascii-art or graphical-output.
For ascii-art, you may choose any characters to draw the curve as long as the output is clear.
The fractal curve consists of a chain of line segments. For each step, you may choose to draw one of the followings, but your choice must be consistent (taking \$n=21\$ as an example):
- the starting point of the segment:
# ###
### #
##
#
##
### #
# ###
- the ending point of the segment:
#
# ###
### #
##
#
##
### #
###
- the whole segment.
#
# ###
### #
##
#
##
### #
# ###
The direction don't need to be consistent. You may arbitrarily rotate or reflect the curve.
This is code-golf, so the shortest code in bytes wins.