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') 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=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() def main(): answer = 'y' while answer == 'y' or answer == 'yes': print 'This program draw a bullseye in a graphical window' w,h = input('Plese input the size of the graphical window (width,height):') if w < 0 or h < 0: raise ValueError('Width and Height should be positive') elif not isinstance(w,int) or not isinstance(h,int): raise TypeError('Width and Height should be integers') numBands=input('please enter the desired number of bands in the bullseye:') 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') r=input('please enter the radius of the bullseye:') if r < 0: raise ValueError('The radius should be positive') elif not isinstance(r,int): raise TypeError('The radius should be integer') print 'Width is %d, and height is %d of graphics window'%(w,h) print 'Beginning to draw' paper=Canvas(w,h,'white','Bullseye') b=Bullseye(numBands,r) print 'Moving to the center' b.move(w/2.0,h/2.0) print 'drawing' paper.add(b) answer=raw_input('Whould you like to do it again (Inpuit Y or Yes)?') answer.lower() print 'Good buy!' main()