Simple implementation of L-Systems in Lua, with examples in LÖVE2D.
- Lua >= 5.1 (?)
- LÖVE2D (for the example project)
Running the example project
love example
Either with git clone as below or by downloading a zipball of the latest...
git clone https://github.com/Profan/lovely-systems.git
When testing the example, use your arrow keys to change scale and segment size.
Example of defining a sierpinski triangle, example also already present in example code.
local lsystem = require "l-system"
initial_state = {state = {'F'}, rules = {['F'] = 'G-F-G', ['G'] = 'F+G+F'} }
fractal = lsystem.nthstep(initial_state, 2) -- recurses twice
-- fractal.state now holds: F+G+F-G-F-G-F+G+F, in table form.
which in turn can be used to produce:
or by increasing the iterations to 8, you can produce:
another example, a christmas tree! (sort of)
- ... write tests?
Credits for the libraries which are used in the example!
- Matthias Richter - HUMP.
See attached LICENSE file.