Files
contents
Code
3 144
contents/celestial_sword/generate_textures.py
from pathlib import Path
import struct
import zlib
SIZE = 32
ROOT = Path(__file__).parent / "resourcepack/assets/celestial_sword/textures/item"
def png(path, pixels):
raw = b"".join(b"\0" + bytes(sum(row, [])) for row in pixels)
def chunk(kind, data):
return struct.pack(">I", len(data)) + kind + data + struct.pack(">I", zlib.crc32(kind + data) & 0xffffffff)
data = b"\x89PNG\r\n\x1a\n"
data += chunk(b"IHDR", struct.pack(">IIBBBBB", SIZE, SIZE, 8, 6, 0, 0, 0))
data += chunk(b"IDAT", zlib.compress(raw, 9))
data += chunk(b"IEND", b"")
path.parent.mkdir(parents=True, exist_ok=True)
path.write_bytes(data)
def canvas():
return [[[0, 0, 0, 0] for _ in range(SIZE)] for _ in range(SIZE)]
def rect(image, x0, y0, x1, y1, color):
for y in range(max(0, y0), min(SIZE, y1)):
for x in range(max(0, x0), min(SIZE, x1)):
image[y][x] = list(color)
def blade():
image = canvas()
for y in range(3, 29):
half = max(1, min(7, (y - 2) // 4))
for x in range(16 - half, 17 + half):
edge = abs(x - 16) == half
image[y][x] = [35, 178 + (y % 3) * 12, 255, 255]
if edge:
image[y][x] = [130, 238, 255, 255]
for y in range(5, 28):
image[y][16] = [220, 255, 255, 255]
if y % 3 == 0 and 17 < SIZE:
image[y][17] = [95, 225, 255, 255]
for x in range(10, 23):
image[29][x] = [190, 250, 255, 255]
return image
def gold():
image = canvas()
rect(image, 3, 12, 29, 20, (255, 190, 35, 255))
rect(image, 4, 13, 28, 15, (255, 239, 120, 255))
rect(image, 14, 4, 19, 29, (255, 183, 26, 255))
rect(image, 15, 5, 17, 28, (255, 239, 105, 255))
rect(image, 11, 20, 22, 23, (176, 94, 18, 255))
rect(image, 13, 21, 19, 22, (255, 207, 54, 255))
return image
def wing():
image = canvas()
for y in range(4, 29):
width = max(1, 13 - abs(y - 16) // 2)
for x in range(16 - width, 16 + width):
if (x + y) % 5 != 0:
image[y][x] = [238, 248, 255, 255]
for y in range(7, 28, 4):
for x in range(5, 28):
if image[y][x][3]:
image[y][x] = [175, 220, 255, 255]
return image
def halo():
image = canvas()
for y in range(32):
for x in range(32):
dx, dy = x - 16, y - 16
distance = (dx * dx + dy * dy) ** 0.5
if 10.5 <= distance <= 14:
image[y][x] = [255, 226, 72, 255]
elif 8.5 <= distance < 10.5:
image[y][x] = [255, 248, 160, 180]
return image
png(ROOT / "celestial_blade.png", blade())
png(ROOT / "celestial_gold.png", gold())
png(ROOT / "celestial_wing.png", wing())
png(ROOT / "celestial_halo.png", halo())
print(f"Textures PNG créées dans {ROOT}")