2021-11-10 14:41:04 +00:00
|
|
|
function animate(sol::Solution, args, name_part::String; framerate::Int64=10)
|
|
|
|
println("Generating animation...")
|
|
|
|
|
2021-11-10 23:24:07 +00:00
|
|
|
set_theme!(theme_black())
|
|
|
|
|
2021-11-10 14:41:04 +00:00
|
|
|
fig = Figure()
|
|
|
|
ax = Axis(
|
|
|
|
fig[1, 1];
|
|
|
|
limits=(-args.l, args.l, -args.l, args.l),
|
|
|
|
aspect=AxisAspect(1),
|
|
|
|
xlabel=L"x",
|
|
|
|
ylabel=L"y",
|
|
|
|
)
|
|
|
|
|
2021-11-10 23:24:07 +00:00
|
|
|
Colorbar(fig[1, 2]; limits=(0, 2), colormap=ColorSchemes.rainbow, label=L"\frac{\varphi}{\pi}")
|
|
|
|
|
2021-11-10 14:41:04 +00:00
|
|
|
animation_path = "exports/$name_part.mkv"
|
|
|
|
|
|
|
|
record(fig, animation_path; framerate=framerate) do io
|
|
|
|
segments_x = zeros(2 * args.N)
|
|
|
|
segments_y = zeros(2 * args.N)
|
|
|
|
|
2021-11-10 23:24:07 +00:00
|
|
|
circles = Vector{Circle}(undef, args.N)
|
|
|
|
interaction_circles = Vector{Circle}(undef, args.N)
|
|
|
|
skin_circles = Vector{Circle}(undef, args.N)
|
2021-11-10 14:41:04 +00:00
|
|
|
|
2021-11-10 23:24:07 +00:00
|
|
|
colors = Vector{RGBAf}(undef, args.N)
|
|
|
|
interaction_colors = Vector{RGBAf}(undef, args.N)
|
|
|
|
skin_colors = Vector{RGBAf}(undef, args.N)
|
2021-11-10 14:41:04 +00:00
|
|
|
|
2021-11-10 23:24:07 +00:00
|
|
|
@showprogress 0.5 for frame in 1:args.n_frames
|
|
|
|
if frame > 1
|
2021-11-10 14:41:04 +00:00
|
|
|
empty!(ax)
|
|
|
|
|
2021-11-10 23:24:07 +00:00
|
|
|
@simd for i in 1:(args.N)
|
|
|
|
segments_x[2 * i - 1] = sol.center[i, frame - 1][1]
|
|
|
|
segments_x[2 * i] = sol.center[i, frame][1]
|
2021-11-10 14:41:04 +00:00
|
|
|
|
2021-11-10 23:24:07 +00:00
|
|
|
segments_y[2 * i - 1] = sol.center[i, frame - 1][2]
|
|
|
|
segments_y[2 * i] = sol.center[i, frame][2]
|
2021-11-10 14:41:04 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
linesegments!(ax, segments_x, segments_y; color=1:(args.N))
|
|
|
|
else
|
|
|
|
println("Started recording!")
|
|
|
|
end
|
|
|
|
|
2021-11-10 23:24:07 +00:00
|
|
|
@simd for i in 1:args.N
|
|
|
|
circles[i] = Circle(Point2(sol.center[i, frame]), args.particle_diameter / 2)
|
|
|
|
interaction_circles[i] = Circle(Point2(sol.center[i, frame]), args.interaction_r)
|
|
|
|
skin_circles[i] = Circle(Point2(sol.center[i, frame]), args.skin_r)
|
2021-11-10 14:41:04 +00:00
|
|
|
|
2021-11-10 23:24:07 +00:00
|
|
|
color = get(ColorSchemes.rainbow, rem2pi(sol.φ[i, frame] / (2 * π), RoundDown))
|
2021-11-10 14:41:04 +00:00
|
|
|
|
2021-11-10 23:24:07 +00:00
|
|
|
colors[i] = RGBAf(color)
|
|
|
|
interaction_colors[i] = RGBAf(color, 0.2)
|
|
|
|
skin_colors[i] = RGBAf(color, 0.05)
|
2021-11-10 14:41:04 +00:00
|
|
|
end
|
|
|
|
|
2021-11-10 23:24:07 +00:00
|
|
|
poly!(ax, circles; color=colors)
|
|
|
|
poly!(ax, interaction_circles; color=interaction_colors)
|
|
|
|
poly!(ax, skin_circles; color=skin_colors)
|
|
|
|
|
|
|
|
ax.title = "t = $(round(sol.t[frame], digits=3))"
|
2021-11-10 14:41:04 +00:00
|
|
|
|
|
|
|
recordframe!(io)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
println("Animation done and saved to $animation_path.")
|
|
|
|
|
|
|
|
return nothing
|
|
|
|
end
|