11
$\begingroup$

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?

$\endgroup$
6
  • 2
    $\begingroup$ 75936 4847 $\endgroup$
    – Kuba
    Jan 23, 2016 at 16:40
  • $\begingroup$ Kuba, it is not the same. What I'm asking is a fading effect on a part of the path drawn. Not on the particle itself. $\endgroup$
    – Cham
    Jan 23, 2016 at 16:43
  • $\begingroup$ I'm not saying it is although I could argue since the trail after the point is continuous. $\endgroup$
    – Kuba
    Jan 23, 2016 at 16:56
  • $\begingroup$ See the answer below. It is great ! $\endgroup$
    – Cham
    Jan 23, 2016 at 16:56
  • 1
    $\begingroup$ There are lot of useful approaches: mathematica.stackexchange.com/q/4847/1997 $\endgroup$
    – ubpdqn
    Jan 24, 2016 at 2:16

1 Answer 1

20
$\begingroup$

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.

$\endgroup$
9
  • $\begingroup$ Wow, it's working ! Thanks. I'll have to study your answer. $\endgroup$
    – Cham
    Jan 23, 2016 at 16:48
  • $\begingroup$ Why the small delay of 0.001 ? $\endgroup$
    – Cham
    Jan 23, 2016 at 16:49
  • $\begingroup$ 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 ? $\endgroup$
    – Cham
    Jan 23, 2016 at 16:55
  • $\begingroup$ @Cham It errors if I use 0 or 0. as the start. Might be a bug. $\endgroup$
    – Edmund
    Jan 23, 2016 at 16:56
  • 1
    $\begingroup$ @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. $\endgroup$
    – Edmund
    Jan 24, 2016 at 11:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.