Skip to content

Latest commit

 

History

History
564 lines (463 loc) · 26.9 KB

README.md

File metadata and controls

564 lines (463 loc) · 26.9 KB

L-system

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.

Table of Contents

  1. Algae
  2. Thue-Morse sequence
  3. Fractal binary tree
  4. Cantor set
  5. Koch curves
    1. Koch snowflake
    2. Quadratic type 1 curve
    3. Quadratic type 2 curve (aka Minkowski sausage)
  6. Sierpiński triangles
    1. Sierpiński triangle
    2. Sierpiński arrowhead curve
  7. Sierpiński carpet
  8. Sierpiński curves
    1. Sierpiński curve
    2. Sierpiński square curve
  9. Dragon curves
    1. Heighway dragon
    2. Twin dragon
    3. Terdragon
    4. Lévy C curve (aka Lévy dragon)
  10. Fractal plant
  11. Hilbert curve
  12. Peano curve
  13. Gosper curves
    1. Hexagonal Gosper curve
    2. Quadratic Gosper curve
  14. Penrose tiling (P3)
  15. Pentigrees
    1. Pentigree
    2. Pentadendrite

1. Algae

code

L-system

  • variables: A, B
  • constants: none
  • axiom: A
  • rules: A→AB, B→A

Results

n = 0: A
n = 1: AB
n = 2: ABA
n = 3: ABAAB
n = 4: ABAABABA
n = 5: ABAABABAABAAB
n = 6: ABAABABAABAABABAABABA
n = 7: ABAABABAABAABABAABABAABAABABAABAAB

2. Thue-Morse sequence

code

L-system

  • variables: 0, 1
  • constants: none
  • axiom: 0
  • rules: 0→01, 1→10

Results

n = 0: 0
n = 1: 01
n = 2: 0110
n = 3: 01101001
n = 4: 0110100110010110
n = 5: 01101001100101101001011001101001
n = 6: 0110100110010110100101100110100110010110011010010110100110010110

3. Fractal binary tree

code

L-system

  • variables: 0, 1
  • constants: [, ]
  • axiom: 0
  • rules: 1→11, 0→1[0]0

Drawing rules

  • 0: go forward with drawing a green line segment
  • 1: 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

Results

4. Cantor set

code

L-system

  • variables: F, f
  • constants: none
  • axiom: F
  • rules: F→FfF, f→fff

Drawing rules

  • F: go forward with drawing a line segment
  • f: go forward without drawing

Results

5. Koch curves

5-1. Koch snowflake

code

L-system

  • variables: F
  • constants: +, -
  • axiom: F--F--F
  • rules: F→F+F--F+F

Drawing rules

  • F: go forward with drawing a line segment
  • +: turn 60° to the left
  • -: turn 60° to the right

Results

5-2. Quadratic type 1 curve

code

L-system

  • variables: F
  • constants: +, -
  • axiom: F
  • rules: F→F+F-F-F+F

Drawing rules

  • F: go forward with drawing a line segment
  • +: turn 90° to the left
  • -: turn 90° to the right

Results

5-3. Quadratic type 2 curve (aka Minkowski sausage)

code

L-system

  • variables: F
  • constants: +, -
  • axiom: F
  • rules: F→F+F-F-FF+F+F-F

Drawing rules

  • F: go forward with drawing a line segment
  • +: turn 90° to the left
  • -: turn 90° to the right

Results

6. Sierpiński triangles

6-1. Sierpiński triangle

code

L-system

  • variables: F, G
  • constants: +, -
  • axiom: F-G-G
  • rules: F→F-G+F+G-F, G→GG

Drawing rules

  • F: go forward with drawing a red line segment
  • G: go forward with drawing a yellow line segment
  • +: turn 120° to the left
  • -: turn 120° to the right

Results

6-2. Sierpiński arrowhead curve

code

L-system

  • variables: F, G
  • constants: +, -
  • axiom: F
  • rules: F→G-F-G, G→F+G+F

Drawing rules

  • F: go forward with drawing a red line segment
  • G: go forward with drawing a blue line segment
  • +: turn 60° to the left
  • -: turn 60° to the right

Results

7. Sierpiński carpet

code

L-system

  • 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+

Drawing rules

  • F: go forward with drawing a line segment
  • f: go forward without drawing
  • X: point a blue dot
  • +: turn 120° to the left
  • -: turn 120° to the right

Results

8. Sierpiński curves

8-1. Sierpiński curve

code

L-system

  • variables: X
  • constants: F, +, -
  • axiom: F--XF--F--XF
  • rules: X→XF+G+XF--F--XF+G+X

Drawing rules

  • X: do nothing
  • F: go forward with drawing an orange line segment
  • G: go forward with drawing a brown line segment
  • +: turn 45° to the left
  • -: turn 45° to the right

