Turtle graphics

Like BASIC, LOGO is a computer language. LOGO is better than BASIC in three ways: by using LOGO, you can more easily create graphics, build "lists of lists", and design your own computer language (by adding your own words to LOGO). Letís see how!

Iíll explain the best version of LOGO, then explain how other versions differ.

To start using LOGO, put the LOGO disk into the computer, then turn the computer on. The computer will say:

WELCOME TO LOGO

Differences Some versions of LOGO come on tapes or ROM cartridges instead of disks. Some versions use a mouse and require you to point at a LOGO icon.

Most versions of LOGO donít understand small letters; they understand just capitals. If your computer has a CAPS LOCK key, make sure itís pressed down.

To start Commodore LOGO, say:

LOAD "LOGO",8

RUN

To start the disk version of Radio Shack Color LOGO, say:

LOADM "LOGO"

EXEC

After Radio Shack Color LOGO says "LOGO:", tap the R key.

To use a version of LOGO called "LOGO Writer", use the student disk that your teacher created from the master disk, or use the TRY ME disk. Before using the TRY ME disk on an IBM PC, do the following: insert the PC-DOS disk, turn on the computer, type the date and time, insert the TRY ME disk, then type ó

A>logowrit

When you start using LOGO Writer, the top of the screen will say CONTENTS. To continue beyond that point, press the ENTER key.

Show the turtle

To draw pictures, you move a turtle across the screen. To see the turtle, say SHOWTURTLE, like this:

SHOWTURTLE

SHOWTURTLE is all one word. Do not put a space between SHOW and TURTLE.

LOGO lets you abbreviate most words. The abbreviation for SHOWTURTLE is ST; so instead of typing SHOWTURTLE you can type just ST, like this:

ST

After you say SHOWTURTLE (or ST), youíll see a turtle in the center of your screen.

You can make the turtle either visible or invisible. To make it invisible, say HIDETURTLE (or HT). To make it visible again, say SHOWTURTLE (or ST) again.

Differences Many versions of LOGO put a question mark on the screen and expect you to type a command after the question mark. For example, to say SHOWTURTLE, type SHOWTURTLE after the question mark, so your screen looks like this:

?SHOWTURTLE

Atari 800 LOGO shows a good picture of a turtle (including the turtleís head, feet, tail, and shell), but most other versions of LOGO show just the turtleís nose, which looks like an arrowhead.

LOGO Writer and Atari 800 LOGO require you to abbreviate. For example, they require you to say ST instead of SHOWTURTLE.

Rotate the turtle

The screen acts as a map of the turtleís desert. Since the desertís only occupant is the turtle, the turtleís the only thing you see on the screen.

Like most maps, the screenís a rectangle whose top edge is called north, bottom edge is south, right edge is east, and left edge is west.

When you start using LOGO, the turtleís at the screenís center. The turtle faces north and stares at the screenís top edge.

As on a compass, north is called 0 degrees, east is 90 degrees, south is 180 degrees, and west is 270 degrees. To make the turtle face east, say SETHEADING 90 (or SETH 90).

When typing that command, you must press the SPACE bar before you type the 90. That command makes the turtle rotate, so that it faces east.

The turtle can rotate to any angle you wish. For example, to make the turtle face northeast, say SETHEADING 45.

You can choose any angle from 0 to 360. You can even choose decimals and negative numbers. Experiment!

Rotate to the right In LOGO, rotating clockwise is called "rotating to the right". To make the turtle rotate to the right, 90 degrees, say RIGHT 90 (or RT 90).

For example, if the turtle is facing north, and you say RIGHT 90, the turtle will face east. Then if you say RIGHT 90 again, the turtle will turn clockwise 90 degrees more, so that the turtle will face south. If you say RIGHT 90 again, the turtle will face west. If you say RIGHT 90 again, the turtle will face north again.

Rotate to the left Rotating counterclockwise is called "rotating to the left". To make the turtle rotate to the left, 90 degrees, say LEFT 90 (or LT 90).

Differences The computerís RAM accurately handles decimals (such as 4.1 degrees), but the screen shows just an approximation of whatís in the RAM. For most versions of LOGO, the screen shows the turtleís angle rounded to the nearest 15 degrees; Radio Shack Color LOGO shows the angle rounded to the nearest 45 degrees.

Move the turtle

To make the turtle walk 50 steps in the direction it faces, say FORWARD 50 (or FD 50).

For example, if the turtle faces east, and you say FORWARD 50, the turtle will walk 50 steps east. If you then say FORWARD 50 again, the turtle will walk 50 steps farther east.

To make the turtle retreat 50 steps backwards, say BACK 50 (or BK 50). For example, if the turtle faces east and you say BACK 50, the turtle will retreat 50 steps backwards: the turtle will retreat to the west while still facing east.

The point at the screenís center is called home. Thatís where the turtleís life began. To make the turtle return to its home and its original heading (facing north), say HOME.

Set the position To make the turtle hop to the point whose coordinates are [30 70], say SETPOS [30 70].

