You are on page 1of 13

11/23/2014

Lesson 1: Getting Started with Turtle Graphics

Lesson 1: Getting Started with Turtle Graphics


Meet the Logo turtle! He doesn't have a name. Everyone just calls him "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 MSWLogo icon on your desktop. It looks like this:

When Logo starts up, it looks like this:

http://fmslogo.sourceforge.net/workshop/getting-started.shtml

1/13

11/23/2014

Lesson 1: Getting Started with Turtle Graphics

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.
http://fmslogo.sourceforge.net/workshop/getting-started.shtml

2/13

11/23/2014

Lesson 1: Getting Started with Turtle Graphics

BACK number

BACK 100

The turtle walks backward 100 screen dots.

RIGHT number
LEFT number

RIGHT 90
LEFT 90

The turtle turns to the right.


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
http://fmslogo.sourceforge.net/workshop/getting-started.shtml

RIGHT 45

RIGHT 90

RIGHT 135
3/13

11/23/2014

Lesson 1: Getting Started with Turtle Graphics

or

or

RIGHT 360

LEFT

or
315

LEFT

or
270

LEFT

225

or
LEFT

or
LEFT

360

RIGHT 180

RIGHT 225

RIGHT 270

RIGHT 135

or

or

or

or

LEFT

180

LEFT

135

LEFT

90

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.
http://fmslogo.sourceforge.net/workshop/getting-started.shtml

4/13

11/23/2014

Lesson 1: Getting Started with Turtle Graphics

FORWARD 100

Next, we make a corner by turning right.

FORWARD 100
RIGHT
90

Next, we draw another straight line.

http://fmslogo.sourceforge.net/workshop/getting-started.shtml

5/13

11/23/2014

Lesson 1: Getting Started with Turtle Graphics

FORWARD 100
RIGHT
90
FORWARD 100

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

FORWARD
RIGHT
FORWARD
RIGHT
FORWARD
RIGHT
FORWARD
RIGHT

100
90
100
90
100
90
100
90

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.
http://fmslogo.sourceforge.net/workshop/getting-started.shtml

6/13

11/23/2014

Lesson 1: Getting Started with Turtle Graphics

Procedure
REPEAT number [
instructions ]

Example

What Happens

REPEAT 4 [ FORWARD 100 RIGHT The turtle does the following four times: moves forward 100, turns
90 ]
right 90.

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

REPEAT 4 [ FORWARD 100 RIGHT 90 ]

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

http://fmslogo.sourceforge.net/workshop/getting-started.shtml

7/13

11/23/2014

Lesson 1: Getting Started with Turtle Graphics

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

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

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
http://fmslogo.sourceforge.net/workshop/getting-started.shtml

8/13

11/23/2014

Lesson 1: Getting Started with Turtle Graphics

TO SQUARE
REPEAT 4 [ FORWARD 100 RIGHT 90 ]
END
TO SQUAREFLOWER
REPEAT 18 [ SQUARE RIGHT 20 ]
END
SQUAREFLOWER

TO SEGMENT
FORWARD 20
LEFT
90
FORWARD 50
LEFT
90
FORWARD 10
LEFT
90
FORWARD 55
FORWARD
RIGHT
FORWARD
RIGHT
FORWARD
RIGHT
FORWARD
END

55
90
10
90
50
90
20

TO PATTERN
RIGHT 62
http://fmslogo.sourceforge.net/workshop/getting-started.shtml

9/13

11/23/2014

Lesson 1: Getting Started with Turtle Graphics

REPEAT 10 [ SEGMENT ]
END
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

TO SAWTOOTH
http://fmslogo.sourceforge.net/workshop/getting-started.shtml

10/13

11/23/2014

Lesson 1: Getting Started with Turtle Graphics

RIGHT
FORWARD
LEFT
FORWARD
RIGHT
END

45
56.56
135
40
90

TO SAWBLADE
REPEAT 12 [ SAWTOOTH RIGHT 30 ]
END
SAWBLADE

TO TRIANGLE
REPEAT 3 [ FORWARD 100 LEFT 120 ]
END
TO SQUARE
REPEAT 4 [ FORWARD 100 RIGHT 90 ]
END
TO DOOR
RIGHT
FORWARD
LEFT
FORWARD
LEFT
FORWARD
LEFT
FORWARD
RIGHT
FORWARD
RIGHT
END

90 ; move into position


60
90 ; draw the rectangle
50
90
20
90
50
90 ; return to where we started
40
90

TO ROOF
FORWARD 100 ; move into position
RIGHT
90
TRIANGLE
; draw the triangle roof
LEFT 90
; return to where we started
http://fmslogo.sourceforge.net/workshop/getting-started.shtml

11/13

11/23/2014

Lesson 1: Getting Started with Turtle Graphics

BACK 100
END
TO HOUSE
SQUARE
DOOR
ROOF
END
HOUSE

TO STAR
REPEAT 5 [ FORWARD 200 RIGHT 144 ]
END
STAR
http://fmslogo.sourceforge.net/workshop/getting-started.shtml

12/13

11/23/2014

Lesson 1: Getting Started with Turtle Graphics

Challenge Questions
Why is asking the turtle to turn by an amount greater than 359 unnecessary?
How can you draw something with curvy lines, like a circle?
How can you turn left by using the RIGHT command?
How can you go backwards using just the FORWARD command?
Why is giving two move instructions in a row unnecessary?
Why is giving two turn instructions in a row unnecessary?
How can you create a solid shape, like a square whose insides are completely black?

http://fmslogo.sourceforge.net/workshop/getting-started.shtml

13/13

You might also like