Logo is an ideal programming language for young students. It is a structured language, so the kids will learn good programming habits from the start. It is very visual and provides immediate feedback, as a computer "turtle" walks around the screen in response to commands. The version we are going to use is free and runs on most types of computer, but there are fancy fun versions of Logo available for those with more money (for example, check out Microworlds Logo.)
As you know, computers do exactly what you tell them to. Learning to program will help your students learn to be precise in their thinking. The computer cannot interpret a poorly phrased request, but will wait patiently for the student to decide what he or she really meant and enter a correct command. Programming may be as useful as proof writing in encouraging logical, precise thinking.
In this handout, we go through a series of exercises to familiarize
you with some basic Logo commands. (If you already know Logo, some
commands may be different from the ones you remember. Versions of
Logo differ, just like different web browsers or editors accept different
commands.) For starters, we will familiarize ourselves with the following
commands. Some commands have a short form listed. As you become more comfortable
with Logo, you will want to start using the shorthand versions of the commands.
| Command | Short Form |
| showturtle | st |
| hideturtle | ht |
| forward | fd |
| back | bk |
| right | rt |
| left | lt |
| clearscreen | cs |
| penup | pu |
| pendown | pd |
| setpencolor | setpc |
| help | help |
| repeat | repeat |
| to | to |
| save | save |
| edit | edit |
| load | load |
Install UCBLogo
or some equivalent program on your computer. Start the program and
move the windows around on the screen until you are comfortable; the one
with the black background will hold the pictures you draw, the white one
with the question mark prompt is where you enter your commands.
forward 50 right 90 forward 100The back and left commands work similarly. Try them out! Look up the short forms of these commands in the table above and see how they work. Try drawing a simple figure -- a square or triangle. (We'll draw more complicated pictures later. Be patient.)
cs pu rt 90 fd 100 pd setpc 1 rt 180 fd 100 rt 90to see what color 1 is. (Notice that we can enter two or more commands on the same line, as we did here. It is good form to always leave the turtle in the position you found it; this will be more important later on.)
help "commandname
at the ? prompt. If you don't know the name of the command, just type help and guess. Hitting enter scrolls through the help pages. Try entering:
help "setpc
(The quotes in front of the command name tell Logo to interpret the word after the quotes as a word and not a variable or procedure. If you leave out the quotes, Logo will try to "evaluate" the command, causing it to run a program and/or give you an error message.)
Now that we've learned the basics, we can play around a bit. If there's something you've been dying to try, do it now. When you're done, try entering the following commands.
cs fd 400
What happens to the turtle when it moves off the top of the screen? Experiment with rt and fd to see what happens as it moves off the edge of the screen.
Now draw a square:
cs fd 50 rt 90 fd 50 rt 90 fd 50 rt 90 fd 50 rt 90
Can you draw a triangle?
repeat 4 [fd 50 rt 90]
The repeat command performs the action in square brackets as many times as the number before the brackets. Like most computer languages, Logo is very fussy about syntax. You must use the right shape brackets and have spaces between the command, the number, and the brackets for this command to work.
Can you draw a triangle using repeat? A pentagon?
repeat 6 [repeat 4 [fd 20 rt 90] pu fd 30 pd]
but it would be far more pleasant (and readable) to just say:
repeat 6 [square pu fd 30 pd]
Using the "to" command we can define a new Logo function to draw squares. Enter the following command at the ? prompt:
to square
Notice that when you hit enter, the prompt changes shape. This is the computer's way of telling you that it's waiting for more instructions on what it means to "square". Keep typing:
repeat 4 [fd 20 rt 90] endOnce you've typed end, the computer goes back to the ? prompt; you have just told the computer that you're done defining the square command. (Note: It is a good idea to leave the turtle in the same position and orientation you started with when you define a new command. You should avoid using commands like cs or setpc when writing commands, because it will generally make them less useful to you in the future.)
Try typing square at the ? prompt. Clear the screen and try:
repeat 6 [square pu fd 30 pd]
much simpler!
save "filename
where filename is some unique name like heidislogo. By default, Logo saves the file in the program folder. You can move it to a floppy disk or delete it later. Notice that we have to use quotes again, to keep the computer from trying to evaluate our filename.
Now, type:
edit "square
at the ? prompt. A new edit window comes up. Make any changes to the square command that you feel are necessary. Then choose "Accept Editor Changes" from the Edit menu. This will return you to the Logo window, with a new improved definition of the command square.
load "filename
This will load any functions defined in the file filename.
One great thing about these Logo files is that you can open them using SimpleText! You don't need to have a copy of UCBLogo on your computer to read your programs (but since it's free, you might as well have one!)
to sq :side repeat 4 [fd :side rt 90] endTry it out!
sq 100
sq 50
You can also define functions that use two variables, and you can use functions within functions:
to twosquares :side :ratio sq :side sq :side * :ratio endYou could use the function twosquares in class to discuss the relation between ratios of side lengths of squares and ratios of areas. For example, the command:
twosquares 100 1.5
illustrates that increasing the side length of a square by half more than doubles its area!