Greyscale bars/Display: Difference between revisions
Content added Content deleted
SqrtNegInf (talk | contribs) m (→{{header|Perl 6}}: better message if file open fails) |
|||
Line 824: | Line 824: | ||
</body></html> |
</body></html> |
||
</lang> |
</lang> |
||
=={{header|Julia}}== |
|||
<lang Julia>using Gtk, Cairo, ColorTypes |
|||
function generategrays(n, screenwidth) |
|||
horizontals = 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!(horizontals, rgbgray) |
|||
end |
|||
end |
|||
horizontals |
|||
end |
|||
function drawline(ctx, p1, p2, color, width) |
|||
move_to(ctx, p1.x, p1.y) |
|||
set_source(ctx, color) |
|||
line_to(ctx, p2.x, p2.y) |
|||
set_line_width(ctx, width) |
|||
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) |
|||
end |
|||
gpoints = reverse(generategrays(16, w)) |
|||
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) |
|||
drawline(ctx, Point(x, 0.75*h), Point(x, 0.5*h), gpoints[i], 1) |
|||
end |
|||
gpoints = reverse(generategrays(64, w)) |
|||
for (i, x) in enumerate(0:w-1) |
|||
drawline(ctx, Point(x, h), Point(x, 0.75*h), gpoints[i], 1) |
|||
end |
|||
end |
|||
show(can) |
|||
sleep(5) |
|||
unfullscreen(win) |
|||
const cond = Condition() |
|||
endit(w) = notify(cond) |
|||
signal_connect(endit, win, :destroy) |
|||
wait(cond)</lang> |
|||
=={{header|Kotlin}}== |
=={{header|Kotlin}}== |