LOGO Procedures


Here is some Logo code you might find helpful when working with Chapters 4 and 5.
to vowelp :letter ; A predicate copied from page 64 of Computer Science Logo Style.
output memberp :letter [a e i o u]
end

to wander ; An example of using conditional statements and predicates with graphics.
 setheading random 360
 repeat 300 ~
  [
   forward 1
   wait 1
   if (lessp (first pos) -100) [turnaround]
   if (greaterp (first pos) 100) [turnaround]
   if (lessp (last pos) -50) [turnaround]
   if (greaterp (last pos) 50) [turnaround]
  ]
end 

to turnaround ; A support procedure for wander.
 setheading sum heading 180
end

to initials :name ; An example copied from page 78 of Computer Science Logo Style.
 local "result
 make "result []
 for [i 1 [count :name]] ~
     [make "result sentence :result first (item :i :name)]
 output :result
end

to addup ; An example using the "for" command.           
 make "total 0                       
 for [i 1 100]~                      
  [make "total sum :total :i]        
 print sentence [The total is] :total
end

make "coordslist [[0 0] [-100 0] [-50 50] [0 0] [25 25] [50 0] [0 0]]

to connect.the.dots :pointlist  ; An example of using the "for" command with graphics.
 pu                             ; May be useful for linear algebra midterm project.
 setpos item 1 :pointlist
 pd
 for [i 1 [count :pointlist]] [setpos item :i :pointlist]
end

to reflect :point ; A sample support procedure for the linear algebra midterm project.
 output list (product -1 (first :point)) last :point
end                           

to dilate :point ; A sample support procedure for the linear algebra midterm project.
 output sentence (product 2 first :point) (product 2 last :point)
end