0
$\begingroup$

I'm trying animate a parametric plot without having to specify the range of the function variables, which will be done later on in a bigger animation. Here's my code:

x1[t_] := Sin[t]
y1[t_] := -Cos[t]
angle[t_] := Graphics[{Line[{{0, 0}, {x1[t], y1[t]}}]}];
tip[t_] := Graphics[{Disk[{x1[t], y1[t]}, 0.1]}]
frame = Graphics[{Line[{{-2, 2}, {-2, -2}, {2, -2}, {2, 2}, {2, 2}}]}];
path = ParametricPlot[{x1[t], y1[t]}, {t, 0, 10}];
Animate[
 Show[path, frame, angle[t], tip[t]],
 {t, 0, 10}, AnimationRunning -> False]

My problem is that I have to specify the range twice here and it's showing the full path of the ball instead of generating it dynamically.

$\endgroup$

1 Answer 1

1
$\begingroup$
Clear["Global`*"]

x1[t_] := Sin[t]
y1[t_] := -Cos[t]
angle[t_] :=
  Graphics[{Line[{{0, 0}, {x1[t], y1[t]}}]}];
tip[t_] := Graphics[{
   ColorData["Rainbow"][t/(2 Pi)],
   Disk[{x1[t], y1[t]}, 0.1]}]
frame := Graphics[{
    Line[{{-2, 2}, {-2, -2}, {2, -2}, {2, 2}, {2, 2}}]}];
path[t_] := ParametricPlot[
   {x1[a], y1[a]}, {a, 0, t},
   ColorFunction ->
    Function[{x, y, u}, ColorData["Rainbow"][u/(2 Pi)]],
   ColorFunctionScaling -> False];
Animate[
 Show[
  path[t], frame, angle[t], tip[t],
  PlotRange -> 1],
 {t, 0.001, 2 Pi},
 AnimationRunning -> False]

enter image description here

$\endgroup$
2
  • $\begingroup$ Is there any way to make t start at 0? $\endgroup$
    – student
    Dec 10, 2022 at 18:33
  • $\begingroup$ Yes and no. It has to be done with mirrors. To change the Animate iterator to {t, 0, 2Pi} you would also have to change the ParametricPlot iterator to something like {a, 0, Max[t, 0.001]} since any plot iterator must cover a nonzero interval. $\endgroup$
    – Bob Hanlon
    Dec 10, 2022 at 19:20

Your Answer

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

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