Centralia Junior High School
Centralia, Illinois
Math and Computers
(All rights reserved. Do not reproduce without permission.)

Procedures used in LOGO Class

These procedures work with pcLogo, Harvard Associates, Inc.

to sq
repeat 4 [ fd 40 rt 90 ]
end
This is our first procedure. We are teaching logo its "first word". This procedure draws a size 40 square.
to flower
repeat 10 [sq rt 36]
end
This "flower" is made of 10 squares spun around in a circle. Notice that it is repeated 10 times and turns 36 degrees each time (10 x 36 = 360). Make sure Logo knows how to sq.
to bouquet
repeat 6 [flower fd 80 lt 60]
end
This bouquet is made of six flowers. Isn't it amazing what Logo can make with squares? Bouquet goes with flower and sq.
to sqr :n
repeat 4 [fd :n rt 90 ]
end
This is a new procedure to draw a square. It uses a variable (changable number) :n . Now we can make different sizes of squares. SQ 20 makes a size 20 square and SQ 80 makes a size 80 square.
to cnt :n
if :n > 20 [stop]
pr :n
cnt :n + 1
end
This procedure teaches Logo how to count (CNT for short). It uses recursion (CNT does itself over and over again). It follows the couning pattern (:n + 1). When you count you always add one to get the next number.
to sqrs :n
if :n > 150 [stop]
sqr :n
sqrs :n + 10
end
This procedure combines counting and making differnt size squares. Use it with sqr. Instead of counting by ones it counts by tens (:n + 10) and instead of printing the numbers (PR) it makes squares (SQR :N) with the numbers. Pretty cool, huh?
to poly :s :x
repeat :s [ fd :x rt 360 / :s ]
end
This procedure can make any regular polygon with any
number of sides (variable :s) and any size side
(variable :x). Why is the right turn (RT) 360 divided
by :s ?
to spiral :s
if :s > 200 [stop]
fd :s
rt 119
spiral :s + 2
end
This is an interesting sprial design. It uses recursion, a pattern of counting by 2 and turns 119 degrees, only one degree less than an equilateral triangle. This makes it look like it spins.
to add :n :e :t
if :n > :e [pr [----] pr :t stop]
pr :n
add :n + 1 :e :t + :n
end
What if you had to add all the numbers from one to a hundred? ...or to one thousand?
to paint
if button? 2 [pr [Paint Stopped.] stop]
if button? 1 then pd else pu
setxy mouse
if key? [menu]
paint
end

to menu ; Goes with paint.
make "key rc
if :key = "r [setpc 12] ; red
if :key = "b [setpc 9] ; blue
if :key = "g [setpc 32] ; green
if :key = "y [setpc 14] ; yellow
if :key = "w [setpc 15] ; white
if :key = "0 [setpc 0] ; black
if :key = "1 [setwidth 1] ; line width 1
if :key = "3 [setwidth 3] ; line width 3
if :key = "5 [setwidth 5] ; line width 5
if :key = "c [cs] ; clear the screen
if :key = "f [pd fill pu] ; fill an enclosed area
if :key = "s [pd repeat 5[fd 10 rt 144] pu] ; star
end
Teaching Logo how to paint with the mouse.

[ Return to Main Logo Page ] [ Return to CJHS Page ]