Greyscale bars/Display: Difference between revisions

Content added Content deleted
Line 828: Line 828:
=={{header|Julia}}==
=={{header|Julia}}==
<lang Julia>using Gtk, Cairo, ColorTypes
<lang Julia>using Gtk, Cairo, ColorTypes

function generategrays(n, screenwidth)
function generategrays(n, screenwidth)
horizontals = Vector{RGB}()
verts = Vector{RGB}()
hwidth = Int(ceil(screenwidth/n))
hwidth = Int(ceil(screenwidth/n))
for (i, x) in enumerate(00:Int(floor(0xff/(n-1))):0xff)
for (i, x) in enumerate(00:Int(floor(0xff/(n-1))):0xff)
rgbgray = RGB(x/255, x/255, x/255)
rgbgray = RGB(x/255, x/255, x/255)
for j in 1:hwidth
for j in 1:hwidth
push!(horizontals, rgbgray)
push!(verts, rgbgray)
end
end
end
end
horizontals
verts
end
end

function drawline(ctx, p1, p2, color, width)
function drawline(ctx, p1, p2, color, width)
move_to(ctx, p1.x, p1.y)
move_to(ctx, p1.x, p1.y)
Line 848: Line 848:
stroke(ctx)
stroke(ctx)
end
end

const can = @GtkCanvas()
const can = @GtkCanvas()
const win = GtkWindow(can, "Grayscale bars/Display", 400, 400)
const win = GtkWindow(can, "Grayscale bars/Display", 400, 400)
fullscreen(win) # start full screen, then reduce to regular window in 5 seconds.
fullscreen(win) # start full screen, then reduce to regular window in 5 seconds.

@guarded draw(can) do widget
draw(can) do widget
ctx = getgc(can)
ctx = getgc(can)
h = height(can)
h = height(can)
w = width(can)
w = width(can)
gpoints = generategrays(8, w)
gpoints = generategrays(8, w)
for (i, x) in enumerate(0:w-1)
for (i, x) in enumerate(0:w-1)
drawline(ctx, Point(x, 0.25*h), Point(x, 0), gpoints[i], 1)
drawline(ctx, Point(x, 0.25*h), Point(x, 0), gpoints[i], 1)
Line 864: Line 864:
for (i, x) in enumerate(0:w-1)
for (i, x) in enumerate(0:w-1)
drawline(ctx, Point(x, 0.5*h), Point(x, 0.25*h), gpoints[i], 1)
drawline(ctx, Point(x, 0.5*h), Point(x, 0.25*h), gpoints[i], 1)
end
end
gpoints = generategrays(32, w)
gpoints = generategrays(32, w)
for (i, x) in enumerate(0:w-1)
for (i, x) in enumerate(0:w-1)