I want to visualize 2D/3D output of some function with different arguments depending on simple keyboard input: a key pressed produces new output for visualization. Here is a simple example:
using Makie
let
npoints = 10
points = Node(Point2f0.(rand(npoints), rand(npoints)))
scene = Scene()
scatter!(scene, points)
display(scene)
lift(scene.events.keyboardbuttons) do key
# ispressed(key, Keyboard.q) && .....?
ispressed(key, Keyboard.down) && (npoints = max(2, npoints-1))
ispressed(key, Keyboard.up) && (npoints += 1)
println(npoints)
points[] = Point2f0.(rand(npoints), rand(npoints))
display(scene)
end
end
It works, but I have these questions:
- Each keystroke produces two events (key pressed and key released). I can’t find in Makie documentation how to distinguish between these two events, in order to have the visualization called only once per keystroke.
- What is an easy way to find symbols for all keyboard keys/buttons other than looking at source code (https://github.com/JuliaPlots/AbstractPlotting.jl/blob/master/src/interaction/iodevices.jl)
- Is this the intended way to implement what I described?
- How to add an option to close visualization window on
q
pressed (commented line in code snippet above)