Skip to content

Commit

Permalink
Support recording of movies
Browse files Browse the repository at this point in the history
  • Loading branch information
kbarros committed Oct 27, 2023
1 parent 0dfc4ce commit 059c12d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
19 changes: 14 additions & 5 deletions examples/extra/heisenberg_animation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,30 @@ latvecs = lattice_vectors(1, 1, 10, 90, 90, 90)
cryst = Crystal(latvecs, [[0,0,0]])

# Simple Heisenberg model
sys = System(cryst, (10,10,1), [SpinInfo(1, S=1, g=2)], :dipole)
sys = System(cryst, (10,10,1), [SpinInfo(1, S=1, g=2)], :dipole; seed=1)
J = -1.0
set_exchange!(sys, J, Bond(1, 1, (1, 0, 0)))
randomize_spins!(sys)

fig = plot_spins(sys; colorfn=i->sys.dipoles[i][3], colorrange=(-1, 1), dims=2)

Δt = 0.1/abs(J)
langevin = Langevin(Δt; kT=0, λ=0.1)
langevin = Langevin(Δt; kT=0, λ=0.05)

fps = 60
# View an animation in real time
for _ in 1:500
for i in 1:5
for _ in 1:5
step!(sys, langevin)
end
notify(fig)
sleep(1/60)
end

# Save an animation to file
randomize_spins!(sys)
record(fig, "animation.mp4", 1:500; framerate=30) do _
for _ in 1:5
step!(sys, langevin)
end
notify(fig)
sleep(1/fps)
end
2 changes: 2 additions & 0 deletions ext/PlottingExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ Base.showable(mime::MIME, fig::NotifiableFigure) = showable(mime, fig.figure)
Base.show(io::IO, ::MIME"text/plain", fig::NotifiableFigure) = print(io, "(Notifiable) " * repr(fig.figure))
Base.show(io::IO, m::MIME, fig::NotifiableFigure) = show(io, m, fig.figure)
Base.notify(fig::NotifiableFigure) = notify(fig.notifier)
Makie.record(func, nf::NotifiableFigure, path, iter; kwargs...) = Makie.record(func, nf.figure, path, iter; kwargs...)

"""
plot_spins(sys::System; arrowscale=1.0, color=:red, colorfn=nothing,
Expand Down Expand Up @@ -349,6 +350,7 @@ function plot_spins!(ax, sys::System; notifier=Makie.Observable(nothing), arrows
end
# Trigger Makie redraw
notify.((vecs, pts, pts_shifted, arrowcolor))
# isnothing(color) || notify(arrowcolor)
end

# Draw arrows
Expand Down

0 comments on commit 059c12d

Please sign in to comment.