Files
builds/greenman-src/build_templates.py
T
Eric WagonerandClaude Fable 5.2 f2bb87caeb Credibility pass over the Green Man generator
Turn audit.py into a run() function and drop audit_run.py, which only
existed to import it quietly. Remove unused parameters, keys, helpers
and imports from draw.py, manifest.py and stl_build.py, and the source
file names in stl_build.FILES that pointed at nothing. Keep the brow
strip's taper and knob positions in geom.py only. Correct comments and
docstrings that disagreed with the code, and the README's claim about
counts.

The page changes only in markup: no stray spaces in class attributes,
and three CSS declarations that did nothing are gone. Guide HTML,
templates and print files are byte-identical apart from that.

Credibility pass over a7c04e5..HEAD; the next one can scope from here.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-10 19:14:03 -05:00

123 lines
10 KiB
Python
Raw 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.
"""1:1 cutting templates, US Letter landscape (content also fits A4). Leaf counts come from the manifest."""
import asyncio
from collections import Counter
import geom as G, manifest as M
from draw import f, path, line
from geom import TOP
import shot, fonts
from paths import OUT, WORK
PW, PH = 279.4, 215.9
FONT = "Inter, 'Helvetica Neue', Helvetica, Arial, sans-serif"
CUT, GUIDE, RED, SCALE = '#111111', '#8a8a8a', '#b3261e', '#0057ff'
def T(x, y, s, size=3.1, weight=400, fill='#111', anchor='start'):
return f'<text x="{f(x)}" y="{f(y)}" font-size="{size}" font-weight="{weight}" fill="{fill}" text-anchor="{anchor}" font-family="{FONT}">{s}</text>'
def lines(x, y, rows, size=3.1, lead=4.4, **kw): return ''.join(T(x, y+i*lead, r, size, **kw) for i, r in enumerate(rows))
def page(body, title, sub, n, total):
head = T(12, 14, title, 5.2, 700) + T(12, 20, sub, 3.1, 400, '#444') + T(PW-12, 14, f'Green Man mask kit · templates {n}/{total}', 2.8, 400, '#666', 'end')
bar = (f'<g stroke="{SCALE}" stroke-width="0.5"><path d="M{PW-122} {PH-18} h100 M{PW-122} {PH-20} v4 M{PW-22} {PH-20} v4 M{PW-72} {PH-19} v2"/></g>'
+ T(PW-72, PH-13, '100 mm. Measure this bar after printing. Print at 100% / actual size, never “fit to page”.', 2.6, 400, '#333', 'middle'))
return f'<svg xmlns="http://www.w3.org/2000/svg" width="{PW}mm" height="{PH}mm" viewBox="0 0 {PW} {PH}">{head}{body}{bar}</svg>'
def base_page(base, n, total):
ox, oy = PW/2, 124.0
g = f'<g transform="translate({ox} {oy})">'
g += f'<path d="{path(base["outline"])}" fill="none" stroke="{CUT}" stroke-width="0.5" fill-rule="evenodd" stroke-linejoin="round" class="cut"/>'
g += f'<path d="M0 {f(-(G.BAND_TOP+4))} V{52}" stroke="{GUIDE}" stroke-width="0.25" stroke-dasharray="3 1.5 0.6 1.5"/>'
for sl, pt in zip(base['slits'], base['patches']):
g += f'<path d="{path(pt)}" fill="none" stroke="{RED}" stroke-width="0.3" stroke-dasharray="2 1.2"/><path d="{path(sl)}" fill="none" stroke="{RED}" stroke-width="0.45"/>'
g += f'<path d="{path(base["top_slit"])}" fill="none" stroke="{GUIDE}" stroke-width="0.35" stroke-dasharray="1 1"/>'
g += T(34, -(TOP+62), 'optional top-strap slit (dotted, under the knot): decide in Stage C', 2.4, 400, '#666') + f'<path d="M33 {f(-(TOP+61))} L13 {f(-(TOP+48))}" stroke="#999" stroke-width="0.2"/>'
g += T(G.SLIT_X+18, -(TOP+30), 'strap slit', 2.6, 600, RED) + T(G.SLIT_X+18, -(TOP+26.3), '3 × 20 mm, cut through', 2.4, 400, RED) + T(G.SLIT_X+18, -(TOP+22.9), 'band and patch together', 2.4, 400, RED)
g += T(-G.SLIT_X-18, -(TOP+30), 'patch on the BACK', 2.6, 600, RED, 'end') + T(-G.SLIT_X-18, -(TOP+26.3), '30 × 36 mm of 2 mm foam', 2.4, 400, RED, 'end')
# where things land, lightly, so the template doubles as a placement map
g += f'<path d="{path(G.place(G.strip_poly(), 0, G.STRIP_Y))}" fill="none" stroke="{GUIDE}" stroke-width="0.25" stroke-dasharray="1.2 1"/>' + T(30, -(G.STRIP_Y-1), 'brow strip', 2.4, 400, '#777', 'middle')
g += f'<circle cx="0" cy="{f(-G.KNOT_C[1])}" r="{G.KNOT_R}" fill="none" stroke="{GUIDE}" stroke-width="0.25" stroke-dasharray="1.2 1"/>' + T(-12, -(G.KNOT_C[1]+12), 'knot', 2.4, 400, '#777', 'middle')
if base['kind'] == 'glasses':
for sg in (-1, 1): g += f'<path d="{path(G.lens(sg))}" fill="none" stroke="{GUIDE}" stroke-width="0.3" stroke-dasharray="2 1.5"/>'
g += f'<path d="{path(G.frame_zone())}" fill="none" stroke="{GUIDE}" stroke-width="0.2" stroke-dasharray="0.6 1.2"/>'
g += T(G.LENS_CX, 3, 'your lens', 2.6, 400, '#777', 'middle') + T(-G.LENS_CX, 3, 'no foam here', 2.6, 400, '#777', 'middle')
for sg in (-1, 1): g += f'<path d="M{f(sg*(G.FRAME_W/2))} {f(-(TOP-2))} H{f(sg*(G.FRAME_W/2+34))}" stroke="{GUIDE}" stroke-width="1.6" stroke-dasharray="0.6 1.2" opacity="0.6"/>'
g += T(G.FRAME_W/2+36, -(TOP-1), 'glasses arm', 2.4, 400, '#777')
else:
g += T(0, 24, 'eye holes 46 × 24 mm, 64 mm between centres', 2.6, 400, '#777', 'middle')
g += '</g>'
if base['kind'] == 'glasses':
title, sub = 'Base, for glasses wearers · cut 1 from 6 mm EVA', 'Worn BEHIND the glasses. Drawn for a frame 140 mm wide; see the fit table to resize.'
notes = ['Paper fit first: cut this page on the solid line, hold it to your face, put your glasses on over it.',
'· The band lies flat on your forehead and the frame’s top bar sits along its lower edge.',
'· The nose strip drops between the nose pads; the pads still touch skin.',
'· Each cheek tab sits outside the frame; the arms pass over the tabs.',
'Fold on the centre line to cut both halves at once.']
table = [(125, 89), (130, 93), (135, 97), (140, 100), (145, 104), (150, 107)]
tb = T(12, 178, 'Frame width → print scale for THIS page only', 2.8, 700) + ''.join(T(12 + i*17, 183.5, f'{w} mm', 2.6, 600) + T(12 + i*17, 187.5, f'{p}%', 2.6) for i, (w, p) in enumerate(table))
tb += T(12, 193, 'Scale brow_strip.stl by the same percentage. Leaf pages always print at 100%.', 2.5, 400, '#555')
else:
title, sub = 'Base, no glasses · cut 1 from 6 mm EVA', 'Same band, nose and cheeks as the glasses base, joined under the eyes.'
notes = ['Paper fit first: cut the outline and both eye holes from paper and hold it to your face.',
'· You see clearly through both holes without the edges touching your lashes.',
'· The band lies flat on your forehead; the nose strip follows the bridge of your nose.',
'Eyes closer or wider than the holes: reprint this page a few percent smaller or larger.',
'Fold on the centre line to cut both halves at once.']
tb = (f'<rect x="12" y="174" width="96" height="16" rx="1.5" fill="none" stroke="{RED}" stroke-width="0.4"/>' + T(15, 180, 'UNTESTED VARIANT', 3.4, 700, RED)
+ T(15, 185.5, 'Drawn from the glasses base but never built. Paper-fit before cutting foam.', 2.5, 400, RED))
body = g + lines(12, 27, notes, 2.75, 4.0, fill='#222') + tb
return page(body, title, sub, n, total)
def leaf_counts():
"""(size, variant) -> how many to cut, from the manifest; spares are counted under variant B."""
c = Counter()
for p in M.PLACEMENTS:
if p['part'] in 'LMST': c[(p['part'], p['variant'])] += 1
for k, n in M.SPARES.items(): c[(k, 1)] += n
return c
def leaf_cell(size, variant, cx, base_y, c):
name = {'L': 'Large', 'M': 'Medium', 'S': 'Small', 'T': 'Tip'}[size] + ' ' + 'AB'[variant]
leaf = G.oak(size, variant); n = c[(size, variant)]
g = f'<g transform="translate({f(cx)} {f(base_y)})"><path d="{path(leaf)}" fill="none" stroke="{CUT}" stroke-width="0.5" stroke-linejoin="round" class="cut"/>'
g += f'<path d="{" ".join(line(l) for l in G.vein_lines(size, variant))}" fill="none" stroke="{GUIDE}" stroke-width="0.25" stroke-dasharray="1.5 1.2"/></g>'
y = base_y + G.STEM_L + 6
g += T(cx, y, name, 3.3, 700, anchor='middle')
box = lambda k: ''.join(f'<rect x="{f(cx - k*2.6 + i*5.2 + 0.6)}" y="{f(y+7.2)}" width="4" height="4" fill="none" stroke="#111" stroke-width="0.3"/>' for i in range(k))
g += T(cx, y+4.8, f'cut {n}', 2.9, 600, anchor='middle') + box(n)
return g, n
def leaf_pages(n0, total):
c = leaf_counts(); ml = M.make_list(); pages = []
# page: large
body, tot = '', 0
for v, cx in ((0, 78), (1, 170)):
g, k = leaf_cell('L', v, cx, 148, c); body += g; tot += k
assert tot == ml['L']['total']
body += lines(214, 60, ['Large leaves make the tall back', 'of the crown.', '', 'Print on card stock, cut the two', 'shapes out, trace onto 2 mm foam.',
'Turn the card over for every', 'other leaf, so they are not all', 'identical.', '', 'Dashed lines: where the veins go', '(stamp or score them later).',
'', 'The stem is part of the leaf.', 'Do not cut it off.'], 2.75, 4.1, fill='#222')
pages.append(page(body, f'Large oak leaf, 95 mm · cut {ml["L"]["total"]} from 2 mm EVA', 'Tick a box for each one you cut. These counts are everything the mask uses: nothing is left over.', n0, total))
# page: medium, small, tip, patch
body, chk = '', Counter(); xs = {('M', 0): 34, ('M', 1): 92, ('S', 0): 142, ('S', 1): 184, ('T', 0): 220, ('T', 1): 248}
for (size, v), cx in xs.items():
g, k = leaf_cell(size, v, cx, {'M': 122, 'S': 100, 'T': 82}[size], c); body += g; chk[size] += k
for k in 'MST': assert chk[k] == ml[k]['total'], (k, chk[k], ml[k]['total'])
px, py = 205, 132
body += f'<rect x="{px}" y="{py}" width="{G.PATCH_W}" height="{G.PATCH_H}" rx="3" fill="none" stroke="{CUT}" stroke-width="0.5"/>' + T(px+G.PATCH_W/2, py+G.PATCH_H/2-1, 'Strap patch', 3.0, 700, anchor='middle') + T(px+G.PATCH_W/2, py+G.PATCH_H/2+3.5, 'cut 2', 2.7, anchor='middle')
sp = ', '.join(f'{n} {"medium" if k == "M" else "small"}' for k, n in M.SPARES.items())
body += lines(12, 172, [f'Counts include {sp} as spares. Keep the spares unsealed and unpainted: they are your repair kit.',
'Medium: 6 for the front row of the crown, 2 for the cheeks. Small: 4 for the cheeks, 1 for the nose. Tip: one on the end of each tendril.'], 2.75, 4.2, fill='#222')
pages.append(page(body, f'Medium, small and tip leaves · cut {ml["M"]["total"]} + {ml["S"]["total"]} + {ml["T"]["total"]} from 2 mm EVA, plus 2 strap patches', 'Tick a box for each one you cut.', n0+1, total))
return pages
def build(out=str(OUT / 'GreenMan_templates.pdf')):
total = 4
pages = [base_page(G.base_glasses(), 1, total), base_page(G.base_plain(), 2, total)] + leaf_pages(3, total)
html = ('<!doctype html><html><head><meta charset="utf-8"><style>' + fonts.CSS + '@page{size:279.4mm 215.9mm;margin:0}html,body{margin:0;padding:0}'
'svg{display:block;page-break-after:always;break-after:page}</style></head><body>' + ''.join(pages) + '</body></html>')
src = str(WORK / 'templates.html'); open(src, 'w').write(html)
asyncio.run(shot.go(src, out)); return out
if __name__ == '__main__':
print(build())