Files
2026-10-25 07:11:03 +01:00

122 lines
4.8 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""Synthetic dusk scene for the App Store screenshots.
Writes SVGs (rendered to PNG by make_screenshots.mjs) in the app's strip
geometry — 3072×1024 px, azimuth 0…360 left to right, altitude +90…−30 top to
bottom — plus the exact horizon profile of the scene.
python3 store/scene.py <out_dir>
"""
import json
import math
import sys
from pathlib import Path
W, H = 3072, 1024
TOP, BOTTOM = 90.0, -30.0
PHOTO_TOP, PHOTO_BOTTOM = 44.0, -22.0 # what 24 frames at +10° tilt cover
def X(az):
return az / 360 * W
def Y(alt):
return (TOP - alt) / (TOP - BOTTOM) * H
def bump(az, c, w, h):
d = (az - c + 540) % 360 - 180
return h * math.exp(-(d / w) ** 2)
def fir(az, c, w, h):
"""Fir tree: triangle with three branch tiers."""
d = abs((az - c + 540) % 360 - 180)
if d > w:
return -90
t = 1 - d / w
tier = 0.18 * h * (1 - ((t * 3) % 1))
return h * t - tier + 2
def alt_at(az):
a = 3.2 + 1.4 * math.sin(math.radians(az) * 3) + 0.8 * math.sin(math.radians(az) * 7 + 1)
a += 0.35 * math.sin(az * 2.3) + 0.25 * math.sin(az * 5.7) # grass / shrubs
# house (roof peak at 49°, chimney at 54°)
if 38 <= az <= 60:
roof = 15 - abs(az - 49) * (6 / 11)
a = max(a, 9, roof)
if 53 <= az <= 55:
a = max(a, 16.5)
# deciduous trees
canopy = max(bump(az, 112, 9, 26), bump(az, 100, 6, 21), bump(az, 127, 6, 18), bump(az, 138, 4, 13))
if canopy > 4:
canopy += 0.9 * math.sin(az * 11) + 0.6 * math.sin(az * 23)
a = max(a, canopy)
# fir trees
for c, w, h in ((205, 5, 22), (214, 4, 17), (224, 6, 25), (232, 3.5, 15)):
a = max(a, fir(az, c, w, h))
# distant tree line and a poplar
if 280 <= az <= 330:
a = max(a, 8.5 + 1.5 * math.sin(az * 0.9) + 0.8 * math.sin(az * 4.1))
a = max(a, bump(az, 346, 1.4, 20))
return a
def silhouette_path(az_max=360.0):
pts = []
n = int(az_max * 10)
for i in range(n + 1):
az = i / 10
pts.append(f'{X(az):.1f},{Y(alt_at(az)):.1f}')
return f'M0,{Y(PHOTO_BOTTOM):.1f} L' + ' L'.join(pts) + f' L{X(az_max):.1f},{Y(PHOTO_BOTTOM):.1f} Z'
def scene_svg(az_max=360.0, view=None, size=(W, H)):
vb = view or (0, 0, W, H)
band = f'<rect x="0" y="{Y(PHOTO_TOP):.1f}" width="{X(az_max):.1f}" height="{Y(PHOTO_BOTTOM) - Y(PHOTO_TOP):.1f}"/>'
house = (f'<rect x="{X(43):.1f}" y="{Y(6.2):.1f}" width="{X(46) - X(43):.1f}" height="{Y(3) - Y(6.2):.1f}" fill="#E8A447" opacity="0.85"/>'
f'<rect x="{X(51):.1f}" y="{Y(5.8):.1f}" width="{X(53.5) - X(51):.1f}" height="{Y(3.2) - Y(5.8):.1f}" fill="#E8A447" opacity="0.22"/>')
return f'''<svg xmlns="http://www.w3.org/2000/svg" width="{size[0]}" height="{size[1]}" viewBox="{' '.join(f'{v:.1f}' for v in vb)}" preserveAspectRatio="none">
<defs>
<linearGradient id="sky" x1="0" y1="{Y(PHOTO_TOP):.1f}" x2="0" y2="{Y(0):.1f}" gradientUnits="userSpaceOnUse">
<stop offset="0" stop-color="#4C6C96"/><stop offset="0.65" stop-color="#93ABC6"/><stop offset="1" stop-color="#C9D6E2"/>
</linearGradient>
<linearGradient id="ground" x1="0" y1="{Y(26):.1f}" x2="0" y2="{Y(PHOTO_BOTTOM):.1f}" gradientUnits="userSpaceOnUse">
<stop offset="0" stop-color="#0E160D"/><stop offset="1" stop-color="#151A10"/>
</linearGradient>
<filter id="grain" x="0" y="0" width="100%" height="100%">
<feTurbulence type="fractalNoise" baseFrequency="0.9" numOctaves="2" seed="7" result="n"/>
<feColorMatrix in="n" type="matrix" values="0 0 0 0 0.10 0 0 0 0 0.13 0 0 0 0 0.07 0 0 0 0.35 0"/>
<feComposite in2="SourceGraphic" operator="in"/>
</filter>
<clipPath id="band">{band}</clipPath>
</defs>
<g clip-path="url(#band)">
<rect x="0" y="0" width="{W}" height="{H}" fill="url(#sky)"/>
<path d="{silhouette_path(min(az_max + 1, 360))}" fill="url(#ground)"/>
<path d="{silhouette_path(min(az_max + 1, 360))}" fill="#000" filter="url(#grain)"/>
{house}
</g>
</svg>
'''
def main():
out = Path(sys.argv[1])
out.mkdir(parents=True, exist_ok=True)
(out / 'strip_full.svg').write_text(scene_svg())
(out / 'strip_partial.svg').write_text(scene_svg(az_max=210))
# Portrait camera frame: 39° × 64°, centred on azimuth 205°, altitude +10°.
hfov, vfov, az0, alt0 = 39.0, 64.0, 205.0, 10.0
view = (X(az0 - hfov / 2), Y(alt0 + vfov / 2), X(hfov), Y(alt0 - vfov / 2) - Y(alt0 + vfov / 2))
(out / 'camera.svg').write_text(scene_svg(view=view, size=(1080, 1920)))
# Exact profile, as the app derives it: highest edge within ±0.5° per degree.
profile = [round(max(alt_at(d + k / 10) for k in range(-5, 6)), 2) for d in range(360)]
(out / 'profile.json').write_text(json.dumps(profile))
print('scene written to', out, '| max altitude', max(profile))
if __name__ == '__main__':
main()