Logo Tutorial

Telling Logo Where To Go

Getting Logo to move around is easy, just tell him where to go and he'll do it. Logo always looks in a special place for instructions. That place is the first line inside the main procedure. Press the Load Code button to load the code provided for you into the pane on the right side of your Logo Application window. At the top of your screen you'll see this:

    procedure main
    end  

Put the instructions you want Logo to follow below procedure main and above end.

To get started, you'll need just three simple instructions. The first instruction, go, is your way of telling Logo to walk forward in the direction he's facing. To get Logo to walk forward 50 steps, type go 50. Remember to type this inside the main procedure. Press the draw button and watch Logo walk forward 50 steps.

The other two instructions, rt and lt tell Logo which way to turn and how much. For example, to make Logo turn right 90 degrees, type rt 90. If you don't remember how degrees work, take a look at this explanation.

The Maze

Your first challenge is to get Logo out of the maze. Use the Load Maze button on your LogoApplication to draw the maze. Now use the instructions you just learned, go, rt, and lt to get Logo out of the maze. Let us know if you need help or hints.

Animation

Logo moves so fast that you really can't see him move, you can only tell where he's been by the line he draws as he moves. To slow Logo down enough that you can see him moving, we wrote a procedure, logo. It is one of the procedures that was loaded when you pressed the Load Code button. You can use logo instead of go to tell Logo to move slowly. To tell Logo to take 50 steps, slowly, type goto logo, steps = 50. Unfortunately, on some of your computers the screen will flicker a lot when Logo moves slowly. What can we say, animation is tricky.

Syntax

Some of you may have experienced problems by now. If you forgot to put your instructions inside the main procedure then you got an error. Also, every computer language requires you to follow very precise rules when writing instructions. These rules are known as the syntax of the language. If you do not follow these rules precisely Logo will not be able to underestand your instructions.

So far, you've used four Logo commands. The first three commands, go, rt and lt just tell Logo how to move. The fourth, goto, allows you to call a procedure.

Calling Procedures

The syntax for calling procedures is:

goto procedure name, parameter = value

In goto logo, steps = 50

Some procedures have no parameters, so the syntax for calling them is just:

goto procedure name

Other procedures have two parameters, and the syntax for calling them is:

goto procedure name, parameter1 = value1, parameter2 = value2

Can you figure out what the syntax for calling a procedure that has three parameters would be?

Write Your Own Procedure

You can make procedures of your own if you want. The syntax for any procedure is the same as that for the main procedure:

procedure procedure name
  procedure body
end

In the main procedure you just wrote,

Do not call your procedure main; main is a special word reserved for the main procedure.

Try writing a procedure to draw a simple shape: a square or a triangle or a rectangle. This is an example of a procedure to draw a pentagon (a five-sided figure).

procedure pentagon
    goto logo, steps = 50
    rt 360/5
    goto logo, steps = 50
    rt 360/5
    goto logo, steps = 50
    rt 360/5
    goto logo, steps = 50
    rt 360/5
    goto logo, steps = 50
    rt 360/5
end

Notice that Logo can do simple math; instead of bothering to calculate 360/5 for myself, I let Logo do it.Also, I used the logo procedure because I wanted Logo to move slowly. If you want Logo to move rapidly, use the go command instead. Go ahead and call your procedure inside your main method. Use the Clear button to get rid of the maze.

Parameterize Your Procedure

The pentagon procedure is nice, but it could be better. Right now, it only makes one size of pentagon, one where Logo takes 50 steps on each side. If I make the number of steps that Logo takes a parameter of the procedure, then I can use the same procedure to draw pentagons of any size.

  
procedure pentagon
    goto logo, steps = side
    rt 360/5
    goto logo, steps = side
    rt 360/5
    goto logo, steps = side
    rt 360/5
    goto logo, steps = side
    rt 360/5
    goto logo, steps = side
    rt 360/5
end
  
  
 

The new procedure uses the variable, side for the number of steps, instead of the number 50. Now, if I want Logo to draw a really small pentagon, I call pentagon like this: goto pentagon, side = 10. If I want Logo to draw a really large pentagon, I call pentagon like this: goto pentagon, side=200. Of course, if Logo tries do draw a pentagon that big, he might walk right off the drawing space. Can you parameterize your procedure in the same way?

More Logo Instructions

Logo commands are the fundamental building blocks of the Logo language. So far, you've used just four commands, go, rt, and lt and the goto command for calling a procedure. Press the Logo Syntax button in LogoApplication to see the other commands you can use.

The repeat command is very powerful. You can use this command to call a procedure many times. These two procedures use repeat to draw a spiral. These procedures were also loaded when you pressed the Load Code button. Try calling spiral from your main procedure. Feel free to change spiral or spiralhelper and see how that changes what Logo does.

  procedure spiralhelper
    goto logo, steps = loop
    rt 50
  end

  procedure spiral
    repeat 100, spiralhelper
  end
  
 

Finishing Up

Do you want to save a procedure you wrote so you can use it later? To do that, open the Notepad application on your computer, copy the procedure into a Notepad document, and save it to the EYH folder on your Desktop. Name the file your_name_here.logo. We'll post your procedure on the main page so that you can access it anytime you want.