demo-04-20/demo.lua

39 lines
978 B
Lua
Raw Normal View History

2020-04-22 13:39:56 +02:00
local bitmap = require'bitmap' --used to read its content
2020-04-22 18:58:33 +02:00
function int_exa(nb)
output = "0123456789abcdef"
first_digit = 0
while nb > 15 do
nb = nb - 16
first_digit = first_digit + 1
end
return output:sub(first_digit + 1, 1)..output:sub(nb + 1, 1)
end
io.write("from casioplot import set_pixel, show_screen as S, R\n")
2020-04-22 13:39:56 +02:00
do --open image
local cairo = require'cairo' --used to open the file
2020-04-22 17:52:59 +02:00
local image = cairo.load_png(arg[1])
2020-04-22 13:39:56 +02:00
image_infos = {width = image:width(), height = image:height()}
image_bitmap = image:bitmap()
end
local getpixel, setpixel = bitmap.pixel_interface(image_bitmap)
2020-04-22 18:58:33 +02:00
pallet = {} --will store colors
pallet_last = 0
for j = 1, image_infos.height, 1 do
for i = 1, image_infos.width, 1 do
r, g, b = getpixel(i, j)
if not pallet[r.." "..g.." "..b] then
pallet[r.." "..g.." "..b] = pallet_last
pallet_last = pallet_last + 1
end
io.write(int_exa(pallet[r.." "..g.." "..b]))
end
end
io.write("\nR()")