I have a difficulty with LOGO. I know it is a powerful list processing language to rival LISP and I know that it has a clever way of dealing with graphics. I know that some gifted teachers in Australia are using it with Key Stage 2 and Key Stage 3 children- the results are fantastic but
I know that A level mathmos, use LOGO for geometric investigations.
I have never seen LOGO taught for its List Processing.
I have never seen LOGO being taught in a manner conducive to an aging computer professional, who programs best in a procedural language, or out of necessity a bit of C++, or Access.
This is an attempt to give London Teachers and others the tools to use the power of LOGO in a way that their pupils can relate to. It is flawed but forms the basis of various worksheets- some more successful than others. Some only work for a limited number of teachers. Each one has been used at least once this last year. I am currently rewriting the lot be more targeted at my students.
All Program fragments are protected GNU General public license, Free Software Foundation.
Version 2 . June 1991
Section Index
Can you draw this picture?
Some commands that might help you:
back forward hideturtle right
bk fd ht rt
penup pendown showturtle left
pu pd st lt
penerase penpaint setpencolour clearscreen
pe ppt setpccs
repeat
Can you add some chimneys and trees in the garden?

Try drawing this picture
Can you add a path?
Can you add a garden?
Can you draw a row of houses?
Here are some colours
| 0 | Black | 8 | Brown |
| 1 | Blue | 9 | Ochre |
| 2 | Green | 10 | Dark Green |
| 3 | Cyan | 11 | Turquiose |
| 4 | Red | 12 | Orange |
| 5 | Magenta | 13 | Violet |
| 6 | Yellow | 14 | Gold |
| 7 | White | 15 | Grey |
You can use them in the commandsetpc n.
Some of the spellings and most unusual. Learn the ones you dont
know.

You can use the repeat command to draw shapes.
repeat 2 [ fd 30 rt 90 fd 50 rt 90 ]
What shape does this draw?
Can you use the repeat command to draw other non regular shapes?
Draw three more shapes.

Try this:
rt 30 fd 50
Copy it onto paper, write down what it does.
Do NOT clear the screen.
repeat 2 [rt 30 fd 50 ]
Copy it onto paper, write down what it does.
repeat 3 [rt 30 fd 50 ]
Copy it onto paper, write down what it does.
repeat 4 [rt 30 fd 50 ]
Copy it onto paper, write down what it does.
What will you need to type to finish the shape?
Could you draw the whole shape using just one line of instructions?
How?
How can you use Logo to draw a circle?
Hint: Try drawing a square,
a pentagon
a hexagon
a decagon.
Big Hint:
repeat x [ fd y rt z ]
| Name |
x |
y |
z |
x times z |
| Square | 4 | 50 | ? | 360 |
| Pentagon | 5 | 50 | 72 | ? |
| Hexagon | 6 | 50 | ? | ? |
| Decagon | 10 | 50 | ? | ? |
What do you notice about your three key numbers?
Use your circle to draw the following patterns.
Look at those numbers again.
Try a shape where the numbers come to 240 or 300.
Try a shape where the numbers come to 720 (thats 2 times 360). What happens?
Predict what will happen with two other numbers that come to 720- try it. Were you right.
Predict another number that will do the same. Try it. Were you right.
Here are some LOGO commands . Each command must be followed by a space and a number
· fd
· bk
· rt
· lt
· setpc (between 1 and 16 )
· setfc (between 1 and 16 )
Can you discover what each command does?
Now try the command: cs
( this does not need to be followed by a number)
What does it do? Now use these commands to draw a simple picture.
Draw a square. Now move the turtle inside the square using he above commands.
Type
setfloodcolor 5 ;setfc
fill
What happens?
You won't be able to see your turtle any more but it is still there.
See if you can move it outside the square again.
Big hint:
If it goes rt 30 fd 40to get it back you must reverse its actions so it will gobk 40lt 30.
Its called the Reverse path principle. We often have to reverse the turtle to get it back to the start.
Can you fill in some of the shapes in different colours -
For the moment, you must draw the edge of the square in the same colour as the fill .
Some useful commands:
setpc pu pd pe ppt
Figure it out.
These are all Logo commands. Can you work out what they all do? Usually you will have to put a number after them. Sometimes you need more than one!
..
hideturtle showturtle
fd bk
penup home
pendown penerase
penpaint setpc setfc
setpensize [ x x ]
fill setxy setpos
repeat circle
Often we make complicated shapes from simple shapes.

