Cloning in Logo Programming
Comenius University Bratislava, Slovak Republic, +421 7 602 95 284,
Imagine is a new 32-bit implementation of Logo programming language. In addition to the standard
commands and structures of Logo language, the authors have implemented objects and object operations.
This enables us to create our own classes, define their properties and then create instances of such classes
and work with them. However, we can also create one and only object and by cloning – simple clipboard
copying – create a number of the same objects. In this way children as young as ten years can program
several exciting games and at the same time become acquainted with a programming language that uses the
newest trends in object-oriented programming. In this article we have described several ways of creating
objects, instances, defining events that will be processed and we have also included several games that can
be programmed using these methods.
Keywords: object-oriented programming, simple games, Imagine, Logo
Cloning human beings and animals has been widely discussed today, especially as an important ethical issue.
However, when we say cloning, we can also mean a simple reproduction of items according to a single
design. This type of cloning has been around since the beginning of industrial production. Each of the
produced items can differ from the
others but only in some details.
Basically, each item is the same as
the others that have been produced
according to the given design. For
example, let’s have a better look at
a simple glass. It is made from
glass. It can be made from other
Picture 1: Objects around us
materials, too, although it can
hardly be made from cloth. It can
also have several different shapes, but it preserves the proportions–it is bigger in its height than in its width.
Even small children know what it is used for. In this way we can observe all items around us. Each item has
certain properties that are essential for the item’s usage. Another characteristic of an item can be its reaction
to different actions. Considering our glass again, the thing first coming to our mind is our clumsiness when
we break the glass.
If we want to introduce objects into programming for children aged 10 to 14, the approach described above
seems to be a good introduction. Together with the kids, we can pretend to be designers of every object in a
program. We will explore their common properties and whether we will need the same objects or only
similar objects. Finally, we will come up with events that the objects need to react to.
Object programming can be found in several programming languages. However, most of them contain many
additional concepts and features which may be very difficult for children to understand. For example,
defining the object with all its variables and attributes and also defining the data structures comprising the
objects. Finally, working with a data structure such as an array in the program is very complicated. This is
precisely the advantage of new programming language utilised in Imagine for young programmers. A child
can focus on what is more important in object programming: finding common properties, discovering events
the object needs to react to, determining the relationship among all single objects, and finally generalising all
We will introduce here several projects that can be completed by older children and/or parents of younger
children or together with them. We will search and design turtles, the simplest objects in the Imagine
environment. Also, we will use several basic Logo commands.
2. Photo Album
Let’s design our family photo album as our first
project. We have several pictures we would like to
show to our relatives. In most of the programs on
the Internet, by clicking the thumbnail image the
big picture will show up. In the Imagine
environment, we will design something similar.
The left part of the screen will contain the
thumbnail images; the right part will show the big
picture. At the beginning of the project we will
have only two turtles – t1 with the shape of the
big picture and t2 the thumbnail image. Let’s put
them in the screen, t1 in the middle of the right
part, t2 to the upper left corner. By clicking t2 by
the right button we will change its picture: select
Change. A dialogue will open; by selecting Set Picture 2: Photo Album
Shape we will open the chooser for a picture
selection. Let us select one of the pictures. Then, we will design an onClick event for t2 in the following
way: t1'setshape shape. One of the built-in capabilities of Imagine language is the capability of
decreasing the size of turtles: in Shape tab we can write the ratio of decrease in Scale X, for example 0.15.
We will close the chooser by clicking OK button. Now if we click the turtle-thumbnail image, the turtle t1
will have the same picture but in the original size. We can create several turtle-thumbnails: Click the turtle-
thumbnail by the right button, find option Copy to Clipboard. If we click somewhere in the screen by the
right button, option Paste from Clipboard will show up. If we select it, we will create another turtle-
thumbnail. In this way we have actually created a clone of turtle t2. It is completely identical to the one
from which we created it. It has a thumbnail image (the same as the original) and defined event onClick.
However, we want this turtle to have a different picture. Let’s click on it by the right button, select option
Change and in open chooser change its picture in the same way as we have done with the first turtle. Thus,
we have added another picture in our album.
3. Solar System
Kids can do many interesting activities without computers, for example matching corresponding items.
Matching a word with its picture in foreign language learning, matching names of planets with their distance
from the sun, creating forecast, sorting items according to their properties, simple computing, creating words
from letters, making a whole picture from its parts (puzzle) – these all are examples of such activities.
In our project, we will match the names of the planets with their pictures. We have found a scheme of
positions of the planets on the Internet. We will use this scheme
as a background in our Imagine program: let’s click the right
button, select Load Background from the menu and in the
chooser find the corresponding picture. Then in LogoMotion
we will prepare names of all the planets in a form of pictures
choosing colours and shape suitable/matching to the whole
composition. Do not forget to save the picture. Let’s go back to
124 Picture 3: The Names of
Imagine, open chooser Change. In Change, let’s change shape into a picture with names and uncheck
option PenDown. Further, let’s choose AutoDrag and Transparent Click in the Shape tab. Close the
chooser by button OK. Now we can drag the turtle representing a name of a planet to the picture of that
By cloning, we will create as many turtles as we have planets. The turtle-clones inherited all the good
qualities of their original, but at the same time, they also have the same position as the original. For the
game’s purposes we want to have all the turtles at positions shown in the picture. We will accomplish that by
? tell all each [sethomestate list pos 0]
into the command line. So far, all the planets have the same name as the first one. Let’s click the New
button button. We will get into the mode of inserting buttons. Let’s click the area where we want to have a
button. Then let’s click the mouse right button, and select Change. In the dialogue define an event onClick
as a call to procedure newGame. We will add procedure in newGame in Procedures tab:
ask all [home]
let "k shuffle [1 2 3 4 5 6 7 8 9]
ask all [ht]
repeat count all
[ask item repc all [setframe item repc :k]]
ask all [st]
After clicking this button, a different name will be set for every turtle-planet. We can match these names
with corresponding pictures by dragging.
I am sure you all are familiar with the game Dominoes. In order to design this game on a computer, first we
will need pictures of all game stones as, for example, in Logo Motion. Since we want to be able to put
stones horizontally in either direction, let’s rotate each picture into four different positions. If our pictures are
ready, let’s program the game.
Cloning game stones
Let’s design one game stone as a model with all the necessary properties: pen up, AutoDrag, and let’s stop
the automatic animation (in Shape tab check Manual Animation). We will rotate the stones with the right
button: in dialogue Change in the Events bookmark by selecting the Add button, we will add an
onRightDown event. We need to write the commands: SetFrameItem FrameItem + 1.
Now we need 27 more stones-turtles with the same properties and the same picture (it contains pictures of all
28 stones). We will create the turtles according to the turtle we have just finished. We could do that by Copy
to Clipboard but in this case we will need too many pieces so we will use the command instead:
? repeat 27 [new "1 [name (1+repc)]]
So far they all have the same picture but we know that that picture has 28 phases. We just need to choose the
corresponding phase according to the turtle’s name:
? repeat 28 [ask repc [setframe repc]]
Further, we will create a button that will shuffle the turtles at the beginning of each game and put them on
the positions in the left part of the game field. By using the New Button button of the Main bar, we will
create a button and position it in the screen and specify the onPush event in its Change dialogue:
reorder shuffle all ask all [home setFrameItem 1]
Finally, we will design the game field. It will be divided in four parts. In the left part there will be a pile of
game stones for the players to choose from. In the
lower part there will be a place for the stones that
the first player cannot use. The upper part will be
used by the other player for the same purpose. The
stones are in the middle.
Alternative solution: creating class
We can also design this game differently. Instead of
one turtle as a model, we can create a class that will
have common properties of all stones. First, we will
design an empty class:
? newclass "turtle "dominoStone 
Let us also create a variable for the class – a picture Picture 4: Variables in dominoStone class
with 28 phases:
? dominoStone'haveown "shape loadimage
In Change dialogue of this class, we will specify create all other variables pos, autoDrag, pen directly in a
line by command
They can be added using Add button. In Events for this class we will design reaction to the right mouse
click, the same that we have designed before for the turtle–model.
After creating the class, we will create all the turtles by writing line command
? repeat 28 [ask repc [setframe repc]]
The game works on the same principles as the one designed for one turtle-model. However, it has an
advantage. If we decide to add a reaction to some other events, we need only define the common class. All
the stones will react to it without any further change. In the previous project, we would have to cancel all
turtle-clones and create them again according to a new model.
5. Catch the Bunny
We will design a simple game with a rabbit jumping and hiding behind big stones. The player’s task is to
click the stone behind which the rabbit is hidden right now. In Logo Motion we will prepare a picture of a
big stone and save it into stone.lgf file.
Further, we will prepare a picture of a rabbit-turtle named rabbit with
the pen up and corresponding picture. Let’s design class bigStone:
? newclass "turtle "bigStone 
We will create variable shape and in this variable a picture of a stone:
? bigStone'haveOwn "shape loadimage "stone
Let’s create five turtles – big stones:
? repeat 5 [new "bigstone  ]
By option Move in the right-click menu, we will position the stones all
Picture 5: Rabbit over the screen. Let’s make the rabbit move:
? every 500 [rabbit'setpos ask pick allOf "stone [pos]]
The rabbit is hiding behind the stones. We can click the stones and count ourselves whether we have caught
it. However, it will be simpler and much more elegant if we let the computer do it for us. Let’s stop the rabbit
and create TextBox, in which we will record the number of correct clicks. First, write zero. Each of the
stones should be able to react to the onLeftDown event. Let us design this event in the bigStone class in its
Change dialogue in the Events tab we will add this event and write the position check of the rabbit when
this event occurs in any of the stones.
ifelse rabbit'pos = pos
[text1'setValue + 1]
[text1'setValue text1'Value – 1]
Let’s get the rabbit running again. After clicking a stone at the moment the rabbit is hiding behind it, the
number of the correct clicks will increase. If we click a stone at a moment the rabbit is not hiding behind it,
the number in textbox will decrease. Are you fast enough?
These activities present many possibilities for use when programming with kids. We tried to find activities
that would be interesting for children. First, we use objects intuitively; we copy them using Clipboard. We
have designed the Dominoes activity in both ways – by copying and also by creating a class. Thus we will
understand better the relationships between objects created by cloning and objects defined directly as
instances of a class. In the last activity, we designed a class at the beginning, and we have gradually added
the events. Thanks to this simple use of objects, we can create many interesting programs in a short time.
Those of you familiar with MyWorld environment may now understand that many activities designed in that
environment can be created in Imagine in a simple way with the knowledge we have just obtained.