Improved and cleaned up code.

This commit is contained in:
KikooDX 2020-04-25 10:52:10 +02:00
parent 5adeab8f24
commit 232d7be94b
5 changed files with 59 additions and 25 deletions

View File

@ -1,7 +0,0 @@
rm -v test.py
echo "demo.lua -> 'test.py'"
../luajit demo.lua pn.png >> test.py
rm -v /run/media/user/disk/test.py
rm -v /run/media/user/disk/draw.py
cp -v test.py /run/media/user/disk/
cp -v draw.py /run/media/user/disk/

View File

@ -1,7 +0,0 @@
rm -v test.py
echo "demo.lua -> 'test.py'"
../luajit demo.lua pn.png >> test.py
rm -v /media/user/disk/test.py
rm -v /media/user/disk/draw.py
cp -v test.py /media/user/disk/
cp -v draw.py /media/user/disk/

View File

@ -7,12 +7,18 @@ function int_hex(nb)
return [[\x]]..add..string.format("%x", nb)
end
io.write([[from draw import *
file = io.open("output.py", "w")
first = true
pallet = {} --will store colors
pallet_last = 1
file:write([[from draw import *
]])
for i = 1, 12, 1 do
print(i)
do --open image
path = "spongebob/out-"
path = "spongebob/resized_cropped_out-"
if i < 10 then path = path.."0" end
path = path..i.."0.png"
local image = cairo.load_png(path)
@ -21,10 +27,9 @@ for i = 1, 12, 1 do
end
local getpixel, setpixel = bitmap.pixel_interface(image_bitmap)
pallet = {} --will store colors
pallet_last = 0
io.write("width=", image_infos.width, "\n", [[data=b"]])
if first then
file:write("width=", image_infos.width, "\n", [[data=b"]])
end
for j = 1, image_infos.height, 1 do
for i = 1, image_infos.width, 1 do
@ -33,15 +38,20 @@ for i = 1, 12, 1 do
pallet[r..","..g..","..b] = pallet_last
pallet_last = pallet_last + 1
end
io.write(int_hex(pallet[r..","..g..","..b]))
file:write(int_hex(pallet[r..","..g..","..b]))
end
end
--let's write the pallet
io.write("\"\npallet={")
for i, v in pairs(pallet) do
io.write(v, ":(", i, "),")
if first then
file:write("\"\npallet={")
for i, v in pairs(pallet) do
file:write(v, ":(", i, "),")
end
end
io.write("}\ndraw(data,pallet,", image_infos.width, ")")
file:write("}\ndraw(", 192 - image_infos.width, ",", 96 - image_infos.height)
file:write(",data,pallet,", image_infos.width, ")")
end
file:close()

38
output.py Normal file

File diff suppressed because one or more lines are too long

Binary file not shown.

Before

Width:  |  Height:  |  Size: 79 KiB

After

Width:  |  Height:  |  Size: 32 KiB