Skip to content
School of Physics
Home Our Teaching Resources C programming mrturtle.html
Back to top

Mr Turtle

Mr Turtle (or ACSlogo as he is formally called) is a well-known teaching tool. We will only be playing with him for this one week. So make the most of him!

For this week only we suggest you work in pairs. Do not print out this page: work from the web as there are some examples to copy and paste.

Before we start it's worth noting that Mr Turtle has his own rather unique language and syntax (he's a turtle after all) and we won't be using all his capabilities. It's the discussions you will have with your partner that will be the most useful part of today's exercise so don't get too worried about the details of how you do things: concentrate on the principles.

For some of the tasks we will tell you what to do and ask you to work out what will happen when you do it. If what happens isn't what you expected, try to work out why it did happen. Other tasks will ask to to combine aspects of two of the previous tasks to do something new.

This is a whole week's practical work so expect it to take several hours.

First, get hold of ACSlogo by clicking on the background of your Desktop so that the word Finder appears at the top left then from the Go menu choose:

Go -> Connect to Server

In the box type cytosine1.ex.ac.uk and press Connect.

After you have logged in select Users. Inside there open Modules then PHY2004 and grab the coloured Logo application from there.

Copy the application to your Desktop, do not open it directly from the server. You should only need the application, not the folder.

Once it's on your desktop, start the application. I recommend setting ACSLogo -> Preferences -> Turtle Speed to about 75%

Make the window with the turtle in quite big.

Controlling the turtle

The text document that opens is a bit like a word-processor: You type in commands (one per line is easiest); to execute a single line of commands click on it and choose
Don't just press Return on its own, that does something entirely different.

Special -> Execute or use the Apple-Return shortcut.

Some useful commands:

forward 100

left 45

right 90

forward 282


clearscreen

You can build up a simple sequence of command lines (use copy and paste if you like) and execute them all at once by highlighting the set of lines to execute then typing Apple-Return.

You may find that copying examples from this web page gives the text a pale blue background. That does not mean it is selected.

For example, copy the following into the control window, highlight all nine lines and press Apple-Return

clearscreen
forward 100
right 90
forward 100
right 90
forward 100
right 90
forward 100
right 90
Play around a bit to get the idea, then move to task 1. (It's worth noticing that Mr Turtle doesn't care too much about new lines: we can put two commands onto one line or split a single command over several lines as we wish.)

Task 1: draw a house

Draw the classic line-drawing of a house (a square with the two diagonals and a roof) without going over any line twice.

Discuss

  • Is it easier to build it up one bit at a time or to go for it all at once?
  • Did anybody manage, or even try, to type it all in one go and have it work first time?

Task 2: teaching Mr Turtle a new trick

A procedure is just a fancy name for a command we can teach Mr Turtle, in the same was that we might teach a dof to sit

Open Window -> Show Procedures This brings up a window. Click the "New" button at the bottom left. Replace the word "newproc1" by the word triangle. In the large box at the lower right paste:

forward 100
left 120
forward 100
left 120
forward 100
left 120
Click "Apply" and close the window.
  • What do you think will happen if you type triangle into the command window and press Apple-Return? Try it.
  • What would have happened if we had called the procedure "square"?

Task 3: teaching Mr Turtle to draw a house

Previously we have created a sequence of commands to draw a house and then defined a new, single command to draw a triangle. Now we will combine these two concepts together to create a new command to draw a house.

Bring the "procedures" window to the front, and click the "New" button at the bottom left.

Replace the word "newproc2" by a suitable name for your new procedure (or command).

Paste your "house" commands into the large box at the bottom right, click "Apply" and close the window.

Try it out!

Task 4: a polygon

In the triangle example above we drew a triangle simply by typing in "forward ... left" three times. Here we see another, more flexible approach.

Discuss

  • What do you think will happen if you type the following into the main window and press Apple-Return? (Don't forget to select both lines.)
make "SIDES  6 
repeat :SIDES [ forward 400/:SIDES    left 360/:SIDES ]
"

Hint: the somewhat strange syntax ":SIDES" means "the value of SIDES".

  • What would happen if the changed the "6" to 8? What would happen if you replaced all four occurrences of the word SIDES with the word AREA?

Task 5: a more-complicated pattern

Modify the above code snippet to draw a regular hexagon of triangles, i.e. six triangles such that their centres form a regular hexagon as shown above. (Do not modify the "triangle" function, rather use it unchanged inside the previous code snippet.

Your first attempt will have an irritating flaw. The commands "penup" and "pendown" may help here.

Try making a pentagon of triangles, octagon of triangles, etc.

Task 6: Teaching Mr Turtle to draw polygons

So far we have taught Mr Turtle what to do on the command "triangle" (unsurprisingly, it's to draw a triangle) and created a sequence of commands to draw an arbitrary polygon.

We can combine this "triangle" procedure and the polygon loop in a rather neat way.

Bring the "procedures" window to the front, and click the "New" button at the bottom left.

Replace the word "newproc3" by the word polygon. Click on the "Add parameter" button towards the top right and in the box just to the left headed "Parameters" replace the word "param" with the word:

SIDES
Now in the large box at the lower right paste:
repeat :SIDES [ forward 400/:SIDES left 360/:SIDES ]
Click "Apply" and close the window.
  • What would happen if you typed the following into the command window:
polygon(3)
and pressed Apple-Return?

How about:

polygon(6)

Try it.

Task 7: a scalable house

In the example above we passed the procedure a parameter, which we chose to call "SIDES". Then inside the body of the procedure we were able to use ":SIDES" (don't forget the colon) inside arithmetic expressions which was then equal to the value we passed to it from the main command line.

Modify your "house" procedure to take an argument which is the side of the main square so that you can can type in "house(100)", "house(200)" etc. (or whatever you chose to call your procedure) to draw houses of different sizes.

Task 8: lots of polygons.

Once again bring the "procedures" window to the front, and click the "New" button at the bottom left.

Replace the word "newproc4" by the word polypolygon (or make up your own name). Click on the "Add parameter" button towards the top right and in the box just to the left headed "Parameters" replace the word "param" with the word POLYS.

Click on the "Add parameter button" a second time and add a second parameter SIDES so that it now looks like:

POLYS
SHAPE
Now in the large box at the lower right paste:
pendown
repeat :POLYS [ polygon(:SHAPE) penup
                forward 1200/:POLYS left 360/:POLYS pendown 
              ]
(wee have split it over several lines for clarity but we could have had one very long line had we preferred.) Click "Apply" and close the window.

Task 9: lots of houses!

Now create a new procedure, based on the previous one, to draw a "polygon of houses", i.e. exactly the same as task 8 but houses instead of polygons. The two parameters should be the number of houses and their size. Do not worry about whether they are vertical or not.

Finally, discuss:

  • What feature(s) of this have you found the most surprising oe fun?
  • How would the things we have seen here helpm you create complicated patterns more easily than just a huge list of "forward"s and "rights"s, etc?
                                                                                                                                                                                                                                                                       

Validate   Link-check © Copyright & disclaimer Share
Back to top