Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I almost remember an example that has a moving red point on a given curve, which will moving time and time again, with no controls...

now, here is my question: given a curve by

u[y_] := y^4 - 4 y^2 + 3
v[y_] := 2 y - y^3
curv=ParametricPlot[{u[y], v[y]}, {y, -2, 2}]

then, how to attach a "big red" moving point on it, which are moving again and again?

share|improve this question
    
How do we decide which curve to put the point on at say x=0? –  JohnD Nov 16 '12 at 12:46

4 Answers 4

A potential way of doing this is by using DynamicModule to keep a scoped variable time, and use Dynamic wrapper to keep it updated:

 curve

 DynamicModule[{t},
   DynamicWrapper[
      Show[curv, Graphics[{PointSize[Large], Red, Point[Dynamic[{u[t], v[t]}]]}]],
   t = Clock[{-2, 2}]
   ]
  ]
share|improve this answer
    
I like the use of Clock I couldn't figure out how to get it neat like that :) –  ssch Nov 16 '12 at 17:00
    
Any way with Dynamic and Clock to do that yet have the point traverse the curve just once? Just as AnimationRepetitions -> 1 would do inside an Animate? –  murray Nov 16 '12 at 18:54
    
@murray Have a look at the documentation for Clock it has a quite useful span of usages. to set it to only run through the animation once in this case, simply use Clock[{-2, 2}, 4, 1]. –  jVincent Nov 16 '12 at 19:02
    
@jVincent: Yes, I see that Clock allows running just once. It's just that I've always been annoyed that Animate, and the Manipulate animation control, produce a loop. –  murray Nov 17 '12 at 15:35

You can use Animate

u[y_] := y^4 - 4 y^2 + 3
v[y_] := 2 y - y^3
curv = ParametricPlot[{u[y], v[y]}, {y, -2, 2}];
Animate[
 Show[
  curv,
  Graphics[{PointSize[Large], Red, Point[Dynamic[{u[t], v[t]}]]}]
  ]
 , {t, -2, 2,AppearanceElements->None}]

Animate None

share|improve this answer
    
can I make it without controls? –  van abel Nov 16 '12 at 12:51
    
@van, you could use Table[] in place of Animate[] and export as a GIF file... –  J. M. Nov 16 '12 at 12:58
    
@vanabel Try Animate[Plot[Sin[x + a], {x, 0, 10}], {a, 0, 5, AppearanceElements -> None}] –  Sasha Nov 16 '12 at 13:01
    
I really think you should review your last solution, what you are producing is the product of an invisible element and a graph, which is perfectly valid in Mathematica, but definitely not what someone reading the code expects. When you want to tie a dynamic expression to a different display form, you should properly use DynamicWrapper. –  jVincent Nov 16 '12 at 15:15
    
@jVincent, Yes I'll make it more clear :) –  ssch Nov 16 '12 at 15:51

You don't want to have controls? How about using timed tasks?

p=0;
t = CreateScheduledTask[p = Mod[p + 0.1, 4, -2], 0.1];

Show[
 curv,
 Graphics[{Red, PointSize[0.03], Dynamic@Point@{u[p], v[p]}}]
 ]

StartScheduledTask[t];

Stop it using:

RemoveScheduledTask[t];

Alternatively, you could use Refresh to take care of the timing.

Show[
 curv,
 Graphics[{Red, PointSize[0.03], 
   Dynamic[Refresh[p = Mod[p + 0.05, 4, -2]; Point@{u[p], v[p]}, 
     UpdateInterval -> 0.05, TrackedSymbols -> {}]]}]
 ]

Note the TrackedSymbols -> {} option which prevents the p = Mod[p + 0.05, 4, -2] part from self-triggering another iteration.


It's even easier using Clock:

Show[curv, 
 Graphics[{Red, PointSize[0.03], 
   Dynamic[Point@{u[#], v[#]} &@Clock[{-2, 2, .05}, 5]]}]]
share|improve this answer

Another way to use Clock: with Mesh and MeshFunctions combination:

 Dynamic@ParametricPlot[{u[x], v[x]}, {x, -2, 2},
 MeshFunctions -> {#3 &}, Mesh -> {{Clock[{-2, 2}]}}, 
 MeshStyle -> {Red, PointSize[Large]}]

Yet another way: Using ListAnimate:

 ListAnimate[Table[Show[ParametricPlot[{u[x], v[x]}, {x, -2, 2}],
    Graphics[{PointSize[Large], Red, Point[{u[t], v[t]}]}]],
    {t, -2, 2, .01}], Paneled -> False] /. 
 HoldPattern[AppearanceElements -> _] -> (AppearanceElements -> None)

(the trick to remove AppearanceElements from Vitaly's answer to a related question.)

share|improve this answer

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.