Procedures and Variables

Turtle Drawing (Procedures and Variables)

Turtles can be instructed to draw in the same way as MicroWorlds predecessor LogoWriter did. The following procedures use variables (parameters) that can be passed from one procedure to another to allow the turtles to draw shapes of different sizes.

The second procedure (triangles) sets the side length to 100 then repeats 50 times a calling routine which draws the triangle, reduces its size by 2, moves a little then draws the triangle again, reduces its size by 2 and so on.
100 - 50*2 = 0
The size of the triangle ends up at zero.

Enter the following procedures in the procedures page

to triangle :s
   repeat 3[fd :s rt 120]

to triangles
   make "s 100
   repeat 50[triangle :s make "s :s - 2 pu rt 30 bk :s / 8 lt 30 pd]

Now create a button with the instruction triangles which should draw the 50 triangles that start with a side length of 100 and reduce in size to zero.

Question. What happens if the size reduces past zero?

Clean Screen

Create a button with the instruction Clean to clean the screen when required.

A Square Cylinder

The following procedures are similar to triangles above. The effect is to draw 20 diminishing squares starting with a side length of 100 and reducing by 5 each time for 20 times so that the size reduces to zero.

Enter the following procedures in the procedures page then create a button called cylinder to draw it.

to square :s
    repeat 4[fd :s rt 90]

to cylinder
    make "s 100
    repeat 20[square :s make "s :s - 5 pu rt 30 bk :s / 8 lt 30 pd]


Use the triangles and square cylinder procedures to help you draw a spiral. Do this by firstly writing the circle procedure hint: repeat 50[fd 1 rt :s] Then create a calling procedure called Spirals that will draw 20 dimiinishing circles starting with size 10 and reducing by 1 each time. Hint: repeat 20[circle :s make "s :s - 1 pu rt 30 bk :s / 8 lt 30 pd]

Create a button with the instruction Spirals then test your work.

Question. What happens if you call the spirals procedure 20 times repeat 20[spirals]?


Write the following star and bigstar procedures on the procedures page, then create a button to draw bigstar.

to star :length
    repeat 24[fd :length lt 150]

to bigstar
    repeat 24[fd 200 lt 150 star 20]

Save, have your procedures and answers checked and you can move on to the Flying Cars task.


Geoff Adcock
Last Update: 22-Oct-2006