Procedural Tree Generator

This project is done in collaboration with Kelly Cho.

I. Overview

Trees and other organic vegetation usually appear in abundance and in a wide variation, are therefore very difficult to model individually. Instead, it would be much more efficient to be able to describe a species or type of tree and be able to create many unique plants with that specification. Our goal with this project is to procedurally generate natural looking trees.

In 1968, Aristid Lindenmayer developed a method to simulate the development of multicellular organims called L-Systems that is particularly useful in modeling plants. This method considers a plant to be modular, consisting several branching units or modules, that as a whole emerge as a plant shape. The paper L-systems: from the Theory to Visual Models of Plants (Prusinkiewicz, 1996) uses the L-System in combination with a turtle interpretor to render plants. We use the turtle interpretation of L-Systems described in this paper to create procedurally generated trees.

II. Live Demo - Coming soon!

Controls:

LMB - Grow one generation



1 - Cycle through configurations
2 - Turn on/off spinning
3 - Turn on/off simple render
4 - Turn on/off leaves
9 - Reset spintable
0 - Reset generation

III. Implementation

This project can be separated into two parts: tree generation using L-Systems that produces a string, and tree rending that reads and visualizes this string.

Tree Generation

L-System

An L-System is a parallel rewriting system that consists of a vocabulary, an axiom, a set of rules, number of iteration steps, and results in a sentence.

With each generation, we sweep through the current sentence and replace all predecessors with their respective successors in accordance to the rules. Below is an example of this process, along with a visualization using a turtle interpretor as described in the next section.

Rule: F → F[+F][-F]

GEN 0: F
GEN 1: F[+F][-F]
GEN 2: F[+F][-F] [ + F[+F][-F] ] [ - F[+F][-F] ]

7th generation Pythagorean tree.

Tree Rendering

Turtle Interpreter

The strings that are produced by our L-Systems can be efficiently visualized through a turtle interpeter. The turtle draws lines given a series of three commands: location, orientation, and pen on/off. This is percisely what our vocabularly describes.

The vocabulary and their definitions are listed below:

F - Move forward a step and draw a line segment.
L - Draw a leaf cluster.
X - Dummy action (does nothing; used for shaping).

[ - Push current state onto stack.
] - Pop a state from the stack make it a current stack.
+(θ) - Turn left by angle θ around the U axis.
−(θ) - Turn right by angle θ around the U axis.
&(θ) - Pitch down by angle θ around the L axis.
∧(θ) - Pitch up by angle θ around the L axis.
/(θ) - Roll left by angle θ around the H axis.
\(θ) - Roll right by angle θ around the H axis.

The turtle begins at the base and draws as it steps through the sentence, following each instruction, to generate the tree. A transformation matrix is used to keep track of all the operations performed on the turtle.

The [ and ] operations are used to create branches in the tree. Processing is capable of keeping track of a stack of transformation matrices. At each [, we simply push the current matrix onto the stack. At each ], we pop a matrix from our stack. This allows the turtle to return to any position and orientation on the tree and continue drawing from there.

Extra Shaping

Realism

While these branching visualizations are reminiscent of real-life trees, the realism can be greatly improved.

IV. Results

SEED: F
RULES: F → F[+FL]&F[\FL]
GEN: 4
Θ: PI/6
REDUC: .7
LEN: 25
SEED: XXL
RULES: X → F-[&[XL]+X]+F[\FLX]-XL
       F → FF
GEN: 4
Θ: 25°
REDUC: .9
LEN: 20