Created
October 8, 2018 13:56
-
-
Save SimonDanisch/ce1bd38cc8ba678cfa802129b04e75c3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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, Interact, WebIO, Colors | |
widgets = ( | |
slider = widget(range(0.0, stop = 2pi, length = 200), label = "size"), # Slider | |
ranges = rangepicker( | |
range(0.1, stop = 3.0, length = 50) | |
), | |
toggle = widget(false), # Checkbox | |
text = widget("text"), # Textbox | |
# spinbox = widget(1.1), # Spinbox | |
playstop = widget([:play, :stop]), # Toggle Buttons | |
val = widget(Dict("π" => float(π), "τ" => 2π)), | |
color = widget(colorant"red"), # Color picker | |
) | |
signals = map(v-> observe(v), widgets) | |
vbox(widgets...) | |
using Makie | |
scene = Scene(resolution = (800, 800)) | |
mesh!(scene, | |
Makie.loadasset("cat.obj"), | |
color = signals.color, show_axis = false | |
) | |
kitty = scene[end] | |
# on(signals[1]) do val | |
# scale!(kitty, val, 1.0, 1.0) | |
# end | |
last_pos = 0.0 | |
on(signals.slider) do rotation | |
global last_pos | |
rotate_cam!(scene, rotation - last_pos, 0.0, 0.0) | |
last_pos = rotation | |
end | |
wcat = wireframe!( | |
scene, kitty[1], | |
visible = signals.toggle, | |
color = (:black, 0.4), show_axis = false | |
)[end] | |
f(t, v, s) = (sin(v + t) * s, cos(v + t) * s, (cos(v + t) + sin(v)) * s) | |
t = Makie.Node(Base.time()) # create a life signal | |
limits = FRect3D(Vec3f0(-1.5, -1.5, -3), Vec3f0(3, 3, 6)) | |
inner_circle = lift((t, r)-> f.(t, range(0, stop = 2pi, length = 50), first(r)), t, signals.ranges) | |
outer_circle = lift((t, r)-> f.(t, range(0, stop = 2pi, length = 50), last(r)), t, signals.ranges) | |
p1 = meshscatter!(scene, inner_circle, markersize = 0.05)[end] | |
p2 = meshscatter!(scene, outer_circle, markersize = 0.05)[end] | |
linepos = lift(p1[1], p2[1]) do pos1, pos2 | |
map((a, b)-> (a, b), pos1, pos2) | |
end | |
linesegments!(scene, linepos, linestyle = :dot, limits = limits) | |
on(signals[1]) do s | |
scale!(wcat, s, s, s) | |
end | |
text!( | |
campixel(scene), signals.text, | |
textsize = 50, | |
position = lift(pixelarea(scene)) do a | |
w, h = widths(a) | |
Point2f0(20, h - 20) | |
end, align = (:left, :top), raw = true | |
) | |
scene | |
display(AbstractPlotting.PlotDisplay(), scene) | |
@async while isopen(scene) | |
if signals.playstop[] == :play | |
t[] = time() | |
end | |
sleep(1/30) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment