You undoubtedly have recognized that there are some similarities to drawing shapes like the square or hexagon. It turns out there is a general pattern to drawing any regular (all sides are the same length and all angles are the same size) geometric shape.
Notice that the only code that is โinsideโ the for loop (indented after it) are the parts we want to repeat. We only want to end_fill once, so it is not indented. It is not part of the code that is repeated.
Any time we want to make a regular polygon, we need the turns to all sum up to \(360\text{.}\) In the triangle example \(3
* 120 = 360\) and in the pentagon example \(5 * 72 = 360\text{.}\)
Change the ?? in line 7 below to the amount to turn each time to draw a 12-sided polygon (called a dodecagon). If you get it right the turtle will draw a 12-sided closed polygon.
Now that we have identified a pattern, it is a bit silly to write separate functions like square and dodecagon for all the shapes. They are all basically the same and we donโt like repeating ourselves.
In this case, the way to avoid repeating ourselves is to make an abstraction - a procedure that can draw any polygon. It will take parameters to control how many sides there are and how long to make each side.
Arrange the blocks in the correct order and indentation to make the polygon procedure. This procedure will use begin_fill and end_fill to make the shapes be colored.