Files
lichtkasten/scripts/make-icon.py
T
Lichtkasten DevandClaude Opus 5.5 f18f1bd9a9 Neues App-Icon: LK-Monogramm in Schwarz-Weiß
- Icon aus Geometrie gezeichnet (keine Schriften nötig), Form wie Apples macOS-Vorlage mit
  kontinuierlichen Ecken, feine Innenkante, entrauschter Verlauf
- Optische Größen: 32/64/128 px mit kräftigeren Strichen, damit das Monogramm im Dock lesbar bleibt
- Varianten monogramm (Standard), hell, kasten, serif; --preview zeigt alle nebeneinander
- install.sh aktualisiert Finder/Dock-Icon-Cache, wenn sich das Icon geändert hat

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012bGzgsxrmbBhDzeMV2L57D
2026-11-05 00:38:44 +00:00

362 lines
14 KiB
Python

#!/usr/bin/env python3
"""Lichtkasten app icon: black and white LK monogram, drawn from geometry (no fonts needed).
python3 scripts/make-icon.py # default variant → Resources/AppIcon.icns + PNGs
python3 scripts/make-icon.py kasten # 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 = "monogramm"
# ---------------------------------------------------------------- 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))
@lru_cache(maxsize=None)
def body(dark, ss=SS):
"""Shadow, squircle body with gradient, inner hairline and soft top light."""
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))
if dark:
fill = gradient(S, (36, 36, 39, 255), (8, 8, 9, 255), light=10)
else:
fill = gradient(S, (255, 255, 255, 255), (226, 226, 230, 255), light=0)
img = paint(img, fill, 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)
ring = ImageChops.subtract(m, inner)
img = paint(img, solid(S, (255, 255, 255, 255) if dark else (0, 0, 0, 255)), faded(ring, 0.16 if dark else 0.10))
return img, m
# ---------------------------------------------------------------- variants
INK_LIGHT = (246, 245, 242, 255) # warm white
INK_DARK = (17, 17, 18, 255)
def v_monogramm(bold=1.0, ss=SS):
img, m = body(True, 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, ss=SS):
img, m = body(False, 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, ss=SS):
img, m = body(True, 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, ss=SS):
img, m = body(True, ss)
letters = raster(lk_serif(512, 512, cap=262, bold=bold), ss)
return paint(img, solid(img.width, INK_LIGHT), ImageChops.multiply(letters, m))
VARIANTS = {
"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))
big = fn(bold=bold)
img = big.reduce(SS) # 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):
"""Comparison sheet: every variant 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 = 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")
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)