Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
2  
75936 4847 – Kuba Jan 23 at 16:40
    
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. – Cham Jan 23 at 16:43
    
I'm not saying it is although I could argue since the trail after the point is continuous. – Kuba Jan 23 at 16:56
    
See the answer below. It is great ! – Cham Jan 23 at 16:56
1  
There are lot of useful approaches: mathematica.stackexchange.com/q/4847/1997 – ubpdqn Jan 24 at 2:16
up vote 16 down vote accepted

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.

share|improve this answer
    
Wow, it's working ! Thanks. I'll have to study your answer. – Cham Jan 23 at 16:48
    
Why the small delay of 0.001 ? – Cham Jan 23 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 at 16:55
    
@Cham It errors if I use 0 or 0. as the start. Might be a bug. – Edmund Jan 23 at 16:56
    
A bug ? Is it the same with your more recent version of Mathematica ? – Cham Jan 23 at 16:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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