Created
March 14, 2020 06:43
-
-
Save jkrumbiegel/626a8ff2d711232ada0d50c2bdc4998c to your computer and use it in GitHub Desktop.
Makie manual screen update
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 Makie | |
using GLFW; GLFW.WindowHint(GLFW.FLOATING, 1) | |
using MakieLayout | |
using AbstractPlotting | |
using AbstractPlotting: px | |
begin | |
scene, layout = layoutscene() | |
begin | |
t = Node(0.0) | |
ax = layout[1, 1] = LAxis(scene, autolimitsaspect = 1) | |
n = 100 | |
points = Node(rand(Point2f0, n)) | |
es = map(1:n) do i | |
x1 = rand(1:n) | |
x2 = rand(1:n) | |
while x1 == x2 | |
x2 = rand(1:n) | |
end | |
x1, x2 | |
end | |
on(t) do t | |
dt = 1/60 | |
ps = points[] | |
magns = [sqrt(sum(p .^ 2)) for p in ps] | |
dirs = ps ./ magns | |
diffs = zeros(Point2f0, n) | |
for i in 1:n | |
for j in i+1:n | |
d = ps[j] .- ps[i] | |
magd = sqrt(sum(d .^ 2)) | |
diffs[i] = diffs[i] .- d / magd | |
diffs[j] = diffs[j] .+ d / magd | |
end | |
end | |
for e in es | |
i, j = e | |
d = ps[j] .- ps[i] | |
magd = sqrt(sum(d .^ 2)) | |
diffs[i] = diffs[i] .+ d | |
diffs[j] = diffs[j] .- d | |
end | |
ps .+= diffs .* dt | |
ps .-= ps .* dt | |
points[] = ps | |
end | |
scat = scatter!(ax, points, markersize = 20px) | |
onpick(scat) do i | |
println(i) | |
end | |
linsegs = lift(points, es) do ps, e | |
arr = Vector{Point2f0}(undef, 2 * length(es)) | |
for (i, ee) in enumerate(e) | |
arr[i * 2 - 1] = ps[ee[1]] | |
arr[i * 2] = ps[ee[2]] | |
end | |
arr | |
end | |
linesegments!(ax, linsegs) | |
screen = display(scene) | |
nothing | |
end | |
f = 1/60 | |
GLMakie.FRAMERATE[] = f | |
target = time() | |
while isopen(scene) | |
global target += + f | |
t[] = t[] + f | |
sleep(max(0.0, target - time())) | |
end | |
end | |
using GLMakie | |
GLMakie.destroy!(screen) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment