diff --git a/hardware/README.md b/hardware/README.md index 8973166..fe6d47c 100644 --- a/hardware/README.md +++ b/hardware/README.md @@ -1,7 +1,7 @@ # ROT-8 硬件:这个目录里有什么 做完大概就是 panel-mockup.png 那样(panel_mockup.py 画的草图,200 x 100 mm 面板、inside 是 160 x 100 mm Eurocard): -![面板草图](panel-mockup.png) +两个版本:`panel-mockup.png` 是 LED 面板(1975 味),`panel-mockup-vintage.png` 是**辉光管 + 氖泡**版本(1960 味,推荐):`n`n![辉光管面板](panel-mockup-vintage.png)`n `docs/hardware.md` 的落地部分。三样东西都跑通了(Icarus Verilog 14.0): diff --git a/hardware/panel-mockup-vintage.png b/hardware/panel-mockup-vintage.png new file mode 100644 index 0000000..8e67507 Binary files /dev/null and b/hardware/panel-mockup-vintage.png differ diff --git a/hardware/panel_mockup_vintage.py b/hardware/panel_mockup_vintage.py new file mode 100644 index 0000000..4d0e30c --- /dev/null +++ b/hardware/panel_mockup_vintage.py @@ -0,0 +1,270 @@ +"""Vintage front panel: Nixie digits, neon ring, filament lamps, hammertone panel. + +Same machine as panel_mockup.py (200 x 100 mm, Eurocard inside), but the display. +Seven segment LEDs look 1975; the ROT-8 panel is nicer as a 1960 panel: Nixie +tubes for the digits (K155ID1 drivers and a 170 V rail), neon lamps for the ring +and the bit rows, grain of wheat bulbs for the instruction lamps, bakelite +buttons, hammertone paint and engraved lettering. + + python hardware/panel_mockup_vintage.py hardware/panel-mockup-vintage.png +""" +import math +import sys + +from PIL import Image, ImageDraw, ImageFilter, ImageFont + +S = 7 +W, H = 200 * S, 100 * S + +PAINT = (46, 44, 42) # hammertone, dark warm grey +PAINT_EDGE = (22, 21, 20) +ENGRAVE = (216, 205, 178) # ivory filled engraving +ENGRAVE_DIM = (150, 141, 122) +GLASS = (26, 24, 28) +NIXIE = (255, 118, 24) +NIXIE_DIM = (86, 44, 20) +NEON = (255, 92, 58) +BULB = (255, 196, 96) +BAKELITE = (72, 33, 30) +CHROME = (176, 178, 182) +DARK = (16, 15, 14) + +DIGITS = { # straight wire segments, unit cell; 0 and 6 are drawn with arcs + "4": [((0.30, 0.98), (0.30, 0.42)), ((0.30, 0.42), (0.82, 0.42)), + ((0.62, 0.02), (0.62, 0.98))], + "8": [], # arcs only + "6": [], # arcs only + "0": [], # arcs only + "-": [((0.25, 0.50), (0.75, 0.50))], + " ": [], +} + + +def font(pt, serif=False): + names = ([r"C:\Windows\Fonts\georgia.ttf", r"C:\Windows\Fonts\georgiab.ttf"] + if serif else [r"C:\Windows\Fonts\consola.ttf"]) + for path in names: + try: + return ImageFont.truetype(path, int(pt * S)) + except OSError: + continue + return ImageFont.load_default() + + +def p(v): + return int(round(v * S)) + + +def engraved(d, xy, text, f, fill=ENGRAVE): + """Lettering with a dark offset behind it, like filled engraving.""" + d.text((xy[0] + p(0.12), xy[1] + p(0.12)), text, font=f, fill=(14, 13, 12)) + d.text(xy, text, font=f, fill=fill) + + +def digit_paths(x, y, w, h, ch): + return [((x + a[0] * w, y + a[1] * h), (x + b[0] * w, y + b[1] * h)) + for a, b in DIGITS.get(ch, [])] + + +def draw_digit(d, g, x, y, w, h, ch, lit=True): + """A Nixie digit: wire numerals, round where the numeral is round. + + 0 and 6 are arcs, 4 is three straight wires; the unlit neighbours of a real + tube are drawn as a faint 8 (all ten cathodes are stacked in there). + """ + color = NIXIE if lit else NIXIE_DIM + thick = 0.62 if lit else 0.32 + if ch == "0": + rings = [(0.14, 0.02, 0.86, 0.98)] + elif ch == "6": + rings = [(0.16, 0.34, 0.84, 0.99)] + elif ch == "8": + rings = [(0.14, 0.02, 0.86, 0.50), (0.14, 0.50, 0.86, 0.98)] + else: + rings = [] + for x0, y0, x1, y1 in rings: + bb = [p(x + x0 * w), p(y + y0 * h), p(x + x1 * w), p(y + y1 * h)] + if lit: + g.ellipse(bb, outline=color + (230,), width=p(thick)) + d.ellipse(bb, outline=color, width=p(thick)) + if ch == "6": # the tail of the 6, and the lid + pts = [(x + 0.50 * w, y + 0.02 * h), (x + 0.22 * w, y + 0.22 * h), + (x + 0.16 * w, y + 0.40 * h)] + for a, b in zip(pts, pts[1:]): + if lit: + g.line([p(a[0]), p(a[1]), p(b[0]), p(b[1])], fill=color + (230,), + width=p(thick)) + d.line([p(a[0]), p(a[1]), p(b[0]), p(b[1])], fill=color, width=p(thick)) + if lit: + g.ellipse([p(x + 0.16 * w), p(y + 0.34 * h), p(x + 0.84 * w), + p(y + 0.99 * h)], outline=color + (230,), width=p(thick)) + d.ellipse([p(x + 0.16 * w), p(y + 0.34 * h), p(x + 0.84 * w), + p(y + 0.99 * h)], outline=color, width=p(thick)) + for a, b in digit_paths(x, y, w, h, ch): + if lit: + g.line([p(a[0]), p(a[1]), p(b[0]), p(b[1])], fill=color + (230,), + width=p(thick)) + d.line([p(a[0]), p(a[1]), p(b[0]), p(b[1])], fill=color, width=p(thick)) + + +def main(): + out = sys.argv[1] if len(sys.argv) > 1 else "panel-mockup-vintage.png" + img = Image.new("RGB", (W, H), (16, 16, 16)) + d = ImageDraw.Draw(img) + + # panel: paint + engraved frame + d.rounded_rectangle([p(4), p(4), p(196), p(96)], radius=p(2.4), fill=PAINT, + outline=PAINT_EDGE, width=p(0.8)) + d.rounded_rectangle([p(8), p(8), p(192), p(92)], radius=p(1.4), + outline=(92, 88, 80), width=p(0.3)) + + # ---- glow layer: everything that emits light ------------------------------ + glow = Image.new("RGBA", (W, H), (0, 0, 0, 0)) + g = ImageDraw.Draw(glow) + + # Nixie tubes: 4 glass envelopes, digits inside + for i, ch in enumerate(["0", "0", "4", "6"]): + x = 13.0 + i * 11.4 + y = 20.5 + w, h = 9.0, 15.0 + # envelope + d.rounded_rectangle([p(x), p(y), p(x + w), p(y + h)], radius=p(1.0), + fill=GLASS, outline=(122, 118, 124), width=p(0.35)) + d.ellipse([p(x + w / 2 - 0.9), p(y - 1.5), p(x + w / 2 + 0.9), p(y + 0.2)], + fill=GLASS, outline=(122, 118, 124), width=p(0.3)) + # mesh plate + for k in range(6): + d.line([p(x + 1.0 + k * 1.18), p(y + 1.2), p(x + 1.0 + k * 1.18), + p(y + h - 1.2)], fill=(40, 38, 42), width=1) + ch_x, ch_y, ch_w, ch_h = x + 1.1, y + 2.0, w - 2.2, h - 4.2 + draw_digit(d, g, ch_x, ch_y, ch_w, ch_h, ch) + # faint unlit neighbours, like a real tube + draw_digit(d, g, ch_x, ch_y, ch_w, ch_h, "8", lit=False) + + # neon ring: 64 lamps, dp lit + cx, cy, r = 160, 32, 19 + for i in range(64): + a = -math.pi / 2 + 2 * math.pi * i / 64 + px, py = cx + r * math.cos(a), cy + r * math.sin(a) + lit = i == 33 + rr = 0.85 if lit else 0.45 + if lit: + g.ellipse([p(px - rr * 1.6), p(py - rr * 1.6), p(px + rr * 1.6), + p(py + rr * 1.6)], fill=NEON + (200,)) + d.ellipse([p(px - rr), p(py - rr), p(px + rr), p(py + rr)], fill=NEON) + else: + d.ellipse([p(px - rr), p(py - rr), p(px + rr), p(py + rr)], + fill=(58, 30, 26)) + a = -math.pi / 2 + 2 * math.pi * 33 / 64 + d.line([p(cx), p(cy), p(cx + r * math.cos(a)), p(cy + r * math.sin(a))], + fill=(196, 160, 96), width=p(0.35)) + + # instruction lamps: 8 grain of wheat bulbs + for i in range(8): + x = 64 + i * 7.6 + lit = i == 1 + if lit: + g.ellipse([p(x - 0.6), p(13.4 - 0.6), p(x + 5.9), p(13.4 + 5.9)], + fill=BULB + (210,)) + d.ellipse([p(x + 0.6), p(14.2), p(x + 5.0), p(18.6)], fill=BULB, + outline=(120, 88, 34)) + else: + d.ellipse([p(x + 0.6), p(14.2), p(x + 5.0), p(18.6)], fill=(40, 36, 30), + outline=(74, 68, 58)) + + # bit rows as neon bars + for i in range(16): + lit = i % 3 == 0 + x0, y0 = 64 + i * 4.4, 25.4 + if lit: + g.rounded_rectangle([p(x0), p(y0), p(x0 + 3.4), p(y0 + 2.6)], + radius=p(0.8), fill=NEON + (190,)) + d.rounded_rectangle([p(x0), p(y0), p(x0 + 3.4), p(y0 + 2.6)], + radius=p(0.8), + fill=(216, 96, 66) if lit else (54, 32, 28), + outline=(80, 44, 38)) + for i in range(6): + lit = i < 4 + x0, y0 = 64 + i * 5.8, 31.4 + if lit: + g.rounded_rectangle([p(x0), p(y0), p(x0 + 4.4), p(y0 + 2.8)], + radius=p(0.9), fill=NEON + (170,)) + d.rounded_rectangle([p(x0), p(y0), p(x0 + 4.4), p(y0 + 2.8)], + radius=p(0.9), + fill=(198, 88, 60) if lit else (54, 32, 28), + outline=(80, 44, 38)) + + # ---- composite the glow ------------------------------------------------ + glow = glow.filter(ImageFilter.GaussianBlur(p(0.9))) + img = Image.alpha_composite(img.convert("RGBA"), glow).convert("RGB") + d = ImageDraw.Draw(img) + + # ---- engraving over the top ------------------------------------------- + d.text((p(12), p(8.6)), "ROT-8", font=font(5.0, serif=True), fill=ENGRAVE) + d.text((p(13.0), p(15.6)), "8 BIT · 64 CELLS · ONE INSTRUCTION PER BYTE", + font=font(1.6), fill=ENGRAVE_DIM) + d.text((p(13.0), p(37.4)), "CELL · IP · DP", font=font(1.5), fill=ENGRAVE_DIM) + d.text((p(64), p(10.6)), "INSTRUCTION", font=font(1.6), fill=ENGRAVE_DIM) + for i, op in enumerate("><+-[].,"): + d.text((p(64 + i * 7.6 + 1.7), p(19.6)), op, font=font(2.0), fill=ENGRAVE) + d.text((p(58.4), p(24.8)), "IP", font=font(1.5), fill=ENGRAVE_DIM) + d.text((p(58.4), p(30.8)), "DP", font=font(1.5), fill=ENGRAVE_DIM) + + # bakelite buttons with chrome bezels + for cx_, label in ((70, "RUN"), (86, "STEP"), (102, "RESET")): + d.ellipse([p(cx_ - 4.8), p(42.6 - 4.8), p(cx_ + 4.8), p(42.6 + 4.8)], + fill=CHROME, outline=(96, 96, 98)) + d.ellipse([p(cx_ - 4.0), p(42.6 - 4.0), p(cx_ + 4.0), p(42.6 + 4.0)], + fill=BAKELITE, outline=(38, 18, 16)) + tw = d.textlength(label, font=font(1.6)) + d.text((p(cx_) - tw / 2, p(47.8)), label, font=font(1.6), fill=ENGRAVE) + + d.text((p(13.0), p(41.0)), "INPUT BYTE", font=font(1.5), fill=ENGRAVE_DIM) + d.rounded_rectangle([p(13), p(44), p(55), p(51.4)], radius=p(0.5), + outline=(112, 106, 96), width=p(0.3)) + for i in range(8): + d.rectangle([p(14.6 + i * 5.0), p(45.4), p(17.6 + i * 5.0), p(49.8)], + fill=(226, 216, 190), outline=(96, 90, 80)) + d.text((p(13.0), p(52.6)), "8 SWITCHES + SEND", font=font(1.4), fill=(128, 121, 106)) + + # cartridge socket + engraving + d.rounded_rectangle([p(13), p(61), p(64), p(75.4)], radius=p(0.6), + fill=(20, 19, 18), outline=(112, 106, 96), width=p(0.3)) + d.text((p(14.6), p(62.6)), "27C512 · UV WINDOW", font=font(1.5), fill=ENGRAVE) + d.text((p(14.6), p(66.4)), "program cartridge", font=font(1.4), fill=ENGRAVE_DIM) + d.text((p(14.6), p(69.8)), "64K x 8, one byte", font=font(1.4), fill=ENGRAVE_DIM) + d.text((p(14.6), p(73.2)), "per instruction", font=font(1.4), fill=ENGRAVE_DIM) + + d.text((p(72), p(58.4)), "SERIAL 9600 8N1", font=font(1.5), fill=ENGRAVE_DIM) + for k, txt, col in ((62.2, "> 12 34 + .", (188, 178, 156)), + (70.2, "0046", NEON)): + d.rounded_rectangle([p(72), p(k), p(118), p(k + 6.2)], radius=p(0.4), + fill=DARK, outline=(96, 90, 80), width=p(0.25)) + d.text((p(73.4), p(k + 1.3)), txt, font=font(1.4), fill=col) + + # optional mechanical dial + d.ellipse([p(150), p(60), p(170), p(80)], fill=(146, 140, 128), + outline=(96, 90, 80), width=p(0.4)) + d.ellipse([p(157.8), p(67.8), p(162.2), p(72.2)], fill=(60, 56, 50), + outline=(32, 30, 26)) + d.line([p(160), p(70), p(166), p(64)], fill=(56, 52, 46), width=p(0.45)) + for k in range(12): + a = 2 * math.pi * k / 12 + d.line([p(160 + 8.6 * math.cos(a)), p(70 + 8.6 * math.sin(a)), + p(160 + 9.6 * math.cos(a)), p(70 + 9.6 * math.sin(a))], + fill=(70, 66, 58), width=p(0.2)) + d.text((p(146), p(82.0)), "MECHANICAL DP", font=font(1.3), fill=ENGRAVE_DIM) + + d.text((p(13.0), p(79.4)), + "INSIDE: EUROCARD 160 x 100 mm · 34 DIP SOCKETS · 5 V 2 A", + font=font(1.4), fill=ENGRAVE_DIM) + d.text((p(13.0), p(82.8)), + "1 MHz CAN · 27C512 + 6116 + 74LS · K155ID1 + 170 V FOR THE TUBES", + font=font(1.3), fill=(128, 121, 106)) + + img.save(out) + print("wrote", out) + + +if __name__ == "__main__": + main()