← Python Foundations with Turtle

Drawing with a turtle

Give a turtle commands, in order, and watch the picture they make.

Every animation, game character and robot is moved by a list of commands that run in order. Today you give the commands.

A turtle walks across the screen, leaving a line behind. Your program tells it where to go. By the end you will draw digits, the way a calculator or a digital clock does.

Info

Meet the commands

A program is a list of commands. The turtle follows them one at a time, from the top down.

Line What it does Why
from turtle import * Gives your program the turtle commands Copy this to the top of every program for now. A later lesson shows how it works
forward(100) Moves the turtle 100 steps and draws a line The number is how far
right(90) Turns the turtle a quarter turn clockwise, on the spot It does not move or draw. 90 is a quarter of a full turn
left(90) Turns the turtle a quarter turn the other way Also on the spot, also no line
forward(100) Moves again, now in the new direction The turn changed which way is forward

The turtle starts in the middle, facing right. The order matters: swap two lines and you get a different picture.

Meet the commands · Sound on for the voiceover
PredictRead the code and say what it will do before you run anything. A wrong guess is fine: it shows you what to look for.

Predict

lesson.py
from turtle import *

forward(60)
right(90)
forward(60)
right(90)
forward(60)
left(90)
forward(60)
left(90)
forward(60)

Read the code line by line, as if you were the turtle. Which picture will it draw?

Reveal what happens
Predict · Sound on for the voiceover
What will the turtle draw?

RunRun it and compare the result with your prediction.

Run

Run the program and compare it with your prediction. Which lines did the drawing, and which only turned?

lesson.py
from turtle import *

forward(60)
right(90)
forward(60)
right(90)
forward(60)
left(90)
forward(60)
left(90)
forward(60)
Try it yourselfYour edits are saved in this browser.
InvestigateTrace how each line of code connects to what you see.

Put the lines in order

Look at the picture, then put the lines in order.

lesson.py
forward(60)
left(90)
forward(40)
right(90)
forward(60)
Show the picture to match
The picture to match · Sound on for the voiceover

These five lines are mixed up. Put them in the order that draws the picture.

Pieces (click to add)
    Your program

      MakeBuild something new using what you have learned. Expect a few tries; that is normal.

      Make

      Draw a 4 like the one on a calculator: a short stroke down, a bar across, then one long stroke from top to bottom. Use bars of 50 steps. The turtle may draw over a line it has already drawn, so you do not need to lift the pen.

      Try it yourselfYour edits are saved in this browser.
      Need a hint?

      Start at the top left. The first stroke goes down 50, then across 50 to the right, then up 50 to the top.

      Another hint

      You can go back over a line you already drew. After the stroke up, turn right twice (right(180)) and go down 100 for the long stroke.

      Show what the 4 should look like
      The expected result: the digit 4 · Sound on for the voiceover

      Draw a 4 with forward, left and right.

        Run your program. This ticks when your code does all of the above.

        For teachers

        Students meet the turtle, read a program that draws a digital 2, learn that the order of commands is the picture, and draw a 4 themselves. About 35 minutes.

        Open the teacher guide: answers, solutions, slides and a worksheet.

        Students will be able to

        Before class

        Draw the 4 yourself. It takes two minutes, and you will see why the last turn is right(180).

        Running the lesson

        1. Meet the commands: you explain, at the board. Run the three lines live, one at a time. Say what forward and right do, that right does not move the turtle, and that left turns the other way.
        2. Predict: show the digit-2 program and take a vote before anyone runs it. Ask students to walk it as the turtle. The wrong options are two slips: thinking the turns draw, and mixing up right with left.
        3. Run: run it on the slide, then students run it themselves. Ask: which lines drew, and which only turned?
        4. Put the lines in order: students do the ordering on their own screens. Circulate; if a student is stuck, ask which way the turtle is facing after the first turn.
        5. Make: the 4. Hints are in the speaker notes. If the room is unsure, model the first stroke on the board and let students write the rest. The last stroke goes over a line already drawn, which is allowed.

        The hard part (on purpose)

        Remembering that right and left turn without drawing. Ask what the turtle did on that line, instead of telling them.

        When students get stuck

        Stretch and support

        Stretch: Draw a second digit beside the first, such as an 8 or a 7. Where does the turtle have to start?

        Support: Give the first stroke and the first turn, and ask the student to add the rest.

        Where it leads

        Next lesson: the same commands again and again. A square is eight lines written out, and a loop makes it three.

        What each step is for

        Now you can
        Next lesson2. Repeat with a loopPredict, run and change short programs that repeat lines with a loop.