from __future__ import print_function, division from visual import * scene.height = 800 scene.width = 800 scene.background = color.white wheel = frame() th = 0.5 y0 = -5 R = 10. M = 0.07 s = cylinder(pos = (0,y0-th/2,0), color=color.cyan, radius=R, axis=(0,th,0), frame=wheel) b = box(pos=(0,y0,0),color=color.red, size=(2*R,th+.2,th+.2), frame=wheel) ##lbar = arrow(pos=(20,y0,0), color=color.magenta, axis = (0,1,0), shaftwidth = 2*th) lbar = arrow(pos=s.pos, color=color.magenta, axis = (0,1,0), shaftwidth = 2*th) t = 0 dt = 0.01 domega = 2*pi/3. omega = pi L = 0.5*M*R**2*omega lbar.axis = (0,L,0) scene.range=30 scene.autoscale = 0 while t < 100: rate(100) wheel.rotate(angle=omega*dt, axis = (0,1,0)) t = t + dt if scene.mouse.clicked: mm = scene.mouse.getclick() omega = omega - domega L = 0.5*M*R**2*omega lbar.axis = (0,L,0) if (omega < -pi) or (omega > pi): domega = -domega