Regular Polygon Generator

Generalization

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.

Instructions

Combine what you’ve learned about variables and shapes to program an automated shape generator. At minimum, your program should execute the following actions:

  1. Draw a shape with a number of sides based upon the value of a variable named sides. For example, if the variable sides is 3, it will draw a triangle. If sides is 8, it will draw an octagon.
  2. Draw the shape based on a variable size that determines the length of each side.
  3. Ask the user to specify each of these parameters (size and sides) when the script is executed.
  4. Personalize it in at least three ways.
  5. Test your program! Make sure it works correctly for an assortment of values for both size and sides.
  6. 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.