11

I would like to add a smooth fading effect to the end of a curve, while it is animated. Here's a minimal working example which shows a particle moving on a circle (the circle is drawn while the particle is moving around):

circle[t_] := {Sin[Pi t], Cos[Pi t]};
dMax = 1.5;

Animate[
  Show[
    {ParametricPlot[circle[t], {t, 0 + 0.001, T},
      PlotRange -> {{-dMax, dMax}, {-dMax, dMax}},
      Frame -> True, Axes -> True, AxesOrigin -> {0, 0}, PlotPoints -> 100],
     Graphics@{Black, PointSize -> 0.015, Point[circle[T]]}},
   ImageSize -> 500], 
 {T, 0, 6}, AnimationRate -> 1, AnimationRunning -> False]
  1. The end of the trajectory should gently fade away while the particle is moving. Is it possible to do this animation effect with Mathematica (I'm using version 7.0)?

  2. Also, I don't understand why I need to add a small delay (0 + 0.001) to the Animate definition. Without that delay, Mathematica gives an error message:

    Endpoints for t in {t, 0+0., T} must have distinct machine-precision numerical values.

    So how to properly fix this problem without adding an arbitrary delay?

mmal
  • 3,508
  • 2
  • 18
  • 38
Cham
  • 4,093
  • 21
  • 36

1 Answers1

20

ColorFunction and Epilog were around in version 7. However, ColorFunction did get an update in version 9 so I am not certain if this will work in version 7.

Animate[
 ParametricPlot[circle[t], {t, Max[0, u - .2], u}, 
  PlotRange -> {{-dMax, dMax}, {-dMax, dMax}},
  ColorFunction -> Function[{x, y, w}, Opacity[w, Blue]],
  Frame -> True, Axes -> True, AxesOrigin -> {0, 0}, PlotPoints -> 100,
  Epilog -> {Black, PointSize -> 0.015, Point[circle[u]]}],
 {u, 0. + $MachineEpsilon, 6}, AnimationRate -> 1, AnimationRunning -> False]

enter image description here

Hope this helps.

Edmund
  • 42,267
  • 3
  • 51
  • 143
  • Wow, it's working ! Thanks. I'll have to study your answer. – Cham Jan 23 '16 at 16:48
  • Why the small delay of 0.001 ? – Cham Jan 23 '16 at 16:49
  • My code appears to be working great ! :-) However, I still don't understand the delay of 0.001. Is it really necessary to add such an arbitrary delay to the animate defintion ? – Cham Jan 23 '16 at 16:55
  • @Cham It errors if I use 0 or 0. as the start. Might be a bug. – Edmund Jan 23 '16 at 16:56
  • A bug ? Is it the same with your more recent version of Mathematica ? – Cham Jan 23 '16 at 16:57
  • Yes. Version 10.3.1 Win 8.1 Pro 64 bit. A ParametricPlot of circle can start at zero with no issues. It seems that Animate does not like it to start at zero. – Edmund Jan 23 '16 at 17:01
  • The problem is you're trying to make a parametric plot from {t,Max[0, u - .2],u}. When u=0, Max[0,u-0.2] evaluates to 0, then you're plotting from {t,0,0}, which parametric plot doesn't like. – N.J.Evans Jan 23 '16 at 23:16
  • @Evans, so what should be the proper way of parametrizing the animation ? My only concern here is the arbitrariness of the 0.001 delay value I'm using. – Cham Jan 24 '16 at 01:08
  • 1
    @Cham You can use 0. + $MachineEpsilon instead of 0.001. This is the closest your computer can get to zero and a less arbitrary way of preventing ParametricPLot from plotting zero to zero. – Edmund Jan 24 '16 at 11:18