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
|
using StaticArrays
|
||||||
|
|
||||||
import Dates: now, CompoundPeriod, canonicalize
|
import Dates: now, CompoundPeriod, canonicalize
|
||||||
import Base.push!
|
import Base: push!, run
|
||||||
|
|
||||||
# Development deps
|
# Development deps
|
||||||
using Revise
|
using Revise
|
||||||
|
|
|
@ -3,7 +3,7 @@ function animate(sol::Solution, args, name_part::String; framerate::Int64=10)
|
||||||
|
|
||||||
set_theme!(theme_black())
|
set_theme!(theme_black())
|
||||||
|
|
||||||
fig = Figure(resolution=(1080, 1080))
|
fig = Figure(; resolution=(1080, 1080))
|
||||||
ax = Axis(
|
ax = Axis(
|
||||||
fig[1, 1];
|
fig[1, 1];
|
||||||
limits=(-args.l, args.l, -args.l, args.l),
|
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",
|
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"
|
animation_path = "exports/$name_part.mkv"
|
||||||
|
|
||||||
record(fig, animation_path; framerate=framerate) do io
|
record(fig, animation_path; framerate=framerate) do io
|
||||||
circles = Vector{Circle}(undef, args.N)
|
circles = Observable(Vector{Circle}(undef, args.N))
|
||||||
colors = Vector{RGBAf}(undef, args.N)
|
colors = Observable(Vector{RGBAf}(undef, args.N))
|
||||||
|
|
||||||
if args.debug
|
if args.debug
|
||||||
segments_x = zeros(2 * args.N)
|
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)
|
skin_colors = Vector{RGBAf}(undef, args.N)
|
||||||
end
|
end
|
||||||
|
|
||||||
@showprogress 0.5 for frame in 1:args.n_frames
|
@showprogress 0.5 for frame in 1:(args.n_frames)
|
||||||
@simd for i in 1:args.N
|
@simd for i in 1:(args.N)
|
||||||
circles[i] = Circle(Point2(sol.center[i, frame]), args.particle_diameter / 2)
|
circles[][i] = Circle(
|
||||||
|
Point2(sol.center[i, frame]), args.particle_diameter / 2
|
||||||
|
)
|
||||||
|
|
||||||
color = get(ColorSchemes.rainbow, rem2pi(sol.φ[i, frame] / (2 * π), RoundDown))
|
color = get(
|
||||||
colors[i] = RGBAf(color)
|
ColorSchemes.rainbow, rem2pi(sol.φ[i, frame] / (2 * π), RoundDown)
|
||||||
|
)
|
||||||
|
colors[][i] = RGBAf(color)
|
||||||
|
|
||||||
if args.debug
|
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)
|
skin_circles[i] = Circle(Point2(sol.center[i, frame]), args.skin_r)
|
||||||
|
|
||||||
interaction_colors[i] = RGBAf(color, 0.12)
|
interaction_colors[i] = RGBAf(color, 0.12)
|
||||||
|
@ -48,8 +59,6 @@ function animate(sol::Solution, args, name_part::String; framerate::Int64=10)
|
||||||
end
|
end
|
||||||
|
|
||||||
if frame > 1
|
if frame > 1
|
||||||
empty!(ax)
|
|
||||||
|
|
||||||
if args.debug
|
if args.debug
|
||||||
@simd for i in 1:(args.N)
|
@simd for i in 1:(args.N)
|
||||||
segments_x[2 * i - 1] = sol.center[i, frame - 1][1]
|
segments_x[2 * i - 1] = sol.center[i, frame - 1][1]
|
||||||
|
@ -59,12 +68,11 @@ function animate(sol::Solution, args, name_part::String; framerate::Int64=10)
|
||||||
segments_y[2 * i] = sol.center[i, frame][2]
|
segments_y[2 * i] = sol.center[i, frame][2]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if frame == 2
|
||||||
linesegments!(ax, segments_x, segments_y; color=colors)
|
linesegments!(ax, segments_x, segments_y; color=colors)
|
||||||
end
|
end
|
||||||
else
|
|
||||||
println("Started recording!")
|
|
||||||
end
|
end
|
||||||
|
else # First frame
|
||||||
poly!(ax, circles; color=colors)
|
poly!(ax, circles; color=colors)
|
||||||
|
|
||||||
if args.debug
|
if args.debug
|
||||||
|
@ -72,6 +80,12 @@ function animate(sol::Solution, args, name_part::String; framerate::Int64=10)
|
||||||
poly!(ax, skin_circles; color=skin_colors)
|
poly!(ax, skin_circles; color=skin_colors)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
println("Started recording!")
|
||||||
|
end
|
||||||
|
|
||||||
|
notify(circles)
|
||||||
|
notify(colors)
|
||||||
|
|
||||||
ax.title = "t = $(round(sol.t[frame], digits=3))"
|
ax.title = "t = $(round(sol.t[frame], digits=3))"
|
||||||
|
|
||||||
recordframe!(io)
|
recordframe!(io)
|
||||||
|
|
Loading…
Reference in a new issue