"""The "Carbone" skin of WinZik: a sporty carbon fibre case (a woven 2x2 twill drawn procedurally), satin black bevelled
buttons with crisp white glyphs, racing red accent lines, a red "redline" at the end of the volume groove, dark grey
LCDs with white and red digits, and small hex bolts. Everything is drawn here pixel by pixel (no picture is copied,
no logo, no brand). Every picture has the name and the size WinZik expects (same layout as tools/skins/classique.py).
Run: python3 -I tools/skins/carbone.py assets/skins/carbone
"""
import math
import os
import sys
from PIL import Image, ImageDraw, ImageFont

OUT = sys.argv[1] if len(sys.argv) > 1 else 'assets/skins/carbone'
os.makedirs(OUT, exist_ok=True)

BLACK = (6, 6, 8)
EDGE = (92, 94, 100)
LCD = (30, 32, 36)
LCD_LINE = (26, 28, 31)
LCD_HI = (84, 86, 92)
LCD_LO = (4, 4, 6)
GHOST = (46, 48, 53)
RED = (226, 24, 36)
RED_DARK = (110, 10, 18)
WHITE = (244, 244, 246)
GREY = (150, 152, 158)
FACE_TOP = (64, 65, 70)
FACE_BOTTOM = (20, 20, 23)
FACE_HI = (128, 130, 136)
LIST = (16, 17, 19)


def font(size):
    try:
        return ImageFont.load_default(size=size)
    except TypeError:
        return ImageFont.load_default()


def new(w, h, color=(0, 0, 0, 0)):
    return Image.new('RGBA', (w, h), color)


def save(im, name):
    im.save(os.path.join(OUT, name + '.png'))


def mix(a, b, t):
    return tuple(int(round(a[i] * (1 - t) + b[i] * t)) for i in range(3))


# --- the carbon weave --------------------------------------------------------------------------------------------
def carbon_pixel(x, y, cell=4, sheen=True):
    """One pixel of a 2x2 twill: tows of `cell` pixels, each over two and under two, so the weave runs in diagonals.
    A horizontal tow is shaded across its height, a vertical one across its width (a round fibre bundle), and the
    horizontal ones catch more light than the vertical ones, like real carbon under a lamp."""
    i, j = x // cell, y // cell
    horizontal = (i + j) % 4 < 2
    u = ((y % cell) + 0.5) / cell if horizontal else ((x % cell) + 0.5) / cell
    s = math.sin(math.pi * u)
    v = (20 + 34 * s) if horizontal else (11 + 13 * s)
    if sheen:
        # a broad glossy reflection across the case, from the top left
        g = math.exp(-((x * 0.55 + y - 70) / 55.0) ** 2)
        v += 14 * g
    v = int(v)
    return (v, v, min(255, v + 4))


def carbon(im, box=None, sheen=True):
    x0, y0, x1, y1 = box or (0, 0, im.width, im.height)
    px = im.load()
    for y in range(y0, y1):
        for x in range(x0, x1):
            px[x, y] = carbon_pixel(x, y, sheen=sheen) + (255,)


def frame(d, w, h):
    d.rectangle([0, 0, w - 1, h - 1], outline=BLACK)
    d.line([(1, 1), (w - 2, 1)], fill=EDGE)
    d.line([(1, 1), (1, h - 2)], fill=(60, 62, 68))
    d.line([(1, h - 2), (w - 2, h - 2)], fill=(10, 10, 12))
    d.line([(w - 2, 1), (w - 2, h - 2)], fill=(12, 12, 14))


