-- ImageData test on love2d function make_gradation(imgdata) local w, h = imgdata:getDimensions() local x, y for y = 0, (h - 1) do for x = 0, (w - 1) do local r, g, b, a r = x / (w - 1) g = y / (h - 1) b = (x / ((w - 1) / 4)) % 1.0 a = (y / ((h - 1) / 4)) % 1.0 imgdata:setPixel(x, y, r, g, b, a) end end end function brighten(x, y, r, g, b, a) r = math.min(r * 1.5, 1.0) g = math.min(g * 1.5, 1.0) b = math.min(b * 1.5, 1.0) return r, g, b, a end function darken(x, y, r, g, b, a) r = math.max(r * 0.75, 0.0) g = math.max(g * 0.75, 0.0) b = math.max(b * 0.75, 0.0) return r, g, b, a end function love.load() love.graphics.setDefaultFilter("nearest", "nearest") local w, h = love.graphics.getDimensions() imgdata = love.image.newImageData(w, h) make_gradation(imgdata) img = love.graphics.newImage(imgdata) end function love.update(dt) end function love.draw() love.graphics.clear(0, 0, 0, 1) love.graphics.setColor(1, 1, 1, 1) love.graphics.draw(img, 0, 0) love.graphics.print("Hit Up/Down key", 2, 20) love.graphics.print("FPS: " .. tostring(love.timer.getFPS()), 2, 2) end function love.keypressed(key, isrepeat) if key == "escape" then -- ESC key to exit love.event.quit() elseif key == "up" then imgdata:mapPixel(brighten) img:replacePixels(imgdata) elseif key == "down" then imgdata:mapPixel(darken) img:replacePixels(imgdata) end end