Professional Documents
Culture Documents
Control
&
Elementary
Programming
Course
601
back forward
right left
bk fd rt lt
penup pendown showturtle hideturtle
pu pd st ht
602
repeat 2 [ fd 30 rt 90 fd 50 rt 90 ]
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?
Yellow
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:
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.
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.
Below is a picture of a sailing ship. I used a trick called mast which was made up of
square. Have a go.
red
to square
repeat 4 [ fd 50 lt 90 ]
end
This will happen so fast that you will want to put in some wait
statements.
You can do this yourself. You need two procedures- one to draw the shape- one to make it move.
Go into edall and type in this.
TO SPIN
PPT
REPEAT 2000 [
THISSHAPE ;DRAW IT
WAIT 20
PE
THISSHAPE ;ERASE IT
WAIT 10
RT 20 ;TWIST A LITTLE
]
END
TO THISSHAPE
; YOU CAN PUT ANY SHAPE IN HERE
REPEAT 4 [ FD 50 RT 90 ]
END
Now that this works, there are many things you can do.
1. You can change the pen colour before you start . SETPC 4.
2. You can change the pensize before you start SETPENSIZE [5 5]
What happens if you change the RT 20 in SPIN to read FD 20. You could draw a little car (or
elephant) and get it drive across the screen. How? Try it!
pink
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 :sidelength is 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.
New Definition. These variables act as arguments or parameters.
We call the :sidelength in the definition, a parameter- and the number that goes into
it when it is called, the argument.
Now type
to spinner
repeat 6 [lt 30 square 70 lt 30 square 40 ]
end
Can you think of a way to write a procedure that allows you to vary the size of
square, in spinner?.
These are the commands that have been written for you.
build
lamp
wait
build
To draw the traffic light you type
To switch on the lamp- you type lamp “red “on
To switch off the lamp you type lamp “red “off
There are three lamps, red orange green. You must not
miss out the quote mark or put in a space.
Purple