For general information on Lindenmayer systems, please see the related Wikipedia article.
The script that I wrote for js1k contest executes given L-system code and generates fractals on the screen. It supports turning (+
and −
), drawing (lowercase letters) and push/pop ([
and ]
) operators.
An L-system code consists of the following lines.
iters:
nangle:
Θstart:
"
S"
:
"
Y"
iters: 5 angle: 45 start: "X" X: "+ff++f++f--f++f++ff" f: "fff[-ffX][+fX]"
iters: 5 angle: 60 start: "f--f--f" f: "f+f--f+f"
iters: 12 angle: 90 start: "fX" X: "X+Yf+" Y: "-fX-Y"
iters: 5 angle: 60 start: "Xf" X: "X+Yf++Yf-fX--fXfX-Yf+" Y: "-fX+YfYf++Yf+fX--fX-Y"
iters: 7 angle: 90 start: "L" L: "-Rf+LfL+fR-" R: "+Lf−RfR−fL+"
iters: 8 angle: 60 start: "f" f: "g-f-g" g: "f+g+f"
iters: 6 angle: 25 start: "+++X" X: "f+[[X]-X]-f[-fX]+X" f: "ff"
iters: 8 angle: 18 start: "+++++X" X: "f[+X]f[-X]+X" f: "ff"
iters: 4 angle: 22.5 start: "++++f" f: "ff-[-f+f+f]+[+f-f-f]"
iters: 6 angle: 90 start: "x-ff-x" x: "xf+fx-ff-xf+fx"