Log In  


I'm working on a script to turn any image into Picotron wallpaper. It sorta kinda works.

Its kinda cool ig.

from PIL import Image

img = Image.open("img.png").convert("RGB")
img = img.resize((480, 270), resample=Image.LANCZOS)

palette = [
    (0x00, 0x00, 0x00), (0x1d, 0x2b, 0x53), (0x7e, 0x25, 0x53), (0x00, 0x87, 0x51),
    (0xab, 0x52, 0x36), (0x5f, 0x57, 0x4f), (0xc2, 0xc3, 0xc7), (0xff, 0xf1, 0xe8),
    (0xff, 0x00, 0x4d), (0xff, 0xa3, 0x00), (0xff, 0xec, 0x27), (0x00, 0xe4, 0x36),
    (0x29, 0xad, 0xff), (0x83, 0x76, 0x9c), (0xff, 0x77, 0xa8), (0xff, 0xcc, 0xaa),
    (0x24, 0x63, 0xb0), (0x00, 0xa5, 0xa1), (0x65, 0x46, 0x88), (0x12, 0x53, 0x59),
    (0x74, 0x2f, 0x29), (0x45, 0x2d, 0x32), (0xa2, 0x88, 0x79), (0xff, 0xac, 0xc5),
    (0xb9, 0x00, 0x3e), (0xe2, 0x6b, 0x02), (0x95, 0xf0, 0x24), (0x00, 0xb2, 0x51),
    (0x64, 0xdf, 0xf6), (0xbd, 0x9a, 0xdf), (0xe4, 0x0d, 0xab), (0xff, 0x85, 0x57)
]

flat_palette = [value for color in palette for value in color]
flat_palette += [0] * (768 - len(flat_palette))

palette_img = Image.new("P", (1, 1))
palette_img.putpalette(flat_palette)

posterized = img.quantize(palette=palette_img, dither=Image.FLOYDSTEINBERG)

indices = list(posterized.getdata())
with open("wallpaper.p64", "w") as f:
    f.write("""picotron cartridge // www.picotron.net
version 2

:: main.lua
include("wallpaper.lua")

function _init()
	window{
		wallpaper = true
	}
end

function _draw()
	cls(0)
	spr(bg, 0, 0)
end
:: wallpaper.lua
bg = userdata("u8", 480, 270)
""")
    for i in range(len(indices)):
        f.write(f"bg:set({i % 480}, {i // 480}, {indices[i]})\n")
    f.write(":: [eoc]\n")
    f.flush()
3



[Please log in to post a comment]