This was originally going to be a small section in a short series building up to a simulation of evolving trees, but it has turned out to be extremely interesting on its own. I have a few parts worth of interesting math to go through related to fractal trees, but in this part we'll just go through what they are, some cool examples, and an interactive demo where you can mess with the parameters and see what comes out.

## Construction🔗

A fractal tree is part of a class of fractals that are composed of several copies of themselves. To build one start with a trunk of any length, then draw two branches coming out of the top of the trunk each slightly smaller than the trunk and rotated to point in a different direction. Then draw two more branches coming out each of the first two branches rotated and scaled in the same way and repeat forever. You can change four parameters: the scaling factor and angle for each branch every time a branch splits into two more branches. Messing with these parameters can get you some really interesting shapes.

## Examples🔗

Some of these examples look a fair bit like actual trees like this half of a christmas tree:

Or this tree with some oddly level leaves:

You can also get some more fractally shapes like this infinite series of self-similar loops on loops:

Or this angry-looking shark fin:

You can also get some more well-known shapes like the Dragon Curve (plus some scaffolding)

And the related Twin Dragon Curve

You can also get this space-filling fractal that looks like a sheet of A4 paper with a ratio $\sqrt{2}$ of between the side lengths.

There are also some pretty normal but unexpected shapes like this octagon.

Fullscreen

## How does it work?🔗

This demo draws the trees up to 100 iterations of branching. Given that the number of branches doubles each time, that's about $2^{100} \approx 10^{30}$ things to draw which is an impossible amount if you draw them individually. Instead of drawing individual branches, you can take advantage of the fact that the tree is made up of the trunk plus two copies of itself rotated and scaled by different amounts. Therefore you can draw two copies of the image itself from the previous iteration in order to increase the total height of the tree by one. Rather than the process taking an exponentially longer time with increased height, the process now scales linearly with height. The image is also persistent (rather than being redrawn every frame) so that I can progressively draw more iterations over time and take advantage of a few seconds of computation time rather than trying to cram everything into a 60th of a second.

Source code