6.2 Drawing a regular polygon

In this part, we’ll learn to draw a square, equilateral triangle, and a regular polygon in general....

6.2.1 Square

PIC

To draw this square, we’re going to write:

fd 200 rt 90 fd 200 rt 90 fd 200 rt 90 fd 200 rt 90

We can see that we repeat 4 times the same instructions. Therefore, a better syntax:

repeat 4[fd 200 rt 90]

6.2.2 Equilatéral triangle

PIC

Here, we’ll learn how to draw this equilatéral triangle (all three sides have 150 steps lengths).

The command will have this form:

repeat 3[fd 150 rt ....]

We must determinate the angle. In an equilateral triangle, all three internal angles are equal to each other and so are each 60 degrees. The turtles turns outside the triangle. Hence, the value for this angle is 180-60=120 degrees. The valid command is:

repeat 3[fd 150 rt 120]

6.2.3 Hexagon

PIC

repeat 6[fd 80 rt ....]

When the turtle has finished its moves, it has made one tour from its initial position to its final position. This is done using 6 steps. Therefore, each angle value is equal to 360-
 6 = 60˚.

The valid command is: repeat 6[fd 80 rt 60]

6.2.4 Drawing a regual polygon in general

In fact, the reasoning makes us think that to draw a polygon with n sides, the turtle will have to turn from an angle whose value is 360 divided by n. For example: