Living fishtank: draw fish, release them, feed them (Advent of AI Slop day 1)

This commit is contained in:
lullu committed 2026-12-01 20:59:14 +00:00
commit ecd1e99139
14 files changed
+1445

No files matched your search

+3
View File
@@ -0,0 +1,3 @@
# The address of the published site, for the og: tags. No secrets here: this file is committed.
# The publish workflow sets the real one; this is for `pnpm dev`.
VITE_SITE_URL=http://localhost:5173
+3
View File
@@ -0,0 +1,3 @@
node_modules/
dist/
.DS_Store
+1
View File
@@ -0,0 +1 @@
26.12.1
+51
View File
@@ -0,0 +1,51 @@
# 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-<day>-<title>`, for example `advent-of-slop-01-living-fishtank`.
## What is here
- `index.html` and `src/main.ts`: the page.
- `src/badge.ts`: the "Advent of AI Slop" link in the top right corner.
- `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">` with the day this is for, 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.
+34
View File
@@ -0,0 +1,34 @@
# Living fishtank — Advent of AI Slop, day 1
> Draw a fish, release it into the tank, and watch it swim. Click the water to drop food and the fish will chase it.
Made for [day 1 of Advent of AI Slop](https://advent-of-slop.quesma.com/day/1/):
*"Create an animated fishtank, to which you can add fishes from your drawings."*
## What it does
- **Fish studio** (right panel): draw with a brush (8 colors, size slider, eraser, undo, clear),
then press **Release into the tank**. The drawing is trimmed to its bounding box, auto-oriented
so the tapered end (the head) faces the swimming direction, and given a random size and depth.
- **🎲 Random fish** generates a procedural fish so the tank is never empty.
- The fish swim with a strip-based tail wiggle, wander on their own, chase food, and turn at the glass.
- **Click anywhere in the water** (or the *Feed the fish* button) to drop pellets; fish home in and eat them.
- Ambient bubbles, swaying plants, caustic light, sandy bottom with pebbles.
- Your fish are stored in `localStorage` and come back on the next visit.
Everything runs in the browser; no server, no keys.
## Commands
```sh
pnpm install
pnpm dev # http://localhost:5173/
pnpm build # typecheck + build to dist/
```
## Notes
- Built on the official [advent-of-slop template](https://github.com/QuesmaOrg/advent-of-slop-template)
(Vite + TypeScript), published to Gitea instead of GitHub — `dist/` is a plain static site,
serve it from any static host. Paths are relative (`base: './'`).
- `pnpm build` must pass before a push (per AGENTS.md).
+23
View File
@@ -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="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><text y='.9em' font-size='90'>🐠</text></svg>" />
<title>Living fishtank | Advent of AI Slop day 1</title>
<meta name="description" content="An animated fishtank you can stock with your own drawings. Made for day 1 of Advent of AI Slop, December 2026." />
<meta property="og:type" content="website" />
<meta property="og:title" content="Living fishtank | Advent of AI Slop day 1" />
<meta property="og:description" content="Draw a fish, release it into the tank, and watch it swim. Click the water to feed them." />
<meta property="og:url" content="%VITE_SITE_URL%/" />
<meta property="og:image" content="%VITE_SITE_URL%/preview.png" />
<meta name="twitter:card" content="summary_large_image" />
<script type="module" src="./src/badge.ts"></script>
<script type="module" src="./src/main.ts"></script>
</head>
<body>
<!-- day: the day of December this was made for, 1 to 24. -->
<advent-badge day="1"></advent-badge>
<main id="app"></main>
</body>
</html>
+15
View File
@@ -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"
}
}
+717
View File
@@ -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
+5
View File
@@ -0,0 +1,5 @@
# Only install package versions published at least 7 days ago (in minutes).
minimumReleaseAge: 10080
allowBuilds:
esbuild: true
Binary file not shown.

After

Width:  |  Height:  |  Size: 198 KiB

+39
View File
@@ -0,0 +1,39 @@
// <advent-badge day="1">: the link in the top right corner, back 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 = `
a {
position: fixed;
top: 0;
right: 0;
z-index: 2147483647;
padding: 0.35rem 0.7rem;
border-bottom-left-radius: 0.5rem;
background: #b8232f;
color: #f6ecd6;
font: 700 0.8125rem/1.2 system-ui, sans-serif;
text-decoration: none;
}
a:hover {
background: #0f3b2d;
}
`;
class AdventBadge extends HTMLElement {
connectedCallback(): void {
const day = Number(this.getAttribute('day'));
if (!Number.isInteger(day) || day < 1 || day > 24) {
throw new Error(`<advent-badge> needs day="1" to day="24", got ${this.getAttribute('day')}`);
}
const style = document.createElement('style');
style.textContent = css;
const link = document.createElement('a');
link.href = `${site}/day/${day}/`;
link.textContent = 'Advent of AI Slop';
link.title = `Made for day ${day} of Advent of AI Slop`;
this.attachShadow({ mode: 'open' }).append(style, link);
}
}
customElements.define('advent-badge', AdventBadge);
+533
View File
@@ -0,0 +1,533 @@
// Living fishtank — Advent of AI Slop, day 1.
// Draw a fish in the studio, release it, and it swims. Click the water to feed them.
const app = document.querySelector<HTMLElement>('#app');
if (app === null) throw new Error('Missing #app in index.html');
app.innerHTML = `
<div class="tank-wrap">
<canvas id="tank"></canvas>
<div class="hud">
<span id="count">0 fish</span>
<button id="feed" type="button">Feed the fish</button>
</div>
<p id="hint" class="hint" hidden>Draw a fish on the right, then press <b>Release into the tank</b> — or click the water to drop food.</p>
</div>
<aside id="panel" class="panel open">
<button id="toggle" class="toggle" type="button" title="Show or hide the studio">🎨 Fish studio</button>
<div class="panel-body">
<canvas id="studio" width="320" height="220"></canvas>
<div class="row swatches" id="swatches"></div>
<div class="row tools">
<label class="size">Brush <input id="brush" type="range" min="3" max="40" value="14"></label>
<button id="eraser" type="button" title="Erase">⌫</button>
<button id="undo" type="button" title="Undo">↩︎</button>
<button id="clear" type="button" title="Clear">🗑</button>
</div>
<div class="row actions">
<button id="release" class="primary" type="button">Release into the tank</button>
<button id="random" type="button" title="Generate a random fish">🎲 Random fish</button>
</div>
</div>
</aside>
`;
const style = document.createElement('style');
style.textContent = `
:root { color-scheme: dark; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #06222e;
font: 15px/1.4 system-ui, sans-serif; color: #e8f4f2; }
#app { height: 100%; position: relative; }
.tank-wrap { position: absolute; inset: 0; }
#tank { width: 100%; height: 100%; display: block; cursor: crosshair; }
.hud { position: absolute; left: 14px; bottom: 12px; display: flex; gap: 10px; align-items: center; }
.hud span { font-size: .85rem; opacity: .75; }
.hint { position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%);
margin: 0; padding: .5rem .9rem; border-radius: .6rem; background: rgba(4,20,28,.72);
backdrop-filter: blur(6px); font-size: .9rem; }
button { font: inherit; border: 1px solid rgba(255,255,255,.18); border-radius: .55rem;
background: rgba(9,42,56,.8); color: #e8f4f2; padding: .35rem .8rem; cursor: pointer; }
button:hover { background: rgba(16,64,84,.9); }
button.primary { background: #b8232f; border-color: #d45660; font-weight: 700; }
button.primary:hover { background: #d0303e; }
button.primary:disabled { opacity: .45; cursor: default; }
button.on { background: #0f3b2d; border-color: #3f8f74; }
.panel { position: absolute; top: 0; right: 0; height: 100%; z-index: 5;
transform: translateX(calc(100% - 2.6rem)); transition: transform .25s ease; }
.panel.open { transform: translateX(0); }
.toggle { position: absolute; left: -2.6rem; top: 50%; transform: translateY(-50%);
writing-mode: vertical-rl; border-radius: .55rem 0 0 .55rem; padding: .7rem .45rem; z-index: 6; }
.panel.open .toggle { writing-mode: horizontal-tb; left: -3.4rem; right: auto; top: 12px;
transform: none; border-radius: .55rem 0 0 .55rem; }
.panel-body { height: 100%; box-sizing: border-box; padding: 52px 14px 14px;
width: 348px; background: rgba(6,28,38,.88); backdrop-filter: blur(10px);
border-left: 1px solid rgba(255,255,255,.12); display: flex; flex-direction: column; gap: 10px; }
#studio { width: 100%; aspect-ratio: 320/220; border-radius: .6rem; touch-action: none;
background: #dcece6; border: 1px solid rgba(255,255,255,.2); cursor: crosshair; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.swatches button { width: 26px; height: 26px; padding: 0; border-radius: 50%; }
.swatches button.sel { outline: 2px solid #fff; }
.size { display: flex; gap: 6px; align-items: center; font-size: .85rem; flex: 1; }
.size input { flex: 1; accent-color: #b8232f; }
@media (max-width: 720px) { .panel-body { width: min(348px, 92vw); } }
`;
document.head.append(style);
// ---------- tank ----------
interface FishSpec { src: string; scale: number }
interface Fish {
img: HTMLImageElement; x: number; y: number; vx: number; vy: number;
facing: 1 | -1; speed: number; scale: number; phase: number;
tx: number; ty: number; retarget: number; depth: number;
}
interface Pellet { x: number; y: number; vy: number; vx: number }
interface Bubble { x: number; y: number; r: number; vy: number; wob: number }
const tankCanvas = document.getElementById('tank') as HTMLCanvasElement;
const tctx = tankCanvas.getContext('2d')!;
const countEl = document.getElementById('count')!;
const hintEl = document.getElementById('hint')!;
let W = 0, H = 0, DPR = 1;
function resize(): void {
DPR = Math.min(window.devicePixelRatio || 1, 2);
W = tankCanvas.clientWidth; H = tankCanvas.clientHeight;
tankCanvas.width = Math.round(W * DPR); tankCanvas.height = Math.round(H * DPR);
tctx.setTransform(DPR, 0, 0, DPR, 0, 0);
}
window.addEventListener('resize', resize);
resize();
const fish: Fish[] = [];
const pellets: Pellet[] = [];
const bubbles: Bubble[] = [];
const sandTop = (): number => H - Math.max(46, H * 0.09);
// scenery, generated once per size
let plants: { x: number; h: number; hue: number; sway: number }[] = [];
let pebbles: { x: number; y: number; r: number; g: number }[] = [];
function genScenery(): void {
plants = []; pebbles = [];
const n = Math.max(4, Math.round(W / 220));
for (let i = 0; i < n; i++) {
plants.push({
x: 30 + Math.random() * (W - 60), h: 60 + Math.random() * 160,
hue: 95 + Math.random() * 60, sway: 0.5 + Math.random(),
});
}
for (let i = 0; i < 26; i++) {
pebbles.push({
x: Math.random() * W, y: sandTop() + 8 + Math.random() * (H - sandTop() - 14),
r: 2 + Math.random() * 5, g: 90 + Math.random() * 60,
});
}
}
genScenery();
window.addEventListener('resize', genScenery);
// ---------- fish behaviour ----------
function addFish(spec: FishSpec, img: HTMLImageElement): void {
const depth = 0.55 + Math.random() * 0.45; // 0.55 back .. 1 front
const scale = spec.scale * (0.75 + depth * 0.45);
const y = 60 + Math.random() * Math.max(60, sandTop() - 120);
const f: Fish = {
img, x: Math.random() * W, y, vx: 0, vy: 0,
facing: Math.random() < 0.5 ? 1 : -1,
speed: (26 + Math.random() * 40) * (1.15 - depth * 0.35),
scale, phase: Math.random() * Math.PI * 2,
tx: Math.random() * W, ty: y, retarget: 0, depth,
};
fish.push(f);
save();
updateHud();
}
function steer(f: Fish, dt: number, t: number): void {
f.retarget -= dt;
let gx = f.tx, gy = f.ty;
// food wins
let best: Pellet | null = null, bd = 1e9;
for (const p of pellets) {
const d = Math.hypot(p.x - f.x, p.y - f.y);
if (d < bd) { bd = d; best = p; }
}
if (best !== null && bd < Math.min(W, H) * 0.6) { gx = best.x; gy = best.y; }
else if (f.retarget <= 0) {
f.retarget = 3 + Math.random() * 5;
f.tx = 40 + Math.random() * Math.max(60, W - 80);
f.ty = 50 + Math.random() * Math.max(60, sandTop() - 110);
}
const dx = gx - f.x, dy = gy - f.y;
const d = Math.hypot(dx, dy) || 1;
const ax = (dx / d) * f.speed, ay = (dy / d) * f.speed * 0.6;
f.vx += (ax - f.vx) * Math.min(1, dt * 1.4);
f.vy += (ay - f.vy + Math.sin(t * 1.7 + f.phase) * 6) * Math.min(1, dt * 1.4);
if (Math.abs(f.vx) > 4) f.facing = f.vx > 0 ? 1 : -1;
f.x += f.vx * dt; f.y += f.vy * dt;
f.x = Math.max(20, Math.min(W - 20, f.x));
f.y = Math.max(30, Math.min(sandTop() - 14, f.y));
// eat pellets
for (let i = pellets.length - 1; i >= 0; i--) {
const p = pellets[i]!;
if (Math.hypot(p.x - f.x, p.y - f.y) < 26 * f.scale + 6) {
pellets.splice(i, 1);
for (let b = 0; b < 3; b++)
bubbles.push({ x: p.x, y: p.y, r: 1.5 + Math.random() * 2, vy: 40 + Math.random() * 30, wob: Math.random() * 6 });
}
}
}
function drawFish(f: Fish, t: number): void {
const img = f.img;
const w = img.naturalWidth * f.scale, h = img.naturalHeight * f.scale;
const strips = 14;
const sw = img.naturalWidth / strips;
const speedNorm = Math.min(1, Math.hypot(f.vx, f.vy) / f.speed);
const wig = 0.10 + 0.16 * speedNorm; // tail swing amplitude (fraction of height)
const ang = Math.atan2(f.vy, Math.abs(f.vx) + 1) * 0.55;
tctx.save();
tctx.translate(f.x, f.y);
tctx.rotate(f.facing === 1 ? ang : -ang);
tctx.scale(f.facing, 1);
tctx.globalAlpha = 0.55 + f.depth * 0.45;
const squash = 1 + 0.02 * Math.sin(t * 6 + f.phase);
tctx.scale(squash, 1);
for (let i = 0; i < strips; i++) {
const s = i / (strips - 1); // 0 head .. 1 tail
const off = Math.sin(t * 7 + f.phase - i * 0.55) * wig * h * s * s;
tctx.drawImage(img, i * sw, 0, sw + 0.6, img.naturalHeight,
-w / 2 + i * (w / strips), off - h / 2, w / strips + 0.6, h);
}
tctx.restore();
}
// ---------- background ----------
function drawScene(t: number): void {
const g = tctx.createLinearGradient(0, 0, 0, H);
g.addColorStop(0, '#0d4f66'); g.addColorStop(0.55, '#0a3a4e'); g.addColorStop(1, '#06222e');
tctx.fillStyle = g; tctx.fillRect(0, 0, W, H);
// caustics
tctx.save();
tctx.globalCompositeOperation = 'soft-light';
for (let i = 0; i < 5; i++) {
const cx = (W * (0.1 + 0.2 * i) + Math.sin(t * 0.3 + i * 2.1) * W * 0.12);
const cy = H * 0.25 + Math.cos(t * 0.23 + i * 1.7) * H * 0.15;
const r = Math.min(W, H) * (0.25 + 0.1 * Math.sin(t * 0.4 + i));
const rg = tctx.createRadialGradient(cx, cy, 0, cx, cy, r);
rg.addColorStop(0, 'rgba(190,255,240,0.5)'); rg.addColorStop(1, 'rgba(190,255,240,0)');
tctx.fillStyle = rg; tctx.fillRect(0, 0, W, H);
}
tctx.restore();
// plants behind sand
const st = sandTop();
for (const p of plants) {
tctx.strokeStyle = `hsl(${p.hue} 45% 30%)`;
tctx.lineCap = 'round';
for (let s = 0; s < 3; s++) {
tctx.lineWidth = 7 - s * 2;
const sway = Math.sin(t * p.sway + s * 1.3) * 14;
tctx.beginPath();
tctx.moveTo(p.x + s * 6, st + 6);
tctx.quadraticCurveTo(p.x + s * 6 + sway * 0.5, st - p.h * 0.6, p.x + s * 6 + sway, st - p.h * (0.7 + s * 0.12));
tctx.stroke();
}
}
// sand
tctx.fillStyle = '#c9b283';
tctx.beginPath();
tctx.moveTo(0, H); tctx.lineTo(0, st + 6);
for (let x = 0; x <= W; x += 40)
tctx.lineTo(x, st + 6 + Math.sin(x * 0.02 + 2) * 5);
tctx.lineTo(W, H); tctx.closePath(); tctx.fill();
for (const p of pebbles) {
tctx.fillStyle = `rgb(${p.g + 40},${p.g + 30},${p.g + 20})`;
tctx.beginPath(); tctx.ellipse(p.x, p.y, p.r, p.r * 0.7, 0, 0, Math.PI * 2); tctx.fill();
}
}
function drawBubbles(dt: number): void {
if (Math.random() < dt * 1.2) {
bubbles.push({ x: 30 + Math.random() * (W - 60), y: sandTop(), r: 2 + Math.random() * 4, vy: 35 + Math.random() * 35, wob: Math.random() * 6 });
}
tctx.strokeStyle = 'rgba(220,250,255,0.5)';
tctx.lineWidth = 1.2;
for (let i = bubbles.length - 1; i >= 0; i--) {
const b = bubbles[i]!;
b.y -= b.vy * dt; b.x += Math.sin(b.y * 0.05 + b.wob) * 12 * dt;
if (b.y < 8) { bubbles.splice(i, 1); continue; }
tctx.beginPath(); tctx.arc(b.x, b.y, b.r, 0, Math.PI * 2); tctx.stroke();
}
}
function drawPellets(dt: number): void {
tctx.fillStyle = '#8a5a2b';
for (const p of pellets) {
p.vy = Math.min(60, p.vy + 60 * dt);
p.y += p.vy * dt; p.x += p.vx * dt; p.vx *= 1 - dt;
if (p.y > sandTop() + 2) { p.y = sandTop() + 2; p.vy = 0; }
tctx.beginPath(); tctx.arc(p.x, p.y, 3, 0, Math.PI * 2); tctx.fill();
}
}
// ---------- main loop ----------
let last = performance.now();
function frame(now: number): void {
const dt = Math.min(0.05, (now - last) / 1000);
const t = now / 1000;
last = now;
drawScene(t);
drawPellets(dt);
const sorted = [...fish].sort((a, b) => a.depth - b.depth);
for (const f of sorted) { steer(f, dt, t); drawFish(f, t); }
drawBubbles(dt);
requestAnimationFrame(frame);
}
requestAnimationFrame(frame);
// ---------- feeding ----------
document.getElementById('feed')!.addEventListener('click', () => dropFood(W / 2, 40));
tankCanvas.addEventListener('pointerdown', (e) => {
const r = tankCanvas.getBoundingClientRect();
dropFood(e.clientX - r.left, e.clientY - r.top);
});
function dropFood(x: number, y: number): void {
for (let i = 0; i < 7; i++)
pellets.push({ x: x + (Math.random() - 0.5) * 46, y: y - Math.random() * 20, vy: 10 + Math.random() * 20, vx: (Math.random() - 0.5) * 20 });
}
function updateHud(): void {
countEl.textContent = `${fish.length} ${fish.length === 1 ? 'fish' : 'fish'}`;
hintEl.hidden = fish.length > 0;
}
// ---------- persistence ----------
const LS = 'aos-01-living-fishtank';
function save(): void {
try {
localStorage.setItem(LS, JSON.stringify(specs));
} catch { /* private mode etc. */ }
}
let specs: FishSpec[] = [];
function loadSaved(): void {
try {
const raw = localStorage.getItem(LS);
if (!raw) return;
specs = JSON.parse(raw) as FishSpec[];
} catch { specs = []; }
for (const s of specs.slice(0, 40)) {
const img = new Image();
img.onload = () => addFish(s, img);
img.src = s.src;
}
}
// ---------- studio ----------
const panel = document.getElementById('panel')!;
document.getElementById('toggle')!.addEventListener('click', () => panel.classList.toggle('open'));
const studio = document.getElementById('studio') as HTMLCanvasElement;
const sctx = studio.getContext('2d', { willReadFrequently: true })!;
const releaseBtn = document.getElementById('release') as HTMLButtonElement;
const COLORS: string[] = ['#e4572e', '#f3a712', '#d6409f', '#2e86ab', '#3aa76d', '#f6f7fb', '#2b2d42', '#8d5524'];
const swatchRow = document.getElementById('swatches')!;
let color: string = COLORS[0] ?? '#e4572e';
let erasing = false;
let brush = 14;
COLORS.forEach((c, i) => {
const b = document.createElement('button');
b.type = 'button'; b.style.background = c; b.title = c;
if (i === 0) b.classList.add('sel');
b.addEventListener('click', () => {
color = c; erasing = false;
swatchRow.querySelector('.sel')?.classList.remove('sel');
b.classList.add('sel');
document.getElementById('eraser')!.classList.remove('on');
});
swatchRow.append(b);
});
document.getElementById('brush')!.addEventListener('input', (e) => {
brush = Number((e.target as HTMLInputElement).value);
});
const eraserBtn = document.getElementById('eraser')!;
eraserBtn.addEventListener('click', () => {
erasing = !erasing;
eraserBtn.classList.toggle('on', erasing);
});
// undo snapshots
const undoStack: ImageData[] = [];
document.getElementById('undo')!.addEventListener('click', () => {
const s = undoStack.pop();
if (s) { sctx.clearRect(0, 0, studio.width, studio.height); sctx.putImageData(s, 0, 0); checkEmpty(); }
});
document.getElementById('clear')!.addEventListener('click', () => {
pushUndo(); sctx.clearRect(0, 0, studio.width, studio.height); checkEmpty();
});
function pushUndo(): void {
undoStack.push(sctx.getImageData(0, 0, studio.width, studio.height));
if (undoStack.length > 15) undoStack.shift();
}
let drawing = false, lx = 0, ly = 0;
function pos(e: PointerEvent): [number, number] {
const r = studio.getBoundingClientRect();
return [(e.clientX - r.left) * (studio.width / r.width), (e.clientY - r.top) * (studio.height / r.height)];
}
studio.addEventListener('pointerdown', (e) => {
e.preventDefault();
studio.setPointerCapture(e.pointerId);
pushUndo();
drawing = true; [lx, ly] = pos(e);
dot(lx, ly);
});
studio.addEventListener('pointermove', (e) => {
if (!drawing) return;
const [x, y] = pos(e);
sctx.save();
sctx.lineCap = 'round'; sctx.lineJoin = 'round'; sctx.lineWidth = brush;
sctx.globalCompositeOperation = erasing ? 'destination-out' : 'source-over';
sctx.strokeStyle = color;
sctx.beginPath(); sctx.moveTo(lx, ly); sctx.lineTo(x, y); sctx.stroke();
sctx.restore();
[lx, ly] = [x, y];
checkEmpty();
});
studio.addEventListener('pointerup', () => { drawing = false; checkEmpty(); });
function dot(x: number, y: number): void {
sctx.save();
sctx.globalCompositeOperation = erasing ? 'destination-out' : 'source-over';
sctx.fillStyle = color;
sctx.beginPath(); sctx.arc(x, y, brush / 2, 0, Math.PI * 2); sctx.fill();
sctx.restore();
}
function checkEmpty(): void {
releaseBtn.disabled = !hasInk();
}
function hasInk(): boolean {
const d = sctx.getImageData(0, 0, studio.width, studio.height).data;
for (let i = 3; i < d.length; i += 4) if (d[i]! > 0) return true;
return false;
}
// ---------- release pipeline ----------
function releaseCurrent(): void {
if (!hasInk()) return;
const src = studio.toDataURL('image/png');
const img = new Image();
img.onload = () => {
const trimmed = trimImage(img);
const scale = Math.min(1.1, Math.max(0.35, trimmed.h / 150));
const spec: FishSpec = { src: trimmed.src, scale };
specs.push(spec);
if (specs.length > 40) specs.shift();
addFish(spec, trimmed.img);
};
img.src = src;
}
interface Trimmed { src: string; h: number; img: HTMLImageElement }
function trimImage(img: HTMLImageElement): Trimmed {
const c = document.createElement('canvas');
c.width = img.naturalWidth; c.height = img.naturalHeight;
const ctx = c.getContext('2d', { willReadFrequently: true })!;
ctx.drawImage(img, 0, 0);
const { data } = ctx.getImageData(0, 0, c.width, c.height);
let minX = c.width, minY = c.height, maxX = 0, maxY = 0;
for (let y = 0; y < c.height; y++) {
for (let x = 0; x < c.width; x++) {
if (data[(y * c.width + x) * 4 + 3]! > 10) {
if (x < minX) minX = x; if (x > maxX) maxX = x;
if (y < minY) minY = y; if (y > maxY) maxY = y;
}
}
}
if (maxX < minX) { minX = 0; minY = 0; maxX = c.width - 1; maxY = c.height - 1; }
const pad = 2;
minX = Math.max(0, minX - pad); minY = Math.max(0, minY - pad);
maxX = Math.min(c.width - 1, maxX + pad); maxY = Math.min(c.height - 1, maxY + pad);
const w = maxX - minX + 1, h = maxY - minY + 1;
const out = document.createElement('canvas');
out.width = w; out.height = h;
const octx = out.getContext('2d')!;
octx.drawImage(c, minX, minY, w, h, 0, 0, w, h);
// orient: fish heads taper, tails flare — flip so the narrower end faces right
const od = octx.getImageData(0, 0, w, h).data;
const colH = (x0: number, x1: number): number => {
let sum = 0;
for (let x = x0; x < x1; x++) {
let top = -1, bot = -1;
for (let y = 0; y < h; y++) {
const a = od[(y * w + x) * 4 + 3]!;
if (a > 10) { if (top < 0) top = y; bot = y; }
}
sum += top < 0 ? 0 : bot - top;
}
return sum / Math.max(1, x1 - x0);
};
const band = Math.max(3, Math.round(w * 0.2));
const leftH = colH(0, band), rightH = colH(w - band, w);
const flipped = document.createElement('canvas');
flipped.width = w; flipped.height = h;
const fctx = flipped.getContext('2d')!;
if (leftH < rightH) { // head already on the right
fctx.drawImage(out, 0, 0);
} else { // mirror so head faces right
fctx.translate(w, 0); fctx.scale(-1, 1); fctx.drawImage(out, 0, 0);
}
const src = flipped.toDataURL('image/png');
const fimg = new Image(); fimg.src = src;
return { src, h, img: fimg };
}
releaseBtn.addEventListener('click', releaseCurrent);
checkEmpty();
// ---------- random fish ----------
document.getElementById('random')!.addEventListener('click', () => {
const c = document.createElement('canvas');
c.width = 200; c.height = 130;
const ctx = c.getContext('2d')!;
const hue = Math.floor(Math.random() * 360);
const body = `hsl(${hue} 70% 55%)`, dark = `hsl(${hue} 70% 38%)`;
// tail
ctx.fillStyle = dark;
ctx.beginPath();
ctx.moveTo(58, 65); ctx.lineTo(14, 34); ctx.lineTo(24, 65); ctx.lineTo(14, 96); ctx.closePath(); ctx.fill();
// body
const g = ctx.createLinearGradient(0, 30, 0, 100);
g.addColorStop(0, body); g.addColorStop(1, dark);
ctx.fillStyle = g;
ctx.beginPath(); ctx.ellipse(110, 65, 62, 34, 0, 0, Math.PI * 2); ctx.fill();
// dorsal fin
ctx.fillStyle = dark;
ctx.beginPath(); ctx.moveTo(95, 34); ctx.quadraticCurveTo(115, 8, 135, 36); ctx.closePath(); ctx.fill();
// stripes
ctx.strokeStyle = `hsla(${(hue + 40) % 360} 80% 80% / .55)`;
ctx.lineWidth = 7; ctx.lineCap = 'round';
for (let i = 0; i < 3; i++) {
ctx.beginPath();
ctx.moveTo(88 + i * 20, 40 + i * 2);
ctx.quadraticCurveTo(84 + i * 20, 65, 88 + i * 20, 90 - i * 2);
ctx.stroke();
}
// eye
ctx.fillStyle = '#fff'; ctx.beginPath(); ctx.arc(150, 57, 8, 0, Math.PI * 2); ctx.fill();
ctx.fillStyle = '#151515'; ctx.beginPath(); ctx.arc(152, 57, 4, 0, Math.PI * 2); ctx.fill();
const img = new Image();
img.onload = () => {
const trimmed = trimImage(img);
const spec: FishSpec = { src: trimmed.src, scale: Math.min(1.1, Math.max(0.35, trimmed.h / 150)) };
specs.push(spec);
if (specs.length > 40) specs.shift();
addFish(spec, trimmed.img);
};
img.src = c.toDataURL('image/png');
});
loadSaved();
updateHud();
+15
View File
@@ -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"]
}
+6
View File
@@ -0,0 +1,6 @@
import { defineConfig } from 'vite';
export default defineConfig({
// Relative links, so the build works under https://<you>.github.io/<repository>/ whatever the repository is called.
base: './',
});