Red Cross with Python Turtle (Source Code)

The following red cross with Python and Turtle. You need to fill it with a color.

Red Cross

Source Code:

import turtle

screen = turtle.Screen()
screen.title('Red Cross - PythonTurtle.Academy')
screen.setup(1000,1000)
turtle.speed(0)
turtle.hideturtle()
turtle.color('red')

turtle.up()
turtle.goto(-450,-150)
turtle.down()
turtle.begin_fill()
for _ in range(4):
    turtle.fd(300)
    turtle.right(90)
    turtle.fd(300)
    turtle.left(90)
    turtle.fd(300)
    turtle.left(90)      
turtle.end_fill()

Vicsek Fractal with Python and Turtle (Source Code)

Draw the Vicsek Fractal based on cross with recursion and Turtle. The following figures show first a few recursive steps:

Recursive Depth 0
Recursive Depth 1
Recursive Depth 2
Recursive Depth 3
Recursive Depth 4
Recursive Depth 5

Source Code:

import turtle

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

def draw_cross(x,y,length):
    turtle.up()
    turtle.goto(x-length/2,y-length/6)
    turtle.down()
    turtle.seth(0)
    turtle.begin_fill()
    for _ in range(4):
        turtle.fd(length/3)
        turtle.right(90)
        turtle.fd(length/3)
        turtle.left(90)
        turtle.fd(length/3)
        turtle.left(90)      
    turtle.end_fill()

def vicsek(x,y,length,n):
    if n==0:
        draw_cross(x,y,length)
        return

    vicsek(x,y,length/3,n-1)
    vicsek(x+length/3,y,length/3,n-1)
    vicsek(x-length/3,y,length/3,n-1)
    vicsek(x,y+length/3,length/3,n-1)
    vicsek(x,y-length/3,length/3,n-1)
    
vicsek(0,0,1600,5)
screen.update()

Cesàro (Torn Squares) Fractal with Python Turtle (Source Code)

Cesàro (Torn Squares) Fractal is a variation of Koch Snowflake. In Cesàro Fractal the degree to turn can vary from 60 degrees to 90 degrees. Koch Snowflake line only curves 60 degrees.

Instead of choosing a degree to turn, Cesàro Fractal is easier to implement by setting the ratio of original length for each of the 4 segments. For Koch snowflake, the ratio is 1/3. For Cesàro Fractal the ratio can range from 1/3 to 1/2. The following is the Cesàro Fractal with different ratios:

Cesàro Fractal with 1/3 Ratio
Cesàro Fractal with Ratio 0.4
Cesàro Fractal with Ratio 0.47
Cesàro Fractal with Ratio 0.49

Source Code:

import turtle
import math

screen = turtle.Screen()
screen.title('Cesàro (Torn Square) Fractal - PythonTurtle.Academy')
screen.setup(1000,1000)
screen.setworldcoordinates(-1000,-1000,1000,1000)
screen.tracer(0,0)
turtle.speed(0)
turtle.hideturtle()
turtle.fillcolor('blue')

# ratio is between [1/3, 1/2)
def Cesàro(x1,y1,x2,y2,ratio):
    dist = ((x2-x1)**2+(y2-y1)**2)**0.5
    if dist<50:
        turtle.goto(x2,y2)
        return
    direction = math.atan2(y2-y1,x2-x1)
    px1, py1 = x1+dist*ratio*math.cos(direction), y1+dist*ratio*math.sin(direction)    
    px3, py3 = x1+dist*(1-ratio)*math.cos(direction), y1+dist*(1-ratio)*math.sin(direction)
    ptx, pty = (px1+px3)/2, (py1+py3)/2
    d = ((dist*ratio)**2 - (dist*(1-2*ratio)/2)**2)**0.5
    px2, py2 = ptx+d*math.cos(direction+math.radians(90)), pty+d*math.sin(direction+math.radians(90))
        
    Cesàro(x1,y1,px1,py1,ratio)
    Cesàro(px1,py1,px2,py2,ratio)
    Cesàro(px2,py2,px3,py3,ratio)
    Cesàro(px3,py3,x2,y2,ratio)

ratio = 0.49
turtle.up()
turtle.goto(-800,800)
turtle.down()
Cesàro(-800,800,-800,-800,ratio)
Cesàro(-800,-800,800,-800,ratio)
Cesàro(800,-800,800,800,ratio)
Cesàro(800,800,-800,800,ratio)

