You can do quite a lot with just three commands: FD to go
forward, RT to turn right and LT to
turn left. Already, you have probably understood how to
make a simple shape like a square. Try typing these lines one by one
into the input box at the bottom of the commander window (don' type
what is in the brackets):
- FD 200 (go forward
200 pixels)
- RT 90
(right turn 90°)
- FD 200
- RT 90
- FD 200
- RT 90
- FD 200
- RT 90
It is also possible to have multiple commands
in a single line so you could have typed:
FD 200 RT 90 FD 200 RT 90 FD 200 RT 90 FD
200 RT 90
However this is not recommended.
Here are some common logo commands (note the
presence of spaces in many commands):
| FD 100 |
go forward 100 pixels |
| BK 100 |
go backwards 100 pixels |
| RT 90 |
right turn 90° (a right
angle) |
| LT 90 |
left turn 90° |
| PU |
pen up (no line is left as
the turtle moves) |
| PD |
pen down (a line is left as
the turtle moves) |
| HOME |
Go to the home (starting)
position (don't forget to precede this with PU if
you don't want a line to be drawn back to the home
position). |
| CS |
Clear screen (erase everything in the drawing
window) |
| PE |
PENERASE. Once you have issued this
command you can erase lines by moving over them in
erase mode. To return to normal drawing mode, issue
the command PENPAINT or PPT. |
| HT |
Hide turtle |
| ST |
Show turtle |
| SETPC [000 255 000] |
Set the pen color to green (the three whole
numbers, each between 0 and 255, give the amount of
red, green and blue, respectively) |
Challenge 2:
a triangle
Try to make the turtle draw an equilateral
triangle i.e. a triangle whose three sides are all the same
length. Hint: to draw the square you turned the turtle through a
full revolution making four turns each equal to 90° (360/4)… If
you are unable to complete this exercise ask your teacher for help.
Correcting mistakes
As you did the above exercises, perhaps you
made a mistake and are wondering how to correct it? Unfortunately
Logo does not have an ‘Undo’ command so the only way to fix a
mistake is to draw over the bad line with white ink, as if you were
using whiteout. To switch to ‘whiteout mode’ (PENERASE mode) issue
the following command: PENERASE (or just PE). After
erasing the bad line by drawing over it on white leave PENERASE mode
and return to the normal (black ink) mode by typing PENPAINT
(or just PPT).
Changing the pen colour
While in PENPAINT mode you are not obliged to
draw in black ink. You can choose between millions of colors by
issuing a command like SETPENCOLOR [000 255 000] or, in its
short form, SETPC [000 255 000]. Note that
the number part of this command consists of three numbers which
represent red, green and blue respectively. Each number must be a
whole number between 0 and 255, with 255 being the brightest. So can
you figure out what color the above command would give? It would
give bright green since the level of red is zero, the level
of green is maximum and the level of blue is zero. And this one:
SETPENCOLOR [255 000 255] ? This would be a combination of
bright red and bright blue i.e. bright magenta (a shade of
purple). And this one: SETPC [255 255 000] ? In color
addition, red + green = yellow. If this surprises you it is
because you are thinking of what happens when you mix paint, but
that's very different because paint works by subtracting
(absorbing) certain colors while your computer screen works by
adding colors, so you have to learn new rules for mixing colors.
Click here to
learn more about adding colors.
Loops
When you typed in the above commands to draw a
square you must have found it a bit tedious to type the same
commands four times. Aren’t computers supposed to be good at
automating repetitive tasks? Yes they are, and you can shorten
the above set of commands for drawing a square into a single line
like this (before you enter the new command, clear the screen by
typing CS):
REPEAT 4 [FD 150 LT 90]
This is pretty easy to understand, isn’t it –
the turtle simply repeats the commands inside the square brackets
four times. Computer programmers call such a repetition a loop
– it’s a fundamental concept in all programming languages. Notice
that you need square brackets, not the normal ones, and pay
attention too to putting spaces in the right places. The computer is
very fussy about the ‘grammar’ of the instructions, which in
computer programs is also called the ‘syntax’. In the above
line you have also noticed that we drew a smaller square than
before, only 150 pixels along each side, and that we turned left
instead of turning right.
Procedures
So now we know how to tell Logo to draw a
square for us any time we want with just a single line of
instructions but the line is rather long and hard to remember –
wouldn’t it be nice if we could make Logo draw a square simply by
issuing the command SQUARE? Try typing that now into the input box
and Logo will give you a message back that it does not understand
that word. So we will try to explain to Logo what that word means by
making a procedure called SQUARE. Here’s how to do it: In the
input box type EDIT "SQUARE (notice the
double quote)
This will open the Editor window where we will
build our procedure – you can see that the window already contains
two commands:
TO SQUARE
END
Insert a blank line between the two lines
given and then copy the long REPEAT command above into the blank
line. Now save your procedure and exit the editor by choosing Save
and Exit in the editor’s File menu. Note that you have only ‘saved’
the procedure into the Logo program – you have not saved it to disk.
However procedures can be saved to disk by choosing Save from
the File menu of the main Logo window. Logo saves all the procedures
into a single file with the extension .LGO . Only procedures
can be saved by Logo, never the instructions that you type into the
input box.
WARNING: If you load a Logo file which contains a
procedure with the same name as a procedure that is already open
then the open procedure will be lost and replaced with the one from
the disk – you must name your procedures carefully to make sure this
does not happen.
Now that you have created your SQUARE
procedure you can run it at any time by typing SQUARE into
the input box and pressing ENTER.
Variables
Of course our SQUARE procedure is rather
limited because it always produces squares with the same size (150
pixels on each side). Wouldn’t it be nice if we could choose how big
the square is to be each time we ask for a square? We will make this
possible by inventing a variable called SIZE. A variable
is like a container or a box – the contents of the box can change.
Variables are a very important part of all programming languages.
Type EDIT "SQUARE into the input box
and press ENTER to open the procedure in the Editor.
Now modify the procedure until it looks like
this:
TO SQUARE :SIZE
REPEAT 4 [FD :SIZE LT 90]
END
Notice that in the first line we have included
the name of our variable – this tells the procedure that when we run
the procedure later the command SQUARE will be followed by a number
which is to be placed into the variable called SIZE. This number
which accompanies the command is called its argument. In the
second line we see :SIZE. The colon in front of the variable
name tells the computer to retrieve the number that is stored
inside the variable – this number replaces the 150 that we used to
have as the size of the square so it becomes the new size. If the
colon were not present then Logo would not recognize SIZE as a
variable and would treat it as ordinary text, causing an error here.
When you have finished, save the procedure,
exit the editor and try running your new procedure by typing
SQUARE 200. This should cause a square to be drawn with sides of
200 pixels.
Challenge 3:
a pentagon
Try to make a procedure called PENTAGON which
draws a regular pentagon (5 sides) with a variable size that can be
included as an argument of the PENTAGON command as for the square.
Challenge 4:
a polygon
Try to make procedure called POLYGON to draw a
regular polygon. Use a variable called :sides so that the
user can request a polygon with any desired number of sides, for
example by typing POLYGON 7. Try to ensure that polygons with many sides can be drawn
without going out of the available space (difficult!!)
Challenge 5:
a flower
Make a procedure called FLOWER to generate the pretty shape
below. At first glance the pattern may seem very complex, with many
different shapes, but look again and you will see that this pattern
actually consists simply of 10 square 'petals' so all your procedure
needs to do is draw a square, then rotate a bit, then draw another
square etc. The neat thing about this procedure is that it will
contain the word 'square' - it will be the first time that you make
a procedure which uses or 'calls' another procedure. That's right -
you can have one procedure inside another one.

Challenge 6:
a house
Make a procedure called HOUSE which makes a
simple house by drawing a triangle on top of a square. Your
procedure should call the SQUARE procedure and the TRIANGLE
procedure that you have already made. You'll need to think about
what you have to do to make sure the triangle is drawn in the right
place! |
 |
Challenge 7: a village
Make a procedure called VILLAGE which draws
three evenly-spaced houses as shown below. Your VILLAGE procedure
should call the HOUSE procedure three times. At some point you'll
need to use the pen up (PU) and pen down (PD) instructions so that
you don't leave lines between the houses.

Challenge 8: a calculator (extra credit)
To get more practice with variables, let’s try
to use Logo as a calculator. Make the following procedure called
MULTIPLY: