Animations are created in 3 steps:
- Initialize an
- Save each frame of the animation with
- Convert the frames to an animated gif with
gif(anim, filename, fps=15)
There are two macros for varying levels of convenience in creating animations:
@gif. The main difference is that
@animate will return an
Animation object for later processing, and
@gif will create an animated gif file (and display it when returned to an IJulia cell).
@gif for simple, one-off animations that you want to view immediately. Use
@animate for anything more complex. Constructing
Animation objects can be done when you need full control of the life-cycle of the animation (usually unnecessary though).
anim = @animate for i=1:100 plot(...) end gif(anim, "/tmp/anim_fps15.gif", fps = 15) gif(anim, "/tmp/anim_fps30.gif", fps = 30)
every flag will only save a frame "every N iterations":
@gif for i=1:100 plot(...) end every 10
when flag will only save a frame "when the expression is true"
@gif for i=1:100 plot(...) end when i > 50 && mod1(i, 10) == 5
animatemethod allows you to pass an arbitrary iterator which returns the "input data" for plotting each frame of an animation. As an example, we'll use
Iterators.repeatedlyto give us an iterator which returns a random vector on each iteration:
using Plots, Iterators itr = repeatedly(()->rand(10), 20) animate(itr, ylims=(0,1), c=:red, fps=5)