Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Turtle Graphics
L i k e most Logos, Atari L o g o has a graphics turtle that has a d r a w i n g p e n
and can leave a path as it moves and turns about the screen. T h e special
h a r d w a r e of Atari computers allows Atari L o g o to have four turtles. These
turtles are dynamic. T h e y can travel about the screen at different speeds
and, if their pens are d o w n , they d r a w and leave a trace of their paths. If
they are going fast, their paths tend to b e dotted rather than solid lines.
Color is another w a y in w h i c h Atari L o g o differs f r o m other Logos.
Atari L o g o has 128 different colors. T h e colors r a n g e through sixteen hues,
each of which consists of eight different intensities (luminances). These
colors are r e f e r r e d to b y n u m b e r f r o m 0 through 127. A n y of these colors
can b e used for the background, the lines the turtles d r a w , or the turtles
themselves.
Each of the four turtles has b e e n given a different color for its shape w h e n
it starts. You can change the color of a turtle's shape to any of the 128 colors.
In the following example the turtles h e a d in different directions, but travel
at the same speed and periodically change color.
By Cynthia Solomon.
T U R T L E GRAPHICS 363
i t.
'W.
At any one time the lines d r a w n by turtles on the screen are limited to three
different colors. This limitation is imposed because there are only three
pens: pen 0, p e n 1, and p e n 2. Each pen can write in any of the 128 different
colors. W h e n you change the color in a pen, lines to b e d r a w n by that p e n
and those already on the screen will appear in that color. This feature of
being able to change the color in a pen and thus change the color of lines
on the screen after they have b e e n d r a w n leads to some startling graphics
effects.
W h e n you first start u p Logo, the turtles are all using p e n 0, which
contains pen color 15 (yellow). If you want a turtle to use a different pen,
then you type or T o change the p e n color you use
the command For example, makes the color in p e n 0
become white. changes p e n 0 back to yellow. is the
L o g o operation that outputs the current pen; outputs the color of what-
ever pen you give as input.
If you refer to a p e n with a n u m b e r other than 0,1, or 2, L o g o will print
out an error message. L o g o will also complain if you refer to a color with
a n u m b e r outside the range 0 through 127.
364 SPECIAL FEATURES OF A T A R I LOGO
N o w try:
STAR 30
You can use m o r e than one turtle to make stars. For example:
Now:
THREESTARS
REPEAT 20 [SETPC 0 RANDOM 128 WAIT 20]
In the previous example all three turtles used the same pen, so the three
stars change to the same color. But each of the three turtles can use a
different pen. T o do this, change or make a n e w procedure like
TURTLE GRAPHICS 365
Try:
STAR3
REPEAT 10 [EACH [SETPC WHO RANDOM 128 WAIT 20]]
Type:
REPEAT 3 [WHIRL]
W h e n you finish, you might want to reset the colors in the pens and
have all the turtles use p e n 0.
Background Color
SETBG 7
SETBG 8
Try:
RAINBOW 30
Designing a Shape
All the turtles start as the same shape (that of a land turtle), but you can
design other shapes yourself. L o g o sets aside m e m o r y just for these shapes.
W e refer to the shape m e m o r y by one of sixteen slot numbers. Slots 1
through 15 are available for your o w n shapes. Slot 0 always contains Logo's
regular turtle shape. T h e L o g o operation outputs the n u m b e r of the
shape the turtle currently carries. is the c o m m a n d by w h i c h the
turtle's shape can b e changed to any of the ones in slots 0 through 15.
You can m a k e shapes in the shape editor. For example, w h e n you type:
By Cynthia Solomon.
TURTLES A N D THEIR SHAPES 387
EDSH 1
the shape editor displays a grid of eight columns and sixteen rows.
At the start, the outline of the u p p e r left rectangle is black while the rest
of the grid is white. T h e black rectangle is the cursor that you m o v e around
the grid using the a r r o w keys (with the C T R L key).
You make a design b y filling in cells of the grid. T o fill in a cell (a
rectangle), m o v e the cursor there and then press the space bar. T o clear a
cell you also m o v e the cursor to the cell and press the space bar. Notice that
pressing the space bar does not m o v e the cursor.
Let's make a shape; fill in the edges of the grid to make a hollow
rectangle.
You get out of the shape editor the same w a y you do the text editor, by
pressing the E S C key.*
Using Shapes
TELL 0
ST
SETSH 1
Sometimes people say that a turtle is " c a r r y i n g " a particular shape. So, for
example, turtle 0 is n o w carrying shape 1.
Animation
You can use the shape you just m a d e in an animation sequence w h e r e the
shape shrinks and grows. For this you n e e d to m a k e another shape. M a k e
a smaller rectangle as shape 2.
Type:
EDSH 2
By alternating the t w o shapes with a delay after the changes, you have a
box that shrinks.
*If you press the BREAK key, you will lose whatever changes you made during this
editing session.
388 SPECIAL FEATURES OF A T A R I LOGO
REPEAT 20 [SHRINK]
Another Animation
M a k e a smaller box and extend SHRINK to include it. You might type
to do this. A f t e r making the n e w shape, change to in-
clude as its last two instructions
SETSH 3
WAIT 10
REPEAT 20 [STRETCH]
At any time you can change the turtle back to shape 0 by typing
A turtle always starts carrying shape 0. You cannot change what is in this
slot. N o r can you v i e w this in the shape editor. Try:
SETSH 0
CS
TELL 0
REPEAT 24 [RT 15 WAIT 10]
As the turtle turns, its body turns and changes. Shape 0 changes at 15-
d e g r e e intervals. Thus, if a turtle's heading is 0 and you turn it right 10
degrees, its n e w heading will b e 10 degrees, but the shape it carries will not
have turned or changed. T u r n the turtle 5 m o r e degrees and the shape will
show a change of rotation.
TURTLES A N D T H E I R SHAPES 369
Rotating Shapes
When you reboot Logo, the shapes you made are not in the shape memory;
slots 1 to 15 are cleared out. (Notice that does not clear out these
slots.) If you want to use or again, you have to put the three
shapes into the same slots they were in before. Thus you have to figure out
a way to save them and-also a way to load them.
There are two steps to saving shapes. The first is getting the informa-
tion from the shape memory into your workspace. Using the Logo opera-
tion you can get a description of each shape. For example,
1 will output a list of numbers that describes the large rectangle. To put the
three rectangle shapes in your workspace, you make three variables.
PR GETSH 1
The three variables that now contain the descriptions of the three
rectangles can be listed by typing
SOUNDS AND MUSIC 371
Copying Shapes
You can copy shapes from one slot into another. This is often useful when
you want to make variations of a shape. For example, you can put the shape
in slot 1 into slot 4 by typing
PUTSH 4 GETSH 1
TOOT 0 440 10 15
In music, alphabetic names are used for the pitches. The letters A through
G name seven pitches. The other five are referred to by one of these letters
By G r e g Gargarian.
372 SPECIAL FEATURES OF ATARI LOGO
followed by either a " # " (sharp) or ' V ' (flat) mark. "Aft," pronounced " A
sharp," means "the chromatic step up from A . " Likewise, " A b , " or " A flat,"
means "the chromatic step down from A . "
T h e following conversion chart shows the relationship b e t w e e n pitch
names and frequencies. Each column of frequencies represents one octave
of chromatic pitches. T h e procedure generates the frequencies for
these pitches.
Pitch N a m e s Frequencies
Try:
OCTAVE 220
OCTAVE 440
OCTAVE 880
Try:
OCTAVE.UP 220
OCTAVE.UP 261
OCTAVE.UP 493
OCTAVE.DOWN 1568
OCTAVE.DOWN 698
A note has pitch, loudness, and duration. ' s third input controls loud-
ness. changes only the loudness of a repeating note. (In music
terminology crescendo means "to get gradually louder.")
type
SETENV 0 1
N o w try:
CRESCENDO 1
Try:
SPEEDUP 60
374 SPECIAL FEATURES OF A T A R I LOGO
Type:
CHANGE.DECAY 1
T o restore type:
MAKE "C.MAJOR [261 293 329 349 392 440 493 523]
SCALE :C.MAJOR
Melodies
Noise Sounds
Hissing, sputtering, grunting, and other such sounds are noise sounds.
W h e n several frequencies are very close together, they can mix and be-
come noise. T h e bouncing or siren sounds found in some of the projects in
this book or in the Sound Effects project demonstrate that noise sounds can
be not only expressive but quite beautiful as well.
PROGRAM LISTING
376 SPECIAL FEATURES OF A T A R I LOGO
Atari Logo provides you with ways to detect certain events, such as whether
a joystick is changing position or whether one turtle is colliding with an-
other. You can write programs to watch for these events or you can set up
special Logo helpers called demons. Demons are invisible creatures and
run independently of your programs. You can create a demon on command
and also get rid of it on command.
Many of the projects described in this book take advantage of Atari
Logo's event detection. In this section w e give examples of the different
kinds of events and ways of checking for them.
Collisions
Logo can detect collisions between any two of the four turtles. There
are six possible ways in which the four turtles can collide. Each of these
possibilities is represented by an event code number. It is not necessary for
you to learn which number represents which event since you can use the
operation
For example, you can type:
PR COND TOUCHING 0 1
and if turtle 0 and turtle 1 are touching one another, Logo responds
otherwise Logo responds If you type:
PR TOUCHING 0 1
Using COND
FLOAT
sets u p the turtles and then turns the j o b of detecting the colli-
sion over to As long as the p r o g r a m is running, L o g o emits a
low A (220) w h e n turtles 0 and 2 touch and a high A (880) w h e n turtles 1
and 3 touch.
Using Demons
FLOAT
PODS
Thus, even if you do not directly refer to the event code, L o g o does. You
can always look the codes u p in the reference manual w h e n you n e e d them;
you can derive the collision event codes experimentally by typing, for
example:
T h e demons remain active until you type CS, shut the machine off, or
explicitly get rid of the demons.
Each turtle can collide with lines d r a w n by any of the three pens. T h e
operation can b e used to describe an event in much the same w a y as
does. takes two inputs: the first is the turtle n u m b e r and the
second is the p e n number. outputs an event code number.
T h e r e are twelve possible collisions. If you want to k n o w a code num-
ber, you can always type something like the following:
L o g o responds:
T h e turtle monotonously bumps into a side of the square, turns around, and
travels until it again b u m p s into a side of the square and repeats the process.
You might want to change the amount the turtle turns. For example, try
A demo n is created and told to watch for event 7 (the passing of a second).
' s second input is a list of L o g o instructions. T h e d e m o n has L o g o run
this list of instructions w h e n it detects the event it is watching for.
In this example the four turtles are set up to head in different direc-
tions. Then the demo n has L o g o run the two instructions and
15 every second.
H e r e is another example that uses a d e m o n to watch for event 7 (the
clock tick). In this example, turtle 0 makes a real clock.
380 SPECIAL FEATURES OF A T A R I L O G O
T h e clock will remain on the screen but the hand will no longer b e visible.
You dismiss all demons w h e n e v e r you type CS.
L o g o will dismiss all demons if an error occurs in a demon's list of
instructions.
Using a Joystick
T w o events you can detect have to do with joysticks, in one case detecting
w h e t h e r any joystick button has b e e n pressed and in the other case detect-
ing whether the joystick itself has changed position. For example, you
might have the turtles moving about the screen using You might
want to change the turtles' direction by pressing a joystick button.
will let you do that; it will make a sound w h e n e v e r you change
the position of a joystick.
Advice
' You cannot create a d e m o n w h e n you first start L o g o or immediately
after you leave the L o g o editor. B e f o r e the demons will function, you
must use a graphics c o m m a n d such as CS. If you want to use a
once-per-second d e m o n to print on the text screen, you might do the
following:
CS TS
Abelson, Harold, 115, 212, 303 Bits (binary digits), x, 283 Demons (Cont.):
Adding Numbers, 258-266 Blaster, 151-159 in Demons, Turtle, Collisions, and Oth-
ADD, 266 BLASTER, 158 er Events, 376-380
Addition table: Boxgame, 133-140 in Dungeon, 193
in Adding Numbers, 260 BOXGAME, 138 in Jack and Jill, 111-112
in preface, vii BYEBYE, 139 in Lines and Mirrors, 356
Adventure, 172-191 JOYGAME, 139 in Pacgame, 140-142, 147
ADVENTURE, 188 NEWGAME, 139 in Rocket, 126, 127
Alien, 160-171 Bytes, 283 Dictionary, 21-27
START, 167 DICTIONARY, 26
Animal Game, 11-21 DiSessa, Andrea, 115
ANIMALGAME, 20 Cartoon, 87-104 Diskette, Logo files for all projects, xvi
Animating Line Drawings, 227-229 CARTOON, 102 (See also Files)
START, 229 Cassette, 282 Display Workspace Manager (DWM),
Animation: Chandler, Jeanry, 160, 191 292-301
by changing shapes: in Blaster, 152 Cipher, 330 DWM, 296-301
in Cartoon, 87ff. Clock, 379 Drawing Letters, 50-58
in Exercise, 80 ff. Collisions: LETTER, 57
in Jack and Jill, 108fF. COND, 376, 377 SAY, 57
in Pacgame, 141 Demons, 377-378 Dula, Annette, 58
in Rocket, 126 OVER, 378 Dungeon, 191-205
in Turtles and Their Shapes, 367-368 TOUCHING, 376 START, 198
colormap, 227 WHEN, 377-378 Duration, 230, 373
of human figures (see Alien; Exercise; Color: DWM (Display Workspace Manager),
Jack and Jill; Rocket) background, 365-366 292-301
of line drawings (see Animating Line pen, 363-365
Drawings) turtle, 362-363
using invisible walls, 93 Commands, 272, 326 EACH, 207
Arctan, 212-213 Computer literacy, vii Ear Training, 239-242
ARCTAN, 213 COND, 376, 377 EAR.TRAINING, 241
Argue, 6-11 Cotten, Susan, 21, 74, 80, 126 (See also Sounds and Music)
ARGUE, 11 Editor, shape, 366
Arithmetic: Electronic mail (see Mail)
in Adding Numbers, 258-266 Data base, 8 English sentences, 1,172
in Math: A Sentence Generator, 39-45 Data representation, 282, 335 (See also Sentence generator, English)
MATH, 45 (See also List, as data representa- Error, minimum, 340
in Number Speller, 46-50 tion) Event code, 376
Arithmetic operations, 39, 258 Data structure, 335 Events, 376
Aspect ratio, 269, 283 Davis, James, 172, 302 Exercise, 80-87
Decay of sound, 374 EXERCISE, 85
Delpit, Lisa, 35
Behensky, Max, 242, 251 Demon joystick, 376, 380
Bestline, 337-347 (See also Joystick) Files:
BESTLINE, 346 Demons, 376 loading additional procedures from:
Binary digits (bits), x, 283 in Alien, 162, 166 in Dungeon, 197
Biology: in Blaster, 153, 155 in Jack and Jill, 117
in Bestline, 337 in Boxgame, 133-134 storing data in: in Display Workspace
in preface, x in Cartoon, 93-96 Manager, 294, 296
381
382 INDEX
Positioning text on screen, 30-31, 292 Slope, 340, 348 Stop rule, 48
Predicate, 173, 181 Societies, computer programs as, x Subtree, 13
Primitive, 266, 302, 307 Solomon, Cynthia, 1, 39, 133, 362, 366, Sussman, Gerald J., 303
Programming languages, xi, 302ff. 376 Szneech, Martian, x
Property lists, 173 Solomon, Erric, 87, 214, 222, 227
Sorting, 295, 331-337
Sounds and Music: Teaching, 258ff.
Quoting special characters, 7, 42 chromatic step, 372 Template, 53, 325
decay, 374 THING, 8, 146, 251
duration, 230, 373 Tinkertoy tic-tac-toe machine, ix
frequency, 371 T O O T , 371
RC, 22, 61, 299
glissandi, 244 TOUCHING, 376
Recursion, 258, 275, 306, 333
half step, 374 Towards and Arctan, 212-213
Reflecting shapes, 157
interval, 239, 374-375 ARCTAN, 213
Rhythm, 236, 374
loudness, 230, 374-375 TOWARDS, 213
Rocket, 124-132
note, 231-242, 251-257, 371-373 Trees (diagram):
ROCKET, 128
names, 231, 251, 371 data representation, 12-13
Rotating shapes, 369
octave, 371 examining, 14
RUN, 179, 204, 308, 324
pitch, 371, 373 represented as list, 13
Run-length encoding, 290
rest, 231 Trees (drawing), 115
rhythm, 236, 374 Turing, Alan, xi
scale, 374 Turtle Collisions, 376-379
Savepict and Loadpict, 282-291 sequencer, 236 Turtle Graphics, 362-366
LOADPICT, 291 SETENV. 249, 374 Turtle Race, 206-210
SAVEPICT, 290, 291 T O O T , 371 RACE, 210
Saving pictures, 282 transpose, 234 Turtles and Their Shapes, 366-
Saving shapes, 144, 157, 369 trill, 247 371
Scale, musical, 374 whole step, 374
Screen dots (pixels), 269, 283 Sound Effects, 242-250
Sengen: A Sentence Generator, 1-6 advance and retreat, 243-244 Variables:
SENGEN, 5-6 ambulance siren, 242, 245 as data base, 8, 251, 309
Sentence generator: bird, 97, 117, 248 global, 17
English, 1-6 boing, 246 local, 272
SENGEN, 5 bounce, 249
math, 39-45 echo, 250
MATH, 45 fanfare, 248-249 Weinreb, William, 11
SETENV, 249, 374 glissandi, 244-245 WHEN, 377-380
Seven-segment digits, 50 motorcycle, 245 WHO, 362
(See also Drawing Letters) rocketship, 126 Word, iteration over (mapping over),
Shape editor, 366 siren, 242, 245 327-328
Shape lists, 370 sliding, 244-245 Wordscram (word scrambling game), 67-
Shapes, 366-371 Space Invader game, 160 74
loading, 144, 153, 369 spaceship, 245 WORDSCRAM, 71
reflecting, 157 trill, 247 Workspace management (see Files)
saving, 144, 157, 369 Sparse data representation, 286
Sharman, Keith, 67 Speed, turtle, 362
Simulation, viii, x, 172 Spelling numbers (see Number Speller) Young, Lauren, 124
384 INDEX
Procedures Index