Fractal Trees refers to a class of fractals that are generated by recursively applying a set of rules to a starting shape. The rules are applied to the starting shape to generate a new shape. The rules are then applied to the new shape to generate another shape. This process is repeated until the desired level of detail is reached.
To run the simulation, simply clone the repository and open the index.html
file in your browser. Alternatively, you can visit the GitHub Pages for this repository.
This is a very simple implementation of fractal trees. We can be more fancy and use a more complex set of rules to generate more complex fractal trees. We can also use a more complex starting shape to generate more complex fractal trees. E.g. (Code Train - Fractal Trees)[https://www.youtube.com/watch?v=fcdNSZ9IzJM] uses objects to represent the branches of the tree with position, angle, and length. This data allows us to manipulate the branches of the tree more easily.
function drawTree(x, y, length, angle, depth) {
if (depth > 0) {
drawBranch(x, y, length, angle);
drawTree(x, y, length * ratio, angle + 30, depth - 1);
drawTree(x, y, length * ratio, angle - 30, depth - 1);
}
}