""" ChapterOO/Balloon.py """ from graphics import * winW, winH = 400, 400 # window size 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, 230 ), 20 ) b1.setFill( "blue") b1.ddraw( win ) while True: b1.mmove( 0, -0.01 ) if b1.getCenter().getY() < b1.getRadius(): b1.setFill("red") break main()