This
section guides you through a sample session with StarLogo, showing you
how to create a new StarLogo project. As an example, it describes how
to create a "paintbrush" consisting of several hundred StarLogo turtles.
To
start a new project, choose New from the File menu of the Control Center.
Make sure you are in the Observer Command Center and type (pressing
the return key after each command):
crt 280
StarLogo creates
280 turtles (crt
stands for create-turtles). By default, the turtles start at position
(0, 0), in the middle of the screen. The "dot" in the middle of the
screen is actually a tall "pile" of turtles.
Next,
switch to the Turtle Command Center and type the following commands
(pressing return after each command):
fd
15
Each turtle moves
forward 15 steps. When new turtles are created, their headings are "spaced
out" from one another, so the new turtles move in different directions.
In this case, the turtles form a circle of radius 15 around the point
(0, 0).
seth 0 fd 30
Each turtle sets
its heading to 0 (north, the top of the screen), then moves forward
30 steps. Since all turtles are headed in the same direction, the circle
moves as a unit.
pd fd 50
Each turtle puts
its "pen down" (pd),
then moves forward 50 steps. Each turtle draws in its own color. Note
that the turtles "wrap" when they reach the edge of the screen.
repeat 36 [fd
2 rt 10]
Each turtle draws
a circle, repeatedly moving forward 2 steps and turning right 10 degrees.
Now,
switch back to the Observer command center and type
cg
This clears the graphics,
turning all of the patches to black (but not affecting the turtles).
It
might be useful to have some buttons that allow you to control the "turtle
paintbrush" interactively. To create a new button, select the button
tool from the Main Toolbar, then click in the Interface area and "drag
out" a rectangle. A dialog box appears. In the Logo Instruction field,
type fd 1.
Be sure that the "Turtle" and not the "Observer" item is checked. Then
click OK. Your new button appears. Whenever you click the button, all
of the turtles move forward one step.
There
are two types of StarLogo buttons. You just created a once-button:
when you click the button, it executes its instruction once. Let's change
the fd 1
button to the other type of button: a forever-button. Select
the fd 1
button (by control-clicking on it, or by dragging a rectangle around
the button). Then double-click on the selected button. The button's
dialog box reappears. (You can also get the button's dialog box by single-clicking
on the button with the button tool.) Check the forever box, then click
OK. Notice the looping pair of arrows on the face of the button. These
looping arrows indicate that the button is a forever-button.
Click
on the fd 1
button. The turtles execute the
fd 1 instruction again and again, so the circle keeps moving
forward. Forever-buttons run in the "background": you can execute other
instructions in the command center while forever-buttons are running.
Try typing rt
45 in the Turtle Command Center. The circle of turtles veers
to the right. Switch to the Observer command center and type cg: the
graphics clear but the turtles continue to draw. To stop the turtles,
click on the fd
1 forever-button.
You
might want to add some additional buttons. For example, make a new forever-button
with the instruction rt
5. Click on both the fd
1 button and the rt
5 button. (StarLogo allows forever buttons to run in parallel.)
The turtles all draw circles. By clicking the rt
5 button on and off selectively, you can move the turtles around
the screen.
It
might be useful to add cg button so that you can easily clear the graphics.
The cg
button should be once-button, not a forever-button, since you donāt
want StarLogo to continue clearing the graphics repeatedly. In addition,
since cg is an observer command, you should be sure to check "Observer"
next to the Logo Instruction field when creating your button. You might
also want to add once-buttons to lift up the turtles' pens (pu)
and to put the pens down (pd).
(Pen up and pen down are both turtle commands, so check "Turtle" next
to the Logo Instruction field.)
If
you plan to save the paintbrush project, it would be a good idea to
write a "setup" procedure so that you can recreate the paintbrush easily
in the future. First, go to the Observer Procedures window. Type:
to setup
ca crt 280
ask-turtles [fd 15 seth 0 pd]
end
This
procedure adds a new word to the list of commands which the observer
knows. First, the observer clears the Graphics area (ca
stands for clear all). Then, the observer creates 280 turtles. Next,
the observer asks the turtles to perform the commands listed inside
the square brackets []. The ask-turtles command in effect transfers
control from the observer to the turtles--just like when you switch
from the Observer Command Center to the Turtle Command Center and back.
After the square brackets are closed, the procedure returns control
to the observer.
Once
you've written the procedure, go back to the Interface area and make
a once-button whose Logo Instruction is the command setup. When you
click the setup button, StarLogo reinitializes the paintbrush.
Here
are some other things to try with the paintbrush project:
Make
a slider called "turn", then change the
rt
5 button
to rt
turn. With
the new slider, you can more interactively control the turning radius
of the turtles.
Add
buttons for changing the colors of the turtles. For example, create
a forever-button with the instruction setc
color + 1
Create
new procedures and buttons that allow you to shrink and expand the circle
as it moves. (Warning: This is not trivial! Hint: Each turtle needs
to "remember" its original heading.)
If
you want to save the paintbrush project, select Save from the File menu
in the Control Center menu bar.
Return to Top
|