using GLMakie, ColorSchemes using LaTeXStrings: @L_str function animate(dir::String; framerate=0) println("Generating animation...") fig = Figure(; resolution=(1080, 1080)) ax = Axis( fig[1, 1]; limits=(-variables.l, variables.l, -variables.l, variables.l), aspect=AxisAspect(1), xlabel=L"x", ylabel=L"y", ) 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}") animation_path = "$directory/animation.mkv" record_framerate = 0 if framerate > 0 record_framerate = framerate else record_framerate = variables.framerate end record(fig, animation_path; framerate=record_framerate) do io circles = Observable(Vector{Circle}(undef, variables.N)) colors = Observable(Vector{RGBAf}(undef, variables.N)) if variables.debug segments_x = Observable(zeros(2 * variables.N)) segments_y = Observable(zeros(2 * variables.N)) interaction_circles = Observable(Vector{Circle}(undef, variables.N)) skin_circles = Observable(Vector{Circle}(undef, variables.N)) interaction_colors = Observable(Vector{RGBAf}(undef, variables.N)) skin_colors = Observable(Vector{RGBAf}(undef, variables.N)) end π2 = 2 * π particle_radius = variables.particle_diameter / 2 @showprogress 0.6 for frame in 1:(variables.n_snapshots) @simd for i in 1:(variables.N) circles[][i] = Circle(Point2(sol.center[i, frame]), particle_radius) color = get(color_scheme, rem2pi(sol.φ[i, frame], RoundDown) / π2) colors[][i] = RGBAf(color) if variables.debug interaction_circles[][i] = Circle( Point2(sol.center[i, frame]), variables.interaction_r ) skin_circles[][i] = Circle( Point2(sol.center[i, frame]), variables.skin_r ) interaction_colors[][i] = RGBAf(color, 0.08) skin_colors[][i] = RGBAf(color, 0.04) end end if frame > 1 if variables.debug @simd for i in 1:(variables.N) 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] segments_y[][first_ind] = sol.center[i, frame_min_1][2] segments_y[][second_ind] = sol.center[i, frame][2] end if frame == 2 linesegments!(ax, segments_x, segments_y; color=colors) end end else # First frame poly!(ax, circles; color=colors) if variables.debug poly!(ax, interaction_circles; color=interaction_colors) poly!(ax, skin_circles; color=skin_colors) end println("Recording started!") end notify(circles) notify(colors) if variables.debug notify(interaction_circles) notify(interaction_colors) notify(skin_circles) notify(skin_colors) notify(segments_x) notify(segments_y) end ax.title = "t = $(round(sol.t[frame], digits=3))" recordframe!(io) end end println("Animation done and saved to $animation_path.") return nothing end