Last active
February 17, 2017 16:27
-
-
Save alblaz/381326d5f400d3259c422fec086c1db0 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 GLVisualize, Colors, GeometryTypes, Reactive, GLAbstraction, GLWindow | |
import GLVisualize: mm | |
gc() | |
window = glscreen() | |
@async GLWindow.waiting_renderloop(window) | |
#Divide the screen area in two parts: editarea and plotarea | |
editarea, plotarea = x_partition_abs(window.area, 70mm) | |
editscreen = Screen(window, area = editarea,color = RGBA{Float32}(1,1,1,1),) | |
plot_screen = Screen(window, area = plotarea) | |
GLVisualize.add_screen(plot_screen) | |
################################################################################ | |
# EDIT AREA (LEFT SIDE OF THE FIGURE) | |
#initialize widgets (sliders, buttons etc.) | |
iconsize = 6mm | |
m_value_v, m_value_s = GLVisualize.labeled_slider(-4000.0:1.0:4000.0, editscreen; text_color = RGBA(0.1f0, 0.1f0, 0.1f0, 1f0)) | |
# load the icons for play and pause buttons | |
paths = ["play.png", "pause.png"] | |
imgs = map(paths) do path | |
img = convert(Matrix{RGBA{N0f8}}, loadasset(path)) | |
img, flipdim(img, 2) | |
end | |
#define togggle button play/pause | |
buttons = Dict{Symbol, Any}( | |
:play => GLVisualize.toggle_button(imgs[1][1], imgs[2][1], editscreen), | |
) | |
play_button, play_stop_signal = buttons[:play] | |
play_s = map(!, play_stop_signal) | |
#slider instantiation. The slider signal is associated with the play button signal | |
slider_w, slider_s = GLVisualize.labeled_slider(0.:1.:120., editscreen; play_signal = play_s, text_color = RGBA(0.1f0, 0.1f0, 0.1f0, 1f0)) | |
play_v, play_s = buttons[:play] | |
const preserved_signals = Set([]) | |
push!(preserved_signals, play_s, m_value_s,slider_s) | |
controls = Pair[ | |
:m => m_value_v, | |
:timesignal => slider_w, | |
:play => play_v, | |
] | |
_view(visualize( | |
controls, | |
text_scale = 4mm, | |
text_color = RGBA(0.1f0, 0.1f0, 0.1f0, 1f0), | |
width = 5iconsize | |
), editscreen, camera = :fixed_pixel) | |
################################################################################ | |
# PLOT AREA: RIGHT SIDE OF THE FIGURE | |
#initial data for plot 1 | |
n1 = 50 | |
xls1 = linspace( 0.,1,n1) | |
yls1 = zeros(xls1) | |
#define the basic structure of the plot using Plots.jl | |
using Plots ; glvisualize(size = widths(plot_screen)) | |
p1 = plot([xls1,xls1,xls1],[yls1,yls1,yls1], | |
color=[:red :green :blue],lw= 2, | |
label = "", ylim = (-5000,5000), xlabel = "x", ylabel = "y"); | |
#initial data for plot 2 | |
n2 = 1000 | |
xls2 = linspace(0.,1,n2) | |
yls2 = zeros(xls2) | |
p2 = plot([xls2,xls2,xls2,xls2,xls2],[yls2,yls2,yls2,yls2,yls2], | |
color=[:red :green :blue :cyan :purple], lw= 2, | |
label = "", ylim = (-10000,10000), xlabel = "w", ylabel = "z"); | |
pl = plot(p1,p2,layout = (2,1)) | |
gui() | |
#defining variables containing the series relative to subplot 1 and subplot 2 | |
subplot1_series = pl.o.children[1].renderlist[1][3:end] | |
subplot2_series = pl.o.children[2].renderlist[1][3:end] | |
#definition of the function that are going to be displayed in the | |
f1(x,coeff) = rand(length(x))*coeff | |
f2(x,t,i) = sin(t*x + i*10./(x+15.))*1000.*i | |
function update_myplot!(x,y,series) | |
new_vals = map(Point2f0, zip(x, y)) | |
set_arg!(series, :vertex, new_vals) | |
nothing | |
end | |
t = slider_s | |
m = const_lift((x,y)->y, t, m_value_s); | |
# update y values for both subplots according to f1 and f2 | |
y1 = [const_lift(f1,xls1,m) for i =1:length(subplot1_series)]; | |
y2 = [const_lift(f2,xls2,t,i) for i =1:length(subplot2_series)]; | |
ref_plotmap = [] | |
for i=1:length(subplot1_series) | |
push!(preserved_signals, preserve(const_lift(update_myplot!,xls1,y1[i],subplot1_series[i]))) | |
end | |
for i=1:length(subplot2_series) | |
push!(preserved_signals, preserve(const_lift(update_myplot!,xls2,y2[i],subplot2_series[i]))) | |
end | |
function clean_signals(refs) | |
for ref in refs | |
unpreserve(ref); | |
end | |
gc(); | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment