Thursday, April 16, 2009

Microworlds Code

Building a triangle of set size

to triangle


rt 30

repeat 3 

  [fd 100

   rt 120]

end


Building a house

to square


repeat 4

  [fd 100 

   lt 90]


end


to house

triangle

rt 150

square

end



Square of any size

to sq :size

repeat 4

 [fd :size 

   lt 90]

end



Polygon of any size

to polygon :side

repeat :side

  [fd 50

   rt 360 / :side

   ]

end 


House of any size

to tr :size

rt 30

repeat 3 

  [fd :size

   rt 120]

end


to hs :size

tr :size

rt 150

sq :size 


end


Circle of any Size 

to circle

repeat 360

  [fd 1

   rt 1] 

end

 Animation

Using the backpack set shapes to change from frog3 frog 4 frog 1 frog2….

 

Defining Red

First: draw red border

Second: right click on the red, go to edit red. Under turtle I typed the directions, rt 130, causing the turtle bounce around the circle

Two Turtles

to tree

fd 60

repeat 3

  [lt 100

   lt 30

     repeat 120 [fd 1 rt 2]

   ]

lt 155 

fd 60

end


to grass

repeat 3[lt 20

     fd 18

     lt 160

   fd 20

   rt 155

     fd 22

     lt 145

   fd 23

   rt 150

      fd 25

      lt 150

  fd 20

  rt 175]


repeat 3[lt 20

fd 18

     lt 160

   fd 20

   rt 155

     fd 22

     lt 145

   fd 23

   rt 150

      fd 25

      lt 155

  fd 20

  rt 170]


end


To Picture

cg 

jill, pu jack, pu

Jack, setpos [-40, 0]

Jill, setpos [100, 0]

jack, pd jack, tree

jill, pd jill, house

pu jack, pu

jill, fd 120, launch [jack, fd 120] 

jill, rt 180, launch [jack, rt 180]

jill, pd  jack, pd

jack, pd

jack, repeat 17 [grass]


A song!    (I bet you recognize it!)

to song

note 64 10

note 62 10

note 60 10

note 62 15

note 64 8

note 64 8

note 64 8

note 62 8

note 62 8

note 62 8

note 64 8

note 67 8

note 67 8

end

Reversing a list:

to reverse :list

        ifelse empty? :list

                [output []]

                [output fput (last :list) (reverse butlast :list)]

End

Button 1 and Reverse Output (see pic)

 


Button 2 –Song (see pic)


No comments:

Post a Comment