Fractal Grammar

Introduction

Lindenmayer Systems use a "find and replace" strategy to form complex, fractal sentences. They start simple, with a letter, or string of letters, called the "axiom". Each "generation" is constructed using rules that tell the system which letters to look for and what should replace them.

For example, let's take a simple example: Lindenmayer's own model of the growth of algae.

Starting with the axiom: A
And using the rules: (A → AB) & (B → A)

Generation 0: A
Generation 1: AB
Generation 2: ABA
Generation 3: ABAAB
Generation 4: ABAABABA
Generation 5: ABAABABAABAAB
...

How does this work, exactly?

To answer this, let's look at each generation, one step at a time:

Generation 0: A
This is what we started with. It's our axiom.

Generation 1: AB
We take each letter from the previous generation (Gen 0), and use the rules to replace that letter.
So, A becomes AB

Generation 2: ABA
There are two letters from Gen 1. We'll replace each of them separately, and then combine them.
A becomes AB
B becomes A
Resulting in ABA

Generation 3: ABAAB
A becomes AB
B becomes A
A becomes AB
Which leaves us with ABAAB
...

This process can continue for as many generations as you want!

Algorithmic Botany

As exciting as modeling the growth of algae is, it's not all that visually appealing to stare at strings of characters all day long. And, while we could visualize the growth of the algae, let's look at something a bit more exciting: Fractal Trees!

If you look at a tree, there is a sense of self-similarity to it; each branch looks like a scaled-down version of a trunk with its own branches jutting out it.

Below, you'll find a series of visualizations for each generation of an algorithmic tree. This particular tree was built using:
Axiom: F
Rule: (F → FF+[+F-F-F]-[-F+F+F])

Under the trees below, you'll find strings of characters. While they are almost unintelligible to us, these strings act are perfect for telling a computer what to draw. The computer uses something called Turtle Graphics to translate the strings into drawing instructions for constructing the trees. Each letter is an instruction that tells the turtle to do something:

  • F "move forward" a certain distance
  • + "rotate clockwise" by a certain angle
  • - "rotate counterclockwise" by a certain angle
  • [ "remember" where it was and how it was oriented
  • ] "recall" the most recently stored location and orientation

Note that each generation's "move forward" distance is different. The distance is smaller for latter generations because most of the tree would be drawn off-screen otherwise.

The colors show when each branch was drawn. Red branches were drawn first. Yellow branches toward the end. And the orange colors sometime in the middle.

Instructions

Use the left or right arrow keys to change the angle.
Click anywhere to reset the angle.