L-System or Lindenmayer System is a type of formal grammar. Each L-System consists of a set of alphabets that can be used to make string. L-System provides a production rule for a set of symbols that can be used to make the current string an even larger string. To start the string, it provides an axiom or an initial string which can be later expanded using the production rules. Each step of the string can be treated as a generation where the axiom is part of generation 1. L-Systems can also be used to generate fractals. They were first developed in 1968 by Aristid Lindenmayer.
L-Systems can be used to generate many different patterns. By using the string and the alphabets as rules, a huge possibility of doors open. As the generations go on increasing, L-System allows to have more detail in each generation.
We can define each alphabet with a given rule, let’s see the different rules:
- F or G := Draw forward.
- A or B := Move forward.
- + := Turn left by angle.
- - := Turn right by angle.
- [ := Push position.
- ] := Pop position.
Try it out here!
- Angle: 22.5°
- Axiom: X
- Rules: (F→FF),(X→F[+X][-X]FX)
- Angle: 45°
- Axiom: X
- Rules: (F→FF),(X→F[-X]+X)
- Angle: 25°
- Axiom: X
- Rules: (F→FF),(X→F+[[X]-X]-F[-FX]+X)
- Angle: 25°
- Axiom: X
- Rules: (F→FF),(X→F[-X]F[-X]+X)
- Angle: 25°
- Axiom: F
- Rules: (F→F[+F]F[-F]F)
- Angle: -120°
- Axiom: F-G-G
- Rules: (F→F-G+F+G-F),(G→GG)
- Angle: 90°
- Axiom: FX
- Rules: (X→X+YF+),(Y→-FX-Y)
- Angle: 90°
- Axiom: F
- Rules: (F→F+F-F-F+F)
- Angle: 60°
- Axiom: F++F++F
- Rules: (F→F-F++F-F)
- Angle: 60°
- Axiom: F
- Rules: (F→F-G--G+F++FF+G-),(G→+F-GG--G-F++F+G)
- Angle: -90°
- Axiom: X
- Rules: (X→-YF+XFX+FY-),(Y→+XF-YFY-FX+)
- Angle: 90°
- Axiom: LFL+F+LFL
- Rules: (L→-RF+LFL+FR-),(R→+LF-RFR-FL+)
- Angle: 45°
- Axiom: F
- Rules: (F→+F--F+)