from __future__ import division from visual import * from visual.controls import * scene.background = color.white scene.height = scene.width = 700 scene.x = scene.y = 0 scene.range = 25 def toggle_visible(object): object.visible = not(object.visible) def toggle_spin(): if rot_angle == 0: rot_angle = pi/2000 else: rot_angle = 0 print '''for a passenger on a Ferris wheel, show r, p, both useful in the "it feels as if something should be constant here..." discussion ''' rot_angle = pi/2000 fw = frame() wheel = ring(pos=(0,0,0), axis=(0,0,1), radius = 20, color=color.magenta, frame = fw, thickness = .25) for theta in arange(0, 2*pi, pi/6): a = sphere(pos = 1.05*wheel.radius*vector(cos(theta), cos(pi/2 + theta), 0), radius = .5, color=color.green, frame = fw) a.color = color.blue ## make one sphere a different color so it can be followed aparr = arrow(color = (.22,.33,.64), axis=(0,0,0), frame = fw, shaftwidth = 1, fixedwidth=1, visible = 0) zhat = vector(0,0,1) aphat = norm(cross(a.pos, -zhat)) ## dir of momentum of a aparr.pos = a.pos aparr.axis = 11*aphat ra = arrow(pos=(0,0,0), axis = a.pos, color=color.cyan, frame = fw, shaftwidth = 1, fixedwidth = 1, visible = 0) c = controls(x = 700, y=0, width = 250, height = 250, range = 100) tR = toggle(pos = (-30,25), width = 10, height = 30, text0='r invisible',text1='r visible', action = lambda: toggle_visible(ra)) tP = toggle(pos = (30,25), width = 10, height = 30, text0 = 'p invisible', text1 = 'p visible', action = lambda: toggle_visible(aparr)) while True: rate(300) fw.rotate(angle=rot_angle, axis = (0,0,1)) c.interact() ## check for control events