mirror of
https://gitlab.rlp.net/mobitar/ReCo.jl.git
synced 2024-12-21 00:51:21 +00:00
Fixed animation memory leak
This commit is contained in:
parent
5b016f7b68
commit
7bade826e0
3 changed files with 37 additions and 22 deletions
1
.JuliaFormatter.toml
Normal file
1
.JuliaFormatter.toml
Normal file
|
@ -0,0 +1 @@
|
|||
style = "blue"
|
|
@ -8,7 +8,7 @@ using GLMakie, ColorSchemes, LaTeXStrings
|
|||
using StaticArrays
|
||||
|
||||
import Dates: now, CompoundPeriod, canonicalize
|
||||
import Base.push!
|
||||
import Base: push!, run
|
||||
|
||||
# Development deps
|
||||
using Revise
|
||||
|
|
|
@ -3,7 +3,7 @@ function animate(sol::Solution, args, name_part::String; framerate::Int64=10)
|
|||
|
||||
set_theme!(theme_black())
|
||||
|
||||
fig = Figure(resolution=(1080, 1080))
|
||||
fig = Figure(; resolution=(1080, 1080))
|
||||
ax = Axis(
|
||||
fig[1, 1];
|
||||
limits=(-args.l, args.l, -args.l, args.l),
|
||||
|
@ -12,13 +12,18 @@ function animate(sol::Solution, args, name_part::String; framerate::Int64=10)
|
|||
ylabel=L"y",
|
||||
)
|
||||
|
||||
Colorbar(fig[1, 2]; limits=(0, 2), colormap=ColorSchemes.rainbow, label=L"\frac{\varphi}{\pi}")
|
||||
Colorbar(
|
||||
fig[1, 2];
|
||||
limits=(0, 2),
|
||||
colormap=ColorSchemes.rainbow,
|
||||
label=L"\frac{\varphi}{\pi}",
|
||||
)
|
||||
|
||||
animation_path = "exports/$name_part.mkv"
|
||||
|
||||
record(fig, animation_path; framerate=framerate) do io
|
||||
circles = Vector{Circle}(undef, args.N)
|
||||
colors = Vector{RGBAf}(undef, args.N)
|
||||
circles = Observable(Vector{Circle}(undef, args.N))
|
||||
colors = Observable(Vector{RGBAf}(undef, args.N))
|
||||
|
||||
if args.debug
|
||||
segments_x = zeros(2 * args.N)
|
||||
|
@ -31,15 +36,21 @@ function animate(sol::Solution, args, name_part::String; framerate::Int64=10)
|
|||
skin_colors = Vector{RGBAf}(undef, args.N)
|
||||
end
|
||||
|
||||
@showprogress 0.5 for frame in 1:args.n_frames
|
||||
@simd for i in 1:args.N
|
||||
circles[i] = Circle(Point2(sol.center[i, frame]), args.particle_diameter / 2)
|
||||
|
||||
color = get(ColorSchemes.rainbow, rem2pi(sol.φ[i, frame] / (2 * π), RoundDown))
|
||||
colors[i] = RGBAf(color)
|
||||
@showprogress 0.5 for frame in 1:(args.n_frames)
|
||||
@simd for i in 1:(args.N)
|
||||
circles[][i] = Circle(
|
||||
Point2(sol.center[i, frame]), args.particle_diameter / 2
|
||||
)
|
||||
|
||||
color = get(
|
||||
ColorSchemes.rainbow, rem2pi(sol.φ[i, frame] / (2 * π), RoundDown)
|
||||
)
|
||||
colors[][i] = RGBAf(color)
|
||||
|
||||
if args.debug
|
||||
interaction_circles[i] = Circle(Point2(sol.center[i, frame]), args.interaction_r)
|
||||
interaction_circles[i] = Circle(
|
||||
Point2(sol.center[i, frame]), args.interaction_r
|
||||
)
|
||||
skin_circles[i] = Circle(Point2(sol.center[i, frame]), args.skin_r)
|
||||
|
||||
interaction_colors[i] = RGBAf(color, 0.12)
|
||||
|
@ -48,8 +59,6 @@ function animate(sol::Solution, args, name_part::String; framerate::Int64=10)
|
|||
end
|
||||
|
||||
if frame > 1
|
||||
empty!(ax)
|
||||
|
||||
if args.debug
|
||||
@simd for i in 1:(args.N)
|
||||
segments_x[2 * i - 1] = sol.center[i, frame - 1][1]
|
||||
|
@ -59,18 +68,23 @@ function animate(sol::Solution, args, name_part::String; framerate::Int64=10)
|
|||
segments_y[2 * i] = sol.center[i, frame][2]
|
||||
end
|
||||
|
||||
linesegments!(ax, segments_x, segments_y; color=colors)
|
||||
if frame == 2
|
||||
linesegments!(ax, segments_x, segments_y; color=colors)
|
||||
end
|
||||
end
|
||||
else
|
||||
else # First frame
|
||||
poly!(ax, circles; color=colors)
|
||||
|
||||
if args.debug
|
||||
poly!(ax, interaction_circles; color=interaction_colors)
|
||||
poly!(ax, skin_circles; color=skin_colors)
|
||||
end
|
||||
|
||||
println("Started recording!")
|
||||
end
|
||||
|
||||
poly!(ax, circles; color=colors)
|
||||
|
||||
if args.debug
|
||||
poly!(ax, interaction_circles; color=interaction_colors)
|
||||
poly!(ax, skin_circles; color=skin_colors)
|
||||
end
|
||||
notify(circles)
|
||||
notify(colors)
|
||||
|
||||
ax.title = "t = $(round(sol.t[frame], digits=3))"
|
||||
|
||||
|
|
Loading…
Reference in a new issue