Munching squares: Difference between revisions

Content added Content deleted
Line 728: Line 728:


=={{header|Julia}}==
=={{header|Julia}}==
<lang julia>using Gtk, Colors, PerceptualColourMaps
<lang julia>using Gtk, Cairo

function munchingsquares(ctx, w, h)
extent = min(max(w, h), 256)
colors = cmap("R1", N=extent)
for i in 1:2:w-2, j in 1:2:h-2
rectangle(ctx, i, j, i + 2, j + 2)
c = colors[((UInt(i) ^ UInt(j)) % extent) + 1]
set_source_rgb(ctx, red(c), blue(c), green(c))
fill(ctx)
end
end
const can = @GtkCanvas()
const can = @GtkCanvas()
const win = GtkWindow(can, "Munching Squares", 720, 360)
const win = GtkWindow(can, "Munching Squares", 512, 512)

@guarded draw(can) do widget
@guarded draw(can) do widget
ctx = getgc(can)
ctx = getgc(can)
for x in 0:255, y in 0:255
h = height(can)
set_source_rgb(ctx, abs(255 - x - y) / 255, ((255 - x) ⊻ y) / 255, (x ⊻ (255 - y)) / 255)
w = width(can)
munchingsquares(ctx, w, h)
circle(ctx, 2x, 2y, 2)
fill(ctx)
end
end
end

show(can)
show(can)
const cond = Condition()
const cond = Condition()