Topic 6 - Introducing Procedures and Functions

You can draw a square or any other regular polygon with a single word if you write a short program as follows.

TO SQUARE
REPEAT 4 [FD 50 RT 90]
END

To draw a square now all you need to type is SQUARE. You have added a new primitive to Logo and extended its capabilities. The primitive you have defined is commonly known as a procedure or function, a short section of code which performs a particular task.

In Logo all new functions are added to the existing primitives so you can carry out an action by typing the function's name.

So now all you need to do is to type 'SQUARE' and Logo carries out the instructions for you.

 

 

 

Now try defining functions which draw a regular triangle, a pentagon, a hexagon, and so on.

Remember the calculations for drawing a regular polygon are based on the number of sides and the number of degrees in a circle.

How are these numbers related???

You can, if you wish, type in the formula instead of the result, for example: 

TO HEXAGON
REPEAT 6 [FD 40 RT 360/6]
END

You will soon find this sort of calculation very useful.

 

 

 

 

Return to Logo Home Page