From: John B. <joh...@gm...> - 2010-01-09 14:05:14
|
I having difficulty in trying to display two windows one with action/animation and the graph that relates to the action. I tried to put together pieces from the documentation on graphs. I want to graph the time by speed of the accelerated ball in the animated window. The code below does succeed in running the animation and can display the graph window but I cannot get the plotting function to display on the graphing window I created. Does the curve need to be an argument with gdisplay at the beginning but that isn't a clear parameter in the documentation. Within the motion loop, I feel like there should be something like graph1 = gdisplay(funct1) to relate the function to the graph window but it isn't clear how to do this. What is the best and tidiest way to do this? # Adapted from erik thompson video lesson 1. from visual import * from visual.text import * from visual.graph import * # import graphing features scene.width = 800 scene.height = 600 scene.autoscale = 0 scene.range = (100,100,100) scene.center = (0,40,0) scene.title = "Acceleration" scene.fov = 0.001 #scene.range = 7 #sets the starting position view. ball = sphere(pos=(100.0,0,0),radius=2) ground = box(pos=(-1,0,0),size=(2,10,10)) initPos = ball.pos acc = 9.8 # m/s**2 seconds = 0.0 dt = .01 #change in time graph1 = gdisplay(x=0, y=600, width=600, height=500, title='dt vs. dv', xtitle='change in time', ytitle='change in speed', xmax=30, xmin=0., ymax=25, ymin=0, foreground=color.black, background=color.white) # is gcurve an argument that should go in here graph1 = gdisplay() graph1.display.visible = 0 # make the display visible finished = False while not finished: rate(100) # sets the general rate and speed of the computations seconds += dt #increment time distance = 0 + .5 * acc * seconds**2 #distance travelled time = seconds speed = distance / time funct1 = gcurve(color=color.cyan) graph1 = gdisplay(funct1) #I know this is wrong but how do I place on graph1. for time in arange(0.0, 30.0, 0.1): # time is a range that goes from 0 to 30 (in increments of 0.1). funct1.plot(pos=(time,speed)) # plot a time by speed graph. # position equation: y(t) = y0 + v0*t + .5 * a * t**2. So the position of the ball at any given instance is... ballTravel = 100.0 - .5 * acc * seconds**2 #new position ball.pos = vector(ballTravel,0,0) if ballTravel - 2 < 0: #try to stop at 1 on the platform finished = True print "seconds to fall: " + str(seconds) #print to the display console. |
From: Bruce S. <Bru...@nc...> - 2010-01-09 15:23:33
|
Thanks, Lenore, for answering John's question. A further simplification is that in the plot statement there's no need to specify "gdisplay=Xvel.display" because Xvelnodrag was created for and belongs to that gdisplay. Xvel = gdisplay(x=0,y=0, width=262, height=100, background=color.white, xmin=0, xmax=12, ymin=-vmax, ymax=vmax, title = 'V_x(t)') Xvelnodrag = gdots(size=3, color=nodragcolor) ...... Xvelnodrag.plot( gdisplay=Xvel.display, pos=(t,nodrag.velocity.x) ) John, if you're comfortable with the default gdisplay and gdisplay settings the minimal structure for making a graph is something like this: Xvelnodrag = gdots() # create a gdots object for graphics ........... Xvelnodrag.plot(pos=t,nodrag.velocity.x)) # add a dot to the gdots object Bruce Sherwood |
From: John B. <joh...@gm...> - 2010-01-11 10:48:53
|
Okay I got it to work. That was my python programming error I getting used to the language. For the record one needs place funct1 = gdots() BEFORE entering the while loop and don't need to nest the for loop " for time in arange(0., 30., 1.): " inside the while loop or even in the program at all. 2010/1/9 Bruce Sherwood <Bru...@nc...> > Thanks, Lenore, for answering John's question. A further simplification is > that in the plot statement there's no need to specify > "gdisplay=Xvel.display" because Xvelnodrag was created for and belongs to > that gdisplay. > > Xvel = gdisplay(x=0,y=0, width=262, height=100, > background=color.white, xmin=0, xmax=12, ymin=-vmax, ymax=vmax, title > = 'V_x(t)') > Xvelnodrag = gdots(size=3, color=nodragcolor) > ...... > Xvelnodrag.plot( gdisplay=Xvel.display, pos=(t,nodrag.velocity.x) ) > > John, if you're comfortable with the default gdisplay and gdisplay settings > the minimal structure for making a graph is something like this: > > Xvelnodrag = gdots() # create a gdots object for graphics > > ........... > Xvelnodrag.plot(pos=t,nodrag.velocity.x)) # add a dot to the gdots object > > Bruce Sherwood > > > > > ------------------------------------------------------------------------------ > This SF.Net email is sponsored by the Verizon Developer Community > Take advantage of Verizon's best-in-class app development support > A streamlined, 14 day to market process makes app distribution fast and > easy > Join now and get one step closer to millions of Verizon customers > http://p.sf.net/sfu/verizon-dev2dev > _______________________________________________ > Visualpython-users mailing list > Vis...@li... > https://lists.sourceforge.net/lists/listinfo/visualpython-users > |
From: John B. <joh...@gm...> - 2010-01-11 11:28:29
|
I would just add that I got the plot to display by removing these lines from original program as well: graph1 = gdisplay() graph1.display.visible = 0 2010/1/11 John Brennan <joh...@gm...> > Okay I got it to work. That was my python programming error I getting used > to the language. For the record one needs place funct1 = gdots() BEFORE > entering the while loop and don't need to nest the for loop " for time in > arange(0., 30., 1.): " inside the while loop or even in the program at all. > > 2010/1/9 Bruce Sherwood <Bru...@nc...> > >> Thanks, Lenore, for answering John's question. A further simplification is >> that in the plot statement there's no need to specify >> "gdisplay=Xvel.display" because Xvelnodrag was created for and belongs to >> that gdisplay. >> >> >> Xvel = gdisplay(x=0,y=0, width=262, height=100, >> background=color.white, xmin=0, xmax=12, ymin=-vmax, ymax=vmax, title >> = 'V_x(t)') >> Xvelnodrag = gdots(size=3, color=nodragcolor) >> ...... >> Xvelnodrag.plot( gdisplay=Xvel.display, pos=(t,nodrag.velocity.x) ) >> >> John, if you're comfortable with the default gdisplay and gdisplay >> settings the minimal structure for making a graph is something like this: >> >> Xvelnodrag = gdots() # create a gdots object for graphics >> >> ........... >> Xvelnodrag.plot(pos=t,nodrag.velocity.x)) # add a dot to the gdots object >> >> Bruce Sherwood >> >> >> >> >> ------------------------------------------------------------------------------ >> This SF.Net email is sponsored by the Verizon Developer Community >> Take advantage of Verizon's best-in-class app development support >> A streamlined, 14 day to market process makes app distribution fast and >> easy >> Join now and get one step closer to millions of Verizon customers >> http://p.sf.net/sfu/verizon-dev2dev >> _______________________________________________ >> Visualpython-users mailing list >> Vis...@li... >> https://lists.sourceforge.net/lists/listinfo/visualpython-users >> > > |
From: Lenore H. <lh...@si...> - 2010-01-09 14:46:16
|
On Jan 9, 2010, at 07:41 , John Brennan wrote: > I having difficulty in trying to display two windows one with action/ > animation and the graph that relates to the action. I tried to put > together pieces from the documentation on graphs. I want to graph > the time by speed of the accelerated ball in the animated window. > The code below does succeed in running the animation and can display > the graph window but I cannot get the plotting function to display > on the graphing window I created. Does the curve need to be an > argument with gdisplay at the beginning but that isn't a clear > parameter in the documentation. Within the motion loop, I feel like > there should be something like graph1 = gdisplay(funct1) to relate > the function to the graph window but it isn't clear how to do this. > What is the best and tidiest way to do this? > > # Adapted from erik thompson video lesson 1. > > from visual import * > from visual.text import * > from visual.graph import * # import graphing features > > scene.width = 800 > scene.height = 600 > > scene.autoscale = 0 > scene.range = (100,100,100) > scene.center = (0,40,0) > > scene.title = "Acceleration" > scene.fov = 0.001 > #scene.range = 7 #sets the starting position view. > > ball = sphere(pos=(100.0,0,0),radius=2) > ground = box(pos=(-1,0,0),size=(2,10,10)) > > initPos = ball.pos > acc = 9.8 # m/s**2 > seconds = 0.0 > dt = .01 #change in time > > graph1 = gdisplay(x=0, y=600, width=600, height=500, > title='dt vs. dv', xtitle='change in time', ytitle='change > in speed', > xmax=30, xmin=0., ymax=25, ymin=0, > foreground=color.black, > background=color.white) # is gcurve an argument > that should go in here > > graph1 = gdisplay() > graph1.display.visible = 0 # make the display visible > > finished = False > while not finished: > > rate(100) # sets the general rate and speed of the computations > seconds += dt #increment time > > > distance = 0 + .5 * acc * seconds**2 #distance travelled > time = seconds > speed = distance / time > > funct1 = gcurve(color=color.cyan) > graph1 = gdisplay(funct1) #I know this is wrong but > how do I place on graph1. > for time in arange(0.0, 30.0, 0.1): # time is a range that > goes from 0 to 30 (in increments of 0.1). > funct1.plot(pos=(time,speed)) # plot a time by speed graph. > > # position equation: y(t) = y0 + v0*t + .5 * a * t**2. So the > position of the ball at any given instance is... > ballTravel = 100.0 - .5 * acc * seconds**2 > > #new position > ball.pos = vector(ballTravel,0,0) > > if ballTravel - 2 < 0: #try to stop at 1 on the platform > finished = True > print "seconds to fall: " + str(seconds) #print to > the display console. > Here are relevant snippets from my code. Xvel = gdisplay(x=0,y=0, width=262, height=100, background=color.white, xmin=0, xmax=12, ymin=-vmax, ymax=vmax, title = 'V_x(t)') Xvelnodrag = gdots(size=3, color=nodragcolor) Xvelnodrag.plot( gdisplay=Xvel.display, pos=(t,nodrag.velocity.x) ) Lenore |