The Computational Beauty of Nature
Source code

lsys

builds an L-system fractal from multiple rules

Full screen →

lsys -help
  or
lsys   [-width  integer]  [-height integer] [-border inte-
       ger] [-depth integer]  [-a0  double]  [-da  double]
       [-ds  double] [-unoise double] [-rule ... ] [-axiom
       string] [-inv] [-mag integer] [-term string]

Builds L-system fractals. Accepts multiple rules so that complicated fractals (such as a Penrose tiling) can be expressed. Great for generating plantlike fractals.

An L-system is computed according to the specified axiom, rules, and step angle. The L-system axiom is recursively expanded for the specified depth, with 'F', 'G', and '|' actions resulting in movement of the virtual plotter, and '+' and '-' commands resulting in rotation of the virtual plotter. See the RULES section of the manual page for more information on the format for legal rules.

Rules

The L-system rules should always take the form "x=..." where "x" is a letter and the remaining portion is a sequence of turtle graphics commands, which operate as described below.

'F' is the draw forward command, which moves the plotter forward by a fixed length, drawing a line from the old position to the new position.

'G' (Go Forward) is similar to 'F', but only moves the plotter and does not draw a line.

'+' and '-' turn the plotter to the right (or left) by a fixed angle determined by the -da switch. If an integer precedes the '+' or '-' symbol, then the plotter effectively makes that number of right-hand turns.

'[' saves the current position and angle of the plotter for later use, which is restored by the ']' command.

'|' move the turtle forward by a length computed from the execution depth, drawing a line from the old position to the new. Thus, this command is similar to 'F' but it is not recursively expanded. If DS is the value supplied by the -ds switch, then the step size will be proportional to DS^depth. This allows for certain types of figures to be drawn that would otherwise be difficult to express without this command.

Miscellany

If you are using a UNIX command shell, be sure to quote any rules with brackets so that the shell passes them to the program correctly.

Bugs

No sanity checks are performed to make sure that any of the options make sense.

The border size is only approximately calculated because the author felt a bit lazy at the time of writing this program. However, it's pretty close for most values.

Options

-widthWidth of the plot in pixels.480
-heightHeight of the plot in pixels.480
-borderApproximate number of border pixels.10
-depthRecursion depth to use.5
-a0Initial angle.90.0
-daDelta angle for '+' and '-' commands.90.0
-dsDelta step size. Only affects '|' commands and should be less than 1.1.0
-unoiseAmount of uniform noise to add to step angle.0.0
-ruleSpecify a production rule. See RULES section of manual page.None
-axiomStarting axiom.f
-invInvert all colors?False
-magMagnification factor.1
-termHow to plot points.None

Examples

lsys -da 20 -rule "F=|[-F]|[+F][-F]F"
lsys -da 60 -rule F=F-F++F-F
lsys -da 18 -axiom F4-F4-F4-F4-F -rule F=F4-F4-F10-F++F4-F
lsys -da 60 -rule "F=[-G+++F][-G+F][GG--F]" -rule G=GG

lsys.c on GitHub