"""THROWAWAY SPIKE: Casio-style clock mockup (static weather). Not production code.""" import os import sys from datetime import datetime from PIL import Image, ImageDraw, ImageFont W, H = 480, 320 BG = (170, 184, 154) INK = (28, 36, 24) GHOST = (158, 172, 143) # unlit segments, barely darker than the background SLANT = 0.14 # mock forecast (spike): rain probability % for the next 12 h, and mm per hour RAIN = [0, 0, 10, 20, 40, 70, 60, 50, 30, 20, 10, 0] MM = [0, 0, 0, 0.1, 0.4, 1.2, 0.9, 0.5, 0.1, 0, 0, 0] SEGS = { "0": "abcdef", "1": "bc", "2": "abdeg", "3": "abcdg", "4": "bcfg", "5": "acdfg", "6": "acdefg", "7": "abc", "8": "abcdefg", "9": "abcdfg", } def slant(pts, base_y): return [(x + SLANT * (base_y - y), y) for x, y in pts] def hexseg(horizontal, c0, c1, c, t): if horizontal: pts = [(c0, c), (c0 + t / 2, c - t / 2), (c1 - t / 2, c - t / 2), (c1, c), (c1 - t / 2, c + t / 2), (c0 + t / 2, c + t / 2)] else: pts = [(c, c0), (c + t / 2, c0 + t / 2), (c + t / 2, c1 - t / 2), (c, c1), (c - t / 2, c1 - t / 2), (c - t / 2, c0 + t / 2)] return pts def digit(d, x, y, w, h, t, ch, ghost=True): g = 1.5 top, mid, bot = y + t / 2, y + h / 2, y + h - t / 2 left, right = x + t / 2, x + w - t / 2 geo = { "a": hexseg(True, left + g, right - g, top, t), "g": hexseg(True, left + g, right - g, mid, t), "d": hexseg(True, left + g, right - g, bot, t), "f": hexseg(False, top + g, mid - g, left, t), "b": hexseg(False, top + g, mid - g, right, t), "e": hexseg(False, mid + g, bot - g, left, t), "c": hexseg(False, mid + g, bot - g, right, t), } on = SEGS.get(ch, "") for name, pts in geo.items(): lit = name in on if lit or ghost: d.polygon(slant(pts, y + h), fill=INK if lit else GHOST) def number(d, text, x, y, w, h, t, gap, ghost=True): """Draw digits and colons; returns x after the last glyph.""" for ch in text: if ch == ":": s = t * 1.1 cx = x + s for cy in (y + h * 0.32, y + h * 0.68): pts = [(cx - s / 2, cy - s / 2), (cx + s / 2, cy - s / 2), (cx + s / 2, cy + s / 2), (cx - s / 2, cy + s / 2)] d.polygon(slant(pts, y + h), fill=INK) x += s * 2 + gap elif ch == ".": s = t * 1.0 pts = [(x, y + h - s), (x + s, y + h - s), (x + s, y + h), (x, y + h)] d.polygon(slant(pts, y + h), fill=INK) x += s + gap elif ch == "-": c = y + h / 2 d.polygon(slant(hexseg(True, x + t, x + w - t, c, t), y + h), fill=INK) x += w + gap else: digit(d, x, y, w, h, t, ch, ghost) x += w + gap return x def font(size): for p in ("/opt/lcd/res/fonts/roboto/Roboto-Bold.ttf", "/System/Library/Fonts/Supplemental/Arial Bold.ttf", "/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf"): if os.path.exists(p): return ImageFont.truetype(p, size) return ImageFont.load_default() def sun_cloud(d, x, y, s): """Partly-cloudy icon in a 'pixel LCD' feel, s = size.""" cx, cy, r = x + s * 0.36, y + s * 0.36, s * 0.2 d.ellipse((cx - r, cy - r, cx + r, cy + r), fill=INK) for dx, dy in ((0, -1), (0, 1), (-1, 0), (1, 0), (-.7, -.7), (.7, -.7), (-.7, .7)): d.line((cx + dx * r * 1.35, cy + dy * r * 1.35, cx + dx * r * 1.8, cy + dy * r * 1.8), fill=INK, width=max(2, int(s / 16))) # cloud with a light outline separating it from the sun by = y + s * 0.82 for pad, col in ((3, BG), (0, INK)): d.ellipse((x + s * 0.30 - pad, by - s * 0.34 - pad, x + s * 0.68 + pad, by + pad), fill=col) d.ellipse((x + s * 0.52 - pad, by - s * 0.26 - pad, x + s * 0.95 + pad, by + pad), fill=col) d.rounded_rectangle((x + s * 0.18 - pad, by - s * 0.20 - pad, x + s * 0.95 + pad, by + pad), radius=int(s * 0.1), fill=col) def render(now): img = Image.new("RGB", (W, H), BG) d = ImageDraw.Draw(img) f_small, f_tiny = font(15), font(12) # inner LCD window frame d.rectangle((6, 6, W - 7, H - 7), outline=INK, width=2) # top: weekday row, current day inverted days = ["PO", "ÚT", "ST", "ČT", "PÁ", "SO", "NE"] cell = (W - 24) // 7 for i, name in enumerate(days): x0 = 12 + i * cell if i == now.weekday(): d.rectangle((x0, 14, x0 + cell - 6, 38), fill=INK) col = BG else: col = INK tw = d.textlength(name, font=f_small) d.text((x0 + (cell - 6 - tw) / 2, 17), name, font=f_small, fill=col) d.line((12, 46, W - 13, 46), fill=INK, width=2) # row A: time (left), seconds + date (right) x = number(d, now.strftime("%H:%M"), 24, 54, 54, 96, 12, 9) number(d, now.strftime("%S"), 378, 58, 24, 42, 6, 6) number(d, now.strftime("%-d.%-m."), 372, 112, 14, 34, 4, 4, ghost=False) d.line((12, 160, W - 13, 160), fill=INK, width=2) # row B left: current weather + rain readout d.text((22, 166), "ZLÍN NYNÍ", font=f_tiny, fill=INK) sun_cloud(d, 20, 182, 56) number(d, "14", 90, 184, 26, 46, 6, 7, ghost=False) d.ellipse((160, 184, 170, 194), outline=INK, width=3) d.text((22, 244), "MAX 16° MIN 7°", font=f_small, fill=INK) d.text((22, 264), "DEŠŤ", font=f_tiny, fill=INK) x = number(d, str(max(RAIN)), 22, 279, 18, 28, 4, 6, ghost=False) d.text((x + 4, 288), "%", font=f_small, fill=INK) # divider + row B right: 12 h rain probability bar graph (LCD-style segments) d.line((206, 168, 206, H - 14), fill=INK, width=2) d.text((220, 166), "DEŠŤ % / HOD", font=f_tiny, fill=INK) mm = f"{sum(MM):.1f} mm" d.text((W - 18 - d.textlength(mm, font=f_small), 164), mm, font=f_small, fill=INK) bar_w, pitch, seg_h, seg_gap, n_seg = 14, 21, 5, 1, 16 gy1 = 282 for i, pct in enumerate(RAIN): bx = 222 + i * pitch lit = round(pct / 100 * n_seg) for k in range(n_seg): y1 = gy1 - k * (seg_h + seg_gap) d.rectangle((bx, y1 - seg_h, bx + bar_w, y1), fill=INK if k < lit else GHOST) hour = (now.hour + i) % 24 if i % 3 == 0: lab = f"{hour:02d}" d.text((bx + bar_w / 2 - d.textlength(lab, font=f_tiny) / 2, 290), lab, font=f_tiny, fill=INK) return img if __name__ == "__main__": # fixed time for a stable preview; spike uses a Thursday afternoon now = datetime(2026, 10, 22, 14, 32, 8) if "--fixed" in sys.argv else datetime.now() img = render(now) out = os.environ.get("OUT") if out: img.save(out) print("saved", out) if os.environ.get("PUSH"): sys.path.insert(0, "/opt/lcd") from library.lcd.lcd_comm import Orientation from library.lcd.lcd_comm_rev_a import LcdCommRevA lcd = LcdCommRevA(com_port=os.environ["PORT"]) lcd.InitializeComm() lcd.SetOrientation(Orientation.LANDSCAPE) lcd.SetBrightness(50) lcd.DisplayPILImage(img, x=0, y=0) print("pushed")