Poly Want a Cracker?

A few days ago, we worked on the Hip to be Square lesson where we created a pattern out of squares. Today we are going to alter that program so that it will draw the pattern with any regular polygon, not just a square.

To accomplish this, we need to steal the drawPoly() function from Exercise #3 of this tutorial.  Copy it and place it in your program in the section where you defined you functions drawSquare() and drawPattern().

Finally, just replace the word drawSquare() with drawPoly() in your drawPattern() function.  Piece of cake, right?  Well, there are a couple of catches.  As you know, the drawPoly() function receives three parameters, one more than the drawSquare() function.  The new parameter is num_sides.  You’ll have to add that variable to your drawPattern() function as well.

Here is an example of the program with hexagons (6 sides) as the polygons:


This is a second example, using 9 pentagons and alternate colors.


Here is a summary of the requirements for this program:

  • Your program will include two functions, drawPattern() and drawPoly().  drawPattern() calls drawPoly() from a loop to create the pattern on the screen.
  • The main program should begin by prompting the user to enter three pieces of information: the number of sides in the shape used to make the pattern, the number of shapes in the pattern, and the length of one side of the shape.
  • Next, you should set up the turtle and the drawing screen.
  • Finally,  call drawPoly() passing the information input by the user.

When you program is working correctly, make sure you name the file yourname-polypattern.py, then submit it here for grading.