Dot Map
A dotted world map lights up city by city, ending on 142 countries.
Source
components/kuchi/dot-map.tsx
1"use client";23import { loadFont as loadManrope } from "@remotion/google-fonts/Manrope";4import type React from "react";5import { useId, useMemo } from "react";6import {7 AbsoluteFill,8 Easing,9 interpolate,10 useCurrentFrame,11 useVideoConfig,12} from "remotion";1314const { fontFamily: manrope } = loadManrope("normal", {15 weights: ["400", "500"],16 subsets: ["latin"],17});1819export interface DotMapCity {20 lon: number;21 lat: number;22}2324export interface DotMapProps {25 count?: number;26 label?: string;27 cities?: DotMapCity[];28 accent?: string;29 /** Text color of the count; overrides the theme ink. */30 ink?: string;31 /** Background fill; "transparent" drops it. */32 background?: string;33 /** Typeface for the count and label. Load it yourself; Manrope by default. */34 fontFamily?: string;35 /** Weight of the count. */36 fontWeight?: number;37 /** Frames for the lights to sweep across the map, west to east. */38 sweep?: number;39 /** Size of the map and count, around the frame's center. */40 scale?: number;41 /** Frames to hold the first frame before anything moves. */42 delay?: number;43 /** Film grain over the scene. */44 grain?: boolean;45 theme?: "dark" | "light";46 speed?: number;47}4849type Poly = number[];5051const LAND: Poly[] = [52 [53 -168, 66, -162, 70, -156, 71.3, -140, 69.6, -128, 70, -115, 68.5, -95, 68,54 -85, 69.5, -80, 69, -68, 66, -62, 60, -56, 52, -60, 47, -66, 44.5, -70, 42,55 -74, 40.5, -76, 35, -81, 31, -80.5, 25.5, -82.5, 28, -84, 30, -89, 30, -94,56 29.5, -97.5, 27, -97.5, 22, -95, 18.5, -91, 18.5, -90.5, 21, -87, 21.5, -88,57 16, -83.5, 15, -83.5, 11, -79.5, 9, -77.5, 8.5, -80, 7.5, -85.5, 10, -87.5,58 13, -92, 14.5, -96, 15.7, -105, 19.5, -106, 23, -109.5, 23.5, -112, 29,59 -117, 32.5, -120.5, 34.5, -124, 40, -124.5, 48, -130, 54.5, -137, 59, -146,60 60.5, -152, 59, -158, 57, -164, 55, -158, 58.5, -162, 60, -166, 62, -165,61 64.5,62 ],63 [64 -90, 74, -78, 73.5, -67, 70, -62, 66.5, -66, 62.5, -74, 64, -84, 66, -90,65 69,66 ],67 [68 -120, 76, -95, 81, -75, 83, -62, 82, -75, 78, -80, 76, -98, 75.5, -118,69 73.5,70 ],71 [72 -73, 78, -60, 82, -35, 83.5, -20, 82, -18, 76, -22, 70, -32, 68, -40, 65,73 -43, 60, -49, 61.5, -53, 66, -55, 70, -58, 75.5, -66, 77,74 ],75 [-85, 21.8, -82, 23.2, -77, 22.3, -74.2, 20.2, -77.5, 19.9, -80, 21.8],76 [-74.4, 18.5, -72.8, 19.9, -69, 19.7, -68.4, 18.5, -71.5, 17.6],77 [78 -77.5, 8.5, -72, 12, -63, 10.7, -58, 6.5, -52, 5, -50, 0, -44, -2.5, -35,79 -5.5, -35, -9, -39, -14, -39.5, -18, -41, -22.5, -48, -26, -48.5, -28.5,80 -53, -33.5, -57, -36, -57.5, -38.5, -62, -39, -65, -41, -63.5, -42.5, -67.5,81 -46, -66, -48, -69, -51, -68.5, -53, -70.5, -54.5, -73.5, -52.5, -75.5, -47,82 -73.5, -42, -73.5, -37, -71.5, -30, -70.5, -23, -70.3, -18, -75, -15.5, -77,83 -12, -79.5, -7.5, -81, -4.5, -80, -1, -80, 1, -78.5, 2.5, -77.5, 4, -77.5,84 7,85 ],86 [-24, 65.5, -14, 66.3, -13.5, 65, -18, 63.4, -22.5, 63.8],87 [88 -5.7, 50, 1.5, 51.2, 1.7, 52.7, 0, 53.5, -0.5, 54.5, -2, 55.9, -1.8, 57.6,89 -3.5, 58.6, -5, 58.6, -6.2, 56.6, -5, 55, -3, 54, -4.5, 53.3, -4.6, 52,90 -5.3, 51.7, -3, 51.4,91 ],92 [-10, 51.6, -6, 52.2, -6, 54, -7.5, 55.2, -10, 54.2],93 [94 -9.3, 43, -8, 43.7, -1.8, 43.4, -1.2, 46, -2.2, 47.1, -4.6, 47.9, -4.6,95 48.6, -1.6, 48.7, -1.3, 49.6, 0.2, 49.7, 1.6, 50.9, 3.2, 51.3, 4.4, 52.2,96 4.8, 53, 7, 53.4, 8.5, 53.8, 8.3, 56.9, 10.5, 57.6, 10.2, 55.2, 12, 54.3,97 14, 54, 19, 54.5, 21, 56.5, 23.5, 59.3, 29, 60, 22.5, 60.2, 21.5, 62.8, 25,98 65, 21.5, 65.8, 19, 63.5, 17.2, 61, 18.7, 59.8, 16.5, 57, 14.3, 55.5, 12.8,99 55.6, 11, 58.7, 10, 59.2, 6, 58.1, 5, 62, 10, 64, 14, 67.5, 18, 69.5, 25,100 71, 31, 70, 41, 67, 44, 68.5, 53, 68.3, 60, 69, 68, 72.5, 72, 73, 80, 72.5,101 87, 75, 100, 78, 105, 77.5, 113, 74, 127, 73.5, 140, 72.5, 150, 71.5, 160,102 70, 170, 70, 180, 69, 180, 65, 178, 62.5, 173, 61.3, 170, 60, 165, 60,103 163.5, 58, 162, 56, 160, 53.5, 156.6, 51, 156, 55, 156, 57.5, 154, 59.2,104 150, 59.6, 143, 59.3, 137, 54, 140.5, 52, 141, 48.5, 138, 45.5, 135, 43.3,105 132, 43, 130, 42.5, 129.5, 40.5, 129.3, 37, 129.4, 35.4, 126.5, 34.4, 126.3,106 36.8, 125.1, 37.8, 124.5, 39.8, 121.6, 39, 122, 40.5, 118.5, 39.2, 118.8,107 37.6, 122.5, 37.2, 120.5, 35.5, 119.5, 34.5, 121, 32, 122, 29.8, 121, 28,108 119.5, 25.5, 116.5, 23, 113, 22.3, 110.4, 21.1, 108, 21.6, 106.5, 20.5,109 105.7, 18.8, 108.5, 15.5, 109.3, 12.5, 108, 11, 105, 8.6, 104.8, 10.4, 103,110 11, 101, 12.5, 100.2, 13.3, 99.2, 10.4, 100.4, 7.3, 103.5, 4.5, 104.3, 1.4,111 103.4, 1.3, 101.3, 2.8, 100.3, 5, 98.3, 8.2, 98.5, 10.5, 97.7, 16.5, 94.5,112 16.2, 94, 19, 92, 21.5, 90, 21.8, 87.2, 21.5, 86.5, 20, 80.3, 15.5, 80.2,113 13, 79.8, 10.3, 77.5, 8, 76.3, 10, 74.8, 13, 73.4, 16, 72.8, 19.5, 72.6,114 21.4, 70.5, 20.8, 69, 22.4, 67.3, 24.6, 66.5, 25.4, 61.5, 25.2, 57.3, 25.8,115 56.5, 27.2, 54, 26.6, 51.5, 27.9, 50.2, 29.9, 48, 30, 48.5, 28.4, 50, 26.3,116 51.6, 24.2, 54.5, 24.2, 56, 25.6, 56.4, 24.3, 58.5, 23.6, 59.8, 22.4, 58.5,117 20.5, 57.7, 19, 55, 17.2, 52.2, 15.7, 48.7, 14, 45, 12.8, 43.5, 12.7, 42.7,118 15.5, 41.2, 18.5, 39, 21.5, 38.4, 24, 36.6, 26, 35, 28, 34.9, 29.5, 34.5,119 31.6, 35.5, 33.5, 36, 35, 36, 36.6, 34.5, 36.8, 32.5, 36.1, 30, 36.3, 28,120 36.7, 27.3, 37.5, 26.6, 38.4, 26.2, 39.5, 26.2, 40.6, 24, 40.8, 22.8, 40.4,121 23.8, 38, 23.2, 36.5, 21.7, 36.8, 21, 38.3, 20.2, 39.6, 19.4, 41.8, 18.5,122 42.5, 15.8, 43.7, 13.7, 45.1, 12.4, 45.4, 12.3, 44.3, 13.7, 43.5, 14.2,123 42.2, 16.1, 41.4, 18.5, 40.2, 16.6, 38.9, 15.7, 38, 15.9, 39.6, 14.9, 40.3,124 12.8, 41.3, 11.1, 42.4, 10, 44, 8.7, 44.4, 7, 43.6, 4.6, 43.4, 3.2, 41.9,125 0.9, 41, 0, 39.8, -0.6, 38.3, -2.2, 36.7, -4.4, 36.7, -5.6, 36, -6.4, 36.8,126 -7.4, 37.2, -8.9, 37, -8.8, 38.7, -9.5, 39.4, -8.8, 41.9,127 ],128 [-180, 69, -174, 67, -170, 66, -172, 64.5, -180, 65],129 [12.4, 38, 15.6, 38.3, 15.1, 36.7],130 [11, 78.5, 16, 80, 23, 80.3, 27, 79.5, 22, 77.5, 17, 76.5, 13, 77.5],131 [51.5, 71.5, 55, 73, 58, 75.5, 68, 77, 65, 75.5, 58, 72.5, 56, 70.6],132 [133 -5.9, 35.8, -1.5, 35.1, 3, 36.8, 10, 37.3, 11, 35, 10, 34, 11, 33.2, 15.2,134 32.3, 20, 30.8, 23, 32.6, 29, 30.9, 32.3, 31.2, 34.2, 31.3, 34.5, 28, 33.5,135 27, 35.5, 23.5, 37.2, 21, 38.5, 18, 39.7, 15.5, 43.3, 12.5, 44, 10.4, 51.2,136 11.8, 51, 10.5, 49, 6.5, 46, 2, 41.5, -1.8, 39.2, -4.7, 39.5, -8, 40.5,137 -10.5, 40.5, -15, 35, -22, 32.8, -25.8, 32.4, -28.6, 30, -31.3, 27, -33.5,138 22, -34.2, 18.5, -34.2, 18.2, -31.5, 15.2, -27, 14.5, -22.5, 11.8, -17,139 12.2, -13, 13.7, -10.7, 12, -5, 9, -1, 9.6, 3.5, 8.5, 4.5, 5.5, 4.3, 1.5,140 6.2, -2, 4.8, -7.5, 4.4, -11.5, 6.9, -13.3, 8.8, -15, 10.9, -16.7, 12.5,141 -17.4, 14.7, -16.4, 19.5, -17, 21, -15, 24.5, -13, 27.6, -9.8, 30, -9.5,142 32.5, -6.8, 34,143 ],144 [44, -25, 47, -25, 50.2, -15.5, 49.3, -12, 44.3, -16.2, 43.3, -22],145 [146 113.5, -22, 114, -26.5, 115, -34, 118, -35, 124, -33.8, 129, -31.6, 132,147 -31.5, 135.5, -34.8, 137.8, -32.5, 138.5, -35.5, 140, -38, 144, -38.3,148 146.5, -39, 150, -37.5, 153.2, -30, 153.5, -25, 150.5, -22, 146, -18.8,149 145.3, -15, 142.5, -10.7, 141.6, -13, 141.5, -16.5, 140.5, -17.5, 135.5,150 -15, 136.8, -12.2, 132, -11.3, 130, -13, 129.3, -15, 126, -14, 122.3, -17.2,151 121, -19.5, 117, -20.7,152 ],153 [144.7, -40.7, 148.3, -40.9, 147.9, -43.2, 146, -43.6],154 [172.7, -34.5, 178.5, -37.7, 177, -39.3, 174.8, -41.4, 173.8, -39.3],155 [172.6, -40.5, 174.2, -41.7, 171.2, -44.3, 169, -46.6, 166.5, -46, 172, -41],156 [157 129.6, 33.3, 131, 31, 132, 33.5, 135.3, 33.6, 139.8, 35, 140.9, 36.9, 141.9,158 39.5, 141.5, 41.4, 140, 40.8, 139.8, 38.4, 137, 37, 133, 35.5, 130.9, 34.3,159 ],160 [161 140, 41.5, 141.5, 42.5, 143.3, 42, 145.5, 43.3, 144.3, 44.2, 142, 45.5,162 141.7, 44.2, 140.4, 43.2,163 ],164 [120.1, 23, 121, 25.3, 122, 25, 120.8, 21.9],165 [79.7, 8, 80.2, 9.8, 81.9, 7.2, 80.5, 5.9],166 [95.2, 5.6, 98, 4, 104.5, -2.5, 106, -5.8, 102.3, -4, 98.5, 0, 95.3, 3],167 [105.2, -6.8, 108, -6.5, 112.5, -6.9, 114.5, -7.8, 110, -8.1, 106, -7.4],168 [169 109, 1.5, 110, -1.5, 111, -3, 114.5, -4, 116.5, -2, 118, 1, 119, 5, 116.5,170 7, 114, 4.5, 111.5, 2.5,171 ],172 [119.4, -3.5, 120, 1, 124.9, 1.5, 121.5, -1, 123, -4.5, 120.5, -5.6],173 [174 131, -1.3, 135, -3.3, 138, -1.6, 141, -2.6, 146, -5, 147.5, -6.5, 147.2,175 -8.5, 150, -10.4, 146, -8.1, 143.5, -9, 142.3, -9.2, 138.5, -8.3, 137.8,176 -5.5, 133.5, -4, 132, -2.7,177 ],178 [120, 18.5, 122.3, 18.5, 124, 13, 121.5, 13.9, 120.6, 14.5, 119.8, 16.3],179 [122, 7, 126.3, 6.3, 125.5, 9.8, 123.5, 8.5],180];181182const WATER: Poly[] = [183 [-95, 59, -88, 56, -82, 53, -79, 55, -77, 60, -78, 62.5, -86, 64, -94, 62],184 [185 27.5, 42, 28, 44, 30, 45.5, 33, 44.5, 36.5, 45.3, 39.5, 47, 38, 44.5, 41.5,186 41.5, 36, 41.5, 31, 41.2, 28.5, 41,187 ],188 [189 47, 44.5, 49, 46.5, 53, 47, 53.5, 45, 51, 44, 52.5, 41.7, 54, 40.5, 53.8,190 37.3, 51, 36.7, 49, 38, 49.5, 40.3, 47.5, 43,191 ],192];193194const DEFAULT_CITIES: DotMapCity[] = [195 { lon: -122.4, lat: 37.8 },196 { lon: -118.2, lat: 34.1 },197 { lon: -123.1, lat: 49.3 },198 { lon: -104.9, lat: 39.7 },199 { lon: -99.1, lat: 19.4 },200 { lon: -87.6, lat: 41.9 },201 { lon: -79.4, lat: 43.7 },202 { lon: -74, lat: 40.7 },203 { lon: -84.4, lat: 33.7 },204 { lon: -74.1, lat: 4.7 },205 { lon: -77, lat: -12 },206 { lon: -70.7, lat: -33.4 },207 { lon: -58.4, lat: -34.6 },208 { lon: -46.6, lat: -23.5 },209 { lon: -43.2, lat: -22.9 },210 { lon: -21.9, lat: 64.1 },211 { lon: -9.1, lat: 38.7 },212 { lon: -3.7, lat: 40.4 },213 { lon: -0.1, lat: 51.5 },214 { lon: -6.3, lat: 53.3 },215 { lon: 2.4, lat: 48.9 },216 { lon: 4.9, lat: 52.4 },217 { lon: -7.6, lat: 33.6 },218 { lon: 3.4, lat: 6.5 },219 { lon: 13.4, lat: 52.5 },220 { lon: 12.5, lat: 41.9 },221 { lon: 18.1, lat: 59.3 },222 { lon: 21, lat: 52.2 },223 { lon: 18.4, lat: -33.9 },224 { lon: 28, lat: -26.2 },225 { lon: 31.2, lat: 30 },226 { lon: 29, lat: 41 },227 { lon: 36.8, lat: -1.3 },228 { lon: 30.5, lat: 50.5 },229 { lon: 46.7, lat: 24.7 },230 { lon: 55.3, lat: 25.2 },231 { lon: 72.9, lat: 19.1 },232 { lon: 77.2, lat: 28.6 },233 { lon: 77.6, lat: 13 },234 { lon: 90.4, lat: 23.8 },235 { lon: 100.5, lat: 13.8 },236 { lon: 103.8, lat: 1.4 },237 { lon: 106.8, lat: -6.2 },238 { lon: 106.7, lat: 10.8 },239 { lon: 114.2, lat: 22.3 },240 { lon: 121.5, lat: 31.2 },241 { lon: 116.4, lat: 39.9 },242 { lon: 121, lat: 14.6 },243 { lon: 127, lat: 37.6 },244 { lon: 139.7, lat: 35.7 },245 { lon: 135.5, lat: 34.7 },246 { lon: 115.9, lat: -31.9 },247 { lon: 151.2, lat: -33.9 },248 { lon: 145, lat: -37.8 },249 { lon: 174.8, lat: -36.8 },250];251252const STEP = 2.5;253const LAT_TOP = 80;254const LAT_BOTTOM = -57.5;255const COLS = Math.round(360 / STEP);256const ROWS = Math.round((LAT_TOP - LAT_BOTTOM) / STEP);257258const EASE_IO = Easing.bezier(0.65, 0, 0.35, 1);259const EASE_OUT = Easing.bezier(0.22, 1, 0.36, 1);260const CLAMP = {261 extrapolateLeft: "clamp",262 extrapolateRight: "clamp",263} as const;264265const THEMES = {266 dark: {267 bg: "#0A0A0B",268 fg: "#F3F2EF",269 muted: "#8B8A90",270 city: "#FFFFFF",271 lift: 0.08,272 dotAlpha: 1,273 grain: 0.06,274 },275 light: {276 bg: "#F5F4F0",277 fg: "#121214",278 muted: "#6E6C67",279 city: "#121214",280 lift: 0.3,281 dotAlpha: 0.85,282 grain: 0.045,283 },284} as const;285286/**287 * gradients.sh palettes, sampled per dot so the land reads as a halftone288 * screen of the gradient: "mesh" on dark, "pixel-glass" on light.289 */290const PALETTES = {291 dark: {292 reach: 0.46,293 bg: "#0E1645",294 colors: ["#ECDCF2", "#2E45B7", "#8796EE", "#2E45B7", "#8796EE", "#ECDCF2"],295 },296 light: {297 reach: 0.68,298 bg: "#F4F3F1",299 colors: ["#7A3CFF", "#FF4FB8", "#3D6BFF"],300 },301} as const;302const BLOBS: [number, number][] = [303 [16, 20],304 [84, 26],305 [72, 86],306 [22, 80],307 [52, 48],308 [92, 62],309];310311function rgb(hex: string): [number, number, number] {312 const v = Number.parseInt(hex.slice(1), 16);313 return [(v >> 16) & 255, (v >> 8) & 255, v & 255];314}315316function toHex(c: [number, number, number]) {317 return `#${c.map((v) => Math.round(v).toString(16).padStart(2, "0")).join("")}`;318}319320/** CSS-equivalent of the stacked radial layers, evaluated at (x, y) in 0–1. */321function meshAt(322 x: number,323 y: number,324 bg: string,325 colors: readonly string[],326 drift: number,327 reach: number,328) {329 let c = rgb(bg);330 for (let i = BLOBS.length - 1; i >= 0; i--) {331 const bx = BLOBS[i][0] / 100 + 0.04 * Math.sin(drift + i * 1.7);332 const by = BLOBS[i][1] / 100 + 0.03 * Math.cos(drift * 0.8 + i * 2.3);333 const d = Math.hypot((x - bx) / 0.85, (y - by) / 0.95);334 const a = Math.max(0, 1 - d / reach);335 const k = rgb(colors[i % colors.length]);336 c = [337 c[0] + (k[0] - c[0]) * a,338 c[1] + (k[1] - c[1]) * a,339 c[2] + (k[2] - c[2]) * a,340 ];341 }342 return c;343}344345const MAP_IN = -6;346const MAP_DUR = 26;347const LIGHT_AT = 20;348const LIGHT_SPAN = 66;349const RIPPLE = 26;350351function hash(n: number) {352 const x = Math.sin(n * 127.1 + 311.7) * 43758.5453;353 return x - Math.floor(x);354}355356function inside(lon: number, lat: number, poly: Poly) {357 let hit = false;358 const n = poly.length / 2;359 for (let i = 0, j = n - 1; i < n; j = i++) {360 const xi = poly[i * 2];361 const yi = poly[i * 2 + 1];362 const xj = poly[j * 2];363 const yj = poly[j * 2 + 1];364 if (365 yi > lat !== yj > lat &&366 lon < ((xj - xi) * (lat - yi)) / (yj - yi) + xi367 ) {368 hit = !hit;369 }370 }371 return hit;372}373374function isLand(lon: number, lat: number) {375 return (376 LAND.some((p) => inside(lon, lat, p)) &&377 !WATER.some((p) => inside(lon, lat, p))378 );379}380381function buildMask() {382 const land: boolean[] = [];383 for (let r = 0; r < ROWS; r++) {384 for (let c = 0; c < COLS; c++) {385 land.push(isLand(-180 + (c + 0.5) * STEP, LAT_TOP - (r + 0.5) * STEP));386 }387 }388 return land;389}390391const MASK = buildMask();392393function Grain({ opacity }: { opacity: number }) {394 const id = `g${useId().replace(/[^a-zA-Z0-9_-]/g, "")}`;395 return (396 <svg397 width="100%"398 height="100%"399 style={{ position: "absolute", inset: 0, opacity, pointerEvents: "none" }}400 aria-hidden401 >402 <filter id={id}>403 <feTurbulence404 type="fractalNoise"405 baseFrequency="0.9"406 numOctaves={2}407 seed={31}408 stitchTiles="stitch"409 />410 <feColorMatrix values="0 0 0 0 0.5 0 0 0 0 0.5 0 0 0 0 0.5 0 0 0 0.9 0" />411 </filter>412 <rect width="100%" height="100%" filter={`url(#${id})`} />413 </svg>414 );415}416417function snap(lon: number, lat: number) {418 const c0 = Math.floor((lon + 180) / STEP);419 const r0 = Math.floor((LAT_TOP - lat) / STEP);420 let best = -1;421 let bestD = Number.POSITIVE_INFINITY;422 for (let dr = -2; dr <= 2; dr++) {423 for (let dc = -2; dc <= 2; dc++) {424 const r = r0 + dr;425 const c = (c0 + dc + COLS) % COLS;426 if (r < 0 || r >= ROWS || !MASK[r * COLS + c]) continue;427 const d = dr * dr + dc * dc;428 if (d < bestD) {429 bestD = d;430 best = r * COLS + c;431 }432 }433 }434 return best;435}436437/** The foreground at `scale`, around the frame's center; nothing extra at 1. */438function ScaleLayer({439 scale,440 children,441}: {442 scale: number;443 children: React.ReactNode;444}) {445 if (scale === 1) return children;446 return (447 <AbsoluteFill style={{ transform: `scale(${scale})` }}>448 {children}449 </AbsoluteFill>450 );451}452453export function DotMap({454 count = 142,455 label = "countries",456 cities = DEFAULT_CITIES,457 accent = "#3B5BFD",458 ink,459 background,460 fontFamily = manrope,461 fontWeight = 400,462 sweep = LIGHT_SPAN,463 scale = 1,464 delay = 0,465 grain = true,466 theme = "dark",467 speed = 1,468}: DotMapProps) {469 const t = Math.max(0, useCurrentFrame() - delay) * speed;470 const { width: W, height: H } = useVideoConfig();471 const u = Math.min(W / 1280, H / 720);472 const p = THEMES[theme];473 const fg = ink ?? p.fg;474 const bg = background ?? p.bg;475 const done = LIGHT_AT + sweep + 6;476477 const mapW = Math.min(W * 0.84, (H * 0.6 * COLS) / ROWS);478 const pitch = mapW / COLS;479 const mapH = pitch * ROWS;480 const numSize = 124 * u;481 const gap = 40 * u;482 const blockH = mapH + gap + numSize * 0.9;483 const mapX = (W - mapW) / 2;484 const mapY = (H - blockH) / 2;485 const r = pitch * 0.3;486487 const lit = useMemo(() => {488 const seen = new Set<number>();489 const out: { cell: number; at: number }[] = [];490 cities.forEach((city, i) => {491 const cell = snap(city.lon, city.lat);492 if (cell < 0 || seen.has(cell)) return;493 seen.add(cell);494 const x = (city.lon + 180) / 360;495 out.push({496 cell,497 at: LIGHT_AT + x * sweep + (hash(i + 0.7) - 0.5) * 8,498 });499 });500 return out.sort((a, b) => a.at - b.at);501 }, [cities, sweep]);502 const litAt = useMemo(() => {503 const m = new Map<number, number>();504 for (const l of lit) m.set(l.cell, l.at);505 return m;506 }, [lit]);507508 const pal = PALETTES[theme];509 const drift = interpolate(t, [0, 135], [0, 1.2]);510 const liftTo = rgb(theme === "dark" ? "#FFFFFF" : p.bg);511512 const push = interpolate(t, [0, done + 40], [0, 1], {513 ...CLAMP,514 easing: EASE_IO,515 });516 const zoom = 0.975 + 0.03 * push;517518 const dots: React.ReactNode[] = [];519 const accents: React.ReactNode[] = [];520 for (let r0 = 0; r0 < ROWS; r0++) {521 for (let c = 0; c < COLS; c++) {522 const idx = r0 * COLS + c;523 if (!MASK[idx]) continue;524 const x = mapX + (c + 0.5) * pitch;525 const y = mapY + (r0 + 0.5) * pitch;526 const delay = MAP_IN + (c / COLS) * 16 + hash(idx * 0.37) * 6;527 const a = interpolate(t, [delay, delay + MAP_DUR - 16], [0, 1], {528 ...CLAMP,529 easing: EASE_OUT,530 });531 if (a <= 0) continue;532 const at = litAt.get(idx);533 if (at !== undefined && t >= at) {534 const k = interpolate(t, [at, at + 10], [0, 1], {535 ...CLAMP,536 easing: EASE_OUT,537 });538 accents.push(539 <circle540 key={`c${idx}`}541 cx={x}542 cy={y}543 r={r * (1.2 + 0.7 * k)}544 fill={p.city}545 />,546 );547 const w = (t - at) / RIPPLE;548 if (w < 1) {549 const e = Easing.bezier(0.22, 1, 0.36, 1)(w);550 accents.push(551 <circle552 key={`w${idx}`}553 cx={x}554 cy={y}555 r={r * 1.6 + e * pitch * 2.6}556 fill="none"557 stroke={accent}558 strokeWidth={Math.max(1, 1.4 * u)}559 opacity={(1 - w) * 0.8}560 />,561 );562 }563 continue;564 }565 const m = meshAt(566 c / COLS,567 r0 / ROWS,568 pal.bg,569 pal.colors,570 drift,571 pal.reach,572 );573 const tint: [number, number, number] = [574 m[0] + (liftTo[0] - m[0]) * p.lift,575 m[1] + (liftTo[1] - m[1]) * p.lift,576 m[2] + (liftTo[2] - m[2]) * p.lift,577 ];578 dots.push(579 <circle580 key={idx}581 cx={x}582 cy={y}583 r={r * (0.7 + 0.3 * a)}584 fill={toHex(tint)}585 opacity={a * p.dotAlpha}586 />,587 );588 }589 }590591 let shown = 0;592 for (const l of lit) if (t >= l.at) shown++;593 const value = lit.length594 ? Math.round((count * shown) / lit.length)595 : Math.round(count);596 const numIn = interpolate(t, [LIGHT_AT - 8, LIGHT_AT + 8], [0, 1], {597 ...CLAMP,598 easing: EASE_OUT,599 });600 const labIn = interpolate(t, [LIGHT_AT, LIGHT_AT + 16], [0, 1], {601 ...CLAMP,602 easing: EASE_OUT,603 });604605 return (606 <AbsoluteFill style={{ background: bg, overflow: "hidden" }}>607 <ScaleLayer scale={scale}>608 <AbsoluteFill609 style={{ transform: `scale(${zoom})`, transformOrigin: "50% 50%" }}610 >611 <svg612 width={W}613 height={H}614 style={{ position: "absolute", inset: 0 }}615 aria-hidden616 >617 {dots}618 {accents}619 </svg>620 <div621 style={{622 position: "absolute",623 left: 0,624 width: W,625 top: mapY + mapH + gap,626 display: "flex",627 justifyContent: "center",628 alignItems: "baseline",629 gap: 18 * u,630 whiteSpace: "nowrap",631 }}632 >633 <span634 style={{635 fontFamily,636 fontWeight,637 fontSize: numSize,638 lineHeight: 0.9,639 letterSpacing: "-0.04em",640 color: fg,641 fontVariantNumeric: "tabular-nums",642 opacity: numIn,643 transform: `translateY(${(1 - numIn) * 12 * u}px)`,644 display: "inline-block",645 minWidth: `${String(Math.round(count)).length * 0.6}em`,646 textAlign: "right",647 }}648 >649 {value}650 </span>651 <span652 style={{653 fontFamily,654 fontWeight: 500,655 fontSize: 30 * u,656 letterSpacing: "-0.015em",657 color: p.muted,658 opacity: labIn,659 transform: `translateY(${(1 - labIn) * 8 * u}px)`,660 display: "inline-block",661 }}662 >663 {label}664 </span>665 </div>666 </AbsoluteFill>667 </ScaleLayer>668669 <AbsoluteFill670 style={{671 background: `radial-gradient(ellipse 80% 80% at 50% 50%, transparent 62%, ${bg} 100%)`,672 opacity: 0.6,673 pointerEvents: "none",674 }}675 />676 {grain ? <Grain opacity={p.grain} /> : null}677 </AbsoluteFill>678 );679}









