Generate and draw L-systems
Find a file
2018-02-01 22:13:08 +00:00
app Read filename from commandline argument 2018-01-17 22:27:14 +00:00
examples Add example: lakes and islands 2018-02-01 22:13:08 +00:00
img Update README 2018-01-17 11:51:38 +00:00
src Add new instruction: draw forward without drawing a line 2018-02-01 22:05:45 +00:00
test Add support for push ('[') and pop (']') operations 2018-01-17 10:54:44 +00:00
.gitignore Hide Emacs configuration files 2018-01-15 23:24:52 +00:00
.travis.yml Add Travis CI 2018-01-15 18:59:35 +00:00
LICENSE Initial commit 2018-01-15 18:47:54 +00:00
package.yaml Parse JSON file for L-system input 2018-01-17 22:18:01 +00:00
README.org Update README for JSON inputs 2018-01-17 22:36:15 +00:00
Setup.hs Initial commit 2018-01-15 18:47:54 +00:00
stack.yaml Initial commit 2018-01-15 18:47:54 +00:00

L-Systems

https://travis-ci.org/dlozeve/lsystems.svg?branch=master https://img.shields.io/badge/License-BSD

Generate and draw L-systems!

/dimitri/lsystems/media/commit/e6b5ddb0930d811ff68d501fa6a40ac6c28e1ac0/img/demo.png

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 Stack.

From the repository, run:

stack build
stack exec lsystems-exe -- examples/penroseP3.json

This will open a window, where you can move around using the mouse and zoom by scrolling.

For tests and documentation, run:

stack test --haddock

You can choose the L-system and the number of iteration via command-line arguments, see the output of --help:

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

Examples

Examples are provided in the examples/ directory.

Space-filling curves

Fractals

Implementation

The program is implemented in Haskell, using Gloss to display the generated L-systems.