# ChapterOO/Balloon2.py from graphics import * winW, winH = 400, 400 # window geometry class Balloon: def __init__(self, c, r ): # constructor: c= center point, radius self.bCircle = Circle( c, r ) self.line = Line(Point(c.getX(),c.getY()+r), Point(c.getX(), c.getY()+3*r )) def setFill( self, colorb ): self.bCircle.setFill( colorb ) def ddraw( self, win ): self.bCircle.draw( win ) self.line.draw( win ) def mmove(self, dx, dy ): self.bCircle.move( dx, dy ) self.line.move( dx, dy ) def getCenter( self ): return self.bCircle.getCenter() def getRadius( self ): return self.bCircle.getRadius() def main(): win = GraphWin( "Demo: Wheels moving", winW, winH ) b1 = Balloon( Point( 250, 330 ), 20 ) # make n balloons b2 = Balloon( Point( 150, 230 ), 25 ) b3 = Balloon( Point( 50, 240 ), 20 ) b4 = Balloon( Point( 100, 350 ), 10 ) blist = [b1,b2,b3,b4] for b in blist: b.setFill( "blue") b.ddraw( win ) while (len(blist) > 0 ): for b in blist: b.mmove( 0, -0.1 ) if b.getCenter().getY() < b.getRadius(): b.setFill("red") blist.remove(b) main()