- Low-Level Instructions
A handful of instructions suffice to begin learning how to program
in LOGO. These instructions all relate to working with the
"turtle" on the graphics screen. (Most LOGO commands can be
spelled out or abbreviated, whichever you would prefer.)
- forward
- Moves the turtle forward a specified distance or number of
steps, e.g., forward 50. Can be abbreviated to
fd 50. Typically, if the command would cause
the turtle to move beyond the screen, it will "wrap around" and
reappear on the opposite side of the screen. Most any number
can be used.
- backward
- Moves the turtle backward a specified distance or number of
steps, e.g., backward 50. Can be abbreviated to
bk 50. Most any number can be used.
- right
- Turns (rotates) the turtle a specified number of degrees to the
right, e.g., right 45. Can be abbreviated to
rt 45. Most any number can be used.
- left
- Turns (rotates) the turtle a specified number of degrees to the
left, e.g., left 45. Can be abbreviated to
lt 45. Most any number can be used.
- pen up (one word when issuing the command)
- Allows the turtle to move without leaving a trail (drawing a
line). There is no "argument" to this command, just type
penup or pu. (Originally, the
turtle was a physical robot that drew figures on paper laid down
on the floor. It had a pen that could be raised and lowered to
avoid or to allow leaving a trail.
- pen down (one word when issuing the command)
- Ensures that the turtle will leave a trail (draw a line) when
moving. Type pendown or pd.
- pen erase (one word when issuing the command)
- Allows erasing of any lines (or pieces of lines) in the path of
movement. Type penerase or pe.
As with penup and pendown, this commands sets
a condition that remains until it is reset (i.e., you will need
to issue a penup command in order to start drawing
again.
- home
- Moves the turtle to the home position facing to the top of the
screen. Type home. If you do not raise the
pen, a line will be drawn.
- clear screen (one word when issuing the command)
- Clears the graphics screen and moves the turtle to the home
position. Type clearscreen or
cs.
- Exploring LOGO Instructions
Before we start "real programming", let's get a feel for the
turtle-graphics instructions. Try out a variety of the commands
above using a variety of numbers. To do so, you make the command
window active and type the instructions. Instructions are executed
immediately when you press the return key. (The immediate execution
of individual instructions is the reason we don't consider this
programmingthe instructions are not saved for later or
repeated execution.)
As you work/explore, keep track of error messages, shortcuts,
etc. that you encounter as you work! We will share them later.
If you think they might be useful to others, announce them.
If you need some ideas for things to try out, some possibilities are
given below. Don't try to do them all. Instead, do a variety of
things. Try to use all the commands. For example, make a mistake
on purpose and see how you might correct it using pen up,
pen erase, and pen down.
- determining the size of the graphics screen
- drawing some geometric figures, e.g., triangle, square, etc.
- drawing block letters, e.g., C, E, F, G, H, I, J, L, T
- drawing a star
- drawing semi-block letters, e.g., B, D, O, P, R, S, U
- drawing the other letters,
e.g., A, K, M, N, Q, V, W, X, Y, Z
Did you notice that you can enter a combination of instructions on
one line? For example, to draw a square you could put one
instruction per line or you could enter
fd 100 rt 90 fd 100 rt 90 fd 100 rt 90 fd 100
Discussion ...
- What error messages have you encoumtered?
- What neat capabilites did you encounter?
- if not already noticed, have participants type the above
instructions on single line and press the Enter key.
Then have them use the arrow key to move up one line (to that
same line) and press Enter again. Is the drawing what
you would expect?
- Repeating Instructions
When making the geometric figures, you probably used the same (or
similar) combination of instructions several times. For example, a
square can be drawn with
fd 100 rt 90 fd 100 rt 90 fd 100 rt 90 fd 100
You could accomplish (almost identically), the same task with
repeat 4 times [ fd 100 rt 90 ]
(There will be an error. Can you find and correct it?)
Discussion ... [have participants do as abovemove the
cursor up one line to the previous instruction(s) and press the
Enter key. What is different? ]
Draw some figures using the repeat instruction. A few
notes:
- we normally do not abbreviate the word repeat
- any combination of known instructions can be placed within the
brackets (we call the contents of the brackets the
scope of the repeat instruction)
- where spaces exist in instructions there must be one or more
spaces. The computer doesn't care if more than one space is
used. We generally put extra spaces in to help human readers
more easily understand what is happening. Later you'll see
that might use several lines of indented material as the scope
of a repeat statement.
You might consider having a repeat instruction inside a repeat
instruction. A spirograph might be the result.
- A Brief CS Note
We have seen two ways to draw a square:
fd 100 rt 90 fd 100 rt 90 fd 100 rt 90 fd 100
repeat 4 times [ fd 100 rt 90 ]
Do these two techniques do the same thing? [no]
Do they accomplish the same task? [yes, you could say so.]
The difference occurs with the status of the turtle. In the first
example the turtle is pointing to the left but in the second
example it points to the top of the screen. Subtle differnces like
this can have an impact when instructions build on other
intructions. Good programming practice requires that programmers
be alert for these situation. A good rule of thumb is, "leave
the tutle in the same state as you found it.
- Defining New instructions
Programming would be very tedious if we were limited to using only
the instructions "built into" a language. We can define our own
instructions by combining the builtin instructions into a new, named
instruction. Then we can use newly defined (and named) instructions
as we build other new instructions. Defining instructions requires
that we:
- determine how the new instruction is to be accomplished using
existing instructions
- enter those instructions in the editor window
- name the new instruction
- make sure the system knows about the new instruction
- and, we should probably make sure the new instruction actually
does what we intend for it to do
Let's try this out by define a new instruction draw square.
- we already know how to draw a square
- activate the editor by invoking it by typing to square
in the command window or by typing the command
edit square in the listener window. A new, editor
window for editting the procedure should appear. The procedure
name (square) will be identified.
- enter the instructions necessary for drawing a square
- define the instructionclick the Define button.
- save the file
- select Save or Save as from the File
menu
- name the file (some variation of "square")
- locate your folder in the dialog window
- click Save
- make sure you were successful (open the My Computer
icon, dodea on 'Student' (Z:) disk
[check to be sure all participants were successful.]
- activate the command window and test your new instruction.
- test your new instruction by creating another new instruction,
that draws a square and then draws another square.
Discussion ... questions? comments?
Combine your knowlegde of repeating instructions and defining new
instructions. Have your turtle draw some diagrams that have
constituent parts, e.g., house, car/truck/bus, etc.
- Teaching Implications
[After 20-30 minutes of exploration, have participants save their
work and prepare for dicussion. Ask: what did you enjoy learning?
what else would you like to learn? ... ]
What are your thoughts about teaching this material to your students?
Some questions you might want to consider are:
- What parts of what we've done so far are inappropriate for your
students? Why/how so?
- What questions remain about what we've been working with? What
else do you need to know in order to teach the same material?
- Conjecture: the amount of instruction given so far provides a
good beginningmore would be too much and less would be too
little. What do you think?
- What questions would be good to ask students?
- Did we move too slowly? too quickly? How much time would be
required to take your students through the same material?
- What would you like to do differently?
- What other programming tasks might be useful?
- ?