Tutorial: How to Draw Football Shape with Python Turtle

In this tutorial we are going show you how to draw a basic football shape with Python’s Turtle graphics library. As seen in the next figure, football shape has two sections: red section and blue section. We are going to draw each section one by one.

Two sections of football shape

To draw the red section, we need to lift up the pen and goto the red dot and use Turtle’s circle function to draw an arc. The degree of the arc can vary, but 90 degree works good. Turtle’s pen will turn 90 degrees counter-clock wise after drawing this arc. If we set the initial heading of the pen to -45 degrees, the heading of the pen will end up to be 45 degrees after drawing the 90 degree arc – a perfect symmetry! The following is the code snippet for drawing the red arc:

r = 500
turtle.up()
turtle.goto(-r/2**0.5,0)
turtle.seth(-45)
turtle.down()
turtle.color('red')
turtle.circle(r,90)
Red Arc

The blue arc can be drawn in the similar way. The first step is to set the heading of Turtle’s pen to 135 (135 = 90 + 45) degree first and draw the 90 degree arc with circle function. The following is the code snippet:

turtle.seth(135)
turtle.color('blue')
turtle.circle(r,90)
Blue Arc

Animation of Sierpinski Triangle Tree with Turtle (Source Code)

Animate the transition from Sierpinski Triangle tree to Fractal tree as shown. This project is related to Sierpinski Triangle and Fractal Tree.

Source Code:

import turtle
turtle.title('Sierpinski Tree Animation - PythonTurtle.Academy')
turtle.setworldcoordinates(-2000,-2000,2000,2000)
screen = turtle.Screen()
screen.tracer(0,0)
turtle.speed(0)
turtle.hideturtle()

def sierpinski_tree(x,y,length,tilt,angle,n):
    if n==0: return
    turtle.up()
    turtle.goto(x,y)
    turtle.seth(tilt)
    turtle.down()
    turtle.fd(length)
    sierpinski_tree(turtle.xcor(),turtle.ycor(),length/2,turtle.heading(),angle,n-1)
    
    turtle.up()
    turtle.goto(x,y)
    turtle.seth(tilt+angle)
    turtle.down()
    turtle.fd(length)
    sierpinski_tree(turtle.xcor(),turtle.ycor(),length/2,turtle.heading(),angle,n-1)

    turtle.up()
    turtle.goto(x,y)
    turtle.seth(tilt-angle)
    turtle.down()
    turtle.fd(length)
    sierpinski_tree(turtle.xcor(),turtle.ycor(),length/2,turtle.heading(),angle,n-1)

def animate():
    global angle
    turtle.clear()
    sierpinski_tree(0,-250,1000,90,angle,7)
    screen.update()
    angle = 120 if angle <= 20 else angle-2
    screen.ontimer(animate,50)

angle = 120
animate()
screen.mainloop()

Fractal Tree with Python Turtle (Source Code)

Draw the following fractal tree with recursion. This project is related to Sierpinski Triangle Tree.

Fractal Tree with Python Turtle

Source Code:

import turtle
turtle.title('Fractal Tree - PythonTurtle.Academy')
turtle.setworldcoordinates(-2000,-2000,2000,2000)
screen = turtle.Screen()
screen.tracer(0,0)
turtle.hideturtle()

def sierpinski_tree(x,y,length,tilt,n):
    if n==0: return
    turtle.up()
    turtle.goto(x,y)
    turtle.seth(tilt)
    turtle.down()
    turtle.fd(length)
    sierpinski_tree(turtle.xcor(),turtle.ycor(),length/2,turtle.heading(),n-1)
    
    turtle.up()
    turtle.goto(x,y)
    turtle.seth(tilt+20)
    turtle.down()
    turtle.fd(length)
    sierpinski_tree(turtle.xcor(),turtle.ycor(),length/2,turtle.heading(),n-1)

    turtle.up()
    turtle.goto(x,y)
    turtle.seth(tilt-20)
    turtle.down()
    turtle.fd(length)
    sierpinski_tree(turtle.xcor(),turtle.ycor(),length/2,turtle.heading(),n-1)

sierpinski_tree(0,-250,1000,90,7)
screen.update()

Sierpinski Triangle Tree with Python and Turtle (Source Code)

Use recursion to draw the following Sierpinski Triangle the similar method to drawing a fractal tree.

Sierpinski Triangle Tree with Python and Turtle

Source Code:

import turtle
turtle.title('Sierpinski Tree - PythonTurtle.Academy')
turtle.setworldcoordinates(-2000,-2000,2000,2000)
screen = turtle.Screen()
screen.tracer(0,0)
turtle.hideturtle()

def sierpinski_tree(x,y,length,tilt,n):
    if n==0: return
    turtle.up()
    turtle.goto(x,y)
    turtle.seth(tilt)
    turtle.down()
    turtle.fd(length)
    sierpinski_tree(turtle.xcor(),turtle.ycor(),length/2,turtle.heading(),n-1)
    
    turtle.up()
    turtle.goto(x,y)
    turtle.seth(tilt+120)
    turtle.down()
    turtle.fd(length)
    sierpinski_tree(turtle.xcor(),turtle.ycor(),length/2,turtle.heading(),n-1)

    turtle.up()
    turtle.goto(x,y)
    turtle.seth(tilt-120)
    turtle.down()
    turtle.fd(length)
    sierpinski_tree(turtle.xcor(),turtle.ycor(),length/2,turtle.heading(),n-1)

sierpinski_tree(0,-250,1000,90,8)
screen.update()