function col2hex(num) local hexstr = '0123456789abcdef' local s = '' for i=1, 6 do local mod = math.fmod(num, 16) s = string.sub(hexstr, mod+1, mod+1) .. s num = math.floor(num / 16) end return s end function colortostring(c) if c == 0xFFFFFF then return "white" end return col2hex(c) end w, h = 100, 100 img = {getInt = function (x,y) return x > 2 and x < 98 and y > 2 and y < 98 and -1 or 0 end} ofs = 0 while ofs <= w/2 and ofs <= h/2 do colors = {} for y=ofs, h-ofs-1 do colors[img.getInt(ofs, y)] = 1 colors[img.getInt(w-ofs-1, y)] = 1 end for x=ofs, w-ofs-1 do colors[img.getInt(x, ofs)] = 1 colors[img.getInt(x, h-ofs-1)] = 1 end list, n = {}, 0 for color, _ in pairs(colors) do n=n+1 list[n] = color end if #list > 1 then return ofs == 0 and "no border found" or "border thickness: "..ofs elseif lastcolor == nil then lastcolor = list[1] elseif lastcolor ~= list[1] then return ofs == 0 and "no border found" or "border thickness: "..ofs end ofs = ofs+1 end --return "unicolor "..colortostring(lastcolor) return "unicolor "..lastcolor