Animate with While loop in Julia

Is it possible to implement plot animation within while loop in Julia? I’m trying to translate a code that my professor gave me in Matlab. (Top Opt - Sigmund 99 line matlab code)
It seems both @gif and @animate support only for loops. Since, the iterations to solve the problem depend on problem (and may take long time in case of fine mesh), I’d rather have the plot update per iteration than recording data and using for loop later. But, I just can’t implement it within while loop. Here is a sample for what I’m trying to do.

using Plots
a = ones(10,10)
i = 1
heatmap(a, c =:grays, framestyle = :none, cbar = false)
while i < 11
    a[i] += i
    i += 1
   heatmap!(a)
   sleep(1e-4)
end

I have tried this both in terminal and Pluto. Please let me know if there is way to implement this. Thanks!

Makie.jl allows for this.
you can see an example here https://github.com/triscale-innov/ScreenCastSpring.jl and a related video (in French with English sub-titles) here : Julia #2/2 : Performance des codes Julia - YouTube

3 Likes

https://github.com/JuliaPlots/Plots.jl/pull/3497

3 Likes

Thanks! Haven’t tried Makie yet but will try it out now!

Wow! Thank you sooo much!!