Jump to content

Greyscale bars/Display: Difference between revisions

→‎{{header|Lua}}: added Lua solution
(→‎{{header|Lua}}: added Lua solution)
Line 1,155:
</lang>
Resulting [http://www.diga.me.uk/greyscale.gif GreyScale image] without the outlines.
 
=={{header|Lua}}==
{{libheader|nw}}
{{libheader|cairo}}
<lang lua>local nw = require("nw")
local app = nw:app()
local cw, ch = 320, 240
local win = app:window(cw, ch, "Grayscale Bars", false)
function win:repaint()
local cr = win:bitmap():cairo()
local ystride = ch/4
for y = 0, 3 do
local i, n = 1, 2^(y+3)
local xstride = cw/n
for x = 0, n-1 do
cr:rectangle(x*xstride, y*ystride, xstride, ystride)
local gray = x / (n-1)
if y%2>0 then gray=1-gray end
cr:rgb(gray, gray, gray)
cr:fill()
end
end
end
win:show()
app:run()</lang>
 
=={{header|Mathematica}} / {{header|Wolfram Language}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.