Hello,
I am new in Julia and I would appreciate your help. I want to record a video. It seems frames are accumulated during recording the frames:
using GLMakie
using MAT
file = matopen(“//home//arostami//Desktop//3D//sample_vrtx_1.mat”)
vrtx=read(file, “vrtx”)
scene=contour(vrtx[1,:,:,:],levels=[-7,7],colormap=:balance,alpha=0.2,colorrange=[-7,7])
record(scene, “//home//arostami//Desktop//3D//kir.mp4”) do io
for i in 1:100
dat=vrtx[i,:,:,:]
scene=contour!(dat,levels=[-7,7],colormap=:balance,alpha=0.2,colorrange=[-7,7])
recordframe!(io)
end
end
I don’t know where the issue comes from. Thank you for your help in advance!
Hi!
Foremost, I will recommend you to read this PSA on quoting code.
Second, what version of Julia and GLMakie are you running? That code looks outdated. You can look at the documentation for animations. You probably want something base on Observable
.
Here is an example of how to use them:
julia> using GLMakie
julia> range = -2π:0.1:2π
-6.283185307179586:0.1:6.216814692820414
julia> mul = Observable(1.0)
Observable{Float64} with 0 listeners. Value:
1.0
julia> xy = lift(mul) do m
[cos(m*x)*cos(m*y) for x=range, y=range]
end
Observable{Matrix{Float64}} with 0 listeners. Value:
[1.0 0.9950041652780258 … 0.9861923022788637 0.9977982791785807; 0.9950041652780258 0.9900332889206209 … 0.9812654485325952 0.9928134438899342; … ; 0.9861923022788637 0.9812654485325952 … 0.9725752570740857 0.9840209821530128; 0.9977982791785807 0.9928134438899342 … 0.9840209821530128 0.9956014059317367]
julia> fig, ax, plot = contour(xy)
julia> framerate = 30
30
julia> multplier_iterator = LinRange(1.0, 10.0, 60)
60-element LinRange{Float64, Int64}:
1.0,1.15254,1.30508,1.45763,1.61017,1.76271,1.91525,2.0678,2.22034,2.37288,…,8.62712,8.77966,8.9322,9.08475,9.23729,9.38983,9.54237,9.69492,9.84746,10.0
julia> record(fig, "cosx_cosy.mp4", multplier_iterator; framerate=framerate) do m
mul[] = m # update multiplier and so the figure
end
"cosx_cosy.mp4"
3 Likes
Re-reading your question, maybe this changes fix your code?
using GLMakie
using MAT
file = matopen("/home/arostami/Deskto/3D/sample_vrtx_1.mat")
vrtx = read(file, "vrtx")
idx = Observable(1) # the index of the layer
#every time you do `idx[] = j`, for a `j`, then `data` will change to the corresponding layer
data = lift(idx) do i
vrtx[i, :, :, :]
end
fig, ax, plot = contour( # just plot
data,
levels = [-7, 7],
colormap = :balance,
alpha = 0.2,
colorrange = [-7, 7],
)
indexes = 1:1000
record(fig, "/home/arostami/Desktop/3D/kir.mp4", indexes) do i
idx[] = i # you just need to update the layer number, and the plot will be updated
end
1 Like
Thank you so much @suavesito . It is working now!
1 Like