Friday, June 13, 2008

L-Systems

I spent some spare time today doing a first draft at an L-System.  I was always intrigued by how nature is apparently governed by mathematics like the Fibonacci sequence.  L-Systems are basically grammars used commonly to model growth as it occurs in nature and to develop self-similar fractals.  A stochastic L-System (an L-System where each possible change has a certain probability of being selected) is what was used in this procedural cities paper for SIGGRAPH 2001.  There are some other methods, but I don't think they are as realistic as what Mueller and Pascal had done.  The L-System (with some add-on rules) is used to draw out the streets and also to generate buildings with different LODs.  I'm not sure where to go from my basic random-blocks-on-a-plane so I decided to look into L-Systems to try and generate a realistic city.  But first things first, here's a fractal plant (L-Systems in WPF):

lsystemFractalPlant

I coded a basic L-System and turtle graphics (something that draws whatever the L-System generates by following it like a path) and got the grammar for the plant on the wiki page.  It looks very like something you'd find in nature, but it all follows a strict grammar with only 2 rules and if you look for it, you can see the self-similar patterns.  It does take a while to execute however, especially at high iterations.  This site has a few of the common L-System grammars in a java app so you can play about with different grammars/iterations etc. and here's a gallery of other simple fractal forms.  Here's one more from my little app before I hit the hay - an arty close-up of part of a Koch snowflake:

lsystemKochSnowflake

I'll be honest, it's not arty, what it is is it's too fecking late to be messing about with WPF is what it is so screw you! Goodnight.

3 comments:

Patrick said...

Wow, you and I have a lot of similarities with what we are working on. I'm also trying to do procedural planets, cities, and vegetation. It looks like we have been reading the same research papers and buying the same books as well. I'm also trying to do it in C#, however I'm using XNA and you are using Managed DirectX. Close enough, eh?

I'm in the middle of trying to implement my own planetary LOD algorithm. It's been a rough road, but I think I'm finally making progress. I should setup a blogger page as well so other people can follow my development exploits.

John Leonard said...

Hey Patrick, it'd be great if you set up a blog, I was thinking of using XNA at the start but stuck with MDX because I've a good MDX9 book (by Tom Miller) so I'd be interested to see how you're getting on with it. Post the blogger link on when ya set it up!

Yeah the planetary LOD terrain was definitely the toughest part so far, and my method is far from elegant. I've seen wireframes of how other people do it and without knowing how they did it I can see that their approach is much simpler (by that I mean better!). Let me know if I can help with explanations of my stuff or whatever.

I've been addicted to Oblivion lately so haven't done much work on JellyEngine but I'm justifying it to myself as 'research' :D

Patrick said...

I have my blog set up now. It's located at http://recreationstudios.blogspot.com/ There is not much there yet, obviously. I'll try my best to keep it updated with what I'm doing.