# Bulls eye class # reference point is the center of the circle, and # initially it is located at the origin from cs1graphics import* class Bullseye(FillableShape): def __init__(self,numBands,radius,primary='black',secondary='white'): if numBands <= 0: raise ValueError('Number of bands must be positive') if not isinstance(numBands,int): raise TypeError('Wrong type of the number of bands, it must be a positive integer') if numBands < 0: raise ValueError('The number of bands should be positive') elif not isinstance(numBands,int): raise TypeError('The number of bands should be integer') if radius < 0: raise ValueError('The radius should be positive') elif not isinstance(radius,int): raise TypeError('The radius should be integer') FillableShape.__init__(self) # call constructor of the FillableShape class self._outer = Circle(radius) # create the outer circle self._outer.setFillColor(primary) # change the fill color to the primary if numBands == 1: # if only one band self._rest = None # no other parts else: #if more than one band, create smaller bullseye innerR=int(float(radius)*(numBands-1)/ numBands) self._rest = Bullseye(numBands-1,innerR,secondary,primary) def getNumBands(self): bandcount = 1 # outer band is always present if self._rest != 0: # if there are more bands bandcount += self._rest.getNumBands() return bandcount def getRadius(self): return radius def setColors(self,primary,secondary): self._outer.setFillColor(primary) if self._rest: self._rest.setColors(secondary,primary) def _draw(self): self._beginDraw() self._outer._draw() # draw the outer circle if self._rest: self._rest._draw() # recursively draw the rest self._completeDraw()