Merge pull request #3660 from t-bltg/anim_glob

Avoid using global variables in animation.jl
This commit is contained in:
t-bltg 2021-07-22 01:57:03 +02:00 committed by GitHub
commit 86fbb39723
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -170,7 +170,7 @@ function _animate(forloop::Expr, args...; callgif = false)
end
push!(block.args, :(if $filterexpr; Plots.frame($animsym); end))
push!(block.args, :(global $countersym += 1))
push!(block.args, :($countersym += 1))
# add a final call to `gif(anim)`?
retval = callgif ? :(Plots.gif($animsym)) : animsym
@ -179,8 +179,9 @@ function _animate(forloop::Expr, args...; callgif = false)
esc(quote
$freqassert # if filtering, check frequency is an Integer > 0
$animsym = Plots.Animation() # init animation object
global $countersym = 1 # init iteration counter
let $countersym = 1 # init iteration counter
$forloop # for loop, saving a frame after each iteration
end
$retval # return the animation object, or the gif
end)
end