public
Created

revised wheel.py

  • Download Gist
wheel
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
from graphics import *
 
class Wheel():
 
def __init__(self, center, wheel_radius, tire_radius):
self.tire_circle = Circle(center, tire_radius)
self.wheel_circle = Circle(center, wheel_radius)
 
def draw(self, win):
self.tire_circle.draw(win)
self.wheel_circle.draw(win)
 
def move(self, dx, dy):
self.tire_circle.move(dx, dy)
self.wheel_circle.move(dx, dy)
 
def set_color(self, wheel_color, tire_color):
self.tire_circle.setFill(tire_color)
self.wheel_circle.setFill(wheel_color)
 
def undraw(self):
self.tire_circle .undraw()
self.wheel_circle .undraw()
 
def get_size(self):
return self.tire_circle.getRadius()
 
def get_center(self):
return self.tire_circle.getCenter()
 
def animate(self, win, dx, dy, n):
if n>0:
self.move(dx,dy)
win > win.after(100,self.animate, win, dx, dy, n-1)
 
 
def main():
new_win = GraphWin('Wheel', 700, 500)
 
wheel_center = Point(200, 200) # The wheel center is a Point at (200, 200)
tire_radius = 100 # The radius of the outer tire is 100
 
new_wheel = Wheel(wheel_center, 0.6*tire_radius, tire_radius)
 
new_wheel.set_color('green', 'yellow')
 
new_wheel.draw(new_win)
 
new_wheel.animate(new_win,1,1,100)
 
 
 
# Run the window loop (must be the *last* line in your code)
new_win.mainloop()
 
 
 
# Comment this call to main() when you import this code into
# your car.py file - otherwise the Wheel will pop up when you
# try to run your car code.
main()
 

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.