# Chapter Graphics/wheel0.py """ONE wheel moving on the canvas stops when reach border """ from graphics import * winW, winH = 400, 200 # window geometry class Wheel: # 2 concentric circles: big circle & small circle def __init__( self, c, rs, rb ): # constructor: c= center,rs = small radius, rb=big radius self.bCircle = Circle( c, rb ) self.sCircle = Circle( c, rs ) def move( self, dx, dy ): self.bCircle.move( dx, dy ) self.sCircle.move( dx, dy ) def setFill( self, colors, colorb ): self.bCircle.setFill( colorb ) self.sCircle.setFill( colors ) def ddraw( self, win ): self.bCircle.draw( win ) self.sCircle.draw( win ) def getCenter( self ): return self.bCircle.getCenter() def getRadius( self ): return self.bCircle.getRadius() def main(): win = GraphWin( "Demo: Wheels moving", winW, winH ) w1 = Wheel( Point( 50, 30 ), 10, 20 ) w1.setFill( "black", "yellow" ) w1.ddraw( win ) while True: w1.move( 0.1, 0 ) if w1.getCenter().getX() > winW - w1.getRadius(): break main()