www.ICT-Teacher.com
Mathstutor 2003-07
for rights & liabilities see:  mathstutor

Logo.

Lesson 1

Logo will involve programming instructions to control a cursor around an area on the computer screen.
In the first week we will look at the layout of the screen, where to write the instructions, and some simple commands. In the next lesson we will look at simple and more advanced instructions.

Back

 

1. Open MSWLogo, click on Start > Programs.

2. Click OK on the form.

3. Your screen should look like this:

The screen appears in three sections: top section where the object draws for you; middle section which stores your commands; and the thin bottom section where you type in your commands.

 

4. Some basic commands are:
Forward, Right, Left, Penup, Pendown, Setpencolor, Back, Repeat, To, Save, Load, Clearscreen.

 

5. These basic commands have their own shortcut code, see table below:
Forward fd
            Back bk                 Right rt                       Repeat repeat
Left lt                      To to                      Penup pu                     Save save
Pendown pd           Load load              Setpencolor setpc
    Clearscreen cs

6. To draw pictures you will need to move the object, this needs an instruction forward, and a number to tell the object how far to move.
Try the following command and see what happens:
fd 100
You will always have to return the Enter key on the keyboard after each command.



7. You will also need to turn the object, this also needs a number to tell the object how far to turn, it will turn left or right. This number is the amount of degrees of angle to turn to (remember 90 degrees is a right angle, and 180 degrees is the opposite direction).

Try the following command and see what happens:
rt 90
fd 100

Remember to press Enter after each command.


8. Other really useful commands:
Clearscreen will clear the area ready for new work.
Penup is useful when you want to move the object somewhere without it drawing a line behind itself, type in pendown when you need it to start drawing again.
Setpencolor will change the colour of the drawing line, type a number between 0 and 7. (7 is white).
Save for saving work, remember to save it in your own area, and give it a name.
Load for loading on any past saved work.

 

9. Try out some of your own designs, or even try to write your own name (this is really tricky).

 

10. Repeat. Repeat is for when you want the same command repeated a number of times. If you were drawing a square you would need to type four times:
fd 100
lt 90

By using repeat we only need to enter it once:
repeat 4[fd 100 lt 90]

Try it, the repeat will do what is in the brackets as many times as the number you typed in before the brackets.


Note all the instructions are displayed in the middle box.

Warning: because Logo is a programming language you have to type in the commands exactly. This means using the correct brackets, and leaving a space between the command and the number.

 

Lesson 2.


Most work done in Logo is achieved by using functions.

  • A function is just a named string of instructions.
  • A function is created by the word to with its name following, e.g. to polygon :.
  • The programming for the function follows.
  • Try the following functions below and work out what is happenning:
to square                               (means make a function called square)
repeat 4 [fd 40 rt 90]           (this makes a square)
end                                         (ends the function)
square                                    (this runs the function square)

Question: how would you draw an octogon (8 sides)?
Answer: repeat 8 and adjust the angle to rt 45.

How would you draw a triangle? Hint: the angle would need to be rt 120.

to polygon :length                                     (function called polygon, the length is entered later)
repeat 6 [fd :length lt division 360 6]    (6 sided figure, for any other replace 6)
end
polygon 30                                                  (this runs the function the length of the sides is 30)

Question: How would you create a circle using this function?
Answer: replace both the 6's with 360.

to polygon :length :num                   (length and number of repeats entered later)
Repeat :num [fd :length lt division 360 :num]
end
polygon 5 120                                     (this runs the function you type in the variables: 5 and 120)

A program using a function within a function:

to figure :s :a
repeat division 360 :a [fd :s lt :a]
end
to rotate :s :a
repeat division 360 :a[figure :s :a lt 90]
end

rotate 20 90              (Try other numbers for other designs).

Try to create some designs of your own.

Exercises:
Define a function named FLOWER to draw a flower with eight petals, as shown here.

TO PETAL
ARC RT 90 ARC RT 90
END
TO FLOWER
REPEAT 8 [PETAL RT 45]
END

Write a functiom for printing six rows of six circles each, as shown in the figure, and call it CIRCLEGRID.

TO SMALL CIRCLE

REPEAT 45 [FD 1 RT 8]
END

TO ROWOFCIRCLES

REPEAT 6 [SMALLCIRCLE RT 90 PENUP FD 15 LT 90 PENDOWN]
LT 90 PENUP FD 90 RT 90 BK 15 PENDOWN
END

 

Note: ROWOFCIRCLES prints a row of six circles and places the turtle on the left edge of the next row of circles.
                       TO CIRCLESGRID
                       LT 90 PENUP FD 60 RT 90 FD 40 PENDOWN REPEAT 6 [ROWOFCIRCLES]
                       END