Function Repository Resource:

AnimatedArrow

Source Notebook

An Arrow whose heads move dynamically

Contributed by: Jon McLoone

ResourceFunction["AnimatedArrow"][pts]

is a Graphics or Graphics3D primitive that displays as an Arrow but with animated Arrowheads.

Details and Options

Arrowheads primitives are ignored, but the following options are available:
"HeadSize"0.04size of the arrowheads
"HeadCount"1number of arrowheads to display
"Period"2time (in seconds) taken for an arrowhead to travel the length of the arrow
"InitialPosition"0position of the arrowhead at time 0
"Time"Automaticcurrent time in the animation

Examples

Basic Examples (1) 

AnimatedArrow displays the same as Arrow except its head position is animated:

In[1]:=
Graphics[ResourceFunction["AnimatedArrow"][{{0, 0}, {1, 1}}]]
Out[1]=

Scope (2) 

AnimatedArrow can be used in Graphics3D:

In[2]:=
Graphics3D[ResourceFunction["AnimatedArrow"][{{0, 0, 0}, {1, 1, 1}}]]
Out[2]=

AnimatedArrow can be specified with a BSplineCurve:

In[3]:=
Graphics3D[
 ResourceFunction["AnimatedArrow"][
  BSplineCurve[{{0, 0, 0}, {1, 1, 1}, {2, -1, 1}}], "HeadCount" -> 2, "Period" -> 2, "HeadSize" -> 0.1]]
Out[3]=

Options (7) 

Control the size of the arrowheads with "HeadSize":

In[4]:=
Graphics[ResourceFunction["AnimatedArrow"][{{0, 0}, {1, 1}}, "HeadSize" -> 0.1]]
Out[4]=

Control the number of arrowheads with "HeadCount":

In[5]:=
Graphics[ResourceFunction["AnimatedArrow"][{{0, 0}, {1, 1}}, "HeadCount" -> 4]]
Out[5]=

Control the speed of the arrowhead movement with "Period". The period is measured in the number of seconds it takes an arrowhead to travel the length of the arrow:

In[6]:=
Graphics[ResourceFunction["AnimatedArrow"][{{0, 0}, {1, 1}}, "Period" -> 4]]
Out[6]=

Multiple arrows will be synchronized:

In[7]:=
Graphics[{
  ResourceFunction["AnimatedArrow"][{{0, 0}, {1, 0}}],
  ResourceFunction["AnimatedArrow"][{{0, 1}, {1, 1}}]
  }, AspectRatio -> 1/5]
Out[7]=

Use "InitialPostion" to control their relative positions:

In[8]:=
Graphics[{
  ResourceFunction["AnimatedArrow"][{{0, 0}, {1, 0}}],
  ResourceFunction["AnimatedArrow"][{{0, 1}, {1, 1}}, "InitialPosition" -> 0.5]
  }, AspectRatio -> 1/5]
Out[8]=

Use "InitialPostion" with RuleDelayed to randomly desynchronize arrows:

In[9]:=
Graphics[Table[
  ResourceFunction["AnimatedArrow"][{{0, i}, {1, i}}, "InitialPosition" :> Random[]], {i, 10}],
 AspectRatio -> 1/5]
Out[9]=

While AnimatedArrow is intended to be automatically animated, you may wish to control the animation by specifying the time, for example, if you wish to export the result to a movie:

In[10]:=
Table[
 Graphics[{
   ResourceFunction["AnimatedArrow"][{{0, 0}, {1, 0}}, "Time" -> t],
   }, AspectRatio -> 1/5],
 {t, 0, 0.5, 0.1}]
Out[10]=

Applications (1) 

AnimatedArrow can be used within a Graph:

In[11]:=
Graph[Table[i -> Mod[i^2, 74], {i, 60}], EdgeShapeFunction -> (ResourceFunction["AnimatedArrow"][#, "InitialPosition" :> Random[]] &)]
Out[11]=

Publisher

Jon McLoone

Version History

  • 1.0.0 – 21 November 2019

License Information