1
$\begingroup$

I'm trying to figure out how to get animations to render smoother in Mathematica. I'm very new to this but I'd like to get a 30fps animation of something. Here's a simple example:

Animate[Plot[Sin[a*x],{x,-2Pi,2Pi}],{a,-1,1,.05},RefreshRate->40]

However, this is not a smooth animation at all. I tried manipulating both step size and refresh rate, but neither seem to work. Am I missing something? I tried this both in cloud and desktop.

$\endgroup$
3
$\begingroup$

Generate the slides outside of the Animate, i.e.

slides = Table[Plot[Sin[a*x], {x, -2 Pi, 2 Pi}, PlotRange -> {{-2 Pi, 2 Pi}, {-1, 1}}],
               {a, -1, 1, .01}];
Animate[slides[[i]], {i, 1, 201, 1}, RefreshRate -> 40]

Otherwise, Animate will try to generate them on the fly, which can slow things down.

Hopefully this helps achieve what you're after.

$\endgroup$
  • $\begingroup$ Thanks for the response! This still seems to be giving me very slow framerates. $\endgroup$ – rb612 Sep 20 '17 at 4:52
  • $\begingroup$ Maybe my computer is faster so I didn’t notice that. Perhaps export the slides as a GIF, at which point they’d be at a standard speed? $\endgroup$ – user6014 Sep 20 '17 at 4:53
  • $\begingroup$ This works! Thanks! Why does the methods I presented in my question not work? $\endgroup$ – rb612 Sep 20 '17 at 5:15
  • 1
    $\begingroup$ @rb612 "Otherwise Animate will try to generate them on the fly, which can slow things down." $\endgroup$ – user6014 Sep 20 '17 at 13:33
1
$\begingroup$

ListAnimate is probably what you're looking for. Set up your slides:

slides = Table[
   Plot[Sin[a*x], {x, -2 Pi, 2 Pi}, 
    PlotRange -> {{-2 Pi, 2 Pi}, {-1, 1}}], {a, -1, 1, 0.05}];

Then ListAnimate allows you to specify the frames per second directly in the second argument:

ListAnimate[slides, 40]

Obviously, you can mess with the stepsize in your Table to get the length of the animation right.

$\endgroup$
  • $\begingroup$ Thank you for the answer! This looks like it should work, but the animation is being generated when I call it, so it's still running at a few fps. It won't even run when I'm at 40fps $\endgroup$ – rb612 Sep 20 '17 at 4:51
  • $\begingroup$ @rb612 It won't be re-generating the plots when you call ListAnimate. ListAnimate just runs through whatever list you give it. All I can think is that there's something else sucking up your resources (unless you're using SetDelayed, :=, or something). $\endgroup$ – aardvark2012 Sep 20 '17 at 8:00

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.