#!/usr/bin/env python3
# Writes the icon masters, drawn on Papirus's 192 grid.
import os
import sys
out = sys.argv[1] if len(sys.argv) > 1 else os.path.join(os.path.dirname(__file__), '../../assets/icons')
def tint(hex_, amount):
# Mixes a colour towards white.
rgb = [int(hex_[i:i + 2], 16) for i in (1, 3, 5)]
return '#%02X%02X%02X' % tuple(round(c + (255 - c) * amount) for c in rgb)
def rect(x, y, w, h, r):
return f''
def circle(x, y, r):
return f''
def path(d):
return f''
def line(points, width):
pts = ' '.join(f'{x},{y}' for x, y in points)
return (f'')
def curve(d, width):
return f''
# The page: 128 by 160, top-right corner folded.
PAGE = 'M40 16H112L160 64V168A8 8 0 0 1 152 176H40A8 8 0 0 1 32 168V24A8 8 0 0 1 40 16Z'
FOLD = 'M112 16V56A8 8 0 0 0 120 64H160Z'
# Part: (svg, colour, shadow, small). Shadow 'body', 'part' or None.
APPS = {}
BLUE = '#3D7FE5'
APPS['ely-doc'] = [
(path(PAGE), BLUE, 'body', True), (path(FOLD), tint(BLUE, .45), 'fold', True),
(rect(56, 84, 64, 12, 4), '#FFFFFF', 'part', True),
(rect(56, 108, 80, 8, 4), '#FFFFFF', 'part', True),
(rect(56, 124, 80, 8, 4), '#FFFFFF', 'part', True),
(rect(56, 140, 80, 8, 4), '#FFFFFF', 'part', False),
(rect(56, 156, 48, 8, 4), tint(BLUE, .55), 'part', False),
]
GREEN = '#2E9E5B'
APPS['ely-table'] = [
(path(PAGE), GREEN, 'body', True), (path(FOLD), tint(GREEN, .45), 'fold', True),
(path('M52 92H140V156H52ZM60 108H92V120H60ZM100 108H132V120H100Z'
'M60 128H92V140H60ZM100 128H132V140H100Z').replace('', f' fill="{colour}"/>', 1)
def draw(parts, small):
body, filters = [], set()
for svg, colour, shadow, keep in parts:
if small and not keep:
continue
if shadow and not small:
dy, _ = SHADOWS[shadow]
filters.add(shadow)
body.append(f''
f'{paint(svg, "#000000")}')
body.append(paint(svg, colour))
return ''.join(body), filters
def svg(parts, macos, small):
body, used = draw(parts, small)
defs = ''.join(f''
f''
for name in sorted(used))
if macos:
# A light squircle; the object fills 86 % of it.
scale = 0.86 * 206 / 192
offset = 128 - 96 * scale
content = (f''
f'{body}')
else:
content = f'{body}'
return ('\n')
for slug, parts in APPS.items():
for macos in (False, True):
for small in (False, True):
name = f'{out}/{slug}{"-small" if small else ""}{"-macos" if macos else ""}.svg'
with open(name, 'w') as file:
file.write(svg(parts, macos, small))