Created
July 25, 2022 07:38
-
-
Save tknopp/56d1946e05685b83b573cc91629826b1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Gtk, CairoMakie, Observables | |
canvas = @GtkCanvas() | |
window = GtkWindow(canvas, "Makie", 500, 500) | |
data = Observable(rand(1000, 2)) | |
function drawonto(canvas, figure) | |
@guarded draw(canvas) do _ | |
scene = figure.scene | |
resize!(scene, Gtk.width(canvas), Gtk.height(canvas)) | |
screen = CairoMakie.CairoScreen( | |
scene, | |
Gtk.cairo_surface(canvas), | |
getgc(canvas), | |
nothing | |
) | |
CairoMakie.cairo_draw(screen, scene) | |
end | |
end | |
fig = Figure() | |
ax = Axis(fig[1, 1], backgroundcolor = "black") | |
xs = Observable(LinRange(0, 2pi, 20)) | |
ys = LinRange(0, 3pi, 20) | |
us = @lift([sin(x) * cos(y) for x in $xs, y in ys]) | |
vs = @lift([-cos(x) * sin(y) for x in $xs, y in ys]) | |
strength = @lift(vec(sqrt.($us .^ 2 .+ $vs .^ 2))) | |
zs = Observable(randn(20, 20)) | |
heatmap!(xs, ys, zs) | |
arrows!(xs, ys, us, vs, arrowsize = 10, lengthscale = 0.3, | |
arrowcolor = strength, linecolor = strength) | |
drawonto(canvas, fig) | |
show(canvas); # trigger rendering | |
## | |
@time for i in 1:60 | |
zs[] = randn(20, 20) | |
xs[] = LinRange(i/10, 2pi + i/10, 20) | |
autolimits!(ax) | |
draw(canvas) | |
sleep(0.001) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment