Here is an example from the Plots documentation:
using Plots
@userplot CirclePlot
@recipe function f(cp::CirclePlot)
x, y, i = cp.args
n = length(x)
inds = circshift(1:n, 1 - i)
linewidth --> range(0, 10, length = n)
seriesalpha --> range(0, 1, length = n)
aspect_ratio --> 1
label --> false
x[inds], y[inds]
end
n = 150
t = range(0, 2π, length = n)
x = sin.(t)
y = cos.(t)
anim = @animate for i ∈ 1:n
circleplot(x, y, i)
end
gif(anim, "anim_fps15.gif", fps = 15)
Suppose that instead of a .gif
file, I want to create a folder of .png
s named frame1.png
, frame2.png
, etc.
In the code above, I could do this by removing the @animate
macro and saving each file:
for i ∈ 1:n
circleplot(x, y, i)
savefig("frame$i.png")
end
But how do I do this if I only have access to the object anim
and not the underlying code that generates it?
I noticed that calling frame()
on anim
produces some sort of iterable that appears to index the frames:
for f in frame(anim)
@show f
end
yields
f = "000001.png"
f = "000002.png"
f = "000003.png"
f = "000004.png"
f = "000005.png"
f = "000006.png"
f = "000007.png"
f = "000008.png"
...
But this is as far as I’ve gotten.
My ultimate goal is to embed the animation in a LaTeX/Beamer presentation, using the method given in this StackExchange question.