In this part, we’ll learn to draw a square, equilateral triangle, and a regular polygon in general....
To draw this square, we’re going to write:
We can see that we repeat 4 times the same instructions. Therefore, a better syntax:
Here, we’ll learn how to draw this equilatéral triangle (all three sides have 150 steps lengths).
The command will have this form:
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:
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 = 60˚.
The valid command is: repeat 6[fd 80 rt 60]
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:
This form is really near a circle!