3
$\begingroup$

I found a solution that's not what I wanted but it will suffice Thanks - Larry

col = RandomChoice[{Blue, Red}];
frames = Table[Graphics[{
     col, Disk[{5*t - 5, 5*t - 5}, .5]},
    PlotRange -> {{-5, 5}, {-5, 5}}],
   {t, 0, 2, .03}];
ListAnimate[frames, 50]
$\endgroup$
4
  • 2
    $\begingroup$ Easiest fix is to use col := RandomChoice[{Blue, Red}];. The way you have it, col is defined once before the Table. With :=, it is recomputed each time. See reference.wolfram.com/language/ref/SetDelayed.html for more info. $\endgroup$
    – Chris K
    Mar 19, 2023 at 17:39
  • 1
    $\begingroup$ No. That just updates for each frame. I wanted it to update only when the animation starts over. $\endgroup$
    – L. Gorham
    Mar 19, 2023 at 19:26
  • $\begingroup$ I tried that suggestion and it doesn’t work. ?? $\endgroup$
    – L. Gorham
    Mar 19, 2023 at 21:28
  • 1
    $\begingroup$ I found a solution that' s not quite what I wanted but it will suffice. Thanks - Larry frames = {}; For[k = 1, k < 5, k++, col2 = RandomChoice[{Blue, Red}]; frame2 = Table[Graphics[{col2, Disk[{5*t - 5, 5*t - 5}, .5]}, PlotRange -> {{-5, 5}, {-5, 5}}], {t, 0, 2, .2}]; frames = Flatten[Append[frames, frame2]];] ListAnimate[frames, 5, AnimationRepetitions -> 1] $\endgroup$
    – L. Gorham
    Mar 20, 2023 at 3:27

2 Answers 2

3
$\begingroup$

Not continuously random but random for 20 sets. If a viewer sees the repeating pattern with the 20 sets, they need a life.

frames = Table[Graphics[{c, Disk[{5*t - 5, 5*t - 5}, .5]}, 
     PlotRange -> {{-5, 5}, {-5, 5}}], {t, 0, 2, .03}];
ListAnimate[Flatten[Table[frames /. c -> RandomChoice[{Red, Blue, Green, Cyan, Orange, Black}], 
  {i, 1, 20}], 1], 100]

Animation

$\endgroup$
1
  • $\begingroup$ Thank you JimB, infinite unnecessary. Much better than mine - Larry $\endgroup$
    – L. Gorham
    Mar 20, 2023 at 14:13
1
$\begingroup$

Putting the definition of col in a Module works:

frames := Module[{col},
   col = RandomChoice[{Blue, Red}]; 
   Table[Graphics[{col, Disk[{5*t - 5, 5*t - 5}, .5]}, 
     PlotRange -> {{-5, 5}, {-5, 5}}], {t, 0, 2, .03}]
];

ListAnimate[frames, 50]
$\endgroup$
3
  • $\begingroup$ Don’t know why this doesn’t work on my Dell Intel I5, Mathematica 11.2 Home Edition, Win 11. Only updates when it’s re-executed. $\endgroup$
    – L. Gorham
    Mar 20, 2023 at 21:32
  • $\begingroup$ I guess I still didn't get what you're looking for -- this does generate a new color each time ListAnimate is run. Sorry! $\endgroup$
    – Chris K
    Mar 20, 2023 at 21:38
  • $\begingroup$ All set now Cris K. I appreciate your help, it’s my first animated rodeo. $\endgroup$
    – L. Gorham
    Mar 21, 2023 at 11:53

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.