using Pkg for p in ["GLMakie", "FFMPEG"] try Base.require(Symbol(p)) catch Pkg.add(p) end end using GLMakie using FFMPEG ############################################################ # SETTINGS ############################################################ const FPS = 60 const DURATION = 20 const FRAMES = FPS * DURATION const OUTFILE = "4_8curves_realtime_overlay.gif" const G = 1.0 const K = 1.0 ############################################################ # MAIN ############################################################ function main() fig = Figure(resolution=(1900, 980), fontsize=18) ######################################################## # SINGLE BIG GRAPH ONLY ######################################################## ax = Axis( fig[1,1], title = "Realtime Overlay: 8 Curves", xlabel = "time", ylabel = "value" ) ######################################################## # OBSERVABLES ######################################################## t = Observable(Float64[]) # gears eBig = Observable(Float64[]) eSmall = Observable(Float64[]) frBig = Observable(Float64[]) frSmall = Observable(Float64[]) # forces F1 = Observable(Float64[]) F2 = Observable(Float64[]) # radii/distances rg = Observable(Float64[]) rc = Observable(Float64[]) ######################################################## # 8 CURVES ######################################################## lines!(ax, t, eBig, linewidth=4, label="Large Gear Energy" ) lines!(ax, t, eSmall, linewidth=4, label="Small Gear Energy" ) lines!(ax, t, frBig, linewidth=3, linestyle=:dash, label="Large Gear Friction" ) lines!(ax, t, frSmall, linewidth=3, linestyle=:dot, label="Small Gear Friction" ) lines!(ax, t, F1, linewidth=3, label="F1 Gravity" ) lines!(ax, t, F2, linewidth=3, label="F2 Coulomb" ) lines!(ax, t, rg, linewidth=2, linestyle=:dashdot, label="rg" ) lines!(ax, t, rc, linewidth=2, linestyle=:dashdotdot, label="rc" ) axislegend(ax, position=:rt) display(fig) ######################################################## # RECORD ######################################################## println("Rendering MP4...") record(fig, OUTFILE, 1:FRAMES; framerate=FPS) do i tt = i / FPS #################################################### # GEARS #################################################### ω_big = exp(-0.02 * tt) ω_small = 2.45 * exp(-0.03 * tt) I_big = 2.5^2 I_small = 1.25^2 E_big = 2 * 0.5 * I_big * ω_big^2 E_small = 2 * 0.5 * I_small * ω_small^2 FR_big = 64.0*abs(sin(tt * 1.4)) * 0.10 FR_small = 64.0*abs(cos(tt * 2.2)) * 0.08 #################################################### # YOUR rg rc MODEL #################################################### rgv = 2.5 - 3.5*(1 - exp(-0.25*tt)) rcv = 2.5 + 3.5*(1 - exp(-0.25*tt)) rgv = max(rgv, 0.45) rcv = max(rcv, 0.45) #################################################### # FORCES #################################################### FG = G / rgv^2 FC = K / rcv^2 #################################################### # PUSH DATA #################################################### push!(t[], tt) push!(eBig[], E_big) push!(eSmall[], E_small) push!(frBig[], FR_big) push!(frSmall[], FR_small) push!(F1[], FG) push!(F2[], FC) push!(rg[], rgv) push!(rc[], rcv) #################################################### # REFRESH #################################################### notify(t) notify(eBig) notify(eSmall) notify(frBig) notify(frSmall) notify(F1) notify(F2) notify(rg) notify(rc) autolimits!(ax) end println("Saved => $OUTFILE") println("Press ENTER to close") readline() end main()