LESSON 2: Procedures & the Project


[Home][Menu][Overview][Art][LOGO][Stories][Links ] [MVHS]


This lesson asssumes you have some experience with Logo. You should know all the
commands listed below, and feel comfortable in the Logo program.

Review Logo Vocabulary (and abbreviations):


Logo Command Review

Command(Abbreviation) Action
FORWARD (FD) moves the turtle in the direction
it's facing.
BACKWARD (BK) moves the turtle in the direction opposite the
one it's facing.
CLEARSCREEN (CS) clears the screen and moves the turtle to
HOME.
LEFT (LT) turns the turtle to the left.
RIGHT (RT) turns the turtle to the right.
PENDOWN (PD) puts the turtle's pen down; the turtle will draw
when moved.
PENUP (PU) picks the turtle's pen up; the turtle will not
draw when moved.
HOME moves the turtle to the center or origin of the
drawing window. Sets the turtle heading to 0 -
makes it point to the top of the screen.

Procedures:


Do not be frightened by that word!

A Procedure is just a collection of Logo commands that performs a specific task.

Thus, BACK is a procedure that tells the turtle how to move backwards. All of the
procedures that the turtle is 'born' knowing - BACK, FORWARD, LEFT, and
RIGHT, for example - are sometimes called Primitives, to indicate that these are the first
or basic things the turtle can do! You don't have to teach the turtle how to move forward or
turn right, it already knows how!

Fortunately, the turtle is able to learn new procedures! You can teach it how to do specific
things - draw a square, for example. Here's how:

Let's begin with a square. You are going to draw a square with sides that are 50 turtle
steps or pixels long. First, clear the graphics window with CG, then type:

FD 50
RT 90
FD 50
RT 90
FD 50
RT 90
FD 50
RT 90


You screen should look like:
So, the turtle has drawn a square! However, every time you want it to draw a square, you
need to type all of those commands again!

Not unless you write a Procedure to draw a square! Type TO SQUARE and press
<RETURN>. The 'Edit' window should appear or become active, the words 'TO
SQUARE
' should be on the top line, and the cursor (the flashing line that shows where
the next character you type is going to go) should be on the next line below the 'T' in TO.

The window should look like this:

Now, type all of the commands to draw a square. That is, type:

FD 50
RT 90
FD 50
RT 90
FD 50
RT 90
FD 50
RT 90


The turtle needs to know where the end of the procedure is. To indicate this, type END
and press <ENTER> - make sure you type <ENTER> and not <RETURN>.
The phrase 'SQUARE defined' should appear in the Logo window.

The END primitive shows turtle where the list of commands in the procedure stops.
Pressing the <ENTER> key defines the procedure; that is, the turtle learns how to
SQUARE. Try it: clear the graphics window by typing CG. Now, type SQUARE.
Did the turtle draw your square? If not, make sure you typed everything correctly and used
the appropriate keys!

Notice that you typed only SQUARE, not TO SQUARE. Remember, TO means that
you are going to teach the turtle how to do something by listing ta set of commands. Once
you defined the procedure SQUARE, you could use it just like an other Logo command.
To see this, let's try a few experiments.

Clear the graphics window. Now, type

FD 50
SQUARE


You should see:

It does not matter that you moved before you drew the square; the turtle just does the
commands in the procedure SQUARE right where it is! Clear the graphics window, then
type

RT 90
SQUARE

The turtle draws:

Again, it does not matter that you turned before you typed SQUARE, the turtle just
follows the commands in the procedure when it is told to do it!

We can think about it like this: when you tell the turtle to SQUARE, it just looks up that
procedure (whose definition you created), then executes the commands in it one-by-one.

Assignments:


(1) Use the SQUARE procedure to have the turtle draw the following:



(2) Write a procedure for each of the following diagrams, using the SQUARE procedure.

Hint: since you've taught the turtle how to SQUARE, you can use that command in other
procedures! You should be able to type one command to draw each picture.


Lesson 2 Answers 1.A 1.B 1.C 2.A 2.B

Lesson 3


Copyright 1995-2000