2 unstable releases

0.3.1 Aug 18, 2024
0.2.0 Aug 7, 2024

#2 in #lsystem

Download history 17/week @ 2024-12-08 5/week @ 2024-12-15

54 downloads per month

MIT license

150KB
439 lines

L-systems in Rust

Render L-systems as SVGs using Rust and Cairo.

Some useful resources on getting started:

Usage

This tool has a command line interface:

Visualize 2D L-Systems with SVGs.

Usage: lsys [OPTIONS] --width <WIDTH> --height <HEIGHT> <AXIOM> <VARIABLES_TO_DRAW> <ANGLE> <ITERATIONS> [RULES]...

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

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

To draw four iterations of the 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.

Sierpinski Triangle

sierpinski

Sierpinski Arrowhead

arrowhead

Koch Curve

koch

Dragon Curve

dragon

Fractal Plant

plant

Moore Curve

moore

Hilbert Curve

hilbert

Sierpinski Carpet

sierpinski_capret

Koch Snowflake

snowflake

Hexagonal Gosper

gosper

Kolam

kolam

Crystal

crystal


lib.rs:

A crate for visualizing 2D L-systems with SVGs.

Dependencies

~9.5MB
~188K SLoC