Recursive Tree

I truly love recursive algorithms – simplicity is at their very heart and in that way they mirror many of natures own solutions to problems. A tree is a perfect example.

Here’s how it works in psuedo-code;

Draw a single thick “branch” at the bottom of the canvas in a straight up direction (aka the trunk!)

Draw Branch algorithm:
Continue drawing in the direction we’re currently moving.
At random intervals;
rotate the direction of the branch and reduce the thickness slightly.
At less frequent random intervals;
call the Draw Branch algorithm 1-3 times using the current position and width as starting points for the new branches.
If the branch is less than 1 pixel thick; draw a leaf and stop.

Beautifully simple.

Tech: ,