A few weeks ago I developed an interest in generative art. This was primarily from my desire to follow in the path of a number of great Flash developers whose art tools were both amazing and inspiring. My search lead me to the generative art wiki, which while sparse, is certainly a good starting place for such things. One page in particular caught my eye: l-systems. These systems can be used to create some very complex and interesting simulations of plants & other abstract visuals (which I discovered quite by accident).
For the full (highly mathematical (and incredibly difficult for me to grok)) breakdown, I would direct you to The Algorithmic Beauty of Plants, which is about a decade and a half old, but still appears to be a great introduction to the subject. Here I will present my own work with l-systems in Actionscript 3 and Flash.
The (extremely) basic concept of an l-system is to generate progressively more complex strings given a start point and a set of transformations (called ‘productions’ or ‘production rules’). Anytime a rule is matched, the character is replaced with the characters from the rule. If no rule is matched, the character is copied into the new string unchanged. For example, an l-system may have a starting string of “A”, and a production rule of “A => BAB”. The first iteration of l-system will be “A”, the second “BAB”, the third “BBABB”, and so on.
(A quick note on the replacement: don’t do what I did and just run a quick stringReplace on each rule & iteration. It has to be done per character, especially as the rules get more complex. That isn’t to say the string replace produces some interesting results…)
In order to create something graphical, the production rules are linked up to a ‘turtle’ with each character affecting the movement of the drawing pointer. The ‘vocabulary’ of the rules is slightly extended in order to allow more complex actions. A basic 2D turtle uses the set of characters ‘F[]+-’.
- F: move forward by a set amount
- [: save turtle state (position, line size, heaving, etc)
- ]: Pop the last turtle state off the stack, and reset turtle to that state
- +/-: Rotate the turtle left or right by a set amount
Other letters may also be added into the vocabulary to be replaced by production rules later on. The first letter typically used is ‘X’.
So, taking a cue from the generative art wiki, a simple system may be defined by these rules:
w: X
p1: X → F[+X]F[-X]+X
p2: F → FF
and would result in
n = 0; X
n = 1; F[+X]F[-X]+X
n = 2; FF[+F[+X]F[-X]+X]FF[-F[+X]F[-X]+X]+F[+X]F[-X]+X
with a graphical representation similar to:

This should be enough to get going. For more information, I highly reccommend “The Algorithmic Beauty of Plants” mentioned earlier.
In addition, I made a little Flash example that randomizes some of the production rules. It creates some interesting results, though not as full-bodied as I would like.