Pallet generation done, one big thing left: draw function
This commit is contained in:
parent
21b54c0683
commit
e00b853bf7
|
@ -0,0 +1,5 @@
|
|||
rm -v test.py
|
||||
echo "demo.lua -> 'test.py'"
|
||||
../luajit demo.lua pn.png >> test.py
|
||||
rm -v /run/media/user/disk/test.py
|
||||
cp -v test.py /run/media/user/disk/
|
25
demo.lua
25
demo.lua
|
@ -1,13 +1,14 @@
|
|||
local bitmap = require'bitmap' --used to read its content
|
||||
|
||||
function int_exa(nb)
|
||||
function int_hex(nb)
|
||||
if nb < 16 then add = "0"
|
||||
else add = "" end
|
||||
return [[\x]]..add..string.format("%x", nb)
|
||||
end
|
||||
|
||||
io.write([[from casioplot import set_pixel, show_screen as S, R
|
||||
data=b"]])
|
||||
io.write([[from casioplot import set_pixel as S
|
||||
from casioplot import show_screen as R
|
||||
]])
|
||||
|
||||
do --open image
|
||||
local cairo = require'cairo' --used to open the file
|
||||
|
@ -20,17 +21,23 @@ local getpixel, setpixel = bitmap.pixel_interface(image_bitmap)
|
|||
pallet = {} --will store colors
|
||||
pallet_last = 0
|
||||
|
||||
io.write("width=", image_infos.width, "\n", [[data=b"]])
|
||||
|
||||
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
|
||||
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]))
|
||||
io.write(int_hex(pallet[r..","..g..","..b]))
|
||||
end
|
||||
end
|
||||
|
||||
io.write([["
|
||||
R()
|
||||
]])
|
||||
--let's write the pallet
|
||||
io.write("\"\npallet=(None")
|
||||
for i, _ in pairs(pallet) do
|
||||
io.write(",(", i, ")")
|
||||
end
|
||||
|
||||
io.write(")\nR()")
|
||||
|
|
Loading…
Reference in New Issue