Green Fractal Tree

About Green Fractal Tree

I created a fractal tree using Python’s built-in turtle graphics library. The tree is drawn using recursion, where each branch creates two smaller branches, forming a natural tree pattern. I also used the colorsys library to gradually change the color of the branches based on their length.

This project helped me understand how recursion works in a visual and interactive way.

What I Learned

How functions work in Python

What recursion is and how it repeats itself

How to use the turtle graphics module

How to control drawing screen and speed updates (and what those are)

How colour values can be generated mathematically

How it works


The function draw_tree(len):

Draws a branch of a certain length

Turns right and draws a smaller branch

Turns left and draws another smaller branch

Keeps repeating this until the branch is very small

This creates a natural tree shape.

A challenge that I faced

When I first tried to make my fractal tree, I had a problem where it kept going and didn’t look right. I didn’t know why the tree kept drawing over and over. After some research and online tutorials, I learned that with recursion, the function needs a rule to stop, and I forgot to add one. Once I told the function to stop when the branches got very small, it finally worked. This taught me that recursion always needs a stopping point and helped me understand how to fix problems in my code.

I fixed the problem by adding this condition that stops the function when the branches get very small

Thank you for reading