From: Young-Jin L. <yl...@ui...> - 2002-01-18 17:10:49
|
Hi, I found out why I didn't see the VPython simulation window except the first time. I set scene.exit to 0 because I wanted to close only the VPython simulation window rather than the whole application. I expected "scene.exit = 0" to a "REAL" clsoing, but apparently it is not. It seems like it just set scene.visible to "0". When I manually set "scene.visible" to "1" for later simulation, the VPython simulation window appeared. But VPython objects created in the previous simulation were still there. I tried to set all the spheres created in the previous simulation by setting them to None, it didn't work. Is there any way to clear all the objects in the scene when it is closed? Thanks. YJ # Button ID BT_START = 10 from wxPython.wx import * from wxPython.html import wxHtmlWindow from visual import * class CPFreeFall1D_InitialPane( wxHtmlWindow ): def __init__( self, parent, id, **kwargs ): wxHtmlWindow.__init__( self, parent, id, **kwargs ) wxButton( self, BT_START, "Start Simulation", wxPoint( 100, 100 ) ) EVT_BUTTON( self, BT_START, self.OnClickStart ) def OnClickStart( self, event ): # read the configuration file import ConfigParser cfg = ConfigParser.ConfigParser() cfg.read( 'freefall1d.cfg' ) self.startSimulation( cfg ) def startSimulation( self, cfg ): print 'start simulation' scene.width = scene.height = 500. scene.x = scene.y = 0 scene.forward = ( -0.2, -0.5, -1 ) scene.autoscale = 0 scene.userzoom = 0 scene.range = ( 15, 15, 15 ) scene.exit = 0 # only close the simulation window # clean up the previous simulation result, but it didn't work. for obj in scene.objects: if obj.__class__ == 'sphere': print obj obj = None # start an actual simulation scene.select() xmax = 10 dx = xmax / 5 grid = [] gravity = cfg.get( 'Characteristics', 'gravity' ) r = float( cfg.get( 'Characteristics', 'diameter' ) ) / 2 # make the scene visible # it should be done automatically, but it is not the case. # So I call it by myself. scene.visible = 1 for x in arange( -xmax, xmax+dx, dx ): grid.append( curve( pos = [(x, 0, -xmax), (x, 0, xmax)], color = ( .7, .7, .7 ) ) ) for z in arange( -xmax, xmax+dx, dx ): grid.append( curve( pos = [(-xmax, 0, z), (xmax, 0, z)], color = (.7, .7, .7) ) ) ball = sphere(pos=(0,8,0), radius=r, color=color.red) ball.selected = 0 ball.velocity = vector(0,-1,0) dt = 0.1 ballPosition = [] ballVelocity = [] t = [] currentT = 0 while ball.y > ball.radius: rate(10) ball.pos = ball.pos + ball.velocity*dt ball.velocity.y = ball.velocity.y - float(gravity)*dt wake = sphere( pos = ball.pos, radius = 0.1, color = color.blue ) t.append( currentT + dt ) ballPosition.append( ball.pos.y ) ballVelocity.append( ball.velocity.y ) currentT = currentT + dt print 'end simulation' |