"""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'') 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'' '' '' '') 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'' 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'' 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'') x += width + 4 defs = vertical_gradient("city_fade", [(0.5, scene["s4"], 0), (1, scene["s4"], 1)]) body = f'{towers}' 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'' f'' '' + "".join(f'' for x, y in stars) + "" f'' f'') 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'' f'' f'' f'' f'') rose_group = f'{rose}' 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'') 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'') 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}