# L-systems

An L-system, short for Lindermayer system, consists of a set of rules created from an alphabet. The alphabet can vary but for this page the alphabet will be

1. F  from current position, draw a segment of length 1 in direction angle
2. f  from current position, move length 1 in direction angle
3. +  from current position, rotate left angle degrees
4. -  from current position, rotate right angle degrees
5. [  put the current position on the stack
6. ]  make the current position the last position on the stack

From this small alphabet of 6 symbols lots of complicated figures can be created by defining a set of rules. You'll need to choose an angle (eg 90 degrees) and define an axiom (the starting iteration). After that you'll need to define two replacement rules, one for F and the other for f. Each F in the axiom is replaced by the string of characters in the replacement rule for F. Likewise each f in the axiom is replaced by the string of characters in the replacement rule for f. For example, an angle of 90 degrees and an axiom of F-F-F-F creates a square because you've gone Forward for 1 unit, turned right 90 degrees, gone Forward another unit, turned right 90 degrees, gone Forward 1 unit, turned 90 degrees and moved Forward 1 unit. Subsequent iterations rely on replacement rules that govern what each symbol (F or f) is replaced with.

Here's a nice page on creating L-systems using Inkscape. Another page on using Inkscape is here and I found this page was useful as well. This web page has examples made using a bigger alphabet and more rules.

Teaching point: Repeating simple rules can create complicated structures.

Here are a variety of L-systems along with the rules to create them.

1. Axiom: F-F-F-F-F
2. F->FF-F-F-F-F-FF
3. No rule needed: the rule f->fff is never implemented since the f isn't in the axiom or the replacement rule for F
4. angle: 72 degrees

The Koch snowflake is constructed by these rules:

1. Axiom: F--F--F
2. F->F+F--F+F
3. No rule needed: the rule f->fff is never implemented since the f isn't in the axiom or the replacement rule for F
4. angle: 60 degrees

Created by the rules:

1. Axiom: F++F++F
2. F->F+F-F-F+F
3. No rule needed: the rule f->fff is never implemented since the f isn't in the axiom or the replacement rule for F
4. angle: 60 degrees

Sierpinski's triangle is created by the rules:

1. Axiom: F+F+F
2. F->F+F-F-F+F
3. No rule needed: the rule f->fff is never implemented since the f isn't in the axiom or the replacement rule for F
4. angle: 120 degrees

L-systems can be used to model plants, too. Perhaps real plant growth is governed by simple rules as well?

1. Axiom: FF+[F]FF
2. F->FF-[-F+F]+[+F-F]
3. No rule needed: the rule f->fff is never implemented since the f isn't in the axiom or the replacement rule for F
4. angle: 17 degrees

Here's an example where the second replacement rule is used.

1. Axiom: FF--FF--FF--FF
2. F-> fF-F-F-F-Ff
3. f-> F[f--FF]fF+F
4. angle: 45 degrees