make_icon.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/usr/bin/env python3
  2. """Generates a 256x256 Sculpt Engine icon PNG (stdlib only): a gold isometric cube with a carved doorway."""
  3. import struct
  4. import sys
  5. import zlib
  6. W = H = 256
  7. CX, CY, S = 128, 130, 84
  8. def pixel(x, y):
  9. t = y / H
  10. color = (int(18 + 14 * t), int(24 + 18 * t), int(34 + 26 * t)) # steel-blue gradient
  11. dx, dy = x - CX, y - CY
  12. # Isometric hexagon silhouette
  13. if abs(dx) <= S * 0.87 and abs(dy) <= S and abs(dx) * 0.577 + abs(dy) <= S:
  14. if dy < -abs(dx) * 0.577 + S * 0.0 and dy < 0 and (-dy) > abs(dx) * 0.577:
  15. color = (236, 196, 92) # top face
  16. elif dx < 0:
  17. color = (150, 120, 52) # left face
  18. else:
  19. color = (105, 84, 38) # right face
  20. if 14 < dx < 48 and 4 < dy < 62:
  21. color = (16, 20, 28) # carved doorway (Subtract)
  22. return color + (255,)
  23. raw = bytearray()
  24. for y in range(H):
  25. raw.append(0)
  26. for x in range(W):
  27. raw.extend(pixel(x, y))
  28. def chunk(tag, data):
  29. body = tag + data
  30. return struct.pack(">I", len(data)) + body + struct.pack(">I", zlib.crc32(body) & 0xFFFFFFFF)
  31. png = b"\x89PNG\r\n\x1a\n"
  32. png += chunk(b"IHDR", struct.pack(">IIBBBBB", W, H, 8, 6, 0, 0, 0))
  33. png += chunk(b"IDAT", zlib.compress(bytes(raw), 9))
  34. png += chunk(b"IEND", b"")
  35. with open(sys.argv[1], "wb") as f:
  36. f.write(png)