a square
a parallelogram
a rhombus
a kite
` an irregular quadrilateral
a rectangle
The command label
lets you label your drawings. You put your list of words in square brackets like these. [ ]
label [a rhombus]
Do your drawings again with the correct label underneath.
.
Type in
repeat 5 [ fd 40 rt 72 ]
What shape do you get?
Try changing the numbers in the expression
What other shapes can you draw?
Try this:
repeat 6 [ repeat 10 [ rt 96 fd 100] fd 20 rt 60 ]
If you are not sure what is happening, put in a wait. It will go slower.
repeat 6 [ repeat 10 [ rt 96 fd 100]wait
10 fd 20 rt 60 ]
You can use the repeat command to draw shapes
repeat 3[fd 50 rt 120]
What shape does this draw?
You can also embed a repeat command inside another repeat command like this
repeat 12 [ repeat 3 [ fd 50 rt 120 ] rt 10 ]
Can you explain what is happening?
Try embedding repeat commands to draw other patterns with spinning shapes.
The turtle already knows many tricks,
like:
fd bk lt rt cs setpc
and to repeat many tricks:
repeat 4 [fd 50 rt 90]
We can teach the turtle new tricks,which it then remembers. the turtle is intelligent, once it has learned square or triangle, we can just say:
square fd 50 triangle
There are two ways we can teach the turtle a square.Try this.:
edall
In the new window type this:
When it is ready- click on File/ Save &Exit
Now type
cs
square
fd 10
square
Type Edall.Now go back to the linerepeat 4,and changefd 50to
fd 60.
We see nothing till we have exited the Editor, and typed square.
Teach the turtle to draw Triangles, Stars, Pentagons,Hexagons..
Once you have taught the turtle a new trick, it remebers it till you
close the LOGO program.
Programming: Putting it together
Write a trick to draw a square and a triangle. Make sure
that the side length is the same in both shapes.
You call the editor with edall
You can now call up these tricks (real name procedures ) with other LOGO commands (real name primitives) inside another procedure.
Suppose you want your turtle to draw this.
You may already see what is wrong with this program, if not type it in and try running it-it needs a couple of extra commands.
Try writing programs to draw a space rocket or a tower block.
to square
repeat 4 [ fd 50 lt 90 ]
end
Yes it will draw a square! But we now teach the turtle ..
to spinning.square
repeat 6 [ lt 60 square ]
end
Each one of these tricks is called aprocedure. A procedure may call other procedures. The final show is called a program. Programs are made up of procedures and glue instructions to join the procedures sensibly. What does this program do?
Write your own progam to spin a shape of your choice?
Investigate the patterns you can make.
Type in this procedure. You must type it exactly and when you are finished click File/Save&Exit
to square :sidelength
repeat 4 [ lt 90 fd :sidelength ]
end
File/Save&Exit
square 20
What happens?
Now type
square 70
Investigate for other numbers.
The :sidelengthis called a variable. You can use any number of them. The name must start with a :. It is called a colon, or double dot. To the turtle it means the contents of the variable.You must list all the ones you will use on the first line of the definition. These variables act as arguments or parameters.
Investigate
to shape :angle :size
repeat 20 [ rt :angle fd :size ]
end
shape 50 50
A mini project for you. Turtle Tags.
Youve seen the tags that mysteriously appear sprayed on tube trains and uncared for walls.
Get the turtle to do a tag for you, save it in a procedure called tag.Now edit this procedure, so all the distances are multipliedby :size.
Call the procedure by typing tag 4.
Fill the screens with different sized tags.

Type in this procedure
to polygon :size :angle
repeat 10 [fd :size lt :angle]
end
Investigate
Now edit the program to read
to polygon :size :angle
while ["true] [fd :size lt :angle]
end
polygon 50 50
You may like to use the halt button.
Why did that happen. Talk turtle with a friend.- You say each command, and your friend shows you what it does with a pencil on a piece of paper. Can you find the problem?
Investigate, improve on the polygon program and try your own tests. What polygons can you make?
orange
Type this in exactly
to redcircle
set pc 4 setfc 4
repeat 360 [ fd2 rt 1]
pu
rt 90 fd 20
fill
bk 90 lt 20
end
You have defined the procedure redcircle- look in the text window (commander) and check what the computer says.
Now try running it by typing
redcircle
What happens? Look at what the computer tells you in the text window,
There are four mistakes in this procedure. Use the edall to enter the editor and cursor keys to go back and change them. (You may only see two or three at first.)
To actually tell the computer that you've edited the procedure you must File/Save and Exit. Two errors are easy to find. They are called syntax errors- errors that break the turtles rules of spelling and grammar. The other two are logical errors- thats down to you. You are correctly telling the turtle to something that you dont want. Dont believe me-type this.
redcircle
redcircle
You may need to go back and edit the procedure several times before it
works (the debugging cycle).
Here are some useful LOGO tricks. Try them.
to arcright :arc :size
repeat :arc [fd :size rt 1]
end
Now type
arcright 40 2
What happens?
Now write one called arcleft.
Now type in this procedure
to sidestep :distance
pu
rt 90 fd :distance lt 90
pd
end
Investigate what it does with + numbers and - numbers.
of houses.
Reverse path principle and
Setpc [red green blue]
Write procedures to draw curves to the left and right.
to arcleft :arc :size
repeat :arc [fd :size lt 1]
end
These can be used to draw leaves. Set the colour (setpc) to green, draw two arcs to outline the leaf. You may find it easier to write a further procedure rparcleft, that draws the arc but then reverses the turtle back to the start. Get the turtle to enter into the leaf and use the fillcommand to colour the leaf, now back it out.
Investigate : draw a field of tulips or possibly a vase full!
Experts corner
MSWLogo allows you to really experiment with colour.
setpc and setfcwork the same way.
setfc 4 -- ;is the simple form.
setfc [ 100 255 255 ] ;is the other form.
The numbers can be 0-255, the numbers red, green and blue.
We can find out what the pencolour is by
show pencolor
show floodcolor
You can also fiddle with the fill command. It can be
fill
(fill "true)
(fill "false)
It affects the parts of the screen it floods. Can you tell me how?
Here
is the sun
I wrote two procedures
arcl arcr
glued them together into
ray ;arcr arcl turn arcr arcl maybe.
I then made a procedure sun.
It called circle. Then 20 times drew an invisible spoke from a fixed point to the rim. Here I called ray.
Can you do the same? Can you make the rays fatter? Can you make the rays shorter?
yellow
Can you write a program to draw this picture?
Plan it carefully on paper.Talk Turtle with your partner.
to building
house
house
end
You have called a procedure house.
Now house will be made up of these procedures
wall.
roof.
window.
window
etc.
When you know exactly what the procedures are, write them and test them, and then assemble the final program. (Remember to Save it to Disk - village.lgo).
Some commands that might help you:
back forward hideturtle right
bk fd ht rt
penup pendown showturtle left
pu pd st lt
penerase setpencolor clearscreen
pe setpc cs
repeat while
Can you add some trees in the garden? Can you make a village?
Save your work-call it village You can use it later.
Random and programming.
I would like to tell you that if wanted to roll a dice, you could type
random 6
but it is not true. It gives numbers like 4 2 0 1 0 4 3 0 5 5 2 6 etc. The problem is the zeros. So to get a dice
1+ random 5.
Try it. Is it really random? Do 100 throws and see if you get an even number of each digit.
Can you draw a dice. You will need to use random, and lines like
if :throw=3 [threeside]
you must then use your drawing skills to draw six dice sides.
You can use
make "height 20*random 20
to draw a series of random height houses. Load back your file village.lgoYou can editsome of your procedures. Experiment with different ways of using random. Would it be better to use
make "height 20*(1+random 19)
Drunken turtle:
pd repeat 1000 [forward 10 right random 360]
green
A starry heaven makes a
nice background.
You need stars of random size.
They need to be set at random positions over the screen.
A few ideas.
Draw a procedure called star- it will need a size parameter.
Star :size
The command random 6 gives a random number between 0 and 6.
The command 5+random 6 gives a random number between 5 and 11. What does star 20 + random 40 do?
setxy 20 50 sends the turtle to a position (20,50).
The useful screen is
|
-250,150 |
||
| The screen. | ||
|
-250,-150 |
250,-150 |
To get a star at a random position one could try
setxy 250+something -150+something.else
spirals and recursion
to spiral :size
if :size > 30 [stop]
fd :size rt 15
spiral :size *1.02
end
Enjoy and experiment.
What happens when you change the numbers you see.
This procedure is called spiral, and it calls itself in line 4, which will of course call itself. lucky that we have a line that will call a stop.
This is called recursion, knowing this definition will impress others! As this call happens on the last line, it is Tail End Recursion. That will impress people even more.
Here is the template.
to name
conditional.stop
all.the.action
name
end
trees
to tree :size
if :size < 5 [stop]
fd :size
lt 30 tree :size * 0.7
rt 60 tree :size * 0.7
lt 30 bk :size
end
tree 50
And
to rantree :size
if :size < 5 [stop]
fd :size
lt 30 rantree :size * (((random 5)+5)/10)
rt 60 rantree :size * (((random 5)+5)/10)
lt 30 bk :size
end
These are examples of Non tailend recursion.
Enjoy!
What types of tree can you grow?
Bushes and trees, windswept and straight- pine trees and poplars.
Draw me a forest.
spirals
to spiral :size
;do stop.condition
if :size > 30 [stop]
;do action
fd :size rt 15
;do recursion
spiral :size *1.02
end
I took the procedure above, and changed the action, the stop conditon and the recursion. I got the diagram above.
Investigate: and explain spirals to someone who has never done one.
Observe carefully living beings like snails and sunflowers- you will
find some interesting similarities.
white
Colours look fantastic on the screen but not very good when printed on a black and white laser printer.Try this
to it :size
; do stop.condition
if :size <1 [stop]
; do action- first validate input
if :size >15 [make "size 15]
pd setfc :size setpc floodcolor
circle 30+10 * :size
(fill "true)
make "size :size - 1
; do recursion
it :size
end
This shows you the simple colours. Try setpc [100 100 250] to have great control over the tint. show pencolor prints out the list.
setpc [0 0 130] setfc pencolor is a useful way to set both pen and flood color. Press the Status button to get info on the turtle.
The three fill commands are not reliable, and are a great challenge to use. fill (fill "true) (fill "false)
The turtle cannot spell colour- he went to school in SouthPark.
repeat 255
[setpc (list repcount repcount 0) fd repcount+1 rt 70]
Here is some code.
to hump :len :ang
if lessp :len 10 [ fd :len stop]
local "bit
local "inang
make "bit :len/3
make "inang :ang+180
hump :bit :inang lt :inang hump :bit :inang
rt :inang hump :bit :inang rt :inang
hump :bit :inang lt :inang hump :bit :inang
end
to sq :size
local "ang make "ang 90
repeat 4 [hump :size :ang rt 90 ]
end
Test it with
sq 9
sq 90
sq 360
How does it work? Test
it with a triangle instead.