def sunken(d, x, y, w, h, fill=LCD, lines=True):
    """A dark grey LCD set into the carbon: a black lip at the top left, a light one at the bottom right."""
    d.rectangle([x, y, x + w - 1, y + h - 1], fill=fill)
    if lines:
        for ly in range(y + 1, y + h, 2):
            d.line([(x, ly), (x + w - 1, ly)], fill=LCD_LINE)
    d.line([(x, y), (x + w - 1, y)], fill=(18, 19, 22))         # inner shadow
    d.line([(x - 1, y - 1), (x + w, y - 1)], fill=LCD_LO)
    d.line([(x - 1, y - 1), (x - 1, y + h)], fill=LCD_LO)
    d.line([(x - 1, y + h), (x + w, y + h)], fill=LCD_HI)
    d.line([(x + w, y - 1), (x + w, y + h)], fill=LCD_HI)


def text(d, xy, s, size=8, fill=WHITE, anchor='la'):
    d.fontmode = '1'
    d.text(xy, s, font=font(size), fill=fill, anchor=anchor)


def satin(d, x, y, w, h, top=FACE_TOP, bottom=FACE_BOTTOM):
    """A satin black bevelled face: a soft vertical gradient, a bright top lip, a black outline with cut corners."""
    for yy in range(y, y + h):
        t = (yy - y) / max(1, h - 1)
        d.line([(x, yy), (x + w - 1, yy)], fill=mix(top, bottom, t ** 0.8))
    d.line([(x + 1, y), (x + w - 2, y)], fill=FACE_HI)
    d.line([(x, y + 1), (x, y + h - 2)], fill=(88, 90, 96))
    d.line([(x + w - 1, y + 1), (x + w - 1, y + h - 2)], fill=(14, 14, 16))
    d.line([(x + 1, y + h - 1), (x + w - 2, y + h - 1)], fill=(10, 10, 12))
    # the black outline, its corners cut (a rounded look)
    d.line([(x, y - 1), (x + w - 1, y - 1)], fill=BLACK)
    d.line([(x, y + h), (x + w - 1, y + h)], fill=BLACK)
    d.line([(x - 1, y), (x - 1, y + h - 1)], fill=BLACK)
    d.line([(x + w, y), (x + w, y + h - 1)], fill=BLACK)


