get("#507") -- averageBrightness ow, oh = img.width, img.height g = math.min(ow, oh)/16 -- grid size -- copy image and invert pixels = {} w, h = math.floor(ow/g), math.floor(oh/g) for y = 0, h-1 do for x = 0, w-1 do x1 = math.floor(x*g+0.5) y1 = math.floor(y*g+0.5) x2 = math.floor((x+1)*g+0.5) y2 = math.floor((y+1)*g+0.5) b = averageBrightness(img, x1, y1, x2, y2) n = math.max(0, math.min(255, math.floor(b*255+0.5))) pixels[y*w+x+1] = n*0x010101 end end