Turtle

Turtle is a built in Python package that allows you to set up a canvas and control a virtual pen to draw on it.

The turtle package must be imported at the top of the program if you wish to use it. By default the turtle is ready to draw on a white canvas. If you wish to change the colour you can create a new screen. For example to make a grey canvas you use:

turtle.Screen().bgcolor("grey")

You can then create a new instance of the Turtle class and start giving it directions using the class methods. These have easy to understand names such as penup(), pendown(), left(), right(), forward(), backward() and so on.

Examine the following code:

import turtle

turtle.Screen().bgcolor("grey")

myrtle = turtle.Turtle()
myrtle.penup()
myrtle.forward(90)
myrtle.left(45)
myrtle.pendown()

def branch():
    for i in range(3):
        for i in range(3):
            myrtle.forward(30)
            myrtle.backward(30)
            myrtle.right(45)
        myrtle.left(90)
        myrtle.backward(30)
        myrtle.left(45)
    myrtle.right(90)
    myrtle.forward(90)

for i in range(8):
    branch()
    myrtle.left(45)
Turtle output
Report a Glow concern
Cookie policy  Privacy policy

Glow Blogs uses cookies to enhance your experience on our service. By using this service or closing this message you consent to our use of those cookies. Please read our Cookie Policy.