Switch knob: scanline model from 42 measured sizes

Integer radius (h-1)//2 with fixed sub-pixel offsets, 4 sub-rows x 1/8 px spans, 1/32 coverage
in linear light; closer to the simulator than the previous distance model on the knob test page.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
mangavalkandClaude Opus 5.5 committed 2026-11-16 13:52:40 +01:00
1 parent 0138a0ba56
commit 922ca21f0f
3 files changed
+35 -4

No files matched your search

+28 -2
View File
@@ -624,6 +624,31 @@ class Renderer:
self._aa_fill(img, (int(cx - r) - 1, int(cy - r) - 1, int(cx + r) + 2, int(cy + r) + 2), col,
lambda px, py: math.hypot(px - cx, py - cy) - r, gamma=True)
def _scan_disc(self, img, cx, cy, R, col):
"""Filled circle the way the Intelligent simulator's switch knob looks: 4 sub-rows per pixel
row, each a span with ends rounded to 1/8 px, so coverage comes in steps of 1/32, blended
in linear light. Closest model found (most edge pixels exact, the rest a few levels off)."""
px = img.load()
W, H = img.size
for yy in range(max(0, int(cy - R) - 1), min(H, int(cy + R) + 2)):
cov = {}
for j in range(4):
d = R * R - (yy + j / 4 - cy) ** 2
if d <= 0:
continue
hw = math.sqrt(d)
l, r = round((cx - hw) * 8) / 8, round((cx + hw) * 8) / 8
for xx in range(int(math.floor(l)), int(math.ceil(r))):
o = min(xx + 1, r) - max(xx, l)
if o > 0:
cov[xx] = cov.get(xx, 0) + round(o * 8)
for xx, k in cov.items():
if 0 <= xx < W:
if k >= 32:
px[xx, yy] = col
else:
px[xx, yy] = tuple(_enc(_lin(f) * k / 32 + _lin(b) * (1 - k / 32)) for f, b in zip(col, px[xx, yy][:3]))
def switch(self, img, c):
"""Switch: rounded track (corner radius dis % of h/2) in bco / bco2 (on), knob pco / pco2
on the left (off) or right (on), text (txt "off/on") in pco1 centred on the free side."""
@@ -631,8 +656,9 @@ class Renderer:
on = bool(c.get("val"))
r = _radius(c, h)
self._round_rect(img, x, y, w, h, r, self.rgb((c.get("bco2") if on else c.get("bco")) or 0))
kx = x + (w - h / 2 + 0.5625 if on else h / 2 - 0.4375)
self._disc(img, kx, y + h / 2 - 0.8125, h / 2 - 1.3125, self.rgb((c.get("pco2") if on else c.get("pco")) or 0))
r = (h - 1) // 2 # knob: integer radius, fixed sub-pixel offsets
kx = x + (w - r - 0.625 if on else r + 0.625)
self._scan_disc(img, kx, y + r + 0.25, r - 0.25, self.rgb((c.get("pco2") if on else c.get("pco")) or 0))
parts = (c.get("txt") or "").split("/")
label = (parts[1] if len(parts) > 1 else "") if on else parts[0]
tx, tw = (x, w - h) if on else (x + h, w - h)