From: Bruce P. <bap...@te...> - 2003-05-13 15:52:53
|
The curve object keeps two arrays in memory -- a position array and a color array. Slicing the position array doesn't affect the color array so that it will keep growing with each append. You need to slice both color and position arrays to keep from overflowing. At 04:07 PM 5/12/2003, you wrote: >From: "Gary Ruben" <ga...@em...> >To: Vis...@li... >Date: Sat, 10 May 2003 01:21:56 -0500 >Subject: [Visualpython-users] How do I truncate a curve? > >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 >-- |