Files

68 lines
3.7 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-3.0-or-later
"""Assemble the TP-10 illustration and independent vector state overlays.
Run from any directory. Writes the self-contained SVG master using the included
transparent shell PNG. Then run prepare-hardware.py --printer to compile the
runtime printer layers.
"""
from pathlib import Path
import base64
import xml.etree.ElementTree as E
ROOT = Path(__file__).resolve().parents[3]
MEDIA = ROOT / 'docs/media'
S = 'http://www.w3.org/2000/svg'
E.register_namespace('', S)
def element(parent, name, **attributes):
return E.SubElement(parent, f'{{{S}}}{name}', attributes)
root = E.Element(f'{{{S}}}svg', {
'width': '636', 'height': '372', 'viewBox': '-113 89 159 93',
'role': 'img', 'aria-labelledby': 'tp10-title tp10-description'})
element(root, 'title', id='tp10-title').text = 'Tandy TP-10 thermal printer'
element(root, 'desc', id='tp10-description').text = (
'Cream thermal printer with substantial rear housing, sloping top, rounded '
'front wall, domed smoked cover and cylindrical paper roll. Capture light '
'and retained-output marks are separate runtime states.')
element(root, 'metadata').text = (
'Original shaded TP-10 illustration with a custom TANDY caption adapting the Radio Shack/TRS-80 hardware identity. The embedded transparent shell PNG is authored illustration, not a reference photograph; editable vector overlays represent paper and lamp states. Printed marks indicate retained output, not thermal-printer emulation. See ATTRIBUTION.md.'
)
defs = element(root, 'defs')
gradient = element(defs, 'linearGradient', id='tp10-led', x1='0', y1='0', x2='1', y2='1')
element(gradient, 'stop', offset='0', **{'stop-color': '#ffb19b'})
element(gradient, 'stop', offset='0.4', **{'stop-color': '#ff5940'})
element(gradient, 'stop', offset='1', **{'stop-color': '#b52721'})
device = element(root, 'g', id='tp10-printer', **{'data-runtime-when': 'scene=on'})
# Pixel coordinates below reference the 1536 × 1024 source directly.
# One uniform transform preserves its proportions and keeps every overlay aligned.
transform = 'translate(-116 80) scale(0.10677083333333333)'
shell = element(device, 'g', id='tp10-shell', transform=transform)
png = (MEDIA / 'tandy-tp-10-shell.png').read_bytes()
element(shell, 'image', x='0', y='0', width='1536', height='1024',
href='data:image/png;base64,' + base64.b64encode(png).decode('ascii'))
printed = element(device, 'g', id='tp10-paper-printed', transform=transform,
style='display:none', **{'data-runtime-when': 'printerPaper=printed',
'aria-label': 'Captured output is available'})
for row in range(4):
y = 420 + row * 24
for col in range(38):
if col % 13 in (11, 12):
continue
# The sheet bends slightly left toward its feed edge.
x = 400 + col * 10.2 - row * 2.5
element(printed, 'ellipse', cx=f'{x:g}', cy=f'{y:g}', rx='1.65', ry='1.4',
fill='#777b79', opacity='0.55')
off = element(device, 'g', id='tp10-power-off', transform=transform,
**{'data-runtime-when': 'printerPower=off', 'aria-label': 'Printer capture stopped'})
element(off, 'path', d='M1265 574 H1282 L1280 589 H1263 Z', fill='#542126', opacity='0.5')
on = element(device, 'g', id='tp10-power-on', transform=transform, style='display:none',
**{'data-runtime-when': 'printerPower=on', 'aria-label': 'Printer capture enabled'})
element(on, 'path', d='M1265 574 H1282 L1280 589 H1263 Z', fill='url(#tp10-led)')
element(on, 'path', d='M1267 576 H1274 L1273 580 H1266 Z', fill='#ffd3bb')
E.indent(root)
E.ElementTree(root).write(MEDIA / 'tandy-tp-10-printer.svg', encoding='utf-8', xml_declaration=True)