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 teaches the user about geometry. 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 a lot of repeated instructions 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. Wouldn't it be more useful just to say "square" when you wanted a square?

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

SQUARE

What are the TO and END for? They 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. What about square of other sizes?

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 do better. Wouldn't it be nice 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 works, but it's more typing than we need to do. Worse, the different procedures are mostly the same and we need to define a different procedure for every shape. 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 load them. How do you load you work from disk?

LOAD "SHAPES.LGO

I could go on forever, yes forever, even to the point of writing Logo within Logo.

That's a quick introduction. Do you want to learn more? Almost every command in this help file has a simple example that shows how to use it. Also check out the examples that come with FMSLogo (see the Help Menu). These examples show how to combine several procedures to perform a simple task. You can search for some tutorials on the Web, like The Logo Workshop. Jim Muller's book "The Great Logo Adventure" is based on MSWLogo, but should be applicable to FMSLogo. For more advanced topics, see Brian Harvey's three volume Computer Science Logo Style from the MIT Press.

However you choose to learn more, make sure that you have fun learning it.


SourceForge.net Logo