Lesson 37 of 51 · Fractals
Fractal Tree
A recursive tree that branches into smaller trees.
Python
from turtle import *
import colorsys
tracer(10)
bgcolor('black')
pensize(2)
left(90)
up()
goto(0, -200)
down()
def draw_tree(length):
if length < 5:
return
else:
h = 0.3 - (length / 200) * 0.3
color(colorsys.hsv_to_rgb(h, 1, 1))
forward(length)
right(25)
draw_tree(length * 0.75)
left(50)
draw_tree(length * 0.75)
right(25)
backward(length)
draw_tree(100)
done()Output

1
Recursive Branching
Each branch calls itself twice with a smaller length.