CSSE 120 — Introduction to Software Development

Homework 7

Reminder: for each class session and associated homework:

  1. Complete the assigned reading for the next session: Zelle, §5.6–5.10.
  2. (15 points) In Angel, complete the Reading Quiz over the above reading.
  3. Some Geometry with Lists. For this problem you'll write three small, separate but similar, graphics functions: pizza, polygon, and star. Put your code for these in the pizzaPolyStar module. That module is inside the 07-TypesAndLists project that you checked out in class.

    Each function takes four arguments:

    Then the programs draw pictures as follows:

    The pictures below show what the display of your programs should look like for a couple of cases.

    Examples when number is 5:

    Expected output for number == 5

    Examples when number is 7:

    Expected output for number == 7

    Be sure to get pizza working before moving on to polygon and star. Each of these problems is slightly more complicated than the one before it, but they'll use similar code.

    I've provided a helper function that generates an appropriate list of Points for any values of center, radius, and number. You should call this function from each of your functions.

    def calculateVertices(center, radius, number):
        '''Returns a list of 'number' points evenly spaced around the
        circumference of a circle with the given location and radius.'''
        centerX = center.getX()
        centerY = center.getY()
        
        # Builds vertices list
        vertices = []
        for i in range(number):
            x = radius * cos(2 * pi * i / number) + centerX
            y = radius * sin(2 * pi * i / number) + centerY
            vertices.append(Point(x, y))
            
        return vertices
    

    Do you see how you can iterate over the Points stored in the list vertices in order to find endpoints for the lines?

    As you finish and test each function, be sure to commit your work to your SVN repository.