L-system.html

Right-click on drawing and select save-as to save the model.

description

This program allows you to explore a number of fractals generated with Lindenmayer-systems (L-systems). L-systems are rewriting systems. They take a list of symbols and repeatedly generate a new list of symbols by following a set of rules. Each new list of symbols is called a generation. The beauty of L-systems is that with just a few symbols and rules amazingly complex shapes can be created.

Most of the fractals and plant models shown here can be found in the book "The Algorithmic Beauty of Plants" (ABOP). Where appropriate the model is labeled with ABOP and the figure number from the book.

Select a L-system model from the drop down list above. A brief description of the model is given. The definition of the model is given including the symbols, their turtle interpretation, the initial list of symbols (axiom) and rules. Some models have parameters that you can adjust. You can set the number of generations to run before drawing. Press the Play button to draw the model. The Previous and Next buttons will draw the previous or next generation respectively.

Control the speed and smoothness of the drawing with the Modules per step and Delay sliders.

Koch Snowflake

The Koch snowflake (or Koch star) is a mathematical curve and one of the earliest fractal curves to have been described. It is named after the Swedish mathematician Helge von Koch.

Symbols:
  F forward(d)
  + left(60)
  - right(60)
Axiom: F - - F - - F
Rules: F --> F + F - - F + F

Koch curve

This is one side of a Koch snowflake.

Symbols:
  F forward(d)
  + left(60)
  - right(60)
Axiom: F
Rules: F --> F + F - - F + F

Dragon curve

The Dragon Curve. This implementation uses edge rewriting as shown in ABOP fig. 1.4.

Symbols:
  Fl forward(d)
  Fr forward(d)
  + left(90)
  - right(90)
Axiom: Fl
Rules:
  Fl --> Fl + Fr +
  Fr --> - Fl - Fr

Sierpinski Triangle

The Sierpinski triangle, also called the Sierpinski gasket, is a fractal named after Wacław Sierpiński who described it in 1915. There are a few different construction methods. This example uses a turtle. See this scratch project for another way.

Symbols:
  Fr forward(d)
  Fl forward(d)
  + left(60)
  - right(60)
Axiom: Fr
Rules:
  Fl --> Fr + Fl + Fr
  Fr --> Fl - Fr - Fl

Sierpinski Triangle2

This is an alternative method for making the Sierpinski triangle. This does not use turtle graphics. It works by replacing a triangle with 3 smaller triangles. See this wikipedia article for an example. This is a parametric L-system where the parameters are points that define a triangle.

Symbols:
  T(a, b, c) draw a triangle
    through points a, b, c
Axiom: T(a, b, c)
Rules:
  T(a, b, c) --> T(a, mid(a,b), mid(a,c))
                 T(mid(a,b), b, mid(b,c))
                 T(mid(a,c), mid(b,c), c)

Quadratic Koch Island

Quadratic Koch Island. ABOP fig. 1.6.

Symbols:
  F forward(d)
  + right(90)
  - left(90)
Axiom: F − F − F − F
Rules: F --> F − F + F + F F − F − F + F

Islands and Lakes

Islands and lakes from ABOP fig. 1.8.

This one is not continuous. In other words the turtle picks up the pen at times.

Symbols:
  F forward(d)
  f penUp() forward(d) penDown()
  + right(90)
  - left(90)
Axiom: F + F + F + F
Rules: F --> F + f - F F + F + F F + 
             F f + F F - f + F F - F - 
             F F - F f - F F F
       f --> f f f f f f

Quadratic Snowflake

Quadratic Snowflake from ABOP fig. 1.7b.

This fractal as well as many other interesting ones can be found in this list of fractals.

Symbols:
  F forward(d)
  + left(90)
  - right(90)
Axiom: F
Rules:
  F --> F + F - F - F + F

Fig. 1.9 a

Fig. 1.9 a from ABOP.

Symbols:
  F forward(d)
  + right(90)
  - left(90)
Axiom: F − F − F − F
Rules: F --> F F - F - F - F − F - F + F

Fig. 1.9 b

Fig. 1.9 b from ABOP.

Symbols:
  F forward(d)
  + right(90)
  - left(90)
Axiom: F − F − F − F
Rules: F --> F F - F - F - F − F F

Fig. 1.9 d

Fig. 1.9 d from ABOP.

Symbols:
  F forward(d)
  + right(90)
  - left(90)
Axiom: F − F − F − F
Rules: F --> F F - F - - F − F

Tree a

Tree a from fig. 1.24 in ABOP.

Symbols:
  F forward(d)
  + left(a)
  - right(a)
  [ push
  ] pop
Axiom: F
Rules:
  F --> F [ + F ] F [ - F ] F

Tree b

Tree b from fig. 1.24 in ABOP.

Symbols:
  F forward(d)
  + left(a)
  - right(a)
  [ push
  ] pop
Axiom: F
Rules:
  F --> F [ + F ] F [ - F ] [ F ]

Tree c

Tree c from fig. 1.24 in ABOP.

Symbols:
  F forward(d)
  + left(a)
  - right(a)
  [ push
  ] pop
Axiom: F
Rules:
  F --> F F - [ - F + F + F ] + 
        [ + F - F - F ]

Tree d

