Professional Documents
Culture Documents
FMSLogo
Using Multiple Turtles
Like many implementations, FMSLogo supports multiple Turtles. These extend the
possibilities for graphical work as well as opening up experiments on interacton
between Turtles.
This workbook aims to provide some fairly straightforward examples based on my
own initial explorations. IT IS A WORK-IN-PROGRESS AND IS STILL CHANGING.
Some of these activities are repeated in my workbook on using bitmapped Turtles
(see Activity Book 3: "Using Bitmaps").
Snail Races is a project workbook on my site that uses multiple bitmapped Turtles
and pixel checking (see below).
You could also look at Chapter 11 in The Great Logo Adventure by Jim Muller
which has some interesting ideas to explore. I have reproduced his predator-prey
model in a separate workbook.
Overview
FMSLogo supports unlimited turtles; each is numbered. The default Turtle is zero.
Each Turtle has its own state properties, i.e. its own heading, position and pen
control.
In addition, if you want to, each Turtle can be given its own individual pen.
The more Turtles you use the slower Logo will go.
When using multiple turtles always use consecutive index numbers. If you use non-
consecutive numbers Logo assumes all the Turtles in between require processing.
CLEARSCREEN always resets all turtles to their default state, i.e. showing and with
the pen down, except Turtle 0 (the default) which retains its penstate and its
hide/show mode.
Commands used
A few additional commands are available. See FMSLogo Help > Contents >
Graphics > Multiple Turtles.
Commands specific to bitmapped Turtles are also covered in Using Bitmaps: Part 3
Bitmapped Turtles
To simplify managing multiple Turtles a little, Turtles 1 - 8 are used. Turtle 0 is
ignored unless used for general purpose tasks such as drawing backgrounds.
REPEAT is used frequently in this workbook and particular use is made of the
system variable REPCOUNT which is simply the number of the current repetition of
REPEAT. So, e.g. this will draw four circles of increasing size:
REPEAT 4 [CIRCLE 100 + REPCOUNT * 10]
produces circles of radii 110, 120, 130, 140
And this will draw four circles of decreasing size:
REPEAT 4 [CIRCLE 100 - REPCOUNT * 10]
produces circles of radii 90, 80, 70, 60
Let's start with four Turtles and run a simple graphical routine to draw a figure
in each quadrant of the graphics screen with centres at the points as
illustrated:
We need to move each Turtle to its designated point starting point and then
draw the figures. For illustration this is done in two stages. First, position the
Turtles:
CS
ASK 1 [PU SETPO [150 150] PD RT 18]
ASK 2 [PU SETPOS [150 -150] PD RT 18]
ASK 3 [PU SETPOS [-150 -150] PD RT 18]
ASK 4 [PU SETPOS [-150 150] PD RT 18]
Next, draw the figures. An individual pattern can be made wIth a procedure
like this:
TO HEXPATTERN
REPEAT 6 [ REPEAT 6 [ FD 50 LT 60 ] LT 60 ]
END
So, taking care with the brackets make all the Turtles draw a pattern in:
ASK 1 [ HEXPATTERN ]
ASK 2 [ HEXPATTERN ]
ASK 3 [ HEXPATTERN ]
ASK 4 [ HEXPATTERN ]
Note that if you type TURTLE, Logo will report zero, showing that the default
Turtle is still active. Typing any command such as FD or RT without using
ASK will control only Turtle 0.
Activity 3. Organising
To make these actions easier to manage let's put them into some procedures:
TO SETUP
CS
ASK 1 [PU SETPO [150 150] PD RT 18]
ASK 2 [PU SETPOS [150 -150] PD RT 18]
ASK 3 [PU SETPOS [-150 -150] PD RT 18]
ASK 4 [PU SETPOS [-150 150] PD RT 18]
TO FOURHEX
ASK 1 [ HEXPATTERN ]
ASK 2 [ HEXPATTERN ]
ASK 3 [ HEXPATTERN ]
ASK 4 [ HEXPATTERN ]
END
It's easy to see that in FOURHEX there are four versions of the same
instruction, only the Turtle index changes.
TO FOURHEX
REPEAT 4 [ ASK REPCOUNT [ HEXPATTERN ] ]
END
In fact it is could often the case that the same action needs to be applied to
many Turtles. We can make our own procedure ASKALL to do this:
ASKALL 4 [HT]
or
ASKALL 4 [ST]
TO FOURHEX
ASKALL 4 [ HEXPATTERN ]
END
Now type:
Remember was said in the introduction about not asking for or activating more
Turtles than you need. The number used with ASKALL will activate that
number of Turtles. The more you use the slower everything goes.
TO FOURHEX
ASKALL 4 [SETPC 0 HEXPATTERN] ;set the pen to black and draw
WAIT 1 ;put in a delay
ASKALL 4 [SETPC 7 HEXPATTERN] ;white pen removes the pattern
WAIT 1 ;another delay
ASKALL 4 [RT 6] ;rotate the Turtles a bit
END
Try this:
Hiding the Turtles has a significant effect on the speed of the animation:
Finally we can make this group of patterns slide across the screen using
SETX and XCOR:
TO FOURHEX
ASKALL 4 [SETPC 0 HEXPATTERN]
WAIT 1
ASKALL 4 [SETPC 7 HEXPATTERN]
Experiment!
Activity 6. Particles
I am very pleased with this little activity as I sort of discovered it while writing
this workbook. I have seen things like it many times but you don't see this kind
of activity very often in Logo. My version is very simple and it is just a starting
point for something even more interesting - but at the time of writing I don't
that the time to do this.
A very good source is of course Starlogo and Mitchell Resnick's book "Turtles,
Termites and Traffic Jams." There is also the classic source book Turtle
Geometry by Abel and DiSessa and in there is simple predator-prey model.
Many other examples may suggest themselves.
'Particles' is very simple pictorially but dynamic and really very effective. The
basis of a good project.
It only works in FMSLogo because it uses the ZOOM to magnify what is in fact
a very tiny image. That's because the particles are made using SETPIXEL to
colour jus tone pixel at a time. Each Turtle simply moves about inside a box in
the form of a yellow dot.
The advantage of this is that the visibility of the dots is greatly enhanced and
because there are in reality fewer pixels being used to display the particles
(the red box is very small in normal zoom) the simulation has a faster time
cycle.
The 'bounce' algorithm I used for this simulation is very simplistic and is one of
the first aspects to improve. I started learning about dot products at this point
But it's still an interesting model and even in simple mode it can be used to
experiment with if...then type rules that test different kinds of pixel conditions.
It also illustrates a key feature of multiple turtles which is that each can have
its own behaviour.
Activity 7.
You can create your own images using any tool you like. Make sure they are
Activity 8.
Activity 9.