HatchLing-TuneBox / make_assets.py
taellinglin's picture
Add Reitenland patriotic preset
f6df5f7 verified
Raw History Blame Contribute Delete
2.59 kB
#!/usr/bin/env python3
"""Rebuilds assets/bg_*.jpg: the theme backgrounds (America: official portrait, public domain; Korea: drawn taegeuk; Ling: the flag; Reitenland: drawn tricolour)."""
import sys
from pathlib import Path
from PIL import Image, ImageDraw
OUT = Path(__file__).parent / 'assets'
RED, BLUE, BLACK = (205, 46, 58), (0, 71, 160), (20, 20, 20)
def shrink(im, w):
im = im.convert('RGB')
return im.resize((w, round(im.height * w / im.width)), Image.LANCZOS)
def korea(W=1600, H=1000, S=2):
im = Image.new('RGB', (W * S, H * S), 'white'); d = ImageDraw.Draw(im)
cx, cy, r = W * S // 2, H * S // 2, 200 * S
d.pieslice([cx - r, cy - r, cx + r, cy + r], 180, 360, fill=RED)
d.pieslice([cx - r, cy - r, cx + r, cy + r], 0, 180, fill=BLUE)
d.ellipse([cx - r, cy - r // 2, cx, cy + r // 2], fill=RED)
d.ellipse([cx, cy - r // 2, cx + r, cy + r // 2], fill=BLUE)
bh, gap, L = 30 * S, 16 * S, 260 * S
def trigram(x, y, rot, lines):
g = Image.new('RGBA', (L, bh * 3 + gap * 2), (0, 0, 0, 0)); gd = ImageDraw.Draw(g)
for i, solid in enumerate(lines):
yy = i * (bh + gap)
if solid: gd.rectangle([0, yy, L, yy + bh], fill=BLACK)
else: gd.rectangle([0, yy, int(L * .44), yy + bh], fill=BLACK); gd.rectangle([int(L * .56), yy, L, yy + bh], fill=BLACK)
g = g.rotate(rot, expand=True)
im.paste(g, (int(x - g.width / 2), int(y - g.height / 2)), g)
# geon, gam, gon, ri at the four corners of the Taegukgi
for sx, sy, rot, lines in [(-1, -1, -33.7, (1, 1, 1)), (1, -1, 33.7, (0, 1, 0)), (1, 1, -33.7, (0, 0, 0)), (-1, 1, 33.7, (1, 0, 1))]:
trigram(cx + sx * 520 * S, cy + sy * 300 * S, rot, lines)
return im.resize((W, H), Image.LANCZOS)
def reitenland(W=1620, H=1080):
"""The flag of Reitenland: three equal horizontal stripes, orange, red and white."""
im = Image.new('RGB', (W, H), 'white'); d = ImageDraw.Draw(im)
d.rectangle([0, 0, W, H // 3], fill=(255, 140, 0)); d.rectangle([0, H // 3, W, 2 * H // 3], fill=(204, 0, 0))
return im
if __name__ == '__main__':
# usage: make_assets.py clinton_portrait.jpg ling_flag.png
OUT.mkdir(exist_ok=True)
shrink(Image.open(sys.argv[1]), 900).save(OUT / 'bg_america.jpg', quality=72, optimize=True)
shrink(Image.open(sys.argv[2]), 800).save(OUT / 'bg_ling.jpg', quality=72, optimize=True)
korea().save(OUT / 'bg_korea.jpg', quality=80, optimize=True)
reitenland().save(OUT / 'bg_reitenland.jpg', quality=90, optimize=True)