2021-11-20 13:15:22 +00:00
|
|
|
function animate(directory::String, sol::Solution, variables; framerate=0)
|
2021-11-10 14:41:04 +00:00
|
|
|
println("Generating animation...")
|
|
|
|
|
2021-11-15 14:17:47 +00:00
|
|
|
fig = Figure(; resolution=(1080, 1080))
|
2021-11-10 14:41:04 +00:00
|
|
|
ax = Axis(
|
|
|
|
fig[1, 1];
|
2021-11-18 18:42:11 +00:00
|
|
|
limits=(-variables.l, variables.l, -variables.l, variables.l),
|
2021-11-10 14:41:04 +00:00
|
|
|
aspect=AxisAspect(1),
|
|
|
|
xlabel=L"x",
|
|
|
|
ylabel=L"y",
|
|
|
|
)
|
|
|
|
|
2021-11-16 21:26:08 +00:00
|
|
|
color_scheme = ColorSchemes.cyclic_mrybm_35_75_c68_n256_s25
|
|
|
|
|
|
|
|
Colorbar(fig[1, 2]; limits=(0, 2), colormap=color_scheme, label=L"\frac{\varphi}{\pi}")
|
2021-11-10 23:24:07 +00:00
|
|
|
|
2021-11-18 18:42:11 +00:00
|
|
|
animation_path = "$directory/animation.mkv"
|
2021-11-10 14:41:04 +00:00
|
|
|
|
2021-11-20 13:15:22 +00:00
|
|
|
record_framerate = 0
|
|
|
|
if framerate > 0
|
|
|
|
record_framerate = framerate
|
|
|
|
else
|
|
|
|
record_framerate = variables.framerate
|
|
|
|
end
|
|
|
|
|
|
|
|
record(fig, animation_path; framerate=record_framerate) do io
|
2021-11-18 18:42:11 +00:00
|
|
|
circles = Observable(Vector{Circle}(undef, variables.N))
|
|
|
|
colors = Observable(Vector{RGBAf}(undef, variables.N))
|
2021-11-11 00:51:58 +00:00
|
|
|
|
2021-11-18 18:42:11 +00:00
|
|
|
if variables.debug
|
|
|
|
segments_x = Observable(zeros(2 * variables.N))
|
|
|
|
segments_y = Observable(zeros(2 * variables.N))
|
2021-11-11 00:51:58 +00:00
|
|
|
|
2021-11-18 18:42:11 +00:00
|
|
|
interaction_circles = Observable(Vector{Circle}(undef, variables.N))
|
|
|
|
skin_circles = Observable(Vector{Circle}(undef, variables.N))
|
2021-11-11 00:51:58 +00:00
|
|
|
|
2021-11-18 18:42:11 +00:00
|
|
|
interaction_colors = Observable(Vector{RGBAf}(undef, variables.N))
|
|
|
|
skin_colors = Observable(Vector{RGBAf}(undef, variables.N))
|
2021-11-11 00:51:58 +00:00
|
|
|
end
|
2021-11-10 14:41:04 +00:00
|
|
|
|
2021-11-20 13:15:22 +00:00
|
|
|
π2 = 2 * π
|
|
|
|
particle_radius = variables.particle_diameter / 2
|
|
|
|
|
2021-11-18 18:42:11 +00:00
|
|
|
@showprogress 0.6 for frame in 1:(variables.n_frames)
|
|
|
|
@simd for i in 1:(variables.N)
|
2021-11-20 13:15:22 +00:00
|
|
|
circles[][i] = Circle(Point2(sol.center[i, frame]), particle_radius)
|
2021-11-15 14:17:47 +00:00
|
|
|
|
2021-11-20 13:15:22 +00:00
|
|
|
color = get(color_scheme, rem2pi(sol.φ[i, frame], RoundDown) / π2)
|
2021-11-15 14:17:47 +00:00
|
|
|
colors[][i] = RGBAf(color)
|
2021-11-11 00:51:58 +00:00
|
|
|
|
2021-11-18 18:42:11 +00:00
|
|
|
if variables.debug
|
2021-11-15 21:48:31 +00:00
|
|
|
interaction_circles[][i] = Circle(
|
2021-11-18 18:42:11 +00:00
|
|
|
Point2(sol.center[i, frame]), variables.interaction_r
|
|
|
|
)
|
|
|
|
skin_circles[][i] = Circle(
|
|
|
|
Point2(sol.center[i, frame]), variables.skin_r
|
2021-11-15 14:17:47 +00:00
|
|
|
)
|
2021-11-11 00:51:58 +00:00
|
|
|
|
2021-11-20 13:15:22 +00:00
|
|
|
interaction_colors[][i] = RGBAf(color, 0.08)
|
|
|
|
skin_colors[][i] = RGBAf(color, 0.04)
|
2021-11-11 00:51:58 +00:00
|
|
|
end
|
2021-11-10 23:45:41 +00:00
|
|
|
end
|
|
|
|
|
2021-11-10 23:24:07 +00:00
|
|
|
if frame > 1
|
2021-11-18 18:42:11 +00:00
|
|
|
if variables.debug
|
|
|
|
@simd for i in 1:(variables.N)
|
2021-11-20 13:15:22 +00:00
|
|
|
first_ind = 2 * i - 1
|
|
|
|
second_ind = 2 * i
|
|
|
|
frame_min_1 = frame - 1
|
|
|
|
|
|
|
|
segments_x[][first_ind] = sol.center[i, frame_min_1][1]
|
|
|
|
segments_x[][second_ind] = sol.center[i, frame][1]
|
2021-11-10 14:41:04 +00:00
|
|
|
|
2021-11-20 13:15:22 +00:00
|
|
|
segments_y[][first_ind] = sol.center[i, frame_min_1][2]
|
|
|
|
segments_y[][second_ind] = sol.center[i, frame][2]
|
2021-11-11 00:51:58 +00:00
|
|
|
end
|
2021-11-10 14:41:04 +00:00
|
|
|
|
2021-11-15 14:17:47 +00:00
|
|
|
if frame == 2
|
|
|
|
linesegments!(ax, segments_x, segments_y; color=colors)
|
|
|
|
end
|
2021-11-11 00:51:58 +00:00
|
|
|
end
|
2021-11-15 14:17:47 +00:00
|
|
|
else # First frame
|
|
|
|
poly!(ax, circles; color=colors)
|
2021-11-10 14:41:04 +00:00
|
|
|
|
2021-11-18 18:42:11 +00:00
|
|
|
if variables.debug
|
2021-11-15 14:17:47 +00:00
|
|
|
poly!(ax, interaction_circles; color=interaction_colors)
|
|
|
|
poly!(ax, skin_circles; color=skin_colors)
|
|
|
|
end
|
2021-11-11 00:51:58 +00:00
|
|
|
|
2021-11-18 18:42:11 +00:00
|
|
|
println("Recording started!")
|
2021-11-11 00:51:58 +00:00
|
|
|
end
|
2021-11-10 23:24:07 +00:00
|
|
|
|
2021-11-15 14:17:47 +00:00
|
|
|
notify(circles)
|
|
|
|
notify(colors)
|
|
|
|
|
2021-11-18 18:42:11 +00:00
|
|
|
if variables.debug
|
2021-11-15 21:48:31 +00:00
|
|
|
notify(interaction_circles)
|
|
|
|
notify(interaction_colors)
|
|
|
|
|
|
|
|
notify(skin_circles)
|
|
|
|
notify(skin_colors)
|
|
|
|
|
|
|
|
notify(segments_x)
|
|
|
|
notify(segments_y)
|
|
|
|
end
|
|
|
|
|
2021-11-10 23:24:07 +00:00
|
|
|
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
|