def glyph(d, kind, cx, cy, color=WHITE):
    """The transport symbols, drawn with polygons (pixel exact)."""
    if kind == 'prev':
        d.rectangle([cx - 6, cy - 4, cx - 5, cy + 4], fill=color)
        d.polygon([(cx + 1, cy - 4), (cx + 1, cy + 4), (cx - 4, cy)], fill=color)
        d.polygon([(cx + 6, cy - 4), (cx + 6, cy + 4), (cx + 1, cy)], fill=color)
    elif kind == 'next':
        d.polygon([(cx - 6, cy - 4), (cx - 6, cy + 4), (cx - 1, cy)], fill=color)
        d.polygon([(cx - 1, cy - 4), (cx - 1, cy + 4), (cx + 4, cy)], fill=color)
        d.rectangle([cx + 5, cy - 4, cx + 6, cy + 4], fill=color)
    elif kind == 'play':
        d.polygon([(cx - 3, cy - 5), (cx - 3, cy + 5), (cx + 4, cy)], fill=color)
    elif kind == 'pause':
        d.rectangle([cx - 4, cy - 4, cx - 2, cy + 4], fill=color)
        d.rectangle([cx + 2, cy - 4, cx + 4, cy + 4], fill=color)
    elif kind == 'stop':
        d.rectangle([cx - 4, cy - 4, cx + 4, cy + 4], fill=color)
    elif kind == 'list':
        for k in range(3):
            d.rectangle([cx - 6, cy - 4 + k * 3, cx - 5, cy - 3 + k * 3], fill=color)
            d.line([(cx - 3, cy - 4 + k * 3), (cx + 6, cy - 4 + k * 3)], fill=color)
            d.line([(cx - 3, cy - 3 + k * 3), (cx + 6, cy - 3 + k * 3)], fill=color)
    elif kind == 'shuffle':
        d.line([(cx - 7, cy - 3), (cx - 3, cy - 3), (cx + 2, cy + 3), (cx + 5, cy + 3)], fill=color)
        d.line([(cx - 7, cy + 3), (cx - 3, cy + 3), (cx + 2, cy - 3), (cx + 5, cy - 3)], fill=color)
        d.polygon([(cx + 5, cy - 6), (cx + 5, cy), (cx + 8, cy - 3)], fill=color)
        d.polygon([(cx + 5, cy), (cx + 5, cy + 6), (cx + 8, cy + 3)], fill=color)
    elif kind == 'info':
        d.rectangle([cx - 1, cy - 5, cx, cy - 4], fill=color)
        d.rectangle([cx - 1, cy - 2, cx, cy + 4], fill=color)
        d.line([(cx - 2, cy - 2), (cx - 1, cy - 2)], fill=color)
        d.line([(cx - 2, cy + 4), (cx + 1, cy + 4)], fill=color)
    elif kind == 'min':
        d.rectangle([cx - 3, cy + 2, cx + 3, cy + 3], fill=color)
    elif kind == 'close':
        for k in range(-3, 4):
            d.rectangle([cx + k, cy + k, cx + k + 1, cy + k], fill=color)
            d.rectangle([cx + k, cy - k, cx + k + 1, cy - k], fill=color)
    elif kind == 'tray':
        d.polygon([(cx - 4, cy - 2), (cx + 4, cy - 2), (cx, cy + 2)], fill=color)
        d.line([(cx - 4, cy + 4), (cx + 4, cy + 4)], fill=color)
    elif kind == 'lyrics':
        # a quaver
        d.rectangle([cx + 1, cy - 4, cx + 1, cy + 2], fill=color)
        d.line([(cx + 2, cy - 4), (cx + 4, cy - 2)], fill=color)
        d.ellipse([cx - 3, cy + 1, cx + 1, cy + 4], fill=color)
    elif kind == 'plus':
        d.rectangle([cx - 4, cy - 1, cx + 4, cy], fill=color)
        d.rectangle([cx - 1, cy - 4, cx, cy + 4], fill=color)
    elif kind == 'minus':
        d.rectangle([cx - 4, cy - 1, cx + 4, cy], fill=color)
    elif kind == 'load':
        # a folder
        d.rectangle([cx - 6, cy - 3, cx + 6, cy + 4], outline=color)
        d.line([(cx - 6, cy - 4), (cx - 2, cy - 4)], fill=color)
        d.line([(cx - 5, cy - 1), (cx + 5, cy - 1)], fill=color)
    elif kind == 'save':
        # a disk
        d.rectangle([cx - 5, cy - 5, cx + 5, cy + 5], outline=color)
        d.rectangle([cx - 3, cy - 5, cx + 2, cy - 2], fill=color)
        d.rectangle([cx - 3, cy + 1, cx + 3, cy + 5], outline=color)
    elif kind == 'bin':
        d.rectangle([cx - 4, cy - 3, cx + 4, cy + 5], outline=color)
        d.line([(cx - 2, cy - 1), (cx - 2, cy + 3)], fill=color)
        d.line([(cx + 2, cy - 1), (cx + 2, cy + 3)], fill=color)
        d.line([(cx, cy - 1), (cx, cy + 3)], fill=color)
        d.line([(cx - 5, cy - 5), (cx + 5, cy - 5)], fill=color)
        d.line([(cx - 1, cy - 6), (cx + 1, cy - 6)], fill=color)


