- Irisblende mit 8 geschwungenen Lamellen, links dunkles Graphit mit hellen Kanten, rechts Creme bis Gold mit dunklen Fugen, weiche Schatten zwischen den Lamellen - warmer, goldener Lichtschein um die helle Hälfte, leuchtender Ring - dunkle Metallkachel mit heller Außenkante und vertiefter Fläche - alles aus Geometrie gezeichnet, LK-Varianten bleiben im Skript verfügbar Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012bGzgsxrmbBhDzeMV2L57D
657 lines
28 KiB
Python
657 lines
28 KiB
Python
#!/usr/bin/env python3
|
||
"""Lichtkasten app icon, drawn from geometry (no fonts or images needed).
|
||
Default: a camera aperture, half in shadow and half in warm light, on a dark metal tile.
|
||
Other variants: LK monograms (gold, black and white) and the golden box that goes on forever.
|
||
|
||
python3 scripts/make-icon.py # default variant → Resources/AppIcon.icns + PNGs
|
||
python3 scripts/make-icon.py fein # another variant (see VARIANTS)
|
||
python3 scripts/make-icon.py --preview x.png # comparison sheet of all variants
|
||
|
||
Needs Pillow and numpy. Layout follows Apple's macOS icon template: 1024 grid, 824 body, 100 margin.
|
||
"""
|
||
import math
|
||
import sys
|
||
from functools import lru_cache
|
||
from pathlib import Path
|
||
|
||
import numpy as np
|
||
from PIL import Image, ImageChops, ImageDraw, ImageFilter
|
||
|
||
ROOT = Path(__file__).resolve().parent.parent
|
||
GRID = 1024
|
||
BODY = (100, 100, 924, 924)
|
||
SS = 4 # supersampling for clean edges
|
||
DEFAULT = "blende"
|
||
|
||
# ---------------------------------------------------------------- geometry (design units, y down)
|
||
|
||
def rect(x0, y0, x1, y1):
|
||
return [(x0, y0), (x1, y0), (x1, y1), (x0, y1)]
|
||
|
||
|
||
def _hit(p, d, q, e):
|
||
"""Intersection of the lines p + t·d and q + s·e."""
|
||
det = d[0] * e[1] - d[1] * e[0]
|
||
t = ((q[0] - p[0]) * e[1] - (q[1] - p[1]) * e[0]) / det
|
||
return (p[0] + t * d[0], p[1] + t * d[1])
|
||
|
||
|
||
def hcut(y):
|
||
return ((0.0, y), (1.0, 0.0))
|
||
|
||
|
||
def vcut(x):
|
||
return ((x, 0.0), (0.0, 1.0))
|
||
|
||
|
||
def along(p0, p1):
|
||
return (p0, (p1[0] - p0[0], p1[1] - p0[1]))
|
||
|
||
|
||
def band(p0, p1, w, cut0, cut1):
|
||
"""Straight stroke of width w on the centre line p0→p1, ends cut by the lines cut0 / cut1."""
|
||
dx, dy = p1[0] - p0[0], p1[1] - p0[1]
|
||
n = math.hypot(dx, dy)
|
||
ox, oy = -dy / n * w / 2, dx / n * w / 2
|
||
a, b = (p0[0] + ox, p0[1] + oy), (p0[0] - ox, p0[1] - oy)
|
||
d = (dx, dy)
|
||
return [_hit(a, d, *cut0), _hit(b, d, *cut0), _hit(b, d, *cut1), _hit(a, d, *cut1)]
|
||
|
||
|
||
def point_on(p0, p1, t):
|
||
return (p0[0] + (p1[0] - p0[0]) * t, p0[1] + (p1[1] - p0[1]) * t)
|
||
|
||
|
||
# Apple's continuous corner (as UIKit draws it): one corner from the edge point 1.5287·r away,
|
||
# local coordinates (u = distance from the vertical edge, v = from the horizontal edge), in units of r.
|
||
_CORNER = [
|
||
((1.52866483, 0.0), (1.08849323, 0.0), (0.86840689, 0.0), (0.66993427, 0.06549600)),
|
||
((0.66993427, 0.06549600), None, None, (0.63149399, 0.07491100)),
|
||
((0.63149399, 0.07491100), (0.37282392, 0.16905899), (0.16906013, 0.37282401), (0.07491176, 0.63149399)),
|
||
((0.07491176, 0.63149399), None, None, (0.06549569, 0.66993493)),
|
||
((0.06549569, 0.66993493), (0.0, 0.86840701), (0.0, 1.08849299), (0.0, 1.52866483)),
|
||
]
|
||
|
||
|
||
def _corner_points(steps=48):
|
||
pts = []
|
||
for p0, c1, c2, p3 in _CORNER:
|
||
if c1 is None:
|
||
pts.append(p3)
|
||
continue
|
||
for i in range(1, steps + 1):
|
||
t = i / steps
|
||
a, b, c, d = (1 - t) ** 3, 3 * (1 - t) ** 2 * t, 3 * (1 - t) * t * t, t ** 3
|
||
pts.append((a * p0[0] + b * c1[0] + c * c2[0] + d * p3[0], a * p0[1] + b * c1[1] + c * c2[1] + d * p3[1]))
|
||
return [_CORNER[0][0]] + pts
|
||
|
||
|
||
def squircle(box, radius=None):
|
||
"""macOS app icon shape: rounded rectangle with continuous corners (r = 185.4 on the 824 body)."""
|
||
x0, y0, x1, y1 = box
|
||
r = radius if radius is not None else (x1 - x0) * 185.4 / 824
|
||
local = _corner_points()
|
||
maps = [
|
||
lambda u, v: (x1 - u * r, y0 + v * r), # top right
|
||
lambda u, v: (x1 - v * r, y1 - u * r), # bottom right
|
||
lambda u, v: (x0 + u * r, y1 - v * r), # bottom left
|
||
lambda u, v: (x0 + v * r, y0 + u * r), # top left
|
||
]
|
||
return [f(u, v) for f in maps for u, v in local]
|
||
|
||
|
||
def bbox(polys):
|
||
xs = [x for p in polys for x, _ in p]
|
||
ys = [y for p in polys for _, y in p]
|
||
return min(xs), min(ys), max(xs), max(ys)
|
||
|
||
|
||
def centred(polys, cx, cy):
|
||
x0, y0, x1, y1 = bbox(polys)
|
||
dx, dy = cx - (x0 + x1) / 2, cy - (y0 + y1) / 2
|
||
return [[(x + dx, y + dy) for x, y in p] for p in polys]
|
||
|
||
# ---------------------------------------------------------------- letters
|
||
|
||
|
||
def k_parts(xk, top, base, w, reach, arm_w=None, leg_w=None, junction=0.64, branch=0.36, leg_reach=None):
|
||
"""Geometric K: stem at xk, arm to the cap height, leg springing from the arm down to `base`."""
|
||
arm_w = arm_w or w * 0.94
|
||
leg_w = leg_w or w
|
||
sc = xk + w / 2
|
||
h = base - top
|
||
arm_end = (xk + reach, top)
|
||
joint = (sc, top + junction * h)
|
||
leg_start = point_on(joint, arm_end, branch)
|
||
leg_end = (xk + (leg_reach if leg_reach is not None else reach * 1.06), base)
|
||
return [
|
||
rect(xk, top, xk + w, base),
|
||
band(joint, arm_end, arm_w, vcut(sc), hcut(top)),
|
||
band(leg_start, leg_end, leg_w, along(joint, arm_end), hcut(base)),
|
||
]
|
||
|
||
|
||
def lk_ligature(cx, cy, cap=330, w=30.0, bold=1.0):
|
||
"""L and K sharing the baseline: the K stands on the L's foot, the foot runs out into the K's leg."""
|
||
w *= bold
|
||
wf = w * 0.92 # horizontals a touch lighter (optical)
|
||
top, base = 0.0, cap
|
||
xk = w + 0.25 * cap # inner space between the two stems: a quarter of the cap height
|
||
k = k_parts(xk, top, base, w, reach=0.60 * cap, junction=0.63)
|
||
leg = k[2]
|
||
inner_bottom = min(x for x, y in leg if abs(y - base) < 1e-6)
|
||
outer_bottom = max(x for x, y in leg if abs(y - base) < 1e-6)
|
||
# foot ends inside the leg, so the outline runs from the baseline straight into the leg's outer edge
|
||
rise = wf * (outer_bottom - inner_bottom) / (base - min(y for _, y in leg))
|
||
foot = rect(0, base - wf, (inner_bottom + outer_bottom - rise) / 2, base)
|
||
polys = [rect(0, top, w, base), foot] + k
|
||
return centred(polys, cx, cy)
|
||
|
||
|
||
def lk_pair(cx, cy, cap=250, w=20.0, bold=1.0):
|
||
"""L and K as two letters (for the framed variant)."""
|
||
w *= bold
|
||
wf = w * 0.92
|
||
foot_len = 0.50 * cap
|
||
l = [rect(0, 0, w, cap), rect(0, cap - wf, foot_len, cap)]
|
||
xk = foot_len + 0.16 * cap
|
||
k = k_parts(xk, 0, cap, w, reach=0.56 * cap, junction=0.62)
|
||
return centred(l + k, cx, cy)
|
||
|
||
|
||
def lk_serif(cx, cy, cap=260, bold=1.0):
|
||
"""High-contrast (Didone) L and K: heavy stems, hairline serifs and arm."""
|
||
ws, wh = 46 * bold, 7.5 * bold ** 1.6 # stem, hairline
|
||
e = 0.105 * cap # serif reach beside a stem
|
||
sh = wh * 1.15 # serif thickness
|
||
top, base = 0.0, cap
|
||
polys = []
|
||
# L
|
||
foot_end = ws + 0.47 * cap
|
||
beak = 0.22 * cap
|
||
polys += [
|
||
rect(0, top, ws, base),
|
||
rect(-e, top, ws + e, top + sh), # top serif
|
||
rect(-e, base - wh * 1.5, foot_end, base), # foot (a bit heavier than a hairline)
|
||
[(foot_end - wh * 3.0, base - wh * 1.5), (foot_end - wh * 1.0, base - beak),
|
||
(foot_end, base - beak), (foot_end, base)], # beak: wedge rising from the foot
|
||
]
|
||
# K
|
||
xk = foot_end + 0.20 * cap
|
||
sc = xk + ws / 2
|
||
arm_end = (xk + 0.58 * cap, top + sh)
|
||
joint = (sc, top + 0.60 * cap)
|
||
leg_start = point_on(joint, arm_end, 0.40)
|
||
leg_end = (xk + 0.64 * cap, base - sh * 0.5)
|
||
leg = band(leg_start, leg_end, ws * 0.92, along(joint, arm_end), hcut(base - sh * 0.5))
|
||
polys += [
|
||
rect(xk, top, xk + ws, base),
|
||
rect(xk - e, top, xk + ws + e, top + sh),
|
||
rect(xk - e, base - sh, xk + ws + e, base),
|
||
band(joint, arm_end, wh * 1.7, vcut(sc), hcut(top + sh)),
|
||
rect(arm_end[0] - e * 1.25, top, arm_end[0] + e * 0.85, top + sh), # arm serif
|
||
leg,
|
||
]
|
||
low = [x for x, y in leg if y > base - sh]
|
||
polys.append(rect(min(low) - e * 0.75, base - sh, max(low) + e * 0.75, base)) # leg serif
|
||
return centred(polys, cx, cy)
|
||
|
||
# ---------------------------------------------------------------- raster helpers
|
||
|
||
|
||
def raster(polys, ss=SS, holes=()):
|
||
m = Image.new("L", (GRID * ss, GRID * ss), 0)
|
||
d = ImageDraw.Draw(m)
|
||
for p in polys:
|
||
d.polygon([(x * ss, y * ss) for x, y in p], fill=255)
|
||
for p in holes:
|
||
d.polygon([(x * ss, y * ss) for x, y in p], fill=0)
|
||
return m
|
||
|
||
|
||
def gradient(size, top, bottom, light=0.0, seed=7):
|
||
"""Vertical gradient with a soft light from the top centre; dithered so dark tones don't band."""
|
||
yy, xx = np.mgrid[0:size, 0:size].astype(np.float32) / (size - 1)
|
||
t = yy[..., None]
|
||
a, b = np.array(top, np.float32), np.array(bottom, np.float32)
|
||
g = a + (b - a) * t
|
||
if light:
|
||
d = np.sqrt(((xx - 0.5) * 1.15) ** 2 + (yy + 0.10) ** 2)
|
||
g[..., :3] += (light * np.clip(1 - d / 0.95, 0, 1) ** 2)[..., None]
|
||
g[..., :3] += np.random.default_rng(seed).uniform(-0.5, 0.5, (size, size, 1)).astype(np.float32)
|
||
return Image.fromarray(np.clip(g, 0, 255).round().astype(np.uint8), "RGBA")
|
||
|
||
|
||
def solid(size, rgba):
|
||
return Image.new("RGBA", (size, size), rgba)
|
||
|
||
|
||
def paint(canvas, fill, mask):
|
||
layer = Image.new("RGBA", canvas.size, (0, 0, 0, 0))
|
||
layer.paste(fill, (0, 0), mask)
|
||
return Image.alpha_composite(canvas, layer)
|
||
|
||
|
||
def faded(mask, alpha):
|
||
return mask.point(lambda v: int(v * alpha))
|
||
|
||
|
||
# app palette (Sources/Lichtkasten/Views/Theme.swift): warm graphite ground, amber light
|
||
GOLD = (242, 181, 68) # LK.amber
|
||
GOLD_LIGHT = (255, 228, 156)
|
||
GOLD_DEEP = (190, 126, 36)
|
||
|
||
BODIES = {
|
||
# top colour, bottom colour, top light, rim colour, rim opacity
|
||
"dark": ((36, 36, 39), (8, 8, 9), 10, (255, 255, 255), 0.16),
|
||
"light": ((255, 255, 255), (226, 226, 230), 0, (0, 0, 0), 0.10),
|
||
"warm": ((40, 33, 24), (10, 8, 6), 8, GOLD, 0.26),
|
||
}
|
||
|
||
|
||
@lru_cache(maxsize=None)
|
||
def body(style, ss=SS):
|
||
"""Shadow, squircle body with gradient, inner hairline (rim)."""
|
||
top, bottom, light, rim, rim_alpha = BODIES[style]
|
||
S = GRID * ss
|
||
img = Image.new("RGBA", (S, S), (0, 0, 0, 0))
|
||
shape = squircle(BODY)
|
||
m = raster([shape], ss)
|
||
# drop shadow in the template margin
|
||
sh = raster([[(x, y + 10) for x, y in shape]], ss).filter(ImageFilter.GaussianBlur(14 * ss))
|
||
img = paint(img, solid(S, (0, 0, 0, 255)), faded(sh, 0.32))
|
||
img = paint(img, gradient(S, top + (255,), bottom + (255,), light=light), m)
|
||
# hairline just inside the edge (defines the shape on any Dock background)
|
||
inner = raster([squircle((BODY[0] + 2.2, BODY[1] + 2.2, BODY[2] - 2.2, BODY[3] - 2.2), 185.4 - 2.2)], ss)
|
||
img = paint(img, solid(S, rim + (255,)), faded(ImageChops.subtract(m, inner), rim_alpha))
|
||
return img, m
|
||
|
||
|
||
def gold_fill(mask, ss=SS):
|
||
"""Gold with light from above: light gold at the top of the letters, amber, deep gold at the bottom."""
|
||
S = GRID * ss
|
||
ys = np.nonzero(np.asarray(mask).max(axis=1))[0]
|
||
y0, y1 = (ys.min(), ys.max()) if len(ys) else (0, S - 1)
|
||
t = np.clip((np.arange(S, dtype=np.float32) - y0) / max(1, y1 - y0), 0, 1)
|
||
stops = [(0.0, GOLD_LIGHT), (0.45, GOLD), (1.0, GOLD_DEEP)]
|
||
col = np.zeros((S, 3), np.float32)
|
||
for (t0, c0), (t1, c1) in zip(stops, stops[1:]):
|
||
sel = (t >= t0) & (t <= t1)
|
||
f = ((t[sel] - t0) / (t1 - t0))[:, None]
|
||
col[sel] = np.array(c0, np.float32) * (1 - f) + np.array(c1, np.float32) * f
|
||
img = np.empty((S, S, 4), np.uint8)
|
||
img[..., :3] = np.repeat(col[:, None, :], S, axis=1).round().astype(np.uint8)
|
||
img[..., 3] = 255
|
||
return Image.fromarray(img, "RGBA")
|
||
|
||
|
||
def smoothstep(e0, e1, x):
|
||
t = np.clip((x - e0) / (e1 - e0), 0, 1)
|
||
return t * t * (3 - 2 * t)
|
||
|
||
|
||
def tunnel(ss=SS, front=292.0, step=0.30, frames=18, line=7.0, inner_fade=(86.0, 170.0), walls=1.0, bloom=0.38):
|
||
"""A square box seen from the front that goes on forever: golden frames at equal depth steps
|
||
(screen size front/(1+i·step)), corner edges to the vanishing point, walls lit from the opening."""
|
||
S = GRID * ss
|
||
c = (np.arange(S, dtype=np.float32) + 0.5) / ss - GRID / 2
|
||
X, Y = np.meshgrid(c, c)
|
||
ax, ay = np.abs(X), np.abs(Y)
|
||
d = np.maximum(ax, ay) # square "radius"
|
||
inside = d <= front
|
||
near = np.clip(d / front, 0, 1) # 1 at the opening, 0 at infinity
|
||
# walls: top lit most, sides less, floor least – all fading into the depth
|
||
top_wall = (Y < 0) & (ay >= ax)
|
||
floor = (Y > 0) & (ay >= ax)
|
||
wall = np.where(top_wall, 1.0, np.where(floor, 0.42, 0.66))[..., None]
|
||
base = np.array((66, 50, 30), np.float32)
|
||
rgb = base * walls * wall * (near ** 1.7)[..., None]
|
||
# golden frames
|
||
lines = np.zeros_like(d)
|
||
for i in range(frames):
|
||
z = 1 + i * step
|
||
f = front / z
|
||
if f < inner_fade[0]:
|
||
break
|
||
t = line * z ** -1.0
|
||
strength = z ** -1.15 * (1.0 if i == 0 else 0.9) * smoothstep(inner_fade[0], inner_fade[1], f)
|
||
lines = np.maximum(lines, (np.abs(d - f) <= t / 2) * strength)
|
||
# corner edges of the box
|
||
edge_t = line * 0.8 * np.maximum(near, 0.05) ** 0.85
|
||
edges = (np.abs(ax - ay) / math.sqrt(2) <= edge_t / 2) & inside
|
||
lines = np.maximum(lines, edges * near ** 1.3 * smoothstep(inner_fade[0], inner_fade[1] * 1.15, d))
|
||
gold = np.array(GOLD, np.float32)
|
||
rgb = rgb * (1 - lines[..., None]) + gold * lines[..., None]
|
||
# the gold lines glow a little: light box
|
||
glow = np.asarray(Image.fromarray((lines * 255).astype(np.uint8)).filter(ImageFilter.GaussianBlur(7 * ss)),
|
||
np.float32) / 255
|
||
rgb = rgb + gold * (bloom * glow * inside)[..., None]
|
||
rgb += np.random.default_rng(11).uniform(-0.5, 0.5, rgb.shape[:2] + (1,)).astype(np.float32) # no banding
|
||
alpha = (d <= front + line / 2).astype(np.float32)
|
||
out = np.dstack([np.clip(rgb, 0, 255), alpha * 255]).round().astype(np.uint8)
|
||
return Image.fromarray(out, "RGBA")
|
||
|
||
|
||
# ---------------------------------------------------------------- variants
|
||
|
||
INK_LIGHT = (246, 245, 242, 255) # warm white
|
||
INK_DARK = (17, 17, 18, 255)
|
||
|
||
|
||
def lettering(img, m, polys, ss, shadow=True):
|
||
"""Gold letters floating in front: soft shadow, dark halo that separates them from the lines, gold fill."""
|
||
letters = raster(polys, ss)
|
||
if shadow:
|
||
sh = letters.filter(ImageFilter.GaussianBlur(9 * ss))
|
||
shadow_layer = Image.new("RGBA", img.size, (0, 0, 0, 0))
|
||
shadow_layer.paste(solid(img.width, (4, 3, 2, 255)), (0, 7 * ss), faded(sh, 0.75))
|
||
img = Image.alpha_composite(img, shadow_layer)
|
||
halo = letters.filter(ImageFilter.GaussianBlur(10 * ss)).point(lambda v: min(255, v * 2))
|
||
img = paint(img, solid(img.width, (8, 6, 4, 255)), ImageChops.multiply(faded(halo, 0.9), m))
|
||
return paint(img, gold_fill(letters, ss), ImageChops.multiply(letters, m))
|
||
|
||
|
||
def v_tunnel(bold=1.0, size=1024, ss=SS):
|
||
img, m = body("warm", ss)
|
||
small = size <= 64
|
||
box = tunnel(ss, frames=(2 if size <= 32 else 3) if small else 18,
|
||
line=7.0 * (1.9 if small else 1.0) * (1.25 if size == 128 else 1.0),
|
||
step=0.42 if small else 0.30)
|
||
img = Image.alpha_composite(img, box)
|
||
return lettering(img, m, lk_ligature(512, 512, cap=272, w=31, bold=bold), ss)
|
||
|
||
|
||
def v_fein(bold=1.0, size=1024, ss=SS):
|
||
"""Calmer 3D box: thin lines, barely lit walls, no glow."""
|
||
img, m = body("warm", ss)
|
||
small = size <= 64
|
||
box = tunnel(ss, front=286, frames=(2 if size <= 32 else 3) if small else 12, step=0.42 if small else 0.34,
|
||
line=(5.0 if not small else 9.0) * (1.25 if size == 128 else 1.0),
|
||
inner_fade=(120.0, 200.0), walls=0.45, bloom=0.0)
|
||
img = Image.alpha_composite(img, box)
|
||
return lettering(img, m, lk_ligature(512, 512, cap=262, w=30, bold=bold), ss)
|
||
|
||
|
||
def v_gold(bold=1.0, size=1024, ss=SS):
|
||
img, m = body("warm", ss)
|
||
return lettering(img, m, lk_ligature(512, 506, bold=bold), ss, shadow=False)
|
||
|
||
|
||
def v_monogramm(bold=1.0, size=1024, ss=SS):
|
||
img, m = body("dark", ss)
|
||
letters = raster(lk_ligature(512, 506, bold=bold), ss)
|
||
return paint(img, solid(img.width, INK_LIGHT), ImageChops.multiply(letters, m))
|
||
|
||
|
||
def v_hell(bold=1.0, size=1024, ss=SS):
|
||
img, m = body("light", ss)
|
||
letters = raster(lk_ligature(512, 506, bold=bold), ss)
|
||
return paint(img, solid(img.width, INK_DARK), ImageChops.multiply(letters, m))
|
||
|
||
|
||
def v_kasten(bold=1.0, size=1024, ss=SS):
|
||
img, m = body("dark", ss)
|
||
letters = lk_pair(512, 512, cap=214, w=19, bold=bold)
|
||
f, t = 262, 9.0 * bold ** 0.7 # frame: half size, line width
|
||
frame = raster([rect(512 - f, 512 - f, 512 + f, 512 + f)], ss,
|
||
holes=[rect(512 - f + t, 512 - f + t, 512 + f - t, 512 + f - t)])
|
||
mark = ImageChops.lighter(raster(letters, ss), frame)
|
||
return paint(img, solid(img.width, INK_LIGHT), ImageChops.multiply(mark, m))
|
||
|
||
|
||
def v_serif(bold=1.0, size=1024, ss=SS):
|
||
img, m = body("dark", ss)
|
||
letters = raster(lk_serif(512, 512, cap=262, bold=bold), ss)
|
||
return paint(img, solid(img.width, INK_LIGHT), ImageChops.multiply(letters, m))
|
||
|
||
|
||
# ---------------------------------------------------------------- Blende (camera aperture)
|
||
|
||
|
||
def radial(size, ss, center, radius, inner, outer, power=1.0, seed=5):
|
||
"""Radial gradient in design units, dithered."""
|
||
c = (np.arange(size, dtype=np.float32) + 0.5) / ss
|
||
X, Y = np.meshgrid(c - center[0], c - center[1])
|
||
t = np.clip(np.hypot(X, Y) / radius, 0, 1) ** power
|
||
a, b = np.array(inner, np.float32), np.array(outer, np.float32)
|
||
g = a + (b - a) * t[..., None]
|
||
g += np.random.default_rng(seed).uniform(-0.5, 0.5, (size, size, 1)).astype(np.float32)
|
||
return Image.fromarray(np.dstack([np.clip(g, 0, 255), np.full((size, size), 255, np.float32)]).round().astype(np.uint8), "RGBA")
|
||
|
||
|
||
def inset(box, d):
|
||
return (box[0] + d, box[1] + d, box[2] - d, box[3] - d)
|
||
|
||
|
||
@lru_cache(maxsize=None)
|
||
def bezel(ss=SS):
|
||
"""Dark metal tile: shadow, rim with a bright outer edge, recessed graphite face."""
|
||
S = GRID * ss
|
||
img = Image.new("RGBA", (S, S), (0, 0, 0, 0))
|
||
shape = squircle(BODY)
|
||
m = raster([shape], ss)
|
||
sh = raster([[(x, y + 12) for x, y in shape]], ss).filter(ImageFilter.GaussianBlur(16 * ss))
|
||
img = paint(img, solid(S, (0, 0, 0, 255)), faded(sh, 0.36))
|
||
img = paint(img, gradient(S, (58, 56, 54, 255), (9, 9, 9, 255)), m)
|
||
# bright outer edge, strongest at the top
|
||
edge = ImageChops.subtract(m, raster([squircle(inset(BODY, 3.2), 185.4 - 3.2)], ss))
|
||
fade = Image.fromarray(np.repeat(np.linspace(250, 110, S, dtype=np.float32)[:, None], S, axis=1).astype(np.uint8))
|
||
img = paint(img, solid(S, (238, 234, 228, 255)), ImageChops.multiply(edge, fade))
|
||
# recessed face with a dark groove around it
|
||
fb, fr = inset(BODY, 26), 185.4 - 26
|
||
groove = raster([squircle(inset(fb, -2.6), fr + 2.6)], ss)
|
||
img = paint(img, solid(S, (6, 6, 6, 255)), faded(groove, 0.85))
|
||
face = raster([squircle(fb, fr)], ss)
|
||
img = paint(img, radial(S, ss, (512, 330), 660, (70, 67, 63), (13, 12, 11), power=1.05), face)
|
||
lip = ImageChops.subtract(face, raster([squircle(inset(fb, 1.8), fr - 1.8)], ss))
|
||
img = paint(img, solid(S, (255, 255, 255, 255)), faded(lip, 0.16))
|
||
return img, m
|
||
|
||
|
||
def _land(q0, q1, R):
|
||
lo, hi = 0.0, 1.0
|
||
for _ in range(40):
|
||
mid = (lo + hi) / 2
|
||
if math.hypot(*point_on(q0, q1, mid)) < R:
|
||
lo = mid
|
||
else:
|
||
hi = mid
|
||
return point_on(q0, q1, hi)
|
||
|
||
|
||
def aperture(R, r0, n=8, rot=-90.0, bend=0.0, step=1.0):
|
||
"""Iris: hole polygon (n corners on radius r0), the n blade boundaries (each continues a hole edge and
|
||
bends on its way to the rim) and the n blade polygons. Coordinates relative to the centre."""
|
||
V = [(r0 * math.cos(math.radians(rot + 360 * i / n)), r0 * math.sin(math.radians(rot + 360 * i / n)))
|
||
for i in range(n)]
|
||
curves = []
|
||
for i in range(n):
|
||
a, b = V[i], V[(i + 1) % n]
|
||
ang = math.atan2(b[1] - a[1], b[0] - a[0])
|
||
p, pts = b, [b]
|
||
while math.hypot(*p) < R:
|
||
ang += bend * step
|
||
p = (p[0] + math.cos(ang) * step, p[1] + math.sin(ang) * step)
|
||
pts.append(p)
|
||
pts[-1] = _land(pts[-2], pts[-1], R)
|
||
curves.append(pts)
|
||
blades = []
|
||
for i in range(n):
|
||
prev, cur = curves[i - 1], curves[i]
|
||
a0 = math.atan2(prev[-1][1], prev[-1][0])
|
||
arc = [(R * math.cos(a0 + k / 64 * 2 * math.pi / n), R * math.sin(a0 + k / 64 * 2 * math.pi / n))
|
||
for k in range(65)]
|
||
blades.append(prev + arc + cur[::-1])
|
||
return V, curves, blades
|
||
|
||
|
||
def strip(curve, width, side):
|
||
"""Band of `width` along one side of a polyline (for the shadow a blade casts on its neighbour)."""
|
||
off = []
|
||
for k, p in enumerate(curve):
|
||
q0, q1 = curve[max(0, k - 1)], curve[min(len(curve) - 1, k + 1)]
|
||
tx, ty = _norm_vec(q1[0] - q0[0], q1[1] - q0[1])
|
||
off.append((p[0] - ty * width * side, p[1] + tx * width * side))
|
||
return curve + off[::-1]
|
||
|
||
|
||
def _norm_vec(x, y):
|
||
l = math.hypot(x, y) or 1.0
|
||
return x / l, y / l
|
||
|
||
|
||
def mix(a, b, t):
|
||
a, b = np.array(a, np.float32), np.array(b, np.float32)
|
||
return a + (b - a) * t[..., None]
|
||
|
||
|
||
def v_blende(bold=1.0, size=1024, ss=SS, n=8, bend=0.0020, rot=-90.0):
|
||
"""Camera aperture, half in shadow and half in warm light – the light box."""
|
||
S = GRID * ss
|
||
base_img, m = bezel(ss)
|
||
img = base_img.copy()
|
||
cx, cy, R = 512.0, 512.0, 288.0
|
||
ring = 12.0 * bold ** 0.7
|
||
line_w = 2.9 * bold ** 1.2
|
||
c = (np.arange(S, dtype=np.float32) + 0.5) / ss
|
||
X, Y = np.meshgrid(c - cx, c - cy)
|
||
rho = np.hypot(X, Y)
|
||
lit = smoothstep(-3.0, 3.0, X) # 0 = shadow half, 1 = lit half
|
||
|
||
# warm light spilling out of the lit half onto the face
|
||
outside = np.clip(rho - R, 0, None)
|
||
side = smoothstep(-0.45 * R, 0.85 * R, X)
|
||
wide = np.exp(-(outside / 74.0) ** 1.2) * side
|
||
tight = np.exp(-(outside / 13.0) ** 1.4) * side
|
||
face = np.asarray(img, np.float32)
|
||
amber, cream = np.array((255, 166, 72), np.float32), np.array((255, 236, 196), np.float32)
|
||
face[..., :3] = face[..., :3] + (amber - face[..., :3]) * (0.72 * wide)[..., None]
|
||
face[..., :3] = face[..., :3] + (cream - face[..., :3]) * (0.85 * tight)[..., None]
|
||
|
||
# blades: shadow half dark graphite, lit half cream → warm gold towards the rim and the split
|
||
t = np.clip(rho / R, 0, 1)
|
||
dark = mix((8, 8, 9), (50, 49, 47), t ** 1.5)
|
||
light = mix((255, 255, 252), (250, 206, 150), t ** 2.1)
|
||
near_split = (1 - smoothstep(0, 0.5 * R, X)) * 0.55
|
||
light = light + (np.array((232, 158, 88), np.float32) - light) * near_split[..., None]
|
||
blades = dark * (1 - lit[..., None]) + light * lit[..., None]
|
||
|
||
V, curves, polys = aperture(R, 0.18 * R, n=n, rot=rot, bend=bend)
|
||
to_px = lambda pts: [(x + cx, y + cy) for x, y in pts]
|
||
# each blade a touch different (overlapping leaves catch the light differently)
|
||
for i, poly in enumerate(polys):
|
||
bm = np.asarray(raster([to_px(poly)], ss), np.float32) / 255
|
||
blades *= (1 + (0.035 if i % 2 else -0.025) * bm * (1 + 0.6 * lit))[..., None]
|
||
# soft shadow next to every boundary, then the boundary line itself
|
||
shade = Image.new("L", (S, S), 0)
|
||
lines = Image.new("L", (S, S), 0)
|
||
dl = ImageDraw.Draw(lines)
|
||
for cur in curves:
|
||
ImageDraw.Draw(shade).polygon([(x * ss, y * ss) for x, y in to_px(strip(cur, 17.0, 1))], fill=255)
|
||
dl.line([(x * ss, y * ss) for x, y in to_px(cur)], fill=255, width=max(1, round(line_w * ss)))
|
||
hole_pts = to_px(V)
|
||
dl.line([(x * ss, y * ss) for x, y in hole_pts + hole_pts[:1]], fill=255, width=max(1, round(line_w * ss)))
|
||
shade = np.asarray(shade.filter(ImageFilter.GaussianBlur(6 * ss)), np.float32) / 255
|
||
blades *= (1 - shade * (0.34 + 0.22 * (1 - lit)))[..., None]
|
||
lines = np.asarray(lines, np.float32) / 255
|
||
line_col = mix((150, 147, 142), (112, 64, 28), lit) # highlight in the shadow, groove in the light
|
||
blades = blades + (line_col - blades) * (lines * (0.70 + 0.22 * lit))[..., None]
|
||
# sheen on the shadow half
|
||
sheen = np.exp(-(((X + 0.42 * R) / (0.55 * R)) ** 2 + ((Y + 0.55 * R) / (0.30 * R)) ** 2)) * (1 - lit)
|
||
blades = blades + (255 - blades) * (0.10 * sheen)[..., None]
|
||
|
||
disc_mask = np.asarray(raster([to_px([(R * math.cos(a), R * math.sin(a))
|
||
for a in np.linspace(0, 2 * math.pi, 720, endpoint=False)])], ss), np.float32) / 255
|
||
hole = np.asarray(raster([hole_pts], ss), np.float32) / 255
|
||
out = face[..., :3] * (1 - disc_mask[..., None]) + blades * disc_mask[..., None]
|
||
out = out + (np.array((5, 5, 6), np.float32) - out) * hole[..., None]
|
||
|
||
# ring: metal on the shadow side, glowing on the lit side
|
||
ring_a = np.clip(1 - np.abs(rho - R) / (ring / 2), 0, 1) ** 0.6
|
||
ring_dark = mix((30, 30, 31), (132, 129, 124), np.clip(0.5 - Y / (2 * R), 0, 1))
|
||
ring_col = ring_dark * (1 - lit[..., None]) + np.array((255, 248, 232), np.float32) * lit[..., None]
|
||
out = out + (ring_col - out) * ring_a[..., None]
|
||
# thin dark line where the blades meet the ring
|
||
seat = np.clip(1 - np.abs(rho - (R - ring / 2)) / 1.4, 0, 1)
|
||
out = out * (1 - 0.55 * seat)[..., None]
|
||
|
||
res = np.dstack([np.clip(out, 0, 255), np.asarray(img, np.float32)[..., 3]]).round().astype(np.uint8)
|
||
return Image.fromarray(res, "RGBA")
|
||
|
||
|
||
VARIANTS = {
|
||
"blende": ("Blende", v_blende),
|
||
"tunnel": ("Unendlicher Kasten", v_tunnel),
|
||
"fein": ("Feiner Kasten", v_fein),
|
||
"gold": ("Gold", v_gold),
|
||
"monogramm": ("Monogramm", v_monogramm),
|
||
"hell": ("Hell", v_hell),
|
||
"kasten": ("Kasten", v_kasten),
|
||
"serif": ("Serif", v_serif),
|
||
}
|
||
|
||
# ---------------------------------------------------------------- output
|
||
|
||
|
||
def render(name, size=1024):
|
||
"""Icon at `size` px. Small sizes are drawn with heavier strokes (optical sizing)."""
|
||
fn = VARIANTS[name][1]
|
||
bold = 1.0 if size >= 256 else (1.18 if size >= 128 else (1.40 if size >= 64 else 1.75))
|
||
ss = SS if size >= 512 else (2 if size >= 256 else 1)
|
||
big = fn(bold=bold, size=size, ss=ss)
|
||
img = big.reduce(ss) if ss > 1 else big # box filter: exact coverage, no ringing
|
||
return img if size == 1024 else img.resize((size, size), Image.LANCZOS)
|
||
|
||
|
||
def write(name):
|
||
icon = render(name)
|
||
extra = [render(name, s) for s in (32, 64, 128, 256, 512)]
|
||
out = ROOT / "Resources"
|
||
(out / "Icon").mkdir(parents=True, exist_ok=True)
|
||
icon.save(out / "Icon" / "AppIcon-1024.png")
|
||
extra[3].save(out / "Icon" / "AppIcon-256.png")
|
||
icon.save(out / "AppIcon.icns", append_images=extra)
|
||
print(f"AppIcon.icns ← {VARIANTS[name][0]}")
|
||
|
||
|
||
def preview(path, names=None):
|
||
"""Comparison sheet: variants large, plus Dock sizes on a light and a dark background."""
|
||
from PIL import ImageFont
|
||
|
||
def font(size):
|
||
for f in ("/usr/share/fonts/opentype/inter/Inter-SemiBold.otf", "/System/Library/Fonts/SFNS.ttf",
|
||
"/System/Library/Fonts/Helvetica.ttc"):
|
||
try:
|
||
return ImageFont.truetype(f, size)
|
||
except OSError:
|
||
pass
|
||
return ImageFont.load_default()
|
||
|
||
names, col, pad = names or list(VARIANTS), 480, 44
|
||
sheet = Image.new("RGBA", (pad + len(names) * (col + pad), 1010), (232, 232, 235, 255))
|
||
d = ImageDraw.Draw(sheet)
|
||
for i, n in enumerate(names):
|
||
x = pad + i * (col + pad)
|
||
d.text((x + 8, 34), f"{chr(65 + i)} {VARIANTS[n][0]}", font=font(34), fill=(22, 22, 24, 255))
|
||
sheet.alpha_composite(render(n).resize((col, col), Image.LANCZOS), (x, 92))
|
||
for j, bg in enumerate([(250, 250, 252, 255), (28, 28, 30, 255)]):
|
||
y = 92 + col + 24 + j * 186
|
||
d.rounded_rectangle((x, y, x + col, y + 166), radius=30, fill=bg)
|
||
ix = x + 22
|
||
for s in (128, 64, 32):
|
||
sheet.alpha_composite(render(n, s), (ix, y + (166 - s) // 2))
|
||
ix += s + 30
|
||
sheet.convert("RGB").save(path)
|
||
print(f"Vorschau → {path}")
|
||
|
||
|
||
if __name__ == "__main__":
|
||
args = sys.argv[1:]
|
||
if args[:1] == ["--preview"]:
|
||
preview(args[1] if len(args) > 1 else "icon-preview.png", args[2:] or None)
|
||
sys.exit()
|
||
name = args[0] if args else DEFAULT
|
||
if name not in VARIANTS:
|
||
sys.exit(f"Unbekannte Variante {name!r}. Möglich: {', '.join(VARIANTS)}")
|
||
write(name)
|