1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
-- a vlorb consists of six gromlings[A
-- 1 2
-- 4 8
-- 16 Q
-- these are characters 0x80 through 0x9f in the cc charset
-- which is only 2^5 characters though. for the sixth bit you flip the colours
-- of that vlorb.
-- on colour, off colour, gromlings 1 through 6 (bools)
-- returns text colour, bg color, and vlorbchar
local function vlorb(onc,offc, g1,g2,g3,g4,g5,g6)
local textc,bgc = onc,offc
if g6 then textc,bgc=bgc,textc end
local vlorbchar = 0x80
-- ~= on booleans is xor
-- if g6 set then flip all the other bits
if g1 ~= g6 then vlorbchar=vlorbchar+1 end
if g2 ~= g6 then vlorbchar=vlorbchar+2 end
if g3 ~= g6 then vlorbchar=vlorbchar+4 end
if g4 ~= g6 then vlorbchar=vlorbchar+8 end
if g5 ~= g6 then vlorbchar=vlorbchar+16 end
return textc,bgc,string.char(vlorbchar)
end
local function should_be_on(col)
return col[1]+col[2]+col[3] > 1.5
end
-- 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
imgx = 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
local ic = img[imgy+ioffy+goffy][imgx+ioffx+goffx] or {0,0,0}
table.insert(gs,should_be_on(ic))
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,disp=disp}
|