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
|
-- 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}
|