TableTower/tools/theme_art/scenes.py

141 lines
8.3 KiB
Python
Raw Normal View History

"""Big background scenes (1920 x 1080, transparent ground) from the mockup's SCENES.
Most scenes are drawn in the mockup's 960 x 450 spread space and scaled by 2. Bottom-anchored
scenes are shifted down 180 px so their floor, hills or trees touch the bottom edge.
"""
from scene_floor import PerspectiveFloor, floor_svg
from scene_paint import (SCENE_HEIGHT, SCENE_WIDTH, in_spread_space, radial_gradient, soft_ellipse_glow,
vertical_gradient)
from svg_common import css_colour, num, svg_document
def vapor_scene(scene):
"""A pale wireframe floor and a soft pink-to-periwinkle sun."""
floor = PerspectiveFloor(-96, 1056, 207, 260, 58)
grid = floor_svg(floor, scene["s1"], 26, 2.08, 52, 2, opacity=0.8)
defs = vertical_gradient("vapor_sun", [(0, scene["s2"], 1), (1, scene["s3"], 1)])
sun = '<circle cx="485" cy="125" r="85" fill="url(#vapor_sun)" opacity=".55"/>'
return defs, in_spread_space(sun + grid, 180), "bottom"
def synth_scene(scene):
"""Blue light bars, a striped setting sun and a glowing pink grid floor."""
bar_fade = "".join(f'<stop offset="{offset}" stop-color="{scene["s3"]}" stop-opacity="{opacity}"/>'
for offset, opacity in ((0, 0), (0.15, 1), (0.85, 1), (1, 0)))
defs = f'<linearGradient id="synth_bars" x1="0" y1="0" x2="1" y2="0">{bar_fade}</linearGradient>'
bars = ""
for top in range(60, 320, 13):
bars += f'<rect x="0" y="{top - 2}" width="960" height="6" fill="url(#synth_bars)" opacity=".22"/>'
bars += f'<rect x="0" y="{top}" width="960" height="2" fill="url(#synth_bars)" opacity=".9"/>'
defs += vertical_gradient("synth_sun", [(0, scene["s1"], 1), (0.52, "#fa8057", 1), (1, scene["s2"], 1)])
sun_top, sun_size = 52, 250
stripes = f'<rect x="350" y="{sun_top}" width="{sun_size}" height="{sun_size * 0.48}"/>'
stripe_top = sun_top
while stripe_top < sun_top + sun_size:
stripes += f'<rect x="350" y="{stripe_top}" width="{sun_size}" height="9"/>'
stripe_top += 14
defs += f'<clipPath id="synth_sun_cut">{stripes}</clipPath>'
sun = (f'<circle cx="475" cy="{sun_top + sun_size / 2}" r="{sun_size / 2}" fill="url(#synth_sun)" '
f'clip-path="url(#synth_sun_cut)"/>')
halo = "".join(f'<circle cx="475" cy="177" r="{125 + grow}" fill="none" stroke="{scene["s2"]}" '
f'stroke-width="6" opacity="{num(0.12 - grow * 0.004)}"/>' for grow in range(3, 28, 6))
floor = PerspectiveFloor(-480, 1440, 150, 180, 55)
grid = floor_svg(floor, scene["s2"], 22, 2.2, 46, 2, glow_width=3, ground_colour="#14051a")
return defs, in_spread_space(bars + halo + sun + grid, 180), "bottom"
def _cloud(defs_needed, x, y, width, opacity):
"""Three soft ellipses, matching the mockup's three-layer CSS cloud."""
height = width * 0.42
layers = [ # sub-box (x, y, w, h), centre within it, solid-until offset
((x, y + height * 0.1, width * 0.55, height * 0.9), (0.30, 0.65), 0.70),
((x + width * 0.45 * 0.4, y, width * 0.55, height), (0.55, 0.40), 0.72),
((x + width * 0.55, y + height * 0.2, width * 0.45, height * 0.8), (0.78, 0.66), 0.70),
]
shapes = ""
for (box_x, box_y, box_w, box_h), (centre_x, centre_y), solid_until in layers:
radius_x = min(centre_x, 1 - centre_x) * box_w
radius_y = min(centre_y, 1 - centre_y) * box_h
gradient_id = f"cloud_soft_{int(solid_until * 100)}"
defs_needed[gradient_id] = radial_gradient(gradient_id, [(solid_until, "#ffffff", 1), (1, "#ffffff", 0)])
shapes += (f'<ellipse cx="{num(box_x + centre_x * box_w)}" cy="{num(box_y + centre_y * box_h)}" '
f'rx="{num(radius_x)}" ry="{num(radius_y)}" fill="url(#{gradient_id})"/>')
return f'<g opacity="{num(opacity)}">{shapes}</g>'
def clouds_scene(scene):
"""Sun glare in the top right and five soft clouds."""
glare_colour, glare_opacity = css_colour(scene["s1"])
defs = radial_gradient("sky_glare", [(0, "#ffffff", 1), (0.25, glare_colour, glare_opacity),
(0.65, glare_colour, 0)], radius=0.707)
body = '<circle cx="870" cy="70" r="150" fill="url(#sky_glare)"/>'
defs_needed = {}
for x, y, width, opacity in ((300, 330, 260, .95), (-40, 360, 240, .9), (600, 20, 150, .7),
(250, 40, 120, .55), (820, 250, 180, .85)):
body += _cloud(defs_needed, x, y, width, opacity)
return defs + "".join(defs_needed.values()), in_spread_space(body, 90), "center"
def aero_scene(scene):
"""Glossy glare, a green hill with a white rim, light swooshes and glass bubbles."""
defs = radial_gradient("aero_glare", [(0, "#ffffff", 0.95), (0.65, "#ffffff", 0)], radius=0.707)
defs += radial_gradient("aero_bubble", [(0, "#ffffff", 1), (0.14, "#ffffff", 1), (0.34, "#ffffff", 0.15),
(0.70, "#74e4ff", 0.35), (1, "#ffffff", 0.8)],
centre=(0.32, 0.28), radius=0.99)
body = '<ellipse cx="200" cy="60" rx="260" ry="180" fill="url(#aero_glare)"/>'
body += (f'<path d="M0 380 C200 300 400 420 620 350 S900 300 960 330 V450 H0Z" fill="{scene["s2"]}"/>'
'<path d="M0 395 C220 330 420 435 640 370 S900 330 960 350" fill="none" stroke="#fff" '
'stroke-width="3" opacity=".8"/>'
'<path d="M-20 120 C200 40 420 180 980 60" fill="none" stroke="#fff" stroke-width="10" opacity=".35"/>'
'<path d="M-20 140 C220 70 460 200 980 90" fill="none" stroke="#fff" stroke-width="2" opacity=".7"/>')
for left, top, radius in ((300, 80, 46), (880, 60, 30), (560, 300, 22), (120, 300, 34), (700, 170, 16)):
centre_x, centre_y = left + radius, top + radius
body += (f'<circle cx="{centre_x}" cy="{centre_y}" r="{radius}" fill="url(#aero_bubble)"/>'
f'<circle cx="{centre_x}" cy="{centre_y}" r="{radius - 1.5}" fill="none" stroke="#fff" '
f'stroke-width="3" opacity=".45"/>')
return defs, in_spread_space(body, 180), "bottom"
"""Dark edges (a vignette)."""
def vignette_scene(scene):
"""Dark edges and a faint red arched window glow at the top."""
# CSS radial-gradient(70% 80% at 50% 40%, transparent 40%, s1): radii are 70% / 80% of the scene.
centre, radii = (SCENE_WIDTH * 0.5, SCENE_HEIGHT * 0.4), (SCENE_WIDTH * 0.7, SCENE_HEIGHT * 0.8)
defs = radial_gradient("gothic_vignette", [(0.4, scene["s1"], 0), (1, scene["s1"], 1)])
body = (f'<rect x="{num(centre[0] - radii[0])}" y="{num(centre[1] - radii[1])}" width="{num(radii[0] * 2)}" '
f'height="{num(radii[1] * 2)}" fill="url(#gothic_vignette)"/>')
# The red arch "window glow" read as a stray red patch (playtest 2026-11-14),
# so the stand-in is the vignette alone; a real window is the user's art.
return defs, body, "center"
def woods_scene(scene):
"""Two soft light patches and dark pines standing on the bottom edge."""
defs_one, glow_one = soft_ellipse_glow("woods_light_a", scene["s1"], (SCENE_WIDTH * 0.25, SCENE_HEIGHT * 0.2),
(SCENE_WIDTH * 0.3, SCENE_HEIGHT * 0.4))
defs_two, glow_two = soft_ellipse_glow("woods_light_b", scene["s1"], (SCENE_WIDTH * 0.7, SCENE_HEIGHT * 0.6),
(SCENE_WIDTH * 0.25, SCENE_HEIGHT * 0.35))
pine = "M0 0 L-30 0 L-8 -40 L-24 -40 L-4 -80 L-16 -80 L0 -120 L16 -80 L4 -80 L24 -40 L8 -40 L30 0Z"
trees = "".join(f'<path transform="translate({x} 450) scale({size})" d="{pine}"/>'
for x, size in ((40, 1), (120, 1.3), (880, 1.2), (940, 0.9)))
body = glow_one + glow_two + in_spread_space(f'<g fill="{scene["s2"]}">{trees}</g>', 180)
return defs_one + defs_two, body, "bottom"
SCENE_MAKERS = {"vapor": vapor_scene, "synth": synth_scene, "clouds": clouds_scene,
"aero": aero_scene, "vignette": vignette_scene, "woods": woods_scene}
from scenes_more import MORE_SCENE_MAKERS # noqa: E402 (second batch)
SCENE_MAKERS.update(MORE_SCENE_MAKERS)
def make_background_scene(scene):
"""Return (svg_text, meta) for a scene, or (None, None) for 'glow' / 'none' (the app's fill does those)."""
maker = SCENE_MAKERS.get(scene["kind"])
if maker is None:
return None, None
defs, body, anchor = maker(scene)
return svg_document(SCENE_WIDTH, SCENE_HEIGHT, body, defs), {"anchor": anchor}