Results

8-2. Sierpiński square curve

code

L-system

  • variables: X
  • constants: F, +, -
  • axiom: F+XF+F+XF
  • rules: X→XF-F+F-XF+F+XF-F+F-X

Drawing rules

  • X: do nothing
  • F: go forward with drawing a line segment
  • +: turn 90° to the left
  • -: turn 90° to the right

Results

9. Dragon curves

9-1. Heighway dragon

code

L-system

  • variables: F, G
  • constants: +, -
  • axiom: F
  • rules: F→F+G, G→F-G

Drawing rules

  • F: go forward with drawing a red line segment
  • G: go forward with drawing a green line segment
  • +: turn 90° to the left
  • -: turn 90° to the right

Results

9-2. Twin dragon

code

L-system

  • variables: F, G, X, Y
  • constants: +, -
  • axiom: F+G+X+Y
  • rules: F→F+G, G→F-G, X→X+Y, Y→X-Y

Drawing rules

  • F: go forward with drawing a red line segment
  • G: go forward with drawing a red line segment
  • X: go forward with drawing a blue line segment
  • Y: go forward with drawing a blue line segment
  • +: turn 90° to the left
  • -: turn 90° to the right

Results

9-3. Terdragon

code

L-system

  • variables: F, G, H
  • constants: +, -
  • axiom: F+G-H
  • rules: F→F+F-F, G→G+G-G, H→H+H-H

Drawing rules

  • F: go forward with drawing a red line segment
  • G: go forward with drawing a green line segment
  • H: go forward with drawing a blue line segment
  • +: turn 120° to the left
  • -: turn 120° to the right

Results

9-4. Lévy C curve (aka Lévy dragon)

code

L-system

  • variables: F
  • constants: +, -
  • axiom: F
  • rules: F→+F--F+

Drawing rules

  • F: go forward with drawing a line segment
  • +: turn 45° to the left
  • -: turn 45° to the right

Results

10. Fractal plant

code

L-system

  • variables: F, X
  • constants: +, -, [, ]
  • axiom: X
  • rules: F→FF, X→F+[[X]-X]-F[-FX]+X

Drawing rules

  • F: go forward with drawing a line segment
  • X: 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

Results

11. Hilbert curve

code

L-system

  • variables: X, Y
  • constants: F, +, -
  • axiom: X
  • rules: X→+YF-XFX-FY+, Y→-XF+YFY+FX-

Drawing rules

  • F: go forward with drawing a line segment
  • X: do nothing
  • Y: do nothing
  • +: turn 90° to the left
  • -: turn 90° to the right

Results

12. Peano curve

code

L-system

  • variables: X, Y
  • constants: F, +, -
  • axiom: X
  • rules: X→XFYFX-F-YFXFY+F+XFYFX, Y→YFXFY+F+XFYFX-F-YFXFY

Drawing rules

  • F: go forward with drawing a line segment
  • X: do nothing
  • Y: do nothing
  • +: turn 90° to the left
  • -: turn 90° to the right

Results

13. Gosper curves

13-1. Hexagonal Gosper curve

code

L-system

  • variables: F, G
  • constants: +, -
  • axiom: F
  • rules: F→F-G--G+F++FF+G-, G→+F-GG--G-F++F+G

Drawing rules

  • F: go forward with drawing a green line segment
  • G: go forward with drawing a blue line segment
  • +: turn 60° to the left
  • -: turn 60° to the right

Results

13-2. Quadratic Gosper curve

code

L-system

  • 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

Drawing rules

  • F: go forward with drawing a green line segment
  • G: go forward with drawing a blue line segment
  • +: turn 90° to the left
  • -: turn 90° to the right

Results

14. Penrose tiling (P3)

code

L-system

  • 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

Drawing rules

  • F: go forward with drawing a line segment
  • 1: do nothing
  • 2: do nothing
  • 3: do nothing
  • 4: 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

Results

15. Pentigrees

15-1. Pentigree

code

L-system

  • 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-

Drawing rules

  • 1: go forward with drawing a red line segment
  • 2: go forward with drawing a yellow line segment
  • 3: go forward with drawing a green line segment
  • 4: go forward with drawing a blue line segment
  • 5: go forward with drawing a purple line segment
  • +: turn 36° to the left
  • -: turn 36° to the right

Results

15-2. Pentadendrite

code

L-system

  • 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

Drawing rules

  • 1: go forward with drawing a red line segment
  • 2: go forward with drawing a yellow line segment
  • 3: go forward with drawing a green line segment
  • 4: go forward with drawing a blue line segment
  • 5: go forward with drawing a purple line segment
  • +: turn 72° to the left
  • -: turn 72° to the right

Results

References