In the interest of creating multi-image desktop wallpapers, I wrote some code to build and render L-systems.


Hilbert Curve

hilbert curve

Sierpinski Triangle

Sierpinsky triangle


terdragon curve

Dragon Curve

dragon curve


The code is written in Python, using PySFML2 for graphics. The core functionality is in L_system.py, with graphics provided by L_app.py and L_shape.py.

The first important function is build_string, which recursively generates a system string from a starting string and rule set. It returns a generator to avoid building the entire string in memory

The second important function is build_shape, which renders a string into a set of (x, y) coordinates tuples based on drawing rules.

The GUI can be invoked with the command L_app.py system, where system is an L-system definition. Included are definitions for the shapes shown above, named hilbert.py, sierpinski.py, terdragon.py, and dragon.py.

While the application is running, the up and down arrows change iteration depth. Escape or command+Q exits the program.


L-System (zip file, 8 KB)