This is a Python implementation of L-systems.
The following is a gallery of various mathematical objects that can be described by an L-system.
- Algae
- Thue-Morse sequence
- Fractal binary tree
- Cantor set
- Koch curves
- Sierpiński triangles
- Sierpiński carpet
- Sierpiński curves
- Dragon curves
- Fractal plant
- Hilbert curve
- Peano curve
- Gosper curves
- Penrose tiling (P3)
- Pentigrees
- variables:
A
,B
- constants: none
- axiom:
A
- rules:
A→AB
,B→A
n = 0: A
n = 1: AB
n = 2: ABA
n = 3: ABAAB
n = 4: ABAABABA
n = 5: ABAABABAABAAB
n = 6: ABAABABAABAABABAABABA
n = 7: ABAABABAABAABABAABABAABAABABAABAAB
- variables:
0
,1
- constants: none
- axiom:
0
- rules:
0→01
,1→10
n = 0: 0
n = 1: 01
n = 2: 0110
n = 3: 01101001
n = 4: 0110100110010110
n = 5: 01101001100101101001011001101001
n = 6: 0110100110010110100101100110100110010110011010010110100110010110
- variables:
0
,1
- constants:
[
,]
- axiom:
0
- rules:
1→11
,0→1[0]0
0
: go forward with drawing a green line segment1
: go forward with drawing a brown line segment[
: push the current pose on the stack, turn 45° to the left[
: pop a pose from the stack, turn 45° to the right
- variables:
F
,f
- constants: none
- axiom:
F
- rules:
F→FfF
,f→fff
F
: go forward with drawing a line segmentf
: go forward without drawing
- variables:
F
- constants:
+
,-
- axiom:
F--F--F
- rules:
F→F+F--F+F
F
: go forward with drawing a line segment+
: turn 60° to the left-
: turn 60° to the right
- variables:
F
- constants:
+
,-
- axiom:
F
- rules:
F→F+F-F-F+F
F
: go forward with drawing a line segment+
: turn 90° to the left-
: turn 90° to the right
- variables:
F
- constants:
+
,-
- axiom:
F
- rules:
F→F+F-F-FF+F+F-F
F
: go forward with drawing a line segment+
: turn 90° to the left-
: turn 90° to the right
- variables:
F
,G
- constants:
+
,-
- axiom:
F-G-G
- rules:
F→F-G+F+G-F
,G→GG
F
: go forward with drawing a red line segmentG
: go forward with drawing a yellow line segment+
: turn 120° to the left-
: turn 120° to the right
- variables:
F
,G
- constants:
+
,-
- axiom:
F
- rules:
F→G-F-G
,G→F+G+F
F
: go forward with drawing a red line segmentG
: go forward with drawing a blue line segment+
: turn 60° to the left-
: turn 60° to the right
- variables:
F
,f
,X
- constants:
+
,-
- axiom:
F+F+F+F+X
- rules:
F→FFF
,f→fff
,X→XfXfX+fF++ff-f-fF++ff-f-f-XfFX++ff-f-XfXFX++ff+ff+
F
: go forward with drawing a line segmentf
: go forward without drawingX
: point a blue dot+
: turn 120° to the left-
: turn 120° to the right
- variables:
X
- constants:
F
,+
,-
- axiom:
F--XF--F--XF
- rules:
X→XF+G+XF--F--XF+G+X
X
: do nothingF
: go forward with drawing an orange line segmentG
: go forward with drawing a brown line segment+
: turn 45° to the left-
: turn 45° to the right
- variables:
X
- constants:
F
,+
,-
- axiom:
F+XF+F+XF
- rules:
X→XF-F+F-XF+F+XF-F+F-X
X
: do nothingF
: go forward with drawing a line segment+
: turn 90° to the left-
: turn 90° to the right
- variables:
F
,G
- constants:
+
,-
- axiom:
F
- rules:
F→F+G
,G→F-G
F
: go forward with drawing a red line segmentG
: go forward with drawing a green line segment+
: turn 90° to the left-
: turn 90° to the right
- variables:
F
,G
,X
,Y
- constants:
+
,-
- axiom:
F+G+X+Y
- rules:
F→F+G
,G→F-G
,X→X+Y
,Y→X-Y
F
: go forward with drawing a red line segmentG
: go forward with drawing a red line segmentX
: go forward with drawing a blue line segmentY
: go forward with drawing a blue line segment+
: turn 90° to the left-
: turn 90° to the right
- variables:
F
,G
,H
- constants:
+
,-
- axiom:
F+G-H
- rules:
F→F+F-F
,G→G+G-G
,H→H+H-H
F
: go forward with drawing a red line segmentG
: go forward with drawing a green line segmentH
: go forward with drawing a blue line segment+
: turn 120° to the left-
: turn 120° to the right
- variables:
F
- constants:
+
,-
- axiom:
F
- rules:
F→+F--F+
F
: go forward with drawing a line segment+
: turn 45° to the left-
: turn 45° to the right
- variables:
F
,X
- constants:
+
,-
,[
,]
- axiom:
X
- rules:
F→FF
,X→F+[[X]-X]-F[-FX]+X
F
: go forward with drawing a line segmentX
: do nothing+
: turn 25° to the left-
: turn 25° to the right[
: push the current pose on the stack]
: pop a pose from the stack
- variables:
X
,Y
- constants:
F
,+
,-
- axiom:
X
- rules:
X→+YF-XFX-FY+
,Y→-XF+YFY+FX-
F
: go forward with drawing a line segmentX
: do nothingY
: do nothing+
: turn 90° to the left-
: turn 90° to the right
- variables:
X
,Y
- constants:
F
,+
,-
- axiom:
X
- rules:
X→XFYFX-F-YFXFY+F+XFYFX
,Y→YFXFY+F+XFYFX-F-YFXFY
F
: go forward with drawing a line segmentX
: do nothingY
: do nothing+
: turn 90° to the left-
: turn 90° to the right
- variables:
F
,G
- constants:
+
,-
- axiom:
F
- rules:
F→F-G--G+F++FF+G-
,G→+F-GG--G-F++F+G
F
: go forward with drawing a green line segmentG
: go forward with drawing a blue line segment+
: turn 60° to the left-
: turn 60° to the right
- variables:
F
,G
- constants:
+
,-
- axiom:
G
- rules:
F→FF-G-G+F+F-G-GF+G+FFG-F+G+FF+G-FG-G-F+F+GG-
,G→+FF-G-G+F+FG+F-GG-F-G+FGG-F-GF+F+G-G-F+F+GG
F
: go forward with drawing a green line segmentG
: go forward with drawing a blue line segment+
: turn 90° to the left-
: turn 90° to the right
- variables:
F
,1
,2
,3
,4
- constants:
+
,-
,[
,]
- axiom:
[2]++[2]++[2]++[2]++[2]
- rules:
F→(empty)
1→3F++4F----2F[-3F----1F]++
2→+3F--4F[---1F--2F]+
3→-1F++2F[+++3F++4F]-
4→--3F++++1F[+4F++++2F]--2F
F
: go forward with drawing a line segment1
: do nothing2
: do nothing3
: do nothing4
: do nothing+
: turn 36° to the left-
: turn 36° to the right[
: push the current pose on the stack]
: pop a pose from the stack
- variables:
1
,2
,3
,4
,5
- constants:
+
,-
- axiom:
1++2++3++4++5
- rules:
1→+1++1----1--1++1++1-
2→+2++2----2--2++2++2-
3→+3++3----3--3++3++3-
4→+4++4----4--4++4++4-
5→+5++5----5--5++5++5-
1
: go forward with drawing a red line segment2
: go forward with drawing a yellow line segment3
: go forward with drawing a green line segment4
: go forward with drawing a blue line segment5
: go forward with drawing a purple line segment+
: turn 36° to the left-
: turn 36° to the right
- variables:
1
,2
,3
,4
,5
- constants:
+
,-
- axiom:
1+2+3+4+5
- rules:
1→1+1-1--1+1+1
2→2+2-2--2+2+2
3→3+3-3--3+3+3
4→4+4-4--4+4+4
5→5+5-5--5+5+5
1
: go forward with drawing a red line segment2
: go forward with drawing a yellow line segment3
: go forward with drawing a green line segment4
: go forward with drawing a blue line segment5
: go forward with drawing a purple line segment+
: turn 72° to the left-
: turn 72° to the right
- Przemyslaw Prusinkiewicz and Aristid Lindenmayer. The Algorithmic Beauty of Plants, Springer-Verlag, 1990.
- Lawrence H. Riddle, Classic Iterated Function Systems, https://larryriddle.agnesscott.org/ifs/ifs.htm
- StackExchange - Does there exist an L-system for the sierpiński curve, https://math.stackexchange.com/questions/3393187
- Wikipedia articles
- https://en.wikipedia.org/wiki/L-system
- https://en.wikipedia.org/wiki/Thue%E2%80%93Morse_sequence
- https://en.wikipedia.org/wiki/Koch_snowflake
- https://en.wikipedia.org/wiki/Sierpi%C5%84ski_curve
- https://en.wikipedia.org/wiki/Hilbert_curve
- https://en.wikipedia.org/wiki/Peano_curve
- https://en.wikipedia.org/wiki/Gosper_curve
- https://en.wikipedia.org/wiki/Dragon_curve
- https://es.wikipedia.org/wiki/Teselaci%C3%B3n_de_Penrose