Day 52 - Creating a Fractal Image Using Recursive Functions

Starting with a Koch Snowflake, we will explore fractal designs using recursive functions by creating our own fractal image.

Finished Code

from turtle import *
s = Screen()
intMaxLevel = 5
pensize(2)
speed(0)
s.bgcolor("black")
def drawSide(intSize, intLevel):
    liColors = ["white", "red", "orange", "green", "blue", "purple"]
    color(liColors[intLevel-1])

    if intLevel <= intMaxLevel:
        intSize /= 3
        forward(intSize/2)
        left(90)
        drawSide(intSize,intLevel+1)
        right(90)
        drawSide(intSize, intLevel + 1)
        right(90)
        drawSide(intSize, intLevel + 1)
        left(90)
        forward(intSize/2)
    else:
        forward(intSize)
    color(liColors[intLevel-2])

def drawBox(intSize, intLevel):
    for x in range(4):
        drawSide(intSize, intLevel)
        right(90)

teleport(-200, 200)
drawBox(750, 1)

s.mainloop()