Atari Logo Basics: Turtles, Procedures, Recursion, Shapes and Sound
Atari Logo is the Atari 8-bit's version of the language Seymour Papert's group at MIT built around the turtle. It was written by Logo Computer Systems Inc. (LCSI), the Montreal company that also produced Apple Logo. Antic credited Brian Silverman with LCSI's technical direction, and marvelled that the whole language fitted into a 16K cartridge when Apple Logo needed 48K. Atari Logo came out in 1983, and it is much more than a drawing toy. On top of the classic turtle it gives you four turtles that can move by themselves, wear shapes you design, detect collisions, and make sound.
What you'll learn: starting Logo, driving the turtle, writing and editing procedures, colours and pens, recursion with stop rules, multiple moving turtles and shapes, collision "demons", the TOOT sound command, and saving your workspace.
What you need: the Atari Logo cartridge (or its ROM image in an emulator) on any Atari 8-bit, and a disk drive or program recorder if you want to save. Everything you define lives in Logo's workspace in memory until you save it.
1. Starting up
To use a disk, switch the drive on first and insert a disk that contains DOS (the Atari master diskette, or a data disk with the DOS files). Then insert the cartridge and switch the computer on. You'll see:
(C) 1983 LCSI ALL RIGHTS RESERVED
WELCOME TO ATARI LOGO.
?
The ? is Logo's prompt. Three things trip up newcomers:
- Capitals only. Logo primitives must be typed in uppercase. If Logo stops understanding you, you've probably pressed CAPS. SHIFT+CAPS locks uppercase again.
- BREAK stops whatever is running and prints
STOPPED!. - Don't press SYSTEM RESET. It wipes everything in memory.
If you type something Logo doesn't know, it says so: I DON'T KNOW HOW TO HELLO.
2. Driving the turtle
The turtle starts in the middle of the screen, pointing straight up. It moves with FORWARD (FD) and BACK (BK), and turns with RIGHT (RT) and LEFT (LT) a number of degrees. The first graphics command splits the screen: the top part becomes the turtle field and the bottom five lines stay for text.
FD 50 RT 90 FD 50
CS
REPEAT 4 [FD 30 RT 90]
CS clears the screen and returns the turtle to its home position. REPEAT runs the instruction list in square brackets a number of times. Don't confuse brackets [ ] with parentheses ( ): they mean different things in Logo.
Pen commands change what the turtle leaves behind: PU (pen up), PD (pen down), PE (pen erase, rubs out lines it crosses) and PX (pen reverse, draws on blank areas and erases existing lines). HT and ST hide and show the turtle.
3. Procedures and the editor
A procedure is a new command you teach Logo. The quickest way is TO:
TO SQUARE :SIZE
REPEAT 4 [FD :SIZE RT 90]
END
While you're defining, the prompt changes to >. After END, Logo answers SQUARE DEFINED. The :SIZE on the title line is an input. Inside the procedure, :SIZE means "the value of SIZE". Now build on it:
TO FLOWER
REPEAT 12 [SQUARE 40 RT 30]
END
Type FLOWER and the turtle draws twelve squares, each turned 30 degrees from the last.
To fix mistakes, use the full-screen editor: ED "SQUARE (note the quote mark and no space). The turtle drawing disappears while you edit. Move with the CTRL+arrow keys, delete with CTRL+DELETE BACK S, and press ESC to finish and define the procedure. BREAK leaves the editor without keeping your changes. POTS prints the title lines of every procedure in the workspace, a handy table of contents.
4. Colours and pens
Atari Logo uses the full 128-colour palette: 16 hues with 8 shades each, numbered 0–127 (for each hue, the lowest number is the darkest). Logo starts with a blue background, colour 74.
SETBG 0
SETPN 1
REPEAT 4 [FD 30 RT 90]
SETPC 1 40
The turtle has three pens, numbered 0, 1 and 2. At start-up pen 0 draws gold (15), pen 1 purple (47) and pen 2 red (121). SETPN chooses the pen. SETPC sets a pen's colour, and it also recolours everything already drawn with that pen. The last line above turns the purple square magenta. PRINT BG and PRINT PC 1 report the current numbers. WAIT 60 pauses for one second (the unit is 1/60 second).
5. Recursion
A procedure that calls itself is recursive. This one draws a square spiral:
TO SPI :STEP :ANGLE :INC
IF :STEP > 150 [STOP]
FD :STEP
RT :ANGLE
SPI :STEP + :INC :ANGLE :INC
END
Try CS SPI 5 90 3, then CS SPI 5 144 2. Each call draws one segment and then calls SPI again with a longer step. The first line is the stop rule: without it the spiral would continue until you pressed BREAK. Other useful stop rules are IF KEYP [STOP] (stop when any key is pressed) and, for closed shapes, stopping when HEADING returns to its starting value. Put a heading test after the turn, or it will stop before drawing anything.
6. Four turtles, shapes and collisions
Turtles are numbered 0 to 3. TELL chooses which one receives your commands, and a list addresses several at once:
TELL [1 2 3] ST
TELL 1 RT 90
TELL 2 RT 180
TELL 3 RT 270
TELL [0 1 2 3] SETSP 20
All four turtles now crawl away in different directions, by themselves. SETSP sets a speed, larger numbers are faster, and SETSP 0 stops them. While they move, the prompt stays free, so you can keep typing commands. SETC changes a turtle's colour, using the same 0–127 numbers.
Shapes. EDSH 1 opens the shape editor for shape 1 (there are 15 shape slots). Each shape is an 8-column by 16-row grid. Move with CTRL+arrows and toggle squares with the space bar, then press ESC. SETSH 1 puts the shape on the current turtle, and SETSH 0 brings back the turtle shape. Custom shapes don't rotate when the heading changes, although the turtle still moves in its heading's direction.
Collisions. Logo can watch for a turtle touching a drawing or another turtle, and run a list of commands when it happens. The "WHEN demon":
WHEN 4 [RT 180]
Condition 4 means turtle 1 has run over something drawn with pen 0. The Reference Manual tabulates all 22 collision numbers (0–21). The OVER and TOUCHING operations work out the number for you, for example OVER 1 0. WHEN 4 [] cancels the demon.
7. Sound and joysticks
TOOT takes four inputs: voice (0 or 1), frequency in hertz (14 and up; 440 is concert A), volume 0–15 and duration 0–255 in sixtieths of a second. A second TOOT on the same voice waits for the first to finish, so a melody is simply a list of TOOTs:
TO TUNE
TOOT 0 262 15 20
TOOT 0 330 15 20
TOOT 0 392 15 40
END
With two voices you can play harmony. The Logo manual's car-race example links sound to the joystick: JOY 0 reports the stick in the first controller jack, JOYB 0 is TRUE while its button is down, and an engine noise is made with TOOT 0 (JOY 0) * 10 + 30 15 4.
8. Saving your work
SAVE writes the whole workspace, every procedure and named variable, to one file. LOAD reads it back.
| Task | Command |
|---|---|
| Save to disk | SAVE "D:DESIGN.001 |
| Load from disk | LOAD "D:DESIGN.001 |
| Disk directory | CATALOG "D: |
| Delete a disk file | ERF "D:DESIGN.001 |
| Save / load cassette | SAVE "C: / LOAD "C: |
| Print all procedures | SAVE "P: |
Disk filenames follow DOS rules: up to 8 characters starting with a letter, an optional 3-character extension, all uppercase. If you see I CAN'T OPEN D:DESIGN.001, the drive probably wasn't on when you started the computer.
Shapes aren't saved automatically. First give each one a name, as in MAKE "BOX GETSH 1, and then SAVE. After loading, PUTSH 1 :BOX puts it back into slot 1.
Troubleshooting
I DON'T KNOW HOW TO SQUARE. The procedure isn't in the workspace. Define it again or LOAD it. Check your spelling:FRWARDis notFORWARD.EDIT SQUAREfails. You left out the quote: it must beED "SQUARE.- Turtle 1 doesn't appear after
TELL 1. It is hidden. TypeST. - Procedure runs forever. Press BREAK, then add a stop rule.
- Disk problems with modern SIO devices. Logo starts DOS itself, which can clash with some devices' configuration menus. The FujiNet Setup Guide describes a workaround.
Further reading
- Atari Logo Reference Manual and Atari Logo: Introduction to Programming Through Turtle Graphics (LCSI for Atari, 1983). The second is the source of the SPI, car race and shape examples, and the Reference Manual covers list processing, which this guide skips.
- Ian Chadwick, "Logo's Lineage: The Canadian Connection", Antic, March 1984.
- Donna Bearden, 1, 2, 3, My Computer and Me: A Logo Funbook for Kids.
- Ryszard Tadeusiewicz, Atari Logo: komputerowe przygody (Polish).
- On this site: Atari PILOT for Beginners, which also has turtle graphics, and FORTH on the Atari.
Credits
- Antic v2n12 (March 1984) — Ian Chadwick, Logo's Lineage: The Canadian Connection — AtariMagazines.com (Kevin Savetz), 1984
- AtariAge — Any interest in Atari LOGO examples? — AtariAge forum members
