using Pkg Pkg.add("GLMakie") Pkg.add("FFMPEG") using GLMakie using FFMPEG GLMakie.activate!() # -------------------------------------------------- # PARAMETRE # -------------------------------------------------- R = 1.0 frames = 600 break_frame = 300 vx = 0.01 # -------------------------------------------------- # FIGURE # -------------------------------------------------- fig = Figure(size = (1200, 600)) ax1 = Axis( fig[1,1], title = "Orbita + odtrhnutie", aspect = DataAspect(), limits = (-3,3,-3,3) ) ax2 = Axis( fig[1,2], title = "Energia", xlabel = "čas", ylabel = "E" ) # -------------------------------------------------- # KRUH # -------------------------------------------------- θ = range(0, 2π, length=400) lines!(ax1, R .* cos.(θ), R .* sin.(θ), linewidth=3) # -------------------------------------------------- # NÁHODNÉ BODY # -------------------------------------------------- orbit_points = [Point2f(R*cos(2π*rand()), R*sin(2π*rand())) for _ in 1:400] scatter!(ax1, orbit_points, markersize=6, alpha=0.4) # -------------------------------------------------- # POHYBLIVÁ BODKA # -------------------------------------------------- particle_pos = Observable(Point2f(R, 0)) scatter!(ax1, particle_pos, color=:red, markersize=18) # -------------------------------------------------- # ENERGIA (DÔLEŽITÉ: definované PRED record) # -------------------------------------------------- energy_data = Point2f[] energy_points = Observable(Point2f[]) lines!(ax2, energy_points, linewidth=3) # -------------------------------------------------- # FYZIKA # -------------------------------------------------- function particle_energy(x, y, vx, vy) kinetic = 0.5 * (vx^2 + vy^2) r = sqrt(x^2 + y^2) potential = -1 / max(r, 0.1) return kinetic + potential end # -------------------------------------------------- # RECORD DO MP4 # -------------------------------------------------- record(fig, "orbit_detach_energy.gif", 1:frames; framerate=60) do frame if frame < break_frame angle = 0.03 * frame x = R * cos(angle) y = R * sin(angle) particle_pos[] = Point2f(x, y) E = particle_energy(x, y, 0.0, 0.03) else t = frame - break_frame x0 = R * cos(0.03 * break_frame) y0 = R * sin(0.03 * break_frame) x = x0 + vx * t y = y0 particle_pos[] = Point2f(x, y) E = particle_energy(x, y, vx, 0.0) end # update grafu push!(energy_data, Point2f(Float32(frame), Float32(E))) energy_points[] = copy(energy_data) autolimits!(ax2) end println("Hotovo: orbit_detach_energy.mp4") fig