From: Gary R. <ga...@em...> - 2003-05-10 06:23:33
|
Hi fellow VPython Users, A few times in my code I have wanted to show a trail behind some moving object. For example, you might want to see the path of the free end of the double pendulum in the doublependulum.py example. To do this, you could add the following code: <code> trailLength = 10000 # no of points in trail trail = curve(color=(0.5,0.5,0.5)) # the existing while loop while 1: . . other code here . posnew = frame2.pos+frame2.axis*L2 trail.append(pos=posnew) # Now keep the trail length finite if len(trail.pos) > trailLength: trail.pos = trail.pos[20:] t = t+dt </code> However, I have encountered a problem with doing this which I assume is to do with the curve being held in a Numeric array structure. If I understand Numeric correctly, trail.pos = trail.pos[20:] won't cause a copy or truncation, just a change to the offset to the start of the array, so the array/curve object will continue to grow despite only showing the last 10000 points (in this example). If a copy could be forced, the curve object would have to be reassociated with the new array object, so I don't think a copy is occurring. A copy would be very inefficient anyway. Actually, when I run this example, everything seems to work OK, but in another example I have, if I leave it running, the vpython window eventually locks up and the lockup is associated with the code I have shown. I'm running Win98. So, has anyone got a more efficient way to limit the length of a curve to some maximum? Do others ever do this sort of thing and if so, do they agree that it would be nice to have a property such as maxlength added to the curve object? Gary -- _______________________________________________ Sign-up for your own FREE Personalized E-mail at Mail.com http://www.mail.com/?sr=signup |