Imagine a screen where there
are some turtles (objects) on the left- hand side, for example
cakes, apples and pizzas.
The user can click on such an object
and an identical copy (turtle) will be created, which can
be dragged to any place on the screen.
To remove such an object it can be
dragged to a bin. The bin is just another turtle on the
screen.

For this activity we will need three
kinds of turtles:
-
A Moveable turtle will have the autodrag
feature switched on and pen up. When clicked with the
left button (i. e. a drag operation starts) then it
goes to the front of all turtles. If the left button
is released (i. e. the dragging operation finishes)
and it is overlapped by the bin, then it is erased.
The easiest way to develop a project having
turtles of several kinds is to use classes of turtles. A
class is a predefined sample defining how all the turtles
of the same kind should behave. But unlike a turtle it does
not live anywhere and you cannot see it.
The idea of not living anywhere is especially
useful for the moveable turtle because initially we have
no such turtles created.
Type
? newclass "turtle "stack [ ]
If you look in the project explorer, you
will see a new class of turtle has been created

Now double click on the stack turtle in
the project explorer.

Click on the Events tab, then click the
Add button.

We need to add an 'onleftdown' event,
which will define the behaviour each time someone clicks
with the left mouse button on our stack turtle

Type in
new "moveable [pos ( pos ) shape (
shape )] ask lastname [startdrag]
The ONLEFTDOWN event handler creates a
new object of class MOVEABLE , sets its position and shape
to the same as the POS and SHAPE of the currently clicked
object. It then asks the newly created object ( LASTNAME
stands for the name of the recently created object) to start
dragging. It means that the new turtle will start off being
dragged by the mouse until the left mouse button is released.
In order for this to work, we need to create a newclass
of moveable turtles, that know all about being moveable.
Type
? newclass "turtle "moveable [ autodrag
true pen pu ]
Go to the project explorer and double
click on the moveable turtle class, then add events for
onleftdown and onleftup.

These two events give the moveable turtle
the behaviour of moving to the front whenever it is clicked
with the left mouse button, and the behaviour of erasing
itself if it is dropped onto a turtle with the name 'bin'.
That is it. All we need to do now is to
create some turtles and give them shapes.
Firstly, I will move T1, the default turtle
to the bottom left of the screen, change his shape to a
bin and change his name from T1 to bin.
You may notice that the bin is animating
automatically. If we want to turn this behaviour off, right
click the bin, choose 'change bin' and click on the shape
tab.
Make sure the Manual Animation is ticked,
and set the frame item to 1 so you see the first frame of
the bin animation.
Now let us create a new stack turtle and
change its shape.
Type
? new "stack [ ]
A new turtle will appear on the screen,
already knowing the behaviour that we have defined for a
stack turtle.

Change his shape to a cake, and see what
happens when you left click on the stack turtle..
What happens when you pick up a moveable
turtle created by the stack turtle and drop it on the bin?
Finally, add some more stack turtles and
change their shapes to an apple and a pizza.
Click
here to view this activity
N.B. First download the Plugin, if you have not already
down so, from here.