Quadratic Koch Snowflake from a Triangle (Source Code)

The quadratic Koch snowflake starts from a square. Draw the quadratic Koch snowflake starting with a triangle.

Quadratic Koch Snowflake from a Triangle

Source Code:

import turtle

screen = turtle.Screen()
screen.title('Quadratic Koch Curve From Triangle - PythonTurtle.Academy')
screen.setup(1000,1000)
screen.setworldcoordinates(-1000,-1000,1000,1000)
screen.tracer(0,0)
turtle.speed(0)
turtle.hideturtle()
turtle.bgcolor('midnight blue')
turtle.color('white')

def koch(x1,y1,x2,y2):
    distance=((x2-x1)**2 + (y2-y1)**2)**0.5
    if distance<10:
        turtle.up()
        turtle.goto(x1,y1)
        turtle.down()
        turtle.goto(x2,y2)
        return
    turtle.up()
    turtle.goto(x1,y1)
    direction=turtle.towards(x2,y2)
    turtle.seth(direction)
    turtle.fd(distance/3)
    x3,y3 = turtle.xcor(), turtle.ycor()
    turtle.left(90)
    turtle.fd(distance/3)
    x4,y4 = turtle.xcor(), turtle.ycor()
    turtle.right(90)
    turtle.fd(distance/3)
    x5,y5 = turtle.xcor(), turtle.ycor()
    turtle.right(90)
    turtle.fd(distance/3)
    x6,y6 = turtle.xcor(), turtle.ycor()
    koch(x1,y1,x3,y3)
    koch(x3,y3,x4,y4)
    koch(x4,y4,x5,y5)
    koch(x5,y5,x6,y6)
    koch(x6,y6,x2,y2)
    

koch(500,-200,-500,-200)
koch(-500,-200,0,500*3**0.5-200)
koch(0,500*3**0.5-200,500,-200)
screen.update()

Quadratic Koch Snowflake with Python Turtle (Source Code)

The original Koch Snowflake is based on triangles. Draw quadratic Koch snowflake that breaks a line into 4 smaller pieces of 1/3 of the original length as shown.

Depth 1 Recursion
Depth 2 Recursion
Depth 3 Recursion

The following is drawn with 4 initial lines that forms a square.

Quadratic Koch Snowflake

Source Code:

import turtle

screen = turtle.Screen()
screen.title('Quadratic Koch Curve - PythonTurtle.Academy')
screen.setup(1000,1000)
screen.setworldcoordinates(-1000,-1000,1000,1000)
screen.tracer(0,0)
turtle.speed(0)
turtle.hideturtle()
turtle.bgcolor('midnight blue')
turtle.color('white')

def koch(x1,y1,x2,y2):
    distance=((x2-x1)**2 + (y2-y1)**2)**0.5
    if distance<10:
        turtle.up()
        turtle.goto(x1,y1)
        turtle.down()
        turtle.goto(x2,y2)
        return
    turtle.up()
    turtle.goto(x1,y1)
    direction=turtle.towards(x2,y2)
    turtle.seth(direction)
    turtle.fd(distance/3)
    x3,y3 = turtle.xcor(), turtle.ycor()
    turtle.left(90)
    turtle.fd(distance/3)
    x4,y4 = turtle.xcor(), turtle.ycor()
    turtle.right(90)
    turtle.fd(distance/3)
    x5,y5 = turtle.xcor(), turtle.ycor()
    turtle.right(90)
    turtle.fd(distance/3)
    x6,y6 = turtle.xcor(), turtle.ycor()
    koch(x1,y1,x3,y3)
    koch(x3,y3,x4,y4)
    koch(x4,y4,x5,y5)
    koch(x5,y5,x6,y6)
    koch(x6,y6,x2,y2)
    

koch(-400,-400,-400,400)
koch(-400,400,400,400)
koch(400,400,400,-400)
koch(400,-400,-400,-400)
screen.update()

Pythagoras Tree Fractal with Filled Color (Source Code)

Based on Pythagoras Tree, draw a version with filled color. Color branches with brown and leaves with green.

Pythagoras Tree Fractal with Filled Color

Source Code:

import turtle
screen = turtle.Screen()
screen.title('Colored Fractal Pythagoras Tree - PythonTurtle.Academy')
screen.setup(1000,1000)
screen.setworldcoordinates(-1000,-1000,1000,1000)
screen.tracer(0,0)
turtle.speed(0)
turtle.hideturtle()
turtle.pensize(2)

def squaretree(x,y,length,tilt,n):
    if n==0: return
    if n<6:
        turtle.color('forest green')
    else:
        turtle.color('saddle brown')
    turtle.up()
    turtle.goto(x,y)
    turtle.down()
    turtle.begin_fill()
    turtle.seth(tilt)
    turtle.fd(length)
    turtle.left(90)
    turtle.fd(length)
    turtle.left(45)
    turtle.fd(length/2**0.5)
    x1,y1 = turtle.xcor(), turtle.ycor()    
    turtle.left(90)
    turtle.fd(length/2**0.5)
    x2,y2 = turtle.xcor(), turtle.ycor()
    turtle.left(45)
    turtle.fd(length)
    turtle.left(90)
    turtle.end_fill()

    squaretree(x1,y1,length/2**0.5,tilt-45,n-1)
    squaretree(x2,y2,length/2**0.5,tilt+45,n-1)
    
squaretree(-150,-600,300,0,13)
screen.update()
    
    

Five Branch Fractal Tree (Source Code)

Draw a fractal tree with five branches.

Five Branch Fractal Tree

Source Code:

import turtle
import colorsys

screen = turtle.Screen()
screen.title('Five Branch Fractal Tree - PythonTurtle.Academy')
screen.setup(1000,1000)
screen.setworldcoordinates(-1000,-1000,1000,1000)
screen.tracer(0,0)
turtle.speed(0)
turtle.hideturtle()

def fivebranchtree(x,y,length,direction,n):
    if n==0: return
    turtle.up()
    turtle.goto(x,y)
    turtle.down()
    turtle.seth(direction)
    turtle.pensize(length/100)
    turtle.fd(length)
    px,py = turtle.xcor(), turtle.ycor()
    fivebranchtree(px,py,length*0.445,direction,n-1)
    fivebranchtree(px,py,length*0.445,direction+360/7,n-1)
    fivebranchtree(px,py,length*0.445,direction+2*360/7,n-1)
    fivebranchtree(px,py,length*0.445,direction-2*360/7,n-1)
    fivebranchtree(px,py,length*0.445,direction-360/7,n-1)

L=1000    
fivebranchtree(0,-900,L,90,8)
screen.update()

Colored Slanted Fractal Tree (Source Code)

Based on Slanted Fractal Tree, draw a colored version with leaves green and branches brown.

Colored Slanted Fractal Tree

Source Code:

import turtle

screen = turtle.Screen()
screen.title('Slanted Fractal Tree - PythonTurtle.Academy')
screen.setup(1000,1000)
screen.setworldcoordinates(-1000,-1000,1000,1000)
screen.tracer(0,0)
turtle.speed(0)
turtle.hideturtle()

def slanted_tree(x,y,length,direction):
    if length < 2: return
    turtle.up()
    turtle.goto(x,y)
    turtle.down()
    turtle.seth(direction)
    turtle.pensize(length/50)
    if length > 20: turtle.color('saddle brown')
    else: turtle.color('green')
    turtle.fd(length)
    px,py = turtle.xcor(), turtle.ycor()
    slanted_tree(px,py,length*0.7,direction-30)
    slanted_tree(px,py,length*0.7,direction+60)

L=400
slanted_tree(100,-500,L,90)
screen.update()