Rusty-Systems

A rust library for procedurally generating content using L-System grammars.

What's this about?

This crate currently supports producing strings using context-free and stochastic L-Systems. L-Systems are a grammar-based method that can be used for procedurally generating content.

rusty-systems is written in rust and is thread safe.

Installing

The library is available via ๐Ÿฆ€ crates.io. You can install it using cargo

cargo add rusty-systems

Examples

Using the following two rules we can create a simple plant:

start: X

F โ†’ F F
X โ†’ F + [ [ X ] - X ] - F [ - F X ] + X

X is the token from which we grow our plant. You may think of it as being short for apex.

F represents forward movement or growth. The first rule, then says that every iteration of the L-System grammars

A black-and-white generated line-image of a plant
6 iterations of the plant rules

The second rule, which matches the token X, gives a scaffolding for the shape of the plant. the + and - tokens effect the angle of growth of a branch, while the [ and ] tokens define branches.

When interpreted as instructions to draw lines, this plant image is produced. One of the provided example applications uses the tiny-skia graphics library to interpret the above L-system grammar to produce a png.

You can run this example using:

# Install the source
git clone https://github.com/TheRiver/rusty-systems.git
cd rusty-systems

# Run the example
cargo run --example skia-plant

# output image saved to target/skia-plant.png
Running example code

The command will create a file named skia_plant.png in the target directory.

If you would like to know more about the turtle interpretation, see ยง1.3 (pg 6) of the Algorithmic Beauty of Plants. The rules are taken from the plant presented in figure 1.24f, from the same book.

The lsystem command line tool

rusty-systems also provides an optional command line interface called lsystem. It produces svg output from plant grammars.

Find out more

The rusty-systems crate has documentation and examples showing how to use it. See docs.rs.

An important book which developed L-Systems is The Algorithmic Beauty of Plants, by Prusinkiewicz and Lindenmayer, and is available for free online. This is a good place to read more about L-Systems and see many examples on how to use them.

The source code is available on GitHub, and is licensed under the MIT license.