Skip to content

Instantly share code, notes, and snippets.

@jkrumbiegel
Created January 27, 2024 17:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jkrumbiegel/d2e6a754c17d0023b8ef1958fb11f0ed to your computer and use it in GitHub Desktop.
Save jkrumbiegel/d2e6a754c17d0023b8ef1958fb11f0ed to your computer and use it in GitHub Desktop.
Makie slide show
using GLMakie
slides = [
(gl) -> begin
for i in 1:2, j in 1:2
lines(gl[i, j], cumsum(randn(1000)))
end
return (; title = "A slide with two Axis")
end,
(gl) -> begin
for i in 1:2
lines(gl[1, i], cumsum(randn(1000)), cumsum(randn(1000)), cumsum(randn(1000)), axis = (; type = Axis3))
end
return (; title = "Another slide with four Axis3")
end,
(gl) -> begin
Axis(gl[1, 1])
sg = SliderGrid(gl[1, 2],
(label = "Amplitude", range = 0:0.1:10, startvalue = 5),
(label = "Frequency", range = 0:0.5:50, format = "{:.1f}Hz", startvalue = 10),
(label = "Phase", range = 0:0.01:2pi,
format = x -> string(round(x/pi, digits = 2), "π"));
tellheight = false,
width = 300,
)
return (; title = "A third slide with Axis and Sliders")
end,
]
function slide_figure(size, slidefunc, i, prevfunc, nextfunc)
f = Figure(size = size)
gl = GridLayout(f[2, 1], alignmode = Outside(15))
(; title) = slidefunc(gl)
Label(f[1, 1], title, fontsize = 24, font = :bold, tellwidth = false)
buttongl = GridLayout(f[3, 1], tellwidth = false)
prevbutton = Button(buttongl[1, 1], label = "Previous Slide")
Label(buttongl[1, 2], "Slide $i")
nextbutton = Button(buttongl[1, 3], label = "Next Slide")
on(_ -> prevfunc(), prevbutton.clicks)
on(_ -> nextfunc(), nextbutton.clicks)
return f
end
function start_slideshow(slides)
screen = GLMakie.Screen(size = (600, 450))
n_slides = length(slides)
current_slide = 1
function prevfunc end
function nextfunc end
function display_current_slide!(screen)
# keep size if there's an existing figure
sz = screen.root_scene === nothing ? (600, 450) : size(screen.root_scene)
empty!(screen)
fig = slide_figure(sz, slides[current_slide], current_slide, prevfunc, nextfunc)
display(screen, fig)
end
function nextfunc()
if current_slide < n_slides
current_slide += 1
display_current_slide!(screen)
end
end
function prevfunc()
if current_slide > 1
current_slide -= 1
display_current_slide!(screen)
end
end
display_current_slide!(screen)
return
end
start_slideshow(slides)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment