diff options
-rw-r--r-- | img/all.dat | 1 | ||||
-rw-r--r-- | img/shitty_disp.lua | 41 |
2 files changed, 42 insertions, 0 deletions
diff --git a/img/all.dat b/img/all.dat index 47b32b3..2c33eaa 100644 --- a/img/all.dat +++ b/img/all.dat @@ -1,2 +1,3 @@ dep img/load_pnm +dep img/shitty_disp file diff --git a/img/shitty_disp.lua b/img/shitty_disp.lua new file mode 100644 index 0000000..f0a1f07 --- /dev/null +++ b/img/shitty_disp.lua @@ -0,0 +1,41 @@ +-- 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 |