onemillioncheckboxes/rgb111.py

28 lines
813 B
Python

from base64 import b64decode
from PIL import Image
from requests import get
BASE_URL = "https://onemillioncheckboxes.com"
with get(f"{BASE_URL}/api/initial-state") as req:
data = req.json()
buffer = b64decode(data["full_state"].encode() + b"=")
def getbit(b: bytes, i: int) -> bool:
return b[i // 8] & (0x80 >> (i % 8)) != 0
with Image.new("RGB", (577, 577)) as im:
for y in range(im.height):
for x in range(im.width):
ndx_start = (x + y * 577) * 3
im.putpixel(
( x, y ),
(
255 if getbit(buffer, ndx_start) else 0,
255 if getbit(buffer, ndx_start + 1) else 0,
255 if getbit(buffer, ndx_start + 2) else 0,
)
)
im.save("rgb111-full.png")