26
The repeat command has two sets of variables - a number indicating the number of
times to repeat the command (“4”) and the list of commands to be repeated “(forward
10 right 90)”. Once this routine is defined, you need only to write “square” and LOGO
will draw a 10-step square at the current Turtle location.
This routine can draw squares of only one size. To enable it to draw squares of
varying sizes, define the command with the input:
to square :n
repeat 4 [forward :n right 90]
end
This command contains additional information or input “:n” which indicates the variable
size of the square. Once this routine is defined, one can write “square 25” to have
LOGO draw a 25-step square at the current Turtle location. “Square 50” will make
LOGO draw a 50-step square, “square 100” will LOGO draw a 100-step square, and
so on.
A routine to draw an equilateral triangle is as follows:
to triangle :n
right 30
repeat 3 [forward :n right 120]
left 30
end
After the routines for a square and a triangle have been defined, a routine to draw a
simple house can be made from a square with a triangle on the top:
to house :n
square :n
forward :n
triangle :n
back :n
end
VARIABLES
LOGO can interpret a string of characters in four ways:
1. Numeric value
The strings “123” and “25.6” are recognized as numeric values.
2. Command
The strings “square” and “triangle”, when created in the routines defined above,
are recognized as commands.
34600 I/M
2/28/00, 11:27 AM
26
Содержание Power Zone Edge
Страница 1: ......