top of page

## Import the Turtle

The turtle library stores all of the code to create and move an object called a turtle

â€‹

The turtle library must be imported into your Python program before you can use it to draw lines, shapes and colours.

Create a new Python program and save the file as PythonTurtle.

â€‹

Write import turtle as the first line of code.

## Basic Shapes

The turtle can be controlled by writing how many pixels it should travel forward and the angle it should point left or right.

## Moving Forwards

turtle.forward(100) will move the turtle forward by 100 pixels.

â€‹

turtle.forward(200) will move the turtle forward by 200 pixels.

â€‹

â€‹

â€‹

â€‹

When using the left command or the right command, the turtle won't actually move, but it will rotate by the number of degrees that you state.

â€‹

For example, typing turtle.left(90) will point the turtle upwards.

## Rotating Left & Right

Copy the code to the right to make the turtle draw a square.

â€‹

Then try to make:

1. A Rectangle

2. A Triangle

3. A Pentagon

4. A Hexagon

## Using Loops

You can use a for loop to repeat code.

â€‹

This is especially helpfully with intricate shapes with many sides.

â€‹

The code below will print a square but in only 3 lines instead of the 8 lines from task 2.

## Press the tab key once on your keyboard to indent your code.

Task 3 - Copy the code above to make the turtle draw a square using a loop.

â€‹

Then try to make:

1. A Heptagon

2. An Octagon

3. A Circle

4. A Pentagram (5-sided Star)

## Hint: To work out the angles, divide 360 by the number of sides.

Choose a background colour

turtle.bgcolor("red")

Choose the line size and colour

turtle.pensize(6)

turtle.color("green")

Fill a shape

turtle.color("yellow")

turtle.begin_fill()

(put your turtle's directions in here)

turtle.end_fill()

â€‹

Lift the pen

turtle.penup()
turtle.pendown()

Speed up/Slow down the turtle

turtle.speed(speed=10)

â€‹

Change the turtle's appearance

turtle.shape("turtle")

Other options include "circle" and "arrow".

Task 4 - Use the code above to make:

â€‹

1. A blue square on a red background.

2. A yellow triangle on a pink background.

3. Two different coloured circles - not touching each other.

4. Three different shapes of three different colours - not touching each other.

## Complex Shapes

â€‹

You could try:â€‹

• A Flower

• A Word (like your name - you will need to use the penup() and pendown() commands.

• A Christmas tree

• A Landscape (green ground, blue sky, yellow sun)â€‹

bottom of page