Topic 18 - Turtle Trigonometry

We can put the sin and cos functions available as primitives in Logo to draw basic geometric shapes such as waves and circles: 

TO WAVE :X
SETY (SIN :X) * 200
SETX :X
WAVE :X + 1
END

WAVE 1
SETZOOM 0.3  

 

 

 

 

 

 

 

Here is the code for a circle:

TO CIRCLE :X
SETY (SIN :X) * 20
SETX (COS :X) * 20
CIRCLE :X + 1
END

Changing the multipliers will draw different sized circles and giving them different values will produce ellipses.

These routines use the SETX and SETY primitives which move the turtle to the co-ordinate specified by the number which follows. The centre of the Logo graphics screen is taken as location (0,0) so SETX 50 moves the turtle 50 units to the right, SETX -50 moves 50 units left, SETY 50 moves the turtle 50 units up the screen and SETY -50 moves the turtle 50 units down.

It is also possible to set the position of the turtle with the SETPOS primitive which takes two values as parameters for the X and Y co-ordinates. For example, SETPOS [50,50] moves the turtle to location [50,50] on the screen. Locations defined by the values of X and Y on a grid are known as Cartesian co-ordinates after the French mathematician and philosopher Descartes who introduced their use.

The next piece of code produces the cardioid shapes which come in various forms according to the value of C.  

TO CARDIOID :X :C 
MAKE "R (1-(COS :X * :C)) * 20 
SETY (SIN :X) * :R 
SETX (COS :X) * :R 
CARDIOID :X + 1 :C 
END 
CARDIOID 1 1 

 

 

 

Changing the value of C will draw cardioids with a corresponding number of lobes. Try it!

The following code will produce similar effects with the value of C once again producing different numbers of lobes: 

TO FLOWER :X :C 
SETx ((SIN :X * :C) * 50) * ((cos :x)) 
SETy ((SIN :X * :C) * 50) * ((sin :x)) 
FLOWER :X +0.1 :C 
END 

FLOWER 1 2 

FLOWER 1 6

Return to Logo Home Page