DSCF

.co.uk

PC32

A ColorForth compiler and editor for x86-64
git clone https://dscf.co.uk/clone/PC32.git
Log | Files | Refs | README

mkicon.py (692B)


      1 #!/usr/bin/env python3
      2 """write a simple 256x256 PNG icon (pure python): usage mkicon.py out.png"""
      3 import sys, zlib, struct
      4 N = 256
      5 rows = bytearray()
      6 for y in range(N):
      7     rows.append(0)
      8     for x in range(N):
      9         edge = min(x, y, N - 1 - x, N - 1 - y) < 12
     10         rows += bytes((255, 200, 0)) if edge else bytes((20 + y // 8, 20, 60 + x // 6))
     11 def chunk(t, d):
     12     c = struct.pack(">I", len(d)) + t + d
     13     return c + struct.pack(">I", zlib.crc32(t + d) & 0xffffffff)
     14 open(sys.argv[1], "wb").write(b"\x89PNG\r\n\x1a\n" + chunk(b"IHDR", struct.pack(">IIBBBBB", N, N, 8, 2, 0, 0, 0))
     15                               + chunk(b"IDAT", zlib.compress(bytes(rows), 9)) + chunk(b"IEND", b""))