An open API service indexing awesome lists of open source software.

https://github.com/sameer/lsys

L-systems in Rust
https://github.com/sameer/lsys

Last synced: 2 months ago
JSON representation

L-systems in Rust

Awesome Lists containing this project

README

          

# L-systems in Rust

Render [L-systems](https://en.wikipedia.org/wiki/L-system) as [SVGs](https://en.wikipedia.org/wiki/SVG) using [Rust](https://www.rust-lang.org/) and [Cairo](https://www.cairographics.org/).

Some useful resources on getting started:

- https://en.wikipedia.org/wiki/L-system
- https://fedimser.github.io/l-systems.html
- https://paulbourke.net/fractals/lsys/

## Usage

This tool has a command line interface:

```
Visualize 2D L-Systems with SVGs.

Usage: lsys [OPTIONS] --width --height [RULES]...

Arguments:
Initial string
Variables that should be treated as a stroke and drawn
Turn angle in degrees
Number of times the rules will run
[RULES]... Rules for replacing characters with a new string (i.e. "F=>F+F")

Options:
--width Width of the SVG Canvas in millimeters
--height Height of the SVG Canvas in millimeters
-o, --out Path to write the SVG to
-h, --help Print help
-V, --version Print version
```

To draw four iterations of the [Koch snowflake](https://en.wikipedia.org/wiki/Koch_snowflake) on a 100mm x 100m SVG:

```
cargo run --release -- --width 100 --height 100 'F++F++F' 'F' 60 4 'F=>F-F++F-F' -o out.svg
```

## Examples

Many of the systems below come from [Paul Bourke's site](http://paulbourke.net/fractals/lsys/).

### Sierpinski Triangle
![sierpinski](tests/sierpinski.svg)

### Sierpinski Arrowhead
![arrowhead](tests/arrowhead.svg)

### Koch Curve
![koch](tests/koch.svg)

### Dragon Curve
![dragon](tests/dragon.svg)

### Fractal Plant
![plant](tests/plant.svg)

### Moore Curve
![moore](tests/moore.svg)

### Hilbert Curve
![hilbert](tests/hilbert.svg)

### Sierpinski Carpet
![sierpinski_capret](tests/sierpinski_carpet.svg)

### Koch Snowflake
![snowflake](tests/snowflake.svg)

### Hexagonal Gosper
![gosper](tests/gosper.svg)

### Kolam
![kolam](tests/kolam.svg)

### Crystal
![crystal](tests/crystal.svg)