TableTower/tools/theme_art/threads.py
RobinFiredrake 3d0ba9c6b8 Nine more built-in themes: Web 1.0 and the eight suggested (Case File, Eldritch Archive, Comic Panel, Brass & Gears, Chrome Street, Star Chart, Cartographer, Storybook)
Generated stand-in art and sounds, ten more OFL fonts, PNG tiles in the theme generator; untrack __pycache__.

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

93 lines
3.8 KiB
Python

"""Thread strips: one horizontal, seamless tile per thread look (greyscale, gradient-mapped by the app).
Black = dark edge (THREAD_DARK), mid grey = thread colour, white = highlight. Source units are 4x px.
Every shape sits inside the tile (or repeats exactly at its edges), so the strip tiles left to right.
"""
from svg_common import grey, num, svg_document
SOURCE_SCALE = 4
def _band(length, height, band_height, lightness, opacity=1.0, shift=0.0):
"""A full-length horizontal band, centred (plus `shift`) in the strip."""
top = (height - band_height) / 2 + shift
return (f'<rect x="0" y="{num(top)}" width="{num(length)}" height="{num(band_height)}" '
f'fill="{grey(lightness)}" fill-opacity="{num(opacity)}"/>')
def _dash(length, height, dash_length):
"""One round-ended dash, centred in the tile (a CSS dash plus its round caps)."""
visible = dash_length + height
return (f'<rect x="{num((length - visible) / 2)}" y="0" width="{num(visible)}" height="{num(height)}" '
f'rx="{num(height / 2)}" fill="{grey(0.5)}"/>')
def _twisted_strand(length, height, strand_width, slant):
"""One slanted strand of a twisted rope, centred in the tile, with a soft shine line."""
middle_x, middle_y = length / 2, height / 2
reach_y = height / 2 - strand_width / 2
start = f"{num(middle_x - slant)},{num(middle_y + reach_y)}"
end = f"{num(middle_x + slant)},{num(middle_y - reach_y)}"
return (f'<path d="M{start} L{end}" stroke="{grey(0.5)}" stroke-width="{num(strand_width)}" '
f'stroke-linecap="round"/>'
f'<path d="M{start} L{end}" stroke="{grey(1.0)}" stroke-width="{num(strand_width * 0.18)}" '
f'stroke-opacity=".35" stroke-linecap="round" transform="translate(-1 -1)"/>')
def dashed_line(length, height):
return _dash(length, height, length * 10 / 16)
def neon_tube(length, height):
return (_band(length, height, height, 0.5, 0.25) + _band(length, height, height * 0.56, 0.5, 0.3)
+ _band(length, height, height * 0.31, 0.5) + _band(length, height, height * 0.12, 1.0, 0.8))
def twine(length, height):
return _band(length, height, height, 0.0) + _twisted_strand(length, height, height * 0.6, length * 0.2)
def rope(length, height):
return _band(length, height, height, 0.0) + _twisted_strand(length, height, height * 0.46, length * 0.24)
def vine(length, height):
return _band(length, height, height, 0.5) + _band(length, height, height * 0.2, 1.0, 0.25, -height * 0.18)
def kite_string(length, height):
return _band(length, height, height, 0.0, 0.25) + _band(length, height, height / 2, 0.5)
def glossy_tube(length, height):
return (_band(length, height, height, 0.0) + _band(length, height, height * 0.58, 0.5)
+ _band(length, height, height * 0.2, 1.0, 0.56, -height * 0.12))
def cord(length, height):
return _band(length, height, height, 0.0) + _band(length, height, height / 2, 0.5)
def dashed_amber(length, height):
return _dash(length, height, length * 6 / 10)
# thread look -> (maker, drawn width in px, repeat length in px)
THREAD_LOOKS = {
"dashed_line": (dashed_line, 3, 16), "neon_tube": (neon_tube, 8, 8), "twine": (twine, 4, 8),
"rope": (rope, 5.5, 6), "vine": (vine, 3, 12), "kite_string": (kite_string, 6, 8),
"glossy_tube": (glossy_tube, 6, 8), "cord": (cord, 4, 8), "dashed_amber": (dashed_amber, 2.5, 10),
}
from threads_more import MORE_THREAD_LOOKS # noqa: E402 (second batch)
THREAD_LOOKS.update(MORE_THREAD_LOOKS)
def make_thread_strip(look):
"""Return (svg_text, meta) for a thread look."""
maker, width_px, repeat_px = THREAD_LOOKS[look]
length, height = round(repeat_px * SOURCE_SCALE), round(width_px * SOURCE_SCALE) # whole numbers: importers round sizes
return svg_document(length, height, maker(length, height)), {"strip_size": [length, height], "width": width_px}