Creating shapes with repeats and procedures
Drawing regular polygons with the repeat command (Year 6 Mathematics
It is possible to draw any regular polygon with one command line using repeat. For
example, a square is :
repeat 4 [forward 50 right 90]
Can you draw a triangle with the repeat command? Can you draw a hexagon? Look
for the relationship between:
? the number of repeats;
? the angle which the turtle turns at each corner.
Can you recreate these patterns?
All of them have been drawn in SuperLogo by writing a procedure to draw an initial
shape and then another procedure to draw the pattern using that shape.
Here the initial shape is a procedure called SQUARE:
to square >repeat 4 [forward 50 right 90] >end to patt3 >repeat 10 [square right 36] >end patt3 (just type the name and Logo will do it!)
Here the initial shape is a procedure called DIAMOND:
Here the initial shape is a procedure called CIRCLE.
Extend pattern making by creating and commanding additional turtles
The turtle that you always see on starting SuperLogo has the number 0. You can
make additional turtles, one at a time:
Communicate with them using the “tell” command:
st (showturtle) setshape (brings up the chooser so that you can choose the shape)
Do the same for the other turtles.
This procedure clears the screen and gets the four turtles pointing in different
>tell 0 seth 0 (setheading 0) >tell 1 seth 90
>tell 2 seth 180
>tell 3 seth 270
>tell all (next commands will affect all turtles) >end
Decide what you want your turtles to do, for example, draw circles:
>repeat 360 [fd1 rt 1]
repeat 10 [circle right 9]
? Why “right 9”? What other combinations will draw a closed pattern?
Slinky springs - what can you vary?
There are many variations, all of which will draw interesting patterns. Try moving the
turtle forward, instead of turning (change the command in the brackets). Now, try
both turning and moving forward.
There are many variables in this project: the number of turtles, the directions in
which they initially point, the shape they draw, etc. What are you going to change?
What mathematics is involved? How can you use this opportunity to extend children
mathematically? For example, can pupils describe their patterns using mathematical
Creating an animation with a background
To create an animated scene you need to draw a background and animate your turtle.
Drawing a background
Use the Windows drawing program Paint to draw a background. First you must set
the size of the screen in Paint to the same dimensions as in SuperLogo.
In SuperLogo, click Options > Set Screens. Make a note of the screen Width and
In Paint, click Image > Attributes.
Type in the Height and Width settings
from the SuperLogo screen.
Make sure the Units are set to Pixels
Click OK and paint your background.
When you have finished, save the background in the SuperLogo screens folder :
Now you can load your screen into SuperLogo. Click File > Load Screen … and
choose the background you created.
Animating your turtle
Now you need to write the program to make the turtle move on the screen.
You need to write two procedures, one called startup that sets the turtle in the correct position and one called main that contains all the movements the turtle will make. Make sure your startup procedure calls the main procedure as its last line.
Some helpful commands include:
setshape - allows you to change the picture that represents the turtle
penup - allows you to make the turtle move without drawing a line
setheading - allows you to point the turtle in a particular direction
hideturtle - makes the turtle invisible
showturtle - makes the turtle visible
playwave - allows you to choose a sound to accompany your animation
When you have finished these procedures you need to save your work as a Project.
Make sure you have selected the background screen you require. Click File > Save
Project As…Give the project a name and then click the Options button.
Make sure you have ticked the Complete
Project box, then click OK.
This will save the background and the turtle you have selected along with your
procedures. The whole animated scene will automatically begin when the project is
SuperLogo Challenge (advanced)
Design a series of probability experiments using random numbers
random 2 has two possible values: 0 and 1.
random 3 has three possible values: 0, 1 and 2.
1 is often added:
(random 2) + 1 will output the values 1 or 2.
forward 10 * random 3
? What are the possible outcomes?
repeat (random 4) + 1 [fd 30 rt 90]
? What are the possible outcomes?
What are the odds?
This procedure to draw a square uses a variable. You have to name the variable –
I’ve chosen the name side.
to newsquare :side
>repeat 4 [fd :side * 10 rt 90]
The colon has great significance – to the processor! Taken literally, :side means “the
value stored in the memory location labelled side”. Yes, this is serious programming!
This procedure generates a random number and draws a square. Then it does
exactly the same thing again, to draw a second square:
>repeat 2 [newsquare (random 2) + 1]
What are the squares that picksquare can draw? Will it draw both?
The possible outcomes are:
1 –1 1-2 2-1 2-2
What is the probability that picksquare will draw both squares (small and large)?
This procedure repeats picksquare across the screen, 26 times. How many times do you think it will draw both squares?
>cs ht pu
>lt 90 fd 386 rt 90 pd
>repeat 26 [picksquare pu rt 90 fd 30 lt 90 pd]
Type play2 repeatedly to see what happens.
Can you now change these procedures so that there are THREE possible outcomes?
Again, work out the probability of all three squares being drawn and make predictions.