Munching squares: Difference between revisions

(→‎{{header|Lua}}: Updated Löve code)
Line 845:
=={{header|Lua}}==
Needs LÖVE 2D Engine 11.0 or higher
<lang lua>local clr = {}
local clr = {}
function drawMSquares()
local points = {}
for y = 0, hei - 1 do
for x = 0, wid - 1 do
local idx = bit.bxor( x, y ) % 256
local r, g, b = clr[idx][1]/255, clr[idx][2]/255, clr[idx][3]/255
local point = { x+1, y+1, r/255, g/255, b/255, 1}
table.insert (points, point)
end
end
love.graphics.points(points)
end
 
function createPalette()
for i = 0, 255 do
clr[i] = { bit.band( i * 2.8%256, 255 ), bit.band( i * 3.2%256, 255 ), bit.band( i * 1.5, 255 ) %256}
end
end
 
function love.load()
wid, hei = 256, 256
wid, hei = love.graphics.getWidth(), love.graphics.getHeight()
canvas = love.graphicswindow.newCanvassetMode( wid, hei )
canvas = love.graphics.setCanvasnewCanvas(canvas);
love.graphics.clearsetCanvas(canvas)
createPalette();
love.graphics.setColor(255/255, 255/255, 255/255)
drawMSquares();
createPalette();
love.graphics.setCanvas()
drawMSquares();
love.graphics.setCanvas()
end
 
function love.draw()
love.graphics.drawsetColor(canvas1,1,1)
love.graphics.draw(canvas)
end
end</lang>
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
Anonymous user