Skip to content

Instantly share code, notes, and snippets.

@SimonDanisch
Last active March 13, 2018 20:51
Show Gist options
  • Save SimonDanisch/62a2168570029063a5c1b24c08fc84b1 to your computer and use it in GitHub Desktop.
Save SimonDanisch/62a2168570029063a5c1b24c08fc84b1 to your computer and use it in GitHub Desktop.
using GLVisualize, GeometryTypes, Colors
using GLAbstraction
using Reactive
window = glscreen()
timesignal = bounce(linspace(0f0,1f0,360))
description = """
Animated 2D particles in 3D space with glow.
"""
function grid(z, radius, N, t)
rg = linspace(-radius, radius, N)
points = zeros(Point3f0, N^2)
for (i,x)=enumerate(rg)
for (j,y)=enumerate(rg)
points[(i-1)*N+j] = Point3f0(x,y,z)
end
end
points
end
t = const_lift(*, 1000f0, timesignal)
ps1 = const_lift(grid, 0, 6, 10, t)
ps2 = const_lift(grid, 1, 5, 10, t)
ps3 = const_lift(grid, 2, 4, 10, t)
ps = map(vcat, ps1, ps2, ps3)
l1, l2, l3 = map(x->length(value(x)), (ps1, ps2, ps3))
colors = [
fill(RGBA(0.9f0, 0.5f0, 0.2f0, 1f0), l1);
fill(RGBA(0.2f0, 0.2f0, 0.5f0, 1f0), l2);
fill(RGBA(0.5f0, 0.9f0, 0.9f0, 1f0), l3);
]
scales = [
fill(Vec2f0(0.5), l3);
fill(Vec2f0(0.5), l2);
fill(Vec2f0(0.5), l1);
]
sprites = visualize(
(Circle, ps),
glow_color = RGBA(0.8f0, 0.6f0, 0.95f0, 0.8f0),
glow_width = const_lift(/, timesignal, 20f0),
scale = scales, color = colors
)
@async renderloop(window)
import GLVisualize: mm
hover(f, window, hover_robj::Context) = hover(f, window, hover_robj.children[])
function hover(display_func, window, hover_robj::RenderObject)
area = map(window.inputs[:mouseposition]) do mp
SimpleRectangle{Int}(round.(Int, mp + 10)..., 60mm, 30mm)
end
m2id = GLWindow.mouse2id(window)
hovering = map(mh-> (mh.id == hover_robj.id), m2id)
popup = GLWindow.Screen(
window,
hidden = map((!), hovering),
area = area,
stroke = (2f0, RGBA(0f0, 0f0, 0f0, 0.8f0))
)
v0 = Signal(display_func(false, hover_robj, value(m2id).index))
_view(visualize(v0), popup)
foreach(hovering) do ishover
if ishover
push!(v0, display_func(true, hover_robj, value(m2id).index))
yield()
GLAbstraction.center!(popup, first(keys(popup.cameras)); border = 10)
end
return
end
nothing
end
hover(window, sprites) do ishover, robj, idx
if ishover
x, y, z = round.(robj[:position][idx], 2)
c = robj[:color][idx]
xs, ys = robj[:scale][idx]
r, g, b = ((f,x)-> f(x)).((red, green, blue), c)
"""
position: ($x, $y, $z)
color: ($r, $g, $b)
scale: ($xs, $ys)
"""
else
" " # ehehe, glvisualize doesn't like empty strings
end
end
_view(sprites, camera=:perspective)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment