Skip to content

sameer/lsys

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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