From: Bruce P. <bap...@te...> - 2002-07-01 21:20:57
|
The VPython documentation discusses using the curve object to create trails for moving objects. The curve can also be used to record the history of an intrinsic parameter (such as temperature represented by object color) with code like: obj.pos=newpos obj.color=newcolor trail.append(pos=newpos, color=newcolor) However if an abbreviated history is desired then the code obj.pos=newpos obj.color=newcolor trail.append(pos=newpos, color=newcolor) if len(trail.pos)>maxlen: trail.pos=trail.pos[1:] correctly truncates the curve length but incorrectly truncates the color. Internally the curve object appears to implement: if len(self.color)>len(self.pos): self.color=self.color[0:len(self.pos)-1] Is there any known way around this so that colors remain correctly associated with position? BTW storing position and color in a seperate list and replacing the entire list on each iteration rapidly goes into memory management meltdown - it works for small examples but rapidly dies with larger examples. Bruce Peterson Terastat, Inc Information Access Systems Voice (425) 466 7344 Fax (206) 350 3685 |
From: Bruce S. <bas...@un...> - 2002-07-02 02:35:13
|
This looks like a bug to me, and I'll try to see whether it can be fixed (assuming it's a bug, not a feature!). Here is a workaround, though it is a workaround that will do the wrong thing in the future if the bug is fixed: trail.color[:-1] = trail.color[1:] # move the colors down one slot to compensate trail.pos = trail.pos[1:] # delete first slot in the position list Bruce Sherwood At 02:20 PM 02/07/01 -0700, Bruce Peterson wrote: >The VPython documentation discusses using the curve object to >create trails for moving objects. The curve can also be used to record >the history of an intrinsic parameter (such as temperature represented >by object color) with code like: > obj.pos=newpos > obj.color=newcolor > trail.append(pos=newpos, color=newcolor) >However if an abbreviated history is desired then the code > obj.pos=newpos > obj.color=newcolor > trail.append(pos=newpos, color=newcolor) > if len(trail.pos)>maxlen: > trail.pos=trail.pos[1:] > >correctly truncates the curve length but incorrectly truncates the color. >Internally the curve object appears to implement: > > if len(self.color)>len(self.pos): > self.color=self.color[0:len(self.pos)-1] > >Is there any known way around this so that colors remain correctly associated >with position? > >BTW storing position and color in a seperate list and replacing the entire >list on each iteration rapidly goes into memory management meltdown - it >works for small examples but rapidly dies with larger examples. > > >Bruce Peterson >Terastat, Inc >Information Access Systems >Voice (425) 466 7344 >Fax (206) 350 3685 > > > >------------------------------------------------------- >This sf.net email is sponsored by:ThinkGeek >Welcome to geek heaven. >http://thinkgeek.com/sf >_______________________________________________ >Visualpython-users mailing list >Vis...@li... >https://lists.sourceforge.net/lists/listinfo/visualpython-users |
From: Bruce S. <bas...@un...> - 2002-07-02 02:53:48
|
On second thought, I guess it isn't a bug, though there might be a missing feature. Here's the issue: When you assign a new set of points trail.pos = trail.pos[1:], as far as Visual is concerned you could be assigning any completely new list, as in trail.pos = mylist. When the new assignment is noticed, Visual has no choice but to adjust the length of the trail.color list to be the same as the length of the trail.pos list. Visual doesn't know anything about the "1", just that a shorter list is being assigned to trail.pos. So it doesn't and can't do an intelligent job and delete the first slot in the color list; it arbitrarily deletes the last slot in the color list. You could argue that a better arbitrary guess would be to delete the first slot rather than the last, and I don't know where that would take us. What this does suggest is that what is missing is a method for the curve object which would let you specify how to slice the pos and color lists in the same way at the same time. Bruce Sherwood At 10:36 PM 02/07/01 -0400, Bruce Sherwood wrote: >This looks like a bug to me, and I'll try to see whether it can be fixed >(assuming it's a bug, not a feature!). Here is a workaround, though it is >a workaround that will do the wrong thing in the future if the bug is fixed: > > trail.color[:-1] = trail.color[1:] # move the colors down one slot to > compensate > trail.pos = trail.pos[1:] # delete first slot in the position list > >Bruce Sherwood |
From: David S. <dsc...@vi...> - 2002-07-02 21:30:29
|
> What this does suggest is that what is missing is a method > for the curve > object which would let you specify how to slice the pos and > color lists in > the same way at the same time. Maybe slice deletion? c = curve(...) del c[:3] |
From: Bruce S. <bas...@un...> - 2002-07-03 01:33:19
|
Sounds like a good suggestion. One oddity is that curve.pos and curve.color are very similar to Numeric arrarys (but not the same as?). Numeric arrays don't permit slice deletion. But presumably Visual can do whatever it wants to? Bruce Sherwood At 05:29 PM 02/07/02 -0400, David Scherer wrote: >Maybe slice deletion? > >c = curve(...) >del c[:3] |