* L-Systems [[https://travis-ci.org/dlozeve/lsystems][https://travis-ci.org/dlozeve/lsystems.svg?branch=master]] [[https://opensource.org/licenses/BSD-3-Clause][https://img.shields.io/badge/License-BSD%203--Clause-blue.svg]] Generate and draw [[https://en.wikipedia.org/wiki/L-system][L-systems]]! [[./img/demo.png]] Check the [[https://www.lozeve.com/post/lsystems/][accompanying blog post.]] ** Introduction This program can be used to generate arbitrary L-systems. It supports: + full rewriting rules + full representation rules + personalized angle and segment length for the representation + push ('[') and pop (']') operations ** L-systems *** ~LSystem~ data type An L-system consists of: + the L-system itself: + an alphabet + an axiom (i.e. the starting point) + a set of rewriting rules (represented as a list of tuples) + rules to transform it into a graphical representation: + an angle and a length + a set of representation rules (which symbols mean "draw forward", "turn left", "pop a position", etc.) *** JSON format for L-systems L-systems can be specified using a straightforward JSON encoding. See the =examples/= folder for examples. Note that the ~rules~ and ~representation~ keys are associated to arrays of arrays in JSON. ~angle~ and ~distance~ are numbers. Everything else should be a string. ** Building and running You will need [[https://docs.haskellstack.org/][Stack]]. From the repository, run: #+BEGIN_SRC sh stack build stack exec lsystems-exe -- examples/penroseP3.json #+END_SRC This will open a window, where you can move around using the mouse and zoom by scrolling. For tests and documentation, run: #+BEGIN_SRC sh stack test --haddock #+END_SRC You can choose the L-system and the number of iteration via command-line arguments, see the output of ~--help~: #+BEGIN_SRC lsystems -- Generate L-systems Usage: lsystems-exe FILENAME [-n|--iterations N] [-c|--color R,G,B] [-w|--white-background] Generate and draw an L-system Available options: FILENAME JSON file specifying an L-system -n,--iterations N Number of iterations (default: 5) -c,--color R,G,B Foreground color RGBA (0-255) (default: RGBA 1.0 1.0 1.0 1.0) -w,--white-background Use a white background -h,--help Show this help text #+END_SRC ** Examples Examples are provided in the =examples/= directory. *** Space-filling curves + [[https://en.wikipedia.org/wiki/Hilbert_curve][Hilbert curve]] + [[https://en.wikipedia.org/wiki/Gosper_curve][Gosper curve]] *** Fractals + [[https://en.wikipedia.org/wiki/L%C3%A9vy_C_curve][Lévy C curve]] + [[https://en.wikipedia.org/wiki/Koch_snowflake][Koch snowflake]] and Koch curve + [[https://en.wikipedia.org/wiki/Sierpinski_triangle][Sierpinski triangle]] and Sierpinski arrow curve + [[https://en.wikipedia.org/wiki/Dragon_curve][Dragon curve]] + Binary tree and fractal plant *** Tilings + [[https://en.wikipedia.org/wiki/Penrose_tiling#Rhombus_tiling_(P3)][Penrose P3 tiling]] ** Implementation The program is implemented in Haskell, using [[https://hackage.haskell.org/package/gloss][Gloss]] to display the generated L-systems.