From cb630d5580174ffe9640fcb23f23a24b376ae9b2 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Sat, 6 Aug 2022 01:20:11 +0100 Subject: vlorb --- img/better_disp.lua | 47 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 14 deletions(-) (limited to 'img') diff --git a/img/better_disp.lua b/img/better_disp.lua index 99fa5dd..4122836 100644 --- a/img/better_disp.lua +++ b/img/better_disp.lua @@ -22,21 +22,40 @@ local function vlorb(onc,offc, g1,g2,g3,g4,g5,g6) return textc,bgc,string.char(vlorbchar) end -local function test() - term.clear() - local gs = {false,false,false,false,false,false} - while true do - term.setCursorPos(5,5) - local tc,bgc,char = vlorb(colors.red,colors.black, table.unpack(gs)) - term.setTextColor(tc) - term.setBackgroundColor(bgc) - term.write(char) - local _,key = os.pullEvent"key" - if 65<=key and key<=70 then - local idx = key-64 - gs[idx] = not gs[idx] +-- todo: refactor common stuff into a common file +local function disp(R,img,scrx,scry,w,h,imgx,imgy) + -- w and h are image coords + scrx = scrx or 1 + scry = scry or 1 + w = w or img.width + h = h or img.width + img = imgx or 1 + imgy = imgy or 1 + + local sw = math.ceil(w/2) + local sh = math.ceil(h/3) + + for soffx=0,sw-1 do + for soffy=0,sh-1 do + local ioffx=soffx*2 + local ioffy=soffy*3 + R.setCursorPos(scrx+soffx,scry+soffy) + local gs = {} + for goffy=0,2 do + for goffx=0,1 do + table.insert(gs,img[imgy+ioffy+goffy][imgx+ioffx+goffx] or {0,0,0}) + end + end + local tc,bc,ch = vlorb(colors.white,colors.black,table.unpack(gs)) + R.setTextColor(tc) + R.setBackgroundColor(bc) + R.write(ch) end end end -return {vlorb=vlorb,test=test} + + + + +return {vlorb=vlorb} -- cgit v1.2.3