-- bad displayment thing local function color_dist(c1,c2) local total = 0 for i=1,3 do total = total + (c1[i]-c2[i])^2 end return total end local function closest_palette_color(R,c) local closest = nil local closest_dist = 99999999 for i=0,15 do local pc = {R.getPaletteColor(2^i)} local dist = color_dist(pc,c) if dist < closest_dist then closest = 2^i closest_dist = dist end end return closest end local function disp(R,img,scrx,scry,w,h,imgx,imgy) scrx = scrx or 1 scry = scry or 1 w = w or img.width h = h or img.height imgx = imgx or 1 imgy = imgy or 1 for offx=0,w-1 do for offy=0,h-1 do R.setCursorPos(scrx+offx,scry+offy) local icol = img[imgy+offy][imgx+offx] local pcol = closest_palette_color(R,icol) R.setBackgroundColor(pcol) R.write(" ") end end end return {disp=disp}