Munching squares: Difference between revisions

Content added Content deleted
(→‎{{header|Lua}}: Updated Löve code)
Line 845: Line 845:
=={{header|Lua}}==
=={{header|Lua}}==
Needs LÖVE 2D Engine 11.0 or higher
Needs LÖVE 2D Engine 11.0 or higher
<lang lua>
<lang lua>local clr = {}
local clr = {}
function drawMSquares()
function drawMSquares()
local points = {}
local points = {}
for y = 0, hei - 1 do
for y = 0, hei-1 do
for x = 0, wid - 1 do
for x = 0, wid-1 do
idx = bit.bxor( x, y ) % 256
local idx = bit.bxor(x, y)%256
local r, g, b = clr[idx][1]/255, clr[idx][2]/255, clr[idx][3]/255
local r, g, b = clr[idx][1], clr[idx][2], clr[idx][3]
local point = { x, y, r, g, b, 1}
local point = {x+1, y+1, r/255, g/255, b/255, 1}
table.insert (points, point)
table.insert (points, point)
end
end
end
end
love.graphics.points(points)
love.graphics.points(points)
end
end

function createPalette()
function createPalette()
for i = 0, 255 do
for i = 0, 255 do
clr[i] = { bit.band( i * 2.8, 255 ), bit.band( i * 3.2, 255 ), bit.band( i * 1.5, 255 ) }
clr[i] = {i*2.8%256, i*3.2%256, i*1.5%256}
end
end
end
end

function love.load()
function love.load()
wid, hei = 256, 256
wid, hei = love.graphics.getWidth(), love.graphics.getHeight()
canvas = love.graphics.newCanvas( wid, hei )
love.window.setMode(wid, hei)
love.graphics.setCanvas(canvas);
canvas = love.graphics.newCanvas()
love.graphics.clear()
love.graphics.setCanvas(canvas)
createPalette()
love.graphics.setColor(255/255, 255/255, 255/255)
drawMSquares()
createPalette();
love.graphics.setCanvas()
drawMSquares();
love.graphics.setCanvas()
end
end

function love.draw()
function love.draw()
love.graphics.draw(canvas)
love.graphics.setColor(1,1,1)
love.graphics.draw(canvas)
end
</lang>
end</lang>


=={{header|Mathematica}}/{{header|Wolfram Language}}==
=={{header|Mathematica}}/{{header|Wolfram Language}}==