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:
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] |
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] |
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 = 60˚.
The valid command is: repeat 6[fd 80 rt 60]
repeat 5[fd 100 rt 72] (360:5=72) |
repeat 9[fd 20 rt 40] (360:9=40) |
repeat 360[fd 2 rt 1] |
This form is really near a circle!
repeat 7[fd 120 rt 360/7] |