TableTower/tools/theme_art/frames.py
RobinFiredrake 61a548902f Theme tiers 1-2: theme folders, mascot recolour, background scene and tile, frame sets, picture threads, sounds; nine new built-in themes
- ThemeAssets loads a theme's files; FrameSet + GradientMap (3-stop) generalise the card frame;
  ThreadStrip draws threads from a picture; BoardBackdrop draws scene and tile; MascotArt
  recolours Morgan by role (logo SVG now uses the Keep File importer); SoundBoard plays
  roll / card turn / thread / click / ambient with View > Sound levels.
- Vaporwave, Synthwave, Cozy Autumn, Rustic, Woodsy, Sky Blue, Frutiger Aero, Gothic, Terminal:
  generated art (tools/theme_art), sounds (tools/theme_sounds), settings (tools/theme_defs).
- Ten OFL fonts; --theme=<id> flag; docs/THEMES.md format spec; test_theme_assets.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 15:05:40 -06:00

99 lines
4 KiB
Python

"""Frame sets (corner + edge, greyscale) built from a band profile, plus optional coloured corner ornaments.
A band profile is a list of Stroke layers drawn along the frame's centre line. The corner draws them along
a rounded (or square) turn; the edge draws them along a straight vertical line. Both use the same
centre line (`band_mid`) and the same layers, so the two join with no step.
"""
import math
from dataclasses import dataclass, field
from svg_common import grey, num, svg_document
SCALE = 0.25 # art is authored at 4x screen size
@dataclass
class Stroke:
"""One layer of the band: width and offset in source units (positive offset = toward the card)."""
width: float
lightness: float
opacity: float = 1.0
offset: float = 0.0
dash: str = ""
@dataclass
class FrameStyle:
band_mid: float # side_mid = top_mid = edge_mid (source units)
radius: float # turn radius of the band centre line (0 = square, mitred)
strokes: list
corner_size: tuple
edge_length: float = 64
band_inside_px: float = 0.0 # where the band centre sits, in px inside the card edge (negative = outside)
corner_extras: str = "" # extra greyscale shapes drawn on the corner
edge_extras: str = "" # extra greyscale shapes drawn on each edge tile
corner_fixed: str = "" # coloured overlay shapes (empty = no corner_fixed file)
pad_extra_px: float = 2.0
notes: list = field(default_factory=list)
def _stroke_attributes(stroke, join):
dash = f' stroke-dasharray="{stroke.dash}"' if stroke.dash else ""
return (f'fill="none" stroke="{grey(stroke.lightness)}" stroke-width="{num(stroke.width)}" '
f'stroke-opacity="{num(stroke.opacity)}" stroke-linejoin="{join}" stroke-linecap="butt"{dash}')
def corner_path(style, offset):
"""The band's line, moved `offset` toward the card, from the corner's bottom edge to its right edge."""
width, height = style.corner_size
position = style.band_mid + offset
turn_start = style.band_mid + style.radius
turn_radius = max(style.radius - offset, 0)
if style.radius <= 0:
return f"M{num(position)},{num(height)} L{num(position)},{num(position)} L{num(width)},{num(position)}"
return (f"M{num(position)},{num(height)} L{num(position)},{num(turn_start)} "
f"A{num(turn_radius)},{num(turn_radius)} 0 0 1 {num(turn_start)},{num(position)} "
f"L{num(width)},{num(position)}")
def corner_svg(style):
join = "miter" if style.radius <= 0 else "round"
body = "".join(f'<path d="{corner_path(style, stroke.offset)}" {_stroke_attributes(stroke, join)}/>'
for stroke in style.strokes)
width, height = style.corner_size
return svg_document(width, height, body + style.corner_extras)
def edge_size(style):
return [style.band_mid * 2, style.edge_length]
def edge_svg(style):
width, height = edge_size(style)
body = ""
for stroke in style.strokes:
position = num(style.band_mid + stroke.offset)
body += f'<path d="M{position},0 L{position},{num(height)}" {_stroke_attributes(stroke, "miter")}/>'
return svg_document(width, height, body + style.edge_extras)
def corner_fixed_svg(style):
if not style.corner_fixed:
return None
width, height = style.corner_size
return svg_document(width, height, style.corner_fixed)
def frame_meta(style):
"""The numbers the app needs to place this frame set."""
band_half_px = max(stroke.width / 2 + abs(stroke.offset) for stroke in style.strokes
if stroke.opacity >= 0.5) * SCALE
outset = style.band_mid * SCALE - style.band_inside_px
pad = max(0.0, style.band_inside_px + band_half_px) + style.pad_extra_px
return {
"corner_size": list(style.corner_size), "edge_size": edge_size(style),
"side_mid": style.band_mid, "top_mid": style.band_mid, "edge_mid": style.band_mid,
"scale": SCALE, "outset": round(outset, 2), "pad": math.ceil(pad),
"mid": 0.5, "has_corner_fixed": bool(style.corner_fixed),
}