Drawing the Pythagoras Tree

This is the first test of recursive drawing in JavaScript. The essence of this “recursive drawing” is that (like in chaos theory) everything is very dependent on the initial parameters. The final drawing can vary significantly even if just one parameter is changed by just a 0,01.

The basics of this recursive drawing are, that there is only 1 function for drawing. This function draws something and in the end it calls itself again, it draws something and calls itself again, draws something, calls itself, … It just cycles how many times we want. And every single time witch parameters changed a bit (or a lot).

Recursive function

Here: Function drawTree calls function drawBranch twice. And both drawBranch functions then call the drawTree function again (with depth — 1 to be able to stop the cycling).

There is a million examples of drawing the Pythagoras tree on the internet, but I wanted to figure it out myself, so… The code may be not the prettiest, but it’s mine :)

Live version: http://studio.romanbartos.cz/Test%202/

Like what you read? Give Roman Bartoš a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.