Group Abstract Group Abstract

Message Boards Message Boards

Problem with $CellContext in Animation

Posted 2 years ago

I have some code here, that worked fine 10 or 20 years ago. Now it won't animate any more and seems to have a problem with $CellContext of variable t. ChatGPT suggested wrapping Animate with DynamicModule[{t},...], but that didn't help. Does anyone know, what's wrong? Here is the code:

AnzahlBilder = b = 18;
numberOfAtoms = 120;
cylRadius = 20;
waveLength = 0.4*cylRadius;
waveConstant = N[2Pi/waveLength];
amplitude = 0.10*waveLength;
angularFrequency = N[2Pi];
fromXAndYToPhiAndR[{x_,y_}] := {ArcTan[x,y], Sqrt[x^2+y^2]}
fromPhiAndRToXAndY[{phi_,r_}] := r*{Cos[phi],Sin[phi]}

coordinatesOfAtoms = Table[
    {Random[Real,{-cylRadius,cylRadius}], 
    Random[Real,{-cylRadius,cylRadius}]},
    {numberOfAtoms}];

cylCoorOfAtoms = Map[fromXAndYToPhiAndR, coordinatesOfAtoms];

displaceAtom[{phi_,r_}] := {phi, 
    Max[0, r + amplitude*Sin[waveConstant*r - angularFrequency*t]]}

Animate[Graphics[Map[Point, Map[fromPhiAndRToXAndY,
Map[displaceAtom, cylCoorOfAtoms]]]], {t, 0, 1-1/b, 1/b}]
POSTED BY: John Barkowsky
Posted 2 years ago

I changed the last line to

ListAnimate[
 Table[Graphics[
   Map[Point, 
    Map[fromPhiAndRToXAndY, Map[displaceAtom, cylCoorOfAtoms]]]], {t, 
   0, 1 - 1/b, 1/b}]]

Now it is working. I would liked to understand the problem, though. Documentation is not too great. Thanks if someone tried to figure it out for me. The animation, by the way, shows air molecules in motion (spherical model). Set numberOfAtoms to 1200.

POSTED BY: John Barkowsky
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard