Reminder: for each class session and associated homework:
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:
window on which to drawcenter point for the circleradius for the circle, and number of sides for the figure.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.
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.