Regular Polygon Generator
The power of programming lies in the ability to not only automate tasks, but to generalize them. Rather than create a different shape generator for each regular polygon with varying numbers of sides, we can use the abstraction variables to program a generic regular shape generator.
Combine what you’ve learned about variables and shapes to program an automated shape generator. At minimum, your program should execute the following actions:
- Draw a shape with a number of sides based upon the value of a variable named
sides. For example, if the variable
3, it will draw a triangle. If
8, it will draw an octagon.
- Draw the shape based on a variable
sizethat determines the length of each side.
- Ask the user to specify each of these parameters (
sides) when the script is executed.
- Personalize it in at least three ways.
- Test your program! Make sure it works correctly for an assortment of values for both
- Provide documentation for your program (describe what it does) as the Instructions. Be sure to describe how your program is original.
When you are satisfied with your work, submit a link to your program or the program itself.
If you are having difficulty with determining the correct “formula” for the number of degrees to turn each time, think about the following:
- You are working with two variables—what are they, and how might they be relevant?
- What numeric value would a square use to fill the blank? A triangle? Use these to think of a function to generalize them.