Getting Started with Programming

1.0 Introduction

This document provides a short introduction to StarLogoT. It describes StarLogoT's basic features and suggests activities for using and learning StarLogoT. At the end are links to other documents that provide a more complete description of the StarLogoT language.

1.1 Emergent Phenomena

Increasingly, scientists are discovering that the world's natural patterns, such as the diffusion of a gas throughout a container, are emergent phenomena. That is, these patterns are not governed by some central authority. Gas molecules do not "know" that they should spread out evenly throughout the container, nor is there a "boss" molecule telling other molecules where to go. Instead, patterns emerge from the particular behaviors exhibited by each element of the pattern. In the case of diffusion, each gas molecule moves almost randomly throughout the container, and this collective randomness eventually produces diffusion.

In physics, the idea of emergent phenomena is well established. Physicists investigate the rules that govern individual particles in order to understand the behaviors of particle systems. You can apply the same understanding, however, to chemical, biological, and even human social systems. Consider, for example, how grade school lunchrooms often become segregated by gender. There is no sign that declares one table is a "boy table" and another one is a "girl table." However, each individual student, feeling slightly more comfortable near children of the same gender, will gravitate toward those children until eventually the gender-segregated pattern emerges.

StarLogoT is a programmable environment designed for modeling and exploring natural systems as emergent phenomena. It is designed especially for use by students. By constructing models of the local actions and interactions of many distributed agents, students can explore the resulting global patterns.

1.2 StarLogoT Mechanics

StarLogoT is an extension of the Logo programming language. With traditional versions of Logo, you can create drawings and animations by giving commands to a graphic "turtle" on a computer screen. StarLogoT extends this idea by allowing you to control thousands of turtles in parallel. In addition, StarLogoT makes the turtles' world computationally active; you can control "patches" that comprise the turtles' environment. Furthermore, turtles and patches interact with one another; turtles can examine and modify patches, and vice versa.

Understanding parallelism is crucial to understanding StarLogoT. StarLogoT is quite different from serial programming languages, such as Logo, C, and Java. Serial programming languages act as centralized authorities that execute linear instructions. Therefore, they are poorly suited for modeling emergent phenomena. StarLogoT, in contrast, employs a parallel execution environment. In this environment, you program sets of behaviors and assign those behaviors to turtles (or patches) that act them out in parallel.

Consider the simple behavior "move forward 1 space." The StarLogoT command for this is fd 1. Open StarLogoT and you will see what looks like one turtle in the middle of the graphics screen (really it is many turtles stacked on top of each other). Type fd 1in the Command Center, then hit return. What happened? Instead of that one turtle moving forward, all the turtles have executed the forward command. And, since each turtle was initialized to a random heading, the turtles have spread out evenly around the space they used to occupy. Type fd 1 again and watch the turtles spread out even farther. Another interesting thing to note is that the original turtle you saw has probably disappeared. This is because there is no standard order that determines which turtle executes a given behavior first. Therefore, your turtle moved and then any number of other turtles moved, some of them landing on its space and covering it up.

Now try "move forward a random amount." First tell all the turtles to go back to the center. Type setxy 0 0 in the Command Center and hit return. Next, execute the forward command. The StarLogoT command for generating random numbers is random, and it requires one argument that provides a ceiling for the numbers it should generate (it will generate numbers greater than or equal to 0 and less than the number provided). So, type fd random 11 in the Command Center and hit return. The turtles have now spread out randomly from the center, forming a circle whose radius is about 10. This is because, instead of calculating one random number and having all the turtles move that amount, StarLogoT simply told each turtle to execute thefd random 10 behavior, so each turtle calculated its own random number before moving.

You don't always want all the turtles to execute the behaviors you program. For example, in a model of aging, you would only want the old turtles to die. Or, in a model of wolf-sheep predation, you would want the wolves to hunt the sheep, and not vice versa. StarLogoT offers two ways to assign behaviors to particular turtles or groups of turtles:

1.2.1 If statements. If statements take the form if condition [behavior]. If the condition is true, the behavior gets executed. All turtles will execute the ifstatement, but only some will satisfy its conditions and therefore execute its behavior. In the aging example, you could write: if age = 80 [die].

1.2.2. Breeds. Breeds allow you to segregate turtles by groups. In the wolf-sheep predation example, you could have a breed called "wolf" and a breed called "sheep." Then you could program different behaviors for wolves and sheep.

You can read more about if statements and breeds in The StarLogoT Development Reference Manual.

2.0 The Cast of Characters

StarLogoT includes three main "characters."

2.1 Turtles. The inhabitants of the StarLogoT world are graphic creatures called "turtles." A turtle can represent almost any object, such as an ant in a colony, a car in a traffic jam, an antibody in an immune system, or a molecule in a gas. Each turtle has a position (where it is), a heading (the direction in which it's going), a breed (the kind of turtle it is), a color, and a "pen" for drawing. If you choose, you can add more specialized traits to make your turtles resemble the real-life objects they represent.

2.2 Patches. Patches are little pieces of the world in which turtles live. They form an evenly distributed grid across the StarLogoT graphics screen. Like turtles, patches execute StarLogoT commands and act on nearby turtles and patches. You can also give patches specialized traits to make them resemble real-life pieces of an environment. Unlike turtles, however, patches cannot move or die.

2.3 Observer. The observer observes the turtles and patches from a global perspective. It can monitor their activity and issue commands to them.

The StarLogoT compiler determines which commands belong to which agents, and executes them accordingly.

3.0 The StarLogoT Workspace

The StarLogoT Workspace consists of several windows and toolbars.

3.1 The Main Interface Window

3.1.1 Interface Window. This window contains buttons, sliders, and monitors that let you interact directly with StarLogoT programs.

This sample interface contains 4 elements: 2 buttons, 1 slider, and 1 monitor. You can edit any element by shift-double-clicking on it, or by clicking the approriate icon in the Main toolbar and then clicking on the element once. To select an interface element, use the mouse to drag a box around it, or shift-click on the element. To delete an interface element, select it, then press the delete button on the keyboard. To resize an interface element, select it and pull on one of its four handles. Buttons can be resized in all directions, whereas monitors and sliders can only be resized horizontally, and switches cannot be resized at all.

3.1.2 Main Toolbar. You can create interface elements using the Main toolbar (see below).

To create a new interface element, click on the approriate icon in the Main toolbar, then drag out a rectangle in the Interface window to choose the element's location and size. For the default size, just click on any position in the Interface window.

Here's how the icons operate:
the mouse arrow icon returns you to interacting with your model;
the blue button with a finger on it creates buttons;
the green volume bar creates sliders;
the lightswitch creates switches;
the television monitor creates monitors;
the big 'T' creates textboxes;
and the last two icons on the toolbar are for selecting the Paint tools and the Shapes Editor, respectively.

3.1.3 Buttons. There are two types of StarLogoT buttons: once-buttons and forever-buttons. When you click on a once-button, it executes its instructions once. Once-buttons are useful for setting up the initial state of your model or changing its state while it runs. When you click on a forever-button, the button executes its instructions repeatedly (in a loop) until you re-click on the button again or execute a stop<BUTTON-NAME> command (see The StarLogoT Development Reference Manual for details). Forever-buttons cause turtles to execute behaviors repeatedly. Most StarLogoT models are driven by forever buttons.

Forever-buttons are distinguished by a looping pair of arrows on their faces (see above). To create a forever-button, check the 'Forever' box in the button's Edit dialog box.

Buttons display either their names or the code they execute. If you mark "Show Name" in the Edit dialog box, the button face shows the contents of the Name field. If you mark "Show Instruction" (which is the default), the button face shows the contents of the Instruction field (or as much of it as fits).

3.1.4 Switches. A switch represents a global variable that is either on or off, meaning either "true" or "false," "0" or "1." Note that, unlike many other programming languages, StarLogoT represents "true" with 0 and "false" with 1.

3.1.5 Textboxes. You can place textboxes in the interface to explain certain controls.

3.1.6 Sliders. A slider represents a global variable that has a range of values. You can choose a slider's minimum and maximum values, as well as the size of its increment.

3.1.7 Monitors. Monitors display the value of an observer expression. Use any observer expression that returns a real number value, including a simple variable. Monitors are updated every half second, but only while StarLogoT code is executing. So if a monitor doesn't seem to display the right value, just wait a moment for it to update.

3.1.8 Read Info Window... Button At the bottom of the Interface window is a button that calls up the current model's Information window. The Information window (see below) provides the user with details about how to use your model. The window can also be accessed from the "Windows" menu.

3.2 The Other Workspace Windows

All of the workspace windows can be selected from the "Windows" menu.

3.2.1 Graphics Window. The Graphics window is where StarLogoT turtles and patches display themselves. The turtles move on top of a grid of patches. When a turtle moves off the edge of the Graphics window, it automatically "wraps" around to the other side. You can move a turtle directly by dragging it with the mouse.

You can change the size and shape of the Graphics window by selecting the "settings" option under the "Edit" menu. The Settings dialog box lets you edit the horizontal and vertical dimensions of the Graphics window, as well as the size of each patch. More information about the Settings dialog box is provided in Section 4: The StarLogoT Menu.

3.2.2 Command Center. You issue commands to StarLogoT in the Command Center. Run a command a second time by moving the cursor back to the command's line and hitting the return key. The show command also prints to the Command Center.

3.2.3 Procedures Window. The Procedures window (initially hidden) is where you write procedures for turtles, patches, and the observer. It is the main programming console for StarLogoT models.

3.2.4 Information Window. The Information window (initially hidden) is a space for providing information about your model. It should introduce the model, explain how to use its controls, and provide examples of what behaviors to expect. The Information window is the most helpful one for first-time users of a model.

3.2.5 Paint Toolbar. The Paint Toolbar appears when you click on the paintbrush icon in the Main Toolbar. From here, you can select different tools for drawing in the Graphics window. The Paint toolbar is useful for drawing model backgrounds/environments.

3.2.6 Color Toolbar. Clicking on the paintbrush icon in the Main toolbar makes the Color toolbar appear. Here, you can select the color with which you can draw.

3.2.7 Shapes Editor Window. The Shapes Editor window appears when you click on the last icon in the Main toolbar. From here, you can create and edit turtle shapes and assign them to particular turtles. Double-click on a shape to edit it. To create a new shape, double-click on an empty slot. Click on a turtle to assign the currently selected shape to the turtle. Shapes are saved with each project.

3.2.8 Output Window. Use the Output window (initially hidden) for printing and recording data generated by a StarLogoT project. The print command prints to this window.

3.2.9 Plotting Windows. The Plotting windows (initially hidden) are used for creating real-time graphs of your StarLogoT project. There are 6 different plot windows, each with its own complement of 6 plot pens. Hence, you can plot many different things at once during the run of your project.

3.2.10 Turtle Monitors. Double-click on a turtle in the Graphics window and a Turtle monitor appears showing the turtle's state variables and their values, which update every 0.5 seconds. Edit a value directly by clicking on it and typing in a new value (or any StarLogoT expression that returns a value), and pressing the return key (or clicking out of the box). The lower half of the Turtle Monitor is also a mini-Command Center that can issue commands directly to the turtle it monitors (But only to that turtle). These features are extremely useful for debugging turtle behavior.

The above Turtle monitor shows information about turtle #4380. It shows the turtle's built-in state variables (color, xcor, ycor, heading, shape, and breed), and its user-created variables (followed-by, following, lock, etc.). The window is the same color as the turtle it monitors.

3.2.11 Patch Monitors. If you shift-double-click on a patch in the Graphics window, a Patch monitor appears. Patch monitors behave similar to Turtle monitors. Thus, you use a Patch monitor to view and edit a patch's variables and to issue commands directly to that patch.

4.0 The StarLogoT Menu

The are many useful items in the StarLogoT menu bar.

4.1 File Menu. The "File" menu lets you perform basic StarLogoT functions. You can create a new model, open an existing model or some other text file, and print. You can also import and export specific data to and from your current model. For more information on ASCII import and export, see Importing/Exporting with ASCII Files.

4.2 Edit Menu. The "Edit" menu provides standard text editor functionality. Note that the "undo" menu item undoes the last edit operation, even if it was an undo operation! Therefore, to undo a series of "Edit" operations, use the "undo more" menu item.

The "Edit" menu also allows you to edit your StarLogoT settings. Select "Settings" and the Settings dialog box appears.

The upper section of the Settings dialog box allows you to change the settings for the Graphics window, including its width and height, and the size (in pixels) of each patch within it. Check the "Force Square" checkbox to ensure that the Grahpics window is a square.

The middle section of the Settings dialog box lets you change StarLogoT's environment settings. The "Turtle Vars" slider controls the maximum number of user-defined variables the turtles in your model can have. The "Patch Vars" slider controls the maximum number of user-defined variables the patches in your model can have. The "# of Turtles" slider controls the maximum number of turtles your model can have alive at one time, and the "Turtle Stack" slider controls the amount of memory each turtle has for executing commands (extremely complicated commands, especially nested ifs and recursive functions, may require larger stacks).

Larger settings (big Graphics window, big patch size, lots of turtles, etc.) require more memory. StarLogoT determines whether enough memory is available for the settings you have chosen. If the necessary memory is unavailable, StarLogoT asks you to change your settings. For information on how to make more memory available to StarLogoT, see "A Note on Memory" in the Read Me section.

Finally, the bottom section of the Settings dialog box allows you to set StarLogoT's "Default Startup Commands." These commads act as a "startup" function whenever one is not defined in the Procedures window. In other words, they execute any time you open StarLogoT, create a new model, or change your settings. The "Default Startup Commands" create 280 turtles for you to play around with. If you don't want any startup commands, simply clear the "Default Startup Commands" text box.

To commit your settings, hit "OK." To cancel them, hit "Cancel." To revert to StarLogoT's default settings, hit "Defaults."

4.3 Windows Menu. The "Windows" menu allows you to select and display any StarLogoT window, and shows and hides the toolbar.

4.4 Help Menu. The "Help" menu gives you access to the StarLogoT Quick Reference (AppleGuide), the StarLogoT User's Guide (HTML), and the MacIntosh Help Guide.

5.0 What's Next?

Now that you are familiar with StarLogoT's basic layout, there are four resources you can use to learn more.

5.1 StarLogoT Tutorials

The User's Guide includes two tutorials (available from the Table of Contents) that walk you through the use and development of StarLogoT models. New users should study at least the Using tutorial to walk through an example of using a model.

5.2 StarLogoT Code Examples

Included in your StarLogoT program folder is a folder of code examples. These examples are not complete models of any particular systems. Rather, they show how to use specific StarLogoT features, such as graphing, making histograms, patch-turtle communication, etc.

5.3 StarLogoT Sample Models

Your StarLogoT program folder also includes a folder of sample models. These are full-feature models that investigate various phenomena. They are an easy way to learn what a quality StarLogoT model looks like.

Each sample model has a set of procedures (loaded into the Procedures window), a set of interface objects, like buttons and sliders (loaded into the Interface window), and a set of explanatory notes (in the Information window).

Be sure to read the notes and instructions in the Information window. These notes explain ways to use the models, ideas underlying the models, and suggestions for further explorations.

StarLogoT beginners might want to start by looking at the "Termites" and "Epidemic" examples.

Check out the "Extensible Models" section of the StarLogoT website for the complete set of StarLogoT models: http://ccl.northwestern.edu/cm/models/

5.4 The StarLogoT Development Reference Manual

For a comprehensive description of the StarLogoT programming language and its syntax, check out the Reference Manual.