Skip to content

Instantly share code, notes, and snippets.

@lobingera
Created July 6, 2015 15:26
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lobingera/712c886cc75ca6019e49 to your computer and use it in GitHub Desktop.
Save lobingera/712c886cc75ca6019e49 to your computer and use it in GitHub Desktop.
gtk anim
_
_ _ _(_)_ | A fresh approach to technical computing
(_) | (_) (_) | Documentation: http://docs.julialang.org
_ _ _| |_ __ _ | Type "help()" for help.
| | | | | | |/ _` | |
| | |_| | | | (_| | | Version 0.4.0-dev+5791 (2015-07-04 23:24 UTC)
_/ |\__'_|_|_|\__'_| | Commit 59a1e9c* (1 day old master)
|__/ | x86_64-linux-gnu
julia> include("gtk_anim.jl")
WARNING: deprecated syntax "LListPair{L} (" at /home/lobi/.julia/v0.4/Gtk/src/GLib/glist.jl:61.
Use "LListPair{L}(" instead.
WARNING: deprecated syntax "< {" at /home/lobi/.julia/v0.4/FixedPointNumbers/src/fixed32.jl:20.
Use "<{" instead.
WARNING: deprecated syntax "< {" at /home/lobi/.julia/v0.4/FixedPointNumbers/src/ufixed.jl:91.
Use "<{" instead.
using Gtk
using Cairo
type Scene
ti::Float64
n::Int64
end
function update(canvas, scene::Scene)
draw(canvas)
end
function init(canvas, scene::Scene)
update_timer = Timer(timer -> update(canvas, scene), 0.0,0.05)
# start_timer
return update_timer
end
function draw_scene(canvas, scene::Scene)
ctx = Gtk.getgc(canvas)
h = height(canvas)
w = width(canvas)
rectangle(ctx, 0, 0, w, h)
set_source_rgb(ctx, 1, 1, 1)
fill(ctx)
set_source_rgb(ctx, 0.5, 0.0, 0.7)
t1 = @sprintf("%07.3fs",time()-scene.ti)
text(ctx,0,18,t1)
ti = (time() - scene.ti)/2.0
for k=1:scene.n
x = (cos(ti*3) * ((w/2.0)-30.0)) + (w/2.0) +5.0
y = (sin(ti*4) * ((h/2.0)-40.0)) + (h/2.0) +15.0
new_path(ctx)
set_line_width(ctx, 10.0);
set_source_rgb(ctx, 0.5, mod(ti,1.0), 0.7)
arc(ctx, x, y, 20.0, 0.0, 6.28);
stroke(ctx);
ti = ti + 0.05
end
end
canvas = Gtk.@GtkCanvas(200,200);
w = Gtk.@GtkWindow(canvas,"animtest");
show(canvas)
scene = Scene(time(),10)
update_timer = init(canvas, scene)
draw(canvas -> draw_scene(canvas, scene), canvas)
if !isinteractive()
cond = Condition()
signal_connect(w, :destroy) do widget
notify(cond)
end
wait(cond)
end
#stop_timer(update_timer)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment