Recursive Tree Animation

john's Avatar

john

04 Sep, 2018 02:56 AM

This realistic, leafy, swaying 3D tree is actually a VERY simple 2D recursive tree graph. I came across the formula in a recent book by David Auerbach, Bitwise. Translated from Logo the algorithm goes something like this:

define tree ( level, size, scale, angle):
   if level > 0:
      draw left branch
      tree (level-2, size*scale, scale, angle)
      draw right branch
      tree (level-1, size*scale, scale, angle)
   end if
end tree

Sadly, NodeBox doesn't do recursion. But you can come close by making a subnetwork that can take itself as an input and string together as many as you need to reach a desired recursion depth. After seven levels (over 8700 line segments) NodeBox starts to bog down, but that is enough for a nice rendering. Add a little color, attach a frame and wave node to the angle parameter, and you have a beautiful bouncing baby tree.

Screenshot, zipped NodeBox file, and animated GIF attached. Enjoy!

John

  1. Support Staff 1 Posted by Frederik De Ble... on 10 Sep, 2018 07:13 PM

    Frederik De Bleser's Avatar

    Very cool! I often use L-systems for this type of animations.

    The ultimate book about this is "The Algorithmic Beauty of Plants" (PDF) by Aristid Lindenmayer himself. My colleague Stefan translated these algorithms to NodeBox Live — I'll ask him for a link.

  2. Support Staff 2 Posted by john on 10 Sep, 2018 10:34 PM

    john's Avatar

    Frederik,

    Thanks for the book reference - this looks *very* interesting. I look forward to getting Stefan's link.

    There has been some discussion about L-systems before in the NodeBox forum. In fact you created a GitHub issue to track it back in 2013: https://github.com/nodebox/nodebox/issues/332

    But my understanding is that NodeBox 3 still does not play well with L-systems due its lack of recursion and state. So when you say you often use L-systems for this type of animation, did you mean using Stefan's NodeBox Live code? Or some other tool?

    As you know, I would very much like to see support for L-systems, fractals, and recursion in general within NodeBox 3. I gather you had something in Nodebox 2. Any chance of porting it to 3?

    Thanks!

    John

  3. Support Staff 3 Posted by Stefan Gabriels on 11 Sep, 2018 08:23 AM

    Stefan Gabriels's Avatar

    The L-systems demo of NodeBox Live lives here:

    https://nodebox.live/demo/lsystem

    But the recursion happens within the LSystem code/node itself and not on the network level. This is something we can't do yet. In NodeBox Live we have a stateLoad and stateSave node though and with those we can reuse the output of nodes between animation frames. For example this way we can implement something like a counter in a recursive way, but this only works when using it with successive frames.

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Already uploaded files

  • tree_screenshot.png 1.45 MB
  • recursive_tree.zip 3.97 KB
  • tree.gif 2.22 MB

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac

 

20 Sep, 2018 05:09 PM
14 Sep, 2018 01:53 PM
11 Sep, 2018 08:23 AM
10 Sep, 2018 02:05 AM
07 Sep, 2018 01:57 PM
26 Aug, 2018 04:34 AM