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>
114 lines
6.5 KiB
Python
114 lines
6.5 KiB
Python
"""Second batch of background scenes (1920 x 1080, transparent ground). Same rules as scenes.py."""
|
|
|
|
import math
|
|
|
|
from scene_paint import SCENE_HEIGHT, SCENE_WIDTH, in_spread_space, radial_gradient, soft_ellipse_glow, vertical_gradient
|
|
from svg_common import MockupRandom, css_colour, num
|
|
|
|
|
|
def blinds_scene(scene):
|
|
"""Lamplight through venetian blinds: tilted light stripes fading out from the middle."""
|
|
colour, opacity = css_colour(scene["s1"])
|
|
defs = radial_gradient("blind_fade", [(0, colour, opacity), (1, colour, 0)])
|
|
left, top, width, height = 180, -60, 680, 560
|
|
stripes = "".join(f"M{left} {stripe_top} h{width} v20 h-{width}z "
|
|
for stripe_top in range(top + 18, top + height, 38))
|
|
body = (f'<path d="{stripes.strip()}" fill="url(#blind_fade)" '
|
|
f'transform="rotate(-18 {left + width / 2} {top + height / 2})"/>')
|
|
return defs, in_spread_space(body, 90), "center"
|
|
|
|
|
|
def eldritch_scene(scene):
|
|
"""A faint green glow low on the right and tentacle silhouettes reaching in from the edges."""
|
|
defs, glow = soft_ellipse_glow("eldritch_glow", scene["s1"], (SCENE_WIDTH * 0.6, SCENE_HEIGHT * 0.7),
|
|
(SCENE_WIDTH * 0.5, SCENE_HEIGHT * 0.6))
|
|
tentacles = (f'<g fill="none" stroke="{scene["s2"]}" stroke-width="7" stroke-linecap="round" opacity=".55">'
|
|
'<path d="M960 420 C860 380 880 300 800 290 S700 330 720 260"/>'
|
|
'<path d="M0 60 C80 90 60 160 140 170 S230 140 210 210"/>'
|
|
'<path d="M960 120 C900 140 880 200 920 230"/></g>')
|
|
return defs, glow + in_spread_space(tentacles, 90), "center"
|
|
|
|
|
|
def burst_scene(scene):
|
|
"""Comic speed lines: thin wedges all round the middle (CSS repeating conic gradient)."""
|
|
colour, opacity = css_colour(scene["s1"])
|
|
centre_x, centre_y, reach = SCENE_WIDTH / 2, SCENE_HEIGHT / 2, 1400
|
|
wedges = ""
|
|
for start in range(0, 360, 12):
|
|
points = [(centre_x, centre_y)]
|
|
for angle in (start, start + 4):
|
|
radians = math.radians(angle)
|
|
points.append((centre_x + reach * math.sin(radians), centre_y - reach * math.cos(radians)))
|
|
wedges += "M" + " L".join(f"{num(x)},{num(y)}" for x, y in points) + "Z "
|
|
body = f'<path d="{wedges.strip()}" fill="{colour}" opacity="{num(opacity * 0.5)}"/>'
|
|
return "", body, "center"
|
|
|
|
|
|
def city_scene(scene):
|
|
"""A skyline of dark towers with lit windows, fading into the ground colour at the bottom."""
|
|
random = MockupRandom(21)
|
|
towers = ""
|
|
x = 0.0
|
|
while x < 960:
|
|
width, height = 50 + random.next() * 70, 90 + random.next() * 190
|
|
tower_left, tower_top = int(x), 450 - int(height)
|
|
towers += f'<rect x="{tower_left}" y="{tower_top}" width="{int(width)}" height="{int(height)}" fill="{scene["s3"]}"/>'
|
|
for _ in range(20):
|
|
if random.next() < 0.5:
|
|
window_x = int(6 + random.next() * (width - 14))
|
|
window_y = int(8 + random.next() * (height - 20))
|
|
colour = scene["s1"] if random.next() < 0.75 else scene["s2"]
|
|
towers += (f'<rect x="{tower_left + window_x}" y="{tower_top + window_y}" width="4" height="6" '
|
|
f'fill="{colour}"/>')
|
|
x += width + 4
|
|
defs = vertical_gradient("city_fade", [(0.5, scene["s4"], 0), (1, scene["s4"], 1)])
|
|
body = f'<g opacity=".7">{towers}</g><rect x="0" y="0" width="960" height="450" fill="url(#city_fade)"/>'
|
|
return defs, in_spread_space(body, 180), "bottom"
|
|
|
|
|
|
def space_scene(scene):
|
|
"""A purple nebula, one constellation and two orbit rings."""
|
|
defs = radial_gradient("space_nebula", [(0, scene["s1"], 1), (0.65, scene["s1"], 0)], radius=0.707)
|
|
stars = ((320, 40), (400, 80), (470, 60), (540, 110), (420, 150))
|
|
body = (f'<ellipse cx="760" cy="150" rx="260" ry="210" fill="url(#space_nebula)" opacity=".65"/>'
|
|
f'<g stroke="{scene["s2"]}" stroke-width="1" fill="{scene["s2"]}" opacity=".7">'
|
|
'<path d="M320 40 L400 80 L470 60 L540 110 M400 80 L420 150" fill="none"/>'
|
|
+ "".join(f'<circle cx="{x}" cy="{y}" r="3"/>' for x, y in stars) + "</g>"
|
|
f'<circle cx="140" cy="380" r="70" fill="none" stroke="{scene["s2"]}" stroke-width="1" opacity=".3"/>'
|
|
f'<circle cx="140" cy="380" r="110" fill="none" stroke="{scene["s2"]}" stroke-width="1" opacity=".2" '
|
|
'stroke-dasharray="4 6"/>')
|
|
return defs, in_spread_space(body, 90), "center"
|
|
|
|
|
|
def map_scene(scene):
|
|
"""A compass rose low on the page and darker, aged edges."""
|
|
rose = (f'<circle r="34" fill="none" stroke="{scene["s1"]}" stroke-width="1.2"/>'
|
|
f'<circle r="40" fill="none" stroke="{scene["s1"]}" stroke-width=".6"/>'
|
|
f'<path d="M0 -46 L6 -6 L46 0 L6 6 L0 46 L-6 6 L-46 0 L-6 -6Z" fill="{scene["s1"]}"/>'
|
|
f'<path d="M0 -46 L6 -6 L0 0Z M46 0 L6 6 L0 0Z M0 46 L-6 6 L0 0Z M-46 0 L-6 -6 L0 0Z" fill="{scene["s2"]}"/>'
|
|
f'<path d="M-2.6 -50 V-57 L2.6 -50 V-57" fill="none" stroke="{scene["s1"]}" stroke-width="1.1"/>')
|
|
rose_group = f'<g transform="translate(645 369) scale(1.5)" opacity=".55">{rose}</g>'
|
|
colour, opacity = css_colour(scene["s3"])
|
|
defs = radial_gradient("map_age", [(0.55, colour, 0), (1, colour, opacity)])
|
|
centre, radii = (SCENE_WIDTH * 0.5, SCENE_HEIGHT * 0.45), (SCENE_WIDTH * 0.8, SCENE_HEIGHT * 0.9)
|
|
age = (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(#map_age)"/>')
|
|
return defs, in_spread_space(rose_group, 180) + age, "bottom"
|
|
|
|
|
|
def story_scene(scene):
|
|
"""Soft watercolour washes."""
|
|
defs, body = "", ""
|
|
for index, (left, top, width, colour) in enumerate(((60, 40, 260, scene["s1"]), (620, -40, 320, scene["s2"]),
|
|
(380, 300, 300, scene["s3"]), (-60, 300, 240, scene["s2"]))):
|
|
gradient_id = f"wash_{index}"
|
|
defs += radial_gradient(gradient_id, [(0, colour, 1), (0.6, colour, 1), (1, colour, 0)])
|
|
height = width * 0.8
|
|
body += (f'<ellipse cx="{num(left + width / 2)}" cy="{num(top + height / 2)}" rx="{num(width / 2 + 14)}" '
|
|
f'ry="{num(height / 2 + 14)}" fill="url(#{gradient_id})" opacity=".45" '
|
|
f'transform="rotate({index * 23 - 30} {num(left + width / 2)} {num(top + height / 2)})"/>')
|
|
return defs, in_spread_space(body, 90), "center"
|
|
|
|
|
|
MORE_SCENE_MAKERS = {"blinds": blinds_scene, "eldritch": eldritch_scene, "burst": burst_scene, "city": city_scene,
|
|
"space": space_scene, "map": map_scene, "story": story_scene}
|