That makes the turtle hop to the point thatís 30 steps east and 70 steps north of home. The turtle hops there regardless of where the turtle was before.

Hopping does not change the direction the turtle faces. For example, if the turtle faced south before hopping, the turtle still faces south after the hop, even if itís hopped north of where it started.

Instead of saying SETPOS [30 70], you can say SETX 30 and then SETY 70, like this:

SETX 30

SETY 70

The SETX 30 makes the turtle hop across the screen horizontally east-west, until it reaches a point thatís 30 steps further east than home was. The SETY 70 makes the turtle hop vertically north-south, until it reaches a point thatís 70 steps further north than home was.

The screenís edge When you try to move the turtle past the screenís edge, what happens? The answer depends on which kind of universe you create. You have three choices.

If you say FENCE, the computer erects a fence around the desert, so that the turtle canít move past the screenís edge. If you give the turtle a command that requires the turtle to go past the fence, the turtle gripes, refuses to do the command at all, and doesnít even walk up to the fence.

If you say WINDOW instead of FENCE, the computer lets the turtle wander off the screen, to locations you canít see. Your screen acts as a window, through which you see just part of the turtleís universe.

If you say WRAP (instead of WINDOW or FENCE), moving the turtle past the screenís edge makes the turtle take a quick trip around the world. For example, if the turtle travels west, past the screenís west edge, the turtle quickly travels around the world and returns from the east. If the turtle travels north, past the screenís top edge, the turtle quickly travels around the world (past the north and south poles) and returns from the south.

When you start using LOGO, you automatically begin with a WRAPped universe, but you can switch to a FENCE or WINDOW.

Leisure-time jog When the turtle isnít busy obeying your commands, how does it spend its leisure time? Normally, the turtle just sits still. But if you say SETSP 30, the turtle will spend all its leisure time jogging at speed 30, in whatever direction the turtle is facing.

For example, suppose the turtle is facing north, and you say SETSP 30. The turtle will jog north, at speed 30. The turtle will keep jogging north, until you give it another command. If you donít give another command soon, it will reach the edge of the screen, and its further fate depends on whether you said FENCE or WINDOW or WRAP.

While the turtle jogs, if you tell it to change direction (by saying SETHEADING or RIGHT or LEFT), it will continue jogging but in the new direction.

While the turtle jogs, if you tell it to walk (by saying FORWARD, BACK, SETPOS, SETX, or SETY), the turtle will walk where you said and then continue jogging from that new location.

To stop the jogging, say SETSP 0 (which sets the jogging speed to 0) or HOME (which makes the turtle go home and rest there).

Differences Atari 800 LOGO understands SETSP, but most other versions of LOGO donít. Some versions of LOGO donít understand FENCE. LOGO Writer lacks SETSP, FENCE, WINDOW, WRAP, SETX, and SETY.

For MIT versions of LOGO (such as Krell LOGO, Terrapin Apple LOGO, and Commodore LOGO), change FENCE to NOWRAP, donít say WINDOW, and change SETPOS [30 70] to SETXY 30 70; if the second number in the SETXY command is negative, put that number in parentheses. Radio Shack Color LOGO resembles MIT versions but lacks some commands, such as SETXY.

Change the pen

The turtleís belly has a ball-point pen sticking out of it. While the turtle moves, the pen scrapes along the ground and draws a line on the ground. That lineís called the turtleís trail. It appears on your screen, since your screenís a map of whatís on the ground. Even if you make the turtle invisible (by saying HIDETURTLE), youíll still see the turtleís trail.

If you say PENUP (or PU), the turtle lifts its pen from the ground, so that the pen stops drawing a trail. To put the pen back down on the ground again, say PENDOWN (or PD).

Create colors You can change the penís ink to a different color. To switch to color #2, say SETPC 2. That makes the computer set the pencolor to 2.

Erase You can replace the pen by an eraser. To do that, say PENERASE (or PE). Then as the turtle moves, it erases any ink on the ground. For example, if you turn the turtle around and make it walk back along the trail it created, it will erase the trail.

The eraser scrapes across the ground until you lift it (by saying PENUP) or insert a pen instead (by saying PENDOWN).

Reverse colors You can replace the pen by a reverser. To do that, say PENREVERSE (or PX). When you draw with the reverser on black ground, the ground becomes white, when you draw on white ground, the ground becomes black; when you draw on colored ground, the ground changes to the opposite color.

The reverser works until you lift it (by saying PENUP) or switch to a pen or eraser (by saying PENDOWN or PENERASE).

Fill in the middle After you draw a polygon (such as a triangle, rectangle, or octagon), you can fill in the middle. To do so, lift the pen (by saying PENUP), then move the turtle to somewhere in the middle of the polygon, then say PENDOWN, then say FILL. The FILL command makes the pen leak, until the ink fills the entire polygon.

Differences Instead of saying SETPC, LOGO Writer and Atari 800 LOGO say SETC; MIT versions say PC.

Instead of PENERASE, Commodore LOGO says PC -1; Krell and Terrapin Apple LOGO say PC 0; Radio Shack Color LOGO says PC 3.

Instead of PENREVERSE, Krell and Terrapin Apple LOGO say PC 6. Commodore LOGO and Radio Shack Color LOGO lack the concept.

Appleís colors are numbered from 0 to 5, IBMís and the Color Computerís from 0 to 3, Commodoreís and the Atari STís from 0 to 15, and the Atari 800ís from 0 to 127.

LOGO Writer, IBM LOGO, DR LOGO, and Atari ST LOGO understand FILL, but most other versions donít.

Change background

The desert sand is called the turtleís background. The sand appears a different color if you shine colored light at it. To make the sand appear to have color #1, say SETBG 1. That makes the computer set the background color to 1.

If you say CLEAN, a gust of wind blows all the sand around, so that the sand covers all the trails that the turtle made, and the screen is clean again: all that remains on the screen is the turtle itself.

To erase everything you did and "start over", you could say HOME (which makes the turtle return home and face north) and CLEAN (which erases the turtleís trails). But instead of saying HOME and then CLEAN, you can combine those two commands into this single command: CLEARSCREEN (or CS).

If you say DOT [20 50], a drop of ink will fall from the sky and land on the point whose coordinates are [20 50], so that you see a dot of ink at that point.

Differences For LOGO Writer, change CLEARSCREEN to CG (which means "Clear the Graphics"); to clear the graphics and the rest of the screen and make everything "fresh", say CT RG (which means "Clear the Text and Reset the Graphics"). For MIT versions of LOGO, change CLEARSCREEN to DRAW, change CLEAN to CLEARSCREEN, and change SETBG to BG. LOGO Writer, MIT versions, and Atari 800 LOGO donít understand DOT.

Extra turtles

You can create several turtles, called turtle 0, turtle 1, turtle 2, turtle 3, etc. Normally, your commands are obeyed by just turtle 0.

To talk to turtle 1 instead, say TELL 1. That makes turtle 1 appear on the screen, and all your future commands will be obeyed by turtle 1 instead of turtle 0.

While turtle 1 obeys your commands and prances around, turtle 0 will sit quietly (unless you told it to jog, by saying SETSP 30).

To start talking to turtle 0 again, say TELL 0. To talk to turtle 2, say TELL 2. To talk to turtle 3, say TELL 3.

If you say TELL [0 1 2 3], youíll be talking to turtles 0, 1, 2, and 3 simultaneously. Any commands you give will be obeyed by all those turtles.

Differences LOGO Writer, Commodore LOGO, and Atari 800 LOGO understand TELL, but most other versions of LOGO donít. LOGO Writer and Commodore LOGO hide turtles 1, 2, and 3, until you make them appear by typing ST.

In Commodore LOGO, TELL must be followed by a single number, not a list of numbers; and before saying TELL, you must feed the computer TELLís definition, by putting the Utilities Disk in the drive and typing:

READ "SPRITES

Put the quotation mark before SPRITES but not afterwards.

Graphics versus text

Usually, the top of the screen shows the map of the turtleís desert, and the bottom of the screen shows the commands youíve been typing. For example, if you say SHOWTURTLE, the top of the screen shows the turtle, and the bottom of the screen shows what you typed: the word SHOWTURTLE.

If you want to devote the entire screen to the map, say FULLSCREEN (or FS). Then the map fills the entire screen, so that you see a larger portion of the desert. Since the entire screen shows the map instead of your typing, what you type will be invisible, until you return to the normal setup (by typing MIXEDSCREEN or MS) or devote the entire screen to your typing instead of a map (by saying TEXTSCREEN or TS).

Differences For MIT versions, change MIXEDSCREEN to SPLITSCREEN, and donít use the abbreviations FS, MS, and TS. LOGO Writer always gives you a mixed screen and wonít let you change to fullscreen or textscreen.

Math

To make the computer print the answer to 5+2, say PRINT 5+2 (or PR 5+2). The computer will print the answer:

7

Like BASIC, LOGO lets you use arithmetic symbols (+, -, *, and /), negative numbers, decimals, E notation, and parentheses.

Differences For Apple LOGO 2, put a blank space before and after the symbol /. LOGO Writer puts its answers at the top of the screen and lacks E notation.

Square roots

SQRT 9 means "the square root of 9". So to print the square root of 9, type this:

PR SQRT 9

The computer will print the answer:

3

If you say ó

PR SQRT 9+7

the computer will print the square root of 16, which is 4. If you leave extra spaces, like this ó

PR SQRT 9 + 7

the computer will ignore the extra spaces: it will still print the square root of 16, which is 4. If you say ó

PR (SQRT 9)+7

the computer will find the square root of 9, which is 3, and then add 7, so it will print 10.

Differences LOGO Writer lacks SQRT.

Turtle numbers

To find out where the turtle is, say PR XCOR (which prints the X coordinate) and PR YCOR (which prints the Y coordinate).

To slide the turtle 20 steps farther east, say SETX XCOR+20. That says to increase the X coordinate by 20.

To slide the turtle 20 steps farther west instead, say SETX XCOR-20. To slide the turtle 20 steps north, say SETY YCOR+20. To slide the turtle 20 steps south, say SETY YCOR-20.

If you say PR HEADING, the computer will tell you which direction the turtleís facing. For example, if the turtleís facing east, the computer will print 90. The HEADING will always be a number between 0 and 360.

If you say PR TOWARDS [30 70], the computer will tell you which direction to turn the turtle, to make the turtle face the point [30 70]. The direction will be a number between 0 and 360. To actually turn the turtle in that direction, so that the turtle faces the point [30 70], say SETHEADING TOWARDS [30 70]. So to make the turtle "walk 10 steps towards the point [30 70]", say this:

SETHEADING TOWARDS [30 70]

FORWARD 10

To find out the color of the ink in the turtleís pen, say PR PENCOLOR (or PR PC); the computer will print the colorís number. To find out the color of the background sand, say PR BACKGROUND (or PR BG).

To find out which turtle youíre talking to, say PR WHO. The computer will print the turtleís number.

Differences For MIT versions, change PENCOLOR to LAST TS, change BACKGROUND to ITEM 3 TS, and omit the brackets after TOWARDS. For LOGO Writer, change PENCOLOR to COLOR, change XCOR to FIRST POS, change YCOR to LAST POS, and donít say TOWARDS.

Random numbers

If you say PR RANDOM 5, the computer randomly chooses one of these 5 integers: 0, 1, 2, 3, 4. The computer prints the integer it chooses.

Rounding

If you say PR INT 3.9, the computer will convert 3.9 to an INTeger by omitting everything after the decimal point. The computer will print just 3.

If you say PR ROUND 3.9, the computer will ROUND 3.9 to the nearest integer, which is 4. The computer will print 4.

Differences For MIT versions, change INT to INTEGER. LOGO Writer lacks INT and ROUND.

Fancy division

If you say PR 11/4, the computer will divide 11 by 4 and print the answer, which is 2.75.

If you say PR QUOTIENT 11 4, the computer will divide 11 by 4 but ignore what comes after the decimal point. The computer will print just 2.

If you say PR REMAINDER 11 4, the computer will divide 11 by 4, and realize that 4 goes into 11 "2 times, with a remainder of 3". The computer will print the remainder, 3.

Differences LOGO Writer lacks QUOTIENT.

Trigonometry

To print the sine of 30 degrees, say PR SIN 30. To print the cosine of 30 degrees, say PR COS 30.

Since the tangent is "the sine divided by the cosine", you can print the tangent of 30 degrees by saying PR (SIN 30)/COS 30.

The opposite of tangent is arctangent. To print the arctangent of .58, say PR ARCTAN .58. That makes the computer print how many degrees are in the angle whose tangent is .58.

Differences LOGO Writer and Atari 800 LOGO lack ARCTAN. For MIT versions, change ARCTAN .58 to ARCTAN .58 1.

Structures

To make the computer print the word LOVE, type this:

PR "LOVE

In LOGO, a quotation mark means: the word. So that whole line means: PRint the word LOVE.

Make sure you put the quotation mark before LOVE, but do not put a quotation mark afterwards! That line is pronounced: P R quotes LOVE.

When you press the ENTER key at the end of that line, the computer will print:

LOVE

Lists

To print a list of words, put the list in brackets, like this:

PR [MA CAN'T LOOK]

That tells the computer to print a list of three words. The first word is MA; the second is CANíT; the third is LOOK.

The computer will print the list but wonít bother to print the brackets. The computer will print just:

MA CANíT LOOK

If you say SHOW instead of PR, the computer will print the brackets also, like this:

[MA CANíT LOOK]

The computer understands FIRST, LAST, and similar concepts:

Function Meaning Result

FIRST [MA CAN'T LOOK] the listís first item MA

LAST [MA CAN'T LOOK] the listís last item LOOK

ITEM 2 [MA CAN'T LOOK] the listís 2nd item CAN'T

COUNT [MA CAN'T LOOK] how many items 3

BUTFIRST [MA CAN'T LOOK] all but the first item [CAN'T LOOK]

BUTLAST [MA CAN'T LOOK] all but the last item [MA CAN'T]

FPUT "WOW [MA CAN'T LOOK] put WOW first [WOW MA CAN'T LOOK]

LPUT "WOW [MA CAN'T LOOK] put WOW last [MA CAN'T LOOK WOW]

WORD "WOW "MA combine words into long word WOWMA

LIST "MA "CAN'T combine words to form a list [MA CAN'T]

SENTENCE [WOW MA] [CAN'T LOOK] combine lists [WOW MA CAN'T LOOK]

When you type those examples, begin each line by saying PR or SHOW. For example, if you say ó

SHOW BUTFIRST [MA CAN'T LOOK]

the computer will say:

[CAN'T LOOK]

You can abbreviate BUTFIRST to BF, BUTLAST to BL, and SENTENCE to SE.

A wordís a list of characters. For example, the word FUN is a list of three characters (F, U, and N). So all the list concepts (such as FIRST, LAST, ITEM, and COUNT) apply to words also. For example, if you say ó

SHOW BUTFIRST "FUN

or ó

PR BUTFIRST "FUN

the computer will say:

UN

Since FIRST [MA CANíT LOOK] is MA, whose last character is A, the computer knows that LAST FIRST [MA CANíT LOOK] is A.

You can put lists inside lists. For example, since FIRST [[MA PA] CANíT LOOK] is [MA PA], whose last item is PA, the computer knows that LAST FIRST [[MA PA] CANíT LOOK] is PA.

Differences MIT versions donít understand SHOW. For Commodore LOGO, change SHOW to FPRINT.

Atari 800 LOGO doesnít understand ITEM. Version 1 of Terrapin Apple LOGO didnít understand ITEM and COUNT. Version 1 of Apple LOGO could find an ITEM within a list of words but not within a single word.

Multiple commands

You can put several LOGO commands on the same line.

For example, you can say:

FD 50 RT 90

When you press the ENTER key at the end of that line, the turtle will go forward 50 and then turn right 90 degrees.

If you say ó

PR 5+2 PR 30+9.1

the computer will print the answers on separate lines:

7

39.1

If you say ó

PR [SKY IS BLUE] PR [SO ARE YOU]

the computer will print this poem:

SKY IS BLUE

SO ARE YOU

REPEAT

Letís make the turtle draw a square, so that each side is 50 steps long.

To do that, first make sure the turtleís pen is down, so that the turtle will draw as it moves. To make sure the penís down, you can say PENDOWN (or PD).

To make the turtle draw the first side, say FORWARD 50 (or FD 50). Then tell the turtle to turn right 90 degrees, by saying RIGHT 90 or RT 90. Draw the second side, by saying FD 50 again. Then tell the turtle to turn right 90 degrees again, etc.

Altogether, these commands make the turtle draw all four sides of the square:

FD 50 RT 90 FD 50 RT 90 FD 50 RT 90 FD 50 RT 90

But instead of typing all that, you can type this short cut:

REPEAT 4 [FD 50 RT 90]

That makes the computer REPEAT, 4 times, the act of going forward 50 and turning right 90 degrees.

Letís make the computer print the word WOW, twenty times. Hereís how:

REPEAT 20 [PR "WOW]

The computer will print the words on separate lines, like this:

WOW

WOW

WOW

etc.

Hereís how to make the computer say FRANCE IS FUNNY, twenty times:

REPEAT 20 [PR [FRANCE IS FUNNY]]

 

Variables

You can MAKE a word stand for something. To make the word DRINKINGAGE stand for 21, type this:

MAKE "DRINKINGAGE 21

In that line, DRINKINGAGE is called the variable or the name; 21 is called DRINKINGAGEís value or the thing that DRINKINGAGE stands for.

After you type that line, you can say:

PR THING "DRINKINGAGE

That makes the computer print the THING that DRINKINGAGE stands for. The computer will print:

21

Instead of typing THING and then a quotation mark, you can type just a colon, like this:

PR :DRINKINGAGE

That means: PRint the thing that DRINKINGAGE stands for. It means: PRINT the value of DRINKINGAGE. The computer will print:

21

LOGO programmers have a nickname for the colon: they call it dots. So the statement ó

PR :DRINKINGAGE

is pronounced: P R dots DRINKINGAGE.

Hereís another example:

MAKE "MAGICNUMBER 7

PR :MAGICNUMBER+2

The first line makes the word MAGICNUMBER stand for 7. The next line says to print the value of the MAGICNUMBER, plus 2. The computer will print 9.

A word can stand for anything; it can even stand for a list. For example, you can say:

MAKE "STOOGES [MOE LARRY CURLEY]

PR COUNT :STOOGES

The first line says the word STOOGES stands for the list [MOE LARRY CURLEY]. The next line makes the computer print the COUNT of how many items are in that list; the computer will print:

3

Hereís the rule: to define a word, say MAKE and type a quotation mark; to use the wordís value, type a colon instead.

Programs

To teach the computer what the word SQUARE means, type this:

TO SQUARE

REPEAT 4 [FD 50 RT 90]

END

The first line means: hereís how TO do a SQUARE. The next line gives the definition itself: repeat 4 times the act of going forward 50 steps and turning right 90 degrees. The bottom line of every definition says END.

Those three lines form the definition of SQUARE. Theyíre also called the program for square, and the procedure for how to do a SQUARE.

After you type those three lines, the computer will know the meaning of SQUARE. So in the future, whenever you say ó

SQUARE

the turtle will draw a square.

Differences Before you type the word TO, LOGO Writer requires you to tap the F key while holding down the CONTROL key (on the IBM) or Open Apple key (on the Apple); Radio Shack Color LOGO requires you to tap the BREAK key, then tap the CLEAR key while holding down the SHIFT key, then tap the E key.

Many versions of LOGO automatically put the symbol ">" at the beginning of each line of the definition.

After you type the word END, some versions of LOGO require you to tap an extra key or two: for LOGO Writer, tap the F key while holding down the CONTROL key (IBM) or Open Apple key (Apple); for Commodore LOGO, tap the RUN STOP key; for Krell and Terrapin Apple LOGO, tap the C key while holding down the CONTROL key; for Radio Shack Color LOGO, tap the BREAK key then the R key.

Pinwheel

If you draw a square, then rotate 10 degrees, then draw another square, you get this:

 

 

 

 

 

 

Suppose you continue that process: draw a square, then rotate 10 degrees, then draw another square, then rotate 10 degrees again, then draw another square, then rotate 10 degrees again, etc. Youíll get this pinwheel:

 

 

 

 

 

 

 

 

 

 

 

 

Letís define PINWHEEL to be that shape. Hereís how:

TO PINWHEEL

REPEAT 36 [SQUARE RT 10]

END

Rebuke

Letís define REBUKE to be this message:

YOU LOOK TERRIF!

YOU DRESS SO SPIFF!

YOU ACT SO COOL!

YOU MAKE ME DROOL!

BUT YOU'RE A FOOL!

YOU'RE FAILING SCHOOL!

YOU'RE REALLY DUMB!

A FIRST - CLASS BUM!

SO GET YOUR MIND

OFF ITS BEHIND,

AND YOU WILL FIND

YOU'RE ONE - OF - A - KIND!

Hereís how:

TO REBUKE

PR [YOU LOOK TERRIF!]

PR [YOU DRESS SO SPIFF!]

PR [YOU ACT SO COOL!]

PR [YOU MAKE ME DROOL!]

PR []

PR [BUT YOU'RE A FOOL!]

PR [YOU'RE FAILING SCHOOL!]

PR [YOU'RE REALLY DUMB!]

PR [A FIRST - CLASS BUM!]

PR []

PR [SO GET YOUR MIND]

PR [OFF ITS BEHIND,]

PR [AND YOU WILL FIND]

PR [YOU'RE ONE - OF - A - KIND!

END

Then whenever you say ó

REBUKE

the computer will print the poem. (To see the whole poem on the screen at once, say TEXTSCREEN before saying REBUKE.)

To have fun, say that poem out loud in a jive rap style, and clap your hands twice at the end of each line.

EDIT

After youíve defined a word (such as REBUKE), you can EDIT that definition by saying ó

EDIT "REBUKE

The computer will put your definition on the screen and let you edit that definition, by using the arrow keys and the other edit keys. When youíve finished editing the definition, tap the ESCAPE key.

If you say EDIT [REBUKE PINWHEEL], the computer will put both definitions on the screen simultaneously and let you edit them both. When youíve finished editing them, tap the ESCAPE key.

If you say just EDIT, the screen will show what you edited last time, so you can edit it again.

The abbreviation for EDIT is ED.

Differences While editing, experiment! Try tapping the arrow keys, ENTER key, RETURN key, BACKSPACE key, DELETE key, INSERT key, CONTROL key, and any other edit keys on your keyboard. When using LOGO, those keys act the same as when using most word processors.

On old Apples that lack up-arrow, down-arrow, and DELETE keys, do this: to move up to the Previous line, tap the P key while holding down the CONTROL key; to delete the Next line, tap the N key while holding down the CONTROL key; to delete the character left of the cursor, tap the ESCAPE key; if you have Apple LOGO 1 and want to move Back to the left, tap the B key while holding down the CONTROL key.

For MIT versions, omit the quotation mark after EDIT.

Instead of tapping the ESCAPE key, do the following: for MIT versions and Apple LOGO 1, tap the C key while holding down the CONTROL key; for Apple LOGO 2, tap the A key while holding down the open-Apple key.

For LOGO Writer and Radio Shack Color LOGO, instead of saying EDIT, follow the procedure for saying TO.

Flexible definitions

Letís change the definition of SQUARE, to make it more flexible. Letís define SQUARE so that SQUARE 50 will be a square thatís 50 steps long on each side, and SQUARE 100 will be a square thatís 100 steps long on each side, and SQUARE 6 will be a square thatís 6 steps long on each side, etc.

To do all that, edit the definition of SQUARE by saying:

EDIT "SQUARE

The computer will show our old definition of SQUARE:

TO SQUARE

REPEAT 4 [FD 50 RT 90]

END

Using the arrow keys, insert :SIDE after SQUARE, and change the 50 to :SIDE, so that the definition looks like this:

TO SQUARE

REPEAT 4 [FD :SIDE RT 90]

END

When youíve finished the editing, press the ESCAPE key.

Then if you say ó

SQUARE 100

the computer will look at the new definition of SQUARE, realize that :SIDE is 100, and do REPEAT 4 [FD 100 RT 90], which draws a square having 100 steps on each side.

After changing the definition of SQUARE in that way, you must always put a number after the word SQUARE. If you say SQUARE 100, the computer will draw a square whose side is 100; if you say SQUARE 6, the computer will draw a square whose side is 6; but if you say just SQUARE, the computer wonít know how long to make the side and will gripe, by saying NOT ENOUGH INPUTS TO SQUARE.

After changing the definition of SQUARE, you must update the definition of PINWHEEL, so that it uses the new definition of SQUARE. Edit PINWHEEL so that it becomes:

TO PINWHEEL :SIDE

REPEAT 36 [SQUARE :SIDE RT 10]

END

Then if you say PINWHEEL 50, the computer will draw a normal pinwheel; if you say PINWHEEL 100, the computer will draw a pinwheel thatís twice as long in each direction; if you say PINWHEEL 30, the computer will draw a pinwheel thatís small.

Polygon

Letís define POLYGON so that POLYGON 5 40 will be a regular polygon having 5 sides, and each side will be 40 steps long.

Hereís how:

TO POLYGON :N :SIDE

REPEAT :N [FD :SIDE RT 360/:N]

END

In that definition, :N is the number of sides (such as 5), and :SIDE is the length of each side (such as 40).

That definition will draw any regular polygon. For example, if you want a triangle so that each side is 60 steps long, say POLYGON 3 70. If you want an octagon so that each side is 20 steps long, say POLYGON 8 20.

If you pick a large number of sides (such as 36), the polygon will look almost like a circle. Thatís how you can make LOGO imitate a circle!

Star

Letís define STAR so that STAR 5 40 will be a 5-pointed star, and each side will be 40 steps long.

The definition is almost the same as POLYGONís:

TO STAR :N :SIDE

REPEAT :N [FD :SIDE RT 360/:N FD :SIDE LT 720/:N]

END

That definition makes the turtle start drawing a polygon, by drawing a polygonís first side (FD :SIDE), then turning right by the polygonís angle (RT 360/:N), then drawing the polygonís second side (FD :SIDE). But then the turtle veers sharply to the left (LT 720/:N). Repeating that procedure :N times produces a star:

 

 

 

 

 

 

 

 

 

Choose as many points as you wish. For a 5-pointed star, say STAR 5 40. For a 6-pointed star (a "Jewish star"), say STAR 6 40. For an 8-pointed star thatís smaller and has just 20 steps per side, say STAR 8 20.

Recursion

Hereís a poem about LOGO lovers:

LOGO LOVERS LOOK LOVELY!

LINGERING LINES, LONGINGLY LEFT!

Letís program the computer so that when you say LOVERS, the computer will print that poem again and again, forever, like this:

LOGO LOVERS LOOK LOVELY!

LINGERING LINES, LONGINGLY LEFT!

LOGO LOVERS LOOK LOVELY!

LINGERING LINES, LONGINGLY LEFT!

LOGO LOVERS LOOK LOVELY!

LINGERING LINES, LONGINGLY LEFT!

etc.

Type this:

TO LOVERS

PR [LOGO LOVERS LOOK LOVELY!]

PR [LINGERING LINES, LONGINGLY LEFT!]

PR []

LOVERS

END

The three PR statements make the computer print the poem and a blank line underneath. The bottom line says END; but above the word END, I inserted the word LOVERS, which makes the computer do LOVERS again, so the computer again prints the poem and blank line and comes to the LOVERS line again, so the computer again prints the poem and blank line and comes to the LOVERS line again, etc. The programís an infinite loop.

After you type that definition of LOVERS, you can activate it by saying just LOVERS or ó better yet ó say TEXTSCREEN and then LOVERS.

To abort the program, press the BREAK key.

Notice I inserted the word LOVERS into the definition of LOVERS, so that LOVERS is defined in terms of itself. Thatís called a self-referent definition or circular definition or recursive definition. Using recursive definitions is called recursion. In LOGO, recursionís the usual way to create loops.

Differences Atari 800 LOGO and Radio Shack Color LOGO let you abort by tapping the BREAK key, but most other versions of LOGO abort differently. For IBM LOGO, tap the BREAK key while holding down the CONTROL key. For LOGO Writer, tap the ESCAPE key. For Apple LOGO 2, tap the ESCAPE key while holding down the Open Apple key. For Apple LOGO 1, Atari ST LOGO, DR LOGO, and MIT versions, tap the G key while holding down the CONTROL key.

Countdown

Letís program the computer so that COUNTDOWN 10 will make the computer count down from 10, like this:

10

9

8

7

etc.

Hereís the definition:

TO COUNTDOWN :N

PR :N

COUNTDOWN :N-1

END

To count down from a number N, that definition tells the computer to print the number N and then count down from N-1.

Unfortunately, that definitionís an infinite loop! For example, if you say COUNTDOWN 10, that definition will make the computer print 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, -1, -2, -3, -4, etc., forever!

Letís edit that definition, to STOP the computer from printing negative numbers. Say:

EDIT "COUNTDOWN

Then use the arrow keys, to change the definition of COUNTDOWN to this:

TO COUNTDOWN :N

IF :N<0 [STOP]

PR :N

COUNTDOWN :N-1

END

Differences For MIT versions, omit the brackets around STOP.

Squiral

Letís make the computer draw the first side of a square (by saying FD :SIDE), then turn right 90 degrees (by saying RT 90), then draw the second side ó but make the second side shorter than the first! Then make the third side even shorter! Then make the fourth side even shorter!

The result will be a "shrinking square" whose fourth side doesnít meet the first side. It looks something like a square, but it spirals inward, becoming smaller. Itís called a squiral.

To create an amazing squiral, feed the computer this definition:

TO SQUIRAL :SIDE

FD :SIDE

RT 90

SQUIRAL :SIDE-3

END

That programís an infinite loop. The side becomes smaller and smaller (decreasing by 3 each time), until finally the side becomes a negative number, which makes the turtle go wild and draw fascinating weird graphics on the screen.

Feed the computer that definition. Then for the most dramatic results, feed the computer this definition ó

TO DRAMATICSQUIRAL

WRAP

PENREVERSE

FULLSCREEN

SQUIRAL 100

END

and type:

DRAMATICSQUIRAL

Workspace

When you invent a definition, the computer puts it into a part of the RAM called the workspace. The workspace holds your definitions of names (such as MAKE "DRINKINGAGE 21) and your definitions of procedures (such as TO SQUARE do REPEAT 4 [FD 50 RT 90] then END).

Printouts

To see all those definitions on your screen, say TEXTSCREEN, so that the computer can use the entire screen for text; then say POALL, which means Print Out ALL. The computer will print out all the definitions. For example, if you defined the name DRINKINGAGE and then MAGICNUMBER, and then defined the procedure SQUARE :SIDE and then PINWHEEL :SIDE, the computer will print all those definitions, like this:

TO PINWHEEL :SIDE

REPEAT 36 [SQUARE :SIDE RT 10]

SQUARE

END

TO SQUARE :SIDE

REPEAT 4 [FD :SIDE RT 90]

END

MAKE "MAGICNUMBER 7

MAKE "DRINKINGAGE 21

The computer begins with the newest procedure (PINWHEEL), then any other procedures (such as SQUARE), then the newest name (MAGICNUMBER), then any other names (such as DRINKINGAGE).

If you donít want to see all that, you can ask for an abridgment. To see definitions of just the procedures (PINWHEEL and SQUARE), say POPS, which means Print Out ProcedureS. To see definitions of just the names (MAGICNUMBER and DRINKINGAGE), say PONS, which means Print Out NameS.

To see just the top line of each procedure, say POTS, which means Print out TopS or Print Out TitleS; the computer will print:

TO PINWHEEL :SIDE

TO SQUARE :SIDE

To see the definition of just the SQUARE procedure, say PO "SQUARE. That makes the computer print the definition of SQUARE :SIDE. To see that definition first, then the definition of PINWHEEL, say PO [SQUARE PINWHEEL].

Differences LOGO Writer doesnít understand any of those commands; instead, tap the F key while holding down the CONTROL or Open Apple key, then browse through all the procedures you created, by pressing the up-arrow and down-arrow keys.

For MIT versions, change POALL to PO ALL, change POPS to PO PROCEDURES, change PONS to PO NAMES, change POTS to PO TITLES, and change PO "SQUARE to PO SQUARE.

Erase the definitions

If you no longer need the definitions you invented, you can erase them.

To ERase ALL the definitions, say ERALL. To ERase just the definitions of ProcedureS (such as PINWHEEL and SQUARE), say ERPS. To ERase just the definitions of NameS (such as MAGICNUMBER and DRINKINGAGE), say ERNS.

To ERASE just the definition of the PINWHEEL procedure, say:

ERASE "PINWHEEL

The abbreviation for ERASE is ER.

To ERase just the definition of the Name MAGICNUMBER, say ERN "MAGICNUMBER.

Differences LOGO Writer doesnít understand any of those commands; instead, get onto the screen the procedures you want to erase, then erase them by holding down the DELETE or BACKSPACE key.

For MIT versions, change ERALL to ER ALL, change ERPS to ER PROCEDURES, change ERNS to ER NAMES, change ERASE "PINWHEEL to ERASE PINWHEEL, and change ERN to ERNAME.

Save to disk

After youíve formatted a blank disk (by using DOS or BASIC or some other method), you can put that disk into the drive and copy all your definitions onto the disk. Hereís how.

Invent a filename (such as FRED) and say SAVE "FRED. On the disk, the computer will create a new file called FRED and copy all your definitions to FRED.

Later, whenever you want to use FRED, just say LOAD "FRED. The computer will go to the disk, find FRED, and copy FREDís definitions to the RAM, so you can use them.

To see a list of all the LOGO files on your disk, say CATALOG.

To delete FRED from the disk, say ERASEFILE "FRED.

Differences For MIT versions, change LOAD to READ. For IBM LOGO, DR LOGO, and Atari ST LOGO, change CATALOG to DIR. For LOGO Writer, change ERASEFILE to ERPAGE, change LOAD to GETPAGE (or GP), change CATALOG to PR PAGELIST, and change SAVE "FRED to NAMEPAGE "FRED NEWPAGE (or NP "FRED NEWPAGE). For the Atari 800, change ERASEFILE to ERF, change "FRED to "D:FRED, and change CATALOG to CATALOG "D:.