"""Draws the Cryo Studio logo (an ice crystal on a blue tile): assets/images/logo.png and assets/thumbnail.png.
   python3 tools/logo.py   (needs Pillow)"""
import math, os
from PIL import Image, ImageDraw

def logo(size):
    s = size * 4                                   # drawn big, then scaled down: smooth edges
    im = Image.new('RGBA', (s, s), (0, 0, 0, 0))
    d = ImageDraw.Draw(im)
    d.rounded_rectangle([0, 0, s - 1, s - 1], radius=s // 5, fill=(26, 74, 140, 255))
    d.rounded_rectangle([s // 14, s // 14, s - 1 - s // 14, s - 1 - s // 14], radius=s // 6, fill=(47, 127, 216, 255))
    c, r, w = s / 2, s * 0.36, max(2, s // 22)
    ice = (232, 246, 255, 255)
    for k in range(6):
        a = math.pi / 3 * k
        x, y = c + r * math.cos(a), c + r * math.sin(a)
        d.line([c, c, x, y], fill=ice, width=w)
        for t, b in ((0.55, 0.36), (0.8, 0.22)):  # two pairs of branches per arm
            px, py = c + r * t * math.cos(a), c + r * t * math.sin(a)
            for side in (-1, 1):
                aa = a + side * math.pi / 4
                d.line([px, py, px + r * b * math.cos(aa), py + r * b * math.sin(aa)], fill=ice, width=w)
    d.ellipse([c - w * 1.6, c - w * 1.6, c + w * 1.6, c + w * 1.6], fill=ice)
    return im.resize((size, size), Image.LANCZOS)

root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
logo(128).save(os.path.join(root, 'assets/images/logo.png'))
thumb = Image.new('RGBA', (640, 360), (243, 244, 247, 255))
thumb.alpha_composite(logo(240), (200, 60))
thumb.convert('RGB').save(os.path.join(root, 'assets/thumbnail.png'))
