Lessons For Logo Lovers - Lesson 3



Procedures, Arguments, Colors, & Beautiful Things


SETPC - Set Pen Color

When we set a pen color, the turtle color also changes. This helps us know what color we are working with.
The command SETPC takes the argument color, but the color is specified as a number.

Here are the color numbers
  • 0 Black
  • 1 Blue
  • 2 Green
  • 3 Cyan
  • 4 Red
  • 5 Violet
  • 6 Brown
  • 7 Light
  • 8 Dark Grey
  • 9 Light Blue
  • 10 Light Green
  • 11 Light Cyan
  • 12 Light Red
  • 13 Magenta
  • 14 Yellow
  • 15 White
Try it. Change your pen color. Draw lines.
Then, draw a pentagon with 5 different-colored sides.


Procedures

You have written instructions for several different types of objects. But, what if you want to draw those objects again? You must write the instructions again, right? Well, not really. That is where Procedures come in.

A Procedure contains a list of commands that you want the computer TO do. So, if you know all of the commands for a square, you can type them into a Procedure, and then tell the computer to run that procedure.

All procedures have names. A good name for the procedure that will draw a square is SQUARE.

How do you tell the computer that you are going to write a procedure?
How does the computer know the difference between a command that you want it to run right NOW, and a set of commands that will be part of a procedure?

Of course, there is a command just for that purpose. The command is TO.
Why TO? Remember that you are teaching the computer to do something.

So, if you are going to write a procedure called Square, you type the command
to square and hit Enter.
A procedure entry box is displayed on the screen.
Type your commands in there.

Do this now. Write your procedure for a square.

Okay so far. Now what? You can write a procedure for a square, but every you time you run the procedure, the computer will draw the exact same square. Is there a better way? Absolutely! This is where Arguments come in.
These are not the kind of arguments that make you think of disagreeing with someone.
These arguments are very different!

Think about a square.
All squares have the sam RT, right?
But, you can pick anything at all for FD or BK.
Another way of saying this is that the number for FD can change, or VARY.
So, instead of typing RT with a number, we can type RT with a variable. We give variables names to identify them.

The command would look something like this:
repeat 4 [rt 90 fd length]
In the example above, length is the variable.


Now to the procedure.
length is typed into the square procedure in place of whatever number you had.
One last thing: You must tell Logo that length is a value that will be determined when the procedure is run.
This is called an argument that is passed to the procedure.
We finally got to an explanation of argument!

Now when you run your procedure, your command will look like this:

square (followed by a number) or, more exactly, square 50


The above example will draw a square with a length of 50 for all the sides.
What is great is that you can now type the same procedure name, but with a different value for length.

square (followed by a number) or, more exactly, square 200


This will create a much larger square.


Top Of Page

Return to Main Page