Tree d from fig. 1.24 in ABOP. This is a non-deterministic version with the possibility of branching either left or right at the first branch point.

Symbols:
  F forward(d)
  + left(a)
  - right(a)
  [ push
  ] pop
Axiom: X
Rules:
  X -->  (pl) F [ + X ] F [ - X ] + X
       (1-pl) F [ - X ] F [ - X ] + X
  F --> F F

Tree e

Tree e from fig. 1.24 in ABOP.

Symbols:
  F forward(d)
  + left(a)
  - right(a)
  [ push
  ] pop
Axiom: X
Rules:
  X --> F [ + X ] [ - X ] F X 
  F --> F F

Tree f

Tree f from fig. 1.24 in ABOP.

This tree can also be found in here in example 8.

Symbols:
  F forward(d)
  + left(a)
  - right(a)
  [ push
  ] pop
Axiom: X
Rules:
  X --> F - [ [ X ] + X ] + F [ + F X ] - X
  F --> F F

Tree 1.27

Tree from fig. 1.27 in ABOP. This is another non-deterministic tree. It will likely look different each time it is generated.

Symbols:
  F forward(d)
  + left(a)
  - right(a)
  [ push
  ] pop
Axiom: F
Rules:
  F -->  (.33) F [ + F ] F [ - F ] + F
         (.33) F [ + F ] F
         (.34) F [ - F ] F

Row Of Trees a

Row of Trees from fig. 1.37a in ABOP. This is a parametric L-system.

Constants: 
  c = 1, p = 0.3, q = c − p, 
  h = (p * q) ^ ∧ 0.5
Symbols:
  F(d) forward(d)
  + left(a)
  - right(a)
Axiom: F(d)
Rules:
  F(x) --> F(x * p) + F(x * h) - - 
           F(x * h) + F(x * q)

Trees 1.31a

Tree from ABOP fig. 1.31 a. This is a context sensitive L-system.

Symbols:
  F forward(d)
  + left(a)
  - right(a)
Ignore: + - F
Axiom: F 1 F 1 F 1
Rules:
0 < 0 > 0 --> 0
0 < 0 > 1 --> 1[+F1F1]
0 < 1 > 0 --> 1
0 < 1 > 1 --> 1
1 < 0 > 0 --> 0
1 < 0 > 1 --> 1F1
1 < 1 > 0 --> 0
1 < 1 > 1 --> 0
    +     --> -
    -     --> +

Trees 1.31b

Tree from ABOP fig. 1.31 b. This is a context sensitive L-system.

Symbols:
  F forward(d)
  + left(a)
  - right(a)
Ignore: + - F
Axiom: F 1 F 1 F 1
Rules:
0 < 0 > 0 --> 1
0 < 0 > 1 --> 1[-F1F1]
0 < 1 > 0 --> 1
0 < 1 > 1 --> 1
1 < 0 > 0 --> 0
1 < 0 > 1 --> 1F1
1 < 1 > 0 --> 1
1 < 1 > 1 --> 0
    +     --> -
    -     --> +

Trees 1.31c

Tree from ABOP fig. 1.31 c. This is a context sensitive L-system.

Symbols:
  F forward(d)
  + left(a)
  - right(a)
Ignore: + - F
Axiom: F 1 F 1 F 1
Rules:
0 < 0 > 0 --> 0
0 < 0 > 1 --> 1
0 < 1 > 0 --> 0
0 < 1 > 1 --> 1[+F1F1]
1 < 0 > 0 --> 0
1 < 0 > 1 --> 1F1
1 < 1 > 0 --> 0
1 < 1 > 1 --> 0
    +     --> -
    -     --> +

Trees 1.31d

Tree from ABOP fig. 1.31 d. This is a context sensitive L-system.

Symbols:
  F forward(d)
  + left(a)
  - right(a)
Ignore: + - F
Axiom: F 0 F 1 F 1
Rules:
0 < 0 > 0 --> 1
0 < 0 > 1 --> 0
0 < 1 > 0 --> 0
0 < 1 > 1 --> 1F1
1 < 0 > 0 --> 1
1 < 0 > 1 --> 1[+F1F1]
1 < 1 > 0 --> 1
1 < 1 > 1 --> 0
    +     --> -
    -     --> +

Trees 1.31e

Tree from ABOP fig. 1.31 e. This is a context sensitive L-system.

Symbols:
  F forward(d)
  + left(a)
  - right(a)
Ignore: + - F
Axiom: F 1 F 1 F 1
Rules:
0 < 0 > 0 --> 0
0 < 0 > 1 --> 1[-F1F1]
0 < 1 > 0 --> 1
0 < 1 > 1 --> 1
1 < 0 > 0 --> 0
1 < 0 > 1 --> 1F1
1 < 1 > 0 --> 1
1 < 1 > 1 --> 0
    +     --> -
    -     --> +
Drawing Control
Copyright © 2008, John Snyders

This work is licensed under a Creative Commons Attribution 3.0 United States License.

L-system.html - A web page for exploring L-systems.

Uses HTML, CSS, the new <canvas> tag, JavaScript and jQuery.

Read the HardLikeSoftware article.

Creative Commons License Copyright © 2008, John Snyders
This work is licensed under a Creative Commons Attribution 3.0 United States License.