Enter derivation rules
A derivation rule maps single characters to output strings
The starting string is called w
. You must have exactly one derivation rule for w
This is very similar to yesterday's L-System
Fractal Generator except this version introduces bracket operators to
save and restore state. It also uses :
for defining derivation
rules rather than ->
because it is easier to type.
Samples
Example
w: F
F: F+F
On the first iteration, we look up the rule for w
. The output string is F
On the second iteration, we replace every F
in the input string with F+F
. The output string is F+F
On the third iteration, we replace every F
in the input string with F+F
. The output string is F+F+F+F
And so on...
After running n
iterations, the output string is used as drawing instructions. The pen starts at the origin aiming north.
Uppercase letter
: draw a line one unit in the current direction+
: rotatea
degrees counterclockwise-
: rotatea
degrees clockwiseLowercase letter
: move one unit in the current direction without drawing a line[
: save the current location and direction]
: restore location and direction- Any other characters are ignored
Further reading: Chapter 1.6 of The Algorithmic Beauty of Plants