Lsystem trees

Hello all,

I’m new here, after lurking for a few weeks. I’m also new to LUA, but not to other languages and to graphics.

Here is some work in progress. It’s an implementation of 3D, non deterministic, context sensitive l-systems. For those who don’t know about l-systems: non deterministic means that each rule can have several predicates to choose from, each with a specific probability. Context sensitive means that the rules can specify other characters that need to be around the one we are comparing against in order to get the pattern to match. These two things allow for a lot more variety in the kinds of structures obtained.

What I’m doing is re-implementing in Codea some code that I initially wrote many years ago in the in-house language of PDI/Dreamworks, where I worked, and later rewrote in Python. My Python code lets you manage “populations” of trees, that you can “evolve” by measuring each tree according to a fitness function, and replacing poor individuals with mutations and mixtures of the better trees. Some more background on that here:

http://www.jbuhler.com/LSystems/index.html

The following Codea code just does the l-system part. The parameters panel lets you edit the grammar used. The symbols I use are pretty standard:

f : draw a segment
+,-,<,>,/,|: rotations around all three axis
[,]: push and pop the transformation matrix

Also, “?” is used in the rules, to specify a wildcard character. The syntax of the rules in the little text box is

rule

So to use the non-deterministic thing, you just specify several rule entries with the same rule character in each. Probabilities are normalized automatically.

To specify a context, just use a with an odd number of characters: the center one is the one to be replaced, and the rest are context, prefix and suffix (this is why I need “?” to use as a wildcard)

Anyway. The above will be clear to those of you who know about l-systems I guess. In any case, the code as it is is kind of cool to play with. I need to figure out what to implement next–probably some easy way to load and save trees, followed by some smart way to combine existing trees. The most interesting part of this for me is the kind of rules that emerge once you make the trees evolve by themselves–really organic structures, and really non-intuitive rules to get them.

Comments and suggestions welcome!

Edit: code pasting fail. Look for it here, and sorry if you saw the earlier, mangled post.

https://gist.github.com/anonymous/4974484

Hey Juan,
Just wanted to drop a line and say high, from your page above I found out about your road trip and I’ve just subscribed to your RSS feed. A few years back I followed the journey that Karl Bushby was making from Punta Arenas back to his hometown in the UK (by walking ALL the way), last I heard he’d got as far as Russia but was having visa problems

http://www.amazon.co.uk/Giant-Steps-Remarkable-Expedition-ebook/dp/B008HRNQH2/ref=sr_1_11?ie=UTF8&qid=1361181296&sr=8-11

Hope your finding plenty of time to get some coding done :slight_smile:

Jon…