Created
June 1, 2017 18:06
-
-
Save lobingera/912a7daf827406219da28c6e3e817896 to your computer and use it in GitHub Desktop.
gtk / cairo anim simple
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 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) |
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 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) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
adding two screenshots
screen of anim1.jl

screen of anim2.jl
