Where to Start

Novices can start in Logo without having to program at all by just learning how to command the turtle. Learning turtle graphics will teach the user about geometry (and they won't even know it). It's amazing how soon you can introduce the concept of programming once they grasp the turtle concept. Let's look at some simple examples:

Draw a square using the turtle.

FORWARD 100
RIGHT 90
FORWARD 100
RIGHT 90
FORWARD 100
RIGHT 90
FORWARD 100
RIGHT 90

That was easy but too much typing, let's try again.

REPEAT 4 [FD 100 RT 90]

That's it? Yes, that's the same square. We did two things. We noticed too much redundant code in our first example, so we asked Logo to repeat the same sequence 4 times. We also used abbreviated forms of the same commands. But we can still do better. A square is a popular item wouldn't you say? Wouldn't it be more useful just to say square when you wanted a square?

EDIT "SQUARE
<Editor will pop up>
TO SQUARE
  REPEAT 4 [FORWARD 100 RIGHT 90]
END
<Exit Editor and save>

SQUARE

What's the TO and END for? It's to define a procedure (a small program) for the square. The TO can be thought of as "to do something", the END terminates the TO. Once SQUARE was "defined" we then called it. That's all you need to get a square now, just type SQUARE. There is a problem, however. SQUARE only draws squares of 100 by 100. Wouldn't it be better to draw any size square? It sure would and it's easy.

EDIT "SQUARE

TO SQUARE :length
  REPEAT 4 [FORWARD :length RIGHT 90]
END

SQUARE 100
SQUARE 200

Note all we did is replace 100 with a variable name called :length. Now when we call square we must specify how big we want it. Above we asked Logo to draw one square at 100x100 and another at 200x200. Note the ":" in front of the word length tells Logo that length is a variable. However, we can still even do better. What's wrong now, you ask. Well, wouldn't it be better if we could draw something other than a square, like a triangle?

TO TRIANGLE :length
  REPEAT 3 [FORWARD :length RIGHT 120]
END

TO SQUARE :length
  REPEAT 4 [FORWARD :length RIGHT 90]
END

TO PENTAGON :length
  REPEAT 5 [FORWARD :length RIGHT 72]
END

TRIANGLE 100
SQUARE 100
PENTAGON 100

That's a lot of typing (programmers hate to type). Why? Because there are more things to break and when a change needs to be made it might have to made in many places. Smaller is not always better but it usually helps. Let's try again.

TO POLYGON :length :sides
  REPEAT :sides [FORWARD :length RIGHT 360/:sides]
END

POLYGON 100 3
POLYGON 100 4
POLYGON 100 5

What happened to TRIANGLE, SQUARE and PENTAGON? We don't need them because POLYGON can draw every equal-sided polygon possible and with only one line of code! We now repeat the sequence based on how many :sides the caller asked for and we turn (RIGHT) the amount of degrees appropriate for that shape. You may not realize it but this is programming.

Now that we have a program, it's a good idea to save it to a file. The edits you've made so far are all in Logo's memory and not on the disk. How do you save your work? It's easy.

SAVE "SHAPES.LGO
BYE

If you ever want to use these definitions again you'll have to reload them. How do you reload you work from disk?

LOAD "SHAPES.LGO

I could go on for ever, yes for ever, even to the point of writing Logo within Logo. This should get you started. Where can I learn more?

Almost every command in this help file has a simple example of using it. Check out the examples (see the Help Menu). The MSWLogo online Video Tutorial (separate kit) only basics. Jim Muller's Great Logo Adventure Book primarily based on MSWLogo. Brian Harvey's MIT Press Books for more advanced programming.

What ever do make sure you have fun.


SourceForge.net Logo