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 |