← Back

L-system Generation

Project Overview

L-System Generator Demo

Project Overview

I developed an OpenGL/C++ program that generates realistic tree models using L-systems. The scene includes a ground mesh, procedurally built hexagonal branches, and flat rhombus leaves. The tree structure is defined by a custom grammar and input file specifying season, recursion depth, starting sentence, and replacement rules.

The program parses this grammar to build complex branching patterns recursively, with transformations based on symbols like turns and groupings. Seasonal settings adjust leaf color, presence, and ground textures for winter, spring, summer, or fall. Leaves are added in natural patterns along branches, scaling dynamically for realism.

The result is a fully configurable tree generator that visualizes grammar-driven structures in 3D, demonstrating recursive modeling techniques and rule-based procedural generation in OpenGL.

How It Works

The generator uses an input file to define the L-system grammar and parameters. This file specifies the desired season, recursion depth, starting sentence, and replacement rule. The season setting changes ground color and leaf appearance to match winter, spring, summer, or fall. The recursion depth controls the complexity of the branching structure by determining how many times the rule replaces the "F" symbol in the sentence.

The grammar defines symbols for actions like branching and turning:

Example rule: F(+F)(-F(F)(/F))(#F(/F)(+F))(F)(/F)

After parsing the input, the program builds the final sentence by recursively applying the replacement rule to all "F" symbols. This resulting string encodes the full tree structure. The buildModel method initializes the ground and then calls buildBranch recursively to interpret the sentence.

Each branch is represented as a hexagonal prism mesh, scaled down at each level of recursion for a natural tapering effect. Leaves are simple rhombus meshes, placed in an “X” pattern at the ends of branches and scattered randomly along them. The result is a 3D model that visually represents the specified L-system grammar with detailed seasonal variation and hierarchical branching.