Tuesday, November 06, 2007

L-Systems pt I

L-Systems are commonly used to create complex patterns and constructs.

This and following posts are my attempt to understand these L-Systems more.

First of all, what is an L-System?

An L-system consists of two parts (roughly speaking). A chain (or a text string) and rules.

The chain can consist of any pre-defined components. To demonstrate I will use a chain of letters. The string AABA could be such a chain.

The rules describe how this chain should change. For instance

A = A
B = AB

You let the chain grow or change by running it through the rules, one component at a time. Let's consider the example above:

Chain: AABA
Rules: A=A
B=AB

First run:
First letter: A, becomes an A
Second letter: A, becomes an A
Third letter: B, becomes AB
Fourth letter: A, becomes A

The result is A+A+AB+A = AAABA

Second run:
First letter: A, becomes an A
Second letter: A, becomes an A
Third letter: A, becomes an A
Fourth letter: B, becomes AB
Fifthletter: A, becomes A

The result is A+A+A+AB+A = AAAABA

In this example, the chain was put through the same set of rules twice. In theory an L-System could be run any number of times, applying the rules over and over again.

Which each iteration, the string evolves and changes according to the rules.

There are a couple of basic patterns that is worth mentioning.

The first one is where you add complexity in the middle of the string.
Example:
Chain: ABA
Rules A = AB, B = A

First run: AB+A+AB = ABAAB
Second run: AB+A+AB+AB+A = ABAABABA
Third run: AB+A+AB+AB+A+AB+A+AB = ABAABABAABAAB

and so on. As can be seen, the string grows longer, and more complex all the time.

Consider instead this string, and in this case, I'll use three letters. The basic principle is the same.

Chain ABX
Rules, A=A, B=B, X=ABX

First run A+B+ABX = ABABX
Second run: A+B+A+B+ABX = ABABABX
Third run: A+B+A+B+A+B+ABX = ABABABABX

In this example, the inner structure isn't changed, instead a tail is added to the end for each run. This is accomplished with a tail component that adds a string+the tail component for each run.

These L-systems can use an indefinite number of rules and components. I could have an L-System with all the letters of the alphabet and a multitude of rules, creating something very complex.

So, what can we do with this then?


No comments: