Files
whale_town/Assets/Tiles/gen_tiles.py
WangXiang 6119faf53e init
2025-12-22 18:57:51 +08:00

29 lines
995 B
Python

import zlib
import struct
def make_png(width, height, data):
def chunk(tag, data):
return struct.pack('>I', len(data)) + tag + data + struct.pack('>I', zlib.crc32(tag + data))
# IHDR
ihdr = struct.pack('>IIBBBBB', width, height, 8, 6, 0, 0, 0)
# IDAT
# RGBA format. width * height * 4
# Scanlines need to be prepended with filter type 0
raw_data = b''
for y in range(height):
raw_data += b'\x00' # Filter type 0
for x in range(width):
if x < 16: # Left side: Green (Grass)
raw_data += b'\x4b\x69\x2f\xff' # #4b692f
else: # Right side: Gray (Wall)
raw_data += b'\x8b\x9b\xb4\xff' # #8b9bb4
idat = zlib.compress(raw_data)
return b'\x89PNG\r\n\x1a\n' + chunk(b'IHDR', ihdr) + chunk(b'IDAT', idat) + chunk(b'IEND', b'')
with open('/Users/wangx/Documents/playground/whale_town/Assets/Tiles/placeholder_tiles.png', 'wb') as f:
f.write(make_png(32, 16, None))