from cs1graphics import * from math import * class Star(Polygon): def __init__(self,numRays=5,outerRadius=30,innerRatio=0.5,center=Point(30,30)): Polygon.__init__(self) # call the parent constructor top = Point(0,-outerRadius) # top point of the star print "Top point:",top angle = 360.0/(2*numRays) # angle between points print "Angle:",angle for i in range(numRays): self.addPoint(top^(angle*2*i)) # adding ray point #print i+1,'th ray point:',top^(angle*i) self.addPoint(innerRatio*top^(angle*(2*i+1))) # adding inner point #print i+1,'th inner point:',top^(angle*(i+0.5)) self.adjustReference(0,outerRadius) # moving Reference Point from the #top point to the center of the star self.moveTo(center.getX(),center.getY()) #self.move(100,100) #moving the star to the given by the user point (as the center of the star) self._innerRatio=innerRatio # record the inner ratio as attribute def setInnerRatio(self,newRatio): factor=newRatio/self._innerRatio self._innerRatio=newRatio #we will modify only inner points for i in range(1,self.getNumberOfPoints(),2): self.setPoint(factor*self.getPoint(i),i) def main(): paper=Canvas(400,600,'lightyellow','Stars') s=Star() paper.add(s) tt=raw_input('Press Enter to continue') s.setInnerRatio(0.2) s1=Star(8,40,0.3,Point(200,200)) s1.setBorderColor('dark blue') s1.setFillColor('blue') paper.add(s1) main()