Eser Aygün

Home Page

Computer

Music

Photos

eseraygun.com

E-mail Address

login

09.02.2012 · Print · History · Edit

L-system Fractal Generator for js1k

For general information on Lindenmayer systems, please see the related Wikipedia article.

The script that I wrote for js1k contest generates given L-system code on the screen. It supports turning (+ and ), drawing (F and G) and push/pop ([ and ]) operators.

An L-system code consists of the following lines.

iters: n
The number of iterations. The more iterations performed, the more detail is achieved and the more time is spent.
angle: Θ
The turning angle in degrees. For example, 60 or 90.
start: "S"
The initial axiom. The computation starts with string S.
X: "Y"
A rewriting rule. In each iteration all Xs in the current string is substituted with Ys.

Examples

Right-angled Koch Curve from Wikipedia

iters: 4
angle: 90
start: "F"
F: "F+F−F−F+F"

Right-angled Koch curve from Wikipedia

iters: 4
angle: 90
start: "F"
F: "F+F−F−F+F"

Sierpinski triangle from Wikipedia

iters: 8
angle: 60
start: "F"
F: "G-F-G"
G: "F+G+F"