Logo Stars

Basic Logo commands
Basic programming: Procedures
Editing your Procedures
Creating new Procedures

The two stars below were drawn using the freeware MSW Logo.

Logo is a programming language, which is great for drawing geometrical diagrams like these.

When you open Logo, you should see:

  • MSWLogo Screen (with menus for File, Bitmap, Set, Zoom and Help) - this where your drawings will be displayed
  • the Commander Screen (which you can move to wherever you find it most convenient, at the bottom in the screenshot) - this is where you type in commands and programs
Logo screenshot

Basic commands

To get started type a command into the Commander. Commands tell the turtle (cursor) what to do:

Command
Short form
Example
What does the turtle do?
forward
fd
fd 100 <ENTER>
moves forward 100 pixels
back
bk
bk 50 <ENTER>
moves backward 50 pixels
right
rt
rt 90 <ENTER>
turns right through an angle of 90 degrees
left
lt
lt 30 <ENTER>

turns left through an angle of 30 degrees

repeat 4[...]
 
repeat 4[fd 100 rt 90] <ENTER>
repeats whatever is in the square brackets the number of times specified, in this case to create a square
show turtle
st
st <ENTER>
shows the turtle - useful for editing
hide turtle
ht
ht <ENTER>
hides the turtle - good for displaying a diagram
clear screen
cs
cs <ENTER>
clears everything on the screen and puts the turtle back into its zero position
pen up
pu
pu <ENTER>
lifts the pen so that you can move the turtle without a line being drawn
pen down
pd
pd <ENTER>
puts the pen back down

Note: you need to leave a single space after a command before putting the value you want or the next command.

The images above on the right were drawn using only these commands, plus two Procedures which used variables.

Basic programming: Procedures and variables

In Logo, you can put a set of commands you want to use more than once into a program or Procedure. This is very useful if you want to use a motif in a bigger drawing, or if you want to perfect something, since a Procedure can be easily edited. It is also a good idea to use variables to specify things like side lengths, that you want to use several times or change quickly when producing different size versions of your drawing.

Procedure for drawing a square, side length 100

Type the following into the Commander:

to square <ENTER>
repeat 4[fd 100 rt 90] <ENTER>
end <ENTER>

Logo knows this is a procedure because it begins with 'to ...' (you add whatever name you want there, but only use letters and numerals, no spaces, hyphens, etc) and finishes with 'end'. As you type 'to square', you should see an editing box in which you can carry on typing. Once you have typed 'end', you should see your square on screen.

Now type:

cs <ENTER>
square <ENTER>

into the Commander. What does each of these commands do?

Procedure for drawing a square, variable side length

Type the following into the Commander (note there is a colon : immediately before the variable a):

to squarea :a <ENTER>
repeat 4[fd :a rt 90] <ENTER>
end <ENTER>

Note: I have used a different name from 'square' because we already have a Procedure called 'square'. I could edit my 'square' Procedure rather than starting again with a different name, but only if I am sure I won't want the original 'square' Procedure again.

When the Commander replies that to squarea is defined , type:

cs squarea 60 <ENTER>

and then:

cs squarea 300 <ENTER>

You should get first a small square, and then a large square.

Now try this:

cs squarea 50 pu rt 90 fd 200 lt 90 pd square 200 <ENTER>

Can you see what each instruction is doing here?

Note 1: you don't need to press <ENTER> after each instruction. Pressing <ENTER> means that Logo will execute what you have typed so far, so I generally only do it when I want to see what I've got. If you don't clear screen, the cursor will continue from its previous position, if you want to add more commands.

Note 2: when you use a variable in a Procedure, you need to put a colon : immediately in front of it, but when you specify the value you want the variable to take when you execute the Procedure, you don't need a colon - just substitute the value you want.

Editing your Procedures

You may well need to edit your Procedures, as it's rare to get it right first time. To edit a Procedure once it's created, click the 'Edall' button on the right of the Commander. You should see all your Procedures listed there, ready for editing. Once you have edited something, to try it out again, click on File > Save and Exit. You can also create new Procedures in this editing pane - just start with 'to ...' and finish with 'end'.

If you are having difficulty with a Procedure, and want to see what it does slowly, use the 'Step' facility on the Commander.

Creating your own Procedures

Now you are ready to create your own Procedures. Try the following:

  • a rectangle with long sides twice the length of the short sides
  • a rectangle with long sides a factor n times the length of the short sides (you will need to use a variable for this)
  • an equilateral triangle with sides 100 pixels (you will need to think carefully about the angle you want to turn through at each stage)
  • an equilateral triangle with variable sides
  • a five-pointed star
  • a six-pointed star
  • any other star you like!

Can you make a whole set of stars in Logo, both ones made of one continuous line, and ones with two or more superimposed regular polygons?