Skip to content

Educational showcase project in Python that explores how L-System strings can be parsed and visualized to create geometric and botanical figures.

Notifications You must be signed in to change notification settings

hunterpope03/python-l-system-studio

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Python Lindenmayer(L)-System Studio Home

In this repository, you will find all versions of the educational showcase project Python L-System Parser and Visualizer.

What is an L-System?

A Lindenmayer(L)-System is a mathematical model first invented by the Hungarian biologist and botanist Aristid Lindenmayer. An L-System works by repeatedly transforming character(s) in a string into a longer, more complex string of characters. Originally used to model the growth of bacteria and algae, L-Systems have grown to be used in textiles, games, neural networks, and art.

An L-System is composed of the following two attributes:

  • Axiom / Seed: an initial starting value
  • Production / Transformation Rules: definitions of how to replace each character or string into a more complex string

Consider this example:

Axiom = F
Transformation rules = F -> F + G and G -> G + H

In the first iteration, the axiom, F, is replaced via the transformation rule for F:

  • F -> F + G

In the following iterations, all of the characters in the resulting string, F + G, are again replaced by the transformation rules for both characters:

  • F + G -> (F + G) + (G + H)

With more more complex axioms and transformation rules and increased iterations, L-System strings can grow to huge lengths.

Consider exploring Paul Bourke's L-System Manual, which was integral in my understanding of L-Systems.

An L-System Parser & Visualizer Program

A parser, in programming terms, breaks down data into smaller pieces. So, think of each character in an axiom as a piece that represents something larger (a longer string). A parser will apply transformation rules for a given number of iterations.

The visualization process is a bit more complex. In a parsed string, there are commonly:

  • Variables - values that are changed in each transformation rule (usually letters)
  • Constants - values that are not changed in a transformation rule, but rather define a geometric action (to turn, create a new branch, etc.)

So when a visualizer takes in a parsed string, each character is a command. Some additional requirements for a visualizer might be:

  • Turn Angle - defines the angle at which to turn
  • Starting Direction - defines the angle at which to start the plot; allows for rotation

Using all of this information, a visualizer is fed a parsed string and creates a complex drawing. Changing the axiom, rules, and angles allows for a plethora of possible figures to be created.

Note that some programs may be more or less complex, allowing for a range of commands/features.

Example Visuals

Here are some examples from the second version of this project:

animation_examples.mp4

Here are some examples from my first version of this project, before I added animated visualizations:

Dragon Curve, via Paul Bourke
Dragon Curve System
L-System Bush 2, via Paul Bourke
L-System Bush 2
Pentaplexity, via Paul Bourke
Pentaplexity
Sierpinski Arrowhead, via Paul Bourke
Screenshot 2025-02-05 at 7 34 07 PM
Quadratic Gosper, via Paul Bourke
Screenshot 2025-02-05 at 7 32 53 PM

About

Educational showcase project in Python that explores how L-System strings can be parsed and visualized to create geometric and botanical figures.

Topics

Resources

Stars

Watchers

Forks

Languages