Skip to content

Instantly share code, notes, and snippets.

@SimonDanisch
Created August 26, 2016 15:52
Show Gist options
  • Save SimonDanisch/6614e57cf08743bb740f299aee457efa to your computer and use it in GitHub Desktop.
Save SimonDanisch/6614e57cf08743bb740f299aee457efa to your computer and use it in GitHub Desktop.
# Install development version of Plots and GLPlot
# Pkg.add("Plots"); Pkg.clone("GLPlot")
# for p in ["GLVisualize", "GeometryTypes", "GLPlot", "GLAbstraction", "GLWindow", "FixedSizeArrays"]
# Pkg.checkout(p)
# end
# checkout https://github.com/tbreloff/Plots.jl/pull/374
using Plots, GLVisualize, GLPlot;GLPlot.init();glvisualize()
using GLVisualize, GeometryTypes, Colors
using Reactive, GLAbstraction
# Prepare a few hover visualizations
# These could be complete plots or whatever glvisualize can display.
timesignal = loop(linspace(0f0,1f0,360))
const N = 128
const range = linspace(-5f0, 5f0, N)
function contour_inner(i, x, y)
Intensity{1,Float32}(sin(1.3*x*i)*cos(0.9*y)+cos(.8*x)*sin(1.9*y)+cos(y*.2*x))
end
const data = zeros(Intensity{1,Float32}, N, N)
function contourdata(t)
for i=1:size(data, 1)
@simd for j=1:size(data, 2)
@inbounds data[i,j] = contour_inner(t, range[i], range[j])
end
end
data
end
r1 = visualize(map(contourdata, timesignal))
large_sphere = HyperSphere(Point3f0(0), 1f0)
rotation_angle = const_lift(*, timesignal, 2f0*pi)
rotation = map(rotationmatrix_z, rotation_angle)
positions = decompose(Point3f0, large_sphere)
indices = rand(Base.range(Cuint(0), Cuint(length(positions))), 1000)
color = map(large_sphere->RGBA{Float32}(large_sphere, 0.9f0), colormap("Blues", length(positions)))
color2 = map(large_sphere->RGBA{Float32}(large_sphere, 1f0), colormap("Blues", length(positions)))
lines = visualize(
positions, :linesegment, thickness=0.5f0,
color=color, indices=indices, model=rotation
)
spheres = visualize(
(Sphere{Float32}(Point3f0(0.0), 1f0), positions),
color=color2, scale=Vec3f0(0.05), model=rotation
)
r2 = Context(lines, spheres)
function mgrid(dim1, dim2)
X = [i for i in dim1, j in dim2]
Y = [j for i in dim1, j in dim2]
return X,Y
end
rotation_angle = const_lift(*, timesignal, 2f0*pi)
rotation = map(rotationmatrix_z, rotation_angle)
dphi, dtheta = pi/200.0f0, pi/200.0f0
phi,theta = mgrid(0f0:dphi:(pi+dphi*1.5f0), 0f0:dtheta:(2f0*pi+dtheta*1.5f0));
m0 = 4f0; m1 = 3f0; m2 = 2f0; m3 = 3f0; m4 = 6f0; m5 = 2f0; m6 = 6f0; m7 = 4f0;
a = sin(m0*phi).^m1;
b = cos(m2*phi).^m3;
c = sin(m4*theta).^m5;
d = cos(m6*theta).^m7;
r = a + b + c + d;
x = r.*sin(phi).*cos(theta);
y = r.*cos(phi);
z = r.*sin(phi).*sin(theta);
r3 = visualize((x,y,z), :surface, model=rotation)
# combine hover items
h = [loadasset("cat.obj"), loadasset("doge.png"), "ahahaha", r1, r2, r3]
# Plot it with Plots.jl
scatter(rand(length(h)), hover=h)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment