commit bb3abcf85cdfe478a78b6695d09b856714b5b0ea Author: hermes Date: Thu Dec 3 23:00:40 2026 +0000 Københavnerkuglen: shakeable Copenhagen snow globe (Advent of AI Slop Day 3) diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2d96e70 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +node_modules/ +dist/ +check_*.png +preview_shot.png +smoke.png diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000..4877420 --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,53 @@ +# My Advent of AI Slop entry + +One small web page, made for one day of [Advent of AI Slop](https://advent-of-slop.quesma.com) (1 to 24 December +2026). The task of each day is behind its door there. One repository per day, named +`advent-of-slop--`, for example `advent-of-slop-01-living-fishtank`. + +## What is here + +- `index.html` and `src/main.ts`: the page. +- `src/badge.ts`: the label in the top right corner, "Advent of AI Slop [Day 1] Living fishtank", which links to the + calendar and to the day. +- `public/preview.png`: the picture shown when the link is shared. +- `.github/workflows/pages.yml`: publishes the page on GitHub Pages after every push to `main`. + +## Building it + +What the page does and how it looks is free: any library, any framework, any style. Add packages with pnpm. + +Keep these in `index.html`: + +- `<title>`, the description and the `og:` tags, rewritten for what was built. +- `<advent-badge day="N" name="...">` with the day this is for and the title of that day, and the script that loads + `src/badge.ts`. + +Replace `public/preview.png` with a 1200 by 630 screenshot of the finished page. + +The page is served from `https://<login>.github.io/<repository>/`, so: + +- Links and file paths are relative (`./`), never starting with `/`. +- There is no server. Everything runs in the browser, and anything in the page, API keys included, is public. + +## Commands + +```sh +pnpm install +pnpm dev # http://localhost:5173/ +pnpm build # typecheck and build to dist/; must pass before a push +``` + +## Publishing + +Push to `main`. A minute later the page is at `https://<login>.github.io/<repository>/`. + +Once per repository, GitHub Pages has to take its site from GitHub Actions (Settings > Pages > Source), or: + +```sh +gh api -X POST "repos/{owner}/{repo}/pages" -f build_type=workflow +``` + +A push made before that fails in the "Publish" workflow: run it again (`gh run rerun --failed`). + +To be listed on the calendar, the repository is public and belongs to the person's own account, not an +organization. They submit the address of the page and of the repository on the day's page. diff --git a/README.md b/README.md new file mode 100644 index 0000000..48aaff1 --- /dev/null +++ b/README.md @@ -0,0 +1,37 @@ +# Københavnerkuglen — Advent of AI Slop, Day 3 (Snow globe) + +> https://pages.obahan.xyz/lullu/advent-of-slop-03-copenhagen-snow-globe/ + +A snow globe of Copenhagen that you can actually shake. Inside: a procedurally +generated Nyhavn — random gabled houses in the classic colours, roof cranes, +lit windows at dusk and night, the spiral spire of Our Saviour's Church, the +Round Tower, a Tivoli-ish tower, street lamps and bundled-up pedestrians +trudging through the accumulating drift. + +## How to play + +- **Shake it**: grab the globe and rattle it left-right, hit *Ryst den!*, or press `space`. + Snow explodes off the drift and settles again over time. +- **Click the drift** for a little snow puff. +- **Sne slider**: from light dusting to full blizzard (150–1300 flakes). +- **Dag / Aften / Nat**: winter day, sunset, or starry night with lit windows. +- **Fej snescooten**: shovel the drift away and start over. + +Everything persists in `localStorage`: the drift you grew, the theme, the +density, and your total shake count (100 shakes earns a 💪). + +## Under the hood + +- Canvas 2D, no libraries. Vite + TypeScript. +- `src/snow.ts` — flake physics (gravity, drag, wobble, dome-wall collisions) + and a 72-column snowdrift that accumulates, slumps sideways, and gets + re-suspended on shakes. +- `src/scene.ts` — deterministic (seeded) Copenhagen skyline renderer with + three time-of-day palettes. +- `src/main.ts` — shake detection from pointer velocity reversals, controls, + persistence, the damped globe-oscillation animation. +- Smoke-tested with headless Chromium (shake via button/space/drag, drift + growth, persistence across reloads, zero page errors). + +Built for [Advent of AI Slop Day 3](https://advent-of-slop.quesma.com/day/3/): +*"Make a snow globe of your hometown that you can shake."* — hometown: Copenhagen, and yes, Copenhagen gets snow. diff --git a/index.html b/index.html new file mode 100644 index 0000000..fdc1d94 --- /dev/null +++ b/index.html @@ -0,0 +1,23 @@ +<!doctype html> +<html lang="en"> + <head> + <meta charset="utf-8" /> + <meta name="viewport" content="width=device-width, initial-scale=1" /> + <link rel="icon" href="./favicon.svg" type="image/svg+xml" /> + <title>Københavnerkuglen — Advent of AI Slop Day 3 + + + + + + + + + + + + + +
+ + diff --git a/package.json b/package.json new file mode 100644 index 0000000..8de90c5 --- /dev/null +++ b/package.json @@ -0,0 +1,15 @@ +{ + "name": "advent-of-slop-entry", + "type": "module", + "private": true, + "scripts": { + "dev": "vite", + "build": "tsc && vite build", + "preview": "vite preview" + }, + "packageManager": "pnpm@11.5.2", + "devDependencies": { + "typescript": "^7.0.2", + "vite": "^8.3.8" + } +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml new file mode 100644 index 0000000..e13864f --- /dev/null +++ b/pnpm-lock.yaml @@ -0,0 +1,717 @@ +lockfileVersion: '9.0' + +settings: + autoInstallPeers: true + excludeLinksFromLockfile: false + +importers: + + .: + devDependencies: + typescript: + specifier: ^7.0.2 + version: 7.0.2 + vite: + specifier: ^8.3.8 + version: 8.3.8 + +packages: + + '@emnapi/core@2.0.0-beta.2': + resolution: {integrity: sha512-MzCVoWtcg4Pm2B3je5mMvYMvj3MmBKw+fU7vbsJc9/iT8ip6/eYIHo/Dsm/mr+wsHB6SEyJDuxB09Yy6r/8+4A==} + + '@emnapi/runtime@2.0.0-beta.2': + resolution: {integrity: sha512-JcrSPzPvZuNZvJqPTF9Fw25LbOJ8avzFVlaf2grmH4Cku0oGP47tRgqPZadcfj3YoZMHkFVnCYFbQM8I+i5QEw==} + + '@emnapi/wasi-threads@2.2.0': + resolution: {integrity: sha512-JP7OYH38Q7+pyTAe14raZHLQIK7BDKbdwji+Xi3pcd/6QkJYQH3SX4wu6EplGrGJWRepoNzedfm0G3B9Z4e9Rw==} + + '@napi-rs/wasm-runtime@1.2.6': + resolution: {integrity: sha512-mRyDmEw9/fCDXCGfL1sbgIw/GUK0PVxRW4YwgPN61F3LQ+fSyoBFarJVzgGyhF6kRzEQZ0FejDqm4WLXSeqQmw==} + engines: {node: ^20.19.0 || ^22.13.0 || >=23.5.0} + peerDependencies: + '@emnapi/core': ^1.7.1 || 2.0.0-beta.2 + '@emnapi/runtime': ^1.7.1 || 2.0.0-beta.2 + + '@oxc-project/types@0.156.0': + resolution: {integrity: sha512-1Duyg48TdJNdyhEB8Xn1L36bT9Pv6GUtlKjHxOys8xkaF/rQq3XJE+bAurSK/AgIz5mGFsb77cn9Pb20+WCScw==} + + '@rolldown/binding-android-arm-eabi@1.2.19': + resolution: {integrity: sha512-e+Ebe0WT+9tbXmNKPIiC8YrWAHYwug3m6i4p3rZGGulfZri1jtI4HslT+OZnFf/OIHowWF71DTlHwXBP2SiA7A==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [arm] + os: [android] + + '@rolldown/binding-android-arm64@1.2.19': + resolution: {integrity: sha512-hOombrTJ+szt2ciEzS7oCA78lMPBgF5UMQWCJIyNfnrI7GLl8HYoFqCnpL2gcPOaXMqryGCU5ExdQKyDDcC+yA==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [arm64] + os: [android] + + '@rolldown/binding-darwin-arm64@1.2.19': + resolution: {integrity: sha512-XoMA2pwCKGTQzUjPgtRwkedH4WmXhdIPKT6l6oOxd1PUbNodGI6DcBekgN7EC//+x3pfBYX/qL1gNmZAqivw5g==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [arm64] + os: [darwin] + + '@rolldown/binding-darwin-x64@1.2.19': + resolution: {integrity: sha512-zo8EsSSwMZCY/e+fRnGaX02YGgvJD0yvhNi/9hpGPA2MJ9ZF8dPCw75UGfpI6OpQ/myR/dIYmogRvqiZD0TrXg==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [x64] + os: [darwin] + + '@rolldown/binding-freebsd-x64@1.2.19': + resolution: {integrity: sha512-O8ISAOfI1nj7AuBPd30FSF47z7f7lzlk5poQVGgiikvQuGEBFYvW8ki+UEnT+YJPnNGjQzn304klt4O9FUE7mA==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [x64] + os: [freebsd] + + '@rolldown/binding-linux-arm-gnueabihf@1.2.19': + resolution: {integrity: sha512-/lYCba5NO0yq4S0jGMH8QTBtkvQxoXjoQWzF5BcWp9MjB9jxVRD1GQDNofkVjcOj30DWyhLIN/4Oe60JKzaONw==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [arm] + os: [linux] + + '@rolldown/binding-linux-arm64-gnu@1.2.19': + resolution: {integrity: sha512-pm/apFMBnSbFb3O6nG5pHO1iqHhZrjGDFEjSm+ot9J17XXPvH9L90y5h+jgfHCE+Qdlsvy8qKEcU4VKxgjD+vA==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [arm64] + os: [linux] + libc: [glibc] + + '@rolldown/binding-linux-arm64-musl@1.2.19': + resolution: {integrity: sha512-K1SmQp3FFichn8oqrNIwvFoZ5wcvjC7goBzpaMNvLf9FZc+QB/QvLmnpJZgAAGHiD980tP8FZZnXk2K94rvlxg==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [arm64] + os: [linux] + libc: [musl] + + '@rolldown/binding-linux-ppc64-gnu@1.2.19': + resolution: {integrity: sha512-I0xwD57jP/3A7+5UPZin2w8Y7XHEmEM5zqpYZOcQ45MlNW6tUJUziymV3yRr7rL4vwyfEcRsRksC4a7Kc08p5Q==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [ppc64] + os: [linux] + libc: [glibc] + + '@rolldown/binding-linux-s390x-gnu@1.2.19': + resolution: {integrity: sha512-BrtEHT24SNXj9HiXqy+s/kXiSiQGt6EKCPUlRirAoIioVxKGnbXBUEkbZASAei7iZJB0/Ynm+0JP00Ipx7AnSw==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [s390x] + os: [linux] + libc: [glibc] + + '@rolldown/binding-linux-x64-gnu@1.2.19': + resolution: {integrity: sha512-rm75/9DkHKeU2WnA8w4X94WGYgLlDCFCfkQC+4bguVJmC/jvDRv2B+2wLOYhyE0fVuv7//Ckk39OoOufyCu76Q==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [x64] + os: [linux] + libc: [glibc] + + '@rolldown/binding-linux-x64-musl@1.2.19': + resolution: {integrity: sha512-irh/4+iYFM4GAzpluDErgjz89bj6NDtqqMAG/6O1LG38Ed3NpyebzCpcVNkFW8uhy+/3/BocUvnXDR33CXWe9A==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [x64] + os: [linux] + libc: [musl] + + '@rolldown/binding-openharmony-arm64@1.2.19': + resolution: {integrity: sha512-+KWTWNoPt+CfSq94CiceWu3yPE+QzkaG+phPyz9G60tmZLwfQkcA4AeksafzvJAw4pvg1mcd5a1TkUqVv0s4JA==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [arm64] + os: [openharmony] + + '@rolldown/binding-wasm32-wasi@1.2.19': + resolution: {integrity: sha512-7EH+skOsl5qpWnK0vzamgJFhOv1cwxQpsxm8tI883K9fur5c27p8q87fzEO6BbBPabA2/+s/zR63/pLc137iOg==} + engines: {node: ^20.19.0 || ^22.13.0 || >=23.5.0} + cpu: [wasm32] + + '@rolldown/binding-win32-arm64-msvc@1.2.19': + resolution: {integrity: sha512-3Q1Yg1Q7tEvBWoZf5rFvG/GKZQPgwfru+p4wBajDfJFBs0SHCpL++dfTjW9gyAKd1T7ZpIYvdaUax7Pa/IhFVQ==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [arm64] + os: [win32] + + '@rolldown/binding-win32-x64-msvc@1.2.19': + resolution: {integrity: sha512-y/sqRRc6d7hECzOFc5n3LSeqctmIp9mMjY1Kq4s14uLPd/LZ4z7i1zrW6fMtp2mPeuQIC4e6ULMcwQzMomqQag==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [x64] + os: [win32] + + '@rolldown/pluginutils@1.1.1': + resolution: {integrity: sha512-glFIJDvLNDtJhT9qrMFWLPbvS+skxgt4L0K8Ei2YtnhPysAJnsI7nyxSJxKj4ADeKX0OLjC4ntRkwpLOoS3rwA==} + + '@tybys/wasm-util@0.10.5': + resolution: {integrity: sha512-dOGOPxlaNV+G046mZzN+9C0dAcQZeSKcXiVaM0TYy/LM4ttTmgSBDxYfovcYI8Em3+eAbiAYpvWLOv8+ZVRJKA==} + + '@typescript/typescript-aix-ppc64@7.0.2': + resolution: {integrity: sha512-MTKKkWB7p/0E9xi1d1tHtZ5PiLkGEMIq88pK2CubZjOsLtYTLqhgIgi6zepFa+9GHZ6h05NMCkQxGKiPXMxXtQ==} + engines: {node: '>=16.20.0'} + cpu: [ppc64] + os: [aix] + + '@typescript/typescript-darwin-arm64@7.0.2': + resolution: {integrity: sha512-gowzar9MwS/aRWp6f3a4KUqzRjAZjOsmGNCM6LcTgXum+dBfgsBVMN+AgvOCCbguXyick6LJhpBszxMebJ8syA==} + engines: {node: '>=16.20.0'} + cpu: [arm64] + os: [darwin] + + '@typescript/typescript-darwin-x64@7.0.2': + resolution: {integrity: sha512-SZ9xZInqApNlNGc9s0W1VSsktYSOe9cFqNOIqmN1Gs8SmkjKZYFt017G4VwPxASInODuAdbTW7sXiFUf893RgA==} + engines: {node: '>=16.20.0'} + cpu: [x64] + os: [darwin] + + '@typescript/typescript-freebsd-arm64@7.0.2': + resolution: {integrity: sha512-W5NH4y/J0plIIS5b2xvTEkU7JFxyqdMAOgf+Ilhl0vHQXKO5dZoxd+C/jEtq56c4F3wk71RB4BMRQ2XdI+bwYQ==} + engines: {node: '>=16.20.0'} + cpu: [arm64] + os: [freebsd] + + '@typescript/typescript-freebsd-x64@7.0.2': + resolution: {integrity: sha512-UMGDx5sTpzNw3WiPebH7l90IWfJggEd+egHt/q6p7/Cm3zqoV7VxkGXt+3DxPIw8CcmvAB0j3sVVfbhX+M4Tpw==} + engines: {node: '>=16.20.0'} + cpu: [x64] + os: [freebsd] + + '@typescript/typescript-linux-arm64@7.0.2': + resolution: {integrity: sha512-Qh4eU4/y3yDjnfjjyPYihMj5/ODIlmt+Bzu17OI+fiSRDW57QmU5SiN63exPRNJPKUzcc1INa1NXdrJ+MqHjUQ==} + engines: {node: '>=16.20.0'} + cpu: [arm64] + os: [linux] + + '@typescript/typescript-linux-arm@7.0.2': + resolution: {integrity: sha512-gffT3xPz9sR7j/YJExkyPntrI0P2EP9XbOyWzth2/Gs0RstK+90RBcO0ncXoXy/beYll1SXw846Nf2zdnEz0QQ==} + engines: {node: '>=16.20.0'} + cpu: [arm] + os: [linux] + + '@typescript/typescript-linux-loong64@7.0.2': + resolution: {integrity: sha512-uEHck9i8hoAzXPiYRib1O7miOnz23SxIeVl6F4LXox+qov1K35jHcEW6VHKvZI+pyvl7fZEP4MCU5LYvIq1GuQ==} + engines: {node: '>=16.20.0'} + cpu: [loong64] + os: [linux] + + '@typescript/typescript-linux-mips64el@7.0.2': + resolution: {integrity: sha512-R4KvAMnE43W5Qeqb0Ly56O3mWMWIAgsMyz36DCaycd5nbg/9kzm0liw3JocfRqyJY0KPmzFjbswozXyW0DnIYA==} + engines: {node: '>=16.20.0'} + cpu: [mips64el] + os: [linux] + + '@typescript/typescript-linux-ppc64@7.0.2': + resolution: {integrity: sha512-DORx5b3sd/4S7eayxm4FQv+A7CrkUIGRaHiwI8oiHTAI1fAPWhF4J0vAlkC8biAlHSVVwxMQ3tjZ2/DVbnQiiA==} + engines: {node: '>=16.20.0'} + cpu: [ppc64] + os: [linux] + + '@typescript/typescript-linux-riscv64@7.0.2': + resolution: {integrity: sha512-wf0jqEDOjrPRnKwYRyyJDRo11KMbvMFrU+q4zqKyChODBzvlkbhNQfKvLxQCcwTpdDaXSHZTVuh0JoCrKCUMHQ==} + engines: {node: '>=16.20.0'} + cpu: [riscv64] + os: [linux] + + '@typescript/typescript-linux-s390x@7.0.2': + resolution: {integrity: sha512-IkwJc3L7yhytWd/ewjyxNDfOmswCm9GWMJT/ue/dU4aZNbwZeYAetq42VyLmsmSjvoX7z74X6ZaYCtzAr0EuGw==} + engines: {node: '>=16.20.0'} + cpu: [s390x] + os: [linux] + + '@typescript/typescript-linux-x64@7.0.2': + resolution: {integrity: sha512-EYdf2cNg7rgCWJnxCdJ+F3V39O8ihb37eHAu1LK8oAFizgTQbPOK7zHHXbPt8rX24COqODXeI3sIf0fCXG7H/A==} + engines: {node: '>=16.20.0'} + cpu: [x64] + os: [linux] + + '@typescript/typescript-netbsd-arm64@7.0.2': + resolution: {integrity: sha512-+polYF4MF04aPpO5FTkHran9yUQDSXqy5GiSDKpsll5jy3l3+g9QLhpf39T+ePtefhXLOGrLl0QIjkQP6VnelA==} + engines: {node: '>=16.20.0'} + cpu: [arm64] + os: [netbsd] + + '@typescript/typescript-netbsd-x64@7.0.2': + resolution: {integrity: sha512-8YIT0EHM/3dq10ZOVF/A7pc/YSMtbcecct4rWtexrnSCHOPcpC2KTLXfTCR6vDpnSiY12heNb1GiN/wu+T/FyA==} + engines: {node: '>=16.20.0'} + cpu: [x64] + os: [netbsd] + + '@typescript/typescript-openbsd-arm64@7.0.2': + resolution: {integrity: sha512-APT8+ClYnuYm1u9+kgGXoMj2VzWzcymwh2gNSQVySHfkRDGOTVkoWLjCmOQSaO+PoqQ57B0flRp9SA+7GnnkzQ==} + engines: {node: '>=16.20.0'} + cpu: [arm64] + os: [openbsd] + + '@typescript/typescript-openbsd-x64@7.0.2': + resolution: {integrity: sha512-yX7s+Q0Dln0Dt9tEzZsAjXXR/+ytBM7AlglaqyeMPxQszJ1JhlJdZ6jLA+IzldHtflX81em7lDao1xXu+aRRkg==} + engines: {node: '>=16.20.0'} + cpu: [x64] + os: [openbsd] + + '@typescript/typescript-sunos-x64@7.0.2': + resolution: {integrity: sha512-dLJDGaLZ1D4HPQn62u1n8mBDkJREwMsAkCdkwd4Ieqw+x3TUyTsqY0YiBCtE6H6OzzgGk3iuZ3vFWRS+E8/d1g==} + engines: {node: '>=16.20.0'} + cpu: [x64] + os: [sunos] + + '@typescript/typescript-win32-arm64@7.0.2': + resolution: {integrity: sha512-Gyl1Vy6OsWesLzmq+EP0Fb7b4Nid5232AvcA2SFcdYreldpNtYFFofPjnt62y9hQy7VTaZp65ICJjuAQRaVcIQ==} + engines: {node: '>=16.20.0'} + cpu: [arm64] + os: [win32] + + '@typescript/typescript-win32-x64@7.0.2': + resolution: {integrity: sha512-0BQ3HkAHHlKLSp1qRvf3SUhGpGsDuhB/jgFw75guyqbxJqEaS0Cw/VFO8i2nHglJUzQCRtMMR/IBAKE3ETMC4g==} + engines: {node: '>=16.20.0'} + cpu: [x64] + os: [win32] + + detect-libc@2.1.2: + resolution: {integrity: sha512-Btj2BOOO83o3WyH59e8MgXsxEQVcarkUOpEYrubB0urwnN10yQ364rsiByU11nZlqWYZm05i/of7io4mzihBtQ==} + engines: {node: '>=8'} + + fdir@6.5.0: + resolution: {integrity: sha512-tIbYtZbucOs0BRGqPJkshJUYdL+SDH7dVM8gjy+ERp3WAUjLEFJE+02kanyHtwjWOnwrKYBiwAmM0p4kLJAnXg==} + engines: {node: '>=12.0.0'} + peerDependencies: + picomatch: ^3 || ^4 + peerDependenciesMeta: + picomatch: + optional: true + + fsevents@2.3.3: + resolution: {integrity: sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==} + engines: {node: ^8.16.0 || ^10.6.0 || >=11.0.0} + os: [darwin] + + lightningcss-android-arm64@1.33.0: + resolution: {integrity: sha512-gEpRTalKdosp4Bb8qWtc2iOgE5SeIHlpS1up9bFq2wAyYhl1UdTObYiHe98zEM9SQvSoqQZ1IQD0JNpg3Ml5pg==} + engines: {node: '>= 12.0.0'} + cpu: [arm64] + os: [android] + + lightningcss-darwin-arm64@1.33.0: + resolution: {integrity: sha512-Sciaz8eenNTKn9b3t7+xr0ipTp9YxKQY4npwQ3mrRuL0BAVHBLyZxofhaKBAVtzmtRZ/zTyo0/to4B1uWG/Djg==} + engines: {node: '>= 12.0.0'} + cpu: [arm64] + os: [darwin] + + lightningcss-darwin-x64@1.33.0: + resolution: {integrity: sha512-Z5UPAxzrjlWNNyGy6i65cJzzvgJ5D3T6wMvs+gWpY9d7qRhANrxqAp6LhxIgZhWEw18RfJTGcRxjuLIBr+m8XQ==} + engines: {node: '>= 12.0.0'} + cpu: [x64] + os: [darwin] + + lightningcss-freebsd-x64@1.33.0: + resolution: {integrity: sha512-QQM/Ti/hQajJwCY+RiWuCZ9sdtI/XQk7nDK5vC8kkdwixezOlDgvDx7+RT+QjK6FcFT4MpsuoBnHIo/O3StRRg==} + engines: {node: '>= 12.0.0'} + cpu: [x64] + os: [freebsd] + + lightningcss-linux-arm-gnueabihf@1.33.0: + resolution: {integrity: sha512-N7FVBe6iS24MlM6R/4RBTxGhQheZGs7tiQ9U32UtF75NzP5Q7xWPRqLBCKxlRQRk3rY1jCIPLzx7WzOhuUIRLQ==} + engines: {node: '>= 12.0.0'} + cpu: [arm] + os: [linux] + + lightningcss-linux-arm64-gnu@1.33.0: + resolution: {integrity: sha512-j2v/itmy4HlNxlc6voKXYgBqNi0Ng2LShg4z7GufpEgs05P+2suBVyi9I6YHq5uoVFx9ETin3eCEhLVyXGQnKg==} + engines: {node: '>= 12.0.0'} + cpu: [arm64] + os: [linux] + libc: [glibc] + + lightningcss-linux-arm64-musl@1.33.0: + resolution: {integrity: sha512-yiO5ROMuYQgXbC60yjZU5CYSFZGKXL0HFATXt9mHJn1+zW55oCtMI9NfcVhYLMFDL7gV7oBPon/EmMMGg2OvtQ==} + engines: {node: '>= 12.0.0'} + cpu: [arm64] + os: [linux] + libc: [musl] + + lightningcss-linux-x64-gnu@1.33.0: + resolution: {integrity: sha512-ar+Ju7LmcN0Jo4FpL4hpFybwNG9/3A/Br5KW2n2jyODg3MEZXaDYADdemoNS+BDNfMgKvylJLj4S5tyRActuAg==} + engines: {node: '>= 12.0.0'} + cpu: [x64] + os: [linux] + libc: [glibc] + + lightningcss-linux-x64-musl@1.33.0: + resolution: {integrity: sha512-RYiYbkokw0trfKqqzfF55lginwEPrD3OJDfTuJzFs1MK6iFnDenaz1fqLLtX4ITG3OktJQXOeTaw1awrBAlZPw==} + engines: {node: '>= 12.0.0'} + cpu: [x64] + os: [linux] + libc: [musl] + + lightningcss-win32-arm64-msvc@1.33.0: + resolution: {integrity: sha512-1K+MPfLSFVpphzpdbfkhlWk6wBrTObBzS2T6db10PNOZgR9GoVsAWzwNyuhUYYbTp23j+4RrncfujZ4uAzXvwA==} + engines: {node: '>= 12.0.0'} + cpu: [arm64] + os: [win32] + + lightningcss-win32-x64-msvc@1.33.0: + resolution: {integrity: sha512-OlEICDx/Xl0FqSp4bry8zFnCvGpig3Gl4gCquvYwHuqJKEC1+n9NgDniFvqHGmMv1ZkqDJrDqKKSykTDX+ehuA==} + engines: {node: '>= 12.0.0'} + cpu: [x64] + os: [win32] + + lightningcss@1.33.0: + resolution: {integrity: sha512-WkUDrojuJs0xkgGf2udWxa3yGBRxPtxUkB79i6aCZLRgc7PM8fZe9TosfPDcvEpQZbuFASnHYmRLBLUbmLOIIA==} + engines: {node: '>= 12.0.0'} + + nanoid@3.3.20: + resolution: {integrity: sha512-uKdg2G3GNCKQn9byYOpxbGqrT2fGO5KRt5J/8b3pok8rT6qxGWF6hxMyJiEYtAf+FVyYuD9hRaDqX5uPFYJ4ZQ==} + engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1} + hasBin: true + + picocolors@1.1.1: + resolution: {integrity: sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==} + + picomatch@4.0.7: + resolution: {integrity: sha512-qcJu88Q2IWqJsDD529JKMdwGm/dvInW4HvQnRwiH9JtihJvzGOscDtHE3x1pBKeUOTysQ8kVmLnJ2kJu7yhcGA==} + engines: {node: '>=12'} + + postcss@8.5.33: + resolution: {integrity: sha512-RVHEU9/Pp1Fnjr/MpAJsZoADukCKhfIi15OunEYiGktIkYLkPVvC1sioWolGDS7XByMTx9m/IGbro0Js13zhnQ==} + engines: {node: ^10 || ^12 || >=14} + + rolldown@1.2.19: + resolution: {integrity: sha512-QIiV1J9d0pzN4jeeTH4sjPy0AZ6cAy2cG0ExeoE1+U8Rvj+hR3gYkokx0YbeUNGlZqiQJJ2utcETe0oKXwzsuA==} + engines: {node: ^20.19.0 || >=22.12.0} + hasBin: true + + source-map-js@1.2.4: + resolution: {integrity: sha512-J7ZjMvHd9O1fcT/5V09QWaaSl2BbWx3F6O08spde82Namf9UB0GxRVIPiNbVsdKkoizHiSpTodo3vp2bAy91MA==} + engines: {node: '>=6.0.0'} + + tinyglobby@0.2.17: + resolution: {integrity: sha512-wXR/dYpcqKmfWpEdZjiKJOwCNFndD0DMnrW/cYjVGttEkBfVgcLFHoNrlj47mjOVic9yyNu65alsgF4NQyTa2g==} + engines: {node: '>=12.0.0'} + + tslib@2.9.1: + resolution: {integrity: sha512-a4Ux9VKuIMHsOS7ENbEq6hK2ZGYIT27Rtl0E4eD9KqwxhKiQeMZE/9xb3IdYwWaSOyIBQLExhQgXDTYoiCxnWA==} + + typescript@7.0.2: + resolution: {integrity: sha512-8FYau96o3NKOhbjKi/qNvG/W5jhzxkbdm5sj9AbZ/5T5sWqn3hJgLfGx27sRKZWTvyzCP8dLRBTf5tBTSRVUNA==} + engines: {node: '>=16.20.0'} + hasBin: true + + vite@8.3.8: + resolution: {integrity: sha512-LzOn3h9rG/0vhLdXrV4yJ4QFA9eEoqCl+Yx+kGJd7aB9w6nfNgVHKSYwLPZUHrz4ZGa+t+kXjV9itvcHDLQouA==} + engines: {node: ^20.19.0 || >=22.12.0} + hasBin: true + peerDependencies: + '@types/node': ^20.19.0 || >=22.12.0 + '@vitejs/devtools': ^0.7.1 || ^0.8.0 + esbuild: ^0.27.0 || ^0.28.0 + jiti: '>=1.21.0' + less: ^4.0.0 + sass: ^1.70.0 + sass-embedded: ^1.70.0 + stylus: '>=0.54.8' + sugarss: ^5.0.0 + terser: ^5.16.0 + tsx: ^4.8.1 + yaml: ^2.4.2 + peerDependenciesMeta: + '@types/node': + optional: true + '@vitejs/devtools': + optional: true + esbuild: + optional: true + jiti: + optional: true + less: + optional: true + sass: + optional: true + sass-embedded: + optional: true + stylus: + optional: true + sugarss: + optional: true + terser: + optional: true + tsx: + optional: true + yaml: + optional: true + +snapshots: + + '@emnapi/core@2.0.0-beta.2': + dependencies: + '@emnapi/wasi-threads': 2.2.0 + tslib: 2.9.1 + optional: true + + '@emnapi/runtime@2.0.0-beta.2': + dependencies: + tslib: 2.9.1 + optional: true + + '@emnapi/wasi-threads@2.2.0': + dependencies: + tslib: 2.9.1 + optional: true + + '@napi-rs/wasm-runtime@1.2.6(@emnapi/core@2.0.0-beta.2)(@emnapi/runtime@2.0.0-beta.2)': + dependencies: + '@emnapi/core': 2.0.0-beta.2 + '@emnapi/runtime': 2.0.0-beta.2 + '@tybys/wasm-util': 0.10.5 + optional: true + + '@oxc-project/types@0.156.0': {} + + '@rolldown/binding-android-arm-eabi@1.2.19': + optional: true + + '@rolldown/binding-android-arm64@1.2.19': + optional: true + + '@rolldown/binding-darwin-arm64@1.2.19': + optional: true + + '@rolldown/binding-darwin-x64@1.2.19': + optional: true + + '@rolldown/binding-freebsd-x64@1.2.19': + optional: true + + '@rolldown/binding-linux-arm-gnueabihf@1.2.19': + optional: true + + '@rolldown/binding-linux-arm64-gnu@1.2.19': + optional: true + + '@rolldown/binding-linux-arm64-musl@1.2.19': + optional: true + + '@rolldown/binding-linux-ppc64-gnu@1.2.19': + optional: true + + '@rolldown/binding-linux-s390x-gnu@1.2.19': + optional: true + + '@rolldown/binding-linux-x64-gnu@1.2.19': + optional: true + + '@rolldown/binding-linux-x64-musl@1.2.19': + optional: true + + '@rolldown/binding-openharmony-arm64@1.2.19': + optional: true + + '@rolldown/binding-wasm32-wasi@1.2.19': + dependencies: + '@emnapi/core': 2.0.0-beta.2 + '@emnapi/runtime': 2.0.0-beta.2 + '@napi-rs/wasm-runtime': 1.2.6(@emnapi/core@2.0.0-beta.2)(@emnapi/runtime@2.0.0-beta.2) + optional: true + + '@rolldown/binding-win32-arm64-msvc@1.2.19': + optional: true + + '@rolldown/binding-win32-x64-msvc@1.2.19': + optional: true + + '@rolldown/pluginutils@1.1.1': {} + + '@tybys/wasm-util@0.10.5': + dependencies: + tslib: 2.9.1 + optional: true + + '@typescript/typescript-aix-ppc64@7.0.2': + optional: true + + '@typescript/typescript-darwin-arm64@7.0.2': + optional: true + + '@typescript/typescript-darwin-x64@7.0.2': + optional: true + + '@typescript/typescript-freebsd-arm64@7.0.2': + optional: true + + '@typescript/typescript-freebsd-x64@7.0.2': + optional: true + + '@typescript/typescript-linux-arm64@7.0.2': + optional: true + + '@typescript/typescript-linux-arm@7.0.2': + optional: true + + '@typescript/typescript-linux-loong64@7.0.2': + optional: true + + '@typescript/typescript-linux-mips64el@7.0.2': + optional: true + + '@typescript/typescript-linux-ppc64@7.0.2': + optional: true + + '@typescript/typescript-linux-riscv64@7.0.2': + optional: true + + '@typescript/typescript-linux-s390x@7.0.2': + optional: true + + '@typescript/typescript-linux-x64@7.0.2': + optional: true + + '@typescript/typescript-netbsd-arm64@7.0.2': + optional: true + + '@typescript/typescript-netbsd-x64@7.0.2': + optional: true + + '@typescript/typescript-openbsd-arm64@7.0.2': + optional: true + + '@typescript/typescript-openbsd-x64@7.0.2': + optional: true + + '@typescript/typescript-sunos-x64@7.0.2': + optional: true + + '@typescript/typescript-win32-arm64@7.0.2': + optional: true + + '@typescript/typescript-win32-x64@7.0.2': + optional: true + + detect-libc@2.1.2: {} + + fdir@6.5.0(picomatch@4.0.7): + optionalDependencies: + picomatch: 4.0.7 + + fsevents@2.3.3: + optional: true + + lightningcss-android-arm64@1.33.0: + optional: true + + lightningcss-darwin-arm64@1.33.0: + optional: true + + lightningcss-darwin-x64@1.33.0: + optional: true + + lightningcss-freebsd-x64@1.33.0: + optional: true + + lightningcss-linux-arm-gnueabihf@1.33.0: + optional: true + + lightningcss-linux-arm64-gnu@1.33.0: + optional: true + + lightningcss-linux-arm64-musl@1.33.0: + optional: true + + lightningcss-linux-x64-gnu@1.33.0: + optional: true + + lightningcss-linux-x64-musl@1.33.0: + optional: true + + lightningcss-win32-arm64-msvc@1.33.0: + optional: true + + lightningcss-win32-x64-msvc@1.33.0: + optional: true + + lightningcss@1.33.0: + dependencies: + detect-libc: 2.1.2 + optionalDependencies: + lightningcss-android-arm64: 1.33.0 + lightningcss-darwin-arm64: 1.33.0 + lightningcss-darwin-x64: 1.33.0 + lightningcss-freebsd-x64: 1.33.0 + lightningcss-linux-arm-gnueabihf: 1.33.0 + lightningcss-linux-arm64-gnu: 1.33.0 + lightningcss-linux-arm64-musl: 1.33.0 + lightningcss-linux-x64-gnu: 1.33.0 + lightningcss-linux-x64-musl: 1.33.0 + lightningcss-win32-arm64-msvc: 1.33.0 + lightningcss-win32-x64-msvc: 1.33.0 + + nanoid@3.3.20: {} + + picocolors@1.1.1: {} + + picomatch@4.0.7: {} + + postcss@8.5.33: + dependencies: + nanoid: 3.3.20 + picocolors: 1.1.1 + source-map-js: 1.2.4 + + rolldown@1.2.19: + dependencies: + '@oxc-project/types': 0.156.0 + '@rolldown/pluginutils': 1.1.1 + optionalDependencies: + '@rolldown/binding-android-arm-eabi': 1.2.19 + '@rolldown/binding-android-arm64': 1.2.19 + '@rolldown/binding-darwin-arm64': 1.2.19 + '@rolldown/binding-darwin-x64': 1.2.19 + '@rolldown/binding-freebsd-x64': 1.2.19 + '@rolldown/binding-linux-arm-gnueabihf': 1.2.19 + '@rolldown/binding-linux-arm64-gnu': 1.2.19 + '@rolldown/binding-linux-arm64-musl': 1.2.19 + '@rolldown/binding-linux-ppc64-gnu': 1.2.19 + '@rolldown/binding-linux-s390x-gnu': 1.2.19 + '@rolldown/binding-linux-x64-gnu': 1.2.19 + '@rolldown/binding-linux-x64-musl': 1.2.19 + '@rolldown/binding-openharmony-arm64': 1.2.19 + '@rolldown/binding-wasm32-wasi': 1.2.19 + '@rolldown/binding-win32-arm64-msvc': 1.2.19 + '@rolldown/binding-win32-x64-msvc': 1.2.19 + + source-map-js@1.2.4: {} + + tinyglobby@0.2.17: + dependencies: + fdir: 6.5.0(picomatch@4.0.7) + picomatch: 4.0.7 + + tslib@2.9.1: + optional: true + + typescript@7.0.2: + optionalDependencies: + '@typescript/typescript-aix-ppc64': 7.0.2 + '@typescript/typescript-darwin-arm64': 7.0.2 + '@typescript/typescript-darwin-x64': 7.0.2 + '@typescript/typescript-freebsd-arm64': 7.0.2 + '@typescript/typescript-freebsd-x64': 7.0.2 + '@typescript/typescript-linux-arm': 7.0.2 + '@typescript/typescript-linux-arm64': 7.0.2 + '@typescript/typescript-linux-loong64': 7.0.2 + '@typescript/typescript-linux-mips64el': 7.0.2 + '@typescript/typescript-linux-ppc64': 7.0.2 + '@typescript/typescript-linux-riscv64': 7.0.2 + '@typescript/typescript-linux-s390x': 7.0.2 + '@typescript/typescript-linux-x64': 7.0.2 + '@typescript/typescript-netbsd-arm64': 7.0.2 + '@typescript/typescript-netbsd-x64': 7.0.2 + '@typescript/typescript-openbsd-arm64': 7.0.2 + '@typescript/typescript-openbsd-x64': 7.0.2 + '@typescript/typescript-sunos-x64': 7.0.2 + '@typescript/typescript-win32-arm64': 7.0.2 + '@typescript/typescript-win32-x64': 7.0.2 + + vite@8.3.8: + dependencies: + lightningcss: 1.33.0 + picomatch: 4.0.7 + postcss: 8.5.33 + rolldown: 1.2.19 + tinyglobby: 0.2.17 + optionalDependencies: + fsevents: 2.3.3 diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml new file mode 100644 index 0000000..6d40426 --- /dev/null +++ b/pnpm-workspace.yaml @@ -0,0 +1,5 @@ +# Only install package versions published at least 7 days ago (in minutes). +minimumReleaseAge: 10080 + +allowBuilds: + esbuild: true diff --git a/public/favicon.svg b/public/favicon.svg new file mode 100644 index 0000000..5a10cca --- /dev/null +++ b/public/favicon.svg @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/public/preview.png b/public/preview.png new file mode 100644 index 0000000..9256b5a Binary files /dev/null and b/public/preview.png differ diff --git a/scripts/preview.py b/scripts/preview.py new file mode 100644 index 0000000..a29999a --- /dev/null +++ b/scripts/preview.py @@ -0,0 +1,42 @@ +# Capture a clean 1200x630 preview.png: fresh state, dusk theme, moderate snow, +# a little drift, one shake for motion. +import http.server, threading, functools, os +DIST = os.path.abspath('dist') +httpd = http.server.ThreadingHTTPServer(('127.0.0.1', 8767), functools.partial(http.server.SimpleHTTPRequestHandler, directory=DIST)) +threading.Thread(target=httpd.serve_forever, daemon=True).start() +from playwright.sync_api import sync_playwright +with sync_playwright() as p: + b = p.chromium.launch( + executable_path='/home/hermeswebui/.hermes/home/.cache/ms-playwright/chromium-1234/chrome-linux64/chrome', + args=['--no-sandbox', '--disable-gpu', '--disable-dev-shm-usage']) + pg = b.new_page(viewport={'width': 1200, 'height': 630}) + pg.goto('http://127.0.0.1:8767/', wait_until='networkidle') + pg.evaluate("localStorage.clear()") + pg.reload(wait_until='networkidle') + pg.wait_for_timeout(500) + # Dusk theme, moderate snow. + pg.click('button[data-theme="dusk"]') + pg.locator('#density').fill('2') + pg.locator('#density').dispatch_event('input') + # Let snow fall and a drift form. + pg.wait_for_timeout(9000) + # One gentle shake so flakes are mid-air. + pg.click('#shake-btn') + pg.wait_for_timeout(2600) + # Fit the whole app into 630px height. + pg.evaluate("""() => { + const st = document.querySelector('#stage'); + st.style.maxWidth = '360px'; + st.style.margin = '0 auto'; + window.dispatchEvent(new Event('resize')); + document.body.style.paddingTop = '0.1rem'; + document.querySelector('header h1').style.marginTop = '0.1rem'; + window.scrollTo(0, 0); + }""") + pg.wait_for_timeout(1500) + box = pg.locator('#globe').bounding_box() + print('canvas box:', box) + pg.screenshot(path='public/preview.png') + print('saved public/preview.png') + b.close() +httpd.shutdown() diff --git a/scripts/smoke3.py b/scripts/smoke3.py new file mode 100644 index 0000000..a54f045 --- /dev/null +++ b/scripts/smoke3.py @@ -0,0 +1,101 @@ +# Smoke-test the built Copenhagen snow globe: shake mechanics, drift growth, +# persistence, theme switching, sweep. Also captures the 1200x630 preview.png. +import http.server, threading, functools, sys, os, json +DIST = os.path.abspath(sys.argv[1]) +OUT = os.path.dirname(DIST) +httpd = http.server.ThreadingHTTPServer(('127.0.0.1', 8766), functools.partial(http.server.SimpleHTTPRequestHandler, directory=DIST)) +threading.Thread(target=httpd.serve_forever, daemon=True).start() +from playwright.sync_api import sync_playwright +errs, msgs = [], [] +results = {} +with sync_playwright() as p: + b = p.chromium.launch( + executable_path='/home/hermeswebui/.hermes/home/.cache/ms-playwright/chromium-1234/chrome-linux64/chrome', + args=['--no-sandbox', '--disable-gpu', '--disable-dev-shm-usage']) + pg = b.new_page(viewport={'width': 1200, 'height': 630}) + pg.on('pageerror', lambda e: errs.append(str(e))) + pg.on('console', lambda m: msgs.append(f"{m.type}: {m.text}")) + pg.goto('http://127.0.0.1:8766/', wait_until='networkidle') + pg.wait_for_timeout(600) + results['title'] = pg.title() + results['has_canvas'] = pg.locator('#globe').count() == 1 + results['badge'] = pg.evaluate("!!document.querySelector('advent-badge')") + + def shakes(): + return int(pg.locator('#stat-shakes').text_content().split(':')[1].split()[0]) + + # Button shake. + pg.click('#shake-btn'); pg.wait_for_timeout(200) + results['shake_btn'] = shakes() == 1 + + # Space shake. + pg.keyboard.press('Space'); pg.wait_for_timeout(200) + results['shake_space'] = shakes() == 2 + + # Drag-shake: fast left-right reversals over the canvas. + box = pg.locator('#globe').bounding_box() + cx, cy = box['x'] + box['width']/2, box['y'] + box['height']/2 + pg.mouse.move(cx, cy); pg.mouse.down() + for i in range(6): + pg.mouse.move(cx + (80 if i % 2 else -80), cy, steps=4) + pg.mouse.up(); pg.wait_for_timeout(200) + results['shake_drag'] = shakes() >= 3 + + # Drift grows as snow falls. + def drift_cm(): + return float(pg.locator('#stat-drift').text_content().split(':')[1].strip().split()[0]) + d0 = drift_cm() + pg.wait_for_timeout(12000) + d1 = drift_cm() + results['drift_grows'] = d1 > d0 + results['drift_before'] = d0 + results['drift_after'] = d1 + + # Click on the drift area = puff, no errors. + pg.mouse.click(cx, cy + box['height']*0.28); pg.wait_for_timeout(300) + + # Theme switch. + pg.click('button[data-theme="night"]'); pg.wait_for_timeout(300) + results['theme_night_active'] = pg.evaluate( + "document.querySelector('button[data-theme=\"night\"]').classList.contains('active')") + + # Density slider to max. + pg.locator('#density').fill('4') + pg.locator('#density').dispatch_event('input') + pg.wait_for_timeout(1500) + results['flakes_text'] = pg.locator('#stat-flakes').text_content() + + # Persistence: reload keeps shakes + theme. + sh = shakes() + pg.reload(wait_until='networkidle'); pg.wait_for_timeout(600) + results['persist_shakes'] = shakes() == sh + results['persist_theme'] = pg.evaluate( + "document.querySelector('button[data-theme=\"night\"]').classList.contains('active')") + results['persist_drift'] = drift_cm() > 0 + + # Sweep resets drift. + pg.click('#sweep-btn'); pg.wait_for_timeout(400) + results['sweep'] = drift_cm() < 0.15 + + # Preview screenshot: shrink stage so the whole app fits 1200x630. + pg.evaluate("""() => { + document.querySelector('#stage').style.maxWidth = '430px'; + window.dispatchEvent(new Event('resize')); + document.body.style.paddingTop = '0.2rem'; + }""") + pg.wait_for_timeout(1200) + pg.screenshot(path=os.path.join(OUT, 'preview_shot.png')) + # Also a full-size dusk shot for my own visual check. + pg.evaluate("""() => { + document.querySelector('#stage').style.maxWidth = ''; + window.dispatchEvent(new Event('resize')); + document.querySelector('button[data-theme=\"dusk\"]').click(); + }""") + pg.set_viewport_size({'width': 800, 'height': 1000}) + pg.wait_for_timeout(1500) + pg.screenshot(path=os.path.join(OUT, 'check_full.png'), full_page=True) + results['pageerrors'] = errs + results['console_errors'] = [m for m in msgs if m.startswith('error')] + b.close() +httpd.shutdown() +print(json.dumps(results, indent=2)) diff --git a/src/badge.ts b/src/badge.ts new file mode 100644 index 0000000..c81df86 --- /dev/null +++ b/src/badge.ts @@ -0,0 +1,56 @@ +// : the label in the top right corner, "Advent of AI Slop [Day 1] +// Living fishtank". Its first part links to the calendar, the rest to the door of the day this was made for. +// It draws itself in a shadow root, so its styles and the page's never touch. +const site = 'https://advent-of-slop.quesma.com'; + +const css = ` + nav { + position: fixed; + top: 0; + right: 0; + z-index: 2147483647; + display: flex; + flex-wrap: wrap; + gap: 0 0.35em; + max-width: 100vw; + box-sizing: border-box; + padding: 0.35rem 0.7rem; + border-bottom-left-radius: 0.5rem; + background: #b8232f; + font: 700 0.8125rem/1.2 system-ui, sans-serif; + } + a { + color: #f6ecd6; + text-decoration: none; + } + a:hover { + text-decoration: underline; + } +`; + +const link = (href: string, text: string): HTMLAnchorElement => { + const anchor = document.createElement('a'); + anchor.href = href; + anchor.textContent = text; + return anchor; +}; + +class AdventBadge extends HTMLElement { + connectedCallback(): void { + const day = Number(this.getAttribute('day')); + if (!Number.isInteger(day) || day < 1 || day > 24) { + throw new Error(` needs day="1" to day="24", got ${this.getAttribute('day')}`); + } + const name = this.getAttribute('name'); + if (name === null || name.trim() === '') { + throw new Error(' needs name="...", the title of its day, such as name="Living fishtank"'); + } + const style = document.createElement('style'); + style.textContent = css; + const label = document.createElement('nav'); + label.append(link(`${site}/`, 'Advent of AI Slop'), link(`${site}/day/${day}/`, `[Day ${day}] ${name}`)); + this.attachShadow({ mode: 'open' }).append(style, label); + } +} + +customElements.define('advent-badge', AdventBadge); diff --git a/src/main.ts b/src/main.ts new file mode 100644 index 0000000..982a3ea --- /dev/null +++ b/src/main.ts @@ -0,0 +1,374 @@ +import './style.css'; +import { DENSITY_LEVELS, SnowSystem, floorY, type Globe } from './snow'; +import { + buildSkyline, + drawDrift, + drawFar, + drawHouses, + drawPeople, + drawQuay, + drawSky, + type Skyline, + type Theme, +} from './scene'; + +const STORE_KEY = 'aos-day3-copenhagen-globe'; + +interface Saved { + density: number; + theme: Theme; + drift: number[]; + shakes: number; +} + +function loadSaved(): Saved { + const fallback: Saved = { density: 1, theme: 'dusk', drift: [], shakes: 0 }; + try { + const raw = localStorage.getItem(STORE_KEY); + if (!raw) return fallback; + const parsed = JSON.parse(raw) as Partial; + return { + density: typeof parsed.density === 'number' ? parsed.density : fallback.density, + theme: parsed.theme === 'day' || parsed.theme === 'dusk' || parsed.theme === 'night' + ? parsed.theme : fallback.theme, + drift: Array.isArray(parsed.drift) ? parsed.drift : [], + shakes: typeof parsed.shakes === 'number' ? parsed.shakes : 0, + }; + } catch { + return fallback; + } +} + +const app = document.getElementById('app'); +if (!app) throw new Error('missing #app'); + +app.innerHTML = ` +
+

Københavnerkuglen

+

A snow globe of Copenhagen. Grab it and shake it — or just hit the button.

+
+
+ +
+
+ + + +
+
+ + +
+ + + +
+ +
+

Tip: click the drift for a puff, or press space to shake.

+`; + +const canvas = document.getElementById('globe') as HTMLCanvasElement; +const ctx = canvas.getContext('2d'); +if (!ctx) throw new Error('no 2d context'); +const statDrift = document.getElementById('stat-drift')!; +const statFlakes = document.getElementById('stat-flakes')!; +const statShakes = document.getElementById('stat-shakes')!; +const shakeBtn = document.getElementById('shake-btn') as HTMLButtonElement; +const sweepBtn = document.getElementById('sweep-btn') as HTMLButtonElement; +const densityInput = document.getElementById('density') as HTMLInputElement; +const themeButtons = Array.from( + document.querySelectorAll('#controls .themes button'), +); + +const saved = loadSaved(); +let theme: Theme = saved.theme; +let shakes = saved.shakes; +const skyline: Skyline = buildSkyline(); +const snow = new SnowSystem({ cx: 0, cy: 0, r: 1 }); +snow.target = DENSITY_LEVELS[saved.density] ?? DENSITY_LEVELS[1]; +densityInput.value = String(saved.density); + +let globe: Globe = { cx: 0, cy: 0, r: 1 }; +let dpr = 1; + +function layout(): void { + const stage = document.getElementById('stage')!; + const size = Math.min(stage.clientWidth, 620); + dpr = window.devicePixelRatio || 1; + canvas.width = Math.round(size * dpr); + canvas.height = Math.round(size * 1.12 * dpr); + canvas.style.width = `${size}px`; + canvas.style.height = `${size * 1.12}px`; + globe = { cx: (size * dpr) / 2, cy: (size * dpr * 1.12) / 2 - size * dpr * 0.02, r: size * dpr * 0.42 }; + snow.resize(globe); +} +layout(); +if (saved.drift.length > 0) snow.loadDrift(saved.drift); +window.addEventListener('resize', layout); + +// ---- shake mechanics ------------------------------------------------------- +let shakeAmp = 0; // px oscillation amplitude +let shakePhase = 0; +let shakeDir = 1; + +function triggerShake(strength: number): void { + const s = Math.min(1, strength); + shakeAmp = Math.max(shakeAmp, globe.r * 0.055 * s); + snow.shake(s); + shakes += 1; + saveSoon(); +} + +// Pointer shake detection: fast horizontal reversals while dragging. +let dragging = false; +let lastX = 0; +let lastT = 0; +let lastVx = 0; +let reversals: number[] = []; +let movedDuringDrag = false; + +canvas.addEventListener('pointerdown', (e) => { + dragging = true; + movedDuringDrag = false; + lastX = e.clientX; + lastT = performance.now(); + lastVx = 0; + reversals = []; + canvas.setPointerCapture(e.pointerId); +}); +canvas.addEventListener('pointermove', (e) => { + if (!dragging) return; + const now = performance.now(); + const dt = Math.max(1, now - lastT) / 1000; + const vx = (e.clientX - lastX) / dt; + if (Math.abs(e.clientX - lastX) > 2) movedDuringDrag = true; + if (Math.abs(vx) > globe.r * 1.2 && Math.sign(vx) !== Math.sign(lastVx) && lastVx !== 0) { + reversals.push(now); + reversals = reversals.filter((t) => now - t < 700); + if (reversals.length >= 2) { + const strength = Math.min(1, Math.abs(vx) / (globe.r * 6)); + triggerShake(0.45 + 0.55 * strength); + reversals = []; + } + } + if (Math.abs(vx) > 20) lastVx = vx; + lastX = e.clientX; + lastT = now; +}); +canvas.addEventListener('pointerup', (e) => { + dragging = false; + if (!movedDuringDrag) { + // Click: puff at the pointer if inside the dome. + const rect = canvas.getBoundingClientRect(); + const x = (e.clientX - rect.left) * dpr; + const y = (e.clientY - rect.top) * dpr; + if (Math.hypot(x - globe.cx, y - globe.cy) < globe.r * 0.95) snow.puff(x, y); + } +}); + +shakeBtn.addEventListener('click', () => triggerShake(0.9)); +window.addEventListener('keydown', (e) => { + if (e.code === 'Space' && !(e.target instanceof HTMLButtonElement)) { + e.preventDefault(); + triggerShake(0.85); + } +}); +sweepBtn.addEventListener('click', () => { + snow.sweep(); + saveSoon(); +}); +densityInput.addEventListener('input', () => { + snow.target = DENSITY_LEVELS[Number(densityInput.value)] ?? DENSITY_LEVELS[1]; + saveSoon(); +}); +for (const btn of themeButtons) { + btn.addEventListener('click', () => { + const t = btn.dataset.theme; + if (t === 'day' || t === 'dusk' || t === 'night') { + theme = t; + markTheme(); + saveSoon(); + } + }); +} +function markTheme(): void { + for (const btn of themeButtons) { + btn.classList.toggle('active', btn.dataset.theme === theme); + } +} +markTheme(); + +let saveTimer = 0; +function saveSoon(): void { + window.clearTimeout(saveTimer); + saveTimer = window.setTimeout(saveNow, 400); +} +function saveNow(): void { + const data: Saved = { + density: Number(densityInput.value), + theme, + drift: snow.serializeDrift(), + shakes, + }; + try { + localStorage.setItem(STORE_KEY, JSON.stringify(data)); + } catch { + // storage full/blocked — the globe keeps working without persistence + } +} +window.addEventListener('beforeunload', saveNow); +window.setInterval(saveNow, 10000); + +// ---- rendering ------------------------------------------------------------- +function drawBase(): void { + const { cx, cy, r } = globe; + const topY = cy + r * 0.78; + const neckW = r * 0.62; + const baseW = r * 0.95; + const baseH = r * 0.34; + // Brass collar. + const brass = ctx!.createLinearGradient(cx - neckW, 0, cx + neckW, 0); + brass.addColorStop(0, '#7a5c2e'); + brass.addColorStop(0.5, '#d9b45f'); + brass.addColorStop(1, '#7a5c2e'); + ctx!.fillStyle = brass; + ctx!.beginPath(); + ctx!.moveTo(cx - neckW, topY); + ctx!.lineTo(cx + neckW, topY); + ctx!.lineTo(cx + neckW * 1.06, topY + r * 0.07); + ctx!.lineTo(cx - neckW * 1.06, topY + r * 0.07); + ctx!.closePath(); + ctx!.fill(); + // Wooden base. + const wood = ctx!.createLinearGradient(cx - baseW, 0, cx + baseW, 0); + wood.addColorStop(0, '#3a2417'); + wood.addColorStop(0.5, '#6b4226'); + wood.addColorStop(1, '#3a2417'); + ctx!.fillStyle = wood; + ctx!.beginPath(); + ctx!.moveTo(cx - neckW * 1.06, topY + r * 0.07); + ctx!.lineTo(cx + neckW * 1.06, topY + r * 0.07); + ctx!.lineTo(cx + baseW, topY + baseH); + ctx!.lineTo(cx - baseW, topY + baseH); + ctx!.closePath(); + ctx!.fill(); + // Name plate. + ctx!.fillStyle = '#caa95c'; + const pw = r * 0.42; + const ph = r * 0.085; + const py = topY + baseH * 0.52; + ctx!.beginPath(); + ctx!.roundRect(cx - pw / 2, py - ph / 2, pw, ph, ph * 0.3); + ctx!.fill(); + ctx!.fillStyle = '#3a2417'; + ctx!.font = `700 ${Math.round(ph * 0.52)}px system-ui, sans-serif`; + ctx!.textAlign = 'center'; + ctx!.textBaseline = 'middle'; + ctx!.fillText('KØBENHAVN', cx, py + ph * 0.04); +} + +function drawGlass(): void { + const { cx, cy, r } = globe; + // Rim ring. + ctx!.lineWidth = Math.max(2, r * 0.014); + ctx!.strokeStyle = 'rgba(210,225,240,0.5)'; + ctx!.beginPath(); + ctx!.arc(cx, cy, r, 0, Math.PI * 2); + ctx!.stroke(); + // Big highlight streak, upper left. + ctx!.save(); + ctx!.beginPath(); + ctx!.arc(cx, cy, r, 0, Math.PI * 2); + ctx!.clip(); + const hl = ctx!.createLinearGradient(cx - r, cy - r, cx - r * 0.2, cy + r * 0.2); + hl.addColorStop(0, 'rgba(255,255,255,0.34)'); + hl.addColorStop(0.5, 'rgba(255,255,255,0.06)'); + hl.addColorStop(1, 'rgba(255,255,255,0)'); + ctx!.fillStyle = hl; + ctx!.fillRect(cx - r, cy - r, r * 2, r * 2); + // Small glare dot. + ctx!.fillStyle = 'rgba(255,255,255,0.5)'; + ctx!.beginPath(); + ctx!.ellipse(cx - r * 0.45, cy - r * 0.55, r * 0.1, r * 0.05, -0.7, 0, Math.PI * 2); + ctx!.fill(); + // Inner vignette. + const vg = ctx!.createRadialGradient(cx, cy, r * 0.75, cx, cy, r); + vg.addColorStop(0, 'rgba(20,30,50,0)'); + vg.addColorStop(1, 'rgba(20,30,50,0.28)'); + ctx!.fillStyle = vg; + ctx!.fillRect(cx - r, cy - r, r * 2, r * 2); + ctx!.restore(); +} + +let last = performance.now(); +let elapsed = 0; + +function frame(now: number): void { + const dt = Math.min(0.033, (now - last) / 1000); + last = now; + elapsed += dt; + + // Damped oscillation of the whole globe while shaking. + let ox = 0; + let oy = 0; + if (shakeAmp > 0.5) { + shakePhase += dt * 34; + shakeAmp *= Math.exp(-dt * 3.2); + ox = Math.sin(shakePhase) * shakeAmp; + oy = Math.sin(shakePhase * 0.8 + 1.2) * shakeAmp * 0.35; + } else { + shakeAmp = 0; + } + + // Pedestrians stroll. + for (const p of skyline.people) { + p.x += p.speed * p.dir * dt; + if (p.x > 0.99) p.dir = -1; + if (p.x < 0.01) p.dir = 1; + } + + snow.update(dt); + + const w = canvas.width; + const h = canvas.height; + ctx!.clearRect(0, 0, w, h); + ctx!.save(); + ctx!.translate(ox, oy); + + // Scene inside the dome. + ctx!.save(); + ctx!.beginPath(); + ctx!.arc(globe.cx, globe.cy, globe.r, 0, Math.PI * 2); + ctx!.clip(); + drawSky(ctx!, globe, theme, elapsed); + drawFar(ctx!, globe, theme); + drawQuay(ctx!, globe, theme); + drawHouses(ctx!, globe, theme, skyline, (x) => snow.driftAt(x)); + drawPeople(ctx!, globe, skyline, (x) => snow.driftAt(x), elapsed); + drawDrift(ctx!, globe, theme, (x) => snow.driftAt(x)); + // Flakes. + ctx!.fillStyle = theme === 'night' ? '#e8f0fb' : '#ffffff'; + for (const f of snow.flakes) { + ctx!.globalAlpha = f.alpha; + ctx!.beginPath(); + ctx!.arc(f.x, f.y, f.r, 0, Math.PI * 2); + ctx!.fill(); + } + ctx!.globalAlpha = 1; + ctx!.restore(); + + drawGlass(); + drawBase(); + ctx!.restore(); + + // HUD. + statDrift.textContent = `drift: ${snow.driftDepthCm().toFixed(1)} cm`; + statFlakes.textContent = `flakes: ${snow.flakes.length}`; + statShakes.textContent = `shakes: ${shakes}${shakes >= 100 ? ' 💪' : ''}`; + + requestAnimationFrame(frame); +} +requestAnimationFrame(frame); diff --git a/src/scene.ts b/src/scene.ts new file mode 100644 index 0000000..f8923fe --- /dev/null +++ b/src/scene.ts @@ -0,0 +1,442 @@ +// Procedural Copenhagen inside the globe: Nyhavn houses, spiral spire, +// Round Tower, lamps, pedestrians — all drawn from a fixed seed. +import type { Globe } from './snow'; +import { floorY } from './snow'; + +export type Theme = 'day' | 'dusk' | 'night'; + +export interface Skyline { + houses: House[]; + lamps: number[]; // x positions + people: Person[]; +} + +interface House { + x: number; // center, fraction of chord (0..1) + w: number; // fraction of chord + h: number; // fraction of r + color: string; + gable: 'tri' | 'step' | 'flat'; + cols: number; + rows: number; + lit: boolean[]; + crane: boolean; +} + +export interface Person { + x: number; // fraction of chord + speed: number; // fraction/s + dir: 1 | -1; + h: number; // fraction of r + coat: string; +} + +function mulberry32(seed: number): () => number { + let a = seed >>> 0; + return () => { + a |= 0; + a = (a + 0x6d2b79f5) | 0; + let t = Math.imul(a ^ (a >>> 15), 1 | a); + t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t; + return ((t ^ (t >>> 14)) >>> 0) / 4294967296; + }; +} + +const HOUSE_COLORS = [ + '#c8503f', '#d9a441', '#4a7fa5', '#7a9b64', '#b5651d', + '#a63d5a', '#c9b458', '#3f6d8e', '#d07a4a', '#8a5a83', + '#c05a4a', '#5d8a68', '#caa06a', '#456b93', +]; + +export function buildSkyline(seed = 1864): Skyline { + const rnd = mulberry32(seed); + const houses: House[] = []; + let x = 0.015; + while (x < 0.985) { + const w = 0.055 + rnd() * 0.045; + if (x + w > 0.99) break; + const gableRoll = rnd(); + const cols = 2 + Math.floor(rnd() * 2); + const rows = 2 + Math.floor(rnd() * 3); + const lit: boolean[] = []; + for (let i = 0; i < cols * rows; i++) lit.push(rnd() < 0.62); + houses.push({ + x: x + w / 2, + w, + h: 0.24 + rnd() * 0.16, + color: HOUSE_COLORS[Math.floor(rnd() * HOUSE_COLORS.length)] ?? '#c8503f', + gable: gableRoll < 0.45 ? 'tri' : gableRoll < 0.85 ? 'step' : 'flat', + cols, + rows, + lit, + crane: rnd() < 0.16, + }); + x += w + 0.004; + } + const lamps = [0.14, 0.38, 0.62, 0.86]; + const people: Person[] = []; + const coats = ['#2b3a55', '#5a2b2b', '#2f4a3a', '#4a3a5a', '#1f2937', '#6b4a2f']; + for (let i = 0; i < 7; i++) { + people.push({ + x: rnd(), + speed: 0.012 + rnd() * 0.02, + dir: rnd() < 0.5 ? 1 : -1, + h: 0.05 + rnd() * 0.018, + coat: coats[Math.floor(rnd() * coats.length)] ?? '#2b3a55', + }); + } + return { houses, lamps, people }; +} + +interface ThemePalette { + skyTop: string; + skyBottom: string; + far: string; + water: string; + quay: string; + snow: string; + snowShade: string; + lit: boolean; + stars: boolean; + glow: string; +} + +const PALETTES: Record = { + day: { + skyTop: '#8fb4d4', skyBottom: '#dcebf4', far: '#93a9bd', water: '#3c5f7a', + quay: '#cfd9e2', snow: '#ffffff', snowShade: '#dfe7f0', lit: false, stars: false, + glow: 'rgba(255,220,140,0)', + }, + dusk: { + skyTop: '#3d3a68', skyBottom: '#e8935a', far: '#5b5378', water: '#3a3a63', + quay: '#b9a9b8', snow: '#f4e9ec', snowShade: '#d8c4cf', lit: true, stars: false, + glow: 'rgba(255,190,110,0.55)', + }, + night: { + skyTop: '#0a142e', skyBottom: '#20375e', far: '#2c4060', water: '#12203c', + quay: '#5f7392', snow: '#dbe6f5', snowShade: '#b9c9e0', lit: true, stars: true, + glow: 'rgba(255,205,130,0.7)', + }, +}; + +export function drawSky( + ctx: CanvasRenderingContext2D, + g: Globe, + theme: Theme, + t: number, +): void { + const p = PALETTES[theme]; + const grad = ctx.createLinearGradient(0, g.cy - g.r, 0, g.cy + g.r); + grad.addColorStop(0, p.skyTop); + grad.addColorStop(1, p.skyBottom); + ctx.fillStyle = grad; + ctx.fillRect(g.cx - g.r, g.cy - g.r, g.r * 2, g.r * 2); + + if (p.stars) { + const rnd = mulberry32(7); + ctx.fillStyle = 'rgba(255,255,255,0.9)'; + for (let i = 0; i < 40; i++) { + const sx = g.cx + (rnd() * 2 - 1) * g.r * 0.9; + const sy = g.cy - g.r + rnd() * g.r * 0.9; + const tw = 0.5 + 0.5 * Math.sin(t * 2 + i); + ctx.globalAlpha = 0.25 + 0.55 * tw; + ctx.fillRect(sx, sy, 1.6, 1.6); + } + ctx.globalAlpha = 1; + // Moon. + const mx = g.cx + g.r * 0.45; + const my = g.cy - g.r * 0.62; + const mg = ctx.createRadialGradient(mx, my, 0, mx, my, g.r * 0.16); + mg.addColorStop(0, 'rgba(240,240,220,0.95)'); + mg.addColorStop(0.35, 'rgba(240,240,220,0.85)'); + mg.addColorStop(1, 'rgba(240,240,220,0)'); + ctx.fillStyle = mg; + ctx.beginPath(); + ctx.arc(mx, my, g.r * 0.16, 0, Math.PI * 2); + ctx.fill(); + } +} + +/** Far spires behind the houses: Our Saviour + Round Tower + a Tivoli tower. */ +export function drawFar(ctx: CanvasRenderingContext2D, g: Globe, theme: Theme): void { + const p = PALETTES[theme]; + const fy = floorY(g); + ctx.fillStyle = p.far; + + // Church of Our Saviour — tapering tower with a spiral-crowned spire. + const ox = g.cx - g.r * 0.52; + const tw = g.r * 0.075; + const th = g.r * 0.34; + ctx.fillRect(ox - tw / 2, fy - th, tw, th); + const spireH = g.r * 0.3; + ctx.beginPath(); + ctx.moveTo(ox - tw / 2, fy - th); + ctx.lineTo(ox, fy - th - spireH); + ctx.lineTo(ox + tw / 2, fy - th); + ctx.closePath(); + ctx.fill(); + // Spiral hint: a light helical line winding up the spire. + ctx.strokeStyle = 'rgba(255,255,255,0.35)'; + ctx.lineWidth = Math.max(1, g.r * 0.006); + ctx.beginPath(); + const turns = 6; + for (let i = 0; i <= 60; i++) { + const u = i / 60; + const yy = fy - th - spireH * u; + const half = (tw / 2) * (1 - u) + g.r * 0.004; + const xx = ox + Math.sin(u * turns * Math.PI * 2) * half; + if (i === 0) ctx.moveTo(xx, yy); + else ctx.lineTo(xx, yy); + } + ctx.stroke(); + // Golden globe on top. + ctx.fillStyle = p.lit ? '#e8c060' : '#c9b98a'; + ctx.beginPath(); + ctx.arc(ox, fy - th - spireH - g.r * 0.018, g.r * 0.016, 0, Math.PI * 2); + ctx.fill(); + + // Round Tower — stubby drum with a narrower tower on top. + const rx = g.cx + g.r * 0.5; + const rw = g.r * 0.16; + const rh = g.r * 0.2; + ctx.fillStyle = p.far; + ctx.fillRect(rx - rw / 2, fy - rh, rw, rh); + ctx.fillRect(rx - rw * 0.22, fy - rh - g.r * 0.12, rw * 0.44, g.r * 0.12); + + // Tivoli-ish pointed tower, left mid-field. + const tx = g.cx + g.r * 0.12; + const tth = g.r * 0.26; + ctx.fillRect(tx - g.r * 0.03, fy - tth, g.r * 0.06, tth); + ctx.beginPath(); + ctx.moveTo(tx - g.r * 0.045, fy - tth); + ctx.lineTo(tx, fy - tth - g.r * 0.11); + ctx.lineTo(tx + g.r * 0.045, fy - tth); + ctx.closePath(); + ctx.fill(); +} + +export function drawHouses( + ctx: CanvasRenderingContext2D, + g: Globe, + theme: Theme, + sky: Skyline, + driftAt: (x: number) => number, +): void { + const p = PALETTES[theme]; + const fy = floorY(g); + const half = Math.sqrt(Math.max(0, g.r * g.r - (fy - g.cy) * (fy - g.cy))); + const left = g.cx - half; + const chord = half * 2; + const snowLine = Math.max(1.5, g.r * 0.012); + + for (const h of sky.houses) { + const hx = left + h.x * chord; + const hw = (h.w * chord) / 2; + const hh = h.h * g.r; + const top = fy - hh; + + ctx.fillStyle = h.color; + ctx.fillRect(hx - hw, top, hw * 2, hh); + + // Gable. + ctx.beginPath(); + if (h.gable === 'tri') { + ctx.moveTo(hx - hw, top); + ctx.lineTo(hx, top - hw * 0.75); + ctx.lineTo(hx + hw, top); + } else if (h.gable === 'step') { + const steps = 3; + const sw = (hw * 2) / (steps * 2 + 1); + const sh = hw * 0.7 / steps; + ctx.moveTo(hx - hw, top); + let cx = hx - hw; + let cy = top; + for (let s = 0; s < steps; s++) { + ctx.lineTo(cx + sw, cy); + ctx.lineTo(cx + sw, cy - sh); + cx += sw; + cy -= sh; + } + ctx.lineTo(cx + sw, cy); + cx += sw; + for (let s = 0; s < steps; s++) { + ctx.lineTo(cx + sw, cy); + ctx.lineTo(cx + sw, cy + sh); + cx += sw; + cy += sh; + } + ctx.lineTo(hx + hw, top); + } else { + ctx.rect(hx - hw, top - hw * 0.18, hw * 2, hw * 0.18); + } + ctx.closePath(); + ctx.fill(); + + // Snow cap along the roofline. + ctx.strokeStyle = p.snow; + ctx.lineWidth = snowLine; + ctx.lineJoin = 'round'; + ctx.beginPath(); + if (h.gable === 'tri') { + ctx.moveTo(hx - hw, top); + ctx.lineTo(hx, top - hw * 0.75); + ctx.lineTo(hx + hw, top); + } else { + ctx.moveTo(hx - hw, top); + ctx.lineTo(hx + hw, top); + } + ctx.stroke(); + + // Crane on some roofs (Nyhavn trademark). + if (h.crane) { + ctx.strokeStyle = '#3a3128'; + ctx.lineWidth = Math.max(1, g.r * 0.006); + ctx.beginPath(); + ctx.moveTo(hx + hw * 0.5, top - hw * 0.3); + ctx.lineTo(hx + hw * 0.5, top - hw * 1.3); + ctx.lineTo(hx - hw * 0.35, top - hw * 1.05); + ctx.moveTo(hx + hw * 0.5, top - hw * 1.3); + ctx.lineTo(hx + hw * 0.95, top - hw * 1.05); + ctx.stroke(); + } + + // Windows. + const ww = (hw * 2) / (h.cols * 1.9); + const wh = (hh * 0.72) / (h.rows * 1.55); + for (let c = 0; c < h.cols; c++) { + for (let r = 0; r < h.rows; r++) { + const wx = hx - hw + (hw * 2) * ((c + 0.5) / h.cols) - ww / 2; + const wy = top + hh * 0.12 + (hh * 0.78) * (r / h.rows); + const isLit = p.lit && (h.lit[c * h.rows + r] ?? false); + if (isLit) { + ctx.fillStyle = '#ffd98a'; + ctx.fillRect(wx, wy, ww, wh); + ctx.fillStyle = p.glow; + ctx.fillRect(wx - ww * 0.4, wy - wh * 0.4, ww * 1.8, wh * 1.8); + } else { + ctx.fillStyle = theme === 'night' ? '#1c2c48' : 'rgba(30,40,55,0.55)'; + ctx.fillRect(wx, wy, ww, wh); + } + ctx.fillStyle = p.snow; + ctx.fillRect(wx, wy, ww, Math.max(1, g.r * 0.004)); + } + } + } + + // Street lamps (in front of houses, standing on the drift). + for (const lx of sky.lamps) { + const x = left + lx * chord; + const base = fy - driftAt(x); + const ph = g.r * 0.16; + ctx.strokeStyle = '#22303f'; + ctx.lineWidth = Math.max(1.2, g.r * 0.008); + ctx.beginPath(); + ctx.moveTo(x, base); + ctx.lineTo(x, base - ph); + ctx.stroke(); + const lampR = g.r * 0.016; + if (p.lit) { + const lg = ctx.createRadialGradient(x, base - ph, 0, x, base - ph, lampR * 6); + lg.addColorStop(0, 'rgba(255,215,140,0.85)'); + lg.addColorStop(1, 'rgba(255,215,140,0)'); + ctx.fillStyle = lg; + ctx.beginPath(); + ctx.arc(x, base - ph, lampR * 6, 0, Math.PI * 2); + ctx.fill(); + ctx.fillStyle = '#ffe6ad'; + } else { + ctx.fillStyle = '#5a6a7a'; + } + ctx.beginPath(); + ctx.arc(x, base - ph - lampR, lampR, 0, Math.PI * 2); + ctx.fill(); + // Snow dab on the lamp head. + ctx.fillStyle = p.snow; + ctx.beginPath(); + ctx.ellipse(x, base - ph - lampR * 2.1, lampR * 1.3, lampR * 0.5, 0, 0, Math.PI * 2); + ctx.fill(); + } +} + +export function drawPeople( + ctx: CanvasRenderingContext2D, + g: Globe, + sky: Skyline, + driftAt: (x: number) => number, + t: number, +): void { + const fy = floorY(g); + const half = Math.sqrt(Math.max(0, g.r * g.r - (fy - g.cy) * (fy - g.cy))); + const left = g.cx - half; + const chord = half * 2; + for (const per of sky.people) { + const x = left + per.x * chord; + const base = fy - driftAt(x); + const hh = per.h * g.r; + const stride = Math.sin(t * 6 * (per.speed / 0.02)) * hh * 0.22; + ctx.strokeStyle = per.coat; + ctx.fillStyle = per.coat; + ctx.lineWidth = Math.max(1.4, hh * 0.16); + ctx.lineCap = 'round'; + // Body. + ctx.beginPath(); + ctx.moveTo(x, base - hh * 0.75); + ctx.lineTo(x, base - hh * 0.3); + ctx.stroke(); + // Head with a beanie. + ctx.beginPath(); + ctx.arc(x, base - hh * 0.88, hh * 0.14, 0, Math.PI * 2); + ctx.fill(); + // Legs. + ctx.beginPath(); + ctx.moveTo(x, base - hh * 0.3); + ctx.lineTo(x + stride, base); + ctx.moveTo(x, base - hh * 0.3); + ctx.lineTo(x - stride, base); + ctx.stroke(); + } +} + +/** The accumulated snowdrift mound. */ +export function drawDrift( + ctx: CanvasRenderingContext2D, + g: Globe, + theme: Theme, + driftAt: (x: number) => number, +): void { + const p = PALETTES[theme]; + const fy = floorY(g); + const half = Math.sqrt(Math.max(0, g.r * g.r - (fy - g.cy) * (fy - g.cy))); + const left = g.cx - half; + const chord = half * 2; + const n = 96; + ctx.fillStyle = p.snow; + ctx.beginPath(); + ctx.moveTo(left, fy); + for (let i = 0; i <= n; i++) { + const x = left + (chord * i) / n; + ctx.lineTo(x, fy - driftAt(x)); + } + ctx.lineTo(left + chord, fy); + ctx.closePath(); + ctx.fill(); + // Highlight line along the surface. + ctx.strokeStyle = 'rgba(255,255,255,0.8)'; + ctx.lineWidth = Math.max(1, g.r * 0.005); + ctx.beginPath(); + for (let i = 0; i <= n; i++) { + const x = left + (chord * i) / n; + const y = fy - driftAt(x); + if (i === 0) ctx.moveTo(x, y); + else ctx.lineTo(x, y); + } + ctx.stroke(); +} + +/** Quay floor strip below the drift, down to the base. */ +export function drawQuay(ctx: CanvasRenderingContext2D, g: Globe, theme: Theme): void { + const p = PALETTES[theme]; + const fy = floorY(g); + ctx.fillStyle = p.quay; + ctx.fillRect(g.cx - g.r, fy, g.r * 2, g.r); +} diff --git a/src/snow.ts b/src/snow.ts new file mode 100644 index 0000000..3bf5e26 --- /dev/null +++ b/src/snow.ts @@ -0,0 +1,207 @@ +// Snow particle system + drifting snowpack inside the globe. + +export interface Globe { + cx: number; + cy: number; + r: number; +} + +export interface Flake { + x: number; + y: number; + vx: number; + vy: number; + r: number; + phase: number; + alpha: number; +} + +export const DENSITY_LEVELS = [150, 350, 600, 900, 1300] as const; + +const COLS = 72; + +export function floorY(g: Globe): number { + return g.cy + 0.62 * g.r; +} + +function chordHalfWidth(g: Globe): number { + const dy = floorY(g) - g.cy; + return Math.sqrt(Math.max(0, g.r * g.r - dy * dy)); +} + +export class SnowSystem { + flakes: Flake[] = []; + drift: Float32Array = new Float32Array(COLS); + target: number = DENSITY_LEVELS[1]; + private g: Globe; + + constructor(g: Globe) { + this.g = g; + } + + resize(g: Globe): void { + this.g = g; + } + + maxDrift(): number { + return 0.3 * this.g.r; + } + + driftAt(x: number): number { + const g = this.g; + const half = chordHalfWidth(g); + const t = (x - (g.cx - half)) / (2 * half); + if (t < 0 || t > 1) return 0; + const i = Math.min(COLS - 1, Math.floor(t * COLS)); + return this.drift[i] ?? 0; + } + + /** Total drift in "cm" for the HUD (dome radius counts as 30 cm). */ + driftDepthCm(): number { + let sum = 0; + for (const h of this.drift) sum += h; + return (sum / COLS / this.g.r) * 30; + } + + serializeDrift(): number[] { + return Array.from(this.drift, (h) => Math.round(h * 100) / 100); + } + + loadDrift(values: number[]): void { + if (values.length !== COLS) return; + const cap = this.maxDrift(); + for (let i = 0; i < COLS; i++) { + this.drift[i] = Math.min(cap, Math.max(0, values[i] ?? 0)); + } + } + + sweep(): void { + this.drift.fill(0); + } + + private spawn(low: boolean): void { + const g = this.g; + const a = Math.random() * Math.PI * 2; + const rad = Math.sqrt(Math.random()) * (g.r * 0.92); + const y = low + ? g.cy + Math.random() * g.r * 0.5 + : g.cy - g.r + Math.random() * g.r * 0.6; + this.flakes.push({ + x: g.cx + Math.cos(a) * rad, + y, + vx: (Math.random() - 0.5) * 0.05 * g.r, + vy: Math.random() * 0.05 * g.r, + r: g.r * (0.004 + Math.random() * 0.008), + phase: Math.random() * Math.PI * 2, + alpha: 0.55 + Math.random() * 0.45, + }); + } + + /** Impulse from a shake. strength is 0..1. */ + shake(strength: number): void { + const g = this.g; + const s = strength * g.r; + for (const f of this.flakes) { + f.vx += (Math.random() - 0.5) * 1.4 * s; + f.vy += (Math.random() - 0.9) * 1.2 * s; + } + // Kick some of the drift back into the air. + const lift = 0.05 * strength; + for (let i = 0; i < COLS; i++) { + const h = this.drift[i] ?? 0; + const removed = h * lift; + this.drift[i] = h - removed; + } + } + + /** Click puff: launch a little plume at (x, y). */ + puff(x: number, y: number): void { + const g = this.g; + const n = 26; + for (let i = 0; i < n; i++) { + if (this.flakes.length >= this.target + 60) break; + const a = -Math.PI / 2 + (Math.random() - 0.5) * 1.6; + const sp = g.r * (0.2 + Math.random() * 0.5); + this.flakes.push({ + x, + y, + vx: Math.cos(a) * sp, + vy: Math.sin(a) * sp, + r: g.r * (0.004 + Math.random() * 0.007), + phase: Math.random() * Math.PI * 2, + alpha: 0.7 + Math.random() * 0.3, + }); + } + } + + update(dt: number): void { + const g = this.g; + const gravity = 0.3 * g.r; + const wobbleA = 0.35 * g.r; + const wall = g.r - 3; + const half = chordHalfWidth(g); + const left = g.cx - half; + const cap = this.maxDrift(); + + // Maintain population toward target. + if (this.flakes.length < this.target) { + const add = Math.min(6, this.target - this.flakes.length); + for (let i = 0; i < add; i++) this.spawn(false); + } else if (this.flakes.length > this.target + 80) { + this.flakes.splice(0, this.flakes.length - this.target); + } + + const keep: Flake[] = []; + for (const f of this.flakes) { + f.vy += gravity * dt; + f.phase += 2.2 * dt; + f.vx += Math.sin(f.phase) * wobbleA * dt; + const drag = Math.max(0, 1 - 1.4 * dt); + f.vx *= drag; + f.vy *= drag; + f.x += f.vx * dt; + f.y += f.vy * dt; + + // Dome wall collision. + const dx = f.x - g.cx; + const dy = f.y - g.cy; + const d = Math.hypot(dx, dy); + if (d > wall - f.r) { + const nx = dx / d; + const ny = dy / d; + f.x = g.cx + nx * (wall - f.r); + f.y = g.cy + ny * (wall - f.r); + const vn = f.vx * nx + f.vy * ny; + if (vn > 0) { + f.vx -= 1.35 * vn * nx; + f.vy -= 1.35 * vn * ny; + } + } + + // Settle on the drift / floor. + const t = (f.x - left) / (2 * half); + if (t >= 0 && t <= 1) { + const i = Math.min(COLS - 1, Math.floor(t * COLS)); + const surface = floorY(g) - (this.drift[i] ?? 0); + if (f.y >= surface - f.r * 0.5) { + const h = this.drift[i] ?? 0; + this.drift[i] = Math.min(cap, h + f.r * 0.32); + // Neighbours slump a little so the drift stays mound-shaped. + const l = this.drift[Math.max(0, i - 1)] ?? 0; + const rr = this.drift[Math.min(COLS - 1, i + 1)] ?? 0; + const avg = (l + rr) / 2; + if (h - avg > this.g.r * 0.012) { + this.drift[i] = h - (h - avg) * 0.25; + if (i > 0) this.drift[i - 1] = l + (h - avg) * 0.125; + if (i < COLS - 1) this.drift[i + 1] = rr + (h - avg) * 0.125; + } + continue; // flake consumed + } + } else if (f.y > floorY(g)) { + continue; // outside the quay, silently gone + } + keep.push(f); + } + this.flakes = keep; + } +} diff --git a/src/style.css b/src/style.css new file mode 100644 index 0000000..d597e39 --- /dev/null +++ b/src/style.css @@ -0,0 +1,144 @@ +:root { + --bg: #0d1626; + --panel: #16233a; + --ink: #e8eef7; + --muted: #93a6c0; + --accent: #d9b45f; +} + +* { + box-sizing: border-box; +} + +body { + margin: 0; + min-height: 100vh; + background: + radial-gradient(1200px 700px at 50% -10%, #1b2c49 0%, var(--bg) 60%), + var(--bg); + color: var(--ink); + font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; + display: flex; + justify-content: center; + padding: 1.2rem 1rem 3rem; +} + +#app { + width: min(680px, 100%); + text-align: center; +} + +header h1 { + margin: 0.4rem 0 0.1rem; + font-size: clamp(1.7rem, 5vw, 2.5rem); + letter-spacing: 0.02em; +} + +header .sub { + margin: 0 0 0.8rem; + color: var(--muted); +} + +#stage { + display: flex; + justify-content: center; +} + +canvas { + display: block; + cursor: grab; + touch-action: none; + max-width: 100%; +} + +canvas:active { + cursor: grabbing; +} + +#hud { + display: flex; + justify-content: center; + gap: 1.2rem; + flex-wrap: wrap; + margin: 0.2rem 0 0.7rem; +} + +.stat { + font-size: 0.85rem; + color: var(--muted); + font-variant-numeric: tabular-nums; +} + +#controls { + display: flex; + justify-content: center; + align-items: center; + gap: 0.8rem; + flex-wrap: wrap; + background: var(--panel); + border: 1px solid #24344f; + border-radius: 14px; + padding: 0.7rem 1rem; + width: fit-content; + margin: 0 auto; +} + +#controls button { + font: 600 0.9rem system-ui, sans-serif; + color: var(--ink); + background: #223554; + border: 1px solid #33507e; + border-radius: 10px; + padding: 0.45rem 0.9rem; + cursor: pointer; +} + +#controls button:hover { + background: #2c4468; +} + +#shake-btn { + background: #b8232f !important; + border-color: #d4404c !important; +} + +#shake-btn:hover { + background: #cf2e3b !important; +} + +.ctl { + display: flex; + align-items: center; + gap: 0.5rem; + font-size: 0.85rem; + color: var(--muted); +} + +input[type="range"] { + accent-color: var(--accent); + width: 110px; +} + +.themes { + gap: 0.35rem; +} + +.themes button.active { + background: var(--accent); + border-color: var(--accent); + color: #241a08; +} + +.hint { + color: var(--muted); + font-size: 0.8rem; + margin-top: 0.8rem; +} + +kbd { + background: #223554; + border: 1px solid #33507e; + border-radius: 4px; + padding: 0.05rem 0.35rem; + font-size: 0.75rem; +} diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..8b42ef2 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,15 @@ +{ + "compilerOptions": { + "target": "ES2023", + "module": "ESNext", + "moduleResolution": "bundler", + "lib": ["ES2023", "DOM", "DOM.Iterable"], + "types": ["vite/client"], + "strict": true, + "noUncheckedIndexedAccess": true, + "verbatimModuleSyntax": true, + "skipLibCheck": true, + "noEmit": true + }, + "include": ["src"] +} diff --git a/vite.config.ts b/vite.config.ts new file mode 100644 index 0000000..08e54d3 --- /dev/null +++ b/vite.config.ts @@ -0,0 +1,6 @@ +import { defineConfig } from 'vite'; + +export default defineConfig({ + // Relative links, so the build works under https://.github.io// whatever the repository is called. + base: './', +});