Ex Nihilo

A Processing Sketch Blog

« | »

Recursive Trees

I spent the better part of this past week trying my hand at creating a decent-looking recursive tree, in between all the sweating this heat wave is causing.


Maybe it’s the heat but I think I’m ready to throw in the towel. I got the recursion working reasonably well, but the branch curves look terrible, and most of the logical adjustments I wanted to make ended up in division by zero for some reason I couldn’t track down.

Like, a for loop starting from zero and incrementing i on each iteration; I get that for the first iteration i = 0 so you’d think this equation should work, right?

    variation = multiplier / (i + 1);

But no such luck. “Division by zero” error. My actual code is more complicated of course, but that’s the essence of it; the loop is just not behaving as I’d have expected.

So I think for now it’s time to put this sketch to bed and move on to something else. Shame, I had some interesting things I wanted to do with the trees eventually.

Friday, July 31st, 2009 | Bezier, Recursion | RSS 2.0

Tags: , ,

4 Responses to “Recursive Trees”

  1. Allen Pike says:

    Procedurally generated plant life is very hard to do without using L-Systems. L-Systems are a formal grammar based way of generating treelike forms from a simple description. They can also be used to generate fractals and other patterns. http://en.wikipedia.org/wiki/L-system Thankfully, there’s barely any math to it at all beyond grammars/regex. You just recurse on the grammar a few times to generate some drawing commands, and draw with them!

  2. Dave says:

    Oh, interesting. I guess it stands to reason that there’s been a lot of prior research into generated plant life. I’ll have to check into that and see if I can make it work. (The limit being me, most likely, and not Processing.)

  3. Adam Sentz says:

    I’d still buy a tee shirt with that on the front – so don’t feel too bad.

  4. Arnold Konrad says:

    … seems my previous comment was lost – it said that the reason for your problem with division by zero could be an integer overflow (http://en.wikipedia.org/wiki/Integer_overflow). This is at least the only sensible explanation that comes to my mind.

Leave a Reply

Powered by WP Hashcash