|  | Home If you're new to Python and VPython: Introduction A VPython tutorial Pictures of 3D objects What's new Classic VPython web site VPython license Python web site |  |
Attach a trail or arrow |
attach_trail and attach_arrow This article describes the simple "make_trail" mechanism for leaving a trail behind a moving object, as shown in the image above. GlowScript offers additional powerful mechanisms for attaching trails or arrows to moving objects. attach_trail is similar to the make_trail mechanism described here but includes the ability to specify an arbitrary function to be called to provide a position rather than using the position of the object. attach_arrow lets you specify a quantity and a scale factor to display an arrow at the location of a moving object. make_trail You can leave a trail behind a moving object simply by specifying make_trail=True: ball = sphere(make_trail=True) Each time the scene is rendered, the new position ball.pos is added to a curve, thereby leaving a trail behind the moving sphere. This works with arrow, box, cone, cylinder, ellipsoid, pyramid, ring, and sphere. You can specify using a points object rather than a curve object for displaying the trail, and you can specify how many points to skip or retain: ball = sphere(make_trail=True, trail_type="points", interval=10, retain=50) The trail of this sphere will show individual points rather than a continuous line, it will display spheres at every 10th sphere location, and it will retain only the most recent 50 of these points. At any time during the moving of the object, you can specify ball.make_trail=False, in which case no more points are added to the ball's trail until you set ball.make_trail=True again (at which point a new trail is started at the ball's current position). If you specify an interval (greater than zero) and do not specify a position when creating the ball, the first point along the trail will occur when a position is later assigned to the ball. If you do specify a position when creating the ball, and make_trail is True, the first point along the trail is that specified position. If no interval is specified, the curve starts with whatever the position is at the time of the first rendering of the scene. Summary make_trail Must be mentioned when creating the moving object; if False, no points will be added to the trail until you say ball.make_trail = True (assuming the moving object is named ball) trail_type Default is "curve", but can be "points" interval If interval=10, a point is added to the trail only every 10th move of the object. If interval is 0, no trail is shown. If trail_type is "points", the default interval = 1; interval must have a nonzero value because the points need to be accurately spaced in order to look right. If trail_type is "curve" (the default), and no interval is specified, updates to the trail are made every time a new image is rendered, typically about 30 to 60 times a second. This usually looks fine. pps If trail_type is "curve", and no interval is specified, pps=15 means "add a point to the curve approximately 15 times per second". retain If retain=50, only the 50 most recently added points will be retained trail_color The color of the curve or points (default is the object's color). If you change this during the motion, later portions of the trail will have this color. trail_radius The radius of the curve or points. The default for the "curve" option is 0, which makes a thin curve (this works best in the xy plain; if it doesn't give the result you want, set trail_radius to the desired value). The default for the "points" option is 0.2 times the radius, 0.1 times the height or size.y, of the moving object. If you change this during the motion, later portions of the trail will have this radius. clear_trail() Clears all points from the existing trail before adding more. Note that setting make_trail to False stops adding more points.