TableTower/tools/theme_art/scene_paint.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

35 lines
1.8 KiB
Python

"""Shared painting helpers for background scenes: gradients, soft glows, and the mockup's spread space."""
from svg_common import css_colour, num
SCENE_WIDTH, SCENE_HEIGHT = 1920, 1080
def in_spread_space(body, shift_y):
"""Scale mockup spread coordinates (960 x 450) by 2, shifted down by `shift_y`."""
return f'<g transform="translate(0 {shift_y}) scale(2)">{body}</g>'
def vertical_gradient(gradient_id, stops):
stop_text = "".join(f'<stop offset="{num(offset)}" stop-color="{colour}" stop-opacity="{num(opacity)}"/>'
for offset, colour, opacity in stops)
return f'<linearGradient id="{gradient_id}" x1="0" y1="0" x2="0" y2="1">{stop_text}</linearGradient>'
def radial_gradient(gradient_id, stops, centre=(0.5, 0.5), radius=0.5):
stop_text = "".join(f'<stop offset="{num(offset)}" stop-color="{colour}" stop-opacity="{num(opacity)}"/>'
for offset, colour, opacity in stops)
return (f'<radialGradient id="{gradient_id}" cx="{num(centre[0])}" cy="{num(centre[1])}" '
f'r="{num(radius)}" fx="{num(centre[0])}" fy="{num(centre[1])}">{stop_text}</radialGradient>')
def soft_ellipse_glow(gradient_id, colour_text, centre, radii, fade_from=0.0):
"""A CSS 'radial-gradient(rx ry at cx cy, colour, transparent)' over the full scene.
The gradient is drawn on a box sized 2*rx by 2*ry, so its bounding box makes the circle an ellipse."""
colour, opacity = css_colour(colour_text)
gradient = radial_gradient(gradient_id, [(fade_from, colour, opacity), (1, colour, 0)])
box_x, box_y = centre[0] - radii[0], centre[1] - radii[1]
shape = (f'<rect x="{num(box_x)}" y="{num(box_y)}" width="{num(radii[0] * 2)}" '
f'height="{num(radii[1] * 2)}" fill="url(#{gradient_id})"/>')
return gradient, shape