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.
(1) Use the SQUARE procedure to have the turtle draw the following: Answer 1.A SQUARE RT 90 FD 50 LT 90 SQUARE RT 90 FD 50 LT 90 SQUARE Answer 1.B SQUARE FD 50 SQUARE RT 90 FD 50 SQUARE Answer 1.C LT 45 SQUARE (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. Answer 2.A TO DICE FD 50 LT 90 SQUARE LT 180 FD 50 LT 90 SQUARE LT 180 FD 50 LT 90 SQUARE LT 180 FD 50 LT 90 SQUARE LT 180 END Answer 2.B TO FOURTITLTED LT 45 LT 90 SQUARE LT 90 SQUARE LT 90 SQUARE LT 90 SQUARE END
Copyright 1995-2000