From Turtles to Atoms

Let’s start by writing a simple script. We’re going to create many turtles to represent atoms within a system and make them move.

Steps:
1) Create a new breed of turtles.
2) Set the number of turtles in that breed.
3) Make all turtles move.

Step 1: Creating a New Breed of Turtles
To create a new breed of turtle, click on the menu icon found at the top of the viewer and select “add a new breed of turtle.”

Wait a moment, and you’ll get a colored box at your cursor. This is the representation of the turtle breed in the world. It serves as an exemplar, or model, for all the turtles that you create from that breed. A small, colored dot (a turtle) will also appear in the Kedama world. The first breed of turtles is always red. If you create more than one turtle breed, the next colors are randomly assigned.
Step 2: Setting the Number of Turtles
To get new turtles, you can do one of two things, depending on what you want your turtles to do.

1) If you want all the turtles to behave in the same way and follow the same script, then you want to add turtles from the same breed as the first. To bring up the viewer for your turtle breed, point your cursor over the exemplar, or red square that represents the breed, and you should see a familiar halo of handles. Open a viewer, and choose the “kedama turtle breed” category.

See the command that says, “turtle1’s turtleCount” and the number assigned?

Go ahead and change that number to however many turtles you want. They should appear in the Kedama world as soon as you hit “Enter” and will be the same color as your first turtle. Keep in mind that even though there may be many turtles, they all share the same name since they’re from the same breed – turtle1.

2) If you want the new turtles to behave differently and follow a different script, you want to add a new breed of turtle. Do this the same way as you added the first breed of turtle, and you’ll see a different colored dot and exemplar appear.

For our simulation, we want all our turtles to behave the same way – as atoms – so we’ll use the first method. When you finish, you should see the Kedama world with many red turtles in it, all from the same breed.

Step 3: Making the Turtles Move
Let’s make our breed of turtles move. It’s very similar to making other objects in Squeak move, so you’re probably already an expert at this! If it’s not already open, go ahead and open the viewer for the turtle and choose the “kedama turtle” category. You should see a list of familiar commands, including “turtle1 forward by.”
Pull these tiles out to create a new script. Enter how far you want the turtles to move each time, set your script running, and watch your turtles go! Congratulations – you’ve now used Kedama to make an atomic simulation.