This project is capable of generating L-systems. More specifically, it generates deterministic, context-free L-systems (D0L-systems) that produce only connected curves. Generating line segment coordinates is done by means of turtle graphics. Finally, the line segments are efficiently rendered in 3D using Three.js, which also provides convenient 3D pan, zoom and rotation controls for the scene.
npm install; npm run dev
Five turtle actions exist on symbols of the axiom:
A, B, C
: move forward while drawing a line
+
: rotate left
-
: rotate right
[
: push turtle on stack
]
: pop turtle from stack
And, for completeness, implicit no-op:
(any)
: no action
Assume the following setup:
axiom = "A";
grammar = {"A": "A+B", "B": "A-B"};
Let's call lSystem.iterateN(3)
. The system will produce the following intermediate axioms by successively applying the production rules of the grammar to all characters of the axiom:
"A"
"A+B"
"A+B+A-B"
"A+B+A-B+A+B-A-B"
This system (and most other systems) will grow exponentially. Setting the number of iterations too high will crash your browser.
- Show all iterations stacked
- Build web interface for user input
- Parse user input
- Show L-system presets