Skip to content

Instantly share code, notes, and snippets.

@lobingera
Created June 1, 2017 18:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lobingera/912a7daf827406219da28c6e3e817896 to your computer and use it in GitHub Desktop.
Save lobingera/912a7daf827406219da28c6e3e817896 to your computer and use it in GitHub Desktop.
gtk / cairo anim simple
using Gtk, Gtk.ShortNames, Graphics
win = Window("Test")
hbox = Box(:h)
setproperty!(hbox, :homogeneous, true)
push!(win, hbox)
for i = 1:4
canv = Canvas()
push!(hbox, canv)
@schedule begin
while true
@guarded draw(canv) do widget
ctx = getgc(canv)
w, h = width(canv), height(canv)
offsetW = w/32
offsetH = h/32
@inbounds for x = 1:32
@inbounds for y = 1:32
set_source_rgb(ctx, rand(), rand(), rand())
rectangle(ctx, x*offsetW, y*offsetH, offsetW, offsetH)
fill(ctx)
end
end
end
sleep(1/10)
end
end
end
showall(win)
cond = Condition()
signal_connect(win, :destroy) do widget
notify(cond)
end
wait(cond)
using Gtk, Gtk.ShortNames, Graphics
using Cairo
win = Window("Test")
hbox = Box(:h)
setproperty!(hbox, :homogeneous, true)
push!(win, hbox)
for i = 1:4
canv = Canvas()
push!(hbox, canv)
@schedule begin
while true
@guarded draw(canv) do widget
ctx = getgc(canv)
w, h = width(canv), height(canv)
m = rand(UInt32,32,32);
Cairo.rectangle(ctx, 0,0 , w,h )
Cairo.set_source_rgb(ctx,1,1,1)
Cairo.fill(ctx)
Cairo.rectangle(ctx, 0,0 , w,h )
imgsurf = Cairo.CairoRGBSurface(m)
imgpatt = Cairo.CairoPattern(imgsurf)
Cairo.pattern_set_filter(imgpatt, Cairo.FILTER_NEAREST)
imgmatrix = Cairo.CairoMatrix(33.0/w, 0, 0, 33.0/h, 0, 0)
Cairo.set_source(ctx,imgpatt)
Cairo.set_matrix(imgpatt, imgmatrix)
Cairo.fill(ctx)
end
sleep(1/10)
end
end
end
showall(win)
cond = Condition()
signal_connect(win, :destroy) do widget
notify(cond)
end
wait(cond)
@lobingera
Copy link
Author

adding two screenshots

screen of anim1.jl
snapshot11

screen of anim2.jl
snapshot12

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment