"""Erzeugt das PilotNG-App-Icon (tools/pilotng.ico) im Glas-Look."""
from pathlib import Path

from PIL import Image, ImageDraw, ImageFilter

S = 512
ROOT = Path(__file__).resolve().parents[1]
img = Image.new('RGBA', (S, S), (0, 0, 0, 0))
d = ImageDraw.Draw(img)
d.rounded_rectangle([8, 8, S - 8, S - 8], radius=118, fill=(10, 15, 28, 255))

glow = Image.new('RGBA', (S, S), (0, 0, 0, 0))
gd = ImageDraw.Draw(glow)
gd.ellipse([-120, -140, 300, 280], fill=(227, 58, 99, 150))
gd.ellipse([260, 280, 640, 660], fill=(59, 130, 246, 120))
glow = glow.filter(ImageFilter.GaussianBlur(70))
mask = Image.new('L', (S, S), 0)
ImageDraw.Draw(mask).rounded_rectangle([8, 8, S - 8, S - 8], radius=118, fill=255)
img.paste(glow, (0, 0), mask)

d = ImageDraw.Draw(img)
d.rounded_rectangle([8, 8, S - 8, S - 8], radius=118,
                    outline=(255, 255, 255, 60), width=4)

tri = Image.new('RGBA', (S, S), (0, 0, 0, 0))
ImageDraw.Draw(tri).polygon(
    [(190, 140), (190, 372), (392, 256)], fill=(255, 255, 255, 255))
grad = Image.new('RGBA', (S, S))
gdraw = ImageDraw.Draw(grad)
for y in range(S):
    t = y / S
    gdraw.line([(0, y), (S, y)], fill=(
        int(240 + (227 - 240) * t), int(90 + (58 - 90) * t),
        int(140 + (99 - 140) * t), 255))
img.paste(grad, (0, 0), tri)

img.save(ROOT / 'tools' / 'pilotng-icon.png')
img.resize((256, 256), Image.LANCZOS).save(
    ROOT / 'tools' / 'pilotng.ico',
    sizes=[(16, 16), (24, 24), (32, 32), (48, 48),
           (64, 64), (128, 128), (256, 256)])
print('Icon geschrieben:', ROOT / 'tools' / 'pilotng.ico')
