Lesson 1: Getting Started with Turtle Graphics

Meet the Logo turtle! He doesn't have a name. Everyone just calls him "the turtle".

the turtle

Sure, he looks like a triangle, but he's really a turtle. He's no ordinary turtle. Unlike other turtles, this one will do exactly what you tell him to do. Right now, the turtle doesn't know many tricks, but he's a fast learner and he wants you to teach him.

The turtle has a pen tied to his back, so he draws a line wherever he goes. This means you can draw pictures just by telling him to walk around.

Getting Started

Start Logo by double-clicking on the FMSLogo icon on your desktop. It looks like this: FMSLogo icon.

When Logo starts up, it looks like this:

logo start-up screen

The window up top is where the turtle lives. The window down below is where you type instructions. You can see that I have typed the instruction "forward 10".

The turtle can only follow instructions that he understands. If you give the turtle an instruction that he doesn't understand, he'll say something like "I don't know how to do that".

Here are some instructions that the turtle already knows.

Procedure Example What Happens
FORWARD number FORWARD 100 The turtle walks forward 100 screen dots.
BACK number BACK 100 The turtle walks backward 100 screen dots.
RIGHT number RIGHT 90 The turtle turns to the right.
LEFT number LEFT 90 The turtle turns to the left.
CLEARSCREEN CLEARSCREEN The turtle erases everything that he has drawn and goes back to where he started.

Activity: Go ahead and type in some instructions and see what happens. Try changing the numbers. Try changing the words. When you're done, enter "CLEARSCREEN". This will erase the image and the turtle will move back where he started.

When you say "FORWARD 10", the turtle moves forward 10 screen dots. These screen dots are also called "picture elements" or just "pixels". The bigger the number, the more the turtle moves.

But what does the number that follows "RIGHT" and "LEFT" mean? It's the number of "degrees" to rotate. So what's a "degree"? Imagine that you are hold a clock flat in front of you (the kind with hands, not a digital clock). Ahead of you is the "12"--this is a 0 degree turn. Behind you is the "6"--this is 180 degree turn. To the right is the "3"--this is a 90 degree right turn. To the left is the "9"--this is a 270 degree right turn. In fact, if you're facing the "12", to can turn to any number by rotating right that number multiplied by 30.

The relationship between clocks and degrees is no accident--they're both based on circle math. In fact, a half of a degree and a half of an hour are both called the same thing: "30 minutes".

Here are some pictures to help you remember. For every "RIGHT" instruction, there's a "LEFT" instruction that does the same thing.

RIGHT 0
RIGHT 0
or
RIGHT 360
or
LEFT  0
or
LEFT  360
RIGHT 45
RIGHT 45
or
LEFT  315
RIGHT 90
RIGHT 90
or
LEFT  270
RIGHT 135
RIGHT 135
or
LEFT  225
RIGHT 180
RIGHT 180
or
LEFT  180
RIGHT 225
RIGHT 225
or
LEFT  135
RIGHT 270
RIGHT 270
or
LEFT  90
RIGHT 315
RIGHT 135
or
LEFT  45

Teaching The Turtle to Draw a Square

The turtle doesn't know how to draw a square. We're going to teach him how, using the commands that he already knows.

First, we draw line.

FORWARD 100
FORWARD 100

Next, we make a corner by turning right.

FORWARD 100
RIGHT   90
FORWARD 100 RIGHT 90

Next, we draw another straight line.

FORWARD 100
RIGHT   90
FORWARD 100
FORWARD 100 RIGHT 90 FORWARD 100

And so on, until we have drawn the entire square.

FORWARD 100
RIGHT   90
FORWARD 100
RIGHT   90
FORWARD 100
RIGHT   90
FORWARD 100
RIGHT   90
a square

Activity: Enter the instructions above to make the turtle draw a square.

That was pretty good, but it was a lot of typing. Since most of the instructions are the same, we can simply things with the "REPEAT" command.

Procedure Example What Happens
REPEAT number [ instructions ] REPEAT 4 [ FORWARD 100 RIGHT 90 ] The turtle does the following four times: moves forward 100, turns right 90°.

With the REPEAT command, we can draw a square with just one instruction.

REPEAT 4 [ FORWARD 100 RIGHT 90 ]
a square

Even though the turtle just drew a square, he didn't learn how to draw a square. If you type in "SQUARE", the turtle will say something like "I don't know how to SQUARE". Try it.

If we want the turtle to learn how to draw a square, we have to give him an instruction that teaches him how.

We teach the turtle new instructions with the "TO" command (as in, "to do this, follow this procedure").

Activity: Press the "Edall" button and enter the following:

TO SQUARE
  REPEAT 4 [ FORWARD 100 RIGHT 90 ]
END

Now select "File -> Save and Exit" as shown here: edall.

You have just taught the turtle how to draw a square. You can make him draw one with the new SQUARE instruction.

SQUARE
a square

Activity: Teach the turtle to draw either a picture or a design. If you get stuck, you can use the sample programs below for ideas. But don't limit yourself to them. Explore what Logo can do and have fun!

When you're done, you can save your program and the picture and we'll put it on our Web page for everyone to see.

Sample Programs

TO SQUARE
  REPEAT 4 [ FORWARD 100 RIGHT 90 ]
END

TO SQUAREFLOWER
  REPEAT 18 [ SQUARE RIGHT 20 ]
END

SQUAREFLOWER
SQUAREFLOWER
TO SEGMENT
  FORWARD 20
  LEFT    90
  FORWARD 50
  LEFT    90
  FORWARD 10
  LEFT    90
  FORWARD 55

  FORWARD 55
  RIGHT   90
  FORWARD 10
  RIGHT   90
  FORWARD 50
  RIGHT   90
  FORWARD 20
END

TO PATTERN
  RIGHT 62
  REPEAT 10 [ SEGMENT ]
END

PATTERN
PATTERN
TO FANBLADE
  REPEAT 2 [
    FORWARD 100
    RIGHT   135
    FORWARD 20
    RIGHT   45
  ]
END

TO FAN
  REPEAT 8 [
    FANBLADE
    LEFT    135
    FORWARD 20
  ]
END

FAN
FAN
TO SAWTOOTH
  RIGHT   45
  FORWARD 56.56
  LEFT    135
  FORWARD 40
  RIGHT   90
END

TO SAWBLADE
  REPEAT 12 [ SAWTOOTH RIGHT 30 ]
END

SAWBLADE
SAWBLADE
TO TRIANGLE
  REPEAT 3 [ FORWARD 100 LEFT 120 ]
END

TO SQUARE
  REPEAT 4 [ FORWARD 100 RIGHT 90 ]
END

TO DOOR
  RIGHT   90 ; move into position
  FORWARD 60
  LEFT    90 ; draw the rectangle
  FORWARD 50
  LEFT    90
  FORWARD 20
  LEFT    90
  FORWARD 50
  RIGHT   90 ; return to where we started
  FORWARD 40
  RIGHT   90
END

TO ROOF
  FORWARD 100 ; move into position
  RIGHT   90
  TRIANGLE    ; draw the triangle roof
  LEFT 90     ; return to where we started
  BACK 100
END

TO HOUSE
  SQUARE
  DOOR
  ROOF
END

HOUSE
HOUSE
TO STAR
  REPEAT 5 [ FORWARD 200 RIGHT 144 ]
END
  
STAR
STAR

Challenge Questions