screen.update()

Minkowski Island with Python Turtle (Source Code)

Minkowski Island is a fractal that is a variant to Koch snowflake. The following figures show Minkowski Island.

Recursive Depth 0
Recursive Depth 1
Recursive Depth 3
Recursive Depth 4
Filled Minkowski Island with Python Turtle

Source Code:

import turtle
import math

screen = turtle.Screen()
screen.title('Minkowski Island - PythonTurtle.Academy')
screen.setup(1000,1000)
screen.setworldcoordinates(-2000,-2000,2000,2000)
screen.tracer(0,0)
turtle.speed(0)
turtle.hideturtle()

def Minkowski(x1,y1,x2,y2,n):
    if n==0:
        turtle.goto(x2,y2)
        return
    dist = ((x2-x1)**2+(y2-y1)**2)**0.5
    direction = math.atan2(y2-y1,x2-x1)
    px1, py1 = x1+dist/4*math.cos(direction), y1+dist/4*math.sin(direction)
    px2, py2 = px1+dist/4*math.cos(direction+math.radians(90)), py1+dist/4*math.sin(direction+math.radians(90))
    px3, py3 = px2+dist/4*math.cos(direction), py2+dist/4*math.sin(direction)
    px4, py4 = px3+dist/4*math.cos(direction-math.radians(90)), py3+dist/4*math.sin(direction-math.radians(90))
    px5, py5 = px4+dist/4*math.cos(direction-math.radians(90)), py4+dist/4*math.sin(direction-math.radians(90))
    px6, py6 = px5+dist/4*math.cos(direction), py5+dist/4*math.sin(direction)
    px7, py7 = x1+3*dist/4*math.cos(direction), y1+3*dist/4*math.sin(direction)
        
    Minkowski(x1,y1,px1,py1,n-1)
    Minkowski(px1,py1,px2,py2,n-1)
    Minkowski(px2,py2,px3,py3,n-1)
    Minkowski(px3,py3,px4,py4,n-1)
    Minkowski(px4,py4,px5,py5,n-1)
    Minkowski(px5,py5,px6,py6,n-1)
    Minkowski(px6,py6,px7,py7,n-1)
    Minkowski(px7,py7,x2,y2,n-1)

turtle.up()
turtle.goto(-800,-800)
turtle.down()
n=3
screen.bgcolor('light gray')
turtle.fillcolor('gray')
turtle.begin_fill()
Minkowski(-800,-800,-800,800,n)
Minkowski(-800,800,800,800,n)
Minkowski(800,800,800,-800,n)
Minkowski(800,-800,-800,-800,n)
turtle.end_fill()
screen.update()

Koch Antisnowflake (Source Code)

In Koch snowflake, the line curves outward. Draw Koch Antisnowflake where lines curve inward as shown here:

Recursion Depth 0
Recursion Depth 1
Recursion Depth 2
Recursion Depth 4
Koch Antisnowflake with Python Turtle

Source Code:

import turtle
import math

screen = turtle.Screen()
screen.title('Koch Antisnowflake - PythonTurtle.Academy')
screen.setup(1000,1000)
screen.setworldcoordinates(-1000,-1000,1000,1000)
turtle.speed(0)
turtle.hideturtle()
turtle.fillcolor('blue')

def koch_anti(x1,y1,x2,y2):
    dist = ((x2-x1)**2+(y2-y1)**2)**0.5
    if dist<50:
        turtle.goto(x2,y2)
        return
    direction = math.atan2(y2-y1,x2-x1)
    px1, py1 = x1+dist/3*math.cos(direction), y1+dist/3*math.sin(direction)
    px2, py2 = px1+dist/3*math.cos(direction-math.radians(60)), py1+dist/3*math.sin(direction-math.radians(60))
    px3, py3 = x1+2*dist/3*math.cos(direction), y1+2*dist/3*math.sin(direction)
        
    koch_anti(x1,y1,px1,py1)
    koch_anti(px1,py1,px2,py2)
    koch_anti(px2,py2,px3,py3)
    koch_anti(px3,py3,x2,y2)

turtle.up()
turtle.goto(800,-600)
turtle.down()
koch_anti(800,-600,-800,-600)
koch_anti(-800,-600,0,-600+1600*3**0.5/2)
koch_anti(0,-600+1600*3**0.5/2,800,-600)