def small_glyph(d, kind, cx, cy, color=WHITE):
    """The symbols of the compact bar, made for 17 x 13 buttons."""
    if kind == 'prev':
        d.rectangle([cx - 4, cy - 3, cx - 4, cy + 3], fill=color)
        d.polygon([(cx, cy - 3), (cx, cy + 3), (cx - 3, cy)], fill=color)
        d.polygon([(cx + 4, cy - 3), (cx + 4, cy + 3), (cx + 1, cy)], fill=color)
    elif kind == 'next':
        d.polygon([(cx - 4, cy - 3), (cx - 4, cy + 3), (cx - 1, cy)], fill=color)
        d.polygon([(cx, cy - 3), (cx, cy + 3), (cx + 3, cy)], fill=color)
        d.rectangle([cx + 4, cy - 3, cx + 4, cy + 3], fill=color)
    elif kind == 'play':
        d.polygon([(cx - 2, cy - 3), (cx - 2, cy + 3), (cx + 2, cy)], fill=color)
    elif kind == 'pause':
        d.rectangle([cx - 3, cy - 3, cx - 2, cy + 3], fill=color)
        d.rectangle([cx + 1, cy - 3, cx + 2, cy + 3], fill=color)
    elif kind == 'back':
        d.rectangle([cx - 4, cy - 3, cx + 3, cy + 3], outline=color)
        d.line([(cx - 4, cy - 2), (cx + 3, cy - 2)], fill=color)
    elif kind == 'open':
        d.polygon([(cx - 3, cy - 1), (cx + 3, cy - 1), (cx, cy + 2)], fill=color)
    elif kind == 'lyrics':
        d.rectangle([cx + 1, cy - 3, cx + 1, cy + 1], fill=color)
        d.line([(cx + 2, cy - 3), (cx + 3, cy - 2)], fill=color)
        d.ellipse([cx - 2, cy, cx + 1, cy + 3], fill=color)


def bolt(im, cx, cy, r=3.2):
    """A small hex bolt: drawn at 4x then reduced, so its edges are smooth."""
    s = 4
    size = int(r * 2 + 4)
    big = new(size * s, size * s)
    d = ImageDraw.Draw(big)
    c = size * s / 2
    hexa = [(c + r * s * math.cos(math.pi / 3 * k + math.pi / 6), c + r * s * math.sin(math.pi / 3 * k + math.pi / 6)) for k in range(6)]
    d.ellipse([c - (r + 1.2) * s, c - (r + 1.2) * s, c + (r + 1.2) * s, c + (r + 1.2) * s], fill=(4, 4, 6, 200))
    d.polygon(hexa, fill=(120, 122, 128, 255), outline=(10, 10, 12, 255))
    d.polygon([hexa[3], hexa[4], hexa[5], (c, c)], fill=(170, 172, 178, 255))
    d.polygon([hexa[0], hexa[1], hexa[2], (c, c)], fill=(70, 72, 78, 255))
    inner = [(c + r * 0.45 * s * math.cos(math.pi / 3 * k), c + r * 0.45 * s * math.sin(math.pi / 3 * k)) for k in range(6)]
    d.polygon(inner, fill=(22, 22, 26, 255))
    small = big.resize((size, size), Image.LANCZOS)
    im.alpha_composite(small, (int(round(cx - size / 2)), int(round(cy - size / 2))))


