Give the Gift of Learning
Looking for a holiday gift to give your son or daughter that's fun,
educational, and has the potential to still be cool well into the new year?
Turtles to the rescue! No, I'm not referring to Michelangelo, Donatello,
Raphael, and Leonardo, those innocent turtles turned human-sized martial
artists by way of radioactive ooze. I'm talking about
dialect of the Logo programming language. That's right, those turtles are
back, and this time they've come for the adults too! Whereas Logo is
traditionally used to teach geometry through graphics, StarLogo is aimed
at exploring and modeling complex systems and emergent behavior. For example, in this article we'll explore a StarLogo simulation that demonstrates how autonomous termites interact to gather wood chips into piles. Indeed, StarLogo offers a playful learning environment that scales to the imaginations of little and big kids alike.
StarLogo is a fun (and free!) present to give your kids. The true gift is one
of learning and sharing the learning experience with them. This article will
explore StarLogo adventure projects from a termite colony that displays
emergent behavior to bumper turtles that familiarize us with the StarLogo
environment. These projects demonstrate how kids can play and explore before learning how to program. Finally, avenues for further exploration will be illuminated and in the end, you might be surprised to find yourself playing with StarLogo long after the kids have gone to bed.
StarLogo was developed by a team at the MIT Media Lab and is available for free at education.mit.edu/starlogo. It conveniently runs on the Java platform. The download page includes downloads for Windows, Macintosh, and Unix, in addition to a generic download for any operating system with Java 1.1 or higher installed. The examples in this article were run on Mac OS X.
Once you've downloaded StarLogo, in addition to excellent documentation, you'll
also find a sleigh overflowing with ready-to-run projects. The Adventure
Projects folder includes a set of projects intended to help beginners get
comfortable in the StarLogo environment and introduce them to the principles
of modeling. These projects were inspired by the design challenges
included in the book Adventures in Modeling (see Resources), an excellent guidebook for parents and educators to help them teach modeling with StarLogo by example. The Sample Projects folder includes intermediate and advanced projects in the categories of biology, graphics, math, physics, and social systems.
Let's get started already by exploring two adventure projects.
Termites are amazing little creatures that can move incredible amounts of wood. Indeed, they're quite fun to watch, as long as it's not our wood they happen to be moving. But what makes them truly fascinating is their ability to self-organize and move wood chips into neat piles without a central leader.
We can't possibly model all of the aspects of real termite behavior in our first
project, but with StarLogo it's easy to visualize how they gather wood chips
into piles. To drop in for a bird's-eye view of a busy colony of termites,
double-click the (4) Termites.slogo file in the Adventure Projects
folder. StarLogo should start and pop up two windows on the screen -- the
Control Center Window and the StarLogo Window -- similar to those in Figure 1.
Figure 1. The Termites project in StarLogo
Ignoring the Control Center Window for now, press the button labeled
"go" in the StarLogo Window. The multi-colored termites will start
randomly wandering around looking for yellow wood chips. If a termite bumps
into a wood chip, and the termite isn't already carrying a chip, then the
termite picks up the chip and continues its random wandering in search of
another chip. When the termite bumps into another chip, the termite puts
down its chip in an empty spot next to the chip the termite had just found. Then
the termite jumps away from the pile and goes back to randomly searching for
its next chip.
go procedure in the Control Center Window encapsulates
the chip-gathering rules followed by all the termites, expressed in
the StarLogo programming language:
search-for-chip ; find a wood chip and pick it up
find-new-pile ; find another wood chip
find-empty-spot ; find a place to put down wood chip
It might help here to point out that StarLogo is a procedural programming language. Notice that the
go procedure calls three other procedures (also shown in the Control Center Window), each of which, in turn, executes a set of StarLogo instructions. The complex termite behavior in the
go procedure, therefore, is broken down into three distinct rules encapsulated in simpler procedures. In other words, using procedures, you can build modular and extensible programs in StarLogo.
As a result of the termites following these simple rules, after a short while you'll notice piles of wood chips beginning to form. While the exact pattern varies, over time you should start to see piles similar to those in Figure 2.
Figure 2. Termites self-organize to gather yellow wood chips into piles
The edges of the two-dimensional Graphics Canvas are connected to each other,
so termites that walk off the right-hand side will reappear on the left-hand
side. Figure 2 actually shows one big pile of wood chips "wrapped" around the flattened world.
Use the slider controls to experiment with the termite colony and then press the
"setup" and "go" buttons to re-run the simulation. You can even
use the Paint and Color Toolbars on the left-hand side of the StarLogo Window
to toss in more yellow wood chips while the simulation is running. The
StarLogo world is live, so the termites will just happily keep tidying up the place.
The Termites project is particularly interesting because it demonstrates emergent behavior -- following simple, local rules, the termites self-organize to accomplish a relatively complex, global task. That is, no one termite is in charge of instructing all of the other termites how or where to make piles. The pile-building behavior simply emerges from the local interactions between termites going about their business.
StarLogo is designed primarily to help non-experts model and explore complex,
dynamic systems. Other examples of "leaderless" systems in our
everyday surroundings include flocks of birds, traffic jams, market economies,
and social gatherings. StarLogo scales well by also making it easy to create simpler models and learn programming principles along the way.
Big Bumper Turtles
Though mesmerizing to watch, your kids probably won't start modeling the
emergent behavior of insect colonies right away. If that was all StarLogo
could do, it wouldn't make for a very good gift. ("Gee, thanks, Mom and Dad. I always wanted to model complex, dynamic systems on the computer!")
Thankfully, StarLogo includes simpler projects in the Adventure Projects folder, such as Big Bumper Turtles.
Open the project by double-clicking the (3) Big Bumper Turtles.slogo file in the Adventure Projects folder, or by using the File->Open Project menu choice. The Big Bumper Turtles project should appear in windows similar to those in Figure 3.
Figure 3. The Big Bumper Turtles project in StarLogo
Get that turtle bumpin' by pressing the "pen-up" button and then the
"go" button. The turtle will start moving forward, but bounces off
any red, green, or blue obstacles. Depending on the color of the obstacle encountered, the turtle either turns left, right, or does an about face. This simple project demonstrates how turtles can sense changes in their environment and react accordingly.
Now let's experiment with the Big Bumper Turtles simulation. While the simulation is running, press the "clear-graphics" button. The colored obstacles will disappear, but the turtle is still there, moving in a straight, unobstructed path. Add a red, green, or blue obstacle in the turtle's path using the Paint and Color Toolbars on the left-hand side of the StarLogo window. Simply pick the appropriate color from the Color palette, select a paint tool, such as the pencil, and then click in the Graphics Canvas where the turtle is moving to paint the selected color. Now try adding more colored obstacles. In this way, we're able to interact with the simulation before learning to program.
In both of the adventure projects we've played with, you've likely noticed that
StarLogo differs from traditional Logo in several important ways. First,
unlike Logo, StarLogo enables you to command multiple turtles in parallel.
Second, turtles can interact with their surroundings. Those two differences
combined allow for interesting turtle-turtle and turtle-world interactions that
are essential in modeling decentralized systems.
Now that we've watched StarLogo in action, it's time to introduce the cast of
characters in Big Bumper Turtles.
Cast Of Characters
A StarLogo world is made up of three characters: turtles, patches, and the
observer. Turtles live on a grid of active patches, and both can be controlled by the observer. This world provides fertile ground for interesting turtle-turtle and turtle-world interactions.
A turtle is anything that moves around on the Graphics Canvas. Turtles can appear as any shape, such as a termite or an automobile. You can move a
turtle around the Graphics Canvas by dragging it with the mouse. Just for fun,
see if you can relocate the bumper turtle.
Each turtle has a set of internal state variables that can influence how it
looks or behaves. Unless you've already stopped the Big Bumper Turtles
simulation, the button labeled "go" will still be depressed. Press
the "go" button again to stop the simulation. Double-clicking on any
turtle shape will pop a Turtle Monitor window similar to the one in Figure 4.
Figure 4. Monitoring a turtle's state
Notice that this turtle has a predefined set of variables, including its unique
who number. A turtle's
who number is useful as its
call sign for communication with other turtles. Think of this as Whoville; this turtle is Cindy Lou Who.
Change the turtle's color by setting its
color variable to
red and watch the on-screen effect. With a bit of programming,
turtles can also be assigned custom variables (e.g.
energy) to modify their behavior.
Notice also that you can command this turtle by typing StarLogo commands in the Command Center text area at the bottom of the Turtle Monitor window. Type the following StarLogo commands to instruct this turtle to move ahead a distance of 2 patches and then turn right 90 degrees:
Perhaps you found those commands to be a bit too cryptic. They use the shorthand notation consistent with the coding style of the adventure projects. If you'd prefer to be more expressive (it's never too early to instill good coding style!), the following StarLogo commands do the same thing:
We'll learn how to command all turtles in one fell swoop a bit later.
The turtles live on an invisible grid of patches. As a turtle moves around, it can interact with the patches. Each patch can contain an arbitrary amount of information to be "sniffed" by turtles. In the termites project, for example, a termite knows it has bumped into a wood chip by asking if the patch underneath the termite is yellow. The termite then picks up the wood chip by updating the patch's color to black.
Patches can also execute commands to do things like grow turtle food or sprout new turtles. Double-click on any empty patch on the Graphics Canvas to pop up a Patch Monitor window similar to the one in Figure 5.
Figure 5. Commanding a patch
Just as we sent commands to a specific turtle in the Turtle Monitor window, we can command a specific patch by typing in the Command Center text area at the bottom of the Patch Monitor window. Type the following StarLogo command to ask the selected patch to create (sprout) a turtle that sets its color to green and moves forward 2 patches:
sprout [setcolor green fd 2]
The syntax of this StarLogo patch command bears explanation here. The
sprout command first creates a turtle and then sends the list of commands between the square brackets to the new turtle. Notice the two turtle commands aren't explicitly separated. That is, separation of multiple commands in a list is implicit.
The observer is the omniscient character watching over the StarLogo world. At the beginning of a simulation, the observer generally sets the stage by
creating turtles and configuring patches. The observer can then ask both
turtles and patches to perform certain commands, but the observer doesn't
necessarily dictate how the newly-created turtles go about their work. That is,
the observer is not intended to be the leader of turtles.
Poking and prodding turtles is good, clean fun. Let's take a closer look at
interacting with Big Bumper Turtles.
Interfacing With The Characters
User interface components -- buttons, sliders, monitors, and graphs -- can be
added anywhere in the white area around the Graphics Canvas. Use the Toolbar
at the top of the StarLogo Window to create new interface components for the
Commanding All Turtles
To see what really happens when a button is pressed, select the "go"
button (on Windows, press the Control key and double-click; on a Mac, press the Shift key and double-click). You should see a window like the one in Figure 6.
Figure 6. The "go" button calls the
The StarLogo instruction associated with this button happens to be called
"go", though the instruction name need not match the button name.
StarLogo doesn't define
go as a primitive command. Rather,
go is a procedure -- a collection of other StarLogo commands
(and/or procedures) -- written specifically for this project. Notice that the
"Turtle" radio button is selected. This means that the
go procedure is intended to be run by all the turtles, not the
observer. Turtles and the observer respond to different commands, so you have to tell StarLogo which character should run the command.
To view the StarLogo commands used in the
go procedure, select the
Turtle tab in the Control Center Window. You'll see the Turtle Command Center pane at the top and the Turtle Procedures pane at the bottom, as shown in Figure 7.
Figure 7. The Turtle Command Center commands all turtles
In the Turtle Procedures pane, you'll find the definition of the
go procedure that encapsulates the commands followed by bumper turtles.
In the Turtle Command Center pane, you can type StarLogo commands or the name
of an existing turtle procedure to be run by all turtles. For example, even while the Big Bumper Turtles simulation is running, you can turn of all the turtles red by typing the StarLogo command:
The "Commands" page of the documentation describes all of the turtle commands.
Feel free to experiment with some turtle commands. Notice that any turtle
command you type in the Turtle Command Center pane is run by all of the
Commanding The Observer
The observer has the power to create turtles and ask them to run commands.
Select the Observer tab in the Control Center Window to command the
observer. You'll see the Observer Command Center pane at the top and the
Observer Procedures pane at the bottom, as shown in Figure 8.
Figure 8. The Observer Command Center controls the observer
Check out the
setup procedure in the Observer Procedures pane.
This observer procedure is called when the
"setup" button is pressed. It's no magic; edit the
"setup" button to see for yourself.
Notice that the
setup procedure includes the following
crt command (shorthand for the
command) creates the specified number of turtles,
in this case the number indicated by the
number variable is set by a slider control.
Select the "number" slider in the StarLogo Window (on Windows, press the Control
key and double-click; on a Mac, press the Shift key and double-click)
and you should see a window like the one in Figure 9.
Figure 9. The "number" slider controls the
number variable controlled by the "number"
slider is used in the observer's
setup procedure, changing the slider's
value only takes effect when the "setup" button is pressed.
Now type the following StarLogo command in the Observer Command Center to
command the observer to create four new bumper turtles:
The newly born turtles start out as a pile in the center patch of the Graphics
Canvas. If the simulation is already running, the turtles will immediately
begin moving forward in different directions while following the instructions
The "Commands" page of the documentation describes all of the observer commands.
Try a few commands and see what happens. The turtles will love you for it!
Teaching Programming Gradually
We've seen glimpses of the StarLogo programming language in the Command Center Window. It's a full-featured programming language with a rich set of commands, including:
- Conditional expressions
- Repetition constructs
- List processing
- Math commands
But as cool as the language might be for us geeks, I wouldn't expect the
kiddies to have aspirations of being StarLogo programmers, at least not
initially. On the other hand, kids might have their own ideas for making
the simulation cool for them. ("Daddy, can we make all the turtles
jump?") So how do you let them create and alter worlds without teaching them the language?
I'd recommend you start by helping them choose buttons and sliders as
interfaces to the world. Then you can write the StarLogo procedures that bring
life to the controls. For example, you can create a button associated with the
jump 5. If and when they express more interest
in how it works, you can gradually introduce them to the language.
Typing individual commands into the Control Center Window is another fun way to
experiment. Seeing the visual effect of a command is a powerful learning aid. And as young programmers start using multiple commands together repeatedly, you can show them how to make a procedure. Style points for refactoring!
Above all else, encourage them to experiment on their own without worrying about making mistakes. Debugging, after all, is an essential part of the learning process.
The projects included with StarLogo offer a lot to explore. Once you've opened
a project, use the Windows->Info Window menu choice to learn more about it.
As further exploration, you may enjoy experimenting with the following
adventure projects, as they demonstrate StarLogo features not covered in this article:
Shiny Happy Turtles:
Demonstrates the use of a custom turtle variable (
happiness) that increases and
decreases proportional to slider values as turtles interact with
"school" and "cinema" patches. And turtles sharing the same patch interact to double their happiness!
Turtles search for four code words in order to invade the castle. Using the
grabcommand, you can modify this project so that turtles
conspire -- communicating with their
whonumber -- to hasten the invasion.
Demonstrates how turtles can "flock" by a turtle following any other
A traffic jam simulation that uses turtle breeding to give
different sets of turtles their own unique behaviors.
Predators Prey Grass:
An advanced predator-prey model.
I found reading and modifying the code in the sample projects to be a
productive way to learn the power of the StarLogo language.
Once you've crafted a spiffy new StarLogo project of your own, you can make it
available on the Web for the world to behold. Yep, since StarLogo runs on
Java, it can also run as an applet. Just save the project using the
File->Save Project As Web Page menu choice. You'll need to place the
resulting .html file, and the existing
starlogo.jar files in the same directory. I wasn't able to
convince a browser on the Mac to run a StarLogo applet, but Netscape on a
PC worked just dandy.
I chose StarLogo for this article primarily because it includes elementary
adventure projects. If you're looking for more advanced models and features, I
recommend you give NetLogo a whirl. NetLogo was inspired by StarLogo, and
shares many of the same features, but offers significant new features and a
redesigned user interface. And NetLogo's model library is quite extensive,
including adult projects for after the kids have gone to bed: Tetris, Frogger,
and even Pac-Man. I'll bet you never thought of Pac-Man as an emergent systems
Figure 10. NetLogo has an extensive model library ;-)
In this article, we've covered a lot of turtle ground. And yet, we've just
barely scratched the surface of the lush StarLogo world. We've seen how StarLogo can scale from one turtle moving forward and making basic turns to hundreds of turtles following simple rules to simulate complex behavior. We've learned how to interact with the StarLogo world using controls. And along the way, we got a taste of the simple, yet powerful, StarLogo programming language.
StarLogo is a open-ended environment that allows kids of all ages to create,
explore, and learn while having fun. This holiday season, give a gift that
keeps on giving -- learn StarLogo with your kids. I hope you have a lot of fun
together. Cowabunga, Dudes!
(Based on interest in this article, it may become the first in a series of articles. I'd love to hear back from you regarding the usefulness of this article and what you might be interested in learning next.)
StarLogo home page
StarLogo downloads, extensive documentation, a tutorial, and more.
Adventures in Modeling: Exploring Complex, Dynamic Systems with StarLogo
Vanessa Stevens Colella, Eric Klopfer, and Mitchel Resnick,
Teachers College Press, 2001.
An educator's guidebook to the adventure projects distributed with
StarLogo, complete with group activities that simulate emergence,
StarLogo modeling challenges, and student handouts for each challenge.
Emergence: The Connected Lives of Ants, Brains, Cities, and Software
Steven Johnson, Scribner, 2002.
Explores decentralized, emergent systems in our everyday surroundings.
NetLogo home page
An extended version of StarLogo (also free and written in Java) that
includes new features, a redesigned user interface, and a plethora of
The Logo Foundation
Links to Logo resources