Turtle Graphics

Drawing Two Squares with Turtle

The code section below draws two squares on the screen using the turtle library:

import turtle

turtle.pensize(5)
turtle.pencolor("Red")

turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.right(90)

turtle.penup()
turtle.backward(10)
turtle.left(90)
turtle.forward(10)
turtle.right(90)
turtle.pendown()
turtle.pencolor("Blue")

turtle.forward(120)
turtle.right(90)
turtle.forward(120)
turtle.right(90)
turtle.forward(120)
turtle.right(90)
turtle.forward(120)
turtle.right(90)

turtle.done()