from visual import* from visual.graph import * print """ Rob Salgado (salgado@physics.syr.edu) - Sept 24, 2003 This program copies objects from one display into another with an improved copyobjects() function. Then, as the animation runs in the source display, the objects in the destination display are updated with a new function updatecopyobjects(). =========== """ scene=display( title="A", width=350,height=350, x=0, y=0, autoscale=0, visible=1, forward=(-1,-1,-1),center=vector(0,0,0) ) sceneB=display( title="B", width=350,height=350, x=350, y=0, autoscale=0, visible=1, forward=(0,-1,-10),center=vector(0,0,0) ) scene.select() def copyobjects(scene1,scene2): # based on http://www.vpython.org/webdoc/visual/options.html # Copy all Visual objects from scene1 into scene2 scene2.select() scenelist=scene1.objects ### ### reverse() is needed so that the items in the destination list of objects ### are in correspondence with those of the source list scenelist.reverse() for obj in scenelist: newobj = obj.__class__() # create object in scene2 for member in obj.__members__: if member == 'display': continue # avoid putting into scene1 setattr(newobj,member,getattr(obj,member)) def updatecopyobjects(scene1,scene2): # Update the Visual objects copied into scene2 from scene1 obj2_list=scene2.objects i=0 for obj in scene1.objects: for member in obj.__members__: if member == 'display': continue # avoid putting into scene1 setattr(obj2_list[i],member,getattr(obj,member)) i += 1 ### A variant of the "Simple program example" ### from http://www.vpython.org/vpythonprog.htm floor = box (pos=(0,0,0), length=4, height=0.5, width=4, color=color.blue) ball = sphere (pos=(0,4,0), radius=1, color=color.red) ball.velocity = vector(0,-1,0) dt = 0.01 copyobjects(scene,sceneB) while 1: rate (100) ball.pos = ball.pos + ball.velocity*dt if ball.y < ball.radius: ball.velocity.y = -ball.velocity.y else: ball.velocity.y = ball.velocity.y - 9.8*dt updatecopyobjects(scene,sceneB)