From a8565927929c78ffb10b27fee3bd5f913f5b3a14 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Fri, 5 Aug 2022 01:09:57 +0100 Subject: img --- img/shitty_disp.lua | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 img/shitty_disp.lua (limited to 'img/shitty_disp.lua') 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 -- cgit v1.2.3