def stripes(d, x, y, h, count=3, gap=4, color=RED):
    """Slanted racing stripes."""
    for k in range(count):
        x0 = x + k * gap
        d.polygon([(x0 + h // 2, y), (x0 + h // 2 + 2, y), (x0 + 2, y + h - 1), (x0, y + h - 1)], fill=color)


def button(w, h, kind=None, label=None, size=8, color=WHITE, lamp=False):
    im = new(w, h)
    d = ImageDraw.Draw(im)
    satin(d, 1, 1, w - 2, h - 2)
    if lamp:
        d.line([(4, h - 3), (w - 5, h - 3)], fill=RED)
    if kind:
        glyph(d, kind, w // 2, h // 2 - (1 if lamp else 0), color)
    if label:
        text(d, (w // 2, h // 2), label, size, color, 'mm')
    return im


# --- the player (main.png, 258 x 128: 99 shown, 128 opened) ------------------------------------------------------
main = new(258, 128)
carbon(main)
d = ImageDraw.Draw(main)
frame(d, 258, 128)

# the title: an LCD with red racing stripes at each end
sunken(d, 47, 1, 163, 12)
stripes(d, 29, 2, 10, 3, 5)
stripes(d, 212, 2, 10, 2, 5)
# the bargraph, its unlit segments shown faintly (an LED meter)
sunken(d, 27, 17, 197, 12, lines=False)
for i in range(23):
    for x in (120 - (i + 1) * 4, 133 + i * 4):
        col = GHOST if i < 14 else ((60, 46, 30) if i < 19 else (66, 26, 28))
        d.rectangle([x, 19, x + 2, 26], fill=col)
d.line([(126, 19), (126, 26)], fill=(70, 72, 78))
# the three small LCDs, their labels
sunken(d, 0, 31, 70, 13)
sunken(d, 112, 31, 32, 13)
sunken(d, 186, 31, 70, 13)
text(d, (148, 37), 'kbps', 8, GREY, 'lm')
stripes(d, 82, 33, 9, 3, 5)
# the socket of the playing light, between the two sliders
d.ellipse([119, 44, 135, 60], fill=(8, 8, 10), outline=(60, 62, 68))
d.ellipse([121, 46, 133, 58], fill=(32, 10, 12))
# a red racing line under the sliders, another under the transport buttons
d.line([(2, 60), (255, 60)], fill=RED)
d.line([(2, 61), (255, 61)], fill=BLACK)
d.line([(58, 96), (255, 96)], fill=RED)
d.line([(58, 97), (255, 97)], fill=BLACK)
# the counter: an LCD with H M S marks
sunken(d, 0, 81, 56, 17)
for cx in (16, 34):
    d.point((cx, 87), fill=GREY)
    d.point((cx, 92), fill=GREY)
# a bolt and the opening chevron at the right of the buttons
bolt(main, 219, 85)
d = ImageDraw.Draw(main)
d.polygon([(239, 82), (249, 82), (244, 87)], fill=WHITE)
d.polygon([(239, 87), (249, 87), (244, 92)], fill=RED)
# the bottom part (opened with the hidden button): a vent grille, a plate with an LCD
d.line([(2, 100), (255, 100)], fill=BLACK)
d.line([(2, 101), (255, 101)], fill=(70, 72, 78))
for k in range(16):
    x = 14 + k * 6
    d.polygon([(x + 6, 106), (x + 8, 106), (x + 2, 122), (x, 122)], fill=(4, 4, 6))
    d.line([(x + 1, 122), (x + 3, 122)], fill=(60, 62, 68))
sunken(d, 124, 107, 118, 15)
for bx, by in [(6, 106), (251, 106), (6, 121), (251, 121)]:
    bolt(main, bx, by)
save(main, 'main')

# the buttons of the player
save(button(25, 17, 'shuffle'), 'hd')
save(button(25, 17, 'shuffle', color=RED, lamp=False), 'he')
save(button(25, 17, 'info'), 'info')
save(button(15, 15, 'min'), 'petit')
save(button(17, 15, 'close'), 'close')
save(button(17, 15, 'tray'), 'tray')
save(button(17, 15, 'lyrics'), 'lyr')
for name, kind in [('barr', 'prev'), ('bpause', 'pause'), ('bplay', 'play'), ('bstop', 'stop'), ('bav', 'next'), ('bpl', 'list')]:
    save(button(25, 18, kind), name)


# the sliders: a groove with tick marks; the volume one ends with a red redline, the balance one has a red middle
def groove(w, h, red_from=None, middle=False, ticks=10):
    im = new(w, h)
    dd = ImageDraw.Draw(im)
    sunken(dd, 2, 3, w - 4, 4, fill=(12, 12, 14), lines=False)
    lo, hi = 8, w - 9
    if red_from is not None:
        dd.rectangle([red_from, 4, w - 3, 5], fill=RED)
    for k in range(ticks + 1):
        x = int(round(lo + (hi - lo) * k / ticks))
        col = RED if (red_from is not None and x >= red_from) or (middle and k == ticks // 2) else (170, 172, 178)
        dd.point((x, 0), fill=col)
        dd.point((x, 1), fill=col)
        dd.point((x, 9), fill=col)
    if middle:
        dd.rectangle([(lo + hi) // 2, 3, (lo + hi) // 2, 6], fill=RED)
    return im


save(groove(116, 10, red_from=92), 'fbson')
save(groove(116, 10, middle=True), 'fbbal')
save(groove(255, 10, ticks=20), 'fpos')
for name, mark in [('bson', RED), ('bbal', RED), ('bpos', WHITE)]:
    im = new(17, 9)
    dd = ImageDraw.Draw(im)
    if name == 'bpos':
        satin(dd, 1, 1, 15, 7, top=(236, 40, 50), bottom=(130, 8, 16))
    else:
        satin(dd, 1, 1, 15, 7)
    dd.line([(8, 2), (8, 6)], fill=mark)
    save(im, name)

# --- the play list (mainpl.png, 258 x 362) -----------------------------------------------------------------------
# rows 296..335 are stretched to the length of the list, rows 336..361 (the foot) are drawn as they are: the band
# is a plain list background between vertically uniform borders; the weave stays on the top and in the foot.
pl = new(258, 362)
carbon(pl, (0, 0, 258, 48))
carbon(pl, (0, 346, 258, 362), sheen=False)
d = ImageDraw.Draw(pl)
d.rectangle([0, 48, 257, 345], fill=(14, 14, 16))
frame(d, 258, 362)
# the title plate between the button rows
text(d, (188, 25), 'PLAYLIST', 8, WHITE, 'mm')
stripes(d, 63, 20, 10, 3, 5)
d.line([(28, 40), (229, 40)], fill=RED)
d.line([(28, 41), (229, 41)], fill=BLACK)
for bx in (36, 110, 154, 223):
    bolt(pl, bx, 25)
d = ImageDraw.Draw(pl)
# the list and the scroll bar's track
sunken(d, 1, 48, 247, 298, fill=LIST, lines=False)
sunken(d, 249, 48, 8, 298, fill=(10, 10, 12), lines=False)
# the foot: an LCD for the count, the two grips
sunken(d, 66, 348, 126, 12)
d.line([(20, 354), (60, 354)], fill=RED)
d.line([(197, 354), (237, 354)], fill=RED)
for right in (False, True):
    # a triangle of dots pointing to the corner, like a resize grip
    for a in range(3):
        for b in range(a + 1):
            x = 251 - b * 4 if right else 3 + b * 4
            y = 350 + a * 4
            d.rectangle([x + 1, y + 1, x + 2, y + 2], fill=(4, 4, 6))
            d.rectangle([x, y, x + 1, y + 1], fill=(196, 198, 204))
save(pl, 'mainpl')

save(button(25, 17, 'plus'), 'plp')
save(button(25, 17, 'minus'), 'plm')
save(button(25, 17, 'load'), 'plload')
save(button(25, 17, 'save'), 'plsave')
save(button(25, 17, 'bin'), 'plrem')
save(button(82, 16, label='MODE EDITION', size=8), 'pledit')
save(button(82, 16, label='MODE LISTE', size=8, color=(255, 70, 76)), 'pledit2')
# the scroll bar: its track and its thumb
track = new(8, 296, (10, 10, 12, 255))
td = ImageDraw.Draw(track)
td.line([(3, 0), (3, 295)], fill=(36, 37, 41))
td.line([(4, 0), (4, 295)], fill=(4, 4, 6))
save(track, 'posplay')
thumb = new(8, 17)
tdd = ImageDraw.Draw(thumb)
satin(tdd, 1, 1, 6, 15)
for y in (6, 8, 10):
    tdd.line([(2, y), (5, y)], fill=RED)
save(thumb, 'btnplay')
# the icons of the lines: the kind of file, the lyrics
for name, label, color in [('infomp3', 'MP3', (176, 18, 30)), ('infowav', 'WAV', (78, 80, 88)), ('infomid', 'MID', (176, 96, 16)), ('infocd', 'CD', (52, 74, 120))]:
    im = new(17, 9)
    dd = ImageDraw.Draw(im)
    dd.rectangle([0, 0, 16, 8], fill=color)
    dd.line([(0, 0), (16, 0)], fill=mix(color, WHITE, 0.35))
    text(dd, (8, 4), label, 7, WHITE, 'mm')
    save(im, name)
for name, color, ring in [('lyrok', RED, (255, 120, 120)), ('lyrno', (44, 44, 48), (70, 70, 76))]:
    im = new(17, 9)
    dd = ImageDraw.Draw(im)
    dd.ellipse([5, 1, 11, 7], fill=color, outline=(4, 4, 6))
    dd.point((7, 3), fill=ring)
    save(im, name)

# --- the compact bar (mainp.png, 112 x 12) and its buttons --------------------------------------------------------
mp = new(112, 12)
carbon(mp, sheen=False)
md = ImageDraw.Draw(mp)
md.rectangle([0, 0, 111, 11], outline=BLACK)
md.line([(1, 10), (110, 10)], fill=RED)
save(mp, 'mainp')
for name, kind in [('arrp', 'prev'), ('pausep', 'pause'), ('playp', 'play'), ('avp', 'next'),
                   ('petitp', 'back'), ('helpp', 'open'), ('lyrp', 'lyrics')]:
    im = new(17, 13)
    dd = ImageDraw.Draw(im)
    satin(dd, 1, 1, 15, 11)
    small_glyph(dd, kind, 8, 6)
    save(im, name)

# --- the icon -----------------------------------------------------------------------------------------------------
ico = new(32, 32)
carbon(ico, sheen=False)
mask = new(32, 32)
ImageDraw.Draw(mask).rounded_rectangle([1, 1, 30, 30], 5, fill=(255, 255, 255, 255))
ico.putalpha(mask.getchannel('A'))
dd = ImageDraw.Draw(ico)
dd.rounded_rectangle([1, 1, 30, 30], 5, outline=(70, 72, 78))
dd.polygon([(11, 8), (11, 24), (24, 16)], fill=WHITE)
dd.line([(5, 27), (26, 27)], fill=RED)
dd.line([(5, 28), (26, 28)], fill=RED)
save(ico, 'ico')


# --- INFO.txt: the colours, as VB wrote them (&H00BBGGRR&) -------------------------------------------------------
def vb(rgb):
    r, g, b = rgb
    return '&H00%02X%02X%02X&' % (b, g, r)


colors = [
    (240, 240, 244),   # title
    (236, 236, 240),   # volume
    (236, 236, 240),   # balance
    (255, 52, 60),     # kbps
    (240, 240, 244),   # hours
    (240, 240, 244),   # minutes
    (255, 52, 60),     # seconds
    (225, 228, 234), (225, 228, 234),   # bargraph: white...
    (255, 150, 40), (255, 150, 40),     # ...amber...
    (255, 32, 44), (255, 32, 44),       # ...then the redline
    (255, 64, 72),     # the active line of the play list
]
lines = ['[INF]', 'Carbone'] + [vb(c) for c in colors] + [vb((214, 216, 222)) for i in range(23)]
with open(os.path.join(OUT, 'INFO.txt'), 'w', encoding='utf-8') as f:
    f.write('\n'.join(lines) + '\n')
print('skin written in', OUT)

# VIS.txt: where WinZik draws its visualizer (the spectrum of the sound), in the opened part of the player
with open(os.path.join(OUT, 'VIS.txt'), 'w') as f:
    f.write('125 108 116 13\n')
