Vtech Power Zone 2000 User Manual - Page 35

draw a 50-step square, square 100 will

Page 35 highlights

end This routine contains a lot of repetition. Routines can be written more concisely using a repeat command: to square : n repeat 4 [forward 30 right 90] end The repeat command has two sets of additional information or input - the number indicating the number of times to repeat the command ("4") and the list of commands to be repeated ("forward 30 right 90"). Once this routine is defined, one need only to write "square" and LOGO will draw a 50-step square at the current Turtle location. This routine can be further improved because as it is, it can draw squares of only one size. To enable it to draw squares of varying sizes, define the command with an 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 need only write "square 25" and LOGO will draw a 25-step square at the current Turtle location. "Square 50" will have LOGO draw a 50-step square, "square 100" will have 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 back :n square :n forward :n triangle :n 27

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47

27
end
This routine contains a lot of repetition. Routines can be written more concisely
using a repeat command:
to square : n
repeat 4 [forward 30 right 90]
end
The repeat command has two sets of additional information or input - the number
indicating the number of times to repeat the command (“4”) and the list of
commands to be repeated (“forward 30 right 90”). Once this routine is defined,
one need only to write “square” and
LOGO
will draw a 50-step square at the
current Turtle location.
This routine can be further improved because as it is, it can draw squares of
only one size. To enable it to draw squares of varying sizes, define the command
with an 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 need only write
“square 25” and
LOGO
will draw a 25-step square at the current
Turtle location.
“Square 50” will have
LOGO
draw a 50-step square, “square 100” will have
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
back
:n
square :n
forward :n
triangle :n