import struct


def color(r, g, b) -> int:
    return (b << 10) | (g << 5) | r


def pack(palette) -> bytes:
    return struct.pack(f'{len(palette)}H', *palette)


obj_palette = [color(10, 10, 10), color(21, 21, 21), color(31, 0, 0)]
bg_palette = [0x2015, color(31, 31, 31)]

obj_packed = pack(obj_palette)
bg_packed = pack(bg_palette)

with open('obj_palette.data', 'wb') as f:
    f.write(obj_packed)

with open('bg_palette.data', 'wb') as f:
    f.write(bg_packed)
