Greyscale bars/Display: Difference between revisions

m
Line 828:
=={{header|Julia}}==
<lang Julia>using Gtk, Cairo, ColorTypes
 
function generategrays(n, screenwidth)
horizontalsverts = Vector{RGB}()
hwidth = Int(ceil(screenwidth/n))
for (i, x) in enumerate(00:Int(floor(0xff/(n-1))):0xff)
rgbgray = RGB(x/255, x/255, x/255)
for j in 1:hwidth
push!(horizontalsverts, rgbgray)
end
end
horizontalsverts
end
 
function drawline(ctx, p1, p2, color, width)
move_to(ctx, p1.x, p1.y)
Line 848:
stroke(ctx)
end
 
const can = @GtkCanvas()
const win = GtkWindow(can, "Grayscale bars/Display", 400, 400)
fullscreen(win) # start full screen, then reduce to regular window in 5 seconds.
 
@guarded draw(can) do widget
ctx = getgc(can)
h = height(can)
w = width(can)
gpoints = generategrays(8, w)
for (i, x) in enumerate(0:w-1)
drawline(ctx, Point(x, 0.25*h), Point(x, 0), gpoints[i], 1)
Line 864:
for (i, x) in enumerate(0:w-1)
drawline(ctx, Point(x, 0.5*h), Point(x, 0.25*h), gpoints[i], 1)
end
gpoints = generategrays(32, w)
for (i, x) in enumerate(0:w-1)
4,108

edits