0
$\begingroup$

I'm new to Mathematica and I'm trying to do this project where I have to animate multiple circles.

I have 4 circles, each with x = 1, 2, 3, 4 , respectively. Each y position is given by a function F(x, n, t). I want to animate the circles with respect to t, manipulate n and have the four circles side-by-side.

I came up with this

Manipulate[
  Animate[
    Graphics[{Circle[{x, F[x, n, t]}, 0.2]}, 
      PlotRange -> {{0, 6}, {-2, 2}}], {t, 0, 10}], 
  {n, 1, 4, 1}]

which works for a defined value of x.

Can anyone help me figure out how to animate for all values of x at the same time?

$\endgroup$
  • 1
    $\begingroup$ what's your F[x,n,t] !? $\endgroup$ – Alrubaie Apr 16 at 19:48
1
$\begingroup$

you have to define your F[x,n,t] also work in position x of F[x,n,t] if you want to place them side by side or above each other !???

Try this will help you

F[x_, n_, t_] := Sin[n*x*t];

Manipulate[Animate[Graphics[{
    {Red, Circle[{x + 2, F[x, n, t]}, 0.2]},
    {Blue, Circle[{x, F[x, n, t]}, 0.2]},
    {Black, Circle[{x + 1, F[x, n, t]}, 0.2]},
    {Green, Circle[{x - 1, F[x, n, t]}, 0.2]}
    }, PlotRange -> {{0, 5}, {-2, 2}}],
  {x, 0, 5}, {t, 0, 10}], {n, 1, 4, 1}]

enter image description here

$\endgroup$
  • $\begingroup$ The function was defined, I just didn't feel like writing it here. That did do it. Is there any way to make it more compact? Maybe with a cycle for the values of x or something? $\endgroup$ – Bernardo Silva Apr 16 at 20:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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