diff --git a/.claude/skills/motion-video/toolkit/dc/build-dc-timeline.py b/.claude/skills/motion-video/toolkit/dc/build-dc-timeline.py new file mode 100644 index 0000000..fbf3059 --- /dev/null +++ b/.claude/skills/motion-video/toolkit/dc/build-dc-timeline.py @@ -0,0 +1,64 @@ +# v9 timeline: slow beats incl. three aborted landings at DCA with a chase camera; fast-forward between. +import json, math, bisect +C = json.load(open('dcv/config.json')); P = json.load(open('day-planes.json')) +def mins(c): p = c.split(':'); return int(p[0]) * 60 + int(p[1]) + (int(p[2]) / 60 if len(p) > 2 else 0) +def hm(t): t = round(t * 60); h, r = divmod(t, 3600); m, s = divmod(r, 60); return f"{h}:{m:02d}:{s:02d}" +def seg(s0, s1, c0, c1, n): a, b = mins(c0), mins(c1); return [[round(s0 + (s1 - s0) * i / n, 3), hm(a + (b - a) * i / n)] for i in range(n + 1)] +BEATS = [ # s0, s1, clock0, clock1, kind + (5, 12, '1:12', '1:30', 'wide'), (14, 21, '4:37', '4:55', 'wide'), + (23, 35, '7:05', '7:20', ('ga', 'ac1951')), + (37, 49, '8:00', '8:25', 'city'), (51, 65, '9:48', '10:08', 'air'), + (67, 86, '12:38', '12:55', ('ga', 'ab7b02')), + (88, 100, '16:28', '16:47', ('ga', 'a36200')), + (102, 114, '17:20', '17:45', 'city'), +] +W = [[0, '8:13'], [3, '8:16'], [3, '0:00']] +for s0, s1, c0, c1, k in BEATS: W += seg(s0, s1, c0, c1, 12 if isinstance(k, tuple) else 4) +W += [[117, '23:59'], [120, '23:59:59']] +C['warp'] = W; C['len'] = 120; C['outro_from'] = 117; C['slices'] = 20 +D0 = 1794978000000 - 5 * 3600000 + 5 * 3600000 # placeholder, replaced below +from datetime import datetime, timezone, timedelta +ET = timezone(timedelta(hours=-5)); D0 = int(datetime(2026, 11, 18, tzinfo=ET).timestamp() * 1000) +DCA = (-77.0377, 38.8521); K = 111320 * math.cos(math.radians(38.85)); MPU = 19.6 # metres per world unit +def ppos(icao, T): + tr = P['tracks'][icao]; ts = [r[0] for r in tr]; i = bisect.bisect_right(ts, T) - 1 + if i < 0: return tr[0][1:4] + if i >= len(tr) - 1: return tr[-1][1:4] + a, b = tr[i], tr[i + 1]; u = (T - a[0]) / max(1, b[0] - a[0]); return [a[1] + (b[1] - a[1]) * u, a[2] + (b[2] - a[2]) * u, (a[3] or 0) + ((b[3] or 0) - (a[3] or 0)) * u] +CAM = {'wide': (-77.045, 38.91, -15, 40, 1900), 'city': (-77.03, 38.898, -4, 48, 1000), 'air': (-77.039, 38.853, 2, 55, 560)} +cam = [[0, -77.03, 38.898, -15, 48, 800, 0], [3, -77.03, 38.898, -10, 50, 850, 0], [3, -77.05, 38.915, -12, 38, 2200, 0]] +HLs = {} +for s0, s1, c0, c1, k in BEATS: + if isinstance(k, tuple): + ic = k[1]; HLs[ic] = [D0 + int(mins(c0) * 60000) - 60000, D0 + int(mins(c1) * 60000) + 60000] + n = int(s1 - s0) + for q in range(n + 1): + s = s0 + q; T = D0 + int((mins(c0) + (mins(c1) - mins(c0)) * q / n) * 60000); lon, lat, ft = ppos(ic, T) + sep = math.hypot((lon - DCA[0]) * K, (lat - DCA[1]) * 111320) + tx, ty = DCA[0] + (lon - DCA[0]) * 0.85, DCA[1] + (lat - DCA[1]) * 0.85 + dist = max(380, min(1600, sep / MPU * 1.6)) + cam.append([s, round(tx, 5), round(ty, 5), round(-8 + 18 * q / n, 1), 54, round(dist), 0, round(ft * 0.9)]) + else: + x, y, az, ti, di = CAM[k]; cam += [[s0, x, y, az - 4, ti, di, 0], [s1, x, y, az + 6, ti, di * 0.95, 0]] +cam += [[117, -77.05, 38.915, 0, 38, 2300, 0], [120, -77.05, 38.915, 0, 38, 2300, 0]] +C['cam'] = cam +T_, P_ = dict(transit=1, planes=0.6, lime=0), dict(transit=0.55, planes=1, lime=0) +foc = [[0, T_]] +for s0, s1, c0, c1, k in BEATS: + w = P_ if (isinstance(k, tuple) or k == 'air') else T_ + foc += [[max(0, s0 - 1.5), w], [s1, w]] +C['focus'] = foc + [[120, T_]] +C['look'].update({'camSpline': True, 'planeHL': HLs, 'altScale': 0.5}) +C['cards'] = [ + {"at": "1:17", "hold": 5, "kick": "1:17 am", "fact": None, "text": "The last Metro train of the night stops."}, + {"at": "4:40", "hold": 5, "kick": "1:17 to 4:40 am", "fact": "metro_dark_minutes", "big": " min", "text": "with no Metro trains moving. The buses kept going."}, + {"at": "7:08", "hold": 5, "kick": "7:08 am", "fact": None, "text": "A jet pulls up over the runway instead of landing, and circles back."}, + {"at": "8:15", "hold": 5, "kick": "8:15 am", "fact": "all_peak_am", "text": "trains and buses moving at once."}, + {"at": "10:00", "hold": 5, "kick": "9 to 10 am", "fact": "DCA_by_hour", "value_path": ["value", "9"], "text": "flights in and out of Reagan National."}, + {"at": "12:42", "hold": 5, "kick": "12:41 pm", "fact": None, "text": "Another one. American 1177 aborts its landing."}, + {"at": "12:52", "hold": 3, "kick": "12:52 pm", "fact": None, "text": "It lands on the second try."}, + {"at": "16:31", "hold": 5, "kick": "4:31 pm", "fact": None, "text": "A third aborted landing, Delta 1454. It lands 15 minutes later."}, + {"at": "17:32", "hold": 5, "kick": "5:32 pm", "fact": "all_peak_pm", "text": "trains and buses moving at once, the busiest moment of the day."}, +] +json.dump(C, open('dcv/config.json', 'w'), indent=1) +print(len(cam), 'cam keys', HLs) diff --git a/.claude/skills/motion-video/toolkit/dc/config.json b/.claude/skills/motion-video/toolkit/dc/config.json index a28b49d..f15afe7 100644 --- a/.claude/skills/motion-video/toolkit/dc/config.json +++ b/.claude/skills/motion-video/toolkit/dc/config.json @@ -1,16 +1,16 @@ { "name": "Washington", "day": "2026-11-18", - "len": 79.5, + "len": 120, "fps": 30, "prefix": "day", - "slices": 15, + "slices": 20, "title": "24 hours in Washington", "kicker": "WEDNESDAY, NOVEMBER 18", "sub": "every Metro train, bus and flight, recorded live", "date": "wednesday, november 18", "outro_line": "recorded live, nothing simulated", - "outro_from": 76.5, + "outro_from": 117, "hook": { "place": "Washington", "line": "Metro trains and buses moving right now.", @@ -31,12 +31,12 @@ "railW": 1.6, "dotScale": 1.3, "dotBright": 1.2, - "busA": 0.75, + "busA": 0.5, "fogNear": 6500, "fogFar": 16000, "runways": "dc/runways.json", "planeScale": 0.4, - "drops": false, + "drops": true, "railDim": 0.55, "railOpacity": 1.0, "trainCore": true, @@ -44,7 +44,27 @@ "railMiter": true, "overTrails": false, "ringScale": 0.45, - "ringAlpha": 0.55 + "ringAlpha": 0.55, + "beams": true, + "beamH": 0.13, + "beamA": 0.6, + "dropMaxFt": 4000, + "camSpline": true, + "planeHL": { + "ac1951": [ + 1795003440000, + 1795004460000 + ], + "ab7b02": [ + 1795023420000, + 1795024560000 + ], + "a36200": [ + 1795037220000, + 1795038480000 + ] + }, + "altScale": 0.5 }, "warp": [ [ @@ -61,114 +81,266 @@ ], [ 5.0, - "1:05" + "1:12:00" ], [ 6.75, - "1:10" + "1:16:30" ], [ 8.5, - "1:15" + "1:21:00" ], [ 10.25, - "1:20" + "1:25:30" ], [ 12.0, - "1:25" + "1:30:00" ], [ 14.0, - "4:30" + "4:37:00" ], [ 15.75, - "4:35" + "4:41:30" ], [ 17.5, - "4:40" + "4:46:00" ], [ 19.25, - "4:45" + "4:50:30" ], [ 21.0, - "4:50" + "4:55:00" + ], + [ + 23.0, + "7:05:00" + ], + [ + 24.0, + "7:06:15" ], [ - 23.5, - "7:50" + 25.0, + "7:07:30" + ], + [ + 26.0, + "7:08:45" ], [ 27.0, - "8:00" + "7:10:00" + ], + [ + 28.0, + "7:11:15" + ], + [ + 29.0, + "7:12:30" ], [ - 30.5, - "8:10" + 30.0, + "7:13:45" + ], + [ + 31.0, + "7:15:00" + ], + [ + 32.0, + "7:16:15" + ], + [ + 33.0, + "7:17:30" ], [ 34.0, - "8:20" + "7:18:45" ], [ - 37.5, - "8:30" + 35.0, + "7:20:00" + ], + [ + 37.0, + "8:00:00" ], [ 40.0, - "9:40" + "8:06:15" ], [ - 43.4, - "9:45" + 43.0, + "8:12:30" ], [ - 46.8, - "9:50" + 46.0, + "8:18:45" ], [ - 50.2, - "9:55" + 49.0, + "8:25:00" ], [ - 53.6, - "10:00" + 51.0, + "9:48:00" ], [ - 57.0, - "10:05" + 54.5, + "9:53:00" ], [ - 59.5, - "17:15" + 58.0, + "9:58:00" ], [ - 63.0, - "17:25" + 61.5, + "10:03:00" ], [ - 66.5, - "17:35" + 65.0, + "10:08:00" ], [ - 70.0, - "17:45" + 67.0, + "12:38:00" ], [ - 73.5, - "17:55" + 68.583, + "12:39:25" + ], + [ + 70.167, + "12:40:50" + ], + [ + 71.75, + "12:42:15" + ], + [ + 73.333, + "12:43:40" + ], + [ + 74.917, + "12:45:05" ], [ 76.5, + "12:46:30" + ], + [ + 78.083, + "12:47:55" + ], + [ + 79.667, + "12:49:20" + ], + [ + 81.25, + "12:50:45" + ], + [ + 82.833, + "12:52:10" + ], + [ + 84.417, + "12:53:35" + ], + [ + 86.0, + "12:55:00" + ], + [ + 88.0, + "16:28:00" + ], + [ + 89.0, + "16:29:35" + ], + [ + 90.0, + "16:31:10" + ], + [ + 91.0, + "16:32:45" + ], + [ + 92.0, + "16:34:20" + ], + [ + 93.0, + "16:35:55" + ], + [ + 94.0, + "16:37:30" + ], + [ + 95.0, + "16:39:05" + ], + [ + 96.0, + "16:40:40" + ], + [ + 97.0, + "16:42:15" + ], + [ + 98.0, + "16:43:50" + ], + [ + 99.0, + "16:45:25" + ], + [ + 100.0, + "16:47:00" + ], + [ + 102.0, + "17:20:00" + ], + [ + 105.0, + "17:26:15" + ], + [ + 108.0, + "17:32:30" + ], + [ + 111.0, + "17:38:45" + ], + [ + 114.0, + "17:45:00" + ], + [ + 117, "23:59" ], [ - 79.5, + 120, "23:59:59" ] ], @@ -201,79 +373,557 @@ 0 ], [ - 21, + 5, -77.045, 38.91, - -15, + -19, + 40, + 1900, + 0 + ], + [ + 12, + -77.045, + 38.91, + -9, + 40, + 1805.0, + 0 + ], + [ + 14, + -77.045, + 38.91, + -19, 40, 1900, 0 ], [ - 23.5, - -77.035, - 38.902, + 21, + -77.045, + 38.91, + -9, + 40, + 1805.0, + 0 + ], + [ + 23, + -76.99626, + 38.74636, + -8.0, + 54, + 1182, + 0, + 2211 + ], + [ + 24, + -77.03006, + 38.78049, + -6.5, + 54, + 768, + 0, + 1600 + ], + [ + 25, + -77.03454, + 38.82592, + -5.0, + 54, + 380, + 0, + 451 + ], + [ + 26, + -77.07181, + 38.85386, + -3.5, + 54, + 380, + 0, + 2258 + ], + [ + 27, + -77.12677, + 38.82456, + -2.0, + 54, + 798, + 0, + 2182 + ], + [ + 28, + -77.12261, + 38.76051, + -0.5, + 54, + 1208, + 0, + 2182 + ], + [ + 29, + -77.11855, + 38.70607, + 1.0, + 54, + 1600, + 0, + 2182 + ], + [ + 30, + -77.08591, + 38.67491, + 2.5, + 54, + 1600, + 0, + 2182 + ], + [ + 31, + -77.03966, + 38.70335, + 4.0, + 54, + 1590, + 0, + 2141 + ], + [ + 32, + -77.02869, + 38.74652, + 5.5, + 54, + 1131, + 0, + 1535 + ], + [ + 33, + -77.03137, + 38.78805, + 7.0, + 54, + 687, + 0, + 691 + ], + [ + 34, + -77.03512, + 38.82447, + 8.5, + 54, + 380, + 0, + 89 + ], + [ + 35, + -77.03831, + 38.85232, + 10.0, + 54, + 380, + 0, + 0 + ], + [ + 37, + -77.03, + 38.898, -8, - 46, - 1100, + 48, + 1000, 0 ], [ - 37.5, + 49, -77.03, 38.898, - 4, + 2, 48, - 950, + 950.0, 0 ], [ - 40, - -77.038, - 38.856, - -12, - 52, - 620, + 51, + -77.039, + 38.853, + -2, + 55, + 560, 0 ], [ - 48.5, - -77.04, - 38.852, - 2, + 65, + -77.039, + 38.853, + 8, 55, - 540, + 532.0, 0 ], [ - 57, - -77.04, - 38.85, - 14, - 56, - 580, + 67, + -77.13825, + 38.78317, + -8.0, + 54, + 1115, + 0, + 3107 + ], + [ + 68, + -77.08719, + 38.75471, + -7.1, + 54, + 1120, + 0, + 2106 + ], + [ + 69, + -77.03748, + 38.7686, + -6.1, + 54, + 893, + 0, + 1229 + ], + [ + 70, + -77.03236, + 38.80347, + -5.2, + 54, + 522, + 0, + 432 + ], + [ + 71, + -77.03802, + 38.84134, + -4.2, + 54, + 380, + 0, + 1217 + ], + [ + 72, + -77.08671, + 38.85816, + -3.3, + 54, + 413, + 0, + 2202 + ], + [ + 73, + -77.12367, + 38.83221, + -2.3, + 54, + 747, + 0, + 2205 + ], + [ + 74, + -77.1228, + 38.78655, + -1.4, + 54, + 997, + 0, + 2205 + ], + [ + 75, + -77.1181, + 38.7406, + -0.4, + 54, + 1367, + 0, + 2216 + ], + [ + 76, + -77.10077, + 38.6961, + 0.5, + 54, + 1600, + 0, + 2205 + ], + [ + 77, + -77.06035, + 38.69185, + 1.5, + 54, + 1600, + 0, + 2205 + ], + [ + 78, + -77.02618, + 38.71335, + 2.4, + 54, + 1487, + 0, + 2164 + ], + [ + 79, + -77.02749, + 38.74997, + 3.4, + 54, + 1095, + 0, + 1468 + ], + [ + 80, + -77.03323, + 38.78506, + 4.3, + 54, + 718, + 0, + 812 + ], + [ + 81, + -77.03396, + 38.81564, + 5.3, + 54, + 391, + 0, + 149 + ], + [ + 82, + -77.03711, + 38.84538, + 6.2, + 54, + 380, + 0, 0 ], [ - 59.5, + 83, + -77.0391, + 38.85492, + 7.2, + 54, + 380, + 0, + 0 + ], + [ + 84, + -77.03983, + 38.85506, + 8.1, + 54, + 380, + 0, + 0 + ], + [ + 85, + -77.04023, + 38.85575, + 9.1, + 54, + 380, + 0, + 0 + ], + [ + 86, + -77.04087, + 38.8557, + 10.0, + 54, + 380, + 0, + 0 + ], + [ + 88, + -77.0254, + 38.72846, + -8.0, + 54, + 1326, + 0, + 1961 + ], + [ + 89, + -77.03227, + 38.78922, + -6.5, + 54, + 674, + 0, + 706 + ], + [ + 90, + -77.0367, + 38.84071, + -5.0, + 54, + 380, + 0, + 478 + ], + [ + 91, + -77.10886, + 38.86378, + -3.5, + 54, + 606, + 0, + 2250 + ], + [ + 92, + -77.14402, + 38.79968, + -2.0, + 54, + 1048, + 0, + 2246 + ], + [ + 93, + -77.13974, + 38.72439, + -0.5, + 54, + 1600, + 0, + 2250 + ], + [ + 94, + -77.13439, + 38.64978, + 1.0, + 54, + 1600, + 0, + 2250 + ], + [ + 95, + -77.07954, + 38.61257, + 2.5, + 54, + 1600, + 0, + 2250 + ], + [ + 96, + -77.01948, + 38.65578, + 4.0, + 54, + 1600, + 0, + 2250 + ], + [ + 97, + -77.02471, + 38.72141, + 5.5, + 54, + 1401, + 0, + 2091 + ], + [ + 98, + -77.03182, + 38.78444, + 7.0, + 54, + 725, + 0, + 780 + ], + [ + 99, + -77.03602, + 38.83355, + 8.5, + 54, + 380, + 0, + 0 + ], + [ + 100, + -77.03918, + 38.85404, + 10.0, + 54, + 380, + 0, + 0 + ], + [ + 102, -77.03, 38.898, - -10, + -8, 48, 1000, 0 ], [ - 73.5, + 114, -77.03, - 38.9, - 8, - 46, - 1100, + 38.898, + 2, + 48, + 950.0, 0 ], [ - 76.5, + 117, -77.05, 38.915, 0, @@ -282,7 +932,7 @@ 0 ], [ - 79.5, + 120, -77.05, 38.915, 0, @@ -301,7 +951,7 @@ } ], [ - 37.5, + 3.5, { "transit": 1, "planes": 0.6, @@ -309,23 +959,47 @@ } ], [ - 40, + 12, { - "transit": 0.6, + "transit": 1, + "planes": 0.6, + "lime": 0 + } + ], + [ + 12.5, + { + "transit": 1, + "planes": 0.6, + "lime": 0 + } + ], + [ + 21, + { + "transit": 1, + "planes": 0.6, + "lime": 0 + } + ], + [ + 21.5, + { + "transit": 0.55, "planes": 1, "lime": 0 } ], [ - 57, + 35, { - "transit": 0.6, + "transit": 0.55, "planes": 1, "lime": 0 } ], [ - 59, + 35.5, { "transit": 1, "planes": 0.6, @@ -333,68 +1007,155 @@ } ], [ - 79.5, + 49, { "transit": 1, "planes": 0.6, "lime": 0 } - ] - ], - "chapters": [ + ], + [ + 49.5, + { + "transit": 0.55, + "planes": 1, + "lime": 0 + } + ], + [ + 65, + { + "transit": 0.55, + "planes": 1, + "lime": 0 + } + ], + [ + 65.5, + { + "transit": 0.55, + "planes": 1, + "lime": 0 + } + ], + [ + 86, + { + "transit": 0.55, + "planes": 1, + "lime": 0 + } + ], + [ + 86.5, + { + "transit": 0.55, + "planes": 1, + "lime": 0 + } + ], + [ + 100, + { + "transit": 0.55, + "planes": 1, + "lime": 0 + } + ], [ - "6:00", - "rush hour" + 100.5, + { + "transit": 1, + "planes": 0.6, + "lime": 0 + } ], [ - "9:45", - "national airport" + 114, + { + "transit": 1, + "planes": 0.6, + "lime": 0 + } ], [ - "15:30", - "evening rush" + 120, + { + "transit": 1, + "planes": 0.6, + "lime": 0 + } ] ], + "chapters": [], "cards": [ { "at": "1:17", - "hold": 3.4, + "hold": 5, "kick": "1:17 am", "fact": null, - "text": "The last Metro train stops moving." + "text": "The last Metro train of the night stops." }, { "at": "4:40", - "hold": 3.4, - "kick": "4:40 am", + "hold": 5, + "kick": "1:17 to 4:40 am", "fact": "metro_dark_minutes", - "count_up": false, - "text": "Metro sat dark for 3 hours 23 minutes. The buses never stopped." + "big": " min", + "text": "with no Metro trains moving. The buses kept going." + }, + { + "at": "7:08", + "hold": 5, + "kick": "7:08 am", + "fact": null, + "text": "A jet pulls up over the runway instead of landing, and circles back." }, { "at": "8:15", - "hold": 3.4, - "kick": "8:15 am, the peak", + "hold": 5, + "kick": "8:15 am", "fact": "all_peak_am", - "text": "Metro trains and buses moving at the same moment." + "text": "trains and buses moving at once." }, { "at": "10:00", - "hold": 3.4, + "hold": 5, "kick": "9 to 10 am", "fact": "DCA_by_hour", - "text": "landings and takeoffs at Reagan National in that one hour.", "value_path": [ "value", "9" - ] + ], + "text": "flights in and out of Reagan National." + }, + { + "at": "12:42", + "hold": 5, + "kick": "12:41 pm", + "fact": null, + "text": "Another one. American 1177 aborts its landing." + }, + { + "at": "12:52", + "hold": 3, + "kick": "12:52 pm", + "fact": null, + "text": "It lands on the second try." + }, + { + "at": "16:31", + "hold": 5, + "kick": "4:31 pm", + "fact": null, + "text": "A third aborted landing, Delta 1454. It lands 15 minutes later." }, { "at": "17:32", - "hold": 3.4, - "kick": "5:32 pm, the evening peak", + "hold": 5, + "kick": "5:32 pm", "fact": "all_peak_pm", - "text": "Metro trains and buses moving at once, more than the morning." + "text": "trains and buses moving at once, the busiest moment of the day." } ], "legend": [ @@ -413,5 +1174,13 @@ "label": "flight" } ], - "ff_chip": true + "ff_chip": true, + "quiet": { + "labelKeep": [ + "White House", + "Capitol", + "Reagan National" + ], + "legendSecs": 7 + } } \ No newline at end of file diff --git a/.claude/skills/motion-video/toolkit/dc/make-dc-job.py b/.claude/skills/motion-video/toolkit/dc/make-dc-job.py index b4206c8..d9d9b23 100644 --- a/.claude/skills/motion-video/toolkit/dc/make-dc-job.py +++ b/.claude/skills/motion-video/toolkit/dc/make-dc-job.py @@ -39,9 +39,9 @@ def clock(v): return [f for s0, f in fs_ if s0 <= v][-1](v) if i not in cuts: assert tmap[i] >= tmap[i - 1], ('time ran backwards', i) # ---- camera: keyframes; a repeated second = cut (two keys one frame apart) keys, prev = [], None -for s, lon, lat, az, ti, di, le in C['cam']: +for s, lon, lat, az, ti, di, le, *rest in C['cam']: # optional 8th value: look-at height above ground in feet (chase shots) f = F(s) + (1 if prev is not None and F(s) <= prev else 0); prev = f - keys.append({'f': f, 'at': [lon, lat], 'az': az, 'tilt': ti, 'dist': di, 'lead': le}) + keys.append({'f': f, 'at': [lon, lat], 'az': az, 'tilt': ti, 'dist': di, 'lead': le, 'lzft': rest[0] if rest else 0}) focus = [{'f': F(s), 'w': w} for s, w in C['focus']] # ---- cards: appear only once the clock has reached their time, after any cut, never overlapping def first_frame(c, after=0): @@ -71,7 +71,7 @@ def series(T): i = (T - run['t0']) // run['step']; return run['all'][int(max(0, 'dayStart': D0, 'sunrise': clk(L['sunrise']), 'sunset': clk(L['sunset']), 'noon': clk(L['noon'])} base = {'warm': 48, 'page': 'dc.html', 'assets': {'/hi-core.png': L['hi_png'], '/fonts/': 'fonts'}, 'extraJson': {'rail': 'dc/rail-lines.json', 'transit': f'{pre}-transit.json', 'planes': f'{pre}-planes.json', 'lime': f'{pre}-lime.json'}} -look.update({k: L[k] for k in ('dotScale', 'dotBright', 'busA', 'bloom', 'railOpacity', 'railDim', 'planeScale', 'drops', 'trainCore', 'busColor', 'railMiter', 'overTrails', 'ringScale', 'ringAlpha') if k in L}) # clarity knobs, optional +look.update({k: L[k] for k in ('dotScale', 'dotBright', 'busA', 'bloom', 'railOpacity', 'railDim', 'planeScale', 'drops', 'trainCore', 'busColor', 'railMiter', 'overTrails', 'ringScale', 'ringAlpha', 'beams', 'beamH', 'beamA', 'dropMaxFt', 'camSpline', 'planeHL', 'altScale') if k in L}) # clarity knobs, optional if L.get('runways'): base['extraJson']['airport'] = L['runways'] NS = C.get('slices', 12) job = dict(base); job.update({'total': N, 'fps': FPS, 'look': look, 'slices': [{'f0': i * N // NS, 'f1': (i + 1) * N // NS} for i in range(NS)]}) @@ -80,7 +80,7 @@ def series(T): i = (T - run['t0']) // run['step']; return run['all'][int(max(0, json.dump(job, open(os.path.join(OUTD, 'job-test.json'), 'w')) else: json.dump(job, open(os.path.join(OUTD, 'job.json'), 'w')) tl = {'total': N, 'fps': FPS, 'clock': tmap, 'date': C['date'], 'title': C['title'], 'kicker': C.get('kicker', 'MOTION'), 'sub': C['sub'], 'counter': counter, - 'cards': cards, 'chapters': chapters, 'cuts': cuts, 'dayStart': D0, 'pins': {}, 'hook': C.get('hook'), 'outroLine': C.get('outro_line', ''), 'legend': C.get('legend'), 'ffChip': C.get('ff_chip', False), 'credit': C['credit'], 'outroFrom': F(C.get('outro_from', DUR - 3)), 'frameDir': 'frames'} + 'cards': cards, 'chapters': chapters, 'cuts': cuts, 'dayStart': D0, 'pins': {}, 'hook': C.get('hook'), 'outroLine': C.get('outro_line', ''), 'legend': C.get('legend'), 'ffChip': C.get('ff_chip', False), 'quiet': C.get('quiet'), 'credit': C['credit'], 'outroFrom': F(C.get('outro_from', DUR - 3)), 'frameDir': 'frames'} json.dump(tl, open(os.path.join(OUTD, 'timeline.json'), 'w')) for c in cards: print(f"{c['f0']/FPS:6.1f}-{c['f1']/FPS:6.1f}s clock {datetime.fromtimestamp(tmap[c['f0']]/1000, ET):%H:%M} {c['kick']}: {c['text']}") print('frames', N, 'cuts at', [c / FPS for c in cuts]) diff --git a/.claude/skills/motion-video/toolkit/dc/snap-rail.py b/.claude/skills/motion-video/toolkit/dc/snap-rail.py new file mode 100644 index 0000000..c1434d2 --- /dev/null +++ b/.claude/skills/motion-video/toolkit/dc/snap-rail.py @@ -0,0 +1,80 @@ +# Put Metro trains on their tracks. +# usage: python3 snap-rail.py REC_DIR PREFIX [RAIL_LINES] +# Rewrites the wmata-rail tracks in PREFIX-transit.json: +# - one track per run on a single route (a train that switches Blue -> Silver becomes two tracks, each the right colour) +# - every fix snapped onto its line's geometry (fixes more than 250 m from it, e.g. yards, are dropped) +# - points added along the line between fixes, so motion follows curves instead of cutting chords +# - default rows are [t_ms, metres along the line] with props.arc = 1; three/dc.html walks the same line geometry +# (same east/north metric) to place the train and shifts it by its line's ribbon offset, so it rides its own ribbon. +# SNAP_MODE=points instead writes densified [t_ms, lon, lat, nx, ny] rows (much heavier on page memory). +import glob, json, math, os, sys +from collections import defaultdict +import numpy as np + +rec, pre = sys.argv[1], sys.argv[2] +lines_path = sys.argv[3] if len(sys.argv) > 3 else os.path.join(os.path.dirname(__file__), 'rail-lines.json') +COL = {'RED': '#BF0D3E', 'BLUE': '#009CDE', 'ORANGE': '#ED8B00', 'SILVER': '#A2A4A1', 'GREEN': '#00B140', 'YELLOW': '#FFD100'} +LAT0 = 38.9; KX, KY = 111320 * math.cos(math.radians(LAT0)), 110540 +STEP_M, SNAP_M, GAP_MS = 120, 250, 600000 +MODE = os.environ.get('SNAP_MODE', 'arc') # 'arc' (default): store metres along the line; 'points': densified lon/lat rows + +L = {} +for l in json.load(open(lines_path))['lines']: + if l['r'] not in COL: continue + P = np.array(l['pts'], float); E = (P[:, 0] + 77) * KX; N = (P[:, 1] - LAT0) * KY + dE, dN = np.diff(E), np.diff(N); seg = np.hypot(dE, dN); seg[seg == 0] = 1e-6 + cum = np.concatenate([[0], np.cumsum(seg)]) + # per-vertex normal from neighbours, the same miter normal the page builds its ribbon from + a = np.r_[0, np.arange(len(P) - 1)]; b = np.r_[np.arange(1, len(P)), len(P) - 1] + vE, vN = E[b] - E[a], N[b] - N[a]; vl = np.hypot(vE, vN); vl[vl == 0] = 1 + L[l['r']] = dict(P=P, E=E, N=N, dE=dE, dN=dN, seg=seg, cum=cum, nE=-vN / vl, nN=vE / vl) + +def snap(r, lon, lat): + g = L[r]; x, y = (lon + 77) * KX, (lat - LAT0) * KY + t = np.clip(((x - g['E'][:-1]) * g['dE'] + (y - g['N'][:-1]) * g['dN']) / g['seg'] ** 2, 0, 1) + d = np.hypot(g['E'][:-1] + t * g['dE'] - x, g['N'][:-1] + t * g['dN'] - y); i = int(d.argmin()) + return float(d[i]), float(g['cum'][i] + t[i] * g['seg'][i]) + +def at(r, s): + g = L[r]; s = min(max(s, 0), g['cum'][-1]); i = int(min(np.searchsorted(g['cum'], s, 'right') - 1, len(g['seg']) - 1)); u = (s - g['cum'][i]) / g['seg'][i] + lon = g['P'][i, 0] + (g['P'][i + 1, 0] - g['P'][i, 0]) * u; lat = g['P'][i, 1] + (g['P'][i + 1, 1] - g['P'][i, 1]) * u + nE = g['nE'][i] + (g['nE'][i + 1] - g['nE'][i]) * u; nN = g['nN'][i] + (g['nN'][i + 1] - g['nN'][i]) * u; nl = math.hypot(nE, nN) or 1 + return [round(lon, 6), round(lat, 6), round(nE / nl, 3), round(nN / nl, 3)] + +fix = defaultdict(dict) +for f in sorted(glob.glob(f'{rec}/*/rail.jsonl')): + for line in open(f): + try: j = json.loads(line) + except ValueError: continue + for vid, lon, lat, route, trip, brg, ts in j['d']: + if route in L: fix[vid][ts * 1000] = (route, lon, lat) + +T = json.load(open(f'{pre}-transit.json')) +for k in [k for k, p in T['props'].items() if p['f'] == 'wmata-rail']: del T['props'][k]; T['tracks'].pop(k, None) +nfix = nkept = npts = nruns = 0 +for vid, F in fix.items(): + run, rid, prev = [], 0, None + def flush(): + global nruns, npts + if len(run) < 2: return + r = run[0][1] + if MODE == 'arc': # rows [t_ms, metres along the line]; the page walks the line geometry itself (light on memory) + rows = [[ts, round(s, 1)] for ts, _, s in run] + else: + rows = [] + for (t0, _, s0), (t1, _, s1) in zip(run, run[1:]): + n = max(1, int(abs(s1 - s0) // STEP_M)) if t1 - t0 <= GAP_MS else 1 + for q in range(n): rows.append([int(t0 + (t1 - t0) * q / n)] + at(r, s0 + (s1 - s0) * q / n)) + rows.append([run[-1][0]] + at(r, run[-1][2])) + k = f'rail-{vid}#{rid}'; T['props'][k] = {'g': 'subway', 'f': 'wmata-rail', 'l': r.title(), 'c': COL[r], **({'arc': 1} if MODE == 'arc' else {})}; T['tracks'][k] = rows + nruns += 1; npts += len(rows) + for ts in sorted(F): + r, lon, lat = F[ts]; nfix += 1 + d, s = snap(r, lon, lat) + if d > SNAP_M: continue + nkept += 1 + if run and r != run[-1][1]: flush(); run, rid = [], rid + 1 + run.append((ts, r, s)) + flush() +json.dump(T, open(f'{pre}-transit.json', 'w'), separators=(',', ':')) +print(f'rail fixes {nfix}, on track {nkept} ({100 * nkept / max(1, nfix):.1f}%), runs {nruns}, points {npts}') diff --git a/.claude/skills/motion-video/toolkit/dc/thin-transit.py b/.claude/skills/motion-video/toolkit/dc/thin-transit.py new file mode 100644 index 0000000..d2eb472 --- /dev/null +++ b/.claude/skills/motion-video/toolkit/dc/thin-transit.py @@ -0,0 +1,18 @@ +# Thin non-rail transit tracks so a full day fits in the browser page's ~4 GB heap. +# usage: python3 thin-transit.py PREFIX [MIN_SECONDS] +# Keeps a bus/regional row only if it is at least MIN_SECONDS (default 60) after the last kept row, plus each +# track's last row and any row that follows a gap of more than 10 minutes (so fades in/out stay correct). +# Metro rail (snap-rail.py output) is left alone. Run after prep-dc.py and snap-rail.py; facts-dc.py should read +# the unthinned data (run it first). +import json, sys +pre = sys.argv[1]; MIN = int(float(sys.argv[2]) * 1000) if len(sys.argv) > 2 else 60000 +T = json.load(open(f'{pre}-transit.json')); before = after = 0 +for k, tr in T['tracks'].items(): + if T['props'][k]['f'] == 'wmata-rail': continue + out = [] + for i, r in enumerate(tr): + if not out or r[0] - out[-1][0] >= MIN or i == len(tr) - 1 or (i + 1 < len(tr) and tr[i + 1][0] - r[0] > 600000) or r[0] - tr[i - 1][0] > 600000: + out.append(r) + before += len(tr); after += len(out); T['tracks'][k] = out +json.dump(T, open(f'{pre}-transit.json', 'w'), separators=(',', ':')) +print(f'non-rail rows {before} -> {after}') diff --git a/.claude/skills/motion-video/toolkit/remo/src/Motion.tsx b/.claude/skills/motion-video/toolkit/remo/src/Motion.tsx index 560cb01..79eab28 100644 --- a/.claude/skills/motion-video/toolkit/remo/src/Motion.tsx +++ b/.claude/skills/motion-video/toolkit/remo/src/Motion.tsx @@ -4,7 +4,7 @@ import { Audio } from '@remotion/media'; export type Card = { f0: number; f1: number; kick: string; big?: string; bigValue?: number; decimals?: number; text: string }; export type TL = { total: number; fps: number; clock: number[]; date: string; title: string; kicker: string; sub: string; counter: { label: string; values: (number | null)[] }[]; cards: Card[]; pins: Record; - credit: string; outroFrom: number; frameDir: string; chapters?: { f: number; text: string }[]; cuts?: number[]; dayStart?: number; hook?: { place: string; line: string; cta?: string }; outroLine?: string; ffChip?: boolean; legend?: { kind: 'train' | 'bus' | 'plane'; label: string; color?: string }[]; + credit: string; outroFrom: number; frameDir: string; chapters?: { f: number; text: string }[]; cuts?: number[]; dayStart?: number; hook?: { place: string; line: string; cta?: string }; outroLine?: string; ffChip?: boolean; quiet?: { labelKeep?: string[]; legendSecs?: number }; legend?: { kind: 'train' | 'bus' | 'plane'; label: string; color?: string }[]; labels?: { defs: { t: 'hood' | 'boro' | 'wp'; label: string }[]; proj: number[][][] } }; const fonts = ` @font-face{font-family:PlexMono;src:url(${staticFile('fonts/IBMPlexMono-Regular.ttf')})} @@ -65,9 +65,9 @@ const Hud: React.FC<{ tl: TL; f: number; fps: number }> = ({ tl, f, fps }) => { const c = tl.counter.map((s) => ({ label: s.label, v: s.values[f] })).find((s) => s.v != null); return
{fmt(tl.clock[f])}
-
{tl.date}
- {c ?
{Math.round(c.v as number).toLocaleString('en-US')} {c.label}
: null} - + {tl.quiet ? null :
{tl.date}
} + {c && !tl.quiet ?
{Math.round(c.v as number).toLocaleString('en-US')} {c.label}
: null} + {tl.quiet ? null : }
; }; @@ -79,7 +79,7 @@ const Chapter: React.FC<{ ch: { f: number; text: string }; f: number; fps: numbe filter: `blur(${interpolate(t, [0, fps * 0.35], [12, 0], { ...clamp, easing: ease })}px)` }}>{ch.text}; }; -const CardView: React.FC<{ c: Card; f: number; fps: number }> = ({ c, f, fps }) => { +const CardView: React.FC<{ c: Card; f: number; fps: number; Q?: boolean }> = ({ c, f, fps, Q }) => { if (f < c.f0 || f > c.f1) return null; const inA = spring({ frame: f - c.f0, fps, config: { damping: 20, mass: 0.7 } }); const outA = interpolate(f, [c.f1 - fps * 0.35, c.f1], [1, 0], clamp); @@ -87,10 +87,10 @@ const CardView: React.FC<{ c: Card; f: number; fps: number }> = ({ c, f, fps }) const dec = c.decimals ?? 0, n = c.bigValue != null ? c.bigValue * interpolate(f - c.f0, [0, fps * 0.9], [0, 1], { ...clamp, easing: Easing.out(Easing.cubic) }) : null; return
-
{c.kick}
- {n != null ?
{n.toLocaleString('en-US', { minimumFractionDigits: dec, maximumFractionDigits: dec })}{c.big ?? ''}
: null} +
{c.kick}
+ {n != null ?
{n.toLocaleString('en-US', { minimumFractionDigits: dec, maximumFractionDigits: dec })}{c.big ?? ''}
: null}
-
{c.text}
+
{c.text}
; }; @@ -102,13 +102,15 @@ const Labels: React.FC<{ tl: TL; f: number; fps: number; pins: { x: number; y: n if (!tl.labels) return null; const g = interpolate(f, [fps * 2.7, fps * 3.4], [0, 1], clamp) * interpolate(f, [tl.outroFrom - fps * 0.6, tl.outroFrom], [1, 0], clamp); const chA = Math.max(0, ...(tl.chapters || []).map((c) => interpolate(f - c.f, [-8, 4, fps * 1.8, fps * 2.3], [0, 1, 1, 0], clamp))); - const gg = g * (1 - chA); if (gg <= 0.001) return null; + const cardA = tl.quiet ? Math.max(0, ...tl.cards.map((c) => interpolate(f, [c.f0 - 12, c.f0, c.f1, c.f1 + 12], [0, 1, 1, 0], clamp))) : 0; + const gg = g * (1 - chA) * (1 - cardA); if (gg <= 0.001) return null; const card = tl.cards.some((c) => f >= c.f0 - 10 && f <= c.f1 + 10), yMax = card ? 1180 : 1500; const taken: number[][] = pins.map((p) => [p.x - 140, p.y - 50, p.x + 140, p.y + 10]); const out: React.JSX.Element[] = []; const idx = tl.labels.defs.map((d, i) => i).sort((a, b) => ORDER[tl.labels!.defs[a].t] - ORDER[tl.labels!.defs[b].t]); for (const i of idx) { const d = tl.labels.defs[i], [x, y, on] = tl.labels.proj[f][i]; if (!on) continue; + if (tl.quiet?.labelKeep && !tl.quiet.labelKeep.includes(d.label)) continue; const fs = d.t === 'boro' ? 28 : d.t === 'wp' ? 24 : 22, txt = d.t === 'wp' ? d.label : d.label.toUpperCase(); const w = txt.length * fs * (d.t === 'wp' ? 0.6 : 0.72) + (d.t === 'wp' ? 22 : 0), h = fs + 10; const box = d.t === 'wp' ? [x - 8, y - h / 2, x + w, y + h / 2] : [x - w / 2, y - h / 2, x + w / 2, y + h / 2]; @@ -131,7 +133,7 @@ const Sw: React.FC<{ k: string; c?: string }> = ({ k, c }) => k === 'train' : ; const Legend: React.FC<{ tl: TL; f: number; fps: number }> = ({ tl, f, fps }) => { if (!tl.legend) return null; - const a = interpolate(f, [CUT(tl) + fps * 0.5, CUT(tl) + fps * 1.5, tl.outroFrom - 10, tl.outroFrom], [0, 1, 1, 0], clamp); + const L = tl.quiet?.legendSecs, a = L ? interpolate(f, [CUT(tl) + fps * 0.5, CUT(tl) + fps * 1.2, CUT(tl) + fps * L, CUT(tl) + fps * (L + 0.8)], [0, 1, 1, 0], clamp) : interpolate(f, [CUT(tl) + fps * 0.5, CUT(tl) + fps * 1.5, tl.outroFrom - 10, tl.outroFrom], [0, 1, 1, 0], clamp); return
{tl.legend.map((l, i) =>
{l.label}
)}
; }; @@ -174,8 +176,9 @@ export const Motion: React.FC<{ tl: TL }> = ({ tl }) => { - {tl.cards.map((c, i) => )} + {tl.quiet ? interpolate(f, [c.f0 - 8, c.f0 + 6, c.f1 - 6, c.f1 + 6], [0, 1, 1, 0], clamp))), background: 'linear-gradient(180deg, rgba(5,6,10,0) 45%, rgba(5,6,10,.62) 72%, rgba(5,6,10,.75) 100%)' }} /> : null} + {tl.cards.map((c, i) => )} -
{tl.credit.split('\n').map((l, i) =>
{l}
)}
+
{tl.credit.split('\n').map((l, i) =>
{l}
)}
; }; diff --git a/.claude/skills/motion-video/toolkit/three-render.cjs b/.claude/skills/motion-video/toolkit/three-render.cjs index d49c297..ed2add5 100644 --- a/.claude/skills/motion-video/toolkit/three-render.cjs +++ b/.claude/skills/motion-video/toolkit/three-render.cjs @@ -13,6 +13,7 @@ async function open() { const b = await chromium.launch({ executablePath: '/opt/pw-browsers/chromium-1194/chrome-linux/chrome', args: ['--use-gl=angle','--use-angle=swiftshader','--enable-unsafe-swiftshader','--ignore-gpu-blocklist','--js-flags=--max-old-space-size=8192'] }); const p = await b.newPage({ viewport: { width: job.look.W || 1080, height: job.look.H || 1920 }, deviceScaleFactor: 1 }); p.on('pageerror', (e) => console.log('PAGEERR', e.message)); + p.on('crash', () => console.log('PAGECRASH')); p.on('console', (m) => { if (m.type() === 'error' || m.text().startsWith('DBG')) console.log('CONSOLE', m.text().slice(0, 300)); }); await p.route('http://local/**', (r) => { const u = new URL(r.request().url()).pathname; const f = u === '/' ? path.join(ROOT, 'three', job.page || 'index.html') : u === '/bg.png' ? path.resolve(bgPath) : (job.assets || {})[u] ? path.resolve(ROOT, job.assets[u]) : Object.keys(job.assets || {}).find((k) => k.endsWith('/') && u.startsWith(k)) ? (() => { const k = Object.keys(job.assets).find((k) => k.endsWith('/') && u.startsWith(k)); return path.resolve(ROOT, job.assets[k], u.slice(k.length)); })() : u.startsWith('/three/') ? path.join(ROOT, 'node_modules', u) : u.startsWith('/nm/') ? path.join(ROOT, 'node_modules', u.slice(4)) : null; diff --git a/.claude/skills/motion-video/toolkit/three/dc.html b/.claude/skills/motion-video/toolkit/three/dc.html index 8fe3ec0..ee0eeb4 100644 --- a/.claude/skills/motion-video/toolkit/three/dc.html +++ b/.claude/skills/motion-video/toolkit/three/dc.html @@ -78,7 +78,9 @@ const patch = new THREE.Mesh(new THREE.PlaneGeometry(HP.w * HP.dpr * k, HP.h * HP.dpr * k), m); const [px, py] = toW(...HP.center); patch.position.set(px, py, 0.3 + 0.05 * hmats.length); patch.renderOrder = 2 + hmats.length; scene.add(patch); } // Metro lines from GTFS shapes, in their own colours, as thin ribbons on the ground (shared track: side by side) const railMats = []; + const ROFF = {}; // per-line ribbon offset (world units); snapped trains shift by the same amount so they ride their own ribbon if (cfg.rail) { const ORD = { ORANGE: -1.5, SILVER: -0.5, BLUE: 0.5, YELLOW: 1.5, GREEN: 1.5, RED: 0 }, RW = (cfg.railW ?? 1.6) * S; + for (const r in ORD) ROFF[r] = ORD[r] * RW * 1.1; for (const L of cfg.rail.lines) { if (!(L.r in ORD)) continue; const w = L.pts.map((q) => toW(q[0], q[1])), v = []; if (cfg.railMiter) { // one continuous strip with mitred joints: separate quads leave dark notches at every bend const o = ORD[L.r] * RW * 1.1, zz = 0.7 + 0.04 * (ORD[L.r] + 2), N = w.map((p, i) => { const a = w[Math.max(0, i - 1)], b = w[Math.min(w.length - 1, i + 1)], l = Math.hypot(b[0] - a[0], b[1] - a[1]) || 1; return [-(b[1] - a[1]) / l, (b[0] - a[0]) / l]; }); @@ -148,6 +150,11 @@ lgeo.setAttribute('position', new THREE.BufferAttribute(lpos, 3)); lgeo.setAttribute('color', new THREE.BufferAttribute(lcol, 3)); const drops = new THREE.LineSegments(lgeo, new THREE.LineBasicMaterial({ vertexColors: true, transparent: true, opacity: 0.7, blending: THREE.AdditiveBlending, depthWrite: false, fog: true })); drops.frustumCulled = false; drops.renderOrder = 9; scene.add(drops); + // light beams over trains, as in the Boston videos: a line plus a stack of soft glows, bright at the base, fading upward + const MAXB = 3000, bpos = new Float32Array(MAXB * 6), bcol = new Float32Array(MAXB * 6), bgeo = new THREE.BufferGeometry(); + bgeo.setAttribute('position', new THREE.BufferAttribute(bpos, 3)); bgeo.setAttribute('color', new THREE.BufferAttribute(bcol, 3)); + const beamL = new THREE.LineSegments(bgeo, new THREE.LineBasicMaterial({ vertexColors: true, transparent: true, opacity: 0.9, blending: THREE.AdditiveBlending, depthWrite: false, fog: true })); + beamL.frustumCulled = false; beamL.renderOrder = 12; scene.add(beamL); const cam = new THREE.PerspectiveCamera(38, W / H, 4, 90000); const composer = new EffectComposer(renderer); composer.addPass(new RenderPass(scene, cam)); @@ -157,9 +164,15 @@ // camera keyframes in video time (frames), each looking at a place with an azimuth / tilt / distance const KF = cfg.keys.map((k) => ({ ...k, w: toW(...k.at) })); const setCam = (fk) => { let i = 0; while (i < KF.length - 2 && fk > KF[i + 1].f) i++; - const a = KF[i], b = KF[i + 1], e = sm((fk - a.f) / (b.f - a.f)), L = (p, q) => p + (q - p) * e; - const gx = L(a.w[0], b.w[0]), gy = L(a.w[1], b.w[1]), az = L(a.az, b.az) * Math.PI / 180, tilt = L(a.tilt, b.tilt) * Math.PI / 180, d = Math.exp(L(Math.log(a.dist), Math.log(b.dist))), ty = gy + L(a.lead ?? 0, b.lead ?? 0); - cam.position.set(gx + d * Math.sin(tilt) * Math.sin(az), ty - d * Math.sin(tilt) * Math.cos(az), d * Math.cos(tilt)); cam.up.set(0, 0, 1); cam.lookAt(gx, ty, 0); }; + const a = KF[i], b = KF[i + 1], e = sm((fk - a.f) / (b.f - a.f)); let L = (p, q) => p + (q - p) * e; + if (cfg.camSpline && b.f - a.f > 1) { // carry speed through keys instead of stopping at each one; a key pair one frame apart is a cut + const A0 = i > 0 && a.f - KF[i - 1].f > 1 ? KF[i - 1] : null, B1 = i + 2 < KF.length && KF[i + 2].f - b.f > 1 ? KF[i + 2] : null, h = b.f - a.f, u = (fk - a.f) / h; + const u2 = u * u, u3 = u2 * u, h00 = 2 * u3 - 3 * u2 + 1, h10 = u3 - 2 * u2 + u, h01 = -2 * u3 + 3 * u2, h11 = u3 - u2; + const g = (o) => o === a ? (x) => x(a) : null; + L = (p, q, get) => { if (!get) return p + (q - p) * e; const pa = A0 ? get(A0) : null, pb = B1 ? get(B1) : null; + const ma = A0 ? (q - pa) / (b.f - A0.f) * h : (q - p) * 0.5, mb = B1 ? (pb - p) / (B1.f - a.f) * h : (q - p) * 0.5; return h00 * p + h10 * ma + h01 * q + h11 * mb; }; } + const gx = L(a.w[0], b.w[0], (k) => k.w[0]), gy = L(a.w[1], b.w[1], (k) => k.w[1]), az = L(a.az, b.az, (k) => k.az) * Math.PI / 180, tilt = L(a.tilt, b.tilt, (k) => k.tilt) * Math.PI / 180, d = Math.exp(L(Math.log(a.dist), Math.log(b.dist), (k) => Math.log(k.dist))), ty = gy + L(a.lead ?? 0, b.lead ?? 0), lz = altZ(Math.max(0, L(a.lzft ?? 0, b.lzft ?? 0, (k) => k.lzft ?? 0))); + cam.position.set(gx + d * Math.sin(tilt) * Math.sin(az), ty - d * Math.sin(tilt) * Math.cos(az), lz + d * Math.cos(tilt)); cam.up.set(0, 0, 1); cam.lookAt(gx, ty, lz); }; // focus: how strongly each layer shows, keyed in video time const FK = cfg.focus; const focus = (fk) => { let i = 0; while (i < FK.length - 2 && fk > FK[i + 1].f) i++; const a = FK[i], b = FK[i + 1], e = sm((fk - a.f) / Math.max(1, b.f - a.f)), o = {}; for (const key of ['transit', 'crowd', 'traffic', 'planes', 'bikes', 'lime']) o[key] = (a.w[key] ?? 0) + ((b.w[key] ?? 0) - (a.w[key] ?? 0)) * e; return o; }; @@ -167,7 +180,7 @@ // --- transit const TR = cfg.transit, crowd = (cfg.crowd || { status: {} }).status, list = []; for (const [k, tr] of Object.entries(TR.tracks)) { const p = TR.props[k], g = p.g, vid = k.slice(k.indexOf(':') + 1).split('#')[0]; - list.push({ tr, g, vid, rail: g !== 'bus', c: new THREE.Color(p.c || LINE[g] || LINE.bus), cs: crowd[vid] || null, hl: (cfg.hl || {})[vid] || null, hist: [], last: null }); } + list.push({ tr, g, vid, ln: (p.l || '').toUpperCase(), arc: !!p.arc, rail: g !== 'bus', c: new THREE.Color(p.c || LINE[g] || LINE.bus), cs: crowd[vid] || null, hl: (cfg.hl || {})[vid] || null, hist: [], last: null }); } const byVid = {}; for (const v of list) (byVid[v.vid] = byVid[v.vid] || []).push(v); const GAP = 600000, FADE = 420000; // gaps over 10 min (restarts, overnight) fade out / in instead of sliding across the map const where = (tr, T) => { const j = seek(tr, T); if (j < 0) return tr[0][0] - T < FADE ? [tr[0][1], tr[0][2], 1 - (tr[0][0] - T) / FADE] : null; @@ -177,21 +190,38 @@ if (Math.hypot(c[1] - a[1], (c[2] - a[2]) * 1.35) > 0.25) return [a[1], a[2], 1]; const p0 = tr[j - 1] || a, p3 = tr[j + 2] || c, u = (T - a[0]) / gap, u2 = u * u, u3 = u2 * u; const cr = (q0, q1, q2, q3) => 0.5 * ((2 * q1) + (-q0 + q2) * u + (2 * q0 - 5 * q1 + 4 * q2 - q3) * u2 + (-q0 + 3 * q1 - 3 * q2 + q3) * u3); - return [cr(p0[1], a[1], c[1], p3[1]), cr(p0[2], a[2], c[2], p3[2]), 1]; }; + return a.length > 4 ? [cr(p0[1], a[1], c[1], p3[1]), cr(p0[2], a[2], c[2], p3[2]), 1, a[3] + (c[3] - a[3]) * u, a[4] + (c[4] - a[4]) * u] : [cr(p0[1], a[1], c[1], p3[1]), cr(p0[2], a[2], c[2], p3[2]), 1]; }; const lvlAt = (cs, T) => { if (!cs) return -1; const j = seek(cs, T); if (j < 0) return cs[0][0] - T < 120000 ? cs[0][1] : -1; return T - cs[j][0] < 1800000 ? cs[j][1] : -1; }; // --- planes (24 h tracks [t, lon, lat, ft, onGround]); colour by what the plane is doing right now const PL = cfg.planes, plist = [], byId = {}; - for (const [k, tr] of Object.entries(PL.tracks)) { const v = { tr, ev: [], hist: [], ph: plist.length % 23 }; plist.push(v); byId[k] = v; } + for (const [k, tr] of Object.entries(PL.tracks)) { const v = { tr, ev: [], hist: [], ph: plist.length % 23 }; v.id = k; plist.push(v); byId[k] = v; } const events = (PL.events || []).map((e) => ({ kind: e[0], t: e[1], at: e[2], id: e[3] })); for (const e of events) if (byId[e.id]) byId[e.id].ev.push(e); const kindAt = (v, T) => { for (const e of v.ev) { if (e.kind === 'arr' && T >= e.t - 1500000 && T <= e.t + 240000) return 'arr'; if (e.kind === 'dep' && T >= e.t - 480000 && T <= e.t + 1500000) return 'dep'; } return 'over'; }; - const AZ = 0.06 * S, altZ = (ft) => ft <= 8000 ? ft * AZ : 8000 * AZ + (ft - 8000) * AZ * 0.3; + const AZ = 0.06 * S * (cfg.altScale ?? 1), altZ = (ft) => ft <= 8000 ? ft * AZ : 8000 * AZ + (ft - 8000) * AZ * 0.3; const pwhere = (tr, T) => { const j = seek(tr, T); if (j < 0) return null; const a = tr[j]; if (j === tr.length - 1) return T - a[0] < 45000 ? a : null; const c = tr[j + 1], gap = c[0] - a[0]; if (gap > GAP) return T - a[0] < 45000 ? a : null; if (gap > 180000 || Math.hypot(c[1] - a[1], c[2] - a[2]) > 0.4) return a; const p0 = tr[j - 1] || a, p3 = tr[j + 2] || c, u = (T - a[0]) / gap, u2 = u * u, u3 = u2 * u; const cr = (q0, q1, q2, q3) => 0.5 * ((2 * q1) + (-q0 + q2) * u + (2 * q0 - 5 * q1 + 4 * q2 - q3) * u2 + (-q0 + 3 * q1 - 3 * q2 + q3) * u3); let br = -1; if (a[5] >= 0 && c[5] >= 0) { let d = ((c[5] - a[5] + 540) % 360) - 180; br = (a[5] + d * u + 360) % 360; } else br = a[5] >= 0 ? a[5] : (c[5] ?? -1); return [T, cr(p0[1], a[1], c[1], p3[1]), cr(p0[2], a[2], c[2], p3[2]), Math.max(0, a[3] + (c[3] - a[3]) * u), a[4] && c[4], br]; }; + // snapped Metro trains (props.arc): rows [t, metres along the line]; walk the same line geometry dc/snap-rail.py used + const RL = {}; if (cfg.rail) { const KX = 111320 * Math.cos(38.9 * Math.PI / 180), KY = 110540; + for (const L of cfg.rail.lines) { const P = L.pts, n = P.length, E = P.map((q) => (q[0] + 77) * KX), N = P.map((q) => (q[1] - 38.9) * KY), cum = [0]; + for (let i = 1; i < n; i++) cum.push(cum[i - 1] + (Math.hypot(E[i] - E[i - 1], N[i] - N[i - 1]) || 1e-6)); + const nE = [], nN = []; for (let i = 0; i < n; i++) { const a = Math.max(0, i - 1), b = Math.min(n - 1, i + 1), vE = E[b] - E[a], vN = N[b] - N[a], l = Math.hypot(vE, vN) || 1; nE.push(-vN / l); nN.push(vE / l); } + RL[L.r] = { P, cum, nE, nN }; } } + const onLine = (r, s) => { const g = RL[r]; if (!g) return null; const C = g.cum; s = Math.max(0, Math.min(C[C.length - 1], s)); let lo = 0, hi = C.length - 1; + while (hi - lo > 1) { const m = (lo + hi) >> 1; if (C[m] <= s) lo = m; else hi = m; } const u = (s - C[lo]) / ((C[hi] - C[lo]) || 1), A = g.P[lo], B = g.P[hi]; + let nx = g.nE[lo] + (g.nE[hi] - g.nE[lo]) * u, ny = g.nN[lo] + (g.nN[hi] - g.nN[lo]) * u; const nl = Math.hypot(nx, ny) || 1; + return [A[0] + (B[0] - A[0]) * u, A[1] + (B[1] - A[1]) * u, nx / nl, ny / nl]; }; + const whereArc = (tr, r, T) => { const j = seek(tr, T); let s, f = 1; + if (j < 0) { if (tr[0][0] - T >= FADE) return null; s = tr[0][1]; f = 1 - (tr[0][0] - T) / FADE; } + else { const a = tr[j]; if (j === tr.length - 1) { if (T - a[0] >= FADE) return null; s = a[1]; f = 1 - (T - a[0]) / FADE; } + else { const c = tr[j + 1], gap = c[0] - a[0]; + if (gap > GAP) { if (T - a[0] < FADE) { s = a[1]; f = 1 - (T - a[0]) / FADE; } else if (c[0] - T < FADE) { s = c[1]; f = 1 - (c[0] - T) / FADE; } else return null; } + else { const p0 = tr[j - 1] || a, p3 = tr[j + 2] || c, u = (T - a[0]) / gap; s = 0.5 * ((2 * a[1]) + (-p0[1] + c[1]) * u + (2 * p0[1] - 5 * a[1] + 4 * c[1] - p3[1]) * u * u + (-p0[1] + 3 * a[1] - 3 * c[1] + p3[1]) * u * u * u); } } } + const q = onLine(r, s); return q ? [q[0], q[1], f, q[2], q[3]] : null; }; const yaw = (p, fallback) => (p[5] >= 0 ? Math.PI / 2 - p[5] * Math.PI / 180 : fallback); // Logan: footprint, lit runways (glow in the colour of the plane using them), label const AP = cfg.airport, rwys = [], RW0 = new THREE.Color('#5d6672'), EDGE = new THREE.Color('#ffe2b0'), GREEN = new THREE.Color('#59e08a'); @@ -226,20 +256,24 @@ window.__frame = async (T, draw, k = 0) => { const fk = Math.max(0, k), F = focus(fk), camP = cam.position, tmpV = new THREE.Vector3(); if (draw) { setCam(fk); cam.updateMatrixWorld(); } - let n = 0, nt = 0, ni = 0, nl = 0; + let n = 0, nt = 0, ni = 0, nl = 0, nb = 0; const BEAM = Math.max(20, cam.position.z) * (cfg.beamH ?? 0.11); const put = (x, y, z, c, s, a) => { if (n >= MAX || a <= 0.003 || !Number.isFinite(x + y + z + s + a)) return; pos[n * 3] = x; pos[n * 3 + 1] = y; pos[n * 3 + 2] = z; col[n * 3] = c.r; col[n * 3 + 1] = c.g; col[n * 3 + 2] = c.b; siz[n] = s; alp[n] = a; n++; }; const seg = (a, b, c, fa, fb) => { if (nt >= MAXT) return; const i = nt * 6; tpos.set(a, i); tpos.set(b, i + 3); tcol[i] = c.r * fa; tcol[i + 1] = c.g * fa; tcol[i + 2] = c.b * fa; tcol[i + 3] = c.r * fb; tcol[i + 4] = c.g * fb; tcol[i + 5] = c.b * fb; nt++; }; // transit (line colours), recoloured by crowding as the crowd focus rises let live = 0, crowded = 0; const CC = CROWD.map((c) => new THREE.Color(c)), tw = 0.35 + 0.65 * Math.max(F.transit, F.crowd), cw = F.crowd, tmpC = new THREE.Color(); for (const v of list) { - v.last = null; const ll = where(v.tr, T); if (!ll) { v.hist.length = 0; continue; } - const [x, y] = toW(ll[0], ll[1]), fa = Math.max(0, Math.min(1, ll[2])); if (v.g !== 'amtrak' && fa > 0.5) live++; + v.last = null; const ll = v.arc ? whereArc(v.tr, v.ln, T) : where(v.tr, T); if (!ll) { v.hist.length = 0; continue; } + let [x, y] = toW(ll[0], ll[1]); const fa = Math.max(0, Math.min(1, ll[2])); + if (ll.length > 3 && ROFF[v.ln]) { x += ll[3] * ROFF[v.ln]; y += ll[4] * ROFF[v.ln]; } if (v.g !== 'amtrak' && fa > 0.5) live++; const lvl = lvlAt(v.cs, T); if (lvl >= 2) crowded++; const boat = v.g === 'ferry' || v.g === 'vessel'; tmpC.copy(v.g === 'bus' && BUSC ? BUSC : v.c); let s = (boat ? 8 : v.rail ? 6.5 : 3.6) * (cfg.dotScale ?? 1), a = Math.min(1, (boat ? 0.8 : v.rail ? 0.85 : cfg.busA ?? 0.5) * (cfg.dotBright ?? 1)) * fa; if (cw > 0.01) { const cc = lvl < 0 ? CC[0] : CC[lvl], cs = lvl < 0 ? 3.5 : [4, 5.5, 8, 10][lvl], ca = lvl < 0 ? 0.25 : [0.4, 0.65, 1, 1][lvl]; tmpC.lerp(cc, cw); s += (cs - s) * cw; a += (ca * fa - a) * cw; } a *= tw; s *= S; const HL = v.hl && v.hl.some((w) => T >= w[0] && T <= w[1]); if (HL) { tmpC.set('#ffe94a'); s = Math.max(s, 9 * S); a = 1; } v.last = [x, y, fa]; for (let j = 0; j < v.hist.length; j++) { const q = 1 - (j + 1) / (TRAIL + 1); put(v.hist[j][0], v.hist[j][1], 2, tmpC, s * (0.35 + 0.5 * q), a * 0.3 * q); } + if (v.rail && cfg.beams && nb < MAXB && a > 0.05) { const BH = BEAM * (v.g === 'subway' ? 1 : 0.8), i = nb * 6; + bpos[i] = x; bpos[i + 1] = y; bpos[i + 2] = 2; bpos[i + 3] = x; bpos[i + 4] = y; bpos[i + 5] = 2 + BH; bcol[i] = tmpC.r * a; bcol[i + 1] = tmpC.g * a; bcol[i + 2] = tmpC.b * a; bcol[i + 3] = 0; bcol[i + 4] = 0; bcol[i + 5] = 0; nb++; + for (let q = 1; q <= 12; q++) { const h = q / 12; put(x, y, 2 + BH * h, tmpC, s * (1.1 - 0.6 * h), ((cfg.beamA ?? 0.3) * (1 - h) * (1 - h) + 0.015) * a); } } if (v.rail && cfg.trainCore) { put(x, y, 2.1, tmpC, s * 2.1, a * 0.6); put(x, y, 2.2, WHITE_T, s * 0.75, Math.min(1, a * 1.25)); } else put(x, y, 2, tmpC, s, a); if (HL) put(x, y, 2, tmpC, s * 2.4, 0.3 + 0.18 * Math.sin(k / 2.5)); if (cw > 0.3 && lvl === 3 && (k + (v.tr.length % 17)) % 20 < 10) put(x, y, 2, tmpC, s * 2.2, 0.35 * cw); if (frameNo % 2 === 0) { v.hist.unshift([x, y]); if (v.hist.length > TRAIL) v.hist.pop(); } } @@ -247,27 +281,28 @@ const pw = 0.3 + 0.7 * F.planes, WHITE = new THREE.Color('#ffffff'); let air = 0; for (const v of plist) { const p = pwhere(v.tr, T); if (!p) { v.hist.length = 0; continue; } - const kind = kindAt(v, T), over = kind === 'over', vc = new THREE.Color(KIND[kind]); - const [x, y] = toW(p[1], p[2]), z = 2 + altZ(p[3]), size = (over ? 12 : 30) * S * (cfg.planeScale ?? 1), ta = (over ? 0.22 : 0.6) * pw; - if (p[4] || p[3] < 50) { v.hist.length = 0; if (over && pw < 0.6) continue; put(x, y, 1.5, vc, size * 0.3, 0.22 * pw); + const HLw = cfg.planeHL && cfg.planeHL[v.id], HL = HLw && T >= HLw[0] && T <= HLw[1]; // the plane a beat is about: gold, larger, long trail + const kind = kindAt(v, T), over = kind === 'over' && !HL, vc = HL ? new THREE.Color('#ffc94a') : new THREE.Color(KIND[kind]), PT = HL ? 260 : PTRAIL; + const [x, y] = toW(p[1], p[2]), z = 2 + altZ(p[3]), size = (over ? 12 : 30) * S * (cfg.planeScale ?? 1) * (HL ? 1.4 : 1), ta = (over ? 0.22 : 0.6) * pw; + if (p[4] || (p[3] < 50 && !HL)) { v.hist.length = 0; if (over && pw < 0.6) continue; put(x, y, 1.5, vc, size * 0.3, 0.22 * pw); const ga = pwhere(v.tr, T - 15000) || p, gb = pwhere(v.tr, T + 15000) || p, [gx0, gy0] = toW(ga[1], ga[2]), [gx1, gy1] = toW(gb[1], gb[2]); if (Math.hypot(gx1 - gx0, gy1 - gy0) > 1.5 * S && ni < 800) { const sc = (over ? 5 : 8) * S * (cfg.planeScale ?? 1); dummy.position.set(x, y, 1.5); dummy.rotation.set(0, 0, yaw(p, Math.atan2(gy1 - gy0, gx1 - gx0))); dummy.scale.set(sc, sc, sc); dummy.updateMatrix(); planes.setMatrixAt(ni, dummy.matrix); planes.setColorAt(ni, tint(vc).multiplyScalar(pw)); ni++; } continue; } if (Math.abs(x) < TW / 2 && Math.abs(y) < TH / 2) air++; let prev = [x, y, z], fp = (over ? 0.4 : 0.95) * pw; - if (!(over && cfg.overTrails === false)) for (let j = 0; j < v.hist.length; j++) { const q = 1 - (j + 1) / (PTRAIL + 1), h = v.hist[j], fj = (over ? 0.4 : 0.95) * pw * q * q; seg(prev, h, vc, fp, fj); prev = h; fp = fj; if (j % 2 === 1) put(h[0], h[1], h[2], vc, size * (0.25 + 0.35 * q), ta * 0.6 * q); } - const near = draw ? sm((camP.distanceTo(tmpV.set(x, y, z)) - 140 * S) / (220 * S)) : 1; + if (!(over && cfg.overTrails === false)) for (let j = 0; j < v.hist.length; j++) { const q = 1 - (j + 1) / (PT + 1), h = v.hist[j], fj = (over ? 0.4 : 0.95) * pw * (HL ? Math.sqrt(q) * 1.4 : q * q); seg(prev, h, vc, fp, fj); prev = h; fp = fj; if (j % 2 === 1) put(h[0], h[1], h[2], vc, size * (0.25 + 0.35 * q), ta * 0.6 * q); } + const near = HL || !draw ? 1 : sm((camP.distanceTo(tmpV.set(x, y, z)) - 140 * S) / (220 * S)); // the followed plane never fades near the camera put(x, y, z, vc, size * 0.75, (over ? 0.4 : 0.9) * near * pw); const pa = pwhere(v.tr, T - 40000) || p, pb = pwhere(v.tr, T + 40000) || p, [ax, ay] = toW(pa[1], pa[2]), [bx, by] = toW(pb[1], pb[2]), hd = yaw(p, Math.atan2(by - ay, bx - ax)); const hz = Math.hypot(bx - ax, by - ay), pitch = Math.max(-0.3, Math.min(0.3, Math.atan2((altZ(pb[3]) - altZ(pa[3])) * 0.3, Math.max(hz, 1)))); let turn = yaw(pb, Math.atan2(by - ay, bx - ax)) - yaw(pa, hd); while (turn > Math.PI) turn -= 2 * Math.PI; while (turn < -Math.PI) turn += 2 * Math.PI; - if (hz > 2 * S && ni < 800 && near > 0.02) { const sc = (over ? 10 : 21) * S * near * (cfg.planeScale ?? 1); dummy.position.set(x, y, z); dummy.rotation.set(Math.max(-0.45, Math.min(0.45, -turn * 1.1)), -pitch, hd); dummy.scale.set(sc, sc, sc); + if (hz > 2 * S && ni < 800 && near > 0.02) { const sc = (over ? 10 : 21) * S * near * (cfg.planeScale ?? 1) * (HL ? 1.4 : 1); dummy.position.set(x, y, z); dummy.rotation.set(Math.max(-0.45, Math.min(0.45, -turn * 1.1)), -pitch, hd); dummy.scale.set(sc, sc, sc); dummy.updateMatrix(); planes.setMatrixAt(ni, dummy.matrix); planes.setColorAt(ni, tint(vc).multiplyScalar((over ? 0.6 : 1) * pw)); ni++; } if (!over && (k + v.ph) % 24 < 2) put(x, y, z, WHITE, size * 0.55, 1.2 * pw); - if (!over && cfg.drops !== false && z > 6 * S && nl < MAXL) { const i = nl * 6; lpos[i] = x; lpos[i + 1] = y; lpos[i + 2] = z; lpos[i + 3] = x; lpos[i + 4] = y; lpos[i + 5] = 0.5; + if (!over && cfg.drops !== false && z > 6 * S && p[3] < (cfg.dropMaxFt ?? 1e9) && nl < MAXL) { const i = nl * 6; lpos[i] = x; lpos[i + 1] = y; lpos[i + 2] = z; lpos[i + 3] = x; lpos[i + 4] = y; lpos[i + 5] = 0.5; lcol[i] = vc.r * 0.5 * pw; lcol[i + 1] = vc.g * 0.5 * pw; lcol[i + 2] = vc.b * 0.5 * pw; lcol[i + 3] = 0; lcol[i + 4] = 0; lcol[i + 5] = 0; nl++; put(x, y, 1, vc, size * 0.5, 0.25 * pw); } - if (frameNo % 2 === 0) { v.hist.unshift([x, y, z]); if (v.hist.length > PTRAIL) v.hist.pop(); } + if (frameNo % 2 === 0) { v.hist.unshift([x, y, z]); if (v.hist.length > PT) v.hist.pop(); } } // touchdown / lift-off rings and runway lights let flights = 0; @@ -311,6 +346,7 @@ skyU.uSun.value.copy(dir).normalize(); } geo.setDrawRange(0, n); for (const a of ['position', 'color', 'size', 'alpha']) geo.attributes[a].needsUpdate = true; tgeo.setDrawRange(0, nt * 2); tgeo.attributes.position.needsUpdate = true; tgeo.attributes.color.needsUpdate = true; + bgeo.setDrawRange(0, nb * 2); bgeo.attributes.position.needsUpdate = true; bgeo.attributes.color.needsUpdate = true; lgeo.setDrawRange(0, nl * 2); lgeo.attributes.position.needsUpdate = true; lgeo.attributes.color.needsUpdate = true; planes.count = ni; planes.instanceMatrix.needsUpdate = true; if (planes.instanceColor) planes.instanceColor.needsUpdate = true; // HUD: title first, then clock + whichever number the camera is on