attach_arrow
attach_arrow creates an arrow representing a vector attribute of an object, and the arrow is continually displayed at the current location of the moving object. This arrow contains some additional information compared to an ordinary arrow, such as what object it is attached to and which attribute of that object is being represented by the arrow. The following statement will automatically display a green arrow at the current location of the ball, as the ball moves. The arrow will have shaftwidth=0.3, and its axis is determined by scale*ball.axis:
attach_arrow(ball, "axis", scale=1e3,
shaftwidth=0.3, color=color.green)
The default value of scale is 1, the default color of the arrow is the color of the ball, and the default shaftwidth is 0.5*ball.size.y. You can specify any vector attribute of the moving object, not just "axis". For example, if you continually update a vector quantity ball.velocity and want to continually display an arrow representing this quantity at the location of the moving ball (with scale=1 and the color of the ball), just say this:
attach_arrow(ball, "velocity")
It is usually sufficient to attach an arrow to a moving object just once, before starting the motion. However, you can modify the appearance of the arrow later by doing this, using color as an example:
myarrow = attach_arrow(ball, "velocity", color=color.green)
...
myarrow.color = color.red # change the color of the arrow
The following scheme will also work, because specifying the moving object (ball) and the attribute of interest ("velocity") is sufficient for identifying the appropriate arrow to modify:
attach_arrow(ball, "velocity", color=color.green)
...
attach_arrow(ball, "velocity", color=color.red)
myarrow = attach_arrow(ball, "velocity")
...
myarrow.stop()
...
myarrow.start()