Turtle Graphics

Drawing Squares in the Center of the Screen

The code section below draws two squares in the center of the screen using the turtle library:

import turtle

turtle.penup()
turtle.goto(-50,50)
turtle.pendown()


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()