Skip to content

244 pixel art effects, every one a small piece of code. Plus a Claude Code skill to make your own.

pixelfx: 299 code-driven pixel art effects and a Claude Code skill

rehan-remade070f4a24be98
diff --git a/.claude-plugin/marketplace.json b/.claude-plugin/marketplace.json
new file mode 100644
index 0000000..d73e5fb
--- /dev/null
+++ b/.claude-plugin/marketplace.json
@@ -0,0 +1,17 @@
+{
+ "name": "pixelfx",
+ "description": "pixelfx by Patch: pixel art effects and animations as code.",
+ "owner": {
+ "name": "Patch",
+ "url": "https://patch.gg"
+ },
+ "plugins": [
+ {
+ "name": "pixelfx",
+ "source": "./",
+ "description": "A skill for pixel art effects and sprite animations: use, recolor and export the library's effects, or draft, render, look at and refine new ones until they look hand-animated.",
+ "category": "gamedev",
+ "tags": ["pixel-art", "vfx", "animation", "sprite-sheet", "gamedev"]
+ }
+ ]
+}
diff --git a/.claude-plugin/plugin.json b/.claude-plugin/plugin.json
new file mode 100644
index 0000000..57d757c
--- /dev/null
+++ b/.claude-plugin/plugin.json
@@ -0,0 +1,14 @@
+{
+ "name": "pixelfx",
+ "displayName": "pixelfx",
+ "version": "0.1.0",
+ "description": "Pixel art effects and animations as code: a library of ready-made effects in 20 categories, sprite sheet export for any engine, and a skill that makes new effects by drafting, rendering, looking and refining.",
+ "author": {
+ "name": "Patch",
+ "url": "https://patch.gg"
+ },
+ "homepage": "https://github.com/patch-gg/pixelfx",
+ "repository": "https://github.com/patch-gg/pixelfx",
+ "license": "MIT",
+ "keywords": ["pixel-art", "vfx", "effects", "animation", "sprite-sheet", "gamedev", "canvas", "godot", "unity", "phaser"]
+}
diff --git a/.github/workflows/gallery.yml b/.github/workflows/gallery.yml
new file mode 100644
index 0000000..4f0eda0
--- /dev/null
+++ b/.github/workflows/gallery.yml
@@ -0,0 +1,35 @@
+name: gallery
+on:
+ push:
+ branches: [main]
+ workflow_dispatch:
+permissions:
+ contents: read
+ pages: write
+ id-token: write
+concurrency:
+ group: pages
+ cancel-in-progress: true
+jobs:
+ build:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v4
+ - uses: actions/setup-node@v4
+ with:
+ node-version: 22
+ - run: npm ci
+ - run: node tools/check.mjs
+ - run: node tools/build-gallery.mjs
+ - uses: actions/upload-pages-artifact@v3
+ with:
+ path: dist/gallery
+ deploy:
+ needs: build
+ runs-on: ubuntu-latest
+ environment:
+ name: github-pages
+ url: ${{ steps.deploy.outputs.page_url }}
+ steps:
+ - id: deploy
+ uses: actions/deploy-pages@v4
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..709400b
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,5 @@
+node_modules/
+dist/
+records/
+sheets/
+.DS_Store
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..c9a7b32
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,23 @@
+MIT License
+
+Copyright (c) 2026 Patch
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+
+The Patch Pixel font in gallery/fonts is not covered by this license; see gallery/fonts/NOTICE.md.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..4bbeb8d
--- /dev/null
+++ b/README.md
@@ -0,0 +1,138 @@
+<p align="center">
+ <img src="docs/readme/montage.gif" width="800" alt="A grid of pixel art effects playing at once: fire, explosions, ice, lightning, slashes, magic, weather, pickups and critters.">
+</p>
+
+# pixelfx.
+
+**<!-- count -->299<!-- /count --> pixel art effects and animations, every one a small piece of code.** Fire,
+explosions, magic, weather, UI, pickups, critters and more. Play them live, recolor and mirror them, drop them into
+a browser game, or export sprite sheets for any engine. Plus a Claude Code skill that makes new ones the way a
+picky pixel artist would: draft, render, look, refine.
+
+**[open the gallery](https://patch-gg.github.io/pixelfx/)** · [catalog](docs/CATALOG.md) · [the skill](#the-skill) ·
+[make your own](#make-your-own) · [how it works](#how-it-works)
+
+The method is [Hugo Duprez](https://x.com/HugoDuprez)'s, from [How to make (good) pixel art effects with
+Claude](https://www.spritefusion.com/blog/how-to-make-good-pixel-art-effects-with-claude): code is clay, trust your
+eyes, feed your references. His [open-source effects](https://www.spritefusion.com/pixel-art-vfx) at Sprite Fusion
+set the bar. This repo is our take on the idea at library scale, with a skill to keep going.
+
+## what's in it.
+
+<!-- catalog -->
+| category | effects | some of them |
+|---|---|---|
+| **fire** | 17 | brazier, campfire, candle, ember burst, fire breath, fire ring… |
+| **explosions** | 16 | barrel explosion, big explosion, cartoon pow, chain explosions, dirt explosion, dust cloud… |
+| **water** | 15 | bubbles, drip, fountain, geyser, puddle step, rain splash… |
+| **ice** | 13 | blizzard vortex, cold mist, freeze, frost breath, frost nova, frozen ground… |
+| **lightning** | 14 | ball lightning, chain lightning, charge up, electric field, electrified, lightning dash… |
+| **sci-fi** | 15 | cloak, data stream, emp blast, energy core, force field, glitch… |
+| **melee** | 16 | axe chop, claw swipe, counter flash, dagger flurry, double slash, hammer smash… |
+| **impacts** | 14 | blunt hit, bullet impact, combo hit, critical hit, ground slam, heavy landing… |
+| **projectiles** | 17 | arrow, arrow hit, boomerang, bullet tracer, cannonball, energy disc… |
+| **spawn & death** | 13 | coin drop, disintegrate, dissolve burn, egg hatch, ghost out, poof… |
+| **arcane** | 16 | arcane beam, arcane missiles, arcane orb, blink in, blink out, enchant… |
+| **holy** | 12 | blessing, divine shield, feather burst, halo, heal, healing ring… |
+| **shadow** | 14 | black hole, curse, dark explosion, doom mark, eclipse, grasping hands… |
+| **status** | 16 | bleeding, burning, charmed, confused, cursed, fortified… |
+| **nature** | 15 | acid splash, boulder, earth spike, healing bloom, leaf storm, poison cloud… |
+| **weather** | 16 | aurora, blizzard, cherry blossoms, clouds, falling leaves, fireflies… |
+| **ui** | 19 | achievement, button press, checkmark, coin collect, combo counter, confetti… |
+| **pickups** | 15 | ammo crate, chest open, coin spin, collect burst, crystal shard, gem spin… |
+| **transitions** | 12 | blinds, burn away, crt off, diamond wipe, dither fade, glitch wipe… |
+| **critters** | 14 | bat, bird, butterfly, crab, eyeball, fish school… |
+<!-- /catalog -->
+
+Every effect is a file in `src/fx/<category>/<name>.js`. The [catalog](docs/CATALOG.md) lists them all.
+
+## use one.
+
+**In a browser game** (canvas, Phaser, PixiJS, Kaplay, three.js), use the code. No dependencies.
+
+```js
+import { createFrame, clearFrame, createFx, composite } from "pixelfx";
+import * as frostNova from "pixelfx/fx/ice/frost-nova";
+
+const frame = createFrame(320, 180); // your game's pixel resolution
+const img = new ImageData(320, 180);
+const fx = createFx(frostNova, { x: 160, y: 140 }); // also: flip, angle, seed, palette, light...
+
+function tick(dt) {
+ fx.update(dt);
+ clearFrame(frame);
+ fx.draw(frame, "back"); // behind characters
+ drawCharacters();
+ fx.draw(frame, "front");
+ composite(frame, img.data, backgroundColor); // color, then light added on top
+ ctx.putImageData(img, 0, 0); // scale up with image-rendering: pixelated
+}
+```
+
+Install from GitHub with `npm i github:patch-gg/pixelfx`, or copy `src/core` and the effects you want.
+
+**In any engine** (Godot, Unity, GameMaker, Defold, LÖVE, Bevy), use sprite sheets:
+
+```bash
+node tools/render.mjs ice/frost-nova --sheet
+```
+
+That writes a transparent PNG of every frame in a grid and an Aseprite-style JSON (frame rects, durations, and
+`meta.pixelfx` with fps, loop, columns and the pivot). Phaser's atlas loader and the Aseprite importers for Godot
+and Unity read it. `node tools/sheets.mjs` exports the whole library to `sheets/`.
+
+Any effect takes a `palette` (a dark-to-bright ramp of hex colors), so a fire can burn blue and a heal can glow
+pink without touching its code:
+
+```bash
+node tools/render.mjs fire/torch --gif --opts '{"palette": ["#102","#215","#43a","#8cf","#cff","#fff"]}'
+```
+
+## the skill.
+
+The `pixelfx` skill teaches Claude Code to find, use, export and make effects. Install it as a plugin:
+
+```
+/plugin marketplace add patch-gg/pixelfx
+/plugin install pixelfx@pixelfx
+```
+
+or copy `skills/pixelfx` into `~/.claude/skills/`. Then ask for what you want:
+
+- "Add a frost nova to my mage's ultimate."
+- "Make five takes on a coin pickup sparkle and show me the best two."
+- "Export the fire and explosions categories as sprite sheets for Godot."
+- "This hit effect feels floaty. Make it punchier."
+
+## make your own.
+
+```bash
+node tools/new.mjs arcane/my-spell # a working starting point (add --loop for a loop)
+node tools/render.mjs arcane/my-spell # records/arcane/my-spell/contact.png: look at it
+node tools/check.mjs arcane/my-spell # spills, seams, unseeded randomness, slow frames
+```
+
+Then go round: look at the contact sheet, fix the worst thing, render again. `--gif` and `--mp4` show the motion,
+`--all` shows every frame. [docs/AUTHORING.md](docs/AUTHORING.md) has the contract, the drawing API and the quality
+bar. `node tools/serve.mjs` runs the gallery locally with your effects in it.
+
+## how it works.
+
+- **An effect is a function of time.** `draw(p, t, o)` draws the frame at `t` seconds. No simulation state, no
+ images, so any frame can be drawn in any order: scrubbed, looped, or rendered to a sheet.
+- **Two buffers.** `color` takes hard, opaque pixels; transparency is faked with a 4×4 ordered dither, so it stays
+ pixel art. `light` takes additive glow, added on top. Hot things look hot because of the light buffer.
+- **Seeded everything.** Particles get their own repeatable random numbers (`burst`, `cycle`, `rng(seed, i)`), and
+ their motion is closed-form (`fly`: gravity and drag without stepping), so frame 40 is the same every time.
+ Loops tile in time with no seam.
+- **Local space.** Effects draw around their own origin; the painter places, mirrors and rotates them. Directional
+ effects face right. A 12×19 stock character stands in for status effects, auras and hits.
+- **Same frame shape as Sprite Fusion's VFX** (`{ w, h, ox, oy, color, light }`), so both libraries can draw into
+ one frame.
+
+## license.
+
+MIT, code and effects. Use them in anything, commercial included. The Patch Pixel font in `gallery/fonts` is
+Patch's own and not covered; see its notice.
+
+Made by [Patch](https://patch.gg).
diff --git a/docs/AUTHORING.md b/docs/AUTHORING.md
new file mode 100644
index 0000000..76e7601
--- /dev/null
+++ b/docs/AUTHORING.md
@@ -0,0 +1,169 @@
+# Writing an effect
+
+An effect is one file, `src/fx/<category>/<name>.js` (kebab-case), that draws pixel art as a function of
+time. No images, no simulation state, no dependencies beyond `src/core`. Because a frame is just `draw(p, t)`,
+an effect can be scrubbed, looped, recolored, mirrored and rendered to a sprite sheet for any engine.
+
+```js
+import { PAL, ramp, at, burst, fly, seg, ease, WHITE } from "../../core/index.js";
+
+export const meta = {
+ name: "Spark burst", // shown in the gallery
+ desc: "White-hot sparks spray out, fall and cool to red.", // one line, under 180 chars
+ tags: ["impact", "sparks", "one-shot"],
+ size: [48, 48], // canvas in art pixels (sheets and previews)
+ origin: [24, 30], // where local (0, 0) sits in that canvas
+ duration: 0.6, // seconds; for a loop, its period
+ loop: false,
+ fps: 30, // sheet frame rate
+ bg: "dark", // preview backdrop: dark | ground | sky | light | black
+ actor: false, // preview with the stock character standing at the origin
+ options: { palette: PAL.volt, count: 12, seed: 1 }, // defaults; callers override any of them
+};
+
+export function draw(p, t, o) {
+ const C = ramp(o.palette);
+ burst(o.count, o.seed, (r) => {
+ const a = r.range(0, Math.PI * 2), sp = r.range(40, 90), life = r.range(0.3, 0.55);
+ if (t > life) return;
+ const [x, y] = fly(0, 0, Math.cos(a) * sp, Math.sin(a) * sp - 20, t, 140, 2);
+ p.px(x, y, at(C.slice(2), 1 - t / life));
+ p.light(x, y, C[4], 0.5 * (1 - t / life));
+ });
+ if (t < 0.05) p.circle(0, 0, 3, WHITE);
+}
+```
+
+## The contract
+
+- **Coordinates are local**: (0, 0) is the effect's anchor: the feet of the character it wraps, the point of
+ impact, the base of a torch, the muzzle of a gun. x goes right, y goes down, 1 unit is 1 art pixel. The
+ painter places, mirrors (`flip`) and rotates (`angle`) the whole effect, so never hard-code screen positions.
+- **Directional effects face right** (+x). Projectiles fly right, slashes swing to the right, breath blows right.
+- **Ground effects** put the origin on the floor line: y = 0 is the ground surface. Nothing goes below y = 2
+ except marks drawn on the floor (cracks, scorch, puddles).
+- **Time**: `t` is seconds since the start. A one-shot runs 0..duration and must draw **nothing at
+ t = duration**. A loop gets `0 <= t < duration` and must be **seamless**: the frame after the last is frame 0.
+- **Options** `o`: `meta.options` merged with whatever the caller passes. Always honour `o.palette` (the main
+ ramp, dark to bright) and `o.seed`. Add the knobs that matter for the effect (`size`, `count`, `radius`,
+ `text`, `height`...) with defaults in `meta.options`. `x`, `y`, `flip`, `angle` and `light` are taken: they
+ place the effect and set its glow, so name your own knobs something else (`cx`, `reach`, `glow`).
+- **Deterministic**: never `Math.random()` or `Date`. Random numbers come from `burst`, `cycle`, `stream`,
+ `rng(seed, i)` or `rand(...)`, which give the same values every frame.
+- **Layers**: export `drawBack(p, t, o)` for what goes behind a character (auras, the far side of an orbit,
+ portals behind a body) and `draw(p, t, o)` for the rest.
+- **Actor effects** (`actor: true`) get `o.actor = { mask, x, y, w, h, head: [x, y], chest: [x, y] }`, the
+ stock character's silhouette in local space with its feet at (0, 0): 12 x 19 px, head top at y = -19. Wrap,
+ tint or outline the mask; previews draw the character, sheets don't. An effect that makes the character vanish
+ or appear (a warp, a cloak) can export `actorAlpha(t, o)` returning 0..1, and previews dither the stand-in
+ character by it; in a game, do the same to your own sprite.
+- **State** (rare): if an effect truly needs simulation, export `create(o)` returning
+ `{ update(dt), draw(p, t, o) }` instead of `draw`. Prefer closed-form motion (`fly`) first.
+
+## Two buffers
+
+A frame has a **color** buffer and a **light** buffer.
+
+- **color**: opaque pixels only. Transparency is faked with ordered (Bayer) dithering: `p.dot(x, y, c, 0.5)`
+ draws half the pixels in a stable pattern. Nothing is ever alpha-blended. This is what keeps it pixel art.
+- **light**: additive glow, composited over everything: `p.glow`, `p.glowLine`, `p.glowRing`, `p.light`.
+ Light is what makes things look hot or bright. Use it sparingly: k 0.2 to 0.6, a big soft glow plus a small
+ tight one at the hottest point.
+
+## Painter API
+
+All coordinates local, floats fine (they snap to pixels). `c` is a color number; `a` is alpha 0..1 (dithered).
+Where noted, `c` and `a` may be functions of the shape's own coordinates.
+
+| call | draws |
+|---|---|
+| `p.px(x, y, c)` | one opaque pixel |
+| `p.dot(x, y, c, a)` | one pixel at alpha a (dithered) |
+| `p.line(x0, y0, x1, y1, c, a)` | 1 px line; c, a may be `(u) =>` with u 0 at start, 1 at end |
+| `p.polyline(pts, c, a)` | lines through `[[x, y], ...]` |
+| `p.beam(x0, y0, x1, y1, w, c, a)` | thick round-ended segment; c, a `(u along, v across 0..1)` |
+| `p.circle(x, y, r, c, a)` | filled disc; c, a `(d 0 center..1 rim, angle)` |
+| `p.ellipse(x, y, rx, ry, c, a)` | filled ellipse; c, a `(d, angle)` |
+| `p.ring(x, y, r, w, c, a)` | ring from r - w to r; c, a `(v 0 inner..1 outer, angle)` |
+| `p.arc(x, y, r, w, a0, a1, c, a)` | band of a ring from angle a0 to a1 (a1 > a0, radians, y down so +angle turns clockwise); `w` may be `(u) =>` to taper; c, a `(u along, v across)`. Slashes, smears, crescents |
+| `p.rect(x, y, w, h, c, a)` | filled rectangle |
+| `p.poly(pts, c, a)`, `p.tri(...)` | filled polygon |
+| `p.shade(x0, y0, x1, y1, fn)` | pixel shader over a box: `fn(x, y, out)` returns a color, or sets `out.c`, `out.a`, `out.l` (light color), `out.k` (light amount). x and y are pixel centers (n.5): floor them for row or column tests like scanlines. Fields, swirls, flames, water |
+| `p.glow(x, y, r, c, k)` | radial light, k at the center falling to 0 at r |
+| `p.glowLine(x0, y0, x1, y1, r, c, k)` | light around a segment (beams) |
+| `p.glowRing(x, y, R, r, c, k)` | light hugging a circle of radius R (shockwaves) |
+| `p.light(x, y, c, k)` | light on one pixel |
+| `p.sprite(rows, pal, x, y, {scale, a, flip, flipY, tint})` | tiny sprite from strings: `["..#..", ".#o#."]`, pal `{ "#": "#222034", o: C[4] }`, `.` is empty |
+| `p.text(str, x, y, c, {font, scale, align, outline, shadow, a})` | pixel text: font `"mini"` (3x5) or `"big"` (5x7); c may be `(gx, gy) =>` for gradients |
+| `p.measure(str, {font, scale})` | `[w, h]` of text |
+| `p.mask(m, x, y, c, a)`, `p.outline(m, x, y, c, a)` | fill a mask, or the 1 px ring just outside it (actor silhouettes) |
+| `p.get(x, y)` | the color already drawn under a point (0 if empty) |
+
+## Helpers (`src/core/index.js`)
+
+- **math**: `clamp lerp invLerp remap fract wrap TAU`, `seg(t, t0, t1)` (0..1 progress through a window: the
+ basic timeline tool), `smooth(e0, e1, x)`, `bump(t, t0, t1)` (0, 1, 0), `pingpong`, `dist`, `angleTo`.
+- **easing**: `ease.outCubic outQuart outExpo outBack(t, s) outElastic outBounce inQuad inCubic inExpo inOutSine ...`
+- **random**: `rng(seed, i)` (a generator for particle i), `rand(seed, i, k)` (one number), `Rng` (`next range int
+ chance sign pick gauss`).
+- **noise**: `noise(x, seed)` 1D, `noise2(x, y, seed)`, `fbm(x, y, seed, octaves)`, all -1..1.
+ For loops: `loopNoise(phase, radius, seed)` (same at phase 0 and 1); `tileNoise(x, y, px, py, seed)` and
+ `tileFbm(...)` repeat every px / py cells, so scrolling by exactly `py` cells over a loop is seamless
+ (`tileFbm(x * 0.3, y * 0.3 + phase * 8, 0, 8, seed)` rises forever without a seam).
+- **particles**: `fly(x, y, vx, vy, t, g, drag)` → `[x, y]` (closed-form ballistic with drag), `flyV(...)` →
+ velocity; `burst(n, seed, (r, i) => ...)` for one-shot sprays; `cycle(t, period, n, seed, life, (age, life,
+ r, i) => ...)` for particles that loop seamlessly; `stream(t, t0, t1, rate, seed, life, fn)` for an emitter
+ that runs then stops.
+- **shapes**: `bolt(r, x0, y0, x1, y1, {jag, depth})` jagged lightning points, `forks(r, path, {...})` its
+ branches, `star(cx, cy, r0, r1, n)`, `ngon(cx, cy, r, n)`, `trail(posFn, t, n, dt)`.
+- **color**: `PAL` (hex ramps) and `RAMP` (the same as color numbers): fire ember lava smoke dust ice water
+ electric volt poison holy heal arcane shadow blood earth stone gold leaf wood metal bone neon cyber matrix
+ candy night. `ramp(hexList)`, `fit(palette, n)` (resample any palette to n steps, so `C[5]` always exists:
+ use it on `o.palette` whenever you index steps by number), `at(ramp, t)` (pick a step, no blending), `blend(ramp, t)` (smooth, for
+ light only), `mix`, `scale`, `hex`, `rgb`, `luma`, `WHITE`, `BLACK`, `INK`, `PATCH` (#f53cd1).
+- **actor**: `stockActor()`, `drawActor(p)`, and the stock sprite itself as `HERO` (rows) and `HERO_PAL` (its colors).
+
+## The bar
+
+Effects here should look like a good pixel artist animated them. The checks:
+
+1. **Pixel art, not vector art.** Hard pixels in the color buffer, fades by dither, softness only in the
+ light buffer. No anti-aliased mush. Use `at()` steps, never `blend()` in the color buffer.
+2. **Palette.** One ramp per element, 4 to 7 steps, hue-shifted (shadows cooler or deeper, highlights warmer
+ or whiter). Hot cores go white or near-white; edges take the darkest step of the ramp, not black. Two or
+ three elements per effect at most (e.g. fire + smoke + sparks).
+3. **Reads at 1x.** A strong silhouette and one focal point. No speckle: no stray single pixels of noise inside
+ shapes. Check the contact sheet at its smallest: can you tell what it is?
+4. **Timing.** Fast in, slow out. Impacts get anticipation (optional), a 1 to 2 frame hero frame (white flash,
+ biggest shape), follow-through, then a longer decay. Use `ease.outCubic/outQuart/outExpo` for things that
+ burst and `inQuad` for things that fall or get sucked in. Hold the key pose a beat.
+5. **Life.** Secondary motion under the main shape: sparks, motes, debris, smoke, drips. Vary every particle's
+ size, speed, angle, life and delay (`r.range`). Nothing perfectly uniform or symmetric unless the style is.
+6. **Light.** A big soft glow at low k plus a tight one at the hot spot, pulsing with the effect and dropping
+ fast after an impact. Never so strong that it washes the pixels out.
+7. **Fits its canvas** with a few pixels to spare; the checker reports spills. Choose the smallest canvas that
+ holds the whole effect (common sizes 32 to 128 px).
+8. **Ends clean or loops clean.** One-shots are empty at t = duration (fade by dither, shrink, fall away).
+ Loops repeat with no seam (`cycle`, `loopNoise`, whole-cell `tileNoise` scrolls, `sin(phase * TAU * n)`).
+9. **Original.** Generic motifs (coins, hearts, gems, skulls, stars, swords) are fine; never recreate a
+ specific game's sprite, character or logo.
+10. **Fast.** Under 2 ms a frame. Big `shade` boxes with heavy per-pixel math are the usual cost; keep boxes
+ tight.
+
+## The method
+
+The method is Hugo Duprez's ([How to make (good) pixel art effects with
+Claude](https://www.spritefusion.com/blog/how-to-make-good-pixel-art-effects-with-claude)): code is clay, trust
+your eyes, feed your references.
+
+1. **Say it in one line** with the art direction: what it is, how it moves, its palette, its timing. "A frost
+ nova: crystals erupt in a ring from the feet outward, white flash at the center, shards spin off, the floor
+ stays frosted and fades."
+2. **Draft**, then **render**: `node tools/render.mjs <category>/<name>` writes
+ `records/<category>/<name>/contact.png`. **Look at it** (open the PNG). `--all` shows every frame, `--gif`
+ or `--mp4` writes an animation, `--opts '{"palette": [...]}'` tries options.
+3. **Judge like a picky artist.** What reads first? Is there a hero frame? Is the timing punchy or floaty? Are
+ the colors clean? Noise pixels, stiff motion, uniform particles, mushy dithering, too much glow?
+4. **Fix the worst thing, render again.** Two to four rounds is normal. When unsure between directions, write
+ 3 to 5 variations side by side (`<name>-a.js`, `-b.js`...), render them all, keep the best, delete the rest.
+5. **Check**: `node tools/check.mjs <category>/<name>` until it passes clean.
diff --git a/docs/CATALOG.md b/docs/CATALOG.md
new file mode 100644
index 0000000..77c0386
--- /dev/null
+++ b/docs/CATALOG.md
@@ -0,0 +1,443 @@
+# Catalog
+
+299 effects in 20 categories. Every one is a file in
+`src/fx/<category>/<name>.js`; render any of them with `node tools/render.mjs <id> --gif`.
+
+## fire
+
+torches, breath, pillars, walls of flame.
+
+| effect | id | | size | what it does |
+|---|---|---|---|---|
+| Brazier | `fire/brazier` | loop 1.2s | 52×92 | An iron bowl on a tripod stand holding a big, lively fire: tall licking tongues, glowing coals at the rim, sparks streaming up. |
+| Campfire | `fire/campfire` | loop 2s | 56×72 | Two crossed logs with a crackling fire: tongues that lick and sway, popping sparks, embers, smoke wisps and a warm pool of light on the ground. |
+| Candle | `fire/candle` | loop 3s | 28×44 | A small wax candle: a calm flame with a blue root that leans and stretches, a soft glow, and a bead of wax that runs down its drip. |
+| Ember burst | `fire/ember-burst` | one-shot 2.4s | 84×100 | A soft pop throws out a cloud of embers that slow, then float up and drift on the heat, twinkling and cooling from white to red as they wink out. |
+| Fire breath | `fire/fire-breath` | loop 0.8s | 104×68 | A roaring cone of fire blowing right: white-hot at the mouth, billows rolling out and widening, edges choking into smoke. |
+| Fire ring | `fire/fire-ring` | one-shot 1.4s | 124×56 | A white flash at the feet, then a ring of flame bursts outward along the ground, burns down as it spreads and leaves a smouldering scorch. |
+| Fire tornado | `fire/fire-tornado` | loop 1s | 64×108 | A spinning column of fire: a funnel narrow at the ground and wide at the top, bright bands spiralling round it, embers orbiting, a swirl at its foot. |
+| Fireball | `fire/fireball` | loop 0.6s | 88×36 | A fireball flying right: a churning white-hot head, flames streaming back into a torn tail, smoke puffs and sparks left behind. |
+| Flame pillar | `fire/flame-pillar` | one-shot 1.8s | 64×116 | The ground cracks and glows, a column of fire erupts white-hot, roars at full height spewing embers, then collapses back into the floor in smoke. |
+| Flamethrower | `fire/flamethrower` | loop 1.2s | 112×48 | A pressurised jet shooting right: a blue-white core at the nozzle, surges racing down a drooping stream, a sputter, burning drips. |
+| Ground fire | `fire/ground-fire` | loop 1.6s | 72×40 | A patch of burning ground: a charred scorch with glowing cracks and a row of low flames that dance up, shrink away and flare again. |
+| Ignite | `fire/ignite` | one-shot 1.8s | 44×64 | A spark sputters twice and catches: the flame whooshes up white-hot, settles into a lively burn, then dwindles out in a curl of smoke. |
+| Inferno wall | `fire/inferno-wall` | loop 1.2s | 136×96 | A wide wall of tall fire: a white-hot base, a ragged crest of tongues tearing upward, sparks and smoke pouring off the top. |
+| Meteor | `fire/meteor` | one-shot 1.8s | 128×116 | A burning rock streaks down from the top left trailing fire and smoke, slams into the ground in a white flash, throws rock and flame, leaves a glowing crater. |
+| Molotov | `fire/molotov` | one-shot 2.8s | 108×68 | A lit bottle tumbles in and shatters: glass flies, burning fuel splashes and races along the floor, flares up, then burns down to smoke and a scorch. |
+| Spirit flame | `fire/spirit-flame` | loop 2.4s | 40×60 | A ghostly blue-teal flame floating in the air: a slow wave running up its wispy tail, curls breaking off and drifting away, motes rising. |
+| Torch | `fire/torch` | loop 1.2s | 36×64 | A wall torch: a licking flame on a wooden handle, rising embers, warm flickering light. |
+
+## explosions
+
+blasts, smoke, fireworks, mushroom clouds.
+
+| effect | id | | size | what it does |
+|---|---|---|---|---|
+| Barrel explosion | `explosions/barrel-explosion` | one-shot 2.5s | 128×124 | An explosive barrel shudders and spits flame, then blows: a white flash, a tall fireball under black smoke, staves and the lid flying, fuel left burning. |
+| Big explosion | `explosions/big-explosion` | one-shot 2.8s | 136×148 | A three-stage blast: a white flash, a fireball that swells twice more as it climbs into a rising column of smoke, heavy debris trailing smoke, a shockwave. |
+| Cartoon POW | `explosions/cartoon-pow` | one-shot 0.9s | 92×68 | A comic-book hit: a jagged burst star slams in with a shake and boiling edges, POW! drops in letter by letter, action lines fly, then it all snaps away. |
+| Chain explosions | `explosions/chain-explosions` | one-shot 1.7s | 160×76 | A string of small blasts marching right along the ground, each a beat after the last and a little bigger, flashes popping, smoke stacking up behind. |
+| Dirt explosion | `explosions/dirt-explosion` | one-shot 1.9s | 108×92 | A ground blast: a flash of fire, a fountain of dirt and dust thrown up in a V, clods arcing out and thudding down, a crater left in the floor. |
+| Dust cloud | `explosions/dust-cloud` | one-shot 1.9s | 124×44 | A cloud of dust kicked up along the ground: puffs roll out to both sides, slow, swell and drift, then settle back onto the floor and thin away. |
+| Firework burst | `explosions/firework-burst` | one-shot 2.4s | 108×120 | A shell bursts into a sphere of coloured stars around a gold core: they streak out, slow, droop on fading trails and crackle as they fall and wink out. |
+| Firework rocket | `explosions/firework-rocket` | one-shot 2.9s | 96×144 | A rocket fizzes off the ground and climbs on a sparkling trail, slows at the top, and bursts into a palm of drooping golden fronds that glitter as they fall. |
+| Gas explosion | `explosions/gas-explosion` | one-shot 1.7s | 144×80 | A spark finds the gas: a whoosh of fire rolls out sideways along the floor, a curling front racing right, burning out behind itself into rising smoke. |
+| Grenade | `explosions/grenade` | one-shot 2.3s | 104×80 | A grenade is lobbed in, bounces once, rolls to a stop and fizzes, then goes off: a flash, a squat fireball, shrapnel streaks, dust and a scorch. |
+| Implosion | `explosions/implosion` | one-shot 1.4s | 84×84 | Everything is sucked in: streaks and rings rush toward a darkening core that crushes down to a point, a beat of stillness, then a tiny pop. |
+| Mine blast | `explosions/mine-blast` | one-shot 1.9s | 88×124 | A buried mine blinks red twice and arms, then fires a narrow jet of fire and dirt straight up; clods rain back down and a crater smokes in the floor. |
+| Nuke | `explosions/nuke` | one-shot 4.4s | 176×172 | A blinding white flash, then a fireball lifts off on a rising stem and rolls into a mushroom cloud, cooling to smoke as a ring of dust surges out along the ground. |
+| Plasma explosion | `explosions/plasma-explosion` | one-shot 0.95s | 104×104 | A blue-white energy blast: a white core flash, a crackling plasma sphere that swells and hollows out, three shock rings, arcs of lightning, plasma motes. |
+| Small explosion | `explosions/small-explosion` | one-shot 1.2s | 84×88 | A quick blast: a white flash frame, a lumpy fireball that cools from the edges into rising smoke, a shockwave, sparks and debris. |
+| Smoke puff | `explosions/smoke-puff` | one-shot 0.75s | 60×52 | A cartoon poof: round outlined puffs pop out with a bounce, drift apart and blink away one by one, with speed lines and a couple of twinkles. |
+
+## water
+
+splashes, falls, fountains, waves.
+
+| effect | id | | size | what it does |
+|---|---|---|---|---|
+| Bubbles | `water/bubbles` | loop 2.4s | 40×64 | Underwater bubbles rise and wobble, big ones faster and squashier, beside a fizzing chain of tiny ones; each pops into a ring of specks. |
+| Drip | `water/drip` | loop 1.8s | 32×72 | A drop swells under a wet ledge, stretches, lets go, falls and plinks into a puddle: droplets hop up and a ring runs out. |
+| Fountain | `water/fountain` | loop 1.2s | 72×72 | A stone basin with a jet shooting up the middle; it blooms at the top and falls back in arcs of droplets that splash and ring the pool. |
+| Geyser | `water/geyser` | one-shot 2.6s | 80×112 | The ground burbles, then a column of water blasts skyward with a churning white head, rains droplets all around, and sinks back into a draining puddle. |
+| Puddle step | `water/puddle-step` | one-shot 0.7s | 64×32 | A foot slaps down in a puddle: a white slap, two low fans of water flung out sideways, droplets pattering down and rings running out. |
+| Rain splash | `water/rain-splash` | loop 1.2s | 80×44 | Rain on the ground: slanted drops hit and burst into tiny crowns, flick droplets and leave rings that spread and fade. |
+| Ripples | `water/ripples` | loop 2s | 80×24 | Rings spread over still water from a bobbing point: bright crests over dark troughs, slowing and breaking into dashes as they fade. |
+| Splash | `water/splash` | one-shot 1.2s | 84×52 | A drop plunges into water: a white flash, a spiky crown leaps up and sheds droplets, a jet bounces back, rings spread. |
+| Steam vent | `water/steam-vent` | loop 1.6s | 56×88 | A floor grate hisses: a white jet spits up, then steam billows out in a widening plume that leans downwind and wears away, with wisps between. |
+| Tidal wave | `water/tidal-wave` | one-shot 2.2s | 128×80 | A towering wall of water rolls right across the screen: a white crest curling over a dark face, spray torn off the top, foam boiling at its foot. |
+| Water jet | `water/water-jet` | loop 0.5s | 96×32 | A pressurised stream blasts right from a nozzle: bright streaks race down a wobbling beam that breaks into blobs and spray at the end. |
+| Water orb | `water/water-orb` | loop 2s | 52×52 | A floating sphere of water that bobs and jiggles, a current swirling inside it, a hard shine on top and droplets circling it. |
+| Waterfall | `water/waterfall` | loop 1s | 64×84 | A sheet of water pours over a lip and streaks down into a churning band of white foam, throwing spray and drifting mist. |
+| Wave crash | `water/wave-crash` | one-shot 1.6s | 100×80 | A wave swells and rolls right, its lip curls over into a tube and slams down: a white flash, a plume of spray and foam that boils away. |
+| Whirlpool | `water/whirlpool` | loop 2s | 64×64 | A top-down vortex: foam streaks spiral into a dark eye, a churning white rim, flecks of foam sucked in faster and faster. |
+
+## ice
+
+spikes, novas, freezing, shattering.
+
+| effect | id | | size | what it does |
+|---|---|---|---|---|
+| Blizzard vortex | `ice/blizzard-vortex` | loop 1.6s | 80×92 | A snow tornado: a swaying funnel striped with spiralling bands, flakes whipping round it in front and behind, powder churning at its foot. |
+| Cold mist | `ice/cold-mist` | loop 4s | 128×32 | Low freezing fog rolls along the floor in two layers drifting right at different speeds, thick at the ground, wispy on top, with ice glints winking in it. |
+| Freeze | `ice/freeze` | one-shot 2.4s | 64×52 | Frost creeps up the character from the feet, an ice block snaps shut around them, glints, cracks, then bursts apart into shards. |
+| Frost breath | `ice/frost-breath` | loop 1s | 104×44 | An icy gust blows right in a widening cone: frost puffs swell and tear apart, streaks of wind race past and ice crystals tumble and twinkle. |
+| Frost nova | `ice/frost-nova` | one-shot 1.3s | 128×64 | A white flash at the feet, then a ring of ice crystals bursts outward across a frosting floor, slows, shatters into spinning shards and melts away. |
+| Frozen ground | `ice/frozen-ground` | one-shot 2.6s | 128×32 | Frost creeps out across the floor in feathery fingers, little crystals sprout as it passes and glint; then it all goes glassy, wet and melts away. |
+| Hail impact | `ice/hail-impact` | loop 1.2s | 80×48 | Hailstones pelt the ground at a slant: each hits with a white crack and a puff of powder, bounces, hops, and melts away; some burst into chips. |
+| Ice crystal | `ice/ice-crystal` | loop 2.4s | 48×64 | A floating six-sided ice crystal turns slowly and bobs: its facets catch the light in turn, a shine sweeps across, a star winks at its tip, motes circle. |
+| Ice lance | `ice/ice-lance` | loop 0.6s | 96×28 | A faceted spear of ice flies right: a glint racing down its shaft, frozen fins at the tail and a trail of frost puffs, wind lines and twinkling crystals. |
+| Ice shatter | `ice/ice-shatter` | one-shot 1.2s | 96×56 | A block of ice cracks, shudders and bursts: a white frame, then shards spin out, bounce once on the floor and skid to nothing in a haze of ice dust. |
+| Ice spikes | `ice/ice-spikes` | one-shot 1.5s | 144×64 | A row of ice spikes bursts out of the ground one after another to the right, each taller than the last, then shatters into tumbling shards. |
+| Icicle fall | `ice/icicle-fall` | one-shot 1.4s | 64×88 | An icicle trembles, cracks loose, drops like a dart and smashes point first: a white burst, shards flung up in a V, frost dust settling. |
+| Snowflake burst | `ice/snowflake-burst` | one-shot 1.4s | 76×76 | A white pop, then big six-armed snowflakes spring out with a bounce, spin away and slow, twinkle and shrink to nothing among drifting specks. |
+
+## lightning
+
+strikes, arcs, coils, storms.
+
+| effect | id | | size | what it does |
+|---|---|---|---|---|
+| Ball lightning | `lightning/ball-lightning` | loop 2.4s | 64×48 | A fizzing ball of charge drifts on a wandering path, trailing a fading wake, its shell spitting little arcs and now and then a long lash. |
+| Chain lightning | `lightning/chain-lightning` | one-shot 0.66s | 112×48 | A bolt leaps from the hand to a target, then on to the next and the next, each hit flashing as the arcs behind it flicker and crumble. |
+| Charge up | `lightning/charge-up` | one-shot 1.25s | 80×80 | Sparks and arcs are drawn in to a point, the core swelling and crackling, ripples closing in faster and faster; a white flash, then it all bursts out as bolts. |
+| Electric field | `lightning/electric-field` | loop 1.2s | 72×32 | A live patch of floor: a humming tinted ellipse where little arcs skitter along the ground, static hairs flicker up and sparks hop. |
+| Electrified | `lightning/electrified` | loop 1.2s | 40×44 | Static crawls over the body: short arcs jump between points on the silhouette, sparks spit off, and every so often the whole outline flares. |
+| Lightning dash | `lightning/lightning-dash` | one-shot 0.52s | 112×40 | A dash to the right on a streak of lightning: a white-hot head tears ahead, the bolt behind it crackles and crumbles from the tail, sparks burst where it lands. |
+| Lightning strike | `lightning/lightning-strike` | one-shot 1s | 80×120 | A bolt cracks down from the sky: a faint leader, a white return stroke with branches, a re-strike, sparks skipping off a smouldering scorch. |
+| Plasma ball | `lightning/plasma-ball` | loop 2s | 48×60 | A glass globe on a stand: pink-violet tendrils wander from the hot core out to the glass, their feet flaring where they touch it. |
+| Spark arc | `lightning/spark-arc` | loop 1.2s | 48×64 | A climbing arc between two rods: it snaps on at the narrow gap, rises as it stretches and bows, then tears apart at the top in a spray of sparks. |
+| Static pops | `lightning/static-pops` | loop 1.6s | 48×40 | Little static discharges snap here and there: a white tick, a tiny zigzag or a short jump between two points, a pinprick of sparks, gone in a blink. |
+| Storm cloud | `lightning/storm-cloud` | loop 2.4s | 88×72 | A brooding thundercloud churning in the rain: lightning flickers inside it, lights it up from within, and once a cycle a bolt forks down out of it. |
+| Tesla coil | `lightning/tesla-coil` | loop 1.6s | 80×88 | A copper-wound coil under a steel crown: branching arcs lash out from the crown every few frames, now and then grounding with a white flash. |
+| Thunderclap | `lightning/thunderclap` | one-shot 0.55s | 96×96 | A crack of thunder in the air: a blinding flash, bolts bursting outward, a heavy shock ring that thins and shatters into arcs, sparks streaking off. |
+| Zap hit | `lightning/zap-hit` | one-shot 0.5s | 56×56 | An electric hit: a white-hot star of zigzag spikes snaps out, re-forms smaller each beat as a ring races off, then kinked sparks scatter and fizzle. |
+
+## sci-fi
+
+holograms, shields, scanners, warps.
+
+| effect | id | | size | what it does |
+|---|---|---|---|---|
+| Cloak | `scifi/cloak` | one-shot 1.1s | 40×40 | Stealth engaging: the outline flares, a bright seam climbs the body turning it to dark rippling glass, a shimmer clings to the edge, then even that fades. |
+| Data stream | `scifi/data-stream` | loop 2s | 48×58 | Columns of code fall through a dark panel: bright heads drop cell by cell, trails of glyphs flicker and change behind them and fade out. |
+| EMP blast | `scifi/emp-blast` | one-shot 0.9s | 96×96 | An electromagnetic pulse: a white pop, then a bubble of interference swells out, strobing and crackling over its skin, and shorts out into dead pixels. |
+| Energy core | `scifi/energy-core` | loop 1.6s | 60×68 | A reactor core held in a steel cage: a swirling ball of light swells on every beat and throws off a shock ring, two tilted rings orbit it, arcs jump to the cage. |
+| Force field | `scifi/force-field` | loop 2s | 88×60 | A hex-plated energy dome over the floor: faint cells shimmer, the rim glows, and a shot from the right strikes it in a white flare that ripples across the plates. |
+| Glitch | `scifi/glitch` | loop 1.6s | 48×44 | A body breaking up like a bad signal: red and cyan ghosts split off it, bands of it tear sideways, junk blocks flicker round it in bursts. |
+| Hologram | `scifi/hologram` | loop 2.4s | 48×64 | A floor projector throws a cone of light; in it a wireframe cube turns, cut by scanlines, a bright sweep running down it, glitching now and then. |
+| Jetpack | `scifi/jetpack` | loop 1s | 48×76 | Twin thrusters blast straight down: white-hot cores with flickering shock diamonds inside ragged orange flames, smoke billowing out below. |
+| Laser grid | `scifi/laser-grid` | loop 2.4s | 80×56 | Security lasers between two posts: red beams slide up and down while two more sweep the floor from the post tops; drifting dust sparkles where it crosses them. |
+| Radar ping | `scifi/radar-ping` | loop 2.4s | 56×56 | A round amber scope: the sweep turns, its afterglow trailing; blips flare as it passes and slowly die, each pinging out a small ring. |
+| Scanner | `scifi/scanner` | loop 1.6s | 44×40 | A scan line sweeps down the body and back up inside blinking target brackets, lighting the slice it crosses and leaving a wireframe outline in its wake. |
+| Teleporter pad | `scifi/teleporter-pad` | loop 1.6s | 56×72 | A metal pad on the floor hums with light: rings lift off it one after another, shrinking and dimming as they rise through a soft column full of motes. |
+| Tractor beam | `scifi/tractor-beam` | loop 2s | 64×84 | A hovering emitter fans a beam down to the floor; rungs of light climb it and loose rocks and grit tumble upward into the lens. |
+| Warp in | `scifi/warp-in` | one-shot 1.3s | 48×84 | A column of light slams down and hums, rings running down it; it narrows to a sparkling silhouette that sets into the body from the head down. |
+| Warp out | `scifi/warp-out` | one-shot 1.2s | 48×84 | A body flares into a silhouette of light, comes apart into motes from the feet up, and they stream up a thin beam that snaps shut with a glint. |
+
+## melee
+
+slashes, smears, cleaves, combos.
+
+| effect | id | | size | what it does |
+|---|---|---|---|---|
+| Axe chop | `melee/axe-chop` | one-shot 0.6s | 68×54 | A short, heavy chop: a thick steel arc drops in front of the fighter, bites with a thunk and a flash, and wood chips tumble out of the cut. |
+| Claw swipe | `melee/claw-swipe` | one-shot 0.5s | 60×48 | Three claws rake down and back in front of the fighter: white tips tear through, three red gashes hold a beat and close, flecks fly. |
+| Counter flash | `melee/counter-flash` | one-shot 0.4s | 68×44 | A parry turned counter: a razor-thin white cross flares where the blow is caught, twinkles to an X, and a quick return cut flicks out. |
+| Dagger flurry | `melee/dagger-flurry` | one-shot 0.6s | 60×48 | A flurry of quick knife cuts: small sharp crescents flick in and out at all angles in front of the fighter, the last one biggest. |
+| Double slash | `melee/double-slash` | one-shot 0.5s | 64×52 | Two quick cuts cross in an X in front of the fighter: down, then up, a white flash where they meet, then the X dissolves. |
+| Hammer smash | `melee/hammer-smash` | one-shot 0.8s | 88×54 | A hammer drops straight down in front of the fighter: a block-wide smear, a white slam on the floor, a dome of force, rocks flung out and dust. |
+| Heavy cleave | `melee/heavy-cleave` | one-shot 0.75s | 92×58 | A two-handed overhead cleave: a glint behind the head, a thick arc that speeds up as it falls, and a slam into the floor that throws dust and grit. |
+| Iaido cut | `melee/iaido-cut` | one-shot 0.9s | 88×36 | A dash cut: the fighter arrives in a white streak that leaves one long line hanging in the air; a beat later the line flashes and splits open. |
+| Punch combo | `melee/punch-combo` | one-shot 0.7s | 60×44 | Jab, jab, straight: two quick puffs pop in front of the fighter, then a bigger straight lands with a burst of rays and a ring. |
+| Scythe reap | `melee/scythe-reap` | one-shot 0.9s | 72×68 | A slow, huge reap: a dark crescent with a pale ghostly edge hangs in the air a beat, then tears away and leaves its ghost to rise, waver and fade. |
+| Spear sweep | `melee/spear-sweep` | one-shot 0.7s | 92×40 | A long polearm swept low around the front: a wide flat arc skims the floor from behind to the far side, kicking up a wake of dust. |
+| Spin slash | `melee/spin-slash` | one-shot 0.45s | 76×48 | A full-circle spin attack: the blade sweeps a ring around the fighter's waist, front then back, and the ring flares out and dissolves. |
+| Sword slash | `melee/sword-slash` | one-shot 0.4s | 72×68 | A fast crescent smear: the white edge whips through in four frames, the tail catches up and dissolves, glints fly off. |
+| Thrust | `melee/thrust` | one-shot 0.4s | 76×40 | A piercing stab: a narrow lance of streaks shoots out in two frames, a sharp star flashes at the tip, speed lines and sparks run on past it. |
+| Uppercut | `melee/uppercut` | one-shot 0.45s | 56×62 | A rising punch: a swoosh hooks up from the hip past the face, and a fat comic star bursts where the fist lands up high. |
+| Whip crack | `melee/whip-crack` | one-shot 0.55s | 92×54 | A whip lashes out to the right: a loop rolls down its length, the tip snaps straight with a white crack and sparks, then the lash sags and fades. |
+
+## impacts
+
+hit sparks, shockwaves, landings.
+
+| effect | id | | size | what it does |
+|---|---|---|---|---|
+| Blunt hit | `impacts/blunt-hit` | one-shot 0.5s | 56×48 | A dull, heavy thud: no sparks, just a dim flash, fat comic impact dashes that pop out and pull back, and a ring of dust that rolls out and settles. |
+| Bullet impact | `impacts/bullet-impact` | one-shot 0.6s | 48×46 | A round hits a wall on the right: a flat white flash, sparks sprayed back in a cone, a puff of grit, chips falling, a hot pock mark cooling. |
+| Combo hit | `impacts/combo-hit` | one-shot 0.8s | 56×56 | A rapid combo lands on one target: four quick crossing slash marks with spark pops, each a little bigger, then a beat and a big finisher with a ring. |
+| Critical hit | `impacts/crit-hit` | one-shot 0.5s | 72×72 | A loud crit: a jagged red-to-white comic starburst punches in with overshoot, shudders, then breaks into a ring, streaks and shards. |
+| Ground slam | `impacts/ground-slam` | one-shot 1.2s | 128×64 | A huge slam: the floor flashes and cracks, a flat shockwave races out with a wall of dust on it, rock chunks erupt, bounce and settle in the dust. |
+| Heavy landing | `impacts/heavy-landing` | one-shot 1s | 80×32 | Something heavy lands: the floor dents and cracks out both ways, two rings of dust spread over the floor one after the other, pebbles hop. |
+| Hit flash | `impacts/hit-flash` | one-shot 0.3s | 40×36 | Taking damage: the body flashes solid white, then red, blinks white once more and cools off, while comic hit lines jab in at it. |
+| Hit spark | `impacts/hit-spark` | one-shot 0.3s | 44×44 | A generic hit: a thin white star pops to full size in a frame and shrinks away while streak sparks spray out and cool. |
+| Impact frame | `impacts/impact-frame` | one-shot 0.2s | 96×64 | An anime impact frame: two frames of white with black burst lines rushing at the hit, two frames inverted, then the lines snap back out and vanish. |
+| Knockback wind | `impacts/knockback-wind` | one-shot 0.6s | 80×40 | A blow lands from the left and the air bursts: a pale shock cone rolls out to the right over the body, speed lines stream past, dust kicks off the feet. |
+| Parry | `impacts/parry` | one-shot 0.5s | 62×58 | Two blades slam together in an X: a white flash at the cross, a fan of gold sparks that arc and cool, a thin ring snapping outward. |
+| Ricochet | `impacts/ricochet` | one-shot 0.4s | 72×40 | A tracer streaks down into the floor, flashes, and skips off up-right in a long fading streak, kicking up sparks and a pinch of dust. |
+| Shield block | `impacts/shield-block` | one-shot 0.6s | 64×48 | A hit lands on a half-dome energy shield: it flares white, a ripple runs out along the rim from the hit, sparks glance off, the dome dims away. |
+| Stomp dust | `impacts/stomp-dust` | one-shot 0.6s | 64×24 | A landing kicks dust out both ways: a flat skirt splits into two rolling clusters of puffs that skid out along the floor, lift a little and thin away. |
+
+## projectiles
+
+bullets, rockets, lasers, arrows.
+
+| effect | id | | size | what it does |
+|---|---|---|---|---|
+| Arrow | `projectiles/arrow` | loop 0.4s | 56×15 | An arrow in flight: a wooden shaft with a steel head, fletching that flutters, wind streaks peeling back along it and a wake behind the nock. |
+| Arrow hit | `projectiles/arrow-hit` | one-shot 1.4s | 60×32 | An arrow streaks in and thunks into the floor, kicking up dirt, quivers back and forth as the wobble dies, then fades. |
+| Boomerang | `projectiles/boomerang` | one-shot 1.3s | 104×50 | A boomerang whirls out in a wide loop, hangs at the far turn, swings back underneath and is caught, a dotted arc of its path fading behind. |
+| Bullet tracer | `projectiles/bullet-tracer` | loop 0.4s | 58×15 | A tracer round: a white-hot slug, a long burning streak that flickers and breaks into dashes as it cools, sparks peeling off behind. |
+| Cannonball | `projectiles/cannonball` | one-shot 1.6s | 128×52 | Cannon fire: a round blast of flame at the muzzle, the iron ball arcing away trailing a wisp, and a big cloud of gunsmoke rolling out and up. |
+| Energy disc | `projectiles/energy-disc` | loop 0.4s | 48×30 | A spinning sawblade of blue energy: a white-hot rim of hooked teeth whirling round a hollow core, motion arcs trailing and sparks flung off. |
+| Signal flare | `projectiles/flare` | one-shot 3.2s | 64×104 | A flare streaks up on a thin smoke trail, bursts into a blinding red star at the top, then sinks slowly, dripping sparks under a column of smoke. |
+| Homing missile | `projectiles/homing-missile` | one-shot 1.9s | 128×80 | A missile launches, curves up and over and dives onto a locked target, a white smoke trail hanging along its path, then a fiery hit. |
+| Laser bolt | `projectiles/laser-bolt` | loop 0.3s | 52×15 | A red blaster bolt: a white-cored capsule with a hard red rim that throbs, a shimmering tail, afterimage dashes dropping behind. |
+| Magic missile | `projectiles/magic-missile` | one-shot 1.05s | 112×48 | An arcane bolt darts out, weaving toward its mark in tightening swerves and shedding twinkling sparkles, then bursts into a star of light. |
+| Pistol muzzle flash | `projectiles/muzzle-pistol` | one-shot 0.45s | 40×28 | One white-hot frame of spiky flash, a fireball tearing off forward and cooling, a few sparks and a small curl of smoke. |
+| Shotgun blast | `projectiles/muzzle-shotgun` | one-shot 0.8s | 80×46 | A wide cone of flame with a white throat, a spray of pellets streaking out, burning powder and a heavy cloud of smoke that rolls forward and rises. |
+| SMG burst | `projectiles/muzzle-smg` | loop 0.4s | 40×28 | Rapid fire: four shots a loop, each flash a different spiky star for a frame then a gutter, sparks spitting and a stream of smoke wisps. |
+| Plasma shot | `projectiles/plasma-shot` | loop 0.6s | 52×23 | A churning teardrop of green plasma, white-hot in the head, its tail tearing into gooey droplets that shrink and boil away behind it. |
+| Rocket | `projectiles/rocket` | loop 0.6s | 100×30 | A rocket in flight: a roaring jet flickering out of the nozzle, a billowing smoke trail streaming back and spreading, sparks spat into it. |
+| Shuriken | `projectiles/shuriken` | loop 0.4s | 46×22 | A four-point throwing star spinning fast, its blades lit and shaded by turns, smears trailing each tip and wind streaks behind. |
+| Sniper trail | `projectiles/sniper-trail` | one-shot 1.3s | 128×24 | A hitscan shot: a blinding line across the canvas for a frame, a thin trace that cools, then a twisted smoke wake that loosens, drifts and breaks apart. |
+
+## spawn & death
+
+poofs, portals, souls, shatters.
+
+| effect | id | | size | what it does |
+|---|---|---|---|---|
+| Coin drop | `spawn/coin-drop` | one-shot 2s | 84×52 | Loot: the enemy goes poof and a spray of spinning gold coins arcs out, bounces on the floor, settles with a glint, then blinks away. |
+| Disintegrate | `spawn/disintegrate` | one-shot 1.9s | 64×50 | The character flashes white, then comes apart pixel by pixel from the head down: each bit lights up, lifts off on the wind and winks out. |
+| Dissolve burn | `spawn/dissolve-burn` | one-shot 2s | 48×56 | Burned away from the feet up: a ragged ember line climbs the body, charring it black just ahead, flames licking up, sparks and ash rising off. |
+| Egg hatch | `spawn/egg-hatch` | one-shot 1.9s | 52×56 | A speckled egg rocks in three nervous bursts, cracking a little more each time, then pops: the cap flies off in a flash of light and shell bits. |
+| Ghost out | `spawn/ghost-out` | one-shot 1.8s | 40×60 | A little sheet ghost pops up out of the fallen, its skirt rippling, sways upward on a lazy wave and fades out, dropping pale wisps. |
+| Poof | `spawn/poof` | one-shot 0.8s | 52×42 | A cartoon poof: a ring of fat smoke balls pops out with an overshoot behind a white flash and speed lines, puffs up, then shrinks away ball by ball. |
+| Respawn beam | `spawn/respawn-beam` | one-shot 1.5s | 48×88 | A beam slams down onto the spawn point, the character is written in from the feet up as glowing scanlines, flashes white and steps out as the beam closes. |
+| Shatter death | `spawn/shatter-death` | one-shot 1.8s | 84×48 | Frozen solid from the feet up, cracks race across the ice statue, then it bursts into tumbling shards that bounce across the floor and melt away. |
+| Skull pop | `spawn/skull-pop` | one-shot 1.5s | 36×48 | A death marker: a skull springs up out of a puff, bobs while its jaw chatters, then floats higher and blinks out. |
+| Soul rise | `spawn/soul-rise` | one-shot 2.1s | 48×80 | The body's outline flares as a pale copy of it lifts out, legs trailing off into a rippling wisp, sways as it climbs and thins away into motes. |
+| Spawn portal | `spawn/spawn-portal` | one-shot 1.7s | 64×64 | A swirling rift tears open flat on the floor, belches a column of violet smoke and sparks as something comes through, then twists shut with a pop. |
+| Summon rise | `spawn/summon-rise` | one-shot 2.2s | 80×60 | A rune circle smoulders on the floor, the ground splits, and a hunched horned shape heaves up out of it in a burst of dust, eyes flaring, before it fades. |
+| Teleport sparkle | `spawn/teleport-sparkle` | one-shot 1.3s | 52×56 | Sparkles spiral in around an empty spot, tightening into a whirling helix, then flash into the character's white silhouette, which fades to reveal them. |
+
+## arcane
+
+portals, runes, missiles, beams.
+
+| effect | id | | size | what it does |
+|---|---|---|---|---|
+| Arcane beam | `arcane/arcane-beam` | loop 0.8s | 132×40 | A continuous violet beam firing right: a white-hot core in a wobbling sheath, two strands twisting round it, a flaring source and a splash at the end. |
+| Arcane missiles | `arcane/arcane-missiles` | one-shot 1.05s | 112×56 | A volley of violet bolts fans out from the hand, curls in on the target and pops one after another. |
+| Arcane orb | `arcane/arcane-orb` | loop 2s | 48×48 | A floating violet orb, energy swirling inside it, bobbing gently while two tilted rings orbit it, passing behind and in front. |
+| Blink in | `arcane/blink-in` | one-shot 0.8s | 48×56 | Teleport arrival: sparks rush to a point, a star pops, a line of light stretches and springs open into the body, the glow drains away. |
+| Blink out | `arcane/blink-out` | one-shot 0.82s | 48×56 | Teleport away: the body lights up from the feet, snaps thin into a tall line of light, shrinks to a point and pops in a star. |
+| Enchant | `arcane/enchant` | loop 1.6s | 40×64 | An enchanted sword: a violet aura licks up the blade, a ring of runes wraps round it and turns, a white sheen runs from hilt to tip. |
+| Glyph burst | `arcane/glyph-burst` | one-shot 1.3s | 84×84 | A big sigil inks itself in the air stroke by stroke, swells and trembles with light, flashes white and blows apart into spinning strokes. |
+| Magic circle cast | `arcane/magic-circle-cast` | one-shot 1.35s | 72×88 | A circle draws itself on the floor stroke by stroke, runes pop in round it, it flashes white and a column of light fires straight up. |
+| Mana burst | `arcane/mana-burst` | one-shot 0.95s | 88×88 | A violet blast: a white flash, a ragged star of energy tearing outward, runes flung to the rim that circle once and pop into sparks. |
+| Mirror images | `arcane/mirror-images` | one-shot 1.3s | 84×40 | Illusion clones slide out from the actor to both sides with afterimages, hold flickering like a bad signal, then pop one by one. |
+| Portal | `arcane/portal` | loop 2s | 64×72 | An oval rift: three spiral arms turning into the dark, a wobbling bright rim, motes spiralling in. |
+| Rune circle | `arcane/rune-circle` | loop 2.4s | 72×52 | A magic circle on the floor: a band of runes turning one way, a triangle the other, a spark racing round the rim, motes rising. |
+| Sparkle swirl | `arcane/sparkle-swirl` | loop 1.6s | 44×46 | Sparkles spiral up around the actor in two twisting ribbons, passing behind and in front, twinkling as they rise and narrow. |
+| Spell charge | `arcane/spell-charge` | loop 1.2s | 56×56 | Energy gathers at a point: motes spiral in, dashed rings collapse onto a throbbing orb that swells as each one lands. |
+| Star fall | `arcane/star-fall` | one-shot 1.4s | 100×88 | Stars rain down on a target area: each streaks in at a slant with a blue tail, bursts on the floor with a flat ring and sparks, and leaves a glint. |
+| Time stop | `arcane/time-stop` | one-shot 1.6s | 76×90 | A clock face rings out, its hands spin and tick slower and slower, then freeze with a white flash, hang drained of color and shatter. |
+
+## holy
+
+heals, halos, pillars of light.
+
+| effect | id | | size | what it does |
+|---|---|---|---|---|
+| Blessing | `holy/blessing` | loop 2.4s | 44×58 | A gentle shower of light over the actor: sparkles drift down through a soft cone of light, twinkling, and wink out at the feet. |
+| Divine shield | `holy/divine-shield` | loop 1.6s | 40×42 | A golden bubble round the actor: two meridians turn on it like a globe, a band of light sweeps the near side, the rim glints and sparkles. |
+| Feather burst | `holy/feather-burst` | one-shot 2.1s | 88×92 | A white puff throws out a spray of feathers that brake hard, then rock from side to side as they drift slowly down and fade. |
+| Halo | `holy/halo` | loop 2s | 32×36 | A golden halo floats over the head, bobbing gently; a glint runs round the ring and now and then a sparkle winks on it. |
+| Heal | `holy/heal` | one-shot 1.3s | 52×56 | A healing burst: the body flashes white then green, plus signs pop up around it and float away, gold motes spiral up, a ring spreads at the feet. |
+| Healing ring | `holy/heal-aoe` | one-shot 1.25s | 100×60 | A healing ring rolls out across the floor; crosses rise wherever it passes and the green glow it leaves fades away. |
+| Holy pillar | `holy/holy-pillar` | one-shot 1.15s | 72×118 | Light from the sky: a thin line drops onto the target, bursts into a white-gold pillar that splashes on the floor, pours a moment, then narrows away. |
+| Purify | `holy/purify` | one-shot 1.3s | 48×56 | Cleansing light: three bright rings sweep up the body one after another, scouring off a dark taint that boils away as smoke, then a clean glint. |
+| Regen | `holy/regen` | loop 1.6s | 44×48 | Steady regeneration: the body beats green twice, a wave of light climbs through it with each beat, small crosses and motes float up beside it. |
+| Resurrection | `holy/resurrection` | one-shot 2.3s | 84×68 | A revive: light falls on the fallen, wings of light unfold behind them, a glow climbs the body, the wings beat once and scatter into feathers. |
+| Smite | `holy/smite` | one-shot 0.85s | 92×108 | A hammer of light slams down on the target: a glint above, a heavy white-gold block crashing in, a flat shockwave, cracks of light and flying stone. |
+| Sunburst | `holy/sunburst` | loop 2.4s | 72×72 | A radiant sun: long and short rays turning slowly round a blazing core, breathing in and out, a ring of light and glints at the tips. |
+
+## shadow
+
+curses, voids, tendrils, souls.
+
+| effect | id | | size | what it does |
+|---|---|---|---|---|
+| Black hole | `shadow/black-hole` | loop 3s | 80×44 | A tilted accretion disk spins around a black shadow, its far side lensed up over the top; debris spirals in and is gone. |
+| Curse | `shadow/curse` | one-shot 1.5s | 48×60 | Dark wisps gather over the head, a violet skull stamps in with a flash, eyes burning, the curse drips down over the target, then the skull crumbles. |
+| Dark explosion | `shadow/dark-explosion` | one-shot 1.4s | 100×100 | Motes are sucked in, then a black star of anti-light rips across a violet flash; a black sphere swells, sheds shards and smoke, and is gone. |
+| Doom mark | `shadow/doom-mark` | loop 3s | 72×40 | A crimson rune burns on the floor: a band of glyphs turning one way, a sigil the other, beating like a slow heart as embers rise. |
+| Eclipse | `shadow/eclipse` | loop 3s | 72×72 | A black moon over a hidden sun: ragged corona streamers turn and breathe, a diamond bead burns on the rim, red flares loop up and fall back. |
+| Grasping hands | `shadow/grasping-hands` | one-shot 1.8s | 84×54 | Shadow arms burst from a black pool, fingers splayed, then clench like claws toward the middle, tremble, and are dragged back under. |
+| Hex sigil | `shadow/hex-sigil` | one-shot 1.9s | 72×72 | A burning pen traces a circle and a six-point star in the air, glyphs pop in at its points, it holds, flares white, then crumbles into motes. |
+| Life steal | `shadow/life-steal` | one-shot 1.5s | 88×44 | A wound bursts open on a target to the right; blood-red orbs pop out, hang a beat, then whip back to the caster, who swells with each one. |
+| Necro skulls | `shadow/necro-skulls` | loop 2.4s | 60×46 | Ghostly green skulls circle a point on a tilted orbit, trailing smoke, jaws chattering, dimming as they swing behind. |
+| Shadow flames | `shadow/shadow-flames` | loop 1.2s | 44×56 | Inside-out fire: a black heart floating in violet flame that burns pale at the edges and tips, tongues tearing off, embers rising. |
+| Shadow step | `shadow/shadow-step` | one-shot 1s | 92×48 | A body-sized blur of shadow whips to the right in a few frames, bursting smoke where it leaves and lands; the trail lingers and thins away. |
+| Shadow tendrils | `shadow/shadow-tendrils` | one-shot 1.7s | 72×60 | A black pool spreads underfoot, tentacles of shadow lash up out of it with violet rims, curl and writhe, then sink back as it closes. |
+| Soul drain | `shadow/soul-drain` | loop 2s | 90×36 | Pale souls are torn from the right and dragged along a funnel of violet streaks into a dark vessel that flares as it feeds. |
+| Void orb | `shadow/void-orb` | loop 1.6s | 48×48 | A ball of pure black with a crawling violet rim; a dark vortex winds into it and bright motes streak in and vanish. |
+
+## status
+
+burning, frozen, poisoned, asleep.
+
+| effect | id | | size | what it does |
+|---|---|---|---|---|
+| Bleeding | `status/bleeding` | loop 1.6s | 36×34 | Dark red drops swell on the body, run a little, let go and spatter on the floor into a small pool; the target flinches red with each tick. |
+| Burning | `status/burning` | loop 1s | 40×50 | Flames lick up the target's outline, tallest off the head and shoulders, tongues curl over the body, embers spit and drift up. |
+| Charmed | `status/charmed` | loop 2s | 44×52 | A heart beats over the target's head, glowing pink on each beat, while little hearts bob up around it, sway and pop. |
+| Confused | `status/confused` | loop 1.8s | 44×48 | A swirl spins over the head while question marks pop up on either side in turn, bounce, wobble and fade. |
+| Cursed | `status/cursed` | loop 2s | 44×52 | Violet wisps curl up off the target and a stain spreads under its feet; twice a loop a skull glitches in over its head and is gone. |
+| Fortified | `status/fortified` | loop 2.4s | 44×40 | Three stone shields circle the target, turning edge-on as they swing round behind it; a sheen runs across them once a beat. |
+| Frozen | `status/frozen` | loop 2s | 40×44 | The target is frosted blue and crusted in ice: crystals jut from its outline, a block grips its feet, a glint hops between shards, frost drifts. |
+| Haste | `status/haste` | loop 0.6s | 52×32 | Striped afterimages shiver behind the target, speed lines stream past it and dust kicks off its heels: it's moving faster than it should. |
+| Invisible | `status/invisible` | loop 1.6s | 36×32 | The target vanishes, leaving only a faint outline that shimmers as a bright band runs down it, a glassy ripple, and a few sparkles. |
+| Marked | `status/marked` | loop 1.4s | 44×40 | Target brackets slam in around the body and lock with a flash, an aim point tightens on the chest, a marker bobs overhead; then it lets go and locks again. |
+| Petrified | `status/petrified` | one-shot 2.4s | 64×44 | Stone creeps up the target from the feet with a crackling edge, holds, splits with a crack, then the shell bursts into tumbling chunks and dust. |
+| Poisoned | `status/poisoned` | loop 2s | 40×44 | Sickly green seeps through the target in slow pulses, darkest parts first; bubbles rise off it and pop, drips fall and splash. |
+| Rage | `status/rage` | loop 1s | 48×54 | A red aura roars up behind the target and swells on every heartbeat; its outline flares, streaks shoot upward and an anger mark pops. |
+| Sleep | `status/sleep` | loop 2.4s | 44×52 | Z letters float up from the sleeper's head one after another, swaying, growing as they rise, fading into the dark. |
+| Slowed | `status/slowed` | loop 2.4s | 44×46 | A clock dial stands behind the target, its rim turning slowly and its hands ticking in heavy steps, while drops of time sink off it. |
+| Stunned | `status/stunned` | loop 1s | 40×40 | Three stars circle the head, passing behind it and in front, twinkling as they turn. |
+
+## nature
+
+poison, vines, thorns, quakes.
+
+| effect | id | | size | what it does |
+|---|---|---|---|---|
+| Acid splash | `nature/acid-splash` | one-shot 1.6s | 72×52 | A gob of acid drops and bursts into a crown, its tips flung off as droplets, then lies as a hissing puddle: bubbles pop, steam curls up, it eats itself away. |
+| Boulder | `nature/boulder` | one-shot 1.3s | 104×60 | A boulder is hurled right in a high arc, spinning, speed lines behind it; it slams into the floor and bursts into tumbling chunks and a cloud of dust. |
+| Earth spike | `nature/earth-spike` | one-shot 1.3s | 72×60 | The floor cracks, then a jagged stone spike rams up in two frames with two smaller shards, throwing chips and dust; it holds, splits, and bursts into falling rubble. |
+| Healing bloom | `nature/healing-bloom` | one-shot 2s | 64×64 | A sprout shoots up and a bud swells and opens into a flower with a glowing heart; a ring of green light pulses out and the petals lift off as glowing motes. |
+| Leaf storm | `nature/leaf-storm` | loop 1.6s | 56×52 | A whirlwind of leaves spirals up around the target: leaves tumble as they orbit behind and in front, pale wind bands sweep round with them. |
+| Poison cloud | `nature/poison-cloud` | loop 2.4s | 76×52 | A low toxic cloud billows on the spot: heavy puffs swell and roll, sickly pale tops over bruised purple shadows, a thin haze, wisps and motes leak out. |
+| Quake | `nature/quake` | one-shot 1.5s | 112×44 | Three jolts: a crack tears along the floor both ways, slabs of ground jump and slam down, pebbles bounce and dust rises along the rift; then it settles. |
+| Root snare | `nature/root-snare` | one-shot 1.6s | 56×44 | Roots crack up out of the floor on both sides, spiral up around the target's legs and waist, cinch tight with a jolt, hold, then split and crumble away. |
+| Sand burst | `nature/sand-burst` | one-shot 1.6s | 80×72 | The floor bulges, then a geyser of sand blasts up: a gushing column, grains raining down in a wide fan, a dust cloud rolling out low, a mound left to slump. |
+| Spore burst | `nature/spore-burst` | one-shot 1.8s | 64×60 | A toadstool pushes up out of the floor, squats, and puffs a cloud of glowing spores that billow up and drift down as it shrivels back into the ground. |
+| Thorns | `nature/thorns` | one-shot 1.1s | 100×44 | A line of bramble thorns punches up out of the floor, one after another to the right, each hooked spike snapping up with a puff of dirt, then sinking back. |
+| Tornado | `nature/tornado` | loop 1.2s | 76×80 | A twisting funnel of wind snakes up from the floor, its bands whipping round; rocks, sticks and leaves orbit it and a dust skirt churns at its foot. |
+| Toxic puddle | `nature/toxic-puddle` | loop 2.4s | 56×40 | A pool of thick green sludge on the floor: fat bubbles swell, wobble and pop with a spit and a ripple, a sheen slides across, little bubbles float up and burst. |
+| Vine whip | `nature/vine-whip` | one-shot 0.8s | 100×64 | A thorny vine bursts from the ground coiled back, then lashes right: the curl unrolls to the tip, which cracks in a spray of sap and leaves, and the vine slithers home. |
+| Wind gust | `nature/wind-gust` | loop 2s | 96×48 | Wind streams right: long pale streaks whip across, some curling into a loop as they go, and leaves tumble along with the gust, bobbing and spinning. |
+
+## weather
+
+rain, snow, fog, aurora.
+
+| effect | id | | size | what it does |
+|---|---|---|---|---|
+| Aurora | `weather/aurora` | loop 8s | 128×72 | Northern lights over a night sky: two curtains ripple and fold, bright green hems fading up into violet, rays shimmering along them. |
+| Blizzard | `weather/blizzard` | loop 2s | 128×72 | A whiteout: snow driven almost flat across the frame in gusts, streaks of near flakes, and pale sheets of blown snow tearing past. |
+| Cherry blossoms | `weather/cherry-blossoms` | loop 4s | 96×64 | Pink petals ride a soft breeze down and across, fluttering and flipping, now and then one catching the light. |
+| Clouds | `weather/clouds` | loop 12s | 128×72 | Moonlit clouds drift across a night sky in three layers: small dim ones far off, big billowing ones close by, each with a bright crown and a flat dark belly. |
+| Falling leaves | `weather/falling-leaves` | loop 6s | 96×64 | Autumn leaves see-saw down through the air, flipping as they swing, settle on the floor for a moment and fade. |
+| Fireflies | `weather/fireflies` | loop 6s | 96×64 | Fireflies wander low over the ground at night, each on its own lazy loop, glowing up and fading out at their own slow rhythms. |
+| Fog | `weather/fog` | loop 12s | 128×72 | Banks of fog roll slowly across in three layers, the far ones slower and darker, a thick pale mist hugging the floor. |
+| God rays | `weather/god-rays` | loop 6s | 96×72 | Shafts of light slant down from a high window into the dark, slowly breathing and swaying; dust motes drift through and flare as they cross the beams. |
+| Hail | `weather/hail` | loop 2s | 96×64 | Hailstones pelt down hard and bounce off the floor in shrinking hops, big ones cracking into chips, then melt away. |
+| Heat haze | `weather/heat-haze` | loop 3s | 96×48 | Hot ground on a still day: wavy heat lines wriggle up off the floor and thin out, and a band of mirage shimmer slides along just above it. |
+| Rain | `weather/rain` | loop 2s | 128×72 | Steady slanted rain in two depths: thin far streaks behind, bright near drops that hit the floor in little crowns and ripples. |
+| Sandstorm | `weather/sandstorm` | loop 2s | 128×72 | A desert wind tears sand across the frame: gritty dust walls roll past in waves, grains streak by at three depths and sand snakes along the floor. |
+| Shooting stars | `weather/shooting-stars` | loop 4s | 128×72 | A quiet starry sky where now and then a meteor streaks down to the right, its trail burning white to blue, flaring once before it winks out. |
+| Snow | `weather/snow` | loop 6s | 128×72 | Snow drifting down in three depths: faint specks far off, single flakes swaying in the middle, big soft flakes floating close by. |
+| Storm | `weather/storm` | loop 3s | 128×72 | Driving rain under a churning cloud deck; a bolt cracks down in a double flash that lights the whole sky, and far off, lightning glows inside the clouds. |
+| Twinkling stars | `weather/twinkling-stars` | loop 4s | 128×72 | A deep starfield: faint dust stars flicker, brighter ones pulse into little crosses, and a few big ones flare out long four-point rays. |
+
+## ui
+
+level ups, numbers, toasts, countdowns.
+
+| effect | id | | size | what it does |
+|---|---|---|---|---|
+| Achievement | `ui/achievement` | one-shot 2.2s | 100×40 | An achievement toast slides in from the right edge with a bump: a gold medal on a ribbon, ACHIEVEMENT UNLOCKED, a shine sweeping across, then it slides away. |
+| Button press | `ui/button-press` | one-shot 1.4s | 72×48 | A cursor glides onto a chunky PLAY button and clicks: the face sinks into its lip and flashes, ripples run out from its edges, then it springs back up. |
+| Checkmark | `ui/checkmark` | one-shot 1.3s | 56×56 | A green badge pops in, a white check draws itself across it in one stroke, the badge thumps bigger and settles while a ring and sparkles fly off. |
+| Coin collect | `ui/coin-collect` | one-shot 1.55s | 96×72 | Coins pop out of a pickup and hop, then streak up into the HUD counter one by one; the icon flashes and the number ticks up and bumps with each. |
+| Combo counter | `ui/combo-counter` | one-shot 1.3s | 88×52 | A slanted x5 COMBO punches in from the left on speed lines, lands with a white flash, a jolt and a ring, pulses, then hops up and blinks out. |
+| Confetti | `ui/confetti` | one-shot 2.6s | 112×88 | Two party poppers fire from the lower corners: bright paper bits and curly streamers shoot up, stall, then flutter down tumbling, flashing their backs. |
+| Countdown | `ui/countdown` | one-shot 2.5s | 76×60 | 3, 2, 1 slam in one by one inside a draining timer ring and zoom away; GO! bursts out white with rays and a shockwave, then blinks off. |
+| Crit number | `ui/crit-number` | one-shot 1.2s | 88×70 | CRIT 128! slams in over a jagged starburst: triple size for a frame, a hard shake, white flashes, speed lines, then the burst folds away. |
+| Damage number | `ui/damage-number` | one-shot 0.9s | 48×40 | A hit number punches out double size in white, snaps down to red, hops up and to the right with an overshoot, then sinks and blinks out. |
+| Error X | `ui/error-x` | one-shot 1.1s | 56×52 | A fat red X slashes in stroke by stroke, white-hot at the tips, then shakes its head no, flashing, with chips flying off; it blinks out. |
+| Exclamation | `ui/exclamation` | one-shot 1.1s | 40×56 | A fat ! springs up over the head: stretched thin on the way up, squashed as it lands, three surprise ticks flicking out; it bobs, then pinches away. |
+| Heal number | `ui/heal-number` | one-shot 1.3s | 44×48 | A green +15 rises in letter by letter and drifts gently upward, little plus signs floating up beside it, then it blinks away. |
+| Health bar hit | `ui/health-bar-hit` | one-shot 1.8s | 76×28 | A segmented health bar takes a hit: it jolts, the lost chunk flashes white and turns to a gold chip that hangs a beat, then drains away to the new value. |
+| Heart lost | `ui/heart-lost` | one-shot 1.1s | 56×52 | A HUD heart takes the hit: it flashes and squashes, a crack zigzags down it, then it snaps in two and the halves tumble apart and fall, shards flying. |
+| Level up | `ui/level-up` | one-shot 1.8s | 96×80 | A golden pillar bursts from the feet, LEVEL UP! drops in letter by letter with a bounce, stars pop, motes rise. |
+| Loading dots | `ui/loading-dots` | loop 1.1s | 48×28 | Three round dots hop one after another: stretched as they leap and fall, round at the top, squashed flat for a beat as they land. |
+| Loading spinner | `ui/loading-spinner` | loop 0.8s | 32×32 | Eight chunky blocks in a ring; a bright head steps round them like a clock hand, its tail cooling down the ramp behind it. |
+| Notification | `ui/notification` | one-shot 1.6s | 56×48 | A gold bell swings hard on its hook and rings, the clapper lagging behind, ping arcs spreading out; a red badge with a 1 pops on its shoulder. |
+| Quest complete | `ui/quest-complete` | one-shot 2.4s | 144×60 | A ribbon banner unrolls from the middle, QUEST COMPLETE types on, a gold seal with a check stamps down with a jolt, three stars pop; then it rolls back up. |
+
+## pickups
+
+coins, gems, chests, potions.
+
+| effect | id | | size | what it does |
+|---|---|---|---|---|
+| Ammo crate | `pickups/ammo-crate` | loop 1.2s | 44×40 | An olive supply crate on the floor, ringed by a pulsing pickup outline with a light chasing round it, a chevron bouncing over it. |
+| Chest open | `pickups/chest-open` | one-shot 2.2s | 88×76 | A treasure chest rattles, light leaking from the seam, then the lid flies back: beams fan up, coins and gems pop out, bounce and twinkle. |
+| Coin spin | `pickups/coin-spin` | loop 1s | 32×36 | A fat gold coin turning on its edge in ten hand-timed poses, bobbing over its shadow, a glint when it faces you. |
+| Collect burst | `pickups/collect-burst` | one-shot 0.6s | 48×48 | The pop when you grab something: a white flash, a thin ring snapping out, eight twinkles thrown wide on a spiral, a pinch of glitter. |
+| Crystal shard | `pickups/crystal-shard` | loop 2s | 40×50 | A tall six-sided crystal turning slowly in the air, lit from within, three splinters orbiting it, behind and in front. |
+| Gem spin | `pickups/gem-spin` | loop 1.6s | 32×40 | A cut ruby turning on its axis: eight facets slide past the light, the crown lit, the pavilion glowing from within, a glint. |
+| Heart pickup | `pickups/heart-pickup` | loop 1s | 36×42 | A plump red heart floating over its shadow, beating lub-dub with a squash on each beat, tiny hearts drifting off it. |
+| Key glint | `pickups/key-glint` | loop 1.6s | 40×40 | A silver key hanging in the air, bobbing and swaying on a slow swing; a glint runs from the bow to the teeth and sparks off the tip. |
+| Loot beam | `pickups/loot-beam` | loop 1.5s | 44×80 | A dropped sword on the floor sends up a pillar of rarity light: bands climb it, motes rise inside, a ring pulses out at its foot. The palette sets the rarity. |
+| Magnet pull | `pickups/magnet-pull` | loop 1.2s | 68×48 | A horseshoe magnet facing right hauls in sparks and tumbling coins: they curve in from a wide fan, speeding up, and flash into the gap between its poles. |
+| Potion | `pickups/potion` | loop 1.5s | 36×48 | A round glass flask of glowing brew floating over its shadow: the surface sloshes with the bob, bubbles rise and pop, wisps curl off the cork. |
+| Power star | `pickups/power-star` | loop 1.2s | 48×52 | A beveled five-point star rocking in the air, swelling on the beat, rays wheeling slowly behind it, twinkles popping around. |
+| Scroll | `pickups/scroll` | loop 2.4s | 40×50 | A spell scroll floating over its shadow: it unrolls with a bounce, its runes light up line by line and shed sparks, then it rolls itself back up. |
+| Trophy | `pickups/trophy` | loop 1.8s | 40×44 | A golden cup on a stepped foot floating over its shadow: polished bands down the bowl, a shine sweeping across it, sparkles winking around. |
+| XP orb | `pickups/xp-orb` | loop 1.6s | 44×40 | A green experience orb looping a lazy figure eight, pulsing as it goes, a tapering comet tail behind it with a twinkle riding it, motes shed. |
+
+## transitions
+
+wipes, irises, dissolves.
+
+| effect | id | | size | what it does |
+|---|---|---|---|---|
+| Blinds | `transitions/blinds` | one-shot 1.4s | 160×90 | Venetian blinds tilt shut slat by slat from the top, light catching each slat's edge, then tilt open again from the bottom. |
+| Burn away | `transitions/burn-away` | one-shot 1.8s | 160×90 | The picture chars and burns in from the edges behind a ragged ember line shedding sparks; then the black burns open from the middle. |
+| CRT off | `transitions/crt-off` | one-shot 1.5s | 160×90 | A tube TV switching off: the picture squeezes into a glowing line, the line into a dot, the dot dies; then it all flicks back on. |
+| Diamond wipe | `transitions/diamond-wipe` | one-shot 1.4s | 160×90 | A lattice of diamonds swells across the screen from left to right with bright growing rims, then shrinks away in the same sweep. |
+| Dither fade | `transitions/dither-fade` | one-shot 1.4s | 160×90 | An old-console fade: chunky ordered dither creeps in from the corners through a deep tint, holds black, then clears from the middle out. |
+| Glitch wipe | `transitions/glitch-wipe` | one-shot 1.3s | 160×90 | Torn bands of cover stutter in from both sides at their own speeds, edges split into pink and cyan, data slivers flicker; then they tear back out. |
+| Iris | `transitions/iris` | one-shot 1.5s | 160×90 | A cartoon iris: the circle closes fast onto a small spotlight, holds a beat, snaps shut, then pops open and widens away. |
+| Pixel dissolve | `transitions/pixel-dissolve` | one-shot 1.4s | 160×90 | The screen breaks into blocks in clumpy random order, each winking in through a dim flash, some with a bright speck; then they wink back out. |
+| Shatter wipe | `transitions/shatter-wipe` | one-shot 2s | 160×90 | A dark pane drops over the screen, cracks race out from an impact with a flash, and the glass breaks into glinting shards that tumble away. |
+| Slash wipe | `transitions/slash-wipe` | one-shot 1.1s | 160×90 | A blade-bright diagonal edge whips across and drags the cover in behind it, throwing sparks; the cover leaves the same way. |
+| Spiral wipe | `transitions/spiral-wipe` | one-shot 1.6s | 160×90 | A glowing spiral arm sweeps clockwise in from the corners and winds the cover shut at the center, then unwinds it from the middle out. |
+| Star iris | `transitions/star-iris` | one-shot 1.5s | 160×90 | A five-point star iris spins shut with a gold rim, twinkles at its tips as it vanishes, then spins back open the other way. |
+
+## critters
+
+slimes, bats, ghosts, frogs.
+
+| effect | id | | size | what it does |
+|---|---|---|---|---|
+| Bat | `critters/bat` | loop 0.9s | 48×34 | A bat flaps in place in four hard wing frames, body bobbing against the beat, ears up, eyes glinting, drifting in a lazy figure eight. |
+| Bird | `critters/bird` | loop 1.2s | 44×40 | A little bluebird flies in place, side on: three hard flaps and a glide, body lifting on each downstroke, tail fanning, beak forward. |
+| Butterfly | `critters/butterfly` | loop 2.4s | 52×44 | A blue butterfly flutters along a lazy looping path: four-frame wingbeats closing to a sliver, dark wing borders with white spots, a little glide. |
+| Crab | `critters/crab` | loop 2s | 56×36 | A red crab scuttles sideways in quick little steps, stops to snap both claws and look about on its eye stalks, then scuttles back. |
+| Eyeball | `critters/eyeball` | loop 3.2s | 40×48 | A floating eyeball darts its gaze left, right and up with snappy holds, blinks with fleshy lids, veins on the white, its nerve tail swaying. |
+| Fish school | `critters/fish-school` | loop 2.4s | 64×44 | A small school of silver fish holds its place in the current: tails beating out of step, each fish nosing about its slot, bubbles rising. |
+| Flying skull | `critters/flying-skull` | loop 1.6s | 48×64 | A flaming skull bobs in the air, jaw chattering, eye sockets lit from inside; fire streams off its crown and embers rise. |
+| Frog | `critters/frog` | loop 1.8s | 48×44 | A fat green frog sits and puffs its throat, crouches, springs straight up with its legs flung out, and lands back in a squat. |
+| Ghost | `critters/ghost` | loop 2s | 36×44 | A little sheet ghost bobs in the air, its scalloped hem rippling, nub arms waving, an O mouth and a slow blink; a cold glow around it. |
+| Jellyfish | `critters/jellyfish` | loop 2.4s | 44×64 | A see-through jellyfish pulses upward: the bell snaps narrow and relaxes wide, tentacles trail and sway behind, frilly arms ripple, a soft inner glow. |
+| Slime | `critters/slime` | loop 1.4s | 40×40 | A glossy slime hops in place: it squashes down to wind up, stretches into the jump, rounds out in the air, splats on landing and wobbles back. |
+| Snake | `critters/snake` | loop 1.6s | 64×32 | A banded snake slithers in place: humps roll back along its body, the head rides high on an S-curved neck and flicks a forked tongue. |
+| Spider | `critters/spider` | loop 2.4s | 36×56 | A round little spider drops on its thread, bounces on the silk like a spring, then climbs back up hand over hand, legs paddling. |
+| Wisp | `critters/wisp` | loop 2s | 44×48 | A will-o'-wisp loops a lazy figure eight: a bright flame-ball with two dot eyes, its cold fire tail licking up behind it, sparks peeling off. |
diff --git a/docs/readme/montage.gif b/docs/readme/montage.gif
new file mode 100644
index 0000000..ba02cb2
Binary files /dev/null and b/docs/readme/montage.gif differ
diff --git a/gallery/app.js b/gallery/app.js
new file mode 100644
index 0000000..2ac1cf6
--- /dev/null
+++ b/gallery/app.js
@@ -0,0 +1,298 @@
+// The gallery: every effect playing live from its own code. Tiles start when they scroll into view; a click
+// opens one effect with its options, a sprite sheet and the code to use it.
+
+import { effects, categories } from "../src/fx/index.js";
+import { createFrame, clearFrame, createFx, composite, backdrop, drawActor, painterFor, stockActor, actorAlphaOf, PAL, BACKDROPS } from "../src/core/index.js";
+
+const REPO = "https://github.com/patch-gg/pixelfx";
+const FX = Object.entries(effects).map(([id, mod]) => {
+ const meta = { fps: 30, bg: "dark", loop: false, duration: 1, tags: [], options: {}, ...mod.meta };
+ return { id, cat: id.split("/")[0], name: meta.name, mod: { ...mod, meta }, meta };
+});
+const reduced = matchMedia("(prefers-reduced-motion: reduce)").matches;
+const $ = (s) => document.querySelector(s);
+function el(tag, props = {}, kids = []) {
+ const e = Object.assign(document.createElement(tag), props);
+ for (const k of [].concat(kids)) e.append(k);
+ return e;
+}
+
+// ---- a live effect on a canvas, at an integer scale that fits the stage
+class Player {
+ constructor(canvas, fx, aspect, pad) {
+ Object.assign(this, { canvas, fx, ctx: canvas.getContext("2d"), opts: {}, flip: false, actor: true, speed: 1, playing: true });
+ this.bg = fx.meta.bg;
+ this.layout(aspect, pad);
+ }
+ // the art-pixel stage: the effect's canvas plus some room, stretched to the tile's aspect; CSS scales it up
+ layout(aspect, pad) {
+ const [w, h] = this.fx.meta.size, [ox, oy] = this.fx.meta.origin;
+ this.W = Math.ceil(Math.max(w * pad, h * pad * aspect));
+ this.H = Math.ceil(this.W / aspect);
+ this.x = Math.floor((this.W - w) / 2) + ox;
+ this.y = Math.floor((this.H - h) / 2) + oy;
+ this.canvas.width = this.W;
+ this.canvas.height = this.H;
+ this.frame = createFrame(this.W, this.H);
+ this.img = this.ctx.createImageData(this.W, this.H);
+ this.setBg(this.bg);
+ this.restart();
+ }
+ setBg(kind) {
+ this.bg = kind;
+ this.bgBuf = kind === "none" ? null : backdrop(kind, this.W, this.H, this.y);
+ this.dirty = true;
+ }
+ restart() {
+ this.inst = createFx(this.fx.mod, { x: this.x, y: this.y, flip: this.flip, ...this.opts });
+ this.acc = 0;
+ this.wait = 0;
+ this.dirty = true;
+ }
+ tick(dt) {
+ const m = this.fx.meta, step = 1 / m.fps;
+ if (this.playing) this.acc = Math.min(this.acc + dt * this.speed, 0.25);
+ let moved = false;
+ while (this.acc >= step) {
+ this.acc -= step;
+ if (!m.loop && this.inst.t >= m.duration) {
+ this.wait += step;
+ if (this.wait > 0.45) this.restart();
+ } else this.inst.update(step);
+ moved = true;
+ }
+ if (moved || this.dirty) this.render();
+ }
+ seek(t) {
+ this.restart();
+ this.inst.update(t);
+ this.render();
+ }
+ render() {
+ const f = clearFrame(this.frame);
+ this.inst.draw(f, "back");
+ const m = this.fx.meta, tt = m.loop ? this.inst.t % m.duration : Math.min(this.inst.t, m.duration);
+ if (m.actor && this.actor) drawActor(painterFor(f).place(this.x, this.y, this.flip), this.inst.options.actor ?? stockActor(), actorAlphaOf(this.fx.mod, tt, this.inst.options));
+ this.inst.draw(f, "front");
+ composite(f, this.img.data, this.bgBuf);
+ this.ctx.putImageData(this.img, 0, 0);
+ this.dirty = false;
+ }
+}
+
+// ---- tiles
+const tiles = [];
+const sections = [];
+function build() {
+ $("#count").textContent = FX.length;
+ const main = $("#grid");
+ for (const c of categories) {
+ const list = FX.filter((f) => f.cat === c.id);
+ if (!list.length) continue;
+ const grid = el("div", { className: "grid" });
+ const sec = el("section", { id: c.id }, [el("div", { className: "section-head" }, [el("h2", { textContent: c.name + "." }), el("p", { textContent: c.blurb })]), grid]);
+ sections.push({ c, sec, list });
+ for (const fx of list) {
+ const cv = el("canvas", { ariaLabel: fx.name });
+ const fig = el("figure", { className: "tile", tabIndex: 0 }, [
+ el("div", { className: "stage" }, cv),
+ el("figcaption", {}, [el("b", { textContent: fx.name }), el("small", { textContent: fx.meta.loop ? "loop" : `${fx.meta.duration}s` })]),
+ ]);
+ const t = { fx, fig, cv, player: null, visible: false, hover: false };
+ fig.addEventListener("click", () => openDetail(fx));
+ fig.addEventListener("keydown", (e) => (e.key === "Enter" || e.key === " ") && (e.preventDefault(), openDetail(fx)));
+ fig.addEventListener("pointerenter", () => (t.hover = true));
+ fig.addEventListener("pointerleave", () => (t.hover = false));
+ grid.append(fig);
+ tiles.push(t);
+ }
+ main.append(sec);
+ }
+ const io = new IntersectionObserver((entries) => {
+ for (const e of entries) {
+ const t = tiles.find((x) => x.fig === e.target);
+ t.visible = e.isIntersecting;
+ if (t.visible && !t.player) {
+ t.player = new Player(t.cv, t.fx, 6 / 5, 1.25);
+ if (reduced) t.player.seek(t.fx.meta.duration * 0.4);
+ }
+ }
+ }, { rootMargin: "200px" });
+ tiles.forEach((t) => io.observe(t.fig));
+}
+
+// ---- filters
+const state = { cat: "all", q: "" };
+function chips() {
+ const box = $("#chips");
+ const mk = (id, label, n) => {
+ const b = el("button", { className: "chip", type: "button" }, [label, el("span", { textContent: n })]);
+ b.dataset.cat = id;
+ b.addEventListener("click", () => setCat(id));
+ box.append(b);
+ };
+ mk("all", "all", FX.length);
+ for (const s of sections) mk(s.c.id, s.c.name, s.list.length);
+}
+function setCat(id, fromHash = false) {
+ state.cat = sections.some((s) => s.c.id === id) ? id : "all";
+ document.querySelectorAll(".chip").forEach((b) => b.setAttribute("aria-pressed", String(b.dataset.cat === state.cat)));
+ if (!fromHash) history.replaceState(null, "", state.cat === "all" ? location.pathname : "#" + state.cat);
+ filter();
+ if (!fromHash) window.scrollTo({ top: 0 });
+}
+function filter() {
+ const q = state.q.trim().toLowerCase();
+ let shown = 0;
+ for (const s of sections) {
+ let any = false;
+ for (const fx of s.list) {
+ const t = tiles.find((x) => x.fx === fx);
+ const hit = (state.cat === "all" || state.cat === s.c.id) && (!q || [fx.id, fx.name, fx.meta.desc, ...fx.meta.tags].join(" ").toLowerCase().includes(q));
+ t.fig.hidden = !hit;
+ any ||= hit;
+ shown += hit;
+ }
+ s.sec.hidden = !any;
+ }
+ $("#none").hidden = shown > 0;
+}
+
+// ---- detail
+let detail = null;
+function openDetail(fx) {
+ const d = $("#detail");
+ const big = $("#big");
+ detail = new Player(big, fx, 16 / 10, 1.6);
+ const m = fx.meta;
+ $("#d-name").textContent = m.name;
+ $("#d-id").textContent = fx.id;
+ $("#d-desc").textContent = m.desc;
+ const frames = Math.round(m.duration * m.fps) + (m.loop ? 0 : 1);
+ $("#d-facts").replaceChildren(
+ ...[["kind", m.loop ? "loop" : "one-shot"], ["length", `${m.duration} s, ${frames} frames at ${m.fps} fps`], ["canvas", `${m.size[0]} × ${m.size[1]} px`], ["tags", m.tags.join(", ")]].flatMap(([k, v]) => [el("dt", { textContent: k }), el("dd", { textContent: v })]),
+ );
+ // controls
+ $("#d-bg").replaceChildren(...BACKDROPS.concat("none").map((b) => btn(b, () => detail.setBg(b), b === m.bg, "bg")));
+ $("#d-speed").replaceChildren(...[0.25, 0.5, 1].map((s) => btn(`${s}×`, () => (detail.speed = s), s === 1, "speed")));
+ const pal = $("#d-pal");
+ pal.replaceChildren(el("option", { value: "", textContent: "its own" }), ...Object.keys(PAL).map((k) => el("option", { value: k, textContent: k })));
+ pal.value = "";
+ $("#d-actor").hidden = !m.actor;
+ $("#d-actor").setAttribute("aria-pressed", "true");
+ $("#d-flip").setAttribute("aria-pressed", "false");
+ $("#d-play").setAttribute("aria-pressed", "true");
+ $("#d-play").textContent = "pause";
+ $("#d-sheet").replaceChildren();
+ code(fx);
+ d.showModal();
+ d.scrollTop = 0;
+}
+function btn(label, fn, on, group) {
+ const b = el("button", { className: "btn", type: "button", textContent: label });
+ b.setAttribute("aria-pressed", String(!!on));
+ b.addEventListener("click", () => {
+ if (group) b.parentElement.querySelectorAll(".btn").forEach((x) => x.setAttribute("aria-pressed", String(x === b)));
+ fn();
+ });
+ return b;
+}
+function code(fx) {
+ const v = fx.id.split("/")[1].replace(/-(\w)/g, (_, c) => c.toUpperCase());
+ const opts = { x: 160, y: 120, ...(detail.opts.palette ? { palette: "[…]" } : {}), ...(detail.flip ? { flip: true } : {}) };
+ $("#d-code").textContent = [
+ `import { createFrame, createFx, composite } from "pixelfx";`,
+ `import * as ${v} from "pixelfx/fx/${fx.id}";`,
+ ``,
+ `const frame = createFrame(320, 180);`,
+ `const fx = createFx(${v}, ${JSON.stringify(opts).replace(/"\[…\]"/, "[…]").replace(/"(\w+)":/g, "$1: ").replace(/,/g, ", ")});`,
+ ``,
+ `// every tick`,
+ `fx.update(dt);`,
+ `fx.draw(frame); // color + light buffers`,
+ `composite(frame, imageData.data, null);`,
+ ].join("\n");
+ $("#d-src").href = `${REPO}/blob/main/src/fx/${fx.id}.js`;
+}
+function sheet() {
+ const fx = detail.fx, m = fx.meta, [w, h] = m.size, n = Math.max(1, Math.round(m.duration * m.fps) + (m.loop ? 0 : 1));
+ const cols = Math.min(n, Math.max(1, Math.ceil(Math.sqrt((n * h) / w)))), rows = Math.ceil(n / cols);
+ const cv = el("canvas", { width: cols * w, height: rows * h }), ctx = cv.getContext("2d");
+ const frame = createFrame(w, h), img = ctx.createImageData(w, h);
+ const inst = createFx(fx.mod, { x: m.origin[0], y: m.origin[1], ...detail.opts, flip: detail.flip });
+ for (let i = 0; i < n; i++) {
+ if (i) inst.update(1 / m.fps);
+ inst.draw(clearFrame(frame));
+ composite(frame, img.data, null);
+ ctx.putImageData(img, (i % cols) * w, Math.floor(i / cols) * h);
+ }
+ const k = Math.max(1, Math.min(4, Math.floor(1100 / (cols * w))));
+ const pic = el("img", { src: cv.toDataURL("image/png"), alt: `${m.name} sprite sheet`, width: cols * w * k, height: rows * h * k });
+ $("#d-sheet").replaceChildren(pic, el("p", { textContent: `${n} frames of ${w} × ${h} px, ${cols} across, ${m.fps} fps, ${m.loop ? "loops" : "plays once"}. Save the image, or run: node tools/render.mjs ${fx.id} --sheet` }));
+}
+function wireDetail() {
+ const d = $("#detail");
+ $("#d-close").addEventListener("click", () => d.close());
+ d.addEventListener("close", () => (detail = null));
+ d.addEventListener("click", (e) => e.target === d && d.close());
+ $("#d-play").addEventListener("click", (e) => {
+ detail.playing = !detail.playing;
+ e.target.setAttribute("aria-pressed", String(detail.playing));
+ e.target.textContent = detail.playing ? "pause" : "play";
+ });
+ $("#d-again").addEventListener("click", () => detail.restart());
+ $("#d-flip").addEventListener("click", (e) => {
+ detail.flip = !detail.flip;
+ e.target.setAttribute("aria-pressed", String(detail.flip));
+ detail.restart();
+ code(detail.fx);
+ });
+ $("#d-actor").addEventListener("click", (e) => {
+ detail.actor = !detail.actor;
+ e.target.setAttribute("aria-pressed", String(detail.actor));
+ detail.dirty = true;
+ });
+ $("#d-seed").addEventListener("click", () => {
+ detail.opts.seed = 1 + Math.floor(Math.random() * 9999);
+ detail.restart();
+ });
+ $("#d-pal").addEventListener("change", (e) => {
+ if (e.target.value) detail.opts.palette = PAL[e.target.value];
+ else delete detail.opts.palette;
+ detail.restart();
+ code(detail.fx);
+ });
+ $("#d-make").addEventListener("click", sheet);
+ $("#d-copy").addEventListener("click", async (e) => {
+ const text = $("#d-code").textContent;
+ try {
+ await navigator.clipboard.writeText(text);
+ e.target.textContent = "copied";
+ } catch {
+ getSelection().selectAllChildren($("#d-code"));
+ e.target.textContent = "selected";
+ }
+ setTimeout(() => (e.target.textContent = "copy"), 1400);
+ });
+}
+
+// ---- the clock
+let last = performance.now();
+function frameLoop(now) {
+ const dt = Math.min(0.1, (now - last) / 1000);
+ last = now;
+ if (detail) detail.tick(dt);
+ else for (const t of tiles) if (t.visible && t.player && !t.fig.hidden && (!reduced || t.hover)) t.player.tick(dt);
+ requestAnimationFrame(frameLoop);
+}
+
+build();
+chips();
+wireDetail();
+$("#q").addEventListener("input", (e) => {
+ state.q = e.target.value;
+ filter();
+});
+setCat(location.hash.slice(1) || "all", true);
+addEventListener("hashchange", () => setCat(location.hash.slice(1) || "all", true));
+requestAnimationFrame(frameLoop);
diff --git a/gallery/fonts/NOTICE.md b/gallery/fonts/NOTICE.md
new file mode 100644
index 0000000..90c9de7
--- /dev/null
+++ b/gallery/fonts/NOTICE.md
@@ -0,0 +1,4 @@
+# Patch Pixel
+
+`PatchPixel-Regular.woff2` is Patch's own typeface, used here for the gallery's display type.
+© 2026 Patch. All rights reserved. It is not covered by this repository's MIT license.
diff --git a/gallery/fonts/PatchPixel-Regular.woff2 b/gallery/fonts/PatchPixel-Regular.woff2
new file mode 100644
index 0000000..9a5f8df
Binary files /dev/null and b/gallery/fonts/PatchPixel-Regular.woff2 differ
diff --git a/gallery/index.html b/gallery/index.html
new file mode 100644
index 0000000..98f127a
--- /dev/null
+++ b/gallery/index.html
@@ -0,0 +1,62 @@
+<!doctype html>
+<html lang="en">
+<head>
+<meta charset="utf-8">
+<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
+<title>pixelfx</title>
+<meta name="description" content="Pixel art effects and animations, every one a small piece of code. Play them, recolor them, export sprite sheets.">
+<link rel="preconnect" href="https://fonts.googleapis.com">
+<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
+<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Funnel+Sans:wght@400;500&family=Red+Hat+Mono:wght@400;500&display=swap">
+<link rel="stylesheet" href="style.css">
+</head>
+<body>
+<!--BODY-->
+<header class="head">
+ <div class="title">
+ <svg class="mark" viewBox="0 0 7 7" shape-rendering="crispEdges" role="img" aria-label="Patch"><rect x="1" y="1" width="6" height="6" fill="#ffffff"/><rect x="0" y="0" width="3" height="3" fill="#f53cd1"/></svg>
+ <div>
+ <h1>pixelfx.</h1>
+ <p class="sub"><span id="count">0</span> pixel art effects, every one a small piece of code.</p>
+ </div>
+ </div>
+ <nav class="links">
+ <a href="https://github.com/patch-gg/pixelfx" target="_blank" rel="noopener">github</a>
+ <a href="https://github.com/patch-gg/pixelfx#the-skill" target="_blank" rel="noopener">claude code skill</a>
+ <a href="https://patch.gg" target="_blank" rel="noopener">patch.gg</a>
+ </nav>
+</header>
+<div class="bar">
+ <div class="bar-in">
+ <div class="chips" id="chips" role="toolbar" aria-label="Categories"></div>
+ <input id="q" type="search" placeholder="search" aria-label="Search effects" autocomplete="off">
+ </div>
+</div>
+<main id="grid"></main>
+<p class="empty" id="none" hidden>Nothing matches that. Try fire, slash or loop.</p>
+<dialog class="detail" id="detail" aria-labelledby="d-name">
+ <div class="sheet">
+ <div>
+ <div class="big"><canvas id="big"></canvas><button class="close" id="d-close" type="button">close</button></div>
+ </div>
+ <div class="info">
+ <h2 id="d-name"></h2>
+ <div class="id" id="d-id"></div>
+ <p id="d-desc"></p>
+ <dl class="facts" id="d-facts"></dl>
+ <div class="controls">
+ <div class="row"><label>play</label><button class="btn" id="d-play" type="button">pause</button><button class="btn" id="d-again" type="button">again</button><span id="d-speed" class="row"></span></div>
+ <div class="row"><label>backdrop</label><span id="d-bg" class="row"></span></div>
+ <div class="row"><label>palette</label><select class="btn" id="d-pal" aria-label="Palette"></select><button class="btn" id="d-seed" type="button">new seed</button></div>
+ <div class="row"><label>show</label><button class="btn" id="d-flip" type="button">mirror</button><button class="btn" id="d-actor" type="button">character</button><button class="btn" id="d-make" type="button">sprite sheet</button></div>
+ </div>
+ <div class="code-head"><span>use it</span><span><a id="d-src" target="_blank" rel="noopener">source</a> · <button class="btn" id="d-copy" type="button">copy</button></span></div>
+ <pre id="d-code"></pre>
+ </div>
+ <div class="sheetout" id="d-sheet"></div>
+ </div>
+</dialog>
+<!--/BODY-->
+<script type="module" src="app.js"></script>
+</body>
+</html>
diff --git a/gallery/style.css b/gallery/style.css
new file mode 100644
index 0000000..8125c46
--- /dev/null
+++ b/gallery/style.css
@@ -0,0 +1,191 @@
+/* layout: one dark play field. A sticky bar (mark, name, categories, search) over a grid of live stages;
+ a sheet opens over the field for one effect. Play is black in every theme, so the page is single-theme. */
+@font-face {
+ font-family: "Patch Pixel";
+ font-weight: 400;
+ font-display: swap;
+ src: url(fonts/PatchPixel-Regular.woff2) format("woff2");
+}
+:root {
+ --ground: #000000;
+ --panel: #111111;
+ --stage: #15131d;
+ --ink: #ffffff;
+ --quiet: #999999;
+ --line: #333333;
+ --patch: #f53cd1;
+ --display: "Patch Pixel", ui-monospace, "SFMono-Regular", monospace;
+ --text: "Funnel Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
+ --mono: "Red Hat Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
+ color-scheme: dark;
+}
+* { box-sizing: border-box; }
+html { background: var(--ground); }
+body {
+ margin: 0;
+ background: var(--ground);
+ color: var(--ink);
+ font: 400 15px/1.5 var(--text);
+ padding-left: max(16px, env(safe-area-inset-left, 0px));
+ padding-right: max(16px, env(safe-area-inset-right, 0px));
+ padding-block: 0 48px;
+}
+body::before {
+ content: "";
+ position: fixed;
+ inset: 0 0 auto;
+ height: env(safe-area-inset-top, 0px);
+ z-index: 10;
+ background: var(--ground);
+}
+a { color: inherit; }
+button, input, select { font: inherit; color: inherit; }
+:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
+
+/* head */
+.head {
+ max-width: 1240px;
+ margin: 0 auto;
+ padding-block: 32px 20px;
+ display: flex;
+ align-items: flex-end;
+ justify-content: space-between;
+ gap: 24px;
+ flex-wrap: wrap;
+}
+.title { display: flex; gap: 18px; align-items: flex-start; }
+.mark { width: 42px; height: 42px; flex: none; image-rendering: pixelated; margin-top: 4px; }
+h1 { margin: 0; font: 400 54px/66px var(--display); letter-spacing: 0; }
+.sub { margin: 4px 0 0; font: 500 17px/1.4 var(--text); color: var(--quiet); text-wrap: balance; }
+.links { display: flex; gap: 20px; font: 500 13px/1 var(--mono); letter-spacing: 0.04em; }
+.links a { text-decoration: none; color: var(--quiet); padding: 6px 0; border-bottom: 1px solid var(--line); }
+.links a:hover { color: var(--ink); border-color: var(--ink); }
+
+/* bar */
+.bar {
+ position: sticky;
+ top: env(safe-area-inset-top, 0px);
+ z-index: 5;
+ background: var(--ground);
+ border-bottom: 1px solid var(--line);
+}
+.bar-in { max-width: 1240px; margin: 0 auto; display: flex; gap: 12px; align-items: center; padding-block: 10px; }
+.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; flex: 1; min-width: 0; padding-block: 2px; }
+.chips::-webkit-scrollbar { display: none; }
+.chip {
+ flex: none;
+ border: 1px solid var(--line);
+ background: none;
+ padding: 6px 10px;
+ font: 500 12px/1 var(--mono);
+ letter-spacing: 0.04em;
+ cursor: pointer;
+ white-space: nowrap;
+}
+.chip span { color: var(--quiet); margin-left: 6px; font-variant-numeric: tabular-nums; }
+.chip:hover { border-color: var(--quiet); }
+.chip[aria-pressed="true"] { background: var(--ink); color: var(--ground); border-color: var(--ink); }
+.chip[aria-pressed="true"] span { color: #555; }
+#q {
+ flex: none;
+ width: 180px;
+ max-width: 40vw;
+ background: none;
+ border: 1px solid var(--line);
+ padding: 6px 10px;
+ font: 400 13px/1 var(--mono);
+}
+#q::placeholder { color: var(--quiet); }
+
+/* grid */
+main { max-width: 1240px; margin: 0 auto; }
+.section-head { display: flex; align-items: baseline; gap: 12px; padding-block: 28px 12px; flex-wrap: wrap; }
+.section-head h2 { margin: 0; font: 400 27px/33px var(--display); }
+.section-head p { margin: 0; color: var(--quiet); font: 400 14px/1.4 var(--text); }
+.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(176px, 1fr)); gap: 12px; }
+.tile { margin: 0; cursor: pointer; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
+.tile .stage { background: var(--stage); aspect-ratio: 6 / 5; overflow: hidden; border: 1px solid transparent; }
+.tile:hover .stage, .tile:focus-visible .stage { border-color: var(--quiet); }
+.tile canvas, .detail canvas { width: 100%; height: 100%; display: block; image-rendering: pixelated; }
+.tile figcaption { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; min-width: 0; }
+.tile b { font: 500 14px/1.3 var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
+.tile small { font: 400 11px/1.3 var(--mono); color: var(--quiet); white-space: nowrap; letter-spacing: 0.04em; }
+.empty { color: var(--quiet); padding-block: 40px; }
+
+/* detail */
+.detail {
+ border: 0;
+ padding: 0;
+ margin: 0;
+ max-width: none;
+ max-height: none;
+ width: 100%;
+ height: 100%;
+ background: rgba(0, 0, 0, 0.92);
+ color: var(--ink);
+}
+.detail::backdrop { background: transparent; }
+.sheet {
+ max-width: 1240px;
+ margin: 0 auto;
+ min-height: 100%;
+ padding: max(20px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) 32px max(16px, env(safe-area-inset-left, 0px));
+ display: grid;
+ grid-template-columns: minmax(0, 1fr) 340px;
+ gap: 28px;
+ align-content: start;
+}
+.sheet .big { background: var(--stage); aspect-ratio: 16 / 10; position: relative; }
+.close {
+ position: absolute;
+ top: 10px;
+ right: 10px;
+ border: 1px solid var(--line);
+ background: var(--ground);
+ padding: 6px 10px;
+ font: 500 12px/1 var(--mono);
+ cursor: pointer;
+}
+.info h2 { margin: 0; font: 400 36px/44px var(--display); }
+.info .id { font: 400 12px/1.4 var(--mono); color: var(--quiet); margin: 4px 0 12px; letter-spacing: 0.04em; }
+.info p { margin: 0 0 16px; color: #ddd; }
+.facts { display: grid; grid-template-columns: auto 1fr; gap: 4px 16px; font: 400 12px/1.5 var(--mono); margin: 0 0 20px; }
+.facts dt { color: var(--quiet); }
+.facts dd { margin: 0; font-variant-numeric: tabular-nums; }
+.controls { display: flex; flex-direction: column; gap: 10px; margin-bottom: 20px; }
+.row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
+.row label { font: 400 11px/1 var(--mono); color: var(--quiet); width: 64px; letter-spacing: 0.04em; }
+.btn {
+ border: 1px solid var(--line);
+ background: none;
+ padding: 6px 9px;
+ font: 500 12px/1 var(--mono);
+ cursor: pointer;
+}
+.btn:hover { border-color: var(--quiet); }
+.btn[aria-pressed="true"] { background: var(--ink); color: var(--ground); border-color: var(--ink); }
+select.btn { padding: 5px 6px; background: var(--ground); }
+pre {
+ margin: 0;
+ background: var(--panel);
+ border: 1px solid var(--line);
+ padding: 12px;
+ font: 400 12px/1.5 var(--mono);
+ overflow-x: auto;
+ white-space: pre;
+}
+.code-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; font: 400 11px/1 var(--mono); color: var(--quiet); letter-spacing: 0.04em; }
+.sheetout { grid-column: 1 / -1; }
+.sheetout img { image-rendering: pixelated; max-width: 100%; background: repeating-conic-gradient(#1a1a1a 0% 25%, #111 0% 50%) 0 0 / 16px 16px; display: block; }
+.sheetout p { font: 400 12px/1.4 var(--mono); color: var(--quiet); margin: 8px 0 0; }
+
+@media (max-width: 900px) {
+ .sheet { grid-template-columns: minmax(0, 1fr); }
+ h1 { font-size: 36px; line-height: 44px; }
+ .mark { width: 28px; height: 28px; margin-top: 4px; }
+ .grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
+}
+@media (max-width: 520px) {
+ .bar-in { flex-wrap: wrap; }
+ #q { width: 100%; max-width: none; }
+}
diff --git a/package-lock.json b/package-lock.json
new file mode 100644
index 0000000..1f442f7
--- /dev/null
+++ b/package-lock.json
@@ -0,0 +1,503 @@
+{
+ "name": "pixelfx",
+ "version": "0.1.0",
+ "lockfileVersion": 3,
+ "requires": true,
+ "packages": {
+ "": {
+ "name": "pixelfx",
+ "version": "0.1.0",
+ "license": "MIT",
+ "devDependencies": {
+ "esbuild": "^0.25.10"
+ },
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/aix-ppc64": {
+ "version": "0.25.10",
+ "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.25.10.tgz",
+ "integrity": "sha512-0NFWnA+7l41irNuaSVlLfgNT12caWJVLzp5eAVhZ0z1qpxbockccEt3s+149rE64VUI3Ml2zt8Nv5JVc4QXTsw==",
+ "cpu": [
+ "ppc64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "aix"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/android-arm": {
+ "version": "0.25.10",
+ "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.25.10.tgz",
+ "integrity": "sha512-dQAxF1dW1C3zpeCDc5KqIYuZ1tgAdRXNoZP7vkBIRtKZPYe2xVr/d3SkirklCHudW1B45tGiUlz2pUWDfbDD4w==",
+ "cpu": [
+ "arm"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "android"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/android-arm64": {
+ "version": "0.25.10",
+ "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.25.10.tgz",
+ "integrity": "sha512-LSQa7eDahypv/VO6WKohZGPSJDq5OVOo3UoFR1E4t4Gj1W7zEQMUhI+lo81H+DtB+kP+tDgBp+M4oNCwp6kffg==",
+ "cpu": [
+ "arm64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "android"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/android-x64": {
+ "version": "0.25.10",
+ "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.25.10.tgz",
+ "integrity": "sha512-MiC9CWdPrfhibcXwr39p9ha1x0lZJ9KaVfvzA0Wxwz9ETX4v5CHfF09bx935nHlhi+MxhA63dKRRQLiVgSUtEg==",
+ "cpu": [
+ "x64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "android"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/darwin-arm64": {
+ "version": "0.25.10",
+ "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.25.10.tgz",
+ "integrity": "sha512-JC74bdXcQEpW9KkV326WpZZjLguSZ3DfS8wrrvPMHgQOIEIG/sPXEN/V8IssoJhbefLRcRqw6RQH2NnpdprtMA==",
+ "cpu": [
+ "arm64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "darwin"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/darwin-x64": {
+ "version": "0.25.10",
+ "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.25.10.tgz",
+ "integrity": "sha512-tguWg1olF6DGqzws97pKZ8G2L7Ig1vjDmGTwcTuYHbuU6TTjJe5FXbgs5C1BBzHbJ2bo1m3WkQDbWO2PvamRcg==",
+ "cpu": [
+ "x64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "darwin"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/freebsd-arm64": {
+ "version": "0.25.10",
+ "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.25.10.tgz",
+ "integrity": "sha512-3ZioSQSg1HT2N05YxeJWYR+Libe3bREVSdWhEEgExWaDtyFbbXWb49QgPvFH8u03vUPX10JhJPcz7s9t9+boWg==",
+ "cpu": [
+ "arm64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "freebsd"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/freebsd-x64": {
+ "version": "0.25.10",
+ "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.25.10.tgz",
+ "integrity": "sha512-LLgJfHJk014Aa4anGDbh8bmI5Lk+QidDmGzuC2D+vP7mv/GeSN+H39zOf7pN5N8p059FcOfs2bVlrRr4SK9WxA==",
+ "cpu": [
+ "x64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "freebsd"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/linux-arm": {
+ "version": "0.25.10",
+ "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.25.10.tgz",
+ "integrity": "sha512-oR31GtBTFYCqEBALI9r6WxoU/ZofZl962pouZRTEYECvNF/dtXKku8YXcJkhgK/beU+zedXfIzHijSRapJY3vg==",
+ "cpu": [
+ "arm"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/linux-arm64": {
+ "version": "0.25.10",
+ "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.25.10.tgz",
+ "integrity": "sha512-5luJWN6YKBsawd5f9i4+c+geYiVEw20FVW5x0v1kEMWNq8UctFjDiMATBxLvmmHA4bf7F6hTRaJgtghFr9iziQ==",
+ "cpu": [
+ "arm64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/linux-ia32": {
+ "version": "0.25.10",
+ "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.25.10.tgz",
+ "integrity": "sha512-NrSCx2Kim3EnnWgS4Txn0QGt0Xipoumb6z6sUtl5bOEZIVKhzfyp/Lyw4C1DIYvzeW/5mWYPBFJU3a/8Yr75DQ==",
+ "cpu": [
+ "ia32"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/linux-loong64": {
+ "version": "0.25.10",
+ "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.25.10.tgz",
+ "integrity": "sha512-xoSphrd4AZda8+rUDDfD9J6FUMjrkTz8itpTITM4/xgerAZZcFW7Dv+sun7333IfKxGG8gAq+3NbfEMJfiY+Eg==",
+ "cpu": [
+ "loong64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/linux-mips64el": {
+ "version": "0.25.10",
+ "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.25.10.tgz",
+ "integrity": "sha512-ab6eiuCwoMmYDyTnyptoKkVS3k8fy/1Uvq7Dj5czXI6DF2GqD2ToInBI0SHOp5/X1BdZ26RKc5+qjQNGRBelRA==",
+ "cpu": [
+ "mips64el"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/linux-ppc64": {
+ "version": "0.25.10",
+ "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.25.10.tgz",
+ "integrity": "sha512-NLinzzOgZQsGpsTkEbdJTCanwA5/wozN9dSgEl12haXJBzMTpssebuXR42bthOF3z7zXFWH1AmvWunUCkBE4EA==",
+ "cpu": [
+ "ppc64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/linux-riscv64": {
+ "version": "0.25.10",
+ "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.25.10.tgz",
+ "integrity": "sha512-FE557XdZDrtX8NMIeA8LBJX3dC2M8VGXwfrQWU7LB5SLOajfJIxmSdyL/gU1m64Zs9CBKvm4UAuBp5aJ8OgnrA==",
+ "cpu": [
+ "riscv64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/linux-s390x": {
+ "version": "0.25.10",
+ "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.25.10.tgz",
+ "integrity": "sha512-3BBSbgzuB9ajLoVZk0mGu+EHlBwkusRmeNYdqmznmMc9zGASFjSsxgkNsqmXugpPk00gJ0JNKh/97nxmjctdew==",
+ "cpu": [
+ "s390x"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/linux-x64": {
+ "version": "0.25.10",
+ "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.25.10.tgz",
+ "integrity": "sha512-QSX81KhFoZGwenVyPoberggdW1nrQZSvfVDAIUXr3WqLRZGZqWk/P4T8p2SP+de2Sr5HPcvjhcJzEiulKgnxtA==",
+ "cpu": [
+ "x64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/netbsd-arm64": {
+ "version": "0.25.10",
+ "resolved": "https://registry.npmjs.org/@esbuild/netbsd-arm64/-/netbsd-arm64-0.25.10.tgz",
+ "integrity": "sha512-AKQM3gfYfSW8XRk8DdMCzaLUFB15dTrZfnX8WXQoOUpUBQ+NaAFCP1kPS/ykbbGYz7rxn0WS48/81l9hFl3u4A==",
+ "cpu": [
+ "arm64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "netbsd"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/netbsd-x64": {
+ "version": "0.25.10",
+ "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.25.10.tgz",
+ "integrity": "sha512-7RTytDPGU6fek/hWuN9qQpeGPBZFfB4zZgcz2VK2Z5VpdUxEI8JKYsg3JfO0n/Z1E/6l05n0unDCNc4HnhQGig==",
+ "cpu": [
+ "x64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "netbsd"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/openbsd-arm64": {
+ "version": "0.25.10",
+ "resolved": "https://registry.npmjs.org/@esbuild/openbsd-arm64/-/openbsd-arm64-0.25.10.tgz",
+ "integrity": "sha512-5Se0VM9Wtq797YFn+dLimf2Zx6McttsH2olUBsDml+lm0GOCRVebRWUvDtkY4BWYv/3NgzS8b/UM3jQNh5hYyw==",
+ "cpu": [
+ "arm64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "openbsd"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/openbsd-x64": {
+ "version": "0.25.10",
+ "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.25.10.tgz",
+ "integrity": "sha512-XkA4frq1TLj4bEMB+2HnI0+4RnjbuGZfet2gs/LNs5Hc7D89ZQBHQ0gL2ND6Lzu1+QVkjp3x1gIcPKzRNP8bXw==",
+ "cpu": [
+ "x64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "openbsd"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/openharmony-arm64": {
+ "version": "0.25.10",
+ "resolved": "https://registry.npmjs.org/@esbuild/openharmony-arm64/-/openharmony-arm64-0.25.10.tgz",
+ "integrity": "sha512-AVTSBhTX8Y/Fz6OmIVBip9tJzZEUcY8WLh7I59+upa5/GPhh2/aM6bvOMQySspnCCHvFi79kMtdJS1w0DXAeag==",
+ "cpu": [
+ "arm64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "openharmony"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/sunos-x64": {
+ "version": "0.25.10",
+ "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.25.10.tgz",
+ "integrity": "sha512-fswk3XT0Uf2pGJmOpDB7yknqhVkJQkAQOcW/ccVOtfx05LkbWOaRAtn5SaqXypeKQra1QaEa841PgrSL9ubSPQ==",
+ "cpu": [
+ "x64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "sunos"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/win32-arm64": {
+ "version": "0.25.10",
+ "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.25.10.tgz",
+ "integrity": "sha512-ah+9b59KDTSfpaCg6VdJoOQvKjI33nTaQr4UluQwW7aEwZQsbMCfTmfEO4VyewOxx4RaDT/xCy9ra2GPWmO7Kw==",
+ "cpu": [
+ "arm64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "win32"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/win32-ia32": {
+ "version": "0.25.10",
+ "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.25.10.tgz",
+ "integrity": "sha512-QHPDbKkrGO8/cz9LKVnJU22HOi4pxZnZhhA2HYHez5Pz4JeffhDjf85E57Oyco163GnzNCVkZK0b/n4Y0UHcSw==",
+ "cpu": [
+ "ia32"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "win32"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/win32-x64": {
+ "version": "0.25.10",
+ "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.25.10.tgz",
+ "integrity": "sha512-9KpxSVFCu0iK1owoez6aC/s/EdUQLDN3adTxGCqxMVhrPDj6bt5dbrHDXUuq+Bs2vATFBBrQS5vdQ/Ed2P+nbw==",
+ "cpu": [
+ "x64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "win32"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/esbuild": {
+ "version": "0.25.10",
+ "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.25.10.tgz",
+ "integrity": "sha512-9RiGKvCwaqxO2owP61uQ4BgNborAQskMR6QusfWzQqv7AZOg5oGehdY2pRJMTKuwxd1IDBP4rSbI5lHzU7SMsQ==",
+ "dev": true,
+ "hasInstallScript": true,
+ "license": "MIT",
+ "bin": {
+ "esbuild": "bin/esbuild"
+ },
+ "engines": {
+ "node": ">=18"
+ },
+ "optionalDependencies": {
+ "@esbuild/aix-ppc64": "0.25.10",
+ "@esbuild/android-arm": "0.25.10",
+ "@esbuild/android-arm64": "0.25.10",
+ "@esbuild/android-x64": "0.25.10",
+ "@esbuild/darwin-arm64": "0.25.10",
+ "@esbuild/darwin-x64": "0.25.10",
+ "@esbuild/freebsd-arm64": "0.25.10",
+ "@esbuild/freebsd-x64": "0.25.10",
+ "@esbuild/linux-arm": "0.25.10",
+ "@esbuild/linux-arm64": "0.25.10",
+ "@esbuild/linux-ia32": "0.25.10",
+ "@esbuild/linux-loong64": "0.25.10",
+ "@esbuild/linux-mips64el": "0.25.10",
+ "@esbuild/linux-ppc64": "0.25.10",
+ "@esbuild/linux-riscv64": "0.25.10",
+ "@esbuild/linux-s390x": "0.25.10",
+ "@esbuild/linux-x64": "0.25.10",
+ "@esbuild/netbsd-arm64": "0.25.10",
+ "@esbuild/netbsd-x64": "0.25.10",
+ "@esbuild/openbsd-arm64": "0.25.10",
+ "@esbuild/openbsd-x64": "0.25.10",
+ "@esbuild/openharmony-arm64": "0.25.10",
+ "@esbuild/sunos-x64": "0.25.10",
+ "@esbuild/win32-arm64": "0.25.10",
+ "@esbuild/win32-ia32": "0.25.10",
+ "@esbuild/win32-x64": "0.25.10"
+ }
+ }
+ }
+}
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..70dec82
--- /dev/null
+++ b/package.json
@@ -0,0 +1,23 @@
+{
+ "name": "pixelfx",
+ "version": "0.1.0",
+ "description": "Code-driven pixel art effects and animations, and a Claude Code skill to make your own.",
+ "type": "module",
+ "license": "MIT",
+ "engines": {
+ "node": ">=18"
+ },
+ "exports": {
+ ".": "./src/core/index.js",
+ "./fx/*": "./src/fx/*.js",
+ "./core/*": "./src/core/*.js"
+ },
+ "scripts": {
+ "render": "node tools/render.mjs",
+ "check": "node tools/check.mjs",
+ "gallery": "node tools/serve.mjs"
+ },
+ "devDependencies": {
+ "esbuild": "^0.25.10"
+ }
+}
diff --git a/skills/pixelfx/SKILL.md b/skills/pixelfx/SKILL.md
new file mode 100644
index 0000000..b53960f
--- /dev/null
+++ b/skills/pixelfx/SKILL.md
@@ -0,0 +1,122 @@
+---
+name: pixelfx
+description: Make pixel art effects and sprite animations in code with the pixelfx library, which has about 300 ready-made ones (fire, explosions, water, ice, lightning, sci-fi, melee, impacts, projectiles, spawn and death, arcane, holy, shadow, status, nature, weather, UI, pickups, transitions, critters) to drop into a game, recolor, export as sprite sheets or remix, plus a draft, render, look, refine loop that makes new ones look hand-animated. Use when someone wants pixel art VFX, sprite animations or sprite sheets, game juice, a specific effect ("a frost nova for my mage", "a coin pickup sparkle"), wants to use or export a pixelfx effect in Godot, Unity, Phaser or a canvas game, or wants their pixel effects to look better.
+license: MIT
+compatibility: Node 18 or newer. ffmpeg is optional (GIF and MP4 previews).
+---
+
+# pixelfx
+
+Pixel art effects as code. Each effect is one small file, `src/fx/<category>/<name>.js`, that draws a frame as a
+function of time into two buffers: **color** (hard pixels, faded with ordered dither) and **light** (additive
+glow). Because a frame is just `draw(p, t)`, an effect can be played live, scrubbed, recolored, mirrored, looped
+and rendered to a sprite sheet for any engine.
+
+The method is Hugo Duprez's ([How to make (good) pixel art effects with
+Claude](https://www.spritefusion.com/blog/how-to-make-good-pixel-art-effects-with-claude)): code is clay, trust
+your eyes, feed your references. One-shot prompts make mediocre effects. Drafts you render, look at and refine
+make good ones.
+
+## Before anything
+
+1. Work in a pixelfx checkout. If the working directory has no `tools/render.mjs`, clone one next to the
+ project: `git clone https://github.com/patch-gg/pixelfx`. No install step: the tools use only Node.
+2. Check it runs: `node tools/render.mjs fire/torch` writes `records/fire/torch/contact.png`. Open that PNG with
+ your image-reading tool. That contact sheet is how you see every effect from now on.
+
+## 1. Look for an existing effect first
+
+`node tools/list.mjs <words>` searches ids, names, tags and descriptions (`node tools/list.mjs frost`,
+`node tools/list.mjs slash loop`). `docs/CATALOG.md` lists everything by category. Render the candidates and
+look at them before choosing. Most requests are an existing effect with different options:
+
+- `palette`: the main ramp, dark to bright, as hex strings. Any `PAL` ramp in `src/core/color.js` (fire ember
+ lava smoke dust ice water electric volt poison holy heal arcane shadow blood earth stone gold leaf wood metal
+ bone neon cyber matrix candy night) or your own. A blue fire is `{"palette": PAL.ice}`.
+- `seed` for a different but equivalent take; `flip` to face left; `angle` to rotate; `light` (0..1+) for glow
+ strength; plus each effect's own knobs in its `meta.options` (size, count, radius, text, height...).
+- Try options without editing code: `node tools/render.mjs fire/torch --opts '{"palette":["#102","#215","#43a","#8cf","#fff"]}'`.
+
+## 2. Put it in the game
+
+**Canvas or WebGL games in JS or TS** (plain canvas, Phaser, PixiJS, Kaplay, three.js): use the code directly. It
+has no dependencies; copy `src/core` and the effect files you need, or depend on the repo.
+
+```js
+import { createFrame, clearFrame, createFx, composite } from "pixelfx"; // src/core/index.js
+import * as frostNova from "pixelfx/fx/ice/frost-nova"; // src/fx/ice/frost-nova.js
+
+const frame = createFrame(320, 180); // the game's pixel resolution; ox, oy scroll it with the camera
+const img = new ImageData(320, 180);
+const fx = createFx(frostNova, { x: hero.x, y: hero.y, flip: hero.facing < 0 });
+
+// every tick
+fx.update(dt);
+clearFrame(frame);
+fx.draw(frame, "back"); // what goes behind characters
+drawCharacters(); // your own sprites, or draw them into frame.color yourself
+fx.draw(frame, "front");
+composite(frame, img.data, background); // color over the background plus light; or null for transparent
+ctx.putImageData(img, 0, 0); // then scale the canvas up with image-rendering: pixelated
+if (fx.done()) removeIt(); // one-shots end on their own; fx.stop() fades a loop out
+```
+
+Several effects can share one frame. In a WebGL engine, upload the composited RGBA to a texture each frame, or
+render the effect to a sprite sheet once (below) and play it like any other animation.
+
+**Any engine** (Godot, Unity, GameMaker, Defold, LÖVE, Bevy, Construct): export sprite sheets.
+`node tools/render.mjs ice/frost-nova --sheet` writes `records/ice/frost-nova/frost-nova.png` (transparent
+frames in a grid) and `frost-nova.json` (Aseprite-style frames, so Phaser's atlas loader, Godot and Unity Aseprite
+importers and most tools read it; `meta.pixelfx` has fps, loop, frame size, columns and the pivot). Set the
+pivot to `meta.pixelfx.pivot` (the effect's origin, e.g. the feet), import with nearest-neighbour filtering and no
+compression, and play at `meta.pixelfx.fps`. Glow is baked into the sheet as color with alpha, which reads as
+additive over dark scenes; for bright scenes, render a recolored version or keep the effect on a dark layer.
+
+For the full library: `node tools/render.mjs <category> --sheet` does a whole category.
+
+## 3. Make a new one
+
+Read `docs/AUTHORING.md` first: it is the contract (meta, `draw(p, t, o)`, local coordinates, seamless loops,
+ending empty), the painter API, the helpers and the quality bar. Then:
+
+1. **Say it in one line** with art direction: what it is, how it moves, its palette, its timing. "A frost nova:
+ crystals erupt in a ring from the feet outward, a white flash at the center, shards spin off, the floor stays
+ frosted and fades."
+2. **Find references** in the library: `node tools/list.mjs <words>`, then read the two or three closest effect
+ files. Borrow their techniques (a merged heat field for fireballs, `p.arc` for smears, `cycle` for seamless
+ particles, `tileFbm` scrolls for flames and water).
+3. **Draft.** `node tools/new.mjs <category>/<name>` (add `--loop` for a loop) gives a working file. When the
+ direction is open, write 3 to 5 genuinely different drafts (`<name>-a.js` .. `-e.js`), render them all
+ (`node tools/render.mjs "<category>/<name>-*"`) and look at every contact sheet before choosing. Show the user
+ the strongest two or three if they're around (`--gif` makes animations to share).
+4. **Look, judge, fix.** Render, open `records/<id>/contact.png`, and judge like a picky pixel artist. Fix the
+ worst thing, render again. Two to four rounds is normal; a showpiece takes more. `--all` shows every frame,
+ `--mp4` shows motion at full speed.
+5. **Check.** `node tools/check.mjs <id>` catches drawing outside the canvas, one-shots that don't end empty,
+ loop seams, unseeded randomness and slow frames. Fix until it passes clean. Delete the drafts you didn't keep.
+
+What to look for, and the usual fix:
+
+| you see | fix |
+|---|---|
+| it reads as mush at 1x | fewer colors, a clear silhouette, one focal point, bigger shapes |
+| speckle: lone noise pixels inside shapes | threshold noise less, quantize with `at()`, no noise on small shapes |
+| floaty, no punch | fast in, slow out (`ease.outQuart`/`outExpo`), a 1 to 2 frame white hero frame, shorter total time |
+| stiff or mechanical | vary every particle (size, speed, delay, life), add secondary motion (sparks, smoke, debris) |
+| washed out | less glow (k 0.2 to 0.5), darker edge steps, keep white for the hottest core only |
+| flat | light from one side: brighter top-left, darker bottom-right step; a darker ramp step at the base |
+| smooth gradients, vector look | hard ramp steps in color, dither for fades, softness only in light |
+| seam when a loop wraps | `cycle`, `loopNoise(phase)`, whole-cell `tileNoise` scrolls, `sin(phase * TAU * n)` |
+| a one-shot that pops off | let it shrink, dither out or fall away before t = duration |
+
+Directional effects face right, ground effects stand on y = 0, actor effects wrap `o.actor` (a 12 x 19 stock
+character's mask), and nothing uses `Math.random`. Generic motifs are fine; never recreate a specific game's
+sprites, characters or logos.
+
+## 4. Native code instead of JS
+
+If the game can't run JS and a sprite sheet isn't enough (an effect that follows a moving target, or needs
+per-instance colors at runtime), port the effect: it is a pure function of time. Keep the two-buffer idea, the
+4x4 Bayer threshold for alpha, the palette ramp lookups and the closed-form particle motion (`fly` in
+`src/core/particles.js`); a GDScript or C# port of one effect is usually under 150 lines. Render the JS original
+and your port side by side to check they match.
diff --git a/src/core/actor.js b/src/core/actor.js
new file mode 100644
index 0000000..38ce7ba
--- /dev/null
+++ b/src/core/actor.js
@@ -0,0 +1,54 @@
+// A stock character to try effects on: status effects wrap its silhouette, hits land on it, auras sit
+// behind it. Previews and the gallery draw it; effects only read its mask through o.actor.
+
+const HERO = [
+ "....kkkkk...",
+ "..kkhhhhhk..",
+ ".khhhhhhhhk.",
+ ".khhhhhhhhhk",
+ ".khhssssshhk",
+ ".khsessesshk",
+ ".khsessesshk",
+ "..ksssssssk.",
+ "...kkSSSkk..",
+ "..kttttttk..",
+ ".kttTttTttk.",
+ ".ksttTTttsk.",
+ ".kstttttttk.",
+ "..kbbbbbbk..",
+ "..kppkkppk..",
+ "..kppk.kppk.",
+ "..kppk.kppk.",
+ "..koook.kook",
+ "..kkkkk.kkkk",
+];
+const HERO_PAL = {
+ k: "#17121f", h: "#7a4128", s: "#f3c49d", S: "#c98b6c", e: "#17121f",
+ t: "#5f6f94", T: "#46536f", b: "#8a5a32", p: "#38334a", o: "#6a4030",
+};
+
+function maskOf(rows) {
+ const h = rows.length, w = rows[0].length, data = new Uint8Array(w * h);
+ rows.forEach((r, y) => [...r].forEach((ch, x) => (data[y * w + x] = ch === "." ? 0 : 1)));
+ return { w, h, data };
+}
+
+const MASK = maskOf(HERO);
+
+/**
+ * The stock actor, in local space with its feet at (0, 0):
+ * { mask, x, y (top-left of the mask), w, h, head: [x, y] (top of the head), chest: [x, y] }.
+ */
+export function stockActor() {
+ const x = -Math.floor(MASK.w / 2), y = -MASK.h;
+ return { mask: MASK, x, y, w: MASK.w, h: MASK.h, head: [0, y], chest: [0, y + 11] };
+}
+
+/** Draw the stock actor with its feet at the painter's origin, at alpha a (dithered). */
+export function drawActor(p, actor = stockActor(), a = 1) {
+ if (a > 0) p.sprite(HERO, HERO_PAL, actor.x, actor.y, { a });
+}
+/** How visible an effect wants the stand-in character at time t (effects may export actorAlpha). */
+export const actorAlphaOf = (mod, t, o) => (typeof mod.actorAlpha === "function" ? mod.actorAlpha(t, o) : 1);
+
+export { HERO, HERO_PAL };
diff --git a/src/core/color.js b/src/core/color.js
new file mode 100644
index 0000000..60cdedd
--- /dev/null
+++ b/src/core/color.js
@@ -0,0 +1,87 @@
+// Colors are 32-bit integers laid out like ImageData bytes (R, G, B, A in memory),
+// so a frame's color buffer can be shown with new ImageData(new Uint8ClampedArray(buf.buffer), w, h).
+
+import { clamp } from "./math.js";
+
+export const rgb = (r, g, b) => (255 << 24) | ((b & 255) << 16) | ((g & 255) << 8) | (r & 255);
+export const red = (c) => c & 255;
+export const green = (c) => (c >>> 8) & 255;
+export const blue = (c) => (c >>> 16) & 255;
+
+/** "#rgb" or "#rrggbb" (or a color number, passed through) to a color number. */
+export function hex(h) {
+ if (typeof h === "number") return h;
+ let s = h.replace("#", "");
+ if (s.length === 3) s = s[0] + s[0] + s[1] + s[1] + s[2] + s[2];
+ const v = parseInt(s.slice(0, 6), 16);
+ return rgb((v >> 16) & 255, (v >> 8) & 255, v & 255);
+}
+export const toHex = (c) => "#" + [red(c), green(c), blue(c)].map((v) => v.toString(16).padStart(2, "0")).join("");
+
+/** Linear mix of two colors. */
+export function mix(a, b, t) {
+ t = clamp(t);
+ return rgb(red(a) + (red(b) - red(a)) * t, green(a) + (green(b) - green(a)) * t, blue(a) + (blue(b) - blue(a)) * t);
+}
+/** Multiply a color's brightness by k. */
+export const scale = (c, k) => rgb(Math.min(255, red(c) * k), Math.min(255, green(c) * k), Math.min(255, blue(c) * k));
+/** Perceived brightness 0..1. */
+export const luma = (c) => (0.299 * red(c) + 0.587 * green(c) + 0.114 * blue(c)) / 255;
+
+/** A list of hex strings (dark to bright) to color numbers. */
+export const ramp = (list) => list.map(hex);
+/**
+ * Resample a ramp to exactly n steps, keeping its ends (the darkest and brightest stay put). Lets an effect
+ * index steps by number (C[5]) whatever length of palette a caller passes.
+ */
+export function fit(r, n) {
+ r = r.map(hex);
+ if (r.length === n) return r;
+ return Array.from({ length: n }, (_, i) => r[Math.round((i * (r.length - 1)) / Math.max(1, n - 1))]);
+}
+/** The ramp step for t in 0..1, no blending: pixel art picks a color, it doesn't fade between two. */
+export const at = (r, t) => r[clamp(Math.floor(t * r.length), 0, r.length - 1)];
+/** Blended color along a ramp (for light, where smooth is right). */
+export function blend(r, t) {
+ const x = clamp(t) * (r.length - 1), i = Math.min(r.length - 2, Math.floor(x));
+ return mix(r[i], r[i + 1], x - i);
+}
+
+// Hue-shifted ramps, dark to bright: shadows lean cool or deep, highlights lean warm or white.
+// Effects take `palette` as an option, so any of these (or your own) can recolor them.
+export const PAL = {
+ fire: ["#1f0b10", "#4a1118", "#8c1d1c", "#cc3a1a", "#f2701f", "#ffae35", "#ffe27a", "#fff8d6"],
+ ember: ["#1a0a0e", "#3d1012", "#701a14", "#a8301a", "#e0561e", "#ff8a2a", "#ffc46a"],
+ lava: ["#14060a", "#380a10", "#6e1210", "#ac2410", "#e8501a", "#ff8c2a", "#ffd25a"],
+ smoke: ["#0e0c12", "#1d1a22", "#2e2a35", "#433e4b", "#5c5664", "#7b7484", "#a39cab"],
+ dust: ["#1c1610", "#33281c", "#4f3f2c", "#6e5a40", "#927a58", "#b89f78", "#dcc8a2"],
+ ice: ["#0c1430", "#162c5c", "#1f4f94", "#2f7fcc", "#58b4ec", "#9bdcff", "#d8f4ff", "#ffffff"],
+ water: ["#081830", "#0e2e5a", "#14508c", "#1c76bc", "#36a2e0", "#78ccf4", "#c4ecff", "#ffffff"],
+ electric: ["#0a0f2e", "#172a78", "#2550d0", "#3f8cff", "#7cc8ff", "#c8f0ff", "#ffffff"],
+ volt: ["#24160a", "#5e3a0c", "#a8680f", "#e8a218", "#ffd23c", "#fff08a", "#ffffff"],
+ poison: ["#0d1a0c", "#173a14", "#265e18", "#3f8a1e", "#6cb82a", "#a8e04a", "#e0ff8a"],
+ holy: ["#2a1c08", "#5a3e10", "#9a6c18", "#d8a428", "#ffd84a", "#fff09a", "#fffbe6", "#ffffff"],
+ heal: ["#08201a", "#0f3f2c", "#17663e", "#24924e", "#3ec466", "#7ee88a", "#c8ffc4", "#ffffff"],
+ arcane: ["#140a26", "#2b1252", "#481c88", "#6b2cc0", "#9a48ec", "#c684ff", "#ecc8ff", "#ffffff"],
+ shadow: ["#050308", "#0f0a18", "#1c1230", "#2c1a4a", "#432468", "#5e3290", "#8048b8", "#a970e0"],
+ blood: ["#14040a", "#3a0a14", "#6a101c", "#a01824", "#d42a30", "#ff5a50", "#ff9a8a"],
+ earth: ["#140e0a", "#2a1e14", "#47321e", "#69492a", "#8e6638", "#b88a52", "#dcb47c"],
+ stone: ["#0e0e12", "#1c1c24", "#2c2c38", "#42424f", "#5c5c6b", "#7d7d8c", "#a4a4b2", "#d0d0da"],
+ gold: ["#1e1206", "#4a2c08", "#86520c", "#c48412", "#f0b424", "#ffe066", "#fff6c4", "#ffffff"],
+ leaf: ["#0c1a0e", "#163418", "#225224", "#357530", "#4f9a3a", "#7cc048", "#b4e070", "#e4ffb0"],
+ wood: ["#160c06", "#2e1a0c", "#4a2c14", "#6a421e", "#8e5c2c", "#b47c40", "#d8a464"],
+ metal: ["#0c0e14", "#1c2230", "#2e3648", "#4a5468", "#6e7a90", "#9aa6ba", "#d0d8e6", "#ffffff"],
+ bone: ["#1a1814", "#3a352c", "#5e5648", "#8a806c", "#b8ad96", "#e4dcc8", "#fffaf0"],
+ neon: ["#1a0516", "#3d0a33", "#701560", "#b0228f", "#f53cd1", "#ff86e6", "#ffd2f6", "#ffffff"],
+ cyber: ["#041418", "#08303a", "#0c5260", "#108088", "#18b4b0", "#4ce8d8", "#b4fff0", "#ffffff"],
+ matrix: ["#020a04", "#05200c", "#0a3c16", "#106624", "#1a9a34", "#3cd650", "#a4ffa8", "#e8ffe8"],
+ candy: ["#ff4a5a", "#ff9a2a", "#ffe03c", "#5ad84a", "#3cc8ff", "#7a6cff", "#f53cd1"],
+ night: ["#07060d", "#0c0a18", "#131026", "#1b1734", "#241f44", "#2f2956"],
+};
+/** The same ramps as color numbers. */
+export const RAMP = Object.fromEntries(Object.entries(PAL).map(([k, v]) => [k, ramp(v)]));
+
+export const WHITE = hex("#ffffff");
+export const BLACK = hex("#000000");
+export const INK = hex("#0b0a10");
+export const PATCH = hex("#f53cd1");
diff --git a/src/core/font.js b/src/core/font.js
new file mode 100644
index 0000000..1aa816b
--- /dev/null
+++ b/src/core/font.js
@@ -0,0 +1,88 @@
+// Two pixel fonts: "mini" (3x5) for small numbers and tags, "big" (5x7) for words like LEVEL UP.
+// Glyphs are trimmed to their inked columns, so text sets proportionally (an I is narrower than an M).
+
+const MINI = {
+ A: ".#.|#.#|###|#.#|#.#", B: "##.|#.#|##.|#.#|##.", C: ".##|#..|#..|#..|.##", D: "##.|#.#|#.#|#.#|##.",
+ E: "###|#..|##.|#..|###", F: "###|#..|##.|#..|#..", G: ".##|#..|#.#|#.#|.##", H: "#.#|#.#|###|#.#|#.#",
+ I: "###|.#.|.#.|.#.|###", J: "..#|..#|..#|#.#|.#.", K: "#.#|#.#|##.|#.#|#.#", L: "#..|#..|#..|#..|###",
+ M: "#.#|###|###|#.#|#.#", N: "##.|#.#|#.#|#.#|#.#", O: ".#.|#.#|#.#|#.#|.#.", P: "##.|#.#|##.|#..|#..",
+ Q: ".#.|#.#|#.#|##.|.##", R: "##.|#.#|##.|#.#|#.#", S: ".##|#..|.#.|..#|##.", T: "###|.#.|.#.|.#.|.#.",
+ U: "#.#|#.#|#.#|#.#|###", V: "#.#|#.#|#.#|#.#|.#.", W: "#.#|#.#|###|###|#.#", X: "#.#|#.#|.#.|#.#|#.#",
+ Y: "#.#|#.#|.#.|.#.|.#.", Z: "###|..#|.#.|#..|###",
+ 0: "###|#.#|#.#|#.#|###", 1: ".#.|##.|.#.|.#.|###", 2: "##.|..#|.#.|#..|###", 3: "##.|..#|.#.|..#|##.",
+ 4: "#.#|#.#|###|..#|..#", 5: "###|#..|##.|..#|##.", 6: ".##|#..|###|#.#|###", 7: "###|..#|.#.|.#.|.#.",
+ 8: "###|#.#|###|#.#|###", 9: "###|#.#|###|..#|##.",
+ "+": "...|.#.|###|.#.|...", "-": "...|...|###|...|...", "!": "#|#|#|.|#", "?": "##.|..#|.#.|...|.#.",
+ ".": ".|.|.|.|#", ",": "..|..|..|.#|#.", ":": ".|#|.|#|.", "/": "..#|..#|.#.|#..|#..",
+ "%": "#.#|..#|.#.|#..|#.#", x: "...|#.#|.#.|#.#|...", "*": "#.#|.#.|#.#|...|...", "'": "#|#|.|.|.",
+ "(": ".#|#.|#.|#.|.#", ")": "#.|.#|.#|.#|#.", "<": "..#|.#.|#..|.#.|..#", ">": "#..|.#.|..#|.#.|#..",
+ "=": "...|###|...|###|...", _: "...|...|...|...|###", "#": "#.#|###|#.#|###|#.#",
+};
+
+const BIG = {
+ A: ".###.|#...#|#...#|#####|#...#|#...#|#...#", B: "####.|#...#|#...#|####.|#...#|#...#|####.",
+ C: ".###.|#...#|#....|#....|#....|#...#|.###.", D: "####.|#...#|#...#|#...#|#...#|#...#|####.",
+ E: "#####|#....|#....|####.|#....|#....|#####", F: "#####|#....|#....|####.|#....|#....|#....",
+ G: ".###.|#...#|#....|#.###|#...#|#...#|.####", H: "#...#|#...#|#...#|#####|#...#|#...#|#...#",
+ I: "###|.#.|.#.|.#.|.#.|.#.|###", J: "..###|...#.|...#.|...#.|...#.|#..#.|.##..",
+ K: "#...#|#..#.|#.#..|##...|#.#..|#..#.|#...#", L: "#....|#....|#....|#....|#....|#....|#####",
+ M: "#...#|##.##|#.#.#|#.#.#|#...#|#...#|#...#", N: "#...#|#...#|##..#|#.#.#|#..##|#...#|#...#",
+ O: ".###.|#...#|#...#|#...#|#...#|#...#|.###.", P: "####.|#...#|#...#|####.|#....|#....|#....",
+ Q: ".###.|#...#|#...#|#...#|#.#.#|#..#.|.##.#", R: "####.|#...#|#...#|####.|#.#..|#..#.|#...#",
+ S: ".####|#....|#....|.###.|....#|....#|####.", T: "#####|..#..|..#..|..#..|..#..|..#..|..#..",
+ U: "#...#|#...#|#...#|#...#|#...#|#...#|.###.", V: "#...#|#...#|#...#|#...#|#...#|.#.#.|..#..",
+ W: "#...#|#...#|#...#|#.#.#|#.#.#|#.#.#|.#.#.", X: "#...#|#...#|.#.#.|..#..|.#.#.|#...#|#...#",
+ Y: "#...#|#...#|.#.#.|..#..|..#..|..#..|..#..", Z: "#####|....#|...#.|..#..|.#...|#....|#####",
+ 0: ".###.|#...#|#..##|#.#.#|##..#|#...#|.###.", 1: ".#.|##.|.#.|.#.|.#.|.#.|###",
+ 2: ".###.|#...#|....#|...#.|..#..|.#...|#####", 3: "#####|...#.|..#..|...#.|....#|#...#|.###.",
+ 4: "...#.|..##.|.#.#.|#..#.|#####|...#.|...#.", 5: "#####|#....|####.|....#|....#|#...#|.###.",
+ 6: "..##.|.#...|#....|####.|#...#|#...#|.###.", 7: "#####|....#|...#.|..#..|.#...|.#...|.#...",
+ 8: ".###.|#...#|#...#|.###.|#...#|#...#|.###.", 9: ".###.|#...#|#...#|.####|....#|...#.|.##..",
+ "!": "#|#|#|#|#|.|#", "?": ".###.|#...#|....#|...#.|..#..|.....|..#..", "+": ".....|..#..|..#..|#####|..#..|..#..|.....",
+ "-": "....|....|....|####|....|....|....", ".": ".|.|.|.|.|.|#", ",": "..|..|..|..|..|.#|#.", ":": ".|.|#|.|.|#|.",
+ "/": "....#|....#|...#.|..#..|.#...|#....|#....", "%": "##...|##..#|...#.|..#..|.#...|#..##|...##",
+ x: ".....|.....|#...#|.#.#.|..#..|.#.#.|#...#", "*": ".....|..#..|#.#.#|.###.|#.#.#|..#..|.....", "'": "#|#|.|.|.|.|.",
+ "<": "...#|..#.|.#..|#...|.#..|..#.|...#", ">": "#...|.#..|..#.|...#|..#.|.#..|#...", "=": "....|....|####|....|####|....|....",
+ "(": "..#|.#.|#..|#..|#..|.#.|..#", ")": "#..|.#.|..#|..#|..#|.#.|#..", "#": ".#.#.|.#.#.|#####|.#.#.|#####|.#.#.|.#.#.",
+};
+
+function build(table, h) {
+ const out = {};
+ for (const [ch, src] of Object.entries(table)) {
+ const rows = src.split("|");
+ out[ch] = { w: rows[0].length, rows: rows.map((r) => [...r].map((c) => c === "#")) };
+ if (rows.length !== h) throw new Error(`glyph ${ch} has ${rows.length} rows, expected ${h}`);
+ }
+ return out;
+}
+
+export const FONTS = {
+ mini: { h: 5, space: 2, gap: 1, glyphs: build(MINI, 5) },
+ big: { h: 7, space: 3, gap: 1, glyphs: build(BIG, 7) },
+};
+
+/** Width in font pixels of a string (before scaling). */
+export function textWidth(str, font = "mini") {
+ const F = FONTS[font];
+ let w = 0;
+ for (const ch of String(str)) {
+ const g = F.glyphs[ch] ?? F.glyphs[ch.toUpperCase()];
+ w += (g ? g.w : F.space) + F.gap;
+ }
+ return Math.max(0, w - F.gap);
+}
+
+/** Calls plot(x, y) for every inked font pixel of str, with the top-left of the text at (0, 0). */
+export function rasterText(str, font, plot) {
+ const F = FONTS[font];
+ let x = 0;
+ for (const ch of String(str)) {
+ const g = F.glyphs[ch] ?? F.glyphs[ch.toUpperCase()];
+ if (!g) {
+ x += F.space + F.gap;
+ continue;
+ }
+ for (let r = 0; r < F.h; r++) for (let c = 0; c < g.w; c++) if (g.rows[r][c]) plot(x + c, r);
+ x += g.w + F.gap;
+ }
+}
diff --git a/src/core/fx.js b/src/core/fx.js
new file mode 100644
index 0000000..41baa6f
--- /dev/null
+++ b/src/core/fx.js
@@ -0,0 +1,126 @@
+// Frames and live effect instances.
+
+import { Painter } from "./painter.js";
+import { clamp } from "./math.js";
+import { stockActor } from "./actor.js";
+import { fit, toHex } from "./color.js";
+
+/**
+ * A frame: w x h pixels whose top-left sits at (ox, oy) in world space. `color` holds opaque pixels,
+ * `light` additive glow; composite() puts them together. Same shape as Sprite Fusion's VFX frames.
+ */
+export function createFrame(w, h, ox = 0, oy = 0) {
+ return { w, h, ox, oy, color: new Uint32Array(w * h), light: new Uint32Array(w * h) };
+}
+export function clearFrame(f) {
+ f.color.fill(0);
+ f.light.fill(0);
+ return f;
+}
+
+const painters = new WeakMap();
+/** The painter for a frame (one per frame, reused). */
+export function painterFor(frame) {
+ let p = painters.get(frame);
+ if (!p) painters.set(frame, (p = new Painter(frame)));
+ return p.reset();
+}
+
+const FADE = 0.3;
+
+const isRamp = (v) => Array.isArray(v) && v.length > 0 && v.every((c) => typeof c === "number" || /^#[0-9a-f]{3,8}$/i.test(c));
+
+/**
+ * An effect's options: its defaults with the caller's on top. Any color ramp (palette, or another ramp option
+ * like dust or smoke) of a different length than its default is resampled to the default's length, so effects
+ * can index steps by number whatever a caller passes.
+ */
+export function resolveOptions(meta, o = {}) {
+ const opts = { ...(meta.options ?? {}), ...o };
+ for (const [k, def] of Object.entries(meta.options ?? {}))
+ if (isRamp(def) && isRamp(o[k]) && o[k].length !== def.length) opts[k] = fit(o[k], def.length).map(toHex);
+ if (meta.actor && !opts.actor) opts.actor = stockActor();
+ return opts;
+}
+
+/**
+ * A live instance of an effect module: { update(dt), draw(frame, layer), stop(), done() }.
+ * o: { x, y, flip, angle, seed, palette, light (glow strength), actor, ...the effect's own options }.
+ * draw(frame, "back") draws what goes behind a character, "front" what goes in front, nothing both.
+ */
+export function createFx(mod, o = {}) {
+ const meta = mod.meta ?? {};
+ const opts = resolveOptions(meta, o);
+ const impl = mod.create ? mod.create(opts) : mod;
+ const D = meta.duration ?? 1;
+ let t = 0, stopAt = Infinity;
+ return {
+ meta,
+ options: opts,
+ get t() {
+ return t;
+ },
+ update(dt) {
+ t += dt;
+ impl.update?.(dt, opts);
+ },
+ draw(frame, layer) {
+ const p = painterFor(frame);
+ p.place(opts.x ?? 0, opts.y ?? 0, !!opts.flip, opts.angle ?? 0);
+ p.fade = stopAt === Infinity ? 1 : clamp(1 - (t - stopAt) / FADE);
+ p.lightK = opts.light ?? 1;
+ const tt = meta.loop ? t % D : Math.min(t, D);
+ if (layer !== "front" && impl.drawBack) {
+ p.layer = "back";
+ impl.drawBack(p, tt, opts);
+ }
+ if (layer !== "back") {
+ p.layer = "front";
+ impl.draw(p, tt, opts);
+ }
+ },
+ /** Let it end: loops fade out, one-shots cut short. */
+ stop() {
+ if (stopAt === Infinity) stopAt = t;
+ },
+ done() {
+ return t - stopAt >= FADE || (!meta.loop && t >= D);
+ },
+ };
+}
+
+/**
+ * Color over a background, plus light, into RGBA bytes (a Uint8ClampedArray or Buffer, w * h * 4).
+ * bg: null for transparent, a color number, or a Uint32Array of the frame's size. Over transparency, light
+ * becomes color with alpha (its brightest channel), which reads as additive over dark backgrounds.
+ */
+export function composite(f, out, bg = null, lightK = 1) {
+ const n = f.w * f.h, C = f.color, L = f.light, flat = typeof bg === "number";
+ for (let i = 0; i < n; i++) {
+ const c = C[i], l = L[i] & 0xffffff;
+ let r, g, b, a;
+ if (c >>> 24) {
+ r = c & 255; g = (c >>> 8) & 255; b = (c >>> 16) & 255; a = 255;
+ } else if (bg === null) {
+ r = g = b = a = 0;
+ } else {
+ const k = flat ? bg : bg[i];
+ r = k & 255; g = (k >>> 8) & 255; b = (k >>> 16) & 255; a = 255;
+ }
+ if (l) {
+ const lr = (l & 255) * lightK, lg = ((l >>> 8) & 255) * lightK, lb = ((l >>> 16) & 255) * lightK;
+ if (a === 0) {
+ const m = Math.min(255, Math.max(lr, lg, lb));
+ if (m >= 1) {
+ const s = 255 / Math.max(lr, lg, lb);
+ r = lr * s; g = lg * s; b = lb * s; a = m;
+ }
+ } else {
+ r = Math.min(255, r + lr); g = Math.min(255, g + lg); b = Math.min(255, b + lb);
+ }
+ }
+ const j = i * 4;
+ out[j] = r; out[j + 1] = g; out[j + 2] = b; out[j + 3] = a;
+ }
+ return out;
+}
diff --git a/src/core/index.js b/src/core/index.js
new file mode 100644
index 0000000..8e564cc
--- /dev/null
+++ b/src/core/index.js
@@ -0,0 +1,11 @@
+// pixelfx core: everything an effect imports comes from here.
+
+export * from "./math.js";
+export * from "./color.js";
+export * from "./particles.js";
+export * from "./shapes.js";
+export { Painter } from "./painter.js";
+export { FONTS, textWidth } from "./font.js";
+export { createFrame, clearFrame, createFx, composite, painterFor, resolveOptions } from "./fx.js";
+export { stockActor, drawActor, actorAlphaOf, HERO, HERO_PAL } from "./actor.js";
+export { backdrop, BACKDROPS } from "./scene.js";
diff --git a/src/core/math.js b/src/core/math.js
new file mode 100644
index 0000000..9035668
--- /dev/null
+++ b/src/core/math.js
@@ -0,0 +1,152 @@
+// Numbers, easing, randomness and noise. Everything here is pure and deterministic,
+// so an effect drawn at time t always looks the same.
+
+export const TAU = Math.PI * 2;
+
+export const clamp = (x, a = 0, b = 1) => (x < a ? a : x > b ? b : x);
+export const lerp = (a, b, t) => a + (b - a) * t;
+export const invLerp = (a, b, x) => (b === a ? 0 : (x - a) / (b - a));
+export const remap = (x, a0, a1, b0, b1) => lerp(b0, b1, invLerp(a0, a1, x));
+export const fract = (x) => x - Math.floor(x);
+export const wrap = (x, m) => ((x % m) + m) % m;
+/** Progress 0..1 of t through the window [t0, t1]: 0 before it, 1 after it. */
+export const seg = (t, t0, t1) => clamp((t - t0) / (t1 - t0));
+/** Hermite smoothstep of x between e0 and e1. */
+export const smooth = (e0, e1, x) => {
+ const t = seg(x, e0, e1);
+ return t * t * (3 - 2 * t);
+};
+/** 0 → 1 → 0 over the window [t0, t1] (sine bump). */
+export const bump = (t, t0, t1) => (t <= t0 || t >= t1 ? 0 : Math.sin(Math.PI * seg(t, t0, t1)));
+export const pingpong = (x) => 1 - Math.abs(wrap(x, 2) - 1);
+export const dist = (x0, y0, x1, y1) => Math.hypot(x1 - x0, y1 - y0);
+export const angleTo = (x0, y0, x1, y1) => Math.atan2(y1 - y0, x1 - x0);
+
+/** Easing curves: input 0..1, output 0..1 (back and elastic overshoot). */
+export const ease = {
+ linear: (t) => t,
+ inQuad: (t) => t * t,
+ outQuad: (t) => 1 - (1 - t) * (1 - t),
+ inOutQuad: (t) => (t < 0.5 ? 2 * t * t : 1 - Math.pow(-2 * t + 2, 2) / 2),
+ inCubic: (t) => t * t * t,
+ outCubic: (t) => 1 - Math.pow(1 - t, 3),
+ inOutCubic: (t) => (t < 0.5 ? 4 * t * t * t : 1 - Math.pow(-2 * t + 2, 3) / 2),
+ inQuart: (t) => t * t * t * t,
+ outQuart: (t) => 1 - Math.pow(1 - t, 4),
+ inExpo: (t) => (t <= 0 ? 0 : Math.pow(2, 10 * t - 10)),
+ outExpo: (t) => (t >= 1 ? 1 : 1 - Math.pow(2, -10 * t)),
+ inSine: (t) => 1 - Math.cos((t * Math.PI) / 2),
+ outSine: (t) => Math.sin((t * Math.PI) / 2),
+ inOutSine: (t) => -(Math.cos(Math.PI * t) - 1) / 2,
+ inBack: (t, s = 1.70158) => (t <= 0 ? 0 : t >= 1 ? 1 : (s + 1) * t * t * t - s * t * t),
+ outBack: (t, s = 1.70158) => (t <= 0 ? 0 : t >= 1 ? 1 : 1 + (s + 1) * Math.pow(t - 1, 3) + s * Math.pow(t - 1, 2)),
+ outElastic: (t) => (t <= 0 ? 0 : t >= 1 ? 1 : Math.pow(2, -10 * t) * Math.sin((t * 10 - 0.75) * ((2 * Math.PI) / 3)) + 1),
+ outBounce: (t) => {
+ const n = 7.5625, d = 2.75;
+ if (t < 1 / d) return n * t * t;
+ if (t < 2 / d) return n * (t -= 1.5 / d) * t + 0.75;
+ if (t < 2.5 / d) return n * (t -= 2.25 / d) * t + 0.9375;
+ return n * (t -= 2.625 / d) * t + 0.984375;
+ },
+};
+
+/** 32-bit integer hash of any number of integers. */
+export function hash(...ns) {
+ let h = 0x9e3779b9;
+ for (const n of ns) {
+ h = Math.imul(h ^ (n | 0), 0x85ebca6b);
+ h ^= h >>> 13;
+ h = Math.imul(h, 0xc2b2ae35);
+ h ^= h >>> 16;
+ }
+ return h >>> 0;
+}
+/** Deterministic random number in [0, 1) from integers (seed, particle index, which value...). */
+export const rand = (...ns) => hash(...ns) / 4294967296;
+
+/** Seeded random generator (mulberry32). */
+export class Rng {
+ constructor(seed = 1) {
+ this.s = seed >>> 0 || 1;
+ }
+ next() {
+ let t = (this.s = (this.s + 0x6d2b79f5) >>> 0);
+ t = Math.imul(t ^ (t >>> 15), t | 1);
+ t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
+ return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
+ }
+ range(a, b) {
+ return a + (b - a) * this.next();
+ }
+ int(a, b) {
+ return Math.floor(this.range(a, b + 1));
+ }
+ chance(p) {
+ return this.next() < p;
+ }
+ sign() {
+ return this.next() < 0.5 ? -1 : 1;
+ }
+ pick(list) {
+ return list[Math.floor(this.next() * list.length)];
+ }
+ /** Roughly normal, mean 0, sd 1. */
+ gauss() {
+ return (this.next() + this.next() + this.next() + this.next() - 2) * 1.732;
+ }
+}
+/** A generator for one particle: rng(seed, i) gives the same numbers every frame. */
+export const rng = (...ns) => new Rng(hash(...ns));
+
+/** Smooth 1D value noise in [-1, 1]. */
+export function noise(x, seed = 0) {
+ const i = Math.floor(x), f = x - i, u = f * f * (3 - 2 * f);
+ return lerp(rand(i, seed), rand(i + 1, seed), u) * 2 - 1;
+}
+/** Smooth 2D value noise in [-1, 1]. */
+export function noise2(x, y, seed = 0) {
+ const ix = Math.floor(x), iy = Math.floor(y), fx = x - ix, fy = y - iy;
+ const ux = fx * fx * (3 - 2 * fx), uy = fy * fy * (3 - 2 * fy);
+ const a = rand(ix, iy, seed), b = rand(ix + 1, iy, seed), c = rand(ix, iy + 1, seed), d = rand(ix + 1, iy + 1, seed);
+ return lerp(lerp(a, b, ux), lerp(c, d, ux), uy) * 2 - 1;
+}
+/** Fractal 2D noise in about [-1, 1]. */
+export function fbm(x, y, seed = 0, octaves = 3) {
+ let s = 0, a = 0.5, n = 0;
+ for (let o = 0; o < octaves; o++) {
+ s += noise2(x, y, seed + o * 101) * a;
+ n += a;
+ x *= 2.03;
+ y *= 2.03;
+ a *= 0.5;
+ }
+ return s / n;
+}
+/**
+ * 2D value noise whose lattice repeats every px cells in x and py cells in y (0: no repeat). Scroll it by
+ * exactly py cells over a loop and the loop has no seam: tileNoise(x, y + phase * py, 0, py).
+ */
+export function tileNoise(x, y, px = 0, py = 0, seed = 0) {
+ const ix = Math.floor(x), iy = Math.floor(y), fx = x - ix, fy = y - iy;
+ const ux = fx * fx * (3 - 2 * fx), uy = fy * fy * (3 - 2 * fy);
+ const x0 = px ? wrap(ix, px) : ix, x1 = px ? wrap(ix + 1, px) : ix + 1;
+ const y0 = py ? wrap(iy, py) : iy, y1 = py ? wrap(iy + 1, py) : iy + 1;
+ const a = rand(x0, y0, seed), b = rand(x1, y0, seed), c = rand(x0, y1, seed), d = rand(x1, y1, seed);
+ return lerp(lerp(a, b, ux), lerp(c, d, ux), uy) * 2 - 1;
+}
+/** Fractal tileNoise: every octave keeps the repeat, so scrolled fields still loop. */
+export function tileFbm(x, y, px = 0, py = 0, seed = 0, octaves = 3) {
+ let s = 0, a = 0.5, n = 0, k = 1;
+ for (let o = 0; o < octaves; o++) {
+ s += tileNoise(x * k, y * k, px * k, py * k, seed + o * 101) * a;
+ n += a;
+ a *= 0.5;
+ k *= 2;
+ }
+ return s / n;
+}
+/** Noise that loops: the same value at phase 0 and phase 1 (for seamless loops). */
+export function loopNoise(phase, radius = 1, seed = 0) {
+ const a = phase * TAU;
+ return noise2(Math.cos(a) * radius + 50, Math.sin(a) * radius + 50, seed);
+}
diff --git a/src/core/painter.js b/src/core/painter.js
new file mode 100644
index 0000000..f90ef4b
--- /dev/null
+++ b/src/core/painter.js
@@ -0,0 +1,328 @@
+// The painter draws into a frame's two buffers: `color` (opaque pixels, faded with ordered dither, never
+// blended) and `light` (additive glow, composited on top). Effects draw in local coordinates around their
+// origin; the painter places, mirrors and rotates them, so an effect never needs to know where it is.
+
+import { clamp } from "./math.js";
+import { hex } from "./color.js";
+import { rasterText, textWidth, FONTS } from "./font.js";
+
+// 4x4 ordered (Bayer) thresholds: a pixel at alpha a is drawn when a is above its cell's threshold.
+const BAYER = [0, 8, 2, 10, 12, 4, 14, 6, 3, 11, 1, 9, 15, 7, 13, 5].map((v) => (v + 0.5) / 16);
+const OUT = { c: 0, a: 1, l: 0, k: 0 };
+const sprites = new WeakMap();
+const call = (v, ...args) => (typeof v === "function" ? v(...args) : v);
+
+export class Painter {
+ constructor(frame) {
+ this.frame = frame;
+ this.reset();
+ }
+
+ /** Re-read the frame and clear placement, fade and light strength. */
+ reset() {
+ const f = this.frame;
+ this.w = f.w; this.h = f.h; this.ox = f.ox | 0; this.oy = f.oy | 0; this.C = f.color; this.L = f.light;
+ this.tx = 0; this.ty = 0; this.fx = 1; this.cs = 1; this.sn = 0;
+ this.fade = 1; this.lightK = 1; this.layer = "front";
+ return this;
+ }
+
+ /** Put the effect's origin at (x, y) in frame space, mirrored if flip, rotated by angle (radians). */
+ place(x, y, flip = false, angle = 0) {
+ this.tx = x; this.ty = y; this.fx = flip ? -1 : 1; this.cs = Math.cos(angle); this.sn = Math.sin(angle);
+ return this;
+ }
+
+ // ---- transforms: local (effect) space <-> screen (frame) space
+ toX(x, y) { return this.tx + x * this.fx * this.cs - y * this.sn; }
+ toY(x, y) { return this.ty + x * this.fx * this.sn + y * this.cs; }
+ fromX(sx, sy) { const dx = sx - this.tx, dy = sy - this.ty; return (dx * this.cs + dy * this.sn) * this.fx; }
+ fromY(sx, sy) { const dx = sx - this.tx, dy = sy - this.ty; return -dx * this.sn + dy * this.cs; }
+ // the screen pixel of the local pixel cell holding (x, y): mirrors and rotations land on whole cells
+ cellX(x, y) { return Math.floor(this.toX(Math.floor(x) + 0.5, Math.floor(y) + 0.5)); }
+ cellY(x, y) { return Math.floor(this.toY(Math.floor(x) + 0.5, Math.floor(y) + 0.5)); }
+
+ // ---- raw writes, screen space, whole pixels. Color 0 means "nothing": it never erases what's there.
+ put(sx, sy, c, a = 1) {
+ if (!c) return;
+ a *= this.fade;
+ if (a < 1 && a <= BAYER[((sy & 3) << 2) | (sx & 3)]) return;
+ const x = sx - this.ox, y = sy - this.oy;
+ if (x < 0 || y < 0 || x >= this.w || y >= this.h) return;
+ this.C[y * this.w + x] = c;
+ }
+ add(sx, sy, c, k = 1) {
+ k *= this.fade * this.lightK;
+ if (k <= 0.004) return;
+ const x = sx - this.ox, y = sy - this.oy;
+ if (x < 0 || y < 0 || x >= this.w || y >= this.h) return;
+ const i = y * this.w + x, d = this.L[i];
+ const r = Math.min(255, (d & 255) + (c & 255) * k) | 0;
+ const g = Math.min(255, ((d >>> 8) & 255) + ((c >>> 8) & 255) * k) | 0;
+ const b = Math.min(255, ((d >>> 16) & 255) + ((c >>> 16) & 255) * k) | 0;
+ this.L[i] = (255 << 24) | (b << 16) | (g << 8) | r;
+ }
+ /** Read back the color under a local point (0 if empty). */
+ get(x, y) {
+ const sx = this.cellX(x, y) - this.ox, sy = this.cellY(x, y) - this.oy;
+ return sx < 0 || sy < 0 || sx >= this.w || sy >= this.h ? 0 : this.C[sy * this.w + sx];
+ }
+
+ // ---- pixels
+ /** One opaque pixel. */
+ px(x, y, c) { this.put(this.cellX(x, y), this.cellY(x, y), c, 1); }
+ /** One pixel at alpha a (0..1), faded by ordered dither. */
+ dot(x, y, c, a = 1) { if (a > 0) this.put(this.cellX(x, y), this.cellY(x, y), c, a); }
+ /** Add light to one pixel. */
+ light(x, y, c, k = 1) { this.add(this.cellX(x, y), this.cellY(x, y), c, k); }
+
+ /**
+ * Visit every screen pixel whose center falls in the local box [x0, x1] x [y0, y1], with that center in
+ * local space: fn(lx, ly, sx, sy). The basis of every filled shape, so shapes mirror and rotate exactly.
+ */
+ each(x0, y0, x1, y1, fn) {
+ let ax = Infinity, bx = -Infinity, ay = Infinity, by = -Infinity;
+ for (let k = 0; k < 4; k++) {
+ const x = k & 1 ? x1 : x0, y = k & 2 ? y1 : y0, sx = this.toX(x, y), sy = this.toY(x, y);
+ if (sx < ax) ax = sx; if (sx > bx) bx = sx; if (sy < ay) ay = sy; if (sy > by) by = sy;
+ }
+ const sx0 = Math.max(Math.floor(ax), this.ox), sx1 = Math.min(Math.ceil(bx), this.ox + this.w - 1);
+ const sy0 = Math.max(Math.floor(ay), this.oy), sy1 = Math.min(Math.ceil(by), this.oy + this.h - 1);
+ for (let sy = sy0; sy <= sy1; sy++)
+ for (let sx = sx0; sx <= sx1; sx++) {
+ const cx = sx + 0.5, cy = sy + 0.5;
+ fn(this.fromX(cx, cy), this.fromY(cx, cy), sx, sy);
+ }
+ }
+
+ /**
+ * A pixel shader over a local box. fn(x, y, out) returns a color, or sets out.c (color), out.a (alpha),
+ * out.l (light color, defaults to out.c) and out.k (light amount). Return nothing to leave the pixel alone.
+ */
+ shade(x0, y0, x1, y1, fn) {
+ const o = OUT;
+ this.each(x0, y0, x1, y1, (lx, ly, sx, sy) => {
+ o.c = 0; o.a = 1; o.l = 0; o.k = 0;
+ const c = fn(lx, ly, o) || o.c;
+ if (c) this.put(sx, sy, c, o.a);
+ if (o.k > 0) this.add(sx, sy, o.l || c, o.k);
+ });
+ }
+
+ // ---- shapes. Colors (c) and alphas (a) can be numbers or functions of the shape's own coordinates.
+ /** 1 px line. c and a may be functions of u (0 at the start, 1 at the end). */
+ line(x0, y0, x1, y1, c, a = 1) {
+ let sx = this.cellX(x0, y0), sy = this.cellY(x0, y0);
+ const ex = this.cellX(x1, y1), ey = this.cellY(x1, y1);
+ const dx = Math.abs(ex - sx), dy = -Math.abs(ey - sy), stepx = sx < ex ? 1 : -1, stepy = sy < ey ? 1 : -1;
+ const n = Math.max(dx, -dy) || 1, fc = typeof c === "function", fa = typeof a === "function";
+ let err = dx + dy, i = 0;
+ for (;;) {
+ const u = i++ / n;
+ this.put(sx, sy, fc ? c(u) : c, fa ? a(u) : a);
+ if (sx === ex && sy === ey) break;
+ const e2 = 2 * err;
+ if (e2 >= dy) { err += dy; sx += stepx; }
+ if (e2 <= dx) { err += dx; sy += stepy; }
+ }
+ }
+ /** Lines through a list of points [[x, y], ...]. */
+ polyline(pts, c, a = 1) {
+ for (let i = 1; i < pts.length; i++) this.line(pts[i - 1][0], pts[i - 1][1], pts[i][0], pts[i][1], c, a);
+ }
+ /** Thick segment with round ends. c and a may be functions of (u along, v across: 0 center, 1 edge). */
+ beam(x0, y0, x1, y1, width, c, a = 1) {
+ const r = width / 2, dx = x1 - x0, dy = y1 - y0, L2 = dx * dx + dy * dy || 1e-9;
+ this.shade(Math.min(x0, x1) - r, Math.min(y0, y1) - r, Math.max(x0, x1) + r, Math.max(y0, y1) + r, (x, y, o) => {
+ const u = clamp(((x - x0) * dx + (y - y0) * dy) / L2), px = x0 + dx * u - x, py = y0 + dy * u - y;
+ const d2 = px * px + py * py;
+ if (d2 > r * r) return;
+ const v = Math.sqrt(d2) / r;
+ o.c = call(c, u, v);
+ o.a = call(a, u, v);
+ });
+ }
+ /** Filled disc. c and a may be functions of (d: 0 center to 1 rim, angle). */
+ circle(cx, cy, r, c, a = 1) {
+ if (r < 0.6) return this.dot(cx, cy, call(c, 0, 0), call(a, 0, 0));
+ this.shade(cx - r, cy - r, cx + r, cy + r, (x, y, o) => {
+ const dx = x - cx, dy = y - cy, d2 = dx * dx + dy * dy;
+ if (d2 > r * r) return;
+ const d = Math.sqrt(d2) / r, ang = Math.atan2(dy, dx);
+ o.c = call(c, d, ang);
+ o.a = call(a, d, ang);
+ });
+ }
+ /** Ellipse. c and a may be functions of (d: 0 center to 1 rim, angle). */
+ ellipse(cx, cy, rx, ry, c, a = 1) {
+ if (rx <= 0 || ry <= 0) return;
+ this.shade(cx - rx, cy - ry, cx + rx, cy + ry, (x, y, o) => {
+ const dx = (x - cx) / rx, dy = (y - cy) / ry, d2 = dx * dx + dy * dy;
+ if (d2 > 1) return;
+ const d = Math.sqrt(d2), ang = Math.atan2(dy, dx);
+ o.c = call(c, d, ang);
+ o.a = call(a, d, ang);
+ });
+ }
+ /** Ring from radius r - w to r. c and a may be functions of (v: 0 inner to 1 outer, angle). */
+ ring(cx, cy, r, w, c, a = 1) {
+ const r0 = Math.max(0, r - w);
+ this.shade(cx - r, cy - r, cx + r, cy + r, (x, y, o) => {
+ const dx = x - cx, dy = y - cy, d2 = dx * dx + dy * dy;
+ if (d2 > r * r || d2 < r0 * r0) return;
+ const v = w > 0 ? (Math.sqrt(d2) - r0) / (r - r0 || 1) : 1, ang = Math.atan2(dy, dx);
+ o.c = call(c, v, ang);
+ o.a = call(a, v, ang);
+ });
+ }
+ /**
+ * Band of a ring from angle a0 to a1 (radians, a1 > a0), radius r - w to r: the slash and smear shape.
+ * c and a may be functions of (u: 0 at a0 to 1 at a1, v: 0 inner to 1 outer). w can be a function of u
+ * for a crescent that tapers at both ends.
+ */
+ arc(cx, cy, r, w, a0, a1, c, a = 1) {
+ const span = a1 - a0, wf = typeof w === "function";
+ this.shade(cx - r, cy - r, cx + r, cy + r, (x, y, o) => {
+ const dx = x - cx, dy = y - cy, d = Math.sqrt(dx * dx + dy * dy);
+ if (d > r) return;
+ let ang = Math.atan2(dy, dx) - a0;
+ ang -= Math.floor(ang / (Math.PI * 2)) * Math.PI * 2;
+ if (ang > span) return;
+ const u = ang / span, ww = wf ? w(u) : w;
+ if (ww <= 0 || d < r - ww) return;
+ const v = (d - (r - ww)) / ww;
+ o.c = call(c, u, v);
+ o.a = call(a, u, v);
+ });
+ }
+ /** Filled rectangle. */
+ rect(x, y, w, h, c, a = 1) {
+ if (this.sn === 0) {
+ const X0 = Math.round(x), Y0 = Math.round(y), X1 = Math.round(x + w), Y1 = Math.round(y + h);
+ for (let yy = Y0; yy < Y1; yy++) for (let xx = X0; xx < X1; xx++) this.put(this.cellX(xx, yy), this.cellY(xx, yy), c, a);
+ return;
+ }
+ this.shade(x, y, x + w, y + h, (lx, ly, o) => {
+ if (lx < x || ly < y || lx >= x + w || ly >= y + h) return;
+ o.c = c; o.a = a;
+ });
+ }
+ /** Filled polygon from points [[x, y], ...] (even-odd rule). */
+ poly(pts, c, a = 1) {
+ let x0 = Infinity, y0 = Infinity, x1 = -Infinity, y1 = -Infinity;
+ for (const [x, y] of pts) { if (x < x0) x0 = x; if (x > x1) x1 = x; if (y < y0) y0 = y; if (y > y1) y1 = y; }
+ const n = pts.length;
+ this.shade(x0, y0, x1, y1, (x, y, o) => {
+ let inside = false;
+ for (let i = 0, j = n - 1; i < n; j = i++) {
+ const [xi, yi] = pts[i], [xj, yj] = pts[j];
+ if (yi > y !== yj > y && x < ((xj - xi) * (y - yi)) / (yj - yi) + xi) inside = !inside;
+ }
+ if (!inside) return;
+ o.c = call(c, x, y);
+ o.a = call(a, x, y);
+ });
+ }
+ tri(x0, y0, x1, y1, x2, y2, c, a = 1) { this.poly([[x0, y0], [x1, y1], [x2, y2]], c, a); }
+
+ // ---- light
+ /** Radial glow into the light buffer: k at the center, falling to 0 at radius r. */
+ glow(x, y, r, c, k = 0.5) {
+ if (r < 1 || k <= 0.004) return;
+ const cx = this.toX(x, y), cy = this.toY(x, y);
+ const x0 = Math.floor(cx - r), x1 = Math.ceil(cx + r), y0 = Math.floor(cy - r), y1 = Math.ceil(cy + r);
+ for (let sy = y0; sy <= y1; sy++) {
+ const dy = (sy + 0.5 - cy) / r;
+ for (let sx = x0; sx <= x1; sx++) {
+ const dx = (sx + 0.5 - cx) / r, d = dx * dx + dy * dy;
+ if (d >= 1) continue;
+ const f = 1 - Math.sqrt(d);
+ this.add(sx, sy, c, f * f * k);
+ }
+ }
+ }
+ /** Glow around a segment (a soft beam of light). */
+ glowLine(x0, y0, x1, y1, r, c, k = 0.5) {
+ if (r < 1 || k <= 0.004) return;
+ const ax = this.toX(x0, y0), ay = this.toY(x0, y0), bx = this.toX(x1, y1), by = this.toY(x1, y1);
+ const dx = bx - ax, dy = by - ay, L2 = dx * dx + dy * dy || 1e-9;
+ const X0 = Math.floor(Math.min(ax, bx) - r), X1 = Math.ceil(Math.max(ax, bx) + r);
+ const Y0 = Math.floor(Math.min(ay, by) - r), Y1 = Math.ceil(Math.max(ay, by) + r);
+ for (let sy = Y0; sy <= Y1; sy++)
+ for (let sx = X0; sx <= X1; sx++) {
+ const px = sx + 0.5, py = sy + 0.5, u = clamp(((px - ax) * dx + (py - ay) * dy) / L2);
+ const ex = ax + dx * u - px, ey = ay + dy * u - py, d = Math.sqrt(ex * ex + ey * ey) / r;
+ if (d >= 1) continue;
+ const f = 1 - d;
+ this.add(sx, sy, c, f * f * k);
+ }
+ }
+ /** Glow hugging a circle of radius R (a shockwave's light), falling off over width r. */
+ glowRing(x, y, R, r, c, k = 0.5) {
+ if (r < 1 || k <= 0.004) return;
+ const cx = this.toX(x, y), cy = this.toY(x, y), E = R + r;
+ for (let sy = Math.floor(cy - E); sy <= Math.ceil(cy + E); sy++)
+ for (let sx = Math.floor(cx - E); sx <= Math.ceil(cx + E); sx++) {
+ const d = Math.abs(Math.hypot(sx + 0.5 - cx, sy + 0.5 - cy) - R) / r;
+ if (d >= 1) continue;
+ const f = 1 - d;
+ this.add(sx, sy, c, f * f * k);
+ }
+ }
+
+ // ---- sprites, text, masks
+ /**
+ * A little sprite from strings: rows like ["..##..", ".#oo#."], pal maps characters to colors
+ * ({ "#": "#222034", o: 0xff... }); "." and " " are empty. Top-left at (x, y).
+ * opts: { scale, a, flip (mirror left-right), flipY (upside down), tint (draw every pixel in one color) }.
+ */
+ sprite(rows, pal, x, y, opts = {}) {
+ let s = sprites.get(rows);
+ if (!s) sprites.set(rows, (s = rows.map((r) => [...r])));
+ const k = opts.scale ?? 1, a = opts.a ?? 1, W = s[0]?.length ?? 0, cache = {};
+ for (let r = 0; r < s.length; r++)
+ for (let q = 0; q < s[r].length; q++) {
+ const ch = s[r][q];
+ if (ch === "." || ch === " ") continue;
+ let c = opts.tint;
+ if (c === undefined) {
+ c = cache[ch];
+ if (c === undefined) c = cache[ch] = pal[ch] === undefined ? 0 : hex(pal[ch]);
+ }
+ if (!c) continue;
+ const col = opts.flip ? W - 1 - q : q, row = opts.flipY ? s.length - 1 - r : r;
+ if (k === 1) this.dot(x + col, y + row, c, a);
+ else this.rect(x + col * k, y + row * k, k, k, c, a);
+ }
+ }
+ /**
+ * Pixel text. opts: { font: "mini" (3x5) | "big" (5x7), scale, align: "left" | "center" | "right",
+ * outline: color, shadow: color, a }. (x, y) is the top of the text, at the left, center or right.
+ */
+ text(str, x, y, c, opts = {}) {
+ const font = opts.font ?? "mini", k = opts.scale ?? 1, a = opts.a ?? 1, w = textWidth(str, font) * k;
+ const left = Math.round(opts.align === "center" ? x - w / 2 : opts.align === "right" ? x - w : x), top = Math.round(y);
+ const ol = opts.outline, sh = opts.shadow;
+ if (ol !== undefined) rasterText(str, font, (gx, gy) => this.rect(left + gx * k - 1, top + gy * k - 1, k + 2, k + 2, ol, a));
+ if (sh !== undefined) rasterText(str, font, (gx, gy) => this.rect(left + gx * k + 1, top + gy * k + 1, k, k, sh, a));
+ rasterText(str, font, (gx, gy) => this.rect(left + gx * k, top + gy * k, k, k, call(c, gx, gy), a));
+ }
+ /** Size of text in pixels: [w, h]. */
+ measure(str, opts = {}) {
+ const k = opts.scale ?? 1;
+ return [textWidth(str, opts.font ?? "mini") * k, FONTS[opts.font ?? "mini"].h * k];
+ }
+ /** Fill a mask ({ w, h, data }) with its top-left at (x, y). c may be a function of (mx, my). */
+ mask(m, x, y, c, a = 1) {
+ for (let my = 0; my < m.h; my++)
+ for (let mx = 0; mx < m.w; mx++) if (m.data[my * m.w + mx]) this.dot(x + mx, y + my, call(c, mx, my), call(a, mx, my));
+ }
+ /** The 1 px outline just outside a mask. */
+ outline(m, x, y, c, a = 1) {
+ const at = (mx, my) => mx >= 0 && my >= 0 && mx < m.w && my < m.h && m.data[my * m.w + mx];
+ for (let my = -1; my <= m.h; my++)
+ for (let mx = -1; mx <= m.w; mx++)
+ if (!at(mx, my) && (at(mx - 1, my) || at(mx + 1, my) || at(mx, my - 1) || at(mx, my + 1)))
+ this.dot(x + mx, y + my, call(c, mx, my), call(a, mx, my));
+ }
+}
diff --git a/src/core/particles.js b/src/core/particles.js
new file mode 100644
index 0000000..345c67f
--- /dev/null
+++ b/src/core/particles.js
@@ -0,0 +1,92 @@
+// Particles without a simulation: each one's position is a closed-form function of its age, so an effect
+// can be drawn at any time t, scrubbed, looped and rendered to a sprite sheet frame by frame.
+
+import { rng, clamp } from "./math.js";
+
+/**
+ * Where a particle is after t seconds, launched from (x, y) at (vx, vy) px/s, under gravity g (px/s²,
+ * positive is down) and linear drag (1/s). Returns [x, y].
+ */
+export function fly(x, y, vx, vy, t, g = 0, drag = 0) {
+ if (drag <= 0) return [x + vx * t, y + vy * t + 0.5 * g * t * t];
+ const f = (1 - Math.exp(-drag * t)) / drag, vt = g / drag;
+ return [x + vx * f, y + vt * t + (vy - vt) * f];
+}
+/** Its velocity at t, for streaks that point along the motion. Returns [vx, vy]. */
+export function flyV(vx, vy, t, g = 0, drag = 0) {
+ if (drag <= 0) return [vx, vy + g * t];
+ const e = Math.exp(-drag * t), vt = g / drag;
+ return [vx * e, vt + (vy - vt) * e];
+}
+
+/**
+ * n one-shot particles: fn(r, i) with a repeatable rng per particle (the same numbers every frame).
+ */
+export function burst(n, seed, fn) {
+ for (let i = 0; i < n; i++) fn(rng(seed, i), i);
+}
+
+/**
+ * Particles that repeat every `period` seconds, for loops with no seam. Particle i is born at its own
+ * phase in the period and lives `life` seconds (a number, or a function of an rng). For every live copy,
+ * fn(age, life, r, i) is called; r is a fresh rng for particle i, the same each period.
+ */
+export function cycle(t, period, count, seed, life, fn) {
+ for (let i = 0; i < count; i++) {
+ const g = rng(seed, i, 911);
+ const born = g.next() * period;
+ const L = typeof life === "function" ? life(g) : life;
+ let age = (((t - born) % period) + period) % period;
+ for (; age < L; age += period) fn(age, L, rng(seed, i), i);
+ }
+}
+
+/**
+ * Particles born at a steady rate between t0 and t1 (an emitter that stops): fn(age, life, r, i) for every
+ * particle alive at t. rate is particles per second.
+ */
+export function stream(t, t0, t1, rate, seed, life, fn) {
+ const n = Math.floor((Math.min(t, t1) - t0) * rate);
+ for (let i = 0; i <= n; i++) {
+ const born = t0 + i / rate, g = rng(seed, i, 911), L = typeof life === "function" ? life(g) : life;
+ const age = t - born;
+ if (age >= 0 && age < L) fn(age, L, rng(seed, i), i);
+ }
+}
+
+/** A simple simulated particle list, for effects that export create() and keep state. */
+export class Particles {
+ constructor() {
+ this.list = [];
+ }
+ /** p: { x, y, vx, vy, life, g?, drag?, ground?, bounce? } plus anything you want to draw with. */
+ add(p) {
+ p.age = 0;
+ p.g ??= 0;
+ p.drag ??= 0;
+ this.list.push(p);
+ return p;
+ }
+ update(dt) {
+ for (let i = this.list.length - 1; i >= 0; i--) {
+ const p = this.list[i];
+ if ((p.age += dt) >= p.life) {
+ this.list.splice(i, 1);
+ continue;
+ }
+ p.vx -= p.vx * p.drag * dt;
+ p.vy += p.g * dt - p.vy * p.drag * dt;
+ p.x += p.vx * dt;
+ p.y += p.vy * dt;
+ if (p.ground !== undefined && p.y > p.ground) {
+ p.y = p.ground;
+ p.vy = -Math.abs(p.vy) * (p.bounce ?? 0.3);
+ p.vx *= 0.7;
+ }
+ }
+ }
+ /** Life left, 1 at birth to 0 at death. */
+ static k(p) {
+ return clamp(1 - p.age / p.life);
+ }
+}
diff --git a/src/core/scene.js b/src/core/scene.js
new file mode 100644
index 0000000..04b61a3
--- /dev/null
+++ b/src/core/scene.js
@@ -0,0 +1,41 @@
+// Preview backdrops: what the tools and the gallery draw behind an effect. Sprite sheets stay transparent.
+
+import { hex, mix } from "./color.js";
+import { rand } from "./math.js";
+
+const SKY = hex("#15131d"), SKY_TOP = hex("#0d0b14"), SKY_LOW = hex("#221d33");
+const FLOOR_EDGE = hex("#4a4263"), FLOOR = hex("#2b2639"), FLOOR_DARK = hex("#211d2d"), MORTAR = hex("#1a1724");
+const BAYER = [0, 8, 2, 10, 12, 4, 14, 6, 3, 11, 1, 9, 15, 7, 13, 5];
+
+export const BACKDROPS = ["dark", "ground", "sky", "light", "black"];
+
+/**
+ * A backdrop as a Uint32Array of w x h colors. kind: "dark" | "ground" (a stone floor from groundY down)
+ * | "sky" (night gradient with stars) | "light" | "black".
+ */
+export function backdrop(kind, w, h, groundY = h) {
+ const out = new Uint32Array(w * h);
+ if (kind === "light") return out.fill(hex("#ebe8f0"));
+ if (kind === "black") return out.fill(hex("#000000"));
+ for (let y = 0; y < h; y++)
+ for (let x = 0; x < w; x++) {
+ let c = SKY;
+ if (kind === "sky") {
+ const t = y / Math.max(1, h - 1), step = (t * 5 + BAYER[((y & 3) << 2) | (x & 3)] / 16) | 0;
+ c = mix(SKY_TOP, SKY_LOW, Math.min(1, step / 4));
+ const r = rand(x, y, 77);
+ if (r > 0.994) c = mix(c, hex("#cfc8ff"), 0.35 + (r - 0.994) * 90);
+ }
+ if (kind === "ground" && y >= groundY) {
+ const gy = y - groundY;
+ if (gy === 0) c = FLOOR_EDGE;
+ else {
+ const row = Math.floor((gy - 1) / 5), off = row % 2 ? 6 : 0;
+ const mortar = (gy - 1) % 5 === 4 || (x + off) % 12 === 0;
+ c = mortar ? MORTAR : gy < 3 ? FLOOR : FLOOR_DARK;
+ }
+ }
+ out[y * w + x] = c;
+ }
+ return out;
+}
diff --git a/src/core/shapes.js b/src/core/shapes.js
new file mode 100644
index 0000000..a59200b
--- /dev/null
+++ b/src/core/shapes.js
@@ -0,0 +1,55 @@
+// Point lists for shapes effects keep reaching for: lightning paths, stars, polygons, trails.
+
+import { TAU } from "./math.js";
+
+/**
+ * A jagged lightning path from (x0, y0) to (x1, y1) by midpoint displacement. jag is how far a midpoint
+ * may move sideways, as a share of the segment's length. Returns [[x, y], ...].
+ */
+export function bolt(r, x0, y0, x1, y1, { jag = 0.22, depth = 5 } = {}) {
+ let pts = [[x0, y0], [x1, y1]];
+ for (let d = 0; d < depth; d++) {
+ const next = [pts[0]];
+ for (let i = 1; i < pts.length; i++) {
+ const [ax, ay] = pts[i - 1], [bx, by] = pts[i], dx = bx - ax, dy = by - ay, L = Math.hypot(dx, dy);
+ const off = (r.next() * 2 - 1) * jag * L;
+ next.push([(ax + bx) / 2 + (-dy / (L || 1)) * off, (ay + by) / 2 + (dx / (L || 1)) * off], pts[i]);
+ }
+ pts = next;
+ }
+ return pts;
+}
+
+/** Forks off a bolt path: count branches, each up to len px long. Returns a list of paths. */
+export function forks(r, path, { count = 3, len = 20, jag = 0.3, spread = 0.9 } = {}) {
+ const out = [];
+ for (let k = 0; k < count; k++) {
+ const i = 1 + Math.floor(r.next() * (path.length - 2)), [x, y] = path[i], [px, py] = path[i - 1];
+ const a = Math.atan2(y - py, x - px) + (r.next() < 0.5 ? -1 : 1) * spread * (0.4 + 0.6 * r.next());
+ const l = len * (0.4 + 0.6 * r.next());
+ out.push(bolt(r, x, y, x + Math.cos(a) * l, y + Math.sin(a) * l, { jag, depth: 3 }));
+ }
+ return out;
+}
+
+/** A star: n points between radii r1 (tips) and r0 (inner corners). */
+export function star(cx, cy, r0, r1, n = 5, rot = -Math.PI / 2) {
+ const pts = [];
+ for (let i = 0; i < n * 2; i++) {
+ const a = rot + (i * Math.PI) / n, r = i % 2 ? r0 : r1;
+ pts.push([cx + Math.cos(a) * r, cy + Math.sin(a) * r]);
+ }
+ return pts;
+}
+
+/** A regular polygon with n sides. */
+export function ngon(cx, cy, r, n = 6, rot = 0) {
+ return Array.from({ length: n }, (_, i) => [cx + Math.cos(rot + (i * TAU) / n) * r, cy + Math.sin(rot + (i * TAU) / n) * r]);
+}
+
+/** Positions of pos(t - i * dt) for i = 0..n-1: a moving thing's trail, newest first. */
+export function trail(pos, t, n, dt) {
+ const out = [];
+ for (let i = 0; i < n; i++) out.push(pos(Math.max(0, t - i * dt)));
+ return out;
+}
diff --git a/src/fx/arcane/_lib.js b/src/fx/arcane/_lib.js
new file mode 100644
index 0000000..89a2b9b
--- /dev/null
+++ b/src/fx/arcane/_lib.js
@@ -0,0 +1,129 @@
+// Shared by the arcane effects: palettes, a small rune alphabet, sparkles and a squashable actor silhouette.
+// Files starting with _ are helpers, not effects.
+
+import { ramp, hex, stockActor, WHITE } from "../../core/index.js";
+import { HERO, HERO_PAL } from "../../core/actor.js";
+
+/** Any palette as exactly n steps (nearest step, never blended), so an effect can index C[0..n-1]. */
+export function fit(pal, n = 8) {
+ const r = ramp(pal);
+ return Array.from({ length: n }, (_, i) => r[Math.round((i * (r.length - 1)) / (n - 1))]);
+}
+
+// Extra ramps in the arcane family, dark to bright, hue-shifted like the core ones.
+export const AZURE = ["#0d0c2a", "#1b1d62", "#28399e", "#3462d2", "#4f96f0", "#8ccaff", "#d6f0ff", "#ffffff"];
+export const MAGENTA = ["#1c0620", "#420e4a", "#741878", "#a8269e", "#da44c8", "#ff80e0", "#ffcef4", "#ffffff"];
+export const CHRONO = ["#071a1f", "#0d3239", "#14535a", "#1d7f80", "#35b0a6", "#7fe0cc", "#d2fff1", "#ffffff"];
+export const STARLIGHT = ["#0f1232", "#1d2766", "#2f479e", "#4c75cf", "#86aef0", "#c8dcff", "#fff4d2", "#ffffff"];
+
+// Runes: an original angular alphabet. 5x5 for floating glyphs, 3x3 for bands on circles and blades.
+export const RUNES = [
+ ["..#..", ".###.", "#.#.#", "..#..", ".#.#."],
+ ["#...#", "##.##", "#.#.#", "..#..", "..#.."],
+ ["####.", "#....", "###..", "#..#.", "#...#"],
+ ["#.#.#", "#.#.#", ".###.", "..#..", ".###."],
+ [".###.", "#...#", "..#..", ".#.#.", "#...#"],
+ ["#..#.", "#.#..", "##...", "#.#..", "#..##"],
+ ["..#..", "#.#.#", "#####", "..#..", "..#.."],
+ ["##.##", "..#..", ".#.#.", "#...#", "#...#"],
+];
+export const RUNES3 = [
+ ["#.#", ".#.", "#.#"],
+ ["###", ".#.", ".#."],
+ ["#..", "###", "..#"],
+ ["#.#", "###", "#.."],
+ ["##.", "#.#", ".##"],
+ [".##", "#..", "##."],
+ ["#.#", "#.#", ".#."],
+ ["###", "#.#", "#.."],
+];
+
+/** One rune centred on (x, y) in one color, alpha a (dithered). small: the 3x3 set. edge: a 1 px outline color. */
+export function rune(p, i, x, y, c, a = 1, small = false, edge) {
+ const set = small ? RUNES3 : RUNES, g = set[((i % set.length) + set.length) % set.length], h = g.length >> 1;
+ const X = Math.round(x) - h, Y = Math.round(y) - h;
+ if (edge !== undefined) for (const [dx, dy] of [[1, 0], [-1, 0], [0, 1], [0, -1]]) p.sprite(g, {}, X + dx, Y + dy, { tint: edge, a });
+ p.sprite(g, {}, X, Y, { tint: c, a });
+}
+
+/**
+ * A four-point twinkle centred on (x, y). size 0 is one pixel, 1 a small plus, 2 longer arms with dim
+ * tips, 3 adds diagonal glints. arm and tip are colors; the core is white unless given.
+ */
+export function sparkle(p, x, y, size, arm, tip = arm, core = WHITE, a = 1) {
+ x = Math.round(x);
+ y = Math.round(y);
+ const s = Math.round(size);
+ if (s >= 1) for (const [dx, dy] of [[1, 0], [-1, 0], [0, 1], [0, -1]]) p.dot(x + dx, y + dy, arm, a);
+ if (s >= 2) for (const [dx, dy] of [[2, 0], [-2, 0], [0, 2], [0, -2]]) p.dot(x + dx, y + dy, tip, a);
+ if (s >= 3) {
+ for (const [dx, dy] of [[3, 0], [-3, 0], [0, 3], [0, -3]]) p.dot(x + dx, y + dy, tip, a * 0.6);
+ for (const [dx, dy] of [[1, 1], [-1, 1], [1, -1], [-1, -1]]) p.dot(x + dx, y + dy, tip, a * 0.7);
+ }
+ p.dot(x, y, s >= 1 ? core : arm, a);
+}
+
+const HERO_COLORS = Object.fromEntries(Object.entries(HERO_PAL).map(([k, v]) => [k, hex(v)]));
+const STOCK_MASK = stockActor().mask;
+
+/**
+ * The actor drawn pixel by pixel, squashed to sx x sy around its feet (0, 0). color(mx, my, base) picks
+ * each pixel's color: base is the stock character's own color for that pixel (or 0 for a custom mask).
+ * a(mx, my) is its alpha. Squashing samples the mask, so it stays hard-edged at any scale.
+ */
+export function silhouette(p, A, sx, sy, color, a = 1, cx = 0) {
+ if (sx <= 0.01 || sy <= 0.01) return;
+ const stock = A.mask === STOCK_MASK; // only the stock character's own colors are known
+ const W = A.w * sx, H = A.h * sy, left = cx + (A.x + A.w / 2) * sx - W / 2, top = -H;
+ const fa = typeof a === "function";
+ p.shade(left - 1, top - 1, left + W + 1, 1, (x, y, o) => {
+ if (x < left || x >= left + W || y < top || y >= 0) return;
+ const mx = Math.floor((x - left) / sx), my = Math.floor((y - top) / sy);
+ if (mx < 0 || my < 0 || mx >= A.w || my >= A.h || !A.mask.data[my * A.w + mx]) return;
+ const base = stock ? HERO_COLORS[HERO[my][mx]] ?? 0 : 0;
+ o.c = color(mx, my, base);
+ o.a = fa ? a(mx, my) : a;
+ });
+}
+
+
+/**
+ * A 1 px ellipse outline (a circle seen at an angle) centred on (x0, y0). c and a may be functions of the
+ * angle around it (radians, 0 at the right, +pi/2 at the front). The pixel test uses the true distance to
+ * the curve, so the line stays one pixel thick all the way round.
+ */
+export function ovalLine(p, rx, ry, c, a = 1, x0 = 0, y0 = 0) {
+ if (rx < 0.5 || ry < 0.5) return;
+ const fc = typeof c === "function", fa = typeof a === "function";
+ p.shade(x0 - rx - 1, y0 - ry - 1, x0 + rx + 1, y0 + ry + 1, (x, y, o) => {
+ const nx = (x - x0) / rx, ny = (y - y0) / ry, d = Math.hypot(nx, ny);
+ if (d < 1e-6) return;
+ const g = Math.hypot(nx / rx, ny / ry) / d;
+ if (Math.abs(d - 1) / g > 0.5) return;
+ const ang = Math.atan2(ny, nx);
+ o.c = fc ? c(ang) : c;
+ o.a = fa ? a(ang) : a;
+ });
+}
+
+/** Angle difference folded into [0, TAU): how far b is past a going clockwise (y down). */
+export const ahead = (a, b) => (((b - a) % (Math.PI * 2)) + Math.PI * 2) % (Math.PI * 2);
+
+/**
+ * A 1 px ellipse outline tilted by `tilt` radians (a ring seen at an angle and rolled). c and a may be
+ * functions of the angle around the ring, measured in the ring's own frame: sin(angle) > 0 is its near side.
+ */
+export function tiltedOval(p, cx, cy, rx, ry, tilt, c, a = 1) {
+ if (rx < 0.5 || ry < 0.5) return;
+ const fc = typeof c === "function", fa = typeof a === "function", cs = Math.cos(tilt), sn = Math.sin(tilt), R = Math.max(rx, ry) + 1;
+ p.shade(cx - R, cy - R, cx + R, cy + R, (x, y, o) => {
+ const dx = x - cx, dy = y - cy, u = dx * cs + dy * sn, v = -dx * sn + dy * cs;
+ const nx = u / rx, ny = v / ry, d = Math.hypot(nx, ny);
+ if (d < 1e-6) return;
+ const g = Math.hypot(nx / rx, ny / ry) / d;
+ if (Math.abs(d - 1) / g > 0.5) return;
+ const ang = Math.atan2(ny, nx);
+ o.c = fc ? c(ang) : c;
+ o.a = fa ? a(ang) : a;
+ });
+}
diff --git a/src/fx/arcane/arcane-beam.js b/src/fx/arcane/arcane-beam.js
new file mode 100644
index 0000000..1687982
--- /dev/null
+++ b/src/fx/arcane/arcane-beam.js
@@ -0,0 +1,70 @@
+import { PAL, cycle, clamp, tileNoise, TAU, WHITE } from "../../core/index.js";
+import { fit, sparkle } from "./_lib.js";
+
+export const meta = {
+ name: "Arcane beam",
+ desc: "A continuous violet beam firing right: a white-hot core in a wobbling sheath, two strands twisting round it, a flaring source and a splash at the end.",
+ tags: ["arcane", "beam", "laser", "channel", "magic", "directional", "loop"],
+ size: [132, 40],
+ origin: [13, 19],
+ duration: 0.8,
+ loop: true,
+ fps: 30,
+ bg: "dark",
+ options: { palette: PAL.arcane, length: 104, width: 4, seed: 15 },
+};
+
+export function draw(p, t, o) {
+ const C = fit(o.palette), L = o.length, W = o.width, S = o.seed, ph = t / meta.duration;
+ // the beam's spine sways more the further it gets from the hand; every motion is a whole number of waves a loop
+ const spine = (x) => Math.sin(x * 0.07 - ph * TAU * 2) * 1.6 * clamp(x / 40);
+ const half = (x) => W * (0.85 + 0.25 * Math.sin(x * 0.3 - ph * TAU * 4)) + 0.6 * tileNoise(x * 0.25 - ph * 16, 0, 16, 0, S);
+ // strands behind the beam
+ const strand = (x, k) => spine(x) + (half(x) + 2.5) * Math.sin(x * 0.18 - ph * TAU * 3 + k * Math.PI);
+ const depth = (x, k) => Math.cos(x * 0.18 - ph * TAU * 3 + k * Math.PI);
+ const strands = (front) => {
+ for (let x = 5; x < L - 3; x++)
+ for (let k = 0; k < 2; k++) {
+ const d = depth(x + 0.5, k);
+ if (d >= 0 !== front) continue;
+ p.line(x, strand(x, k), x + 1, strand(x + 1, k), front ? (d > 0.6 ? C[6] : C[5]) : C[3]);
+ }
+ };
+ strands(false);
+ // the body: core, sheath and a ragged edge, scrolling
+ p.shade(0, -W * 2 - 4, L + 1, W * 2 + 4, (x, y, out) => {
+ if (x < 0 || x > L) return;
+ const v = Math.abs(y - spine(x)) / half(x), flick = tileNoise(x * 0.35 - ph * 24, y * 0.5, 24, 0, S + 1) * 0.12;
+ const tipFade = clamp((L - x) / 6);
+ const lvl = v - flick + (1 - tipFade) * 0.6;
+ if (lvl > 1.2) return;
+ out.c = lvl < 0.2 ? WHITE : lvl < 0.45 ? C[6] : lvl < 0.72 ? C[5] : lvl < 0.98 ? C[4] : C[3];
+ out.k = 0.12;
+ });
+ // strands in front
+ strands(true);
+ // motes streaming along it, faster than the eye can follow
+ cycle(t, meta.duration, 10, S, (r) => r.range(0.25, 0.45), (age, life, r) => {
+ const k = age / life, x = 6 + k * (L - 10), y = spine(x) + r.range(-1, 1) * (half(x) + 4);
+ p.line(x - 4, y, x, y, k < 0.7 ? C[6] : C[5]);
+ });
+ // the source: a hot ball at the hand with four rays turning
+ const pulse = 0.5 + 0.5 * Math.sin(ph * TAU * 4);
+ p.circle(0, 0, W + 1.5 + pulse, (d) => (d < 0.55 ? WHITE : d < 0.85 ? C[6] : C[5]));
+ for (let i = 0; i < 4; i++) {
+ const a = ph * TAU + (i * TAU) / 4, rl = W + 5 + 2 * pulse;
+ p.line(Math.cos(a) * (W + 1), Math.sin(a) * (W + 1), Math.cos(a) * rl, Math.sin(a) * rl, i % 2 ? C[6] : C[5]);
+ }
+ // the end: a splash that churns and throws sparks back
+ const ex = L, ey = spine(L);
+ // flattened against whatever it hits: taller than it is wide
+ p.ellipse(ex, ey, W * 0.7 + pulse, W * 1.5 + pulse * 1.5, (d) => (d < 0.4 ? WHITE : d < 0.75 ? C[6] : C[5]));
+ cycle(t, meta.duration, 8, S + 3, (r) => r.range(0.12, 0.24), (age, life, r) => {
+ const k = age / life, a = Math.PI + r.range(-1.3, 1.3), sp = r.range(50, 90);
+ const x = ex + Math.cos(a) * sp * age, y = ey + Math.sin(a) * sp * age + 60 * age * age;
+ sparkle(p, x, y, k < 0.4 ? 1 : 0, C[6], C[5], k < 0.5 ? WHITE : C[6]);
+ });
+ p.glowLine(0, 0, L, ey, 10, C[4], 0.28);
+ p.glow(0, 0, 14, C[5], 0.35 + 0.15 * pulse);
+ p.glow(ex, ey, 12, C[5], 0.35 + 0.15 * pulse);
+}
diff --git a/src/fx/arcane/arcane-missiles.js b/src/fx/arcane/arcane-missiles.js
new file mode 100644
index 0000000..63a60ad
--- /dev/null
+++ b/src/fx/arcane/arcane-missiles.js
@@ -0,0 +1,102 @@
+import { PAL, burst, fly, seg, ease, bump, rng, TAU, WHITE } from "../../core/index.js";
+import { fit, sparkle } from "./_lib.js";
+
+export const meta = {
+ name: "Arcane missiles",
+ desc: "A volley of violet bolts fans out from the hand, curls in on the target and pops one after another.",
+ tags: ["arcane", "projectile", "magic", "homing", "directional", "one-shot"],
+ size: [112, 56],
+ origin: [12, 28],
+ duration: 1.05,
+ loop: false,
+ fps: 30,
+ bg: "dark",
+ options: { palette: PAL.arcane, count: 4, range: 86, seed: 7 },
+};
+
+const bez = (a, b, c, d, u) => {
+ const v = 1 - u;
+ return v * v * v * a + 3 * v * v * u * b + 3 * v * u * u * c + u * u * u * d;
+};
+
+// one missile's flight: launch time, flight time and a curve that swings out wide then hooks onto the target
+function missile(o, i, n) {
+ const r = rng(o.seed, i, 3), lane = n > 1 ? (i / (n - 1)) * 2 - 1 : 0;
+ // alternate up and down so consecutive bolts fan apart; outer lanes swing widest
+ const side = i % 2 ? 1 : -1, swing = 0.62 + 0.38 * Math.abs(lane);
+ const t0 = 0.03 + i * 0.075 + r.range(-0.01, 0.015), fd = r.range(0.34, 0.42);
+ const tx = o.range + r.range(-2, 2), ty = side * r.range(1, 5);
+ const P = [[0, 0], [r.range(8, 18), side * swing * r.range(38, 46)], [tx - r.range(24, 34), -side * r.range(8, 16)], [tx, ty]];
+ const wob = r.range(0, TAU), wf = r.range(16, 24);
+ const at = (k) => {
+ const u = 0.7 * k + 0.3 * k * k;
+ return [bez(P[0][0], P[1][0], P[2][0], P[3][0], u), bez(P[0][1], P[1][1], P[2][1], P[3][1], u) + Math.sin(u * wf + wob) * 1.4 * (1 - u)];
+ };
+ return { t0, fd, at, tx, ty };
+}
+
+export function draw(p, t, o) {
+ const C = fit(o.palette), n = o.count, S = o.seed;
+ const ms = Array.from({ length: n }, (_, i) => missile(o, i, n));
+ // the casting hand: a small orb that throbs with each launch
+ const last = ms[n - 1].t0;
+ if (t < last + 0.14) {
+ let kick = 0;
+ for (const m of ms) kick = Math.max(kick, bump(t, m.t0 - 0.02, m.t0 + 0.1));
+ const fade = 1 - seg(t, last + 0.02, last + 0.14);
+ p.circle(0, 0, 1.6 + 1.6 * kick, (d) => (d < 0.5 ? WHITE : d < 0.8 ? C[6] : C[5]), fade);
+ p.glow(0, 0, 12, C[4], (0.25 + 0.3 * kick) * fade);
+ }
+ ms.forEach((m, i) => {
+ const k = seg(t, m.t0, m.t0 + m.fd);
+ // motes shed along the path, lingering after the bolt has passed
+ burst(5, S * 31 + i, (r) => {
+ const km = r.range(0.06, 0.85), age = t - (m.t0 + m.fd * km), life = r.range(0.16, 0.3);
+ if (age < 0 || age > life) return;
+ const [x0, y0] = m.at(km), q = age / life;
+ const [x, y] = fly(x0, y0, r.range(-12, 12), r.range(-14, 10), age, 0, 5);
+ p.dot(x, y, q < 0.4 ? C[6] : q < 0.75 ? C[5] : C[4], 1 - q * 0.7);
+ });
+ if (k > 0 && k < 1) {
+ // trail: a tapering tail of older positions, cooling from white-violet to deep violet
+ const TR = [C[6], C[5], C[5], C[4], C[4], C[3], C[3], C[2], C[2]];
+ let [px, py] = m.at(k);
+ for (let j = 1; j <= TR.length; j++) {
+ const kj = k - j * 0.03;
+ if (kj < 0) break;
+ const [x, y] = m.at(kj), w = 3.2 - j * 0.3;
+ if (w > 1.6) p.beam(px, py, x, y, w, (u, v) => (v < 0.5 ? TR[j - 1] : TR[j]));
+ else p.line(px, py, x, y, TR[j - 1], j < 8 ? 1 : 0.5);
+ px = x;
+ py = y;
+ }
+ // the bolt: a small hot orb
+ const [x, y] = m.at(k);
+ p.circle(x, y, 2.3, (d) => (d < 0.5 ? WHITE : d < 0.85 ? C[6] : C[5]));
+ p.glow(x, y, 8, C[5], 0.4);
+ p.light(x, y, C[6], 0.6);
+ }
+ // the hit: a white star for two frames, a ring and a pinch of sparks
+ const a = t - (m.t0 + m.fd);
+ if (a >= 0 && a < 0.32) {
+ const q = a / 0.32;
+ if (a < 0.034) {
+ p.circle(m.tx, m.ty, 4, WHITE);
+ p.line(m.tx - 8, m.ty, m.tx + 8, m.ty, C[6]);
+ p.line(m.tx, m.ty - 7, m.tx, m.ty + 7, C[6]);
+ } else if (a < 0.1) {
+ p.circle(m.tx, m.ty, 3, (d) => (d < 0.5 ? WHITE : C[6]));
+ sparkle(p, m.tx, m.ty, 3, C[6], C[5], WHITE);
+ }
+ const rr = seg(a, 0.02, 0.2);
+ if (rr > 0 && rr < 1) p.ring(m.tx, m.ty, 4 + 6 * ease.outCubic(rr), 1, rr < 0.4 ? C[6] : C[5], rr < 0.5 ? 1 : 2 * (1 - rr));
+ burst(5, S * 17 + i, (r) => {
+ const ang = r.range(0, TAU), sp = r.range(45, 85), life = r.range(0.14, 0.3);
+ if (a > life) return;
+ const [x, y] = fly(m.tx, m.ty, Math.cos(ang) * sp, Math.sin(ang) * sp, a, 30, 6);
+ p.px(x, y, a / life < 0.5 ? C[6] : C[4]);
+ });
+ p.glow(m.tx, m.ty, 14, C[4], 0.55 * (1 - q) * (1 - q));
+ }
+ });
+}
diff --git a/src/fx/arcane/arcane-orb.js b/src/fx/arcane/arcane-orb.js
new file mode 100644
index 0000000..258af05
--- /dev/null
+++ b/src/fx/arcane/arcane-orb.js
@@ -0,0 +1,69 @@
+import { PAL, cycle, TAU, WHITE } from "../../core/index.js";
+import { fit, tiltedOval, sparkle } from "./_lib.js";
+
+export const meta = {
+ name: "Arcane orb",
+ desc: "A floating violet orb, energy swirling inside it, bobbing gently while two tilted rings orbit it, passing behind and in front.",
+ tags: ["arcane", "orb", "magic", "floating", "pickup", "loop"],
+ size: [48, 48],
+ origin: [24, 24],
+ duration: 2,
+ loop: true,
+ fps: 30,
+ bg: "dark",
+ options: { palette: PAL.arcane, radius: 7, seed: 14 },
+};
+
+// the two rings: size, tilt, how fast their beads run (whole laps a loop, so it loops clean)
+const RINGS = [
+ { rx: 15, ry: 4.5, tilt: 0.38, laps: 1, wob: 0 },
+ { rx: 13, ry: 5.5, tilt: -0.62, laps: -2, wob: 1.7 },
+];
+
+function rings(p, t, o, front) {
+ const C = fit(o.palette), ph = t / meta.duration, by = Math.round(Math.sin(ph * TAU) * 1.5);
+ for (const g of RINGS) {
+ const tilt = g.tilt + 0.08 * Math.sin(ph * TAU + g.wob), beads = [ph * TAU * g.laps, ph * TAU * g.laps + Math.PI];
+ const show = (ang) => Math.sin(ang) > 0 === front;
+ tiltedOval(p, 0, by, g.rx, g.ry, tilt, (ang) => {
+ for (const b of beads) {
+ const d = Math.abs(Math.atan2(Math.sin(ang - b), Math.cos(ang - b)));
+ if (d < 0.18) return WHITE;
+ if (d < 0.5) return C[6];
+ }
+ return front ? C[6] : C[3];
+ }, (ang) => (show(ang) ? 1 : 0));
+ for (const b of beads) {
+ if (Math.sin(b) > 0 !== front) continue;
+ const u = Math.cos(b) * g.rx, v = Math.sin(b) * g.ry;
+ const x = u * Math.cos(tilt) - v * Math.sin(tilt), y = by + u * Math.sin(tilt) + v * Math.cos(tilt);
+ p.light(x, y, C[6], 0.6);
+ }
+ }
+}
+
+export function draw(p, t, o) {
+ const C = fit(o.palette), ph = t / meta.duration, R = o.radius, S = o.seed, by = Math.round(Math.sin(ph * TAU) * 1.5);
+ rings(p, t, o, false);
+ // the orb: lit from the top left, a swirl of brighter bands turning inside, a hard rim
+ p.circle(0, by, R + 1, C[2]);
+ p.circle(0, by, R, (d, ang) => {
+ const lit = -Math.cos(ang - 0.6) * d; // brighter toward the upper left
+ const swirl = Math.sin(ang * 3 + d * 5 - ph * TAU * 3) > 0.7 && d > 0.3 && d < 0.85;
+ const v = (1 - d) * 1.6 + lit * 1.1 + (swirl ? 0.6 : 0);
+ return v > 2.1 ? WHITE : v > 1.55 ? C[6] : v > 0.95 ? C[5] : v > 0.45 ? C[4] : C[3];
+ });
+ p.px(-3, by - 4, WHITE);
+ p.px(-4, by - 3, C[6]);
+ rings(p, t, o, true);
+ // a few motes drifting up and twinkling around it
+ cycle(t, meta.duration, 6, S, (r) => r.range(0.6, 1), (age, life, r) => {
+ const k = age / life, a = r.range(0, TAU), rad = r.range(9, 17);
+ const x = Math.cos(a) * rad, y = by + Math.sin(a) * rad * 0.8 - age * 10;
+ sparkle(p, x, y, k > 0.3 && k < 0.6 ? 1 : 0, C[5], C[5], k < 0.6 ? C[6] : C[5]);
+ });
+ const pulse = 0.85 + 0.15 * Math.sin(ph * TAU * 2);
+ p.glow(0, by, 22, C[4], 0.22 * pulse);
+ p.glow(-2, by - 2, 7, C[6], 0.22 * pulse);
+}
+
diff --git a/src/fx/arcane/blink-in.js b/src/fx/arcane/blink-in.js
new file mode 100644
index 0000000..070e6ea
--- /dev/null
+++ b/src/fx/arcane/blink-in.js
@@ -0,0 +1,70 @@
+import { PAL, burst, cycle, seg, ease, clamp, stockActor, TAU, WHITE } from "../../core/index.js";
+import { fit, silhouette, sparkle } from "./_lib.js";
+
+export const meta = {
+ name: "Blink in",
+ desc: "Teleport arrival: sparks rush to a point, a star pops, a line of light stretches and springs open into the body, the glow drains away.",
+ tags: ["arcane", "teleport", "blink", "appear", "magic", "character", "one-shot"],
+ size: [48, 56],
+ origin: [24, 44],
+ duration: 0.8,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ actor: false,
+ options: { palette: PAL.arcane, seed: 13 },
+};
+
+export function draw(p, t, o) {
+ const C = fit(o.palette), A = o.actor ?? stockActor(), S = o.seed, cy = -A.h * 0.6, mid = (A.w - 1) / 2;
+ // 1. sparks rush in to a point, faster and faster
+ burst(10, S, (r) => {
+ const t0 = r.range(0, 0.06), k = seg(t, t0, 0.16);
+ if (t < t0 || k >= 1) return;
+ const ang = r.range(0, TAU), R = r.range(14, 20) * (1 - ease.inQuad(k)), R2 = r.range(14, 20) * (1 - ease.inQuad(Math.max(0, k - 0.15)));
+ const x = Math.cos(ang) * R - 0.5, y = cy + Math.sin(ang) * R;
+ p.line(Math.cos(ang) * R2 - 0.5, cy + Math.sin(ang) * R2, x, y, k > 0.5 ? C[6] : C[5]);
+ p.light(x, y, C[5], 0.4);
+ });
+ // 2. the star at the meeting point
+ const a = t - 0.16;
+ if (a >= 0 && a < 0.08) {
+ p.line(-9, cy, 8, cy, C[6]);
+ p.line(-0.5, cy - 10, -0.5, cy + 9, C[6]);
+ sparkle(p, -0.5, cy, 3, WHITE, C[6], WHITE);
+ p.glow(0, cy, 22, C[5], 0.6);
+ }
+ // 3. a line of light stretches from the star to full height (taller than the body)
+ const grow = ease.outCubic(seg(t, 0.18, 0.26)), open = seg(t, 0.26, 0.42), drain = seg(t, 0.44, 0.66);
+ const H0 = A.h * 1.4;
+ if (grow > 0 && open === 0) {
+ const top = cy + (-H0 - cy) * grow, bot = cy * (1 - grow);
+ p.line(-0.5, top, -0.5, bot, WHITE);
+ if (grow > 0.6) {
+ p.line(-1.5, top + 3, -1.5, bot - 2, C[6]);
+ p.line(0.5, top + 3, 0.5, bot - 2, C[5]);
+ }
+ p.glowLine(0, top, 0, bot, 8, C[5], 0.45);
+ }
+ // 4. the body springs open from the line, overshoots wide and settles, then its glow drains top to bottom
+ if (open > 0 && t < meta.duration) {
+ const sx = 0.06 + 0.94 * ease.outBack(open, 2.2), sy = 1.4 - 0.4 * ease.outCubic(open) + 0.06 * Math.sin(seg(t, 0.38, 0.5) * Math.PI);
+ const row = (A.h + 3) * ease.inOutSine(drain) - 1, out = seg(t, 0.62, 0.76);
+ silhouette(p, A, Math.max(0.06, sx), sy, (mx, my, base) => {
+ if (drain > 0 && my <= row - 2) return base || 0; // revealed (custom actors: leave it to the game's sprite)
+ if (drain > 0 && my <= row) return WHITE; // the drain's leading edge
+ const side = Math.abs(mx - mid) / (mid + 0.5);
+ return side < 0.7 - open * 0.5 ? WHITE : side < 0.8 ? C[6] : C[5];
+ });
+ if (drain > 0.3 && out < 1 && Math.floor(t * 30) % 2 === 0) p.outline(A.mask, A.x, A.y, C[5], 1 - out);
+ p.glow(0, cy, 18, C[4], 0.35 * (1 - drain));
+ }
+ // motes left floating as it settles
+ cycle(t, 10, 6, S + 5, 0.4, (age, life, r) => {
+ const born = 0.3 + r.range(0, 0.15), q = (t - born) / life;
+ if (q < 0 || q >= 1) return;
+ const x = r.range(-8, 8), y = cy + r.range(-8, 10) - (t - born) * r.range(14, 26);
+ p.px(x, y, q < 0.5 ? C[6] : C[5]);
+ });
+ if (a >= 0) p.glow(0, cy, 12, C[4], 0.3 * clamp(1 - (a - 0.1) / 0.4));
+}
diff --git a/src/fx/arcane/blink-out.js b/src/fx/arcane/blink-out.js
new file mode 100644
index 0000000..e4a098c
--- /dev/null
+++ b/src/fx/arcane/blink-out.js
@@ -0,0 +1,67 @@
+import { PAL, burst, fly, seg, ease, clamp, stockActor, TAU, WHITE } from "../../core/index.js";
+import { fit, silhouette, sparkle } from "./_lib.js";
+
+export const meta = {
+ name: "Blink out",
+ desc: "Teleport away: the body lights up from the feet, snaps thin into a tall line of light, shrinks to a point and pops in a star.",
+ tags: ["arcane", "teleport", "blink", "vanish", "magic", "character", "one-shot"],
+ size: [48, 56],
+ origin: [24, 44],
+ duration: 0.82,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ actor: false,
+ options: { palette: PAL.arcane, seed: 12 },
+};
+
+export function draw(p, t, o) {
+ const C = fit(o.palette), A = o.actor ?? stockActor(), S = o.seed;
+ const sweep = seg(t, 0.06, 0.16), squash = seg(t, 0.16, 0.32), shrink = seg(t, 0.34, 0.44);
+ const sx = 1 - 0.94 * ease.inCubic(squash), sy = 1 + 0.4 * ease.inQuad(squash), H = A.h * sy, cy = -A.h * 0.6;
+ const mid = (A.w - 1) / 2;
+ // 1. the body: own colors, lit from the feet up, then squeezed thin and stretched tall
+ if (sx * A.w >= 2 && t < 0.34) {
+ const lineRow = A.h * (1 - ease.inQuad(sweep)) - 1;
+ silhouette(p, A, sx, sy, (mx, my, base) => {
+ const lit = my >= lineRow || squash > 0;
+ if (!lit) return base || 0;
+ const side = Math.abs(mx - mid) / (mid + 0.5);
+ if (squash > 0) return side < 0.2 + squash * 0.5 ? WHITE : side < 0.7 ? C[6] : C[5];
+ return my >= lineRow + 2 ? C[6] : WHITE; // the leading edge of the sweep is white
+ });
+ // a crackling outline while it charges
+ if (t < 0.18 && Math.floor(t * 30) % 2 === 0) p.outline(A.mask, A.x, A.y, C[5]);
+ }
+ // 2. the line: a white thread from the feet to above the head, which then shrinks into its middle
+ if (squash >= 1 && shrink < 1 || (sx * A.w < 2 && t < 0.44)) {
+ const k = ease.inQuad(shrink), top = -H + (cy + H) * k, bot = cy * k;
+ p.line(-0.5, top, -0.5, bot, WHITE);
+ if (shrink < 0.5) {
+ p.line(-1.5, top + 3, -1.5, bot - 2, C[6]);
+ p.line(0.5, top + 3, 0.5, bot - 2, C[5]);
+ }
+ p.glowLine(0, top, 0, bot, 8, C[5], 0.45);
+ }
+ if (t < 0.44) p.glow(0, cy, 18, C[4], 0.3 * seg(t, 0.04, 0.3));
+ // 3. the pop: a star for two frames, a ring, sparkles flung out and slowing
+ const a = t - 0.44;
+ if (a >= 0) {
+ if (a < 0.07) {
+ p.line(-9, cy, 8, cy, C[6]);
+ p.line(-0.5, cy - 10, -0.5, cy + 9, C[6]);
+ sparkle(p, -0.5, cy, 3, WHITE, C[6], WHITE);
+ p.glow(0, cy, 22, C[5], 0.6);
+ }
+ const rr = seg(a, 0.02, 0.22);
+ if (rr > 0 && rr < 1) p.ring(-0.5, cy, 3 + 9 * ease.outCubic(rr), 1, rr < 0.5 ? C[6] : C[5], (v, ang) => (Math.sin(ang * 6 + rr * 4) > rr * 2 - 1 ? 1 : 0));
+ burst(9, S, (r) => {
+ const ang = r.range(0, TAU), sp = r.range(55, 100), life = r.range(0.22, 0.36);
+ if (a > life) return;
+ const q = a / life, [x, y] = fly(-0.5, cy, Math.cos(ang) * sp, Math.sin(ang) * sp - 10, a, -20, 5);
+ sparkle(p, x, y, q < 0.35 ? 1 : 0, q < 0.5 ? C[6] : C[5], C[5], q < 0.5 ? WHITE : C[6]);
+ p.light(x, y, C[5], 0.4 * (1 - q));
+ });
+ p.glow(0, cy, 14, C[4], 0.35 * clamp(1 - a / 0.3));
+ }
+}
diff --git a/src/fx/arcane/enchant.js b/src/fx/arcane/enchant.js
new file mode 100644
index 0000000..b65e7aa
--- /dev/null
+++ b/src/fx/arcane/enchant.js
@@ -0,0 +1,89 @@
+import { PAL, RAMP, cycle, fract, clamp, tileNoise, TAU, WHITE } from "../../core/index.js";
+import { fit, rune, sparkle } from "./_lib.js";
+
+export const meta = {
+ name: "Enchant",
+ desc: "An enchanted sword: a violet aura licks up the blade, a ring of runes wraps round it and turns, a white sheen runs from hilt to tip.",
+ tags: ["arcane", "enchant", "weapon", "sword", "buff", "item", "loop"],
+ size: [40, 64],
+ origin: [20, 59],
+ duration: 1.6,
+ loop: true,
+ fps: 30,
+ bg: "dark",
+ options: { palette: PAL.arcane, sword: true, seed: 19 },
+};
+
+const M = RAMP.metal, G = RAMP.gold, W = RAMP.wood;
+const TIP = -50, GUARD = -13;
+// half-width of the blade at height y (tapering to a point)
+const half = (y) => (y < TIP || y > GUARD - 1 ? -1 : y < TIP + 1 ? 0 : y < TIP + 4 ? 1 : 2);
+
+function sword(p, ph, C) {
+ // blade: dark edges, a bright left bevel, the fuller down the middle; a sheen band sweeps up it once a loop
+ const sheen = -8 - 56 * fract(ph + 0.35);
+ for (let y = TIP; y <= GUARD - 1; y++) {
+ const w = half(y);
+ for (let x = -w; x <= w; x++) {
+ let c = Math.abs(x) === w && w > 0 ? M[2] : x < 0 ? M[6] : x === 0 ? M[4] : M[3];
+ if (w === 0) c = M[5];
+ const s = y - x - sheen;
+ if (Math.abs(s) < 1.2) c = WHITE;
+ else if (Math.abs(s) < 2.6 && Math.abs(x) < w) c = C[6];
+ p.px(x, y, c);
+ }
+ }
+ // guard, grip, pommel
+ for (let x = -6; x <= 6; x++) {
+ p.px(x, GUARD, Math.abs(x) === 6 ? G[3] : G[5]);
+ p.px(x, GUARD + 1, Math.abs(x) === 6 ? G[2] : G[3]);
+ }
+ p.px(-6, GUARD - 1, G[4]);
+ p.px(6, GUARD - 1, G[3]);
+ for (let y = GUARD + 2; y <= -4; y++) for (let x = -1; x <= 1; x++) p.px(x, y, (y + (x > 0 ? 1 : 0)) % 2 ? W[3] : W[2]);
+ for (let y = -3; y <= -1; y++) for (let x = -1; x <= 1; x++) p.px(x, y, y === -2 && x === 0 ? C[6] : y === -3 ? G[5] : G[3]);
+}
+
+// the rune ring: glyphs at fixed heights orbiting the blade in a spiral, a full turn each loop
+function runes(p, ph, C, front) {
+ for (let i = 0; i < 6; i++) {
+ const th = ph * TAU + i * 2.1, depth = Math.cos(th), y = -18 - i * 5.5;
+ if (depth >= 0 !== front) continue;
+ const x = Math.sin(th) * 8.5;
+ if (front) rune(p, i + 2, x, y, depth > 0.75 ? WHITE : C[6], 1, true, C[1]);
+ else rune(p, i + 2, x, y, C[3], 1, true);
+ if (front) p.light(x, y, C[5], 0.35);
+ }
+}
+
+export function draw(p, t, o) {
+ const C = fit(o.palette), S = o.seed, ph = t / meta.duration;
+ runes(p, ph, C, false);
+ // the aura: a 1 px glowing rim hugging the blade, with violet flames licking up off it
+ p.shade(-6, TIP - 6, 6, GUARD, (x, y, out) => {
+ const yy = Math.floor(y), xx = Math.floor(x), w = Math.max(half(yy), half(yy + 2) - 1);
+ const d = w < 0 ? 9 : xx >= 0 ? xx - w : -xx - 1 - w; // pixels out from the blade edge
+ const tipd = TIP - yy; // above the tip
+ const lick = tileNoise(x * 0.9, y * 0.16 + ph * 6, 0, 6, S) * 0.5 + 0.5; // tall tongues, rising
+ const wave = 0.5 + 0.5 * Math.sin(y * 0.3 + ph * TAU * 2);
+ if ((d === 1 && w >= 0) || (tipd > 0 && tipd <= 1 && Math.abs(xx + 0.5) < 1)) {
+ out.c = wave > 0.75 ? C[6] : C[5];
+ out.k = 0.2;
+ return;
+ }
+ if ((d === 2 || d === 3 || (tipd > 1 && tipd < 6 && Math.abs(xx + 0.5) < 2)) && lick > 0.55 + (d - 2) * 0.14 + Math.max(0, tipd) * 0.04) {
+ out.c = lick > 0.7 && d === 2 ? C[4] : C[3];
+ }
+ });
+ if (o.sword) sword(p, ph, C);
+ runes(p, ph, C, true);
+ // motes peeling off the blade and drifting up
+ cycle(t, meta.duration, 8, S, (r) => r.range(0.5, 0.9), (age, life, r) => {
+ const k = age / life, side = r.sign(), y0 = r.range(TIP + 4, GUARD - 4);
+ const x = side * (3 + age * r.range(6, 12)), y = y0 - age * r.range(10, 18);
+ sparkle(p, x, y, k > 0.2 && k < 0.5 ? 1 : 0, C[5], C[5], k < 0.6 ? C[6] : C[5]);
+ });
+ const pulse = 0.85 + 0.15 * Math.sin(ph * TAU * 2);
+ p.glowLine(0, TIP, 0, GUARD, 10, C[4], 0.22 * pulse);
+ p.glow(0, -2, 6, C[5], 0.3 * clamp(pulse));
+}
diff --git a/src/fx/arcane/glyph-burst.js b/src/fx/arcane/glyph-burst.js
new file mode 100644
index 0000000..fe28442
--- /dev/null
+++ b/src/fx/arcane/glyph-burst.js
@@ -0,0 +1,81 @@
+import { burst, fly, seg, ease, clamp, rng, TAU, WHITE } from "../../core/index.js";
+import { fit, sparkle, MAGENTA } from "./_lib.js";
+
+export const meta = {
+ name: "Glyph burst",
+ desc: "A big sigil inks itself in the air stroke by stroke, swells and trembles with light, flashes white and blows apart into spinning strokes.",
+ tags: ["arcane", "glyph", "sigil", "burst", "magic", "one-shot"],
+ size: [84, 84],
+ origin: [42, 42],
+ duration: 1.3,
+ loop: false,
+ fps: 30,
+ bg: "dark",
+ options: { palette: MAGENTA, size: 17, seed: 21 },
+};
+
+// the sigil's strokes in unit space (radius 1): a staff through a diamond, two chevrons, two bars
+const STROKES = [
+ [0, -1.32, 0, 1.32],
+ [0, -0.78, 0.78, 0], [0.78, 0, 0, 0.78], [0, 0.78, -0.78, 0], [-0.78, 0, 0, -0.78],
+ [-0.5, -0.12, 0, -0.42], [0, -0.42, 0.5, -0.12],
+ [-0.5, 0.12, 0, 0.42], [0, 0.42, 0.5, 0.12],
+ [-0.62, -0.62, -0.38, -0.86], [0.62, 0.62, 0.38, 0.86],
+];
+const ARCS = 8, T_FLASH = 0.62, T_BURST = 0.69;
+
+export function draw(p, t, o) {
+ const C = fit(o.palette), S = o.seed, R0 = o.size;
+ const swell = ease.inQuad(seg(t, 0.36, T_FLASH)), flash = t >= T_FLASH && t < T_BURST, b = seg(t, T_BURST, 1.24);
+ const R = R0 * (1 + 0.12 * swell), shake = swell > 0.5 && b === 0 ? ((Math.floor(t * 60) % 2) * 2 - 1) * 0.6 : 0;
+ const col = (base) => (flash ? WHITE : swell > 0.6 ? C[6] : base);
+ // the ring: drawn round by a pen, then broken into arcs that fly apart
+ const ring = ease.inOutSine(seg(t, 0, 0.24));
+ for (let i = 0; i < ARCS; i++) {
+ const r = rng(S, i, 2), a0 = -Math.PI / 2 + (i / ARCS) * TAU, span = TAU / ARCS, shown = clamp(ring * ARCS - i);
+ if (shown <= 0) continue;
+ const mid = a0 + span / 2, k = ease.outCubic(b), out = (r.range(16, 26) * k), spin = r.sign() * 0.6 * k;
+ const life = r.range(0.4, 0.55);
+ if (b > 0 && t - T_BURST > life) continue;
+ const dx = Math.cos(mid) * out + shake, dy = Math.sin(mid) * out;
+ const shrink = b > 0 ? 1 - seg(t - T_BURST, life * 0.5, life) : 1;
+ p.arc(dx, dy, R, 2, a0 + spin + (1 - shrink) * span * 0.5, a0 + spin + span * shown - 0.05 - (1 - shrink) * span * 0.5,
+ (u, v) => col(b > 0.35 ? C[4] : v > 0.5 ? C[5] : C[3]));
+ }
+ // strokes: inked one after another while the ring closes; at the burst each flies out from the centre and spins
+ STROKES.forEach(([x0, y0, x1, y1], i) => {
+ const r = rng(S, i, 3), born = 0.08 + i * 0.022, ink = ease.outQuad(seg(t, born, born + 0.07));
+ if (ink <= 0) return;
+ let mx = ((x0 + x1) / 2) * R, my = ((y0 + y1) / 2) * R, hx = ((x1 - x0) / 2) * R, hy = ((y1 - y0) / 2) * R;
+ let len = 1, alpha = 1;
+ if (b > 0) {
+ const life = r.range(0.38, 0.55), age = t - T_BURST;
+ if (age > life) return;
+ const away = Math.hypot(mx, my) > 1 ? Math.atan2(my, mx) : r.range(0, TAU), k = ease.outCubic(seg(age, 0, life));
+ const spin = r.sign() * r.range(1.5, 3.5) * k, cs = Math.cos(spin), sn = Math.sin(spin);
+ mx += Math.cos(away) * r.range(18, 30) * k;
+ my += Math.sin(away) * r.range(18, 30) * k;
+ [hx, hy] = [hx * cs - hy * sn, hx * sn + hy * cs];
+ len = 1 - seg(age, life * 0.45, life);
+ }
+ // inking runs from the stroke's start; a white pen point leads
+ const ax = mx - hx * len + shake, ay = my - hy * len, bx = ax + 2 * hx * len * ink, by = ay + 2 * hy * len * ink;
+ const c = col(b > 0.4 ? C[4] : b > 0 ? C[6] : C[5]);
+ p.line(ax, ay, bx, by, c, alpha);
+ if (ink < 1) p.px(bx, by, WHITE);
+ });
+ // the flash, the blast ring and sparks
+ if (flash) p.glow(0, 0, 40, C[5], 0.7);
+ const sw = seg(t, T_FLASH + 0.03, T_FLASH + 0.29);
+ if (sw > 0 && sw < 1) p.ring(0, 0, R0 * 1.1 + 18 * ease.outCubic(sw), 1, sw < 0.4 ? WHITE : C[6], (v, a) => (Math.sin(a * 6 + sw * 5) > sw * 2.4 - 1.2 ? 1 : 0));
+ burst(12, S + 9, (r) => {
+ const a = r.range(0, TAU), sp = r.range(60, 120), life = r.range(0.3, 0.5), age = t - T_BURST;
+ if (age < 0 || age > life) return;
+ const q = age / life, [x, y] = fly(0, 0, Math.cos(a) * sp, Math.sin(a) * sp, age, 0, 5);
+ sparkle(p, x, y, q < 0.3 ? 1 : 0, C[6], C[5], q < 0.5 ? WHITE : C[6]);
+ });
+ // light: builds with the swell, peaks on the flash, falls away fast
+ const L = b > 0 ? Math.pow(1 - b, 2) * 0.55 : 0.15 + 0.3 * swell;
+ p.glow(0, 0, R0 * 2.2, C[4], L);
+ p.glow(0, 0, 8, C[6], L * 0.6);
+}
diff --git a/src/fx/arcane/magic-circle-cast.js b/src/fx/arcane/magic-circle-cast.js
new file mode 100644
index 0000000..91b23a1
--- /dev/null
+++ b/src/fx/arcane/magic-circle-cast.js
@@ -0,0 +1,89 @@
+import { stream, seg, ease, clamp, tileNoise, TAU, WHITE } from "../../core/index.js";
+import { fit, rune, ovalLine, ahead, AZURE } from "./_lib.js";
+
+export const meta = {
+ name: "Magic circle cast",
+ desc: "A circle draws itself on the floor stroke by stroke, runes pop in round it, it flashes white and a column of light fires straight up.",
+ tags: ["arcane", "circle", "cast", "ground", "magic", "runes", "one-shot"],
+ size: [72, 88],
+ origin: [36, 74],
+ duration: 1.35,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ options: { palette: AZURE, radius: 27, height: 64, seed: 11 },
+};
+
+export function draw(p, t, o) {
+ const C = fit(o.palette), RX = o.radius, RY = Math.round(RX * 0.43), H = o.height, S = o.seed;
+ const flash = t >= 0.66 && t < 0.73, charge = t < 0.66 ? seg(t, 0.52, 0.66) : 0, fade = seg(t, 0.78, 1.18);
+ const ink = (base) => (flash ? WHITE : charge > 0.5 ? C[6] : base);
+ const gone = (ang, k) => fade > 0 && (Math.sin(ang * 9 + k) + 1) / 2 < fade * 1.25; // the lines break up as it fades
+ const near = (ang) => Math.sin(ang) > -0.15;
+ // 1. the outer ring is drawn by a pen of light starting at the front and running clockwise
+ const A0 = Math.PI / 2, s1 = ease.inOutSine(seg(t, 0, 0.3)) * TAU;
+ if (t < 1.3) {
+ ovalLine(p, RX, RY, (ang) => ink(near(ang) ? C[5] : C[4]), (ang) => (ahead(A0, ang) <= s1 && !gone(ang, 0) ? 1 : 0));
+ // 2. the inner ring, counterclockwise from the back
+ const s2 = ease.inOutSine(seg(t, 0.12, 0.38)) * TAU, A1 = -Math.PI / 2, ri = 0.62;
+ ovalLine(p, RX * ri, RY * ri, (ang) => ink(near(ang) ? C[5] : C[4]), (ang) => (ahead(ang, A1) <= s2 && !gone(ang, 2) ? 1 : 0));
+ // 3. two squares make an eight-point star, each edge drawn out from its corner
+ const V = (k) => {
+ const a = (k * TAU) / 8 - Math.PI / 2;
+ return [Math.cos(a) * RX * ri, Math.sin(a) * RY * ri];
+ };
+ for (let k = 0; k < 8; k++) {
+ const u = ease.outQuad(seg(t, 0.3 + k * 0.025, 0.38 + k * 0.025));
+ if (u <= 0 || fade > 0.35 + (k % 4) * 0.12) continue;
+ const [x0, y0] = V(k), [x1, y1] = V(k + 2), x2 = x0 + (x1 - x0) * u, y2 = y0 + (y1 - y0) * u;
+ p.line(x0, y0, x2, y2, ink((y0 + y1) / 2 > 0 ? C[5] : C[4]));
+ if (u < 1) p.px(x2, y2, WHITE);
+ }
+ // 4. runes pop in round the band, one after another, and lift off as it fades
+ for (let i = 0; i < 10; i++) {
+ const born = 0.4 + i * 0.016, a = (i / 10) * TAU + Math.PI / 2, lift = seg(t, 0.8 + i * 0.025, 1.05 + i * 0.025);
+ if (t < born || lift >= 1) continue;
+ const x = Math.cos(a) * RX * 0.81, y = Math.sin(a) * RY * 0.81 - 10 * ease.inQuad(lift);
+ const shake = charge > 0 && charge < 1 ? (Math.floor(t * 60 + i) % 2) * 2 - 1 : 0;
+ rune(p, i + S, x + shake * 0.6, y, t - born < 0.05 || flash ? WHITE : ink(near(a) ? C[6] : C[5]), 1 - lift, true);
+ }
+ // the pen heads
+ for (const [s, A, R, dir] of [[s1, A0, RX, 1], [ease.inOutSine(seg(t, 0.12, 0.38)) * TAU, -Math.PI / 2, RX * 0.62, -1]]) {
+ if (s <= 0 || s >= TAU) continue;
+ const a = A + s * dir, x = Math.cos(a) * R, y = Math.sin(a) * R * (RY / RX);
+ p.circle(x, y, 1.5, WHITE);
+ p.glow(x, y, 8, C[5], 0.5);
+ }
+ }
+ // floor light: builds while it charges, blinds on the flash
+ p.shade(-RX, -RY, RX, RY, (x, y, out) => {
+ const d = Math.hypot(x / RX, y / RY);
+ if (d > 1) return;
+ out.l = C[5];
+ out.k = (0.08 + 0.2 * charge + (flash ? 0.5 : 0)) * (1 - d * d) * (1 - fade);
+ });
+ // 5. the column: snaps up out of the inner ring, then narrows to a thread and is gone
+ const up = seg(t, 0.66, 0.76), thin = ease.inQuad(seg(t, 0.78, 1.1));
+ if (up > 0 && thin < 1) {
+ const top = -H * ease.outExpo(up), w = RX * 0.55 * (1 - thin) + 0.6, ri = 0.62;
+ p.shade(-w, top - 2, w, RY * ri, (x, y, out) => {
+ const v = Math.abs(x) / w, front = RY * ri * Math.sqrt(Math.max(0, 1 - (x / (RX * ri)) ** 2));
+ if (v > 1 || y > front) return;
+ // streaks: vertical bands that race upward; the top frays into them
+ const streak = tileNoise(x * 0.7, y * 0.06 + t * 16, 0, 0, S) * 0.5 + 0.5, tip = clamp((y - top) / 18);
+ const lvl = (1 - v) * 1.15 + streak * 0.6 - (1 - tip) * 0.9;
+ if (lvl < 0.4) return;
+ out.c = flash || lvl > 1.22 ? WHITE : lvl > 0.95 ? C[6] : lvl > 0.65 ? C[5] : C[4];
+ out.k = 0.15;
+ });
+ p.glowLine(0, top * 0.8, 0, 0, w + 8, C[5], 0.35 * (1 - thin));
+ }
+ // streaks shooting up the column
+ stream(t, 0.68, 1.0, 40, S, (r) => r.range(0.18, 0.32), (age, life, r) => {
+ const x = r.range(-RX * 0.7, RX * 0.7), y0 = r.range(-RY * 0.4, RY * 0.6), sp = r.range(200, 300);
+ const y = y0 - age * sp, len = r.range(4, 9), k = age / life;
+ if (y < -H - 6) return;
+ p.line(x, y, x, y + len * (1 - k * 0.5), k < 0.4 ? WHITE : k < 0.75 ? C[6] : C[5]);
+ });
+ if (flash) p.glow(0, -8, 34, C[5], 0.55);
+}
diff --git a/src/fx/arcane/mana-burst.js b/src/fx/arcane/mana-burst.js
new file mode 100644
index 0000000..7eb1290
--- /dev/null
+++ b/src/fx/arcane/mana-burst.js
@@ -0,0 +1,80 @@
+import { PAL, burst, fly, seg, ease, rand, clamp, TAU, WHITE } from "../../core/index.js";
+import { fit, rune, sparkle } from "./_lib.js";
+
+export const meta = {
+ name: "Mana burst",
+ desc: "A violet blast: a white flash, a ragged star of energy tearing outward, runes flung to the rim that circle once and pop into sparks.",
+ tags: ["arcane", "burst", "magic", "runes", "explosion", "one-shot"],
+ size: [88, 88],
+ origin: [44, 44],
+ duration: 0.95,
+ loop: false,
+ fps: 30,
+ bg: "dark",
+ options: { palette: PAL.arcane, count: 8, seed: 9 },
+};
+
+export function draw(p, t, o) {
+ const C = fit(o.palette), S = o.seed, n = o.count;
+ // the blast: a ragged star that tears outward and hollows into a ring, cooling from the inside
+ const b = seg(t, 0, 0.34);
+ if (b > 0 && b < 1) {
+ const Rb = 5 + 21 * ease.outExpo(b), hollow = Rb * 0.9 * ease.outCubic(seg(t, 0.05, 0.34)), N = 9;
+ // spikes of uneven length and width: a triangle wave around the circle, warped so they bunch up
+ const spikes = (a) => {
+ const f0 = (a / TAU + 1) % 1, f = (f0 + 0.04 * Math.sin(f0 * TAU * 2 + S)) * N, i = Math.floor(f) % N, w = f - Math.floor(f);
+ const tri = 1 - Math.abs(2 * w - 1);
+ return Math.pow(tri, 1.6 + rand(S, i, 1)) * (0.4 + 0.6 * rand(S, i));
+ };
+ const BODY = [C[2], C[3], C[4], C[5], C[6], WHITE];
+ p.shade(-Rb * 1.15, -Rb * 1.15, Rb * 1.15, Rb * 1.15, (x, y) => {
+ const d = Math.hypot(x, y), edge = Rb * (0.6 + 0.55 * spikes(Math.atan2(y, x)));
+ if (d > edge || d < hollow) return;
+ const v = (d - hollow) / Math.max(1, edge - hollow), heat = (1 - b) * 2.6 + (1 - Math.abs(v - 0.4)) * 2.2;
+ return BODY[clamp(Math.floor(heat - (v > 0.8 ? 1.2 : 0)), 0, 5)];
+ });
+ }
+ // flash: two frames of white
+ if (t < 0.067) {
+ p.circle(0, 0, 7 + 40 * t, WHITE);
+ p.glow(0, 0, 44, C[5], 0.8);
+ }
+ // shockwave
+ const sw = seg(t, 0.02, 0.3);
+ if (sw > 0 && sw < 1) {
+ const r = 8 + 30 * ease.outCubic(sw);
+ // crisp at first, then torn into dashes rather than dithered away
+ p.ring(0, 0, r, 1, sw < 0.4 ? C[6] : C[5], (v, a) => (Math.sin(a * 7 + sw * 3) > sw * 2.4 - 1.2 ? 1 : 0));
+ p.glowRing(0, 0, r, 4, C[4], 0.3 * (1 - sw));
+ }
+ // runes: flung out, braking hard, then circling slowly at the rim until each one pops into a spark
+ burst(n, S + 1, (r, i) => {
+ const ang0 = (i / n) * TAU + r.range(-0.22, 0.22) - Math.PI / 2, reach = r.range(22, 29), t0 = r.range(0.02, 0.05);
+ const k = ease.outCubic(seg(t, t0, t0 + 0.36)), pop = 0.42 + (i / n) * 0.26 + r.range(0, 0.04);
+ if (t < t0) return;
+ const ang = ang0 + 0.5 * ease.inOutSine(seg(t, 0.15, pop)), rad = 4 + reach * k + 3 * seg(t, 0.35, pop);
+ const x = Math.cos(ang) * rad, y = Math.sin(ang) * rad;
+ if (t < pop) {
+ const hot = seg(t, t0, t0 + 0.16), flick = t > pop - 0.1 && Math.sin(t * 90 + i) > 0.3;
+ rune(p, r.int(0, 7), x, y, hot < 0.5 || flick ? WHITE : C[6], 1, false, C[3]);
+ if (k < 0.85) p.line(x - Math.cos(ang) * 7 * (1 - k), y - Math.sin(ang) * 7 * (1 - k), x - Math.cos(ang) * 3, y - Math.sin(ang) * 3, C[4]);
+ p.glow(x, y, 6, C[4], 0.3);
+ return;
+ }
+ // the pop: a twinkle that shrinks away
+ const q = seg(t, pop, pop + 0.2);
+ if (q >= 1) return;
+ sparkle(p, x, y, 3 - q * 3, q < 0.3 ? WHITE : C[6], C[5], WHITE);
+ p.light(x, y, C[5], 0.5 * (1 - q));
+ });
+ // motes thrown off the blast
+ burst(16, S + 2, (r) => {
+ const a = r.range(0, TAU), sp = r.range(50, 110), life = r.range(0.35, 0.7);
+ if (t > life) return;
+ const q = t / life, [x, y] = fly(0, 0, Math.cos(a) * sp, Math.sin(a) * sp, t, 10, 4.5);
+ p.dot(x, y, q < 0.3 ? WHITE : q < 0.6 ? C[6] : C[5], 1 - q * 0.6);
+ });
+ const L = 1 - seg(t, 0, 0.5);
+ p.glow(0, 0, 40, C[4], 0.5 * L * L);
+ p.glow(0, 0, 12, C[6], 0.5 * L * L * L);
+}
diff --git a/src/fx/arcane/mirror-images.js b/src/fx/arcane/mirror-images.js
new file mode 100644
index 0000000..82430ec
--- /dev/null
+++ b/src/fx/arcane/mirror-images.js
@@ -0,0 +1,65 @@
+import { PAL, burst, seg, ease, luma, clamp, TAU, WHITE } from "../../core/index.js";
+import { fit, silhouette, sparkle } from "./_lib.js";
+
+export const meta = {
+ name: "Mirror images",
+ desc: "Illusion clones slide out from the actor to both sides with afterimages, hold flickering like a bad signal, then pop one by one.",
+ tags: ["arcane", "illusion", "clone", "decoy", "buff", "character", "one-shot"],
+ size: [84, 40],
+ origin: [42, 33],
+ duration: 1.3,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ actor: true,
+ options: { palette: PAL.arcane, count: 4, spacing: 15, seed: 18 },
+};
+
+// where each clone stands: alternating sides, the outer pair further out and a beat later
+function clones(o) {
+ return Array.from({ length: o.count }, (_, i) => {
+ const side = i % 2 ? 1 : -1, rank = Math.floor(i / 2) + 1;
+ return { side, x: side * o.spacing * rank, t0: 0.04 + (rank - 1) * 0.07, pop: 0.78 + i * 0.065 };
+ });
+}
+
+// the clone's own pixels mapped onto the ramp by brightness: a violet copy that keeps the face and clothes
+const tint = (C) => (mx, my, base) => (base ? [C[2], C[3], C[4], C[5], C[6]][clamp(Math.floor(luma(base) * 5.5), 0, 4)] : C[4]);
+
+export function drawBack(p, t, o) {
+ const C = fit(o.palette), A = o.actor, frame = Math.floor(t * 30);
+ for (const c of clones(o)) {
+ const k = ease.outCubic(seg(t, c.t0, c.t0 + 0.26));
+ if (k <= 0 || t >= c.pop) continue;
+ // afterimages left along the slide
+ if (k < 1)
+ for (const [lag, col] of [[0.6, C[2]], [0.3, C[3]]]) silhouette(p, A, 1, 1, () => col, 1, Math.round(c.x * k * (1 - lag)));
+ // the clone: a scanline gap rolls down it, and now and then it jumps a pixel sideways
+ const glitch = Math.sin(t * 47 + c.x) > 0.93 ? c.side : 0, roll = frame % 6;
+ silhouette(p, A, 1, 1, (mx, my, base) => ((my + roll) % 6 === 0 ? 0 : tint(C)(mx, my, base)), 1, Math.round(c.x * k) + glitch);
+ p.glow(c.x * k, -9, 12, C[4], 0.22 * k);
+ }
+}
+
+export function draw(p, t, o) {
+ const C = fit(o.palette), A = o.actor, S = o.seed;
+ // the split: a flash on the actor as the copies peel away
+ const f = seg(t, 0, 0.12);
+ if (f < 1) {
+ p.outline(A.mask, A.x, A.y, f < 0.5 ? WHITE : C[6]);
+ p.glow(0, -9, 16, C[5], 0.4 * (1 - f));
+ }
+ // each clone pops into a twinkle and a puff of motes
+ clones(o).forEach((c, i) => {
+ const a = t - c.pop;
+ if (a < 0 || a > 0.3) return;
+ const q = a / 0.3;
+ if (q < 0.25) silhouette(p, A, 1, 1, () => WHITE, 1, c.x);
+ sparkle(p, c.x, -10, Math.round(3 * (1 - q)), WHITE, C[6], WHITE);
+ burst(6, S * 11 + i, (r) => {
+ const ang = r.range(0, TAU), sp = r.range(22, 34), x = c.x + Math.cos(ang) * sp * a, y = -10 + Math.sin(ang) * sp * a - a * 24;
+ p.px(x, y, q < 0.5 ? C[6] : C[5]);
+ });
+ p.glow(c.x, -10, 12, C[5], 0.45 * (1 - q));
+ });
+}
diff --git a/src/fx/arcane/portal.js b/src/fx/arcane/portal.js
new file mode 100644
index 0000000..00d1070
--- /dev/null
+++ b/src/fx/arcane/portal.js
@@ -0,0 +1,46 @@
+import { PAL, fit, at, cycle, tileNoise, fract, ease, TAU } from "../../core/index.js";
+
+export const meta = {
+ name: "Portal",
+ desc: "An oval rift: three spiral arms turning into the dark, a wobbling bright rim, motes spiralling in.",
+ tags: ["arcane", "portal", "magic", "teleport", "loop"],
+ size: [64, 72],
+ origin: [32, 38],
+ duration: 2,
+ loop: true,
+ fps: 30,
+ bg: "ground",
+ options: { palette: PAL.arcane, width: 14, height: 22, seed: 4 },
+};
+
+export function draw(p, t, o) {
+ const C = fit(o.palette, 8), rx = o.width, ry = o.height, S = o.seed, ph = t / meta.duration;
+ const inner = [C[0], C[1], C[2], C[3], C[4], C[5]];
+ p.shade(-rx - 3, -ry - 3, rx + 3, ry + 3, (x, y, out) => {
+ const dx = x / rx, dy = y / ry, d = Math.sqrt(dx * dx + dy * dy), a = Math.atan2(dy, dx);
+ // the rim wobbles: noise around the oval (12 cells, wrapping) scrolling a whole number of cells a loop
+ const rim = 1 + 0.07 * tileNoise((a / TAU) * 12 + ph * 12, ph * 3, 12, 3, S);
+ if (d > rim) return;
+ if (d > rim - 0.1) {
+ // the rim, lit from the top-left: white only where the light catches it
+ const lit = Math.cos(a + 2.36) > 0.25;
+ out.c = d > rim - 0.045 ? (lit ? C[7] : C[6]) : C[5];
+ out.k = 0.25;
+ return;
+ }
+ // three arms that spiral inward and turn twice a loop; deeper is darker
+ const arm = fract((a / TAU) * 3 - Math.log(d + 0.06) * 0.85 + ph * 2);
+ const band = 0.5 + 0.5 * Math.sin(arm * TAU);
+ return at(inner, d * 0.75 + band * 0.42 - 0.12);
+ });
+ // motes drawn in from outside, spinning faster as they fall in
+ cycle(t, meta.duration, 16, S, (r) => r.range(0.7, 1.2), (age, life, r) => {
+ const k = age / life, a = r.range(0, TAU) + ease.inQuad(k) * 3.2, rad = 1.55 - 1.45 * ease.inQuad(k);
+ const x = Math.cos(a) * rx * rad, y = Math.sin(a) * ry * rad;
+ p.px(x, y, k < 0.75 ? C[6] : C[4]);
+ p.light(x, y, C[5], 0.5);
+ });
+ const pulse = 0.85 + 0.15 * Math.sin(ph * TAU * 2);
+ p.glow(0, 0, ry * 1.7, C[4], 0.32 * pulse);
+ p.glow(0, ry + 2, rx * 1.6, C[5], 0.18 * pulse);
+}
diff --git a/src/fx/arcane/rune-circle.js b/src/fx/arcane/rune-circle.js
new file mode 100644
index 0000000..e8b32a9
--- /dev/null
+++ b/src/fx/arcane/rune-circle.js
@@ -0,0 +1,70 @@
+import { PAL, cycle, TAU, WHITE } from "../../core/index.js";
+import { fit, rune, ovalLine, ahead } from "./_lib.js";
+
+export const meta = {
+ name: "Rune circle",
+ desc: "A magic circle on the floor: a band of runes turning one way, a triangle the other, a spark racing round the rim, motes rising.",
+ tags: ["arcane", "circle", "runes", "ground", "magic", "aura", "loop"],
+ size: [72, 52],
+ origin: [36, 36],
+ duration: 2.4,
+ loop: true,
+ fps: 30,
+ bg: "ground",
+ options: { palette: PAL.arcane, radius: 27, seed: 10 },
+};
+
+export function draw(p, t, o) {
+ const C = fit(o.palette), D = meta.duration, ph = t / D, RX = o.radius, RY = Math.round(RX * 0.43), S = o.seed;
+ const pulse = 0.75 + 0.25 * Math.sin(ph * TAU * 2);
+ const spark = ph * TAU * 2 - Math.PI / 2; // a bright head racing round the rim, two laps a loop
+ const near = (ang) => Math.sin(ang) > -0.15; // the front half is closer: one step brighter
+ // a pool of light on the floor inside the circle (light only, no pixels)
+ p.shade(-RX, -RY, RX, RY, (x, y, out) => {
+ const d = Math.hypot(x / RX, y / RY);
+ if (d > 1) return;
+ out.l = C[4];
+ out.k = 0.14 * (1 - d * d) * pulse;
+ });
+ // the rune band is inked dark so the glyphs stand out on it
+ p.shade(-RX, -RY, RX, RY, (x, y) => {
+ const d = Math.hypot(x / RX, y / RY);
+ if (d < 1 && d > 0.64) return C[1];
+ });
+ // outer rim with the spark and its fading tail
+ ovalLine(p, RX, RY, (ang) => {
+ const behind = ahead(ang, spark);
+ if (behind < 0.12) return WHITE;
+ if (behind < 0.7) return C[6];
+ return near(ang) ? C[5] : C[4];
+ });
+ // inner ring and a triangle turning against the runes (a third of a turn a loop: seamless)
+ const ri = 0.64;
+ ovalLine(p, RX * ri, RY * ri, (ang) => (near(ang) ? C[5] : C[4]));
+ const vx = (k) => {
+ const a = -ph * (TAU / 3) + (k * TAU) / 3 - Math.PI / 2;
+ return [Math.cos(a) * RX * ri, Math.sin(a) * RY * ri];
+ };
+ for (let k = 0; k < 3; k++) {
+ const [x0, y0] = vx(k), [x1, y1] = vx(k + 1);
+ p.line(x0, y0, x1, y1, (u) => (y0 + (y1 - y0) * u > 0 ? C[5] : C[4]));
+ }
+ ovalLine(p, RX * 0.2, RY * 0.2, C[5]);
+ // the rune band: twelve runes, a three-glyph pattern, a quarter turn a loop (seamless)
+ const glyphs = [S % 8, (S + 3) % 8, (S + 5) % 8];
+ for (let i = 0; i < 12; i++) {
+ const a = (i / 12) * TAU + ph * (TAU / 4), x = Math.cos(a) * RX * 0.8, y = Math.sin(a) * RY * 0.8;
+ const lit = ahead(a, spark) < 0.5;
+ rune(p, glyphs[i % 3], x, y, lit ? WHITE : near(a) ? C[6] : C[5], 1, true);
+ if (lit) p.light(x, y, C[5], 0.5);
+ }
+ // motes lifting off the rim
+ cycle(t, D, 16, S, (r) => r.range(0.8, 1.4), (age, life, r) => {
+ const k = age / life, a = r.range(0, TAU), rr = r.range(0.75, 1);
+ const x = Math.cos(a) * RX * rr + Math.sin(age * r.range(3, 6) + r.next() * TAU) * 1.2;
+ const y = Math.sin(a) * RY * rr - age * r.range(8, 16);
+ p.dot(x, y, k < 0.3 ? WHITE : k < 0.65 ? C[6] : C[5], k < 0.7 ? 1 : (1 - k) / 0.3);
+ p.light(x, y, C[5], 0.35 * (1 - k));
+ });
+ p.glow(0, -3, RX + 8, C[4], 0.14 * pulse);
+}
diff --git a/src/fx/arcane/sparkle-swirl.js b/src/fx/arcane/sparkle-swirl.js
new file mode 100644
index 0000000..5e0945e
--- /dev/null
+++ b/src/fx/arcane/sparkle-swirl.js
@@ -0,0 +1,51 @@
+import { PAL, clamp, TAU, WHITE } from "../../core/index.js";
+import { fit, sparkle } from "./_lib.js";
+
+export const meta = {
+ name: "Sparkle swirl",
+ desc: "Sparkles spiral up around the actor in two twisting ribbons, passing behind and in front, twinkling as they rise and narrow.",
+ tags: ["arcane", "sparkle", "aura", "buff", "magic", "character", "loop"],
+ size: [44, 46],
+ origin: [22, 40],
+ duration: 1.6,
+ loop: true,
+ fps: 30,
+ bg: "ground",
+ actor: true,
+ options: { palette: PAL.arcane, count: 14, radius: 11, height: 30, seed: 20 },
+};
+
+function swirl(p, t, o, front) {
+ const C = fit(o.palette), D = meta.duration, ph = t / D, R0 = o.radius, H = o.height;
+ // where a sparkle is at rise k: on one of two helices that also turn once a loop
+ const at = (k, strand) => {
+ const th = strand * Math.PI + k * TAU * 1.3 + ph * TAU, R = R0 * (1 - 0.4 * k);
+ return [Math.cos(th) * R, -k * H + Math.sin(th) * R * 0.32, Math.sin(th)];
+ };
+ // two strands, sparkles evenly strung along each, all rising one full height a loop (seamless)
+ const n = Math.max(2, Math.round(o.count / 2));
+ for (let strand = 0; strand < 2; strand++)
+ for (let i = 0; i < n; i++) {
+ const k = (ph + i / n + (strand * 0.5) / n) % 1;
+ const [x, y, depth] = at(k, strand);
+ // a tail along the helix, drawn on whichever side of the body it falls
+ for (let s = 1; s <= 4; s++) {
+ const kk = k - s * 0.03;
+ if (kk < 0) break;
+ const [tx, ty, td] = at(kk, strand);
+ if (td > 0 === front) p.px(tx, ty, front ? (s < 3 ? C[5] : C[4]) : s < 3 ? C[3] : C[2]);
+ }
+ if (depth > 0 !== front) continue;
+ const tw = Math.sin(ph * TAU * 3 + i * 2.3 + strand), size = k < 0.08 || k > 0.92 ? 0 : tw > 0.5 ? 2 : 1;
+ if (front) sparkle(p, x, y, size, C[6], C[5], WHITE);
+ else sparkle(p, x, y, Math.min(size, 1), C[4], C[4], C[5]);
+ p.light(x, y, C[5], front ? 0.45 : 0.2);
+ }
+}
+
+export const drawBack = (p, t, o) => swirl(p, t, o, false);
+export function draw(p, t, o) {
+ swirl(p, t, o, true);
+ const C = fit(o.palette), ph = t / meta.duration;
+ p.glow(0, -12, 20, C[4], clamp(0.16 + 0.04 * Math.sin(ph * TAU * 2)));
+}
diff --git a/src/fx/arcane/spell-charge.js b/src/fx/arcane/spell-charge.js
new file mode 100644
index 0000000..5a12538
--- /dev/null
+++ b/src/fx/arcane/spell-charge.js
@@ -0,0 +1,52 @@
+import { PAL, cycle, fract, ease, clamp, TAU, WHITE } from "../../core/index.js";
+import { fit } from "./_lib.js";
+
+export const meta = {
+ name: "Spell charge",
+ desc: "Energy gathers at a point: motes spiral in, dashed rings collapse onto a throbbing orb that swells as each one lands.",
+ tags: ["arcane", "charge", "magic", "buildup", "loop"],
+ size: [56, 56],
+ origin: [28, 28],
+ duration: 1.2,
+ loop: true,
+ fps: 30,
+ bg: "dark",
+ options: { palette: PAL.arcane, radius: 24, seed: 8 },
+};
+
+export function draw(p, t, o) {
+ const C = fit(o.palette), D = meta.duration, ph = t / D, R = o.radius, S = o.seed;
+ // rings: four a loop (two at a time), three dashes each, turning as they fall in faster and faster;
+ // the dashes lengthen as they close, so each ring reads as one shape tightening rather than a spray of dots
+ let pulse = 0;
+ for (let j = 0; j < 2; j++) {
+ const q = fract(ph * 2 + j * 0.5), e = ease.inQuad(q);
+ const r = 6 + (R - 6) * (1 - e), rot = (j ? 1.3 : 0) + ph * TAU * (j ? -1 : 1) + e * 2.5;
+ pulse = Math.max(pulse, Math.exp(-q * 8));
+ const cut = 0.95 - 0.9 * Math.sqrt(q);
+ p.ring(0, 0, r, 1, e < 0.3 ? C[4] : e < 0.7 ? C[5] : C[6], (v, ang) => (Math.sin(ang * 3 + rot) > cut ? 1 : 0));
+ }
+ // motes: drawn in from the dark, spinning faster as they fall, streaking at the end
+ cycle(t, D, 10, S, (r) => r.range(0.5, 0.8), (age, life, r) => {
+ const k = age / life, e = ease.inQuad(k), a0 = r.range(0, TAU), R0 = r.range(R * 0.7, R * 1.05);
+ const pos = (ee) => {
+ const ang = a0 + ee * 2.2, rad = R0 * (1 - ee) + 3 * ee;
+ return [Math.cos(ang) * rad, Math.sin(ang) * rad];
+ };
+ const [x, y] = pos(e), [bx, by] = pos(ease.inQuad(Math.max(0, k - 0.12)));
+ const c = k < 0.35 ? C[4] : k < 0.75 ? C[5] : C[6];
+ if (k > 0.5) p.line(bx, by, x, y, c);
+ else p.dot(x, y, c, clamp(k * 5));
+ if (k > 0.7) p.light(x, y, C[5], 0.35);
+ });
+ // the orb: a hard-edged ball with a white heart that swells and flashes as each ring lands
+ const breathe = 0.5 + 0.5 * Math.sin(ph * TAU * 4);
+ const rO = 3.4 + 1.6 * pulse + 0.4 * breathe;
+ p.circle(0, 0, rO + 1, pulse > 0.7 ? C[6] : C[3]);
+ p.circle(0, 0, rO, (d, ang) => {
+ const lit = d * Math.cos(ang + 2.4); // lit from the top left
+ return d < 0.32 + 0.2 * pulse ? WHITE : d < 0.6 || lit > 0.45 ? C[6] : d < 0.86 ? C[5] : C[4];
+ });
+ p.glow(0, 0, R + 6, C[4], 0.16 + 0.1 * pulse);
+ p.glow(0, 0, 7, C[5], 0.25 + 0.25 * pulse);
+}
diff --git a/src/fx/arcane/star-fall.js b/src/fx/arcane/star-fall.js
new file mode 100644
index 0000000..b3c3156
--- /dev/null
+++ b/src/fx/arcane/star-fall.js
@@ -0,0 +1,70 @@
+import { burst, fly, seg, ease, clamp, rng, WHITE } from "../../core/index.js";
+import { fit, sparkle, ovalLine, STARLIGHT } from "./_lib.js";
+
+export const meta = {
+ name: "Star fall",
+ desc: "Stars rain down on a target area: each streaks in at a slant with a blue tail, bursts on the floor with a flat ring and sparks, and leaves a glint.",
+ tags: ["arcane", "stars", "meteor", "rain", "area", "ground", "one-shot"],
+ size: [100, 88],
+ origin: [58, 76],
+ duration: 1.4,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ options: { palette: STARLIGHT, count: 7, spread: 28, seed: 16 },
+};
+
+const STAR = ["...a...", "...a...", "..aba..", "aabbbaa", ".abbba.", ".ab.ba.", ".a...a."];
+const SLANT = 0.3; // dx per dy of the fall: stars come in from the upper left
+
+export function draw(p, t, o) {
+ const C = fit(o.palette), n = o.count, S = o.seed, top = -meta.origin[1] + 6;
+ // landing spots spread across the area in a shuffled order, so the rain doesn't sweep one way
+ const order = Array.from({ length: n }, (_, i) => i).sort((a, b) => rng(S, a, 5).next() - rng(S, b, 5).next());
+ for (let i = 0; i < n; i++) {
+ const r = rng(S, i), lx = ((order[i] + 0.5) / n - 0.5) * 2 * o.spread + r.range(-3, 3);
+ const t0 = i * (0.62 / n) + r.range(0, 0.05), fall = r.range(0.26, 0.34), H = -top;
+ const k = seg(t, t0, t0 + fall), e = ease.inQuad(k);
+ const pos = (ee) => [lx - (1 - ee) * H * SLANT, -(1 - ee) * H];
+ if (k > 0 && k < 1) {
+ // the tail: thick and pale near the head, thinning into deep blue, clipped at the top of the canvas
+ const [x, y] = pos(e), len = 10 + 14 * e, ux = SLANT / Math.hypot(SLANT, 1), uy = 1 / Math.hypot(SLANT, 1);
+ const tx = x - ux * len, ty = Math.max(top, y - uy * len);
+ p.line(x, y, tx + (ty - (y - uy * len)) * SLANT, ty, (u) => (u < 0.25 ? C[5] : u < 0.55 ? C[4] : u < 0.8 ? C[3] : C[2]));
+ p.line(x - 1, y, x - 1 - ux * len * 0.45, y - uy * len * 0.45, (u) => (u < 0.5 ? C[4] : C[3]));
+ p.sprite(STAR, { a: C[6], b: WHITE }, Math.round(x) - 3, Math.round(y) - 4);
+ p.glow(x, y, 9, C[5], 0.4);
+ // dust shed from the tail, hanging a moment
+ burst(3, S * 7 + i, (q) => {
+ const kk = q.range(0.15, 0.85), born = t0 + fall * Math.sqrt(kk), age = t - born, life = q.range(0.15, 0.3);
+ if (age < 0 || age > life) return;
+ const [bx, by] = pos(ease.inQuad(Math.sqrt(kk)));
+ p.px(bx + q.range(-2, 2), by + q.range(-2, 2) + age * 8, age / life < 0.5 ? C[5] : C[4]);
+ });
+ }
+ // the hit
+ const a = t - (t0 + fall);
+ if (a < 0 || a > 0.5) continue;
+ if (a < 0.067) {
+ p.ellipse(lx, -1, 6, 2, WHITE);
+ sparkle(p, lx, -3, 3, WHITE, C[6], WHITE);
+ p.glow(lx, -2, 18, C[5], 0.55);
+ }
+ const rr = seg(a, 0.02, 0.2);
+ if (rr > 0 && rr < 1) {
+ const R = 4 + 6 * ease.outCubic(rr);
+ ovalLine(p, R, R * 0.33, rr < 0.5 ? C[5] : C[4], 1, lx, 0);
+ }
+ burst(3, S * 13 + i, (q) => {
+ const ang = -Math.PI / 2 + q.range(-1.1, 1.1), sp = q.range(40, 75), life = q.range(0.22, 0.36);
+ if (a > life) return;
+ const [x, y] = fly(lx, -1, Math.cos(ang) * sp, Math.sin(ang) * sp, a, 260, 1);
+ if (y > 0) return;
+ p.px(x, y, a / life < 0.4 ? C[6] : C[4]);
+ });
+ // the glint it leaves on the floor
+ const g = seg(a, 0.08, 0.45);
+ if (g > 0 && g < 1) sparkle(p, lx, -1, g < 0.2 ? 2 : g < 0.6 ? 1 : 0, C[6], C[5], WHITE, 1 - g * 0.5);
+ p.glow(lx, -2, 12, C[4], 0.35 * clamp(1 - a / 0.35));
+ }
+}
diff --git a/src/fx/arcane/time-stop.js b/src/fx/arcane/time-stop.js
new file mode 100644
index 0000000..6e7dcb0
--- /dev/null
+++ b/src/fx/arcane/time-stop.js
@@ -0,0 +1,102 @@
+import { burst, fly, seg, ease, clamp, rgb, red, green, blue, luma, TAU, WHITE } from "../../core/index.js";
+import { fit, sparkle, CHRONO } from "./_lib.js";
+
+export const meta = {
+ name: "Time stop",
+ desc: "A clock face rings out, its hands spin and tick slower and slower, then freeze with a white flash, hang drained of color and shatter.",
+ tags: ["arcane", "time", "clock", "freeze", "stop", "one-shot"],
+ size: [76, 90],
+ origin: [38, 37],
+ duration: 1.6,
+ loop: false,
+ fps: 30,
+ bg: "dark",
+ options: { palette: CHRONO, radius: 24, seed: 17 },
+};
+
+const T_FREEZE = 0.8, T_BREAK = 1.16, STEP = TAU / 12;
+// the same ramp with most of its color drained: the frozen clock
+const drain = (c) => {
+ const l = luma(c) * 255, k = 0.75;
+ return rgb(red(c) + (l - red(c)) * k, green(c) + (l - green(c)) * k + 4, blue(c) + (l - blue(c)) * k + 14);
+};
+
+export function draw(p, t, o) {
+ const C0 = fit(o.palette), F = C0.map(drain), S = o.seed;
+ const frozen = t >= T_FREEZE, flash = t >= T_FREEZE && t < T_FREEZE + 0.067;
+ const C = frozen ? F : C0, ink = (c) => (flash ? WHITE : c);
+ const R = o.radius * ease.outBack(seg(t, 0, 0.2), 1.8);
+ if (R < 1) return;
+ // the hands: the minute hand snaps tick to tick, quickly at first, then slower and slower until it stops
+ const tm = Math.min(t, T_FREEZE), turn = 2.25 * TAU * ease.outCubic(seg(tm, 0.12, T_FREEZE));
+ const mAng = Math.floor(turn / STEP + 1e-6) * STEP - Math.PI / 2, hAng = turn / 12 + (TAU * 10) / 12 - Math.PI / 2;
+ const speed = 2.25 * TAU * 3 * Math.pow(1 - seg(tm, 0.12, T_FREEZE), 2) / (T_FREEZE - 0.12); // rad/s, from outCubic
+ // shattering: every twelfth of the face flies off on its own and falls
+ const age = t - T_BREAK, piece = (i) => {
+ if (age < 0) return [0, 0, 1];
+ const mid = -Math.PI / 2 + i * STEP, r = burstRng(S, i);
+ const [x, y] = fly(0, 0, Math.cos(mid) * r[0], Math.sin(mid) * r[0] - r[1], age, 420, 1);
+ const life = 0.26 + r[2] * 0.18;
+ return [x, y, y > 24 ? 0 : 1 - seg(age, life - 0.05, life)];
+ };
+ for (let i = 0; i < 12; i++) {
+ const [dx, dy, a] = piece(i);
+ if (a <= 0) continue;
+ // whole, the face is two rings; broken, each piece carries its own two arcs
+ if (age >= 0) {
+ const a0 = -Math.PI / 2 + (i - 0.5) * STEP, a1 = a0 + STEP - 0.05;
+ p.arc(dx, dy, R, 1, a0, a1, ink(C[5]), a);
+ p.arc(dx, dy, R - 3, 1, a0, a1, ink(C[3]), a);
+ } else if (i === 0) {
+ p.ring(0, 0, R, 1, ink(C[5]));
+ p.ring(0, 0, R - 3, 1, ink(C[3]));
+ }
+ // ticks appear one by one round the face as it opens; the one under the minute hand lights up
+ if (t < 0.1 + i * 0.012) continue;
+ const ang = -Math.PI / 2 + i * STEP, major = i % 3 === 0, r0 = R - 5, r1 = major ? R - 10 : R - 7;
+ const lit = !frozen && Math.abs(Math.atan2(Math.sin(ang - mAng), Math.cos(ang - mAng))) < 0.1;
+ const born = t < 0.16 + i * 0.012;
+ p.line(dx + Math.cos(ang) * r0, dy + Math.sin(ang) * r0, dx + Math.cos(ang) * r1, dy + Math.sin(ang) * r1,
+ ink(lit || born ? WHITE : major ? C[6] : C[5]), a);
+ }
+ // hands, with two fading echoes while they spin fast
+ const [hx, hy, ha] = piece(12), [mx, my, ma] = piece(13);
+ const hand = (ang, len, c, a, ox, oy) => {
+ p.line(ox, oy, ox + Math.cos(ang) * len, oy + Math.sin(ang) * len, c, a);
+ p.line(ox + 1, oy, ox + 1 + Math.cos(ang) * (len - 1), oy + Math.sin(ang) * (len - 1), c, a);
+ };
+ if (!frozen && speed > 8) {
+ hand(mAng - STEP * 1.5, R - 9, C[3], 0.8, 0, 0);
+ hand(mAng - STEP * 0.75, R - 8, C[4], 1, 0, 0);
+ }
+ if (ha > 0) hand(hAng, R - 14, ink(C[5]), ha, hx, hy);
+ if (ma > 0) hand(mAng, R - 7, ink(C[6]), ma, mx, my);
+ if (ma > 0) p.circle(mx + 0.5, my, 1.6, ink(WHITE), ma);
+ // motes swept round by the spin; they stop dead at the freeze and drop with the pieces
+ burst(10, S + 1, (r, i) => {
+ const a0 = r.range(0, TAU), rr = R + r.range(3, 8), w = r.range(0.5, 0.9);
+ const ang = a0 + turn * w, [dx, dy, a] = piece(i % 12);
+ if (a <= 0) return;
+ const x = dx + Math.cos(ang) * rr, y = dy + Math.sin(ang) * rr;
+ p.px(x, y, frozen ? (Math.floor(t * 12 + i) % 3 === 0 ? WHITE : C[5]) : C[6], a);
+ });
+ // the freeze: a white flash, a wave of stillness rolling out, frost glinting round the rim
+ if (frozen && age < 0) {
+ const wv = seg(t, T_FREEZE, T_FREEZE + 0.2);
+ if (wv < 1) p.ring(0, 0, R + 2 + 9 * ease.outCubic(wv), 1, F[6], (v, ang) => (Math.sin(ang * 8) > wv * 2 - 1 ? 1 : 0));
+ for (let i = 0; i < 4; i++) {
+ const g = seg(t, T_FREEZE + 0.05 + i * 0.06, T_FREEZE + 0.2 + i * 0.06), ang = -Math.PI / 2 + (i * 5 + 1) * STEP * 0.6;
+ if (g > 0 && g < 1) sparkle(p, Math.cos(ang) * R, Math.sin(ang) * R, g < 0.5 ? 2 : 1, WHITE, F[6], WHITE);
+ }
+ }
+ if (flash) p.glow(0, 0, 40, C0[5], 0.55);
+ const L = frozen ? clamp(1 - (t - T_FREEZE) / 0.3) * 0.6 : 0.25 * seg(t, 0, 0.2);
+ p.glow(0, 0, R + 10, C0[4], L * (age > 0 ? 0 : 1));
+}
+
+// launch speed, lift and fade delay for a piece of the shattered face
+function burstRng(seed, i) {
+ const out = [];
+ burst(1, seed * 97 + i, (r) => out.push(r.range(16, 34), r.range(0, 30), r.next()));
+ return out;
+}
diff --git a/src/fx/categories.js b/src/fx/categories.js
new file mode 100644
index 0000000..14a3adc
--- /dev/null
+++ b/src/fx/categories.js
@@ -0,0 +1,24 @@
+// The categories, in gallery order, with a line for each.
+
+export const categories = [
+ { id: "fire", name: "fire", blurb: "torches, breath, pillars, walls of flame" },
+ { id: "explosions", name: "explosions", blurb: "blasts, smoke, fireworks, mushroom clouds" },
+ { id: "water", name: "water", blurb: "splashes, falls, fountains, waves" },
+ { id: "ice", name: "ice", blurb: "spikes, novas, freezing, shattering" },
+ { id: "lightning", name: "lightning", blurb: "strikes, arcs, coils, storms" },
+ { id: "scifi", name: "sci-fi", blurb: "holograms, shields, scanners, warps" },
+ { id: "melee", name: "melee", blurb: "slashes, smears, cleaves, combos" },
+ { id: "impacts", name: "impacts", blurb: "hit sparks, shockwaves, landings" },
+ { id: "projectiles", name: "projectiles", blurb: "bullets, rockets, lasers, arrows" },
+ { id: "spawn", name: "spawn & death", blurb: "poofs, portals, souls, shatters" },
+ { id: "arcane", name: "arcane", blurb: "portals, runes, missiles, beams" },
+ { id: "holy", name: "holy", blurb: "heals, halos, pillars of light" },
+ { id: "shadow", name: "shadow", blurb: "curses, voids, tendrils, souls" },
+ { id: "status", name: "status", blurb: "burning, frozen, poisoned, asleep" },
+ { id: "nature", name: "nature", blurb: "poison, vines, thorns, quakes" },
+ { id: "weather", name: "weather", blurb: "rain, snow, fog, aurora" },
+ { id: "ui", name: "ui", blurb: "level ups, numbers, toasts, countdowns" },
+ { id: "pickups", name: "pickups", blurb: "coins, gems, chests, potions" },
+ { id: "transitions", name: "transitions", blurb: "wipes, irises, dissolves" },
+ { id: "critters", name: "critters", blurb: "slimes, bats, ghosts, frogs" },
+];
diff --git a/src/fx/critters/_lib.js b/src/fx/critters/_lib.js
new file mode 100644
index 0000000..be2be4f
--- /dev/null
+++ b/src/fx/critters/_lib.js
@@ -0,0 +1,162 @@
+// Shared by the critters: a small offscreen grid to build a creature from parts (shaded shapes, string
+// sprites, lines), then wrap the whole silhouette in one dark outline and put it on the painter.
+
+import { hex, ramp, clamp, wrap } from "../../core/index.js";
+
+/**
+ * The loop time for this critter: seeds other than 1 start it at a different point in its loop, so a crowd of
+ * the same critter doesn't move in lockstep.
+ */
+export const shift = (t, D, seed = 1) => wrap(t + ((seed - 1) * 0.618) * D, D);
+
+/** k colors spread evenly over a palette (dark to bright), so any ramp length works. */
+export function shades(palette, k = 5) {
+ const C = ramp(palette), n = C.length;
+ if (n === k) return C;
+ return Array.from({ length: k }, (_, i) => C[Math.round((i * (n - 1)) / (k - 1))]);
+}
+
+/**
+ * Lambert light on a sphere-ish blob from a normalized offset (nx, ny in -1..1, y down): 0 dark .. 1 lit.
+ * The light comes from the top-left and a little in front.
+ */
+export function lit(nx, ny, lx = -0.55, ly = -0.62) {
+ const d2 = nx * nx + ny * ny, nz = Math.sqrt(Math.max(0, 1 - d2));
+ const lz = Math.sqrt(Math.max(0, 1 - lx * lx - ly * ly));
+ return clamp(nx * lx + ny * ly + nz * lz);
+}
+
+/** A looping curve through keyframes [[phase, value], ...] (phases 0..1, eased between keys). */
+export function keys(ph, list) {
+ ph = wrap(ph, 1);
+ for (let i = 0; i < list.length; i++) {
+ const [p0, v0] = list[i], [p1, v1] = list[(i + 1) % list.length];
+ const end = i + 1 < list.length ? p1 : p1 + 1;
+ const x = ph < p0 ? ph + 1 : ph;
+ if (x >= p0 && x <= end) {
+ const u = (x - p0) / (end - p0 || 1);
+ return v0 + (v1 - v0) * u * u * (3 - 2 * u);
+ }
+ }
+ return list[0][1];
+}
+
+/** A creature-sized canvas in local coordinates: cells [x0, x0 + w) x [y0, y0 + h). */
+export class Grid {
+ constructor(x0, y0, w, h) {
+ this.x0 = x0; this.y0 = y0; this.w = w; this.h = h;
+ this.c = new Uint32Array(w * h);
+ }
+ idx(x, y) {
+ const ix = Math.floor(x) - this.x0, iy = Math.floor(y) - this.y0;
+ return ix < 0 || iy < 0 || ix >= this.w || iy >= this.h ? -1 : iy * this.w + ix;
+ }
+ set(x, y, c) {
+ const i = this.idx(x, y);
+ if (i >= 0) this.c[i] = c;
+ }
+ get(x, y) {
+ const i = this.idx(x, y);
+ return i < 0 ? 0 : this.c[i];
+ }
+ /** fn(x, y) at each cell center in the box returns a color (or 0 / undefined to leave it). */
+ shade(x0, y0, x1, y1, fn) {
+ for (let y = Math.floor(y0); y <= Math.floor(y1); y++)
+ for (let x = Math.floor(x0); x <= Math.floor(x1); x++) {
+ const c = fn(x + 0.5, y + 0.5);
+ if (c) this.set(x, y, c);
+ }
+ }
+ /** Filled ellipse; c may be fn(nx, ny) of the normalized offset (-1..1), returning a color. */
+ ellipse(cx, cy, rx, ry, c) {
+ if (rx <= 0 || ry <= 0) return;
+ this.shade(cx - rx, cy - ry, cx + rx, cy + ry, (x, y) => {
+ const nx = (x - cx) / rx, ny = (y - cy) / ry;
+ if (nx * nx + ny * ny > 1) return 0;
+ return typeof c === "function" ? c(nx, ny) : c;
+ });
+ }
+ /** 1 px line. */
+ line(x0, y0, x1, y1, c) {
+ const n = Math.max(1, Math.ceil(Math.max(Math.abs(x1 - x0), Math.abs(y1 - y0))));
+ for (let i = 0; i <= n; i++) this.set(x0 + ((x1 - x0) * i) / n, y0 + ((y1 - y0) * i) / n, typeof c === "function" ? c(i / n) : c);
+ }
+ /** A line of discs, r may be fn(u): tails, tentacles, legs. c may be fn(u, v) with v 0 center .. 1 edge. */
+ tube(pts, r, c) {
+ for (let k = 1; k < pts.length; k++) {
+ const [ax, ay] = pts[k - 1], [bx, by] = pts[k], L = Math.max(1, Math.hypot(bx - ax, by - ay));
+ for (let s = 0; s <= L; s += 0.5) {
+ const u = (k - 1 + s / L) / (pts.length - 1), rr = typeof r === "function" ? r(u) : r;
+ const x = ax + ((bx - ax) * s) / L, y = ay + ((by - ay) * s) / L;
+ if (rr < 0.75) {
+ this.set(x, y, typeof c === "function" ? c(u, 0) : c);
+ continue;
+ }
+ this.shade(x - rr, y - rr, x + rr, y + rr, (px, py) => {
+ const d = Math.hypot(px - x, py - y) / rr;
+ return d > 1 ? 0 : typeof c === "function" ? c(u, d) : c;
+ });
+ }
+ }
+ }
+ /** Filled polygon (even-odd); c may be fn(x, y). */
+ poly(pts, c) {
+ let x0 = Infinity, y0 = Infinity, x1 = -Infinity, y1 = -Infinity;
+ for (const [x, y] of pts) (x0 = Math.min(x0, x)), (x1 = Math.max(x1, x)), (y0 = Math.min(y0, y)), (y1 = Math.max(y1, y));
+ const n = pts.length;
+ this.shade(x0, y0, x1, y1, (x, y) => {
+ let inside = false;
+ for (let i = 0, j = n - 1; i < n; j = i++) {
+ const [xi, yi] = pts[i], [xj, yj] = pts[j];
+ if (yi > y !== yj > y && x < ((xj - xi) * (y - yi)) / (yj - yi) + xi) inside = !inside;
+ }
+ return inside ? (typeof c === "function" ? c(x, y) : c) : 0;
+ });
+ }
+ /**
+ * A sprite from strings, its pixel (ax, ay) placed at (X, Y). opts: { sx, sy (scale), rot, flip }.
+ * Scaled or turned sprites are resampled nearest-neighbour, so they stay hard pixels.
+ */
+ sprite(rows, pal, X, Y, { ax = 0, ay = 0, sx = 1, sy = 1, rot = 0, flip = false } = {}) {
+ const H = rows.length, W = rows[0].length, cache = {};
+ const col = (ch) => (ch in cache ? cache[ch] : (cache[ch] = pal[ch] === undefined ? 0 : hex(pal[ch])));
+ if (sx === 1 && sy === 1 && rot === 0) {
+ for (let r = 0; r < H; r++)
+ for (let q = 0; q < W; q++) {
+ const ch = rows[r][flip ? W - 1 - q : q];
+ if (ch === "." || ch === " ") continue;
+ const c = col(ch);
+ if (c) this.set(Math.round(X - (flip ? W - 1 - ax : ax)) + q, Math.round(Y - ay) + r, c);
+ }
+ return;
+ }
+ const cs = Math.cos(rot), sn = Math.sin(rot);
+ const R = Math.hypot(Math.max(ax, W - ax) * Math.abs(sx), Math.max(ay, H - ay) * Math.abs(sy)) + 1;
+ this.shade(X - R, Y - R, X + R, Y + R, (x, y) => {
+ const dx = x - X, dy = y - Y, u = (dx * cs + dy * sn) / sx, v = (-dx * sn + dy * cs) / sy;
+ let q = Math.floor(ax + u), r = Math.floor(ay + v);
+ if (q < 0 || r < 0 || q >= W || r >= H) return 0;
+ if (flip) q = W - 1 - q;
+ const ch = rows[r][q];
+ return ch === "." || ch === " " ? 0 : col(ch);
+ });
+ }
+ /** Wrap everything drawn so far in a 1 px outline (4-neighbour), color c. */
+ outline(c) {
+ const src = this.c.slice(), w = this.w, h = this.h;
+ for (let y = 0; y < h; y++)
+ for (let x = 0; x < w; x++) {
+ const i = y * w + x;
+ if (src[i]) continue;
+ if ((x > 0 && src[i - 1]) || (x < w - 1 && src[i + 1]) || (y > 0 && src[i - w]) || (y < h - 1 && src[i + w])) this.c[i] = c;
+ }
+ }
+ /** Put the grid on the painter (a < 1 dithers it out). */
+ draw(p, a = 1) {
+ for (let y = 0; y < this.h; y++)
+ for (let x = 0; x < this.w; x++) {
+ const c = this.c[y * this.w + x];
+ if (c) p.dot(this.x0 + x, this.y0 + y, c, a);
+ }
+ }
+}
diff --git a/src/fx/critters/bat.js b/src/fx/critters/bat.js
new file mode 100644
index 0000000..a3d3731
--- /dev/null
+++ b/src/fx/critters/bat.js
@@ -0,0 +1,62 @@
+import { hex, TAU } from "../../core/index.js";
+import { Grid, shades, lit, shift } from "./_lib.js";
+
+export const meta = {
+ name: "Bat",
+ desc: "A bat flaps in place in four hard wing frames, body bobbing against the beat, ears up, eyes glinting, drifting in a lazy figure eight.",
+ tags: ["critter", "bat", "flying", "spooky", "loop"],
+ size: [48, 34],
+ origin: [24, 16],
+ duration: 0.9,
+ loop: true,
+ fps: 30,
+ bg: "dark",
+ options: { palette: ["#130d1c", "#2f2245", "#57437a", "#8c74ad", "#d4a2c4"], eyes: "#ffd23c", flaps: 3, seed: 1 },
+};
+
+// the right wing spread flat, from the shoulder: leading edge out to the wrist, three fingers, scalloped trailing edge
+const WRIST = [7, -3.5], TIPS = [[15.5, -4.5], [15, 3], [8.5, 7]];
+const EDGE = [[0, -1.5], WRIST, TIPS[0], [12.5, 0], TIPS[1], [10, 3], TIPS[2], [4.5, 4], [0, 4.5]];
+// four wing frames a flap: [angle, span]: up, sweeping down, down, folded on the way back up
+const FRAMES = [[-1.05, 0.9], [-0.15, 1], [0.62, 0.92], [-0.42, 0.66]];
+
+export function draw(p, time, o) {
+ const t = shift(time, meta.duration, o.seed);
+ const S = shades(o.palette, 5), eye = hex(o.eyes), ph = t / meta.duration;
+ const f = (ph * o.flaps) % 1, fi = Math.floor(f * 4), [ang, span] = FRAMES[fi];
+ const bx = Math.round(Math.sin(ph * TAU) * 3), by = Math.round(Math.sin(ph * TAU * 2) * 1.5 + [1, 0, -1.5, -0.5][fi]);
+ const g = new Grid(-24, -17, 48, 34);
+ const cs = Math.cos(ang), sn = Math.sin(ang);
+ for (const side of [-1, 1]) {
+ const sx = bx + side * 2.5, sy = by - 1;
+ const tf = ([x, y]) => [sx + side * (x * span * cs - y * sn), sy + x * span * sn + y * cs];
+ const pts = EDGE.map(tf);
+ g.poly(pts, S[1]);
+ // the arm and finger bones catch a little light
+ const [wx, wy] = tf(WRIST);
+ g.line(sx, sy - 1, wx, wy, S[3]);
+ for (const tip of TIPS) {
+ const [tx, ty] = tf(tip);
+ g.line(wx, wy, wx + (tx - wx) * 0.8, wy + (ty - wy) * 0.8, S[2]);
+ }
+ g.set(wx, wy, S[3]);
+ }
+ // body: furry egg, head with tall ears, pale snout
+ g.ellipse(bx, by + 2.5, 3.2, 4.2, (nx, ny) => (lit(nx, ny) > 0.62 ? S[3] : S[2]));
+ g.ellipse(bx, by - 2.5, 3.6, 3.2, (nx, ny) => (lit(nx, ny) > 0.6 ? S[3] : S[2]));
+ for (const side of [-1, 1]) {
+ g.poly([[bx + side * 0.6, by - 4], [bx + side * 3.6, by - 9.5], [bx + side * 3.8, by - 3.5]], S[2]);
+ g.set(bx + side * 2.6 - (side > 0 ? 0 : 0), by - 6, S[4]);
+ g.set(bx + side * 2.6, by - 5, S[4]);
+ }
+ // eyes, a pink nose, two fangs
+ g.set(bx - 2, by - 3, eye), g.set(bx + 1, by - 3, eye);
+ g.set(bx - 1, by - 1, S[4]), g.set(bx, by - 1, S[4]);
+ g.set(bx - 1, by, 0xffffffff), g.set(bx, by + 0, S[2]), g.set(bx + 1, by, 0xffffffff);
+ // feet tucked under
+ g.set(bx - 1, by + 7, S[2]), g.set(bx + 1, by + 7, S[2]);
+ g.outline(S[0]);
+ g.draw(p);
+ p.light(bx - 2, by - 3, eye, 0.5);
+ p.light(bx + 1, by - 3, eye, 0.5);
+}
diff --git a/src/fx/critters/bird.js b/src/fx/critters/bird.js
new file mode 100644
index 0000000..cf82098
--- /dev/null
+++ b/src/fx/critters/bird.js
@@ -0,0 +1,65 @@
+import { hex, TAU, WHITE } from "../../core/index.js";
+import { Grid, shades, lit, shift } from "./_lib.js";
+
+export const meta = {
+ name: "Bird",
+ desc: "A little bluebird flies in place, side on: three hard flaps and a glide, body lifting on each downstroke, tail fanning, beak forward.",
+ tags: ["critter", "bird", "flying", "nature", "loop"],
+ size: [44, 40],
+ origin: [22, 20],
+ duration: 1.2,
+ loop: true,
+ fps: 30,
+ bg: "dark",
+ options: { palette: ["#0b1330", "#1d3c7c", "#3a74ca", "#7cb6f2", "#e4f2ff"], breast: "#f0a050", beak: "#f6c344", seed: 1 },
+};
+
+// wing tip (from the shoulder) for each frame of a beat: up, down-sweep, down, folded back up; and the glide
+const TIP = [[-3, -13], [-10, -4], [-4, 9], [-8, -6]], GLIDE = [-10, -3];
+const LIFT = [1, 0, -1, -1];
+
+function wing(g, sx, sy, [tx, ty], fill, lead, tips) {
+ // leading edge from the front of the shoulder to the tip; the trailing edge from the back of the shoulder,
+ // its feathers fanning out away from the leading edge
+ const A = [sx + 2, sy - 1], B = [sx - 3, sy + 1], T = [sx + tx, sy + ty];
+ let nx = -(T[1] - A[1]), ny = T[0] - A[0];
+ const L = Math.hypot(nx, ny) || 1;
+ if (nx * (B[0] - A[0]) + ny * (B[1] - A[1]) < 0) (nx = -nx), (ny = -ny);
+ (nx /= L), (ny /= L);
+ const at = (f, out) => [B[0] + (T[0] - B[0]) * f + nx * out, B[1] + (T[1] - B[1]) * f + ny * out];
+ const mid = [(A[0] + T[0]) / 2 - nx * 0.8, (A[1] + T[1]) / 2 - ny * 0.8];
+ g.poly([A, mid, T, at(0.84, 1.8), at(0.74, 0.6), at(0.6, 2), at(0.46, 0.8), at(0.3, 1.8), at(0.15, 0.6), B], fill);
+ g.line(A[0], A[1], T[0], T[1], lead);
+ for (const f of [0.84, 0.6, 0.3]) {
+ const [x, y] = at(f, 1.4);
+ g.set(x, y, tips);
+ }
+}
+
+export function draw(p, time, o) {
+ const t = shift(time, meta.duration, o.seed);
+ const S = shades(o.palette, 5), breast = hex(o.breast), beak = hex(o.beak), ph = t / meta.duration;
+ const beat = Math.floor(ph * 4), f = (ph * 4) % 1, fi = Math.floor(f * 4), glide = beat === 3;
+ const tip = glide ? GLIDE : TIP[fi];
+ const by = Math.round((glide ? 0 : LIFT[fi]) + Math.sin(ph * TAU) * 1.5), bx = 0;
+ const g = new Grid(-22, -20, 44, 40);
+ // far wing first, in shadow
+ wing(g, bx + 1, by - 2, [tip[0] * 0.8 + 2, tip[1] * 0.85], S[1], S[2], S[0]);
+ // tail: a little fan behind
+ const tl = glide ? 0 : fi === 2 ? 1 : fi === 0 ? -1 : 0;
+ g.poly([[bx - 4, by - 1], [bx - 10, by - 3 + tl], [bx - 9, by + 0.5 + tl], [bx - 10.5, by + 3 + tl], [bx - 4, by + 2]], S[2]);
+ g.line(bx - 5, by + 0.5, bx - 9, by + 0.5 + tl, S[1]);
+ // body: blue back, warm breast
+ g.ellipse(bx, by, 6.2, 4.2, (nx, ny) => {
+ if (ny > 0.05 && nx > -0.55) return lit(nx, ny) > 0.35 ? breast : hex("#c06a34");
+ return lit(nx, ny) > 0.62 ? S[3] : S[2];
+ });
+ // head and beak
+ g.ellipse(bx + 5.5, by - 3.4, 3.4, 3.1, (nx, ny) => (ny > 0.45 && nx > -0.2 ? breast : lit(nx, ny) > 0.55 ? S[3] : S[2]));
+ g.poly([[bx + 8.4, by - 4.6], [bx + 11.6, by - 3.2], [bx + 8.4, by - 2]], beak);
+ g.set(bx + 6, by - 4, S[0]), g.set(bx + 6, by - 5, WHITE);
+ // near wing on top
+ wing(g, bx, by - 1, tip, S[2], S[3], S[1]);
+ g.outline(S[0]);
+ g.draw(p);
+}
diff --git a/src/fx/critters/butterfly.js b/src/fx/critters/butterfly.js
new file mode 100644
index 0000000..bdb1af1
--- /dev/null
+++ b/src/fx/critters/butterfly.js
@@ -0,0 +1,64 @@
+import { hex, TAU, WHITE } from "../../core/index.js";
+import { Grid, shades, shift } from "./_lib.js";
+
+export const meta = {
+ name: "Butterfly",
+ desc: "A blue butterfly flutters along a lazy looping path: four-frame wingbeats closing to a sliver, dark wing borders with white spots, a little glide.",
+ tags: ["critter", "butterfly", "insect", "flying", "nature", "loop"],
+ size: [52, 44],
+ origin: [26, 22],
+ duration: 2.4,
+ loop: true,
+ fps: 30,
+ bg: "dark",
+ options: { palette: ["#0b0f2c", "#18296e", "#2a5fc4", "#4fa4f2", "#c6ecff"], body: "#3a2c40", beats: 9, seed: 1 },
+};
+
+// a wing is a turned ellipse: [cx, cy, rx, ry, turn] from the body, for the right side
+const UPPER = [6.6, -4.4, 7.4, 5.3, -0.6], LOWER = [4.6, 3.4, 5, 4, 0.6];
+// openness through one beat: open, closing, edge-on, opening (one frame each, held)
+const OPEN = [1, 0.55, 0.2, 0.55];
+
+function wing(g, S, bx, by, side, open, [cx, cy, rx, ry, a], spots) {
+ const cs = Math.cos(a), sn = Math.sin(a), R = Math.max(rx, ry) + 1;
+ g.shade(bx - (R + Math.abs(cx)) * 1.1, by + cy - R, bx + (R + Math.abs(cx)) * 1.1, by + cy + R, (x, y) => {
+ const ux = ((x - bx) * side) / open; // undo the flap squash
+ if (ux < 0) return 0;
+ const dx = ux - cx, dy = y - by - cy, u = (dx * cs + dy * sn) / rx, v = (-dx * sn + dy * cs) / ry;
+ const d = Math.sqrt(u * u + v * v);
+ if (d > 1) return 0;
+ const ang = Math.atan2(v, u);
+ if (d > 0.74) {
+ // the dark border, with a row of white spots along the outer edge
+ for (const s of spots) if (Math.abs(ang - s) < 0.16 && d > 0.79 && d < 0.92) return WHITE;
+ return S[1];
+ }
+ if (ux < 1.2 || d < 0.3) return S[2];
+ return u < -0.1 && v < 0.2 ? S[4] : S[3];
+ });
+}
+
+export function draw(p, time, o) {
+ const t = shift(time, meta.duration, o.seed);
+ const S = shades(o.palette, 5), body = hex(o.body), ph = t / meta.duration;
+ const beat = (ph * o.beats) % 1, fi = Math.floor(beat * 4);
+ // a glide: on one beat in three the wings hold open
+ const glide = Math.floor(ph * o.beats) % 3 === 2 && fi < 3;
+ const open = glide ? 1 : OPEN[fi];
+ const bx = Math.round(Math.sin(ph * TAU) * 10), by = Math.round(Math.sin(ph * TAU * 2) * 5 + (fi === 2 ? -1 : 0));
+ const g = new Grid(-26, -22, 52, 44);
+ for (const side of [-1, 1]) {
+ const root = side > 0 ? bx + 0.5 : bx - 0.5;
+ wing(g, S, root, by, side, open, LOWER, [0.7]);
+ wing(g, S, root, by, side, open, UPPER, [-0.25, 0.45]);
+ }
+ // body and feelers
+ for (let y = -3; y <= 5; y++) g.set(bx, by + y, body), g.set(bx - 1, by + y, y < 3 ? body : 0);
+ g.set(bx - 1, by - 3, S[1]);
+ const sway = fi === 2 ? 1 : 0;
+ g.line(bx - 1, by - 4, bx - 4, by - 9 + sway, body);
+ g.line(bx, by - 4, bx + 3, by - 9 + sway, body);
+ g.outline(S[0]);
+ g.set(bx - 4, by - 10 + sway, S[4]), g.set(bx + 3, by - 10 + sway, S[4]);
+ g.draw(p);
+}
diff --git a/src/fx/critters/crab.js b/src/fx/critters/crab.js
new file mode 100644
index 0000000..c1b0568
--- /dev/null
+++ b/src/fx/critters/crab.js
@@ -0,0 +1,80 @@
+import { seg, TAU, WHITE } from "../../core/index.js";
+import { Grid, shades, lit, keys, shift } from "./_lib.js";
+
+export const meta = {
+ name: "Crab",
+ desc: "A red crab scuttles sideways in quick little steps, stops to snap both claws and look about on its eye stalks, then scuttles back.",
+ tags: ["critter", "crab", "beach", "sea", "scuttle", "loop", "ground"],
+ size: [56, 36],
+ origin: [28, 32],
+ duration: 2,
+ loop: true,
+ fps: 30,
+ bg: "ground",
+ options: { palette: ["#2a0b10", "#7c1c1e", "#c93b26", "#f27c3c", "#ffd2a2"], seed: 1 },
+};
+
+// where it is across the floor: scuttle right, stop, scuttle left, stop
+const PATH = [[0, -7], [0.28, 7], [0.5, 7], [0.78, -7]];
+const moving = (ph) => (ph < 0.28) || (ph >= 0.5 && ph < 0.78);
+
+function claw(g, S, x, y, side, open) {
+ // a fat palm with two fingers reaching out; the upper one lifts open on a snap
+ const shade = (nx, ny) => (lit(nx, ny) > 0.72 ? S[4] : lit(nx, ny) > 0.38 ? S[3] : S[2]);
+ g.ellipse(x, y, 3, 2.6, shade);
+ g.ellipse(x + side * 3.2, y + 1.1, 2.4, 1.2, shade);
+ g.ellipse(x + side * 3, y - 1.4 - open * 1.8, 2.3, 1.1, shade);
+ g.set(x + side * 4.6, y - 1.6 - open * 1.8, S[4]);
+}
+
+export function draw(p, time, o) {
+ const t = shift(time, meta.duration, o.seed);
+ const S = shades(o.palette, 5), ph = t / meta.duration;
+ const bx = Math.round(keys(ph, PATH)), mv = moving(ph);
+ const step = Math.floor(t * 16) % 2, bob = mv && step ? -1 : 0;
+ const by = -8 + bob;
+ // two snaps in each stop, and the stalks look around
+ const snapA = Math.sin(Math.PI * seg(ph, 0.32, 0.4)), snapB = Math.sin(Math.PI * seg(ph, 0.82, 0.9));
+ const snapC = Math.sin(Math.PI * seg(ph, 0.41, 0.48)), snapD = Math.sin(Math.PI * seg(ph, 0.91, 0.98));
+ const look = mv ? 0 : Math.round(Math.sin(ph * TAU * 3));
+ const g = new Grid(-28, -32, 56, 36);
+ // legs: three a side, stepping in alternation while it moves
+ for (const side of [-1, 1])
+ for (let k = 0; k < 3; k++) {
+ const lift = mv && (k + (side > 0 ? 1 : 0) + step) % 2 === 0 ? 2 : 0;
+ const hx = bx + side * (5 + k * 1.5), hy = by + 3;
+ const kx = bx + side * (10 + k * 1.6), ky = by - 0.5 + k * 0.6 - lift;
+ const fx = bx + side * (12 + k * 1.8), fy = -0.5 - lift * 0.5;
+ g.line(hx, hy, kx, ky, S[2]);
+ g.line(kx, ky, fx, fy, S[2]);
+ g.set(kx, ky, S[3]);
+ }
+ // arms up to the claws
+ const snapL = Math.max(snapA, snapB), snapR = Math.max(snapC, snapD);
+ for (const side of [-1, 1]) {
+ const cx = bx + side * 12, cy = by - 6 + (side < 0 ? -snapL : -snapR) * 1.5;
+ g.line(bx + side * 7, by - 1, cx - side * 2, cy + 2, S[2]);
+ g.line(bx + side * 7, by - 2, cx - side * 2, cy + 1, S[3]);
+ claw(g, S, cx, cy, side, side < 0 ? snapL : snapR);
+ }
+ // eye stalks with beady eyes
+ for (const side of [-1, 1]) {
+ const ex = bx + side * 3 + look, ey = by - 9;
+ g.line(bx + side * 3, by - 4, ex, ey + 1, S[3]);
+ g.set(ex, ey, S[0]), g.set(ex + (side > 0 ? 1 : -1), ey, S[0]), g.set(ex, ey - 1, S[0]), g.set(ex + (side > 0 ? 1 : -1), ey - 1, WHITE);
+ }
+ // the shell: wide and low, lit from above, a speckled back and a little mouth
+ g.shade(bx - 10, by - 6, bx + 10, by + 5, (x, y) => {
+ const nx = (x - bx) / 9.5, ny = (y - by) / (y < by ? 5.5 : 4.2);
+ if (nx * nx + ny * ny > 1) return 0;
+ const L = lit(nx, ny * 1.2);
+ const spot = ((Math.floor(x) * 7 + Math.floor(y) * 13) % 11 === 0) && ny < 0 && L > 0.4;
+ if (spot) return S[4];
+ return L > 0.84 ? S[4] : L > 0.5 ? S[3] : L > 0.18 ? S[2] : S[1];
+ });
+ g.set(bx - 1, by + 3, S[1]), g.set(bx, by + 3, S[1]), g.set(bx + 1, by + 3, S[1]);
+ g.outline(S[0]);
+ g.draw(p);
+ // a soft shadow on the sand
+ p.ellipse(bx, 0.5, 13, 1.3, 0xff19141a, 0.6);
+}
diff --git a/src/fx/critters/eyeball.js b/src/fx/critters/eyeball.js
new file mode 100644
index 0000000..c7a762f
--- /dev/null
+++ b/src/fx/critters/eyeball.js
@@ -0,0 +1,72 @@
+import { hex, seg, TAU, WHITE } from "../../core/index.js";
+import { Grid, shades, lit, keys, shift } from "./_lib.js";
+
+export const meta = {
+ name: "Eyeball",
+ desc: "A floating eyeball darts its gaze left, right and up with snappy holds, blinks with fleshy lids, veins on the white, its nerve tail swaying.",
+ tags: ["critter", "eye", "eyeball", "monster", "creepy", "float", "loop"],
+ size: [40, 48],
+ origin: [20, 20],
+ duration: 3.2,
+ loop: true,
+ fps: 30,
+ bg: "dark",
+ options: { palette: ["#0d2418", "#1d6232", "#36a648", "#8ede6e", "#e2ffb4"], seed: 1 },
+};
+
+const WHITES = ["#2a1422", "#8c5e72", "#c9aab0", "#ece0dc", "#fffaf4"].map(hex);
+const LID = ["#5a2c44", "#8e4e66", "#b8748a"].map(hex);
+const VEIN = hex("#c02c44"), PUPIL = hex("#0b0a10");
+// where it looks: snap, hold, snap (phase, value)
+const GX = [[0, 0], [0.12, 0], [0.16, -0.5], [0.36, -0.5], [0.4, 0.48], [0.58, 0.48], [0.62, 0.22], [0.76, 0.22], [0.8, 0]];
+const GY = [[0, 0], [0.12, 0], [0.16, 0.06], [0.36, 0.06], [0.4, -0.04], [0.58, -0.04], [0.62, -0.42], [0.76, -0.42], [0.8, 0]];
+// veins: [angle on the rim, bend]
+const VEINS = [[2.6, 1], [3.5, -1], [0.3, -1], [5.6, 1], [1.4, 1]];
+
+export function draw(p, time, o) {
+ const t = shift(time, meta.duration, o.seed);
+ const I = shades(o.palette, 5), ph = t / meta.duration, R = 9;
+ const by = Math.round(Math.sin(ph * TAU * 2) * 1.6), cx = 0, cy = by;
+ const gx = keys(ph, GX), gy = keys(ph, GY);
+ const g = new Grid(-20, -20, 40, 48);
+ // the nerve tail hangs behind and sways
+ const tail = [];
+ for (let s = 0; s <= 12; s += 1.5) tail.push([-2 - s * 0.35 + Math.sin(ph * TAU * 2 - s * 0.3) * s * 0.22, cy + R - 1 + s]);
+ g.tube(tail, (u) => 2.2 * (1 - u * 0.7), (u, v) => (v < 0.45 ? LID[2] : LID[1]));
+ // the white: a lit sphere
+ g.ellipse(cx, cy, R, R, (nx, ny) => {
+ const L = lit(nx, ny);
+ return WHITES[L > 0.8 ? 4 : L > 0.48 ? 3 : L > 0.22 ? 2 : 1];
+ });
+ // veins creep in from the rim
+ for (const [a, bend] of VEINS) {
+ const x0 = Math.cos(a) * (R - 0.5), y0 = cy + Math.sin(a) * (R - 0.5);
+ const x1 = Math.cos(a) * (R - 3.5) + Math.cos(a + 1.57) * bend, y1 = cy + Math.sin(a) * (R - 3.5) + Math.sin(a + 1.57) * bend;
+ g.line(x0, y0, x1, y1, VEIN);
+ g.set(x1 + Math.cos(a + 1.57 * bend) * 1, y1 + Math.sin(a + 1.57 * bend) * 1, VEIN);
+ }
+ // the iris turns on the ball: it slides and foreshortens toward the rim
+ const ix = cx + gx * R, iy = cy + gy * R, irx = 4.4 * Math.sqrt(1 - gx * gx * 0.9), iry = 4.4 * Math.sqrt(1 - gy * gy * 0.9);
+ g.ellipse(ix, iy, irx, iry, (nx, ny) => {
+ const d = Math.hypot(nx, ny);
+ if (d < 0.42) return PUPIL;
+ if (d > 0.82) return I[1];
+ return lit(nx, ny) > 0.55 ? I[3] : I[2];
+ });
+ g.set(Math.round(ix - irx * 0.4) - 1, Math.round(iy - iry * 0.45), WHITE);
+ g.set(Math.round(ix - irx * 0.4), Math.round(iy - iry * 0.45) - 1, WHITE);
+ // a blink: fleshy lids shut from top and bottom and open again
+ const shut = Math.sin(Math.PI * seg(ph, 0.86, 0.93));
+ if (shut > 0) {
+ const top = cy - R + shut * (R + 0.5) * 1.05, bot = cy + R - shut * (R - 0.5) * 0.95;
+ g.shade(cx - R - 1, cy - R - 1, cx + R + 1, cy + R + 1, (x, y) => {
+ if (Math.hypot(x - cx, y - cy) > R + 0.2) return 0;
+ if (y > top && y < bot) return 0;
+ // lid edges dark, the lids lit like the ball they cover
+ if ((y < top && y > top - 1.2) || (y > bot && y < bot + 1.2)) return LID[0];
+ return lit((x - cx) / R, (y - cy) / R) > 0.55 ? LID[2] : LID[1];
+ });
+ }
+ g.outline(WHITES[0]);
+ g.draw(p);
+}
diff --git a/src/fx/critters/fish-school.js b/src/fx/critters/fish-school.js
new file mode 100644
index 0000000..666b7f7
--- /dev/null
+++ b/src/fx/critters/fish-school.js
@@ -0,0 +1,68 @@
+import { hex, loopNoise, cycle, TAU, WHITE } from "../../core/index.js";
+import { Grid, shades, shift } from "./_lib.js";
+
+export const meta = {
+ name: "Fish school",
+ desc: "A small school of silver fish holds its place in the current: tails beating out of step, each fish nosing about its slot, bubbles rising.",
+ tags: ["critter", "fish", "school", "sea", "water", "swim", "loop"],
+ size: [64, 44],
+ origin: [32, 22],
+ duration: 2.4,
+ loop: true,
+ fps: 30,
+ bg: "dark",
+ options: { palette: ["#0a1a2c", "#17496c", "#2b88aa", "#70ccd8", "#dcfbff"], fin: "#f2b33c", count: 6, seed: 3 },
+};
+
+// formation slots: [x, y, size, depth (1 = behind)]
+const SLOTS = [[12, -6, 1, 0], [-2, -11, 0.8, 1], [17, 7, 0.9, 0], [3, 2, 1.05, 0], [-12, -1, 0.85, 1], [-6, 10, 0.95, 0]];
+
+function fish(g, S, fin, x, y, k, wag, deep) {
+ const rx = 5 * k, ry = 2.7 * k, C = deep ? [S[0], S[1], S[1], S[2], S[3]] : S;
+ // tail: a forked fin swinging behind
+ const tx = x - rx - 0.5, tip = wag * 1.6 * k;
+ g.poly([[tx + 1, y - 0.6], [tx - 3.6 * k, y - 2.6 * k + tip], [tx - 2.2 * k, y + tip * 0.6], [tx - 3.6 * k, y + 2.6 * k + tip], [tx + 1, y + 0.6]], deep ? C[2] : fin);
+ // dorsal fin
+ g.poly([[x - 1.5 * k, y - ry + 0.6], [x - 0.5 * k, y - ry - 2 * k], [x + 1.6 * k, y - ry + 0.4]], deep ? C[2] : fin);
+ // body: dark back, bright belly, a pointed nose
+ g.shade(x - rx, y - ry, x + rx + 1, y + ry, (px, py) => {
+ const nx = (px - x) / rx, ny = (py - y) / ry, w = nx > 0 ? 1 - nx * nx * 0.25 : 1;
+ if (nx * nx + (ny / w) * (ny / w) > 1) return 0;
+ if (ny < -0.45) return C[1];
+ if (ny < 0.05) return nx > 0.55 ? C[3] : C[2];
+ if (ny < 0.5) return C[3];
+ return C[4];
+ });
+ // eye
+ const ex = Math.round(x + rx * 0.55), ey = Math.round(y - ry * 0.25);
+ g.set(ex, ey, deep ? C[1] : S[0]);
+ g.set(ex - 1, ey, deep ? C[3] : WHITE);
+}
+
+export function draw(p, time, o) {
+ const t = shift(time, meta.duration, o.seed);
+ const S = shades(o.palette, 5), fin = hex(o.fin), ph = t / meta.duration, n = Math.min(o.count, SLOTS.length);
+ // bubbles behind everything
+ cycle(t, meta.duration, 6, o.seed, (r) => r.range(1, 1.8), (age, life, r) => {
+ const k = age / life, x = r.range(-6, 24) + Math.sin(age * 5 + r.next() * 6) * 1.2, y = r.range(-4, 10) - age * r.range(14, 22);
+ if (y < -20) return;
+ if (r.next() < 0.5) p.px(x, y, S[3]);
+ else p.px(x, y, S[2]), p.px(x + 1, y, S[2]), p.px(x, y - 1, S[2]), p.px(x + 1, y - 1, S[4]);
+ });
+ // back row first, darker; each fish noses around its slot and beats its tail at its own rate
+ const school = [];
+ for (let i = 0; i < n; i++) {
+ const [sx, sy, k, d] = SLOTS[i];
+ const x = sx + loopNoise(ph, 1.1, o.seed + i) * 3.5, y = sy + loopNoise(ph, 0.9, o.seed + 20 + i) * 2.2;
+ school.push({ i, x: Math.round(x), y: Math.round(y), k, d });
+ }
+ school.sort((a, b) => b.d - a.d || a.y - b.y);
+ for (const f of school) {
+ // each fish gets its own outline, so overlapping fish stay apart
+ const g = new Grid(f.x - 14, f.y - 8, 26, 16);
+ const wag = Math.sin(ph * TAU * (6 + (f.i % 3)) + f.i * 1.3);
+ fish(g, S, fin, f.x, f.y, f.k, Math.round(wag * 2) / 2, f.d);
+ g.outline(S[0]);
+ g.draw(p);
+ }
+}
diff --git a/src/fx/critters/flying-skull.js b/src/fx/critters/flying-skull.js
new file mode 100644
index 0000000..e6950b6
--- /dev/null
+++ b/src/fx/critters/flying-skull.js
@@ -0,0 +1,76 @@
+import { hex, ramp, at, clamp, cycle, tileFbm, PAL, TAU } from "../../core/index.js";
+import { Grid, lit, shift } from "./_lib.js";
+
+export const meta = {
+ name: "Flying skull",
+ desc: "A flaming skull bobs in the air, jaw chattering, eye sockets lit from inside; fire streams off its crown and embers rise.",
+ tags: ["critter", "skull", "undead", "fire", "flying", "spooky", "loop"],
+ size: [48, 64],
+ origin: [24, 52],
+ duration: 1.6,
+ loop: true,
+ fps: 30,
+ bg: "dark",
+ options: { palette: PAL.fire, seed: 1 },
+};
+
+const BONE = ["#2a2018", "#6e6250", "#ada186", "#e0d6bc", "#fffaf0"].map(hex);
+const HOLE = hex("#140c10");
+
+export function draw(p, time, o) {
+ const t = shift(time, meta.duration, o.seed);
+ const F = ramp(o.palette), n = F.length, ph = t / meta.duration;
+ const by = Math.round(Math.sin(ph * TAU) * 2.5), cy = -8 + by;
+ // jaw chatters four times a loop
+ const jaw = Math.sin(ph * TAU * 4) > 0.3 ? 2 : Math.sin(ph * TAU * 4) > -0.2 ? 1 : 0;
+ // fire streaming up off the crown (behind the skull)
+ const body = F.slice(2, n - 1);
+ p.shade(-14, cy - 30, 14, cy + 2, (x, y) => {
+ const v = clamp((cy - 3 - y) / 26, 0, 1.2);
+ const w = 10.5 * (1 - v * 0.8) + 1.2 * Math.sin(v * 7 - ph * TAU * 2);
+ const sway = Math.sin(ph * TAU + v * 3) * v * 3;
+ const d = Math.abs(x - sway) / Math.max(1, w);
+ const nz = tileFbm(x * 0.32, y * 0.22 + ph * 14, 0, 14, o.seed, 3);
+ const heat = (1 - d * d) * (1.05 - v * 0.9) + nz * (0.32 + v * 0.22);
+ // the thinnest wisps at the top are dropped, so the tips tear off in clean tongues
+ if (heat < 0.16 + v * 0.14) return;
+ return at(body, (heat - 0.14) / 0.85);
+ });
+ const g = new Grid(-24, -52, 48, 64);
+ // cranium and cheeks
+ g.ellipse(0, cy - 3, 8, 7, (nx, ny) => BONE[lit(nx, ny) > 0.8 ? 4 : lit(nx, ny) > 0.5 ? 3 : lit(nx, ny) > 0.25 ? 2 : 1]);
+ g.shade(-6, cy + 1, 6, cy + 5, (x, y) => {
+ const nx = x / 6.5, L = lit(nx, 0.35);
+ if (Math.abs(nx) > 0.92 && y > cy + 3) return 0;
+ return BONE[L > 0.5 ? 3 : L > 0.25 ? 2 : 1];
+ });
+ // sockets with a burning pupil, a nose hole
+ for (const side of [-1, 1]) {
+ g.ellipse(side * 3.2 - 0.5 + 0.5, cy + 0.2, 2.3, 2.5, HOLE);
+ g.set(side * 3.2 - (side < 0 ? 1 : 0), cy + 0.5, F[n - 2]);
+ }
+ g.set(-1, cy + 3, HOLE), g.set(0, cy + 3, HOLE), g.set(-1, cy + 4, BONE[1]), g.set(0, cy + 4, BONE[1]);
+ // upper teeth
+ for (let x = -4; x <= 3; x++) g.set(x, cy + 6, x % 2 ? BONE[3] : BONE[2]);
+ // the jaw, hinged: it drops and snaps back
+ const jy = cy + 7 + jaw;
+ g.shade(-5, jy, 5, jy + 3, (x, y) => {
+ const nx = x / 5.5, ny = (y - jy) / 3.5;
+ if (nx * nx * 0.7 + ny * ny > 1 && y > jy + 1) return 0;
+ if (y < jy + 1) return Math.floor(x) % 2 ? BONE[3] : BONE[2];
+ return BONE[lit(nx, 0.6) > 0.35 ? 2 : 1];
+ });
+ if (jaw > 0) for (let x = -4; x <= 3; x++) for (let k = 0; k < jaw; k++) g.set(x, cy + 7 + k, HOLE);
+ g.outline(BONE[0]);
+ g.draw(p);
+ // eye glow and embers
+ p.light(-3.7, cy + 0.5, F[n - 2], 0.6), p.light(2.7, cy + 0.5, F[n - 2], 0.6);
+ cycle(t, meta.duration, 8, o.seed + 4, (r) => r.range(0.5, 0.9), (age, life, r) => {
+ const k = age / life, x = r.range(-6, 6) + Math.sin(age * 7 + r.next() * 6) * 2, y = cy - 14 - age * r.range(22, 34);
+ if (y < -50 || (k > 0.6 && Math.sin(age * 40 + r.next() * 9) < -0.4)) return;
+ p.px(x, y, k < 0.4 ? F[n - 2] : F[n - 4]);
+ p.light(x, y, F[n - 3], 0.5 * (1 - k));
+ });
+ p.glow(0, cy - 10, 26, F[n - 4], 0.25);
+ p.glow(0, cy - 6, 9, F[n - 2], 0.18);
+}
diff --git a/src/fx/critters/frog.js b/src/fx/critters/frog.js
new file mode 100644
index 0000000..997e8d7
--- /dev/null
+++ b/src/fx/critters/frog.js
@@ -0,0 +1,101 @@
+import { seg, clamp, lerp, hex, RAMP, TAU, WHITE } from "../../core/index.js";
+import { Grid, shades, lit, shift } from "./_lib.js";
+
+export const meta = {
+ name: "Frog",
+ desc: "A fat green frog sits and puffs its throat, crouches, springs straight up with its legs flung out, and lands back in a squat.",
+ tags: ["critter", "frog", "hop", "nature", "jump", "loop", "ground"],
+ size: [48, 44],
+ origin: [24, 39],
+ duration: 1.8,
+ loop: true,
+ fps: 30,
+ bg: "ground",
+ options: { palette: ["#0e2416", "#23592b", "#47993b", "#9bd35b", "#eef6b6"], seed: 1 },
+};
+
+const EYE = hex("#f2c84a");
+
+// poses: body center, tilt (radians, nose up is negative), stretch; hind leg hip, knee, ankle, toe; front leg
+// shoulder, elbow, hand. All in px from the spot it sits on, facing right.
+const P = {
+ sit: { b: [0, -6], tilt: -0.32, s: 1, h: [[-4, -5], [2, -2.5], [-5, -1], [1, 0]], f: [[4, -4], [5.5, -2], [6.5, 0]] },
+ crouch: { b: [0, -4.8], tilt: -0.2, s: 0.9, h: [[-4, -4], [2.5, -2], [-5, -1], [1.5, 0]], f: [[4.5, -3], [6.5, -1.5], [7, 0]] },
+ leap: { b: [1, -11], tilt: -0.85, s: 1.22, h: [[-3, -8], [-5, -4], [-6.5, -1], [-8, 0]], f: [[5, -14], [8, -15], [10.5, -16]] },
+ air: { b: [0, -17], tilt: -0.15, s: 1.1, h: [[-5, -16], [-9, -14], [-12.5, -15], [-15, -14.5]], f: [[5, -15], [8, -13.5], [10, -12]] },
+ fall: { b: [0, -11], tilt: 0.1, s: 1, h: [[-5, -10], [-2, -7], [-7, -6], [-3, -4.5]], f: [[5, -9], [7, -6], [8, -3.5]] },
+ land: { b: [0, -4.5], tilt: -0.05, s: 0.82, h: [[-4.5, -4], [2, -2], [-5.5, -1], [1.5, 0]], f: [[5, -3], [7, -1.5], [8.5, 0]] },
+};
+const SEQ = [[0, "sit"], [0.34, "sit"], [0.42, "crouch"], [0.47, "leap"], [0.58, "air"], [0.7, "fall"], [0.76, "land"], [0.88, "sit"], [1, "sit"]];
+
+function pose(ph) {
+ for (let i = 0; i < SEQ.length - 1; i++) {
+ const [p0, a] = SEQ[i], [p1, b] = SEQ[i + 1];
+ if (ph < p0 || ph > p1) continue;
+ let u = seg(ph, p0, p1);
+ u = u * u * (3 - 2 * u);
+ const A = P[a], B = P[b], L = (x, y) => lerp(x, y, u), LP = (pa, pb) => [L(pa[0], pb[0]), L(pa[1], pb[1])];
+ return { b: LP(A.b, B.b), tilt: L(A.tilt, B.tilt), s: L(A.s, B.s), h: A.h.map((q, k) => LP(q, B.h[k])), f: A.f.map((q, k) => LP(q, B.f[k])) };
+ }
+ return P.sit;
+}
+
+export function draw(p, time, o) {
+ const t = shift(time, meta.duration, o.seed);
+ const S = shades(o.palette, 5), ph = t / meta.duration, Q = pose(ph);
+ const [bx, by] = Q.b, cs = Math.cos(Q.tilt), sn = Math.sin(Q.tilt), rx = 7.4 * Q.s, ry = 4.8 / Math.sqrt(Q.s);
+ // along the body axis: u forward, v down
+ const at = (u, v) => [bx + u * cs - v * sn, by + u * sn + v * cs];
+ const g = new Grid(-24, -39, 48, 42);
+ // far front leg, in shadow
+ const [sh, el, ha] = Q.f;
+ g.tube([[sh[0] - 2, sh[1]], [el[0] - 2, el[1]], [ha[0] - 2, ha[1]]], 1, S[1]);
+ // body: a tilted egg, green back with dark spots, pale belly
+ g.shade(bx - 12, by - 12, bx + 12, by + 10, (x, y) => {
+ const dx = x - bx, dy = y - by, u = (dx * cs + dy * sn) / rx, v = (-dx * sn + dy * cs) / ry;
+ const w = u > 0 ? 1 - u * 0.12 : 1;
+ if (u * u + (v / w) * (v / w) > 1) return 0;
+ if (v > 0.5) return S[4];
+ if (Math.hypot(u + 0.45, v + 0.5) < 0.16) return S[1];
+ const L = lit(u, v);
+ return L > 0.72 ? S[3] : S[2];
+ });
+ // throat: a pale pouch that puffs while it sits
+ const puff = ph < 0.34 ? Math.max(0, Math.sin(ph * TAU * 6)) : 0;
+ const [tx, ty] = at(rx * 0.68, ry * 0.62);
+ g.ellipse(tx, ty, 2 + puff * 1.2, 1.4 + puff * 1.1, S[4]);
+ // hind leg: a big thigh, a shin, a long webbed foot
+ const [hip, knee, ankle, toe] = Q.h;
+ g.tube([hip, knee], (u) => 2.8 - u * 1.2, (u, v) => (v < 0.45 ? S[3] : v < 0.85 ? S[2] : S[1]));
+ g.tube([knee, ankle], (u) => 1.6 - u * 0.5, S[2]);
+ g.tube([ankle, toe], 0.8, S[2]);
+ const fx = toe[0] - ankle[0], fy = toe[1] - ankle[1], fl = Math.hypot(fx, fy) || 1;
+ g.set(toe[0] + (fx / fl) * 1.3, toe[1] + (fy / fl) * 1.3, S[3]);
+ // near front leg
+ g.tube([sh, el, ha], (u) => 1.4 - u * 0.4, (u, v) => (v < 0.4 ? S[3] : S[2]));
+ g.set(ha[0] + 1, ha[1], S[2]);
+ // the eye bump on top of the head, a wide mouth
+ const [ex, ey] = at(rx * 0.42, -ry * 0.92);
+ g.ellipse(ex, ey, 3, 2.8, (nx, ny) => (lit(nx, ny) > 0.6 ? S[3] : S[2]));
+ // a gold eye with a bar pupil; a blink shuts it to a line
+ const blink = ph > 0.12 && ph < 0.16;
+ const eX = Math.round(ex + 0.4), eY = Math.round(ey - 0.2);
+ for (let j = -1; j <= 1; j++)
+ for (let i = -1; i <= 1; i++) g.set(eX + i, eY + j, blink ? (j === 0 ? S[0] : S[3]) : j === 0 ? S[0] : EYE);
+ if (!blink) g.set(eX + 1, eY - 1, WHITE);
+ for (let k = 0; k <= 7; k++) {
+ const [mx, my] = at(rx * 0.96 - k * 1.05, ry * 0.18 + k * 0.1);
+ g.set(mx, my, k < 6 ? S[0] : S[1]);
+ }
+ g.outline(S[0]);
+ g.draw(p);
+ // shadow on the floor, small while it's up; dust when it lands
+ const high = clamp(-(by + 6) / 11);
+ p.ellipse(0, 0.5, 9 * (1 - 0.45 * high), 1.3, 0xff141019, 0.65);
+ const d = seg(ph, 0.76, 0.9);
+ if (d > 0 && d < 1)
+ for (const side of [-1, 1]) {
+ const e = 1 - (1 - d) ** 2;
+ p.circle(side * (9 + e * 6), -1.5 - e * 2, 1.6 * (1 - d * 0.6), RAMP.dust[5], clamp(1.3 - d * 1.4));
+ }
+}
diff --git a/src/fx/critters/ghost.js b/src/fx/critters/ghost.js
new file mode 100644
index 0000000..02fb5a4
--- /dev/null
+++ b/src/fx/critters/ghost.js
@@ -0,0 +1,68 @@
+import { cycle, fract, TAU } from "../../core/index.js";
+import { Grid, shades, lit, shift } from "./_lib.js";
+
+export const meta = {
+ name: "Ghost",
+ desc: "A little sheet ghost bobs in the air, its scalloped hem rippling, nub arms waving, an O mouth and a slow blink; a cold glow around it.",
+ tags: ["critter", "ghost", "spooky", "undead", "float", "loop"],
+ size: [36, 44],
+ origin: [18, 22],
+ duration: 2,
+ loop: true,
+ fps: 30,
+ bg: "dark",
+ options: { palette: ["#1e1838", "#5a5490", "#a6a8d8", "#dfe4fa", "#ffffff"], seed: 1 },
+};
+
+export function draw(p, time, o) {
+ const t = shift(time, meta.duration, o.seed);
+ const S = shades(o.palette, 5), ph = t / meta.duration;
+ const bob = Math.sin(ph * TAU) * 2.5, lean = Math.cos(ph * TAU) * 0.08;
+ const hy = -7 + bob, R = 8.5, base = 7 + bob;
+ const g = new Grid(-18, -22, 36, 44);
+ // the sheet: a dome over a body that flares a touch, the hem in rounded lobes that roll sideways
+ g.shade(-12, hy - R - 1, 12, base + 4, (x, y) => {
+ const xs = x - (y - hy) * lean;
+ let nx, ny;
+ if (y < hy) {
+ nx = xs / R;
+ ny = (y - hy) / R;
+ if (nx * nx + ny * ny > 1) return 0;
+ } else {
+ const w = R + (y - hy) * 0.14;
+ nx = xs / w;
+ ny = 0;
+ if (Math.abs(nx) > 1) return 0;
+ const lobe = fract((xs + 10) / 6.4 + ph * 2), hem = base + 3 * Math.sqrt(Math.max(0, 1 - (2 * lobe - 1) ** 2));
+ if (y > hem) return 0;
+ if (y > hem - 1.5) return S[2];
+ }
+ const L = lit(nx, ny * 0.8 - 0.1);
+ if (L > 0.86 && y < hy - 2) return S[4];
+ if (L > 0.45) return S[3];
+ if (L > 0.2) return S[2];
+ return S[1];
+ });
+ // nub arms, waving out of step
+ for (const side of [-1, 1]) {
+ const wave = Math.sin(ph * TAU * 2 + (side > 0 ? 1.4 : 0));
+ g.ellipse(side * (R + 1.2), hy + 7 + wave * (side > 0 ? 1.5 : 0.8), 2.4, 1.6, (nx, ny) => (ny < 0 && side < 0 ? S[3] : S[2]));
+ }
+ // face: tall eyes, an O mouth, a blink once a loop
+ const blink = ph > 0.62 && ph < 0.67;
+ for (const ex of [-3, 2]) {
+ const x = Math.round(ex + 0.4 * lean * 10), y = Math.round(hy - 1);
+ if (blink) g.set(x, y + 1, S[0]), g.set(x + 1, y + 1, S[0]);
+ else for (let k = -1; k <= 1; k++) g.set(x, y + k, S[0]), g.set(x + 1, y + k, S[0]);
+ }
+ const my = Math.round(hy + 4);
+ g.set(-1, my, S[0]), g.set(0, my, S[0]), g.set(-1, my + 1, S[1]), g.set(0, my + 1, S[0]);
+ g.outline(S[0]);
+ // a few cold motes trickle off the hem and fade (drawn first, so the sheet hides them)
+ cycle(t, meta.duration, 6, o.seed, 1.2, (age, life, r) => {
+ const k = age / life, x = r.range(-8, 8) + Math.sin(age * 3 + r.next() * 6) * 1.5, y = base + 1 + age * r.range(5, 9);
+ p.dot(x, y, k < 0.4 ? S[4] : S[2], 1 - k);
+ });
+ g.draw(p);
+ p.glow(0, hy + 4, 22, S[2], 0.16);
+}
diff --git a/src/fx/critters/jellyfish.js b/src/fx/critters/jellyfish.js
new file mode 100644
index 0000000..5b46399
--- /dev/null
+++ b/src/fx/critters/jellyfish.js
@@ -0,0 +1,72 @@
+import { ease, seg, lerp, cycle, TAU } from "../../core/index.js";
+import { Grid, shades, lit, shift } from "./_lib.js";
+
+export const meta = {
+ name: "Jellyfish",
+ desc: "A see-through jellyfish pulses upward: the bell snaps narrow and relaxes wide, tentacles trail and sway behind, frilly arms ripple, a soft inner glow.",
+ tags: ["critter", "jellyfish", "sea", "water", "glow", "loop"],
+ size: [44, 64],
+ origin: [22, 20],
+ duration: 2.4,
+ loop: true,
+ fps: 30,
+ bg: "dark",
+ options: { palette: ["#1d0b2e", "#5b2276", "#a24aac", "#e88ad2", "#ffdcf6"], pulses: 2, tentacles: 6, seed: 1 },
+};
+
+export function draw(p, time, o) {
+ const t = shift(time, meta.duration, o.seed);
+ const S = shades(o.palette, 5), ph = t / meta.duration, N = o.tentacles;
+ const f = (ph * o.pulses) % 1;
+ // a pulse: a quick squeeze, then a long slow relax; it rises on the squeeze and sinks back as it relaxes
+ const squeeze = f < 0.18 ? ease.outQuad(f / 0.18) : 1 - ease.inOutSine(seg(f, 0.18, 1));
+ const rise = f < 0.3 ? ease.outCubic(f / 0.3) : 1 - ease.inOutSine(seg(f, 0.3, 1));
+ const rx = lerp(10.5, 7.5, squeeze), ry = lerp(7, 9, squeeze), cy = -4 * rise, rimY = cy + ry * 0.3;
+ // tentacles first, behind the bell: each point lags the bell, so the pulse travels down them
+ for (let i = 0; i < N; i++) {
+ const u = ((i + 0.5) / N) * 2 - 1, x0 = u * rx * 0.78, len = 24 + ((i * 7) % 5) * 2;
+ for (let s = 1; s <= len; s++) {
+ const back = ph * TAU * o.pulses - s * 0.22 + i * 1.7;
+ const spread = lerp(1, 0.55, Math.max(0, Math.sin(back)) * 0.5 + squeeze * 0.5);
+ const x = x0 * spread + Math.sin(back) * s * 0.09 + u * s * 0.06, y = rimY + s * (0.92 + squeeze * 0.06);
+ const k = s / len;
+ p.px(x, y, k > 0.7 ? S[1] : s % 3 === 0 ? S[3] : S[2]);
+ }
+ }
+ const g = new Grid(-22, -20, 44, 64);
+ // frilly oral arms in the middle, wider and shorter, rippling
+ for (const side of [-1, 1]) {
+ const pts = [];
+ for (let s = 0; s <= 14; s += 1.5) pts.push([side * 2.2 + Math.sin(ph * TAU * o.pulses - s * 0.35 + side) * (0.5 + s * 0.13), rimY + s]);
+ g.tube(pts, (u) => 1.1 * (1 - u * 0.5), (u, v) => (v < 0.5 && u < 0.6 ? S[4] : S[3]));
+ }
+ // the bell: a dome with a hollow underside, inner lobes, a beaded rim
+ g.shade(-rx - 1, cy - ry - 1, rx + 1, rimY + 2, (x, y) => {
+ const nx = x / rx, ny = (y - cy) / ry;
+ if (ny > 0.3) return 0;
+ if (nx * nx + ny * ny > 1 && ny < 0) return 0;
+ if (Math.abs(nx) > 1) return 0;
+ // the underside curves up into the bell
+ const under = 0.3 - 0.55 * (1 - nx * nx);
+ if (ny > under && ny > 0 - 0.6 * (1 - nx * nx)) {
+ if (ny > under + 0.18) return 0;
+ return S[3];
+ }
+ const L = lit(nx, Math.min(ny, 0));
+ const lobe = Math.hypot(nx * 1.6, (ny + 0.42) * 2.2);
+ if (lobe < 0.55 && lobe > 0.28) return S[4];
+ if (L > 0.88) return S[4];
+ if (L > 0.55) return S[3];
+ return S[2];
+ });
+ g.outline(S[1]);
+ g.draw(p);
+ // glow from inside, brightest on the squeeze
+ p.glow(0, cy - 1, 20, S[3], 0.18 + 0.14 * squeeze);
+ p.glow(0, cy - 2, 7, S[4], 0.2 + 0.2 * squeeze);
+ // specks of plankton drift past
+ cycle(t, meta.duration, 5, o.seed, 2.4, (age, life, r) => {
+ const x = r.range(-20, 20) + Math.sin(age * 2 + r.next() * 6), y = r.range(-16, 40) - age * 3;
+ p.dot(x, y, S[2], 0.7 * Math.sin((age / life) * Math.PI));
+ });
+}
diff --git a/src/fx/critters/slime.js b/src/fx/critters/slime.js
new file mode 100644
index 0000000..468f32b
--- /dev/null
+++ b/src/fx/critters/slime.js
@@ -0,0 +1,73 @@
+import { RAMP, seg, clamp, hex, WHITE } from "../../core/index.js";
+import { Grid, shades, lit, keys, shift } from "./_lib.js";
+
+export const meta = {
+ name: "Slime",
+ desc: "A glossy slime hops in place: it squashes down to wind up, stretches into the jump, rounds out in the air, splats on landing and wobbles back.",
+ tags: ["critter", "slime", "monster", "bounce", "loop"],
+ size: [40, 40],
+ origin: [20, 34],
+ duration: 1.4,
+ loop: true,
+ fps: 30,
+ bg: "ground",
+ options: { palette: ["#123a2c", "#1f6b3c", "#3aa64a", "#8edc5a", "#effcc4"], height: 14, seed: 1 },
+};
+
+const SHADOW = hex("#141019");
+
+// squash (-) and stretch (+) through the hop, and when it's off the ground
+const SQUASH = [[0, 0], [0.1, 0.04], [0.2, -0.06], [0.3, -0.34], [0.345, 0.3], [0.45, 0.06], [0.53, -0.03],
+ [0.64, 0.12], [0.71, 0.22], [0.745, -0.42], [0.8, 0.17], [0.86, -0.1], [0.92, 0.05], [0.97, -0.01]];
+const AIR0 = 0.335, AIR1 = 0.72;
+
+export function draw(p, time, o) {
+ const t = shift(time, meta.duration, o.seed);
+ const S = shades(o.palette, 5), ph = t / meta.duration;
+ const q = seg(ph, AIR0, AIR1), air = q > 0 && q < 1 ? 1 : 0;
+ const lift = -o.height * 4 * q * (1 - q);
+ const s = keys(ph, SQUASH);
+ const Hs = 13 * (1 + s), Ws = 10.5 * (1 - 0.5 * s), base = lift;
+ const c = 0.34, low = air ? 1.0 : 1.45;
+ // the shadow on the floor shrinks as it rises
+ const sw = Ws * (1 - 0.45 * (-lift / o.height)) + 1;
+ p.ellipse(0, 0.5, sw, 1.4, SHADOW, 0.7);
+ const g = new Grid(-20, -36, 40, 38);
+ g.shade(-Ws - 1, base - Hs - 1, Ws + 1, base, (x, y) => {
+ const v = (base - y) / Hs;
+ if (v < 0 || v > 1) return 0;
+ const nx = x / Ws, ny = (c - v) / (v > c ? 1 - c : c * low);
+ if (nx * nx + ny * ny > 1) return 0;
+ // a glossy blob: highlight up-left, the base sinking into shadow, light bouncing up into the far side
+ const sx = nx + 0.42, sy = ny + 0.5;
+ if (sx * sx + sy * sy * 1.4 < 0.035) return S[4];
+ const L = lit(nx, ny * 0.9);
+ if (v < 0.09 && !air) return S[1];
+ if (L > 0.7) return S[3];
+ if (L > 0.32) return S[2];
+ return nx > 0.35 && ny > 0.3 && L > 0.12 ? S[2] : S[1];
+ });
+ // eyes ride the squash; a blink near the start of the loop
+ const blink = ph > 0.06 && ph < 0.1, eh = Math.max(1, Math.round(3 * (1 + s * 0.8)));
+ for (const side of [-1, 1]) {
+ const ex = Math.round(side * Ws * 0.32 - (side > 0 ? 1 : 0)), ey = Math.round(base - Hs * 0.52);
+ if (blink) {
+ g.set(ex, ey + 1, S[0]), g.set(ex + 1, ey + 1, S[0]);
+ continue;
+ }
+ for (let k = 0; k < eh; k++) g.set(ex, ey + k - 1, S[0]), g.set(ex + 1, ey + k - 1, S[0]);
+ g.set(ex, ey - 1, WHITE);
+ }
+ g.outline(S[0]);
+ g.draw(p);
+ // landing dust: little puffs kicked out sideways
+ const d = seg(ph, 0.745, 0.92);
+ if (d > 0 && d < 1) {
+ const DU = RAMP.dust;
+ for (const side of [-1, 1])
+ for (let k = 0; k < 2; k++) {
+ const e = 1 - (1 - d) ** 2, x = side * (11 + e * (5 + k * 4)), y = -1.5 - e * (1.5 + k * 1.5);
+ p.circle(x, y, (k ? 1.2 : 1.8) * (1 - d * 0.6), DU[k ? 4 : 5], clamp(1.3 - d * 1.4));
+ }
+ }
+}
diff --git a/src/fx/critters/snake.js b/src/fx/critters/snake.js
new file mode 100644
index 0000000..5d4ae22
--- /dev/null
+++ b/src/fx/critters/snake.js
@@ -0,0 +1,81 @@
+import { hex, smooth, seg, fract, TAU, WHITE } from "../../core/index.js";
+import { Grid, shades, shift } from "./_lib.js";
+
+export const meta = {
+ name: "Snake",
+ desc: "A banded snake slithers in place: humps roll back along its body, the head rides high on an S-curved neck and flicks a forked tongue.",
+ tags: ["critter", "snake", "reptile", "slither", "loop", "ground"],
+ size: [64, 32],
+ origin: [30, 27],
+ duration: 1.6,
+ loop: true,
+ fps: 30,
+ bg: "ground",
+ options: { palette: ["#0f2414", "#245c24", "#46a032", "#94d24c", "#e8f2a4"], tongue: "#e8344c", seed: 1 },
+};
+
+// the spine, tail to head: along the floor with humps rolling back, then up an S-curved neck
+function spine(ph) {
+ const pts = [];
+ for (let x = -27; x <= 4; x += 0.5) {
+ const r = 0.7 + 2.5 * smooth(-27, -8, x);
+ const env = smooth(-26, -15, x) * (1 - smooth(-4, 3, x));
+ const hump = 3.4 * env * Math.max(0, Math.sin(((x + 27) / 15) * TAU + ph * TAU * 2)) ** 1.6;
+ pts.push([x, -r - hump, r]);
+ }
+ const hx = 14 + Math.sin(ph * TAU * 2 + 0.6) * 0.8, hy = -14 + Math.sin(ph * TAU * 2) * 1.2;
+ const P = [[4, -3.2], [13, -3.2], [7, -13], [hx - 2, hy + 0.5]];
+ for (let s = 0.05; s <= 1.001; s += 0.04) {
+ const u = 1 - s, w = [u * u * u, 3 * u * u * s, 3 * u * s * s, s * s * s];
+ pts.push([w.reduce((a, k, i) => a + k * P[i][0], 0), w.reduce((a, k, i) => a + k * P[i][1], 0), 3.2 - 0.7 * s]);
+ }
+ return { pts, hx, hy };
+}
+
+export function draw(p, time, o) {
+ const t = shift(time, meta.duration, o.seed);
+ const S = shades(o.palette, 5), tongue = hex(o.tongue), ph = t / meta.duration;
+ const { pts, hx, hy } = spine(ph);
+ // each spine point's normal toward the belly (right of the direction of travel)
+ const nrm = pts.map((pt, i) => {
+ const a = pts[Math.max(0, i - 1)], b = pts[Math.min(pts.length - 1, i + 1)], dx = b[0] - a[0], dy = b[1] - a[1], L = Math.hypot(dx, dy) || 1;
+ return [-dy / L, dx / L];
+ });
+ const g = new Grid(-32, -27, 64, 30);
+ g.shade(-29, -22, 20, 0, (x, y) => {
+ let best = Infinity, bi = -1;
+ for (let i = 0; i < pts.length; i++) {
+ const d = Math.hypot(x - pts[i][0], y - pts[i][1]) - pts[i][2];
+ if (d < best) (best = d), (bi = i);
+ }
+ if (best > 0) return 0;
+ const [px, py, r] = pts[bi], [nx, ny] = nrm[bi], side = ((x - px) * nx + (y - py) * ny) / r; // -1 back .. 1 belly
+ if (side > 0.45) return bi % 3 === 0 ? S[3] : S[4];
+ // bands down the back, more like saddles than stripes
+ const band = fract(bi / 10) < 0.38 && bi < pts.length - 6;
+ if (side < -0.4) return band ? S[1] : S[3];
+ return band && side < 0.1 ? S[1] : S[2];
+ });
+ // the head: a wedge tapering to a rounded snout, pale jaw, a mouth line, a brow over a beady eye
+ g.shade(hx - 5, hy - 4, hx + 7, hy + 4, (x, y) => {
+ const nx = (x - hx - 1) / 5.6, taper = 1 - 0.3 * Math.max(0, nx), ny = (y - hy) / (3.3 * taper);
+ if (nx * nx + ny * ny > 1) return 0;
+ if (ny > 0.42) return S[4];
+ if (ny > 0.12 && nx > -0.2) return Math.abs(ny - 0.27) < 0.15 ? S[1] : S[4];
+ return ny < -0.45 ? S[3] : S[2];
+ });
+ const ex = Math.round(hx + 1), ey = Math.round(hy - 1);
+ g.set(ex, ey, S[0]), g.set(ex + 1, ey, S[0]), g.set(ex + 1, ey - 1, WHITE), g.set(ex, ey - 1, S[0]);
+ g.set(ex - 1, ey - 2, S[1]), g.set(ex, ey - 2, S[1]), g.set(ex + 1, ey - 2, S[1]), g.set(ex + 2, ey - 2, S[1]);
+ g.set(Math.round(hx + 5), Math.round(hy - 1), S[1]);
+ g.outline(S[0]);
+ // the tongue flicks out twice a loop: out fast, a wiggle, back in
+ for (const t0 of [0.18, 0.62]) {
+ const k = seg(ph, t0, t0 + 0.14);
+ if (k <= 0 || k >= 1) continue;
+ const len = Math.round(6 * Math.sin(Math.PI * k)), tx = Math.round(hx + 7), ty = Math.round(hy + 0.5);
+ for (let i = 0; i < len; i++) g.set(tx + i, ty, tongue);
+ if (len >= 4) g.set(tx + len, ty - 1, tongue), g.set(tx + len, ty + 1, tongue);
+ }
+ g.draw(p);
+}
diff --git a/src/fx/critters/spider.js b/src/fx/critters/spider.js
new file mode 100644
index 0000000..72841e3
--- /dev/null
+++ b/src/fx/critters/spider.js
@@ -0,0 +1,56 @@
+import { hex, TAU, WHITE } from "../../core/index.js";
+import { Grid, shades, lit, keys, shift } from "./_lib.js";
+
+export const meta = {
+ name: "Spider",
+ desc: "A round little spider drops on its thread, bounces on the silk like a spring, then climbs back up hand over hand, legs paddling.",
+ tags: ["critter", "spider", "insect", "spooky", "hanging", "loop"],
+ size: [36, 56],
+ origin: [18, 2],
+ duration: 2.4,
+ loop: true,
+ fps: 30,
+ bg: "dark",
+ options: { palette: ["#0e0a16", "#2b1f3c", "#4f3b68", "#8a6aa8", "#d6c2ea"], mark: "#e8344c", silk: "#b4b0c6", seed: 1 },
+};
+
+// how far down the thread it hangs: a drop, springy bounces, then a climb back up in pulls
+const DROP = [[0, 14], [0.11, 33], [0.19, 26.5], [0.27, 31.5], [0.35, 28.5], [0.43, 30.5], [0.52, 29.6],
+ [0.62, 26], [0.72, 22.5], [0.82, 19], [0.92, 15.5]];
+
+export function draw(p, time, o) {
+ const t = shift(time, meta.duration, o.seed);
+ const S = shades(o.palette, 5), mark = hex(o.mark), silk = hex(o.silk), ph = t / meta.duration;
+ const y = keys(ph, DROP), climb = ph > 0.55;
+ const ay = Math.round(y), ax = 0, cy = ay + 6;
+ // silk from the ceiling
+ p.line(0, -2, ax, ay - 5, silk);
+ // legs: four a side from the head, knees up, feet out; they paddle when it climbs and splay as it falls
+ for (const side of [-1, 1])
+ for (let k = 0; k < 4; k++) {
+ const w = Math.sin(ph * TAU * (climb ? 6 : 3) + k * 1.7 + (side > 0 ? 1 : 0)) * (climb ? 1.6 : 0.8);
+ const hx = ax + side * 2, hy = cy - 1 + k * 0.9;
+ const kx = ax + side * (5.5 + k * 0.4), ky = cy - 4 + k * 2.2 + w * (k < 2 ? -1 : 1) - (ph < 0.12 ? 2 : 0);
+ const fx = ax + side * (7.5 + (k === 0 || k === 3 ? 0.5 : 1.5)), fy = cy + 1 + k * 2.8 + w;
+ p.line(hx, hy, kx, ky, S[2]);
+ p.line(kx, ky, fx, fy, S[2]);
+ p.px(kx, ky, S[3]);
+ }
+ const g = new Grid(-18, -2, 36, 56);
+ // abdomen up top, hung from the silk, with a mark
+ g.ellipse(ax, ay, 5, 5.5, (nx, ny) => {
+ const L = lit(nx, ny);
+ // an hourglass mark
+ if (ny > -0.72 && ny < 0.22 && Math.abs(nx) < 0.1 + 0.62 * Math.abs(ny + 0.25)) return mark;
+ return L > 0.75 ? S[3] : L > 0.4 ? S[2] : S[1];
+ });
+ // head below it, big shiny eyes and two fangs
+ g.ellipse(ax, cy + 0.5, 3.8, 3.2, (nx, ny) => (lit(nx, ny) > 0.6 ? S[3] : S[2]));
+ for (const side of [-1, 1]) {
+ const ex = ax + (side < 0 ? -3 : 1);
+ g.set(ex, cy - 1, WHITE), g.set(ex + 1, cy - 1, WHITE), g.set(ex, cy, WHITE), g.set(ex + 1, cy, S[0]);
+ }
+ g.set(ax - 1, cy + 4, S[3]), g.set(ax + 1, cy + 4, S[3]);
+ g.outline(S[0]);
+ g.draw(p);
+}
diff --git a/src/fx/critters/wisp.js b/src/fx/critters/wisp.js
new file mode 100644
index 0000000..684d9ec
--- /dev/null
+++ b/src/fx/critters/wisp.js
@@ -0,0 +1,63 @@
+import { cycle, tileFbm, loopNoise, TAU } from "../../core/index.js";
+import { Grid, shades, shift } from "./_lib.js";
+
+export const meta = {
+ name: "Wisp",
+ desc: "A will-o'-wisp loops a lazy figure eight: a bright flame-ball with two dot eyes, its cold fire tail licking up behind it, sparks peeling off.",
+ tags: ["critter", "wisp", "spirit", "fire", "magic", "glow", "loop"],
+ size: [44, 48],
+ origin: [22, 26],
+ duration: 2,
+ loop: true,
+ fps: 30,
+ bg: "dark",
+ options: { palette: ["#061e2a", "#0e5668", "#1ea4ae", "#6deed8", "#e8fffa"], seed: 2 },
+};
+
+const path = (ph) => [Math.sin(ph * TAU) * 8, Math.sin(ph * TAU * 2) * 4 + 2];
+
+export function draw(p, time, o) {
+ const t = shift(time, meta.duration, o.seed);
+ const S = shades(o.palette, 5), ph = t / meta.duration, D = meta.duration;
+ const [hx, hy] = path(ph);
+ // the tail: a flame that always licks upward, dragged back against the way it's flying, thinning out
+ const vx = Math.cos(ph * TAU) * 8, vy = Math.cos(ph * TAU * 2) * 8, vl = Math.hypot(vx, vy) || 1;
+ const nodes = [];
+ for (let i = 0; i < 10; i++) {
+ const r = 5.2 * (1 - i / 11.5) + 0.5 * loopNoise(ph * 2 + i * 0.07, 0.6, o.seed);
+ const wob = Math.sin(ph * TAU * 3 - i * 0.7) * i * 0.18;
+ nodes.push([hx - (vx / vl) * i * 1.1 + wob, hy - (vy / vl) * i * 0.6 - i * 1.5, r, 1 - i * 0.07]);
+ }
+ const g = new Grid(-22, -26, 44, 48);
+ g.shade(-21, -25, 21, 21, (x, y) => {
+ let heat = 0;
+ for (const [nx, ny, r, w] of nodes) {
+ const d = Math.hypot(x - nx, (y - ny) * 0.9) / r;
+ if (d < 1) heat = Math.max(heat, (1 - d) * w);
+ }
+ if (heat <= 0) return 0;
+ heat += tileFbm(x * 0.35, y * 0.3 + ph * 10, 0, 10, o.seed, 2) * 0.22;
+ if (heat > 0.62) return S[4];
+ if (heat > 0.38) return S[3];
+ if (heat > 0.18) return S[2];
+ if (heat > 0.05) return S[1];
+ return 0;
+ });
+ // a solid round head over the flame, with a bright core and two eyes that look where it's going
+ g.ellipse(hx, hy, 4.6, 4.4, (nx, ny) => (nx * nx + ny * ny < 0.35 ? S[4] : ny > 0.3 || nx > 0.55 ? S[2] : S[3]));
+ const look = Math.cos(ph * TAU) > 0 ? 1 : -1, ex = Math.round(hx + look * 1.2), ey = Math.round(hy - 0.5);
+ const blink = (ph > 0.3 && ph < 0.33) || (ph > 0.8 && ph < 0.83);
+ g.set(ex - 2, ey, S[0]), g.set(ex + 1, ey, S[0]);
+ if (!blink) g.set(ex - 2, ey - 1, S[0]), g.set(ex + 1, ey - 1, S[0]);
+ g.outline(S[0]);
+ g.draw(p);
+ // sparks shed from the tail
+ cycle(t, D, 7, o.seed + 1, (r) => r.range(0.4, 0.8), (age, life, r) => {
+ const k = age / life, [sx, sy] = path((t - age) / D - 0.1);
+ const x = sx + r.range(-3, 3) + Math.sin(age * 6 + r.next() * 6), y = sy - 8 - age * r.range(10, 18);
+ p.px(x, y, k < 0.4 ? S[4] : k < 0.75 ? S[3] : S[2]);
+ p.light(x, y, S[3], 0.4 * (1 - k));
+ });
+ p.glow(hx, hy, 20, S[3], 0.3);
+ p.glow(hx, hy, 7, S[4], 0.3);
+}
diff --git a/src/fx/explosions/_lib.js b/src/fx/explosions/_lib.js
new file mode 100644
index 0000000..00da5f6
--- /dev/null
+++ b/src/fx/explosions/_lib.js
@@ -0,0 +1,189 @@
+// Shared by the explosions (and the fire effects that blow up): billows of fire that cool into smoke,
+// sparks, bouncing debris, ground rings and flashes. Not an effect (the leading _ keeps the tools away).
+
+import { at, burst, fly, flyV, seg, ease, clamp, noise2, TAU, WHITE } from "../../core/index.js";
+export { fit, pool } from "../fire/_lib.js";
+
+/** A blast's fire ramp from an 8-step palette: the cool edge up to a white-hot core. */
+export const hot = (F) => [F[2], F[3], F[4], F[5], F[6], F[7], WHITE];
+
+/**
+ * Billows: puffs { x, y, r, v } (centre, radius, strength 0..1) painted as one lumpy mass. At each pixel the
+ * strongest puff decides: color(v, lit, x, y, out, puff) picks the color (lit > 0 faces the top-left light)
+ * and may set out.a / out.k. Puffs are bucketed by row, so a cloud of fifty stays fast.
+ */
+export function billow(p, list, color) {
+ let x0 = Infinity, y0 = Infinity, x1 = -Infinity, y1 = -Infinity;
+ const P = [];
+ for (const f of list) {
+ if (!(f.r > 0.6 && f.v > 0)) continue;
+ P.push(f);
+ x0 = Math.min(x0, f.x - f.r); x1 = Math.max(x1, f.x + f.r);
+ y0 = Math.min(y0, f.y - f.r); y1 = Math.max(y1, f.y + f.r);
+ }
+ if (!P.length) return;
+ const Y0 = Math.floor(y0), rows = Array.from({ length: Math.ceil(y1) - Y0 + 2 }, () => []);
+ for (const f of P) for (let r = Math.floor(f.y - f.r) - Y0, e = Math.ceil(f.y + f.r) - Y0; r <= e; r++) rows[r].push(f);
+ p.shade(x0, y0, x1, y1, (x, y, out) => {
+ const row = rows[Math.floor(y) - Y0];
+ if (!row) return;
+ let best = 0, lit = 0, bf = null;
+ for (let i = 0; i < row.length; i++) {
+ const f = row[i], dx = x - f.x, dy = y - f.y, r2 = f.r * f.r, d2 = dx * dx + dy * dy;
+ if (d2 >= r2) continue;
+ const v = (1 - d2 / r2) * f.v;
+ if (v > best) (best = v), (lit = (-dx - dy * 1.4) / f.r), (bf = f);
+ }
+ if (best > 0) return color(best, lit, x, y, out, bf);
+ });
+}
+
+/**
+ * Sparks: streaks along their velocity, thrown from (x, y) at angle a +- spread, falling and cooling
+ * through cols [hot, warm, cool]. t0 delays them; with a floor (a y) they go out when they reach it.
+ */
+export function sparks(p, t, n, seed, cols, o = {}) {
+ const { x = 0, y = 0, a = -Math.PI / 2, spread = Math.PI, sp = [60, 120], life = [0.3, 0.55], g = 160 } = o;
+ const { drag = 2.5, len = 0.025, up = 0, k = 0.6, t0 = 0, glow = cols[1], floor = Infinity } = o;
+ const age = t - t0;
+ if (age < 0) return;
+ burst(n, seed, (r) => {
+ const ang = a + r.range(-spread, spread), s = r.range(sp[0], sp[1]), L = r.range(life[0], life[1]);
+ if (age > L) return;
+ const q = age / L, vx0 = Math.cos(ang) * s, vy0 = Math.sin(ang) * s - up;
+ const [px, py] = fly(x, y, vx0, vy0, age, g, drag), [vx, vy] = flyV(vx0, vy0, age, g, drag);
+ if (py > floor) return;
+ p.line(px, py, px - vx * len, py - vy * len, q < 0.3 ? cols[0] : q < 0.6 ? cols[1] : cols[2]);
+ if (k) p.light(px, py, glow, k * (1 - q));
+ });
+}
+
+/**
+ * Where a thrown thing is after t seconds: ballistic from (x, y) at (vx, vy) under gravity g, bouncing on the
+ * floor line (e: bounce, f: skid) up to `hops` times, then resting. Returns [x, y, rested].
+ */
+export function hop(x, y, vx, vy, t, g, floor = 0, e = 0.35, f = 0.55, hops = 2) {
+ for (let h = 0; ; h++) {
+ const A = 0.5 * g, C = y - floor, disc = vy * vy - 4 * A * C;
+ const tl = disc < 0 ? Infinity : (-vy + Math.sqrt(disc)) / (2 * A);
+ if (t < tl) return [x + vx * t, y + vy * t + A * t * t, false];
+ x += vx * tl; y = floor; t -= tl;
+ vy = -(vy + g * tl) * e; vx *= f;
+ if (h >= hops || vy > -12) return [x, floor, true];
+ }
+}
+
+/**
+ * Debris: chunks thrown from (x, y) at angle a +- spread. With a floor they land, hop and rest; they fade
+ * out over the last fifth of their life. cols: [lit, shade]. size: [min, max] px.
+ */
+export function debris(p, t, n, seed, cols, o = {}) {
+ const { x = 0, y = 0, a = -Math.PI / 2, spread = 1.2, sp = [50, 95], g = 260, life = [0.6, 0.9], size = [1, 2] } = o;
+ const { floor = null, t0 = 0, drag = 0 } = o;
+ const age = t - t0;
+ if (age < 0) return;
+ burst(n, seed, (r) => {
+ const ang = a + r.range(-spread, spread), s = r.range(sp[0], sp[1]), L = r.range(life[0], life[1]);
+ const sz = Math.min(size[1], Math.floor(r.range(size[0], size[1] + 1))), spin = r.range(8, 16) * r.sign();
+ if (age > L) return;
+ const vx = Math.cos(ang) * s, vy = Math.sin(ang) * s;
+ const [px, py, rest] = floor === null ? [...fly(x, y, vx, vy, age, g, drag), false] : hop(x, y, vx, vy, age, g, floor);
+ const al = 1 - seg(age, L * 0.8, L), turn = rest ? 0 : Math.floor(age * spin) & 1;
+ const w = sz + (sz > 1 && turn ? 1 : 0), h = sz > 1 && !turn ? sz + 1 : sz;
+ const top = floor !== null && rest ? floor - h : py - h / 2;
+ p.rect(Math.round(px - w / 2), Math.round(top), w, h, cols[1], al);
+ if (sz > 1) p.rect(Math.round(px - w / 2), Math.round(top), w - 1, 1, cols[0], al);
+ });
+}
+
+/** A 1 px ellipse outline (rings lying on the floor), alpha a. */
+export function oval(p, x, y, rx, ry, c, a = 1) {
+ const n = Math.max(12, Math.ceil((rx + ry) * 3.2));
+ let lx = NaN, ly = NaN;
+ for (let i = 0; i < n; i++) {
+ const ang = (i / n) * TAU, px = Math.round(x + Math.cos(ang) * rx - 0.5), py = Math.round(y + Math.sin(ang) * ry - 0.5);
+ if (px === lx && py === ly) continue;
+ p.dot(px, py, c, a);
+ lx = px; ly = py;
+ }
+}
+
+/** Light hugging an ellipse (a ground shockwave's glow), falling off over width w. */
+export function glowOval(p, x, y, rx, ry, w, c, k) {
+ if (k <= 0.004 || rx < 1) return;
+ p.shade(x - rx - w, y - ry - w, x + rx + w, y + ry + w, (px, py, out) => {
+ const dx = (px - x) / rx, dy = (py - y) / ry, d = Math.abs(Math.sqrt(dx * dx + dy * dy) - 1) * rx / w;
+ if (d >= 1) return;
+ out.l = c;
+ out.k = (1 - d) * (1 - d) * k;
+ });
+}
+
+/** The hero frame: a solid white disc and a big glow, for `dur` seconds from t0. */
+export function flash(p, t, x, y, t0, dur, r, glowC, { R = 48, k = 0.9, grow = 40 } = {}) {
+ const age = t - t0;
+ if (age < 0 || age >= dur) return;
+ p.circle(x, y, r + grow * age, WHITE);
+ p.glow(x, y, R, glowC, k);
+}
+
+/** A thin shock ring racing from r0 to r1 over [t0, t1], dithering away; sy < 1 squashes it onto the floor. */
+export function shock(p, t, x, y, t0, t1, r0, r1, c, glowC, { sy = 1, k = 0.3 } = {}) {
+ const s = seg(t, t0, t1);
+ if (s <= 0 || s >= 1) return;
+ // solid for the first frames, then it dithers away
+ const r = r0 + (r1 - r0) * ease.outCubic(s), a = s < 0.4 ? 1 : 1 - ((s - 0.4) / 0.6) * 0.95;
+ if (sy === 1) {
+ p.ring(x, y, r, 1, c, a);
+ p.glowRing(x, y, r, 4, glowC, k * (1 - s));
+ } else {
+ oval(p, x, y, r, r * sy, c, a);
+ glowOval(p, x, y, r, r * sy, 4, glowC, k * (1 - s));
+ }
+}
+
+
+/**
+ * A blast's puffs, the small explosion's recipe made reusable: n puffs thrown from (x, y) at t0 toward angle
+ * a +- spread, each a ball of fire that cools from the edge and a ball of smoke that takes over and rises.
+ * Pushes into o.fire / o.smoke (pass the same lists to gather several blasts) and returns them.
+ * floor: keep puffs above this y (ground blasts).
+ */
+export function blast(t, seed, o = {}) {
+ const { x = 0, y = 0, t0 = 0, n = 12, reach = [5, 13], size = [5, 8], life = [0.75, 1.05], a = 0, spread = Math.PI } = o;
+ const { squash = 0.7, lift = 26, delay = 0.07, core = 2, grow = 0.8, rise = 16, floor = null, k = 1 } = o;
+ const fire = o.fire ?? [], smoke = o.smoke ?? [];
+ burst(n, seed, (r, i) => {
+ const ang = a + ((i + 0.5) / n - 0.5) * 2 * spread + r.range(-0.35, 0.35) * (spread / Math.PI);
+ const reach0 = (i < core ? r.range(0, 3) : r.range(reach[0], reach[1])) * k;
+ const age = t - t0 - (i < core ? 0 : r.range(0.01, delay)), L = r.range(life[0], life[1]);
+ const r0 = r.range(size[0], size[1]) * k;
+ if (age < 0 || age > L) return;
+ const q = age / L, e = ease.outCubic(seg(age, 0, 0.28));
+ let px = x + Math.cos(ang) * reach0 * e, py = y + Math.sin(ang) * reach0 * e * squash - age * age * lift * k;
+ const rr = r0 * (0.5 + 0.7 * e);
+ if (floor !== null) py = Math.min(py, floor - rr * 0.45);
+ fire.push({ x: px, y: py, r: rr * (1 - 0.45 * seg(q, 0.15, 0.6)), v: 1 - seg(q, 0.05, 0.62) });
+ smoke.push({ x: px, y: py - q * q * rise * k, r: rr * (1.05 + grow * q), v: seg(q, 0.12, 0.4) * (1 - seg(q, 0.62, 1)) });
+ });
+ return { fire, smoke };
+}
+
+/**
+ * Paint blast puffs the small explosion's way: smoke behind, shaded from the top-left, then fire in front
+ * with a little light. FIRE: the fire ramp (hot(F)), SM: a smoke ramp (7 steps), tone shifts the smoke
+ * darker (0) or lighter.
+ */
+export function paintBlast(p, { fire, smoke }, FIRE, SM, seed, { tone = 0.25, k = 0.25 } = {}) {
+ const S5 = SM.slice(1, 6);
+ billow(p, smoke, (v, lit, x, y, out) => {
+ if (v < 0.06) return;
+ out.a = clamp(v * 4);
+ return at(S5, tone + lit * 0.3 + v * 0.35 + noise2(x * 0.4, y * 0.4, seed) * 0.12);
+ });
+ billow(p, fire, (v, lit, x, y, out) => {
+ if (v < 0.08) return;
+ out.k = v * k;
+ return at(FIRE, v * 0.95 + lit * 0.12 + noise2(x * 0.5, y * 0.5, seed + 1) * 0.1);
+ });
+}
diff --git a/src/fx/explosions/barrel-explosion.js b/src/fx/explosions/barrel-explosion.js
new file mode 100644
index 0000000..c1c9e55
--- /dev/null
+++ b/src/fx/explosions/barrel-explosion.js
@@ -0,0 +1,85 @@
+import { PAL, RAMP, ramp, seg, ease, burst, WHITE, hex } from "../../core/index.js";
+import { fit, hot, blast, paintBlast, sparks, hop, shock, flash, pool } from "./_lib.js";
+import { tongue, flames } from "../fire/_lib.js";
+
+export const meta = {
+ name: "Barrel explosion",
+ desc: "An explosive barrel shudders and spits flame, then blows: a white flash, a tall fireball under black smoke, staves and the lid flying, fuel left burning.",
+ tags: ["explosion", "barrel", "prop", "fire", "debris", "ground", "one-shot"],
+ size: [128, 124],
+ origin: [64, 110],
+ duration: 2.5,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ options: { palette: PAL.fire, seed: 32 },
+};
+
+const RED = [hex("#2a0c10"), hex("#6a1418"), hex("#a82424"), hex("#d84a3a")];
+const METAL = [hex("#24222c"), hex("#4a4856"), hex("#8a8898")];
+const HAZ = [hex("#1a1418"), hex("#f0c020")], CHAR = [hex("#0e0a0c"), hex("#201618")];
+const BOOM = 0.42;
+
+function barrel(p, dx, bulge) {
+ for (let y = -16; y < 0; y++) {
+ const mid = y > -13 && y < -3 ? bulge : 0;
+ for (let x = -6 - mid; x <= 5 + mid; x++) {
+ const e = x - mid * Math.sign(x + 0.5);
+ let c = e <= -6 || e >= 5 ? RED[0] : e === -5 ? RED[2] : e <= -2 ? RED[3] : e <= 2 ? RED[2] : RED[1];
+ if (y === -16 || y === -12 || y === -2) c = e <= -6 || e >= 5 ? METAL[0] : e <= -3 ? METAL[2] : METAL[1];
+ else if (y >= -10 && y <= -7 && e > -6 && e < 5) c = (x + y + 40) % 4 < 2 ? HAZ[1] : HAZ[0];
+ p.px(x + dx, y, c);
+ }
+ }
+ for (let x = -4; x <= 3; x++) p.px(x + dx, -17, x < -1 ? METAL[2] : METAL[1]);
+}
+
+export function draw(p, t, o) {
+ const F = fit(ramp(o.palette)), SM = RAMP.smoke, S = o.seed, FIRE = hot(F);
+ if (t < BOOM) {
+ // it shudders, swells, and spits a jet of flame from a split seam
+ const tense = seg(t, 0.1, BOOM), f = Math.floor(t * 30);
+ const dx = tense > 0 ? (f % 2 ? 1 : -1) * (tense > 0.5 ? 1 : f % 4 < 2 ? 1 : 0) : 0;
+ barrel(p, dx, tense > 0.6 ? 1 : 0);
+ if (tense > 0.25) {
+ const k = seg(t, 0.2, 0.3);
+ for (let i = 0; i < 6 * k; i++) p.px(dx + 7 + i, -9 - (i > 3 ? 1 : 0), i < 2 ? WHITE : i < 4 ? F[6] : F[4]);
+ p.glow(dx + 8, -9, 10, F[5], 0.5 * k);
+ }
+ return;
+ }
+ const age = t - BOOM;
+ const sc = seg(age, 0.03, 0.15) * (1 - seg(t, 2.0, 2.5));
+ if (sc > 0) p.ellipse(0, 0.5, 22, 2.6, (d) => (d > 0.6 ? CHAR[1] : CHAR[0]), sc);
+ // fuel left burning where the barrel stood, dying down
+ const burn = seg(age, 0.3, 0.5) * (1 - ease.inQuad(seg(t, 1.3, 2.2)));
+ if (burn > 0.05) {
+ const T = [-9, -4, 1, 6, 10].map((x, i) => tongue(x, 0, 3 + (i % 2), (8 + (i % 3) * 4) * burn, t / 0.6, S + i * 9, { beat: 3, sway: 1.6, pulse: 0.3 }));
+ flames(p, T, { F, ph: t, seed: S, box: [-15, -26, 15, 1], scroll: 14 });
+ }
+ // a tall fireball under a heavy black cloud
+ const L = blast(age, S, { y: -10, n: 15, reach: [8, 18], size: [8, 11], life: [0.95, 1.3], a: -Math.PI / 2, spread: 1.85, squash: 0.75, lift: 28, rise: 24, floor: 0 });
+ paintBlast(p, L, FIRE, SM, S, { tone: 0.02 });
+ // staves tumbling out, landing flat; the lid shot straight up, flipping like a coin
+ burst(8, S + 1, (r, i) => {
+ const a = -Math.PI / 2 + (i % 2 ? 1 : -1) * r.range(0.35, 1.2), sp = r.range(75, 115), life = r.range(1.3, 1.8);
+ if (age > life) return;
+ const [x, y, rest] = hop(0, -8, Math.cos(a) * sp, Math.sin(a) * sp, age, 380, 0, 0.3, 0.45, 1);
+ const rot = rest ? 0 : age * r.range(10, 18) * r.sign(), cx = Math.cos(rot) * 3, cy = Math.sin(rot) * 3;
+ const al = 1 - seg(age, life * 0.8, life), yy = rest ? -1 : y;
+ p.beam(x - cx, yy - cy, x + cx, yy + cy, 2, (u, v) => (v > 0.5 ? RED[1] : RED[3]), al);
+ });
+ {
+ const [x, y, rest] = hop(0, -16, 16, -165, age, 340, 0, 0.25, 0.4, 1), life = 1.9;
+ if (age < life) {
+ const ry = rest ? 1 : Math.max(0.6, 4.5 * Math.abs(Math.cos(age * 14)));
+ p.ellipse(x, rest ? -1 : y, 4.5, ry, (d) => (d > 0.72 ? METAL[2] : METAL[1]), 1 - seg(age, life * 0.8, life));
+ }
+ }
+ sparks(p, age, 22, S + 2, [F[7], F[5], F[3]], { floor: 0, y: -10, a: -Math.PI / 2, spread: 1.6, sp: [90, 170], life: [0.35, 0.7], g: 200 });
+ flash(p, age, 0, -10, 0, 0.08, 11, F[6], { R: 40, grow: 80 });
+ shock(p, age, 0, 0, 0, 0.35, 8, 50, F[5], F[4], { sy: 0.15 });
+ const lt = 1 - seg(age, 0, 0.8);
+ p.glow(0, -20, 46, F[5], 0.5 * lt * lt);
+ pool(p, 0, 0, 44, 6, F[4], 0.5 * Math.max(lt, burn * 0.6));
+}
diff --git a/src/fx/explosions/big-explosion.js b/src/fx/explosions/big-explosion.js
new file mode 100644
index 0000000..d1cffd6
--- /dev/null
+++ b/src/fx/explosions/big-explosion.js
@@ -0,0 +1,70 @@
+import { PAL, RAMP, ramp, seg, burst, stream, fly, TAU, hex } from "../../core/index.js";
+import { fit, hot, blast, paintBlast, sparks, debris, hop, shock, flash, pool } from "./_lib.js";
+
+export const meta = {
+ name: "Big explosion",
+ desc: "A three-stage blast: a white flash, a fireball that swells twice more as it climbs into a rising column of smoke, heavy debris trailing smoke, a shockwave.",
+ tags: ["explosion", "fire", "smoke", "debris", "big", "ground", "one-shot"],
+ size: [136, 148],
+ origin: [68, 128],
+ duration: 2.8,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ options: { palette: PAL.fire, size: 1, seed: 21 },
+};
+
+const ROCK = [hex("#5a4648"), hex("#2e2228"), hex("#1a1218")];
+const CHAR = [hex("#100c10"), hex("#211619")];
+
+export function draw(p, t, o) {
+ const F = fit(ramp(o.palette)), SM = RAMP.smoke, S = o.seed, k = o.size, FIRE = hot(F);
+ const L = { fire: [], smoke: [] };
+ // the scorch left on the floor
+ const sc = seg(t, 0.05, 0.2) * (1 - seg(t, 2.2, 2.8));
+ if (sc > 0) p.ellipse(0, 0.5, 30 * k, 3, (d) => (d > 0.7 ? CHAR[1] : CHAR[0]), sc);
+ // stage one sits on the floor; stages two and three burst out of it higher up, a beat apart
+ blast(t, S, { ...L, y: -12 * k, n: 14, reach: [8, 20], size: [8, 12], life: [1.0, 1.4], a: -Math.PI / 2, spread: Math.PI, squash: 0.65, lift: 20, rise: 34, floor: 0, k });
+ blast(t, S + 1, { ...L, t0: 0.13, x: 12 * k, y: -28 * k, n: 8, reach: [5, 12], size: [7, 10], life: [0.9, 1.25], a: -Math.PI / 2, spread: 2.2, lift: 24, rise: 34, k });
+ blast(t, S + 2, { ...L, t0: 0.26, x: -9 * k, y: -40 * k, n: 8, reach: [5, 12], size: [7, 10], life: [0.9, 1.25], a: -Math.PI / 2, spread: 2.2, lift: 24, rise: 34, k });
+ // the column: hot puffs that keep boiling up out of the blast, slowing as they climb, swelling into smoke
+ stream(t, 0.12, 1.45, 24, S + 3, (g) => g.range(1.1, 1.3), (age, life, r) => {
+ const born = t - age, thin = 1 - 0.5 * seg(born, 0.4, 1.45); // later puffs are smaller: the column narrows
+ const q = age / life, [cx, cy] = fly(r.range(-6, 6) * k * thin, -18 * k, r.range(-10, 10), -r.range(88, 114) * k, age, 0, 1.1);
+ const rad = (r.range(5, 7) + 9 * Math.sqrt(q)) * k * thin;
+ L.smoke.push({ x: cx + Math.sin(age * 3 + r.next() * TAU) * 2, y: cy, r: rad, v: seg(q, 0.05, 0.2) * (1 - seg(q, 0.55, 1)) });
+ if (age < 0.3 && born < 0.45) L.fire.push({ x: cx, y: cy, r: rad * 0.8, v: (1 - age / 0.3) * (1 - born / 0.45) });
+ });
+ // heavy chunks arc out trailing smoke, thud down and rest
+ burst(7, S + 5, (r) => {
+ const a = -Math.PI / 2 + r.range(-0.9, 0.9), sp = r.range(85, 120) * k, life = r.range(1.4, 1.9), sz = Math.round(r.range(2.5, 4));
+ if (t > life) return;
+ const vx = Math.cos(a) * sp, vy = Math.sin(a) * sp, at = (tt) => hop(0, -10 * k, vx, vy, tt, 300, 0, 0.25, 0.4, 1);
+ for (let j = 7; j >= 1; j--) {
+ const tt = t - j * 0.04;
+ if (tt < 0.02) continue;
+ const [x, y, rest] = at(tt), rad = (2.8 - j * 0.3) * (1 - seg(t, 0.5, 0.9));
+ if (!rest && rad > 0.6) p.circle(x, y, rad, j < 3 ? SM[4] : SM[3]);
+ }
+ const [x, y, rest] = at(t), al = 1 - seg(t, life * 0.8, life), x0 = Math.round(x - sz / 2), y0 = rest ? -sz : Math.round(y - sz / 2);
+ p.rect(x0, y0, sz, sz, ROCK[1], al);
+ p.rect(x0, y0, sz - 1, 1, ROCK[0], al);
+ p.rect(x0 + sz - 1, y0 + 1, 1, sz - 1, ROCK[2], al);
+ if (!rest) p.light(x, y, F[4], 0.4 * (1 - seg(t, 0.2, 0.8)));
+ });
+ debris(p, t, 18, S + 8, [ROCK[0], ROCK[1]], { y: -10 * k, sp: [60, 115], spread: 1, g: 340, life: [1.1, 1.5], size: [1, 2], floor: 0 });
+ paintBlast(p, L, FIRE, SM, S, { tone: 0.18 });
+ sparks(p, t, 26, S + 7, [F[7], F[5], F[3]], { floor: 0, y: -14 * k, a: -Math.PI / 2, spread: 1.6, sp: [90, 170], life: [0.4, 0.8], g: 180, up: 20 });
+ // the hero frame, the shockwave in the air and along the floor
+ flash(p, t, 0, -14 * k, 0, 0.08, 14 * k, F[6], { R: 46, grow: 90 });
+ // a dome of shock racing up and out over the blast
+ const sw = seg(t, 0.03, 0.36);
+ if (sw > 0 && sw < 1) {
+ const r = 14 + 46 * k * (1 - (1 - sw) ** 3);
+ p.arc(0, -2, r, 1, Math.PI, Math.PI * 2, F[7], sw < 0.4 ? 1 : 1 - (sw - 0.4) / 0.6);
+ }
+ shock(p, t, 0, 0, 0, 0.42, 10, 62 * k, F[6], F[5], { sy: 0.14 });
+ const lt = 1 - seg(t, 0, 0.9);
+ p.glow(0, -24 * k, 56, F[5], 0.55 * lt * lt);
+ pool(p, 0, 0, 50, 6, F[4], 0.5 * lt);
+}
diff --git a/src/fx/explosions/cartoon-pow.js b/src/fx/explosions/cartoon-pow.js
new file mode 100644
index 0000000..8cc2d3e
--- /dev/null
+++ b/src/fx/explosions/cartoon-pow.js
@@ -0,0 +1,60 @@
+import { ramp, seg, ease, rng, burst, star, TAU } from "../../core/index.js";
+import { fit } from "./_lib.js";
+
+export const meta = {
+ name: "Cartoon POW",
+ desc: "A comic-book hit: a jagged burst star slams in with a shake and boiling edges, POW! drops in letter by letter, action lines fly, then it all snaps away.",
+ tags: ["explosion", "cartoon", "comic", "text", "impact", "ui", "one-shot"],
+ size: [92, 68],
+ origin: [46, 34],
+ duration: 0.9,
+ loop: false,
+ fps: 30,
+ bg: "dark",
+ options: { palette: ["#1a0810", "#5a0c1c", "#b81c28", "#f0461e", "#ff9a26", "#ffd84a", "#fff6c4"], text: "POW!", seed: 26 },
+};
+
+// a jagged burst: n points with uneven tips, re-drawn every other frame so the outline boils
+function burstStar(cx, cy, r0, r1, n, seed, s) {
+ const r = rng(seed), pts = [];
+ for (let i = 0; i < n * 2; i++) {
+ const a = -Math.PI / 2 + (i * Math.PI) / n + r.range(-0.08, 0.08), rr = (i % 2 ? r0 * r.range(0.85, 1.1) : r1 * r.range(0.82, 1.08)) * s;
+ pts.push([cx + Math.cos(a) * rr * 1.18, cy + Math.sin(a) * rr]);
+ }
+ return pts;
+}
+
+export function draw(p, t, o) {
+ const P = fit(ramp(o.palette), 7), S = o.seed;
+ const pop = ease.outBack(seg(t, 0, 0.12), 2.2), out = ease.inBack(seg(t, 0.7, 0.86), 2.2), s = pop * (1 - out);
+ if (s <= 0.02) return;
+ // a hard shake for the first few frames
+ const f = Math.floor(t * 30), shake = t < 0.2 ? [[2, -1], [-2, 1], [1, 2], [-1, -1], [1, 0], [0, 1]][f % 6] : [0, 0];
+ const cx = shake[0], cy = shake[1], boil = S + Math.floor(t * 15);
+ const outer = burstStar(cx, cy, 12, 22, 11, boil, s), inner = burstStar(cx, cy, 8.5, 15.5, 11, boil + 99, s);
+ // a dark outline, the red outer burst, the yellow inner burst
+ p.poly(outer.map(([x, y]) => [cx + (x - cx) * 1.1, cy + (y - cy) * 1.12]), P[0]);
+ p.poly(outer, (x, y) => (y - cy > 6 * s ? P[2] : P[3]));
+ p.poly(inner, (x, y) => (y - cy < -5 * s ? P[6] : y - cy < 3 * s ? P[5] : P[4]));
+ // action lines flying out past the burst
+ const al = seg(t, 0.04, 0.26);
+ if (al > 0 && al < 1)
+ burst(10, S + 1, (r, i) => {
+ const a = (i / 10) * TAU + r.range(-0.15, 0.15), r0 = 25 + 8 * ease.outCubic(al), len = 6 * (1 - al) + 1;
+ p.line(cx + Math.cos(a) * r0 * 1.15, cy + Math.sin(a) * r0 * 0.85, cx + Math.cos(a) * (r0 + len) * 1.15, cy + Math.sin(a) * (r0 + len) * 0.85, P[6]);
+ });
+ // POW! drops in letter by letter with a bounce
+ if (out < 0.5) {
+ const str = o.text, total = p.measure(str, { font: "big", scale: 2 })[0] + (str.length - 1) * 2;
+ let x = cx - Math.round(total / 2);
+ [...str].forEach((ch, i) => {
+ const k = seg(t, 0.06 + i * 0.05, 0.24 + i * 0.05), w = p.measure(ch, { font: "big", scale: 2 })[0];
+ if (k > 0) {
+ const dy = Math.round(-9 * (1 - ease.outBack(k, 2.4))) + (i % 2 ? 1 : -1);
+ p.text(ch, x, cy - 7 + dy, (gx, gy) => (gy < 3 ? P[6] : P[5]), { font: "big", scale: 2, outline: P[0], shadow: P[2] });
+ }
+ x += w + 2;
+ });
+ }
+ p.glow(cx, cy, 34 * s, P[4], 0.3 * (1 - seg(t, 0.1, 0.8)));
+}
diff --git a/src/fx/explosions/chain-explosions.js b/src/fx/explosions/chain-explosions.js
new file mode 100644
index 0000000..9843097
--- /dev/null
+++ b/src/fx/explosions/chain-explosions.js
@@ -0,0 +1,44 @@
+import { PAL, RAMP, ramp, seg, rng, hex } from "../../core/index.js";
+import { fit, hot, blast, paintBlast, sparks, debris, shock, flash } from "./_lib.js";
+
+export const meta = {
+ name: "Chain explosions",
+ desc: "A string of small blasts marching right along the ground, each a beat after the last and a little bigger, flashes popping, smoke stacking up behind.",
+ tags: ["explosion", "chain", "sequence", "barrage", "ground", "directional", "one-shot"],
+ size: [160, 76],
+ origin: [28, 64],
+ duration: 1.7,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ options: { palette: PAL.fire, count: 5, spacing: 25, beat: 0.12, seed: 27 },
+};
+
+const CHAR = [hex("#100c10"), hex("#221a1c")];
+
+export function draw(p, t, o) {
+ const F = fit(ramp(o.palette)), SM = RAMP.smoke, DU = RAMP.dust, S = o.seed, FIRE = hot(F), n = o.count;
+ const L = { fire: [], smoke: [] }, spots = [];
+ for (let i = 0; i < n; i++) {
+ const r = rng(S, i), x = i * o.spacing + r.range(-3, 3), t0 = i * o.beat + r.range(-0.015, 0.015), k = 0.62 + (0.38 * i) / Math.max(1, n - 1);
+ spots.push({ x, t0, k });
+ const sc = seg(t, t0 + 0.03, t0 + 0.12) * (1 - seg(t, 1.25 + i * 0.06, 1.55 + i * 0.03));
+ if (sc > 0) p.ellipse(x, 0.5, 9 * k, 2, (d) => (d > 0.6 ? CHAR[1] : CHAR[0]), sc);
+ blast(t, S + i * 7, { ...L, t0, x, y: -6 * k, n: 7, reach: [3, 10], size: [5.5, 8], life: [0.55, 0.85], a: -Math.PI / 2, spread: 2.2, squash: 0.7, lift: 30, rise: 22, floor: 0, k });
+ }
+ for (let i = 0; i < n; i++) {
+ const { x, t0, k } = spots[i];
+ debris(p, t, 6, S + 40 + i, [DU[3], DU[1]], { x, y: -3, t0, sp: [45, 85], spread: 0.9, g: 340, life: [0.5, 0.8], size: [1, 2], floor: 0 });
+ }
+ paintBlast(p, L, FIRE, SM, S);
+ for (let i = 0; i < n; i++) {
+ const { x, t0, k } = spots[i], age = t - t0;
+ sparks(p, t, 8, S + 60 + i, [F[7], F[5], F[3]], { floor: 0, x, y: -6 * k, t0, a: -Math.PI / 2, spread: 1.4, sp: [60, 115], life: [0.25, 0.45], g: 200 });
+ flash(p, t, x, -6 * k, t0, 0.05, 6 * k, F[6], { R: 24, grow: 50 });
+ shock(p, t, x, 0, t0, t0 + 0.25, 4, 22 * k, F[6], F[5], { sy: 0.2, k: 0.25 });
+ if (age > 0) {
+ const lt = 1 - seg(age, 0, 0.45);
+ p.glow(x, -10 * k, 26 * k, F[5], 0.4 * lt * lt);
+ }
+ }
+}
diff --git a/src/fx/explosions/dirt-explosion.js b/src/fx/explosions/dirt-explosion.js
new file mode 100644
index 0000000..2a2201f
--- /dev/null
+++ b/src/fx/explosions/dirt-explosion.js
@@ -0,0 +1,56 @@
+import { PAL, RAMP, ramp, at, seg, ease, clamp, burst, fly, noise2, WHITE, hex } from "../../core/index.js";
+import { fit, billow, debris } from "./_lib.js";
+
+export const meta = {
+ name: "Dirt explosion",
+ desc: "A ground blast: a flash of fire, a fountain of dirt and dust thrown up in a V, clods arcing out and thudding down, a crater left in the floor.",
+ tags: ["explosion", "dirt", "dust", "ground", "impact", "one-shot"],
+ size: [108, 92],
+ origin: [54, 78],
+ duration: 1.9,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ options: { palette: PAL.dust, seed: 22 },
+};
+
+const HOLE = [hex("#0e0b0c"), hex("#1d1614")];
+
+export function draw(p, t, o) {
+ const D = fit(ramp(o.palette), 7), E = RAMP.earth, Fi = RAMP.fire, S = o.seed;
+ const DUST = D.slice(1, 7);
+ // the crater: a dark bowl with a lip of thrown-up dirt, filling back in by dither at the end
+ const cr = seg(t, 0.02, 0.12) * (1 - seg(t, 1.4, 1.9));
+ if (cr > 0) {
+ p.ellipse(0, 0.5, 15, 2.6, (d, a) => (d > 0.75 ? (a < 0 ? D[4] : D[2]) : d > 0.45 ? HOLE[1] : HOLE[0]), cr);
+ p.px(-15, -1, D[4], cr), p.px(14, -1, D[3], cr);
+ }
+ // the plume: dust thrown up in a V, slowing, spreading and settling, plus a skirt rolling along the floor
+ const puffs = [];
+ burst(34, S, (r, i) => {
+ const skirt = i < 8, side = i % 2 ? 1 : -1;
+ const a = skirt ? -Math.PI / 2 + side * r.range(1.2, 1.45) : -Math.PI / 2 + ((i % 13) / 12 - 0.5) * 1.1 + r.range(-0.08, 0.08);
+ const sp = skirt ? r.range(60, 100) : r.range(40, 165), life = r.range(1.0, 1.45), born = r.range(0, 0.06);
+ const age = t - born;
+ if (age < 0 || age > life) return;
+ const q = age / life;
+ let [x, y] = fly(0, -3, Math.cos(a) * sp, Math.sin(a) * sp, age, skirt ? 0 : 50, skirt ? 3.2 : 2.3);
+ const rad = (skirt ? r.range(3.5, 5) : r.range(4.5, 7)) * (0.55 + 1.0 * ease.outCubic(seg(age, 0, 0.5)));
+ y = Math.min(y, -rad * 0.4);
+ puffs.push({ x, y, r: rad, v: (1 - q * q) * seg(age, 0, 0.04) });
+ });
+ billow(p, puffs, (v, lit, x, y, out) => {
+ if (v < 0.08) return;
+ out.a = clamp(v * 3.5);
+ return at(DUST, 0.15 + lit * 0.32 + v * 0.42 + noise2(x * 0.45, y * 0.45, S) * 0.12);
+ });
+ // clods arcing out and thudding down, and grit raining after them
+ debris(p, t, 12, S + 1, [E[4], E[2]], { y: -3, a: -Math.PI / 2, spread: 0.8, sp: [80, 122], g: 360, life: [1.1, 1.6], size: [2, 3], floor: 0 });
+ debris(p, t, 22, S + 2, [E[3], E[2]], { y: -3, a: -Math.PI / 2, spread: 0.6, sp: [70, 128], g: 360, life: [0.8, 1.3], size: [1, 1], floor: 0 });
+ // a quick flash of fire at the heart of the blast
+ if (t < 0.1) {
+ const q = t / 0.1;
+ p.circle(0, -4, 4 + 6 * q, (d) => (d < 0.4 && q < 0.5 ? WHITE : d < 0.7 ? Fi[6] : Fi[4]), 1 - q * 0.7);
+ p.glow(0, -6, 34, Fi[5], 0.7 * (1 - q));
+ }
+}
diff --git a/src/fx/explosions/dust-cloud.js b/src/fx/explosions/dust-cloud.js
new file mode 100644
index 0000000..9dac744
--- /dev/null
+++ b/src/fx/explosions/dust-cloud.js
@@ -0,0 +1,46 @@
+import { PAL, RAMP, ramp, at, seg, ease, clamp, burst, fly, noise2 } from "../../core/index.js";
+import { fit, billow, hop } from "./_lib.js";
+
+export const meta = {
+ name: "Dust cloud",
+ desc: "A cloud of dust kicked up along the ground: puffs roll out to both sides, slow, swell and drift, then settle back onto the floor and thin away.",
+ tags: ["dust", "smoke", "landing", "stomp", "ground", "one-shot"],
+ size: [124, 44],
+ origin: [62, 38],
+ duration: 1.9,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ options: { palette: PAL.dust, seed: 25 },
+};
+
+export function draw(p, t, o) {
+ const D = fit(ramp(o.palette), 7), E = RAMP.earth, S = o.seed, DUST = D.slice(1, 7);
+ // puffs rolling out along the floor; each carries how far it has rolled, to turn its texture
+ const puffs = [];
+ burst(26, S, (r, i) => {
+ // most roll out to the sides; a few slow ones billow up in the middle and keep the cloud whole
+ const side = i % 2 ? 1 : -1, mid = i >= 20, born = r.range(0, 0.08), life = r.range(1.2, 1.75), age = t - born;
+ if (age < 0 || age > life) return;
+ const q = age / life, v0 = mid ? r.range(5, 25) : r.range(30, 115), [x] = fly(side * r.range(0, 4), 0, side * v0, 0, age, 0, 2.2);
+ const rad = (mid ? r.range(5, 7) : r.range(3.5, 6.5)) * (0.5 + 1.0 * ease.outCubic(seg(age, 0, 0.8)));
+ const settle = seg(q, 0.55, 1);
+ const y = -rad * (0.75 - 0.35 * settle) - age * (mid ? r.range(8, 14) : r.range(3, 8)) * (1 - settle);
+ puffs.push({ x, y, r: rad * (1 - 0.25 * settle), v: (1 - settle) * seg(age, 0, 0.05), roll: x / rad, id: i });
+ });
+ billow(p, puffs, (v, lit, x, y, out, f) => {
+ if (v < 0.08) return;
+ out.a = clamp(v * 3.2);
+ // the texture turns with the puff, so it reads as rolling rather than sliding
+ const dx = x - f.x, dy = y - f.y, c = Math.cos(f.roll), s = Math.sin(f.roll);
+ const n = noise2((dx * c - dy * s) * 0.55 + f.id * 9.1, (dx * s + dy * c) * 0.55, S);
+ return at(DUST, 0.12 + lit * 0.3 + v * 0.38 + n * 0.16);
+ });
+ // grit skittering along the floor
+ burst(12, S + 1, (r, i) => {
+ const side = i % 2 ? 1 : -1, life = r.range(0.6, 1.1);
+ if (t > life) return;
+ const [x, y, rest] = hop(side * 2, -1, side * r.range(40, 95), -r.range(25, 60), t, 320, 0, 0.35, 0.6, 2);
+ p.px(x, rest ? -1 : y - 1, i % 3 ? E[3] : E[4]);
+ });
+}
diff --git a/src/fx/explosions/firework-burst.js b/src/fx/explosions/firework-burst.js
new file mode 100644
index 0000000..5a7730c
--- /dev/null
+++ b/src/fx/explosions/firework-burst.js
@@ -0,0 +1,44 @@
+import { PAL, RAMP, ramp, seg, burst, fly, rand, TAU, WHITE } from "../../core/index.js";
+import { fit } from "./_lib.js";
+
+export const meta = {
+ name: "Firework burst",
+ desc: "A shell bursts into a sphere of coloured stars around a gold core: they streak out, slow, droop on fading trails and crackle as they fall and wink out.",
+ tags: ["firework", "celebration", "sparks", "sky", "one-shot"],
+ size: [108, 120],
+ origin: [54, 48],
+ duration: 2.4,
+ loop: false,
+ fps: 30,
+ bg: "sky",
+ options: { palette: PAL.neon, count: 60, seed: 28 },
+};
+
+// one shell: stars thrown over a sphere, so seen from the side the ones flying at us look slower
+function shell(p, t, n, seed, speed, life, cols, trail) {
+ burst(n, seed, (r, i) => {
+ const z = r.range(-1, 1), a = r.range(0, TAU), s = Math.sqrt(1 - z * z), sp = speed * r.range(0.9, 1.06);
+ const vx = Math.cos(a) * s * sp, vy = Math.sin(a) * s * sp, L = r.range(life[0], life[1]);
+ if (t > L) return;
+ const q = t / L, pos = (tt) => fly(0, 0, vx, vy, tt, 36, 2.3);
+ const [x, y] = pos(t), [tx, ty] = pos(Math.max(0, t - trail * (1 - q * 0.6)));
+ if (q < 0.85) p.line(tx, ty, x, y, (u) => (u < 0.45 ? cols[0] : cols[1]));
+ // late in life the stars crackle: blinking on and off, a few flaring white
+ const blink = q > 0.5 ? rand(i, Math.floor(t * 18), seed) : 1;
+ if (blink < 0.35) return;
+ p.px(x, y, q < 0.25 || blink > 0.93 ? WHITE : q < 0.7 ? cols[3] : cols[2]);
+ p.light(x, y, cols[2], 0.55 * (1 - q));
+ });
+}
+
+export function draw(p, t, o) {
+ const C = fit(ramp(o.palette)), G = RAMP.gold, S = o.seed;
+ if (t < 0.08) {
+ p.circle(0, 0, 3 + 30 * t, WHITE);
+ p.glow(0, 0, 34, C[5], 0.8 * (1 - t / 0.08));
+ }
+ shell(p, t, o.count, S, 92, [1.6, 2.3], [C[2], C[3], C[5], C[6]], 0.16);
+ shell(p, t, 22, S + 1, 38, [1.1, 1.6], [G[2], G[3], G[5], G[6]], 0.12);
+ const L = 1 - seg(t, 0, 1.4);
+ p.glow(0, 4, 46, C[4], 0.35 * L * L);
+}
diff --git a/src/fx/explosions/firework-rocket.js b/src/fx/explosions/firework-rocket.js
new file mode 100644
index 0000000..cd7db48
--- /dev/null
+++ b/src/fx/explosions/firework-rocket.js
@@ -0,0 +1,85 @@
+import { PAL, RAMP, ramp, seg, ease, burst, stream, fly, rand, TAU, WHITE, hex } from "../../core/index.js";
+import { fit } from "./_lib.js";
+
+export const meta = {
+ name: "Firework rocket",
+ desc: "A rocket fizzes off the ground and climbs on a sparkling trail, slows at the top, and bursts into a palm of drooping golden fronds that glitter as they fall.",
+ tags: ["firework", "rocket", "celebration", "sky", "one-shot"],
+ size: [96, 144],
+ origin: [48, 138],
+ duration: 2.9,
+ loop: false,
+ fps: 30,
+ bg: "sky",
+ options: { palette: PAL.gold, height: 100, arms: 11, seed: 29 },
+};
+
+const SHELL = [hex("#7a1c24"), hex("#d23a3a"), hex("#ff8a6a")], STICK = hex("#6a4a2a");
+const UP = 0.1, TOP = 0.95;
+
+export function draw(p, t, o) {
+ const G = fit(ramp(o.palette)), SM = RAMP.smoke, S = o.seed, H = o.height;
+ const pos = (tt) => {
+ const k = ease.outQuad(seg(tt, UP, TOP));
+ return [Math.sin(tt * 9) * 1.2 * (1 - k) + k * 2, -H * k];
+ };
+ // a few dim puffs of smoke hang along the climb
+ stream(t, UP, TOP, 22, S + 1, (g) => g.range(0.4, 0.7), (age, life, r) => {
+ const [x, y] = pos(t - age), q = age / life, rad = (1 - q) * r.range(1.2, 2.2), sy = y - 3 + age * 6;
+ if (rad > 0.6 && sy + rad < 0) p.circle(x + r.range(-1, 1), sy, rad, q < 0.5 ? SM[3] : SM[2]);
+ });
+ // ignition: a fountain of sparks at the foot
+ burst(10, S + 2, (r) => {
+ const L = r.range(0.15, 0.3), age = t - r.range(0, 0.08);
+ if (age < 0 || age > L) return;
+ const [x, y] = fly(0, -1, r.range(-40, 40), -r.range(30, 70), age, 300);
+ if (y < 0) p.px(x, y, age / L < 0.5 ? G[6] : G[4]);
+ });
+ // the climb: sparks shed from the tail, falling and twinkling out
+ stream(t, UP, TOP, 70, S + 3, (g) => g.range(0.3, 0.6), (age, life, r, i) => {
+ const [x0, y0] = pos(t - age), q = age / life, [x, y] = fly(x0, y0 - 4, r.range(-14, 14), r.range(0, 20), age, 70, 1);
+ if (y > -1 || (q > 0.5 && rand(i, Math.floor(t * 20), S) < 0.4)) return;
+ p.px(x, y, q < 0.3 ? WHITE : q < 0.65 ? G[5] : G[3]);
+ });
+ if (t < TOP) {
+ // the rocket: (x, y) is the foot of its stick; a red shell with a white nose, the exhaust under the shell
+ const [px, py] = pos(t), x = Math.round(px), y = Math.round(py);
+ p.rect(x, y - 10, 2, 5, SHELL[1]);
+ p.px(x, y - 10, SHELL[2]), p.px(x + 1, y - 6, SHELL[0]), p.px(x, y - 11, WHITE);
+ p.line(x + 1, y - 5, x + 1, y - 1, STICK);
+ if (t > UP) p.px(x, y - 5, Math.floor(t * 30) % 2 ? WHITE : G[6]), p.px(x, y - 4, G[5]);
+ p.glow(x, y - 5, 9, G[5], t > UP ? 0.5 : 0.2);
+ return;
+ }
+ // the burst: a palm of heavy fronds that arc out, droop, and leave glittering trails
+ const age = t - TOP, [bx, by0] = pos(TOP), by = by0 - 8;
+ if (age < 0.07) {
+ p.circle(bx, by, 3 + 30 * age, WHITE);
+ p.glow(bx, by, 32, G[5], 0.8);
+ }
+ burst(o.arms, S + 4, (r, i) => {
+ const a = (i / o.arms) * TAU + r.range(-0.2, 0.2), z = r.range(0.55, 1), sp = r.range(62, 74) * z, L = r.range(1.45, 1.85);
+ if (age > L) return;
+ const vx = Math.cos(a) * sp, vy = Math.sin(a) * sp * 0.9 - 8, q = age / L;
+ // the frond: points along its own path, newest brightest; its tail burns away first
+ for (let j = 13; j >= 0; j--) {
+ const tt = age - j * 0.045;
+ if (tt < 0) continue;
+ const fade = j / 13 + q * 0.9;
+ if (fade > 1.15) continue;
+ const [x, y] = fly(bx, by, vx, vy, tt, 58, 1.7);
+ const glit = rand(i, j, Math.floor(t * 15)) > 0.86;
+ p.px(x, y, j === 0 && q < 0.6 ? WHITE : glit ? G[7] : fade < 0.45 ? G[5] : fade < 0.8 ? G[4] : G[2]);
+ }
+ const [hx, hy] = fly(bx, by, vx, vy, age, 58, 1.7);
+ p.light(hx, hy, G[5], 0.5 * (1 - q));
+ });
+ // glitter dropping off the fronds
+ stream(t, TOP + 0.3, TOP + 1.25, 26, S + 5, (g) => g.range(0.4, 0.6), (ga, life, r) => {
+ const born = t - ga, a = r.range(0, TAU), d = r.range(14, 30) * seg(born - TOP, 0, 0.6);
+ const x = bx + Math.cos(a) * d, y = by + Math.sin(a) * d * 0.8 + 12 * seg(born - TOP, 0, 1.4) + ga * ga * 40;
+ if (rand(r.next() * 999, Math.floor(t * 20)) > 0.45) p.px(x, y, ga / life < 0.5 ? G[6] : G[4]);
+ });
+ const L = 1 - seg(age, 0, 1.2);
+ p.glow(bx, by + 8, 40, G[4], 0.35 * L * L);
+}
diff --git a/src/fx/explosions/gas-explosion.js b/src/fx/explosions/gas-explosion.js
new file mode 100644
index 0000000..d64ec3a
--- /dev/null
+++ b/src/fx/explosions/gas-explosion.js
@@ -0,0 +1,68 @@
+import { PAL, RAMP, ramp, at, seg, ease, clamp, noise2, WHITE } from "../../core/index.js";
+import { fit, hot, billow, sparks, pool } from "./_lib.js";
+
+export const meta = {
+ name: "Gas explosion",
+ desc: "A spark finds the gas: a whoosh of fire rolls out sideways along the floor, a curling front racing right, burning out behind itself into rising smoke.",
+ tags: ["explosion", "gas", "whoosh", "fire", "ground", "directional", "one-shot"],
+ size: [144, 80],
+ origin: [12, 70],
+ duration: 1.7,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ options: { palette: PAL.fire, reach: 96, seed: 34 },
+};
+
+export function draw(p, t, o) {
+ const F = fit(ramp(o.palette)), SM = RAMP.smoke, S = o.seed, R = o.reach, FIRE = hot(F);
+ const T0 = 0.06, T1 = 0.62; // the front sets off, and arrives
+ // the spark that sets it off
+ if (t < T0 + 0.02) {
+ p.px(0, -2, WHITE), p.px(1, -3, F[6]), p.px(-1, -3, F[6]);
+ p.glow(0, -2, 10, F[5], 0.6);
+ }
+ // puffs along the path: each catches as the front reaches it, rolls on a little, rises, cools to smoke
+ const fire = [], smoke = [];
+ // two rows of puffs: a low rolling carpet, and a taller, later crest that curls over at the front
+ const N = 26;
+ for (let i = 0; i < N; i++) {
+ const crest = i % 2 === 1, u = (Math.floor(i / 2) + (crest ? 0.75 : 0.25)) / (N / 2), x0 = u * R;
+ const born = T0 + (T1 - T0) * (1 - Math.cbrt(1 - u)) + (crest ? 0.03 : 0), age = t - born;
+ if (age < 0) continue;
+ const r = rng2(S, i), L = r[0] * 0.3 + (crest ? 0.8 : 0.65), q = age / L;
+ if (q >= 1) continue;
+ const big = (crest ? 4.5 : 3.5) + 4 * u + r[1] * 1.5, rad = big * (0.45 + 0.75 * ease.outCubic(seg(age, 0, 0.25)));
+ const x = x0 + 9 * ease.outCubic(seg(age, 0, 0.5)) * (0.6 + u), y = -rad * (crest ? 1.5 : 0.7) - age * age * (crest ? 22 : 12);
+ fire.push({ x, y, r: rad * (1 - 0.4 * seg(q, 0.12, 0.5)), v: 1 - seg(q, 0.04, 0.45), roll: x / Math.max(3, rad), id: i });
+ smoke.push({ x: x + q * 3, y: y - q * q * 12, r: rad * (1.1 + 0.5 * q), v: seg(q, 0.12, 0.35) * (1 - seg(q, 0.6, 1)), roll: x / Math.max(3, rad), id: i });
+ }
+ const tex = (x, y, f) => {
+ const dx = x - f.x, dy = y - f.y, c = Math.cos(f.roll), s = Math.sin(f.roll);
+ return noise2((dx * c - dy * s) * 0.45 + f.id * 7.3, (dx * s + dy * c) * 0.45, S);
+ };
+ billow(p, smoke, (v, lit, x, y, out, f) => {
+ if (v < 0.06) return;
+ out.a = clamp(v * 4);
+ return at(SM.slice(1, 6), 0.2 + lit * 0.3 + v * 0.35 + tex(x, y, f) * 0.14);
+ });
+ // the fire rolls: its texture turns with the distance each puff has travelled
+ billow(p, fire, (v, lit, x, y, out, f) => {
+ if (v < 0.08) return;
+ out.k = v * 0.25;
+ return at(FIRE, v * 0.95 + lit * 0.12 + tex(x, y, f) * 0.16);
+ });
+ // sparks flung ahead of the front
+ const front = R * ease.outCubic(seg(t, T0, T1));
+ sparks(p, t, 16, S + 2, [F[7], F[5], F[3]], { floor: 0, x: 6, y: -4, t0: T0, a: -0.35, spread: 0.45, sp: [120, 190], life: [0.35, 0.6], g: 160, drag: 2 });
+ const L = 1 - seg(t, T1 - 0.1, T1 + 0.6);
+ if (t > T0) {
+ p.glow(front * 0.8, -10, 40, F[5], 0.4 * L);
+ pool(p, front * 0.55, 0, front * 0.6 + 14, 5, F[4], 0.45 * L);
+ }
+}
+
+function rng2(seed, i) {
+ const a = Math.sin(seed * 12.9898 + i * 78.233) * 43758.5453, b = Math.sin(seed * 39.3468 + i * 11.135) * 24634.6345;
+ return [a - Math.floor(a), b - Math.floor(b)];
+}
diff --git a/src/fx/explosions/grenade.js b/src/fx/explosions/grenade.js
new file mode 100644
index 0000000..7357ba0
--- /dev/null
+++ b/src/fx/explosions/grenade.js
@@ -0,0 +1,70 @@
+import { PAL, RAMP, ramp, seg, ease, lerp, burst, fly, TAU, WHITE, hex } from "../../core/index.js";
+import { fit, hot, blast, paintBlast, sparks, debris, hop, shock, flash, pool } from "./_lib.js";
+
+export const meta = {
+ name: "Grenade",
+ desc: "A grenade is lobbed in, bounces once, rolls to a stop and fizzes, then goes off: a flash, a squat fireball, shrapnel streaks, dust and a scorch.",
+ tags: ["explosion", "grenade", "bounce", "weapon", "ground", "one-shot"],
+ size: [104, 80],
+ origin: [56, 68],
+ duration: 2.3,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ options: { palette: PAL.fire, seed: 23 },
+};
+
+const BODY = [hex("#1c2414"), hex("#3a4a22"), hex("#5c7034"), hex("#8aa050")];
+const CAP = [hex("#3a3a46"), hex("#8a8a9a")];
+const SHRAP = hex("#d8d4e0"), CHAR = [hex("#100c10"), hex("#221a1c")];
+const BOOM = 1.1, REST = 0.78;
+
+export function draw(p, t, o) {
+ const F = fit(ramp(o.palette)), SM = RAMP.smoke, DU = RAMP.dust, S = o.seed, FIRE = hot(F);
+ if (t < BOOM) {
+ // lobbed in from the left, one bounce, a short roll to rest; a fizzing fuse and a shiver before it goes
+ const [hx, hy] = hop(-46, -32, 72, 32, t, 300, -3, 0.45, 0.6, 1);
+ const roll = seg(t, REST, REST + 0.12), x = hx + 2 * ease.outCubic(roll), shiver = t > BOOM - 0.1 ? (Math.floor(t * 60) % 2 ? 1 : -1) : 0;
+ const a = lerp(-TAU - 0.9, 0.3, ease.outCubic(seg(t, 0, REST + 0.12))), dx = Math.sin(a), dy = -Math.cos(a);
+ const cx = x + shiver * 0.6, cy = hy;
+ p.beam(cx - dx, cy - dy, cx + dx * 0.8, cy + dy * 0.8, 5.4, (u, v) => {
+ const groove = (u * 3.2) % 1 < 0.22;
+ return v > 0.78 ? BODY[0] : groove ? BODY[1] : v < 0.35 && u > 0.4 ? BODY[3] : BODY[2];
+ });
+ p.beam(cx + dx * 2.4, cy + dy * 2.4, cx + dx * 3.6, cy + dy * 3.6, 2.4, (u, v) => (v < 0.4 ? CAP[1] : CAP[0]));
+ if (t > REST - 0.1) {
+ const sx = cx + dx * 4.6, sy = cy + dy * 4.6;
+ burst(3, S + Math.floor(t * 30), (r) => p.px(sx + r.range(-1.5, 1.5), sy + r.range(-1.5, 0.5), r.next() < 0.5 ? F[7] : F[5]));
+ p.light(sx, sy, F[5], 0.6);
+ }
+ return;
+ }
+ const age = t - BOOM;
+ // scorch on the floor
+ const sc = seg(age, 0.03, 0.15) * (1 - seg(t, 1.8, 2.3));
+ if (sc > 0) p.ellipse(0, 0.5, 18, 2.5, (d) => (d > 0.65 ? CHAR[1] : CHAR[0]), sc);
+ // a squat fireball that hugs the floor and cools into smoke
+ const L = blast(age, S, { y: -6, n: 12, reach: [5, 15], size: [6, 9], life: [0.7, 1.0], a: -Math.PI / 2, spread: 1.9, squash: 0.7, lift: 20, rise: 20, floor: 0 });
+ // a skirt of dust thrown along the floor
+ burst(8, S + 1, (r, i) => {
+ const side = i % 2 ? 1 : -1, L2 = r.range(0.6, 0.9);
+ if (age > L2) return;
+ const q = age / L2, [x] = fly(0, 0, side * r.range(50, 90), 0, age, 0, 3.4), rad = r.range(3, 4.5) * (0.6 + q * 0.8);
+ L.smoke.push({ x, y: -rad * 0.6 - age * 6, r: rad, v: (1 - q) * seg(age, 0, 0.05) });
+ });
+ debris(p, age, 12, S + 2, [DU[3], DU[1]], { y: -3, sp: [60, 110], spread: 1.2, g: 340, life: [0.7, 1.1], size: [1, 2], floor: 0 });
+ paintBlast(p, L, FIRE, SM, S);
+ // shrapnel: hard, straight, fast streaks
+ burst(14, S + 3, (r) => {
+ const a = -Math.PI / 2 + r.range(-1.45, 1.45), sp = r.range(220, 320), L3 = r.range(0.1, 0.18);
+ if (age > L3) return;
+ const d = sp * age, x = Math.cos(a) * d, y = -5 + Math.sin(a) * d, len = 4 + (1 - age / L3) * 4;
+ p.line(x, y, x - Math.cos(a) * len, y - Math.sin(a) * len, (u) => (u < 0.3 ? WHITE : SHRAP));
+ });
+ sparks(p, age, 12, S + 4, [F[7], F[5], F[3]], { floor: 0, y: -5, a: -Math.PI / 2, spread: 1.5, sp: [80, 140], life: [0.3, 0.5], g: 200 });
+ flash(p, age, 0, -8, 0, 0.07, 8, F[6], { R: 30, grow: 70 });
+ shock(p, age, 0, 0, 0, 0.3, 6, 36, F[6], F[5], { sy: 0.16 });
+ const lt = 1 - seg(age, 0, 0.6);
+ p.glow(0, -12, 34, F[5], 0.45 * lt * lt);
+ pool(p, 0, 0, 34, 5, F[4], 0.45 * lt);
+}
diff --git a/src/fx/explosions/implosion.js b/src/fx/explosions/implosion.js
new file mode 100644
index 0000000..1394dd0
--- /dev/null
+++ b/src/fx/explosions/implosion.js
@@ -0,0 +1,65 @@
+import { ramp, seg, ease, burst, clamp, TAU, WHITE } from "../../core/index.js";
+import { fit } from "./_lib.js";
+
+export const meta = {
+ name: "Implosion",
+ desc: "Everything is sucked in: streaks and rings rush toward a darkening core that crushes down to a point, a beat of stillness, then a tiny pop.",
+ tags: ["implosion", "vortex", "magic", "void", "collapse", "one-shot"],
+ size: [84, 84],
+ origin: [42, 42],
+ duration: 1.4,
+ loop: false,
+ fps: 30,
+ bg: "dark",
+ options: { palette: ["#07050f", "#1a1030", "#33265e", "#574ea0", "#928cdc", "#d4d0ff", "#ffffff"], radius: 34, seed: 30 },
+};
+
+const POP = 1.05;
+
+export function draw(p, t, o) {
+ const C = fit(ramp(o.palette), 7), S = o.seed, R = o.radius;
+ // streaks rushing in, faster and faster, each pointing back the way it came
+ burst(60, S, (r) => {
+ const a = r.range(0, TAU), arrive = r.range(0.45, 0.97), born = arrive - r.range(0.35, 0.55), r0 = R * r.range(0.7, 1.08);
+ const q = seg(t, born, arrive);
+ if (q <= 0 || q >= 1) return;
+ const d = r0 * (1 - ease.inCubic(q)), len = 2 + 12 * q * q, dx = Math.cos(a), dy = Math.sin(a);
+ p.line(dx * d, dy * d, dx * (d + len), dy * (d + len), (u) => (u < 0.25 ? C[5] : u < 0.6 ? C[4] : C[3]), (u) => (q < 0.15 ? q / 0.15 : 1) * (1 - u * 0.5));
+ if (q > 0.6) p.light(dx * d, dy * d, C[4], 0.4);
+ });
+ // rings closing in, one after another, firming up as they tighten
+ for (let i = 0; i < 3; i++) {
+ const q = seg(t, 0.08 + i * 0.2, 0.62 + i * 0.16);
+ if (q <= 0 || q >= 1) continue;
+ const rr = R * (1 - ease.inQuad(q)) + 1;
+ p.ring(0, 0, rr, 1, q > 0.7 ? C[5] : q > 0.35 ? C[4] : C[3]);
+ }
+ // the core: a void with a bright rim that swells, then is crushed to a point
+ const grow = ease.outCubic(seg(t, 0, 0.45)), crush = ease.inQuad(seg(t, 0.62, 0.98));
+ const rc = 8 * grow * (1 - crush * 0.9);
+ if (t < 0.98 && rc > 0.8) {
+ p.circle(0, 0, rc + 1, (d) => (d > 0.82 ? (crush > 0.5 ? C[6] : C[5]) : d > 0.6 ? C[3] : C[0]));
+ p.glow(0, 0, 14 + 10 * crush, C[4], 0.25 + 0.35 * crush);
+ }
+ // a beat of stillness: one point of light
+ if (t >= 0.98 && t < POP) {
+ p.px(0, 0, WHITE);
+ p.light(0, 0, C[5], 0.8);
+ }
+ // the pop: small and quick
+ const age = t - POP;
+ if (age >= 0) {
+ if (age < 0.07) p.circle(0, 0, 2 + 30 * age, WHITE), p.glow(0, 0, 16, C[5], 0.8);
+ const rq = seg(age, 0, 0.2);
+ if (rq > 0 && rq < 1) p.ring(0, 0, 2 + 12 * ease.outCubic(rq), 1, rq < 0.5 ? C[6] : C[4], rq < 0.6 ? 1 : 1 - (rq - 0.6) / 0.4);
+ burst(8, S + 1, (r, i) => {
+ const a = (i / 8) * TAU + r.range(-0.3, 0.3), L = r.range(0.15, 0.3);
+ if (age > L) return;
+ const d = 3 + r.range(30, 50) * age * (1 - age / L / 2);
+ p.px(Math.cos(a) * d, Math.sin(a) * d, age / L < 0.5 ? WHITE : C[5]);
+ });
+ }
+ // the pull darkens the air a little around the core while it lasts
+ const pull = clamp(t / 0.3) * (1 - seg(t, 0.95, 1));
+ p.glow(0, 0, R + 4, C[3], 0.2 * pull);
+}
diff --git a/src/fx/explosions/mine-blast.js b/src/fx/explosions/mine-blast.js
new file mode 100644
index 0000000..2859b7a
--- /dev/null
+++ b/src/fx/explosions/mine-blast.js
@@ -0,0 +1,76 @@
+import { PAL, RAMP, ramp, at, seg, ease, clamp, burst, fly, noise2, WHITE, hex } from "../../core/index.js";
+import { fit, hot, billow, paintBlast, debris, shock, pool } from "./_lib.js";
+
+export const meta = {
+ name: "Mine blast",
+ desc: "A buried mine blinks red twice and arms, then fires a narrow jet of fire and dirt straight up; clods rain back down and a crater smokes in the floor.",
+ tags: ["explosion", "mine", "trap", "dirt", "ground", "one-shot"],
+ size: [88, 124],
+ origin: [44, 116],
+ duration: 1.9,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ options: { palette: PAL.fire, height: 88, seed: 33 },
+};
+
+const SHELL = [hex("#1c201c"), hex("#3c463a"), hex("#66725e"), hex("#98a48a")];
+const LAMP = [hex("#5a1018"), hex("#ff3a3a"), hex("#ffc0b0")], HOLE = [hex("#0e0b0c"), hex("#1e1714")];
+const BOOM = 0.45;
+
+export function draw(p, t, o) {
+ const F = fit(ramp(o.palette)), SM = RAMP.smoke, DU = RAMP.dust, E = RAMP.earth, S = o.seed, H = o.height, FIRE = hot(F);
+ if (t < BOOM) {
+ // the mine: a squat dome half sunk in the floor; its lamp blinks, blinks, then holds
+ p.shade(-6, -4, 6, 1, (x, y) => {
+ const d = Math.hypot(x / 6, (y + 0.5) / 3.6);
+ if (d > 1 || y > 0) return;
+ return d > 0.82 ? SHELL[0] : y < -2.5 ? SHELL[3] : x < 0 ? SHELL[2] : SHELL[1];
+ });
+ const on = (t > 0.06 && t < 0.11) || (t > 0.22 && t < 0.27) || t > 0.36;
+ p.px(0, -4, on ? LAMP[1] : LAMP[0]);
+ if (on) p.px(0, -5, LAMP[2]), p.glow(0, -4, 10, LAMP[1], 0.55);
+ return;
+ }
+ const age = t - BOOM;
+ // the crater: dark, with a lip of dirt, filling back in at the end
+ const cr = seg(age, 0.02, 0.1) * (1 - seg(t, 1.45, 1.9));
+ if (cr > 0) p.ellipse(0, 0.5, 11, 2.4, (d, a) => (d > 0.72 ? (a < 0 ? DU[4] : DU[2]) : d > 0.4 ? HOLE[1] : HOLE[0]), cr);
+ // the jet: a narrow column of puffs fired straight up, cooling into a column of smoke
+ const reach = ease.outExpo(seg(age, 0, 0.16)), fire = [], smoke = [];
+ burst(13, S, (r, i) => {
+ const h = (6 + (i / 12) * (H - 10)) * reach, L = r.range(0.6, 0.95) - i * 0.015, q = clamp(age / L);
+ if (q >= 1) return;
+ const x = r.range(-1.5, 1.5) + Math.sin(i * 1.7 + age * 6) * (1 + q * 2), y = -h - age * age * 20;
+ const rad = (r.range(4, 6) - i * 0.12) * (0.7 + 0.6 * ease.outCubic(seg(age, 0, 0.3)));
+ fire.push({ x, y, r: rad * (1 - 0.4 * seg(q, 0.1, 0.6)), v: 1 - seg(q, 0.02, 0.5) });
+ smoke.push({ x: x + q * r.range(-4, 4), y: y - q * 10, r: rad * (1.1 + 0.7 * q), v: seg(q, 0.1, 0.3) * (1 - seg(q, 0.6, 1)) });
+ });
+ // a skirt of dust thrown out low along the floor
+ const dust = [];
+ burst(8, S + 1, (r, i) => {
+ const side = i % 2 ? 1 : -1, L = r.range(0.7, 1.1), q = age / L;
+ if (q >= 1) return;
+ const [x] = fly(0, 0, side * r.range(45, 85), 0, age, 0, 3.2), rad = r.range(3, 4.5) * (0.6 + q);
+ dust.push({ x, y: -rad * 0.6 - age * 5, r: rad, v: (1 - q) * seg(age, 0, 0.05) });
+ });
+ billow(p, dust, (v, lit, x, y, out) => {
+ if (v < 0.08) return;
+ out.a = clamp(v * 3);
+ return at(DU.slice(1, 6), 0.2 + lit * 0.3 + v * 0.35 + noise2(x * 0.5, y * 0.5, S) * 0.12);
+ });
+ paintBlast(p, { fire, smoke }, FIRE, SM, S, { tone: 0.1 });
+ // the white-hot core of the jet for the first frames
+ if (age < 0.1) {
+ const top = -(H * 0.85) * ease.outExpo(seg(age, 0, 0.1));
+ p.beam(0, -2, 0, top, 4 * (1 - age / 0.1) + 1.5, WHITE);
+ p.glowLine(0, 0, 0, top, 16, F[6], 0.7);
+ }
+ // dirt clods fired up in a narrow cone, raining back down
+ debris(p, age, 14, S + 2, [E[4], E[2]], { y: -4, a: -Math.PI / 2, spread: 0.16, sp: [120, 215], g: 330, life: [1.2, 1.45], size: [1, 2], floor: 0 });
+ debris(p, age, 10, S + 3, [E[3], E[2]], { y: -4, a: -Math.PI / 2, spread: 0.75, sp: [55, 95], g: 340, life: [0.7, 1.1], size: [1, 2], floor: 0 });
+ shock(p, age, 0, 0, 0, 0.3, 4, 28, F[5], F[4], { sy: 0.18 });
+ const lt = 1 - seg(age, 0, 0.7);
+ p.glowLine(0, -6, 0, -H * 0.6, 26, F[4], 0.4 * lt * lt);
+ pool(p, 0, 0, 26, 5, F[4], 0.45 * lt);
+}
diff --git a/src/fx/explosions/nuke.js b/src/fx/explosions/nuke.js
new file mode 100644
index 0000000..b292bc9
--- /dev/null
+++ b/src/fx/explosions/nuke.js
@@ -0,0 +1,95 @@
+import { PAL, RAMP, ramp, at, seg, ease, clamp, lerp, stream, rng, noise2, TAU, WHITE } from "../../core/index.js";
+import { fit, hot, billow, shock, oval, pool } from "./_lib.js";
+
+export const meta = {
+ name: "Nuke",
+ desc: "A blinding white flash, then a fireball lifts off on a rising stem and rolls into a mushroom cloud, cooling to smoke as a ring of dust surges out along the ground.",
+ tags: ["explosion", "nuke", "mushroom", "cloud", "big", "ground", "one-shot"],
+ size: [176, 172],
+ origin: [88, 156],
+ duration: 4.4,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ options: { palette: PAL.fire, size: 1, seed: 35 },
+};
+
+// the cap, in units of its radius: a dome, a ring of puffs that turns (the roll), and a tucked-under lip
+const DOME = [[0, -0.5, 0.62], [-0.48, -0.36, 0.5], [0.48, -0.36, 0.5], [0, -0.05, 0.66], [-0.85, -0.08, 0.44], [0.85, -0.08, 0.44]];
+const LIP = [[-0.95, 0.3, 0.36], [-0.5, 0.36, 0.36], [0, 0.38, 0.36], [0.5, 0.36, 0.36], [0.95, 0.3, 0.36]];
+
+export function draw(p, t, o) {
+ const F = fit(ramp(o.palette)), SM = RAMP.smoke, DU = RAMP.dust, S = o.seed, k = o.size, FIRE = hot(F);
+ const SMK = SM.slice(1, 7), DST = DU.slice(1, 7), gone = 1 - seg(t, 3.3, 4.3);
+ // ---- the flash: two frames of white over everything
+ if (t < 0.067) {
+ p.rect(-meta.origin[0], -meta.origin[1], meta.size[0], meta.size[1], WHITE);
+ return;
+ }
+ // ---- the cap: a ball of fire on the ground that lifts off, swells and flattens into a rolling cap
+ const lift = ease.inOutCubic(seg(t, 0.25, 2.6)), cy = lerp(-12, -104, lift) * k, R = (11 + 19 * ease.outCubic(seg(t, 0.05, 1.7))) * k;
+ const flat = ease.inOutSine(seg(t, 0.35, 1.9)), sx = 1 + 0.42 * flat, sy = 1 - 0.22 * flat;
+ const coolOut = seg(t, 0.15, 2.3), coolIn = seg(t, 0.4, 3.0), drift = seg(t, 3.0, 4.3);
+ const cloud = [];
+ const put = (x, y, r, h) => cloud.push({ x, y, r, v: gone, h });
+ for (const [u, w, rr] of DOME) put(u * R * sx * (1 + drift * 0.2), cy + w * R * sy - drift * 8, rr * R * (1 + drift * 0.25), 1 - (u === 0 ? coolIn : coolOut));
+ const roll = t * 1.3;
+ for (let i = 0; i < 12; i++) {
+ const a = (i / 12) * TAU + roll, x = Math.cos(a) * R * 0.95 * sx, y = cy + Math.sin(a) * R * (0.42 - 0.2 * flat) + R * 0.1;
+ put(x * (1 + drift * 0.2), y - drift * 8, R * (0.4 + 0.06 * Math.sin(a * 3 + t * 4)) * (1 + drift * 0.25), 1 - coolOut);
+ }
+ if (flat > 0.2) for (const [u, w, rr] of LIP) put(u * R * sx, cy + w * R * sy, rr * R * flat, (1 - coolOut) * 0.8);
+ // ---- the stem: puffs boiling up from the ground into the cap's belly, flared at the foot, narrowest mid-way
+ stream(t, 0.3, 3.2, 30, S + 1, 1.1, (age, life, r) => {
+ const q = age / life, top = cy + R * 0.3 * sy, y = lerp(-4, top, Math.pow(q, 0.85));
+ const waist = 1 - 0.38 * Math.sin(Math.min(1, q * 1.3) * Math.PI) + 0.5 * (1 - seg(q, 0, 0.15));
+ const rad = (5.5 + 4 * flat) * k * waist * r.range(0.85, 1.15);
+ put(r.range(-2.5, 2.5) * k + Math.sin(age * 4 + r.next() * TAU) * 1.5, y, rad, (1 - seg(t, 0.4, 1.6)) * (1 - q) * 0.9);
+ });
+ // ---- the base surge: a thick ring of dust rolling out along the floor, an inner ring a beat behind
+ const surge = [], sg = ease.outCubic(seg(t, 0.22, 2.6)), sfade = 1 - seg(t, 2.6, 3.9);
+ if (t > 0.22 && sfade > 0) {
+ for (let i = 0; i < 44; i++) {
+ const inner = i >= 28, g = rng(S + 2, i), n = inner ? 16 : 28, a = ((inner ? i - 28 : i) / n) * TAU + g.range(-0.12, 0.12);
+ const Rb = (8 + 58 * sg * (inner ? 0.62 : 1)) * k, front = Math.sin(a);
+ const rad = (4 + (inner ? 7 : 6) * sg) * k * g.range(0.8, 1.2);
+ surge.push({ x: Math.cos(a) * Rb, y: -rad * 0.7 + front * Rb * 0.09, r: rad, v: sfade * seg(t, 0.22, 0.3) });
+ }
+ }
+ billow(p, surge, (v, lit, x, y, out) => {
+ if (v < 0.06) return;
+ out.a = clamp(v * 4);
+ return at(DST, 0.08 + lit * 0.3 + v * 0.35 + noise2(x * 0.3, y * 0.4, S) * 0.12);
+ });
+ // ---- the cloud: white-hot to red to smoke; the smoke's belly glows with the heat still in it
+ billow(p, cloud, (v, lit, x, y, out, f) => {
+ if (v < 0.06) return;
+ out.a = clamp(v * 4);
+ const n = noise2(x * 0.22 + t * 0.6, y * 0.22 - t * 0.9, S);
+ const heat = f.h * (0.55 + 0.6 * v) + n * 0.08;
+ if (heat > 0.46) {
+ out.k = heat * 0.3;
+ return at(FIRE.slice(1), (heat - 0.46) / 0.54 + lit * 0.08);
+ }
+ // cooling: smoke that still smoulders red from inside, brightest on its belly
+ if (heat > 0.2) {
+ out.l = F[3];
+ out.k = (heat - 0.2) * (lit < 0 ? 1.6 : 0.9);
+ }
+ return at(SMK, 0.18 + lit * 0.3 + v * 0.3 + n * 0.12);
+ });
+ // ---- the shockwave: a dome racing out and a ring along the floor
+ const sw = seg(t, 0.07, 0.75);
+ if (sw > 0 && sw < 1) {
+ const r = (16 + 64 * ease.outCubic(sw)) * k;
+ p.arc(0, 0, r, 1, Math.PI, TAU, F[7], sw < 0.4 ? 1 : 1 - (sw - 0.4) / 0.6);
+ }
+ shock(p, t, 0, 0, 0.07, 0.8, 14 * k, 84 * k, F[6], F[5], { sy: 0.1 });
+ // ---- light: the glare after the flash, then the fireball's heat on the ground
+ const glare = 1 - seg(t, 0.067, 0.6);
+ p.glow(0, -40, 110, F[6], 0.7 * glare * glare);
+ const heat = 1 - seg(t, 0.2, 2.2);
+ p.glow(0, cy, R * 2.2, F[5], 0.4 * heat);
+ pool(p, 0, 0, 70 * k, 8, F[4], 0.5 * heat * gone);
+ if (t < 0.6) oval(p, 0, 0, (8 + 58 * sg) * k * 0.6, (8 + 58 * sg) * k * 0.06, F[6], 1 - t / 0.6);
+}
diff --git a/src/fx/explosions/plasma-explosion.js b/src/fx/explosions/plasma-explosion.js
new file mode 100644
index 0000000..61c42d7
--- /dev/null
+++ b/src/fx/explosions/plasma-explosion.js
@@ -0,0 +1,68 @@
+import { PAL, RAMP, ramp, at, seg, ease, burst, fly, flyV, fbm, rng, bolt, TAU, WHITE } from "../../core/index.js";
+import { fit } from "./_lib.js";
+
+export const meta = {
+ name: "Plasma explosion",
+ desc: "A blue-white energy blast: a white core flash, a crackling plasma sphere that swells and hollows out, three shock rings, arcs of lightning, plasma motes.",
+ tags: ["explosion", "plasma", "energy", "electric", "sci-fi", "magic", "one-shot"],
+ size: [104, 104],
+ origin: [52, 52],
+ duration: 0.95,
+ loop: false,
+ fps: 30,
+ bg: "dark",
+ options: { palette: PAL.electric, radius: 30, seed: 31 },
+};
+
+export function draw(p, t, o) {
+ const E = fit(ramp(o.palette)), V = RAMP.arcane, S = o.seed, Rm = o.radius;
+ // the sphere: swells fast, hollows from the middle, its rim crackling, then thins away by dither
+ const R = 5 + Rm * ease.outExpo(seg(t, 0, 0.4)), hollow = Math.pow(seg(t, 0.1, 0.55), 0.8), fade = 1 - seg(t, 0.35, 0.68);
+ if (fade > 0) {
+ p.shade(-R - 3, -R - 3, R + 3, R + 3, (x, y, out) => {
+ const d = Math.hypot(x, y), n = fbm(x * 0.16 + t * 4, y * 0.16 - t * 3, S, 2);
+ const rim = R * (1 + n * 0.08);
+ if (d > rim) return;
+ const v = d / rim;
+ if (v < hollow * 0.92) return;
+ out.a = fade;
+ out.k = 0.15;
+ if (v > 0.9) return v > 0.96 ? WHITE : E[6];
+ const swirl = Math.sin(Math.atan2(y, x) * 3 + d * 0.4 - t * 14 + n * 4);
+ return at([E[2], E[3], E[4], E[5]], 0.45 + swirl * 0.25 + n * 0.5 + v * 0.3);
+ });
+ }
+ // the white core flash
+ if (t < 0.07) p.circle(0, 0, 8 + 60 * t, WHITE);
+ // three shock rings, each a little later and slower
+ const rings = [[0.02, 0.42, 48, E[6], 1], [0.08, 0.58, 42, V[5], 2], [0.16, 0.74, 34, E[5], 1]];
+ for (const [t0, t1, r1, c, w] of rings) {
+ const q = seg(t, t0, t1);
+ if (q <= 0 || q >= 1) continue;
+ const rr = 4 + (r1 - 4) * ease.outCubic(q);
+ p.ring(0, 0, rr, w, c, q < 0.4 ? 1 : 1 - (q - 0.4) / 0.6);
+ p.glowRing(0, 0, rr, 4, c, 0.25 * (1 - q));
+ }
+ // arcs of lightning jumping out to the rim, a new shape every other frame
+ if (t > 0.02 && t < 0.4) {
+ const r = rng(S, Math.floor(t * 15));
+ for (let i = 0; i < 5; i++) {
+ const a = r.range(0, TAU), L = R * r.range(0.7, 1.05);
+ const path = bolt(r, Math.cos(a) * 3, Math.sin(a) * 3, Math.cos(a) * L, Math.sin(a) * L, { jag: 0.28, depth: 4 });
+ p.polyline(path, i % 2 ? WHITE : E[6]);
+ p.glowLine(0, 0, Math.cos(a) * L, Math.sin(a) * L, 5, E[4], 0.15);
+ }
+ }
+ // plasma motes flung out on short trails, cooling to violet
+ burst(18, S + 1, (r) => {
+ const a = r.range(0, TAU), sp = r.range(90, 160), L = r.range(0.5, 0.9);
+ if (t > L) return;
+ const q = t / L, vx = Math.cos(a) * sp, vy = Math.sin(a) * sp, [x, y] = fly(0, 0, vx, vy, t, 0, 3), [ux, uy] = flyV(vx, vy, t, 0, 3);
+ p.line(x, y, x - ux * 0.04, y - uy * 0.04, q < 0.4 ? E[5] : V[4]);
+ p.px(x, y, q < 0.3 ? WHITE : q < 0.6 ? E[6] : V[5]);
+ p.light(x, y, E[5], 0.5 * (1 - q));
+ });
+ const L = 1 - seg(t, 0, 0.8);
+ p.glow(0, 0, 50, E[4], 0.5 * L * L);
+ p.glow(0, 0, 12, E[6], 0.6 * (1 - seg(t, 0, 0.3)));
+}
diff --git a/src/fx/explosions/small-explosion.js b/src/fx/explosions/small-explosion.js
new file mode 100644
index 0000000..79a4fa2
--- /dev/null
+++ b/src/fx/explosions/small-explosion.js
@@ -0,0 +1,91 @@
+import { PAL, RAMP, fit, at, burst, fly, flyV, seg, ease, clamp, noise2, TAU, WHITE } from "../../core/index.js";
+
+export const meta = {
+ name: "Small explosion",
+ desc: "A quick blast: a white flash frame, a lumpy fireball that cools from the edges into rising smoke, a shockwave, sparks and debris.",
+ tags: ["explosion", "fire", "smoke", "impact", "one-shot"],
+ size: [84, 88],
+ origin: [42, 48],
+ duration: 1.2,
+ loop: false,
+ fps: 30,
+ bg: "dark",
+ options: { palette: PAL.fire, size: 1, seed: 3 },
+};
+
+export function draw(p, t, o) {
+ const F = fit(o.palette, 8), SM = RAMP.smoke, S = o.seed, k = o.size;
+ const FIRE = [F[2], F[3], F[4], F[5], F[6], F[7], WHITE]; // cool edge .. white-hot core
+
+ // puffs: pushed out fast then drifting up; each is both a ball of heat and, later, a ball of smoke
+ const puffs = [];
+ burst(12, S, (r, i) => {
+ const ang = (i / 12) * TAU + r.range(-0.35, 0.35), reach = (i < 2 ? r.range(0, 3) : r.range(5, 13)) * k;
+ const age = t - (i < 2 ? 0 : r.range(0.01, 0.07)), life = r.range(0.75, 1.05);
+ if (age < 0 || age > life) return;
+ const q = age / life, e = ease.outCubic(seg(age, 0, 0.28));
+ const x = Math.cos(ang) * reach * e, y = Math.sin(ang) * reach * e * 0.7 - age * age * 26 * k;
+ const r0 = r.range(5, 8) * k * (0.5 + 0.7 * e);
+ puffs.push({
+ x, y,
+ fr: r0 * (1 - 0.45 * seg(q, 0.15, 0.6)), heat: 1 - seg(q, 0.05, 0.62),
+ sx: x, sy: y - q * q * 16 * k, sr: r0 * (1.05 + 0.8 * q), smoke: seg(q, 0.12, 0.4) * (1 - seg(q, 0.62, 1)),
+ });
+ });
+ // the field: the strongest puff at each pixel decides, with light from the top-left
+ const field = (x, y, rk, vk, xk, yk) => {
+ let best = 0, lit = 0;
+ for (const f of puffs) {
+ const dx = x - f[xk], dy = y - f[yk], d = Math.sqrt(dx * dx + dy * dy) / f[rk];
+ if (d >= 1) continue;
+ const v = (1 - d * d) * f[vk];
+ if (v > best) (best = v), (lit = (-dx - dy * 1.4) / f[rk]);
+ }
+ return [best, lit];
+ };
+ // debris: dark chunks tossed up and falling (behind the fire, so they show once they're clear of it)
+ burst(6, S + 2, (r) => {
+ const a = -Math.PI / 2 + r.range(-1.2, 1.2), sp = r.range(50, 95) * k, life = r.range(0.4, 0.55);
+ if (t > life) return;
+ const [x, y] = fly(0, 0, Math.cos(a) * sp, Math.sin(a) * sp, t, 260, 0.5), s = r.next() < 0.5 ? 2 : 1;
+ p.rect(x, y, s, s, SM[1], 1 - seg(t, life * 0.7, life));
+ });
+ // smoke behind
+ p.shade(-36, -42, 36, 30, (x, y, out) => {
+ const [v, lit] = field(x, y, "sr", "smoke", "sx", "sy");
+ if (v < 0.06) return;
+ out.c = at(SM.slice(1, 6), 0.25 + lit * 0.3 + v * 0.35 + noise2(x * 0.4, y * 0.4, S) * 0.12);
+ out.a = clamp(v * 4);
+ });
+ // fire in front
+ p.shade(-36, -42, 36, 30, (x, y, out) => {
+ const [v, lit] = field(x, y, "fr", "heat", "x", "y");
+ if (v < 0.08) return;
+ out.c = at(FIRE, v * 0.95 + lit * 0.12 + noise2(x * 0.5, y * 0.5, S + 1) * 0.1);
+ out.k = v * 0.25;
+ });
+ // flash: one or two frames of solid white, the frame that sells the hit
+ if (t < 0.07) {
+ p.circle(0, 0, (6 + 40 * t) * k, WHITE);
+ p.glow(0, 0, 48 * k, F[6], 0.9);
+ }
+ // shockwave: a thin ring racing out, dithering away
+ const sw = seg(t, 0.02, 0.24);
+ if (sw > 0 && sw < 1) {
+ const r = (8 + 22 * ease.outCubic(sw)) * k;
+ p.ring(0, 0, r, 1, F[7], 1 - sw * 0.9);
+ p.glowRing(0, 0, r, 4, F[5], 0.3 * (1 - sw));
+ }
+ // sparks: streaks along their velocity, falling, cooling yellow to red
+ burst(14, S + 1, (r) => {
+ const a = r.range(0, TAU), sp = r.range(60, 120) * k, life = r.range(0.3, 0.55);
+ if (t > life) return;
+ const q = t / life, vx0 = Math.cos(a) * sp, vy0 = Math.sin(a) * sp - 30;
+ const [x, y] = fly(0, 0, vx0, vy0, t, 160, 2.5), [vx, vy] = flyV(vx0, vy0, t, 160, 2.5);
+ p.line(x, y, x - vx * 0.025, y - vy * 0.025, q < 0.3 ? F[7] : q < 0.6 ? F[5] : F[3]);
+ p.light(x, y, F[5], 0.6 * (1 - q));
+ });
+ // the blast lights everything up, then lets go fast
+ const L = 1 - seg(t, 0, 0.5);
+ p.glow(0, -2, 42 * k, F[5], 0.55 * L * L);
+}
diff --git a/src/fx/explosions/smoke-puff.js b/src/fx/explosions/smoke-puff.js
new file mode 100644
index 0000000..a721679
--- /dev/null
+++ b/src/fx/explosions/smoke-puff.js
@@ -0,0 +1,53 @@
+import { ramp, seg, ease, rng, burst, TAU } from "../../core/index.js";
+import { fit } from "./_lib.js";
+
+export const meta = {
+ name: "Smoke puff",
+ desc: "A cartoon poof: round outlined puffs pop out with a bounce, drift apart and blink away one by one, with speed lines and a couple of twinkles.",
+ tags: ["smoke", "poof", "cartoon", "teleport", "vanish", "one-shot"],
+ size: [60, 52],
+ origin: [30, 30],
+ duration: 0.75,
+ loop: false,
+ fps: 30,
+ bg: "dark",
+ options: { palette: ["#241e38", "#4c4668", "#8a84a8", "#c8c4dc", "#ffffff"], size: 1, seed: 24 },
+};
+
+export function draw(p, t, o) {
+ const P = fit(ramp(o.palette), 5), S = o.seed, k = o.size;
+ // seven puffs: one in the middle, six around it; each pops in with an overshoot and blinks out on its own beat
+ const puffs = [];
+ for (let i = 0; i < 7; i++) {
+ const r = rng(S, i), a = i === 0 ? 0 : ((i - 1) / 6) * TAU + r.range(-0.3, 0.3);
+ const d0 = i === 0 ? 0 : r.range(5, 7.5), drift = i === 0 ? 0 : 6 * ease.outCubic(seg(t, 0.04, 0.6));
+ const pop = ease.outBack(seg(t, 0.01 * i, 0.12 + 0.01 * i), 2.6);
+ const out = i === 0 ? 0.56 : 0.34 + r.range(0, 0.12) + (i % 3) * 0.04, gone = ease.inBack(seg(t, out, out + 0.15), 2);
+ const rad = (i === 0 ? 7 : r.range(4.5, 6)) * k * pop * (1 - gone);
+ if (rad < 0.6) continue;
+ puffs.push({ x: Math.cos(a) * (d0 + drift) * k, y: Math.sin(a) * (d0 + drift) * k * 0.8 - t * 6, r: rad });
+ }
+ // outline first, under everything, so the puffs merge into one cartoon cloud
+ for (const f of puffs) p.circle(f.x, f.y, f.r + 1, P[1]);
+ for (const f of puffs)
+ p.circle(f.x, f.y, f.r, (d, a) => {
+ const lit = Math.cos(a + 2.3); // +1 facing the top-left
+ if (d > 0.62 && lit < -0.35) return P[2];
+ if (d < 0.62 && d > 0.28 && lit > 0.62 && f.y < 2) return P[4];
+ return P[3];
+ });
+ // speed lines bursting outward
+ const sl = seg(t, 0.02, 0.18);
+ if (sl > 0 && sl < 1)
+ burst(8, S + 1, (r, i) => {
+ const a = (i / 8) * TAU + r.range(-0.2, 0.2), r0 = (11 + 14 * ease.outCubic(sl)) * k, len = 4 * (1 - sl) + 1;
+ p.line(Math.cos(a) * r0, Math.sin(a) * r0 * 0.72, Math.cos(a) * (r0 + len), Math.sin(a) * (r0 + len) * 0.72, P[4]);
+ });
+ // two twinkles pop at the edge
+ burst(2, S + 2, (r, i) => {
+ const b = seg(t, 0.12 + i * 0.12, 0.34 + i * 0.12);
+ if (b <= 0 || b >= 1) return;
+ const a = r.range(0, TAU), x = Math.cos(a) * 15 * k, y = Math.sin(a) * 12 * k, s = Math.round(2 * Math.sin(b * Math.PI));
+ p.line(x - s, y, x + s, y, P[4]), p.line(x, y - s, x, y + s, P[4]);
+ });
+}
diff --git a/src/fx/fire/_lib.js b/src/fx/fire/_lib.js
new file mode 100644
index 0000000..2389faa
--- /dev/null
+++ b/src/fx/fire/_lib.js
@@ -0,0 +1,107 @@
+// Shared by the fire effects: flame tongues torn by rising noise, embers, smoke wisps, pools of light.
+// Not an effect (the leading _ keeps the tools from listing it).
+
+import { at, cycle, tileFbm, loopNoise, TAU } from "../../core/index.js";
+
+/** A ramp resampled to n steps (nearest), so an effect can index steps whatever palette it is given. */
+export function fit(C, n = 8) {
+ if (C.length === n) return C;
+ return Array.from({ length: n }, (_, i) => C[Math.round((i * (C.length - 1)) / (n - 1))]);
+}
+
+/** Half-width of a tongue at height v (0 base, 1 tip) as a share of its widest: round bottom, pointed top. */
+export function taper(v) {
+ if (v < 0.2) {
+ const q = (0.2 - v) / 0.28;
+ return q >= 1 ? 0 : Math.sqrt(1 - q * q);
+ }
+ return v >= 1.05 ? 0 : Math.pow(1 - (v - 0.2) / 0.85, 0.7);
+}
+
+/**
+ * A flame tongue on loop phase ph: its height breathes with noise and its tip whips side to side, `beat`
+ * whole sways a loop (keep it whole for seamless loops). Returns { x, y, w, h, a, f, b } for flames().
+ */
+export function tongue(x, y, w, h, ph, seed, { sway = 2.4, beat = 2, pulse = 0.15 } = {}) {
+ return {
+ x, y, w,
+ h: h * (1 - pulse + pulse * loopNoise(ph, 1.4, seed)),
+ a: 0.8 * sway, f: ph * TAU * beat + seed * 1.7, b: loopNoise(ph, 0.8, seed + 3) * sway,
+ };
+}
+
+/**
+ * Fire made of tongues, painted over box [x0, y0, x1, y1]. Each pixel takes the heat of its strongest
+ * tongue, torn up by noise that rises `scroll` whole cells a loop (seamless). The palest step is kept for
+ * the base of the core. o: { F (8 steps), ph, seed, box, scroll, nx, ny, tear, core, k (light) }.
+ */
+export function flames(p, tongues, o) {
+ const F = o.F, body = [F[2], F[3], F[4], F[5], F[6]], ph = o.ph ?? 0, S = o.seed ?? 1, k = o.k ?? 0;
+ const sc = o.scroll ?? 12, nx = o.nx ?? 0.36, ny = o.ny ?? 0.24, tear = o.tear ?? 1, n = tongues.length;
+ const cut = 0.12 - 0.5 * tear, hot = o.core === false ? 9 : 1.02;
+ const [x0, y0, x1, y1] = o.box;
+ // how far each tongue can reach sideways, sway included: a cheap test before the real one
+ const reach = tongues.map((T) => T.w * 1.7 + (Math.abs(T.a) + Math.abs(T.b)) * 1.2);
+ p.shade(x0, y0, x1, y1, (x, y, out) => {
+ let best = -9, bv = 0;
+ for (let i = 0; i < n; i++) {
+ const T = tongues[i], v = (T.y - y) / T.h;
+ if (v < -0.08 || v > 1.05 || Math.abs(x - T.x) > reach[i]) continue;
+ const w = T.w * taper(v);
+ if (w <= 0.3) continue;
+ const d = Math.abs(x - T.x - (T.a * Math.sin(T.f + v * 2.4) + T.b) * v * v) / w;
+ if (d > 1.7) continue;
+ const h = (1 - Math.pow(d, 1.6)) * (1.08 - v * 0.8);
+ if (h > best) (best = h), (bv = v);
+ }
+ if (best < cut) return;
+ const heat = best + tileFbm(x * nx, y * ny + ph * sc, 0, sc, S, 3) * (0.3 + bv * 0.35) * tear;
+ if (heat < 0.12) return;
+ out.c = heat > hot && bv < 0.35 ? F[7] : at(body, (heat - 0.12) / 0.92);
+ if (k) out.k = k * Math.min(1, heat);
+ });
+}
+
+/**
+ * Embers: single pixels rising from around (x, y), wobbling, cooling and flickering out: a seamless cycle
+ * over period D. cols: [hot, warm, cool] colors, glow: their light.
+ */
+export function embers(p, t, D, n, seed, cols, glow, o = {}) {
+ const { x = 0, y = 0, w = 4, rise = [16, 28], life = [0.7, 1.2], wob = 3, k = 0.6, drift = 0 } = o;
+ cycle(t, D, n, seed, (g) => g.range(life[0], life[1]), (age, L, r) => {
+ const q = age / L, ex = x + r.range(-w, w) + Math.sin(age * r.range(4, 8) + r.next() * TAU) * wob * q + drift * age;
+ const ey = y - age * r.range(rise[0], rise[1]);
+ if (q > 0.5 && Math.sin(age * 38 + r.next() * 9) < -0.5) return;
+ p.px(ex, ey, q < 0.35 ? cols[0] : q < 0.7 ? cols[1] : cols[2]);
+ p.light(ex, ey, glow, k * (1 - q));
+ });
+}
+
+/**
+ * Smoke wisps: little puffs that rise from (x, y), lean with `drift`, swell from r0 to r1 and thin out by
+ * dither. A seamless cycle over period D. SM: a smoke ramp, dark to light.
+ */
+export function wisps(p, t, D, n, seed, SM, o = {}) {
+ const { x = 0, y = 0, w = 3, rise = [10, 16], drift = 4, life = [1.2, 1.8], r0 = 1, r1 = 3, tone = 2 } = o;
+ const lo = SM[Math.min(tone, SM.length - 1)], mid = SM[Math.min(tone + 1, SM.length - 1)], hi = SM[Math.min(tone + 2, SM.length - 1)];
+ cycle(t, D, n, seed, (g) => g.range(life[0], life[1]), (age, L, r) => {
+ const q = age / L, sway = Math.sin(age * r.range(1.5, 2.6) + r.next() * TAU) * 1.6 * q;
+ const sx = x + r.range(-w, w) + drift * q * r.range(0.5, 1) + sway, sy = y - age * r.range(rise[0], rise[1]);
+ // solid pixels: it swells, then shrinks away as it thins (tiny shapes dithered just look like dirt)
+ const rad = q < 0.6 ? r0 + (r1 - r0) * Math.sqrt(q / 0.6) : r1 * (1 - (q - 0.6) / 0.4) ** 0.7;
+ if (rad < 0.5) return;
+ p.circle(sx, sy, rad, (d, ang) => (q < 0.5 && d < 0.6 && ang < -0.5 ? hi : q < 0.8 && d < 0.8 ? mid : lo));
+ });
+}
+
+/** A pool of light on the floor: an ellipse of glow, k at its middle, falling to 0 at its rim. */
+export function pool(p, x, y, rx, ry, c, k) {
+ if (k <= 0.004 || rx < 1 || ry < 0.5) return;
+ p.shade(x - rx, y - ry, x + rx, y + ry, (px, py, out) => {
+ const dx = (px - x) / rx, dy = (py - y) / ry, d = dx * dx + dy * dy;
+ if (d >= 1) return;
+ const f = 1 - Math.sqrt(d);
+ out.l = c;
+ out.k = f * f * k;
+ });
+}
diff --git a/src/fx/fire/brazier.js b/src/fx/fire/brazier.js
new file mode 100644
index 0000000..a29bf17
--- /dev/null
+++ b/src/fx/fire/brazier.js
@@ -0,0 +1,62 @@
+import { PAL, ramp, rand, loopNoise } from "../../core/index.js";
+import { fit, tongue, flames, embers, pool } from "./_lib.js";
+
+export const meta = {
+ name: "Brazier",
+ desc: "An iron bowl on a tripod stand holding a big, lively fire: tall licking tongues, glowing coals at the rim, sparks streaming up.",
+ tags: ["fire", "brazier", "prop", "light", "dungeon", "loop"],
+ size: [52, 92],
+ origin: [26, 88],
+ duration: 1.2,
+ loop: true,
+ fps: 30,
+ bg: "ground",
+ options: { palette: PAL.fire, height: 34, seed: 3 },
+};
+
+const IRON = ramp(["#100f15", "#24222c", "#383542", "#55515f", "#7a7585"]);
+
+export function draw(p, t, o) {
+ const F = fit(ramp(o.palette)), S = o.seed, D = meta.duration, ph = t / D, H = o.height;
+ const flick = 0.82 + 0.18 * loopNoise(ph, 2, S + 5), rim = -36;
+ // stand: a back leg in shadow, two splayed front legs, a brace ring
+ p.line(0, rim + 8, 0, -2, IRON[1]);
+ p.beam(-7, rim + 8, -13, -1, 2.4, (u, v) => (v > 0.6 ? IRON[0] : IRON[2]));
+ p.beam(7, rim + 8, 13, -1, 2.4, (u, v) => (v > 0.6 ? IRON[0] : IRON[1]));
+ p.rect(-15, -1, 4, 1, IRON[2]), p.rect(11, -1, 4, 1, IRON[1]);
+ p.line(-10, -14, 10, -14, IRON[1]);
+ p.line(-10, -15, 10, -15, IRON[2]);
+ // coals heaped above the rim, glowing in and out
+ for (let x = -11; x <= 11; x++) {
+ const h = 1 + Math.round(2 * (1 - Math.abs(x) / 12) + rand(x, S) * 1.2);
+ for (let y = 0; y < h; y++) {
+ const g = rand(x, y, S + 1) + 0.25 * Math.sin(ph * 6.283 * 2 + x * 1.3);
+ p.px(x, rim - 1 - y, g > 0.75 ? F[5] : g > 0.4 ? F[4] : g > 0.15 ? F[3] : F[2]);
+ }
+ }
+ // the fire
+ const T = [
+ tongue(0, rim - 1, 8, H, ph, S, { beat: 3, sway: 3 }),
+ tongue(-6, rim, 5.5, H * 0.66, ph, S + 13, { beat: 3, sway: 2.6 }),
+ tongue(6.5, rim, 5.5, H * 0.72, ph, S + 29, { beat: 2, sway: 2.6 }),
+ tongue(-10.5, rim + 1, 3.4, H * 0.36, ph, S + 41, { beat: 4, sway: 1.6, pulse: 0.3 }),
+ tongue(10.5, rim + 1, 3.4, H * 0.4, ph, S + 53, { beat: 4, sway: 1.6, pulse: 0.3 }),
+ ];
+ flames(p, T, { F, ph, seed: S, box: [-17, rim - H - 12, 17, rim + 2], scroll: 14, tear: 1.1 });
+ // the bowl: a wide iron dish with a rolled rim catching the firelight
+ p.shade(-14, rim, 14, rim + 9, (x, y) => {
+ const dx = x / 14, dy = (y - rim) / 9, d = dx * dx + dy * dy;
+ if (d > 1) return;
+ if (d > 0.72) return IRON[0];
+ return dy < 0.3 ? IRON[3] : dy < 0.62 ? IRON[2] : IRON[1];
+ });
+ for (let x = -14; x <= 14; x++) p.px(x, rim, Math.abs(x) > 12 ? IRON[2] : (x + 20) % 7 === 0 ? IRON[1] : F[3]);
+ for (let x = -15; x <= 15; x++) p.px(x, rim + 1, Math.abs(x) === 15 ? IRON[1] : x < 3 ? IRON[4] : IRON[3]);
+ for (const x of [-8, 0, 8]) p.px(x, rim + 4, IRON[4]);
+ // sparks streaming up
+ embers(p, t, D, 12, S + 7, [F[7], F[5], F[3]], F[4], { x: 0, y: rim - H * 0.5, w: 8, rise: [24, 38], life: [0.45, 0.8], wob: 4 });
+ // light
+ p.glow(0, rim - H * 0.4, 36 * flick, F[4], 0.28 * flick);
+ p.glow(0, rim - 6, 12, F[6], 0.32 * flick);
+ pool(p, 0, 0, 18, 3, F[4], 0.25 * flick);
+}
diff --git a/src/fx/fire/campfire.js b/src/fx/fire/campfire.js
new file mode 100644
index 0000000..0637aed
--- /dev/null
+++ b/src/fx/fire/campfire.js
@@ -0,0 +1,69 @@
+import { PAL, RAMP, ramp, cycle, fly, loopNoise, rand } from "../../core/index.js";
+import { fit, tongue, flames, embers, wisps, pool } from "./_lib.js";
+
+export const meta = {
+ name: "Campfire",
+ desc: "Two crossed logs with a crackling fire: tongues that lick and sway, popping sparks, embers, smoke wisps and a warm pool of light on the ground.",
+ tags: ["fire", "camp", "prop", "light", "ambient", "loop"],
+ size: [56, 72],
+ origin: [28, 60],
+ duration: 2,
+ loop: true,
+ fps: 30,
+ bg: "ground",
+ options: { palette: PAL.fire, height: 24, seed: 1 },
+};
+
+const BARK = ramp(["#170d0b", "#3a2318", "#5c3a24", "#835a37"]);
+const GRAIN = ramp(["#6e4428", "#b4824f", "#e2b77c"]);
+
+// a log lying on the floor from its near end (x0, y0) to its far end (x1, y1), r px thick: outlined, lit
+// from above, bark lines along it, charred near the far end with embers glowing in the cracks
+function log(p, x0, y0, x1, y1, r, F, flick, S, u0 = 0, u1 = 1.04) {
+ const dx = x1 - x0, dy = y1 - y0, L = Math.hypot(dx, dy), nx = -dy / L, ny = dx / L, side = ny > 0 ? -1 : 1;
+ p.shade(Math.min(x0, x1) - r, Math.min(y0, y1) - r, Math.max(x0, x1) + r, Math.max(y0, y1) + r, (x, y) => {
+ const u = ((x - x0) * dx + (y - y0) * dy) / (L * L), s = (((x - x0) * nx + (y - y0) * ny) / r) * side;
+ if (u < u0 || u > u1 || Math.abs(s) > 1) return;
+ if (Math.abs(s) > 0.7 || u > 1) return BARK[0];
+ const burnt = u > 0.55, along = Math.floor(u * L);
+ if (burnt && s > -0.2 && rand(along, Math.round(s * 3), S) > 0.62) return rand(along, S) > 0.5 * flick ? F[4] : F[3];
+ if (rand(along >> 1, Math.round(s * 2), S + 3) > 0.8) return BARK[1];
+ return s < -0.25 ? BARK[burnt ? 2 : 3] : s < 0.3 ? BARK[burnt ? 1 : 2] : BARK[1];
+ });
+ // end grain at the near end
+ if (u0 === 0) p.ellipse(x0, y0, r * 0.62, r * 0.9, (d) => (d > 0.75 ? GRAIN[0] : d > 0.4 ? GRAIN[1] : GRAIN[2]));
+}
+
+export function draw(p, t, o) {
+ const F = fit(ramp(o.palette)), SM = RAMP.smoke, S = o.seed, D = meta.duration, ph = t / D, H = o.height;
+ const flick = 0.82 + 0.18 * loopNoise(ph, 2, S + 5);
+ // smoke curls up from above the flames, behind everything
+ wisps(p, t, D, 4, S + 20, SM, { x: 1, y: -H - 8, w: 2, rise: [8, 12], drift: 5, life: [1.4, 1.9], r0: 1, r1: 2.4, tone: 1 });
+ // two logs crossed in an X: their far halves behind the fire, their near halves over its base
+ const A = [13.5, -1.5, -10, -12], B = [-13.5, -1.5, 10, -12];
+ log(p, ...A, 2.8, F, flick, S + 1, 0.5);
+ log(p, ...B, 2.8, F, flick, S + 2, 0.5);
+ const T = [
+ tongue(0, -7, 6.5, H, ph, S, { beat: 2, sway: 2.6 }),
+ tongue(-4.5, -6, 4.2, H * 0.62, ph, S + 11, { beat: 3, sway: 2 }),
+ tongue(4.5, -6, 4.4, H * 0.7, ph, S + 23, { beat: 3, sway: 2.2 }),
+ tongue(-8, -6, 2.6, H * 0.34, ph, S + 31, { beat: 4, sway: 1.4, pulse: 0.3 }),
+ tongue(8.5, -6, 2.6, H * 0.38, ph, S + 47, { beat: 4, sway: 1.4, pulse: 0.3 }),
+ ];
+ flames(p, T, { F, ph, seed: S, box: [-13, -H - 12, 13, -2], scroll: 20 });
+ log(p, ...A, 2.8, F, flick, S + 1, 0, 0.5);
+ log(p, ...B, 2.8, F, flick, S + 2, 0, 0.5);
+ // crackle: sparks that pop out of the logs and arc down
+ cycle(t, D, 4, S + 40, 0.42, (age, life, r) => {
+ const q = age / life, vx = r.range(14, 30) * r.sign(), vy = -r.range(45, 70);
+ const [x, y] = fly(r.range(-4, 4), -7, vx, vy, age, 220, 0.5);
+ if (y > -1) return;
+ p.px(x, y, q < 0.4 ? F[7] : q < 0.75 ? F[6] : F[4]);
+ p.light(x, y, F[5], 0.6 * (1 - q));
+ });
+ embers(p, t, D, 9, S + 7, [F[6], F[5], F[3]], F[4], { x: 0, y: -H * 0.6, w: 6, rise: [16, 26], life: [0.9, 1.5] });
+ // light: a warm pool on the floor and a glow that breathes with the flames
+ pool(p, 0, 0, 27 * flick, 6, F[4], 0.42 * flick);
+ p.glow(0, -H * 0.45, 30 * flick, F[4], 0.26 * flick);
+ p.glow(0, -8, 10, F[6], 0.3 * flick);
+}
diff --git a/src/fx/fire/candle.js b/src/fx/fire/candle.js
new file mode 100644
index 0000000..5798cd8
--- /dev/null
+++ b/src/fx/fire/candle.js
@@ -0,0 +1,72 @@
+import { PAL, ramp, at, clamp, seg, ease, loopNoise, tileNoise, TAU, hex } from "../../core/index.js";
+import { fit, pool } from "./_lib.js";
+
+export const meta = {
+ name: "Candle",
+ desc: "A small wax candle: a calm flame with a blue root that leans and stretches, a soft glow, and a bead of wax that runs down its drip.",
+ tags: ["fire", "candle", "light", "prop", "ambient", "loop"],
+ size: [28, 44],
+ origin: [14, 40],
+ duration: 3,
+ loop: true,
+ fps: 30,
+ bg: "ground",
+ options: { palette: PAL.fire, height: 14, seed: 2 },
+};
+
+const WAX = ramp(["#4a2f37", "#9a7468", "#d8bfa6", "#f1e4cc", "#fffaee"]);
+const WICK = hex("#2a1716"), BLUE = hex("#3a5cd0"), BLUE_DARK = hex("#24307a");
+
+export function draw(p, t, o) {
+ const F = fit(ramp(o.palette)), S = o.seed, D = meta.duration, ph = t / D, H = o.height, top = -H;
+ const flick = 0.85 + 0.15 * loopNoise(ph, 1.6, S);
+ // the candle: lit from the flame above, so warm at the top and dimmer toward the floor
+ for (let y = top; y < 0; y++)
+ for (let x = -3; x <= 3; x++) {
+ const v = (y - top) / H;
+ let c = x === -3 ? WAX[2] : x === 3 ? WAX[1] : x === 2 ? WAX[2] : WAX[3];
+ if (x === -2 && v < 0.5) c = WAX[4];
+ if (v > 0.75 && x !== -2) c = x === 3 || x === 2 ? WAX[1] : WAX[2];
+ p.px(x, y, c);
+ }
+ // melted lip and the pool of wax around the wick
+ p.px(-3, top - 1, WAX[3]), p.px(3, top - 1, WAX[2]);
+ for (let x = -2; x <= 2; x++) p.px(x, top, WAX[4]);
+ // drips: a long one down the shaded side with a fat foot, a short one on the lit edge, a melted base
+ const dx = 2;
+ for (let y = top + 1; y <= -6; y++) p.px(dx, y, WAX[3]);
+ p.px(dx, -5, WAX[4]), p.px(dx, -4, WAX[3]), p.px(dx + 1, -5, WAX[3]), p.px(dx + 1, -4, WAX[2]);
+ for (let y = top + 1; y < top + 4; y++) p.px(-3, y, WAX[3]);
+ p.px(-3, top + 4, WAX[4]), p.px(-4, top + 4, WAX[2]);
+ for (let x = -4; x <= 4; x++) p.px(x, -1, x < 0 ? WAX[3] : WAX[2]);
+ // a fresh bead swells on the lip, then runs down the drip, gathering speed, and joins its foot
+ const grow = seg(ph, 0.05, 0.45), run = ease.inQuad(seg(ph, 0.45, 0.95));
+ if (grow > 0 && ph < 0.95) {
+ const by = Math.round(top + run * (-6 - top));
+ p.px(dx, by, WAX[4]);
+ if (grow > 0.6) p.px(dx + 1, by, WAX[3]);
+ if (run > 0.1) p.px(dx, by - 1, WAX[4]);
+ p.light(dx, by, F[6], 0.3);
+ }
+ // wick
+ p.px(0, top - 1, WICK), p.px(0, top - 2, WICK), p.px(0, top - 3, F[3]);
+ // the flame: a calm teardrop with a blue root, leaning and stretching a little
+ const fh = 10 * (0.92 + 0.12 * loopNoise(ph, 1.2, S + 3)), base = top - 2;
+ const lean = loopNoise(ph, 0.9, S + 7) * 1.4 + Math.sin(ph * TAU * 3) * 0.35;
+ p.shade(-5, base - fh - 2, 5, base + 2, (x, y) => {
+ const v = (base - y) / fh;
+ if (v < -0.15 || v > 1) return;
+ const w = 2.7 * (v < 0.25 ? Math.sqrt(clamp(1 - ((0.25 - v) / 0.4) ** 2)) : Math.pow(clamp(1 - (v - 0.25) / 0.8), 0.8));
+ if (w < 0.35) return;
+ const d = Math.abs(x - lean * v * v) / w + tileNoise(x * 0.5, y * 0.35 + ph * 9, 0, 9, S) * 0.18 * v;
+ if (d > 1) return;
+ if (v < 0.12) return d > 0.45 ? (d > 0.8 ? BLUE_DARK : BLUE) : F[6];
+ if (d < 0.38 && v < 0.55) return F[7];
+ if (d < 0.7 && v < 0.8) return F[6];
+ return v > 0.82 ? F[4] : F[5];
+ });
+ // light: a soft halo and a warm spot at the heart of the flame
+ p.glow(0, base - 4, 24 * flick, F[4], 0.22 * flick);
+ p.glow(0, base - 3, 7, F[6], 0.32 * flick);
+ pool(p, 0, 0, 12, 2.5, F[5], 0.2 * flick);
+}
diff --git a/src/fx/fire/ember-burst.js b/src/fx/fire/ember-burst.js
new file mode 100644
index 0000000..6494ab7
--- /dev/null
+++ b/src/fx/fire/ember-burst.js
@@ -0,0 +1,48 @@
+import { PAL, ramp, burst, fly, flyV, seg, ease, TAU, WHITE } from "../../core/index.js";
+import { fit } from "./_lib.js";
+
+export const meta = {
+ name: "Ember burst",
+ desc: "A soft pop throws out a cloud of embers that slow, then float up and drift on the heat, twinkling and cooling from white to red as they wink out.",
+ tags: ["fire", "embers", "sparks", "burst", "ambient", "one-shot"],
+ size: [84, 100],
+ origin: [42, 78],
+ duration: 2.4,
+ loop: false,
+ fps: 30,
+ bg: "dark",
+ options: { palette: PAL.fire, count: 56, seed: 14 },
+};
+
+export function draw(p, t, o) {
+ const F = fit(ramp(o.palette)), S = o.seed;
+ const COOL = [F[7], F[6], F[5], F[4], F[3], F[2]];
+ // the pop: a quick ring of heat and a white heart
+ if (t < 0.12) {
+ const q = t / 0.12;
+ p.ring(0, 0, 3 + 9 * ease.outCubic(q), 1.5, F[5], 1 - q);
+ if (t < 0.05) p.circle(0, 0, 4, WHITE);
+ p.glow(0, 0, 22, F[5], 0.6 * (1 - q));
+ }
+ burst(o.count, S, (r, i) => {
+ const a = r.range(0, TAU), sp = r.range(35, 95), life = r.range(0.9, 2.2), born = r.range(0, 0.05);
+ const age = t - born;
+ if (age < 0 || age > life) return;
+ const q = age / life, vx = Math.cos(a) * sp, vy = Math.sin(a) * sp * 0.8;
+ // thrown out, dragged to a stop, then lifted by the heat and wandering
+ let [x, y] = fly(0, 0, vx, vy - 15, age, -r.range(70, 100), 3);
+ x += Math.sin(age * r.range(2, 4) + r.next() * TAU) * 3 * seg(age, 0.2, 0.8);
+ const c = COOL[Math.min(5, Math.floor(q * q * 6 + r.range(0, 0.6)))];
+ // late in life they twinkle and wink out
+ if (q > 0.55 && Math.sin(age * r.range(25, 40) + i) < -0.2) return;
+ if (age < 0.16) {
+ const [ux, uy] = flyV(vx, vy, age, 0, 3.2);
+ p.line(x, y, x - ux * 0.03, y - uy * 0.03, COOL[1]);
+ }
+ const big = i % 6 === 0 && q < 0.7;
+ if (big) p.rect(Math.round(x), Math.round(y), 2, 2, COOL[Math.min(5, Math.floor(q * 6) + 1)]);
+ p.px(x, y, c);
+ p.light(x, y, F[5], (big ? 0.6 : 0.4) * (1 - q));
+ });
+ p.glow(0, -8, 34, F[4], 0.3 * (1 - seg(t, 0, 1.2)));
+}
diff --git a/src/fx/fire/fire-breath.js b/src/fx/fire/fire-breath.js
new file mode 100644
index 0000000..d16ff17
--- /dev/null
+++ b/src/fx/fire/fire-breath.js
@@ -0,0 +1,52 @@
+import { PAL, RAMP, ramp, at, cycle, tileFbm, loopNoise, TAU, WHITE } from "../../core/index.js";
+import { fit } from "./_lib.js";
+
+export const meta = {
+ name: "Fire breath",
+ desc: "A roaring cone of fire blowing right: white-hot at the mouth, billows rolling out and widening, edges choking into smoke.",
+ tags: ["fire", "breath", "dragon", "cone", "directional", "loop"],
+ size: [104, 68],
+ origin: [4, 34],
+ duration: 0.8,
+ loop: true,
+ fps: 30,
+ bg: "dark",
+ options: { palette: PAL.fire, length: 92, spread: 0.25, seed: 7 },
+};
+
+export function draw(p, t, o) {
+ const F = fit(ramp(o.palette)), SM = RAMP.smoke, S = o.seed, D = meta.duration, ph = t / D, L = o.length, k = o.spread;
+ const FIRE = [F[2], F[3], F[4], F[5], F[6], F[7], WHITE];
+ const roar = 0.92 + 0.08 * loopNoise(ph, 1.2, S);
+ // smoke puffs boiling off the far end and the edges, rising as they go
+ cycle(t, D, 8, S + 2, (g) => g.range(0.45, 0.7), (age, life, r) => {
+ const q = age / life, side = r.sign(), x0 = r.range(L * 0.5, L * 0.85);
+ const x = x0 + age * r.range(30, 50), y = side * (2 + x0 * k * 0.8) - age * r.range(14, 24) + side * age * 6;
+ const rad = r.range(3, 4.5) * (q < 0.4 ? 0.5 + q * 1.25 : (1 - (q - 0.4) / 0.6) ** 0.6);
+ if (rad < 0.6 || x + rad > L + 6 || Math.abs(y) + rad > 32) return;
+ p.circle(x, y, rad, (d, a) => (d < 0.5 && a < -0.4 ? SM[3] : d < 0.8 ? SM[2] : SM[1]));
+ });
+ // the cone: heat falls off across and along it, big billows rolling outward with the noise
+ p.shade(0, -L * k - 6, L + 4, L * k + 6, (x, y) => {
+ const u = x / L;
+ if (u > 1.06) return;
+ const n = tileFbm(x * 0.085 - ph * 8, y * 0.14, 8, 0, S, 2);
+ const w = (2.2 + x * k) * roar * (1 + 0.35 * n);
+ const d = Math.abs(y + Math.sin(x * 0.07 - ph * TAU * 2) * u * 2.5) / w;
+ if (d > 1.3) return;
+ const heat = (1 - Math.pow(d, 1.6)) * (1.15 - u * 0.9) + n * (0.2 + u * 0.3) - Math.max(0, u - 0.85) * 2.5;
+ // the outer, cooler fringe chokes into smoke along the back half of the cone
+ if (heat < 0.1) return heat > -0.14 && u > 0.4 ? (heat > -0.03 && y < 0 ? SM[3] : SM[2]) : undefined;
+ return at(FIRE, heat);
+ });
+ // embers flung forward along the cone
+ cycle(t, D, 12, S + 5, (g) => g.range(0.3, 0.5), (age, life, r) => {
+ const q = age / life, a = r.range(-k, k) * 0.9, sp = r.range(110, 170);
+ const x = Math.cos(a) * sp * age, y = Math.sin(a) * sp * age - age * age * 30;
+ if (x > L + 4 || Math.abs(y) > 32) return;
+ p.px(x, y, q < 0.4 ? F[7] : q < 0.7 ? F[5] : F[3]);
+ p.light(x, y, F[5], 0.5 * (1 - q));
+ });
+ p.glowLine(4, 0, L * 0.75, 0, 22, F[4], 0.3 * roar);
+ p.glow(4, 0, 12, F[6], 0.45);
+}
diff --git a/src/fx/fire/fire-ring.js b/src/fx/fire/fire-ring.js
new file mode 100644
index 0000000..2a12410
--- /dev/null
+++ b/src/fx/fire/fire-ring.js
@@ -0,0 +1,66 @@
+import { PAL, ramp, at, seg, ease, rng, rand, burst, fly, hex, TAU, WHITE } from "../../core/index.js";
+import { fit, tongue, flames, pool } from "./_lib.js";
+import { oval, glowOval } from "../explosions/_lib.js";
+
+export const meta = {
+ name: "Fire ring",
+ desc: "A white flash at the feet, then a ring of flame bursts outward along the ground, burns down as it spreads and leaves a smouldering scorch.",
+ tags: ["fire", "ring", "nova", "spell", "ground", "area", "one-shot"],
+ size: [124, 56],
+ origin: [62, 40],
+ duration: 1.4,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ options: { palette: PAL.fire, radius: 52, height: 20, count: 30, seed: 12 },
+};
+
+const SQ = 0.2; // how flat the ring lies on the floor
+const CHAR = [hex("#141014"), hex("#2a1c1c")];
+
+export function draw(p, t, o) {
+ const F = fit(ramp(o.palette)), S = o.seed, Rm = o.radius, Hm = o.height, N = o.count;
+ const grow = ease.outCubic(seg(t, 0, 0.6)), R = 3 + (Rm - 3) * grow, end = 1 - seg(t, 1.05, 1.4);
+ // the scorch it leaves: a charred band inside the ring with a few embers in it, thinning away by dither
+ const sc = seg(t, 0.08, 0.3) * end;
+ if (sc > 0) {
+ p.shade(-R - 1, -R * SQ - 1, R + 1, R * SQ + 1, (x, y, out) => {
+ const d = Math.hypot(x / R, y / (R * SQ));
+ if (d > 0.98 || d < 0.55 - 0.3 * grow) return;
+ out.a = sc;
+ const ex = Math.floor(x / 2), ey = Math.floor(y);
+ const ember = rand(ex, ey, S) > 0.955 && t < 0.95 + rand(ex, ey, S + 2) * 0.3;
+ if (ember) return rand(ex, ey, S + 1) + Math.sin(t * 14 + ex) * 0.3 > 0.5 ? F[4] : F[3];
+ return d > 0.86 ? CHAR[1] : CHAR[0];
+ });
+ }
+ // tongues stand on the ring: tall as it bursts out, burning down as it spreads
+ const T = [];
+ const life = (1 - ease.inQuad(seg(t, 0.25, 1.15))) * ease.outCubic(seg(t, 0, 0.08));
+ for (let i = 0; i < N; i++) {
+ const r = rng(S, i), a = ((i + r.range(-0.3, 0.3)) / N) * TAU;
+ const h = Hm * r.range(0.55, 1) * life * (1 - 0.35 * Math.sin(a) * grow), x = Math.cos(a) * R, y = Math.sin(a) * R * SQ;
+ if (h < 2) continue;
+ T.push(tongue(x, y, r.range(2.6, 3.8) * (0.7 + 0.3 * life), h, t * 1.5, S + i * 7, { beat: 3, sway: 1.6, pulse: 0.25 }));
+ }
+ if (T.length) flames(p, T, { F, ph: t, seed: S, box: [-R - 5, -R * SQ - Hm - 6, R + 5, R * SQ + 2], scroll: 12 });
+ // the leading edge: a bright line racing out along the floor
+ if (grow < 0.98) oval(p, 0, 0, R + 1, (R + 1) * SQ, F[6], 1 - grow * 0.6);
+ // sparks skidding outward along the floor
+ burst(18, S + 3, (r) => {
+ const a = r.range(0, TAU), sp = r.range(70, 120), L = r.range(0.35, 0.6);
+ if (t > L) return;
+ const q = t / L, [x, y] = fly(0, 0, Math.cos(a) * sp, Math.sin(a) * sp * SQ - r.range(20, 50), t, 160, 2);
+ if (y > Math.abs(Math.sin(a)) * 10) return;
+ p.px(x, y, q < 0.4 ? F[7] : q < 0.7 ? F[5] : F[3]);
+ p.light(x, y, F[5], 0.5 * (1 - q));
+ });
+ // the flash at the centre: the hero frame
+ if (t < 0.07) {
+ p.ellipse(0, -1, 7 + 60 * t, 3 + 14 * t, WHITE);
+ p.glow(0, -2, 36, F[6], 0.8);
+ }
+ const L = (1 - seg(t, 0.05, 1.2)) * end;
+ glowOval(p, 0, 0, R, R * SQ, 6, F[4], 0.35 * L);
+ pool(p, 0, 0, R + 6, R * SQ + 6, F[4], 0.25 * L);
+}
diff --git a/src/fx/fire/fire-tornado.js b/src/fx/fire/fire-tornado.js
new file mode 100644
index 0000000..4fb3778
--- /dev/null
+++ b/src/fx/fire/fire-tornado.js
@@ -0,0 +1,58 @@
+import { PAL, RAMP, ramp, at, clamp, tileFbm, rng, wrap, TAU, WHITE } from "../../core/index.js";
+import { fit, pool } from "./_lib.js";
+
+export const meta = {
+ name: "Fire tornado",
+ desc: "A spinning column of fire: a funnel narrow at the ground and wide at the top, bright bands spiralling round it, embers orbiting, a swirl at its foot.",
+ tags: ["fire", "tornado", "vortex", "hazard", "spell", "loop"],
+ size: [64, 108],
+ origin: [32, 102],
+ duration: 1,
+ loop: true,
+ fps: 30,
+ bg: "ground",
+ options: { palette: PAL.fire, height: 86, seed: 10 },
+};
+
+export function draw(p, t, o) {
+ const F = fit(ramp(o.palette)), DU = RAMP.dust, S = o.seed, D = meta.duration, ph = t / D, H = o.height;
+ const FIRE = [F[2], F[3], F[4], F[5], F[6], F[7]];
+ const axis = (v) => Math.sin(v * 3.2 - ph * TAU) * 3 * v + Math.sin(v * 1.3 + ph * TAU) * 1.5 * v;
+ const width = (v) => 2.5 + 15 * Math.pow(v, 1.5);
+ // orbiting embers and grit: each circles the funnel and climbs, behind it on the far side
+ const orbit = (front) => {
+ for (let i = 0; i < 16; i++) {
+ const r = rng(S + 3, i), v = wrap(r.next() + ph, 1), a = r.range(0, TAU) + ph * TAU * 2 * (1 + (i % 2));
+ if (Math.sin(a) >= 0 !== front) continue;
+ const x = axis(v) + Math.cos(a) * (width(v) + 3), y = -v * H + Math.sin(a) * 2;
+ const ember = i % 3 !== 0;
+ p.px(x, y, ember ? (front ? F[6] : F[4]) : front ? DU[4] : DU[2]);
+ if (!ember) p.px(x + 1, y, front ? DU[3] : DU[1]);
+ if (ember && front) p.light(x, y, F[5], 0.4);
+ }
+ };
+ orbit(false);
+ // the funnel: bands of heat spiral round it, so it reads as turning
+ p.shade(-22, -H - 6, 22, 1, (x, y) => {
+ const v = -y / H;
+ if (v < 0 || v > 1.05) return;
+ const W = width(v), u = (x - axis(v)) / W;
+ if (Math.abs(u) > 1.2) return;
+ // bright and dark bands wrap round the funnel and slide sideways, so it spins
+ const th = Math.asin(clamp(u, -1, 1));
+ const band = Math.sin(th * 2.4 + y * 0.38 + ph * TAU * 3);
+ const n = tileFbm(x * 0.3, y * 0.2 + ph * 10, 0, 10, S, 2);
+ const heat = (1 - u * u) * 0.55 + band * 0.36 + n * 0.22 + 0.3 - v * 0.3 - Math.max(0, v - 0.92) * 4;
+ if (heat < 0.14) return;
+ return heat > 1.02 ? WHITE : at(FIRE, heat);
+ });
+ orbit(true);
+ // a ring of flame and grit swirling at its foot
+ for (let i = 0; i < 22; i++) {
+ const r = rng(S + 5, i), a = r.range(0, TAU) + ph * TAU * 2, rad = r.range(5, 12);
+ const x = Math.cos(a) * rad, y = Math.sin(a) * rad * 0.25 - 1;
+ p.px(x, y, i % 3 ? (Math.sin(a) > 0 ? F[5] : F[3]) : DU[3]);
+ }
+ pool(p, 0, 0, 22, 4, F[4], 0.35);
+ p.glowLine(axis(0.2), -H * 0.2, axis(0.8), -H * 0.8, 26, F[4], 0.28);
+}
diff --git a/src/fx/fire/fireball.js b/src/fx/fire/fireball.js
new file mode 100644
index 0000000..399c01f
--- /dev/null
+++ b/src/fx/fire/fireball.js
@@ -0,0 +1,61 @@
+import { PAL, RAMP, ramp, at, cycle, clamp, tileFbm, tileNoise, loopNoise, TAU, WHITE } from "../../core/index.js";
+import { fit } from "./_lib.js";
+
+export const meta = {
+ name: "Fireball",
+ desc: "A fireball flying right: a churning white-hot head, flames streaming back into a torn tail, smoke puffs and sparks left behind.",
+ tags: ["fire", "projectile", "spell", "directional", "loop"],
+ size: [88, 36],
+ origin: [68, 18],
+ duration: 0.6,
+ loop: true,
+ fps: 30,
+ bg: "dark",
+ options: { palette: PAL.fire, radius: 6.5, length: 48, seed: 6 },
+};
+
+export function draw(p, t, o) {
+ const F = fit(ramp(o.palette)), SM = RAMP.smoke, S = o.seed, D = meta.duration, ph = t / D, R = o.radius, L = o.length;
+ const body = [F[2], F[3], F[4], F[5], F[6], F[7]];
+ // smoke left behind: dark puffs that fall back fast, swell and shrink away
+ cycle(t, D, 4, S + 3, (g) => g.range(0.35, 0.5), (age, life, r) => {
+ const q = age / life, x = -L * 0.6 - age * r.range(60, 80), y = r.range(-3, 3) + Math.sin(age * 9 + r.next() * TAU) * 1.5 - age * 8;
+ const rad = r.range(2.2, 3.4) * (q < 0.4 ? 0.6 + q : 1.0 * (1 - (q - 0.4) / 0.6) ** 0.6);
+ if (rad < 0.7) return;
+ p.circle(x, y, rad, (d, a) => (d < 0.5 && a < -0.6 ? SM[3] : d < 0.8 ? SM[2] : SM[1]));
+ });
+ // the tail: a plume that narrows and cools away from the head, its noise streaming back and tearing
+ // licks off its edges
+ p.shade(-L - 2, -R - 7, R * 0.5, R + 7, (x, y) => {
+ const u = clamp(-x / L); // 0 at the head, 1 at the end of the tail
+ const wave = Math.sin(x * 0.16 + ph * TAU * 2) * 2 * u;
+ const w = (R + 1) * (1.04 - u) ** 0.6 + 0.5;
+ const d = Math.abs(y - wave) / w;
+ if (d > 1.5) return;
+ const n = tileFbm(x * 0.16 + ph * 10, y * 0.3, 10, 0, S, 2);
+ const heat = (1 - d * d) * (1.15 - u * 1.05) + n * (0.3 + u * 0.35);
+ if (heat < 0.1) return;
+ return at(body, heat * 0.95);
+ });
+ // the head: a lumpy ball churning inside, white-hot at the front
+ const wob = (a) => 1 + 0.12 * tileNoise((a / TAU) * 8 + ph * 8, ph * 2, 8, 2, S + 9);
+ p.shade(-R - 2, -R - 2, R + 2, R + 2, (x, y) => {
+ const a = Math.atan2(y, x), d = Math.hypot(x, y) / (R * wob(a));
+ if (d > 1) return;
+ const n = tileFbm(x * 0.4 + ph * 6, y * 0.4, 6, 0, S + 4, 2) * 0.22;
+ const core = Math.hypot(x - R * 0.3, y + R * 0.15) / R;
+ const h = 1.15 - core * 0.85 + n - (d > 0.82 ? 0.25 : 0);
+ return h > 0.95 ? WHITE : at(body, h);
+ });
+ // sparks peeling off the head and whipping back
+ cycle(t, D, 9, S + 5, (g) => g.range(0.2, 0.32), (age, life, r) => {
+ const q = age / life, a = r.range(-2.4, 2.4), x = Math.cos(a) * R * 0.8 - age * r.range(110, 160);
+ const y = Math.sin(a) * R * 0.8 + Math.sign(Math.sin(a)) * age * r.range(10, 30);
+ p.px(x, y, q < 0.4 ? F[7] : q < 0.7 ? F[5] : F[3]);
+ p.light(x, y, F[5], 0.5 * (1 - q));
+ });
+ const pulse = 0.9 + 0.1 * loopNoise(ph, 1.5, S);
+ p.glow(-4, 0, 26 * pulse, F[4], 0.32 * pulse);
+ p.glow(R * 0.3, 0, R + 4, F[6], 0.4);
+ p.glowLine(-L * 0.6, 0, 0, 0, 9, F[4], 0.18);
+}
diff --git a/src/fx/fire/flame-pillar.js b/src/fx/fire/flame-pillar.js
new file mode 100644
index 0000000..88b9c04
--- /dev/null
+++ b/src/fx/fire/flame-pillar.js
@@ -0,0 +1,74 @@
+import { PAL, RAMP, ramp, at, seg, ease, bump, clamp, fbm, stream, fly, rand, TAU, WHITE } from "../../core/index.js";
+import { fit, tongue, flames, pool } from "./_lib.js";
+
+export const meta = {
+ name: "Flame pillar",
+ desc: "The ground cracks and glows, a column of fire erupts white-hot, roars at full height spewing embers, then collapses back into the floor in smoke.",
+ tags: ["fire", "pillar", "eruption", "spell", "ground", "one-shot"],
+ size: [64, 116],
+ origin: [32, 108],
+ duration: 1.8,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ options: { palette: PAL.fire, height: 90, width: 8, seed: 11 },
+};
+
+export function draw(p, t, o) {
+ const F = fit(ramp(o.palette)), SM = RAMP.smoke, S = o.seed, H = o.height, W0 = o.width;
+ const FIRE = [F[2], F[3], F[4], F[5], F[6], F[7], WHITE];
+ const rise = ease.outExpo(seg(t, 0.2, 0.34)), fall = ease.inQuad(seg(t, 1.0, 1.4));
+ const top = H * rise * (1 - fall), hero = bump(t, 0.2, 0.42), live = 1 - seg(t, 1.45, 1.8);
+ const w = W0 * (1 + 0.5 * hero) * (1 - 0.45 * fall);
+ // smoke left where the column stood, rising and shrinking away
+ stream(t, 1.0, 1.4, 16, S + 4, (g) => g.range(0.3, 0.4), (age, life, r) => {
+ const q = age / life, x = r.range(-6, 6) + Math.sin(age * 5 + r.next() * TAU) * 2, y = -r.range(6, 40) - age * r.range(20, 34);
+ const rad = r.range(2.5, 4.5) * (q < 0.35 ? 0.6 + q : (1 - (q - 0.35) / 0.65) ** 0.7);
+ if (rad > 0.6) p.circle(x, y, rad, (d, a) => (d < 0.5 && a < -0.5 ? SM[4] : d < 0.8 ? SM[3] : SM[2]));
+ });
+ // the crack in the floor: glows before the eruption and cools after
+ const crack = seg(t, 0, 0.18) * (1 - seg(t, 1.3, 1.75));
+ if (crack > 0) {
+ p.shade(-15, -2, 15, 3, (x, y) => {
+ const dx = x / 14, dy = (y - 0.5) / 2.4, d = dx * dx + dy * dy;
+ if (d > crack) return;
+ const line = Math.abs(y - 0.5 - Math.sin(x * 0.9) * 0.9) < 0.6 && Math.abs(x) < 12 * crack;
+ return line ? (crack > 0.6 && rand(Math.floor(x), S) > 0.3 ? F[5] : F[4]) : d > 0.6 * crack ? F[1] : F[0];
+ });
+ }
+ // little flames lick at the crack before it goes, and burn out after the collapse
+ const lick = Math.max(seg(t, 0.05, 0.2) * (1 - seg(t, 0.2, 0.3)), seg(t, 1.3, 1.4) * (1 - seg(t, 1.45, 1.75)));
+ if (lick > 0.05) {
+ const T = [-7, -2, 3, 8].map((x, i) => tongue(x, 0, 2.6, (6 + (i % 2) * 3) * lick, t, S + i * 9, { beat: 3, sway: 1, pulse: 0.2 }));
+ flames(p, T, { F, ph: t, seed: S + 2, box: [-12, -14, 12, 1], scroll: 6 });
+ }
+ // the column: a flared foot, a straight roaring shaft and a crown, white-hot on the hero frames,
+ // tearing apart as it sinks back into the ground
+ if (top > 1.5) {
+ p.shade(-w * 2.2, -top - 10, w * 2.2, 1, (x, y) => {
+ const v = -y / top;
+ if (v < 0 || v > 1.15) return;
+ const prof = v < 0.12 ? 1 + (0.12 - v) * 4 : v > 0.8 ? Math.sqrt(clamp(1 - ((v - 0.8) / 0.33) ** 2)) : 1;
+ const n = fbm(x * 0.26, y * 0.11 + t * 14, S, 3);
+ const sway = Math.sin(v * 5 + t * 18) * 1.2 * v;
+ const d = Math.abs(x - sway) / (w * prof * (1 + 0.25 * n));
+ if (d > 1.35) return;
+ const heat = (1 - d * d) * (0.98 - v * 0.3) + n * (0.34 + fall * 0.6) + hero * 0.45 - fall * 0.25;
+ if (heat < 0.12) return;
+ return at(FIRE, heat);
+ });
+ }
+ // embers spewed out of the crown, arcing down
+ stream(t, 0.26, 1.1, 34, S + 3, (g) => g.range(0.45, 0.7), (age, life, r) => {
+ const q = age / life, x0 = r.range(-w, w), y0 = -H * r.range(0.55, 0.95);
+ const [x, y] = fly(x0, y0, r.range(18, 42) * Math.sign(x0 || 1), -r.range(30, 70), age, 120, 0.8);
+ if (y > -1) return;
+ p.px(x, y, q < 0.35 ? F[7] : q < 0.7 ? F[5] : F[3]);
+ p.light(x, y, F[5], 0.5 * (1 - q));
+ });
+ // light: the floor glows first, then the column floods everything and lets go as it falls
+ const L = Math.max(crack * 0.4, (top / H) * (0.8 + 0.4 * hero)) * live;
+ pool(p, 0, 0, 22, 5, F[4], 0.45 * L);
+ if (top > 2) p.glowLine(0, -2, 0, -top * 0.9, 26, F[4], 0.32 * L);
+ p.glow(0, -4, 14, F[6], 0.4 * L);
+}
diff --git a/src/fx/fire/flamethrower.js b/src/fx/fire/flamethrower.js
new file mode 100644
index 0000000..f54ce2d
--- /dev/null
+++ b/src/fx/fire/flamethrower.js
@@ -0,0 +1,66 @@
+import { PAL, RAMP, ramp, at, cycle, smooth, wrap, tileFbm, fly, TAU, WHITE, hex } from "../../core/index.js";
+import { fit } from "./_lib.js";
+
+export const meta = {
+ name: "Flamethrower",
+ desc: "A pressurised jet shooting right: a blue-white core at the nozzle, surges racing down a drooping stream, a sputter, burning drips.",
+ tags: ["fire", "flamethrower", "jet", "weapon", "directional", "loop"],
+ size: [112, 48],
+ origin: [4, 20],
+ duration: 1.2,
+ loop: true,
+ fps: 30,
+ bg: "dark",
+ options: { palette: PAL.fire, length: 96, seed: 8 },
+};
+
+const BLUE = [hex("#2438a8"), hex("#4f7cff"), hex("#b8dcff")];
+
+export function draw(p, t, o) {
+ const F = fit(ramp(o.palette)), SM = RAMP.smoke, S = o.seed, D = meta.duration, ph = t / D, L = o.length;
+ const FIRE = [F[2], F[3], F[4], F[5], F[6], F[7], WHITE];
+ const V = 190; // how fast the stream travels, px/s
+ // nozzle pressure as a function of when the fuel left it: steady surges, and a short sputter once a loop
+ const pressure = (e) => {
+ const q = wrap(e / D, 1);
+ const surge = 0.82 + 0.18 * Math.sin(q * TAU * 4);
+ const sput = 1 - 0.85 * smooth(0.55, 0.6, q) * (1 - smooth(0.66, 0.72, q));
+ return surge * sput;
+ };
+ // the stream droops under its own weight, then the slowing tip curls up as the burning gas rises
+ const droop = (x) => x * x * 0.0016 - Math.max(0, x - L * 0.62) ** 2 * 0.012;
+ // smoke boiling off the end of the stream
+ cycle(t, D, 7, S + 2, (g) => g.range(0.45, 0.65), (age, life, r) => {
+ const q = age / life, x = L * r.range(0.75, 0.95) + age * r.range(10, 25), y = droop(L * 0.85) - 6 - age * r.range(16, 26);
+ const rad = r.range(3, 4.5) * (q < 0.4 ? 0.5 + q * 1.25 : (1 - (q - 0.4) / 0.6) ** 0.6);
+ if (rad < 0.6 || y - rad < -17) return;
+ p.circle(x, y, rad, (d, a) => (d < 0.5 && a < -0.4 ? SM[3] : d < 0.8 ? SM[2] : SM[1]));
+ });
+ // the jet: narrow and hard at the nozzle, swelling and churning as it slows, each slice as strong as the
+ // pressure was when it left the nozzle, so surges and the sputter travel down the stream
+ p.shade(0, -16, L + 6, 22, (x, y) => {
+ const u = x / L;
+ if (u > 1.05) return;
+ const s = pressure(t - x / V), n = tileFbm(x * 0.1 - ph * 24, y * 0.22, 24, 0, S, 2);
+ const w = (0.8 + x * 0.1) * (0.35 + 0.65 * s) * (1 + 0.3 * n * u * 2) * (1 + Math.max(0, u - 0.6) * 1.6);
+ const d = Math.abs(y - droop(x)) / w;
+ if (d > 1.3) return;
+ if (x < 13 && d < 0.55 && s > 0.4) return x < 4 ? BLUE[2] : d < 0.25 ? WHITE : BLUE[1];
+ if (x < 8 && d < 1) return BLUE[0];
+ const heat = (1 - d * d) * (1.1 - u * 0.8) * (0.55 + 0.45 * s) + n * (0.2 + u * 0.3) - Math.max(0, u - 0.9) * 3;
+ if (heat < 0.1) return;
+ return at(FIRE, heat * 1.02);
+ });
+ // burning fuel dripping off the stream and falling away
+ cycle(t, D, 8, S + 5, (g) => g.range(0.3, 0.45), (age, life, r) => {
+ const q = age / life, x0 = r.range(L * 0.3, L * 0.8);
+ const [x, y] = fly(x0, droop(x0) + 2, V * 0.35, r.range(-10, 10), age, 260, 1);
+ if (y > 23) return;
+ p.px(x, y, q < 0.4 ? F[6] : q < 0.75 ? F[5] : F[3]);
+ if (q < 0.5) p.px(x, y - 1, F[4]);
+ p.light(x, y, F[5], 0.5 * (1 - q));
+ });
+ const s0 = pressure(t);
+ p.glowLine(6, 0, L * 0.8, droop(L * 0.8), 18, F[4], 0.28);
+ p.glow(2, 0, 10, BLUE[1], 0.5 * s0);
+}
diff --git a/src/fx/fire/ground-fire.js b/src/fx/fire/ground-fire.js
new file mode 100644
index 0000000..923fe31
--- /dev/null
+++ b/src/fx/fire/ground-fire.js
@@ -0,0 +1,48 @@
+import { PAL, ramp, rand, rng, loopNoise, clamp, hex, TAU } from "../../core/index.js";
+import { fit, tongue, flames, embers, pool } from "./_lib.js";
+
+export const meta = {
+ name: "Ground fire",
+ desc: "A patch of burning ground: a charred scorch with glowing cracks and a row of low flames that dance up, shrink away and flare again.",
+ tags: ["fire", "ground", "hazard", "area", "loop"],
+ size: [72, 40],
+ origin: [36, 32],
+ duration: 1.6,
+ loop: true,
+ fps: 30,
+ bg: "ground",
+ options: { palette: PAL.fire, width: 26, height: 15, count: 11, seed: 4 },
+};
+
+const CHAR = [hex("#100b0e"), hex("#1f1416"), hex("#2e1d1c")];
+
+export function draw(p, t, o) {
+ const F = fit(ramp(o.palette)), S = o.seed, D = meta.duration, ph = t / D, W = o.width, H = o.height;
+ const flick = 0.85 + 0.15 * loopNoise(ph, 2, S + 5);
+ // the scorch: a charred oval on the floor, cracks glowing and dimming
+ p.shade(-W - 4, -2, W + 4, 3, (x, y) => {
+ const dx = x / (W + 3), dy = (y - 0.5) / 2.6, d = dx * dx + dy * dy;
+ if (d > 1) return;
+ const crack = rand(Math.floor(x / 2), Math.floor(y), S) > 0.78 && d < 0.75;
+ if (crack) {
+ const g = 0.5 + 0.5 * Math.sin(ph * TAU * 2 + x * 0.7);
+ return g > 0.66 ? F[4] : g > 0.3 ? F[3] : F[2];
+ }
+ return d > 0.8 ? CHAR[2] : d > 0.4 ? CHAR[1] : CHAR[0];
+ });
+ // low tongues along the patch, each breathing on its own: some sink out of sight, then flare back up
+ // a low lick of flame along the whole patch keeps it reading as one fire
+ const T = [tongue(0, 1, W, 6, ph, S + 77, { beat: 2, sway: 1, pulse: 0.2 })];
+ for (let i = 0; i < o.count; i++) {
+ const r = rng(S, i), x = -W + 2 + ((2 * W - 4) * (i + r.range(0.2, 0.8))) / o.count;
+ const lift = clamp(0.5 + 0.8 * loopNoise(ph, 1.3, S + i * 7));
+ const h = H * r.range(0.55, 1) * lift * (1 - 0.45 * Math.abs(x / W) ** 2);
+ if (h < 2.5) continue;
+ T.push(tongue(x, 0, r.range(3.2, 4.6) * (0.65 + 0.35 * lift), h, ph, S + i * 13, { beat: 2 + (i % 3), sway: 1.6, pulse: 0.1 }));
+ }
+ flames(p, T, { F, ph, seed: S, box: [-W - 4, -H * 1.2 - 4, W + 4, 1], scroll: 12, nx: 0.42, ny: 0.3 });
+ embers(p, t, D, 7, S + 9, [F[6], F[5], F[3]], F[4], { x: 0, y: -H * 0.6, w: W * 0.8, rise: [12, 20], life: [0.6, 1], wob: 2 });
+ // light: a low, wide pool and a soft glow
+ pool(p, 0, 0, W + 10, 6, F[4], 0.38 * flick);
+ p.glow(0, -H * 0.4, W + 6, F[4], 0.18 * flick);
+}
diff --git a/src/fx/fire/ignite.js b/src/fx/fire/ignite.js
new file mode 100644
index 0000000..9341db3
--- /dev/null
+++ b/src/fx/fire/ignite.js
@@ -0,0 +1,69 @@
+import { PAL, RAMP, ramp, seg, ease, burst, fly, clamp, WHITE } from "../../core/index.js";
+import { fit, tongue, flames, pool } from "./_lib.js";
+
+export const meta = {
+ name: "Ignite",
+ desc: "A spark sputters twice and catches: the flame whooshes up white-hot, settles into a lively burn, then dwindles out in a curl of smoke.",
+ tags: ["fire", "ignite", "spark", "burn", "status", "one-shot"],
+ size: [44, 64],
+ origin: [22, 56],
+ duration: 1.8,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ options: { palette: PAL.fire, height: 24, seed: 13 },
+};
+
+// the flame's height over time: nothing, a whoosh that overshoots, a steady burn, then out
+function size(t) {
+ if (t < 0.36) return 0;
+ if (t < 0.56) return 0.1 + 1.25 * ease.outBack(seg(t, 0.36, 0.56), 2.2) * 1.1;
+ if (t < 0.75) return 1.47 - 0.47 * ease.inOutQuad(seg(t, 0.56, 0.75));
+ return 1 - ease.inQuad(seg(t, 0.95, 1.5));
+}
+
+export function draw(p, t, o) {
+ const F = fit(ramp(o.palette)), SM = RAMP.smoke, S = o.seed, H = o.height;
+ // two sputtering sparks before it catches: a white pixel, a crackle of bits
+ for (const [t0, n, k] of [[0.04, 4, 1], [0.2, 6, 2], [0.33, 7, 3]]) {
+ const age = t - t0;
+ if (age < 0 || age > 0.24) continue;
+ if (age < 0.06) {
+ p.px(0, -1, WHITE), p.px(-1, -1, F[6]), p.px(1, -1, F[6]), p.px(0, -2, F[6]);
+ p.glow(0, -1, 10, F[5], 0.6);
+ }
+ burst(n, S + k, (r) => {
+ const a = -Math.PI / 2 + r.range(-1.3, 1.3), sp = r.range(30, 60), L = r.range(0.12, 0.24);
+ if (age > L) return;
+ const [x, y] = fly(0, -1, Math.cos(a) * sp, Math.sin(a) * sp, age, 200, 1);
+ if (y > 0) return;
+ p.px(x, y, age / L < 0.5 ? F[7] : F[5]);
+ p.light(x, y, F[5], 0.4);
+ });
+ }
+ // the flame
+ const s = size(t), hot = clamp(1 - seg(t, 0.4, 0.62)) * (t > 0.36 ? 1 : 0);
+ if (s > 0.04) {
+ const T = [
+ tongue(0, 0, 5.5 * Math.min(1, 0.4 + s * 0.6), H * s, t / 0.6, S, { beat: 2, sway: 2.2 }),
+ tongue(-3.5, 0, 3.4 * Math.min(1, s), H * 0.55 * s, t / 0.6, S + 11, { beat: 3, sway: 1.6 }),
+ tongue(3.5, 0, 3.4 * Math.min(1, s), H * 0.62 * s, t / 0.6, S + 23, { beat: 3, sway: 1.6 }),
+ ];
+ flames(p, T, { F, ph: t, seed: S, box: [-12, -H * 1.6 - 8, 12, 1], scroll: 20, tear: 1 - hot * 0.6 });
+ // the whoosh: the heart goes white for a moment as it catches
+ if (hot > 0.55) p.ellipse(0, -H * s * 0.22, 1.6 * s, H * s * 0.18, WHITE);
+ }
+ // a curl of smoke as it goes out: a few puffs that wind up, swell a little and shrink away
+ for (let i = 0; i < 4; i++) {
+ const age = t - 1.14 - i * 0.08, life = 0.4;
+ if (age < 0 || age > life) continue;
+ const q = age / life, x = Math.sin(q * 4 + i * 1.3) * (1.5 + q * 3), y = -5 - age * 46;
+ const rad = (q < 0.3 ? 1.2 + q * 4.5 : 2.55 * (1 - (q - 0.3) / 0.7)) * (1 - i * 0.1);
+ if (rad > 0.55) p.circle(x, y, rad, (d, a) => (d < 0.5 && a < -0.5 ? SM[4] : d < 0.85 ? SM[3] : SM[2]));
+ }
+ // light swells with the flame
+ const L = Math.min(1.3, s) + hot * 0.4;
+ p.glow(0, -H * 0.4 * Math.max(0.3, s), 26 * Math.max(0.4, Math.min(1.2, s)), F[4], 0.28 * L);
+ p.glow(0, -4, 9, F[6], 0.3 * L);
+ pool(p, 0, 0, 16, 3, F[4], 0.3 * Math.min(1, L));
+}
diff --git a/src/fx/fire/inferno-wall.js b/src/fx/fire/inferno-wall.js
new file mode 100644
index 0000000..7cc7586
--- /dev/null
+++ b/src/fx/fire/inferno-wall.js
@@ -0,0 +1,47 @@
+import { PAL, RAMP, ramp, at, rng, cycle, loopNoise, clamp } from "../../core/index.js";
+import { fit, tongue, flames, embers, pool } from "./_lib.js";
+import { billow } from "../explosions/_lib.js";
+
+export const meta = {
+ name: "Inferno wall",
+ desc: "A wide wall of tall fire: a white-hot base, a ragged crest of tongues tearing upward, sparks and smoke pouring off the top.",
+ tags: ["fire", "wall", "barrier", "hazard", "area", "wide", "loop"],
+ size: [136, 96],
+ origin: [68, 90],
+ duration: 1.2,
+ loop: true,
+ fps: 30,
+ bg: "ground",
+ options: { palette: PAL.fire, width: 58, height: 52, seed: 5 },
+};
+
+export function draw(p, t, o) {
+ const F = fit(ramp(o.palette)), SM = RAMP.smoke, S = o.seed, D = meta.duration, ph = t / D, W = o.width, H = o.height;
+ const flick = 0.85 + 0.15 * loopNoise(ph, 2, S + 5);
+ // thick dark smoke rolling up off the crest, behind the fire: puffs that swell, rise and thin away
+ const puffs = [];
+ cycle(t, D, 20, S + 30, 1.2, (age, life, r) => {
+ const q = age / life;
+ puffs.push({ x: r.range(-W * 0.9, W * 0.9) + q * r.range(-5, 5), y: -H * 0.45 - age * r.range(20, 26), r: r.range(8, 12) * (0.55 + 0.6 * q), v: 1 - q * q * q });
+ });
+ const SMK = [SM[0], SM[1], SM[2], SM[3]];
+ billow(p, puffs, (v, lit, x, y, out) => {
+ if (v < 0.1) return;
+ out.a = clamp((v - 0.1) * 5);
+ return at(SMK, 0.15 + lit * 0.12 + v * 0.55);
+ });
+ // a row of tall tongues over a low band of heat that runs the whole width
+ const T = [tongue(0, 2, W + 2, H * 0.34, ph, S + 99, { beat: 2, sway: 2, pulse: 0.06 })];
+ const n = Math.round(W / 4.4);
+ for (let i = 0; i < n; i++) {
+ const r = rng(S, i), x = -W + 4 + ((2 * W - 8) * (i + r.range(0.25, 0.75))) / n;
+ const edge = 1 - Math.pow(Math.abs(x) / W, 3) * 0.6;
+ T.push(tongue(x, 0, r.range(5, 7.5), H * r.range(0.55, 1) * edge, ph, S + i * 17, { beat: 2 + (i % 2), sway: 3.2, pulse: 0.22 }));
+ }
+ flames(p, T, { F, ph, seed: S, box: [-W - 6, -H - 14, W + 6, 2], scroll: 12, tear: 1.15 });
+ embers(p, t, D, 18, S + 7, [F[7], F[5], F[3]], F[4], { x: 0, y: -H * 0.7, w: W, rise: [22, 34], life: [0.4, 0.75], wob: 4 });
+ // light along the wall and on the floor in front of it
+ p.glowLine(-W, -H * 0.35, W, -H * 0.35, 34, F[4], 0.3 * flick);
+ p.glowLine(-W + 8, -6, W - 8, -6, 10, F[6], 0.25 * flick);
+ pool(p, 0, 0, W + 8, 5, F[4], 0.4 * flick);
+}
diff --git a/src/fx/fire/meteor.js b/src/fx/fire/meteor.js
new file mode 100644
index 0000000..7969672
--- /dev/null
+++ b/src/fx/fire/meteor.js
@@ -0,0 +1,96 @@
+import { PAL, RAMP, ramp, at, seg, ease, clamp, burst, stream, fbm, noise2, rand, lerp, WHITE, hex } from "../../core/index.js";
+import { fit, pool } from "./_lib.js";
+import { billow, sparks, debris, shock, flash } from "../explosions/_lib.js";
+
+export const meta = {
+ name: "Meteor",
+ desc: "A burning rock streaks down from the top left trailing fire and smoke, slams into the ground in a white flash, throws rock and flame, leaves a glowing crater.",
+ tags: ["fire", "meteor", "impact", "spell", "ground", "one-shot"],
+ size: [128, 116],
+ origin: [84, 98],
+ duration: 1.8,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ options: { palette: PAL.fire, seed: 16 },
+};
+
+const ROCK = [hex("#160f14"), hex("#33242a"), hex("#54393a")];
+const HIT = 0.38, X0 = -70, Y0 = -84;
+
+export function draw(p, t, o) {
+ const F = fit(ramp(o.palette)), SM = RAMP.smoke, DU = RAMP.dust, S = o.seed;
+ const FIRE = [F[2], F[3], F[4], F[5], F[6], F[7], WHITE];
+ const L0 = Math.hypot(X0, Y0), dx = -X0 / L0, dy = -Y0 / L0; // the direction of travel
+ const pos = (tt) => { const s = Math.pow(clamp(tt / HIT), 1.2); return [lerp(X0, 0, s), lerp(Y0, -3, s)]; };
+ // ---- smoke left along the path: puffs that hang, swell and thin away
+ stream(t, 0.04, HIT, 70, S + 1, (g) => g.range(0.4, 0.6), (age, life, r) => {
+ const [x, y] = pos(t - age), q = age / life, rad = r.range(2.6, 3.8) * (q < 0.3 ? 0.6 + q * 1.4 : 1.02 * (1 - (q - 0.3) / 0.7) ** 0.6);
+ if (rad > 0.6) p.circle(x + r.range(-2, 2), y - age * 8, rad, (d, a) => (d < 0.5 && a < -0.5 ? SM[3] : d < 0.85 ? SM[2] : SM[1]));
+ });
+ if (t < HIT) {
+ const [mx, my] = pos(t);
+ // the trail: fire streaming back from the rock, cooling and tearing as it goes
+ const TL = 42 * seg(t, 0, 0.14) + 2; // the trail grows in as the rock enters
+ p.shade(mx - TL - 4, my - TL - 4, mx + 6, my + 6, (x, y) => {
+ const rx = x - mx, ry = y - my, a = -(rx * dx + ry * dy), c = rx * -dy + ry * dx;
+ if (a < -2 || a > TL) return;
+ const u = clamp(a / TL), w = 5 * (1.02 - u) ** 0.6 + 0.4, n = fbm(a * 0.18 - t * 30, c * 0.35, S, 2);
+ const d = Math.abs(c + Math.sin(a * 0.25 - t * 30) * u * 1.5) / w;
+ if (d > 1.4) return;
+ const heat = (1 - d * d) * (1.15 - u * 1.05) + n * (0.3 + u * 0.3);
+ return heat < 0.1 ? undefined : at(FIRE, heat * 0.95);
+ });
+ // the rock: dark, cracked, white-hot along its leading face
+ p.shade(mx - 5, my - 5, mx + 5, my + 5, (x, y) => {
+ const rx = x - mx, ry = y - my, d = Math.hypot(rx, ry) / (4.2 + noise2(Math.atan2(ry, rx) * 2, 0, S) * 0.6);
+ if (d > 1) return;
+ const face = (rx * dx + ry * dy) / 4.2;
+ if (face > 0.45 && d > 0.55) return face > 0.7 ? WHITE : F[6];
+ if (rand(Math.floor(x), Math.floor(y), S + 2) > 0.8) return F[4];
+ return d > 0.8 ? ROCK[0] : rx + ry < 0 ? ROCK[2] : ROCK[1];
+ });
+ p.glow(mx, my, 16, F[4], 0.45);
+ p.glow(mx + dx * 2, my + dy * 2, 7, F[6], 0.4);
+ return;
+ }
+ const age = t - HIT;
+ // ---- the crater: a dark bowl in the floor with a molten rim that cools and fades
+ const cool = seg(age, 0.1, 1.2), gone = 1 - seg(t, 1.45, 1.8);
+ p.shade(-16, -2, 16, 3, (x, y, out) => {
+ const d = Math.hypot(x / 15, (y - 0.5) / 2.6);
+ if (d > 1) return;
+ out.a = gone;
+ if (d > 0.72) return at([F[5], F[4], F[3], F[2], ROCK[1]], cool + (rand(Math.floor(x), S) - 0.5) * 0.3);
+ return d > 0.4 ? ROCK[1] : ROCK[0];
+ });
+ // ---- debris rocks thrown out of the crater, bouncing on the floor
+ debris(p, age, 10, S + 3, [ROCK[2], ROCK[1]], { a: -Math.PI / 2, spread: 1.1, sp: [55, 110], g: 340, life: [0.9, 1.3], size: [1, 3], floor: 0 });
+ debris(p, age, 14, S + 4, [DU[4], DU[3]], { a: -Math.PI / 2, spread: 1.3, sp: [40, 100], g: 320, life: [0.6, 1], size: [1, 1], floor: 0 });
+ // ---- the fireball: thrown up and forward with the rock's momentum, cooling into rising smoke
+ const fire = [], smoke = [];
+ burst(13, S + 5, (r, i) => {
+ const a = -Math.PI / 2 + r.range(-1.25, 1.25) + 0.2, reach = (i < 2 ? r.range(0, 4) : r.range(7, 20)) * ease.outCubic(seg(age, 0, 0.3));
+ const L = r.range(0.8, 1.2), q = clamp(age / L);
+ if (q >= 1) return;
+ const x = Math.cos(a) * reach * 1.3, y = -4 + Math.sin(a) * reach * 0.9 - age * age * 22, r0 = r.range(6, 10) * (0.6 + 0.6 * ease.outCubic(seg(age, 0, 0.25)));
+ fire.push({ x, y, r: r0 * (1 - 0.5 * seg(q, 0.15, 0.6)), v: 1 - seg(q, 0.05, 0.6) });
+ smoke.push({ x, y: y - q * q * 18, r: r0 * (1 + 0.8 * q), v: seg(q, 0.1, 0.35) * (1 - seg(q, 0.6, 1)) });
+ });
+ billow(p, smoke, (v, lit, x, y, out) => {
+ if (v < 0.06) return;
+ out.a = clamp(v * 4);
+ return at(SM.slice(1, 6), 0.25 + lit * 0.3 + v * 0.35 + noise2(x * 0.4, y * 0.4, S) * 0.1);
+ });
+ billow(p, fire, (v, lit, x, y, out) => {
+ if (v < 0.08) return;
+ out.k = v * 0.25;
+ return at(FIRE, v * 0.95 + lit * 0.12 + noise2(x * 0.5, y * 0.5, S + 1) * 0.1);
+ });
+ sparks(p, age, 18, S + 6, [F[7], F[5], F[3]], { floor: 0, y: -3, a: -Math.PI / 2, spread: 1.45, sp: [80, 150], life: [0.35, 0.6], g: 200, up: 20 });
+ shock(p, age, 0, 0, 0, 0.28, 6, 36, F[5], F[4], { sy: 0.16, k: 0.3 });
+ flash(p, age, 0, -4, 0, 0.07, 9, F[6], { R: 34, k: 0.9, grow: 50 });
+ const L = 1 - seg(age, 0, 0.7);
+ p.glow(0, -14, 38, F[5], 0.5 * L * L);
+ pool(p, 0, 0, 30, 5, F[4], 0.45 * (1 - cool) * gone);
+}
diff --git a/src/fx/fire/molotov.js b/src/fx/fire/molotov.js
new file mode 100644
index 0000000..8c75c64
--- /dev/null
+++ b/src/fx/fire/molotov.js
@@ -0,0 +1,97 @@
+import { PAL, RAMP, ramp, at, seg, ease, burst, stream, rng, rand, fly, WHITE, hex } from "../../core/index.js";
+import { fit, tongue, flames, pool } from "./_lib.js";
+import { billow, hop } from "../explosions/_lib.js";
+
+export const meta = {
+ name: "Molotov",
+ desc: "A lit bottle tumbles in and shatters: glass flies, burning fuel splashes and races along the floor, flares up, then burns down to smoke and a scorch.",
+ tags: ["fire", "molotov", "grenade", "splash", "area", "ground", "one-shot"],
+ size: [108, 68],
+ origin: [40, 58],
+ duration: 2.8,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ options: { palette: PAL.fire, reach: 34, seed: 15 },
+};
+
+const GLASS = [hex("#123a2a"), hex("#2a7a4e"), hex("#5cc48a"), hex("#c8f5d8")];
+const RAG = hex("#c8b08a"), CHAR = [hex("#110c10"), hex("#231719")];
+const HIT = 0.32;
+
+export function draw(p, t, o) {
+ const F = fit(ramp(o.palette)), SM = RAMP.smoke, S = o.seed, R = o.reach;
+ // ---- the throw: a bottle tumbling in on an arc, its rag alight
+ if (t < HIT) {
+ const [bx, by] = fly(-32, -42, 100, 83, t, 300), a = -0.7 + t * 15;
+ const dx = Math.cos(a), dy = Math.sin(a);
+ p.beam(bx - dx * 2.5, by - dy * 2.5, bx + dx * 1.5, by + dy * 1.5, 4.2, (u, v) => (v > 0.7 ? GLASS[0] : u < 0.5 ? GLASS[1] : GLASS[2]));
+ p.beam(bx + dx * 1.5, by + dy * 1.5, bx + dx * 4.5, by + dy * 4.5, 2, GLASS[1]);
+ p.px(bx - dx * 0.5 - dy, by - dy * 0.5 + dx, GLASS[3]);
+ const rx = bx + dx * 5.5, ry = by + dy * 5.5;
+ p.px(rx, ry, RAG);
+ // the rag's flame trails behind the throw
+ p.px(rx - 1, ry - 1, F[6]), p.px(rx - 2, ry - 1, F[5]), p.px(rx - 2, ry - 2, F[4]), p.px(rx - 3, ry - 2, F[3]);
+ p.glow(rx, ry, 8, F[5], 0.4);
+ return;
+ }
+ const age = t - HIT, spread = ease.outCubic(seg(age, 0, 0.45));
+ const xl = -14 * spread, xr = R * spread, burnDown = seg(t, 1.5, 2.55), fadeOut = 1 - seg(t, 2.3, 2.8);
+ // ---- the scorch and the burning puddle on the floor
+ p.shade(xl - 3, -2, xr + 3, 3, (x, y, out) => {
+ const u = (x - (xl + xr) / 2) / ((xr - xl) / 2 + 3), dy = (y - 0.5) / 2.2;
+ if (u * u + dy * dy > 1) return;
+ out.a = fadeOut;
+ const wet = 1 - burnDown;
+ if (rand(Math.floor(x / 2), Math.floor(y), S) > 0.7 && wet > 0.2) return rand(Math.floor(x), S + 1) > 0.5 * wet ? F[3] : F[4];
+ return u * u + dy * dy > 0.6 ? CHAR[1] : CHAR[0];
+ });
+ // ---- flames ride the spreading fuel: each catches as the splash reaches it, flares, then burns out
+ const T = [];
+ for (let i = 0; i < 11; i++) {
+ const r = rng(S, i), fx = -12 + (R + 10) * ((i + r.range(0.1, 0.9)) / 11), reachAt = HIT + Math.abs(fx) / 110;
+ const k = seg(t, reachAt, reachAt + 0.12) * (1 - ease.inQuad(seg(t, r.range(1.2, 1.9), r.range(2.1, 2.5))));
+ if (fx < xl || fx > xr || k <= 0.05) continue;
+ const flare = 1 + 0.7 * (1 - seg(t, reachAt + 0.1, reachAt + 0.55));
+ const h = r.range(6, 22) * k * flare * (1 - Math.abs(fx - R * 0.3) / (R * 1.5));
+ if (h < 2) continue;
+ T.push(tongue(fx, 0, r.range(2.6, 5) * Math.min(1, 0.4 + k), h, t / 0.7, S + i * 11, { beat: 2 + (i % 3), sway: 2.2, pulse: 0.3 }));
+ }
+ if (T.length) flames(p, T, { F, ph: t, seed: S, box: [xl - 6, -40, xr + 6, 1], scroll: 14 });
+ // ---- the smash: a whoosh of fire, glass shards, splashing fuel
+ if (age < 0.5) {
+ const puffs = [];
+ burst(6, S + 3, (r, i) => {
+ const a = -Math.PI / 2 + r.range(-1.3, 1.3), reach = r.range(3, 9) * ease.outCubic(seg(age, 0, 0.2));
+ const q = seg(age, 0, r.range(0.3, 0.45));
+ puffs.push({ x: Math.cos(a) * reach + age * 20, y: -3 + Math.sin(a) * reach * 0.6 - age * 30, r: r.range(4, 6.5) * (1 - q * 0.6), v: 1 - q });
+ });
+ billow(p, puffs, (v, lit) => (v < 0.1 ? undefined : at([F[3], F[4], F[5], F[6], F[7], WHITE], v * 1.1 + lit * 0.15)));
+ }
+ burst(12, S + 4, (r) => {
+ const a = -Math.PI / 2 + r.range(-1.4, 1.4), sp = r.range(50, 110), L = r.range(0.4, 0.7);
+ if (age > L) return;
+ const [x, y, rest] = hop(0, -2, Math.cos(a) * sp + 15, Math.sin(a) * sp, age, 320, 0, 0.3, 0.5);
+ p.px(x, rest ? -1 : y, r.next() < 0.4 ? GLASS[3] : GLASS[2]);
+ });
+ burst(14, S + 5, (r) => {
+ const a = -Math.PI / 2 + r.range(-1.2, 1.3), sp = r.range(40, 95), L = r.range(0.35, 0.6);
+ if (age > L) return;
+ const [x, y] = fly(0, -2, Math.cos(a) * sp + 30, Math.sin(a) * sp, age, 300, 0.6);
+ if (y > -1) return;
+ const q = age / L;
+ p.px(x, y, q < 0.4 ? F[6] : F[5]), p.px(x, y + 1, F[4]);
+ p.light(x, y, F[5], 0.5 * (1 - q));
+ });
+ // ---- smoke rolling up off the fire as it burns
+ stream(t, 0.5, 2.2, 9, S + 6, (g) => g.range(0.5, 0.7), (sa, life, r) => {
+ const q = sa / life, x = r.range(-6, R * 0.8) + sa * 8, y = -10 - sa * r.range(26, 36);
+ const rad = r.range(2.5, 4) * (q < 0.35 ? 0.6 + q : (1 - (q - 0.35) / 0.65) ** 0.7);
+ if (rad > 0.6) p.circle(x, y, rad, (d, a) => (d < 0.5 && a < -0.5 ? SM[3] : d < 0.8 ? SM[2] : SM[1]));
+ });
+ // ---- light: the smash, then the fire on the floor
+ if (age < 0.06) p.glow(0, -6, 26, F[6], 0.8);
+ const L = (seg(age, 0, 0.1) * (1 - burnDown * 0.8)) * fadeOut;
+ pool(p, (xl + xr) / 2, 0, (xr - xl) / 2 + 12, 5, F[4], 0.4 * L);
+ p.glow((xl + xr) / 2, -8, (xr - xl) / 2 + 14, F[4], 0.22 * L);
+}
diff --git a/src/fx/fire/spirit-flame.js b/src/fx/fire/spirit-flame.js
new file mode 100644
index 0000000..2d3153e
--- /dev/null
+++ b/src/fx/fire/spirit-flame.js
@@ -0,0 +1,59 @@
+import { ramp, cycle, clamp, tileFbm, loopNoise, TAU } from "../../core/index.js";
+import { fit } from "./_lib.js";
+
+export const meta = {
+ name: "Spirit flame",
+ desc: "A ghostly blue-teal flame floating in the air: a slow wave running up its wispy tail, curls breaking off and drifting away, motes rising.",
+ tags: ["fire", "spirit", "ghost", "wisp", "magic", "floating", "loop"],
+ size: [40, 60],
+ origin: [20, 46],
+ duration: 2.4,
+ loop: true,
+ fps: 30,
+ bg: "dark",
+ options: { palette: ["#0c0a2a", "#182462", "#1e4d9a", "#2584c4", "#38bede", "#7ceeea", "#d2fff6", "#ffffff"], height: 26, seed: 9 },
+};
+
+export function draw(p, t, o) {
+ const C = fit(ramp(o.palette)), S = o.seed, D = meta.duration, ph = t / D, H = o.height;
+ const bob = Math.sin(ph * TAU) * 2, by = bob; // it floats: the whole flame rises and sinks
+ const body = [C[2], C[3], C[4], C[5], C[6]];
+ // curls that break off the tip and drift up, shrinking away
+ cycle(t, D, 5, S + 3, (g) => g.range(0.8, 1.2), (age, life, r) => {
+ const q = age / life, x = Math.sin(age * 3 + r.next() * TAU) * 3 + r.range(-2, 2), y = by - H * 0.85 - age * r.range(10, 16);
+ const s = (1 - q) * r.range(1.4, 2.2);
+ if (s < 0.5) return;
+ p.ellipse(x, y, s * 0.7, s * 1.4, q < 0.4 ? C[5] : C[4]);
+ if (q < 0.3) p.px(x, y, C[6]);
+ p.light(x, y, C[4], 0.3 * (1 - q));
+ });
+ // the flame: a teardrop whose tail carries a slow S-wave upward. Lit from its rim like a ghost: a bright
+ // edge, a dim hollow body, a white heart low down
+ p.shade(-12, by - H - 8, 12, by + 4, (x, y) => {
+ const v = (by - y) / H;
+ if (v < -0.12 || v > 1.1) return;
+ const w = 6.5 * (v < 0.22 ? Math.sqrt(clamp(1 - ((0.22 - v) / 0.34) ** 2)) : Math.pow(clamp(1 - (v - 0.22) / 0.9), 0.85));
+ if (w < 0.3) return;
+ const sway = (Math.sin(v * 4.2 - ph * TAU * 2) * 2.6 + loopNoise(ph, 0.7, S) * 1.2) * v * v;
+ const d = Math.abs(x - sway) / w;
+ const n = tileFbm(x * 0.3, y * 0.18 + ph * 6, 0, 6, S, 2);
+ const heat = (1 - Math.pow(d, 1.8)) * (1.05 - v * 0.75) + n * (0.22 + v * 0.4);
+ if (heat < 0.14) return;
+ if (heat < 0.3) return v > 0.75 ? C[4] : C[5]; // the rim
+ const core = Math.hypot(x - sway, (y - by + 3.5) * 0.7) / 2.8;
+ if (core < 0.6) return C[7];
+ if (core < 1) return C[6];
+ if (heat < 0.46) return C[4];
+ return heat > 0.8 && v < 0.35 ? C[3] : C[2]; // a hollow, darker heart
+ });
+ // motes drifting up around it, twinkling
+ cycle(t, D, 10, S + 7, (g) => g.range(1, 1.6), (age, life, r) => {
+ const q = age / life, x = r.range(-12, 12) + Math.sin(age * 2 + r.next() * TAU) * 2, y = by + r.range(-6, 4) - age * r.range(8, 14);
+ if (Math.sin(age * 20 + r.next() * TAU) < -0.3) return;
+ p.px(x, y, q < 0.5 ? C[6] : C[4]);
+ p.light(x, y, C[5], 0.35 * (1 - q));
+ });
+ const pulse = 0.88 + 0.12 * Math.sin(ph * TAU * 2);
+ p.glow(0, by - H * 0.35, 26, C[4], 0.3 * pulse);
+ p.glow(0, by - 3, 8, C[6], 0.3 * pulse);
+}
diff --git a/src/fx/fire/torch.js b/src/fx/fire/torch.js
new file mode 100644
index 0000000..7d124ac
--- /dev/null
+++ b/src/fx/fire/torch.js
@@ -0,0 +1,62 @@
+import { PAL, ramp, fit, at, cycle, tileFbm, loopNoise, clamp, TAU } from "../../core/index.js";
+
+export const meta = {
+ name: "Torch",
+ desc: "A wall torch: a licking flame on a wooden handle, rising embers, warm flickering light.",
+ tags: ["fire", "light", "prop", "ambient"],
+ size: [36, 64],
+ origin: [18, 44],
+ duration: 1.2,
+ loop: true,
+ fps: 30,
+ bg: "dark",
+ options: { palette: PAL.fire, handle: true, height: 22, seed: 1 },
+};
+
+const WOOD = ramp(["#2a160c", "#4a2a16", "#6e4222", "#8e5a30"]);
+const IRON = ramp(["#1b1a22", "#34323f", "#55525f", "#807c8a"]);
+
+export function draw(p, t, o) {
+ const F = fit(o.palette, 8), S = o.seed, D = meta.duration, ph = t / D;
+ const H = o.height * (0.9 + 0.1 * loopNoise(ph, 1.4, S));
+ const body = F.slice(2, 7); // dark red edge .. yellow; the palest step is kept for the base of the core
+ // the flame: a teardrop of heat, wide at the base, torn into tongues at the top by rising noise
+ p.shade(-10, -H - 8, 10, 2, (x, y) => {
+ const v = clamp(-y / H, 0, 1.4);
+ const sway = (Math.sin(ph * TAU * 2 + v * 2.4) * 0.8 + loopNoise(ph, 0.8, S + 3)) * v * v * 2.4;
+ const w = 6.4 * (v < 0.2 ? Math.sqrt(Math.max(0, 1 - ((0.2 - v) / 0.28) ** 2)) : Math.pow(Math.max(0, 1 - (v - 0.2) / 0.85), 0.7));
+ if (w <= 0.3) return;
+ const d = Math.abs(x - sway) / w;
+ const n = tileFbm(x * 0.36, y * 0.24 + ph * 12, 0, 12, S, 3);
+ const heat = (1 - Math.pow(d, 1.6)) * (1.08 - v * 0.8) + n * (0.3 + v * 0.35);
+ if (heat < 0.12) return;
+ if (heat > 1.02 && v < 0.35) return F[7];
+ return at(body, (heat - 0.12) / 0.92);
+ });
+ // tongues tear off the tip and rise, shrinking and cooling
+ cycle(t, D, 4, S + 7, 0.36, (age, life, r) => {
+ const k = age / life, x = r.range(-3, 3) + Math.sin(k * 4 + r.next() * 6) * 1.6, y = -H * 0.78 - k * 11;
+ const s = (1 - k) * r.range(1.3, 2);
+ p.ellipse(x, y, s * 0.75, s * 1.5, k < 0.45 ? F[4] : F[3]);
+ if (k < 0.3) p.px(x, y, F[5]);
+ });
+ // embers: single pixels drifting up and sideways, flickering out
+ cycle(t, D, 7, S + 11, (r) => r.range(0.7, 1.2), (age, life, r) => {
+ const k = age / life, x = r.range(-4, 4) + Math.sin(age * r.range(4, 8) + r.next() * TAU) * 3 * k, y = -H * 0.55 - age * r.range(16, 28);
+ if (k > 0.5 && Math.sin(age * 38 + r.next() * 9) < -0.5) return;
+ p.px(x, y, k < 0.35 ? F[5] : k < 0.7 ? F[4] : F[3]);
+ p.light(x, y, F[4], 0.6 * (1 - k));
+ });
+ // light: a warm pool that breathes with the flame
+ const flick = 0.82 + 0.18 * loopNoise(ph, 2, S + 5);
+ p.glow(0, -H * 0.4, 28 * flick, F[4], 0.3 * flick);
+ p.glow(0, -H * 0.3, 10, F[6], 0.3 * flick);
+ if (!o.handle) return;
+ // handle: iron cup on a wooden stick
+ for (let y = 3; y < 17; y++) for (let x = -1; x <= 1; x++) p.px(x, y, WOOD[x === -1 ? 3 : x === 0 ? 2 : 1]);
+ p.px(-1, 17, WOOD[1]), p.px(0, 17, WOOD[0]);
+ for (let x = -5; x <= 5; x++) p.px(x, 0, IRON[Math.abs(x) === 5 ? 1 : x < 0 ? 3 : 2]);
+ for (let x = -4; x <= 4; x++) p.px(x, 1, IRON[x < 0 ? 2 : 1]);
+ for (let x = -3; x <= 3; x++) p.px(x, 2, IRON[1]);
+ for (let x = -2; x <= 2; x++) p.px(x, 7, IRON[x < 0 ? 2 : 1]);
+}
diff --git a/src/fx/holy/_lib.js b/src/fx/holy/_lib.js
new file mode 100644
index 0000000..29e0287
--- /dev/null
+++ b/src/fx/holy/_lib.js
@@ -0,0 +1,54 @@
+// Shared by the holy effects: plus signs, feathers, and the generic helpers the arcane effects use.
+// Files starting with _ are helpers, not effects.
+
+import { WHITE } from "../../core/index.js";
+export { fit, sparkle, ovalLine, tiltedOval, silhouette, ahead } from "../arcane/_lib.js";
+
+// Light ramps for things that are white rather than gold: feathers, wings.
+export const FEATHER = ["#2a2440", "#4d4566", "#7f7898", "#b5b0c8", "#e4e1ee", "#fffdf6"];
+
+// Plus signs: o is the outline (dark step), a the body, w the hot middle.
+const PLUS = [
+ ["a"],
+ [".a.", "awa", ".a."],
+ ["..a..", "..a..", "aawaa", "..a..", "..a.."],
+ ["..ooo..", "..oao..", "oooaooo", "oaawaao", "oooaooo", "..oao..", "..ooo.."],
+];
+
+/** A plus sign centred on (x, y). size 0..3 (1 px, 3 px, 5 px, 7 px with an outline). C: [outline, body, core]. */
+export function plus(p, x, y, size, C, a = 1) {
+ const s = Math.max(0, Math.min(3, Math.round(size))), g = PLUS[s], h = g.length >> 1;
+ p.sprite(g, { o: C[0], a: C[1], w: C[2] ?? WHITE }, Math.round(x) - h, Math.round(y) - h, { a });
+}
+
+// Feathers in three directions (tip right, tip up-right, tip up); mirroring gives the other three.
+// w vane, s shaded vane, r the rachis, q the quill.
+const FEATHERS = [
+ ["...wwww.", "qrrrrrrw", "..ssss.."],
+ ["....ww", "...wwr", "..wwrs", ".wrss.", ".rs...", "q....."],
+ [".w.", "wwr", "wrs", "wrs", "wrs", ".rs", ".r.", ".q."],
+];
+
+/**
+ * A small feather centred near (x, y), pointing along `ang` (radians, 0 = right, y down) snapped to the
+ * nearest of eight directions. F: a feather ramp (dark to light, at least 4 steps).
+ */
+export function feather(p, x, y, ang, F, a = 1) {
+ const k = ((Math.round(ang / (Math.PI / 4)) % 8) + 8) % 8; // 0 right, 2 down, 4 left, 6 up
+ const pal = { w: F[F.length - 1], s: F[F.length - 3], r: F[F.length - 2], q: F[1] };
+ // [sprite, mirror left-right, mirror top-bottom] for each of the eight directions
+ const [base, flip, down] = [
+ [FEATHERS[0], false, false], [FEATHERS[1], false, true], [FEATHERS[2], false, true], [FEATHERS[1], true, true],
+ [FEATHERS[0], true, false], [FEATHERS[1], true, false], [FEATHERS[2], false, false], [FEATHERS[1], false, false],
+ ][k];
+ const rows = down ? flipV(base) : base;
+ const w = rows[0].length, h = rows.length;
+ p.sprite(rows, pal, Math.round(x - w / 2), Math.round(y - h / 2), { flip, a });
+}
+
+const flipped = new Map();
+function flipV(rows) {
+ if (!flipped.has(rows)) flipped.set(rows, [...rows].reverse());
+ return flipped.get(rows);
+}
+
diff --git a/src/fx/holy/blessing.js b/src/fx/holy/blessing.js
new file mode 100644
index 0000000..c310189
--- /dev/null
+++ b/src/fx/holy/blessing.js
@@ -0,0 +1,49 @@
+import { PAL, cycle, clamp, TAU, WHITE } from "../../core/index.js";
+import { fit, sparkle } from "./_lib.js";
+
+export const meta = {
+ name: "Blessing",
+ desc: "A gentle shower of light over the actor: sparkles drift down through a soft cone of light, twinkling, and wink out at the feet.",
+ tags: ["holy", "blessing", "buff", "light", "sparkles", "character", "loop"],
+ size: [44, 58],
+ origin: [22, 52],
+ duration: 2.4,
+ loop: true,
+ fps: 30,
+ bg: "ground",
+ actor: true,
+ options: { palette: PAL.holy, count: 16, seed: 39 },
+};
+
+const TOP = -46;
+
+function shower(p, t, o, front) {
+ const C = fit(o.palette), D = meta.duration;
+ cycle(t, D, o.count, o.seed, (r) => r.range(1.3, 1.9), (age, life, r, i) => {
+ if (r.next() < 0.4 === front) return; // some fall behind the actor
+ const k = age / life, x0 = r.range(-5, 5), spread = r.range(-1, 1);
+ const y = TOP + 2 + (0 - TOP - 2) * k, x = x0 + spread * 10 * k + Math.sin(age * r.range(2.5, 4) + r.next() * TAU) * 1.8;
+ const tw = Math.sin(age * r.range(7, 11) + i), size = k > 0.9 ? 0 : tw > 0.55 ? 2 : tw > -0.3 ? 1 : 0;
+ if (front) sparkle(p, x, y, size, C[6], C[5], WHITE);
+ else sparkle(p, x, y, Math.min(1, size), C[5], C[4], C[6]);
+ p.light(x, y, C[5], (front ? 0.4 : 0.2) * (1 - k * 0.5));
+ });
+}
+
+export function drawBack(p, t, o) {
+ const C = fit(o.palette), ph = t / meta.duration;
+ // a soft cone of light from above (light only), shimmering slowly
+ p.shade(-16, TOP, 16, 2, (x, y, out) => {
+ const v = (y - TOP) / (0 - TOP), w = 3 + 11 * v, d = Math.abs(x) / w;
+ if (d > 1) return;
+ out.l = C[4];
+ out.k = 0.13 * (1 - d * d) * (0.85 + 0.15 * Math.sin(ph * TAU * 2 + y * 0.2)) * clamp(v * 4);
+ });
+ shower(p, t, o, false);
+}
+
+export function draw(p, t, o) {
+ const C = fit(o.palette);
+ shower(p, t, o, true);
+ p.glow(0, -2, 14, C[4], 0.15);
+}
diff --git a/src/fx/holy/divine-shield.js b/src/fx/holy/divine-shield.js
new file mode 100644
index 0000000..a12af74
--- /dev/null
+++ b/src/fx/holy/divine-shield.js
@@ -0,0 +1,58 @@
+import { PAL, cycle, TAU, WHITE } from "../../core/index.js";
+import { fit, sparkle, ovalLine } from "./_lib.js";
+
+export const meta = {
+ name: "Divine shield",
+ desc: "A golden bubble round the actor: two meridians turn on it like a globe, a band of light sweeps the near side, the rim glints and sparkles.",
+ tags: ["holy", "shield", "barrier", "bubble", "buff", "character", "loop"],
+ size: [40, 42],
+ origin: [20, 36],
+ duration: 1.6,
+ loop: true,
+ fps: 30,
+ bg: "ground",
+ actor: true,
+ options: { palette: PAL.holy, radius: 13, seed: 35 },
+};
+
+const CY = -11;
+
+// the wireframe: two meridians half a turn a loop (they swap places, so it repeats) and an equator.
+// front: the near halves, drawn over the actor; otherwise the far halves, behind it.
+function globe(p, t, o, front) {
+ const C = fit(o.palette), R = o.radius - 0.5, ph = t / meta.duration;
+ const band = -2.2 * R + 4.4 * R * ph; // the sweep of light, off the ball at both ends of the loop
+ const lit = (x, y) => Math.abs((x - y) * 0.7071 - band) < 4;
+ for (const th of [ph * Math.PI, ph * Math.PI + Math.PI / 2]) {
+ const sx = Math.sin(th), cz = Math.cos(th), rx = R * Math.abs(sx);
+ if (rx < 1) continue;
+ const near = (ang) => cz * Math.cos(ang) * Math.sign(sx) > 0;
+ // the near halves only show where the sweep of light catches them: the bubble stays clear over the actor
+ ovalLine(p, rx, R, (ang) => (front ? (Math.abs((Math.cos(ang) * rx - Math.sin(ang) * R) * 0.7071 - band) < 1.5 ? WHITE : C[6]) : C[3]),
+ (ang) => (near(ang) === front && Math.abs(Math.sin(ang)) < 0.93 && (!front || lit(Math.cos(ang) * rx, Math.sin(ang) * R)) ? 1 : 0), 0, CY);
+ }
+ ovalLine(p, R, R * 0.28, (ang) => (front && lit(Math.cos(ang) * R, Math.sin(ang) * R * 0.28) ? WHITE : front ? C[5] : C[3]),
+ (ang) => (Math.sin(ang) > 0 === front ? 1 : 0), 0, CY);
+}
+
+export const drawBack = (p, t, o) => globe(p, t, o, false);
+
+export function draw(p, t, o) {
+ const C = fit(o.palette), R = o.radius, ph = t / meta.duration, S = o.seed;
+ globe(p, t, o, true);
+ // the rim: bright at the top left where the light catches it, deeper at the bottom right
+ const breathe = 0.5 + 0.5 * Math.sin(ph * TAU * 2);
+ p.ring(0, CY, R, 1, (v, a) => {
+ const l = Math.cos(a + 2.36); // 1 at the top left
+ return l > 0.75 ? WHITE : l > -0.2 ? C[5] : breathe > 0.5 ? C[4] : C[3];
+ });
+ p.ring(0, CY, R - 1, 1, C[4], (v, a) => (Math.cos(a + 2.36) < -0.55 ? 1 : 0));
+ p.arc(0, CY, R - 3, 1, -2.75, -2.05, WHITE);
+ // sparkles winking on the surface
+ cycle(t, meta.duration, 4, S, 0.45, (age, life, r) => {
+ const k = age / life, a = r.range(0, TAU), rr = r.range(0.35, 0.9) * R;
+ sparkle(p, Math.cos(a) * rr, CY + Math.sin(a) * rr, k < 0.3 ? 1 : k < 0.6 ? 2 : k < 0.85 ? 1 : 0, C[6], C[5], WHITE);
+ });
+ p.glow(0, CY, R + 8, C[4], 0.14 + 0.06 * breathe);
+ p.glow(-R * 0.5, CY - R * 0.5, 7, C[6], 0.2);
+}
diff --git a/src/fx/holy/feather-burst.js b/src/fx/holy/feather-burst.js
new file mode 100644
index 0000000..cf3a1c2
--- /dev/null
+++ b/src/fx/holy/feather-burst.js
@@ -0,0 +1,49 @@
+import { burst, fly, flyV, seg, ease, TAU, WHITE } from "../../core/index.js";
+import { fit, sparkle, feather, FEATHER } from "./_lib.js";
+
+export const meta = {
+ name: "Feather burst",
+ desc: "A white puff throws out a spray of feathers that brake hard, then rock from side to side as they drift slowly down and fade.",
+ tags: ["holy", "feathers", "burst", "angelic", "soft", "one-shot"],
+ size: [88, 92],
+ origin: [44, 36],
+ duration: 2.1,
+ loop: false,
+ fps: 30,
+ bg: "dark",
+ options: { palette: FEATHER, count: 16, seed: 38 },
+};
+
+export function draw(p, t, o) {
+ const F = fit(o.palette, 6), S = o.seed;
+ // the puff: a white ball that blows open into a ring and thins away
+ if (t < 0.05) p.circle(0, 0, 5, WHITE);
+ const pf = seg(t, 0.02, 0.3);
+ if (pf > 0 && pf < 1) p.ring(0, 0, 5 + 14 * ease.outCubic(pf), 2 - pf, pf < 0.4 ? WHITE : F[4], (v, a) => (Math.sin(a * 7 + pf * 3) > pf * 2 - 1 ? 1 : 0));
+ p.glow(0, 0, 24, F[5], 0.5 * Math.pow(1 - seg(t, 0, 0.35), 2));
+ // feathers: flung out, braking hard, then rocking as they settle into a slow fall
+ burst(o.count, S, (r, i) => {
+ const a = (i / o.count) * TAU + r.range(-0.35, 0.35), sp = r.range(70, 200), life = r.range(1.5, 2.0);
+ if (t > life) return;
+ const vx = Math.cos(a) * sp, vy = Math.sin(a) * sp - 50;
+ const [x0, y0] = fly(0, 0, vx, vy, t, 0, 7), [ux, uy] = flyV(vx, vy, t, 0, 7);
+ const settle = seg(t, 0.15, 0.6), w = r.range(4.5, 6.5), ph0 = r.range(0, TAU), amp = r.range(3, 6);
+ const sway = Math.sin(t * w + ph0), fall = r.range(14, 26) * Math.max(0, t - 0.25);
+ // the fall: a slow sink that lifts a little at each end of the swing, like a real feather
+ const x = x0 + sway * amp * settle, y = y0 + fall - Math.abs(Math.cos(t * w + ph0)) * 1.5 * settle;
+ // early on it points along its flight; once settled it tips with the sway, quill end leading the fall
+ const flight = Math.atan2(uy, ux), rock = (Math.cos(t * w + ph0) > 0 ? 0 : Math.PI) + sway * 0.7;
+ const ang = settle < 0.5 ? flight : rock, end = seg(t, life - 0.3, life);
+ // it doesn't dither away: it thins to a sliver of light, then a mote
+ if (end === 0) feather(p, x, y, ang, F);
+ else if (end < 0.5) p.line(x - Math.cos(ang) * 1.5, y - Math.sin(ang) * 1.5, x + Math.cos(ang) * 1.5, y + Math.sin(ang) * 1.5, F[4]);
+ else p.px(x, y, F[3]);
+ });
+ // a few glints in the puff
+ burst(6, S + 1, (r) => {
+ const a = r.range(0, TAU), sp = r.range(40, 70), life = r.range(0.3, 0.5);
+ if (t > life) return;
+ const q = t / life, [x, y] = fly(0, 0, Math.cos(a) * sp, Math.sin(a) * sp, t, 0, 5);
+ sparkle(p, x, y, q < 0.4 ? 1 : 0, F[4], F[3], WHITE);
+ });
+}
diff --git a/src/fx/holy/halo.js b/src/fx/holy/halo.js
new file mode 100644
index 0000000..a91bbeb
--- /dev/null
+++ b/src/fx/holy/halo.js
@@ -0,0 +1,40 @@
+import { PAL, cycle, TAU, WHITE } from "../../core/index.js";
+import { fit, ovalLine, ahead, sparkle } from "./_lib.js";
+
+export const meta = {
+ name: "Halo",
+ desc: "A golden halo floats over the head, bobbing gently; a glint runs round the ring and now and then a sparkle winks on it.",
+ tags: ["holy", "halo", "blessed", "status", "character", "loop"],
+ size: [32, 36],
+ origin: [16, 31],
+ duration: 2,
+ loop: true,
+ fps: 30,
+ bg: "ground",
+ actor: true,
+ options: { palette: PAL.holy, radius: 6, seed: 37 },
+};
+
+export function draw(p, t, o) {
+ const C = fit(o.palette), A = o.actor, ph = t / meta.duration, S = o.seed;
+ const RX = o.radius, RY = Math.max(1.5, RX * 0.32), hy = A.head[1] - 4 + Math.round(Math.sin(ph * TAU) * 1);
+ const glint = ph * TAU - Math.PI / 2;
+ // the ring: thin and deeper gold on its far side, a thick bright band on its near side, a white glint running round
+ const col = (ang) => {
+ const g = ahead(ang, glint);
+ if (g < 0.35) return WHITE;
+ if (g < 0.9) return C[6];
+ return Math.sin(ang) > 0 ? C[5] : C[4];
+ };
+ ovalLine(p, RX, RY, col, 1, 0, hy);
+ ovalLine(p, RX - 0.6, RY, (ang) => (ahead(ang, glint) < 0.6 ? C[6] : C[3]), (ang) => (Math.sin(ang) > 0.35 ? 1 : 0), 0, hy + 1);
+ // sparkles that wink on the ring
+ cycle(t, meta.duration, 2, S, 0.4, (age, life, r) => {
+ const k = age / life, a = r.range(0, TAU);
+ sparkle(p, Math.cos(a) * RX, hy + Math.sin(a) * RY - 1, k < 0.25 ? 1 : k < 0.6 ? 2 : k < 0.85 ? 1 : 0, C[6], C[5], WHITE);
+ });
+ // warm light over the head
+ const pulse = 0.85 + 0.15 * Math.sin(ph * TAU * 2);
+ p.glow(0, hy, RX + 10, C[4], 0.28 * pulse);
+ p.glow(0, hy + 3, 8, C[5], 0.18 * pulse);
+}
diff --git a/src/fx/holy/heal-aoe.js b/src/fx/holy/heal-aoe.js
new file mode 100644
index 0000000..19fd088
--- /dev/null
+++ b/src/fx/holy/heal-aoe.js
@@ -0,0 +1,51 @@
+import { PAL, burst, seg, ease, clamp, TAU, WHITE } from "../../core/index.js";
+import { fit, plus, ovalLine } from "./_lib.js";
+
+export const meta = {
+ name: "Healing ring",
+ desc: "A healing ring rolls out across the floor; crosses rise wherever it passes and the green glow it leaves fades away.",
+ tags: ["holy", "heal", "aoe", "area", "ground", "one-shot"],
+ size: [100, 60],
+ origin: [50, 44],
+ duration: 1.25,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ options: { palette: PAL.heal, accent: PAL.gold, radius: 42, count: 14, seed: 32 },
+};
+
+const SQ = 0.34; // floor squash
+const T_RING = 0.75;
+
+export function draw(p, t, o) {
+ const C = fit(o.palette), G = fit(o.accent), RM = o.radius, S = o.seed;
+ const e = ease.outCubic(seg(t, 0, T_RING)), R = 4 + (RM - 4) * e, gone = seg(t, T_RING * 0.7, T_RING + 0.15);
+ // the glow it leaves on the floor (light only)
+ if (t < 1.1)
+ p.shade(-R, -R * SQ, R, R * SQ, (x, y, out) => {
+ const d = Math.hypot(x / R, y / (R * SQ));
+ if (d > 1) return;
+ out.l = C[5];
+ out.k = 0.16 * d * d * (1 - seg(t, 0.4, 1.1));
+ });
+ // the ring: a bright leading line with a darker echo inside, breaking into dashes as it dies
+ if (gone < 1) {
+ const dash = (k) => (ang) => (Math.sin(ang * 12 + k) > gone * 2.2 - 1.1 ? 1 : 0);
+ ovalLine(p, R, R * SQ, gone < 0.3 ? C[6] : C[5], dash(0));
+ if (R > 8) ovalLine(p, R - 3, (R - 3) * SQ, C[4], dash(2));
+ }
+ // crosses rise from the floor at the moment the ring reaches them
+ burst(o.count, S, (q, i) => {
+ const f = q.range(0.32, 0.97), ang = (i / o.count) * TAU + q.range(-0.3, 0.3);
+ const x0 = Math.cos(ang) * RM * f, y0 = Math.sin(ang) * RM * f * SQ;
+ const born = T_RING * (1 - Math.cbrt(1 - clamp((RM * f - 4) / (RM - 4)))) + 0.02, life = q.range(0.55, 0.75), age = t - born;
+ if (age < 0 || age > life) return;
+ const k = age / life, gold = i % 4 === 3;
+ const x = x0 + Math.sin(age * 7 + i) * 1.2, y = y0 - 2 - age * q.range(26, 38);
+ const size = k < 0.06 ? 1 : k < 0.3 ? 3 : k < 0.68 ? 2 : k < 0.88 ? 1 : 0;
+ plus(p, x, y, size, gold ? [G[3], G[5], WHITE] : [C[3], C[5], C[7]]);
+ if (k < 0.15) p.px(x0, y0, WHITE);
+ p.light(x, y, gold ? G[5] : C[5], 0.35 * (1 - k));
+ });
+ p.glow(0, -4, RM * 0.8, C[4], 0.2 * (1 - seg(t, 0.2, 1.05)));
+}
diff --git a/src/fx/holy/heal.js b/src/fx/holy/heal.js
new file mode 100644
index 0000000..f5f0f5e
--- /dev/null
+++ b/src/fx/holy/heal.js
@@ -0,0 +1,64 @@
+import { PAL, burst, stream, seg, ease, TAU, WHITE } from "../../core/index.js";
+import { fit, plus, ovalLine } from "./_lib.js";
+
+export const meta = {
+ name: "Heal",
+ desc: "A healing burst: the body flashes white then green, plus signs pop up around it and float away, gold motes spiral up, a ring spreads at the feet.",
+ tags: ["holy", "heal", "restore", "buff", "character", "one-shot"],
+ size: [52, 56],
+ origin: [26, 48],
+ duration: 1.3,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ actor: true,
+ options: { palette: PAL.heal, accent: PAL.gold, count: 8, seed: 31 },
+};
+
+// gold motes spiralling up round the body; the ones on the far side go behind it
+function motes(p, t, o, front) {
+ const G = fit(o.accent);
+ stream(t, 0, 0.75, 18, o.seed + 1, (q) => q.range(0.4, 0.7), (age, life, q) => {
+ const k = age / life, ang = q.range(0, TAU) + age * 7, R = 9 - k * 3;
+ if (Math.sin(ang) > 0 !== front) return;
+ const x = Math.cos(ang) * R, y = -q.range(0, 6) - age * q.range(26, 40) + Math.sin(ang) * 2;
+ p.px(x, y, k < 0.5 ? G[6] : G[4]);
+ p.light(x, y, G[5], 0.3 * (1 - k));
+ });
+}
+
+export function drawBack(p, t, o) {
+ const C = fit(o.palette);
+ motes(p, t, o, false);
+ // a soft green column of light behind the body
+ const c = 1 - seg(t, 0.1, 0.9);
+ if (c > 0) p.glowLine(0, 0, 0, -26, 11, C[4], 0.3 * c * Math.min(1, t / 0.08));
+}
+
+export function draw(p, t, o) {
+ const C = fit(o.palette), G = fit(o.accent), A = o.actor, S = o.seed;
+ // the body lights up: the outline flashes white, then green, and fades
+ const f = seg(t, 0, 0.45);
+ if (f < 1) {
+ p.outline(A.mask, A.x, A.y, f < 0.12 ? WHITE : f < 0.45 ? C[6] : C[5], f < 0.6 ? 1 : (1 - f) / 0.4);
+ p.glow(0, -10, 22, C[5], 0.45 * (1 - f) * (1 - f));
+ }
+ // a ring spreading at the feet, breaking up as it goes
+ const r = seg(t, 0.02, 0.45);
+ if (r > 0 && r < 1) {
+ const R = 5 + 14 * ease.outCubic(r);
+ ovalLine(p, R, R * 0.33, r < 0.3 ? C[7] : r < 0.6 ? C[6] : r < 0.85 ? C[5] : C[4]);
+ }
+ motes(p, t, o, true);
+ // plus signs: pop in big around the body, settle, rise and sway, shrink away; every third one gold
+ burst(o.count, S, (q, i) => {
+ const born = 0.04 + i * 0.065 + q.range(0, 0.04), life = q.range(0.6, 0.75), age = t - born;
+ if (age < 0 || age > life) return;
+ const k = age / life, side = i % 2 ? 1 : -1;
+ const x = side * q.range(6, 14) + Math.sin(age * 6 + i) * 1.2, y = q.range(-18, -5) - age * q.range(18, 28);
+ const size = k < 0.06 ? 1 : k < 0.3 ? 3 : k < 0.7 ? 2 : k < 0.88 ? 1 : 0;
+ const gold = i % 3 === 2;
+ plus(p, x, y, size, gold ? [G[3], G[5], WHITE] : [C[3], C[5], C[7]]);
+ p.light(x, y, gold ? G[5] : C[5], 0.4 * (1 - k));
+ });
+}
diff --git a/src/fx/holy/holy-pillar.js b/src/fx/holy/holy-pillar.js
new file mode 100644
index 0000000..b6aa3a7
--- /dev/null
+++ b/src/fx/holy/holy-pillar.js
@@ -0,0 +1,85 @@
+import { PAL, burst, stream, fly, seg, ease, clamp, tileNoise, WHITE } from "../../core/index.js";
+import { fit, ovalLine, sparkle } from "./_lib.js";
+
+export const meta = {
+ name: "Holy pillar",
+ desc: "Light from the sky: a thin line drops onto the target, bursts into a white-gold pillar that splashes on the floor, pours a moment, then narrows away.",
+ tags: ["holy", "light", "pillar", "beam", "ground", "one-shot"],
+ size: [72, 118],
+ origin: [36, 106],
+ duration: 1.15,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ options: { palette: PAL.holy, width: 10, seed: 33 },
+};
+
+export function draw(p, t, o) {
+ const C = fit(o.palette), S = o.seed, top = -meta.origin[1], W = o.width;
+ // 1. the warning line: a thread of light drops from the sky to the floor
+ const drop = ease.inQuad(seg(t, 0, 0.1));
+ if (drop > 0 && t < 0.16) {
+ const y = top + (0 - top) * drop;
+ p.line(0, top, 0, y, C[6]);
+ p.px(0, y, WHITE);
+ p.glow(0, y, 6, C[5], 0.4);
+ }
+ // 2. the pillar: opens in a blink, pours, then narrows to nothing
+ const open = ease.outExpo(seg(t, 0.12, 0.2)), close = ease.inQuad(seg(t, 0.8, 1.1)), flash = t >= 0.12 && t < 0.19;
+ const w = W * open * (1 - close);
+ if (w > 0.3) {
+ p.shade(-w * 1.8 - 1, top, w * 1.8 + 1, 1, (x, y, out) => {
+ const base = clamp((y + 9) / 9), ww = w * (1 + 0.7 * base * base); // it flares where it meets the floor
+ const v = Math.abs(x) / ww;
+ if (v > 1) return;
+ const pour = tileNoise(x * 0.7, y * 0.05 - t * 12, 0, 0, S) * 0.5 + 0.5; // streaks pouring down
+ const lvl = (1 - v) * 1.3 + pour * 0.5 - 0.15;
+ if (lvl < 0.2) return;
+ out.c = flash || lvl > 1.2 ? WHITE : lvl > 0.95 ? C[6] : lvl > 0.7 ? C[5] : lvl > 0.42 ? C[4] : C[3];
+ out.k = 0.1;
+ });
+ p.glowLine(0, top + 24, 0, 0, w + 12, C[4], 0.3 * (1 - close));
+ }
+ // falling rays: thin threads of light either side of the pillar, sliding down
+ if (w > 2)
+ stream(t, 0.14, 0.95, 26, S + 5, (q) => q.range(0.2, 0.35), (age, life, q) => {
+ const k = age / life, x = q.sign() * (w + q.range(2, 7)), len = q.range(10, 22);
+ const y = top + (0 - top + len) * k - len;
+ p.line(x, Math.max(top, y), x, Math.min(0, y + len), k < 0.5 ? C[6] : C[5]);
+ });
+ // 3. the splash on the floor: a flat white burst, rings racing out, dust kicked aside
+ const a = t - 0.12;
+ if (a >= 0) {
+ if (a < 0.067) {
+ p.ellipse(0, 0, W * 2.2, 3, WHITE);
+ p.glow(0, -6, 28, C[5], 0.6);
+ }
+ for (const [d, R0] of [[0, 20], [0.1, 14]]) {
+ const rr = seg(a, d, d + 0.3);
+ if (rr <= 0 || rr >= 1) continue;
+ const R = W + R0 * ease.outCubic(rr);
+ ovalLine(p, R, R * 0.28, rr < 0.35 ? C[7] : rr < 0.7 ? C[5] : C[3]);
+ }
+ burst(6, S + 2, (q) => {
+ const side = q.sign(), sp = q.range(40, 75), up = q.range(30, 60), life = q.range(0.3, 0.45);
+ if (a > life) return;
+ const [x, y] = fly(side * W * 0.6, -1, side * sp, -up, a, 240, 2);
+ if (y > 1) return;
+ p.px(x, y, a / life < 0.4 ? C[6] : C[4]);
+ });
+ }
+ // 4. a bright puddle where it lands, while it pours
+ if (w > 0.6) {
+ p.ellipse(0, 0, w * 1.8, 1.6, C[6]);
+ p.shade(-w * 3, -6, w * 3, 6, (x, y, out) => {
+ const d = Math.hypot(x / (w * 3), y / 6);
+ if (d < 1) (out.l = C[5]), (out.k = 0.25 * (1 - d));
+ });
+ }
+ // 5. motes rising inside the light
+ stream(t, 0.18, 0.95, 24, S + 3, (q) => q.range(0.35, 0.6), (age, life, q) => {
+ const k = age / life, x = q.range(-0.8, 0.8) * W, y = -q.range(0, 20) - age * q.range(50, 90);
+ if (Math.abs(x) > w) return;
+ sparkle(p, x, y, k < 0.3 ? 1 : 0, C[7], C[6], WHITE);
+ });
+}
diff --git a/src/fx/holy/purify.js b/src/fx/holy/purify.js
new file mode 100644
index 0000000..1bf2712
--- /dev/null
+++ b/src/fx/holy/purify.js
@@ -0,0 +1,89 @@
+import { PAL, burst, stream, seg, ease, clamp, rng, WHITE } from "../../core/index.js";
+import { fit, ovalLine, sparkle } from "./_lib.js";
+
+export const meta = {
+ name: "Purify",
+ desc: "Cleansing light: three bright rings sweep up the body one after another, scouring off a dark taint that boils away as smoke, then a clean glint.",
+ tags: ["holy", "purify", "cleanse", "dispel", "cure", "character", "one-shot"],
+ size: [48, 56],
+ origin: [24, 46],
+ duration: 1.3,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ actor: true,
+ options: { palette: PAL.holy, taint: PAL.shadow, seed: 40 },
+};
+
+const RINGS = [0.08, 0.26, 0.44], RISE = 0.42, TOPY = -25;
+// the height of ring i at time t (null when it isn't up)
+const ringY = (t, i) => {
+ const k = seg(t, RINGS[i], RINGS[i] + RISE);
+ return k <= 0 || k >= 1 ? null : 2 + (TOPY - 2) * ease.inOutSine(k);
+};
+
+function rings(p, t, o, front) {
+ const C = fit(o.palette);
+ for (let i = 0; i < 3; i++) {
+ const y = ringY(t, i);
+ if (y === null) continue;
+ const k = seg(t, RINGS[i], RINGS[i] + RISE), rx = 10 - 3 * k, ry = 3 - k;
+ const show = (ang) => (Math.sin(ang) > 0 === front ? 1 : 0);
+ ovalLine(p, rx, ry, front ? (k > 0.8 ? C[5] : WHITE) : C[4], show, 0, y);
+ if (front) ovalLine(p, rx, ry, C[5], show, 0, y + 1);
+ if (front) p.glow(0, y, 12, C[5], 0.3 * (1 - k * 0.5));
+ }
+}
+
+// taint blots stuck to the body; each one lets go when the first ring reaches it
+function blots(o) {
+ const A = o.actor, out = [];
+ for (let i = 0, tries = 0; out.length < 7 && tries < 400; tries++) {
+ const r = rng(o.seed, tries, 7), n = out.length, band = A.h / 7;
+ const my = Math.min(A.h - 2, Math.floor(1 + n * band + r.range(0, band - 1))), mx = n % 2 ? r.int(A.w / 2, A.w - 2) : r.int(1, A.w / 2 - 1);
+ if (!A.mask.data[my * A.w + mx]) continue;
+ const y = A.y + my, k = Math.acos(1 - 2 * clamp((y - 2) / (TOPY - 2))) / Math.PI; // when ring 0 passes y
+ out.push({ x: A.x + mx, y, free: RINGS[0] + RISE * k, r: r.range(1.3, 2.3), i: i++ });
+ }
+ return out;
+}
+
+export const drawBack = (p, t, o) => rings(p, t, o, false);
+
+export function draw(p, t, o) {
+ const C = fit(o.palette), T = fit(o.taint), A = o.actor, S = o.seed;
+ // the taint: dark blots that wobble on the body, then tear off and boil away as smoke
+ for (const b of blots(o)) {
+ const a = t - b.free;
+ if (a < 0) {
+ const wob = Math.sin(t * 20 + b.i * 2) * 0.3;
+ p.circle(b.x, b.y, b.r + wob, (d) => (d > 0.7 ? T[3] : d > 0.35 ? T[2] : T[4]));
+ continue;
+ }
+ // torn off: puffs of dark smoke that rise, swell a little, then shrink to nothing
+ burst(3, S * 5 + b.i, (r) => {
+ const life = r.range(0.35, 0.55);
+ if (a > life) return;
+ const q = a / life, x = b.x + r.range(-6, 6) * ease.outCubic(q), y = b.y - a * r.range(22, 36);
+ p.circle(x, y, b.r * 0.9 * Math.sin(Math.PI * (0.25 + 0.75 * q)), (d) => (d > 0.6 ? T[2] : q < 0.5 ? T[4] : T[3]));
+ });
+ if (a < 0.08) sparkle(p, b.x, b.y, 2, WHITE, C[6], WHITE);
+ }
+ // as a ring passes, the slice of body it touches lights up
+ for (let i = 0; i < 3; i++) {
+ const y = ringY(t, i);
+ if (y === null) continue;
+ p.mask(A.mask, A.x, A.y, (mx, my) => (Math.abs(A.y + my - y) < 0.8 ? WHITE : C[6]), (mx, my) => (Math.abs(A.y + my - y) < 1.6 ? 1 : 0));
+ }
+ rings(p, t, o, true);
+ // clean: a glint over the head and motes rising
+ const g = seg(t, 0.86, 1.22);
+ if (g > 0 && g < 1) {
+ sparkle(p, 4, A.head[1] - 3, g < 0.2 ? 2 : g < 0.6 ? 3 : g < 0.85 ? 1 : 0, WHITE, C[6], WHITE);
+ p.outline(A.mask, A.x, A.y, C[5], 1 - g);
+ }
+ stream(t, 0.3, 0.8, 14, S + 2, (r) => r.range(0.35, 0.48), (age, life, r) => {
+ const k = age / life, x = r.range(-9, 9), y = -r.range(2, 20) - age * r.range(20, 34);
+ p.px(x, y, k < 0.5 ? C[6] : C[4]);
+ });
+}
diff --git a/src/fx/holy/regen.js b/src/fx/holy/regen.js
new file mode 100644
index 0000000..e90d931
--- /dev/null
+++ b/src/fx/holy/regen.js
@@ -0,0 +1,50 @@
+import { PAL, cycle, seg, bump, ease, WHITE } from "../../core/index.js";
+import { fit, plus } from "./_lib.js";
+
+export const meta = {
+ name: "Regen",
+ desc: "Steady regeneration: the body beats green twice, a wave of light climbs through it with each beat, small crosses and motes float up beside it.",
+ tags: ["holy", "heal", "regen", "hot", "buff", "character", "loop"],
+ size: [44, 48],
+ origin: [22, 42],
+ duration: 1.6,
+ loop: true,
+ fps: 30,
+ bg: "ground",
+ actor: true,
+ options: { palette: PAL.heal, seed: 42 },
+};
+
+const BEATS = [0, 0.2]; // lub-dub, then a long rest
+
+export function drawBack(p, t, o) {
+ const C = fit(o.palette);
+ // a soft green pool behind the body that swells on each beat
+ let beat = 0;
+ for (const b of BEATS) beat = Math.max(beat, bump(t, b, b + 0.3));
+ p.glowLine(0, 0, 0, -20, 9, C[4], 0.12 + 0.2 * beat);
+}
+
+export function draw(p, t, o) {
+ const C = fit(o.palette), A = o.actor, S = o.seed;
+ // each beat: the outline flashes, and a wave of light climbs the body from the feet to the head
+ for (const [i, b] of BEATS.entries()) {
+ const k = seg(t, b, b + 0.08);
+ if (k > 0 && k < 1) p.outline(A.mask, A.x, A.y, k < 0.5 ? C[6] : C[5]);
+ const w = seg(t, b + 0.02, b + 0.6);
+ if (w <= 0 || w >= 1) continue;
+ const y = -A.h * ease.inOutSine(w) + 1, hot = i === 0 ? C[6] : C[5];
+ p.mask(A.mask, A.x, A.y, (mx, my) => (Math.abs(A.y + my - y) < 0.8 ? hot : C[4]), (mx, my) => (Math.abs(A.y + my - y) < 1.8 ? 1 : 0));
+ }
+ // crosses floating up beside the body, steady as a drip
+ cycle(t, meta.duration, 5, S, (r) => r.range(0.9, 1.3), (age, life, r, i) => {
+ const k = age / life, side = i % 2 ? 1 : -1, x = side * r.range(7, 11) + Math.sin(age * 5 + i) * 1, y = -r.range(2, 12) - age * r.range(14, 20);
+ plus(p, x, y, k < 0.08 ? 0 : k < 0.35 ? 2 : k < 0.8 ? 1 : 0, [C[3], C[5], WHITE]);
+ p.light(x, y, C[5], 0.3 * (1 - k));
+ });
+ // motes
+ cycle(t, meta.duration, 7, S + 1, (r) => r.range(0.6, 0.9), (age, life, r) => {
+ const k = age / life, x = r.range(-8, 8), y = -r.range(0, 6) - age * r.range(20, 30);
+ p.px(x, y, k < 0.5 ? C[6] : C[4]);
+ });
+}
diff --git a/src/fx/holy/resurrection.js b/src/fx/holy/resurrection.js
new file mode 100644
index 0000000..7955694
--- /dev/null
+++ b/src/fx/holy/resurrection.js
@@ -0,0 +1,113 @@
+import { PAL, burst, stream, seg, ease, bump, clamp, rng, lerp, TAU, WHITE } from "../../core/index.js";
+import { fit, ovalLine, sparkle, feather } from "./_lib.js";
+
+export const meta = {
+ name: "Resurrection",
+ desc: "A revive: light falls on the fallen, wings of light unfold behind them, a glow climbs the body, the wings beat once and scatter into feathers.",
+ tags: ["holy", "revive", "resurrect", "wings", "light", "character", "one-shot"],
+ size: [84, 68],
+ origin: [42, 60],
+ duration: 2.3,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ actor: true,
+ options: { palette: PAL.holy, seed: 34 },
+};
+
+const SHOULDER = [2, -13];
+// the right wing at rest, fully open: an arm rising up and out from the shoulder, feathers hanging from it,
+// short ones near the body pointing down, long primaries at the tip sweeping out. Points are relative to the shoulder.
+const ARM = [[0, 0], [6, -7], [12, -13]];
+const QUILLS = Array.from({ length: 7 }, (_, k) => {
+ const u = k / 6, seg2 = u * 2, i = Math.min(1, Math.floor(seg2)), f = seg2 - i;
+ const bx = ARM[i][0] + (ARM[i + 1][0] - ARM[i][0]) * f, by = ARM[i][1] + (ARM[i + 1][1] - ARM[i][1]) * f;
+ return { bx, by, ang: lerp(1.7, -0.35, Math.pow(u, 1.2)), len: lerp(9, 16, u) };
+});
+
+// the wing's pose: folded down the back, unfolding with an overshoot, one deep beat, then coming apart
+function pose(t) {
+ const open = ease.outBack(seg(t, 0.3, 0.75), 1.5), beat = bump(t, 1.15, 1.45);
+ return { rot: (1 - open) * 1.6 + beat * 0.55, scale: 0.45 + 0.55 * Math.min(1, open) };
+}
+const dissolve = (t) => seg(t, 1.42, 1.72);
+
+// a point of the right wing (relative to the shoulder), turned and scaled by the pose, mirrored for the left
+function place(x, y, P, side) {
+ const c = Math.cos(P.rot), s = Math.sin(P.rot), X = (x * c - y * s) * P.scale, Y = (x * s + y * c) * P.scale;
+ return [SHOULDER[0] * side + X * side, SHOULDER[1] + Y];
+}
+
+function wings(p, t, o) {
+ const C = fit(o.palette), P = pose(t), dis = dissolve(t);
+ if (t < 0.3 || dis >= 1) return;
+ for (const side of [-1, 1]) {
+ // feathers from the body outward, so the long primaries lie on top
+ QUILLS.forEach((q, j) => {
+ const r = rng(o.seed, j, side > 0 ? 1 : 2), keep = 1 - seg(dis, r.range(0, 0.4), r.range(0.45, 1));
+ if (keep <= 0) return;
+ const a = q.ang + P.rot, L = q.len * P.scale * keep, dx = Math.cos(a) * side, dy = Math.sin(a), nx = -dy, ny = dx;
+ const [bx, by] = place(q.bx, q.by, P, side), tx = bx + dx * L, ty = by + dy * L, w = 1.9 * P.scale + 0.6;
+ p.poly([[bx + nx * w, by + ny * w], [tx + nx * w * 0.7, ty + ny * w * 0.7], [tx + dx * 1.6, ty + dy * 1.6], [tx - nx * w * 0.7, ty - ny * w * 0.7], [bx - nx * w, by - ny * w]],
+ (x, y) => {
+ const v = ((x - bx) * nx + (y - by) * ny) / w; // -1 .. 1 across the feather
+ return v * side < -0.45 ? C[4] : v * side > 0.5 ? C[6] : C[5];
+ });
+ });
+ // the arm: a bright bone of light along the top edge
+ const pts = ARM.map(([x, y]) => place(x, y, P, side));
+ p.polyline(pts, WHITE);
+ p.polyline(pts.map(([x, y]) => [x, y + 1]), C[6]);
+ }
+ p.glow(0, -18, 30, C[5], 0.3 * P.scale * (1 - dis));
+}
+
+export function drawBack(p, t, o) {
+ const C = fit(o.palette);
+ // light falling from above: a soft column that brightens as the wings open
+ const col = bump(t, 0, 1.9);
+ p.glowLine(0, -56, 0, 0, 12, C[4], 0.28 * col);
+ wings(p, t, o);
+}
+
+export function draw(p, t, o) {
+ const C = fit(o.palette), A = o.actor, S = o.seed;
+ // a ring of light on the floor
+ const g = seg(t, 0.05, 0.6), gOut = seg(t, 1.5, 1.9);
+ if (g > 0 && gOut < 1) {
+ const R = 6 + 10 * ease.outCubic(g);
+ ovalLine(p, R, R * 0.3, g < 0.3 ? WHITE : C[5], 1 - gOut);
+ }
+ // the revive glow: a bright band climbs the body, then the outline pulses twice
+ const climb = seg(t, 0.45, 1.0);
+ if (climb > 0 && climb < 1) {
+ const band = -A.h * ease.inOutSine(climb);
+ p.mask(A.mask, A.x, A.y, (mx, my) => {
+ const d = Math.abs(A.y + my - band);
+ return d < 1 ? WHITE : C[6];
+ }, (mx, my) => (Math.abs(A.y + my - band) < 2.5 ? 1 : 0));
+ }
+ const pulse = Math.max(bump(t, 0.95, 1.15), bump(t, 1.2, 1.4), seg(t, 0.4, 0.5) * (1 - seg(t, 1.5, 1.8)) * 0.5);
+ if (pulse > 0.05) p.outline(A.mask, A.x, A.y, pulse > 0.6 ? WHITE : C[5], Math.min(1, pulse * 1.6));
+ // motes rising from the floor all the way up
+ stream(t, 0.1, 1.3, 22, S, (r) => r.range(0.55, 0.85), (age, life, r) => {
+ const k = age / life, x = r.range(-12, 12) + Math.sin(age * 5 + r.next() * TAU), y = -age * r.range(30, 48);
+ sparkle(p, x, y, k > 0.2 && k < 0.45 ? 1 : 0, C[6], C[5], k < 0.5 ? WHITE : C[6]);
+ });
+ // a halo flickers on above the head at the peak
+ const h = seg(t, 0.9, 1.05) * (1 - seg(t, 1.5, 1.75));
+ if (h > 0) ovalLine(p, 5, 1.6, (ang) => (Math.sin(ang) > 0 ? WHITE : C[5]), h, 0, A.head[1] - 4);
+ // the wings scatter: feathers fall away from where they were, rocking as they drift
+ if (dissolve(t) > 0)
+ burst(14, S + 3, (r, i) => {
+ const side = i % 2 ? 1 : -1, q = QUILLS[(i >> 1) % 7], P = pose(1.42), along = r.range(0.4, 1) * q.len;
+ const born = 1.42 + r.range(0, 0.25), age = t - born, life = r.range(0.45, 0.6);
+ if (age < 0 || age > life) return;
+ const [bx, by] = place(q.bx, q.by, P, side), a = q.ang + P.rot;
+ const x0 = bx + Math.cos(a) * side * along * P.scale, y0 = by + Math.sin(a) * along * P.scale;
+ const sway = Math.sin(age * 8 + i), x = x0 + side * age * r.range(6, 14) + sway * 2.5, y = y0 + age * r.range(16, 26);
+ if (y > -1) return; // landed
+ feather(p, x, y, sway * 0.8 + (side > 0 ? 0 : Math.PI), [C[2], C[3], C[5], C[6], WHITE], 1 - seg(age, life * 0.75, life));
+ });
+ p.glow(0, -10, 20, C[5], 0.3 * clamp(climb * 2) * (1 - seg(t, 1.3, 1.9)));
+}
diff --git a/src/fx/holy/smite.js b/src/fx/holy/smite.js
new file mode 100644
index 0000000..bf59327
--- /dev/null
+++ b/src/fx/holy/smite.js
@@ -0,0 +1,82 @@
+import { PAL, RAMP, burst, fly, seg, ease, rng, bolt, TAU, WHITE } from "../../core/index.js";
+import { fit, ovalLine, sparkle } from "./_lib.js";
+
+export const meta = {
+ name: "Smite",
+ desc: "A hammer of light slams down on the target: a glint above, a heavy white-gold block crashing in, a flat shockwave, cracks of light and flying stone.",
+ tags: ["holy", "smite", "strike", "impact", "light", "ground", "one-shot"],
+ size: [92, 108],
+ origin: [46, 94],
+ duration: 0.85,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ options: { palette: PAL.holy, seed: 36 },
+};
+
+const T_FALL = 0.12, T_HIT = 0.19;
+
+export function draw(p, t, o) {
+ const C = fit(o.palette), S = o.seed, top = -meta.origin[1] + 4, ST = RAMP.stone;
+ // 1. the mark: a ring on the floor closing on the target, a glint high above
+ const m = seg(t, 0, T_HIT);
+ if (m < 1) {
+ const R = 20 - 12 * ease.inQuad(m);
+ ovalLine(p, R, R * 0.3, m > 0.6 ? C[6] : C[5], (a) => (Math.sin(a * 6 + t * 30) > -0.3 ? 1 : 0));
+ if (t < T_FALL + 0.02) sparkle(p, 0, top + 6, t < 0.05 ? 1 : 3, WHITE, C[6], WHITE);
+ }
+ // 2. the hammer: a long haft and a heavy head, dropping in two frames, squashing on the hit
+ const fall = ease.inQuad(seg(t, T_FALL, T_HIT)), hit = t >= T_HIT, after = seg(t, T_HIT + 0.03, 0.45);
+ if (t >= T_FALL && after < 1) {
+ const yb = hit ? 0 : top + 12 + (0 - top - 12) * fall;
+ const squash = hit ? 1 - ease.outCubic(seg(t, T_HIT, T_HIT + 0.08)) : 0;
+ const hw = (11 + 5 * squash) * (1 - after * 0.6), hh = hit ? (12 - 5 * squash) * (1 - after) : 12;
+ const shaft = 4 * (1 - ease.outCubic(after));
+ const white = hit && t < T_HIT + 0.07;
+ const fill = (v, u) => (white ? WHITE : v < 0.35 ? WHITE : v < 0.7 ? C[6] : v < 0.9 ? C[5] : C[4]);
+ if (shaft > 0.4) p.shade(-shaft, top, shaft, yb - hh, (x, y) => fill(Math.abs(x) / shaft));
+ if (hh > 0.5) p.shade(-hw, yb - hh, hw, yb, (x, y) => fill(Math.max(Math.abs(x) / hw, (yb - y) / hh * 0.8)));
+ // speed lines while it falls
+ if (!hit) for (const x of [-hw - 3, -hw + 2, hw - 2, hw + 3]) p.line(x, yb - hh - 4, x, Math.max(top, yb - hh - 22), C[5]);
+ p.glowLine(0, top + 20, 0, yb, 14, C[5], 0.3 * (1 - after));
+ }
+ if (!hit) return;
+ const a = t - T_HIT;
+ // 3. the hit: a flat white burst along the floor, a big light that drops fast
+ if (a < 0.067) {
+ p.ellipse(0, 0, 26, 4, WHITE);
+ p.glow(0, -10, 34, C[5], 0.7);
+ }
+ // 4. shockwave rolling out over the floor
+ const sw = seg(a, 0, 0.32);
+ if (sw < 1) {
+ const R = 14 + 24 * ease.outCubic(sw);
+ ovalLine(p, R, R * 0.28, sw < 0.3 ? WHITE : sw < 0.6 ? C[6] : C[4], (ang) => (Math.sin(ang * 8) > sw * 2.4 - 1.4 ? 1 : 0));
+ }
+ // 5. cracks of light split the floor, glow, then cool and close
+ const cr = seg(a, 0, 0.06), cool = seg(a, 0.16, 0.55);
+ if (cool < 1)
+ for (let i = 0; i < 6; i++) {
+ const r = rng(S, i, 4), ang = (i / 6) * TAU + r.range(-0.35, 0.35), L = r.range(14, 24) * cr;
+ const path = bolt(r, 0, 0, Math.cos(ang) * L, Math.sin(ang) * L * 0.3, { jag: 0.18, depth: 3 });
+ const flat = path.map(([x, y]) => [x, Math.max(-1, y)]);
+ p.polyline(flat, cool < 0.3 ? C[6] : cool < 0.65 ? C[4] : C[2]);
+ }
+ // 6. stone chunks and gold sparks thrown up
+ burst(8, S + 1, (r) => {
+ const ang = -Math.PI / 2 + r.range(-1.2, 1.2), sp = r.range(60, 110), life = r.range(0.4, 0.6);
+ if (a > life) return;
+ const [x, y] = fly(r.range(-8, 8), -1, Math.cos(ang) * sp, Math.sin(ang) * sp, a, 340, 0.5);
+ if (y > 1) return;
+ const s = r.next() < 0.4 ? 2 : 1;
+ p.rect(x, y, s, s, r.next() < 0.5 ? ST[4] : ST[3]);
+ });
+ burst(12, S + 2, (r) => {
+ const ang = -Math.PI / 2 + r.range(-1.4, 1.4), sp = r.range(70, 140), life = r.range(0.2, 0.4);
+ if (a > life) return;
+ const q = a / life, [x, y] = fly(0, -2, Math.cos(ang) * sp, Math.sin(ang) * sp, a, 200, 3);
+ p.px(x, y, q < 0.3 ? WHITE : q < 0.6 ? C[6] : C[4]);
+ p.light(x, y, C[5], 0.4 * (1 - q));
+ });
+ p.glow(0, -4, 30, C[4], 0.45 * Math.pow(1 - seg(a, 0, 0.5), 2));
+}
diff --git a/src/fx/holy/sunburst.js b/src/fx/holy/sunburst.js
new file mode 100644
index 0000000..bfb095e
--- /dev/null
+++ b/src/fx/holy/sunburst.js
@@ -0,0 +1,45 @@
+import { PAL, cycle, TAU, WHITE } from "../../core/index.js";
+import { fit, sparkle } from "./_lib.js";
+
+export const meta = {
+ name: "Sunburst",
+ desc: "A radiant sun: long and short rays turning slowly round a blazing core, breathing in and out, a ring of light and glints at the tips.",
+ tags: ["holy", "sun", "light", "radiant", "icon", "background", "loop"],
+ size: [72, 72],
+ origin: [36, 36],
+ duration: 2.4,
+ loop: true,
+ fps: 30,
+ bg: "dark",
+ options: { palette: PAL.holy, rays: 12, length: 28, seed: 41 },
+};
+
+export function draw(p, t, o) {
+ const C = fit(o.palette), n = o.rays, ph = t / meta.duration, S = o.seed, L = o.length;
+ // the rays turn one long/short pair a loop, so the loop has no seam; they all breathe together
+ const rot = ph * ((TAU * 2) / n) - Math.PI / 2, breathe = Math.sin(ph * TAU * 2);
+ for (let i = 0; i < n; i++) {
+ const a = rot + (i * TAU) / n, long = i % 2 === 0;
+ const len = long ? L + 2 * breathe : L * 0.6 - 1.5 * breathe, w = long ? 3.4 : 2.4, r0 = 7;
+ const dx = Math.cos(a), dy = Math.sin(a), nx = -dy, ny = dx;
+ // a light runs round the rays: brighter where it is (a function of the ray's angle, not its index)
+ const lit = 0.5 + 0.5 * Math.cos(a + Math.PI / 2 - ph * TAU);
+ p.poly([[dx * r0 + nx * w, dy * r0 + ny * w], [dx * len, dy * len], [dx * r0 - nx * w, dy * r0 - ny * w]], (x, y) => {
+ const u = (Math.hypot(x, y) - r0) / (len - r0), v = Math.abs(x * nx + y * ny) / (w * (1 - u) + 0.01);
+ if (u > 0.82) return C[3];
+ if (v < 0.4 && u < 0.55 + 0.3 * lit) return long ? C[6] : C[5];
+ return u > 0.6 ? C[4] : C[5];
+ });
+ if (long && lit > 0.85) p.light(dx * len * 0.7, dy * len * 0.7, C[5], 0.3);
+ }
+ // the core: blazing white heart, a gold rim, a thin ring of light just outside that turns the other way
+ p.circle(0, 0, 8.5, (d) => (d < 0.55 ? WHITE : d < 0.8 ? C[6] : C[5]));
+ p.ring(0, 0, 11, 1, C[6], (v, a) => (Math.sin(a * 6 - ph * TAU) > -0.2 ? 1 : 0));
+ // glints winking at the tips of the long rays
+ cycle(t, meta.duration, 3, S, 0.4, (age, life, r, j) => {
+ const k = age / life, i = 2 * r.int(0, n / 2 - 1), a = rot + (i * TAU) / n + (age / meta.duration) * ((TAU * 2) / n), d = L + 2 * breathe + 2;
+ sparkle(p, Math.cos(a) * d, Math.sin(a) * d, k < 0.25 ? 1 : k < 0.6 ? 2 : k < 0.85 ? 1 : 0, C[6], C[5], WHITE);
+ });
+ p.glow(0, 0, L + 8, C[4], 0.28 + 0.04 * breathe);
+ p.glow(0, 0, 12, C[6], 0.45);
+}
diff --git a/src/fx/ice/_lib.js b/src/fx/ice/_lib.js
new file mode 100644
index 0000000..e7ea4f9
--- /dev/null
+++ b/src/fx/ice/_lib.js
@@ -0,0 +1,99 @@
+// Shared by the ice effects: palette fitting, faceted spikes and shards, snowflakes and glints.
+// Files starting with _ are helpers, not effects.
+
+import { ramp, TAU } from "../../core/index.js";
+
+/** Any palette as exactly n steps (nearest step, never blended), so an effect can index I[0..n-1]. */
+export function fit(pal, n = 8) {
+ const r = ramp(pal);
+ return Array.from({ length: n }, (_, i) => r[Math.round((i * (r.length - 1)) / (n - 1))]);
+}
+
+/**
+ * A crystal spike growing up from (x, y): base half-width w, height h, tip leaning by `lean` px. Two facets,
+ * lit on the left, a white ridge from the tip, a dark edge on the shadow side. I is an 8-step ice ramp.
+ */
+export function spike(p, x, y, w, h, lean, I, a = 1) {
+ if (h < 1 || w < 0.5) return;
+ const tx = x + lean, ty = y - h, rx = x + w * 0.2;
+ p.poly([[x - w, y], [rx, y], [tx, ty]], I[6], a);
+ p.poly([[rx, y], [x + w, y], [tx, ty]], I[4], a);
+ p.line(x + w, y - 0.5, tx, ty, I[2], a);
+ p.line(rx, y - 0.5, tx, ty, (u) => (u > 0.45 ? I[7] : I[5]), a);
+ p.line(x - w, y - 0.5, tx, ty, I[5], a);
+ p.dot(tx, ty, I[7], a);
+}
+
+/**
+ * A shard: polygon pts (relative to its center) turned by rot and placed at (x, y). The face picks a step by
+ * how it's turned (it catches the light as it spins); edges facing up-left go white, edges facing
+ * down-right take the dark step.
+ */
+export function shard(p, x, y, pts, rot, I, a = 1, tint = null) {
+ const c = Math.cos(rot), s = Math.sin(rot), q = pts.map(([px, py]) => [x + px * c - py * s, y + px * s + py * c]);
+ const face = tint ?? (Math.cos(rot * 2 + 0.6) > 0.3 ? I[6] : Math.cos(rot * 2 + 0.6) > -0.4 ? I[5] : I[4]);
+ p.poly(q, face, a);
+ for (let i = 0; i < q.length; i++) {
+ const [ax, ay] = q[i], [bx, by] = q[(i + 1) % q.length], nx = by - ay, ny = -(bx - ax), L = Math.hypot(nx, ny) || 1;
+ const lit = (-nx - ny) / L;
+ if (tint === null) p.line(ax, ay, bx, by, lit > 0.35 ? I[7] : lit < -0.35 ? I[2] : face, a);
+ }
+}
+
+/** A random shard outline: n corners around a center, radius about r (r is an Rng). */
+export function shardPts(r, rad, n = r.int(3, 4)) {
+ const pts = [], a0 = r.range(0, TAU);
+ for (let i = 0; i < n; i++) {
+ const a = a0 + (i / n) * TAU + r.range(-0.4, 0.4), d = rad * r.range(0.6, 1.2) * (i === 0 ? 1.4 : 1);
+ pts.push([Math.cos(a) * d, Math.sin(a) * d]);
+ }
+ return pts;
+}
+
+// small flakes as hand-made sprites, a sixth of a turn apart, so they stay crisp as they spin
+const SMALL_FLAKES = [
+ ["t...t", ".a.a.", "taoat", ".a.a.", "t...t"],
+ ["..t..", "t.a.t", ".aoa.", "t.a.t", "..t.."],
+];
+
+/**
+ * A six-armed snowflake of radius r turned by rot: arms with a pair of side branches, white tips and core.
+ * Below r 3 it's a small sprite that flips between two poses as it turns; below 1.5 a plus.
+ */
+export function flake(p, x, y, r, rot, arm, tip, core, a = 1) {
+ if (r < 1.5) {
+ p.dot(x, y, core, a);
+ if (r >= 1) for (const [dx, dy] of [[1, 0], [-1, 0], [0, 1], [0, -1]]) p.dot(x + dx, y + dy, arm, a);
+ return;
+ }
+ if (r < 3) {
+ const pose = Math.floor((((rot % (TAU / 6)) + TAU / 6) % (TAU / 6)) / (TAU / 12));
+ p.sprite(SMALL_FLAKES[pose], { a: arm, t: tip, o: core }, Math.round(x) - 2, Math.round(y) - 2, { a });
+ return;
+ }
+ for (let k = 0; k < 6; k++) {
+ const t = rot + (k * TAU) / 6, cx = Math.cos(t), cy = Math.sin(t);
+ p.line(x, y, x + cx * r, y + cy * r, arm, a);
+ if (r >= 3.5) {
+ const bx = x + cx * r * 0.55, by = y + cy * r * 0.55, bl = r * 0.36;
+ for (const sgn of [-1, 1]) {
+ const b = t + sgn * 0.95;
+ p.line(bx, by, bx + Math.cos(b) * bl, by + Math.sin(b) * bl, arm, a);
+ }
+ }
+ p.dot(x + cx * r, y + cy * r, tip, a);
+ }
+ p.dot(x, y, core, a);
+ if (r >= 4) for (const [dx, dy] of [[1, 0], [-1, 0], [0, 1], [0, -1]]) p.dot(x + dx, y + dy, core, a);
+}
+
+/** A four-point twinkle: arms of length s (0 is one pixel) in `arm`, a `core` center, dimmer tips. */
+export function glint(p, x, y, s, arm, core, a = 1) {
+ x = Math.round(x);
+ y = Math.round(y);
+ p.dot(x, y, core, a);
+ for (let i = 1; i <= s; i++) {
+ const c = i === s && s > 1 ? arm : i === 1 ? core : arm;
+ p.dot(x + i, y, c, a), p.dot(x - i, y, c, a), p.dot(x, y + i, c, a), p.dot(x, y - i, c, a);
+ }
+}
diff --git a/src/fx/ice/blizzard-vortex.js b/src/fx/ice/blizzard-vortex.js
new file mode 100644
index 0000000..ad8e943
--- /dev/null
+++ b/src/fx/ice/blizzard-vortex.js
@@ -0,0 +1,58 @@
+import { PAL, cycle, fract, clamp, tileNoise, TAU, WHITE } from "../../core/index.js";
+import { fit } from "./_lib.js";
+
+export const meta = {
+ name: "Blizzard vortex",
+ desc: "A snow tornado: a swaying funnel striped with spiralling bands, flakes whipping round it in front and behind, powder churning at its foot.",
+ tags: ["ice", "snow", "tornado", "vortex", "blizzard", "storm", "loop"],
+ size: [80, 92],
+ origin: [40, 86],
+ duration: 1.6,
+ loop: true,
+ fps: 30,
+ bg: "ground",
+ options: { palette: PAL.ice, height: 80, width: 24, seed: 29 },
+};
+
+export function draw(p, t, o) {
+ const I = fit(o.palette), S = o.seed, ph = t / meta.duration, H = o.height, Wd = o.width;
+ const hgt = (y) => clamp(-y / H);
+ const cx = (y) => Math.sin(ph * TAU + y * 0.05) * 3.5 * hgt(y);
+ const rad = (y) => 3 + Wd * Math.pow(hgt(y), 1.25);
+ // flakes whipping round the funnel: a rising spiral, fast near the ground; far side first
+ const flakes = (front) => cycle(t, meta.duration, 60, S, (r) => r.range(0.9, 1.5), (age, life, r) => {
+ const k = age / life, y = -r.range(2, 12) - k * r.range(50, 70), h = hgt(y);
+ const th = r.range(0, TAU) + age * (14 - 8 * h), z = Math.sin(th);
+ if (z > 0 !== front) return;
+ const R = rad(y) * r.range(0.95, 1.25) + k * 3, x = cx(y) + Math.cos(th) * R;
+ if (y < -H - 2) return;
+ if (front) {
+ const pth = th - 0.12, px = cx(y) + Math.cos(pth) * R;
+ p.line(px, y + 0.6, x, y, I[6]);
+ p.px(x, y, k < 0.7 ? WHITE : I[6]);
+ } else p.px(x, y, I[3]);
+ });
+ flakes(false);
+ // the funnel: spiralling bands of snow, edges catching the light
+ p.shade(-Wd - 8, -H - 2, Wd + 8, 0, (x, y) => {
+ const R = rad(y), u = (x - cx(y)) / R, h = hgt(y);
+ if (Math.abs(u) > 1) return;
+ // fray the top into clumps
+ const n = tileNoise((x - cx(y)) * 0.25 + ph * 0, y * 0.3 - ph * 12, 0, 12, S);
+ if (h > 0.82 && n < (h - 0.82) * 6 - 0.4) return;
+ const th = Math.asin(u), front = fract(th / TAU * 2 + y * 0.045 + ph * 3), back = fract((Math.PI - th) / TAU * 2 + y * 0.045 + ph * 3);
+ const wid = 0.12 + 0.05 * n;
+ if (Math.abs(u) > 0.9 && front < 0.5) return u < 0 ? I[5] : I[4];
+ if (front < wid) return u < 0.2 ? I[6] : I[5];
+ if (back < wid * 0.6 && h > 0.15) return I[2];
+ });
+ // powder churning at the foot
+ for (let i = 0; i < 9; i++) {
+ const a = ph * TAU * 2 + (i * TAU) / 9, rr = 6 + 3 * Math.sin(ph * TAU * 3 + i * 1.7);
+ const x = Math.cos(a) * rr, y = Math.sin(a) * 1.8 - 1;
+ p.circle(x, y, 1.6 + (i % 3) * 0.5, Math.sin(a) > 0 ? I[6] : I[5]);
+ }
+ p.ellipse(0, 0, 10, 1.5, I[5]);
+ flakes(true);
+ p.glow(cx(-H * 0.5), -H * 0.5, 40, I[4], 0.14);
+}
diff --git a/src/fx/ice/cold-mist.js b/src/fx/ice/cold-mist.js
new file mode 100644
index 0000000..35ba98a
--- /dev/null
+++ b/src/fx/ice/cold-mist.js
@@ -0,0 +1,39 @@
+import { PAL, tileFbm, clamp, seg, cycle, WHITE } from "../../core/index.js";
+import { fit, glint } from "./_lib.js";
+
+export const meta = {
+ name: "Cold mist",
+ desc: "Low freezing fog rolls along the floor in two layers drifting right at different speeds, thick at the ground, wispy on top, with ice glints winking in it.",
+ tags: ["ice", "mist", "fog", "cold", "ambient", "ground", "loop"],
+ size: [128, 32],
+ origin: [64, 26],
+ duration: 4,
+ loop: true,
+ fps: 30,
+ bg: "ground",
+ options: { palette: PAL.ice, width: 60, height: 15, seed: 32 },
+};
+
+export function draw(p, t, o) {
+ const I = fit(o.palette), S = o.seed, ph = t / meta.duration, HW = o.width, H = o.height;
+ // thick at the floor, thinning upward, and thinning out toward the ends so it has no hard edge
+ const body = (x, y) => Math.pow(clamp(1 - -y / H), 0.8) * (y > 2 ? clamp(1 - (y - 2) / 3) : 1) - seg(Math.abs(x), HW * 0.55, HW) * 0.9;
+ p.shade(-HW - 2, -H - 6, HW + 2, 5, (x, y) => {
+ const b = body(x, y);
+ if (b < -0.3) return;
+ // the front layer: pale streaks, faster
+ const f = b * 0.62 + tileFbm(x * 0.055 - ph * 11, y * 0.34 + 5, 11, 0, S + 1, 3) * 0.8;
+ if (f > 0.74) return I[6];
+ if (f > 0.58) return I[5];
+ // the back layer: dimmer, slower, showing through the gaps
+ const k = b * 0.55 + tileFbm(x * 0.04 - ph * 5, y * 0.28, 5, 0, S, 3) * 0.75;
+ if (k > 0.55) return I[3];
+ if (k > 0.45) return I[2];
+ });
+ // ice glints winking in the fog
+ cycle(t, meta.duration, 9, S + 2, (r) => r.range(0.3, 0.5), (age, life, r) => {
+ const x = r.range(-HW * 0.6, HW * 0.6) + age * 20, y = -r.range(1, H * 0.6), k = Math.sin((age / life) * Math.PI);
+ glint(p, x, y, k > 0.7 ? 1 : 0, I[6], WHITE);
+ });
+ p.glow(0, -4, HW * 0.9, I[4], 0.08);
+}
diff --git a/src/fx/ice/freeze.js b/src/fx/ice/freeze.js
new file mode 100644
index 0000000..1175fa0
--- /dev/null
+++ b/src/fx/ice/freeze.js
@@ -0,0 +1,105 @@
+import { PAL, burst, rng, seg, ease, fly, bolt, TAU, WHITE } from "../../core/index.js";
+import { fit, shard, shardPts, glint } from "./_lib.js";
+
+export const meta = {
+ name: "Freeze",
+ desc: "Frost creeps up the character from the feet, an ice block snaps shut around them, glints, cracks, then bursts apart into shards.",
+ tags: ["ice", "freeze", "frozen", "status", "crowd-control", "one-shot"],
+ size: [64, 52],
+ origin: [32, 44],
+ duration: 2.4,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ actor: true,
+ options: { palette: PAL.ice, seed: 23 },
+};
+
+const CREEP = [0.05, 0.5], SNAP = [0.42, 0.56], CRACK = [1.35, 1.72], BREAK = 1.72;
+const BX = 9, BH = 24, TOP = 4; // block half-width, height, depth of its top face
+
+export function drawBack(p, t, o) {
+ const I = fit(o.palette);
+ // frost spreading on the floor around the feet, melting after the break
+ const f = ease.outCubic(seg(t, 0.02, 0.4)) * (1 - ease.inQuad(seg(t, BREAK + 0.15, 2.3)));
+ if (f > 0.05) p.ellipse(0, 0.5, 14 * f, 2.5 * f, (d) => (d > 0.8 ? I[6] : I[5]));
+ // the block's far edges, seen through the ice
+ const s = blockRise(t);
+ if (s > 0 && t < BREAK) {
+ const top = -BH * s;
+ p.line(-BX + TOP, top - TOP, BX + TOP, top - TOP, I[4]);
+ p.line(BX + TOP, top - TOP, BX + TOP, -TOP + 0.5, I[3]);
+ }
+}
+
+const blockRise = (t) => ease.outBack(seg(t, SNAP[0], SNAP[1]), 1.6);
+
+export function draw(p, t, o) {
+ const I = fit(o.palette), S = o.seed, A = o.actor;
+ // frost on the character: it turns to ice from the feet up, a bright edge creeping ahead
+ if (t < BREAK) {
+ const line = -A.h * ease.inOutSine(seg(t, CREEP[0], CREEP[1]));
+ // (a color of 0 would still be written and punch a hole, so the alpha does the masking)
+ const iced = (mx, my) => (A.y + my >= line - 0.5 ? 1 : 0);
+ p.mask(A.mask, A.x, A.y, (mx, my) => {
+ if (A.y + my < line + 1) return I[7];
+ return mx < 4 || (mx + my) % 7 === 0 ? I[6] : mx > 8 ? I[4] : I[5];
+ }, iced);
+ p.outline(A.mask, A.x, A.y, I[3], iced);
+ }
+ const s = blockRise(t), jit = t > CRACK[0] && t < BREAK ? (Math.floor(t * 30) % 2 ? 1 : -1) * Math.round(seg(t, CRACK[0] + 0.15, BREAK)) : 0;
+ if (s > 0 && t < BREAK) {
+ const top = Math.round(-BH * s), x0 = -BX + jit, x1 = x0 + BX * 2 - 1;
+ if (t >= SNAP[0] + 0.06 && t < SNAP[0] + 0.094) {
+ // the snap: one frame of solid white block
+ p.rect(x0, top - TOP, BX * 2 + TOP, -top + TOP, WHITE);
+ } else {
+ // clear ice: hard edges, a top face catching the light, a darker side, streaks of shine
+ p.poly([[x0, top], [x0 + TOP, top - TOP], [x1 + 1 + TOP, top - TOP], [x1 + 1, top]], I[6]);
+ p.poly([[x1 + 1, top], [x1 + 1 + TOP, top - TOP], [x1 + 1 + TOP, -TOP], [x1 + 1, 0]], I[3]);
+ p.line(x1 + TOP, top - TOP + 1, x1 + TOP, -TOP, I[2]);
+ p.line(x0, top, x0, -1, I[6]);
+ p.line(x1, top, x1, -1, I[4]);
+ p.line(x0, top, x1, top, I[7]);
+ p.line(x0, -1, x1, -1, I[4]);
+ for (const [a, b] of [[4, 3], [7, 4], [14, 3]]) p.line(x0 + a, top + 2, x0 + a - b, top + 2 + b * 1.4, I[7]);
+ p.line(x1 - 2, -3, x1 - 5, -7, I[6]);
+ // a shine band sweeping across
+ const sw = seg(t, 0.75, 1.2);
+ if (sw > 0 && sw < 1) {
+ const sx = x0 - 6 + sw * (BX * 2 + 14);
+ p.shade(x0, top, x1, -1, (x, y) => (Math.abs(x - sx + (y - top) * 0.5) < 1 ? I[7] : 0));
+ }
+ // cracks running out from a point, growing until it gives
+ const c = seg(t, CRACK[0], BREAK);
+ if (c > 0) {
+ const path = bolt(rng(S, 1), x0 + 5, top + 5, x0 + 15, -3, { jag: 0.3, depth: 4 });
+ p.polyline(path.slice(0, Math.max(2, Math.floor(path.length * Math.min(1, c * 1.6)))), WHITE);
+ if (c > 0.4) p.polyline(bolt(rng(S, 2), x0 + 10, top + 11, x0 + 2, -5, { jag: 0.3, depth: 3 }).slice(0, Math.max(2, Math.floor(9 * (c - 0.4) / 0.6))), WHITE);
+ }
+ if (t > 0.6 && t < 1.3 && Math.sin(t * 18) > 0.8) glint(p, x1 + 1, top - 1, 2, I[6], WHITE);
+ }
+ }
+ // the break: a white frame, then shards fly out spinning and fall away; frost flakes off the character
+ if (t >= BREAK) {
+ const b = t - BREAK;
+ if (b < 0.034) p.rect(-BX - 1, -BH - TOP - 1, BX * 2 + TOP + 2, BH + TOP + 2, WHITE);
+ else burst(16, S + 9, (r, i) => {
+ const life = r.range(0.45, 0.65);
+ if (b > life) return;
+ const x0 = r.range(-BX, BX), y0 = -r.range(2, BH), dir = x0 / BX;
+ const [x, y] = fly(x0, y0, dir * r.range(22, 48) + r.range(-10, 10), -r.range(20, 70), b, 360, 1.2);
+ if (y > 1) return;
+ const sz = r.range(1.8, 3.4);
+ shard(p, x, Math.min(y, -sz), shardPts(r, sz), r.range(0, TAU) + b * r.range(-12, 12), I, 1 - seg(b, life * 0.65, life));
+ });
+ burst(10, S + 10, (r) => {
+ const life = r.range(0.3, 0.5);
+ if (b > life) return;
+ const [x, y] = fly(r.range(-5, 5), -r.range(2, 18), r.range(-30, 30), -r.range(10, 40), b, 200, 2);
+ if (y < 0) p.px(x, y, b / life < 0.5 ? I[7] : I[5]);
+ });
+ p.glow(0, -12, 30, I[5], 0.45 * (1 - seg(b, 0, 0.35)));
+ }
+ p.glow(0, -12, 24, I[4], 0.15 * seg(t, 0.4, 0.6) * (1 - seg(t, BREAK, BREAK + 0.2)));
+}
diff --git a/src/fx/ice/frost-breath.js b/src/fx/ice/frost-breath.js
new file mode 100644
index 0000000..1db432c
--- /dev/null
+++ b/src/fx/ice/frost-breath.js
@@ -0,0 +1,60 @@
+import { PAL, cycle, rng, seg, ease, wrap, noise2, TAU, WHITE } from "../../core/index.js";
+import { fit, glint } from "./_lib.js";
+
+export const meta = {
+ name: "Frost breath",
+ desc: "An icy gust blows right in a widening cone: frost puffs swell and tear apart, streaks of wind race past and ice crystals tumble and twinkle.",
+ tags: ["ice", "breath", "frost", "cone", "wind", "directional", "loop"],
+ size: [104, 44],
+ origin: [4, 22],
+ duration: 1,
+ loop: true,
+ fps: 30,
+ bg: "dark",
+ options: { palette: PAL.ice, length: 92, spread: 0.2, seed: 27 },
+};
+
+export function draw(p, t, o) {
+ const I = fit(o.palette), S = o.seed, D = meta.duration, L = o.length;
+ const half = (x) => 2 + x * o.spread * (1 - 0.2 * (x / L));
+ // frost puffs: blown out of the mouth, slowing, swelling, wearing away into rags
+ const puffs = [];
+ for (let i = 0; i < 20; i++) {
+ // births spread evenly through the loop so the gust never gaps
+ const r = rng(S, i), born = ((i + r.range(-0.3, 0.3)) / 20) * D, life = r.range(0.6, 0.75), age = wrap(t - born, D);
+ if (age >= life) continue;
+ const k = age / life, sp = r.range(150, 195), x = 5 + (sp / 1.2) * (1 - Math.exp(-1.2 * age));
+ const v = (((i * 7) % 20) / 19 - 0.5) * 1.5 * Math.min(1, 0.4 + k);
+ puffs.push({ x, y: v * half(x), r: 2 + 5 * ease.outCubic(k) * r.range(0.8, 1.2), f: 1 - seg(k, 0.3, 1), s: i * 5.3 });
+ }
+ p.shade(0, -21, L, 21, (x, y) => {
+ let best = -1, lit = 0;
+ for (const f of puffs) {
+ const dx = x - f.x, dy = y - f.y, d2 = (dx * dx + dy * dy) / (f.r * f.r);
+ if (d2 >= 1) continue;
+ const v = 1 - d2 - (1 - f.f) * 0.9 + noise2(dx * 0.5 + f.s, dy * 0.5, S) * 0.35 * (1.2 - f.f);
+ if (v > best) (best = v), (lit = (-dx * 0.6 - dy) / f.r);
+ }
+ if (best < 0.1) return;
+ const l = lit + best * 0.5;
+ return l > 0.75 ? I[7] : l > 0.15 ? I[6] : l > -0.45 ? I[5] : I[4];
+ });
+ // streaks of wind racing through
+ cycle(t, D, 18, S + 1, (r) => r.range(0.22, 0.38), (age, life, r) => {
+ const v = r.range(-0.95, 0.95), x = 4 + age * r.range(190, 260), y = Math.round(v * half(x)), len = r.range(4, 10) * (1 - age / life);
+ if (x - len > L) return;
+ p.line(Math.max(0, x - len), y, Math.min(x, L), y, age / life < 0.45 ? WHITE : I[5]);
+ });
+ // ice crystals tumbling along with the gust
+ cycle(t, D, 12, S + 2, (r) => r.range(0.6, 0.9), (age, life, r) => {
+ const k = age / life, v = r.range(-0.85, 0.85), x = 6 + age * r.range(80, 115), y = v * half(x) + Math.sin(age * 9 + r.next() * TAU) * 1.5;
+ if (x > L) return;
+ if (r.next() < 0.4 && k < 0.75) glint(p, x, y, Math.sin(age * 20 + r.next() * 6) > 0 ? 1 : 0, I[6], WHITE);
+ else p.px(x, y, k < 0.5 ? WHITE : I[5]);
+ });
+ // the mouth of it: a hard white jet
+ p.tri(0, -2.5, 0, 2.5, 14, 0, I[6]);
+ p.tri(0, -1.5, 0, 1.5, 9, 0, WHITE);
+ p.glow(2, 0, 12, I[6], 0.4);
+ p.glowLine(0, 0, L * 0.6, 0, 12, I[5], 0.1);
+}
diff --git a/src/fx/ice/frost-nova.js b/src/fx/ice/frost-nova.js
new file mode 100644
index 0000000..989641a
--- /dev/null
+++ b/src/fx/ice/frost-nova.js
@@ -0,0 +1,80 @@
+import { PAL, burst, rng, seg, ease, fly, noise2, TAU, WHITE } from "../../core/index.js";
+import { fit, spike, shard, shardPts, glint } from "./_lib.js";
+
+export const meta = {
+ name: "Frost nova",
+ desc: "A white flash at the feet, then a ring of ice crystals bursts outward across a frosting floor, slows, shatters into spinning shards and melts away.",
+ tags: ["ice", "nova", "frost", "aoe", "spell", "burst", "one-shot"],
+ size: [128, 64],
+ origin: [64, 48],
+ duration: 1.3,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ actor: true,
+ options: { palette: PAL.ice, radius: 46, count: 18, seed: 22 },
+};
+
+const Q = 0.28; // how flat the floor looks
+
+// the ring's radius, how tall its crystals stand, when each one shatters
+const ringR = (t, R) => 4 + (R - 4) * ease.outCubic(seg(t, 0.02, 0.5));
+const brk = (r) => 0.52 + r.range(0, 0.12);
+
+export function drawBack(p, t, o) {
+ const I = fit(o.palette), S = o.seed, R = ringR(t, o.radius);
+ // the frosted floor inside the ring: pale, veined with cracks, melting away at the end
+ const melt = ease.inQuad(seg(t, 0.7, 1.2)), fr = R * (1 - melt);
+ if (t > 0.02 && fr > 2)
+ p.shade(-fr, -fr * Q, fr, fr * Q, (x, y) => {
+ const d = Math.hypot(x / fr, y / (fr * Q));
+ if (d > 1 + noise2(Math.atan2(y / Q, x) * 3, 0, S) * 0.08) return;
+ // a bright frosted band behind the ring, the floor inside only tinted, veined with frost
+ const vein = Math.abs(noise2(x * 0.14, y * 0.45, S + 1)) < 0.07;
+ if (d > 0.9) return I[6];
+ if (d > 0.72 - melt * 0.3) return vein ? I[6] : I[5];
+ return vein ? I[5] : I[3];
+ });
+ crystals(p, t, o, I, false);
+}
+
+export function draw(p, t, o) {
+ const I = fit(o.palette);
+ crystals(p, t, o, I, true);
+ // the flash at the feet, and light that rides the ring then lets go
+ if (t < 0.07) {
+ p.ellipse(0, 0, 12, 4, WHITE);
+ p.rect(-2, -26, 5, 26, WHITE);
+ p.glow(0, -8, 40, I[5], 0.6);
+ }
+ const R = ringR(t, o.radius), L = 1 - seg(t, 0.1, 0.8);
+ for (const [x, y] of [[-R, 0], [R, 0], [0, R * Q]]) p.glow(x, y - 3, 18, I[5], 0.18 * L);
+ p.glow(0, -6, 30, I[4], 0.2 * L);
+}
+
+function crystals(p, t, o, I, front) {
+ const S = o.seed, n = o.count, R = ringR(t, o.radius);
+ for (let i = 0; i < n; i++) {
+ const r = rng(S, i), a = (i / n) * TAU + r.range(-0.12, 0.12), s = Math.sin(a);
+ if (s > 0 !== front) continue;
+ const cx = Math.cos(a), x = cx * R, y = s * R * Q, h = r.range(6, 13) * (front ? 1.1 : 0.85), b = brk(r);
+ const up = ease.outBack(seg(t, 0.02, 0.14), 2), J = front ? I : [I[0], I[1], I[1], I[2], I[3], I[4], I[5], I[6]];
+ if (t < b) {
+ spike(p, x - cx * 1.5, y, 1.6, h * 0.6 * up, -cx * 2 - 1.5, J);
+ spike(p, x, y, 2.2, h * up, cx * h * 0.45, J);
+ if (r.next() < 0.5) spike(p, x + cx * 2, y, 1.3, h * 0.45 * up, cx * h * 0.6 + 1, J);
+ if (t > 0.2 && Math.sin(t * 20 + i * 2.7) > 0.93) glint(p, x + cx * h * 0.3, y - h * 0.7, 1, I[6], WHITE);
+ continue;
+ }
+ // shattered: shards thrown outward and up, spinning, falling, fading
+ const age = t - b;
+ burst(3, S + 50 + i, (rr) => {
+ const life = rr.range(0.35, 0.55);
+ if (age > life) return;
+ const [sx, sy] = fly(x, y - h * rr.range(0.2, 0.8), cx * rr.range(15, 38) + rr.range(-8, 8), -rr.range(30, 70), age, 300, 1.5);
+ if (sy > y - 1) return;
+ shard(p, sx, sy, shardPts(rr, rr.range(1.4, 2.4)), rr.range(0, TAU) + age * rr.range(-14, 14), J, 1 - seg(age, life * 0.6, life));
+ });
+ if (age < 0.05) p.circle(x, y - h * 0.4, 2.5, WHITE);
+ }
+}
diff --git a/src/fx/ice/frozen-ground.js b/src/fx/ice/frozen-ground.js
new file mode 100644
index 0000000..62ac594
--- /dev/null
+++ b/src/fx/ice/frozen-ground.js
@@ -0,0 +1,60 @@
+import { PAL, burst, rng, seg, ease, noise, noise2, WHITE } from "../../core/index.js";
+import { fit, spike, glint } from "./_lib.js";
+
+export const meta = {
+ name: "Frozen ground",
+ desc: "Frost creeps out across the floor in feathery fingers, little crystals sprout as it passes and glint; then it all goes glassy, wet and melts away.",
+ tags: ["ice", "frost", "ground", "freeze", "aoe", "trap", "one-shot"],
+ size: [128, 32],
+ origin: [64, 20],
+ duration: 2.6,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ options: { palette: PAL.ice, radius: 56, count: 14, seed: 30 },
+};
+
+const Q = 0.15, MELT = [1.5, 2.45];
+
+export function draw(p, t, o) {
+ const I = fit(o.palette), S = o.seed, R = o.radius;
+ const grow = ease.outCubic(seg(t, 0, 0.95)), melt = seg(t, MELT[0], MELT[1]), F = R * grow * (1 - ease.inQuad(melt) * 0.25);
+ // the frost: feathery fingers at the edge, fresh white at the front, pale and veined inside;
+ // melting, it darkens to wet ice and wears away into puddles
+ if (F > 1)
+ p.shade(-F - 3, -F * Q - 1, F + 3, F * Q + 2, (x, y) => {
+ const yy = y - 1, a = Math.atan2(yy / Q, x), d = Math.hypot(x, yy / Q) / F;
+ const fingers = 0.07 * noise(a * 9, S) + 0.05 * noise(a * 21, S + 1);
+ const edge = 1 + fingers - (1 - grow) * 0.02;
+ if (d > edge) return;
+ const wear = melt > 0 ? noise2(x * 0.18, yy * 0.6, S + 3) * 0.5 + 0.5 : 1;
+ if (melt > 0 && wear < melt * 1.25) return;
+ const vein = Math.abs(noise2(x * 0.16, yy * 0.5, S + 4)) < 0.06;
+ if (melt > 0.15) return vein || d > edge - 0.08 ? I[4] : melt > 0.5 ? I[2] : I[3];
+ if (d > edge - 0.035) return grow < 1 ? WHITE : I[7];
+ if (d > edge - 0.11) return I[6];
+ return vein ? I[6] : d < 0.5 ? I[4] : I[5];
+ });
+ // crystals sprouting where the frost has reached; they shrink and drip as it melts
+ for (let i = 0; i < o.count; i++) {
+ const r = rng(S, i), side = i % 2 ? 1 : -1, x = side * r.range(4, R * 0.88), y = r.range(-0.5, 2.5);
+ const reach = Math.hypot(x, (y - 1) / Q) / R;
+ const born = reach < 1 ? 0.95 * (1 - Math.cbrt(1 - reach)) : 9, age = t - born;
+ if (age < 0) continue;
+ const h = r.range(3, 7) * ease.outBack(seg(age, 0, 0.15), 2.4) * (1 - ease.inQuad(seg(t, MELT[0] + 0.1, MELT[0] + 0.6 + r.range(0, 0.25))));
+ if (h > 0.8) spike(p, x, y, 1.4, h, side * r.range(0.5, 2), I);
+ if (h > 3 && Math.sin(t * 17 + i * 2.3) > 0.94 && t < MELT[0]) glint(p, x + side, y - h, 1, I[6], WHITE);
+ if (melt > 0.15 && melt < 0.8 && h > 0.8) {
+ const dk = (t * 2.2 + i * 0.37) % 1;
+ p.px(x, y - h * (1 - dk) + dk * 2, I[5]);
+ }
+ }
+ // cold vapour lifting off the fresh frost
+ burst(10, S + 9, (r) => {
+ const t0 = r.range(0.2, 1.3), life = r.range(0.6, 0.9), a = t - t0;
+ if (a < 0 || a > life) return;
+ const x = r.range(-R * 0.8, R * 0.8) * grow, y = -1 - a * r.range(8, 14);
+ p.px(x + Math.sin(a * 6 + x) * 1.5, y, a / life < 0.5 ? I[6] : I[4]);
+ });
+ p.glow(0, 0, R * 0.9, I[4], 0.14 * grow * (1 - melt));
+}
diff --git a/src/fx/ice/hail-impact.js b/src/fx/ice/hail-impact.js
new file mode 100644
index 0000000..76d6d69
--- /dev/null
+++ b/src/fx/ice/hail-impact.js
@@ -0,0 +1,71 @@
+import { PAL, rng, wrap, clamp, WHITE } from "../../core/index.js";
+import { fit } from "./_lib.js";
+
+export const meta = {
+ name: "Hail impact",
+ desc: "Hailstones pelt the ground at a slant: each hits with a white crack and a puff of powder, bounces, hops, and melts away; some burst into chips.",
+ tags: ["ice", "hail", "weather", "storm", "impact", "ambient", "loop"],
+ size: [80, 48],
+ origin: [40, 42],
+ duration: 1.2,
+ loop: true,
+ fps: 30,
+ bg: "ground",
+ options: { palette: PAL.ice, count: 16, width: 27, seed: 33 },
+};
+
+const G = 900;
+const STONE = { 4: [".ab.", "abbc", "bbcc", ".cc."], 3: ["ab.", "abc", ".cc"], 2: ["ab", "bc"], 1: ["b"] };
+
+export function draw(p, t, o) {
+ const I = fit(o.palette), S = o.seed, D = meta.duration, n = o.count, HW = o.width, pal = { a: WHITE, b: I[6], c: I[4] };
+ const stone = (x, y, s) => {
+ const rows = STONE[s];
+ p.sprite(rows, pal, Math.round(x) - (rows[0].length >> 1), Math.round(y) - rows.length + 1);
+ };
+ for (let i = 0; i < n; i++) {
+ const r = rng(S, i), born = ((i + r.range(-0.3, 0.3)) / n) * D, lane = (i * 5) % n;
+ const x0 = -HW + ((lane + r.range(0.15, 0.85)) / n) * HW * 2, depth = r.range(-1, 3), size = r.next() < 0.35 ? 4 : r.next() < 0.5 ? 3 : 2;
+ const fallT = r.range(0.08, 0.1), vy = (32 + depth) / fallT, vx = vy * 0.16, burstOn = r.next() < 0.3;
+ const age = wrap(t - born, D);
+ if (age < fallT) {
+ // falling: a streak behind a hard little stone
+ const x = x0 - vx * (fallT - age), y = depth - vy * (fallT - age);
+ p.line(x - vx * 0.012, y - vy * 0.012 - size + 1, x - vx * 0.004, y - size, I[5]);
+ stone(x, y, size);
+ continue;
+ }
+ const a = age - fallT;
+ // the hit: a white crack and a puff of powder
+ if (a < 0.035) {
+ p.line(x0 - 2, depth - 1, x0 + 2, depth - 1, WHITE);
+ p.px(x0, depth - 2, WHITE);
+ p.light(x0, depth - 1, I[6], 0.6);
+ }
+ for (let j = 0; j < 4; j++) {
+ const pa = a * (1 - j * 0.1), life = 0.22;
+ if (pa > life) continue;
+ const dir = j < 2 ? -1 : 1, x = x0 + dir * (1 + pa * (j % 2 ? 22 : 40)), y = depth - 1 - pa * (j % 2 ? 26 : 14) + pa * pa * 60;
+ p.px(x, y, pa < life * 0.5 ? I[6] : I[4]);
+ }
+ if (burstOn) {
+ // this one bursts: chips flung out low
+ for (let j = 0; j < 4; j++) {
+ const life = 0.3, vxj = (j - 1.5) * r.range(18, 30), vyj = -r.range(40, 70), tj = Math.min(a, (-2 * vyj) / G);
+ if (a > life) continue;
+ p.px(x0 + vxj * a, depth - 1 + vyj * tj + 0.5 * G * tj * tj, a < life * 0.6 ? WHITE : I[5]);
+ }
+ continue;
+ }
+ // bounce, hop, rest, melt
+ const h1 = r.range(5, 9), h2 = h1 * 0.3, T1 = 2 * Math.sqrt((2 * h1) / G), T2 = 2 * Math.sqrt((2 * h2) / G), vxb = r.range(14, 30);
+ let x, y;
+ if (a < T1) (x = x0 + vxb * a), (y = depth - (h1 - 0.5 * G * (a - T1 / 2) ** 2));
+ else if (a < T1 + T2) { const b = a - T1; (x = x0 + vxb * T1 + vxb * 0.5 * b), (y = depth - (h2 - 0.5 * G * (b - T2 / 2) ** 2)); }
+ else (x = x0 + vxb * T1 + vxb * 0.5 * T2), (y = depth);
+ const rest = a - T1 - T2, melt = clamp(rest / 0.35), s = melt < 0.4 ? size : melt < 0.75 ? Math.max(1, size - 1) : 1;
+ if (melt >= 1) continue;
+ stone(x, Math.min(depth, y), s);
+ if (melt > 0.5) p.px(x + 1, depth, I[3]);
+ }
+}
diff --git a/src/fx/ice/ice-crystal.js b/src/fx/ice/ice-crystal.js
new file mode 100644
index 0000000..8c08e6a
--- /dev/null
+++ b/src/fx/ice/ice-crystal.js
@@ -0,0 +1,72 @@
+import { PAL, TAU, fract, WHITE } from "../../core/index.js";
+import { fit, glint } from "./_lib.js";
+
+export const meta = {
+ name: "Ice crystal",
+ desc: "A floating six-sided ice crystal turns slowly and bobs: its facets catch the light in turn, a shine sweeps across, a star winks at its tip, motes circle.",
+ tags: ["ice", "crystal", "gem", "floating", "pickup", "magic", "loop"],
+ size: [48, 64],
+ origin: [24, 32],
+ duration: 2.4,
+ loop: true,
+ fps: 30,
+ bg: "dark",
+ options: { palette: PAL.ice, size: 1.2, seed: 31 },
+};
+
+// toward the light: up, left and toward the viewer (y is down, -z comes out of the screen)
+const TILT = 0.32, LIGHT = (() => { const v = [-0.6, -0.7, -0.4], l = Math.hypot(...v); return v.map((c) => c / l); })();
+
+export function draw(p, t, o) {
+ const I = fit(o.palette), k = o.size, ph = t / meta.duration, bob = Math.round(Math.sin(ph * TAU) * 2);
+ const rot = (ph * TAU) / 6; // a sixth of a turn a loop: the crystal looks the same after it, so it loops
+ const ct = Math.cos(TILT), st = Math.sin(TILT);
+ const P = (x, y, z) => [x, y * ct - z * st + bob, y * st + z * ct]; // tilt toward the viewer
+ const top = P(0, -17 * k, 0), bot = P(0, 13 * k, 0);
+ const ring = Array.from({ length: 6 }, (_, i) => {
+ const a = rot + (i * TAU) / 6;
+ return P(Math.cos(a) * 8.5 * k, -1 * k, Math.sin(a) * 8.5 * k);
+ });
+ // motes circling it, the far ones behind
+ const motes = (front) => {
+ for (let i = 0; i < 5; i++) {
+ const a = ph * TAU * 2 + (i * TAU) / 5, z = Math.sin(a);
+ if (z > 0 !== front) continue;
+ const x = Math.cos(a) * 17, y = bob + Math.sin(a) * 4 + Math.sin(ph * TAU * 3 + i) * 7;
+ p.px(x, y, front ? (Math.sin(t * 20 + i) > 0 ? WHITE : I[6]) : I[3]);
+ }
+ };
+ motes(false);
+ // faces: only those turned toward us, shaded by the light, a shine band sweeping across them
+ const faces = [];
+ for (let i = 0; i < 6; i++) {
+ const a = ring[i], b = ring[(i + 1) % 6];
+ faces.push([top, a, b], [bot, b, a]);
+ }
+ const sweep = fract(ph * 2) * 70 - 30;
+ for (const f of faces) {
+ const [a, b, c] = f, ux = b[0] - a[0], uy = b[1] - a[1], uz = b[2] - a[2], vx = c[0] - a[0], vy = c[1] - a[1], vz = c[2] - a[2];
+ let nx = uy * vz - uz * vy, ny = uz * vx - ux * vz, nz = ux * vy - uy * vx;
+ const nl = Math.hypot(nx, ny, nz) || 1;
+ (nx /= nl), (ny /= nl), (nz /= nl);
+ if (nz > 0) continue; // facing away from us
+ const lit = nx * LIGHT[0] + ny * LIGHT[1] + nz * LIGHT[2];
+ const base = lit > 0.75 ? 6 : lit > 0.45 ? 5 : lit > 0.1 ? 4 : lit > -0.25 ? 3 : 2;
+ p.poly([[a[0], a[1]], [b[0], b[1]], [c[0], c[1]]], (x, y) => (Math.abs(x + y * 0.6 - sweep) < 2 ? I[Math.min(7, base + 2)] : I[base]));
+ }
+ // edges: the silhouette in the dark step, the ridges between faces lighter
+ for (let i = 0; i < 6; i++) {
+ const a = ring[i], b = ring[(i + 1) % 6];
+ if (a[2] > 0.5 || b[2] > 0.5) continue; // only the near half's edges show
+ p.line(top[0], top[1], a[0], a[1], a[0] < 0 ? I[7] : I[5]);
+ p.line(a[0], a[1], b[0], b[1], I[6]);
+ }
+ const xs = ring.map((v) => v[0]), L = ring[xs.indexOf(Math.min(...xs))], R = ring[xs.indexOf(Math.max(...xs))];
+ p.polyline([[top[0], top[1]], [R[0], R[1]], [bot[0], bot[1]], [L[0], L[1]], [top[0], top[1]]], I[2]);
+ // a star winks at the tip now and then
+ const wink = Math.sin(ph * TAU * 2 + 1);
+ if (wink > 0.6) glint(p, top[0], top[1], wink > 0.9 ? 3 : 2, I[6], WHITE);
+ motes(true);
+ p.glow(0, bob, 26, I[4], 0.22);
+ p.glow(0, bob - 3, 9, I[6], 0.2);
+}
diff --git a/src/fx/ice/ice-lance.js b/src/fx/ice/ice-lance.js
new file mode 100644
index 0000000..fa73c76
--- /dev/null
+++ b/src/fx/ice/ice-lance.js
@@ -0,0 +1,79 @@
+import { PAL, cycle, rng, seg, ease, wrap, noise2, fract, WHITE } from "../../core/index.js";
+import { fit, glint } from "./_lib.js";
+
+export const meta = {
+ name: "Ice lance",
+ desc: "A faceted spear of ice flies right: a glint racing down its shaft, frozen fins at the tail and a trail of frost puffs, wind lines and twinkling crystals.",
+ tags: ["ice", "lance", "spear", "projectile", "frost", "directional", "loop"],
+ size: [96, 28],
+ origin: [86, 14],
+ duration: 0.6,
+ loop: true,
+ fps: 30,
+ bg: "dark",
+ options: { palette: PAL.ice, seed: 28 },
+};
+
+const TIP = 6, NECK = -8, TAIL = -28;
+
+export function draw(p, t, o) {
+ const I = fit(o.palette), S = o.seed, D = meta.duration, ph = t / D;
+ // the frost trail: puffs shed from the tail, falling behind, swelling and wearing away
+ const puffs = [];
+ for (let i = 0; i < 9; i++) {
+ const r = rng(S, i), born = ((i + r.range(-0.3, 0.3)) / 9) * D, life = r.range(0.4, 0.55), age = wrap(t - born, D);
+ if (age >= life) continue;
+ const k = age / life;
+ puffs.push({ x: TAIL - 2 - age * r.range(85, 110), y: r.range(-2.5, 2.5) * (0.5 + k), r: 1.2 + 3.2 * ease.outCubic(k), f: 1 - seg(k, 0.2, 1), s: i * 4.1 });
+ }
+ p.shade(-86, -12, TAIL, 12, (x, y) => {
+ let best = -1, lit = 0;
+ for (const f of puffs) {
+ const dx = x - f.x, dy = y - f.y, d2 = (dx * dx + dy * dy) / (f.r * f.r);
+ if (d2 >= 1) continue;
+ const v = 1 - d2 - (1 - f.f) * 0.9 + noise2(dx * 0.6 + f.s, dy * 0.6, S) * 0.35 * (1.2 - f.f);
+ if (v > best) (best = v), (lit = (-dx * 0.5 - dy) / f.r);
+ }
+ if (best < 0.1) return;
+ return lit > 0.3 ? I[6] : lit > -0.4 ? I[5] : I[4];
+ });
+ // wind lines streaming back off the lance
+ cycle(t, D, 8, S + 1, (r) => r.range(0.15, 0.25), (age, life, r) => {
+ const y = r.pick([-6, -5, 4, 5, -8, 7]), x = r.range(-14, 0) - age * r.range(200, 250), len = r.range(6, 12) * (1 - age / life);
+ if (x - len < -84) return;
+ p.line(x, y, x - len, y, age / life < 0.4 ? I[6] : I[4]);
+ });
+ // crystals left twinkling in its wake
+ cycle(t, D, 10, S + 2, (r) => r.range(0.3, 0.5), (age, life, r) => {
+ const k = age / life, x = TAIL + 2 - age * r.range(100, 130), y = r.range(-6, 6) + age * r.range(-6, 10);
+ if (x < -84) return;
+ if (Math.sin(age * 30 + r.next() * 6) > 0.3 && k < 0.7) glint(p, x, y, 1, I[5], WHITE);
+ else p.px(x, y, k < 0.5 ? I[7] : I[5]);
+ });
+ // frozen fins at the tail: jagged spikes swept back
+ for (const [dy, len, lean, c] of [[-1, 8, -4.5, 6], [1, 8, 4, 3], [0, 10, 0, 5]]) {
+ const bx = TAIL + 5;
+ p.tri(bx, dy - 1, bx, dy + 1, bx - len, dy + lean, I[c]);
+ }
+ // the shaft: thin, top facet lit, a white ridge, the underside dark
+ p.shade(TAIL, -3, NECK + 1, 3, (x, y) => {
+ const u = (x - TAIL) / (NECK - TAIL), w = 1.1 + 0.8 * u;
+ if (Math.abs(y + 0.5) > w) return;
+ const v = (y + 0.5) / w;
+ if (v < -0.5) return I[6];
+ if (v < 0) return I[7];
+ return v < 0.6 ? I[4] : I[2];
+ });
+ // the head: a broad diamond point, the upper facets catching the light
+ p.poly([[NECK - 3, -0.5], [NECK + 4, -5], [TIP, -0.5]], I[6]);
+ p.poly([[NECK - 3, -0.5], [NECK + 4, 4], [TIP, -0.5]], I[4]);
+ p.poly([[NECK + 4, -5], [TIP, -0.5], [NECK + 6, -0.5]], I[7]);
+ p.line(NECK - 3, 0, NECK + 4, 4, I[2]);
+ p.line(NECK + 4, 4, TIP, 0, I[2]);
+ p.line(NECK - 2, -0.5, TIP - 1, -0.5, WHITE);
+ // a glint racing down the shaft every loop
+ const gx = TIP - fract(ph) * (TIP - TAIL + 6);
+ if (gx > TAIL) glint(p, gx, -1, gx > NECK ? 2 : 1, I[6], WHITE);
+ p.glowLine(TAIL, 0, TIP, 0, 9, I[5], 0.22);
+ p.glow(TIP - 2, 0, 10, I[6], 0.35);
+}
diff --git a/src/fx/ice/ice-shatter.js b/src/fx/ice/ice-shatter.js
new file mode 100644
index 0000000..0605744
--- /dev/null
+++ b/src/fx/ice/ice-shatter.js
@@ -0,0 +1,79 @@
+import { PAL, burst, rng, seg, ease, bolt, TAU, WHITE } from "../../core/index.js";
+import { fit, shard, shardPts, glint } from "./_lib.js";
+
+export const meta = {
+ name: "Ice shatter",
+ desc: "A block of ice cracks, shudders and bursts: a white frame, then shards spin out, bounce once on the floor and skid to nothing in a haze of ice dust.",
+ tags: ["ice", "shatter", "break", "destroy", "crystal", "one-shot"],
+ size: [96, 56],
+ origin: [48, 48],
+ duration: 1.2,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ options: { palette: PAL.ice, size: 1, seed: 24 },
+};
+
+const BREAK = 0.2, G = 420, BW = 8, BH = 15, D = 4; // block half-width, height, depth of its top face
+
+// where a shard is after t seconds: thrown from (x, y), one bounce off the floor, then a skid
+function toss(x, y, vx, vy, t) {
+ const tl = (-vy + Math.sqrt(vy * vy - 2 * G * y)) / G;
+ if (t < tl) return [x + vx * t, y + vy * t + 0.5 * G * t * t, false];
+ const b = t - tl, ux = vx * 0.55, uy = -(vy + G * tl) * 0.3, t2 = (-2 * uy) / G;
+ if (b < t2) return [x + vx * tl + ux * b, uy * b + 0.5 * G * b * b, true];
+ const s = b - t2, x2 = x + vx * tl + ux * t2;
+ return [x2 + ux * 0.25 * (1 - Math.exp(-6 * s)), 0, true];
+}
+
+export function draw(p, t, o) {
+ const I = fit(o.palette), S = o.seed, k = o.size;
+ if (t < BREAK) {
+ // the block: a lit top, a clear front with streaks, a dark side; cracks spread and it shudders
+ const c = seg(t, 0.04, BREAK), j = t > 0.1 ? (Math.floor(t * 60) % 2 ? 1 : -1) : 0;
+ const x0 = -BW * k + j, x1 = BW * k - 1 + j, top = -BH * k;
+ p.rect(x0, top, x1 - x0 + 1, -top, I[5]);
+ p.poly([[x0, top], [x0 + D, top - D], [x1 + 1 + D, top - D], [x1 + 1, top]], I[6]);
+ p.poly([[x1 + 1, top], [x1 + 1 + D, top - D], [x1 + 1 + D, -D], [x1 + 1, 0]], I[3]);
+ p.line(x0, top, x1, top, I[7]);
+ p.line(x0, top, x0, -1, I[6]);
+ p.line(x1, top + 1, x1, -1, I[4]);
+ p.line(x0, -1, x1, -1, I[4]);
+ for (const [a, b] of [[3, 3], [6, 5]]) p.line(x0 + a, top + 2, x0 + a - b + 1, top + 2 + b * 1.3, I[7]);
+ p.rect(x0 + 2, top + 4, x1 - x0 - 4, -top - 6, I[4]);
+ if (c > 0) {
+ const path = bolt(rng(S, 1), x0 + 2, top + 3, x1 - 2, -3, { jag: 0.35, depth: 4 });
+ p.polyline(path.slice(0, Math.max(2, Math.ceil(path.length * c))), WHITE);
+ if (c > 0.5) p.polyline(bolt(rng(S, 2), x1 - 3, top + 2, x0 + 3, -4, { jag: 0.35, depth: 3 }).slice(0, Math.ceil(9 * (c - 0.5) * 2)), WHITE);
+ }
+ if (t > 0.1) p.glow(0, top * 0.5, 22, I[5], 0.2 * c);
+ return;
+ }
+ const b = t - BREAK;
+ // the break: one frame of white block, a ring of light
+ if (b < 0.034) {
+ p.rect(-BW * k - 1, -BH * k - D - 1, BW * 2 * k + D + 2, BH * k + D + 2, WHITE);
+ p.glow(0, -BH * k * 0.5, 34, I[6], 0.6);
+ return;
+ }
+ // shards: thrown out from the middle, spinning, one bounce, a skid, shrinking away
+ burst(18, S, (r, i) => {
+ const life = r.range(0.6, 0.95), q = b / life;
+ if (q >= 1) return;
+ const cx = r.range(-BW, BW) * k, cy = -r.range(1, BH) * k, dx = cx / (BW * k), up = (-cy / (BH * k));
+ const vx = (dx * r.range(25, 55) + r.range(-10, 10)) * k, vy = -(r.range(50, 105) * (0.4 + up)) * k;
+ const [x, y, landed] = toss(cx, cy, vx, vy, b);
+ const spin = r.range(0, TAU) + (landed ? 1 : b) * r.range(-16, 16), size = r.range(1.6, 3.6) * k * (1 - ease.inQuad(seg(q, 0.55, 1)));
+ if (size < 0.6) return;
+ shard(p, x, Math.min(0, y - size * 0.5), shardPts(rng(S, i, 5), size), spin, I);
+ if (i % 5 === 0 && !landed && Math.sin(b * 30 + i) > 0.6) glint(p, x, y - size, 1, I[6], WHITE);
+ });
+ // ice dust: fine bright specks hanging and drifting down
+ burst(22, S + 1, (r) => {
+ const life = r.range(0.4, 0.8);
+ if (b > life) return;
+ const e = (1 - Math.exp(-4 * b)) / 4, x = r.range(-BW, BW) + r.range(-60, 60) * e, y = -r.range(2, BH) - r.range(10, 50) * e + b * b * 30;
+ if (y < 0) p.px(x, y, b / life < 0.5 ? I[7] : I[5]);
+ });
+ p.glow(0, -8, 28, I[5], 0.3 * (1 - seg(b, 0, 0.4)));
+}
diff --git a/src/fx/ice/ice-spikes.js b/src/fx/ice/ice-spikes.js
new file mode 100644
index 0000000..e2d752e
--- /dev/null
+++ b/src/fx/ice/ice-spikes.js
@@ -0,0 +1,67 @@
+import { PAL, burst, rng, seg, ease, fly, TAU, WHITE } from "../../core/index.js";
+import { fit, spike, shard, shardPts, glint } from "./_lib.js";
+
+export const meta = {
+ name: "Ice spikes",
+ desc: "A row of ice spikes bursts out of the ground one after another to the right, each taller than the last, then shatters into tumbling shards.",
+ tags: ["ice", "spikes", "frost", "ground", "attack", "directional", "one-shot"],
+ size: [144, 64],
+ origin: [14, 56],
+ duration: 1.5,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ options: { palette: PAL.ice, count: 6, spacing: 18, seed: 21 },
+};
+
+export function draw(p, t, o) {
+ const I = fit(o.palette), S = o.seed, n = o.count;
+ for (let i = 0; i < n; i++) {
+ const r = rng(S, i), x = 8 + i * o.spacing + r.range(-2, 2), h = 14 + i * 6 + r.range(-2, 2);
+ const born = 0.03 + i * 0.06, brk = 0.74 + i * 0.045, age = t - born;
+ if (age < 0) continue;
+ const up = ease.outBack(seg(age, 0, 0.12), 2.2), broken = t >= brk;
+ // the frost slab it stands on, melting away after it breaks
+ const slab = (6 + h * 0.3) * (1 - ease.inQuad(seg(t, brk + 0.05, brk + 0.4)));
+ if (slab > 1) {
+ p.ellipse(x, 0.5, slab, 1.8, (d, a) => (d > 0.75 ? I[4] : Math.sin(a) < 0 ? I[6] : I[5]));
+ }
+ const w = 2.5 + h * 0.1, lean = h * 0.1, flash = broken && t - brk < 0.034;
+ if (!broken || flash) {
+ // a smaller spike leaning back behind, the main spike, a stubby one leaning forward in front
+ const J = flash ? Array(8).fill(WHITE) : I;
+ spike(p, x - w * 0.9, 0, w * 0.6, h * 0.55 * up, -h * 0.22, J);
+ spike(p, x, 0, w, h * up, lean, J);
+ spike(p, x + w * 0.9, 0, w * 0.55, h * 0.4 * up, h * 0.25, J);
+ // a glint runs up the ridge while it stands
+ const g = seg(t, born + 0.2, born + 0.55);
+ if (!flash && g > 0 && g < 1) glint(p, x + w * 0.2 + lean * g, -h * g * 0.9, g < 0.5 ? 2 : 1, I[6], WHITE);
+ }
+ // the burst out of the ground: a flash, chips and frost powder
+ if (age < 0.06) {
+ p.ellipse(x, -1, 6 + h * 0.15, 2.5, WHITE);
+ p.glow(x, -h * 0.4, h * 0.9, I[5], 0.4);
+ }
+ burst(5, S + i * 7, (rr) => {
+ const life = rr.range(0.25, 0.4);
+ if (age > life) return;
+ const [cx, cy] = fly(x + rr.range(-4, 4), -1, rr.range(-50, 60), -rr.range(40, 110), age, 400);
+ p.px(cx, Math.min(0, cy), age / life < 0.5 ? I[7] : I[5]);
+ });
+ // shattering: the spike breaks into shards that tumble and fall away
+ if (broken && !flash) {
+ const b = t - brk;
+ burst(5, S + 100 + i, (rr, j) => {
+ const life = rr.range(0.3, 0.42);
+ if (b > life) return;
+ const k = b / life, hy = -h * rr.range(0.1, 0.9), pts = shardPts(rr, (2.2 + h * 0.07) * (1 - 0.5 * seg(k, 0.5, 1)));
+ const [sx, sy] = fly(x + rr.range(-w, w) + lean * (-hy / h), hy, rr.sign() * rr.range(25, 60), -rr.range(10, 50), b, 520, 1.4);
+ if (sy > 1) return;
+ shard(p, sx, sy, pts, rr.range(0, TAU) + b * rr.range(-12, 12), I, 1 - seg(k, 0.75, 1));
+ });
+ if (b < 0.07) p.glow(x, -h * 0.5, h, I[6], 0.3);
+ }
+ }
+ // a cold light following the eruption
+ p.glow(40, -20, 70, I[4], 0.1 * seg(t, 0.03, 0.2) * (1 - seg(t, 0.9, 1.3)));
+}
diff --git a/src/fx/ice/icicle-fall.js b/src/fx/ice/icicle-fall.js
new file mode 100644
index 0000000..e79a8c9
--- /dev/null
+++ b/src/fx/ice/icicle-fall.js
@@ -0,0 +1,82 @@
+import { PAL, burst, seg, ease, fly, TAU, WHITE } from "../../core/index.js";
+import { fit, shard, shardPts } from "./_lib.js";
+
+export const meta = {
+ name: "Icicle fall",
+ desc: "An icicle trembles, cracks loose, drops like a dart and smashes point first: a white burst, shards flung up in a V, frost dust settling.",
+ tags: ["ice", "icicle", "falling", "trap", "hazard", "shatter", "one-shot"],
+ size: [64, 88],
+ origin: [32, 82],
+ duration: 1.4,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ options: { palette: PAL.ice, length: 26, seed: 25 },
+};
+
+const LOOSE = 0.42, G = 1500, TOP = -80;
+
+function icicle(p, x, y, L, I, white) {
+ // a long cone with ripples down its sides: lit left, shaded right, a white ridge
+ p.shade(x - 6, y, x + 6, y + L, (px, py) => {
+ const v = (py - y) / L, w = 4.4 * (1 - v) + 0.4 + Math.sin((py - y) * 0.9) * 0.5 * (1 - v);
+ const dx = px - x;
+ if (Math.abs(dx) > w) return;
+ if (white) return WHITE;
+ if (dx > w - 1) return I[2];
+ if (Math.abs(dx + 0.5) < 0.6 && v < 0.85) return I[7];
+ return dx < 0 ? (dx < -w + 1 ? I[5] : I[6]) : I[4];
+ });
+ if (!white) p.px(x, y + L, I[7]);
+}
+
+export function draw(p, t, o) {
+ const I = fit(o.palette), S = o.seed, L = o.length, tipY = TOP + L, fallT = Math.sqrt((2 * -tipY) / G), HIT = LOOSE + fallT;
+ if (t < HIT) {
+ // hanging: it starts to shiver and a crack opens at the root; then it drops
+ const shiver = t > 0.15 && t < LOOSE ? (Math.floor(t * 30) % 2 ? 1 : 0) : 0;
+ const f = Math.max(0, t - LOOSE), dy = 0.5 * G * f * f;
+ icicle(p, shiver, TOP + dy, L, I, f > 0 && f < 0.034);
+ if (t > 0.25 && t < LOOSE) p.line(-3 + shiver, TOP + 2, 3 + shiver, TOP + 1, WHITE);
+ // flakes shaken loose from the root
+ burst(4, S, (r, i) => {
+ const a = t - 0.18 - i * 0.05;
+ if (a < 0 || a > 0.5) return;
+ p.px(r.range(-3, 3) + Math.sin(a * 12 + i) * 1.5, TOP + 3 + a * r.range(40, 70), a < 0.3 ? I[6] : I[5]);
+ });
+ // speed lines while it falls
+ if (f > 0.05) {
+ const v = G * f;
+ for (const [sx, k] of [[-5, 0.03], [5, 0.022], [-2, 0.015]]) p.line(sx, TOP + dy - v * k, sx, TOP + dy - 3, I[4]);
+ }
+ return;
+ }
+ const b = t - HIT;
+ // the smash: a white star on the floor, frost blown along it
+ if (b < 0.07) {
+ p.ellipse(0, -2, 10, 3, WHITE);
+ p.line(0, -1, 0, -16, WHITE);
+ p.line(-6, -6, 6, -6, WHITE);
+ p.glow(0, -10, 24, I[6], 0.6);
+ }
+ const frost = 1 - ease.inQuad(seg(b, 0.3, 0.62));
+ if (b > 0.03 && frost > 0) p.ellipse(0, 0.5, (6 + 10 * ease.outCubic(seg(b, 0, 0.2))) * frost, 2 * frost + 0.5, (d) => (d > 0.7 ? I[6] : I[5]));
+ // shards flung up and out in a V, the body's chunks tumbling out low
+ burst(16, S + 1, (r, i) => {
+ const big = i < 6, life = r.range(0.45, 0.7);
+ if (b > life) return;
+ const side = r.sign(), ang = -Math.PI / 2 + side * (big ? r.range(0.3, 1.0) : r.range(0.15, 0.5)), sp = big ? r.range(45, 80) : r.range(90, 140);
+ const [x, y] = fly(side * r.range(0, 3), -2 - (big ? r.range(0, 8) : 0), Math.cos(ang) * sp, Math.sin(ang) * sp, b, 520, 0.4);
+ if (y > 0) return;
+ const sz = (big ? r.range(2.4, 3.6) : r.range(1.2, 2)) * (1 - ease.inQuad(seg(b / life, 0.6, 1)));
+ if (sz > 0.6) shard(p, x, y, shardPts(r, sz), r.range(0, TAU) + b * r.range(-18, 18), I);
+ });
+ // frost dust: a low puff of bright specks
+ burst(18, S + 2, (r) => {
+ const life = r.range(0.35, 0.6);
+ if (b > life) return;
+ const [x, y] = fly(r.range(-3, 3), -1, r.range(-70, 70), -r.range(10, 50), b, 60, 4);
+ p.px(x, y, b / life < 0.4 ? I[7] : I[5]);
+ });
+ p.glow(0, -10, 20, I[5], 0.3 * (1 - seg(b, 0, 0.4)));
+}
diff --git a/src/fx/ice/snowflake-burst.js b/src/fx/ice/snowflake-burst.js
new file mode 100644
index 0000000..0b2d168
--- /dev/null
+++ b/src/fx/ice/snowflake-burst.js
@@ -0,0 +1,55 @@
+import { PAL, burst, seg, ease, TAU, WHITE } from "../../core/index.js";
+import { fit, flake, glint } from "./_lib.js";
+
+export const meta = {
+ name: "Snowflake burst",
+ desc: "A white pop, then big six-armed snowflakes spring out with a bounce, spin away and slow, twinkle and shrink to nothing among drifting specks.",
+ tags: ["ice", "snow", "snowflake", "burst", "magic", "winter", "one-shot"],
+ size: [76, 76],
+ origin: [38, 38],
+ duration: 1.4,
+ loop: false,
+ fps: 30,
+ bg: "dark",
+ options: { palette: PAL.ice, count: 6, seed: 26 },
+};
+
+const STEP = TAU / 24; // turn in 15 degree steps so the arms stay crisp
+
+export function draw(p, t, o) {
+ const I = fit(o.palette), S = o.seed, n = o.count;
+ // the pop
+ if (t < 0.07) {
+ p.circle(0, 0, 4 + t * 60, WHITE);
+ p.glow(0, 0, 30, I[6], 0.7);
+ }
+ // the big flakes: spring out with an overshoot, fly out and slow, spinning down, then shrink away
+ burst(n + 4, S, (r, i) => {
+ const big = i < n, born = big ? 0.02 + r.range(0, 0.04) : 0.08 + r.range(0, 0.1), age = t - born;
+ if (age < 0) return;
+ const a = (i / n) * TAU + r.range(-0.25, 0.25) + (big ? 0 : TAU / (2 * n)), reach = big ? r.range(16, 22) : r.range(24, 28);
+ const d = reach * ease.outCubic(seg(age, 0, 0.55)) + age * 4, x = Math.cos(a) * d, y = Math.sin(a) * d + age * age * 2;
+ const pop = ease.outBack(seg(age, 0, 0.18), 2.8), gone = ease.inQuad(seg(t, 0.85 + r.range(0, 0.15), 1.32));
+ const R = (big ? r.range(5.5, 8) : r.range(2.5, 3.5)) * pop * (1 - gone);
+ if (R < 1) return;
+ const w = r.sign() * r.range(5, 9), rot = Math.round((r.range(0, TAU) + (w * (1 - Math.exp(-2.5 * age))) / 2.5) / STEP) * STEP;
+ const tw = Math.sin(t * 22 + i * 1.7) > 0.4;
+ flake(p, x, y, R, rot, R > 4 ? I[5] : I[6], tw ? WHITE : I[6], WHITE);
+ if (R > 4) p.light(x, y, I[5], 0.35 * (1 - gone));
+ });
+ // glints winking on and off around them
+ burst(9, S + 1, (r) => {
+ const t0 = r.range(0.12, 0.9), k = seg(t, t0, t0 + 0.25);
+ if (k <= 0 || k >= 1) return;
+ const a = r.range(0, TAU), d = r.range(8, 30), s = Math.round(2 * Math.sin(k * Math.PI));
+ glint(p, Math.cos(a) * d, Math.sin(a) * d, s, I[5], WHITE);
+ });
+ // fine snow specks drifting outward and down
+ burst(18, S + 2, (r) => {
+ const life = r.range(0.6, 1.1), age = t - 0.04;
+ if (age < 0 || age > life) return;
+ const a = r.range(0, TAU), e = (1 - Math.exp(-3 * age)) / 3, sp = r.range(25, 60);
+ p.px(Math.cos(a) * sp * e + Math.sin(age * 5 + a) * 1.5, Math.sin(a) * sp * e + age * age * 14, age / life < 0.6 ? I[6] : I[4]);
+ });
+ p.glow(0, 0, 34, I[4], 0.25 * (1 - seg(t, 0.05, 0.9)));
+}
diff --git a/src/fx/impacts/_lib.js b/src/fx/impacts/_lib.js
new file mode 100644
index 0000000..34436a4
--- /dev/null
+++ b/src/fx/impacts/_lib.js
@@ -0,0 +1,57 @@
+// Shared bits for the impacts category: sharp ray stars, streak sparks and shaded dust puffs.
+// Files starting with _ are helpers, not effects.
+
+import { at, clamp, TAU } from "../../core/index.js";
+
+/**
+ * A sharp star made of tapered rays around (x, y). rays: [{ a (angle), len, w (half-width at the base) }].
+ * col(q) picks the color by q = distance along the ray (0 center .. 1 tip). The spine of each ray is a 1 px
+ * line so thin tips never break up.
+ */
+export function rayStar(p, x, y, rays, col) {
+ for (const r of rays) {
+ if (r.len < 1) continue;
+ const dx = Math.cos(r.a), dy = Math.sin(r.a), nx = -dy, ny = dx, w = Math.max(0, r.w);
+ if (w > 0.6) {
+ const tip = [x + dx * r.len, y + dy * r.len];
+ p.poly([[x + nx * w, y + ny * w], tip, [x - nx * w, y - ny * w], [x - dx * w * 0.8, y - dy * w * 0.8]], (px, py) =>
+ col(clamp(((px - x) * dx + (py - y) * dy) / r.len)));
+ }
+ p.line(x, y, x + dx * r.len, y + dy * r.len, (u) => col(u));
+ }
+}
+
+/**
+ * Rays for an n-point hit star (4..8): the four cardinal rays long, then n - 4 short diagonals picked by the
+ * rng, so 5 to 7 points come out uneven. Returns [{ a, len, w }].
+ */
+export function starRays(n, r, long, short, w = 1.6) {
+ const rays = [];
+ for (let i = 0; i < 4; i++) rays.push({ a: (i * TAU) / 4, len: long * r.range(0.85, 1.12), w });
+ const diag = [0, 1, 2, 3];
+ for (let i = 3; i > 0; i--) {
+ const j = Math.floor(r.next() * (i + 1));
+ [diag[i], diag[j]] = [diag[j], diag[i]];
+ }
+ diag.length = clamp(n - 4, 0, 4);
+ for (const i of diag) rays.push({ a: TAU / 8 + (i * TAU) / 4, len: short * r.range(0.8, 1.2), w: w * 0.3 });
+ return rays;
+}
+
+/** A spark streak: a short line from its head back along its velocity. c(u): u 0 at the tail .. 1 at the head. */
+export function streak(p, x, y, vx, vy, len, c) {
+ const v = Math.hypot(vx, vy) || 1;
+ p.line(x - (vx / v) * len, y - (vy / v) * len, x, y, c);
+}
+
+/**
+ * A dust puff: a ball lit from the top-left with the ramp's darker steps on its shadowed side, dithered by a.
+ * D: dust ramp (dark .. light), lift shifts it brighter (-1..1), contrast < 1 flattens the shading (soft dust).
+ */
+export function puff(p, x, y, r, D, a = 1, lift = 0, contrast = 1) {
+ if (r < 0.6 || a <= 0) return;
+ p.circle(x, y, r, (d, ang) => {
+ const lit = Math.cos(ang + Math.PI * 0.75) * d; // +1 toward the top-left
+ return at(D, clamp(0.55 + (lit * 0.45 - d * d * 0.25) * contrast + lift * 0.3));
+ }, (d) => a * (d > 0.8 ? 0.8 : 1));
+}
diff --git a/src/fx/impacts/blunt-hit.js b/src/fx/impacts/blunt-hit.js
new file mode 100644
index 0000000..91919f5
--- /dev/null
+++ b/src/fx/impacts/blunt-hit.js
@@ -0,0 +1,47 @@
+import { PAL, ramp, burst, seg, ease, clamp, TAU, WHITE } from "../../core/index.js";
+import { puff } from "./_lib.js";
+
+export const meta = {
+ name: "Blunt hit",
+ desc: "A dull, heavy thud: no sparks, just a dim flash, fat comic impact dashes that pop out and pull back, and a ring of dust that rolls out and settles.",
+ tags: ["impact", "hit", "blunt", "dust", "combat", "comic", "one-shot"],
+ size: [56, 48],
+ origin: [28, 24],
+ duration: 0.5,
+ loop: false,
+ fps: 30,
+ bg: "dark",
+ options: { palette: PAL.dust, count: 9, size: 1, seed: 9 },
+};
+
+export function draw(p, t, o) {
+ const D = ramp(o.palette), S = o.seed, k = o.size, N = D.length - 1, n = clamp(Math.round(o.count), 5, 14);
+ // dust ring: lumpy puffs pushed out in a ring, slowing, some sinking, some lifting, shrinking as they thin
+ burst(16, S, (r, i) => {
+ const a = ((i + r.range(-0.4, 0.4)) / 16) * TAU, born = r.range(0.02, 0.07), life = r.range(0.3, 0.44), age = t - born;
+ if (age < 0 || age > life) return;
+ const q = age / life, e = ease.outCubic(seg(age, 0, r.range(0.16, 0.26)));
+ const reach = r.range(9, 19) * k, drift = r.range(-3, 5) * k;
+ const x = Math.cos(a) * (4 * k + reach * e), y = Math.sin(a) * (3 * k + reach * 0.75 * e) + q * q * drift;
+ const rad = (1.2 + r.range(1.4, 3.6) * ease.outQuad(seg(q, 0, 0.4))) * k * (1 - 0.65 * ease.inQuad(seg(q, 0.35, 1)));
+ puff(p, x, y, rad, D.slice(2), 1 - seg(q, 0.75, 1), 0.45 - q * 0.6);
+ });
+ // impact dashes: fat outside, pointed toward the hit; out fast, then they pull back in and vanish
+ const go = ease.outExpo(seg(t, 0, 0.08)), back = ease.inQuad(seg(t, 0.1, 0.22));
+ if (back < 1)
+ burst(n, S + 1, (r, i) => {
+ const a = ((i + r.range(-0.25, 0.25)) / n) * TAU, len = r.range(6, 10) * k * (1 - back), w = r.range(1.5, 2.2) * k * (1 - back * 0.6);
+ const r0 = (5 + 6 * go + r.range(0, 2)) * k + back * 4 * k;
+ if (len < 1) return;
+ const dx = Math.cos(a), dy = Math.sin(a), nx = -dy * w, ny = dx * w;
+ const x0 = dx * r0, y0 = dy * r0, x1 = dx * (r0 + len), y1 = dy * (r0 + len);
+ p.poly([[x0, y0], [x1 + nx, y1 + ny], [x1 - nx, y1 - ny]], (px, py) =>
+ (px * dx + py * dy - r0) / len > 0.45 ? WHITE : D[N]);
+ p.line(x0, y0, x0 + dx * len * 0.7, y0 + dy * len * 0.7, WHITE);
+ });
+ // the dull flash: a pale disc for a frame, a dusty ring for the next
+ if (t < 0.035) p.circle(0, 0, 6 * k, (d) => (d < 0.6 ? WHITE : D[N]));
+ else if (t < 0.075) p.ring(0, 0, 7 * k, 2 * k, D[N], 0.8);
+ const L = 1 - seg(t, 0, 0.18);
+ p.glow(0, 0, 18 * k, D[N], 0.32 * L * L);
+}
diff --git a/src/fx/impacts/bullet-impact.js b/src/fx/impacts/bullet-impact.js
new file mode 100644
index 0000000..2226718
--- /dev/null
+++ b/src/fx/impacts/bullet-impact.js
@@ -0,0 +1,64 @@
+import { PAL, ramp, burst, fly, flyV, seg, ease, clamp, WHITE } from "../../core/index.js";
+import { rayStar, streak, puff } from "./_lib.js";
+
+export const meta = {
+ name: "Bullet impact",
+ desc: "A round hits a wall on the right: a flat white flash, sparks sprayed back in a cone, a puff of grit, chips falling, a hot pock mark cooling.",
+ tags: ["impact", "bullet", "gun", "sparks", "dust", "debris", "directional", "one-shot"],
+ size: [48, 46],
+ origin: [40, 26],
+ duration: 0.6,
+ loop: false,
+ fps: 30,
+ bg: "dark",
+ options: { palette: PAL.volt, dust: PAL.stone, count: 12, seed: 10 },
+};
+
+export function draw(p, t, o) {
+ const C = ramp(o.palette), G = ramp(o.dust), S = o.seed, N = C.length - 1;
+ // grit: a puff that billows back off the wall, spreads, drifts up and thins
+ burst(6, S + 3, (r, i) => {
+ const born = 0.02 + i * 0.015, life = r.range(0.38, 0.55), age = t - born;
+ if (age < 0 || age > life) return;
+ const q = age / life, [x, y] = fly(-2, r.range(-2, 2), -r.range(45, 120), r.range(-42, 16), age, -20, 4.5);
+ const rad = (1 + r.range(2.2, 4.8) * ease.outCubic(seg(q, 0, 0.45))) * (1 - 0.7 * ease.inQuad(seg(q, 0.45, 1)));
+ puff(p, x, y, rad, G.slice(3), 1 - seg(q, 0.85, 1), 0.4 - q * 0.7);
+ });
+ // the pock mark: a hot dot in the wall face that cools to a dark pit, then goes
+ const hot = seg(t, 0, 0.3), pit = 1 - seg(t, 0.42, 0.6);
+ if (pit > 0) {
+ p.rect(-1, -1, 2, 3, hot < 0.35 ? C[N - 1] : hot < 0.7 ? C[N - 3] : G[1], pit);
+ if (hot < 1) p.px(-1, 0, hot < 0.5 ? WHITE : C[N - 2]);
+ p.light(-1, 0, C[N - 2], 0.5 * (1 - hot));
+ }
+ // chips knocked off the wall: tumble back and drop
+ burst(5, S + 2, (r) => {
+ const born = r.range(0, 0.04), life = r.range(0.3, 0.4), age = t - born;
+ if (age < 0 || age > life) return;
+ const [x, y] = fly(-1, r.range(-2, 1), -r.range(25, 70), -r.range(20, 60), age, 260, 1);
+ const big = r.next() < 0.5;
+ p.rect(x, y, big ? 2 : 1, big ? 2 : 1, G[r.next() < 0.5 ? 6 : 5], 1 - seg(age / life, 0.75, 1));
+ });
+ // sparks: a fan thrown back off the wall, fast, falling, cooling white > yellow > orange
+ burst(o.count, S, (r) => {
+ const a = Math.PI + r.range(-0.6, 1.05), sp = r.range(100, 240), born = r.range(0, 0.03), life = r.range(0.13, 0.3), age = t - born;
+ if (age < 0 || age > life) return;
+ const q = age / life, vx0 = Math.cos(a) * sp, vy0 = Math.sin(a) * sp;
+ const [x, y] = fly(-1, 0, vx0, vy0, age, 170, 4.5), [vx, vy] = flyV(vx0, vy0, age, 170, 4.5);
+ const head = q < 0.35 ? WHITE : q < 0.7 ? C[N - 1] : C[N - 3];
+ streak(p, x, y, vx, vy, clamp(Math.hypot(vx, vy) * 0.03, 1, 5), (u) => (u > 0.5 ? head : C[N - 3]));
+ p.light(x, y, C[N - 2], 0.45 * (1 - q));
+ });
+ // the flash: flattened against the wall, pointing back the way the round came
+ if (t < 0.1) {
+ const s = t < 0.035 ? 1 : t < 0.07 ? 0.6 : 0.3;
+ rayStar(p, -1, 0, [
+ { a: Math.PI, len: 13 * s, w: 2 }, { a: Math.PI - 0.6, len: 7 * s, w: 1 }, { a: Math.PI + 0.6, len: 7 * s, w: 1 },
+ { a: -Math.PI / 2, len: 6 * s, w: 1.2 }, { a: Math.PI / 2, len: 6 * s, w: 1.2 },
+ ], (q) => (q < 0.55 ? WHITE : C[N - 1]));
+ p.circle(-1, 0, 2.6 * s, WHITE);
+ }
+ const L = 1 - seg(t, 0, 0.2);
+ p.glow(-2, 0, 16, C[N - 2], 0.4 * L * L);
+ p.glow(-1, 0, 5, C[N - 1], 0.5 * L);
+}
diff --git a/src/fx/impacts/combo-hit.js b/src/fx/impacts/combo-hit.js
new file mode 100644
index 0000000..942e5c5
--- /dev/null
+++ b/src/fx/impacts/combo-hit.js
@@ -0,0 +1,76 @@
+import { PAL, ramp, rng, burst, fly, flyV, seg, ease, clamp, TAU, WHITE } from "../../core/index.js";
+import { rayStar, starRays, streak } from "./_lib.js";
+
+export const meta = {
+ name: "Combo hit",
+ desc: "A rapid combo lands on one target: four quick crossing slash marks with spark pops, each a little bigger, then a beat and a big finisher with a ring.",
+ tags: ["impact", "hit", "combo", "multi-hit", "sparks", "combat", "one-shot"],
+ size: [56, 56],
+ origin: [28, 28],
+ duration: 0.8,
+ loop: false,
+ fps: 30,
+ bg: "dark",
+ options: { palette: PAL.electric, hits: 4, gap: 0.07, seed: 18 },
+};
+
+// a slash mark: a thin pointed sliver across (x, y), bowed to one side, white along its spine
+function sliver(p, x, y, ang, len, w, C, N) {
+ const dx = Math.cos(ang) * len * 0.5, dy = Math.sin(ang) * len * 0.5, nx = -Math.sin(ang) * w, ny = Math.cos(ang) * w;
+ p.poly([[x - dx, y - dy], [x + nx, y + ny], [x + dx, y + dy], [x - nx * 0.3, y - ny * 0.3]], C[N - 1]);
+ p.line(x - dx * 0.8 + nx * 0.3, y - dy * 0.8 + ny * 0.3, x + dx * 0.8 + nx * 0.3, y + dy * 0.8 + ny * 0.3, WHITE);
+}
+
+export function draw(p, t, o) {
+ const C = ramp(o.palette), S = o.seed, N = C.length - 1, n = Math.max(1, Math.round(o.hits));
+ const fin = n * o.gap + 0.08; // the finisher, after a beat
+ // the quick hits: each a slash mark that cuts in, holds a frame, then wipes from both ends
+ for (let i = 0; i < n; i++) {
+ const r = rng(S, i), t0 = i * o.gap, age = t - t0, s = 0.75 + (0.25 * i) / Math.max(1, n - 1);
+ if (age < 0 || age > 0.36) continue;
+ const x = (i % 2 ? 1 : -1) * r.range(1, 8), y = r.range(-8, 8), ang = (i % 2 ? -0.75 : 0.75) + r.range(-0.25, 0.25);
+ const grow = age < 0.017 ? 0.8 : 1, wipe = ease.inQuad(seg(age, 0.1, 0.22 + 0.04 * (n - i) / n));
+ if (wipe < 1) sliver(p, x, y, ang, 24 * s * grow * (1 - wipe), 2.6 * s * (1 - wipe * 0.5), C, N);
+ if (age < 0.07) {
+ const k = age < 0.035 ? 1 : 0.5;
+ rayStar(p, x, y, [0, 1, 2, 3].map((j) => ({ a: (j * TAU) / 4 + 0.785, len: 5 * s * k, w: 1 })), (q) => (q < 0.5 ? WHITE : C[N - 1]));
+ p.circle(x, y, 1.6 * s * k, WHITE);
+ }
+ burst(4, S * 7 + i, (rr) => {
+ const a = ang + Math.PI / 2 + rr.range(-1, 1) + (rr.next() < 0.5 ? Math.PI : 0), sp = rr.range(60, 130) * s, life = rr.range(0.12, 0.22);
+ if (age > life) return;
+ const q = age / life, vx = Math.cos(a) * sp, vy = Math.sin(a) * sp;
+ const [px, py] = fly(x, y, vx, vy, age, 100, 6), [qx, qy] = flyV(vx, vy, age, 100, 6);
+ streak(p, px, py, qx, qy, clamp(Math.hypot(qx, qy) * 0.03, 1, 3), (u) => (u > 0.5 && q < 0.5 ? WHITE : C[N - 2]));
+ });
+ p.glow(x, y, 12 * s, C[N - 2], 0.4 * (1 - seg(age, 0, 0.12)));
+ }
+ // the finisher: a big star at the middle, a ring, a spray of sparks
+ const age = t - fin;
+ if (age >= 0) {
+ const sk = age < 0.035 ? 1 : Math.pow(1 - seg(age, 0.035, 0.13), 2);
+ if (sk > 0.05) {
+ const rays = starRays(8, rng(S, 99), 17, 8, 2).map((ry) => ({ ...ry, len: ry.len * sk, w: ry.w * (0.4 + 0.6 * sk) }));
+ rayStar(p, 0, 0, rays, (q) => (q < 0.55 ? WHITE : q < 0.85 ? C[N - 1] : C[N - 2]));
+ p.circle(0, 0, 3.2 * sk, WHITE);
+ }
+ const rk = seg(age, 0.06, 0.32);
+ if (rk > 0 && rk < 1) {
+ const R = 11 + 13 * ease.outCubic(rk), gap = -2 + 3.6 * rk;
+ p.ring(0, 0, R, rk < 0.3 ? 2 : 1, rk < 0.35 ? WHITE : C[N - 1], (v, a) => (Math.sin(a * 5 + S) + Math.sin(a * 3 - S) > gap ? 1 : 0));
+ p.glowRing(0, 0, R, 3, C[N - 2], 0.25 * (1 - rk));
+ }
+ burst(12, S + 5, (r, i) => {
+ const a = ((i + r.range(0.1, 0.9)) / 12) * TAU, sp = r.range(90, 170), born = r.range(0.02, 0.05), life = r.range(0.16, 0.3), ag = age - born;
+ if (ag < 0 || ag > life) return;
+ const q = ag / life, vx = Math.cos(a) * sp, vy = Math.sin(a) * sp;
+ const [x, y] = fly(Math.cos(a) * 5, Math.sin(a) * 5, vx, vy, ag, 90, 5.5), [qx, qy] = flyV(vx, vy, ag, 90, 5.5);
+ const head = q < 0.35 ? WHITE : q < 0.7 ? C[N - 1] : C[N - 3];
+ streak(p, x, y, qx, qy, clamp(Math.hypot(qx, qy) * 0.035, 1, 5), (u) => (u > 0.5 ? head : C[N - 3]));
+ p.light(x, y, C[N - 2], 0.4 * (1 - q));
+ });
+ const L = 1 - seg(age, 0, 0.3);
+ p.glow(0, 0, 26, C[N - 2], 0.45 * L * L);
+ p.glow(0, 0, 7, C[N - 1], 0.5 * L);
+ }
+}
diff --git a/src/fx/impacts/crit-hit.js b/src/fx/impacts/crit-hit.js
new file mode 100644
index 0000000..8bff55c
--- /dev/null
+++ b/src/fx/impacts/crit-hit.js
@@ -0,0 +1,100 @@
+import { ramp, rng, burst, fly, seg, ease, clamp, TAU, WHITE } from "../../core/index.js";
+import { streak } from "./_lib.js";
+
+export const meta = {
+ name: "Critical hit",
+ desc: "A loud crit: a jagged red-to-white comic starburst punches in with overshoot, shudders, then breaks into a ring, streaks and shards.",
+ tags: ["impact", "hit", "critical", "crit", "combat", "comic", "one-shot"],
+ size: [72, 72],
+ origin: [36, 36],
+ duration: 0.5,
+ loop: false,
+ fps: 30,
+ bg: "dark",
+ options: {
+ palette: ["#2a0508", "#7a0d14", "#c81c1c", "#ff5a1a", "#ffb424", "#fff07a", "#ffffff"],
+ spikes: 12,
+ size: 1,
+ seed: 8,
+ },
+};
+
+// the burst outline: alternating tips and notches, uneven like an inked comic burst
+function burstPts(n, R, Ri, r) {
+ const pts = [];
+ for (let j = 0; j < 2 * n; j++) {
+ const a = (j * Math.PI) / n + r.range(-0.09, 0.09);
+ const rad = j % 2 ? Ri * r.range(0.82, 1.12) : R * (j % 4 === 0 ? 1 : 0.8) * r.range(0.78, 1.14);
+ pts.push([Math.cos(a) * rad, Math.sin(a) * rad]);
+ }
+ return pts;
+}
+
+// how far the outline is from the center along angle ang (the ray meets one of the edges near its slot)
+function edgeR(pts, ang) {
+ const m = pts.length, ux = Math.cos(ang), uy = Math.sin(ang);
+ const j0 = Math.floor((((ang % TAU) + TAU) % TAU) / (TAU / m));
+ for (const dj of [0, -1, 1, -2, 2]) {
+ const j = (j0 + dj + m) % m, [ax, ay] = pts[j], [bx, by] = pts[(j + 1) % m], ex = bx - ax, ey = by - ay;
+ const den = ux * ey - uy * ex;
+ if (Math.abs(den) < 1e-9) continue;
+ const sAlong = (ax * uy - ay * ux) / den, tRay = (ax * ey - ay * ex) / den;
+ if (sAlong >= -1e-6 && sAlong <= 1 + 1e-6 && tRay > 0) return tRay;
+ }
+ return 0;
+}
+
+export function draw(p, t, o) {
+ const C = ramp(o.palette), S = o.seed, k = o.size, n = clamp(Math.round(o.spikes), 8, 20), N = C.length - 1;
+ const fi = Math.floor(t * meta.fps + 1e-6);
+ // the burst: frame 0 a white flash, then it slams in past full size, shudders for a few frames, collapses
+ const grow = ease.outBack(seg(t, 0, 0.07), 3.2), fall = ease.inQuad(seg(t, 0.13, 0.2));
+ const s = (0.62 + 0.38 * grow) * (1 - fall);
+ if (s > 0.05) {
+ const shake = t > 0.04 && t < 0.13, jx = shake ? [1, -1, 0, 1][fi % 4] : 0, jy = shake ? [0, 1, -1, -1][fi % 4] : 0;
+ const pts = burstPts(n, 28 * k, 15 * k, rng(S, fi % 2 && shake ? 2 : 1));
+ // nested copies of the outline, outer to inner: an inked rim stepping in to a white core (one pass)
+ const flash = t < 0.033, cool = seg(t, 0.12, 0.22);
+ const bands = flash ? [C[N - 2], C[N - 1], WHITE] : [...C.slice(0, N), WHITE], nb = bands.length;
+ const scale = bands.map((c, b) => s * (flash ? 1 - b / 3.4 : b ? 0.94 * (1 - (b - 1) / (nb - 0.6)) * (1 - cool * 0.5) : 1));
+ const R = 28 * k * 1.14 * s + 1;
+ p.shade(jx - R, jy - R, jx + R, jy + R, (x, y) => {
+ const dx = x - jx, dy = y - jy, d = Math.hypot(dx, dy), e = edgeR(pts, Math.atan2(dy, dx));
+ let c = 0;
+ for (let b = 0; b < nb; b++) if (d < e * scale[b]) c = bands[b];
+ return c;
+ });
+ }
+ // the ring the burst leaves behind: fat and yellow, torn into arcs, thinning to red as it runs out
+ const rk = seg(t, 0.14, 0.42);
+ if (rk > 0 && rk < 1) {
+ const R = (17 + 15 * ease.outCubic(rk)) * k, W = 4 * (1 - rk) * k, gap = -2 + 3.7 * Math.pow(rk, 1.3);
+ p.ring(0, 0, R, Math.max(1, W), rk < 0.25 ? C[N - 1] : rk < 0.5 ? C[N - 2] : rk < 0.75 ? C[3] : C[2],
+ (v, ang) => (Math.sin(ang * 5 + S) + Math.sin(ang * 3 - S * 2) > gap ? 1 : 0));
+ p.glowRing(0, 0, R, 5, C[N - 2], 0.3 * (1 - rk) * (1 - rk));
+ }
+ // streaks shot out radially as it breaks: long and white first, shrinking to red dashes
+ burst(14, S + 1, (r, i) => {
+ const a = ((i + r.range(-0.3, 0.3)) / 14) * TAU, born = r.range(0.12, 0.15), life = r.range(0.12, 0.18), age = t - born;
+ if (age < 0 || age > life) return;
+ const q = age / life, d = (13 + r.range(14, 21) * ease.outCubic(q)) * k, len = r.range(8, 13) * (1 - q * 0.8) * k;
+ const x = Math.cos(a) * d, y = Math.sin(a) * d;
+ streak(p, x, y, Math.cos(a), Math.sin(a), len, (u) => (u > 0.55 ? (q < 0.45 ? WHITE : C[N - 1]) : u > 0.25 ? C[N - 2] : C[3]));
+ p.light(x, y, C[N - 2], 0.5 * (1 - q));
+ });
+ // shards: little spinning red-orange triangles thrown out, falling, shrinking away
+ burst(8, S + 2, (r, i) => {
+ const a = ((i + r.range(0.1, 0.9)) / 8) * TAU, sp = r.range(60, 105) * k, born = r.range(0.13, 0.17), life = r.range(0.22, 0.32), age = t - born;
+ if (age < 0 || age > life) return;
+ const q = age / life, vx = Math.cos(a) * sp, vy = Math.sin(a) * sp - 25;
+ const [x, y] = fly(Math.cos(a) * 9 * k, Math.sin(a) * 9 * k, vx, vy, age, 150, 3.5);
+ const sz = r.range(1.8, 3) * k * (1 - q * 0.7), spin = r.range(-14, 14) * age + r.range(0, TAU);
+ const pts = [0, 1, 2].map((j) => [x + Math.cos(spin + (j * TAU) / 3) * sz * (j ? 1 : 1.6), y + Math.sin(spin + (j * TAU) / 3) * sz * (j ? 1 : 1.6)]);
+ if (sz > 1.1) p.poly(pts, q < 0.35 ? C[N - 2] : q < 0.7 ? C[3] : C[2]);
+ if (q < 0.75) p.px(x, y, q < 0.4 ? C[N - 1] : C[3]);
+ });
+ // light: blinding for a moment, then gone
+ const L = 1 - seg(t, 0, 0.32);
+ p.glow(0, 0, 40 * k, C[N - 2], 0.5 * L * L);
+ p.glow(0, 0, 12 * k, C[N - 1], 0.55 * L);
+}
diff --git a/src/fx/impacts/ground-slam.js b/src/fx/impacts/ground-slam.js
new file mode 100644
index 0000000..9e56525
--- /dev/null
+++ b/src/fx/impacts/ground-slam.js
@@ -0,0 +1,121 @@
+import { PAL, ramp, hex, burst, fly, seg, ease, clamp, TAU, WHITE } from "../../core/index.js";
+import { puff } from "./_lib.js";
+
+export const meta = {
+ name: "Ground slam",
+ desc: "A huge slam: the floor flashes and cracks, a flat shockwave races out with a wall of dust on it, rock chunks erupt, bounce and settle in the dust.",
+ tags: ["impact", "ground", "slam", "shockwave", "rocks", "dust", "one-shot"],
+ size: [128, 64],
+ origin: [64, 50],
+ duration: 1.2,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ options: { palette: PAL.stone, dust: PAL.dust, radius: 56, count: 9, seed: 12 },
+};
+
+const HOT = hex("#ffe2a0");
+
+// a rock thrown from (x0, y0 <= 0): flies, hits the floor, hops once, then rests. Returns [x, y, phase].
+function hop(x0, y0, vx, vy, t, g) {
+ const T1 = (-vy + Math.sqrt(vy * vy - 2 * g * y0)) / g;
+ if (t < T1) return [x0 + vx * t, y0 + vy * t + 0.5 * g * t * t, 0];
+ const x1 = x0 + vx * T1, vy2 = -(vy + g * T1) * 0.3, vx2 = vx * 0.45, T2 = (-2 * vy2) / g, t2 = t - T1;
+ if (t2 < T2) return [x1 + vx2 * t2, vy2 * t2 + 0.5 * g * t2 * t2, 1];
+ return [x1 + vx2 * T2 + vx2 * 0.15 * (1 - Math.exp(-(t2 - T2) * 12)), 0, 2];
+}
+
+export function draw(p, t, o) {
+ const C = ramp(o.palette), D = ramp(o.dust), S = o.seed, R = o.radius, N = C.length - 1, M = D.length - 1;
+ const R0 = 6, front = (tt) => R0 + (R - R0) * ease.outCubic(seg(tt, 0.03, 0.55));
+ const sw = seg(t, 0.03, 0.5);
+ // cracks: jagged dark lines run out across the floor face, a lit lip under each, fading at the end
+ const crk = ease.outCubic(seg(t, 0, 0.12)), cf = 1 - seg(t, 0.85, 1.15);
+ if (crk > 0 && cf > 0)
+ burst(6, S + 5, (r, i) => {
+ const side = i % 2 ? 1 : -1, len = r.range(14, 30) * crk;
+ let x = side * r.range(1, 3), y = 0, dir = r.range(0.2, 0.5);
+ const pts = [[x, y]];
+ for (let d = 0; d < len; ) {
+ const step = r.range(2.5, 5);
+ d += step;
+ y = clamp(y + dir * step * r.range(0.2, 1.1), 0, 4);
+ if (y >= 4 || r.next() < 0.3) dir = -dir * r.range(0.5, 1);
+ x += side * step;
+ pts.push([x, y]);
+ }
+ p.polyline(pts.map(([px, py]) => [px, py + 1]), C[2], cf);
+ p.polyline(pts, C[0], cf);
+ });
+ // the dust wall: kicked up where the front passes, a tall bright crest that slumps and thins behind it
+ burst(36, S + 1, (r, i) => {
+ const side = i % 2 ? 1 : -1, j = i >> 1, d = R0 + 1 + ((R - R0 - 3) * (j + r.range(0, 0.9))) / 18;
+ const born = 0.03 + 0.52 * (1 - Math.cbrt(1 - (d - R0) / (R - R0))), near = 1 - d / R;
+ const life = r.range(0.22, 0.36) * (0.7 + near), age = t - born;
+ if (age < 0 || age > life) return;
+ const q = age / life;
+ const [x, y] = fly(side * d, -1, side * r.range(10, 30), -r.range(30, 80) * (0.35 + near), age, 20, 4);
+ const rad = (1 + (1.8 + 3.4 * near) * r.range(0.7, 1.25) * ease.outCubic(seg(q, 0, 0.35))) * (1 - 0.7 * ease.inQuad(seg(q, 0.4, 1)));
+ puff(p, x, Math.min(y, -rad * 0.5), rad, D.slice(2), 1 - seg(q, 0.9, 1), 0.9 - q * 1.2, 0.7);
+ });
+ // the cloud left at the middle: a cluster of soft puffs that billows up together, thins and shrinks away
+ burst(16, S + 2, (r, i) => {
+ const born = 0.04 + i * 0.012, life = r.range(0.5, 0.85), age = t - born;
+ if (age < 0 || age > life) return;
+ const q = age / life, [x, y] = fly(r.range(-12, 12), -2, r.range(-30, 30), -r.range(16, 70) * (1 - Math.abs(i - 8) / 14), age, -4, 2.8);
+ const rad = (1.5 + r.range(1.8, 4.6) * ease.outCubic(seg(q, 0, 0.4))) * (1 - 0.8 * ease.inQuad(seg(q, 0.4, 1)));
+ puff(p, x, Math.min(y, -rad * 0.6), rad, D.slice(2), 1 - seg(q, 0.88, 1), 0.6 - q * 0.4, 0.4);
+ });
+ // the shockwave: a flat ring skating out along the floor (its far half shows above the floor line)
+ if (sw > 0 && sw < 1) {
+ const rx = front(t), ry = Math.max(2.5, rx * 0.16);
+ p.shade(-rx - 1, -ry - 1, rx + 1, 0, (x, y, out) => {
+ const d = Math.sqrt((x / rx) ** 2 + (y / ry) ** 2);
+ if (d > 1 || d < 1 - 2 / ry) return;
+ out.c = sw < 0.35 ? WHITE : D[M];
+ out.a = 1.2 - sw * 1.2;
+ });
+ for (const sx of [-rx, rx]) p.glow(sx, -1, 7, D[M], 0.3 * (1 - sw)); // light rides the two fronts along the floor
+ }
+ // the floor's edge lights up from the middle out, white at the front, cooling behind it
+ if (sw > 0 && sw < 1) {
+ const rx = front(t);
+ p.line(-rx, 0, rx, 0, (u) => (Math.abs(u * 2 - 1) > 0.82 ? WHITE : D[M]), (u) => clamp(Math.abs(u * 2 - 1) * 2.2 - 1 - sw * 0.8));
+ }
+ // the crests: two white crescents skating out along the floor, shrinking as they go
+ if (sw > 0 && sw < 1) {
+ const rx = front(t), h = 16 - 9 * sw, w = (u) => 5 * (1 - sw * 0.6) * Math.pow(u, 0.6);
+ const col = (u, v) => (v > 0.55 && sw < 0.6 ? WHITE : sw < 0.3 ? D[M] : D[M - 1]);
+ const al = (u, v) => clamp(1.3 - sw * 1.2 - (1 - u) * 0.6);
+ p.arc(rx - h, 0, h, w, -Math.PI / 2, -0.05, (u, v) => col(u, v), al);
+ p.arc(-rx + h, 0, h, (u) => w(1 - u), -Math.PI + 0.05, -Math.PI / 2, (u, v) => col(1 - u, v), (u, v) => al(1 - u, v));
+ }
+ // rock chunks: thrown up, tumbling, lit from above; they land, hop once, rest, then sink away
+ burst(o.count, S + 3, (r, i) => {
+ const born = r.range(0, 0.05), age = t - born;
+ if (age < 0) return;
+ const side = i % 2 ? 1 : -1, sz = r.range(1.8, 3.4), vx = side * r.range(12, 60), vy = -r.range(120, 200);
+ const [x, y, ph] = hop(side * r.range(1, 8), -2, vx, vy, age, 640);
+ const gone = seg(t, r.range(0.8, 0.95), 1.12);
+ if (gone >= 1) return;
+ const spin = r.range(-11, 11) * (ph < 2 ? age : Math.min(age, 0.9)) + r.range(0, TAU), cy = y - sz * 0.9 + gone * sz * 2;
+ const shape = [0, 1, 2, 3, 4, 5].map((j) => [spin + (j * TAU) / 6 + r.range(-0.25, 0.25), r.range(0.7, 1.15)]);
+ const at = (k) => shape.map(([a, rr]) => [x + Math.cos(a) * rr * sz * 1.2 * k, cy + Math.sin(a) * rr * sz * k]);
+ const under = (px, py) => (py > 0.5 ? 0 : 1);
+ p.poly(at(1 + 1 / sz), C[1], under);
+ p.poly(at(1), (px, py) => (py < cy - sz * 0.3 ? C[N - 1] : py < cy + sz * 0.35 ? C[N - 3] : C[N - 4]), under);
+ });
+ // grit: single pebbles flicked up fast
+ burst(12, S + 4, (r) => {
+ const life = r.range(0.3, 0.5);
+ if (t > life) return;
+ const a = -Math.PI / 2 + r.range(-1.1, 1.1), sp = r.range(80, 160), [x, y] = fly(r.range(-6, 6), -1, Math.cos(a) * sp, Math.sin(a) * sp, t, 380, 1);
+ if (y < 0) p.px(x, y, t < 0.15 ? D[M] : D[M - 2]);
+ });
+ // the flash: the floor itself goes white for a frame, then a hot rim
+ if (t < 0.035) p.ellipse(0, -1, 18, 6, (d) => (d < 0.6 ? WHITE : HOT), (d, a) => (Math.sin(a) > 0.2 ? 0 : 1));
+ else if (t < 0.07) p.ellipse(0, -1, 14, 4, HOT, (d, a) => (d > 0.65 && Math.sin(a) <= 0.2 ? 1 : 0));
+ const L = 1 - seg(t, 0, 0.35);
+ p.glow(0, -6, 48, HOT, 0.45 * L * L);
+ p.glow(0, -2, 14, WHITE, 0.4 * L * L * L);
+}
diff --git a/src/fx/impacts/heavy-landing.js b/src/fx/impacts/heavy-landing.js
new file mode 100644
index 0000000..de03c9c
--- /dev/null
+++ b/src/fx/impacts/heavy-landing.js
@@ -0,0 +1,86 @@
+import { PAL, ramp, rng, burst, fly, seg, ease, clamp, noise, WHITE } from "../../core/index.js";
+import { puff } from "./_lib.js";
+
+export const meta = {
+ name: "Heavy landing",
+ desc: "Something heavy lands: the floor dents and cracks out both ways, two rings of dust spread over the floor one after the other, pebbles hop.",
+ tags: ["impact", "land", "ground", "crack", "dust", "heavy", "one-shot"],
+ size: [80, 32],
+ origin: [40, 24],
+ duration: 1,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ options: { palette: PAL.dust, stone: PAL.stone, size: 1, seed: 16 },
+};
+
+// a crack: a jagged path along the floor face, from the dent outward, with a branch or two
+function crackPaths(r, side, len) {
+ const paths = [];
+ let x = side * 2, y = 0;
+ const main = [[x, y]];
+ while (Math.abs(x) < len) {
+ x += side * r.range(2, 4.5);
+ y = clamp(y + r.range(-1.2, 1.6), 0, 3);
+ main.push([x, Math.round(y)]);
+ }
+ paths.push(main);
+ for (let b = 0; b < 2; b++) {
+ const i = 1 + Math.floor(r.next() * (main.length - 2));
+ const [bx, by] = main[i], br = [[bx, by]];
+ let xx = bx, yy = by;
+ for (let s = 0; s < 3; s++) (xx += side * r.range(1.5, 3)), (yy = clamp(yy + r.range(0.6, 1.6), 0, 5)), br.push([xx, Math.round(yy)]);
+ paths.push(br);
+ }
+ return paths;
+}
+
+export function draw(p, t, o) {
+ const D = ramp(o.palette), G = ramp(o.stone), S = o.seed, k = o.size, N = D.length - 1;
+ // the crack runs out from the dent in a couple of frames, then sits until it fades
+ const grow = ease.outCubic(seg(t, 0, 0.1)), cf = 1 - seg(t, 0.68, 0.94);
+ if (cf > 0) {
+ [-1, 1].forEach((side, j) => {
+ for (const path of crackPaths(rng(S, j), side, (12 + j * 4) * k)) {
+ const keep = path.filter(([x]) => Math.abs(x) <= 2 + grow * 20 * k);
+ if (keep.length < 2) continue;
+ p.polyline(keep.map(([x, y]) => [x, y + 1]), G[5], cf); // the lit lower lip
+ p.polyline(keep, G[0], cf);
+ }
+ });
+ // the dent: the floor edge knocked down at the impact
+ p.rect(-3, 0, 6, 1, G[0], cf);
+ p.rect(-2, 1, 4, 1, G[1], cf);
+ }
+ // the floor edge flashes out from the feet for a frame or two
+ const fl = seg(t, 0, 0.07);
+ if (fl < 1) p.line(-10 * fl - 8, 0, 10 * fl + 8, 0, (u) => (Math.abs(u - 0.5) < 0.25 ? WHITE : D[N]));
+ if (t < 0.035) p.ellipse(0, -1, 9 * k, 3 * k, (d) => (d < 0.5 ? WHITE : D[N]), (d, a) => (Math.sin(a) > 0.1 ? 0 : 1));
+ // two rings of dust spreading over the floor, the second smaller and later: thin far arcs that crumble,
+ // with puffs riding the ends where they meet the floor
+ [[0.02, 0.62, 30], [0.14, 0.8, 19]].forEach(([t0, t1, R], ri) => {
+ const q = seg(t, t0, t1);
+ if (q <= 0 || q >= 1) return;
+ const rx = (4 + R * ease.outCubic(q)) * k, ry = Math.max(2, rx * 0.24), th = 1.6 + (1 - q) * 1.2;
+ p.shade(-rx - 1, -ry - 1, rx + 1, 0, (x, y, out) => {
+ const d = Math.sqrt((x / rx) ** 2 + (y / ry) ** 2);
+ if (d > 1 || d < 1 - th / ry) return;
+ const ang = Math.atan2(y / ry, x / rx);
+ if (noise(ang * 5 + ri * 7, S + ri) < -1 + 2.1 * ease.inQuad(q)) return;
+ out.c = d > 1 - th / ry / 2 ? D[N] : D[N - 1];
+ });
+ burst(6, S + 3 + ri, (r, i) => {
+ const side = i % 2 ? 1 : -1, x = side * rx * r.range(0.86, 1.02), y = -1 - q * r.range(1, 5);
+ const rad = (1 + r.range(1, 2.4) * ease.outCubic(seg(q, 0, 0.3))) * (1 - 0.75 * ease.inQuad(seg(q, 0.35, 1))) * k;
+ puff(p, x, Math.min(y, -rad * 0.7), rad, D.slice(2), 1 - seg(q, 0.85, 1), 0.5 - q * 0.6, 0.8);
+ });
+ });
+ // pebbles knocked loose: hop out, land, roll a touch
+ burst(6, S + 1, (r, i) => {
+ const side = i % 2 ? 1 : -1, life = r.range(0.4, 0.6);
+ if (t > life) return;
+ const vx = side * r.range(25, 70) * k, vy = -r.range(45, 85), g = 380, T1 = (-2 * vy) / g;
+ const x = t < T1 ? vx * t : vx * T1 + vx * 0.3 * (t - T1), y = t < T1 ? fly(0, 0, vx, vy, t, g)[1] : 0;
+ p.px(side * 2 + x, y - 1, r.next() < 0.5 ? G[5] : G[4]);
+ });
+}
diff --git a/src/fx/impacts/hit-flash.js b/src/fx/impacts/hit-flash.js
new file mode 100644
index 0000000..6c7a1a9
--- /dev/null
+++ b/src/fx/impacts/hit-flash.js
@@ -0,0 +1,44 @@
+import { PAL, ramp, burst, seg, ease, WHITE } from "../../core/index.js";
+
+export const meta = {
+ name: "Hit flash",
+ desc: "Taking damage: the body flashes solid white, then red, blinks white once more and cools off, while comic hit lines jab in at it.",
+ tags: ["impact", "hit", "damage", "flash", "status", "actor", "one-shot"],
+ size: [40, 36],
+ origin: [20, 30],
+ duration: 0.3,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ actor: true,
+ options: { palette: PAL.blood, lines: 6, seed: 17 },
+};
+
+export function draw(p, t, o) {
+ const C = ramp(o.palette), S = o.seed, N = C.length - 1, a = o.actor, m = a.mask;
+ const f = Math.floor(t * meta.fps + 1e-6); // the flashes are frame-exact, like a game's damage blink
+ // the body: white, white, red, red, white rim, then a red rim cooling away
+ const red = (mx, my) => (my < m.h * 0.45 ? C[N - 1] : C[N - 2]);
+ if (f <= 1) p.mask(m, a.x, a.y, WHITE);
+ else if (f <= 3) {
+ p.mask(m, a.x, a.y, red);
+ p.outline(m, a.x, a.y, C[N - 4]);
+ } else if (f === 4) p.outline(m, a.x, a.y, WHITE);
+ else if (f <= 6) p.outline(m, a.x, a.y, C[N - 1]);
+ else if (f <= 8) p.outline(m, a.x, a.y, C[N - 3]);
+ // hit lines: short strokes around the body, jabbing in toward it, gone in a few frames
+ const k = seg(t, 0, 0.16);
+ if (k < 1) {
+ const [cx, cy] = a.chest;
+ burst(o.lines, S, (r, i) => {
+ // spread over the top and sides of the body, never down into the floor
+ const ang = -Math.PI - 0.35 + ((i + r.range(0.2, 0.8)) / o.lines) * (Math.PI + 0.7);
+ const d0 = r.range(10, 13) - 3 * ease.outCubic(k), len = r.range(4, 6) * (1 - k);
+ if (len < 1) return;
+ const dx = Math.cos(ang), dy = Math.sin(ang) * 1.1;
+ p.line(cx + dx * (d0 + len), cy + dy * (d0 + len), cx + dx * d0, cy + dy * d0, (u) => (u > 0.5 ? WHITE : C[N]));
+ });
+ }
+ const L = 1 - seg(t, 0, 0.2);
+ p.glow(a.chest[0], a.chest[1], 18, f <= 1 ? WHITE : C[N - 1], 0.25 * L * L);
+}
diff --git a/src/fx/impacts/hit-spark.js b/src/fx/impacts/hit-spark.js
new file mode 100644
index 0000000..602a92a
--- /dev/null
+++ b/src/fx/impacts/hit-spark.js
@@ -0,0 +1,45 @@
+import { PAL, ramp, rng, burst, fly, flyV, seg, clamp, WHITE } from "../../core/index.js";
+import { rayStar, starRays, streak } from "./_lib.js";
+
+export const meta = {
+ name: "Hit spark",
+ desc: "A generic hit: a thin white star pops to full size in a frame and shrinks away while streak sparks spray out and cool.",
+ tags: ["impact", "hit", "spark", "combat", "one-shot"],
+ size: [44, 44],
+ origin: [22, 22],
+ duration: 0.3,
+ loop: false,
+ fps: 30,
+ bg: "dark",
+ options: { palette: PAL.volt, points: 8, size: 1, seed: 7 },
+};
+
+export function draw(p, t, o) {
+ const C = ramp(o.palette), S = o.seed, k = o.size, n = clamp(Math.round(o.points), 4, 8);
+ const top = C.length - 1;
+ // the star: a small hot core on the hit frame, full size the next, then it shrinks and cools
+ const s = t < 0.03 ? 0.55 : Math.pow(1 - seg(t, 0.033, 0.19), 1.6);
+ if (s > 0.05) {
+ const rays = starRays(n, rng(S, 5), 14 * k, 6 * k, 1.8 * k).map((r) => ({ ...r, len: r.len * s, w: r.w * (0.4 + 0.6 * s) }));
+ const cool = seg(t, 0.06, 0.16);
+ rayStar(p, 0, 0, rays, (q) => (q < 0.5 - cool * 0.4 ? WHITE : q < 0.82 ? C[top - 1] : C[top - 2]));
+ p.circle(0, 0, 2 * k * (0.5 + 0.5 * s), cool < 0.5 ? WHITE : C[top - 1]);
+ }
+ // streak sparks: fast out, dragged to a stop, cooling white > yellow > orange
+ burst(8, S, (r, i) => {
+ const a = ((i + r.range(0.1, 0.9)) / 8) * Math.PI * 2, sp = r.range(55, 165) * k, life = r.range(0.12, 0.24), born = r.range(0.045, 0.08);
+ const age = t - born;
+ if (age < 0 || age > life) return;
+ const q = age / life, vx0 = Math.cos(a) * sp, vy0 = Math.sin(a) * sp;
+ const [x, y] = fly(Math.cos(a) * 5, Math.sin(a) * 5, vx0, vy0, age, 60, 8), [vx, vy] = flyV(vx0, vy0, age, 60, 8);
+ const len = clamp(Math.hypot(vx, vy) * 0.04, 0, 6);
+ const head = q < 0.3 ? WHITE : q < 0.65 ? C[top - 1] : C[top - 3];
+ if (len < 1) p.px(x, y, head);
+ else streak(p, x, y, vx, vy, len, (u) => (u > 0.5 ? head : C[top - 3]));
+ p.light(x, y, C[top - 2], 0.5 * (1 - q));
+ });
+ // light: a quick pop, gone as the star dies
+ const L = 1 - seg(t, 0, 0.2);
+ p.glow(0, 0, 15 * k, C[top - 2], 0.4 * L * L);
+ p.glow(0, 0, 5 * k, C[top - 1], 0.5 * L);
+}
diff --git a/src/fx/impacts/impact-frame.js b/src/fx/impacts/impact-frame.js
new file mode 100644
index 0000000..3966da3
--- /dev/null
+++ b/src/fx/impacts/impact-frame.js
@@ -0,0 +1,52 @@
+import { ramp, rng, clamp, TAU } from "../../core/index.js";
+
+export const meta = {
+ name: "Impact frame",
+ desc: "An anime impact frame: two frames of white with black burst lines rushing at the hit, two frames inverted, then the lines snap back out and vanish.",
+ tags: ["impact", "hit", "anime", "manga", "flash", "speed-lines", "screen", "one-shot"],
+ size: [96, 64],
+ origin: [48, 32],
+ duration: 0.2,
+ loop: false,
+ fps: 30,
+ bg: "black",
+ options: { palette: ["#000000", "#ffffff"], lines: 26, seed: 19 },
+};
+
+// the burst lines: wedges pointing at the origin from past the canvas edge, each with its own reach
+function wedges(n, r) {
+ const out = [];
+ for (let i = 0; i < n; i++)
+ out.push({ a: ((i + r.range(0.1, 0.9)) / n) * TAU, inner: r.range(10, 26), w: r.range(0.9, 3) });
+ return out; // wedge i sits in the i-th slice of the circle, so a pixel only has to test its slice and the two beside it
+}
+
+export function draw(p, t, o) {
+ const C = ramp(o.palette), S = o.seed, DARK = C[0], LIGHT = C[C.length - 1];
+ const [W, H] = meta.size, [OX, OY] = meta.origin, x0 = -OX, y0 = -OY, x1 = W - OX - 1, y1 = H - OY - 1;
+ const f = Math.floor(t * meta.fps + 1e-6);
+ if (f >= 6) return;
+ const inverted = f >= 2, field = f <= 3, set = wedges(o.lines, rng(S, f % 2 && field ? 2 : 1));
+ const back = field ? 0 : f === 4 ? 0.3 : 0.65; // after the field drops, the lines pull back out for two frames
+ const ink = inverted ? LIGHT : DARK, paper = inverted ? DARK : LIGHT;
+ // the jagged hit at the middle, in the line color, only while the field is up
+ const spikes = (ang) => 7 + 4 * Math.abs(Math.sin(ang * 6 + S)) + 2 * Math.sin(ang * 13 + S * 3);
+ p.shade(x0, y0, x1, y1, (x, y, out) => {
+ const ex = x, ey = y * 1.45, rho = Math.hypot(ex, ey), ang = Math.atan2(ey, ex);
+ let line = false;
+ const n = set.length, slot = Math.floor(((ang + TAU) % TAU) / (TAU / n));
+ for (let j = -1; j <= 1; j++) {
+ const w = set[(slot + j + n) % n];
+ let d = (((ang - w.a) % TAU) + TAU) % TAU;
+ if (d > Math.PI) d = TAU - d;
+ const inner = w.inner + back * 40, hw = Math.max(0.8, w.w * clamp((rho - inner) / 30) * (1 - back * 0.5));
+ if (rho > inner && d * rho < hw) {
+ line = true;
+ break;
+ }
+ }
+ if (line) return ink;
+ if (field && rho < spikes(ang + f * 0.4)) return ink;
+ if (field) return paper;
+ });
+}
diff --git a/src/fx/impacts/knockback-wind.js b/src/fx/impacts/knockback-wind.js
new file mode 100644
index 0000000..b02e04f
--- /dev/null
+++ b/src/fx/impacts/knockback-wind.js
@@ -0,0 +1,55 @@
+import { PAL, ramp, burst, fly, seg, ease, clamp, WHITE } from "../../core/index.js";
+import { puff } from "./_lib.js";
+
+export const meta = {
+ name: "Knockback wind",
+ desc: "A blow lands from the left and the air bursts: a pale shock cone rolls out to the right over the body, speed lines stream past, dust kicks off the feet.",
+ tags: ["impact", "knockback", "wind", "air", "speed-lines", "directional", "actor", "one-shot"],
+ size: [80, 40],
+ origin: [26, 36],
+ duration: 0.6,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ actor: true,
+ options: { palette: ["#1a2a3a", "#2e5468", "#4f8aa0", "#86c4d4", "#c4eef4", "#ffffff"], dust: PAL.dust, lines: 12, seed: 20 },
+};
+
+export function draw(p, t, o) {
+ const C = ramp(o.palette), D = ramp(o.dust), S = o.seed, N = C.length - 1;
+ const bx = -9, by = -10; // where the blow lands: the actor's left side, chest high
+ // the shock cone: crescents of compressed air rolling out to the right from the blow, worn away at the ends
+ [[0, 0.3, 26, 12], [0.06, 0.36, 18, 8]].forEach(([t0, t1, run, R], i) => {
+ const q = seg(t, t0, t1);
+ if (q <= 0 || q >= 1) return;
+ const e = ease.outCubic(q), cx = bx - 3 + run * e, r = 5 + R * e;
+ const span = 1.15 * (1 - ease.inQuad(q) * 0.6), lo = Math.min(span, Math.asin(clamp((-1 - by) / r)));
+ const w = (u) => (3.4 - i) * (1 - q * 0.5) * Math.sin(Math.PI * clamp(u * 1.1));
+ p.arc(cx, by, r, w, -span, lo, (u, v) => (v > 0.6 && q < 0.6 ? WHITE : q < 0.4 ? C[N - 1] : C[N - 2]));
+ });
+ // speed lines: streaks racing right past the body, each born a little later than the last
+ burst(o.lines, S, (r, i) => {
+ const born = r.range(0, 0.3) * (i / o.lines + 0.2), life = r.range(0.14, 0.24), age = t - born;
+ if (age < 0 || age > life) return;
+ const q = age / life, y = Math.round(-r.range(1.5, 22)), len = r.range(8, 20) * (1 - q * 0.5);
+ const x = Math.min(51, -16 + r.range(0, 8) + ease.outQuad(q) * r.range(50, 66)), x0 = Math.max(-24, x - len);
+ if (x - x0 >= 2) p.line(x0, y, x, y, (u) => (u > 0.75 && q < 0.5 ? WHITE : u > 0.35 ? C[N - 1] : C[N - 3]));
+ });
+ // dust kicked off the feet, pushed right, lifting and thinning
+ burst(6, S + 1, (r, i) => {
+ const born = 0.03 + i * 0.025, life = r.range(0.28, 0.4), age = t - born;
+ if (age < 0 || age > life) return;
+ const q = age / life, [x, y] = fly(r.range(-3, 4), -1, r.range(60, 120), -r.range(4, 16), age, -4, 4);
+ const rad = (1 + r.range(1.2, 2.6) * ease.outCubic(seg(q, 0, 0.35))) * (1 - 0.7 * ease.inQuad(seg(q, 0.4, 1)));
+ puff(p, x, Math.min(y, -rad * 0.8), rad, D.slice(2), 1 - seg(q, 0.88, 1), 0.45 - q * 0.6, 0.85);
+ });
+ // the blow: a white pop on the actor's side
+ if (t < 0.07) {
+ const s = t < 0.035 ? 1 : 0.5;
+ p.circle(bx, by, 3.5 * s, (d) => (d < 0.6 ? WHITE : C[N - 1]));
+ p.line(bx - 8 * s, by, bx + 3 * s, by, WHITE);
+ p.line(bx, by - 6 * s, bx, by + 6 * s, C[N - 1]);
+ }
+ const L = 1 - seg(t, 0, 0.3);
+ p.glow(bx + 4, by, 18, C[N - 1], 0.3 * L * L);
+}
diff --git a/src/fx/impacts/parry.js b/src/fx/impacts/parry.js
new file mode 100644
index 0000000..654ab97
--- /dev/null
+++ b/src/fx/impacts/parry.js
@@ -0,0 +1,61 @@
+import { PAL, ramp, burst, fly, flyV, seg, ease, clamp, TAU, WHITE } from "../../core/index.js";
+import { rayStar, streak } from "./_lib.js";
+
+export const meta = {
+ name: "Parry",
+ desc: "Two blades slam together in an X: a white flash at the cross, a fan of gold sparks that arc and cool, a thin ring snapping outward.",
+ tags: ["impact", "parry", "clash", "block", "sparks", "sword", "combat", "one-shot"],
+ size: [62, 58],
+ origin: [28, 30],
+ duration: 0.5,
+ loop: false,
+ fps: 30,
+ bg: "dark",
+ options: { palette: PAL.gold, blade: PAL.metal, count: 18, seed: 13 },
+};
+
+export function draw(p, t, o) {
+ const G = ramp(o.palette), B = ramp(o.blade), S = o.seed, N = G.length - 1, M = B.length - 1;
+ const T = 0.034; // contact
+ // the blades: two edges slide in from either side and lock in an X, then spring apart, shrinking away
+ const inK = ease.outQuad(seg(t, 0, T)), apart = ease.outCubic(seg(t, 0.1, 0.22));
+ if (t < 0.22)
+ [-1, 1].forEach((s) => {
+ const a = s < 0 ? -Math.PI / 4 : (-3 * Math.PI) / 4; // hilt low on its own side, tip up across
+ const dx = Math.cos(a), dy = Math.sin(a), off = (1 - inK) * 7 + apart * 5, sh = 1 - apart * 0.75;
+ const cx = s * off, cy = apart * 2, hilt = 9 * sh, tip = 11 * sh;
+ const x0 = cx - dx * hilt, y0 = cy - dy * hilt, x1 = cx + dx * tip, y1 = cy + dy * tip;
+ if (t < T) p.line(x0 + s * 4, y0, x1 + s * 4, y1, B[M - 4]); // motion line behind the sweep
+ p.line(x0 + s, y0, x1 + s, y1, B[M - 4]);
+ p.line(x0, y0 + 1, x1, y1 + 1, B[M - 2]);
+ p.line(x0, y0, x1, y1, (u) => (t < 0.12 && u > 0.2 ? WHITE : B[M - 1]));
+ });
+ // the ring: thin, snapping out from the contact and breaking into arcs
+ const rk = seg(t, T + 0.03, 0.28);
+ if (rk > 0 && rk < 1) {
+ const R = 7 + 13 * ease.outCubic(rk), gap = -2 + 3.6 * rk;
+ p.ring(0, 0, R, 1, rk < 0.35 ? WHITE : rk < 0.7 ? G[N - 1] : G[N - 3],
+ (v, ang) => (Math.sin(ang * 4 + S) + Math.sin(ang * 7 - S) > gap ? 1 : 0));
+ p.glowRing(0, 0, R, 3, G[N - 2], 0.25 * (1 - rk));
+ }
+ // sparks: thrown up and out from the cross, perpendicular to the lock, arcing down and cooling
+ burst(o.count, S, (r, i) => {
+ const up = i % 3 !== 2, a = up ? -Math.PI / 2 + r.range(-1.25, 1.25) : Math.PI / 2 + r.range(-0.9, 0.9);
+ const sp = r.range(70, 170) * (up ? 1 : 0.55), born = T + r.range(0, 0.05), life = r.range(0.18, 0.4), age = t - born;
+ if (age < 0 || age > life) return;
+ const q = age / life, vx0 = Math.cos(a) * sp, vy0 = Math.sin(a) * sp;
+ const [x, y] = fly(0, 0, vx0, vy0, age, 260, 2.5), [vx, vy] = flyV(vx0, vy0, age, 260, 2.5);
+ const head = q < 0.25 ? WHITE : q < 0.55 ? G[N - 1] : q < 0.8 ? G[N - 3] : G[N - 4];
+ streak(p, x, y, vx, vy, clamp(Math.hypot(vx, vy) * 0.03, 1, 5), (u) => (u > 0.5 ? head : G[N - 4]));
+ p.light(x, y, G[N - 2], 0.45 * (1 - q));
+ });
+ // the flash where the edges meet
+ if (t >= T && t < T + 0.07) {
+ const s = t < T + 0.035 ? 1 : 0.5;
+ rayStar(p, 0, 0, [0, 1, 2, 3].map((i) => ({ a: (i * TAU) / 4, len: (i % 2 ? 9 : 12) * s, w: 1.6 })), (q) => (q < 0.5 ? WHITE : G[N - 1]));
+ p.circle(0, 0, 2.5 * s, WHITE);
+ }
+ const L = t < T ? 0.3 : 1 - seg(t, T, 0.3);
+ p.glow(0, 0, 24, G[N - 2], 0.4 * L * L);
+ p.glow(0, 0, 6, G[N - 1], 0.5 * L);
+}
diff --git a/src/fx/impacts/ricochet.js b/src/fx/impacts/ricochet.js
new file mode 100644
index 0000000..be7ccfd
--- /dev/null
+++ b/src/fx/impacts/ricochet.js
@@ -0,0 +1,69 @@
+import { PAL, ramp, burst, fly, flyV, seg, ease, clamp, WHITE } from "../../core/index.js";
+import { rayStar, streak, puff } from "./_lib.js";
+
+export const meta = {
+ name: "Ricochet",
+ desc: "A tracer streaks down into the floor, flashes, and skips off up-right in a long fading streak, kicking up sparks and a pinch of dust.",
+ tags: ["impact", "bullet", "ricochet", "tracer", "sparks", "directional", "one-shot"],
+ size: [72, 40],
+ origin: [26, 32],
+ duration: 0.4,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ options: { palette: ["#3a0e0a", "#8a2a10", "#d85a14", "#ff9a2a", "#ffd86a", "#fff6c8", "#ffffff"], dust: PAL.dust, skip: 0.32, seed: 11 },
+};
+
+export function draw(p, t, o) {
+ const C = ramp(o.palette), D = ramp(o.dust), S = o.seed, N = C.length - 1;
+ const ix = Math.cos(0.72), iy = Math.sin(0.72); // the way in: down and right
+ const ox = Math.cos(-o.skip), oy = Math.sin(-o.skip); // the way out: up and right, shallow
+ const T = 0.034; // the frame it hits
+ // the round coming in: a tracer whose head reaches the floor on the hit frame
+ const inHead = 15 * (1 - seg(t, 0, T)), inTail = Math.min(33, inHead + 26 * (1 - seg(t, 0, 0.07)));
+ if (inTail - inHead > 1)
+ p.line(-ix * inTail, -iy * inTail, -ix * inHead, -iy * inHead, (u) => (u > 0.75 ? WHITE : u > 0.35 ? C[N - 2] : C[N - 3]));
+ // the round going out: the head races off, the tail chases it down
+ const outHead = 44 * ease.outQuad(seg(t, T, 0.15)), outTail = 44 * ease.inQuad(seg(t, T + 0.02, 0.24));
+ if (outHead - outTail > 1) {
+ const fade = seg(t, 0.14, 0.24);
+ p.line(ox * outTail, oy * outTail - 1, ox * outHead, oy * outHead - 1,
+ (u) => (u > 0.8 - fade * 0.3 ? (fade < 0.5 ? WHITE : C[N - 1]) : u > 0.4 ? C[N - 2] : C[N - 3]));
+ if (fade < 0.6) p.px(ox * outHead, oy * outHead - 2, WHITE);
+ p.glowLine(ox * outTail, oy * outTail - 1, ox * outHead, oy * outHead - 1, 4, C[N - 2], 0.3 * (1 - fade));
+ }
+ // a scorch skid on the floor where it hit, fading
+ const sk = 1 - seg(t, 0.2, 0.4);
+ if (t >= T && sk > 0) p.line(-3, 0, 3, 0, (u) => (u < 0.3 || u > 0.8 ? C[1] : C[2]), sk);
+ // dust kicked up off the floor
+ burst(3, S + 2, (r, i) => {
+ const born = T + i * 0.02, life = r.range(0.24, 0.32), age = t - born;
+ if (age < 0 || age > life) return;
+ const q = age / life, [x, y] = fly(r.range(-1, 2), -1, r.range(10, 40), -r.range(16, 34), age, -10, 4);
+ puff(p, x, Math.min(y, -1), (0.8 + r.range(0.8, 1.8) * ease.outCubic(q)) * (1 - 0.6 * seg(q, 0.5, 1)), D.slice(4), 1 - seg(q, 0.8, 1), 0.5 - q * 0.5);
+ });
+ // sparks: sprayed forward off the hit, dropping, skidding along the floor as they cool
+ burst(9, S, (r) => {
+ const a = -o.skip + r.range(-0.9, 0.35), sp = r.range(70, 170), born = T + r.range(0, 0.03), life = r.range(0.15, 0.32), age = t - born;
+ if (age < 0 || age > life) return;
+ const q = age / life, vx0 = Math.cos(a) * sp, vy0 = Math.sin(a) * sp;
+ let [x, y] = fly(0, -1, vx0, vy0, age, 260, 3.5);
+ const [vx, vy] = flyV(vx0, vy0, age, 260, 3.5);
+ y = Math.min(y, -1);
+ const head = q < 0.3 ? WHITE : q < 0.65 ? C[N - 1] : C[N - 3];
+ streak(p, x, y, vx, y >= -1 ? 0 : vy, clamp(Math.hypot(vx, vy) * 0.03, 1, 4), (u) => (u > 0.5 ? head : C[N - 3]));
+ p.light(x, y, C[N - 2], 0.4 * (1 - q));
+ });
+ // the hit: a flat white flash pressed onto the floor
+ if (t >= T && t < T + 0.07) {
+ const s = t < T + 0.035 ? 1 : 0.5;
+ rayStar(p, 0, -1, [
+ { a: 0, len: 8 * s, w: 1.4 }, { a: Math.PI, len: 7 * s, w: 1.4 }, { a: -Math.PI / 2, len: 6 * s, w: 1.4 },
+ { a: -Math.PI / 4, len: 4 * s, w: 0.4 }, { a: (-3 * Math.PI) / 4, len: 4 * s, w: 0.4 },
+ ], (q) => (q < 0.5 ? WHITE : C[N - 1]));
+ p.circle(0, -1, 2 * s, WHITE);
+ }
+ const L = t < T ? 0.4 : 1 - seg(t, T, 0.25);
+ p.glow(0, -2, 18, C[N - 2], 0.4 * L * L);
+ p.glow(0, -1, 5, C[N - 1], 0.5 * L);
+}
diff --git a/src/fx/impacts/shield-block.js b/src/fx/impacts/shield-block.js
new file mode 100644
index 0000000..03e854d
--- /dev/null
+++ b/src/fx/impacts/shield-block.js
@@ -0,0 +1,73 @@
+import { PAL, ramp, burst, fly, flyV, seg, ease, clamp, TAU, WHITE } from "../../core/index.js";
+import { rayStar, streak } from "./_lib.js";
+
+export const meta = {
+ name: "Shield block",
+ desc: "A hit lands on a half-dome energy shield: it flares white, a ripple runs out along the rim from the hit, sparks glance off, the dome dims away.",
+ tags: ["impact", "shield", "block", "barrier", "defense", "sparks", "directional", "one-shot"],
+ size: [64, 48],
+ origin: [22, 40],
+ duration: 0.6,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ actor: true,
+ options: { palette: PAL.cyber, radius: 15, hit: -0.25, seed: 14 },
+};
+
+export function draw(p, t, o) {
+ const C = ramp(o.palette), S = o.seed, N = C.length - 1;
+ const R = o.radius + Math.round(2.2 * Math.sin(seg(t, 0.03, 0.4) * Math.PI * 3) * (1 - seg(t, 0.03, 0.4))); // it gives, then rings
+ const cx = 1, cy = -10, H = o.hit; // dome center (the chest) and where the blow lands (angle)
+ const hx = cx + Math.cos(H) * (o.radius - 1), hy = cy + Math.sin(H) * (o.radius - 1);
+ const flare = 1 - seg(t, 0, 0.1), wave = (Math.PI / 2 + 0.3) * ease.outQuad(seg(t, 0.02, 0.24)), out = seg(t, 0.32, 0.6);
+ // the membrane: a lattice that flashes over the dome on impact
+ if (flare > 0)
+ p.shade(cx, cy - R, cx + R, Math.min(0, cy + R), (x, y, o2) => {
+ const dx = x - cx, dy = y - cy, d = Math.hypot(dx, dy);
+ if (d > R - 2 || dx < 0) return;
+ const lat = (Math.floor(x + y) % 5 === 0) || (Math.floor(x - y + 100) % 5 === 0);
+ if (!lat) return;
+ o2.c = d / R > 0.65 ? C[N - 2] : C[N - 3];
+ o2.a = flare * (0.35 + 0.65 * (d / R));
+ });
+ // the rim: a thick bright arc, the ripple running along it from the hit, ends eaten away as it dims
+ const end = (Math.PI / 2) * (1 - ease.inQuad(out));
+ if (end > 0.05) {
+ const a0 = -end, a1 = Math.min(end, Math.asin(clamp((0 - cy) / R)));
+ p.arc(cx, cy, R, (u) => 3 - out * 1.5 - (Math.abs(u - 0.5) > 0.46 ? 1 : 0), a0, a1, (u, v) => {
+ const ang = a0 + (a1 - a0) * u, phi = Math.abs(ang - H), w = Math.abs(phi - wave);
+ if (flare > 0.7) return v > 0.4 ? WHITE : C[N - 1];
+ if (w < 0.32 && wave < Math.PI / 2 + 0.28) return v > 0.3 ? WHITE : C[N - 1];
+ return v > 0.66 ? C[N - 2] : v > 0.33 ? C[N - 3] : C[N - 4];
+ }, (u, v) => (out > 0.7 && v < 0.5 ? 0 : 1));
+ for (let k = -2; k <= 2; k++) {
+ const a = (k / 2) * end * 0.9;
+ if (cy + Math.sin(a) * R < 2) p.glow(cx + Math.cos(a) * R, cy + Math.sin(a) * R, 9, C[N - 2], 0.12 * (1 - out));
+ }
+ }
+ // concentric ripples around the hit
+ const rp = seg(t, 0.03, 0.24);
+ if (rp > 0 && rp < 1)
+ p.ring(hx, hy, 3 + 8 * ease.outCubic(rp), 1, rp < 0.4 ? WHITE : C[N - 2], (v, ang) => (Math.cos(ang - H) > -0.2 + rp * 1.1 ? 1 : 0));
+ // sparks glance off the shield's face
+ burst(8, S, (r, i) => {
+ const a = H + (i % 2 ? 1 : -1) * r.range(0.5, 1.35), sp = r.range(80, 170), born = r.range(0, 0.04), life = r.range(0.2, 0.34), age = t - born;
+ if (age < 0 || age > life) return;
+ const q = age / life, vx0 = Math.cos(a) * sp, vy0 = Math.sin(a) * sp;
+ const [x, y] = fly(hx + 1, hy, vx0, vy0, age, 110, 3.5), [vx, vy] = flyV(vx0, vy0, age, 110, 3.5);
+ if (y > 0) return;
+ const head = q < 0.45 ? WHITE : q < 0.75 ? C[N - 1] : C[N - 2];
+ streak(p, x, y, vx, vy, clamp(Math.hypot(vx, vy) * 0.03, 1, 4), (u) => (u > 0.5 ? head : C[N - 3]));
+ p.light(x, y, C[N - 2], 0.4 * (1 - q));
+ });
+ // the blow itself: a white star on the rim for two frames
+ if (t < 0.07) {
+ const s = t < 0.035 ? 1 : 0.55;
+ rayStar(p, hx + 1, hy, [0, 1, 2, 3].map((i) => ({ a: (i * TAU) / 4, len: (i % 2 ? 7 : 9) * s, w: 1.4 })), (q) => (q < 0.5 ? WHITE : C[N - 1]));
+ p.circle(hx + 1, hy, 2.2 * s, WHITE);
+ }
+ const L = 1 - seg(t, 0, 0.45);
+ p.glow(hx, hy, 20, C[N - 2], 0.4 * L * L);
+ p.glow(cx + R * 0.5, cy, R * 1.6, C[N - 3], 0.2 * L);
+}
diff --git a/src/fx/impacts/stomp-dust.js b/src/fx/impacts/stomp-dust.js
new file mode 100644
index 0000000..63a12f7
--- /dev/null
+++ b/src/fx/impacts/stomp-dust.js
@@ -0,0 +1,39 @@
+import { PAL, ramp, burst, fly, seg, ease } from "../../core/index.js";
+import { puff } from "./_lib.js";
+
+export const meta = {
+ name: "Stomp dust",
+ desc: "A landing kicks dust out both ways: a flat skirt splits into two rolling clusters of puffs that skid out along the floor, lift a little and thin away.",
+ tags: ["impact", "dust", "land", "stomp", "jump", "ground", "one-shot"],
+ size: [64, 24],
+ origin: [32, 20],
+ duration: 0.6,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ options: { palette: PAL.dust, size: 1, seed: 15 },
+};
+
+export function draw(p, t, o) {
+ const D = ramp(o.palette), S = o.seed, k = o.size, N = D.length - 1;
+ // the squash: a flat skirt of dust under the feet for the first frames
+ const sq = seg(t, 0, 0.1);
+ if (sq < 1) p.ellipse(0, -1, (5 + 9 * ease.outCubic(sq)) * k, (2.2 - sq) * k, (d, a) => (Math.sin(a) < -0.3 ? D[N] : D[N - 1]), (d) => (d > 1 - sq ? 0 : 1));
+ // two clusters rolling out: a lead puff, smaller ones trailing and lifting, all skidding to a stop
+ burst(12, S, (r, i) => {
+ const side = i % 2 ? 1 : -1, rank = i >> 1; // 0 leads, the rest trail further and further behind
+ const born = 0.01 + rank * r.range(0.01, 0.025), life = r.range(0.4, 0.58) - rank * 0.025, age = t - born;
+ if (age < 0 || age > life) return;
+ const q = age / life, sp = (130 - rank * 17) * r.range(0.85, 1.15) * k;
+ const [x, y] = fly(side * r.range(1, 4) * k, -1.5, side * sp, -r.range(4, 10 + rank * 5) * k, age, -4, 4.8);
+ const rad = (1 + (3 - rank * 0.35) * r.range(0.75, 1.15) * ease.outCubic(seg(q, 0, 0.35))) * k * (1 - 0.75 * ease.inQuad(seg(q, 0.4, 1)));
+ puff(p, x, Math.min(y, -rad * 0.8), rad, D.slice(2), 1 - seg(q, 0.88, 1), 0.45 - q * 0.7, 0.95);
+ });
+ // a few pebbles hopping out
+ burst(4, S + 1, (r, i) => {
+ const side = i % 2 ? 1 : -1, life = r.range(0.3, 0.42);
+ if (t > life) return;
+ const [x, y] = fly(side * 2, -1, side * r.range(40, 80) * k, -r.range(35, 60), t, 320, 1);
+ if (y < 0) p.px(x, y, D[N - 2]);
+ });
+}
diff --git a/src/fx/index.js b/src/fx/index.js
new file mode 100644
index 0000000..1b8fb1d
--- /dev/null
+++ b/src/fx/index.js
@@ -0,0 +1,605 @@
+// Generated by tools/index.mjs: every effect, by id. Don't edit; run `node tools/index.mjs`.
+
+import * as fire_brazier from "./fire/brazier.js";
+import * as fire_campfire from "./fire/campfire.js";
+import * as fire_candle from "./fire/candle.js";
+import * as fire_ember_burst from "./fire/ember-burst.js";
+import * as fire_fire_breath from "./fire/fire-breath.js";
+import * as fire_fire_ring from "./fire/fire-ring.js";
+import * as fire_fire_tornado from "./fire/fire-tornado.js";
+import * as fire_fireball from "./fire/fireball.js";
+import * as fire_flame_pillar from "./fire/flame-pillar.js";
+import * as fire_flamethrower from "./fire/flamethrower.js";
+import * as fire_ground_fire from "./fire/ground-fire.js";
+import * as fire_ignite from "./fire/ignite.js";
+import * as fire_inferno_wall from "./fire/inferno-wall.js";
+import * as fire_meteor from "./fire/meteor.js";
+import * as fire_molotov from "./fire/molotov.js";
+import * as fire_spirit_flame from "./fire/spirit-flame.js";
+import * as fire_torch from "./fire/torch.js";
+import * as explosions_barrel_explosion from "./explosions/barrel-explosion.js";
+import * as explosions_big_explosion from "./explosions/big-explosion.js";
+import * as explosions_cartoon_pow from "./explosions/cartoon-pow.js";
+import * as explosions_chain_explosions from "./explosions/chain-explosions.js";
+import * as explosions_dirt_explosion from "./explosions/dirt-explosion.js";
+import * as explosions_dust_cloud from "./explosions/dust-cloud.js";
+import * as explosions_firework_burst from "./explosions/firework-burst.js";
+import * as explosions_firework_rocket from "./explosions/firework-rocket.js";
+import * as explosions_gas_explosion from "./explosions/gas-explosion.js";
+import * as explosions_grenade from "./explosions/grenade.js";
+import * as explosions_implosion from "./explosions/implosion.js";
+import * as explosions_mine_blast from "./explosions/mine-blast.js";
+import * as explosions_nuke from "./explosions/nuke.js";
+import * as explosions_plasma_explosion from "./explosions/plasma-explosion.js";
+import * as explosions_small_explosion from "./explosions/small-explosion.js";
+import * as explosions_smoke_puff from "./explosions/smoke-puff.js";
+import * as water_bubbles from "./water/bubbles.js";
+import * as water_drip from "./water/drip.js";
+import * as water_fountain from "./water/fountain.js";
+import * as water_geyser from "./water/geyser.js";
+import * as water_puddle_step from "./water/puddle-step.js";
+import * as water_rain_splash from "./water/rain-splash.js";
+import * as water_ripples from "./water/ripples.js";
+import * as water_splash from "./water/splash.js";
+import * as water_steam_vent from "./water/steam-vent.js";
+import * as water_tidal_wave from "./water/tidal-wave.js";
+import * as water_water_jet from "./water/water-jet.js";
+import * as water_water_orb from "./water/water-orb.js";
+import * as water_waterfall from "./water/waterfall.js";
+import * as water_wave_crash from "./water/wave-crash.js";
+import * as water_whirlpool from "./water/whirlpool.js";
+import * as ice_blizzard_vortex from "./ice/blizzard-vortex.js";
+import * as ice_cold_mist from "./ice/cold-mist.js";
+import * as ice_freeze from "./ice/freeze.js";
+import * as ice_frost_breath from "./ice/frost-breath.js";
+import * as ice_frost_nova from "./ice/frost-nova.js";
+import * as ice_frozen_ground from "./ice/frozen-ground.js";
+import * as ice_hail_impact from "./ice/hail-impact.js";
+import * as ice_ice_crystal from "./ice/ice-crystal.js";
+import * as ice_ice_lance from "./ice/ice-lance.js";
+import * as ice_ice_shatter from "./ice/ice-shatter.js";
+import * as ice_ice_spikes from "./ice/ice-spikes.js";
+import * as ice_icicle_fall from "./ice/icicle-fall.js";
+import * as ice_snowflake_burst from "./ice/snowflake-burst.js";
+import * as lightning_ball_lightning from "./lightning/ball-lightning.js";
+import * as lightning_chain_lightning from "./lightning/chain-lightning.js";
+import * as lightning_charge_up from "./lightning/charge-up.js";
+import * as lightning_electric_field from "./lightning/electric-field.js";
+import * as lightning_electrified from "./lightning/electrified.js";
+import * as lightning_lightning_dash from "./lightning/lightning-dash.js";
+import * as lightning_lightning_strike from "./lightning/lightning-strike.js";
+import * as lightning_plasma_ball from "./lightning/plasma-ball.js";
+import * as lightning_spark_arc from "./lightning/spark-arc.js";
+import * as lightning_static_pops from "./lightning/static-pops.js";
+import * as lightning_storm_cloud from "./lightning/storm-cloud.js";
+import * as lightning_tesla_coil from "./lightning/tesla-coil.js";
+import * as lightning_thunderclap from "./lightning/thunderclap.js";
+import * as lightning_zap_hit from "./lightning/zap-hit.js";
+import * as scifi_cloak from "./scifi/cloak.js";
+import * as scifi_data_stream from "./scifi/data-stream.js";
+import * as scifi_emp_blast from "./scifi/emp-blast.js";
+import * as scifi_energy_core from "./scifi/energy-core.js";
+import * as scifi_force_field from "./scifi/force-field.js";
+import * as scifi_glitch from "./scifi/glitch.js";
+import * as scifi_hologram from "./scifi/hologram.js";
+import * as scifi_jetpack from "./scifi/jetpack.js";
+import * as scifi_laser_grid from "./scifi/laser-grid.js";
+import * as scifi_radar_ping from "./scifi/radar-ping.js";
+import * as scifi_scanner from "./scifi/scanner.js";
+import * as scifi_teleporter_pad from "./scifi/teleporter-pad.js";
+import * as scifi_tractor_beam from "./scifi/tractor-beam.js";
+import * as scifi_warp_in from "./scifi/warp-in.js";
+import * as scifi_warp_out from "./scifi/warp-out.js";
+import * as melee_axe_chop from "./melee/axe-chop.js";
+import * as melee_claw_swipe from "./melee/claw-swipe.js";
+import * as melee_counter_flash from "./melee/counter-flash.js";
+import * as melee_dagger_flurry from "./melee/dagger-flurry.js";
+import * as melee_double_slash from "./melee/double-slash.js";
+import * as melee_hammer_smash from "./melee/hammer-smash.js";
+import * as melee_heavy_cleave from "./melee/heavy-cleave.js";
+import * as melee_iaido_cut from "./melee/iaido-cut.js";
+import * as melee_punch_combo from "./melee/punch-combo.js";
+import * as melee_scythe_reap from "./melee/scythe-reap.js";
+import * as melee_spear_sweep from "./melee/spear-sweep.js";
+import * as melee_spin_slash from "./melee/spin-slash.js";
+import * as melee_sword_slash from "./melee/sword-slash.js";
+import * as melee_thrust from "./melee/thrust.js";
+import * as melee_uppercut from "./melee/uppercut.js";
+import * as melee_whip_crack from "./melee/whip-crack.js";
+import * as impacts_blunt_hit from "./impacts/blunt-hit.js";
+import * as impacts_bullet_impact from "./impacts/bullet-impact.js";
+import * as impacts_combo_hit from "./impacts/combo-hit.js";
+import * as impacts_crit_hit from "./impacts/crit-hit.js";
+import * as impacts_ground_slam from "./impacts/ground-slam.js";
+import * as impacts_heavy_landing from "./impacts/heavy-landing.js";
+import * as impacts_hit_flash from "./impacts/hit-flash.js";
+import * as impacts_hit_spark from "./impacts/hit-spark.js";
+import * as impacts_impact_frame from "./impacts/impact-frame.js";
+import * as impacts_knockback_wind from "./impacts/knockback-wind.js";
+import * as impacts_parry from "./impacts/parry.js";
+import * as impacts_ricochet from "./impacts/ricochet.js";
+import * as impacts_shield_block from "./impacts/shield-block.js";
+import * as impacts_stomp_dust from "./impacts/stomp-dust.js";
+import * as projectiles_arrow from "./projectiles/arrow.js";
+import * as projectiles_arrow_hit from "./projectiles/arrow-hit.js";
+import * as projectiles_boomerang from "./projectiles/boomerang.js";
+import * as projectiles_bullet_tracer from "./projectiles/bullet-tracer.js";
+import * as projectiles_cannonball from "./projectiles/cannonball.js";
+import * as projectiles_energy_disc from "./projectiles/energy-disc.js";
+import * as projectiles_flare from "./projectiles/flare.js";
+import * as projectiles_homing_missile from "./projectiles/homing-missile.js";
+import * as projectiles_laser_bolt from "./projectiles/laser-bolt.js";
+import * as projectiles_magic_missile from "./projectiles/magic-missile.js";
+import * as projectiles_muzzle_pistol from "./projectiles/muzzle-pistol.js";
+import * as projectiles_muzzle_shotgun from "./projectiles/muzzle-shotgun.js";
+import * as projectiles_muzzle_smg from "./projectiles/muzzle-smg.js";
+import * as projectiles_plasma_shot from "./projectiles/plasma-shot.js";
+import * as projectiles_rocket from "./projectiles/rocket.js";
+import * as projectiles_shuriken from "./projectiles/shuriken.js";
+import * as projectiles_sniper_trail from "./projectiles/sniper-trail.js";
+import * as spawn_coin_drop from "./spawn/coin-drop.js";
+import * as spawn_disintegrate from "./spawn/disintegrate.js";
+import * as spawn_dissolve_burn from "./spawn/dissolve-burn.js";
+import * as spawn_egg_hatch from "./spawn/egg-hatch.js";
+import * as spawn_ghost_out from "./spawn/ghost-out.js";
+import * as spawn_poof from "./spawn/poof.js";
+import * as spawn_respawn_beam from "./spawn/respawn-beam.js";
+import * as spawn_shatter_death from "./spawn/shatter-death.js";
+import * as spawn_skull_pop from "./spawn/skull-pop.js";
+import * as spawn_soul_rise from "./spawn/soul-rise.js";
+import * as spawn_spawn_portal from "./spawn/spawn-portal.js";
+import * as spawn_summon_rise from "./spawn/summon-rise.js";
+import * as spawn_teleport_sparkle from "./spawn/teleport-sparkle.js";
+import * as arcane_arcane_beam from "./arcane/arcane-beam.js";
+import * as arcane_arcane_missiles from "./arcane/arcane-missiles.js";
+import * as arcane_arcane_orb from "./arcane/arcane-orb.js";
+import * as arcane_blink_in from "./arcane/blink-in.js";
+import * as arcane_blink_out from "./arcane/blink-out.js";
+import * as arcane_enchant from "./arcane/enchant.js";
+import * as arcane_glyph_burst from "./arcane/glyph-burst.js";
+import * as arcane_magic_circle_cast from "./arcane/magic-circle-cast.js";
+import * as arcane_mana_burst from "./arcane/mana-burst.js";
+import * as arcane_mirror_images from "./arcane/mirror-images.js";
+import * as arcane_portal from "./arcane/portal.js";
+import * as arcane_rune_circle from "./arcane/rune-circle.js";
+import * as arcane_sparkle_swirl from "./arcane/sparkle-swirl.js";
+import * as arcane_spell_charge from "./arcane/spell-charge.js";
+import * as arcane_star_fall from "./arcane/star-fall.js";
+import * as arcane_time_stop from "./arcane/time-stop.js";
+import * as holy_blessing from "./holy/blessing.js";
+import * as holy_divine_shield from "./holy/divine-shield.js";
+import * as holy_feather_burst from "./holy/feather-burst.js";
+import * as holy_halo from "./holy/halo.js";
+import * as holy_heal from "./holy/heal.js";
+import * as holy_heal_aoe from "./holy/heal-aoe.js";
+import * as holy_holy_pillar from "./holy/holy-pillar.js";
+import * as holy_purify from "./holy/purify.js";
+import * as holy_regen from "./holy/regen.js";
+import * as holy_resurrection from "./holy/resurrection.js";
+import * as holy_smite from "./holy/smite.js";
+import * as holy_sunburst from "./holy/sunburst.js";
+import * as shadow_black_hole from "./shadow/black-hole.js";
+import * as shadow_curse from "./shadow/curse.js";
+import * as shadow_dark_explosion from "./shadow/dark-explosion.js";
+import * as shadow_doom_mark from "./shadow/doom-mark.js";
+import * as shadow_eclipse from "./shadow/eclipse.js";
+import * as shadow_grasping_hands from "./shadow/grasping-hands.js";
+import * as shadow_hex_sigil from "./shadow/hex-sigil.js";
+import * as shadow_life_steal from "./shadow/life-steal.js";
+import * as shadow_necro_skulls from "./shadow/necro-skulls.js";
+import * as shadow_shadow_flames from "./shadow/shadow-flames.js";
+import * as shadow_shadow_step from "./shadow/shadow-step.js";
+import * as shadow_shadow_tendrils from "./shadow/shadow-tendrils.js";
+import * as shadow_soul_drain from "./shadow/soul-drain.js";
+import * as shadow_void_orb from "./shadow/void-orb.js";
+import * as status_bleeding from "./status/bleeding.js";
+import * as status_burning from "./status/burning.js";
+import * as status_charmed from "./status/charmed.js";
+import * as status_confused from "./status/confused.js";
+import * as status_cursed from "./status/cursed.js";
+import * as status_fortified from "./status/fortified.js";
+import * as status_frozen from "./status/frozen.js";
+import * as status_haste from "./status/haste.js";
+import * as status_invisible from "./status/invisible.js";
+import * as status_marked from "./status/marked.js";
+import * as status_petrified from "./status/petrified.js";
+import * as status_poisoned from "./status/poisoned.js";
+import * as status_rage from "./status/rage.js";
+import * as status_sleep from "./status/sleep.js";
+import * as status_slowed from "./status/slowed.js";
+import * as status_stunned from "./status/stunned.js";
+import * as nature_acid_splash from "./nature/acid-splash.js";
+import * as nature_boulder from "./nature/boulder.js";
+import * as nature_earth_spike from "./nature/earth-spike.js";
+import * as nature_healing_bloom from "./nature/healing-bloom.js";
+import * as nature_leaf_storm from "./nature/leaf-storm.js";
+import * as nature_poison_cloud from "./nature/poison-cloud.js";
+import * as nature_quake from "./nature/quake.js";
+import * as nature_root_snare from "./nature/root-snare.js";
+import * as nature_sand_burst from "./nature/sand-burst.js";
+import * as nature_spore_burst from "./nature/spore-burst.js";
+import * as nature_thorns from "./nature/thorns.js";
+import * as nature_tornado from "./nature/tornado.js";
+import * as nature_toxic_puddle from "./nature/toxic-puddle.js";
+import * as nature_vine_whip from "./nature/vine-whip.js";
+import * as nature_wind_gust from "./nature/wind-gust.js";
+import * as weather_aurora from "./weather/aurora.js";
+import * as weather_blizzard from "./weather/blizzard.js";
+import * as weather_cherry_blossoms from "./weather/cherry-blossoms.js";
+import * as weather_clouds from "./weather/clouds.js";
+import * as weather_falling_leaves from "./weather/falling-leaves.js";
+import * as weather_fireflies from "./weather/fireflies.js";
+import * as weather_fog from "./weather/fog.js";
+import * as weather_god_rays from "./weather/god-rays.js";
+import * as weather_hail from "./weather/hail.js";
+import * as weather_heat_haze from "./weather/heat-haze.js";
+import * as weather_rain from "./weather/rain.js";
+import * as weather_sandstorm from "./weather/sandstorm.js";
+import * as weather_shooting_stars from "./weather/shooting-stars.js";
+import * as weather_snow from "./weather/snow.js";
+import * as weather_storm from "./weather/storm.js";
+import * as weather_twinkling_stars from "./weather/twinkling-stars.js";
+import * as ui_achievement from "./ui/achievement.js";
+import * as ui_button_press from "./ui/button-press.js";
+import * as ui_checkmark from "./ui/checkmark.js";
+import * as ui_coin_collect from "./ui/coin-collect.js";
+import * as ui_combo_counter from "./ui/combo-counter.js";
+import * as ui_confetti from "./ui/confetti.js";
+import * as ui_countdown from "./ui/countdown.js";
+import * as ui_crit_number from "./ui/crit-number.js";
+import * as ui_damage_number from "./ui/damage-number.js";
+import * as ui_error_x from "./ui/error-x.js";
+import * as ui_exclamation from "./ui/exclamation.js";
+import * as ui_heal_number from "./ui/heal-number.js";
+import * as ui_health_bar_hit from "./ui/health-bar-hit.js";
+import * as ui_heart_lost from "./ui/heart-lost.js";
+import * as ui_level_up from "./ui/level-up.js";
+import * as ui_loading_dots from "./ui/loading-dots.js";
+import * as ui_loading_spinner from "./ui/loading-spinner.js";
+import * as ui_notification from "./ui/notification.js";
+import * as ui_quest_complete from "./ui/quest-complete.js";
+import * as pickups_ammo_crate from "./pickups/ammo-crate.js";
+import * as pickups_chest_open from "./pickups/chest-open.js";
+import * as pickups_coin_spin from "./pickups/coin-spin.js";
+import * as pickups_collect_burst from "./pickups/collect-burst.js";
+import * as pickups_crystal_shard from "./pickups/crystal-shard.js";
+import * as pickups_gem_spin from "./pickups/gem-spin.js";
+import * as pickups_heart_pickup from "./pickups/heart-pickup.js";
+import * as pickups_key_glint from "./pickups/key-glint.js";
+import * as pickups_loot_beam from "./pickups/loot-beam.js";
+import * as pickups_magnet_pull from "./pickups/magnet-pull.js";
+import * as pickups_potion from "./pickups/potion.js";
+import * as pickups_power_star from "./pickups/power-star.js";
+import * as pickups_scroll from "./pickups/scroll.js";
+import * as pickups_trophy from "./pickups/trophy.js";
+import * as pickups_xp_orb from "./pickups/xp-orb.js";
+import * as transitions_blinds from "./transitions/blinds.js";
+import * as transitions_burn_away from "./transitions/burn-away.js";
+import * as transitions_crt_off from "./transitions/crt-off.js";
+import * as transitions_diamond_wipe from "./transitions/diamond-wipe.js";
+import * as transitions_dither_fade from "./transitions/dither-fade.js";
+import * as transitions_glitch_wipe from "./transitions/glitch-wipe.js";
+import * as transitions_iris from "./transitions/iris.js";
+import * as transitions_pixel_dissolve from "./transitions/pixel-dissolve.js";
+import * as transitions_shatter_wipe from "./transitions/shatter-wipe.js";
+import * as transitions_slash_wipe from "./transitions/slash-wipe.js";
+import * as transitions_spiral_wipe from "./transitions/spiral-wipe.js";
+import * as transitions_star_iris from "./transitions/star-iris.js";
+import * as critters_bat from "./critters/bat.js";
+import * as critters_bird from "./critters/bird.js";
+import * as critters_butterfly from "./critters/butterfly.js";
+import * as critters_crab from "./critters/crab.js";
+import * as critters_eyeball from "./critters/eyeball.js";
+import * as critters_fish_school from "./critters/fish-school.js";
+import * as critters_flying_skull from "./critters/flying-skull.js";
+import * as critters_frog from "./critters/frog.js";
+import * as critters_ghost from "./critters/ghost.js";
+import * as critters_jellyfish from "./critters/jellyfish.js";
+import * as critters_slime from "./critters/slime.js";
+import * as critters_snake from "./critters/snake.js";
+import * as critters_spider from "./critters/spider.js";
+import * as critters_wisp from "./critters/wisp.js";
+
+export { categories } from "./categories.js";
+
+export const effects = {
+ "fire/brazier": fire_brazier,
+ "fire/campfire": fire_campfire,
+ "fire/candle": fire_candle,
+ "fire/ember-burst": fire_ember_burst,
+ "fire/fire-breath": fire_fire_breath,
+ "fire/fire-ring": fire_fire_ring,
+ "fire/fire-tornado": fire_fire_tornado,
+ "fire/fireball": fire_fireball,
+ "fire/flame-pillar": fire_flame_pillar,
+ "fire/flamethrower": fire_flamethrower,
+ "fire/ground-fire": fire_ground_fire,
+ "fire/ignite": fire_ignite,
+ "fire/inferno-wall": fire_inferno_wall,
+ "fire/meteor": fire_meteor,
+ "fire/molotov": fire_molotov,
+ "fire/spirit-flame": fire_spirit_flame,
+ "fire/torch": fire_torch,
+ "explosions/barrel-explosion": explosions_barrel_explosion,
+ "explosions/big-explosion": explosions_big_explosion,
+ "explosions/cartoon-pow": explosions_cartoon_pow,
+ "explosions/chain-explosions": explosions_chain_explosions,
+ "explosions/dirt-explosion": explosions_dirt_explosion,
+ "explosions/dust-cloud": explosions_dust_cloud,
+ "explosions/firework-burst": explosions_firework_burst,
+ "explosions/firework-rocket": explosions_firework_rocket,
+ "explosions/gas-explosion": explosions_gas_explosion,
+ "explosions/grenade": explosions_grenade,
+ "explosions/implosion": explosions_implosion,
+ "explosions/mine-blast": explosions_mine_blast,
+ "explosions/nuke": explosions_nuke,
+ "explosions/plasma-explosion": explosions_plasma_explosion,
+ "explosions/small-explosion": explosions_small_explosion,
+ "explosions/smoke-puff": explosions_smoke_puff,
+ "water/bubbles": water_bubbles,
+ "water/drip": water_drip,
+ "water/fountain": water_fountain,
+ "water/geyser": water_geyser,
+ "water/puddle-step": water_puddle_step,
+ "water/rain-splash": water_rain_splash,
+ "water/ripples": water_ripples,
+ "water/splash": water_splash,
+ "water/steam-vent": water_steam_vent,
+ "water/tidal-wave": water_tidal_wave,
+ "water/water-jet": water_water_jet,
+ "water/water-orb": water_water_orb,
+ "water/waterfall": water_waterfall,
+ "water/wave-crash": water_wave_crash,
+ "water/whirlpool": water_whirlpool,
+ "ice/blizzard-vortex": ice_blizzard_vortex,
+ "ice/cold-mist": ice_cold_mist,
+ "ice/freeze": ice_freeze,
+ "ice/frost-breath": ice_frost_breath,
+ "ice/frost-nova": ice_frost_nova,
+ "ice/frozen-ground": ice_frozen_ground,
+ "ice/hail-impact": ice_hail_impact,
+ "ice/ice-crystal": ice_ice_crystal,
+ "ice/ice-lance": ice_ice_lance,
+ "ice/ice-shatter": ice_ice_shatter,
+ "ice/ice-spikes": ice_ice_spikes,
+ "ice/icicle-fall": ice_icicle_fall,
+ "ice/snowflake-burst": ice_snowflake_burst,
+ "lightning/ball-lightning": lightning_ball_lightning,
+ "lightning/chain-lightning": lightning_chain_lightning,
+ "lightning/charge-up": lightning_charge_up,
+ "lightning/electric-field": lightning_electric_field,
+ "lightning/electrified": lightning_electrified,
+ "lightning/lightning-dash": lightning_lightning_dash,
+ "lightning/lightning-strike": lightning_lightning_strike,
+ "lightning/plasma-ball": lightning_plasma_ball,
+ "lightning/spark-arc": lightning_spark_arc,
+ "lightning/static-pops": lightning_static_pops,
+ "lightning/storm-cloud": lightning_storm_cloud,
+ "lightning/tesla-coil": lightning_tesla_coil,
+ "lightning/thunderclap": lightning_thunderclap,
+ "lightning/zap-hit": lightning_zap_hit,
+ "scifi/cloak": scifi_cloak,
+ "scifi/data-stream": scifi_data_stream,
+ "scifi/emp-blast": scifi_emp_blast,
+ "scifi/energy-core": scifi_energy_core,
+ "scifi/force-field": scifi_force_field,
+ "scifi/glitch": scifi_glitch,
+ "scifi/hologram": scifi_hologram,
+ "scifi/jetpack": scifi_jetpack,
+ "scifi/laser-grid": scifi_laser_grid,
+ "scifi/radar-ping": scifi_radar_ping,
+ "scifi/scanner": scifi_scanner,
+ "scifi/teleporter-pad": scifi_teleporter_pad,
+ "scifi/tractor-beam": scifi_tractor_beam,
+ "scifi/warp-in": scifi_warp_in,
+ "scifi/warp-out": scifi_warp_out,
+ "melee/axe-chop": melee_axe_chop,
+ "melee/claw-swipe": melee_claw_swipe,
+ "melee/counter-flash": melee_counter_flash,
+ "melee/dagger-flurry": melee_dagger_flurry,
+ "melee/double-slash": melee_double_slash,
+ "melee/hammer-smash": melee_hammer_smash,
+ "melee/heavy-cleave": melee_heavy_cleave,
+ "melee/iaido-cut": melee_iaido_cut,
+ "melee/punch-combo": melee_punch_combo,
+ "melee/scythe-reap": melee_scythe_reap,
+ "melee/spear-sweep": melee_spear_sweep,
+ "melee/spin-slash": melee_spin_slash,
+ "melee/sword-slash": melee_sword_slash,
+ "melee/thrust": melee_thrust,
+ "melee/uppercut": melee_uppercut,
+ "melee/whip-crack": melee_whip_crack,
+ "impacts/blunt-hit": impacts_blunt_hit,
+ "impacts/bullet-impact": impacts_bullet_impact,
+ "impacts/combo-hit": impacts_combo_hit,
+ "impacts/crit-hit": impacts_crit_hit,
+ "impacts/ground-slam": impacts_ground_slam,
+ "impacts/heavy-landing": impacts_heavy_landing,
+ "impacts/hit-flash": impacts_hit_flash,
+ "impacts/hit-spark": impacts_hit_spark,
+ "impacts/impact-frame": impacts_impact_frame,
+ "impacts/knockback-wind": impacts_knockback_wind,
+ "impacts/parry": impacts_parry,
+ "impacts/ricochet": impacts_ricochet,
+ "impacts/shield-block": impacts_shield_block,
+ "impacts/stomp-dust": impacts_stomp_dust,
+ "projectiles/arrow": projectiles_arrow,
+ "projectiles/arrow-hit": projectiles_arrow_hit,
+ "projectiles/boomerang": projectiles_boomerang,
+ "projectiles/bullet-tracer": projectiles_bullet_tracer,
+ "projectiles/cannonball": projectiles_cannonball,
+ "projectiles/energy-disc": projectiles_energy_disc,
+ "projectiles/flare": projectiles_flare,
+ "projectiles/homing-missile": projectiles_homing_missile,
+ "projectiles/laser-bolt": projectiles_laser_bolt,
+ "projectiles/magic-missile": projectiles_magic_missile,
+ "projectiles/muzzle-pistol": projectiles_muzzle_pistol,
+ "projectiles/muzzle-shotgun": projectiles_muzzle_shotgun,
+ "projectiles/muzzle-smg": projectiles_muzzle_smg,
+ "projectiles/plasma-shot": projectiles_plasma_shot,
+ "projectiles/rocket": projectiles_rocket,
+ "projectiles/shuriken": projectiles_shuriken,
+ "projectiles/sniper-trail": projectiles_sniper_trail,
+ "spawn/coin-drop": spawn_coin_drop,
+ "spawn/disintegrate": spawn_disintegrate,
+ "spawn/dissolve-burn": spawn_dissolve_burn,
+ "spawn/egg-hatch": spawn_egg_hatch,
+ "spawn/ghost-out": spawn_ghost_out,
+ "spawn/poof": spawn_poof,
+ "spawn/respawn-beam": spawn_respawn_beam,
+ "spawn/shatter-death": spawn_shatter_death,
+ "spawn/skull-pop": spawn_skull_pop,
+ "spawn/soul-rise": spawn_soul_rise,
+ "spawn/spawn-portal": spawn_spawn_portal,
+ "spawn/summon-rise": spawn_summon_rise,
+ "spawn/teleport-sparkle": spawn_teleport_sparkle,
+ "arcane/arcane-beam": arcane_arcane_beam,
+ "arcane/arcane-missiles": arcane_arcane_missiles,
+ "arcane/arcane-orb": arcane_arcane_orb,
+ "arcane/blink-in": arcane_blink_in,
+ "arcane/blink-out": arcane_blink_out,
+ "arcane/enchant": arcane_enchant,
+ "arcane/glyph-burst": arcane_glyph_burst,
+ "arcane/magic-circle-cast": arcane_magic_circle_cast,
+ "arcane/mana-burst": arcane_mana_burst,
+ "arcane/mirror-images": arcane_mirror_images,
+ "arcane/portal": arcane_portal,
+ "arcane/rune-circle": arcane_rune_circle,
+ "arcane/sparkle-swirl": arcane_sparkle_swirl,
+ "arcane/spell-charge": arcane_spell_charge,
+ "arcane/star-fall": arcane_star_fall,
+ "arcane/time-stop": arcane_time_stop,
+ "holy/blessing": holy_blessing,
+ "holy/divine-shield": holy_divine_shield,
+ "holy/feather-burst": holy_feather_burst,
+ "holy/halo": holy_halo,
+ "holy/heal": holy_heal,
+ "holy/heal-aoe": holy_heal_aoe,
+ "holy/holy-pillar": holy_holy_pillar,
+ "holy/purify": holy_purify,
+ "holy/regen": holy_regen,
+ "holy/resurrection": holy_resurrection,
+ "holy/smite": holy_smite,
+ "holy/sunburst": holy_sunburst,
+ "shadow/black-hole": shadow_black_hole,
+ "shadow/curse": shadow_curse,
+ "shadow/dark-explosion": shadow_dark_explosion,
+ "shadow/doom-mark": shadow_doom_mark,
+ "shadow/eclipse": shadow_eclipse,
+ "shadow/grasping-hands": shadow_grasping_hands,
+ "shadow/hex-sigil": shadow_hex_sigil,
+ "shadow/life-steal": shadow_life_steal,
+ "shadow/necro-skulls": shadow_necro_skulls,
+ "shadow/shadow-flames": shadow_shadow_flames,
+ "shadow/shadow-step": shadow_shadow_step,
+ "shadow/shadow-tendrils": shadow_shadow_tendrils,
+ "shadow/soul-drain": shadow_soul_drain,
+ "shadow/void-orb": shadow_void_orb,
+ "status/bleeding": status_bleeding,
+ "status/burning": status_burning,
+ "status/charmed": status_charmed,
+ "status/confused": status_confused,
+ "status/cursed": status_cursed,
+ "status/fortified": status_fortified,
+ "status/frozen": status_frozen,
+ "status/haste": status_haste,
+ "status/invisible": status_invisible,
+ "status/marked": status_marked,
+ "status/petrified": status_petrified,
+ "status/poisoned": status_poisoned,
+ "status/rage": status_rage,
+ "status/sleep": status_sleep,
+ "status/slowed": status_slowed,
+ "status/stunned": status_stunned,
+ "nature/acid-splash": nature_acid_splash,
+ "nature/boulder": nature_boulder,
+ "nature/earth-spike": nature_earth_spike,
+ "nature/healing-bloom": nature_healing_bloom,
+ "nature/leaf-storm": nature_leaf_storm,
+ "nature/poison-cloud": nature_poison_cloud,
+ "nature/quake": nature_quake,
+ "nature/root-snare": nature_root_snare,
+ "nature/sand-burst": nature_sand_burst,
+ "nature/spore-burst": nature_spore_burst,
+ "nature/thorns": nature_thorns,
+ "nature/tornado": nature_tornado,
+ "nature/toxic-puddle": nature_toxic_puddle,
+ "nature/vine-whip": nature_vine_whip,
+ "nature/wind-gust": nature_wind_gust,
+ "weather/aurora": weather_aurora,
+ "weather/blizzard": weather_blizzard,
+ "weather/cherry-blossoms": weather_cherry_blossoms,
+ "weather/clouds": weather_clouds,
+ "weather/falling-leaves": weather_falling_leaves,
+ "weather/fireflies": weather_fireflies,
+ "weather/fog": weather_fog,
+ "weather/god-rays": weather_god_rays,
+ "weather/hail": weather_hail,
+ "weather/heat-haze": weather_heat_haze,
+ "weather/rain": weather_rain,
+ "weather/sandstorm": weather_sandstorm,
+ "weather/shooting-stars": weather_shooting_stars,
+ "weather/snow": weather_snow,
+ "weather/storm": weather_storm,
+ "weather/twinkling-stars": weather_twinkling_stars,
+ "ui/achievement": ui_achievement,
+ "ui/button-press": ui_button_press,
+ "ui/checkmark": ui_checkmark,
+ "ui/coin-collect": ui_coin_collect,
+ "ui/combo-counter": ui_combo_counter,
+ "ui/confetti": ui_confetti,
+ "ui/countdown": ui_countdown,
+ "ui/crit-number": ui_crit_number,
+ "ui/damage-number": ui_damage_number,
+ "ui/error-x": ui_error_x,
+ "ui/exclamation": ui_exclamation,
+ "ui/heal-number": ui_heal_number,
+ "ui/health-bar-hit": ui_health_bar_hit,
+ "ui/heart-lost": ui_heart_lost,
+ "ui/level-up": ui_level_up,
+ "ui/loading-dots": ui_loading_dots,
+ "ui/loading-spinner": ui_loading_spinner,
+ "ui/notification": ui_notification,
+ "ui/quest-complete": ui_quest_complete,
+ "pickups/ammo-crate": pickups_ammo_crate,
+ "pickups/chest-open": pickups_chest_open,
+ "pickups/coin-spin": pickups_coin_spin,
+ "pickups/collect-burst": pickups_collect_burst,
+ "pickups/crystal-shard": pickups_crystal_shard,
+ "pickups/gem-spin": pickups_gem_spin,
+ "pickups/heart-pickup": pickups_heart_pickup,
+ "pickups/key-glint": pickups_key_glint,
+ "pickups/loot-beam": pickups_loot_beam,
+ "pickups/magnet-pull": pickups_magnet_pull,
+ "pickups/potion": pickups_potion,
+ "pickups/power-star": pickups_power_star,
+ "pickups/scroll": pickups_scroll,
+ "pickups/trophy": pickups_trophy,
+ "pickups/xp-orb": pickups_xp_orb,
+ "transitions/blinds": transitions_blinds,
+ "transitions/burn-away": transitions_burn_away,
+ "transitions/crt-off": transitions_crt_off,
+ "transitions/diamond-wipe": transitions_diamond_wipe,
+ "transitions/dither-fade": transitions_dither_fade,
+ "transitions/glitch-wipe": transitions_glitch_wipe,
+ "transitions/iris": transitions_iris,
+ "transitions/pixel-dissolve": transitions_pixel_dissolve,
+ "transitions/shatter-wipe": transitions_shatter_wipe,
+ "transitions/slash-wipe": transitions_slash_wipe,
+ "transitions/spiral-wipe": transitions_spiral_wipe,
+ "transitions/star-iris": transitions_star_iris,
+ "critters/bat": critters_bat,
+ "critters/bird": critters_bird,
+ "critters/butterfly": critters_butterfly,
+ "critters/crab": critters_crab,
+ "critters/eyeball": critters_eyeball,
+ "critters/fish-school": critters_fish_school,
+ "critters/flying-skull": critters_flying_skull,
+ "critters/frog": critters_frog,
+ "critters/ghost": critters_ghost,
+ "critters/jellyfish": critters_jellyfish,
+ "critters/slime": critters_slime,
+ "critters/snake": critters_snake,
+ "critters/spider": critters_spider,
+ "critters/wisp": critters_wisp,
+};
diff --git a/src/fx/lightning/_lib.js b/src/fx/lightning/_lib.js
new file mode 100644
index 0000000..039886d
--- /dev/null
+++ b/src/fx/lightning/_lib.js
@@ -0,0 +1,122 @@
+// Shared by the lightning effects: palettes resampled to a fixed length, bolts drawn the way a pixel artist
+// draws them (a hard 1 px core inside a 1 px halo), and light that hugs a whole path without beading at joints.
+
+import { ramp, bolt, clamp, rand } from "../../core/index.js";
+
+/** The palette as exactly n steps, dark to bright, so an effect can index it the same whatever its length. */
+export function steps(pal, n = 7) {
+ const C = ramp(pal);
+ if (C.length === n) return C;
+ return Array.from({ length: n }, (_, i) => C[Math.round((i * (C.length - 1)) / (n - 1))]);
+}
+
+const HALO = [[-1, 0], [1, 0], [0, -1], [0, 1]];
+
+/** A path as a bolt: a 1 px `core` line inside a 1 px `edge` halo (no halo when edge is null). */
+export function zap(p, pts, core, edge = null, a = 1) {
+ if (edge != null)
+ for (const [dx, dy] of HALO)
+ for (let i = 1; i < pts.length; i++) p.line(pts[i - 1][0] + dx, pts[i - 1][1] + dy, pts[i][0] + dx, pts[i][1] + dy, edge, a);
+ p.polyline(pts, core, a);
+}
+
+/** The first share u (0..1) of a path, cut at the right point: for bolts that grow along their length. */
+export function part(pts, u) {
+ if (u >= 1) return pts;
+ if (u <= 0) return [pts[0]];
+ const f = u * (pts.length - 1), i = Math.floor(f), k = f - i, out = pts.slice(0, i + 1);
+ if (k > 0) out.push([pts[i][0] + (pts[i + 1][0] - pts[i][0]) * k, pts[i][1] + (pts[i + 1][1] - pts[i][1]) * k]);
+ return out;
+}
+
+/**
+ * Light along a path: k at the path falling to 0 at distance r. One distance field for the whole path, so
+ * joints don't bead the way overlapping glowLines do. `every` thins the path first (light is soft anyway).
+ */
+export function glowPath(p, pts, r, c, k, every = 3) {
+ if (k <= 0.004 || pts.length < 2) return;
+ const q = [];
+ for (let i = 0; i < pts.length; i += every) q.push(pts[i]);
+ if (q[q.length - 1] !== pts[pts.length - 1]) q.push(pts[pts.length - 1]);
+ let x0 = Infinity, y0 = Infinity, x1 = -Infinity, y1 = -Infinity;
+ for (const [x, y] of q) { if (x < x0) x0 = x; if (x > x1) x1 = x; if (y < y0) y0 = y; if (y > y1) y1 = y; }
+ const R2 = r * r, n = q.length;
+ p.shade(x0 - r, y0 - r, x1 + r, y1 + r, (x, y, o) => {
+ let best = R2;
+ for (let i = 1; i < n; i++) {
+ const ax = q[i - 1][0], ay = q[i - 1][1], dx = q[i][0] - ax, dy = q[i][1] - ay;
+ const u = clamp(((x - ax) * dx + (y - ay) * dy) / (dx * dx + dy * dy || 1e-9));
+ const ex = ax + dx * u - x, ey = ay + dy * u - y, d2 = ex * ex + ey * ey;
+ if (d2 < best) best = d2;
+ }
+ if (best >= R2) return;
+ const f = 1 - Math.sqrt(best) / r;
+ o.l = c;
+ o.k = f * f * k;
+ });
+}
+
+/** A short crackle between two points: a bolt with few, sharp kinks (for arcs a few pixels to ~30 px long). */
+export function crackle(r, x0, y0, x1, y1, jag = 0.3) {
+ const L = Math.hypot(x1 - x0, y1 - y0);
+ return bolt(r, x0, y0, x1, y1, { jag, depth: L < 8 ? 1 : L < 16 ? 2 : L < 36 ? 3 : 4 });
+}
+
+/**
+ * Branches off a bolt path that alternate sides and leave from the stretch between shares `from` and `to`
+ * of it, each pointing along the path's direction turned out by up to `spread` radians. Returns paths.
+ */
+export function branches(r, path, { count = 4, len = 20, jag = 0.3, spread = 0.8, from = 0.1, to = 0.8, side = 1 } = {}) {
+ const out = [], n = path.length;
+ if (n < 3) return out;
+ for (let k = 0; k < count; k++) {
+ const u = from + (to - from) * ((k + r.next()) / count);
+ const i = Math.max(1, Math.min(n - 2, Math.round(u * (n - 1))));
+ const [x, y] = path[i], [px, py] = path[Math.max(0, i - 2)];
+ const s = (k % 2 ? -1 : 1) * side;
+ const a = Math.atan2(y - py, x - px) + s * spread * (0.45 + 0.55 * r.next());
+ const l = len * (0.45 + 0.55 * r.next());
+ out.push(bolt(r, x, y, x + Math.cos(a) * l, y + Math.sin(a) * l, { jag, depth: l < 10 ? 2 : 3 }));
+ }
+ return out;
+}
+
+/** Each segment of a path drawn only while u < its own random cut: a bolt that crumbles away as u goes 0 -> 1. */
+export function crumble(p, pts, u, seed, c, a = 1) {
+ for (let i = 1; i < pts.length; i++) {
+ if (rand(seed, i) * 0.85 + 0.15 * (i / pts.length) < u) continue;
+ p.line(pts[i - 1][0], pts[i - 1][1], pts[i][0], pts[i][1], c, a);
+ }
+}
+
+/**
+ * A zigzag from (x0, y0) to (x1, y1): kinks every `step` px or so, each pushed sideways up to `amp` px,
+ * mostly alternating sides. Reads as pixel-art lightning at any length (midpoint displacement bows long arcs).
+ */
+export function jagged(r, x0, y0, x1, y1, { step = 5, amp = 3 } = {}) {
+ const dx = x1 - x0, dy = y1 - y0, L = Math.hypot(dx, dy) || 1, nx = -dy / L, ny = dx / L;
+ const n = Math.max(1, Math.round(L / step)), pts = [[x0, y0]];
+ let s = r.sign();
+ for (let i = 1; i < n; i++) {
+ const u = (i + r.range(-0.3, 0.3)) / n, off = s * amp * r.range(0.3, 1);
+ pts.push([x0 + dx * u + nx * off, y0 + dy * u + ny * off]);
+ if (r.next() < 0.75) s = -s;
+ }
+ pts.push([x1, y1]);
+ return pts;
+}
+
+/**
+ * A ring drawn as n arcs with gaps (gap 0: a whole ring, toward 1: short dashes), turned by `turn` radians;
+ * each arc's length and radius wobble a little by seed. Shock fronts break up this way instead of dithering.
+ */
+export function brokenRing(p, x, y, R, w, { n = 6, gap = 0, turn = 0, seed = 0, c, wobble = 1 } = {}) {
+ for (let j = 0; j < n; j++) {
+ const a0 = turn + ((j + 0.4 * rand(seed, j)) / n) * Math.PI * 2;
+ const a1 = a0 + ((Math.PI * 2) / n) * (1 - Math.min(0.95, gap * (0.6 + 0.8 * rand(seed, j, 1))));
+ if (a1 > a0) p.arc(x, y, R + (rand(seed, j, 2) - 0.5) * wobble, w, a0, a1, c);
+ }
+}
+
+/** A path with its points held inside the box [x0, x1] x [y0, y1] (keeps long branches on the canvas). */
+export const fence = (pts, x0, x1, y0, y1) => pts.map(([x, y]) => [clamp(x, x0, x1), clamp(y, y0, y1)]);
diff --git a/src/fx/lightning/ball-lightning.js b/src/fx/lightning/ball-lightning.js
new file mode 100644
index 0000000..92f3e1a
--- /dev/null
+++ b/src/fx/lightning/ball-lightning.js
@@ -0,0 +1,59 @@
+import { PAL, rand, rng, TAU, WHITE } from "../../core/index.js";
+import { steps, glowPath, jagged } from "./_lib.js";
+
+export const meta = {
+ name: "Ball lightning",
+ desc: "A fizzing ball of charge drifts on a wandering path, trailing a fading wake, its shell spitting little arcs and now and then a long lash.",
+ tags: ["lightning", "electric", "orb", "wisp", "ambient", "loop"],
+ size: [64, 48],
+ origin: [32, 24],
+ duration: 2.4,
+ loop: true,
+ fps: 30,
+ bg: "dark",
+ options: { palette: PAL.cyber, radius: 4, seed: 15 },
+};
+
+const RATE = 15;
+// a wandering closed path: whole numbers of turns per loop, so it comes back to where it started
+const path = (ph) => [
+ 18 * Math.sin(ph * TAU + 0.4) + 4 * Math.sin(ph * TAU * 3),
+ 6 * Math.sin(ph * TAU * 2) + 3 * Math.cos(ph * TAU * 3 + 1),
+];
+
+export function draw(p, t, o) {
+ const C = steps(o.palette, 8), S = o.seed, D = meta.duration, ph = t / D, R = o.radius;
+ const beat = Math.floor(t * RATE), fresh = t * RATE - beat < 0.5;
+ const [x, y] = path(ph);
+
+ // the wake: where it has been, cooling and thinning out
+ for (let i = 9; i >= 1; i--) {
+ const [tx, ty] = path(ph - i * 0.012), k = i / 9;
+ p.circle(tx, ty, R * (1 - k * 0.75), k < 0.35 ? C[4] : k < 0.7 ? C[3] : C[2], k < 0.6 ? 1 : 0.6);
+ }
+
+ // shell arcs: short kinks jumping off the surface, new ones each beat
+ for (let i = 0; i < 4; i++) {
+ const r = rng(S, beat, i), a = r.range(0, TAU), b = a + r.range(0.6, 1.5) * r.sign();
+ const l = R + r.range(2, 5);
+ const pts = jagged(r, x + Math.cos(a) * R, y + Math.sin(a) * R, x + Math.cos(b) * l, y + Math.sin(b) * l, { step: 2.5, amp: 1.4 });
+ p.polyline(pts, fresh ? C[6] : C[5]);
+ }
+ // now and then a long lash out into the air
+ if (rand(S, beat, 7) < 0.2) {
+ const r = rng(S, beat, 8), a = r.range(0, TAU), l = r.range(12, 18);
+ const ex = Math.max(-28, Math.min(28, x + Math.cos(a) * l)), ey = Math.max(-20, Math.min(20, y + Math.sin(a) * l * 0.7));
+ const pts = jagged(r, x, y, ex, ey, { step: 3.5, amp: 2.2 });
+ p.polyline(pts, fresh ? WHITE : C[5]);
+ glowPath(p, pts, 6, C[5], 0.3, 2);
+ }
+
+ // the ball: a hot core in a shimmering shell that never sits still
+ const wob = 0.4 * (rand(S, beat, 3) - 0.5);
+ p.circle(x, y, R + 0.5 + wob, (d, a) => (d > 0.82 ? (Math.sin(a * 3 + beat) > 0 ? C[5] : C[4]) : d > 0.5 ? C[6] : WHITE));
+ p.px(x - 1, y - 1, WHITE);
+
+ const fl = 0.85 + 0.15 * rand(S, beat, 5);
+ p.glow(x, y, 22, C[4], 0.38 * fl);
+ p.glow(x, y, 7, C[6], 0.45 * fl);
+}
diff --git a/src/fx/lightning/chain-lightning.js b/src/fx/lightning/chain-lightning.js
new file mode 100644
index 0000000..1686cd4
--- /dev/null
+++ b/src/fx/lightning/chain-lightning.js
@@ -0,0 +1,81 @@
+import { PAL, burst, fly, flyV, seg, ease, clamp, rng, rand, TAU, WHITE } from "../../core/index.js";
+import { steps, zap, glowPath, part, crackle, branches, crumble, jagged } from "./_lib.js";
+
+export const meta = {
+ name: "Chain lightning",
+ desc: "A bolt leaps from the hand to a target, then on to the next and the next, each hit flashing as the arcs behind it flicker and crumble.",
+ tags: ["lightning", "electric", "spell", "chain", "directional", "one-shot"],
+ size: [112, 48],
+ origin: [8, 25],
+ duration: 0.66,
+ loop: false,
+ fps: 30,
+ bg: "dark",
+ options: { palette: ["#100c34", "#241c7c", "#3c3cd0", "#6a78ff", "#a8b8ff", "#e0e6ff", "#ffffff"], targets: 3, spacing: 30, seed: 8 },
+};
+
+const HOP = 0.09, LIFE = 0.34;
+
+export function draw(p, t, o) {
+ const C = steps(o.palette, 7), S = o.seed, n = o.targets;
+ const pts = [[0, 0]];
+ for (let i = 1; i <= n; i++) pts.push([i * o.spacing + rand(S, i, 1) * 8 - 4, (rand(S, i, 2) * 2 - 1) * 9]);
+ const fi = Math.floor(t * 20);
+
+ // the hand: a crackling spark ball that throws the first bolt
+ const hand = 1 - seg(t, 0.05, 0.22);
+ if (hand > 0) {
+ p.circle(0, 0, 1 + 2 * hand, hand > 0.6 ? WHITE : C[5]);
+ burst(3, S + fi, (r) => {
+ const a = r.range(0, TAU), l = r.range(3, 6) * hand;
+ p.polyline(crackle(r, 0, 0, Math.cos(a) * l, Math.sin(a) * l, 0.5), C[4]);
+ });
+ p.glow(0, 0, 12, C[4], 0.4 * hand);
+ }
+
+ for (let i = 0; i < n; i++) {
+ const t0 = 0.03 + i * HOP, age = t - t0;
+ if (age < 0) continue;
+ const [x0, y0] = pts[i], [x1, y1] = pts[i + 1];
+ // the arc: jumps across in a frame, white-hot for two, then flickers thinner and crumbles
+ if (age < LIFE) {
+ const q = age / LIFE, path = jagged(rng(S, i, fi), x0, y0, x1, y1, { step: 4.5, amp: 3.2 });
+ const arc = part(path, seg(age, 0, 0.034));
+ if (q < 0.25) {
+ for (const b of branches(rng(S, i, fi, 1), arc, { count: 2, len: 9, from: 0.2, to: 0.8 })) p.polyline(b, C[4]);
+ zap(p, arc, q < 0.12 ? WHITE : C[6], q < 0.12 ? C[5] : C[4]);
+ } else if (q < 0.55) zap(p, arc, C[5], fi % 3 ? null : C[3]);
+ else crumble(p, arc, (q - 0.55) / 0.45, S + i, C[4]);
+ glowPath(p, arc, 9, C[4], 0.4 * (1 - q) * (1 - q));
+ }
+ // the hit: a white flash and a ring at the target, sparks kicked out the far side
+ const h = age - 0.034;
+ if (h >= 0 && h < 0.4) {
+ if (h < 0.034) p.circle(x1, y1, 4.5, WHITE);
+ else if (h < 0.2) {
+ // a star of short spikes, re-forming each beat and shrinking
+ const k = seg(h, 0.034, 0.2);
+ burst(5, S + 60 + i * 7 + fi, (r, j) => {
+ const a = (j / 5) * TAU + r.range(-0.4, 0.4), l = r.range(5, 9) * (1 - ease.inQuad(k));
+ p.polyline(jagged(r, x1, y1, x1 + Math.cos(a) * l, y1 + Math.sin(a) * l, { step: 3, amp: 1.5 }), k < 0.4 ? C[6] : C[4]);
+ });
+ p.circle(x1, y1, 2.5 * (1 - k) + 0.5, k < 0.5 ? WHITE : C[6]);
+ }
+ p.glow(x1, y1, 16, C[4], 0.5 * (1 - seg(h, 0, 0.3)));
+ burst(6, S + 40 + i, (r) => {
+ const life = r.range(0.18, 0.34);
+ if (h > life) return;
+ const a = r.range(-1.4, 1.4), sp = r.range(35, 75), vx0 = Math.cos(a) * sp, vy0 = Math.sin(a) * sp - 20;
+ const [x, y] = fly(x1, y1, vx0, vy0, h, 160, 4), [vx, vy] = flyV(vx0, vy0, h, 160, 4), q = h / life;
+ if (x > 101 || Math.abs(y) > 21) return;
+ p.line(x, y, x - vx * 0.03, y - vy * 0.03, q < 0.4 ? WHITE : q < 0.7 ? C[5] : C[3]);
+ p.light(x, y, C[4], 0.4 * (1 - q));
+ });
+ // a little leftover charge crawling around the struck point
+ if (h > 0.05 && h < 0.3) {
+ const a = rand(S, i, fi) * TAU, rr = 4;
+ p.polyline(crackle(rng(S, i, fi, 2), x1 + Math.cos(a) * rr, y1 + Math.sin(a) * rr, x1 + Math.cos(a + 2.2) * rr, y1 + Math.sin(a + 2.2) * rr, 0.5), C[4], clamp((0.3 - h) / 0.1));
+ }
+ }
+ }
+}
diff --git a/src/fx/lightning/charge-up.js b/src/fx/lightning/charge-up.js
new file mode 100644
index 0000000..de6deed
--- /dev/null
+++ b/src/fx/lightning/charge-up.js
@@ -0,0 +1,86 @@
+import { PAL, burst, fly, flyV, seg, ease, rng, rand, TAU, WHITE } from "../../core/index.js";
+import { steps, zap, jagged, brokenRing } from "./_lib.js";
+
+export const meta = {
+ name: "Charge up",
+ desc: "Sparks and arcs are drawn in to a point, the core swelling and crackling, ripples closing in faster and faster; a white flash, then it all bursts out as bolts.",
+ tags: ["lightning", "electric", "charge", "spell", "buildup", "release", "one-shot"],
+ size: [80, 80],
+ origin: [40, 40],
+ duration: 1.25,
+ loop: false,
+ fps: 30,
+ bg: "dark",
+ options: { palette: PAL.electric, radius: 30, seed: 20 },
+};
+
+const GATHER = 0.75, FLASH = 0.8;
+
+export function draw(p, t, o) {
+ const C = steps(o.palette, 7), S = o.seed, R = o.radius, beat = Math.floor(t * 20);
+
+ if (t < FLASH) {
+ const g = seg(t, 0, GATHER), core = 1 + 4 * ease.inQuad(g);
+ // ripples closing in, quicker as the charge builds, broken arcs turning as they shrink
+ [0, 0.32, 0.56, 0.72].forEach((r0, j) => {
+ const k = seg(t, r0 * GATHER, r0 * GATHER + 0.28 * (1 - r0 * 0.6));
+ if (k > 0 && k < 1)
+ brokenRing(p, 0, 0, R * (1 - ease.inQuad(k)) + core, 1, { n: 5, gap: 0.45 - 0.3 * k, turn: j + k * 2, seed: S + j, c: k < 0.6 ? C[3] : C[4] });
+ });
+ // sparks sucked in from all round
+ burst(30, S, (r) => {
+ const born = r.range(0, GATHER - 0.15), life = r.range(0.22, 0.34), age = t - born;
+ if (age < 0 || age > life) return;
+ const a = r.range(0, TAU) + age * 2, k = ease.inQuad(age / life), d = (R + r.range(-2, 3)) * (1 - k) + core;
+ const x = Math.cos(a) * d, y = Math.sin(a) * d;
+ p.line(x, y, x + Math.cos(a) * (1 + 3 * k), y + Math.sin(a) * (1 + 3 * k), k > 0.6 ? WHITE : C[5]);
+ });
+ // arcs leaping in from the edge, more of them as it builds
+ const n = Math.floor(1 + 3 * g);
+ for (let i = 0; i < n; i++) {
+ const r = rng(S, beat, i);
+ if (!r.chance(0.35 + 0.5 * g)) continue;
+ const a = r.range(0, TAU), d = R * r.range(0.6, 1);
+ const pts = jagged(r, Math.cos(a) * d, Math.sin(a) * d, 0, 0, { step: 3.5, amp: 2 });
+ p.polyline(pts, g > 0.6 ? C[6] : C[5]);
+ }
+ // the core: swelling, flickering
+ const jit = rand(S, beat, 4) * 0.8;
+ p.circle(0, 0, core + jit, (d) => (d < 0.55 ? WHITE : d < 0.85 ? C[6] : C[5]));
+ p.glow(0, 0, 12 + 22 * g, C[4], 0.15 + 0.35 * g);
+ p.glow(0, 0, 6 + 4 * g, C[6], 0.3 * g);
+ }
+
+ // the flash
+ if (t >= GATHER && t < FLASH + 0.034) {
+ p.circle(0, 0, 9, WHITE);
+ p.glow(0, 0, 44, C[5], 0.8);
+ }
+
+ // the release: bolts burst outward and hold a beat, then flicker and thin
+ const rel = seg(t, FLASH, 1.15);
+ if (t >= FLASH && rel < 1) {
+ const hb = Math.floor((t - FLASH) * 20);
+ burst(7, S + 50 + hb, (r, i) => {
+ const a = (i / 7) * TAU + r.range(-0.3, 0.3), l = (R + r.range(-4, 6)) * (0.6 + 0.4 * ease.outCubic(seg(t, FLASH, FLASH + 0.08)));
+ if (rel > 0.4 && r.chance(rel)) return;
+ const pts = jagged(r, 0, 0, Math.cos(a) * l, Math.sin(a) * l, { step: 4.5, amp: 2.6 });
+ zap(p, pts, rel < 0.25 ? WHITE : C[5], rel < 0.15 ? C[4] : null);
+ });
+ const k = ease.outCubic(seg(t, FLASH, FLASH + 0.3));
+ if (k < 1) brokenRing(p, 0, 0, 8 + (R + 2) * k, Math.max(1, Math.round(3 * (1 - k))), { n: 7, gap: seg(k, 0.4, 1), seed: S + 9, c: k < 0.4 ? WHITE : C[5] });
+ p.circle(0, 0, 5 * (1 - rel), rel < 0.3 ? WHITE : C[5]);
+ p.glow(0, 0, 40, C[4], 0.45 * (1 - rel) * (1 - rel));
+ }
+
+ // sparks flung out with the release
+ burst(16, S + 9, (r) => {
+ const age = t - FLASH - r.range(0, 0.03), life = r.range(0.25, 0.42);
+ if (age < 0 || age > life) return;
+ const a = r.range(0, TAU), sp = r.range(70, 140), vx0 = Math.cos(a) * sp, vy0 = Math.sin(a) * sp;
+ const [x, y] = fly(0, 0, vx0, vy0, age, 90, 3), [vx, vy] = flyV(vx0, vy0, age, 90, 3), q = age / life;
+ if (Math.abs(x) > 36 || Math.abs(y) > 36) return;
+ p.line(x, y, x - vx * 0.03, y - vy * 0.03, q < 0.35 ? WHITE : q < 0.7 ? C[5] : C[3]);
+ p.light(x, y, C[4], 0.4 * (1 - q));
+ });
+}
diff --git a/src/fx/lightning/electric-field.js b/src/fx/lightning/electric-field.js
new file mode 100644
index 0000000..e03aac8
--- /dev/null
+++ b/src/fx/lightning/electric-field.js
@@ -0,0 +1,75 @@
+import { cycle, rand, rng, clamp, TAU, WHITE } from "../../core/index.js";
+import { steps, glowPath, jagged } from "./_lib.js";
+
+export const meta = {
+ name: "Electric field",
+ desc: "A live patch of floor: a humming tinted ellipse where little arcs skitter along the ground, static hairs flicker up and sparks hop.",
+ tags: ["lightning", "electric", "trap", "hazard", "zone", "ground", "loop"],
+ size: [72, 32],
+ origin: [36, 26],
+ duration: 1.2,
+ loop: true,
+ fps: 30,
+ bg: "ground",
+ options: { palette: ["#140a30", "#2e1a78", "#5a38c8", "#8a70ff", "#bcb0ff", "#e8e2ff", "#ffffff"], width: 28, seed: 17 },
+};
+
+const RATE = 15;
+
+export function draw(p, t, o) {
+ const C = steps(o.palette, 7), S = o.seed, RX = o.width, RY = RX * 0.17, beat = Math.floor(t * RATE);
+ const fresh = t * RATE - beat < 0.5, ph = t / meta.duration;
+ // a point on the floor patch, from two numbers in 0..1
+ const at = (u, v) => {
+ const a = u * TAU, d = Math.sqrt(v) * 0.92;
+ return [Math.cos(a) * RX * d, Math.sin(a) * RY * d];
+ };
+
+ // the live floor: the patch lit from within (light only, so the floor shows through), a hard rim
+ // with a pulse chasing round it
+ p.shade(-RX, -RY, RX, RY, (x, y, out) => {
+ const d = Math.hypot(x / RX, y / RY);
+ if (d > 1) return;
+ out.l = C[3];
+ out.k = 0.22 + 0.2 * d * d;
+ });
+ const n = Math.round(RX * 4.4);
+ for (let i = 0; i < n; i++) {
+ const a = (i / n) * TAU, x = Math.cos(a) * RX, y = Math.sin(a) * RY;
+ const pulse = Math.sin(a * 3 - ph * TAU * 2);
+ p.px(x, y, pulse > 0.75 ? C[5] : pulse > 0.2 ? C[4] : C[3]);
+ }
+
+ // static hairs: short upright flickers across the patch
+ for (let i = 0; i < 9; i++) {
+ if (rand(S, beat, i, 1) < 0.45) continue;
+ const [x, y] = at(rand(S, i, 2), rand(S, i, 3)), h = 2 + Math.floor(rand(S, beat, i, 4) * 4);
+ p.line(x, y, x, y - h, C[3]);
+ p.px(x, y - h, C[5]);
+ }
+
+ // skittering arcs: flat zigzags hopping between points on the floor, new ones every beat
+ for (let i = 0; i < 3; i++) {
+ const r = rng(S, beat, i), [x0, y0] = at(r.next(), r.next());
+ const a = r.range(-0.35, 0.35) + (r.chance(0.5) ? Math.PI : 0), l = r.range(7, 15);
+ const x1 = clamp(x0 + Math.cos(a) * l, -RX * 0.9, RX * 0.9), y1 = clamp(y0 + Math.sin(a) * l * 0.3, -RY * 0.8, RY * 0.8);
+ const pts = jagged(r, x0, y0, x1, y1, { step: 2.5, amp: 1.6 }).map(([x, y], j, all) => [x, y - 1.5 * Math.sin((Math.PI * j) / (all.length - 1))]);
+ p.polyline(pts, fresh ? WHITE : C[5]);
+ if (fresh) p.px(x0, y0, C[6]), p.px(x1, y1, C[6]);
+ glowPath(p, pts, 6, C[4], fresh ? 0.3 : 0.15, 2);
+ }
+
+ // sparks hop up off the floor and drop back
+ cycle(t, meta.duration, 8, S + 3, (r) => r.range(0.2, 0.32), (age, life, r) => {
+ const [x0, y0] = at(r.next(), r.next()), vy = -r.range(45, 75), vx = r.range(-15, 15);
+ const x = x0 + vx * age, y = y0 + vy * age + 300 * age * age;
+ if (y > y0) return;
+ p.px(x, y, age / life < 0.5 ? WHITE : C[4]);
+ p.light(x, y, C[4], 0.4);
+ });
+
+ // the hum: light pooled on the patch, flickering with the beats
+ const fl = 0.8 + 0.2 * rand(S, beat, 77);
+ p.glow(0, -2, RX * 1.2, C[3], 0.3 * fl);
+ p.glow(0, 0, RX * 0.5, C[4], 0.2 * fl);
+}
diff --git a/src/fx/lightning/electrified.js b/src/fx/lightning/electrified.js
new file mode 100644
index 0000000..852e8d1
--- /dev/null
+++ b/src/fx/lightning/electrified.js
@@ -0,0 +1,74 @@
+import { PAL, cycle, clamp, rng, rand, TAU, WHITE } from "../../core/index.js";
+import { steps, glowPath, jagged } from "./_lib.js";
+
+export const meta = {
+ name: "Electrified",
+ desc: "Static crawls over the body: short arcs jump between points on the silhouette, sparks spit off, and every so often the whole outline flares.",
+ tags: ["lightning", "electric", "status", "shock", "debuff", "loop"],
+ size: [40, 44],
+ origin: [20, 40],
+ duration: 1.2,
+ loop: true,
+ fps: 30,
+ bg: "ground",
+ actor: true,
+ options: { palette: PAL.volt, arcs: 3, seed: 13 },
+};
+
+const RATE = 15;
+const rims = new WeakMap();
+
+// points just outside the silhouette, with the outward direction at each
+function rim(a) {
+ let list = rims.get(a.mask);
+ if (list) return list;
+ const m = a.mask, inside = (x, y) => x >= 0 && y >= 0 && x < m.w && y < m.h && m.data[y * m.w + x];
+ list = [];
+ for (let y = -1; y <= m.h; y++)
+ for (let x = -1; x <= m.w; x++) {
+ if (inside(x, y)) continue;
+ const nx = inside(x - 1, y) - inside(x + 1, y), ny = inside(x, y - 1) - inside(x, y + 1);
+ if (nx || ny || inside(x - 1, y) || inside(x, y - 1)) list.push([a.x + x, a.y + y, nx, ny]);
+ }
+ rims.set(a.mask, list);
+ return list;
+}
+
+export function draw(p, t, o) {
+ const C = steps(o.palette, 7), S = o.seed, a = o.actor, R = rim(a), beat = Math.floor(t * RATE);
+ const fresh = t * RATE - beat < 0.5;
+ // the flare: twice a cycle the whole body lights up for a frame, then just its outline for one more
+ const flare = beat % 9 === 4 ? (fresh ? 2 : 1) : 0;
+ if (flare === 2) p.mask(a.mask, a.x, a.y, C[5]);
+ if (flare) p.outline(a.mask, a.x, a.y, flare === 2 ? WHITE : C[5]);
+ // arcs: each beat a few short zigzags hop between two points on the rim, bowing out from the body
+ for (let i = 0; i < o.arcs; i++) {
+ const r = rng(S, beat, i), A = R[Math.floor(r.next() * R.length)];
+ let best = null;
+ for (let k = 0; k < 6; k++) {
+ const B = R[Math.floor(r.next() * R.length)], d = Math.hypot(B[0] - A[0], B[1] - A[1]);
+ if (d >= 5 && d <= 12) { best = B; break; }
+ }
+ if (!best) continue;
+ const pts = jagged(r, A[0], A[1], best[0], best[1], { step: 2.5, amp: 1.6 });
+ const nx = (A[2] + best[2]) * 0.6, ny = (A[3] + best[3]) * 0.6;
+ const bowed = pts.map(([x, y], j) => {
+ const s = Math.sin((Math.PI * j) / (pts.length - 1));
+ return [x + nx * s * 2, y + ny * s * 2];
+ });
+ p.polyline(bowed, fresh ? WHITE : C[5]);
+ if (fresh) for (const [x, y] of [bowed[0], bowed[bowed.length - 1]]) p.px(x, y, C[6]);
+ glowPath(p, bowed, 6, C[4], fresh ? 0.35 : 0.2, 2);
+ }
+ // sparks spit off the rim and fall
+ cycle(t, meta.duration, 10, S + 5, (r) => r.range(0.12, 0.22), (age, life, r) => {
+ const P = R[Math.floor(r.next() * R.length)], k = age / life;
+ const vx = (P[2] || r.range(-1, 1)) * r.range(30, 60), vy = (P[3] || 0) * 30 - r.range(20, 50);
+ const x = P[0] + vx * age, y = P[1] + vy * age + 200 * age * age;
+ if (y > 0) return;
+ p.line(x, y, x - vx * 0.03, y - vy * 0.03, k < 0.5 ? WHITE : C[4]);
+ });
+ // a jittery glow that never settles
+ const j = 0.75 + 0.25 * rand(S, beat, 9);
+ p.glow(a.chest[0], a.chest[1] - 1, 20, C[4], (flare ? 0.32 : 0.18) * j);
+}
diff --git a/src/fx/lightning/lightning-dash.js b/src/fx/lightning/lightning-dash.js
new file mode 100644
index 0000000..fb6f95a
--- /dev/null
+++ b/src/fx/lightning/lightning-dash.js
@@ -0,0 +1,71 @@
+import { PAL, burst, fly, flyV, seg, ease, rng, rand, TAU, WHITE } from "../../core/index.js";
+import { steps, zap, glowPath, part, jagged, branches, crumble } from "./_lib.js";
+
+export const meta = {
+ name: "Lightning dash",
+ desc: "A dash to the right on a streak of lightning: a white-hot head tears ahead, the bolt behind it crackles and crumbles from the tail, sparks burst where it lands.",
+ tags: ["lightning", "electric", "dash", "movement", "directional", "one-shot"],
+ size: [112, 40],
+ origin: [12, 33],
+ duration: 0.52,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ options: { palette: PAL.volt, length: 76, seed: 19 },
+};
+
+const Y = -9, RUN = 0.1;
+
+export function draw(p, t, o) {
+ const C = steps(o.palette, 7), S = o.seed, L = o.length, beat = Math.floor(t * 20);
+ const run = ease.outQuart(seg(t, 0, RUN)), hx = L * run;
+
+ // the trail: a bolt from the start to the head, re-forming every beat; it crumbles from the tail
+ const path = jagged(rng(S, beat), 0, Y, L, Y, { step: 5, amp: 3 });
+ const trail = part(path, run);
+ const decay = seg(t, 0.14, 0.42);
+ if (decay < 1) {
+ if (t < 0.2) {
+ for (const b of branches(rng(S, beat, 1), trail, { count: 3, len: 10, from: 0.1, to: 0.8 })) p.polyline(b, t < 0.1 ? C[5] : C[4]);
+ zap(p, trail, t < 0.1 ? WHITE : C[6], t < 0.14 ? C[4] : null);
+ } else crumble(p, trail, decay, S + 3, decay < 0.4 ? C[5] : C[4]);
+ glowPath(p, trail, 8, C[4], 0.4 * (1 - decay));
+ }
+
+ // where it left from: a flash on the floor that shrinks away, a couple of backward skids
+ const kick = seg(t, 0, 0.16);
+ if (kick < 1) {
+ const w = Math.round(7 * (1 - kick));
+ p.rect(-w, 0, w * 2 + 1, 1, kick < 0.4 ? WHITE : C[5]);
+ p.rect(-w - 3, -1, 2, 1, C[4]);
+ p.light(0, -1, C[4], 0.6 * (1 - kick));
+ }
+
+ // the head: a white-hot spark racing ahead, flaring as it lands
+ if (t < RUN + 0.08) {
+ const land = seg(t, RUN, RUN + 0.08), r = land > 0 ? 6 * (1 - land) : 3;
+ p.circle(hx, Y, r, land > 0.5 ? C[6] : WHITE);
+ if (land === 0) p.line(hx - 10, Y, hx, Y, C[6]);
+ p.glow(hx, Y, 18, C[4], 0.5);
+ }
+
+ // the landing: sparks thrown forward and up, a few crackles round the arrival point
+ burst(10, S + 5, (r) => {
+ const age = t - RUN - r.range(0, 0.04), life = r.range(0.2, 0.36);
+ if (age < 0 || age > life) return;
+ const a = r.range(-2.6, 0.6), sp = r.range(45, 90), vx0 = Math.cos(a) * sp + 12, vy0 = Math.sin(a) * sp;
+ const [x, y] = fly(L, Y, vx0, vy0, age, 260, 2.5), [vx, vy] = flyV(vx0, vy0, age, 260, 2.5), q = age / life;
+ if (y > 0) return;
+ p.line(x, y, x - vx * 0.03, y - vy * 0.03, q < 0.35 ? WHITE : q < 0.7 ? C[5] : C[3]);
+ });
+ if (t > RUN && t < 0.4 && beat % 2 === 0) {
+ const r = rng(S, beat, 9), a = r.range(0, TAU), l = r.range(4, 8);
+ p.polyline(jagged(r, L, Y, L + Math.cos(a) * l, Y + Math.sin(a) * l, { step: 2.5, amp: 1.4 }), C[5]);
+ }
+ // little arcs dropping from the trail to the floor as it passes
+ burst(3, S + 7, (r, i) => {
+ const x = L * r.range(0.2, 0.85), born = (x / L) * RUN * 0.6, age = t - born;
+ if (age < 0 || age > 0.1 || rand(S, i, beat) < 0.3) return;
+ p.polyline(jagged(r, x, Y + 2, x + r.range(-4, 4), 0, { step: 2.5, amp: 1.5 }), C[4]);
+ });
+}
diff --git a/src/fx/lightning/lightning-strike.js b/src/fx/lightning/lightning-strike.js
new file mode 100644
index 0000000..f3dd6cf
--- /dev/null
+++ b/src/fx/lightning/lightning-strike.js
@@ -0,0 +1,126 @@
+import { PAL, ramp, at, burst, cycle, fly, flyV, seg, ease, clamp, rng, rand, bolt, TAU, WHITE } from "../../core/index.js";
+import { steps, zap, glowPath, part, crackle, branches, crumble, fence } from "./_lib.js";
+
+export const meta = {
+ name: "Lightning strike",
+ desc: "A bolt cracks down from the sky: a faint leader, a white return stroke with branches, a re-strike, sparks skipping off a smouldering scorch.",
+ tags: ["lightning", "electric", "storm", "impact", "ground", "one-shot"],
+ size: [80, 120],
+ origin: [40, 110],
+ duration: 1,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ options: { palette: PAL.electric, height: 104, seed: 7 },
+};
+
+const CHAR = ramp(["#0c090c", "#191215", "#2a1d1c"]);
+const EMBER = ramp(["#5a1a10", "#a83a18", "#e8782a", "#ffc870"]);
+const SMOKE = ramp(["#2a2734", "#3b3747", "#4d485a"]);
+
+// stroke brightness over time: leader, hero return stroke, a dark beat, the re-strike, then decay
+function stroke(t) {
+ if (t < 0.066) return 0;
+ if (t < 0.1) return 1;
+ if (t < 0.133) return 0.8;
+ if (t < 0.166) return 0.3;
+ if (t < 0.233) return 0.9;
+ return 0.5;
+}
+
+export function draw(p, t, o) {
+ const C = steps(o.palette, 7), S = o.seed, H = o.height;
+ const main = bolt(rng(S, 1), rand(S, 2) * 12 - 6, -H, 0, 0, { jag: 0.2, depth: 5 });
+ const I = stroke(t);
+
+ // the stepped leader: a dim, forked tip feeling its way down before the stroke
+ if (t < 0.066) {
+ const u = ease.inQuad(seg(t, 0, 0.066)) * 0.8 + 0.2, lead = part(main, u);
+ zap(p, lead, C[4], null, 0.85);
+ for (const f of branches(rng(S, 3), lead, { count: 3, len: 12, from: 0.3, to: 0.95 })) p.polyline(f, C[3], 0.7);
+ const [tx, ty] = lead[lead.length - 1];
+ p.px(tx, ty, WHITE);
+ glowPath(p, lead, 8, C[4], 0.25);
+ p.glow(main[0][0], -H, 44, C[3], 0.3);
+ }
+
+ // the channel: hero stroke white with a halo, the re-strike takes the same channel with new branches,
+ // then the spent channel crumbles away segment by segment
+ if (t >= 0.066 && t < 0.233) {
+ const hero = I > 0.95, bright = I > 0.75;
+ const core = hero ? WHITE : bright ? C[6] : C[4];
+ const edge = hero ? C[5] : bright ? C[4] : null;
+ const set = t < 0.166 ? 4 : 5; // a new set of branches for the re-strike
+ if (I > 0.25) {
+ const br = branches(rng(S, set), main, { count: bright ? 6 : 3, len: 30, jag: 0.3, spread: 0.85, from: 0.08, to: 0.75, side: set === 4 ? 1 : -1 });
+ br.forEach((f, i) => {
+ p.polyline(fence(f, -38, 38, -118, -2), hero ? C[5] : C[4]);
+ if (bright && i < 4) for (const g of branches(rng(S, set, i), f, { count: 1, len: 12, jag: 0.35, from: 0.3, to: 0.7 })) p.polyline(fence(g, -38, 38, -118, -2), C[3]);
+ });
+ }
+ zap(p, main, core, edge);
+ glowPath(p, main, 12, C[4], 0.45 * I * I);
+ } else if (t >= 0.233) {
+ const u = seg(t, 0.233, 0.43);
+ if (u < 1) {
+ crumble(p, main, u, S + 6, u < 0.35 ? C[5] : C[4]);
+ glowPath(p, main, 8, C[3], 0.25 * (1 - u));
+ }
+ }
+
+ // the whole sky goes white for the hero frame, then the light drops away fast
+ if (t >= 0.066) {
+ const flash = Math.max(t < 0.1 ? 1 : 0, t >= 0.166 && t < 0.2 ? 0.7 : 0, 0.45 * (1 - seg(t, 0.066, 0.45)));
+ p.glow(0, -H * 0.55, 90, C[4], 0.35 * flash);
+ p.glow(0, -2, 26, C[5], 0.5 * flash);
+ }
+
+ // impact: a white burst on the floor, crackles running out along it
+ if (t >= 0.066 && t < 0.2) {
+ const k = seg(t, 0.066, 0.2);
+ p.ellipse(0, 0, 10 - 5 * k, 3 - k, k < 0.3 ? WHITE : C[5], (d) => (d < 0.6 ? 1 : 1 - k));
+ p.circle(0, -1, 3.5 - 2 * k, WHITE);
+ }
+ if (t >= 0.066 && t < 0.36) {
+ const fi = Math.floor(t * 15), k = seg(t, 0.066, 0.36);
+ burst(4, S + 20, (r, i) => {
+ const side = i % 2 ? 1 : -1, reach = r.range(9, 22) * (1 - 0.45 * k);
+ const pts = crackle(rng(S, 21, i, fi), side * 2, -1, side * reach, r.range(-3, -1), 0.35);
+ p.polyline(pts, k < 0.4 ? C[5] : C[4]);
+ });
+ }
+
+ // scorch: a black burn on the floor, its glowing cracks cooling, smoke curling up off it
+ if (t >= 0.08) {
+ const k = seg(t, 0.08, 0.97), fade = 1 - ease.inQuad(k);
+ p.ellipse(0, 1, 13, 2.2, (d) => (d < 0.5 ? CHAR[0] : d < 0.8 ? CHAR[1] : CHAR[2]), (d) => (d > 0.8 ? 0.6 : 1) * fade);
+ const heat = 1 - seg(t, 0.1, 0.75);
+ burst(7, S + 30, (r) => {
+ const x = Math.round(r.range(-10, 10)), y = r.chance(0.5) ? 1 : 0, w = r.int(1, 3), hk = heat * (1.1 - Math.abs(x) / 14);
+ if (hk <= 0.05) return;
+ p.rect(x, y, w, 1, at(EMBER, hk));
+ });
+ p.ellipse(0, 0, 3.5 * heat + 1, 1, EMBER[3], heat > 0.35 ? 1 : 0);
+ p.glow(0, 0, 16, EMBER[2], 0.35 * heat * heat);
+ burst(4, S + 31, (r, i) => {
+ const age = t - 0.16 - i * 0.07 - r.range(0, 0.04), life = r.range(0.45, 0.6);
+ if (age < 0 || age > life) return;
+ const q = age / life, x = r.range(-7, 7) + Math.sin(age * 6 + r.next() * TAU) * 1.5, y = -1.5 - age * r.range(16, 24);
+ p.circle(x, y, 1.2 + q * 1.8, at(SMOKE, 1 - q * 0.9), 1 - seg(q, 0.6, 1));
+ });
+ }
+
+ // sparks: thrown up off the strike, falling, skipping once off the floor, cooling
+ burst(13, S + 9, (r) => {
+ const born = 0.07 + r.range(0, 0.05), age = t - born, life = r.range(0.3, 0.55);
+ if (age < 0 || age > life) return;
+ const a = -Math.PI / 2 + r.range(-1.1, 1.1), sp = r.range(50, 100);
+ const vx0 = Math.cos(a) * sp, vy0 = Math.sin(a) * sp;
+ let [x, y] = fly(0, -2, vx0, vy0, age, 320, 1.8);
+ let [vx, vy] = flyV(vx0, vy0, age, 320, 1.8);
+ if (y > 0) (y = -y * 0.3), (vy = -vy * 0.3);
+ const q = age / life;
+ p.line(x, y, x - vx * 0.035, y - vy * 0.035, q < 0.3 ? WHITE : q < 0.65 ? C[5] : C[3]);
+ p.light(x, y, C[4], 0.5 * (1 - q));
+ });
+}
diff --git a/src/fx/lightning/plasma-ball.js b/src/fx/lightning/plasma-ball.js
new file mode 100644
index 0000000..599df8e
--- /dev/null
+++ b/src/fx/lightning/plasma-ball.js
@@ -0,0 +1,78 @@
+import { ramp, rand, rng, loopNoise, TAU, WHITE } from "../../core/index.js";
+import { steps, glowPath } from "./_lib.js";
+
+export const meta = {
+ name: "Plasma ball",
+ desc: "A glass globe on a stand: pink-violet tendrils wander from the hot core out to the glass, their feet flaring where they touch it.",
+ tags: ["lightning", "electric", "plasma", "prop", "ambient", "loop"],
+ size: [48, 60],
+ origin: [24, 57],
+ duration: 2,
+ loop: true,
+ fps: 30,
+ bg: "dark",
+ options: {
+ palette: ["#12061e", "#2a0b46", "#521880", "#8a2cb8", "#c84ae0", "#f08af0", "#ffd0fa", "#ffffff"],
+ radius: 17, tendrils: 6, seed: 9,
+ },
+};
+
+const BASE = ramp(["#0f0d16", "#1d1a27", "#2f2b3c", "#454057", "#625c78"]);
+
+function tendril(t, ph, i, n, R, S) {
+ const g = rng(S, i);
+ const th = (i / n) * TAU + g.range(-0.35, 0.35) + 0.8 * loopNoise(ph, 0.8, S + i * 7);
+ const A = g.range(1.4, 2.6), k1 = g.range(6, 10), w1 = g.pick([1, 2]) * g.sign(), w2 = g.pick([2, 3]) * g.sign(), off = g.range(0, TAU);
+ const dx = Math.cos(th), dy = Math.sin(th), pts = [];
+ for (let j = 0; j <= 16; j++) {
+ const s = j / 16, r = 3 + s * (R - 4.5);
+ const wig = A * Math.sin(s * Math.PI) * (Math.sin(s * k1 + ph * TAU * w1 + off) + 0.5 * Math.sin(s * k1 * 1.9 - ph * TAU * w2 + off * 2));
+ pts.push([dx * r - dy * wig, dy * r + dx * wig]);
+ }
+ return { th, pts };
+}
+
+export function draw(p, t, o) {
+ const C = steps(o.palette, 8), S = o.seed, R = o.radius, n = o.tendrils, ph = t / meta.duration;
+ const cy = -13 - R + 3, fl = Math.floor(t * 15);
+
+ // the dark glass
+ p.circle(0, cy, R, (d) => (d > 0.9 ? C[2] : d > 0.78 ? C[1] : C[0]));
+
+ // tendrils: thin hot filaments, their softness all in the light buffer
+ const ts = Array.from({ length: n }, (_, i) => tendril(t, ph, i, n, R, S));
+ const shift = (pts) => pts.map(([x, y]) => [x, y + cy]);
+ for (const { pts } of ts) glowPath(p, shift(pts), 4, C[4], 0.35, 2);
+ ts.forEach(({ th, pts }, i) => {
+ const hot = rand(S, i, fl) < 0.3;
+ const sp = shift(pts);
+ p.polyline(sp.slice(0, 9), hot ? C[7] : C[6]);
+ p.polyline(sp.slice(8), hot ? C[6] : C[5]);
+ // the foot: the tendril frays into a small fan where it meets the glass
+ const [fx, fy] = sp[13];
+ for (const s of [-0.13, 0, 0.13]) {
+ const ex = Math.cos(th + s) * (R - 1.5), ey = Math.sin(th + s) * (R - 1.5) + cy;
+ p.line(fx, fy, ex, ey, C[5]);
+ p.px(ex, ey, s === 0 ? WHITE : C[6]);
+ }
+ p.glow(Math.cos(th) * (R - 2), Math.sin(th) * (R - 2) + cy, 7, C[5], 0.35);
+ });
+
+ // the core electrode
+ p.circle(0, cy, 3.6, (d) => (d < 0.45 ? WHITE : d < 0.8 ? C[6] : C[5]));
+ // glass: rim and a cold highlight top-left
+ p.ring(0, cy, R + 0.5, 1, (v, a) => (a > -2.9 && a < -1.2 ? C[5] : C[3]));
+ p.arc(0, cy, R - 2, 1.2, -2.55, -1.95, C[7]);
+ p.px(-R * 0.42, cy - R * 0.55, WHITE);
+
+ // the stand: a collar the globe sits in, a flared base
+ p.ellipse(0, -13, 7, 2, (d, a) => (Math.sin(a) < 0 ? C[3] : d > 0.6 ? BASE[3] : BASE[2]));
+ p.poly([[-6, -13], [6, -13], [11, -1], [-11, -1]], (x) => (x < -3 ? BASE[3] : x < 4 ? BASE[2] : BASE[1]));
+ p.rect(-11, -1, 22, 1, BASE[1]);
+ p.rect(-10, -9, 20, 1, BASE[4]);
+ p.px(-8, -5, BASE[4]);
+
+ const pulse = 0.85 + 0.15 * loopNoise(ph, 1.5, S + 3);
+ p.glow(0, cy, R * 2, C[4], 0.22 * pulse);
+ p.glow(0, cy, 7, C[6], 0.45 * pulse);
+}
diff --git a/src/fx/lightning/spark-arc.js b/src/fx/lightning/spark-arc.js
new file mode 100644
index 0000000..dc5f928
--- /dev/null
+++ b/src/fx/lightning/spark-arc.js
@@ -0,0 +1,76 @@
+import { ramp, burst, fly, flyV, seg, ease, clamp, lerp, rng, rand, WHITE } from "../../core/index.js";
+import { steps, zap, glowPath, jagged } from "./_lib.js";
+
+export const meta = {
+ name: "Spark arc",
+ desc: "A climbing arc between two rods: it snaps on at the narrow gap, rises as it stretches and bows, then tears apart at the top in a spray of sparks.",
+ tags: ["lightning", "electric", "arc", "machine", "prop", "loop"],
+ size: [48, 64],
+ origin: [24, 61],
+ duration: 1.2,
+ loop: true,
+ fps: 30,
+ bg: "dark",
+ options: { palette: ["#140a30", "#2e1a78", "#5a38c8", "#8a70ff", "#bcb0ff", "#e8e2ff", "#ffffff"], seed: 10 },
+};
+
+const METAL = ramp(["#15131c", "#2c2936", "#4a4656", "#77718a", "#b4afc4"]);
+const Y0 = -9, Y1 = -54, X0 = 2.5, X1 = 17, CLIMB = 0.95;
+const rodX = (y) => lerp(X0, X1, (Y0 - y) / (Y0 - Y1));
+
+// the arc at climb u: jagged between the rods, bowed upward by the hot air it rides
+function arcAt(r, u) {
+ const y = lerp(Y0 - 2, Y1 + 8, u), xr = rodX(y) - 0.5, bow = 1 + 7 * u;
+ const pts = jagged(r, -xr, y, xr, y, { step: 4, amp: 1.2 + 1.6 * u });
+ return pts.map(([x, yy]) => [x, yy - bow * Math.sin(Math.PI * clamp((x + xr) / (2 * xr)))]);
+}
+
+export function draw(p, t, o) {
+ const C = steps(o.palette, 7), S = o.seed, fi = Math.floor(t * 20);
+
+ // the rods and their insulator base
+ for (const s of [-1, 1]) {
+ p.line(s * X0, Y0, s * X1, Y1, METAL[3]);
+ p.line(s * (X0 + 1), Y0, s * (X1 + 1), Y1, METAL[1]);
+ p.px(s * X1, Y1, METAL[4]);
+ }
+ p.rect(-9, -9, 18, 3, METAL[2]);
+ p.rect(-8, -6, 16, 6, METAL[1]);
+ p.rect(-9, -9, 18, 1, METAL[3]);
+ for (const x of [-6, -2, 2, 6]) p.px(x, -4, METAL[0]);
+
+ if (t < CLIMB) {
+ const u = Math.pow(t / CLIMB, 1.6), pts = arcAt(rng(S, fi), u), snap = t < 0.05;
+ // it starts fat and white-hot, and thins as it stretches
+ zap(p, pts, snap ? WHITE : u > 0.85 ? C[5] : C[6], snap ? C[5] : u < 0.4 ? C[4] : u < 0.75 || fi % 2 ? C[3] : null);
+ const [lx, ly] = pts[0], [rx, ry] = pts[pts.length - 1];
+ p.px(lx, ly, WHITE), p.px(rx, ry, WHITE);
+ glowPath(p, pts, 11, C[4], snap ? 0.7 : 0.4);
+ if (snap) p.glow(0, Y0 - 2, 18, C[5], 0.6);
+ } else {
+ // the break: the arc tears at its peak and the halves whip back to the rods
+ const k = seg(t, CLIMB, CLIMB + 0.1), pts = arcAt(rng(S, 999), 1), m = pts.length >> 1;
+ if (k < 1) {
+ const keep = Math.max(1, Math.round(m * (1 - ease.outQuad(k))));
+ p.polyline(pts.slice(0, keep + 1), k < 0.4 ? C[6] : C[4]);
+ p.polyline(pts.slice(pts.length - 1 - keep), k < 0.4 ? C[6] : C[4]);
+ if (k < 0.35) p.circle(pts[m][0], pts[m][1], 3 - 6 * k, WHITE);
+ glowPath(p, pts, 10, C[4], 0.4 * (1 - k));
+ }
+ burst(7, S + 3, (r) => {
+ const age = t - CLIMB, life = r.range(0.16, 0.24);
+ if (age > life) return;
+ const a = -Math.PI / 2 + r.sign() * r.range(0.5, 1.4), sp = r.range(45, 85), vx0 = Math.cos(a) * sp, vy0 = Math.sin(a) * sp;
+ const [x, y] = fly(pts[m][0], pts[m][1], vx0, vy0, age, 420, 1.5), [vx, vy] = flyV(vx0, vy0, age, 420, 1.5), q = age / life;
+ p.line(x, y, x - vx * 0.025, y - vy * 0.025, q < 0.35 ? WHITE : q < 0.7 ? C[5] : C[3]);
+ p.light(x, y, C[4], 0.4 * (1 - q));
+ });
+ // voltage builds again at the gap: little ticks of spark before the next arc
+ if (t > 1.07 && rand(S, fi, 5) < 0.7) {
+ const y = Y0 - 1 - rand(S, fi, 6) * 2, xr = rodX(y) - 0.5;
+ p.polyline(jagged(rng(S, fi, 7), -xr, y, xr, y, { step: 2, amp: 1 }), C[4]);
+ p.glow(0, y, 8, C[4], 0.35);
+ }
+ }
+ p.glow(0, Y0 - 2, 10, C[3], 0.2);
+}
diff --git a/src/fx/lightning/static-pops.js b/src/fx/lightning/static-pops.js
new file mode 100644
index 0000000..64eeca4
--- /dev/null
+++ b/src/fx/lightning/static-pops.js
@@ -0,0 +1,47 @@
+import { rng, rand, wrap, TAU, WHITE } from "../../core/index.js";
+import { steps, jagged } from "./_lib.js";
+
+export const meta = {
+ name: "Static pops",
+ desc: "Little static discharges snap here and there: a white tick, a tiny zigzag or a short jump between two points, a pinprick of sparks, gone in a blink.",
+ tags: ["lightning", "electric", "static", "sparkle", "ambient", "loop"],
+ size: [48, 40],
+ origin: [24, 20],
+ duration: 1.6,
+ loop: true,
+ fps: 30,
+ bg: "dark",
+ options: { palette: ["#0e1430", "#1f2f66", "#3b58a8", "#6a8ee0", "#a6c4f6", "#dfeaff", "#ffffff"], count: 16, width: 18, height: 13, seed: 18 },
+};
+
+export function draw(p, t, o) {
+ const C = steps(o.palette, 7), S = o.seed;
+ const D = meta.duration, n = o.count;
+ // pops spread evenly through the loop (a little jitter), so no stretch of it goes quiet
+ for (let i = 0; i < n; i++) {
+ const born = ((i + 0.6 * rand(S, i, 1)) / n) * D, age = wrap(t - born, D), life = 0.1 + 0.04 * rand(S, i, 2);
+ if (age >= life) continue;
+ const r = rng(S, i), k = age / life, x = Math.round(r.range(-o.width, o.width)), y = Math.round(r.range(-o.height, o.height));
+ const jump = r.chance(0.5), a = r.range(0, TAU), l = jump ? r.range(8, 14) : r.range(4, 7);
+ const ex = Math.max(-o.width - 3, Math.min(o.width + 3, x + Math.cos(a) * l)), ey = Math.max(-o.height - 3, Math.min(o.height + 3, y + Math.sin(a) * l));
+ const pts = jagged(r, x, y, ex, ey, { step: 2.2, amp: 1.2 });
+ if (k < 0.34) {
+ // the snap: a white tick with a tiny cross of light, the zigzag at full brightness
+ p.polyline(pts, WHITE);
+ p.px(x - 1, y, C[5]), p.px(x + 1, y, C[5]), p.px(x, y - 1, C[5]), p.px(x, y + 1, C[5]);
+ p.px(x, y, WHITE);
+ if (jump) p.px(ex, ey, C[6]);
+ p.glow(x, y, 9, C[4], 0.45);
+ p.glow((x + ex) / 2, (y + ey) / 2, 5, C[5], 0.3);
+ } else {
+ // the after-spit: the zigzag cools and a few pinpricks fly off and wink out
+ if (k < 0.67) p.polyline(pts, C[4]);
+ const d = 1.5 + k * 4;
+ for (let j = 0; j < 3; j++) {
+ const b = a + Math.PI + (j - 1) * 0.9 + r.range(-0.3, 0.3);
+ p.px(x + Math.cos(b) * d, y + Math.sin(b) * d, k < 0.67 ? C[5] : C[3]);
+ }
+ p.glow(x, y, 6, C[3], 0.25 * (1 - k));
+ }
+ }
+}
diff --git a/src/fx/lightning/storm-cloud.js b/src/fx/lightning/storm-cloud.js
new file mode 100644
index 0000000..878e54e
--- /dev/null
+++ b/src/fx/lightning/storm-cloud.js
@@ -0,0 +1,86 @@
+import { PAL, ramp, at, cycle, seg, clamp, rng, rand, loopNoise, tileFbm, TAU, WHITE } from "../../core/index.js";
+import { steps, zap, glowPath, jagged, branches } from "./_lib.js";
+
+export const meta = {
+ name: "Storm cloud",
+ desc: "A brooding thundercloud churning in the rain: lightning flickers inside it, lights it up from within, and once a cycle a bolt forks down out of it.",
+ tags: ["lightning", "weather", "storm", "cloud", "rain", "ambient", "loop"],
+ size: [88, 72],
+ origin: [44, 24],
+ duration: 2.4,
+ loop: true,
+ fps: 30,
+ bg: "sky",
+ options: { palette: PAL.electric, seed: 12 },
+};
+
+const STORM = ramp(["#0b0c16", "#141626", "#1e2236", "#2a2f47", "#3a405a", "#4f5670", "#6a7290"]);
+const RAIN = ramp(["#34406a", "#4a5888"]);
+// puffs of the cloud: [x, y, radius]; a flat belly, a lumpy top
+const PUFFS = [[-27, 3, 8], [-17, 4, 10], [-5, 5, 10], [8, 4, 10], [20, 4, 9], [29, 3, 7], [-20, -4, 9], [-8, -7, 11], [6, -8, 12], [18, -4, 9], [-1, -13, 8]];
+// flashes: [time, length, x, y, strength]; the big one at 1.0 throws a bolt
+const FLASHES = [[0.25, 0.16, -15, 0, 0.7], [1.0, 0.26, 8, 2, 1], [1.85, 0.13, 22, -2, 0.55]];
+const FLICK = [1, 0.35, 1, 0.8, 0.2, 0.9, 0.5, 0.3];
+
+function flashAt(t) {
+ for (const [t0, len, x, y, k] of FLASHES) {
+ if (t < t0 || t >= t0 + len) continue;
+ const i = Math.floor((t - t0) * 30), f = FLICK[i % FLICK.length] * (1 - 0.6 * seg(t, t0, t0 + len));
+ return { x, y, k: k * f, big: k === 1, age: t - t0 };
+ }
+ return null;
+}
+
+export function draw(p, t, o) {
+ const C = steps(o.palette, 7), S = o.seed, ph = t / meta.duration, F = flashAt(t);
+
+ // rain: thin slanted streaks falling out of the belly
+ cycle(t, meta.duration, 22, S + 1, (r) => r.range(0.35, 0.5), (age, life, r) => {
+ const x = r.range(-30, 30) - age * 14, y = 8 + age * r.range(80, 100);
+ if (y > 46) return;
+ p.line(x, y, x + 1, y - 3, F && F.k > 0.5 ? C[4] : RAIN[r.next() < 0.5 ? 0 : 1]);
+ });
+
+ // the bolt: forks down out of the belly on the big flash, and re-strikes once
+ if (F && F.big && F.age < 0.2) {
+ const strong = F.k > 0.6, main = jagged(rng(S, 2), F.x, 8, F.x + 9, 46, { step: 5, amp: 3.5 });
+ for (const b of branches(rng(S, 3), main, { count: 3, len: 14, from: 0.15, to: 0.7 })) p.polyline(b, strong ? C[5] : C[3]);
+ zap(p, main, strong ? WHITE : C[5], strong ? C[4] : null);
+ glowPath(p, main, 10, C[4], 0.5 * F.k);
+ }
+
+ // the cloud: lumpy, lit faintly from above, churning; a flash lights it up from inside
+ const puffs = PUFFS.map(([x, y, r], i) => [
+ x + 1.2 * loopNoise(ph, 0.7, S + i), y + 1 * loopNoise(ph, 0.7, S + i + 40), r * (1 + 0.06 * loopNoise(ph, 0.9, S + i + 80)),
+ ]);
+ p.shade(-38, -24, 38, 12, (x, y, out) => {
+ let best = 0, lit = 0;
+ for (const [px, py, pr] of puffs) {
+ const dx = x - px, dy = y - py, d2 = (dx * dx + dy * dy) / (pr * pr);
+ if (d2 >= 1) continue;
+ const v = 1 - d2;
+ if (v > best) (best = v), (lit = (-dx * 0.3 - dy) / pr);
+ }
+ if (best <= 0 || y > 9) return;
+ const n = tileFbm(x * 0.12 + ph * 6, y * 0.18, 6, 0, S, 2);
+ let v = 0.18 + lit * 0.3 + best * 0.25 + n * 0.16 - seg(y, 2, 9) * 0.25;
+ if (F) {
+ const d = Math.hypot(x - F.x, (y - F.y) * 1.4) / (F.big ? 34 : 22), f = F.k * clamp(1 - d) * (0.8 + n);
+ if (f > 0.55) return at(C.slice(3, 6), (f - 0.55) * 2.5);
+ v += f * 1.1 + (F.big ? 0.22 * F.k : 0.08 * F.k);
+ }
+ return at(STORM, v);
+ });
+
+ if (F) {
+ // veins of lightning running through the lit part of the cloud
+ if (F.k > 0.6)
+ for (let i = 0; i < 2; i++) {
+ const r = rng(S, 7, Math.floor(t * 30), i), a = r.range(0, TAU), l = r.range(7, 13);
+ const pts = jagged(r, F.x, F.y, F.x + Math.cos(a) * l, F.y + Math.sin(a) * l * 0.5, { step: 3, amp: 1.5 });
+ p.polyline(pts, i ? C[5] : WHITE);
+ }
+ p.glow(F.x, F.y, F.big ? 46 : 30, C[4], 0.4 * F.k);
+ p.glow(F.x, F.y + 2, 12, C[5], 0.3 * F.k);
+ }
+}
diff --git a/src/fx/lightning/tesla-coil.js b/src/fx/lightning/tesla-coil.js
new file mode 100644
index 0000000..d30990a
--- /dev/null
+++ b/src/fx/lightning/tesla-coil.js
@@ -0,0 +1,71 @@
+import { PAL, ramp, at, seg, clamp, rng, rand, TAU, WHITE } from "../../core/index.js";
+import { steps, zap, glowPath, jagged, branches, fence } from "./_lib.js";
+
+export const meta = {
+ name: "Tesla coil",
+ desc: "A copper-wound coil under a steel crown: branching arcs lash out from the crown every few frames, now and then grounding with a white flash.",
+ tags: ["lightning", "electric", "machine", "prop", "ground", "loop"],
+ size: [80, 88],
+ origin: [40, 84],
+ duration: 1.6,
+ loop: true,
+ fps: 30,
+ bg: "ground",
+ options: { palette: PAL.electric, arcs: 3, seed: 11 },
+};
+
+const COPPER = ramp(["#2e140c", "#5c2a14", "#91481f", "#c4733a", "#eaa76a"]);
+const STEEL = ramp(["#17161e", "#2f2d3a", "#4e4b5c", "#7b788c", "#b2afc2", "#e2e0ec"]);
+const TOP = -52, RATE = 15;
+
+export function draw(p, t, o) {
+ const C = steps(o.palette, 7), S = o.seed, beat = Math.floor(t * RATE), sub = t * RATE - beat;
+
+ // base plinth
+ p.rect(-12, -6, 24, 6, STEEL[1]);
+ p.rect(-12, -6, 24, 1, STEEL[3]);
+ p.rect(-10, -9, 20, 3, STEEL[2]);
+ p.rect(-10, -9, 20, 1, STEEL[4]);
+ // the coil: a wound copper cylinder, lit from the left
+ for (let y = TOP + 5; y < -9; y++)
+ for (let x = -5; x <= 5; x++) {
+ const lit = 1 - (x + 5) / 11, wire = y % 2 === 0 ? 0.2 : 0;
+ p.px(x, y, at(COPPER, clamp(0.25 + lit * 0.75 - wire + (x === -3 ? 0.15 : 0))));
+ }
+ // the crown: a steel torus
+ p.ellipse(0, TOP, 14, 4.5, (d, a) => {
+ const top = -Math.sin(a);
+ if (d < 0.38) return STEEL[0];
+ return at(STEEL, clamp(0.45 + top * 0.4 - Math.cos(a) * 0.15 + (d > 0.85 && top > 0.3 ? 0.3 : 0)));
+ });
+ p.line(-8, TOP - 3, -3, TOP - 4, STEEL[5]);
+
+ // arcs: each beat (two frames) new ones lash out from the crown's rim; a fresh arc is white-hot, then dims
+ const fresh = sub < 0.5;
+ let grounded = false;
+ for (let i = 0; i < o.arcs; i++) {
+ const r = rng(S, beat, i);
+ if (i > 1 && !r.chance(0.7)) continue;
+ const side = r.sign(), ra = r.range(-0.5, 0.3), sx = side * 13 * Math.cos(ra), sy = TOP + 4 * Math.sin(ra);
+ let ex, ey;
+ if (i === 0 && rand(S, beat, 50) < 0.22) {
+ // a ground strike: one long arc down to the floor
+ grounded = true;
+ ex = side * r.range(22, 33), ey = 0;
+ } else {
+ const a = (side > 0 ? 0 : Math.PI) + side * r.range(-1.25, 0.3), len = r.range(16, 30);
+ ex = clamp(sx + Math.cos(a) * len, -35, 35), ey = clamp(sy + Math.sin(a) * len, -80, -16);
+ }
+ const pts = fence(jagged(r, sx, sy, ex, ey, { step: 4.5, amp: 2.4 }), -38, 38, -82, 0);
+ for (const b of branches(r, pts, { count: grounded && i === 0 ? 3 : 2, len: 9, from: 0.35, to: 0.9 })) p.polyline(fence(b, -38, 38, -82, 0), fresh ? C[4] : C[3]);
+ zap(p, pts, fresh ? WHITE : C[5], fresh && i === 0 ? C[3] : null);
+ glowPath(p, pts, 9, C[4], fresh ? 0.4 : 0.22);
+ if (grounded && i === 0) {
+ if (fresh) p.ellipse(ex, 0, 5, 1.5, WHITE);
+ p.glow(ex, -1, 16, C[5], fresh ? 0.6 : 0.3);
+ }
+ }
+ // the crown glows with the charge; brighter on a grounding beat
+ p.glow(0, TOP, 26, C[4], grounded ? 0.4 : 0.25);
+ p.glow(0, TOP - 1, 9, C[5], 0.3);
+}
diff --git a/src/fx/lightning/thunderclap.js b/src/fx/lightning/thunderclap.js
new file mode 100644
index 0000000..60a6d97
--- /dev/null
+++ b/src/fx/lightning/thunderclap.js
@@ -0,0 +1,72 @@
+import { burst, fly, flyV, seg, ease, rand, TAU, WHITE } from "../../core/index.js";
+import { steps, zap, glowPath, jagged } from "./_lib.js";
+
+export const meta = {
+ name: "Thunderclap",
+ desc: "A crack of thunder in the air: a blinding flash, bolts bursting outward, a heavy shock ring that thins and shatters into arcs, sparks streaking off.",
+ tags: ["lightning", "electric", "thunder", "shockwave", "explosion", "one-shot"],
+ size: [96, 96],
+ origin: [48, 48],
+ duration: 0.55,
+ loop: false,
+ fps: 30,
+ bg: "dark",
+ options: { palette: ["#0e1430", "#1f2f66", "#3b58a8", "#6a8ee0", "#a6c4f6", "#dfeaff", "#ffffff"], radius: 40, seed: 16 },
+};
+
+export function draw(p, t, o) {
+ const C = steps(o.palette, 7), S = o.seed, RAD = o.radius, beat = Math.floor(t * 20);
+
+ // the flash: a white disc and bolts bursting out of it for the first beats
+ if (t < 0.12) {
+ const k = seg(t, 0, 0.12);
+ burst(5, S + beat * 13, (r, i) => {
+ const a = (i / 5) * TAU + r.range(-0.4, 0.4), l = r.range(22, 34) * (1 - 0.3 * k);
+ const pts = jagged(r, 0, 0, Math.cos(a) * l, Math.sin(a) * l, { step: 5, amp: 3 });
+ zap(p, pts, k < 0.4 ? WHITE : C[5], k < 0.4 ? C[4] : null);
+ glowPath(p, pts, 8, C[4], 0.3 * (1 - k));
+ });
+ p.circle(0, 0, 11 - 6 * k, k < 0.5 ? WHITE : C[6]);
+ }
+
+ // the shock ring: thick and white as it leaves, thinning and cooling as it slows, then breaking up into
+ // arcs
+ const ring = (t0, t1, R1, w0, main) => {
+ const k = seg(t, t0, t1);
+ if (k <= 0 || k >= 1) return 0;
+ const R = 7 + (R1 - 7) * ease.outQuart(k), w = Math.max(1, Math.round(w0 * (1 - k * 1.2)));
+ const edge = main ? (k < 0.25 ? WHITE : k < 0.5 ? C[6] : C[5]) : C[5], body = k < 0.4 ? C[5] : C[4];
+ const gap = main ? seg(k, 0.55, 1) * 0.85 : 0.35 + 0.5 * k, n = main ? 7 : 9;
+ for (let j = 0; j < n; j++) {
+ const a0 = ((j + 0.5 * rand(S, j, main)) / n) * TAU, a1 = a0 + (TAU / n) * (1 - gap * (0.6 + 0.8 * rand(S, j, 2)));
+ if (a1 > a0) p.arc(0, 0, R + (rand(S, j, 3) - 0.5) * 1.5, w, a0, a1, (u, v) => (v > 0.5 || w === 1 ? edge : body));
+ }
+ p.glowRing(0, 0, R, 6, C[4], 0.35 * (1 - k) * (main ? 1 : 0.5));
+ return R;
+ };
+ const R = ring(0.02, 0.45, RAD, 5, true);
+
+ // crackles riding the ring's edge
+ if (R > 0 && t < 0.36) {
+ burst(4, S + 40 + beat, (r) => {
+ const a = r.range(0, TAU), s = r.range(0.25, 0.45);
+ const pts = jagged(r, Math.cos(a) * R, Math.sin(a) * R, Math.cos(a + s) * (R + r.range(-2, 3)), Math.sin(a + s) * (R + r.range(-2, 3)), { step: 3, amp: 2 });
+ p.polyline(pts, beat % 2 ? C[5] : WHITE);
+ });
+ }
+
+ // sparks streaking straight out, braking hard, cooling
+ burst(18, S + 7, (r) => {
+ const born = r.range(0, 0.05), age = t - born, life = r.range(0.22, 0.4);
+ if (age < 0 || age > life) return;
+ const a = r.range(0, TAU), sp = r.range(120, 200), vx0 = Math.cos(a) * sp, vy0 = Math.sin(a) * sp;
+ const [x, y] = fly(0, 0, vx0, vy0, age, 30, 3.5), [vx, vy] = flyV(vx0, vy0, age, 30, 3.5), q = age / life;
+ p.line(x, y, x - vx * 0.04, y - vy * 0.04, q < 0.3 ? WHITE : q < 0.65 ? C[5] : C[3]);
+ p.light(x, y, C[4], 0.4 * (1 - q));
+ });
+
+ // the air lights up for an instant, then lets go
+ const L = 1 - seg(t, 0, 0.4);
+ p.glow(0, 0, 56, C[4], 0.55 * L * L * L);
+ p.glow(0, 0, 14, C[6], 0.5 * L * L);
+}
diff --git a/src/fx/lightning/zap-hit.js b/src/fx/lightning/zap-hit.js
new file mode 100644
index 0000000..2205fb5
--- /dev/null
+++ b/src/fx/lightning/zap-hit.js
@@ -0,0 +1,64 @@
+import { PAL, burst, fly, flyV, seg, ease, rng, TAU, WHITE } from "../../core/index.js";
+import { steps, zap, glowPath, jagged } from "./_lib.js";
+
+export const meta = {
+ name: "Zap hit",
+ desc: "An electric hit: a white-hot star of zigzag spikes snaps out, re-forms smaller each beat as a ring races off, then kinked sparks scatter and fizzle.",
+ tags: ["lightning", "electric", "hit", "impact", "combat", "one-shot"],
+ size: [56, 56],
+ origin: [28, 28],
+ duration: 0.5,
+ loop: false,
+ fps: 30,
+ bg: "dark",
+ options: { palette: PAL.electric, spikes: 6, seed: 14 },
+};
+
+export function draw(p, t, o) {
+ const C = steps(o.palette, 7), S = o.seed, beat = Math.floor(t * 20);
+
+ // the star: zigzag spikes out from the hit, white and haloed on the hero frames, shrinking and re-forming
+ const k = seg(t, 0, 0.26);
+ if (k < 1) {
+ const hero = t < 0.067, len = (hero ? 1 : 0.9 - 0.6 * ease.inQuad(k));
+ burst(o.spikes, S + beat * 31, (r, i) => {
+ const a = (i / o.spikes) * TAU + r.range(-0.35, 0.35) + 0.4, l = r.range(12, 19) * len;
+ const pts = jagged(r, 0, 0, Math.cos(a) * l, Math.sin(a) * l, { step: 3.5, amp: 2 });
+ if (k < 0.45) zap(p, pts, hero ? WHITE : C[6], k < 0.25 ? C[4] : null);
+ else p.polyline(pts, C[4]);
+ if (hero) glowPath(p, pts, 6, C[4], 0.3, 2);
+ });
+ p.circle(0, 0, t < 0.034 ? 6 : hero ? 4.5 : 3.5 * (1 - k) + 0.6, hero ? WHITE : k < 0.4 ? C[6] : C[5]);
+ }
+
+ // a thin ring racing out, breaking into arcs as it goes
+ const rk = seg(t, 0.03, 0.17);
+ if (rk > 0 && rk < 1) {
+ const R = 7 + 15 * ease.outCubic(rk), gap = rk * 0.9;
+ for (let j = 0; j < 5; j++) {
+ const a0 = (j / 5) * TAU + 0.3, a1 = a0 + (TAU / 5) * (1 - gap);
+ p.arc(0, 0, R, 1, a0, a1, rk < 0.4 ? WHITE : rk < 0.7 ? C[5] : C[4]);
+ }
+ }
+
+ // kinked sparks: three-pixel zigzags flung out, flickering, burning down
+ burst(9, S + 3, (r) => {
+ const born = r.range(0.02, 0.08), age = t - born, life = r.range(0.2, 0.36);
+ if (age < 0 || age > life) return;
+ const a = r.range(0, TAU), sp = r.range(70, 130), vx0 = Math.cos(a) * sp, vy0 = Math.sin(a) * sp;
+ const [x, y] = fly(0, 0, vx0, vy0, age, 60, 5), [vx, vy] = flyV(vx0, vy0, age, 60, 5), q = age / life;
+ if (q > 0.6 && (beat + r.int(0, 1)) % 2) return;
+ const s = Math.hypot(vx, vy) || 1, ux = vx / s, uy = vy / s, L = 2 + 3 * (1 - q);
+ p.polyline([[x, y], [x - ux * L * 0.5 - uy * 1.5, y - uy * L * 0.5 + ux * 1.5], [x - ux * L, y - uy * L]], q < 0.35 ? WHITE : q < 0.7 ? C[5] : C[3]);
+ p.light(x, y, C[4], 0.4 * (1 - q));
+ });
+
+ // a few after-crackles twitching around the spot
+ if (t > 0.18 && t < 0.42 && beat % 2 === 0) {
+ const r = rng(S, beat, 9), a = r.range(0, TAU), l = r.range(5, 9);
+ p.polyline(jagged(r, 0, 0, Math.cos(a) * l, Math.sin(a) * l, { step: 2.5, amp: 1.5 }), C[4]);
+ }
+ const L = 1 - seg(t, 0, 0.3);
+ p.glow(0, 0, 30, C[4], 0.55 * L * L);
+ p.glow(0, 0, 8, C[5], 0.5 * L);
+}
diff --git a/src/fx/melee/_lib.js b/src/fx/melee/_lib.js
new file mode 100644
index 0000000..39d6e24
--- /dev/null
+++ b/src/fx/melee/_lib.js
@@ -0,0 +1,94 @@
+// Shared bits for the melee category: the crescent smear of a swing, the lens of a straight cut, glints.
+// Files starting with _ are helpers, not effects.
+
+import { at, clamp, smooth, noise2, WHITE } from "../../core/index.js";
+
+/**
+ * A crescent smear swung around a pivot (cx, cy) at radius r, from angle `from` to angle `to` (either
+ * direction; y is down so a growing angle turns clockwise). `lead` and `tail` are 0..1 progress of the blade
+ * edge and of the smear's end along that path (ease them yourself). The smear is thickest just behind the
+ * edge, tapers to nothing at the tail and wears a hard rim on its outer side. C: ramp, dark to bright.
+ * fade 0..1 dissolves it from the inside out.
+ */
+export function swing(p, { cx, cy, r, w, from, to, lead, tail, C, rim = WHITE, fade = 0, rimAt = 0.8, a = 1 }) {
+ const la = from + (to - from) * lead, ta = from + (to - from) * tail;
+ if (Math.abs(la - ta) < 0.02 || fade >= 1) return;
+ const fwd = to > from, lo = Math.min(la, ta), hi = Math.max(la, ta), body = C.slice(1);
+ const S = (u) => (fwd ? u : 1 - u); // 0 at the tail, 1 at the edge
+ p.arc(cx, cy, r, (u) => {
+ const s = S(u);
+ return w * Math.pow(s, 0.55) * (s > 0.94 ? (1 - s) / 0.06 : 1) + 1;
+ }, lo, hi,
+ (u, v) => (v > rimAt ? rim : at(body, v * 0.9 + S(u) * 0.15)),
+ (u, v) => a * clamp(smooth(0, 0.45, S(u)) * (v > rimAt ? 1.4 : 0.6 + v)) * (1 - fade * (1 - v * 0.6)));
+}
+
+/**
+ * A straight cut from (x0, y0) to (x1, y1) that bows `bulge` px to its left (negative: right). Like swing, it
+ * runs from `tail` to `lead` (0..1 along the chord), thickest behind the edge, tapering to points at both
+ * ends of the chord, with a bright rim on the bulge side. w is the widest it gets.
+ */
+export function cut(p, x0, y0, x1, y1, { bulge = 3, w = 4, lead = 1, tail = 0, C, rim = WHITE, fade = 0, rimAt = 0.72, a = 1, inner = 0.75 }) {
+ if (lead - tail < 0.01 || fade >= 1) return;
+ const dx = x1 - x0, dy = y1 - y0, L = Math.hypot(dx, dy) || 1, ux = dx / L, uy = dy / L;
+ const sg = bulge < 0 ? -1 : 1, nx = uy * sg, ny = -ux * sg, B = Math.abs(bulge), pad = B + w + 2;
+ const body = C.slice(1);
+ p.shade(Math.min(x0, x1) - pad, Math.min(y0, y1) - pad, Math.max(x0, x1) + pad, Math.max(y0, y1) + pad, (x, y, o) => {
+ const rx = x - x0, ry = y - y0, u = (rx * ux + ry * uy) / L;
+ if (u < tail || u > lead || u < 0 || u > 1) return;
+ const s = (u - tail) / (lead - tail);
+ const d = rx * nx + ry * ny - B * 4 * u * (1 - u); // across, + toward the bulge
+ const ww = w * Math.pow(s, 0.6) * (s > 0.9 ? (1 - s) / 0.1 : 1) * Math.sqrt(Math.sin(Math.PI * u)) + 0.7;
+ const lo = -ww * inner, hi = ww * (1 - inner);
+ if (d < lo || d > hi) return;
+ const v = (d - lo) / (hi - lo);
+ o.c = v > rimAt ? rim : at(body, v * 0.85 + s * 0.2);
+ o.a = a * clamp(smooth(0, 0.35, s) * (v > rimAt ? 1.5 : 0.55 + v)) * (1 - fade * (1 - v * 0.5));
+ });
+}
+
+/** A 4-point twinkle: a white center and arms of length n in color c. */
+export function glint(p, x, y, n, c, core = WHITE) {
+ for (let i = 1; i <= n; i++) {
+ const cc = i === n && n > 1 ? c : i === 1 ? core : c;
+ p.px(x - i, y, cc), p.px(x + i, y, cc), p.px(x, y - i, cc), p.px(x, y + i, cc);
+ }
+ p.px(x, y, core);
+}
+
+/**
+ * A dust ball lit from the top-left: the ramp's lighter steps on its lit side, darker on its shadow side, a
+ * crisp edge (no dithered rim). a dithers the whole ball; keep it for the last moments of its life.
+ */
+export function dustBall(p, x, y, r, D, a = 1, lift = 0) {
+ if (r < 0.6 || a <= 0) return;
+ p.circle(x, y, r, (d, ang) => at(D, clamp(0.45 + lift + Math.cos(ang + Math.PI * 0.75) * d * 0.5 - d * d * 0.15)), a);
+}
+
+/**
+ * A dust cloud: puffs [{ x, y, r, a, sy }] merged into one lumpy shape, lit from the top-left, the strongest
+ * puff deciding each pixel (so overlaps read as one cloud, not a pile of balls). a fades a puff by dither, sy
+ * squashes it (0.6: flatter). lo and span pick the slice of the ramp D the cloud uses (keep it narrow: dust is
+ * soft, rocks are contrasty).
+ */
+export function dustCloud(p, puffs, D, seed = 0, lo = 0.3, span = 0.55) {
+ let x0 = Infinity, y0 = Infinity, x1 = -Infinity, y1 = -Infinity;
+ for (const f of puffs) {
+ if (f.r < 0.6 || f.a <= 0) continue;
+ x0 = Math.min(x0, f.x - f.r); x1 = Math.max(x1, f.x + f.r); y0 = Math.min(y0, f.y - f.r); y1 = Math.max(y1, f.y + f.r);
+ }
+ if (x0 > x1) return;
+ p.shade(x0, y0, x1, y1, (x, y, out) => {
+ let best = 0, lit = 0, fa = 1;
+ for (const f of puffs) {
+ if (f.r < 0.6 || f.a <= 0) continue;
+ const dx = x - f.x, dy = (y - f.y) / (f.sy ?? 1), d2 = (dx * dx + dy * dy) / (f.r * f.r);
+ if (d2 >= 1) continue;
+ const v = 1 - d2;
+ if (v > best) (best = v), (lit = (-dx - dy * 1.3) / f.r), (fa = f.a);
+ }
+ if (best <= 0.03) return;
+ out.c = at(D, clamp(lo + span * (0.5 + lit * 0.45 + best * 0.5 - 0.25 + noise2(x * 0.45, y * 0.45, seed) * 0.2)));
+ out.a = fa * clamp(best * 6);
+ });
+}
diff --git a/src/fx/melee/axe-chop.js b/src/fx/melee/axe-chop.js
new file mode 100644
index 0000000..32dd17d
--- /dev/null
+++ b/src/fx/melee/axe-chop.js
@@ -0,0 +1,66 @@
+import { PAL, ramp, fit, burst, fly, seg, ease, clamp, WHITE } from "../../core/index.js";
+import { swing } from "./_lib.js";
+
+export const meta = {
+ name: "Axe chop",
+ desc: "A short, heavy chop: a thick steel arc drops in front of the fighter, bites with a thunk and a flash, and wood chips tumble out of the cut.",
+ tags: ["melee", "chop", "axe", "heavy", "wood", "combat", "directional", "one-shot"],
+ size: [68, 54],
+ origin: [16, 46],
+ duration: 0.6,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ actor: true,
+ options: { palette: PAL.metal, chips: PAL.wood, radius: 20, seed: 9 },
+};
+
+export function draw(p, t, o) {
+ const C = ramp(o.palette), W = fit(o.chips, 7), R = o.radius, S = o.seed, top = C.length - 1;
+ const cx = 5, cy = -15, A0 = -1.35, A1 = 0.38, HIT = 0.1;
+ const hx = cx + Math.cos(A1) * (R - 3), hy = cy + Math.sin(A1) * (R - 3); // where the bit sinks in
+ // it drops faster and faster, stops dead in the cut, then the smear lets go
+ const lead = ease.inQuad(seg(t + 0.03, 0, HIT + 0.03)), tail = ease.inCubic(seg(t, 0.06, 0.24));
+ swing(p, { cx, cy, r: R, w: 10, from: A0, to: A1, lead, tail, C, rimAt: 0.78, fade: seg(t, HIT + 0.04, 0.24) });
+ if (t < 0.24) {
+ const la = A0 + (A1 - A0) * lead;
+ p.glow(cx + Math.cos(la) * (R - 4), cy + Math.sin(la) * (R - 4), 12, C[top - 3], 0.3 * (1 - seg(t, HIT, 0.24)));
+ }
+ const q = t - HIT;
+ if (q < 0) return;
+ // the bite: a white wedge for a frame, then a notch that cools
+ if (q < 0.1) {
+ const hot = q < 0.034, s = hot ? 1 : 0.7;
+ p.tri(hx - 7 * s, hy - 5 * s, hx + 4 * s, hy + 1, hx - 4 * s, hy + 6 * s, hot ? WHITE : C[top - 1]);
+ if (hot) for (const [dx, dy] of [[6, -6], [8, -1], [6, 4]]) p.line(hx + dx * 0.5, hy + dy * 0.5, hx + dx * 1.3, hy + dy * 1.3, C[top - 1]);
+ }
+ p.glow(hx, hy, 18, C[top - 2], 0.45 * Math.pow(1 - seg(q, 0, 0.2), 2));
+ p.glow(hx, hy, 5, WHITE, 0.5 * (1 - seg(q, 0, 0.08)));
+ // wood chips spat out of the cut: up and away, a few back, tumbling, falling to the floor
+ burst(9, S, (r, i) => {
+ const a = -Math.PI / 2 + (i < 2 ? r.range(-1.3, -0.6) : r.range(-0.3, 1.2)), sp = r.range(55, 105);
+ const life = r.range(0.32, 0.46), born = r.range(0, 0.03), age = q - born;
+ if (age < 0 || age > life) return;
+ const [x, y] = fly(hx, hy - 1, Math.cos(a) * sp, Math.sin(a) * sp, age, 330, 0.8);
+ if (y > 0) return;
+ const spin = Math.floor(age * r.range(18, 30) + i) % 4, big = i % 3 !== 2, n = W.length;
+ const lit = W[n - 1], mid = W[n - 2], dark = W[n - 4];
+ if (spin % 2 === 0) p.rect(x, y, big ? 3 : 2, 1, spin ? mid : lit), big && p.px(x, y + 1, dark);
+ else p.rect(x, y, 1, big ? 3 : 2, spin === 1 ? lit : mid), big && p.px(x + 1, y + 1, dark);
+ });
+ // sparks off the edge
+ burst(5, S + 1, (r) => {
+ const a = r.range(-1.6, 0.4), sp = r.range(70, 130), life = r.range(0.12, 0.2);
+ if (q > life) return;
+ const [x, y] = fly(hx, hy, Math.cos(a) * sp, Math.sin(a) * sp, q, 200, 4), k = q / life;
+ p.px(x, y, k < 0.5 ? WHITE : C[top - 1]);
+ p.light(x, y, C[top - 2], 0.5 * (1 - k));
+ });
+ // a little sawdust drifting down
+ burst(6, S + 2, (r) => {
+ const born = r.range(0.02, 0.1), age = q - born, life = r.range(0.3, 0.45);
+ if (age < 0 || age > life) return;
+ const x = hx + r.range(-4, 3) + Math.sin(age * 9 + r.next() * 6) * 1.5, y = hy + r.range(-3, 2) + age * r.range(14, 26);
+ p.dot(x, y, W[W.length - 2], clamp(1.6 - age / life * 1.6));
+ });
+}
diff --git a/src/fx/melee/claw-swipe.js b/src/fx/melee/claw-swipe.js
new file mode 100644
index 0000000..cde212a
--- /dev/null
+++ b/src/fx/melee/claw-swipe.js
@@ -0,0 +1,55 @@
+import { PAL, ramp, burst, fly, seg, ease, clamp, WHITE } from "../../core/index.js";
+import { cut } from "./_lib.js";
+
+export const meta = {
+ name: "Claw swipe",
+ desc: "Three claws rake down and back in front of the fighter: white tips tear through, three red gashes hold a beat and close, flecks fly.",
+ tags: ["melee", "claw", "beast", "scratch", "slash", "combat", "directional", "one-shot"],
+ size: [60, 48],
+ origin: [12, 40],
+ duration: 0.5,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ actor: true,
+ options: { palette: PAL.blood, count: 3, seed: 7 },
+};
+
+export function draw(p, t, o) {
+ const C = ramp(o.palette), S = o.seed, top = C.length - 1, n = clamp(Math.round(o.count), 1, 5);
+ // the rake: from up and out in front, down and back toward the fighter
+ const ax = 29, ay = -26, bx = 12, by = -1, L = Math.hypot(bx - ax, by - ay), nx = -(by - ay) / L, ny = (bx - ax) / L;
+ for (let i = 0; i < n; i++) {
+ const off = (i - (n - 1) / 2) * 7, mid = Math.abs(off) < 1;
+ const shrink = mid ? 0 : 0.12; // the middle claw reaches furthest
+ const x0 = ax + nx * off + (bx - ax) * shrink * 0.3, y0 = ay + ny * off + (by - ay) * shrink * 0.3;
+ const x1 = bx + nx * off - (bx - ax) * shrink, y1 = by + ny * off - (by - ay) * shrink;
+ const t0 = [0.02, 0, 0.035, 0.05, 0.015][i] - 0.02, q = t - t0;
+ if (q < 0) continue;
+ const lead = ease.outQuart(seg(q, 0, 0.06)), tail = ease.inCubic(seg(q, 0.01, 0.11));
+ cut(p, x0, y0, x1, y1, { bulge: -2, w: 3, lead, tail, C, inner: 0.6 });
+ // the gash it leaves: a thin red lens that holds, then closes toward its middle
+ const g = seg(q, 0.05, 0.09) * (1 - seg(t, 0.26, 0.44));
+ if (g <= 0) continue;
+ const len = Math.hypot(x1 - x0, y1 - y0), sx = (x1 - x0) / len, sy = (y1 - y0) / len;
+ for (let j = 0; j <= len; j++) {
+ const u = j / len, s = Math.sin(Math.PI * u) - (1 - g) * 1.05;
+ if (s <= 0) continue;
+ const b = 2 * 4 * u * (1 - u), x = x0 + sx * j - sy * b, y = y0 + sy * j + sx * b; // on the cut's bowed center line
+ const hot = t >= 0.066 && t < 0.1; // the frame all three are open: white-hot
+ p.px(x, y, hot && s > 0.3 ? WHITE : s > 0.55 ? C[top - 1] : C[top - 2]);
+ if (s > 0.3) p.px(x + 1, y, hot ? C[top - 1] : s > 0.6 ? C[top - 3] : C[top - 4]);
+ }
+ }
+ // red flecks flung off the claws' ends as they finish the rake
+ burst(6, S, (r, i) => {
+ const born = 0.05 + r.range(0, 0.04), age = t - born, life = r.range(0.18, 0.28);
+ if (age < 0 || age > life) return;
+ const off = ((i % 3) - 1) * 7, x0 = bx + nx * off + 2, y0 = by + ny * off - 4;
+ const a = Math.atan2(by - ay, bx - ax) + r.range(-0.6, 0.3), sp = r.range(40, 80);
+ const [x, y] = fly(x0, y0, Math.cos(a) * sp, Math.sin(a) * sp - 30, age, 260, 2), k = age / life;
+ if (y > 1) return;
+ p.px(x, y, k < 0.35 ? C[top] : k < 0.7 ? C[top - 2] : C[top - 4]);
+ });
+ p.glow(20, -13, 22, C[top - 2], 0.35 * (1 - seg(t, 0.05, 0.3)) * seg(t, -0.02, 0.03));
+}
diff --git a/src/fx/melee/counter-flash.js b/src/fx/melee/counter-flash.js
new file mode 100644
index 0000000..e7fad15
--- /dev/null
+++ b/src/fx/melee/counter-flash.js
@@ -0,0 +1,68 @@
+import { ramp, burst, fly, seg, ease, clamp, WHITE } from "../../core/index.js";
+import { swing } from "./_lib.js";
+
+export const meta = {
+ name: "Counter flash",
+ desc: "A parry turned counter: a razor-thin white cross flares where the blow is caught, twinkles to an X, and a quick return cut flicks out.",
+ tags: ["melee", "parry", "counter", "riposte", "flash", "combat", "directional", "one-shot"],
+ size: [68, 44],
+ origin: [26, 36],
+ duration: 0.4,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ actor: true,
+ options: { palette: ["#08202a", "#0c3a4a", "#12607a", "#1c90b0", "#40c4e0", "#90e8f8", "#d8faff", "#ffffff"], seed: 17 },
+};
+
+export function draw(p, t, o) {
+ const C = ramp(o.palette), S = o.seed, top = C.length - 1;
+ const X = 11, Y = -12; // where the blow is caught
+ // the catch: a long, thin cross of light that snaps out on the first frame and pulls back in
+ const pull = ease.outCubic(seg(t, 0.03, 0.2));
+ if (pull < 1) {
+ const H = Math.round(28 * (1 - pull)), V = Math.round(15 * (1 - pull)), hot = t < 0.034;
+ for (let i = -H; i <= H; i++) {
+ const u = Math.abs(i) / (H || 1);
+ p.px(X + i, Y, u < 0.45 ? WHITE : u < 0.8 ? C[top - 1] : C[top - 3]);
+ if (u < 0.12 || (hot && u < 0.3)) p.px(X + i, Y - 1, hot ? WHITE : C[top - 1]), p.px(X + i, Y + 1, hot ? WHITE : C[top - 1]);
+ }
+ for (let j = -V; j <= V; j++) {
+ const u = Math.abs(j) / (V || 1);
+ p.px(X, Y + j, u < 0.45 ? WHITE : u < 0.8 ? C[top - 1] : C[top - 3]);
+ }
+ p.glowLine(X - H, Y, X + H, Y, 4, C[top - 2], 0.35 * (1 - pull));
+ }
+ // the core: a white diamond that twinkles from + to x and shrinks away
+ const tw = 1 - seg(t, 0.02, 0.3);
+ if (tw > 0) {
+ const r = Math.round(1 + 3 * tw);
+ for (let i = -r; i <= r; i++) for (let j = -r + Math.abs(i); j <= r - Math.abs(i); j++) p.px(X + i, Y + j, Math.abs(i) + Math.abs(j) < r ? WHITE : C[top - 1]);
+ if (t > 0.07 && t < 0.24) {
+ const d = Math.round(2 + 6 * seg(t, 0.07, 0.12) * (1 - seg(t, 0.12, 0.24)));
+ for (let i = 2; i <= d; i++) for (const [sx, sy] of [[1, 1], [1, -1], [-1, 1], [-1, -1]]) p.px(X + sx * i, Y + sy * i, i < d * 0.6 ? C[top] : C[top - 2]);
+ }
+ p.glow(X, Y, 22, C[top - 2], 0.5 * tw * tw);
+ p.glow(X, Y, 6, WHITE, 0.5 * tw);
+ }
+ // the return cut: a short, quick crescent flicked out from the catch
+ const q = t - 0.08;
+ if (q > 0) {
+ const lead = ease.outQuart(seg(q, 0, 0.06)), tail = ease.inCubic(seg(q, 0.01, 0.14));
+ swing(p, { cx: X - 2, cy: Y + 2, r: 17, w: 6, from: -1.2, to: 0.75, lead, tail, C, rimAt: 0.72 });
+ if (q < 0.14) {
+ const la = -1.2 + 1.95 * lead;
+ p.glow(X - 2 + Math.cos(la) * 14, Y + 2 + Math.sin(la) * 14, 12, C[top - 3], 0.4 * (1 - seg(q, 0.05, 0.14)));
+ }
+ }
+ // sparks knocked off the catch, out and down
+ burst(9, S, (r) => {
+ const born = r.range(0, 0.03), age = t - born, life = r.range(0.16, 0.3);
+ if (age < 0 || age > life) return;
+ const a = r.range(-2.4, 0.6), sp = r.range(60, 130);
+ const [x, y] = fly(X, Y, Math.cos(a) * sp, Math.sin(a) * sp, age, 220, 4), k = age / life;
+ if (y > 0) return;
+ p.px(x, y, k < 0.3 ? WHITE : k < 0.65 ? C[top - 1] : C[top - 3]);
+ p.light(x, y, C[top - 2], 0.45 * (1 - k));
+ });
+}
diff --git a/src/fx/melee/dagger-flurry.js b/src/fx/melee/dagger-flurry.js
new file mode 100644
index 0000000..b2289b6
--- /dev/null
+++ b/src/fx/melee/dagger-flurry.js
@@ -0,0 +1,50 @@
+import { ramp, burst, rng, fly, seg, ease, clamp, WHITE } from "../../core/index.js";
+import { swing } from "./_lib.js";
+
+export const meta = {
+ name: "Dagger flurry",
+ desc: "A flurry of quick knife cuts: small sharp crescents flick in and out at all angles in front of the fighter, the last one biggest.",
+ tags: ["melee", "slash", "dagger", "flurry", "combo", "rogue", "combat", "directional", "one-shot"],
+ size: [60, 48],
+ origin: [14, 40],
+ duration: 0.6,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ actor: true,
+ options: { palette: ["#140a26", "#2b1252", "#4a2390", "#7440cc", "#a070f0", "#cfa8ff", "#f0e0ff", "#ffffff"], count: 10, seed: 8 },
+};
+
+export function draw(p, t, o) {
+ const C = ramp(o.palette), S = o.seed, n = clamp(Math.round(o.count), 2, 14), top = C.length - 1;
+ for (let i = 0; i < n; i++) {
+ const r = rng(S, i), last = i === n - 1;
+ const born = (i / n) * 0.32 + r.range(0, 0.02) - 0.035, q = t - born;
+ if (q < -0.001 || q > 0.2) continue;
+ // where it lands: in front of the fighter, the outer edge mostly facing out (right)
+ const mx = r.range(15, 31) + (last ? 2 : 0), my = r.range(-23, -6), th = r.range(-1.3, 1.3);
+ const R = last ? 13 : r.range(8.5, 11), span = r.range(2, 2.5) * (last ? 1.1 : 1), cw = r.next() < 0.5;
+ const cx = mx - Math.cos(th) * R, cy = my - Math.sin(th) * R;
+ const a0 = th + (cw ? -span / 2 : span / 2), a1 = th + (cw ? span / 2 : -span / 2);
+ const lead = ease.outQuart(seg(q, 0, 0.045)), tail = ease.inCubic(seg(q, 0.01, 0.1));
+ swing(p, { cx, cy, r: R, w: last ? 6 : 4, from: a0, to: a1, lead, tail, C, rimAt: 0.66 });
+ // a pin of light where the blade leaves the cut
+ const ex = cx + Math.cos(a1) * R, ey = cy + Math.sin(a1) * R, k = seg(q, 0.03, 0.05) * (1 - seg(q, 0.05, 0.12));
+ if (k > 0) {
+ p.px(ex, ey, WHITE);
+ if (k > 0.5) p.px(ex - 1, ey, C[top - 1]), p.px(ex + 1, ey, C[top - 1]), p.px(ex, ey - 1, C[top - 1]), p.px(ex, ey + 1, C[top - 1]);
+ }
+ p.glow(mx, my, last ? 14 : 9, C[top - 3], 0.35 * (1 - seg(q, 0.02, 0.12)) * seg(q, -0.01, 0.01));
+ // the last cut lands with a flash
+ if (last && q > 0.03 && q < 0.07) p.circle(mx, my, 2.5, WHITE), p.glow(mx, my, 18, C[top - 2], 0.5);
+ }
+ // nicks of light thrown off the cuts
+ burst(n, S + 1, (r, j) => {
+ const born = (j / n) * 0.32 + 0.02 + r.range(0, 0.03), age = t - born, life = r.range(0.08, 0.14);
+ if (age < 0 || age > life) return;
+ const g = rng(S, j), mx = g.range(14, 30), my = g.range(-22, -6), a = r.range(-2.2, 1.2), sp = r.range(40, 80);
+ const [x, y] = fly(mx, my, Math.cos(a) * sp, Math.sin(a) * sp, age, 120, 5), k = age / life;
+ p.px(x, y, k < 0.4 ? WHITE : C[top - 2]);
+ p.light(x, y, C[top - 3], 0.4 * (1 - k));
+ });
+}
diff --git a/src/fx/melee/double-slash.js b/src/fx/melee/double-slash.js
new file mode 100644
index 0000000..79d88c3
--- /dev/null
+++ b/src/fx/melee/double-slash.js
@@ -0,0 +1,82 @@
+import { PAL, ramp, burst, fly, seg, ease, clamp, WHITE } from "../../core/index.js";
+import { cut, glint } from "./_lib.js";
+
+export const meta = {
+ name: "Double slash",
+ desc: "Two quick cuts cross in an X in front of the fighter: down, then up, a white flash where they meet, then the X dissolves.",
+ tags: ["melee", "slash", "sword", "combo", "combat", "directional", "one-shot"],
+ size: [64, 52],
+ origin: [16, 40],
+ duration: 0.5,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ actor: true,
+ options: { palette: PAL.neon, size: 1, seed: 3 },
+};
+
+// a point on a cut's bowed center line, u 0..1
+const along = (c, u) => {
+ const dx = c.x1 - c.x0, dy = c.y1 - c.y0, L = Math.hypot(dx, dy), s = Math.sign(c.bulge), m = Math.abs(c.bulge) * 0.8 * 4 * u * (1 - u);
+ return [c.x0 + dx * u + (dy / L) * s * m, c.y0 + dy * u - (dx / L) * s * m];
+};
+
+export function draw(p, t, o) {
+ const C = ramp(o.palette), k = o.size, S = o.seed, top = C.length - 1;
+ const X = 20 * k, Y = -13 * k, h = 14 * k; // the X's center and half its span
+ const cuts = [
+ { x0: X - h, y0: Y - h, x1: X + h, y1: Y + h, bulge: 4 * k, t0: -0.015 }, // down
+ { x0: X - h, y0: Y + h, x1: X + h, y1: Y - h, bulge: -4 * k, t0: 0.11 }, // up
+ ];
+ // where the two bowed lines really cross
+ let cx = X, cy = Y, best = Infinity;
+ for (let i = 0; i <= 40; i++)
+ for (let j = 0; j <= 40; j++) {
+ const [ax, ay] = along(cuts[0], i / 40), [bx, by] = along(cuts[1], j / 40), d = (ax - bx) ** 2 + (ay - by) ** 2;
+ if (d < best) (best = d), (cx = (ax + bx) / 2), (cy = (ay + by) / 2);
+ }
+ const T2 = cuts[1].t0 + 0.07; // the second cut lands: the hero frame
+ const hot = t >= T2 && t < T2 + 0.034;
+ for (const c of cuts) {
+ const q = t - c.t0;
+ if (q < 0) continue;
+ const lead = ease.outQuart(seg(q, 0, 0.07)), tail = ease.inCubic(seg(q, 0.015, 0.15));
+ cut(p, c.x0, c.y0, c.x1, c.y1, { bulge: c.bulge, w: 7 * k, lead, tail, C, rim: WHITE });
+ // the line it leaves in the air: a thin scar that holds, flashes white when the X closes, then shrinks to the middle
+ const scar = seg(q, 0.06, 0.1) * (1 - seg(t, 0.3, 0.46));
+ if (scar <= 0) continue;
+ const L = Math.hypot(c.x1 - c.x0, c.y1 - c.y0);
+ for (let i = 0; i <= L * 1.5; i++) {
+ const u = i / (L * 1.5), [x, y] = along(c, u), keep = Math.sin(Math.PI * u) - (1 - scar) * 1.05;
+ if (keep <= 0) continue;
+ if (hot) {
+ p.px(x, y, WHITE), p.px(x + 1, y, WHITE);
+ continue;
+ }
+ p.dot(x, y, keep > 0.4 ? C[top - 1] : C[top - 3], clamp(keep * 4));
+ }
+ }
+ // the crossing: a white burst the frame the X closes, then a twinkle that shrinks
+ const fl = t >= T2 ? 1 - seg(t, T2, T2 + 0.16) : 0;
+ if (fl > 0) {
+ glint(p, cx, cy, Math.round(1 + 6 * ease.outCubic(fl)), hot ? WHITE : C[top - 2]);
+ if (hot) p.circle(cx, cy, 3 * k, WHITE);
+ p.glow(cx, cy, 20 * k, C[top - 3], 0.5 * fl * fl);
+ }
+ // sparks thrown from the crossing
+ burst(9, S, (r) => {
+ const age = t - T2 - r.range(0, 0.03), life = r.range(0.12, 0.24);
+ if (age < 0 || age > life) return;
+ const a = r.range(0, Math.PI * 2), sp = r.range(50, 100) * k;
+ const [x, y] = fly(cx, cy, Math.cos(a) * sp, Math.sin(a) * sp, age, 110, 6), q = age / life;
+ p.px(x, y, q < 0.4 ? WHITE : q < 0.75 ? C[top - 2] : C[top - 4]);
+ p.light(x, y, C[top - 3], 0.4 * (1 - q));
+ });
+ // the edge light rides each cut as it passes
+ for (const c of cuts) {
+ const q = t - c.t0;
+ if (q < 0.005 || q > 0.16) continue;
+ const [x, y] = along(c, ease.outQuart(seg(q, 0, 0.07)));
+ p.glow(x, y, 14 * k, C[top - 3], 0.4 * (1 - seg(q, 0.05, 0.16)));
+ }
+}
diff --git a/src/fx/melee/hammer-smash.js b/src/fx/melee/hammer-smash.js
new file mode 100644
index 0000000..9169d6b
--- /dev/null
+++ b/src/fx/melee/hammer-smash.js
@@ -0,0 +1,90 @@
+import { PAL, ramp, fit, at, burst, fly, seg, ease, clamp, WHITE } from "../../core/index.js";
+import { dustCloud } from "./_lib.js";
+
+export const meta = {
+ name: "Hammer smash",
+ desc: "A hammer drops straight down in front of the fighter: a block-wide smear, a white slam on the floor, a dome of force, rocks flung out and dust.",
+ tags: ["melee", "smash", "hammer", "heavy", "ground", "shockwave", "combat", "directional", "one-shot"],
+ size: [88, 54],
+ origin: [24, 46],
+ duration: 0.8,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ actor: true,
+ options: { palette: PAL.volt, debris: PAL.stone, reach: 17, seed: 15 },
+};
+
+const DUST = ramp(["#2e2830", "#463e48", "#655b63", "#8a7f84", "#b0a5a6", "#d6cdc8"]);
+
+export function draw(p, t, o) {
+ const C = ramp(o.palette), St = fit(o.debris, 8), S = o.seed, X = o.reach, top = C.length - 1;
+ const HIT = 0.1, W = 5; // half the hammer head's width
+ // the drop: a block-wide smear falling faster and faster, its leading edge white
+ const fall = ease.inQuad(seg(t + 0.03, 0, HIT + 0.03)), headY = -36 + 36 * fall, tailY = -38 + 38 * ease.inQuad(seg(t, 0.04, HIT + 0.06));
+ if (headY - tailY > 1 && t < HIT + 0.06) {
+ p.shade(X - W, tailY, X + W, headY, (x, y, out) => {
+ const v = (y - tailY) / (headY - tailY), side = Math.abs(x - X) / W; // v 0 at the top .. 1 at the head
+ if (side > 0.35 + 0.65 * Math.sqrt(v)) return; // a wedge: narrow where it has been, full width at the head
+ out.c = v > 0.85 ? WHITE : v > 0.5 ? (side > 0.75 ? C[top - 1] : C[top]) : side > 0.6 ? C[top - 3] : C[top - 2];
+ out.a = clamp(v * 1.8);
+ });
+ // speed lines either side, staggered
+ for (const [dx, y0, l] of [[-W - 3, -14, 10], [-W - 6, -8, 6], [W + 2, -12, 9], [W + 5, -6, 6]])
+ if (t < HIT && headY + y0 > -40) p.line(X + dx, headY + y0, X + dx, headY + y0 + l, (u) => (u > 0.5 ? C[top - 1] : C[top - 3]));
+ p.glow(X, headY - 2, 14, C[top - 2], 0.4 * (1 - seg(t, HIT, 0.2)));
+ }
+ const q = t - HIT;
+ if (q < 0) return;
+ // the slam: a white flash flat on the floor, rays shooting up, then gone
+ if (q < 0.07) {
+ const hot = q < 0.034;
+ p.ellipse(X, 0, hot ? 15 : 9, hot ? 6 : 3, (d) => (d < 0.5 ? WHITE : hot ? C[top] : C[top - 1]), (d, a) => (a <= 0.05 ? 1 : 0));
+ for (const [dx, h] of [[-9, 8], [-5, 14], [0, 20], [5, 14], [9, 8]]) p.line(X + dx * 0.6, -3, X + dx * 1.4, -h * (hot ? 1 : 0.65), (u) => (u < 0.55 ? WHITE : C[top - 1]));
+ }
+ // a dome of force swells off the floor and thins away
+ const dm = seg(q, 0.01, 0.22);
+ if (dm > 0 && dm < 1) {
+ const r = 5 + 16 * ease.outCubic(dm);
+ p.ring(X, 0, r, dm < 0.4 ? 2 : 1, dm < 0.3 ? WHITE : dm < 0.6 ? C[top - 1] : C[top - 3], (v, a) => (a < -0.08 && a > -Math.PI + 0.08 ? 1 : 0));
+ p.glowRing(X, 0, r, 4, C[top - 2], 0.2 * (1 - dm));
+ }
+ p.glow(X, -3, 30, C[top - 2], 0.5 * Math.pow(1 - seg(q, 0, 0.3), 2));
+ p.glow(X, -1, 7, WHITE, 0.6 * (1 - seg(q, 0, 0.1)));
+ // the dent: a dark crater line in the floor with cracks running off it
+ const dent = 1 - seg(t, 0.62, 0.8);
+ if (dent > 0) {
+ p.line(X - 6, 1, X + 6, 1, St[0], dent);
+ p.line(X - 4, 2, X + 4, 2, St[1], dent);
+ for (const [x0, x1, y] of [[X - 6, X - 11, 2], [X + 6, X + 12, 3], [X + 6, X + 9, 1]]) p.line(x0, 1, x1, y, St[0], dent);
+ }
+ // dust rolls out both ways from under the head
+ const puffs = [];
+ burst(10, S + 1, (r, i) => {
+ const side = i % 2 ? 1 : -1, born = r.range(0, 0.05), age = q - born, life = r.range(0.36, 0.52);
+ if (age < 0 || age > life) return;
+ const k = age / life, push = ease.outCubic(seg(age, 0, 0.3));
+ puffs.push({
+ x: X + side * (r.range(3, 6) + push * r.range(8, 18)), y: -2 - push * r.range(1, 5) - age * 6,
+ r: r.range(2.4, 4) * (0.5 + 0.7 * push) * (1 - 0.8 * ease.inQuad(seg(k, 0.45, 1))), a: 1 - seg(k, 0.82, 1), sy: 0.8,
+ });
+ });
+ dustCloud(p, puffs, DUST, S, 0.22, 0.5);
+ // rocks flung out of the hole: tumbling up and out, landing, a little hop, then sinking away
+ burst(8, S + 2, (r, i) => {
+ const side = i % 2 ? 1 : -1, a = -Math.PI / 2 + side * r.range(0.25, 1.1), sp = r.range(60, 110), born = r.range(0, 0.02);
+ const age = q - born, life = r.range(0.45, 0.62);
+ if (age < 0 || age > life) return;
+ const g = 300, vy = Math.sin(a) * sp, land = (-vy + Math.sqrt(vy * vy + 2 * g * 2)) / g; // when it comes back to the floor
+ let [x, y] = fly(X + side * 2, -2, Math.cos(a) * sp, vy, Math.min(age, land), g);
+ if (age > land) { // a small hop, then it rests
+ const h = age - land;
+ x += Math.cos(a) * sp * 0.25 * Math.min(h, 0.12);
+ y = Math.min(0, -1 + -(30 * h - 150 * h * h));
+ }
+ const s = r.next() < 0.4 ? 3 : 2, spin = Math.floor(age * 16 + i) % 2, k = seg(age, life - 0.1, life);
+ p.rect(x, y - s + 1, s, s, St[5 - spin], 1 - k);
+ p.rect(x, y - s + 1, s, 1, St[6], 1 - k);
+ p.px(x + s - 1, y, St[3]);
+ });
+}
diff --git a/src/fx/melee/heavy-cleave.js b/src/fx/melee/heavy-cleave.js
new file mode 100644
index 0000000..e83cedc
--- /dev/null
+++ b/src/fx/melee/heavy-cleave.js
@@ -0,0 +1,94 @@
+import { PAL, ramp, at, rand, burst, fly, seg, ease, clamp, WHITE } from "../../core/index.js";
+import { swing, glint, dustCloud } from "./_lib.js";
+
+export const meta = {
+ name: "Heavy cleave",
+ desc: "A two-handed overhead cleave: a glint behind the head, a thick arc that speeds up as it falls, and a slam into the floor that throws dust and grit.",
+ tags: ["melee", "slash", "cleave", "greatsword", "heavy", "ground", "combat", "directional", "one-shot"],
+ size: [92, 58],
+ origin: [30, 48],
+ duration: 0.75,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ actor: true,
+ options: { palette: PAL.ember, radius: 27, seed: 6 },
+};
+
+const DUST = ramp(["#2e2830", "#463e48", "#655b63", "#8a7f84", "#b0a5a6", "#d6cdc8"]);
+const CRACK = ramp(["#0c0a10", "#5a5262"]);
+
+export function draw(p, t, o) {
+ const C = ramp(o.palette), R = o.radius, S = o.seed, top = C.length - 1;
+ const cx = 1, cy = -15, A0 = -2.7, A1 = Math.asin(clamp(-cy / R)); // the arc ends on the floor in front
+ const hx = cx + Math.cos(A1) * R, HIT = 0.14;
+ // wind-up: a glint where the blade waits behind the head
+ if (t < 0.075) {
+ const gx = cx + Math.cos(A0) * (R - 2), gy = cy + Math.sin(A0) * (R - 2);
+ glint(p, gx, gy, t < 0.035 ? 2 : 3, C[top - 1]);
+ p.glow(gx, gy, 8, C[top - 2], 0.4);
+ }
+ // the swing speeds up as it falls (heavy), and the smear burns out after the slam
+ const lead = ease.inQuad(seg(t, 0.05, HIT)), tail = ease.inCubic(seg(t, 0.09, 0.32));
+ swing(p, { cx, cy, r: R, w: 12, from: A0, to: A1, lead, tail, C, fade: seg(t, HIT + 0.02, 0.27) });
+ if (t > 0.05 && t < 0.3) {
+ const la = A0 + (A1 - A0) * lead;
+ p.glow(cx + Math.cos(la) * (R - 4), cy + Math.sin(la) * (R - 4), 18, C[top - 2], 0.45 * (1 - seg(t, HIT, 0.3)));
+ }
+ const q = t - HIT; // time since the slam
+ if (q < 0) return;
+ // cracks in the floor, out from the hit both ways
+ const cr = ease.outCubic(seg(q, 0, 0.08)) * (1 - seg(t, 0.55, 0.75));
+ if (cr > 0) {
+ for (const side of [-1, 1]) {
+ let x = hx, y = 1;
+ const n = Math.round((side > 0 ? 10 : 7) * cr);
+ for (let i = 0; i < n; i++) {
+ const nx = x + side, ny = clamp(y + (rand(S, i, side + 5) - 0.5) * 1.6, 1, 3);
+ p.px(nx, Math.round(ny), CRACK[0]);
+ if (i < n - 2) p.px(nx, Math.round(ny) - 1, CRACK[1]);
+ (x = nx), (y = ny);
+ }
+ }
+ }
+ // the slam: a white dome and a flash along the floor for a frame, then hot, then gone
+ if (q < 0.07) {
+ const hot = q < 0.034;
+ p.ellipse(hx, 0, hot ? 10 : 6, hot ? 7 : 4, (d) => (d < 0.55 ? WHITE : hot ? C[top] : C[top - 1]), (d, ang) => (ang <= 0.05 ? 1 : 0));
+ p.line(hx - (hot ? 20 : 12), 0, hx + (hot ? 26 : 16), 0, (u) => (Math.abs(u - 0.43) < 0.2 ? WHITE : C[top - 1]));
+ // streaks shooting up off the floor
+ for (const [dx, h] of [[-7, 8], [-3, 15], [1, 18], [4, 13], [8, 7]]) p.line(hx + dx, -2, hx + dx * 1.7, -h * (hot ? 1 : 0.6), (u) => (u < 0.5 ? WHITE : C[top - 1]));
+ }
+ p.glow(hx, -2, 32, C[top - 2], 0.55 * Math.pow(1 - seg(q, 0, 0.3), 2));
+ p.glow(hx, -1, 9, C[top], 0.7 * (1 - seg(q, 0, 0.12)));
+ // dust rolls out along the floor both ways (more away from the fighter), lifts, swells and thins away
+ const puffs = [];
+ burst(14, S + 1, (r, i) => {
+ const side = i < 5 ? -1 : 1, born = r.range(0, 0.06), age = q - born, life = r.range(0.38, 0.56);
+ if (age < 0 || age > life) return;
+ const k = age / life, reach = (side > 0 ? r.range(6, 28) : r.range(4, 14)) * ease.outCubic(seg(age, 0, 0.32));
+ puffs.push({
+ x: hx + side * (r.range(1, 4) + reach), y: -r.range(2, 3.5) - age * r.range(4, 10),
+ r: r.range(2.6, 4.4) * (0.5 + 0.7 * ease.outCubic(seg(k, 0, 0.4))) * (1 - 0.75 * ease.inQuad(seg(k, 0.45, 1))), a: 1 - seg(k, 0.7, 1),
+ });
+ });
+ dustCloud(p, puffs, DUST, S, 0.2, 0.7);
+ // grit and chips thrown up, falling back
+ burst(8, S + 2, (r) => {
+ const a = -Math.PI / 2 + r.range(-1.1, 1.1), sp = r.range(50, 100), life = r.range(0.35, 0.5);
+ if (q > life) return;
+ const [x, y] = fly(hx, -1, Math.cos(a) * sp, Math.sin(a) * sp, q, 300, 0.5);
+ if (y > 0) return;
+ const c = at(DUST, r.range(0.4, 1));
+ p.px(x, y, c);
+ if (r.next() < 0.4) p.px(x + 1, y, c);
+ });
+ // a few embers knocked loose
+ burst(5, S + 3, (r) => {
+ const a = -Math.PI / 2 + r.range(-1.3, 1.3), sp = r.range(60, 120), life = r.range(0.2, 0.3);
+ if (q > life) return;
+ const [x, y] = fly(hx, -2, Math.cos(a) * sp, Math.sin(a) * sp, q, 200, 3), k = q / life;
+ p.px(x, y, k < 0.4 ? WHITE : C[top - 1]);
+ p.light(x, y, C[top - 2], 0.5 * (1 - k));
+ });
+}
diff --git a/src/fx/melee/iaido-cut.js b/src/fx/melee/iaido-cut.js
new file mode 100644
index 0000000..945e02b
--- /dev/null
+++ b/src/fx/melee/iaido-cut.js
@@ -0,0 +1,80 @@
+import { ramp, hex, burst, fly, seg, ease, clamp, WHITE } from "../../core/index.js";
+
+export const meta = {
+ name: "Iaido cut",
+ desc: "A dash cut: the fighter arrives in a white streak that leaves one long line hanging in the air; a beat later the line flashes and splits open.",
+ tags: ["melee", "slash", "dash", "iaido", "katana", "combat", "directional", "one-shot"],
+ size: [88, 36],
+ origin: [74, 30],
+ duration: 0.9,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ actor: true,
+ options: { palette: ["#10141c", "#232b3a", "#3e4a60", "#64748e", "#98a6bc", "#cad4e2", "#f0f4fa", "#ffffff"], accent: "#e8304a", length: 66, seed: 14 },
+};
+
+// the fighter is a blur inside the streak on the first frame, then stands where the dash ended
+export const actorAlpha = (t) => (t < 0.03 ? 0 : 1);
+
+export function draw(p, t, o) {
+ const C = ramp(o.palette), A = hex(o.accent), L = o.length, S = o.seed, top = C.length - 1;
+ const y0 = -10, xa = -L + 2, xb = 5; // the cut runs from where the dash began to just past the fighter
+ const SPLIT = 0.36;
+ // afterimages of the fighter left along the dash: flat silhouettes, the farthest gone first
+ const act = o.actor;
+ if (act) {
+ for (let i = 1; i <= 3; i++) {
+ if (t >= 0.1 - i * 0.025) continue;
+ p.mask(act.mask, act.x - i * 15, act.y, C[top - 2 - i]);
+ p.outline(act.mask, act.x - i * 15, act.y, C[top - 1 - i]);
+ }
+ }
+ // the dash: a thick white streak on the first frames, with speed lines
+ if (t < 0.1) {
+ const e = 1 - seg(t, 0.03, 0.1), th = Math.round(1 + 2 * e);
+ for (let d = -th; d <= th; d++) {
+ const back = xa + (L * 0.5 * seg(t, 0.02, 0.1)) * (1 - Math.abs(d) / (th + 1)) + Math.abs(d) * 6;
+ p.line(back, y0 + d, xb + 2 - Math.abs(d) * 2, y0 + d, Math.abs(d) < 2 ? WHITE : C[top - 1]);
+ }
+ burst(7, S + 3, (r, i) => {
+ const dy = (i % 2 ? 1 : -1) * r.range(4, 9), x1 = xb - r.range(2, 14), l = r.range(14, 34) * e;
+ if (l > 2) p.line(x1 - l, y0 + dy, x1, y0 + dy, r.next() < 0.5 ? C[top - 1] : C[top - 3]);
+ });
+ p.glowLine(xa, y0, xb, y0, 8, C[top - 2], 0.4 * e);
+ }
+ // the line that hangs in the air: a hairline with a glint running along it, holding for a beat
+ if (t >= 0.06 && t < SPLIT) {
+ p.line(xa + 4, y0, xb, y0, (u) => (u < 0.06 || u > 0.97 ? C[top - 3] : C[top - 1]));
+ const gx = xa + (xb - xa) * ease.inOutSine(seg(t, 0.1, SPLIT - 0.04));
+ if (gx > xa + 6 && gx < xb - 2) p.px(gx, y0, WHITE), p.px(gx - 1, y0, WHITE), p.px(gx, y0 - 1, C[top]), p.px(gx, y0 + 1, C[top]);
+ }
+ const q = t - SPLIT;
+ if (q < 0) return;
+ // the split: one white frame, then the two lips part, crimson showing between them, and fray from the ends in
+ if (q < 0.034) {
+ p.rect(xa + 2, y0 - 1, xb - xa - 2, 3, WHITE);
+ p.glowLine(xa, y0, xb, y0, 12, C[top - 1], 0.6);
+ return;
+ }
+ const open = ease.outCubic(seg(q, 0.03, 0.2)), fray = seg(q, 0.12, 0.5);
+ const half = (xb - xa) / 2, mid = (xa + xb) / 2, reach = half * (1 - ease.inQuad(fray));
+ if (reach > 1) {
+ const gap = 1 + 3 * open;
+ for (const side of [-1, 1]) {
+ const y = y0 + side * gap, x0 = mid - reach, x1 = mid + reach;
+ p.line(x0, y, x1, y, (u) => (Math.abs(u - 0.5) < 0.42 ? (q < 0.12 ? WHITE : C[top - 1]) : C[top - 3]));
+ }
+ if (open > 0.3) p.line(mid - reach * 0.85, y0, mid + reach * 0.85, y0, A);
+ p.glowLine(mid - reach, y0, mid + reach, y0, 7, A, 0.25 * (1 - fray));
+ }
+ // flecks spat out of the split along its length
+ burst(9, S, (r) => {
+ const born = r.range(0, 0.06), age = q - born, life = r.range(0.18, 0.3);
+ if (age < 0 || age > life) return;
+ const x0 = xa + (xb - xa) * r.range(0.1, 0.95), side = r.next() < 0.5 ? -1 : 1;
+ const [x, y] = fly(x0, y0 + side * 2, r.range(-20, 30), side * r.range(20, 60), age, 160, 3), k = age / life;
+ if (y > 0) return;
+ p.px(x, y, k < 0.35 ? WHITE : k < 0.7 ? A : C[top - 3]);
+ });
+}
diff --git a/src/fx/melee/punch-combo.js b/src/fx/melee/punch-combo.js
new file mode 100644
index 0000000..94a619d
--- /dev/null
+++ b/src/fx/melee/punch-combo.js
@@ -0,0 +1,70 @@
+import { ramp, burst, fly, seg, ease, clamp, WHITE } from "../../core/index.js";
+
+export const meta = {
+ name: "Punch combo",
+ desc: "Jab, jab, straight: two quick puffs pop in front of the fighter, then a bigger straight lands with a burst of rays and a ring.",
+ tags: ["melee", "punch", "combo", "brawler", "fist", "combat", "directional", "one-shot"],
+ size: [60, 44],
+ origin: [14, 36],
+ duration: 0.7,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ actor: true,
+ options: { palette: ["#2a1208", "#5a2410", "#9a4018", "#d8702a", "#f8a850", "#ffd890", "#fff4d8", "#ffffff"], seed: 16 },
+};
+
+// jab, jab, straight: when, where, how big
+const HITS = [
+ { t: 0.0, x: 13, y: -12, s: 0.75 },
+ { t: 0.13, x: 15, y: -8, s: 0.8 },
+ { t: 0.3, x: 19, y: -10, s: 1.15 },
+];
+
+export function draw(p, t, o) {
+ const C = ramp(o.palette), S = o.seed, top = C.length - 1;
+ HITS.forEach((h, i) => {
+ const q = t - h.t, k = h.s, big = i === 2;
+ if (q < -0.04 || q > 0.36) return;
+ // the fist's streak: lines racing in from the fighter the frame before it lands
+ if (q < 0.035) {
+ const e = seg(q, -0.04, 0.0);
+ for (const [dy, l] of [[0, 1], [-2, 0.6], [2, 0.7]]) {
+ const x1 = h.x - 2, x0 = 5 + (x1 - 5) * (1 - l) * e;
+ p.line(x0, h.y + dy * k, x1, h.y + dy * k, dy === 0 ? WHITE : C[top - 2]);
+ }
+ }
+ if (q < 0) return;
+ // the pop: a white ball for a frame, then a ring of little puffs blown outward that shrink away
+ if (q < 0.034) p.circle(h.x, h.y, 3.2 * k, WHITE), p.glow(h.x, h.y, 16 * k, C[top - 2], 0.6);
+ const n = big ? 8 : 6, spread = ease.outCubic(seg(q, 0, 0.18)), life = big ? 0.26 : 0.2;
+ burst(n, S + i * 7, (r, j) => {
+ // puffs blown mostly forward (the way the fist was going), each its own size, reach and life
+ const a = (j / n - 0.5) * 3.6 + r.range(-0.25, 0.25), d = (2 + r.range(4, 8) * spread) * k;
+ const rad = (r.range(1.8, 2.8) - 2.2 * seg(q, 0.05, life * r.range(0.8, 1.1))) * k;
+ if (rad < 0.5 || q < 0.034) return;
+ const x = h.x + Math.cos(a) * d, y = h.y + Math.sin(a) * d * 0.8;
+ p.circle(x, y, rad, (dd, an) => (dd < 0.5 && Math.sin(an) < 0.3 ? C[top] : q < 0.1 ? C[top - 1] : C[top - 2]));
+ });
+ if (q > 0.02 && q < 0.09) p.circle(h.x, h.y, (2.2 - 12 * (q - 0.02)) * k, q < 0.06 ? C[top] : C[top - 1]);
+ p.glow(h.x, h.y, 14 * k, C[top - 3], 0.35 * (1 - seg(q, 0, 0.2)));
+ if (!big) return;
+ // the straight: sharp rays shooting out, a thin ring, sparks
+ if (q < 0.14) {
+ const e = ease.outCubic(seg(q, 0, 0.14));
+ for (let j = 0; j < 8; j++) {
+ const a = (j / 8) * Math.PI * 2 + 0.2, r0 = (5 + 9 * e) * k * (j % 2 ? 0.8 : 1), r1 = r0 + (6 - 5 * e) * k * (j % 2 ? 0.6 : 1);
+ p.line(h.x + Math.cos(a) * r0, h.y + Math.sin(a) * r0, h.x + Math.cos(a) * r1, h.y + Math.sin(a) * r1, j % 2 ? C[top - 1] : WHITE);
+ }
+ }
+ const rg = seg(q, 0.02, 0.16);
+ if (rg > 0 && rg < 1) p.ring(h.x, h.y, (5 + 8 * ease.outCubic(rg)) * k, 1, rg < 0.5 ? C[top - 1] : C[top - 3]);
+ burst(5, S, (r) => {
+ const a = r.range(-1.2, 1.2), sp = r.range(60, 110), lf = r.range(0.12, 0.22), age = q - 0.02;
+ if (age < 0 || age > lf) return;
+ const [x, y] = fly(h.x, h.y, Math.cos(a) * sp, Math.sin(a) * sp, age, 140, 5), kk = age / lf;
+ p.px(x, y, kk < 0.4 ? WHITE : kk < 0.75 ? C[top - 1] : C[top - 3]);
+ p.light(x, y, C[top - 2], 0.4 * (1 - kk));
+ });
+ });
+}
diff --git a/src/fx/melee/scythe-reap.js b/src/fx/melee/scythe-reap.js
new file mode 100644
index 0000000..2287146
--- /dev/null
+++ b/src/fx/melee/scythe-reap.js
@@ -0,0 +1,62 @@
+import { ramp, at, burst, seg, ease, clamp, smooth, WHITE } from "../../core/index.js";
+
+export const meta = {
+ name: "Scythe reap",
+ desc: "A slow, huge reap: a dark crescent with a pale ghostly edge hangs in the air a beat, then tears away and leaves its ghost to rise, waver and fade.",
+ tags: ["melee", "slash", "scythe", "reaper", "dark", "ghost", "shadow", "combat", "directional", "one-shot"],
+ size: [72, 68],
+ origin: [22, 56],
+ duration: 0.9,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ actor: true,
+ options: { palette: ["#05030a", "#120a1e", "#24123a", "#3a1e5a", "#5a3a80", "#8a7ab0", "#bfe8d8", "#effff8"], radius: 30, seed: 13 },
+};
+
+export function draw(p, t, o) {
+ const C = ramp(o.palette), R = o.radius, S = o.seed, top = C.length - 1;
+ const cx = -2, cy = -10, A0 = -1.75, A1 = Math.asin(clamp((-1 - cy) / R)); // from overhead round to the floor in front
+ const lead = ease.outCubic(seg(t + 0.02, 0, 0.17)), tail = ease.inQuad(seg(t, 0.14, 0.5));
+ const la = A0 + (A1 - A0) * lead, ta = A0 + (A1 - A0) * tail, W = 11, tear = seg(t, 0.18, 0.55);
+ if (la - ta > 0.02) {
+ // the crescent: dark body, a pale edge on the outside, thickest a little behind the blade; as it tears away
+ // the body goes first and the ghostly edge lingers
+ p.arc(cx, cy, R, (u) => W * Math.pow(u, 0.5) * (u > 0.9 ? (1 - u) / 0.1 : 1) + 1, ta, la,
+ (u, v) => (v > 0.86 ? (u > 0.5 ? C[top] : C[top - 1]) : v > 0.72 ? C[top - 2] : at(C.slice(1, top - 2), v * 0.85 + u * 0.3)),
+ (u, v) => clamp(smooth(0, 0.3, u) * 1.5) * clamp(1.4 - (1 - u * 0.7) * tear * (v > 0.72 ? 1.6 : 3)));
+ const ex = cx + Math.cos(la) * (R - 3), ey = cy + Math.sin(la) * (R - 3);
+ p.glow(ex, ey, 16, C[top - 2], 0.3 * (1 - seg(t, 0.15, 0.5)));
+ p.glow(cx + Math.cos((la + ta) / 2) * R * 0.85, cy + Math.sin((la + ta) / 2) * R * 0.85, 26, C[top - 3], 0.22 * (1 - seg(t, 0.2, 0.55)));
+ }
+ // its ghost: where the crescent tore away, a pale copy of it lingers, rising and wavering, thinning from below
+ const g = seg(t, 0.2, 0.32) * (1 - seg(t, 0.5, 0.86));
+ if (g > 0) {
+ const rise = 14 * ease.outQuad(seg(t, 0.2, 0.86)), wob = 0.6 + 2.2 * seg(t, 0.2, 0.86), ph = t * 14;
+ const span = A1 - A0, x0 = cx - R - 4, x1 = cx + R + 4, y0 = cy - R - rise - 2, y1 = cy + R * Math.sin(A1) + 2 - rise;
+ p.shade(x0, y0, x1, y1, (x, y, out) => {
+ const sy = y + rise, sx = x - Math.sin(sy * 0.45 + ph) * wob, dx = sx - cx, dy = sy - cy, d = Math.sqrt(dx * dx + dy * dy);
+ if (d > R || d < R - 7) return;
+ let a = Math.atan2(dy, dx) - A0;
+ a -= Math.floor(a / 6.283185) * 6.283185;
+ const u = a / span;
+ if (u > 1) return;
+ const w = 7 * Math.pow(u, 0.5) * (u > 0.9 ? (1 - u) / 0.1 : 1) + 1, v = (d - (R - w)) / w;
+ if (v < 0) return;
+ out.c = v > 0.8 ? C[top - 1] : C[top - 2];
+ out.a = g * (v > 0.8 ? 0.95 : 0.4) * clamp(1.6 - (sy - (cy - R)) / (R * 1.4) * (1 - g) * 2.4);
+ out.k = 0.12 * g;
+ });
+ }
+ // a few souls slip out of it and float up
+ burst(6, S, (r, i) => {
+ const u = (i + r.range(0.2, 0.8)) / 6, ang = A0 + (A1 - A0) * u;
+ const born = 0.2 + 0.25 * Math.sqrt(u) + r.range(0, 0.05), age = t - born, life = r.range(0.28, 0.38);
+ if (age < 0 || age > life) return;
+ const k = age / life, x = cx + Math.cos(ang) * (R - 2) + Math.sin(age * 10 + i) * 2, y = cy + Math.sin(ang) * (R - 2) - age * r.range(30, 46);
+ p.dot(x, y, k < 0.5 ? C[top] : C[top - 1], clamp((1 - k) * 2.2));
+ p.dot(x, y + 1, C[top - 1], clamp((1 - k) * 1.6));
+ p.dot(x, y + 2, C[top - 2], clamp((1 - k) * 1.2));
+ p.light(x, y, C[top - 1], 0.3 * (1 - k));
+ });
+}
diff --git a/src/fx/melee/spear-sweep.js b/src/fx/melee/spear-sweep.js
new file mode 100644
index 0000000..46b2991
--- /dev/null
+++ b/src/fx/melee/spear-sweep.js
@@ -0,0 +1,99 @@
+import { PAL, ramp, at, burst, fly, seg, ease, clamp, smooth, wrap, TAU, WHITE } from "../../core/index.js";
+import { dustCloud } from "./_lib.js";
+
+export const meta = {
+ name: "Spear sweep",
+ desc: "A long polearm swept low around the front: a wide flat arc skims the floor from behind to the far side, kicking up a wake of dust.",
+ tags: ["melee", "sweep", "spear", "polearm", "low", "ground", "combat", "directional", "one-shot"],
+ size: [92, 40],
+ origin: [44, 32],
+ duration: 0.7,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ actor: true,
+ options: { palette: PAL.cyber, radius: 34, seed: 10 },
+};
+
+const DUST = ramp(["#2e2830", "#463e48", "#655b63", "#8a7f84", "#b0a5a6", "#d6cdc8"]);
+const P0 = Math.PI + 0.45, P1 = -0.4; // from behind on the left, round the front, to behind on the right
+const CY = -7;
+
+const leadAt = (t) => P0 + (P1 - P0) * ease.outCubic(seg(t + 0.02, 0, 0.22));
+const tailAt = (t) => P0 + (P1 - P0) * ease.inQuad(seg(t, 0.05, 0.34));
+
+function band(p, t, o, front) {
+ const C = ramp(o.palette), R = o.radius, ry = R * 0.24, top = C.length - 1;
+ const lead = leadAt(t), tail = tailAt(t), span = tail - lead, fade = seg(t, 0.2, 0.34);
+ if (span <= 0.03 || fade >= 1) return;
+ p.shade(-R - 1, CY - ry - 1, R + 1, CY + ry + 1, (x, y, out) => {
+ const nx = x / R, ny = (y - CY) / ry, d = Math.sqrt(nx * nx + ny * ny);
+ if (d > 1) return;
+ const ang = Math.atan2(ny, nx);
+ if (Math.sin(ang) >= 0 !== front) return;
+ const s = 1 - wrap(tail - ang, TAU) / span; // 0 at the tail .. 1 at the spear
+ if (s < 0) return;
+ const wdt = 0.55 * Math.pow(s, 0.7) * (s > 0.97 ? (1 - s) / 0.03 : 1) + 0.08;
+ if (d < 1 - wdt) return;
+ const v = (d - (1 - wdt)) / wdt;
+ out.c = v > 0.74 ? (front ? WHITE : C[top - 1]) : at(C.slice(1, top), v * 0.7 + s * 0.3 + (front ? 0.1 : -0.15));
+ out.a = clamp(smooth(0, 0.5, s) * (v > 0.74 ? 1.4 : 0.5 + v)) * (1 - fade * (1 - v * 0.5));
+ });
+ // the shaft itself at the edge: a bright line from the hands out to the tip
+ if (t < 0.24 && Math.sin(lead) >= 0 === front) {
+ const ex = Math.cos(lead), ey = Math.sin(lead);
+ p.line(ex * 9, CY + ey * ry * 0.3, ex * R, CY + ey * ry, (u) => (u > 0.8 ? WHITE : C[top - 1]));
+ p.glow(ex * (R - 3), CY + ey * (ry - 1), 12, C[top - 3], 0.4 * (1 - seg(t, 0.15, 0.24)));
+ }
+}
+
+export function drawBack(p, t, o) {
+ band(p, t, o, false);
+}
+
+export function draw(p, t, o) {
+ const C = ramp(o.palette), R = o.radius, ry = R * 0.24, S = o.seed, top = C.length - 1;
+ // a wake of dust where the tip skims the floor across the front: low, flat, overlapping puffs that roll on
+ const puffs = [];
+ burst(20, S, (r, i) => {
+ const ang = P0 + (P1 - P0) * (0.32 + 0.56 * (i + r.range(0, 1)) / 20); // along the front of the sweep
+ const born = bornAt(ang) + r.range(0, 0.02), age = t - born, life = r.range(0.3, 0.42);
+ if (age < 0 || age > life || Math.sin(ang) < 0.2) return;
+ const k = age / life, push = ease.outCubic(seg(age, 0, 0.35));
+ puffs.push({
+ x: Math.cos(ang) * R * r.range(0.82, 0.98) + push * r.range(3, 9), y: -1 - push * r.range(1, 3.5) - age * 4,
+ r: r.range(3, 4.6) * (0.45 + 0.7 * push) * (1 - 0.85 * ease.inQuad(seg(k, 0.4, 1))), a: 1 - seg(k, 0.85, 1), sy: 0.6,
+ });
+ });
+ dustCloud(p, puffs, DUST, S, 0.22, 0.4);
+ band(p, t, o, true); // the blade over its own dust
+ // grit flicked up ahead of the blade
+ burst(8, S + 1, (r) => {
+ const ang = P0 + (P1 - P0) * r.range(0.3, 0.85), born = bornAt(ang), age = t - born, life = r.range(0.25, 0.4);
+ if (age < 0 || age > life || Math.sin(ang) < 0.1) return;
+ const x0 = Math.cos(ang) * R * 0.95, y0 = CY + Math.sin(ang) * ry, vx = Math.sin(ang) * r.range(40, 80);
+ const [x, y] = fly(x0, Math.min(y0, -1), vx, -r.range(40, 80), age, 320, 1);
+ if (y > 0) return;
+ p.px(x, y, at(DUST, r.range(0.5, 1)));
+ });
+ // glints off the spearhead as it whips past the front
+ burst(5, S + 2, (r) => {
+ const ang = P0 + (P1 - P0) * r.range(0.35, 0.8), born = bornAt(ang), age = t - born, life = r.range(0.12, 0.2);
+ if (age < 0 || age > life) return;
+ const x0 = Math.cos(ang) * R, y0 = CY + Math.sin(ang) * ry;
+ const [x, y] = fly(x0, y0, Math.sin(ang) * r.range(50, 90), -r.range(10, 40), age, 100, 4), k = age / life;
+ p.px(x, y, k < 0.5 ? WHITE : C[top - 1]);
+ p.light(x, y, C[top - 3], 0.4 * (1 - k));
+ });
+}
+
+// when the spear's edge passes an angle on its way round
+function bornAt(ang) {
+ let lo = 0, hi = 0.22;
+ for (let i = 0; i < 12; i++) {
+ const mid = (lo + hi) / 2;
+ if (leadAt(mid) > ang) lo = mid;
+ else hi = mid;
+ }
+ return lo;
+}
diff --git a/src/fx/melee/spin-slash.js b/src/fx/melee/spin-slash.js
new file mode 100644
index 0000000..6b87d8a
--- /dev/null
+++ b/src/fx/melee/spin-slash.js
@@ -0,0 +1,75 @@
+import { ramp, at, burst, fly, seg, ease, clamp, smooth, wrap, TAU, WHITE } from "../../core/index.js";
+
+export const meta = {
+ name: "Spin slash",
+ desc: "A full-circle spin attack: the blade sweeps a ring around the fighter's waist, front then back, and the ring flares out and dissolves.",
+ tags: ["melee", "slash", "spin", "sword", "aoe", "combat", "one-shot"],
+ size: [76, 48],
+ origin: [38, 38],
+ duration: 0.45,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ actor: true,
+ options: { palette: ["#04201c", "#0a3a30", "#12604a", "#1f8a62", "#3cb87a", "#7ee0a0", "#c8ffd8", "#ffffff"], radius: 26, seed: 4 },
+};
+
+// the swept band of the spin, front (sin > 0, in front of the body) or back half
+function band(p, t, o, front) {
+ const C = ramp(o.palette), R = o.radius, ry = R * 0.3, cy = -11, top = C.length - 1;
+ // the edge goes once round, left > front > right > back > left: angle runs from PI down to -PI
+ const lead = Math.PI - 0.25 - TAU * ease.outSine(seg(t + 0.03, 0, 0.25));
+ const tail = Math.PI - 0.25 - TAU * ease.inQuad(seg(t, 0, 0.3));
+ const span = tail - lead, fade = seg(t, 0.2, 0.32);
+ if (span > 0.03 && fade < 1) {
+ p.shade(-R - 1, cy - ry - 1, R + 1, cy + ry + 1, (x, y, out) => {
+ const nx = x / R, ny = (y - cy) / ry, d = Math.sqrt(nx * nx + ny * ny);
+ if (d > 1) return;
+ const ang = Math.atan2(ny, nx);
+ if (Math.sin(ang) >= 0 !== front) return;
+ const s = 1 - wrap(tail - ang, TAU) / span; // 0 at the tail .. 1 at the edge
+ if (s < 0) return;
+ const wdt = 0.55 * Math.pow(s, 0.6) * (s > 0.96 ? (1 - s) / 0.04 : 1) + 0.1;
+ if (d < 1 - wdt) return;
+ const v = (d - (1 - wdt)) / wdt; // 0 inner .. 1 rim
+ const near = front ? 0.12 : -0.18; // the far side sits deeper in the ramp
+ out.c = v > 0.78 ? (front ? WHITE : C[top - 1]) : at(C.slice(1, top), v * 0.75 + s * 0.25 + near);
+ out.a = clamp(smooth(0, 0.4, s) * (v > 0.78 ? 1.4 : 0.55 + v)) * (1 - fade * (1 - v * 0.5));
+ });
+ // light rides the edge
+ const lx = Math.cos(lead) * (R - 2), ly = cy + Math.sin(lead) * (ry - 1);
+ if (Math.sin(lead) >= 0 === front) p.glow(lx, ly, 10, C[top - 3], (front ? 0.4 : 0.2) * (1 - fade));
+ }
+ // the closed ring flares outward and dissolves once the spin is done
+ const ring = seg(t, 0.22, 0.38);
+ if (ring > 0 && ring < 1) {
+ const e = ease.outCubic(ring), rr = R + 6 * e, rry = ry + 2 * e;
+ p.shade(-rr - 1, cy - rry - 1, rr + 1, cy + rry + 1, (x, y, out) => {
+ const nx = x / rr, ny = (y - cy) / rry, d = Math.sqrt(nx * nx + ny * ny);
+ if (d > 1 || d < 1 - 1.2 / rry) return;
+ if ((y - cy >= 0) !== front) return;
+ out.c = ring < 0.3 ? (front ? WHITE : C[top - 1]) : front ? C[top - 1] : C[top - 3];
+ out.a = 1 - ring;
+ });
+ }
+}
+
+export function drawBack(p, t, o) {
+ band(p, t, o, false);
+}
+
+export function draw(p, t, o) {
+ const C = ramp(o.palette), R = o.radius, S = o.seed, top = C.length - 1;
+ band(p, t, o, true);
+ // glints flung off the edge, tangent to the spin
+ burst(9, S, (r) => {
+ const born = r.range(0.02, 0.2), age = t - born, life = r.range(0.14, 0.22);
+ if (age < 0 || age > life) return;
+ const ang = Math.PI - 0.25 - TAU * ease.outSine(seg(born + 0.03, 0, 0.25)), ry = R * 0.3;
+ const x0 = Math.cos(ang) * R, y0 = -11 + Math.sin(ang) * ry, sp = r.range(40, 80);
+ const [x, y] = fly(x0, y0, Math.sin(ang) * sp + Math.cos(ang) * 20, -r.range(20, 50), age, 150, 3), q = age / life;
+ p.px(x, y, q < 0.4 ? WHITE : C[top - 2]);
+ if (q < 0.3) p.px(x + 1, y, C[top - 1]), p.px(x - 1, y, C[top - 1]);
+ p.light(x, y, C[top - 3], 0.4 * (1 - q));
+ });
+}
diff --git a/src/fx/melee/sword-slash.js b/src/fx/melee/sword-slash.js
new file mode 100644
index 0000000..884614f
--- /dev/null
+++ b/src/fx/melee/sword-slash.js
@@ -0,0 +1,47 @@
+import { fit, at, burst, fly, seg, ease, clamp, smooth, TAU, WHITE } from "../../core/index.js";
+
+export const meta = {
+ name: "Sword slash",
+ desc: "A fast crescent smear: the white edge whips through in four frames, the tail catches up and dissolves, glints fly off.",
+ tags: ["melee", "slash", "sword", "combat", "directional", "one-shot"],
+ size: [72, 68],
+ origin: [26, 42],
+ duration: 0.4,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ actor: true,
+ options: { palette: ["#1f4f94", "#2f7fcc", "#58b4ec", "#9bdcff", "#d8f4ff", "#ffffff"], radius: 24, seed: 2 },
+};
+
+export function draw(p, t, o) {
+ const C = fit(o.palette, 6), R = o.radius, S = o.seed;
+ const A0 = -1.95, A1 = 0.62, cx = 1, cy = -13; // from over the shoulder to low in front
+ const lead = A0 + (A1 - A0) * ease.outQuart(seg(t, 0, 0.1));
+ const tail = A0 + (A1 - A0) * ease.inCubic(seg(t, 0.02, 0.24));
+ if (lead - tail > 0.02) {
+ const W = 9;
+ // the smear: thick behind the edge, tapering to nothing at the tail, a hard white rim outside
+ p.arc(cx, cy, R, (u) => W * Math.pow(u, 0.55) * (u > 0.94 ? (1 - u) / 0.06 : 1) + 1, tail, lead,
+ (u, v) => (v > 0.82 ? WHITE : at(C.slice(1), v * 0.9 + u * 0.15)),
+ (u, v) => clamp(smooth(0, 0.45, u) * (v > 0.82 ? 1.4 : 0.6 + v)) * (1 - seg(t, 0.14, 0.24) * (1 - v)));
+ // an inner echo, thinner, a beat behind
+ const echo = Math.max(tail, lead - 0.9);
+ if (lead - echo > 0.05) p.arc(cx, cy, R - 7, (u) => 2 * u, echo, lead - 0.15, C[3], (u) => 0.7 * u * (1 - seg(t, 0.12, 0.26)));
+ // light rides the edge
+ const lx = cx + Math.cos(lead) * (R - 3), ly = cy + Math.sin(lead) * (R - 3);
+ p.glow(lx, ly, 16, C[3], 0.5 * (1 - seg(t, 0.1, 0.35)));
+ }
+ // glints thrown off the edge as it passes
+ burst(7, S, (r) => {
+ const a = A0 + (A1 - A0) * r.range(0.25, 0.95), born = 0.13 * ease.inQuad(r.next()) + 0.01, life = r.range(0.14, 0.22);
+ const age = t - born;
+ if (age < 0 || age > life) return;
+ const sp = r.range(30, 70), dx = Math.cos(a), dy = Math.sin(a);
+ const [x, y] = fly(cx + dx * R, cy + dy * R, dx * sp - dy * 25, dy * sp + dx * 25, age, 40, 3);
+ const k = age / life;
+ if (k < 0.5) p.px(x - 1, y, C[4]), p.px(x + 1, y, C[4]), p.px(x, y - 1, C[4]), p.px(x, y + 1, C[4]);
+ p.px(x, y, WHITE);
+ p.light(x, y, C[3], 0.5 * (1 - k));
+ });
+}
diff --git a/src/fx/melee/thrust.js b/src/fx/melee/thrust.js
new file mode 100644
index 0000000..94329ee
--- /dev/null
+++ b/src/fx/melee/thrust.js
@@ -0,0 +1,66 @@
+import { PAL, ramp, burst, fly, seg, ease, WHITE } from "../../core/index.js";
+
+export const meta = {
+ name: "Thrust",
+ desc: "A piercing stab: a narrow lance of streaks shoots out in two frames, a sharp star flashes at the tip, speed lines and sparks run on past it.",
+ tags: ["melee", "thrust", "stab", "spear", "rapier", "combat", "directional", "one-shot"],
+ size: [76, 40],
+ origin: [10, 31],
+ duration: 0.4,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ actor: true,
+ options: { palette: PAL.gold, reach: 44, seed: 5 },
+};
+
+export function draw(p, t, o) {
+ const C = ramp(o.palette), R = o.reach, S = o.seed, top = C.length - 1;
+ const x0 = 5, y0 = -10; // the hand
+ const tipX = x0 + R * ease.outExpo(seg(t + 0.025, 0, 0.09)); // the tip shoots out in two frames
+ const tailX = x0 + R * ease.inCubic(seg(t, 0.05, 0.21)); // and the smear is pulled in after it
+ const len = tipX - tailX;
+ if (len > 1) {
+ // the lance: a bundle of streaks, the white one longest, the outer ones shorter and deeper, so it comes to a point
+ const rows = [[0, 0, 0, WHITE], [-1, 0.2, 2, C[top - 1]], [1, 0.2, 2, C[top - 1]], [-2, 0.4, 6, C[top - 3]], [2, 0.42, 6, C[top - 3]]];
+ const thin = seg(t, 0.09, 0.18); // the outer streaks drop away first
+ for (const [dy, from, back, c] of rows) {
+ if (Math.abs(dy) > 2 - Math.floor(thin * 2.5)) continue;
+ const a = tailX + len * from, b = tipX - back;
+ if (b - a >= 1) p.line(a, y0 + dy, b, y0 + dy, c);
+ }
+ p.px(tipX + 1, y0, WHITE);
+ p.glowLine(tailX, y0, tipX, y0, 7, C[top - 3], 0.3 * (1 - seg(t, 0.1, 0.22)));
+ }
+ // speed lines: thin streaks above and below, racing out with the lance, gone right after
+ burst(6, S + 2, (r, i) => {
+ const dy = (i % 2 ? 1 : -1) * r.range(5, 10), born = r.range(0, 0.05), age = t - born, life = r.range(0.08, 0.13);
+ if (age < 0 || age > life) return;
+ const q = age / life, head = x0 + 6 + R * r.range(0.5, 0.95) * ease.outCubic(seg(age, 0, 0.08)), l = r.range(6, 16) * (1 - q * 0.7);
+ p.line(head - l, y0 + dy, head, y0 + dy, q < 0.5 ? C[top - 1] : C[top - 3]);
+ });
+ // the tip flash: a sharp four-point star, long along the thrust, from the frame the lance lands
+ const fl = seg(t, 0.06, 0.07) * (1 - seg(t, 0.07, 0.24));
+ if (fl > 0) {
+ const tx = x0 + R + 1, e = Math.pow(fl, 1.4), H = Math.round(14 * e), V = Math.round(7 * e), hot = t < 0.1;
+ for (let i = -H; i <= H; i++) {
+ const w = Math.abs(i) / (H || 1);
+ p.px(tx + i, y0, w < 0.55 ? WHITE : C[top - 1]);
+ if (w < 0.25 && H > 5) p.px(tx + i, y0 - 1, hot ? WHITE : C[top - 1]), p.px(tx + i, y0 + 1, hot ? WHITE : C[top - 1]);
+ }
+ for (let j = -V; j <= V; j++) p.px(tx, y0 + j, Math.abs(j) / (V || 1) < 0.5 ? WHITE : C[top - 1]);
+ if (hot) p.circle(tx, y0, 3, WHITE);
+ p.glow(tx, y0, 20, C[top - 3], 0.5 * e);
+ p.glow(tx, y0, 6, C[top - 1], 0.6 * e);
+ }
+ // sparks carried on past the tip
+ burst(7, S, (r) => {
+ const born = 0.07 + r.range(0, 0.03), age = t - born, life = r.range(0.12, 0.22);
+ if (age < 0 || age > life) return;
+ const a = r.range(-0.7, 0.7), sp = r.range(60, 130), q = age / life;
+ const [x, y] = fly(x0 + R, y0, Math.cos(a) * sp, Math.sin(a) * sp, age, 60, 7);
+ p.px(x, y, q < 0.35 ? WHITE : q < 0.7 ? C[top - 1] : C[top - 3]);
+ if (q < 0.4) p.px(x - 1, y, C[top - 2]);
+ p.light(x, y, C[top - 2], 0.5 * (1 - q));
+ });
+}
diff --git a/src/fx/melee/uppercut.js b/src/fx/melee/uppercut.js
new file mode 100644
index 0000000..05b31bc
--- /dev/null
+++ b/src/fx/melee/uppercut.js
@@ -0,0 +1,62 @@
+import { PAL, ramp, burst, fly, seg, ease, star, clamp, WHITE } from "../../core/index.js";
+import { swing } from "./_lib.js";
+
+export const meta = {
+ name: "Uppercut",
+ desc: "A rising punch: a swoosh hooks up from the hip past the face, and a fat comic star bursts where the fist lands up high.",
+ tags: ["melee", "punch", "uppercut", "brawler", "launcher", "combat", "directional", "one-shot"],
+ size: [56, 62],
+ origin: [16, 52],
+ duration: 0.45,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ actor: true,
+ options: { palette: PAL.volt, size: 1, seed: 12 },
+};
+
+export function draw(p, t, o) {
+ const C = ramp(o.palette), k = o.size, S = o.seed, top = C.length - 1;
+ const cx = 1, cy = -13 * k, R = 15 * k, A0 = 0.8, A1 = -1.42; // from the hip, up and round past the face
+ const lead = ease.outQuart(seg(t + 0.02, 0, 0.1)), tail = ease.inCubic(seg(t, 0.02, 0.2));
+ swing(p, { cx, cy, r: R, w: 8 * k, from: A0, to: A1, lead, tail, C, rimAt: 0.74 });
+ const la = A0 + (A1 - A0) * lead;
+ if (t < 0.18) p.glow(cx + Math.cos(la) * (R - 3), cy + Math.sin(la) * (R - 3), 14 * k, C[top - 2], 0.4 * (1 - seg(t, 0.08, 0.18)));
+ // rising speed lines beside the swoosh
+ burst(4, S + 2, (r, i) => {
+ const born = 0.02 + i * 0.015, age = t - born, life = r.range(0.1, 0.16);
+ if (age < 0 || age > life) return;
+ const x = cx + R + r.range(1, 5) * k - i * 2, y = cy + r.range(-2, 6) * k - age * 140 * k, l = r.range(5, 9) * k * (1 - age / life);
+ p.line(x, y, x, y + l, (u) => (u < 0.4 ? C[top - 1] : C[top - 3]));
+ });
+ // the punch lands up high: a fat star pops with an overshoot, holds, then shrinks away spinning
+ const HIT = 0.085, q = t - HIT;
+ if (q < 0) return;
+ const fx = cx + Math.cos(A1) * (R + 2) + 2 * k, fy = cy + Math.sin(A1) * (R + 2) - 3 * k;
+ const grow = ease.outBack(seg(q, 0, 0.06), 2.2), shrink = 1 - ease.inQuad(seg(q, 0.12, 0.26)), s = grow * shrink;
+ if (s > 0.05) {
+ const hot = q < 0.034, rot = -Math.PI / 2 + q * 2.5;
+ if (!hot) p.poly(star(fx, fy, 5.2 * k * s, 11.5 * k * s, 8, rot), C[top - 3]); // an orange rim, comic style
+ p.poly(star(fx, fy, 4.2 * k * s, 10 * k * s, 8, rot), hot ? WHITE : C[top - 1]);
+ if (!hot) p.poly(star(fx, fy, 2.6 * k * s, 6 * k * s, 8, rot), WHITE);
+ if (s > 0.6) p.poly(star(fx, fy, 1.2 * k, 2.6 * k, 4, rot + 0.4), C[top - 1]);
+ p.glow(fx, fy, 22 * k, C[top - 2], 0.4 * s);
+ p.glow(fx, fy, 6 * k, WHITE, 0.4 * s);
+ }
+ // impact lines bursting out round the star
+ if (q < 0.12) {
+ const e = ease.outCubic(seg(q, 0, 0.12));
+ for (let i = 0; i < 7; i++) {
+ const a = -Math.PI / 2 + (i - 3) * 0.55 + (i % 2) * 0.15, r0 = (8 + 8 * e) * k, r1 = r0 + (5 - 4 * e) * k;
+ p.line(fx + Math.cos(a) * r0, fy + Math.sin(a) * r0, fx + Math.cos(a) * r1, fy + Math.sin(a) * r1, C[top - 1]);
+ }
+ }
+ // sparks thrown up off the hit
+ burst(8, S, (r) => {
+ const a = -Math.PI / 2 + r.range(-1.4, 1.4), sp = r.range(50, 110) * k, life = r.range(0.15, 0.28), age = q - r.range(0, 0.02);
+ if (age < 0 || age > life) return;
+ const [x, y] = fly(fx, fy, Math.cos(a) * sp, Math.sin(a) * sp, age, 200, 3), kk = age / life;
+ p.px(x, y, kk < 0.4 ? WHITE : kk < 0.75 ? C[top - 1] : C[top - 3]);
+ p.light(x, y, C[top - 2], 0.5 * (1 - kk));
+ });
+}
diff --git a/src/fx/melee/whip-crack.js b/src/fx/melee/whip-crack.js
new file mode 100644
index 0000000..28fdcf1
--- /dev/null
+++ b/src/fx/melee/whip-crack.js
@@ -0,0 +1,85 @@
+import { PAL, ramp, fit, burst, fly, seg, ease, lerp, WHITE } from "../../core/index.js";
+
+export const meta = {
+ name: "Whip crack",
+ desc: "A whip lashes out to the right: a loop rolls down its length, the tip snaps straight with a white crack and sparks, then the lash sags and fades.",
+ tags: ["melee", "whip", "lash", "crack", "combat", "directional", "one-shot"],
+ size: [92, 54],
+ origin: [26, 44],
+ duration: 0.55,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ actor: true,
+ options: { palette: PAL.volt, leather: ["#2a160c", "#4a2a16", "#6e4222", "#8e5a30", "#b07a48"], length: 46, seed: 11 },
+};
+
+const N = 28, HX = 5, HY = -11;
+const T0 = -0.03, DUR = 0.13, LAG = 0.1; // the handle swings over 0.13 s; the bend reaches the tip 0.1 s later
+
+// the whip as points, handle first: each bit of it turns from wound-back to straight out, later and faster
+// the further it is from the hand, so a loop rolls down to the tip and the tip flips over in a flash
+function rope(t, L) {
+ const pts = [[HX, HY]], l = L / N, crack = T0 + LAG + DUR * 0.3;
+ let x = HX, y = HY;
+ for (let i = 0; i < N; i++) {
+ const s = (i + 0.5) / N, start = T0 + s * LAG, win = DUR * (1 - 0.72 * s);
+ const k = ease.inOutCubic(seg(t, start, start + win));
+ const back = -1.45 - 1.75 * s; // wound back: up from the hand, curling over behind the head
+ const sag = 0.55 * s * s * ease.outQuad(seg(t, crack + 0.03, crack + 0.35)); // after the crack it droops
+ const th = lerp(back, 0.04 - 0.08 * s, k) + sag;
+ x += Math.cos(th) * l;
+ y += Math.sin(th) * l;
+ pts.push([x, y]);
+ }
+ return pts;
+}
+
+export function draw(p, t, o) {
+ const C = ramp(o.palette), Lc = fit(o.leather, 5), L = o.length, S = o.seed, top = C.length - 1;
+ const crack = T0 + LAG + DUR * 0.3, gone = seg(t, crack + 0.2, crack + 0.38);
+ // the tip's path just before the crack: a fast streak of light
+ if (t < crack + 0.05) {
+ for (let j = 1; j <= 4; j++) {
+ const a = rope(Math.max(0, t - j * 0.012), L)[N], b = rope(Math.max(0, t - (j - 1) * 0.012), L)[N];
+ const k = seg(t, crack - 0.07, crack) * (1 - seg(t, crack, crack + 0.05));
+ if (k > 0.25 * j) p.line(a[0], a[1], b[0], b[1], j < 2 ? WHITE : j < 3 ? C[top - 1] : C[top - 3]);
+ }
+ }
+ // the whip: a thick handle, a tapering lash, a pale popper at the tip; it frays from the tip as it goes
+ if (gone < 1) {
+ const pts = rope(t, L), keep = Math.round(N * (1 - gone));
+ for (let i = 0; i < keep; i++) {
+ const [x0, y0] = pts[i], [x1, y1] = pts[i + 1], s = i / N;
+ if (i < 4) p.line(x0, y0 + 1, x1, y1 + 1, Lc[1]), p.line(x0, y0, x1, y1, Lc[2]);
+ else {
+ p.line(x0, y0, x1, y1, s < 0.55 ? Lc[4] : Lc[3]);
+ if (s < 0.45) p.line(x0, y0 + 1, x1, y1 + 1, Lc[2]);
+ }
+ }
+ if (keep === N) p.px(pts[N][0], pts[N][1], Lc[4]);
+ }
+ // the crack: a white pop at the tip, crack lines jabbing out, a ring, sparks
+ const q = t - crack;
+ if (q >= 0) {
+ const [tx, ty] = [HX + L * 0.985, HY + 0.5]; // where the tip snaps straight
+ if (q < 0.034) p.circle(tx, ty, 3, WHITE), p.glow(tx, ty, 20, C[top - 1], 0.7);
+ if (q < 0.1) {
+ const e = 1 - seg(q, 0.02, 0.1);
+ for (const [a, len] of [[-1.1, 7], [-0.35, 9], [0.4, 8], [1.15, 6], [-2.3, 5], [2.4, 5]]) {
+ const r0 = 3 + 4 * seg(q, 0, 0.1), r1 = r0 + len * e;
+ p.line(tx + Math.cos(a) * r0, ty + Math.sin(a) * r0, tx + Math.cos(a) * r1, ty + Math.sin(a) * r1, (u) => (u < 0.5 ? WHITE : C[top - 1]));
+ }
+ }
+ const rg = seg(q, 0.01, 0.09);
+ if (rg > 0 && rg < 1) p.ring(tx, ty, 4 + 7 * ease.outCubic(rg), 1, rg < 0.5 ? C[top - 1] : C[top - 3], (v, a) => (Math.sin(a * 3 + 1) > -0.45 ? 1 : 0));
+ p.glow(tx, ty, 16, C[top - 2], 0.5 * (1 - seg(q, 0, 0.2)));
+ burst(9, S, (r) => {
+ const a = r.range(-Math.PI, Math.PI), sp = r.range(50, 120), life = r.range(0.14, 0.3);
+ if (q > life) return;
+ const [x, y] = fly(tx, ty, Math.cos(a) * sp, Math.sin(a) * sp, q, 160, 4), k = q / life;
+ p.px(x, y, k < 0.35 ? WHITE : k < 0.7 ? C[top - 1] : C[top - 3]);
+ p.light(x, y, C[top - 2], 0.5 * (1 - k));
+ });
+ }
+}
diff --git a/src/fx/nature/acid-splash.js b/src/fx/nature/acid-splash.js
new file mode 100644
index 0000000..3b400e8
--- /dev/null
+++ b/src/fx/nature/acid-splash.js
@@ -0,0 +1,112 @@
+import { ramp, at, burst, stream, fly, flyV, seg, ease, clamp, noise, TAU, hex } from "../../core/index.js";
+
+export const meta = {
+ name: "Acid splash",
+ desc: "A gob of acid drops and bursts into a crown, its tips flung off as droplets, then lies as a hissing puddle: bubbles pop, steam curls up, it eats itself away.",
+ tags: ["nature", "acid", "poison", "splash", "ground", "one-shot"],
+ size: [72, 52],
+ origin: [36, 44],
+ duration: 1.6,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ options: {
+ palette: ["#1d2208", "#35420c", "#55700f", "#7fa214", "#acd21c", "#d8f040", "#f6ffa6"],
+ size: 1,
+ seed: 11,
+ },
+};
+
+const STEAM = ["#56653f", "#7a8b55", "#a3b273", "#cdd8a0"].map(hex);
+const T0 = 0.1; // impact
+const GROW = 0.1; // the crown rises for this long, then its tips break off
+
+export function draw(p, t, o) {
+ const C = ramp(o.palette), S = o.seed, k = o.size;
+ // the gob falls in fast, stretched by its speed
+ if (t < T0) {
+ const y = -36 + 36 * ease.inQuad(t / T0);
+ p.line(0, y - 8, 0, y - 4, C[3]);
+ p.rect(-1, y - 4, 2, 4, C[4]);
+ p.px(-1, y - 4, C[6]);
+ p.light(0, y - 2, C[5], 0.4);
+ return;
+ }
+ const a = t - T0, end = 1 - seg(t, 1.3, 1.58);
+ // the puddle: spreads in a blink, sits, then eats itself away from the rim inward
+ const spread = ease.outCubic(seg(a, 0, 0.16)), shrink = ease.inQuad(seg(a, 0.7, 1.4));
+ const rx = 16 * k * spread * (1 - 0.7 * shrink), ry = 3 * k * spread * (1 - 0.5 * shrink);
+ if (rx > 1) {
+ p.shade(-rx - 3, -ry - 1, rx + 3, ry + 1, (x, y, out) => {
+ const ang = Math.atan2(y, x), wob = 1 + 0.16 * noise(ang * 2.2 + 9, S) + 0.05 * noise(a * 9 + ang * 4, S + 1);
+ const dx = x / (rx * wob), dy = y / (ry * wob), d = Math.sqrt(dx * dx + dy * dy);
+ if (d > 1) return;
+ out.a = 1 - seg(a, 1.15, 1.45);
+ if (d > 0.78) return dy > 0 ? C[2] : C[3];
+ return dy < -0.2 && dx > -0.55 && dx < 0.2 ? C[5] : at([C[3], C[4]], 1.1 - d);
+ });
+ }
+ // hero frame: a flat white-hot splat and a flash
+ if (a < 0.067) {
+ p.ellipse(0, -1, 11 * k, 4 * k, (d) => (d < 0.45 ? C[6] : d < 0.8 ? C[5] : C[4]));
+ p.glow(0, -3, 28 * k, C[5], 0.6);
+ }
+ // the crown: horns of acid thrown up from the rim; at the top their tips pinch off and fly
+ burst(7, S + 4, (r, i) => {
+ const u = (i / 6) * 2 - 1, x0 = u * 9 * k, side = u < 0 ? -1 : u > 0 ? 1 : r.sign();
+ const H = r.range(7, 14) * k * (1 - Math.abs(u) * 0.25), lean = side * r.range(2, 5) * (0.4 + Math.abs(u));
+ const rise = ease.outCubic(seg(a, 0, GROW)), fall = ease.inQuad(seg(a, GROW, GROW + 0.12));
+ const h = H * rise * (1 - fall), tx = x0 + lean * rise, ty = -1 - h;
+ if (h >= 1) {
+ if (h > 3) p.beam(x0, -1, x0 + (tx - x0) * 0.55, -1 - h * 0.55, 2.4, (q, v) => (v > 0.6 && q < 0.5 ? C[3] : C[4]));
+ p.line(x0, -1, tx, ty, (q) => (q > 0.6 ? C[5] : C[4]));
+ }
+ // the tip: a droplet riding the horn, then flung up and out
+ const vx = side * r.range(18, 46) * k, vy = -r.range(35, 75) * k, g = 420, y0 = -1 - H, x1 = x0 + lean;
+ const land = (-vy + Math.sqrt(vy * vy - 2 * g * y0)) / g, da = a - GROW;
+ if (da < 0) {
+ if (rise > 0.3) p.rect(tx - 0.5, ty - 1.5, 2, 2, C[5]), p.px(tx - 0.5, ty - 1.5, C[6]);
+ } else if (da < land) {
+ const [x, y] = fly(x1, y0, vx, vy, da, g), [ux, uy] = flyV(vx, vy, da, g);
+ p.line(x, y, x - ux * 0.03, y - uy * 0.03, C[4]);
+ if (i % 3) p.rect(x - 0.5, y - 0.5, 2, 2, C[5]);
+ p.px(x - 0.5, y - 0.5, C[6]);
+ p.light(x, y, C[5], 0.35);
+ } else if (da < land + 0.5) {
+ const x = x1 + vx * land, q = (da - land) / 0.5;
+ p.px(x, 0, q < 0.3 ? C[5] : C[3]);
+ if (q < 0.6) p.px(x + side, 0, C[2]), p.px(x - side, 0, C[3]);
+ }
+ });
+ // a spray of fine drops off the splat
+ burst(8, S, (r, i) => {
+ const side = i % 2 ? 1 : -1, vx = side * r.range(30, 70) * k, vy = -r.range(40, 90) * k, g = 420;
+ const land = (-2 * vy) / g, age = a - r.range(0, 0.04);
+ if (age < 0 || age > land) return;
+ const [x, y] = fly(side * 3, 0, vx, vy, age, g);
+ p.px(x, y, age < land * 0.5 ? C[6] : C[5]);
+ });
+ // sizzle: bubbles swell on the surface and pop
+ stream(t, T0 + 0.2, T0 + 1.1, 18, S + 2, (r) => r.range(0.18, 0.3), (age, life, r) => {
+ const q = age / life, x = r.range(-0.75, 0.75) * rx, y = r.range(-0.4, 0.3) * ry;
+ if (q < 0.75) {
+ const s = 0.6 + 1.4 * ease.outQuad(q / 0.75) * r.range(0.6, 1);
+ p.circle(x, y - s * 0.6, s, (d, ang) => (d > 0.6 && ang > 0 ? C[3] : C[5]));
+ p.px(x - s * 0.4, y - s, C[6]);
+ } else {
+ for (const [ox, oy] of [[-2, 0], [2, 0], [-1, -2], [1, -2]]) p.px(x + ox, y + oy - 1, C[5]);
+ }
+ });
+ // steam: thin wavy wisps hiss up off the puddle and thin out
+ stream(t, T0 + 0.15, T0 + 1.15, 10, S + 3, (r) => r.range(0.5, 0.75), (age, life, r) => {
+ const q = age / life, x0 = r.range(-0.75, 0.75) * 14 * k, y0 = -4 - ease.outQuad(q) * r.range(10, 18) * k;
+ const len = Math.round(r.range(5, 8) * (1 - 0.45 * q)), ph = r.range(0, TAU), al = clamp(1.8 - q * 1.9) * end;
+ for (let j = 0; j < len; j++) {
+ const x = x0 + Math.round(Math.sin(ph + j * 0.9 + q * 6) * 1.2);
+ p.dot(x, y0 + j, j < 2 ? STEAM[3] : j < 4 ? STEAM[2] : STEAM[1], al);
+ }
+ });
+ const L = 1 - seg(a, 0, 0.35), fade = 1 - seg(a, 0.6, 1.4);
+ p.glow(0, -3, 22 * k, C[4], 0.08 * fade + 0.32 * L * L);
+ p.glow(0, 0, 14 * k, C[5], 0.12 * fade);
+}
diff --git a/src/fx/nature/boulder.js b/src/fx/nature/boulder.js
new file mode 100644
index 0000000..007f867
--- /dev/null
+++ b/src/fx/nature/boulder.js
@@ -0,0 +1,97 @@
+import { PAL, ramp, burst, fly, seg, ease, clamp, lerp, TAU, hex } from "../../core/index.js";
+
+export const meta = {
+ name: "Boulder",
+ desc: "A boulder is hurled right in a high arc, spinning, speed lines behind it; it slams into the floor and bursts into tumbling chunks and a cloud of dust.",
+ tags: ["nature", "earth", "rock", "projectile", "throw", "directional", "one-shot"],
+ size: [104, 60],
+ origin: [14, 52],
+ duration: 1.3,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ options: { palette: PAL.stone, distance: 60, size: 7, seed: 43 },
+};
+
+const DUST = ["#2c2a32", "#47444f", "#6a6672", "#928e99"].map(hex);
+const FLIGHT = 0.42;
+
+// the flight: from the hand (0, -16) up over a hump and down onto the floor at x = distance
+function pos(t, o) {
+ const k = clamp(t / FLIGHT), R = o.size;
+ const x = o.distance * k, y = lerp(-16, -R, k) - Math.sin(k * Math.PI) * 18;
+ return [x, y];
+}
+
+// a lumpy rock lit from the top left; the cracks turn with its spin
+function rock(p, C, x, y, R, spin) {
+ p.shade(x - R - 1, y - R - 1, x + R + 1, y + R + 1, (px, py) => {
+ const dx = px - x, dy = py - y, a = Math.atan2(dy, dx);
+ const lump = R * (1 + 0.1 * Math.sin(a * 3 + spin) + 0.06 * Math.sin(a * 5 - spin * 2));
+ const d = Math.hypot(dx, dy);
+ if (d > lump) return;
+ if (d > lump - 1) return dy + dx * 0.3 > 0 ? C[1] : C[3];
+ const lit = (-dx * 0.7 - dy) / R, crack = Math.abs(Math.sin(a * 2 + spin) * d - 1.2) < 0.5 && d > 1.5 && d < lump - 1.5;
+ if (crack) return C[2];
+ return lit > 0.6 ? C[6] : lit > 0.1 ? C[5] : lit > -0.4 ? C[4] : C[3];
+ });
+}
+
+export function draw(p, t, o) {
+ const C = ramp(o.palette), S = o.seed, R = o.size, D = o.distance;
+ if (t < FLIGHT) {
+ const [x, y] = pos(t, o);
+ // speed lines trailing behind, along the path
+ for (let i = 0; i < 3; i++) {
+ const [tx, ty] = pos(Math.max(0, t - 0.06 - (i % 2) * 0.03), o), [bx, by] = pos(Math.max(0, t - 0.02), o);
+ const nx = -(by - ty), ny = bx - tx, l = Math.hypot(nx, ny) || 1, off = (i - 1) * 3.5;
+ if (t > 0.04) p.line(tx + (nx / l) * off, ty + (ny / l) * off, bx + (nx / l) * off * 0.8, by + (ny / l) * off * 0.8, i === 1 ? C[6] : C[4]);
+ }
+ rock(p, C, x, y, R, t * 24);
+ return;
+ }
+ const a = t - FLIGHT, gx = D, gy = 0;
+ // impact: a white frame, a dent in the floor, the glow drops fast
+ if (a < 0.07) {
+ rock(p, C, gx, -R * 0.7, R * 1.15, 10);
+ p.ellipse(gx, -R * 0.5, R + 4, R * 0.9, C[7], (d) => (d > 0.75 ? 1 : 0));
+ p.glow(gx, -R * 0.5, 30, C[6], 0.45);
+ }
+ const crack = 1 - seg(a, 0.6, 0.85);
+ if (crack > 0) {
+ p.line(gx - 9, 0, gx + 9, 0, C[0], crack);
+ p.line(gx - 3, 1, gx - 6, 2, C[0], crack);
+ p.line(gx + 3, 1, gx + 7, 2, C[0], crack);
+ }
+ // dust: puffs that roll out low along the floor and lift
+ burst(9, S, (r, i) => {
+ const life = r.range(0.5, 0.8), q = a / life;
+ if (q >= 1) return;
+ const side = i % 3 === 0 ? -1 : 1, e = ease.outCubic(Math.min(1, q * 1.8));
+ const x = gx + side * r.range(3, 20) * e, y = -2 - r.range(1, 8) * e - q * 4;
+ const rad = r.range(2.5, 5) * (0.6 + 0.6 * e) * (1 - 0.9 * ease.inQuad(q));
+ p.circle(x, y, rad, (d, an) => (d < 0.5 && an < -0.3 ? DUST[3] : d < 0.85 ? DUST[2] : DUST[1]));
+ });
+ // chunks: the rock splits and its pieces bounce on forward, tumbling
+ burst(7, S + 1, (r, i) => {
+ const life = r.range(0.55, 0.8);
+ if (a > life) return;
+ const vx = r.range(-35, 48), vy = -r.range(50, 105), s = r.range(2, 3.6), g = 340;
+ // one bounce: after landing it hops again, lower
+ const t1 = (-2 * vy) / g;
+ let x, y;
+ if (a < t1) [x, y] = fly(gx, -s, vx, vy, a, g);
+ else [x, y] = fly(gx + vx * t1, -s, vx * 0.6, vy * 0.35, a - t1, g);
+ if (y > -s) y = -s;
+ const sz = s * (1 - ease.inQuad(seg(a, life * 0.6, life)));
+ if (sz > 0.6) p.circle(x, y, sz, (d, an) => (an < -0.6 && an > -2.6 && d > 0.3 ? C[5] : d > 0.7 ? C[2] : C[3]));
+ });
+ // gravel: little bits sprayed out
+ burst(12, S + 2, (r) => {
+ const life = r.range(0.3, 0.5);
+ if (a > life) return;
+ const ang = -Math.PI / 2 + r.range(-1.2, 1), sp = r.range(45, 95);
+ const [x, y] = fly(gx, -3, Math.cos(ang) * sp, Math.sin(ang) * sp, a, 360);
+ if (y < 0) p.px(x, y, C[r.int(3, 6)]);
+ });
+}
diff --git a/src/fx/nature/earth-spike.js b/src/fx/nature/earth-spike.js
new file mode 100644
index 0000000..cb783b5
--- /dev/null
+++ b/src/fx/nature/earth-spike.js
@@ -0,0 +1,128 @@
+import { ramp, burst, fly, seg, ease, clamp, lerp, rand, hex } from "../../core/index.js";
+
+export const meta = {
+ name: "Earth spike",
+ desc: "The floor cracks, then a jagged stone spike rams up in two frames with two smaller shards, throwing chips and dust; it holds, splits, and bursts into falling rubble.",
+ tags: ["nature", "earth", "rock", "spike", "stone", "ground", "one-shot"],
+ size: [72, 60],
+ origin: [36, 52],
+ duration: 1.3,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ options: { palette: ["#17121a", "#2b2430", "#443a46", "#5f5359", "#806f6e", "#a39087", "#c9b6a5", "#eee2d2"], height: 34, seed: 41 },
+};
+
+const DUST = ["#3a3230", "#5a4e48", "#7e7068", "#a4968a"].map(hex);
+const T_UP = 0.1, T_BREAK = 0.86;
+
+// a jagged spike: outline points from the left foot up to the tip and down to the right foot
+function spikePts(x0, w, h, lean, S) {
+ const L = [], R = [];
+ for (let i = 0; i <= 5; i++) {
+ const v = i / 5, j = i > 0 && i < 5 ? (rand(S, i, 1) - 0.5) * 2.2 * (1 - v) : 0;
+ const cx = x0 + lean * v * h * 0.25, hw = w * Math.pow(1 - v, 0.95);
+ L.push([cx - hw + j, -v * h]);
+ R.push([cx + hw + (rand(S, i, 2) - 0.5) * 1.6 * (1 - v), -v * h]);
+ }
+ return { pts: [...L, ...R.slice(0, -1).reverse()], tip: L[5], foot: x0 + w * 0.25 };
+}
+
+function spike(p, C, s, h) {
+ const { pts, tip, foot } = s;
+ // two faces split by the ridge from the tip to the foot: lit left, shadowed right, dark right rim
+ p.poly(pts, (x, y) => {
+ const v = -y / h, ridge = lerp(foot, tip[0], v);
+ if (x > ridge) return x > ridge + (1 - v) * 4.5 ? C[2] : C[3];
+ const band = Math.floor((-y + 2) / 6) % 2 === 1 && v < 0.8;
+ return v > 0.72 ? C[6] : band ? C[4] : C[5];
+ });
+ p.line(tip[0], tip[1], foot, 0, C[6], (u) => (u < 0.5 ? 1 : 0));
+}
+
+export function draw(p, t, o) {
+ const C = ramp(o.palette), S = o.seed, H = o.height;
+ // anticipation: the floor splits and pebbles hop
+ const crack = seg(t, 0, 0.08) * (1 - seg(t, 1.0, 1.25));
+ if (crack > 0) {
+ const reach = 4 + 12 * ease.outCubic(seg(t, 0, 0.12));
+ for (const sx of [-1, 1]) {
+ let x = 0, y = 0;
+ for (let i = 0; i < 6 && Math.abs(x) < reach; i++) {
+ const nx = x + sx * (2 + rand(S, i, sx + 3) * 2), ny = rand(S, i, sx + 5) < 0.5 ? 0 : 1;
+ p.line(x, y, nx, ny, C[0], crack);
+ (x = nx), (y = ny);
+ }
+ }
+ }
+ if (t < T_UP) {
+ burst(4, S + 9, (r) => p.px(r.range(-7, 7), -1 - Math.abs(Math.sin(t * r.range(50, 70))) * 2, C[3]));
+ }
+ // the spikes: ram up with a hair of overshoot, the big one first; a tremor while they settle
+ const up = (d) => ease.outExpo(seg(t, T_UP + d, T_UP + d + 0.07)) * (1 + 0.06 * Math.sin(seg(t, T_UP + d + 0.07, 0.32) * Math.PI));
+ const shake = t > T_UP + 0.07 && t < 0.3 ? Math.round(Math.sin(t * 90)) * 0.6 : 0;
+ const crackUp = seg(t, 0.74, T_BREAK);
+ if (t < T_BREAK) {
+ const spikes = [[-8, 4.5, H * 0.45, -1.2, 0.05], [9, 4, H * 0.32, 1.2, 0.08], [shake, 8, H, 0.25, 0]];
+ for (const [x0, w, hh, lean, d] of spikes) {
+ const h = hh * up(d);
+ if (h < 1) continue;
+ spike(p, C, spikePts(x0, w, h, lean, S + x0), h);
+ }
+ // just before it goes: cracks race up the big spike and it flashes
+ if (crackUp > 0) {
+ const h = H * up(0);
+ p.polyline([[1, -1], [-1, -h * 0.3 * crackUp], [2, -h * 0.55 * crackUp], [0, -h * 0.8 * crackUp]], C[1]);
+ if (crackUp > 0.85) p.poly(spikePts(shake, 8, h, 0.25, S).pts, C[7]);
+ }
+ }
+ // rubble ring at the foot
+ if (t > T_UP && t < 1.15) {
+ for (const [x, s] of [[-14, 2], [-12, 1], [14, 2], [16, 1]]) {
+ p.rect(x - s / 2, -s, s, s, C[x < 0 ? 4 : 2]);
+ p.px(x - s / 2, -s, C[5]);
+ }
+ }
+ // the hit: dust bursting out low and wide, chips thrown high
+ const da = t - T_UP;
+ if (da > 0) {
+ burst(10, S + 1, (r, i) => {
+ const life = r.range(0.45, 0.7), q = da / life;
+ if (q >= 1) return;
+ const side = i % 2 ? 1 : -1, e = ease.outCubic(Math.min(1, q * 2));
+ const x = side * (4 + r.range(6, 18) * e), y = -2 - r.range(1, 6) * q - q * 3;
+ const rad = r.range(2.5, 4.5) * (1 - ease.inQuad(q) * 0.85);
+ p.circle(x, y, rad, (d, a) => (d < 0.5 && a < -0.3 ? DUST[3] : d < 0.85 ? DUST[2] : DUST[1]));
+ });
+ burst(9, S + 2, (r) => {
+ const life = r.range(0.4, 0.6);
+ if (da > life) return;
+ const a = -Math.PI / 2 + r.range(-1, 1), sp = r.range(55, 105);
+ const [x, y] = fly(Math.cos(a) * 3, -6, Math.cos(a) * sp, Math.sin(a) * sp, da, 380);
+ if (y > 0) return;
+ const s = r.next() < 0.4 ? 2 : 1;
+ p.rect(x, y, s, s, C[r.int(3, 5)]);
+ });
+ if (da < 0.06) p.glow(0, -H * 0.4, 30, C[6], 0.35);
+ }
+ // the break: the spike bursts into chunks that tumble down and crumble
+ const ba = t - T_BREAK;
+ if (ba >= 0) {
+ burst(14, S + 3, (r, i) => {
+ const life = r.range(0.28, 0.42);
+ if (ba > life) return;
+ const v = (i + r.next()) / 14, y0 = -H * v, x0 = r.range(-1, 1) * 7 * (1 - v);
+ const [x, y] = fly(x0, y0, x0 * r.range(4, 9) + r.range(-12, 12), -r.range(10, 45), ba, 340);
+ if (y > 0) return;
+ const s = Math.round((1 - v) * 2.5 + r.range(1.5, 2.5));
+ p.rect(x - s / 2, y - s / 2, s, s, x0 > 0 ? C[3] : C[4]);
+ p.px(x - s / 2, y - s / 2, C[6]);
+ });
+ burst(6, S + 4, (r, i) => {
+ const life = r.range(0.3, 0.42), q = ba / life;
+ if (q >= 1) return;
+ const x0 = r.range(-8, 8), x = x0 + q * x0 * 0.6, y = -r.range(2, H * 0.6) - q * 6, rad = r.range(2.5, 4) * (1 - ease.inQuad(q) * 0.9);
+ p.circle(x, y, rad, (d, a) => (d < 0.5 && a < -0.3 ? DUST[3] : d < 0.85 ? DUST[2] : DUST[1]));
+ });
+ }
+}
diff --git a/src/fx/nature/healing-bloom.js b/src/fx/nature/healing-bloom.js
new file mode 100644
index 0000000..9bcc5c3
--- /dev/null
+++ b/src/fx/nature/healing-bloom.js
@@ -0,0 +1,99 @@
+import { PAL, ramp, burst, fly, seg, ease, clamp, lerp, TAU, hex } from "../../core/index.js";
+
+export const meta = {
+ name: "Healing bloom",
+ desc: "A sprout shoots up and a bud swells and opens into a flower with a glowing heart; a ring of green light pulses out and the petals lift off as glowing motes.",
+ tags: ["nature", "heal", "flower", "plant", "buff", "ground", "one-shot"],
+ size: [64, 64],
+ origin: [32, 56],
+ duration: 2,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ options: { palette: PAL.heal, seed: 37 },
+};
+
+const PETAL = ["#7a2e5a", "#c4508a", "#f08ab8", "#ffc8de", "#fff4f8"].map(hex);
+const STALK = ["#163a1c", "#2c6a2c", "#4c9a3a", "#86cc58"].map(hex);
+const N = 6;
+const T_OPEN = 0.45;
+
+export function draw(p, t, o) {
+ const C = ramp(o.palette), S = o.seed;
+ const out = 1 - seg(t, 1.45, 1.85); // the whole plant shrinks back into the floor at the end
+ const grow = ease.outCubic(seg(t, 0, 0.3)) * ease.outQuad(out);
+ const H = 18 * grow;
+ if (H > 0.5) {
+ // the stalk with a slight S curve, two leaves unfurling off it
+ const sway = Math.sin(t * 5) * 0.6 * seg(t, 0.3, 0.6);
+ const pts = [];
+ for (let i = 0; i <= 8; i++) {
+ const v = i / 8;
+ pts.push([Math.sin(v * Math.PI) * 1.4 + sway * v, -v * H]);
+ }
+ for (let i = 1; i < pts.length; i++) {
+ p.line(pts[i - 1][0], pts[i - 1][1], pts[i][0], pts[i][1], STALK[2]);
+ p.px(pts[i][0] + 1, pts[i][1], STALK[1]);
+ }
+ const lf = ease.outBack(seg(t, 0.12, 0.35), 2) * out;
+ if (lf > 0.1) {
+ const ly = -H * 0.35, l = 5 * lf;
+ p.poly([[1, ly], [1 + l * 0.6, ly - l * 0.7], [1 + l * 1.2, ly - l * 0.4], [1 + l * 0.5, ly + 0.5]], STALK[3]);
+ p.line(1, ly, 1 + l * 1.1, ly - l * 0.45, STALK[2]);
+ const ry = -H * 0.55;
+ p.poly([[0, ry], [-l * 0.6, ry - l * 0.7], [-l * 1.2, ry - l * 0.4], [-l * 0.5, ry + 0.5]], STALK[2]);
+ p.line(0, ry, -l * 1.1, ry - l * 0.45, STALK[1]);
+ }
+ }
+ const head = [Math.sin(Math.PI) * 1.4 + Math.sin(t * 5) * 0.6 * seg(t, 0.3, 0.6), -H];
+ // the bud swells, then the petals unfold outward with an overshoot
+ const bud = ease.outBack(seg(t, 0.2, 0.4), 2) * out;
+ const open = ease.outBack(seg(t, T_OPEN, T_OPEN + 0.22), 1.8);
+ const lift = seg(t, 1.0, 1.5); // the petals let go one by one
+ for (let i = 0; i < N; i++) {
+ const a0 = -Math.PI / 2 + ((i - (N - 1) / 2) / N) * Math.PI * 1.25;
+ const free = seg(lift, i / N * 0.6, i / N * 0.6 + 0.3);
+ if (free > 0) continue;
+ const a = lerp(-Math.PI / 2 + (a0 + Math.PI / 2) * 0.15, a0, open), len = lerp(3, 8, Math.min(1, open)) * bud;
+ if (len < 1) continue;
+ const x1 = head[0] + Math.cos(a) * len, y1 = head[1] + Math.sin(a) * len;
+ p.beam(head[0], head[1], x1, y1, 3.6 * Math.min(1, bud), (u, v) => (v > 0.62 ? PETAL[1] : u > 0.72 ? PETAL[3] : PETAL[2]));
+ if (open > 0.5) p.px(head[0] + Math.cos(a) * (len - 1.5), head[1] + Math.sin(a) * (len - 1.5) - 0.5, PETAL[4]);
+ }
+ if (bud > 0.2 && lift < 1) {
+ // the heart: gold-green, glowing hard as it opens
+ const hk = open > 0 ? 1 : 0.5;
+ p.circle(head[0], head[1], 1.6 * Math.min(1, bud), open > 0 ? C[6] : STALK[3]);
+ if (open > 0) p.px(head[0], head[1], C[7]);
+ p.glow(head[0], head[1], 16, C[5], 0.35 * hk * (1 - lift));
+ }
+ // the pulse: a flash and a ring of healing light spreading over the floor
+ const pk = seg(t, T_OPEN, T_OPEN + 0.5);
+ if (pk > 0 && pk < 1) {
+ const r = 4 + 24 * ease.outCubic(pk);
+ p.ellipse(0, 0, r, r * 0.22, pk < 0.4 ? C[7] : C[5], (d) => (d > 1 - 0.3 * (1 - pk) ? 1 : 0));
+ p.glowRing(0, 0, r * 0.6, 6, C[5], 0.25 * (1 - pk));
+ if (pk < 0.12) p.circle(head[0], head[1], 5, C[7]);
+ }
+ // petals set free: lift and spiral up, turning into glowing motes
+ burst(N, S, (r, i) => {
+ const born = 1.0 + (i / N) * 0.3, age = t - born, life = r.range(0.55, 0.72);
+ if (age < 0 || age > life) return;
+ const k = age / life, a0 = -Math.PI / 2 + ((i - (N - 1) / 2) / N) * Math.PI * 1.25;
+ const x = head[0] + Math.cos(a0) * 6 + Math.sin(age * 7 + i) * 3, y = head[1] + Math.sin(a0) * 6 - ease.outQuad(k) * 22;
+ if (k < 0.45) p.sprite(age * 12 % 2 < 1 ? ["ab", "b."] : [".a", "ab"], { a: PETAL[2], b: PETAL[4] }, x, y);
+ else p.px(x, y, k < 0.75 ? C[7] : C[6]);
+ p.light(x, y, C[5], 0.5 * (1 - k));
+ });
+ // healing motes rising around the flower
+ burst(14, S + 1, (r) => {
+ const born = T_OPEN + r.range(0, 0.8), age = t - born, life = r.range(0.55, 0.75);
+ if (age < 0 || age > life) return;
+ const k = age / life, x = r.range(-14, 14) + Math.sin(age * 6 + r.next() * TAU), y = -r.range(0, 8) - age * r.range(22, 36);
+ const plus = r.next() < 0.3 && k < 0.6;
+ if (plus) p.px(x - 1, y, C[5]), p.px(x + 1, y, C[5]), p.px(x, y - 1, C[5]), p.px(x, y + 1, C[5]);
+ p.px(x, y, k < 0.5 ? C[7] : C[5]);
+ p.light(x, y, C[5], 0.4 * (1 - k));
+ });
+ p.glow(0, -10, 34, C[4], 0.22 * seg(t, T_OPEN - 0.1, T_OPEN + 0.1) * (1 - seg(t, 1.2, 1.9)));
+}
diff --git a/src/fx/nature/leaf-storm.js b/src/fx/nature/leaf-storm.js
new file mode 100644
index 0000000..37015ea
--- /dev/null
+++ b/src/fx/nature/leaf-storm.js
@@ -0,0 +1,61 @@
+import { PAL, ramp, at, cycle, TAU, hex } from "../../core/index.js";
+
+export const meta = {
+ name: "Leaf storm",
+ desc: "A whirlwind of leaves spirals up around the target: leaves tumble as they orbit behind and in front, pale wind bands sweep round with them.",
+ tags: ["nature", "wind", "leaves", "whirlwind", "buff", "actor", "loop"],
+ size: [56, 52],
+ origin: [28, 44],
+ duration: 1.6,
+ loop: true,
+ fps: 30,
+ bg: "ground",
+ actor: true,
+ options: { palette: PAL.leaf, count: 20, radius: 15, seed: 29 },
+};
+
+const WIND = ["#40564a", "#7e9a86", "#c6dccb"].map(hex);
+// a leaf in four turns of its tumble, small and big
+const LEAVES = [
+ ["ab.", ".bc"],
+ [".a", "bb", "c."],
+ ["abc"],
+ ["c.", "bb", ".a"],
+];
+const BIG = [
+ ["..ab", ".abc", "abc."],
+ [".ab.", "abbc", ".cc."],
+ ["ab..", "cba.", ".cba"],
+ [".a.", "abc", "abc", ".c."],
+];
+
+function storm(p, t, o, front) {
+ const C = ramp(o.palette), S = o.seed, D = meta.duration, R = o.radius;
+ // wind bands: arcs of an ellipse sweeping round the body at a few heights
+ for (let j = 0; j < 4; j++) {
+ const y0 = -4 - j * 7, rx = R * (0.75 + j * 0.12), ry = 3 + j * 0.4, a0 = (t / D) * TAU * 2 + j * 1.9, span = 1.6 + (j % 2) * 0.6;
+ let prev = null;
+ for (let k = 0; k <= 14; k++) {
+ const a = a0 + (k / 14) * span, d = Math.sin(a);
+ const x = Math.cos(a) * rx, y = y0 + d * ry;
+ if (prev && d >= 0 === front) p.line(prev[0], prev[1], x, y, front ? (k > 10 ? WIND[2] : WIND[1]) : WIND[0], k / 14 < 0.25 ? 0.5 : 1);
+ prev = [x, y];
+ }
+ }
+ // leaves: each rides a rising spiral, tumbling, a whole number of turns a loop
+ cycle(t, D, o.count, S, (r) => r.range(0.9, 1.5), (age, life, r, i) => {
+ const q = age / life, a = r.range(0, TAU) + age * r.range(5.5, 8.5);
+ const rad = R * r.range(0.65, 1.05) * (0.75 + 0.35 * q), d = Math.sin(a);
+ if (d >= 0 !== front) return;
+ const x = Math.cos(a) * rad, y = -1 - q * r.range(26, 36) + d * 3.5;
+ const frame = (i % 3 === 0 ? BIG : LEAVES)[(Math.floor(age * r.range(10, 16)) + i) % 4];
+ const tone = r.int(0, 2), dim = front ? 0 : 1;
+ p.sprite(frame, { a: C[3 + tone - dim], b: C[4 + tone - dim], c: C[2 + tone - dim] }, x - 1, y - 1, {
+ a: q > 0.85 ? (1 - q) / 0.15 : 1,
+ });
+ });
+ if (front) p.glow(0, -14, 26, C[5], 0.08);
+}
+
+export const drawBack = (p, t, o) => storm(p, t, o, false);
+export const draw = (p, t, o) => storm(p, t, o, true);
diff --git a/src/fx/nature/poison-cloud.js b/src/fx/nature/poison-cloud.js
new file mode 100644
index 0000000..6335b80
--- /dev/null
+++ b/src/fx/nature/poison-cloud.js
@@ -0,0 +1,84 @@
+import { ramp, at, cycle, rng, noise2, clamp, ease, TAU } from "../../core/index.js";
+
+export const meta = {
+ name: "Poison cloud",
+ desc: "A low toxic cloud billows on the spot: heavy puffs swell and roll, sickly pale tops over bruised purple shadows, a thin haze, wisps and motes leak out.",
+ tags: ["nature", "poison", "gas", "cloud", "area", "loop"],
+ size: [76, 52],
+ origin: [38, 46],
+ duration: 2.4,
+ loop: true,
+ fps: 30,
+ bg: "ground",
+ options: {
+ palette: ["#221a33", "#3a3450", "#4a5a4a", "#5f7f40", "#84a842", "#aed056", "#d6ee86", "#f4ffcc"],
+ size: 1,
+ seed: 7,
+ },
+};
+
+// the cloud's resting lumps: [x, y, radius], a wide flat skirt along the floor, a few big billows on top
+const BODY = [
+ [-25, -4, 5], [-15, -6, 8], [0, -8, 10.5], [15, -6, 8], [25, -4, 5],
+ [-10, -15, 8.5], [8, -16, 9],
+ [-2, -24, 7.5],
+];
+
+export function draw(p, t, o) {
+ const C = ramp(o.palette), S = o.seed, D = meta.duration, ph = t / D, k = o.size;
+ const puffs = [];
+ BODY.forEach(([x, y, r], i) => {
+ const g = rng(S, i, 3), a = g.range(0, TAU), m = 1 + (i % 2);
+ puffs.push({
+ x: (x + Math.cos(ph * TAU * m + a) * 1.3) * k,
+ y: (y + Math.sin(ph * TAU + a) * 1.3) * k,
+ r: r * k * (1 + 0.1 * Math.sin(ph * TAU * m + a * 2)),
+ });
+ });
+ // billows: swell out of the upper surface, roll outward and up, then sink back in
+ cycle(t, D, 5, S + 1, (r) => r.range(1.5, 2.3), (age, life, r) => {
+ const q = age / life, th = r.range(-2.6, -0.55), rad = r.range(10, 14);
+ const out = rad + 6 * q, x = Math.cos(th) * out * 1.3, y = -12 + Math.sin(th) * out - 3 * q;
+ const size = r.range(5.5, 8) * Math.pow(Math.sin(Math.PI * q), 0.7);
+ if (size > 1) puffs.push({ x: x * k, y: y * k, r: size * k });
+ });
+
+ const top = -34 * k;
+ p.shade(-36 * k, -42 * k, 36 * k, 1, (x, y, out) => {
+ let best = 0, lit = 0, bi = -1;
+ for (let i = 0; i < puffs.length; i++) {
+ const f = puffs[i], dx = x - f.x, dy = y - f.y, e = Math.sqrt(dx * dx + dy * dy) / f.r;
+ if (e >= 1) continue;
+ const v = 1 - e * e;
+ if (v > best) (best = v), (lit = (-dx * 0.5 - dy) / f.r), (bi = i);
+ }
+ if (bi < 0) return;
+ // height sets the tone (the tops catch the light); each billow darkens toward its underside, so the
+ // creases read only where one billow rolls over another
+ const h = clamp((y - 1) / top), f = puffs[bi];
+ const n = noise2((x - f.x) * 0.25 + bi * 9.1, (y - f.y) * 0.25, S) * 0.06;
+ const v = 0.2 + h * 0.6 + Math.min(0, lit) * 0.3 + Math.max(0, lit - 0.5) * 0.2 + n;
+ // the skirt along the floor thins out into the ground
+ if (y > -2) out.a = y > -1 ? 0.5 : 0.75;
+ if (best < 0.14 && lit < 0) return at(C.slice(1, 6), v - 0.14);
+ return at(C.slice(1, 8), v);
+ });
+
+ // wisps: small puffs tear off the top and thin out as they rise
+ cycle(t, D, 4, S + 2, (r) => r.range(1, 1.5), (age, life, r) => {
+ const q = age / life, x0 = r.range(-16, 18) * k, x = x0 + Math.sin(q * 3 + r.next() * 6) * 2 + q * Math.sign(x0) * 4;
+ const y = (-25 + Math.abs(x0) * 0.4) * k - q * 13 * k, s = r.range(2.4, 3.4) * (1 - 0.8 * ease.inQuad(q));
+ if (s > 0.6) p.circle(x, y, s, (d, a) => (d < 0.6 && a < -0.4 && a > -2.4 ? C[6] : C[5]));
+ });
+ // motes: sickly specks drifting up and out, flickering
+ cycle(t, D, 9, S + 3, (r) => r.range(0.8, 1.5), (age, life, r) => {
+ const q = age / life, side = r.sign(), x = (r.range(4, 28) * side + side * q * 6) * k + Math.sin(age * 5 + r.next() * TAU) * 1.5;
+ const y = r.range(-30, -8) * k - age * r.range(8, 16);
+ if (q > 0.6 && Math.sin(age * 31 + r.next() * 9) < -0.3) return;
+ p.px(x, y, q < 0.5 ? C[7] : C[5]);
+ p.light(x, y, C[5], 0.45 * (1 - q));
+ });
+ const pulse = 0.85 + 0.15 * Math.sin(ph * TAU * 2);
+ p.glow(0, -16 * k, 36 * k, C[4], 0.14 * pulse);
+ p.glow(-2, -22 * k, 14 * k, C[6], 0.1 * pulse);
+}
diff --git a/src/fx/nature/quake.js b/src/fx/nature/quake.js
new file mode 100644
index 0000000..77c63a8
--- /dev/null
+++ b/src/fx/nature/quake.js
@@ -0,0 +1,84 @@
+import { PAL, ramp, burst, fly, seg, ease, clamp, rand, hex } from "../../core/index.js";
+
+export const meta = {
+ name: "Quake",
+ desc: "Three jolts: a crack tears along the floor both ways, slabs of ground jump and slam down, pebbles bounce and dust rises along the rift; then it settles.",
+ tags: ["nature", "earth", "quake", "earthquake", "crack", "area", "ground", "one-shot"],
+ size: [112, 44],
+ origin: [56, 30],
+ duration: 1.5,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ options: { palette: PAL.earth, width: 48, seed: 47 },
+};
+
+const DUST = ["#2e2620", "#4e4236", "#76664f", "#a08c6c"].map(hex);
+const JOLTS = [0.0, 0.32, 0.62];
+
+// the rift: a jagged path along the floor from the center outward, one per side
+function rift(S, side, W) {
+ const pts = [[0, 0]];
+ let x = 0;
+ for (let i = 0; x * side < W; i++) {
+ x += side * (2 + rand(S, i, side + 7) * 3);
+ pts.push([x, Math.round(rand(S, i, side + 9) * 2)]);
+ }
+ return pts;
+}
+
+export function draw(p, t, o) {
+ const C = ramp(o.palette), S = o.seed, W = o.width;
+ const jolt = JOLTS.reduce((m, j) => (t >= j ? j : m), 0), ja = t - jolt, n = JOLTS.filter((j) => t >= j).length;
+ const settle = 1 - seg(t, 1.15, 1.48);
+ // how far the rift has torn: a step further each jolt
+ const reach = W * (0.35 + 0.65 * ease.outCubic(seg(t, 0, 0.8)));
+ for (const side of [-1, 1]) {
+ const pts = rift(S, side, W);
+ for (let i = 1; i < pts.length; i++) {
+ const [x0, y0] = pts[i - 1], [x1, y1] = pts[i];
+ if (Math.abs(x1) > reach) break;
+ // the gap: black in the middle, a lit lip above, closing up as it settles
+ p.line(x0, y0, x1, y1, C[0], settle);
+ p.line(x0, y0 + 1, x1, y1 + 1, C[0], settle * (i < 6 ? 1 : 0.5));
+ p.line(x0, y0 - 1, x1, y1 - 1, C[4], settle * 0.75);
+ // branches down the face of the floor
+ if (i % 3 === 0) p.line(x1, y1 + 1, x1 + side * 2, y1 + 4 + (i % 2), C[0], settle);
+ }
+ }
+ // the heave: each jolt sends a wave out from the center that throws the floor tiles up as it passes
+ for (let x = -W; x <= W; x += 6) {
+ let lift = 0;
+ JOLTS.forEach((j, k) => {
+ const at = j + Math.abs(x) / 160, q = (t - at) / 0.16;
+ if (q > 0 && q < 1) lift = Math.max(lift, Math.sin(q * Math.PI) * (4 + k * 1.5) * (1 - Math.abs(x) / (W * 1.3)));
+ });
+ if (lift < 0.6 || Math.abs(x) > reach + 4) continue;
+ const r = rand(S, x, 5), tilt = (r - 0.5) * lift * 0.5, w = 6, y = -lift;
+ p.rect(x - w / 2, 0, w, 2, C[0]); // the hole it left
+ p.poly([[x - w / 2, y + tilt], [x + w / 2, y - tilt], [x + w / 2, y - tilt + 3], [x - w / 2, y + tilt + 3]], (px, py) =>
+ py < Math.min(y + tilt, y - tilt) + 1.2 ? C[5] : px > x + w / 2 - 1.2 ? C[2] : C[3]);
+ }
+ // pebbles: bounce up on every jolt
+ burst(16, S + 2, (r, i) => {
+ const x0 = r.range(-reach, reach), vx = r.range(-20, 20), vy = -r.range(45, 95) * (0.6 + 0.4 * (n / 3)), g = 420;
+ const air = (-2 * vy) / g;
+ if (ja > air || t > 1.4) return;
+ const [x, y] = fly(x0, 0, vx, vy, ja, g);
+ const s = i % 4 === 0 ? 2 : 1;
+ p.rect(x, y - s, s, s, C[r.int(3, 5)]);
+ });
+ // dust kicked up along the rift each jolt, lifting and shrinking away
+ for (let j = 0; j < JOLTS.length; j++) {
+ const da = t - JOLTS[j];
+ if (da < 0) continue;
+ const span = W * (0.35 + 0.65 * ease.outCubic(seg(JOLTS[j] + 0.1, 0, 0.8)));
+ burst(6, S + 10 + j, (r, i) => {
+ const x0 = ((i + r.next()) / 6 * 2 - 1) * span, life = r.range(0.45, 0.7), q = (da - Math.abs(x0) / 160) / life;
+ if (q <= 0 || q >= 1) return;
+ const x = x0 + q * r.range(-5, 5), y = -2 - ease.outQuad(q) * r.range(5, 11);
+ const rad = r.range(2.5, 4.2) * (0.7 + 0.5 * ease.outQuad(Math.min(1, q * 3))) * (1 - ease.inQuad(q) * 0.9) * settle;
+ p.circle(x, y, rad, (d, a) => (d < 0.5 && a < -0.3 ? DUST[3] : d < 0.85 ? DUST[2] : DUST[1]));
+ });
+ }
+}
diff --git a/src/fx/nature/root-snare.js b/src/fx/nature/root-snare.js
new file mode 100644
index 0000000..547c00b
--- /dev/null
+++ b/src/fx/nature/root-snare.js
@@ -0,0 +1,95 @@
+import { PAL, ramp, burst, fly, seg, ease, clamp, lerp, TAU, hex } from "../../core/index.js";
+
+export const meta = {
+ name: "Root snare",
+ desc: "Roots crack up out of the floor on both sides, spiral up around the target's legs and waist, cinch tight with a jolt, hold, then split and crumble away.",
+ tags: ["nature", "plant", "roots", "root", "snare", "debuff", "actor", "one-shot"],
+ size: [56, 44],
+ origin: [28, 38],
+ duration: 1.6,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ actor: true,
+ options: { palette: PAL.wood, seed: 23 },
+};
+
+const DIRT = ["#2e2418", "#4c3a26", "#6e5638"].map(hex);
+const LEAF = ["#2c5a22", "#4f9a3a", "#8ccc52"].map(hex);
+const STEPS = 64;
+
+// the two roots: where they break the floor, which way they wind, how high they climb
+const ROOTS = [
+ { x: -1, dir: 1, turns: 1.4, top: 13, born: 0.02, w: 1 },
+ { x: 1, dir: -1, turns: 1.15, top: 9, born: 0.07, w: 0.9 },
+];
+
+function point(R, s, t) {
+ const cinch = ease.outBack(seg(t, 0.36, 0.44), 3);
+ const rad = lerp(8.4, 6.4, cinch) + (1 - s) * (1 - s) * 3.5 + Math.sin(t * 50) * 0.25 * seg(t, 0.44, 0.5) * (1 - seg(t, 0.5, 0.6));
+ const th = (R.x < 0 ? Math.PI : 0) + R.dir * s * R.turns * TAU;
+ const depth = Math.sin(th);
+ return [Math.cos(th) * rad, -1 - s * R.top + depth * 1.5, depth];
+}
+
+function roots(p, t, o, front) {
+ const C = ramp(o.palette), S = o.seed;
+ ROOTS.forEach((R, ri) => {
+ const grow = ease.outCubic(seg(t, R.born, R.born + 0.32)), smax = grow;
+ if (smax <= 0) return;
+ const breakAt = 1.06 + ri * 0.05, segs = [];
+ for (let i = 0; i < STEPS; i++) {
+ const s0 = i / STEPS, s1 = (i + 1) / STEPS;
+ if (s1 > smax) break;
+ let [x0, y0, d0] = point(R, s0, t), [x1, y1] = point(R, s1, t);
+ if (d0 >= 0 !== front) continue;
+ // crumbling: each chunk drops free, the top first, and dithers away
+ const chunk = Math.floor(i / 6), cb = breakAt + (1 - s0) * 0.16 + (chunk % 3) * 0.02, ca = t - cb;
+ let a = 1;
+ if (ca > 0) {
+ const vx = ((chunk * 37) % 7 - 3) * 6, dy = 0.5 * 300 * ca * ca, dx = vx * ca;
+ x0 += dx, x1 += dx, y0 += dy, y1 += dy;
+ a = 1 - seg(ca, 0.12, 0.38);
+ if (a <= 0 || y0 > 1) continue;
+ }
+ const w = lerp(3.6, 2.4, s0) * R.w * (smax - s0 < 0.04 ? 0.7 : 1);
+ segs.push({ x0, y0, x1, y1, w, a, d0, knot: i % 7 === 3 && ca < 0 });
+ }
+ // a dark rind first, then the lit upper face over it, then knots catching the light
+ for (const g of segs) p.beam(g.x0, g.y0, g.x1, g.y1, g.w, C[1], g.a);
+ const snap = t > 0.4 && t < 0.47; // the cinch: the bark flashes taut for two frames
+ for (const g of segs) p.beam(g.x0, g.y0 - 0.45, g.x1, g.y1 - 0.45, g.w - 1.6, front ? (snap ? C[6] : g.d0 > 0.5 ? C[5] : C[4]) : C[3], g.a);
+ if (front) for (const g of segs) if (g.knot) p.px(g.x0, g.y0 - 1, C[6]);
+ });
+ if (!front) return;
+ // where the roots broke through: cracked floor and dirt flung up
+ for (const R of ROOTS) {
+ const gx = R.x < 0 ? -11 : 11, k = 1 - seg(t, 1.2, 1.5);
+ if (t > R.born && k > 0) {
+ p.line(gx - 3, 0, gx + 3, 0, DIRT[0], k);
+ p.px(gx - 4, 1, DIRT[0]), p.px(gx + 2, 1, DIRT[0]);
+ }
+ burst(6, S + (R.x < 0 ? 1 : 2), (r) => {
+ const age = t - R.born - r.range(0, 0.05), life = r.range(0.3, 0.45);
+ if (age < 0 || age > life) return;
+ const [x, y] = fly(gx + r.range(-2, 2), -1, r.range(-30, 30), -r.range(35, 75), age, 280);
+ if (y < 1) p.px(x, y, DIRT[r.int(0, 2)]);
+ });
+ }
+ // the cinch: a jolt, leaves shaken loose, strain lines
+ const ck = seg(t, 0.4, 0.62);
+ if (ck > 0 && ck < 1) {
+ burst(5, S + 5, (r, i) => {
+ const a = -Math.PI / 2 + r.range(-1.4, 1.4), sp = r.range(25, 50);
+ const [x, y] = fly(Math.cos(a) * 6, -9 + r.range(-4, 4), Math.cos(a) * sp, Math.sin(a) * sp, ck * 0.4, 160, 2);
+ p.sprite(i % 2 ? ["ab"] : ["a", "b"], { a: LEAF[0], b: LEAF[2] }, x, y);
+ });
+ if (ck < 0.4) for (const sx of [-1, 1]) {
+ p.line(sx * 10, -16, sx * 12, -18, C[6]);
+ p.line(sx * 11, -12, sx * 14, -12, C[6]);
+ }
+ }
+}
+
+export const drawBack = (p, t, o) => roots(p, t, o, false);
+export const draw = (p, t, o) => roots(p, t, o, true);
diff --git a/src/fx/nature/sand-burst.js b/src/fx/nature/sand-burst.js
new file mode 100644
index 0000000..9435cdc
--- /dev/null
+++ b/src/fx/nature/sand-burst.js
@@ -0,0 +1,76 @@
+import { ramp, burst, fly, seg, ease, clamp, rand, TAU } from "../../core/index.js";
+
+export const meta = {
+ name: "Sand burst",
+ desc: "The floor bulges, then a geyser of sand blasts up: a gushing column, grains raining down in a wide fan, a dust cloud rolling out low, a mound left to slump.",
+ tags: ["nature", "earth", "sand", "desert", "geyser", "ground", "one-shot"],
+ size: [80, 72],
+ origin: [40, 64],
+ duration: 1.6,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ options: { palette: ["#2a1c0c", "#4e3418", "#7a5426", "#a87a3a", "#d0a456", "#ecc87a", "#fae6b0"], height: 46, seed: 53 },
+};
+
+const T0 = 0.14; // the blast
+
+export function draw(p, t, o) {
+ const C = ramp(o.palette), S = o.seed, H = o.height;
+ // anticipation: a mound swells and trembles; after the blast it is a pile that slumps flat
+ const swell = ease.outQuad(seg(t, 0, T0)), slump = seg(t, 0.95, 1.55);
+ const mh = (t < T0 ? 4 * swell : 4 + 2 * ease.outCubic(seg(t, T0, 0.7))) * (1 - ease.inQuad(slump));
+ const mw = (t < T0 ? 7 * swell : 7 + 7 * ease.outCubic(seg(t, T0, 0.8))) * (1 + slump * 0.3);
+ if (mh > 0.5) {
+ const shake = t < T0 ? Math.round(Math.sin(t * 120)) * 0.5 : 0;
+ p.shade(-mw - 1, -mh - 1, mw + 1, 0, (x, y) => {
+ const dx = (x - shake) / mw, dy = y / mh;
+ if (dx * dx + dy * dy > 1) return;
+ const lit = -dx * 0.8 - dy;
+ return lit > 0.9 ? C[6] : lit > 0.3 ? C[5] : lit > -0.3 ? C[4] : C[3];
+ });
+ }
+ if (t < T0) return;
+ const a = t - T0;
+ // the column: a gushing jet that shoots up, then the supply stops and it falls back into itself
+ const rise = ease.outExpo(seg(a, 0, 0.1)), fall = ease.inQuad(seg(a, 0.24, 0.55));
+ const top = -H * rise * (1 - fall);
+ if (top < -2) {
+ p.shade(-7, top - 1, 7, 0, (x, y) => {
+ const v = clamp((y - top) / -top); // 0 at the top, 1 at the bottom
+ // a narrow jet that widens at the foot and blooms into a ragged head at the top
+ const head = y < top + 6 ? Math.sqrt(Math.max(0, 1 - ((y - top - 3) / 3.5) ** 2)) * 5 : 0;
+ const w = Math.max(1.8 + 2.4 * v, head) + Math.sin(y * 0.8 + a * 45) * 0.7 + (rand(Math.floor(y), Math.floor(a * 30), S) - 0.5);
+ if (Math.abs(x) > w) return;
+ const u = x / w;
+ return u < -0.45 ? C[6] : u < 0.15 ? C[5] : u < 0.65 ? C[4] : C[3];
+ });
+ // a ragged crown spraying off the top
+ burst(8, S + 5, (r) => {
+ const x = r.range(-6, 6), y = top - r.range(0, 4) + Math.sin(a * 50 + r.next() * TAU);
+ p.px(x, y, C[6]);
+ });
+ }
+ // the fan: grains thrown up and out, falling back in a spray
+ burst(70, S, (r, i) => {
+ const born = r.range(0, 0.3), age = a - born;
+ if (age < 0) return;
+ const ang = -Math.PI / 2 + clamp(r.gauss() * 0.42, -0.95, 0.95), sp = r.range(60, 135) * (born < 0.12 ? 1 : 0.8);
+ const vx = Math.cos(ang) * sp, vy = Math.sin(ang) * sp, g = 330;
+ const [x, y] = fly(r.range(-2, 2), -2, vx, vy, age, g, 0.6);
+ if (y > -1 || Math.abs(x) > 37) return;
+ const falling = vy + g * age > 0;
+ p.px(x, y, falling ? C[4] : C[5 + (i % 2)]);
+ if (i % 3 === 0) p.px(x, y - (falling ? 1 : -1), C[3]);
+ });
+ // dust: a low cloud rolling out both ways, lifting and thinning
+ burst(10, S + 1, (r, i) => {
+ const life = r.range(0.6, 0.95), q = a / life;
+ if (q >= 1) return;
+ const side = i % 2 ? 1 : -1, e = ease.outCubic(Math.min(1, q * 1.7));
+ const x = side * r.range(4, 26) * e, y = -2 - r.range(1, 7) * e - q * 5;
+ const rad = r.range(2.5, 5) * (0.6 + 0.5 * e) * (1 - 0.9 * ease.inQuad(q));
+ p.circle(x, y, rad, (d, an) => (d < 0.5 && an < -0.3 ? C[5] : d < 0.85 ? C[4] : C[3]));
+ });
+ if (a < 0.06) p.glow(0, -10, 30, C[6], 0.3);
+}
diff --git a/src/fx/nature/spore-burst.js b/src/fx/nature/spore-burst.js
new file mode 100644
index 0000000..b07c79d
--- /dev/null
+++ b/src/fx/nature/spore-burst.js
@@ -0,0 +1,88 @@
+import { ramp, at, burst, fly, seg, ease, clamp, lerp, TAU, hex } from "../../core/index.js";
+
+export const meta = {
+ name: "Spore burst",
+ desc: "A toadstool pushes up out of the floor, squats, and puffs a cloud of glowing spores that billow up and drift down as it shrivels back into the ground.",
+ tags: ["nature", "mushroom", "fungus", "spores", "poison", "ground", "one-shot"],
+ size: [64, 60],
+ origin: [32, 52],
+ duration: 1.8,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ options: { palette: ["#1e0c26", "#3a1450", "#5e1f74", "#8c2f92", "#bc4aa6", "#e47cc0", "#ffbade", "#fff2f8"], seed: 31 },
+};
+
+const STEM = ["#4a3c3a", "#8a7a6c", "#cbbca4", "#f0e6d0"].map(hex);
+const T_PUFF = 0.42;
+
+export function draw(p, t, o) {
+ const C = ramp(o.palette), S = o.seed;
+ // the toadstool: grows, squats (anticipation), springs up as it puffs, then shrivels into the floor
+ const grow = ease.outBack(seg(t, 0, 0.22), 1.6), squat = ease.inOutQuad(seg(t, 0.26, T_PUFF)), spring = seg(t, T_PUFF, T_PUFF + 0.16);
+ const shrivel = ease.inQuad(seg(t, 1.05, 1.45));
+ const sq = squat * (1 - spring) + (spring > 0 ? Math.sin(spring * Math.PI * 2.5) * (1 - spring) * -0.5 : 0);
+ const sy = grow * (1 - 0.3 * sq) * (1 - shrivel), sx = 1 + 0.35 * sq + 0.1 * shrivel;
+ if (sy > 0.05) {
+ const stemH = 9 * sy, capY = -stemH - 1, cw = 9 * sx * Math.min(1, grow + 0.2), ch = 6 * sy;
+ // stem: pale, shaded right, a frill under the cap
+ p.shade(-2.5 * sx, capY, 2.5 * sx, 0, (x) => (x < -1.2 * sx ? STEM[3] : x < 0.6 * sx ? STEM[2] : STEM[1]));
+ if (stemH > 4) p.line(-3 * sx, capY + 2, 3 * sx, capY + 2, STEM[1]);
+ // cap: a dome lit from the top left, dark rim underneath, pale spots
+ p.shade(-cw - 1, capY - ch - 1, cw + 1, capY + 1.5, (x, y) => {
+ const dx = x / cw, dy = (y - capY) / ch;
+ if (dy > 0.25) return dx * dx < 1 - (dy - 0.25) * 2 && Math.abs(dx) < 0.95 ? C[1] : undefined;
+ if (dx * dx + dy * dy > 1) return;
+ const lit = -dx * 0.6 - dy;
+ return lit > 0.75 ? C[6] : lit > 0.25 ? C[5] : lit > -0.25 ? C[4] : C[3];
+ });
+ if (cw > 4) {
+ p.px(-cw * 0.45, capY - ch * 0.55, STEM[3]), p.px(-cw * 0.45 + 1, capY - ch * 0.55, STEM[3]);
+ p.px(cw * 0.25, capY - ch * 0.75, STEM[3]);
+ p.px(cw * 0.6, capY - ch * 0.3, STEM[2]);
+ }
+ }
+ const a = t - T_PUFF;
+ if (a < 0) return;
+ const top = -9 * (1 - 0.3) - 8;
+ // the puff: a white burst off the cap for two frames
+ if (a < 0.07) {
+ p.ellipse(0, top - 2, 9, 5, (d) => (d < 0.5 ? C[7] : C[6]));
+ p.glow(0, top, 30, C[5], 0.5);
+ }
+ // the cloud: clumps of spore dust that billow up and out as one lumpy mass, then shrink away darkening
+ const puffs = [];
+ burst(11, S, (r) => {
+ const life = r.range(0.7, 1), q = a / life;
+ if (q >= 1) return;
+ const ang = -Math.PI / 2 + r.range(-1.1, 1.1), sp = r.range(10, 26), e = ease.outCubic(Math.min(1, q * 1.6));
+ const x = Math.cos(ang) * sp * e, y = top - 2 + Math.sin(ang) * sp * 0.8 * e - q * 6;
+ const rad = r.range(3.5, 6) * (0.6 + 0.6 * e) * (1 - ease.inQuad(q) * 0.95);
+ if (rad > 0.7) puffs.push({ x, y, r: rad, q });
+ });
+ if (puffs.length) {
+ p.shade(-30, -56, 30, -4, (x, y) => {
+ let best = 0, lit = 0, q = 0;
+ for (const f of puffs) {
+ const dx = x - f.x, dy = y - f.y, v = 1 - (dx * dx + dy * dy) / (f.r * f.r);
+ if (v > best) (best = v), (lit = (-dx * 0.6 - dy) / f.r), (q = f.q);
+ }
+ if (best <= 0) return;
+ // fresh dust is bright; it dulls as it ages
+ return at(C.slice(2, 8), 0.3 + lit * 0.32 + best * 0.2 - q * 0.45);
+ });
+ }
+ // spores: glowing specks shot up and out, then drifting down, swaying, twinkling out
+ burst(26, S + 1, (r) => {
+ const life = r.range(0.9, 1.3), age = a - r.range(0, 0.08);
+ if (age < 0 || age > life) return;
+ const k = age / life, ang = -Math.PI / 2 + r.range(-1.25, 1.25), sp = r.range(30, 72);
+ let [x, y] = fly(0, top - 1, Math.cos(ang) * sp, Math.sin(ang) * sp, age, 22, 3.2);
+ x += Math.sin(age * r.range(5, 8) + r.next() * TAU) * 2 * k;
+ if (k > 0.6 && Math.sin(age * 40 + r.next() * 9) < -0.4) return;
+ p.px(x, y, k < 0.4 ? C[7] : k < 0.75 ? C[6] : C[5]);
+ p.light(x, y, C[5], 0.5 * (1 - k));
+ });
+ const L = 1 - seg(a, 0, 0.6);
+ p.glow(0, top - 6, 28, C[4], 0.3 * L * L);
+}
diff --git a/src/fx/nature/thorns.js b/src/fx/nature/thorns.js
new file mode 100644
index 0000000..5c44427
--- /dev/null
+++ b/src/fx/nature/thorns.js
@@ -0,0 +1,74 @@
+import { ramp, burst, fly, seg, ease, clamp, TAU, hex } from "../../core/index.js";
+
+export const meta = {
+ name: "Thorns",
+ desc: "A line of bramble thorns punches up out of the floor, one after another to the right, each hooked spike snapping up with a puff of dirt, then sinking back.",
+ tags: ["nature", "plant", "thorns", "spikes", "ground", "directional", "one-shot"],
+ size: [100, 44],
+ origin: [8, 36],
+ duration: 1.1,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ options: { palette: ["#1a0c10", "#341420", "#56202a", "#7a3030", "#a04c38", "#c87a52", "#f0bc8c"], count: 7, spacing: 12, seed: 19 },
+};
+
+const DIRT = ["#2e2418", "#4c3a26", "#6e5638"].map(hex);
+const MOSS = ["#22401c", "#3a6a26", "#6a9a36"].map(hex);
+
+// one thorn: a curved horn, wide at the root, hooked forward at the tip; h is its height, lean its curl
+function thorn(p, C, x0, h, w, lean, barb) {
+ if (h < 1) return;
+ const cx = (v) => x0 + lean * v * v * h * 0.45, hw = (v) => w * Math.pow(1 - v, 0.85);
+ const pts = [];
+ for (let i = 0; i <= 8; i++) pts.push([cx(i / 8) - hw(i / 8), -(i / 8) * h]);
+ for (let i = 8; i >= 0; i--) pts.push([cx(i / 8) + hw(i / 8), -(i / 8) * h]);
+ // lit from the left: a bright ridge, a deep right flank, a pale tip
+ p.poly(pts, (x, y) => {
+ const v = -y / h, u = (x - cx(v)) / Math.max(0.6, hw(v));
+ if (v > 0.8) return C[6];
+ return u < -0.5 ? C[5] : u < 0.1 ? C[4] : u < 0.6 ? C[3] : C[2];
+ });
+ // the hooked tip stays one connected pixel line
+ const tip = [];
+ for (let i = 6; i <= 10; i++) tip.push([cx(Math.min(1, i / 10)), -Math.min(1, i / 10) * h]);
+ p.polyline(tip, C[6]);
+ // a barb on the back, angled down
+ if (barb && h > 9) {
+ const v = 0.42, bx = cx(v) - hw(v), by = -v * h;
+ p.tri(bx + 1, by - 2, bx + 1, by + 1, bx - 3, by + 1.5, C[4]);
+ p.px(bx - 3, by + 1, C[5]);
+ }
+}
+
+export function draw(p, t, o) {
+ const C = ramp(o.palette), S = o.seed, n = o.count, gap = o.spacing;
+ burst(n, S, (r, i) => {
+ const x0 = 4 + i * gap + r.range(-2, 2), born = 0.04 + i * 0.07, a = t - born;
+ if (a < 0) return;
+ const H = (11 + i * 1.7 + r.range(-2, 3)) * (i === n - 1 ? 1.25 : 1), W = r.range(2.8, 3.6) + i * 0.18, lean = r.range(0.25, 0.6);
+ // up fast with an overshoot, hold, then sink back
+ const up = ease.outBack(seg(a, 0, 0.09), 2.2), down = ease.inQuad(seg(t, 0.62 + i * 0.035, 0.86 + i * 0.03));
+ const h = H * up * (1 - down);
+ // the floor cracks open under it first
+ const crack = 1 - seg(t, 0.85, 1.05);
+ if (crack > 0) {
+ p.line(x0 - W - 1, 0, x0 + W + 1, 0, DIRT[0], crack);
+ p.px(x0 - W - 2, 1, DIRT[0]), p.px(x0 + W + 2, 1, DIRT[0]);
+ }
+ thorn(p, C, x0, h, W, lean, i % 2 === 0);
+ // moss at the root of the bigger ones
+ if (h > 6) p.line(x0 - W, -1, x0 - W + 2, -1, MOSS[1]), p.px(x0 - W + 1, -2, MOSS[2]);
+ // a puff of dirt as it breaks through
+ burst(5, S + 10 + i, (q) => {
+ const life = q.range(0.25, 0.4);
+ if (a > life) return;
+ const [x, y] = fly(x0 + q.range(-W, W), -1, q.range(-35, 35), -q.range(25, 65), a, 260);
+ if (y < 1) p.px(x, y, DIRT[q.int(0, 2)]);
+ });
+ if (a < 0.07) {
+ p.line(x0 - W - 2, -1, x0 + W + 2, -1, C[6]);
+ p.glow(x0, -4, 12, C[5], 0.4);
+ }
+ });
+}
diff --git a/src/fx/nature/tornado.js b/src/fx/nature/tornado.js
new file mode 100644
index 0000000..e29eb80
--- /dev/null
+++ b/src/fx/nature/tornado.js
@@ -0,0 +1,62 @@
+import { ramp, at, cycle, tileNoise, clamp, lerp, TAU, hex } from "../../core/index.js";
+
+export const meta = {
+ name: "Tornado",
+ desc: "A twisting funnel of wind snakes up from the floor, its bands whipping round; rocks, sticks and leaves orbit it and a dust skirt churns at its foot.",
+ tags: ["nature", "wind", "tornado", "storm", "hazard", "ground", "loop"],
+ size: [76, 80],
+ origin: [38, 72],
+ duration: 1.2,
+ loop: true,
+ fps: 30,
+ bg: "ground",
+ options: { palette: ["#1a1b24", "#2c2e3a", "#43465a", "#5e6378", "#7e8498", "#a2a8ba", "#c8ccd8", "#eef0f4"], height: 62, seed: 59 },
+};
+
+const DEBRIS = ["#3a2a1c", "#6a4a2c", "#8e6a3e"].map(hex);
+const LEAF = ["#2c5a22", "#4f9a3a", "#8ccc52"].map(hex);
+
+export function draw(p, t, o) {
+ const C = ramp(o.palette), S = o.seed, D = meta.duration, ph = t / D, H = o.height;
+ // the axis snakes: the foot stays put, the body leans and sways once a loop
+ const axis = (y) => {
+ const v = -y / H;
+ return Math.sin(ph * TAU + v * 2.4) * 4 * v + v * v * 5;
+ };
+ const rad = (y) => {
+ const v = clamp(-y / H);
+ return 2.2 + 17 * Math.pow(v, 1.5) + Math.sin(v * 9 - ph * TAU * 2) * 0.8 * v;
+ };
+ // debris behind the funnel
+ const debris = (front) => cycle(t, D, 12, S + 1, (r) => r.range(0.8, 1.2), (age, life, r, i) => {
+ const k = age / life, a = r.range(0, TAU) + age * r.range(9, 13), y = -r.range(4, 12) - k * r.range(26, 44);
+ const R = rad(y) + r.range(2, 6), d = Math.sin(a);
+ if (d >= 0 !== front) return;
+ const x = axis(y) + Math.cos(a) * R, yy = y + d * 2;
+ if (i % 3 === 0) p.sprite(age * 14 % 2 < 1 ? ["ab"] : ["a", "b"], { a: LEAF[1], b: LEAF[2] }, x, yy);
+ else if (i % 3 === 1) p.rect(x, yy, 2, 2, DEBRIS[front ? 1 : 0]), p.px(x, yy, DEBRIS[2]);
+ else p.line(x - 1, yy + (age * 10 % 2 < 1 ? 1 : -1), x + 1, yy - (age * 10 % 2 < 1 ? 1 : -1), DEBRIS[1]);
+ });
+ debris(false);
+ // the funnel: a surface of bands spinning round the axis; lit on the left, dark on the right
+ p.shade(-32, -H - 6, 32, 0, (x, y) => {
+ const v = -y / H, R = rad(y), u = (x - axis(y)) / R;
+ // a ragged edge; the top flares into lumps that roll round with the spin
+ const lumps = tileNoise((Math.atan2(0.4, u) / TAU) * 8 + ph * 8, 0.5, 8, 0, S + 2);
+ const edge = 1 + tileNoise(y * 0.35, ph * 6, 0, 6, S) * 0.16 + (v > 0.86 ? (v - 0.86) * 4 * (0.6 + lumps * 0.5) : 0);
+ if (Math.abs(u) > edge || v > 1.04 + lumps * 0.05) return;
+ const phi = Math.asin(clamp(u)); // where on the front of the funnel this pixel is
+ const band = tileNoise((phi / TAU) * 10 + ph * 20, y * 0.42, 10, 0, S + 1);
+ let k = 0.3 - u * 0.3 + band * 0.4 + v * 0.12;
+ if (Math.abs(u) > edge - 0.2) k -= 0.16;
+ return at(C.slice(1, 8), k);
+ });
+ debris(true);
+ // the dust skirt: puffs churning round the foot
+ cycle(t, D, 10, S + 2, (r) => r.range(0.5, 0.8), (age, life, r) => {
+ const k = age / life, a = r.range(0, TAU) + age * 8, R = 4 + k * r.range(8, 13);
+ const x = Math.cos(a) * R, y = -1 - k * r.range(2, 6) + Math.sin(a) * 1.5, s = r.range(1.8, 3) * (1 - k * 0.7);
+ p.circle(x, y, s, (d, an) => (d < 0.5 && an < -0.3 ? C[5] : d < 0.85 ? C[4] : C[3]));
+ });
+ p.glow(axis(-H * 0.5), -H * 0.5, 30, C[6], 0.06);
+}
diff --git a/src/fx/nature/toxic-puddle.js b/src/fx/nature/toxic-puddle.js
new file mode 100644
index 0000000..b3280b4
--- /dev/null
+++ b/src/fx/nature/toxic-puddle.js
@@ -0,0 +1,72 @@
+import { ramp, cycle, noise, ease, clamp, TAU } from "../../core/index.js";
+
+export const meta = {
+ name: "Toxic puddle",
+ desc: "A pool of thick green sludge on the floor: fat bubbles swell, wobble and pop with a spit and a ripple, a sheen slides across, little bubbles float up and burst.",
+ tags: ["nature", "poison", "puddle", "hazard", "ground", "loop"],
+ size: [56, 40],
+ origin: [28, 32],
+ duration: 2.4,
+ loop: true,
+ fps: 30,
+ bg: "ground",
+ options: { palette: ["#0d1a0c", "#173a14", "#265e18", "#3f8a1e", "#6cb82a", "#a8e04a", "#e0ff8a"], width: 20, seed: 13 },
+};
+
+const BIG = [".##.", "#o.#", "#..#", ".##."];
+const SMALL = [".#.", "#.#", ".#."];
+
+export function draw(p, t, o) {
+ const C = ramp(o.palette), S = o.seed, D = meta.duration, ph = t / D, RX = o.width, RY = 4.5;
+ // the pool's outline: an ellipse with a few soft lobes that breathe
+ const rim = (ang) => 1 + 0.07 * Math.sin(ang * 3 + 1.3 + S) + 0.04 * Math.sin(ang * 5 + ph * TAU);
+ const sheen = -RX * 0.9 + ph * RX * 1.8;
+ p.shade(-RX - 3, -RY - 2, RX + 3, RY + 2, (x, y) => {
+ const ang = Math.atan2(y / RY, x / RX), w = rim(ang);
+ const dx = x / (RX * w), dy = y / (RY * w), d = Math.sqrt(dx * dx + dy * dy);
+ if (d > 1) return;
+ // dark lip in front, pale bank behind, a lighter band across the far half of the surface
+ if (dy > 0 && d > 0.7) return C[1];
+ if (dy <= 0 && d > 0.84) return C[4];
+ const s = Math.abs(x - sheen) / 4 + Math.abs(dy + 0.35) * 2;
+ if (s < 1 && dy < 0) return s < 0.45 ? C[5] : C[4];
+ return dy < -0.2 ? C[3] : C[2];
+ });
+ p.px(-RX * 0.55, -RY * 0.55, C[6]), p.px(-RX * 0.55 + 1, -RY * 0.55, C[5]);
+
+ // fat bubbles: swell and wobble, then burst with a spit of droplets and a flat ripple
+ cycle(t, D, 5, S + 2, (r) => r.range(1, 1.4), (age, life, r) => {
+ const q = age / life, bx = r.range(-0.65, 0.65) * RX, by = r.range(-0.3, 0.4) * RY, big = r.next() < 0.5;
+ const R = big ? r.range(3.6, 4.6) : r.range(2.2, 2.8), grow = 0.72;
+ if (q < grow) {
+ const s = R * ease.outCubic(q / grow), wob = 1 + 0.1 * Math.sin(age * 26 + bx), cy = by - s * 0.6;
+ p.ellipse(bx, cy, s * wob + 0.3, s / wob + 0.3, (d, ang) =>
+ d > 0.74 ? C[1] : ang < -0.8 && ang > -2.7 && d > 0.3 ? C[5] : ang > 0.4 && d > 0.4 ? C[3] : C[4]);
+ if (s > 1.5) p.px(bx - s * 0.4, cy - s * 0.5, C[6]);
+ return;
+ }
+ const k = (q - grow) / (1 - grow), tt = (q - grow) * life;
+ // the pop: a flash of the burst skin, then a ripple spreading on the surface
+ if (k < 0.1) p.ring(bx, by - R * 0.6, R + 1, 1, C[5]);
+ if (k > 0.05 && k < 0.6) p.ellipse(bx, by, R + 1 + k * 7, 1.2 + k * 1.8, k < 0.3 ? C[5] : C[4], (d) => (d > 0.72 ? 1 : 0));
+ for (let j = 0; j < (big ? 3 : 2); j++) {
+ const a = -Math.PI / 2 + (j - (big ? 1 : 0.5)) * 0.55, sp = 30 + j * 6;
+ const x = bx + Math.cos(a) * sp * tt, y = by - R + Math.sin(a) * sp * tt + 0.5 * 230 * tt * tt;
+ if (y < by - 1) p.px(x, y, k < 0.4 ? C[6] : C[5]);
+ }
+ });
+ // little bubbles break loose and float up, wobbling, then burst
+ cycle(t, D, 6, S + 3, (r) => r.range(1, 1.6), (age, life, r) => {
+ const q = age / life, x = r.range(-0.6, 0.6) * RX + Math.sin(age * r.range(4, 7) + r.next() * TAU) * 1.5;
+ const y = -3 - ease.outQuad(q) * r.range(14, 22), s = r.range(1.2, 2);
+ if (q > 0.9) {
+ p.px(x - 2, y, C[5]), p.px(x + 2, y, C[5]), p.px(x, y - 2, C[5]), p.px(x, y + 2, C[5]);
+ return;
+ }
+ if (s > 1.6) p.sprite(BIG, { "#": C[4], o: C[6] }, x - 2, y - 2);
+ else p.sprite(SMALL, { "#": C[4] }, x - 1, y - 1);
+ p.light(x, y, C[4], 0.25);
+ });
+ const pulse = 0.85 + 0.15 * Math.sin(ph * TAU * 2);
+ p.glow(0, -2, RX + 10, C[4], 0.18 * pulse);
+}
diff --git a/src/fx/nature/vine-whip.js b/src/fx/nature/vine-whip.js
new file mode 100644
index 0000000..a04ae50
--- /dev/null
+++ b/src/fx/nature/vine-whip.js
@@ -0,0 +1,116 @@
+import { PAL, ramp, burst, fly, seg, ease, clamp, lerp, smooth, TAU, hex } from "../../core/index.js";
+
+export const meta = {
+ name: "Vine whip",
+ desc: "A thorny vine bursts from the ground coiled back, then lashes right: the curl unrolls to the tip, which cracks in a spray of sap and leaves, and the vine slithers home.",
+ tags: ["nature", "plant", "vine", "whip", "melee", "directional", "one-shot"],
+ size: [100, 64],
+ origin: [26, 56],
+ duration: 0.8,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ options: { palette: PAL.leaf, length: 56, seed: 17 },
+};
+
+const THORN = ["#5a4a24", "#a8925a", "#e6d8a0"].map(hex);
+const DIRT = ["#2e2418", "#4c3a26", "#6e5638"].map(hex);
+const N = 30;
+
+// the vine's centerline at time t: N + 1 points along its length, base on the floor
+function path(t, L) {
+ const lash = seg(t, 0.13, 0.26); // the unrolling wave runs from base to tip
+ const settle = seg(t, 0.26, 0.46);
+ const ds = (L * (0.6 + 0.4 * ease.outCubic(lash))) / N, pts = [[0, 0]];
+ let x = 0, y = 0;
+ for (let i = 0; i < N; i++) {
+ const u = i / N;
+ const wound = -1.7 - 1.25 * Math.pow(u, 1.2); // reared up and back, the tip hanging behind
+ const lashed = -1.45 + 1.62 * Math.pow(u, 0.5); // up out of the ground, then out flat to the right
+ const w = smooth(0, 1, lash * 1.7 - u * 0.7);
+ const flick = Math.sin(settle * Math.PI * 2.5) * (1 - settle) * 0.5 * u * u; // the tip overshoots and wobbles
+ const droop = ease.inQuad(seg(t, 0.46, 0.75)) * 0.8 * u; // and wilts as it pulls back
+ const a = lerp(wound, lashed, w) + flick + droop + Math.sin(t * 9 + u * 5) * 0.04;
+ x += Math.cos(a) * ds;
+ y += Math.sin(a) * ds;
+ pts.push([x, y]);
+ }
+ return pts;
+}
+
+export function draw(p, t, o) {
+ const C = ramp(o.palette), S = o.seed, L = o.length;
+ const grow = ease.outCubic(seg(t, 0, 0.1)), back = ease.inCubic(seg(t, 0.48, 0.78));
+ const pts = path(t, L);
+ const len = N * grow, off = N * back; // vine points [0, len) are out, slid back `off` points into the ground
+ const at = (s) => {
+ const u = s - off;
+ if (u < 0) return null;
+ const i = Math.min(N - 1, Math.floor(u)), f = u - i, a = pts[i], b = pts[i + 1];
+ return [lerp(a[0], b[0], f), lerp(a[1], b[1], f)];
+ };
+ // dirt kicked up where it breaks the ground
+ burst(7, S + 3, (r) => {
+ const age = t - r.range(0, 0.06), life = r.range(0.3, 0.5);
+ if (age < 0 || age > life) return;
+ const [x, y] = fly(r.range(-2, 2), -1, r.range(-40, 40), -r.range(30, 70), age, 260);
+ if (y < 1) p.px(x, y, DIRT[r.int(0, 2)]);
+ });
+ // the body: a tapering tube, dark rim, bright core
+ for (let s = 0; s < len - 0.5; s += 0.5) {
+ const P = at(s), Q = at(s + 0.5);
+ if (!P || !Q) continue;
+ const w = 1.4 + 2.8 * (1 - s / N);
+ p.beam(P[0], P[1], Q[0], Q[1], w, (u, v) => (v > 0.55 ? C[2] : C[4]));
+ }
+ for (let s = 0; s < len - 1; s += 1) {
+ const P = at(s), Q = at(s + 1);
+ if (P && Q && s < N * 0.85) p.line(P[0], P[1] - 1, Q[0], Q[1] - 1, s % 6 < 3 ? C[5] : C[4]);
+ }
+ // thorns: hooked spikes along the outside of the curve, leaves at two joints
+ for (let j = 0; j < 9; j++) {
+ const s = 3 + j * 3.1;
+ if (s > len - 1) break;
+ const P = at(s), Q = at(s + 0.6);
+ if (!P || !Q) continue;
+ const dx = Q[0] - P[0], dy = Q[1] - P[1], l = Math.hypot(dx, dy) || 1, side = j % 2 ? 1 : -1;
+ const nx = (-dy / l) * side, ny = (dx / l) * side, sz = 2.5 - j * 0.12;
+ const bx = P[0] + nx * 1.2, by = P[1] + ny * 1.2, tx = bx + nx * sz - (dx / l) * 1.2, ty = by + ny * sz - (dy / l) * 1.2;
+ p.line(bx, by, tx, ty, THORN[1]);
+ p.px(tx, ty, THORN[2]);
+ }
+ for (const [s, side] of [[8, 1], [17, -1]]) {
+ if (s > len - 1) continue;
+ const P = at(s);
+ if (!P) continue;
+ p.sprite(side > 0 ? [".ab", "ab."] : ["ba.", ".ba"], { a: C[3], b: C[5] }, P[0] - 1, P[1] - (side > 0 ? 3 : -1));
+ }
+ // the smear: where the tip has just been during the lash
+ if (t > 0.15 && t < 0.32 && off === 0) {
+ let prev = null;
+ for (let i = 0; i < 7; i++) {
+ const tt = t - i * 0.014, q = path(tt, L)[N];
+ if (prev) p.line(prev[0], prev[1], q[0], q[1], i < 3 ? C[7] : C[6], 1 - i / 7);
+ prev = q;
+ }
+ }
+ // the crack: a star of light at the tip, sap and leaf bits thrown forward
+ const tip = pts[N], ck = seg(t, 0.25, 0.38);
+ if (ck > 0 && ck < 1) {
+ const s = Math.round(4 * (1 - ck) + 1);
+ p.line(tip[0] - s, tip[1], tip[0] + s, tip[1], C[7]);
+ p.line(tip[0], tip[1] - s, tip[0], tip[1] + s, C[7]);
+ if (ck < 0.35) p.circle(tip[0], tip[1], 2, C[7]);
+ p.glow(tip[0], tip[1], 14, C[6], 0.5 * (1 - ck));
+ }
+ burst(9, S, (r, i) => {
+ const age = t - 0.26 - r.range(0, 0.03), life = r.range(0.28, 0.45);
+ if (age < 0 || age > life) return;
+ const a = r.range(-1.3, 0.8), sp = r.range(35, 70);
+ const [x, y] = fly(tip[0], tip[1], Math.cos(a) * sp, Math.sin(a) * sp, age, 180, 2.5), k = age / life;
+ if (y > 0) return;
+ if (i < 3) p.sprite(k < 0.5 ? ["ab", "b."] : ["b.", "ab"], { a: C[3], b: C[5] }, x, y);
+ else p.px(x, y, k < 0.4 ? C[7] : C[5]);
+ });
+ p.glow(tip[0] * 0.6, tip[1] * 0.6, 26, C[4], 0.12 * clamp(grow - back));
+}
diff --git a/src/fx/nature/wind-gust.js b/src/fx/nature/wind-gust.js
new file mode 100644
index 0000000..eeef6b1
--- /dev/null
+++ b/src/fx/nature/wind-gust.js
@@ -0,0 +1,55 @@
+import { PAL, ramp, rng, fract, clamp, ease, TAU, hex } from "../../core/index.js";
+
+export const meta = {
+ name: "Wind gust",
+ desc: "Wind streams right: long pale streaks whip across, some curling into a loop as they go, and leaves tumble along with the gust, bobbing and spinning.",
+ tags: ["nature", "wind", "air", "gust", "leaves", "directional", "loop"],
+ size: [96, 48],
+ origin: [48, 24],
+ duration: 2,
+ loop: true,
+ fps: 30,
+ bg: "dark",
+ options: { palette: ["#3c4a5c", "#6e8296", "#a8bccc", "#e2eef6"], count: 11, leaves: PAL.leaf, seed: 61 },
+};
+
+const LEAVES = [["..ab", ".abc", "abc."], [".ab.", "abbc", ".cc."], ["ab..", "cba.", ".cba"], [".a.", "abc", "abc", ".c."]];
+
+export function draw(p, t, o) {
+ const C = ramp(o.palette), L = ramp(o.leaves), S = o.seed, D = meta.duration, ph = t / D;
+ const [W, H] = meta.size, [OX, OY] = meta.origin, X0 = -OX, X1 = W - OX - 1, Y0 = -OY, Y1 = H - OY - 1;
+ const inside = (x, y) => x >= X0 && x <= X1 && y >= Y0 && y <= Y1;
+ // streaks: each crosses the canvas a whole number of times a loop, so the loop has no seam
+ for (let i = 0; i < o.count; i++) {
+ const r = rng(S, i), laps = r.int(2, 3), u = fract(r.next() + (laps * t) / D);
+ const len = r.range(22, 44), y0 = r.range(-17, 17), amp = r.range(1, 2.5), curl = r.chance(0.5), R = r.range(2.6, 3.8);
+ const loopLen = curl ? TAU * R : 0, c = len * r.range(0.3, 0.5), span = W + len + 30, head = X0 - 15 + u * span;
+ const near = r.chance(0.55);
+ // s is the distance back along the streak from its head; curlers turn one loop at c, then carry on
+ const path = (s) => {
+ const xl = head - Math.min(s, c) - Math.max(0, s - c - loopLen), base = y0 + Math.sin(xl * 0.07 + i) * amp;
+ if (!curl || s < c || s > c + loopLen) return [xl, base];
+ const a = (s - c) / R;
+ return [head - c - Math.sin(a) * R, base - R + Math.cos(a) * R];
+ };
+ let prev = null;
+ const total = len + loopLen, steps = Math.ceil(total * 1.3);
+ for (let k = 0; k <= steps; k++) {
+ const s2 = (k / steps) * total, pt = path(s2);
+ if (prev && inside(pt[0], pt[1]) && inside(prev[0], prev[1])) {
+ const f = s2 / total; // 0 at the head, 1 at the tail
+ const col = f < 0.12 ? C[3] : f < 0.5 ? (near ? C[2] : C[1]) : C[near ? 1 : 0];
+ p.line(prev[0], prev[1], pt[0], pt[1], col, f > 0.82 ? 0.5 : 1);
+ }
+ prev = pt;
+ }
+ }
+ // leaves riding the gust
+ for (let i = 0; i < 5; i++) {
+ const r = rng(S + 7, i), laps = r.int(1, 2), u = fract(r.next() + (laps * t) / D);
+ const x = X0 - 6 + u * (W + 12), y = r.range(-14, 14) + Math.sin(u * TAU * r.int(1, 3) + i) * r.range(3, 7);
+ if (!inside(x, y) || !inside(x + 3, y + 3)) continue;
+ const frame = LEAVES[(Math.floor(t * r.range(9, 14)) + i) % 4], tone = r.int(0, 2);
+ p.sprite(frame, { a: L[3 + tone], b: L[4 + tone], c: L[2 + tone] }, x, y);
+ }
+}
diff --git a/src/fx/pickups/_lib.js b/src/fx/pickups/_lib.js
new file mode 100644
index 0000000..485802b
--- /dev/null
+++ b/src/fx/pickups/_lib.js
@@ -0,0 +1,151 @@
+// Helpers for the pickups: a scratch layer to build outlined sprites in, floor shadows, twinkles and bobs.
+// Not an effect (the file name starts with _).
+
+import { createFrame, Painter, TAU, WHITE, hex, ramp } from "../../core/index.js";
+
+/**
+ * The palette as at least n color steps, dark to bright, so effects can index C[0]..C[n-1] whatever ramp a
+ * caller passes: a 7-step ramp repeats its brightest step, a short one is stretched step by step (no blending).
+ */
+export function fit(palette, n = 8) {
+ const r = ramp(palette);
+ if (!r.length) return Array(n).fill(WHITE);
+ if (r.length >= n - 1) {
+ while (r.length < n) r.push(r[r.length - 1]);
+ return r;
+ }
+ return Array.from({ length: n }, (_, i) => r[Math.round((i * (r.length - 1)) / (n - 1))]);
+}
+
+/**
+ * A scratch layer: draw a sprite into it with its own painter (same local coordinates as the effect), give
+ * it a dark outline, recolor it, then stamp it onto the frame. Lets a procedural shape get a hand-made
+ * 1 px outline and lets shines sweep across exactly the sprite's pixels.
+ */
+export class Layer {
+ constructor(w = 64, h = 64) {
+ this.f = createFrame(w, h);
+ this.q = new Painter(this.f);
+ this.tmp = new Uint32Array(w * h);
+ }
+ /** Clear it and put its top-left at local (x0, y0). Returns the layer's painter. */
+ begin(x0, y0) {
+ const f = this.f;
+ f.ox = Math.floor(x0);
+ f.oy = Math.floor(y0);
+ f.color.fill(0);
+ f.light.fill(0);
+ return this.q.reset().place(0, 0);
+ }
+ idx(x, y) {
+ const f = this.f, i = Math.floor(x) - f.ox, j = Math.floor(y) - f.oy;
+ return i < 0 || j < 0 || i >= f.w || j >= f.h ? -1 : j * f.w + i;
+ }
+ get(x, y) {
+ const i = this.idx(x, y);
+ return i < 0 ? 0 : this.f.color[i];
+ }
+ set(x, y, c) {
+ const i = this.idx(x, y);
+ if (i >= 0) this.f.color[i] = c;
+ }
+ /** Fill each pixel from fn(x, y) at the pixel's center (x + 0.5, y + 0.5): return a color or 0. */
+ fill(x0, y0, x1, y1, fn) {
+ for (let y = Math.floor(y0); y <= y1; y++)
+ for (let x = Math.floor(x0); x <= x1; x++) {
+ const c = fn(x + 0.5, y + 0.5);
+ if (c) this.set(x, y, c);
+ }
+ }
+ /** A 1 px outline around everything drawn: c is a color or fn(x, y, neighbour color). corners adds diagonals. */
+ outline(c, corners = false) {
+ const f = this.f, C = f.color, T = this.tmp, w = f.w, h = f.h;
+ T.fill(0);
+ for (let j = 0; j < h; j++)
+ for (let i = 0; i < w; i++) {
+ const k = j * w + i;
+ if (C[k]) continue;
+ let n = (i > 0 && C[k - 1]) || (i < w - 1 && C[k + 1]) || (j > 0 && C[k - w]) || (j < h - 1 && C[k + w]);
+ if (!n && corners) n = (i > 0 && j > 0 && C[k - w - 1]) || (i < w - 1 && j > 0 && C[k - w + 1]) || (i > 0 && j < h - 1 && C[k + w - 1]) || (i < w - 1 && j < h - 1 && C[k + w + 1]);
+ if (n) T[k] = typeof c === "function" ? c(i + f.ox, j + f.oy, n) : c;
+ }
+ for (let k = 0; k < w * h; k++) if (T[k]) C[k] = T[k];
+ return this;
+ }
+ /** Recolor every drawn pixel: fn(x, y, c) returns the new color. */
+ map(fn) {
+ const f = this.f, C = f.color;
+ for (let k = 0; k < C.length; k++) if (C[k]) C[k] = fn((k % f.w) + f.ox, Math.floor(k / f.w) + f.oy, C[k]) || C[k];
+ return this;
+ }
+ /** Stamp the layer onto p, offset by (dx, dy), at alpha a (dithered); clip [x0, x1] keeps x0 <= x < x1. */
+ draw(p, dx = 0, dy = 0, a = 1, clip = null) {
+ const f = this.f, C = f.color;
+ for (let k = 0; k < C.length; k++) {
+ if (!C[k]) continue;
+ const x = (k % f.w) + f.ox + dx;
+ if (clip && (x < clip[0] || x >= clip[1])) continue;
+ p.dot(x, Math.floor(k / f.w) + f.oy + dy, C[k], a);
+ }
+ return this;
+ }
+}
+
+const SHADOW = hex("#100e17");
+/**
+ * A floor shadow centered on x, half-width rx: a solid dark band on the floor line (y = 0) and a narrower one
+ * under it, with dithered ends. Shrink rx as the thing above rises.
+ */
+export function shadow(p, x, rx, k = 1) {
+ if (rx < 1) return;
+ for (let row = 0; row < 2; row++) {
+ const w = rx - row * 2;
+ for (let i = Math.floor(x - w); i < Math.ceil(x + w); i++) {
+ const e = Math.abs(i + 0.5 - x) / w;
+ if (e <= 1) p.dot(i, row, SHADOW, row ? k : k * (e < 0.8 ? 1 : 0.5));
+ }
+ }
+}
+
+/** A four-point twinkle of arm length s (whole pixels): white core, bright inner arms, colored tips. */
+export function twinkle(p, x, y, s, c, mid = c, core = WHITE) {
+ s = Math.round(s);
+ if (s <= 0) return;
+ for (let d = 1; d <= s - 1; d++) {
+ const k = d < s / 2 ? mid : c;
+ p.px(x + d, y, k), p.px(x - d, y, k), p.px(x, y + d, k), p.px(x, y - d, k);
+ }
+ if (s >= 4) p.px(x + 1, y + 1, c), p.px(x - 1, y - 1, c), p.px(x + 1, y - 1, c), p.px(x - 1, y + 1, c);
+ p.px(x, y, core);
+}
+
+/** A seamless bob: up-and-down offset in px for loop phase ph (0..1), n bobs a loop. */
+export const bob = (ph, amp, n = 1, off = 0) => -amp * Math.sin((ph * n + off) * TAU);
+
+/**
+ * Fill a puffy shape into layer L from a signed distance sdf(x, y) in px (negative inside). The surface is
+ * flat in the middle and rounds over in a bevel px wide at the edge; color(b, e, x, y) gets the light b
+ * (about -0.3 facing away .. 1 facing the light, 0.62 flat) and the depth e in px from the edge. clip(x, y)
+ * returning true cuts a pixel away without shading the cut (a break, a bite).
+ */
+export function pillow(L, x0, y0, x1, y1, sdf, color, { bevel = 3, light = [-0.5, -0.6, 0.62], clip = null } = {}) {
+ L.fill(x0, y0, x1, y1, (x, y) => {
+ const d = sdf(x, y);
+ if (d > 0 || (clip && clip(x, y))) return 0;
+ const e = -d;
+ let gx = sdf(x + 0.5, y) - sdf(x - 0.5, y), gy = sdf(x, y + 0.5) - sdf(x, y - 0.5);
+ const gl = Math.hypot(gx, gy) || 1;
+ gx /= gl;
+ gy /= gl;
+ const k = Math.max(0, 1 - e / bevel) * 1.25, sn = Math.sin(k), cs = Math.cos(k);
+ return color(gx * sn * light[0] + gy * sn * light[1] + cs * light[2], e, x, y);
+ });
+}
+
+/** Signed distance (px, roughly) to a heart of half-width w centered at (cx, cy): the classic sextic curve. */
+export function heartSdf(x, y, cx, cy, w, h = w) {
+ const S = w / 1.14, X = (x - cx) / S, Y = -(y - cy) / (h / 1.14) + 0.12;
+ const q = X * X + Y * Y - 1, f = q * q * q - X * X * Y * Y * Y;
+ const gx = 6 * X * q * q - 2 * X * Y * Y * Y, gy = 6 * Y * q * q - 3 * X * X * Y * Y;
+ return (f / Math.max(Math.hypot(gx, gy), 0.6)) * S;
+}
diff --git a/src/fx/pickups/ammo-crate.js b/src/fx/pickups/ammo-crate.js
new file mode 100644
index 0000000..d9fc71d
--- /dev/null
+++ b/src/fx/pickups/ammo-crate.js
@@ -0,0 +1,62 @@
+import { PAL, hex, bump, fract, TAU, WHITE } from "../../core/index.js";
+import { Layer, fit } from "./_lib.js";
+
+export const meta = {
+ name: "Ammo crate",
+ desc: "An olive supply crate on the floor, ringed by a pulsing pickup outline with a light chasing round it, a chevron bouncing over it.",
+ tags: ["pickup", "crate", "ammo", "supply", "highlight", "loop"],
+ size: [44, 40],
+ origin: [22, 34],
+ duration: 1.2,
+ loop: true,
+ fps: 30,
+ bg: "ground",
+ options: { palette: PAL.ice, seed: 11 },
+};
+
+const L = new Layer(48, 40);
+const OD = ["#151a0e", "#262f18", "#384522", "#4b5c2c", "#627538", "#7e8f48", "#a3b064"].map(hex);
+const STEEL = ["#1c1c24", "#42424f", "#7d7d8c", "#a4a4b2"].map(hex);
+const STENCIL = hex("#cfc58a");
+const CHEVRON = ["a.....a", ".ab.ba.", "..aba..", "...a..."];
+
+export function draw(p, t, o) {
+ const C = fit(o.palette), ph = t / meta.duration;
+ const pulse = 0.5 + 0.5 * Math.cos(ph * TAU * 2);
+ const q = L.begin(-24, -30);
+ const X0 = -11, X1 = 10, TOPY = -17, FY = -13;
+ // the top face, planks running across
+ for (let y = TOPY; y < FY; y++) for (let x = X0; x <= X1; x++) q.px(x, y, y === TOPY ? OD[6] : (x - X0) % 7 === 6 ? OD[3] : OD[5]);
+ // the front face: three planks, lit left edge, shaded right, a dark lip under the top
+ for (let y = FY; y < 0; y++)
+ for (let x = X0; x <= X1; x++) {
+ let c = y === FY ? OD[2] : (y - FY) % 4 === 0 ? OD[2] : x === X0 ? OD[5] : x >= X1 - 1 ? OD[2] : OD[4];
+ if (y === -1) c = OD[2];
+ q.px(x, y, c);
+ }
+ // steel corners
+ for (const [x, y] of [[X0, FY], [X1 - 2, FY], [X0, -3], [X1 - 2, -3]]) {
+ q.rect(x, y, 3, 3, STEEL[2]);
+ q.px(x + 1, y + 1, STEEL[3]);
+ q.px(x + 2, y + 2, STEEL[1]);
+ }
+ for (const x of [X0, X1 - 2]) q.rect(x, TOPY, 3, 2, STEEL[2]), q.px(x + 1, TOPY, STEEL[3]);
+ // stenciled lettering
+ q.text("AMMO", -0.5, -10, STENCIL, { align: "center" });
+ L.outline(OD[0]);
+ // the pickup outline: pulsing, with a bright run chasing round it
+ L.outline((x, y) => {
+ const a = fract(Math.atan2(y + 9, (x + 0.5) * 0.8) / TAU - ph * 2);
+ const run = a < 0.08 ? 2 : a < 0.16 ? 1 : 0;
+ return run === 2 ? WHITE : run === 1 ? C[6] : pulse > 0.5 ? C[5] : C[4];
+ });
+ L.draw(p);
+ // a double chevron bounces over it, pointing down at it, the near one lit first
+ const hop = Math.abs(Math.sin(ph * TAU));
+ const cy = Math.round(-25 - 3 * hop);
+ p.sprite(CHEVRON, { a: pulse > 0.5 ? C[5] : C[4], b: C[6] }, -3, cy - 3);
+ p.sprite(CHEVRON, { a: C[6], b: WHITE }, -3, cy);
+ p.light(0, cy, C[5], 0.4);
+ p.glowRing(0, -9, 13, 6, C[5], 0.12 + 0.12 * pulse);
+ p.glow(0, -9, 26, C[4], 0.06 + 0.06 * bump(pulse, 0, 1));
+}
diff --git a/src/fx/pickups/chest-open.js b/src/fx/pickups/chest-open.js
new file mode 100644
index 0000000..05e4066
--- /dev/null
+++ b/src/fx/pickups/chest-open.js
@@ -0,0 +1,137 @@
+import { PAL, RAMP, hex, burst, seg, ease, bump, WHITE } from "../../core/index.js";
+import { Layer, twinkle, fit } from "./_lib.js";
+
+export const meta = {
+ name: "Chest open",
+ desc: "A treasure chest rattles, light leaking from the seam, then the lid flies back: beams fan up, coins and gems pop out, bounce and twinkle.",
+ tags: ["pickup", "chest", "treasure", "loot", "reward", "one-shot"],
+ size: [88, 76],
+ origin: [44, 68],
+ duration: 2.2,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ options: { palette: PAL.gold, loot: 7, seed: 15 },
+};
+
+const L = new Layer(48, 44);
+const W = RAMP.wood;
+const GEMS = [["#6e1030", "#e0304a", "#ffb4a8"], ["#0f3d2e", "#2fb86a", "#b4ffcc"], ["#14306e", "#3a7ae8", "#b4dcff"]].map((g) => g.map(hex));
+const X0 = -13, X1 = 12, BASE = -11, LID = -20;
+
+// gold trim at the corners, lit on the left
+const strap = (C, x) => (x === X0 || x === X1 - 1 ? C[5] : x <= X0 + 1 || x >= X1 - 1 ? C[3] : 0);
+
+// the chest in one of four poses: 0 closed, 1 lid lifted off the seam, 2 swinging back, 3 open
+function chest(q, pose, C) {
+ // the box: planks, gold straps, a gold rim, the lock plate
+ for (let y = BASE; y <= -1; y++)
+ for (let x = X0; x <= X1; x++) {
+ let c = (y - BASE) % 4 === 3 ? W[2] : x === X0 + 2 ? W[5] : x >= X1 - 4 ? W[3] : W[4];
+ c = strap(C, x) || c;
+ if (y === BASE) c = x < 0 ? C[5] : C[4];
+ if (y === -1) c = C[2];
+ q.px(x, y, c);
+ }
+ q.rect(-2, BASE, 5, 5, C[4]);
+ q.rect(-2, BASE, 5, 1, C[6]);
+ q.rect(-2, BASE, 1, 5, C[5]);
+ q.px(0, BASE + 2, W[0]), q.px(0, BASE + 3, W[0]), q.px(1, BASE + 2, W[1]);
+ if (pose < 2) {
+ const up = pose === 1 ? 2 : 0;
+ // the closed lid: a rounded top, planks, a gold rim along the front edge
+ for (let y = LID - up; y <= BASE - 1 - up; y++) {
+ const row = y - LID + up, inset = row === 0 ? 3 : row === 1 ? 1 : 0;
+ for (let x = X0 + inset; x <= X1 - inset; x++) {
+ let c = row < 2 ? W[5] : row === 4 ? W[3] : row > 6 ? W[3] : W[4];
+ c = strap(C, x) || c;
+ if (row === 8) c = x < 0 ? C[5] : C[4];
+ q.px(x, y, c);
+ }
+ }
+ q.rect(-1, BASE - 2 - up, 3, 3, C[4]), q.px(-1, BASE - 2 - up, C[6]); // the latch
+ if (up) for (let x = X0 + 1; x < X1; x++) q.px(x, BASE - 1, C[6]), q.px(x, BASE - 2, x % 4 ? C[6] : WHITE);
+ return;
+ }
+ // open: the glowing mouth, then the inside of the lid standing up behind it
+ for (let x = X0 + 1; x < X1; x++) q.px(x, BASE - 1, C[6]), q.px(x, BASE - 2, WHITE);
+ const top = pose === 2 ? BASE - 7 : BASE - 12;
+ for (let y = top; y <= BASE - 3; y++)
+ for (let x = X0; x <= X1; x++) {
+ const row = y - top;
+ let c = row === 1 ? W[3] : row % 3 === 0 ? W[1] : W[2];
+ c = strap(C, x) || c;
+ if (row === 0) c = x < 0 ? C[5] : C[4];
+ q.px(x, y, c);
+ }
+}
+
+// where a piece of loot is after `age` seconds: tossed, then bouncing to a stop on the floor
+function hop(vx, vy, age) {
+ const g = 360;
+ let x = 0, y = BASE - 2, t = age;
+ for (let b = 0; b < 3; b++) {
+ const land = (-vy + Math.sqrt(vy * vy - 2 * g * y)) / g;
+ if (t < land) return [x + vx * t, y + vy * t + 0.5 * g * t * t, b];
+ x += vx * land;
+ y = -1;
+ t -= land;
+ vy = -(b ? 0.2 : 0.4) * (vy + g * land);
+ vx *= 0.5;
+ }
+ return [x, -1, 3];
+}
+
+const COIN = [[".aa.", "abba", "abba", ".bb."], [".a.", "aba", "aba", ".b."], [".a", "ab", "ab", ".b"]];
+
+export function draw(p, t, o) {
+ const C = fit(o.palette), S = o.seed, OPEN = 0.52, fade = 1 - seg(t, 1.75, 2.15);
+ if (fade <= 0) return;
+ // the rattle: faster and harder until it bursts open
+ const rattle = t < OPEN ? Math.round(Math.sin(t * (40 + 90 * t)) * seg(t, 0.08, 0.3)) : 0;
+ const peek = (t > 0.22 && t < 0.27) || (t > 0.38 && t < 0.45);
+ const pose = t < OPEN ? (peek ? 1 : 0) : t < OPEN + 0.05 ? 2 : 3;
+ // beams fan up out of the mouth: solid wedges, white at the core, shrinking away
+ const bk = ease.outCubic(seg(t, OPEN, OPEN + 0.16)), bOut = 1 - ease.inQuad(seg(t, 0.95, 1.5));
+ if (bk > 0 && bOut > 0) {
+ burst(5, S + 3, (r, i) => {
+ const a = -Math.PI / 2 + (i - 2) * 0.36 + r.range(-0.05, 0.05), len = (24 + r.range(0, 12) - Math.abs(i - 2) * 4) * bk * (0.4 + 0.6 * bOut);
+ const x0 = (i - 2) * 3, y0 = BASE - 2, ca = Math.cos(a), sa = Math.sin(a), nx = -sa, ny = ca;
+ const w0 = 1.2 * bOut, w1 = (i % 2 ? 2.4 : 3.6) * bOut;
+ const wedge = (k, c) =>
+ p.poly([[x0 + nx * w0 * k, y0 + ny * w0 * k], [x0 + ca * len + nx * w1 * k, y0 + sa * len + ny * w1 * k], [x0 + ca * len - nx * w1 * k, y0 + sa * len - ny * w1 * k], [x0 - nx * w0 * k, y0 - ny * w0 * k]], c);
+ wedge(1, C[5]);
+ wedge(0.45, WHITE);
+ p.glowLine(x0, y0, x0 + ca * len, y0 + sa * len, 6, C[5], 0.2 * bOut);
+ });
+ }
+ // the chest
+ const q = L.begin(-24, -34);
+ q.place(rattle, 0);
+ chest(q, pose, C);
+ L.outline(W[0]);
+ L.draw(p, 0, 0, fade);
+ if (peek) p.glowLine(X0, BASE - 1, X1, BASE - 1, 7, C[5], 0.5);
+ // loot: coins and gems arc out to both sides, bounce, settle and twinkle
+ burst(o.loot, S, (r, i) => {
+ const born = OPEN + 0.04 + i * 0.045, age = t - born;
+ if (age < 0) return;
+ const side = i % 2 ? 1 : -1, vx = side * r.range(12, 34), vy = -r.range(110, 150);
+ const [x, y, b] = hop(vx, vy, age), X = Math.round(x), Y = Math.round(y);
+ if (i % 3 === 2) {
+ const G = GEMS[i % GEMS.length];
+ p.sprite([".a.", "abc", "bbc", "bcc", ".c."], { a: G[2], b: G[1], c: G[0] }, X - 1, Y - 4, { a: fade });
+ } else {
+ const spin = b < 3 ? Math.floor(age * 14 + i) % 3 : 0;
+ p.sprite(COIN[spin], { a: C[6], b: C[4] }, X - (spin === 0 ? 2 : 1), Y - 3, { a: fade });
+ }
+ p.light(X, Y - 2, C[5], 0.3 * fade);
+ const tw = bump(age, 0.8 + r.range(0, 0.25), 1.1 + r.range(0, 0.25));
+ if (tw > 0) twinkle(p, X + 1, Y - 5, Math.round(1 + tw * 2), C[5], C[6]);
+ });
+ // the flash as the lid flies, then a warm light that lingers
+ const fl = 1 - seg(t, OPEN, OPEN + 0.5);
+ if (t >= OPEN && t < OPEN + 0.07) p.ellipse(0, BASE - 2, 15, 5, WHITE);
+ if (t >= OPEN && fl > 0) p.glow(0, BASE - 4, 44, C[5], 0.55 * fl * fl);
+ p.glow(0, BASE, 26, C[4], 0.14 * fade * (t < OPEN ? seg(t, 0.15, OPEN) : 1));
+}
diff --git a/src/fx/pickups/coin-spin.js b/src/fx/pickups/coin-spin.js
new file mode 100644
index 0000000..f1a1b07
--- /dev/null
+++ b/src/fx/pickups/coin-spin.js
@@ -0,0 +1,59 @@
+import { PAL, TAU, bump } from "../../core/index.js";
+import { Layer, shadow, twinkle, bob, fit } from "./_lib.js";
+
+export const meta = {
+ name: "Coin spin",
+ desc: "A fat gold coin turning on its edge in ten hand-timed poses, bobbing over its shadow, a glint when it faces you.",
+ tags: ["pickup", "coin", "gold", "money", "loop"],
+ size: [32, 36],
+ origin: [16, 32],
+ duration: 1,
+ loop: true,
+ fps: 30,
+ bg: "ground",
+ options: { palette: PAL.gold, radius: 7, poses: 10, shadow: true, seed: 1 },
+};
+
+const L = new Layer(40, 40);
+
+export function draw(p, t, o) {
+ const C = fit(o.palette), R = o.radius, T = 3, ph = t / meta.duration;
+ // poses are held like hand-drawn frames; the bob runs smooth underneath
+ const pose = Math.floor(ph * o.poses) / o.poses, th = pose * TAU;
+ const cs = Math.cos(th), sn = Math.sin(th), rx = Math.max(0.6, R * Math.abs(cs));
+ const xf = (T / 2) * sn * Math.sign(cs || 1), a = Math.abs(xf);
+ const cy = Math.round(-R - 8 + bob(ph, 2));
+ // the face leans toward the light (top left) or away from it as it turns
+ const lean = -sn * Math.sign(cs || 1) * 0.5;
+ L.begin(-R - 4, cy - R - 3);
+ L.fill(-R - 3, cy - R - 2, R + 3, cy + R + 2, (x, y) => {
+ const v = (y - cy) / R;
+ if (Math.abs(v) > 1) return 0;
+ const half = rx * Math.sqrt(1 - v * v);
+ if (Math.max(0, Math.abs(x) - a) > half) return 0;
+ if (Math.abs(x - xf) > half) {
+ // the reeded rim: ticks on alternate rows, lit on the left
+ const side = x < xf ? 1 : 0;
+ return (Math.floor(y) & 1) ? C[2 + side] : C[3 + side];
+ }
+ // distance in px to the face's edge (ellipse gradient estimate), so the lip stays a pixel wide however thin
+ const X = x - xf, Y = y - cy, U = X / rx;
+ const g = 2 * Math.sqrt((X * X) / rx ** 4 + (Y * Y) / R ** 4) || 1e-6, e = (1 - U * U - v * v) / g;
+ const nd = Math.hypot(U, v) || 1e-6, lit = -(U * 0.6 + v * 0.8) / nd;
+ if (e < 1.3) return lit > 0.6 ? C[6] : lit > -0.3 ? C[5] : C[3]; // the raised lip, lit top left
+ if (e < 2.3) return lit > 0.1 ? C[3] : C[5]; // its inner wall: in shadow top left, catching light bottom right
+ if (Math.abs(U) < 0.26 && Math.abs(v) < 0.42) return U < 0 ? C[6] : C[5]; // a stamped bar
+ return lean < -0.2 ? C[3] : C[4];
+ });
+ L.outline(C[1]);
+ L.draw(p);
+ // a glint when it faces you
+ const g = bump(ph, 0.02, 0.24);
+ if (g > 0) {
+ const gx = Math.round(R * 0.55), gy = cy - Math.round(R * 0.6);
+ twinkle(p, gx, gy, 1 + Math.round(g * 3), C[5], C[6]);
+ p.light(gx, gy, C[6], 0.6 * g);
+ }
+ p.glow(0, cy, R * 2.2, C[4], 0.08 + 0.05 * Math.abs(cs));
+ if (o.shadow) shadow(p, 0, (Math.max(rx, a + 1) + 1) * (0.9 + 0.1 * Math.sin(ph * TAU)));
+}
diff --git a/src/fx/pickups/collect-burst.js b/src/fx/pickups/collect-burst.js
new file mode 100644
index 0000000..f66b446
--- /dev/null
+++ b/src/fx/pickups/collect-burst.js
@@ -0,0 +1,48 @@
+import { PAL, burst, seg, ease, bump, TAU, WHITE } from "../../core/index.js";
+import { twinkle, fit } from "./_lib.js";
+
+export const meta = {
+ name: "Collect burst",
+ desc: "The pop when you grab something: a white flash, a thin ring snapping out, eight twinkles thrown wide on a spiral, a pinch of glitter.",
+ tags: ["pickup", "collect", "sparkle", "burst", "one-shot"],
+ size: [48, 48],
+ origin: [24, 24],
+ duration: 0.6,
+ loop: false,
+ fps: 30,
+ bg: "dark",
+ options: { palette: PAL.holy, count: 8, seed: 14 },
+};
+
+export function draw(p, t, o) {
+ const C = fit(o.palette), S = o.seed;
+ // the flash: two frames of solid white, then a shrinking core
+ if (t < 0.07) p.circle(0, 0, 4 + 30 * t, WHITE);
+ else if (t < 0.14) p.circle(0, 0, 3 * (1 - seg(t, 0.07, 0.14)), C[6]);
+ // the ring snaps out and thins
+ const rk = seg(t, 0.02, 0.26);
+ if (rk > 0 && rk < 1) {
+ const r = 4 + 15 * ease.outCubic(rk);
+ p.ring(0, 0, r, rk < 0.4 ? 2 : 1, rk < 0.5 ? C[6] : C[4], rk < 0.75 ? 1 : 0.5);
+ p.glowRing(0, 0, r, 4, C[5], 0.35 * (1 - rk));
+ }
+ // twinkles thrown out on a slight spiral, big and small alternating, shrinking as they go
+ burst(o.count, S, (r, i) => {
+ const life = r.range(0.38, 0.52), k = t / life;
+ if (t < 0.03 || k >= 1) return;
+ const a = (i / o.count) * TAU + r.range(-0.2, 0.2) + 0.5 * ease.outCubic(k), reach = (i % 2 ? 12 : 17) * r.range(0.85, 1.1);
+ const d = 3 + reach * ease.outExpo(k), x = Math.cos(a) * d, y = Math.sin(a) * d;
+ const s = Math.round((i % 2 ? 2 : 3.4) * (1 - ease.inQuad(k)) + 0.4);
+ twinkle(p, Math.round(x), Math.round(y), s, C[4], C[5]);
+ p.light(x, y, C[5], 0.5 * (1 - k));
+ });
+ // glitter: specks drifting out past the twinkles, blinking off
+ burst(10, S + 1, (r) => {
+ const life = r.range(0.3, 0.48), k = t / life, born = r.range(0.03, 0.08);
+ if (t < born || k >= 1) return;
+ const a = r.range(0, TAU), d = r.range(6, 21) * ease.outCubic(seg(t, born, life));
+ if (k > 0.6 && Math.floor(t * 30) % 2) return;
+ p.px(Math.cos(a) * d, Math.sin(a) * d, k < 0.5 ? C[6] : C[4]);
+ });
+ p.glow(0, 0, 22, C[4], 0.55 * bump(t, 0, 0.3) * (1 - seg(t, 0, 0.3)) + 0.5 * (t < 0.07 ? 1 : 0));
+}
diff --git a/src/fx/pickups/crystal-shard.js b/src/fx/pickups/crystal-shard.js
new file mode 100644
index 0000000..b4af7f8
--- /dev/null
+++ b/src/fx/pickups/crystal-shard.js
@@ -0,0 +1,79 @@
+import { PAL, bump, TAU } from "../../core/index.js";
+import { Layer, shadow, twinkle, bob, fit } from "./_lib.js";
+
+export const meta = {
+ name: "Crystal shard",
+ desc: "A tall six-sided crystal turning slowly in the air, lit from within, three splinters orbiting it, behind and in front.",
+ tags: ["pickup", "crystal", "mana", "magic", "loop"],
+ size: [40, 50],
+ origin: [20, 46],
+ duration: 2,
+ loop: true,
+ fps: 30,
+ bg: "ground",
+ options: { palette: PAL.cyber, shards: 3, shadow: true, seed: 3 },
+};
+
+const L = new Layer(32, 40);
+const N = 6, STEP = TAU / N;
+const LX = -0.6, LY = -0.4, LZ = 0.69;
+const SPLINTER = [".c.", "cbb", "bba", ".a."];
+
+function body(p, t, o) {
+ const C = fit(o.palette), ph = t / meta.duration, th = ph * STEP * 4;
+ const cy = Math.round(-24 + bob(ph, 2.5)), TIP = cy - 14, SH = cy - 8, BASE = cy + 5, END = cy + 10;
+ const prof = (y) =>
+ y < SH ? [5 * ((y - TIP) / (SH - TIP)), 0.62] : y < BASE ? [5 - 0.6 * ((y - SH) / (BASE - SH)), 0] : [4.4 * (1 - (y - BASE) / (END - BASE)), -0.65];
+ L.begin(-12, TIP - 3);
+ L.fill(-8, TIP, 8, END, (x, y) => {
+ if (y < TIP || y > END) return 0;
+ const [r, tilt] = prof(y);
+ if (r <= 0.3) return 0;
+ const s = x / r;
+ for (let k = 0; k < N; k++) {
+ const a0 = th + k * STEP, mid = a0 + STEP / 2;
+ if (Math.cos(mid) <= 0) continue;
+ const x0 = Math.sin(a0), x1 = Math.sin(a0 + STEP);
+ if (s < x0 || s >= x1) continue;
+ const ct = Math.cos(tilt), nx = Math.sin(mid) * ct, ny = -Math.sin(tilt), nz = Math.cos(mid) * ct;
+ const b = nx * LX + ny * LY + nz * LZ; // about -0.4 (facing away) .. 1 (facing the light)
+ const seam = Math.min(s - x0, x1 - s) * r < 0.55 ? 1 : 0; // a bright line where two faces meet
+ const step = (b > 0.8 ? 5 : b > 0.45 ? 4 : b > 0 ? 3 : 2) + seam;
+ return C[Math.min(6, step)];
+ }
+ return 0;
+ });
+ L.outline(C[1]);
+ L.draw(p);
+ return { C, cy, ph, TIP, SH };
+}
+
+// three splinters ride an ellipse around it, behind on the far side and in front on the near side
+function splinters(p, t, o, front) {
+ const C = fit(o.palette), ph = t / meta.duration, cy = Math.round(-24 + bob(ph, 2.5));
+ for (let i = 0; i < o.shards; i++) {
+ const a = ph * TAU + (i * TAU) / o.shards, depth = Math.sin(a);
+ if (depth >= 0 !== front) continue;
+ const x = Math.round(Math.cos(a) * 13), y = Math.round(cy + 2 + depth * 4 + Math.sin(a * 2 + i) * 1.5);
+ p.sprite(SPLINTER, front ? { a: C[2], b: C[4], c: C[6] } : { a: C[1], b: C[2], c: C[4] }, x - 1, y - 2);
+ p.light(x, y, C[5], front ? 0.35 : 0.15);
+ }
+}
+
+export function drawBack(p, t, o) {
+ splinters(p, t, o, false);
+}
+
+export function draw(p, t, o) {
+ const { C, cy, ph, TIP } = body(p, t, o);
+ splinters(p, t, o, true);
+ const g = bump(ph, 0.3, 0.5);
+ if (g > 0) {
+ twinkle(p, -2, TIP + 3, 1 + Math.round(g * 3.5), C[5], C[6]);
+ p.light(-2, TIP + 3, C[6], 0.6 * g);
+ }
+ const pulse = 0.85 + 0.15 * Math.sin(ph * TAU * 2);
+ p.glow(0, cy - 3, 26, C[4], 0.14 * pulse);
+ p.glow(0, cy - 2, 8, C[6], 0.1 * pulse);
+ if (o.shadow) shadow(p, 0, 5 + bob(ph, 0.8));
+}
diff --git a/src/fx/pickups/gem-spin.js b/src/fx/pickups/gem-spin.js
new file mode 100644
index 0000000..235b5b9
--- /dev/null
+++ b/src/fx/pickups/gem-spin.js
@@ -0,0 +1,69 @@
+import { at, bump, cycle, TAU } from "../../core/index.js";
+import { Layer, shadow, twinkle, bob, fit } from "./_lib.js";
+
+export const meta = {
+ name: "Gem spin",
+ desc: "A cut ruby turning on its axis: eight facets slide past the light, the crown lit, the pavilion glowing from within, a glint.",
+ tags: ["pickup", "gem", "jewel", "treasure", "loop"],
+ size: [32, 40],
+ origin: [16, 36],
+ duration: 1.6,
+ loop: true,
+ fps: 30,
+ bg: "ground",
+ options: { palette: ["#1a0410", "#40081e", "#78102c", "#b8163a", "#ec2a48", "#ff6670", "#ffc2c2", "#ffffff"], shadow: true, seed: 2 },
+};
+
+const L = new Layer(40, 40);
+const N = 8, STEP = TAU / N;
+// light from the upper left, toward the viewer; the pavilion takes it mirrored (light bouncing inside)
+const LX = -0.55, LY = -0.55, LZ = 0.63;
+
+export function draw(p, t, o) {
+ const C = fit(o.palette), ph = t / meta.duration;
+ const th = ph * STEP * 6; // six facets slide past per loop: the octagon repeats every STEP, so this loops
+ const cy = Math.round(-15 + bob(ph, 2)), TOP = cy - 7, GIR = cy - 2, BOT = cy + 9;
+ const radius = (y) => (y < GIR ? 4 + (4 * (y - TOP)) / (GIR - TOP) : 8 * (1 - (y - GIR) / (BOT - GIR)));
+ L.begin(-12, TOP - 3);
+ L.fill(-11, TOP, 11, BOT, (x, y) => {
+ if (y < TOP || y > BOT) return 0;
+ const r = radius(y);
+ if (r <= 0.2) return 0;
+ const s = x / r;
+ // the front facet under this pixel
+ for (let k = 0; k < N; k++) {
+ const a0 = th + k * STEP, mid = a0 + STEP / 2;
+ if (Math.cos(mid) <= 0) continue;
+ const x0 = Math.sin(a0), x1 = Math.sin(a0 + STEP);
+ if (s < x0 || s >= x1) continue;
+ const crown = y < GIR, tilt = crown ? 0.75 : -0.7, ct = Math.cos(tilt);
+ const nx = Math.sin(mid) * ct, ny = -Math.sin(tilt), nz = Math.cos(mid) * ct;
+ // b runs about 0 (facing away) to 1 (facing the light)
+ const b = crown ? nx * LX + ny * LY + nz * LZ : -nx * LX + ny * -LY + nz * LZ * 0.6;
+ const edge = Math.min(s - x0, x1 - s) * r < 0.6 ? 0.18 : 0; // facet edges read as a lighter seam
+ if (crown && y < TOP + 1) return b > 0.5 ? C[6] : C[5]; // the table's front edge
+ return crown ? at(C.slice(3, 7), b * 0.8 + edge) : at(C.slice(2, 6), b * 0.95 + edge);
+ }
+ return 0;
+ });
+ // the girdle: a hard bright line where crown meets pavilion
+ for (let x = -8; x < 8; x++) if (L.get(x, GIR)) L.set(x, GIR, x < 0 ? C[6] : C[5]);
+ L.outline(C[1]);
+ L.draw(p);
+ // glints ride the crown's edge once a loop, and a smaller one on the pavilion
+ const g = bump(ph, 0.55, 0.8);
+ if (g > 0) {
+ twinkle(p, -5, TOP, 1 + Math.round(g * 3.4), C[5], C[6]);
+ p.light(-5, TOP, C[6], 0.7 * g);
+ }
+ const g2 = bump(ph, 0.1, 0.25);
+ if (g2 > 0) twinkle(p, 3, cy + 3, 1 + Math.round(g2 * 2), C[6], C[6]);
+ // motes of red light drift off it
+ cycle(t, meta.duration, 4, o.seed, 0.8, (age, life, r) => {
+ const k = age / life, x = r.range(-9, 9), y = cy + r.range(-4, 6) - age * 10;
+ if (k < 0.8) p.px(x, y, k < 0.4 ? C[6] : C[5]);
+ p.light(x, y, C[5], 0.4 * (1 - k));
+ });
+ p.glow(0, cy, 22, C[4], 0.08 + 0.03 * Math.sin(ph * TAU * 2));
+ if (o.shadow) shadow(p, 0, 6.5 + bob(ph, 0.8));
+}
diff --git a/src/fx/pickups/heart-pickup.js b/src/fx/pickups/heart-pickup.js
new file mode 100644
index 0000000..5b27936
--- /dev/null
+++ b/src/fx/pickups/heart-pickup.js
@@ -0,0 +1,48 @@
+import { PAL, cycle, ease, bump, WHITE } from "../../core/index.js";
+import { Layer, shadow, twinkle, bob, pillow, heartSdf, fit } from "./_lib.js";
+
+export const meta = {
+ name: "Heart pickup",
+ desc: "A plump red heart floating over its shadow, beating lub-dub with a squash on each beat, tiny hearts drifting off it.",
+ tags: ["pickup", "heart", "health", "life", "loop"],
+ size: [36, 42],
+ origin: [18, 38],
+ duration: 1,
+ loop: true,
+ fps: 30,
+ bg: "ground",
+ options: { palette: PAL.blood, shadow: true, seed: 4 },
+};
+
+const L = new Layer(40, 40);
+const MINI = [".a.a.", "abbba", ".aba.", "..a.."];
+
+// tiny hearts float off from behind it and fade
+export function drawBack(p, t, o) {
+ const C = fit(o.palette), ph = t / meta.duration, cy = Math.round(-17 + bob(ph, 1.5));
+ cycle(t, meta.duration, 3, o.seed, 0.85, (age, life, r, i) => {
+ const side = i % 2 ? 1 : -1, k = age / life;
+ const x = side * r.range(6, 12) + Math.sin(age * 7 + r.next() * 6) * 1.5, y = cy - 4 - age * r.range(12, 16);
+ if (k > 0.75 && Math.floor(age * 30) % 2) return;
+ p.sprite(MINI, { a: k < 0.5 ? C[4] : C[3], b: k < 0.4 ? C[6] : C[5] }, Math.round(x) - 2, Math.round(y) - 2);
+ });
+}
+
+export function draw(p, t, o) {
+ const C = fit(o.palette), ph = t / meta.duration;
+ // lub-dub: a big fast swell, a smaller echo, then rest
+ const beat = 0.2 * ease.outQuad(bump(ph, 0, 0.16)) + 0.1 * bump(ph, 0.2, 0.34);
+ const w = 7.5 * (1 + beat), h = 7.5 * (1 + beat * 0.55);
+ const cy = Math.round(-17 + bob(ph, 1.5));
+ L.begin(-16, cy - 14);
+ pillow(L, -13, cy - 12, 13, cy + 12, (x, y) => heartSdf(x, y, 0, cy, w, h), (b, e) => {
+ if (b > 0.93 && e > 1) return WHITE;
+ return b > 0.8 ? C[6] : b > 0.55 ? C[5] : b > 0.3 ? C[4] : b > 0.1 ? C[3] : C[2];
+ }, { bevel: 3.5 });
+ L.outline(C[1]);
+ L.draw(p);
+ const g = bump(ph, 0.04, 0.3);
+ if (g > 0) twinkle(p, -4, cy - 5, 1 + Math.round(g * 2.4), C[5], C[6]);
+ p.glow(0, cy, 20 + 8 * beat, C[4], 0.12 + 0.5 * beat);
+ if (o.shadow) shadow(p, 0, 6 + bob(ph, 0.6) + beat * 6);
+}
diff --git a/src/fx/pickups/key-glint.js b/src/fx/pickups/key-glint.js
new file mode 100644
index 0000000..dd0799c
--- /dev/null
+++ b/src/fx/pickups/key-glint.js
@@ -0,0 +1,55 @@
+import { PAL, bump, TAU, WHITE } from "../../core/index.js";
+import { Layer, shadow, twinkle, bob, fit } from "./_lib.js";
+
+export const meta = {
+ name: "Key glint",
+ desc: "A silver key hanging in the air, bobbing and swaying on a slow swing; a glint runs from the bow to the teeth and sparks off the tip.",
+ tags: ["pickup", "key", "unlock", "item", "loop"],
+ size: [40, 40],
+ origin: [20, 36],
+ duration: 1.6,
+ loop: true,
+ fps: 30,
+ bg: "ground",
+ options: { palette: PAL.metal, shadow: true, seed: 7 },
+};
+
+const L = new Layer(40, 40);
+const UPLEFT = (-3 * Math.PI) / 4;
+
+export function draw(p, t, o) {
+ const C = fit(o.palette), ph = t / meta.duration;
+ const cy = -18 + bob(ph, 2), ang = -0.62 + 0.13 * Math.sin(ph * TAU + 0.8);
+ const q = L.begin(-20, -36);
+ q.place(0, Math.round(cy), false, ang);
+ // key-local space: the bow on the left, the shaft running right, the bit hanging under the tip
+ const metal = (x, y) => (y < -0.4 ? C[6] : y < 0.6 ? C[5] : C[3]);
+ // the bow: a thick ring, its outer face lit top left and its inner wall lit bottom right
+ q.ring(-6.5, 0, 5, 3, (v, a) => {
+ const f = Math.cos(a - UPLEFT - ang);
+ return v > 0.45 ? (f > 0.35 ? C[6] : f > -0.45 ? C[5] : C[3]) : f > 0.2 ? C[3] : C[5];
+ });
+ q.poly([[-2, -1.5], [9.5, -1.5], [9.5, 1.5], [-2, 1.5]], metal); // the shaft
+ q.poly([[-2.2, -2.6], [-0.4, -2.6], [-0.4, 2.6], [-2.2, 2.6]], (x, y) => (y < 0 ? C[6] : C[4])); // the collar
+ q.poly([[5, 1], [7, 1], [7, 4.5], [5, 4.5]], (x, y) => (x < 6 ? C[5] : C[3])); // the bit's two teeth
+ q.poly([[8, 1], [9.5, 1], [9.5, 3.5], [8, 3.5]], (x, y) => (x < 8.8 ? C[5] : C[3]));
+ L.outline(C[1]);
+ // a glint runs along the key: a narrow band of white crossing it once a loop
+ const run = (ph - 0.36) / 0.26, sweep = -13 + 25 * run, ca = Math.cos(ang), sa = Math.sin(ang), Y = Math.round(cy);
+ if (run > 0 && run < 1)
+ L.map((x, y, c) => {
+ if (c === C[1]) return c;
+ const d = Math.abs((x + 0.5) * ca + (y + 0.5 - Y) * sa - sweep);
+ return d < 0.8 ? WHITE : d < 1.6 ? C[6] : c;
+ });
+ L.draw(p);
+ // the tip sparks when the glint gets there
+ const g = bump(ph, 0.58, 0.8);
+ if (g > 0) {
+ const tx = Math.cos(ang) * 10, ty = cy + Math.sin(ang) * 10;
+ twinkle(p, Math.round(tx), Math.round(ty) - 1, 1 + Math.round(g * 3.5), C[5], C[6]);
+ p.light(tx, ty, C[6], 0.6 * g);
+ }
+ p.glow(0, cy, 18, C[5], 0.08);
+ if (o.shadow) shadow(p, 1, 7 + bob(ph, 0.8));
+}
diff --git a/src/fx/pickups/loot-beam.js b/src/fx/pickups/loot-beam.js
new file mode 100644
index 0000000..a239f99
--- /dev/null
+++ b/src/fx/pickups/loot-beam.js
@@ -0,0 +1,58 @@
+import { RAMP, cycle, fract, seg, ease, TAU, WHITE } from "../../core/index.js";
+import { Layer, fit } from "./_lib.js";
+
+export const meta = {
+ name: "Loot beam",
+ desc: "A dropped sword on the floor sends up a pillar of rarity light: bands climb it, motes rise inside, a ring pulses out at its foot. The palette sets the rarity.",
+ tags: ["pickup", "loot", "drop", "rarity", "beam", "loop"],
+ size: [44, 80],
+ origin: [22, 72],
+ duration: 1.5,
+ loop: true,
+ fps: 30,
+ bg: "ground",
+ // legendary orange; try PAL.arcane (epic), PAL.electric (rare), PAL.heal (uncommon)
+ options: { palette: ["#1e0c04", "#4a1e06", "#8a3a0a", "#d0640e", "#ff9a1e", "#ffc860", "#ffeab0", "#ffffff"], height: 68, seed: 12 },
+};
+
+const L = new Layer(32, 16);
+const STEEL = RAMP.metal, GRIP = RAMP.wood;
+
+export function draw(p, t, o) {
+ const C = fit(o.palette), ph = t / meta.duration, H = o.height;
+ // the pillar: three nested columns (wide and deep, narrower and brighter, a white core), each ending in a
+ // dithered tip at its own height; light bands climb all three
+ const cols = [[3.6, 0.6, C[3], C[4]], [2.1, 0.8, C[5], C[5]], [1, 0.95, C[6], C[6]]];
+ for (const [w, top, c, cb] of cols) {
+ const h = H * top;
+ p.shade(-w - 1, -h, w + 1, -1, (x, y, out) => {
+ const v = -y / h, ww = w * (v > 0.75 ? 1 - (v - 0.75) * 1.6 : 1);
+ if (Math.abs(x + 0.5) > ww) return;
+ out.c = fract(-y / 12 - ph * 3) < 0.25 ? cb : c;
+ out.a = v > 0.7 ? 1 - (v - 0.7) / 0.3 : 1;
+ });
+ }
+ // the ring at its foot, pulsing out once a loop
+ const rk = ease.outCubic(seg(ph, 0, 0.6));
+ if (rk < 0.95) p.ellipse(0, 0, 4 + 13 * rk, 1.5 + 3 * rk, rk < 0.4 ? C[6] : rk < 0.75 ? C[5] : C[3], (d) => (d > 0.74 ? 1 : 0));
+ // motes rise inside it
+ cycle(t, meta.duration, 9, o.seed, (r) => r.range(0.6, 1.1), (age, life, r) => {
+ const k = age / life, x = r.range(-4, 4) + Math.sin(age * 6 + r.next() * TAU), y = -2 - age * r.range(30, 55);
+ if (-y > H * 0.9) return;
+ p.px(x, y, k < 0.5 ? WHITE : C[6]);
+ p.light(x, y, C[5], 0.4 * (1 - k));
+ });
+ // the item: a short sword lying on the floor, its guard and pommel in the rarity colour
+ const q = L.begin(-16, -8);
+ for (let x = -3; x <= 7; x++) q.px(x, -3, STEEL[6]), q.px(x, -2, STEEL[4]);
+ q.px(8, -3, STEEL[5]);
+ q.rect(-5, -5, 2, 5, C[4]);
+ q.px(-5, -5, C[6]);
+ q.rect(-9, -3, 4, 2, GRIP[3]);
+ q.px(-9, -3, GRIP[5]), q.px(-7, -3, GRIP[5]);
+ q.rect(-11, -3, 2, 2, C[5]);
+ L.outline(C[1]);
+ L.draw(p);
+ p.glowLine(0, -2, 0, -H * 0.7, 11, C[4], 0.28);
+ p.glow(0, -2, 18, C[5], 0.3);
+}
diff --git a/src/fx/pickups/magnet-pull.js b/src/fx/pickups/magnet-pull.js
new file mode 100644
index 0000000..aecd21a
--- /dev/null
+++ b/src/fx/pickups/magnet-pull.js
@@ -0,0 +1,70 @@
+import { PAL, RAMP, cycle, ease, bump, TAU, WHITE } from "../../core/index.js";
+import { Layer, fit } from "./_lib.js";
+
+export const meta = {
+ name: "Magnet pull",
+ desc: "A horseshoe magnet facing right hauls in sparks and tumbling coins: they curve in from a wide fan, speeding up, and flash into the gap between its poles.",
+ tags: ["pickup", "magnet", "power-up", "attract", "directional", "loop"],
+ size: [68, 48],
+ origin: [26, 24],
+ duration: 1.2,
+ loop: true,
+ fps: 30,
+ bg: "dark",
+ options: { palette: PAL.electric, count: 20, seed: 13 },
+};
+
+const L = new Layer(28, 24);
+const RED = RAMP.blood, STEEL = RAMP.metal, GOLD = RAMP.gold;
+
+// the magnet: a thick red U opening to the right, steel pole tips, lit from the top; it shudders a pixel on the beat
+function magnet(p, kick) {
+ const q = L.begin(-24, -12);
+ q.place(-kick, 0);
+ q.arc(-12, 0, 8, 4, Math.PI * 0.5, Math.PI * 1.5, (u, v) => (u < 0.22 ? RED[4] : u < 0.62 ? (v > 0.55 ? RED[6] : RED[5]) : u < 0.85 ? RED[4] : RED[3]));
+ for (let x = -12; x < -4; x++) {
+ q.px(x, -8, RED[6]), q.px(x, -7, RED[5]), q.px(x, -6, RED[5]), q.px(x, -5, RED[3]);
+ q.px(x, 4, RED[5]), q.px(x, 5, RED[4]), q.px(x, 6, RED[3]), q.px(x, 7, RED[2]);
+ }
+ for (let x = -4; x < -1; x++) {
+ q.px(x, -8, STEEL[7]), q.px(x, -7, STEEL[6]), q.px(x, -6, STEEL[5]), q.px(x, -5, STEEL[3]);
+ q.px(x, 4, STEEL[6]), q.px(x, 5, STEEL[5]), q.px(x, 6, STEEL[4]), q.px(x, 7, STEEL[3]);
+ }
+ L.outline(RED[1]);
+ L.draw(p);
+}
+
+export function draw(p, t, o) {
+ const C = fit(o.palette), D = meta.duration;
+ let land = 0;
+ // the field: a soft cone of light in front of the poles, breathing with the pull
+ p.glowLine(0, 0, 26, 0, 13, C[3], 0.1 + 0.04 * Math.sin((t / D) * TAU * 2));
+ // sparks: born on a wide fan to the right, spiralling in to the gap, faster and faster
+ cycle(t, D, o.count, o.seed, (r) => r.range(0.5, 0.8), (age, life, r, i) => {
+ const k = age / life, a0 = ((i + r.range(0.1, 0.9)) / o.count - 0.5) * 2.7, R0 = r.range(22, 34), turn = r.range(0.3, 0.7) * Math.sign(a0 || 1);
+ const at = (q) => {
+ const e = ease.inQuad(q), rad = R0 * (1 - e), a = a0 * (1 - e) + turn * Math.sin(e * Math.PI);
+ return [Math.cos(a) * rad, Math.sin(a) * rad * 0.7];
+ };
+ const [x, y] = at(k), [tx, ty] = at(Math.max(0, k - 0.14));
+ if (k > 0.9) land = Math.max(land, (k - 0.9) / 0.1);
+ const kind = i % 4;
+ if (kind === 0) {
+ // a coin tumbling in, flat then edge-on
+ const edge = Math.floor(age * 16) % 2;
+ p.rect(Math.round(x) - 1, Math.round(y) - 1, edge ? 1 : 2, 2, GOLD[5]);
+ p.px(Math.round(x) - 1, Math.round(y) - 1, GOLD[6]);
+ } else {
+ if (k > 0.25) p.line(tx, ty, x, y, (u) => (u > 0.55 ? C[4] : C[2]));
+ p.px(x, y, k > 0.7 ? WHITE : C[5]);
+ }
+ p.light(x, y, C[4], 0.25 + 0.35 * k);
+ });
+ const kick = bump((t / D) * 4 % 1, 0, 0.3) > 0.5 ? 1 : 0;
+ magnet(p, kick);
+ // the gap glows, flaring as sparks land
+ const fl = 0.5 + 0.5 * Math.sin((t / D) * TAU * 4);
+ p.glow(0, 0, 10, C[4], 0.25 + 0.2 * fl);
+ p.glow(0, 0, 3, C[6], 0.3 + 0.3 * land);
+ p.glow(-8, 0, 26, C[3], 0.1);
+}
diff --git a/src/fx/pickups/potion.js b/src/fx/pickups/potion.js
new file mode 100644
index 0000000..10108e8
--- /dev/null
+++ b/src/fx/pickups/potion.js
@@ -0,0 +1,71 @@
+import { PAL, hex, cycle, TAU, WHITE } from "../../core/index.js";
+import { Layer, shadow, bob, fit } from "./_lib.js";
+
+export const meta = {
+ name: "Potion",
+ desc: "A round glass flask of glowing brew floating over its shadow: the surface sloshes with the bob, bubbles rise and pop, wisps curl off the cork.",
+ tags: ["pickup", "potion", "flask", "mana", "loop"],
+ size: [36, 48],
+ origin: [18, 44],
+ duration: 1.5,
+ loop: true,
+ fps: 30,
+ bg: "ground",
+ options: { palette: PAL.arcane, fill: 0.6, shadow: true, seed: 8 },
+};
+
+const L = new Layer(40, 40);
+const GLASS = [hex("#16141f"), hex("#2a2738"), hex("#3c3850"), hex("#8f8aa8"), hex("#d8d4ec")];
+const CORK = [hex("#3d2414"), hex("#6a421e"), hex("#8e5c2c"), hex("#b47c40")];
+
+export function draw(p, t, o) {
+ const C = fit(o.palette), ph = t / meta.duration, S = o.seed;
+ const by = Math.round(-15 + bob(ph, 1.5)), R = 7.5;
+ // the surface sloshes against the bob and ripples
+ const tilt = 0.14 * Math.cos(ph * TAU), level = by + R - 2 * R * o.fill;
+ const surf = (x) => level + tilt * x + 0.6 * Math.sin(x * 0.8 - ph * TAU * 2);
+ const q = L.begin(-18, by - 24);
+ // glass: the bulb and the neck, dark inside
+ q.circle(0, by, R, GLASS[1]);
+ q.rect(-3, by - 13, 6, 8, GLASS[1]);
+ // the brew, shaded round: lit top left, deep at the bottom right, a bright line at the surface
+ L.fill(-8, by - 8, 8, by + 8, (x, y) => {
+ const dx = x, dy = y - by, d = Math.hypot(dx, dy);
+ if (d > R - 0.6 || y < surf(x)) return 0;
+ if (y < surf(x) + 1) return C[5];
+ const lit = -(dx * 0.6 + dy * 0.8) / R;
+ return d > R - 1.8 && lit < 0 ? C[2] : lit > 0.25 ? C[4] : lit > -0.45 ? C[3] : C[2];
+ });
+ // bubbles rise through the brew and pop at the surface
+ cycle(t, meta.duration, 6, S, (r) => r.range(0.4, 0.8), (age, life, r) => {
+ const x = r.range(-4.5, 4.5) + Math.sin(age * 9 + r.next() * 6) * 0.8, y = by + 6 - age * r.range(12, 18);
+ if (y < surf(x) + 0.5) return;
+ if (r.next() < 0.35) {
+ q.px(x, y, C[6]);
+ q.px(x + 1, y, C[5]), q.px(x, y + 1, C[5]), q.px(x + 1, y + 1, C[4]);
+ } else q.px(x, y, C[6]);
+ });
+ // the rim and the cork
+ q.rect(-4, by - 14, 8, 2, GLASS[3]);
+ q.rect(-4, by - 14, 8, 1, GLASS[4]);
+ q.rect(-2, by - 18, 4, 4, CORK[2]);
+ q.rect(-2, by - 18, 1, 4, CORK[3]);
+ q.rect(1, by - 18, 1, 4, CORK[1]);
+ q.rect(-2, by - 18, 4, 1, CORK[3]);
+ // glass highlights: a curved streak on the bulb, a line down the neck
+ q.arc(0, by, R - 1.2, 1.2, Math.PI * 1.05, Math.PI * 1.42, GLASS[4]);
+ q.px(-5, by - 2, WHITE);
+ q.rect(-2, by - 12, 1, 4, GLASS[3]);
+ L.outline(GLASS[0]);
+ L.draw(p);
+ // wisps curl up from the cork and fade
+ cycle(t, meta.duration, 4, S + 1, 0.75, (age, life, r) => {
+ const k = age / life, x = r.range(-2, 2) + Math.sin(age * 5 + r.next() * TAU) * 2.5 * k, y = by - 19 - age * r.range(8, 11);
+ if (k > 0.65 && Math.floor(age * 30) % 2) return;
+ p.px(x, y, k < 0.3 ? C[6] : k < 0.6 ? C[5] : C[4]);
+ p.light(x, y, C[5], 0.4 * (1 - k));
+ });
+ const pulse = 0.85 + 0.15 * Math.sin(ph * TAU * 2);
+ p.glow(0, by + 2, 20, C[4], 0.16 * pulse);
+ if (o.shadow) shadow(p, 0, 6.5 + bob(ph, 0.6));
+}
diff --git a/src/fx/pickups/power-star.js b/src/fx/pickups/power-star.js
new file mode 100644
index 0000000..75508c9
--- /dev/null
+++ b/src/fx/pickups/power-star.js
@@ -0,0 +1,75 @@
+import { PAL, cycle, bump, TAU } from "../../core/index.js";
+import { Layer, shadow, twinkle, bob, fit } from "./_lib.js";
+
+export const meta = {
+ name: "Power star",
+ desc: "A beveled five-point star rocking in the air, swelling on the beat, rays wheeling slowly behind it, twinkles popping around.",
+ tags: ["pickup", "star", "power-up", "invincible", "loop"],
+ size: [48, 52],
+ origin: [24, 48],
+ duration: 1.2,
+ loop: true,
+ fps: 30,
+ bg: "ground",
+ options: { palette: PAL.volt, shadow: true, seed: 5 },
+};
+
+const L = new Layer(40, 40);
+const LIGHT = [-0.45, -0.65, 0.62];
+
+// the facet normal of the triangle (center raised by H, tip, inner corner), dotted with the light
+function facetLight(tx, ty, kx, ky, H) {
+ // vectors from the raised center to the tip and to the corner
+ const ax = tx, ay = ty, az = -H, bx = kx, by = ky, bz = -H;
+ let nx = ay * bz - az * by, ny = az * bx - ax * bz, nz = ax * by - ay * bx;
+ if (nz < 0) (nx = -nx), (ny = -ny), (nz = -nz);
+ const l = Math.hypot(nx, ny, nz) || 1;
+ return (nx * LIGHT[0] + ny * LIGHT[1] + nz * LIGHT[2]) / l;
+}
+
+export function draw(p, t, o) {
+ const C = fit(o.palette), ph = t / meta.duration;
+ const pulse = bump((ph * 2) % 1, 0, 0.35), rot = 0.14 * Math.sin(ph * TAU);
+ const R = 10 * (1 + 0.1 * pulse), r = R * 0.45, H = 6;
+ const cy = Math.round(-22 + bob(ph, 2));
+ L.begin(-18, cy - 16);
+ L.fill(-14, cy - 14, 14, cy + 14, (x, y) => {
+ const dx = x, dy = y - cy, d = Math.hypot(dx, dy);
+ if (d > R + 1) return 0;
+ const phi = Math.atan2(dy, dx) - (-Math.PI / 2 + rot);
+ // which arm, and the angle from its tip line (-36° .. 36°)
+ const seg = TAU / 5, k = Math.round(phi / seg), off = phi - k * seg, half = seg / 2;
+ // the star's edge between the tip (angle 0, radius R) and the corner (angle half, radius r)
+ const u = Math.abs(off) / half, edgeR = (R * r) / (r + (R - r) * u * 0.92 + 0.0001);
+ if (d > edgeR * (1 - 0.08 * u) + 0.25) return 0;
+ const a = -Math.PI / 2 + rot + k * seg, side = off < 0 ? -1 : 1;
+ const tx = Math.cos(a) * R, ty = Math.sin(a) * R, kx = Math.cos(a + side * half) * r, ky = Math.sin(a + side * half) * r;
+ const b = facetLight(tx, ty, kx, ky, H);
+ if (d < 1.2) return C[6];
+ return b > 0.78 ? C[5] : b > 0.5 ? C[4] : C[3];
+ });
+ L.outline(C[1]);
+ L.draw(p);
+ // the beat throws a white rim for a frame or two
+ if (pulse > 0.75) twinkle(p, 0, cy - Math.round(R) - 2, 2, C[5], C[6]);
+ // twinkles pop around it
+ cycle(t, meta.duration, 4, o.seed, 0.4, (age, life, r2) => {
+ const k = age / life, a = r2.range(0, TAU), rad = r2.range(13, 18);
+ twinkle(p, Math.cos(a) * rad, cy + Math.sin(a) * rad * 0.9, Math.round(1 + 2 * bump(k, 0, 1)), C[4], C[5]);
+ });
+ p.glowRing(0, cy, 12, 9, C[4], 0.1 + 0.14 * pulse);
+ p.glow(0, cy, 4, C[6], 0.2 * pulse);
+ if (o.shadow) shadow(p, 0, 7 + bob(ph, 0.8));
+}
+
+// rays wheel slowly behind the star: eight of them, turning one gap a loop so the loop is seamless
+export function drawBack(p, t, o) {
+ const C = fit(o.palette), ph = t / meta.duration, cy = Math.round(-22 + bob(ph, 2));
+ const pulse = bump((ph * 2) % 1, 0, 0.35);
+ for (let i = 0; i < 8; i++) {
+ const a = (i / 8 + ph / 8) * TAU, len = (i % 2 ? 15 : 19) + 3 * pulse;
+ const x1 = Math.cos(a) * len, y1 = cy + Math.sin(a) * len;
+ p.line(Math.cos(a) * 12, cy + Math.sin(a) * 12, x1, y1, C[i % 2 ? 2 : 3]);
+ p.glowLine(0, cy, x1, y1, 3, C[4], 0.1);
+ }
+}
diff --git a/src/fx/pickups/scroll.js b/src/fx/pickups/scroll.js
new file mode 100644
index 0000000..98ddd02
--- /dev/null
+++ b/src/fx/pickups/scroll.js
@@ -0,0 +1,76 @@
+import { PAL, RAMP, ramp, seg, ease, cycle, rand, TAU, WHITE } from "../../core/index.js";
+import { Layer, shadow, bob, fit } from "./_lib.js";
+
+export const meta = {
+ name: "Scroll",
+ desc: "A spell scroll floating over its shadow: it unrolls with a bounce, its runes light up line by line and shed sparks, then it rolls itself back up.",
+ tags: ["pickup", "scroll", "spell", "magic", "loop"],
+ size: [40, 50],
+ origin: [20, 46],
+ duration: 2.4,
+ loop: true,
+ fps: 30,
+ bg: "ground",
+ options: { palette: PAL.electric, shadow: true, seed: 10 },
+};
+
+const L = new Layer(40, 44);
+const PAPER = ramp(["#2a1c10", "#4e3620", "#7a5a36", "#a8865a", "#cfb184", "#ecd9ae", "#fff4d6"]), WOOD = RAMP.wood;
+// rune glyphs, 3 x 3
+const GLYPHS = ["#.#.#.#.#", "##..##..#", ".#.###.#.", "#..###..#", "####..##.", ".#.#.#.#.", "#.##.#..#", "##.#...##"];
+const OPEN = 15, W = 7;
+
+// a roller: a short wooden cylinder with round knobs
+function roller(q, y) {
+ for (let x = -W - 1; x <= W; x++) {
+ q.px(x, y - 1, WOOD[5]);
+ q.px(x, y, WOOD[4]);
+ q.px(x, y + 1, WOOD[2]);
+ }
+ for (const s of [-1, 1]) {
+ const x = s < 0 ? -W - 3 : W + 1;
+ q.rect(x, y - 2, 2, 5, WOOD[3]);
+ q.px(x, y - 2, WOOD[5]);
+ q.px(x + 1, y + 2, WOOD[1]);
+ }
+}
+
+export function draw(p, t, o) {
+ const C = fit(o.palette), ph = t / meta.duration, S = o.seed;
+ // unroll with a bounce, hold, roll back up
+ const open = ph < 0.62 ? ease.outBack(seg(ph, 0.12, 0.32), 2.2) : 1 - ease.inQuad(seg(ph, 0.72, 0.88));
+ const h = Math.max(0, Math.round(OPEN * open));
+ const cy = Math.round(-26 + bob(ph, 1.5)), top = cy - Math.round(h / 2) - 3, bot = top + 3 + h;
+ const q = L.begin(-20, cy - 22);
+ // the parchment between the rollers: lit on the left, a soft curl at the right edge, lines of runes
+ for (let y = top + 2; y < bot - 1; y++)
+ for (let x = -W; x < W; x++) q.px(x, y, x === -W ? PAPER[5] : x >= W - 1 ? PAPER[2] : x >= W - 3 ? PAPER[3] : PAPER[4]);
+ // three lines of runes; each lights up once the paper has unrolled past it, flickering
+ for (let line = 0; line < 3; line++) {
+ const gy = top + 3 + line * 4;
+ if (gy + 2 >= bot - 1) break;
+ const lit = seg(ph, 0.3 + line * 0.07, 0.34 + line * 0.07) * (1 - seg(ph, 0.68, 0.72));
+ for (let j = 0; j < 3; j++) {
+ const g = GLYPHS[Math.floor(rand(S, line, j) * GLYPHS.length)], gx = -W + 2 + j * 4;
+ const flick = rand(S, line, j, Math.floor(t * 10)) < 0.2;
+ for (let k = 0; k < 9; k++) if (g[k] === "#") q.px(gx + (k % 3), gy + Math.floor(k / 3), lit > 0.5 ? (flick ? WHITE : C[4]) : lit > 0 ? C[3] : PAPER[2]);
+ }
+ }
+ roller(q, top + 1);
+ roller(q, bot);
+ // closed, a ribbon ties the roll
+ if (h < 3) q.rect(-1, top - 1, 3, bot - top + 3, C[3]), q.rect(-1, top - 1, 1, bot - top + 3, C[5]);
+ L.outline(WOOD[0]);
+ L.draw(p);
+ // runes shed sparks while it is open
+ const lit = seg(ph, 0.3, 0.4) * (1 - seg(ph, 0.68, 0.74));
+ cycle(t, meta.duration, 10, S, (r) => r.range(0.4, 0.6), (age, life, r) => {
+ if (lit <= 0) return;
+ const k = age / life, x = r.range(-W + 2, W - 2), y = top + 4 + r.range(0, OPEN - 4) - age * r.range(12, 18);
+ if (r.next() > lit) return;
+ p.px(x + Math.sin(age * 8 + r.next() * TAU), y, k < 0.4 ? WHITE : k < 0.7 ? C[5] : C[3]);
+ p.light(x, y, C[4], 0.45 * (1 - k));
+ });
+ p.glow(0, (top + bot) / 2, 22, C[4], 0.06 + 0.14 * lit);
+ if (o.shadow) shadow(p, 0, 8 + bob(ph, 0.6));
+}
diff --git a/src/fx/pickups/trophy.js b/src/fx/pickups/trophy.js
new file mode 100644
index 0000000..b991620
--- /dev/null
+++ b/src/fx/pickups/trophy.js
@@ -0,0 +1,74 @@
+import { PAL, bump, cycle, TAU, WHITE } from "../../core/index.js";
+import { Layer, shadow, twinkle, bob, fit } from "./_lib.js";
+
+export const meta = {
+ name: "Trophy",
+ desc: "A golden cup on a stepped foot floating over its shadow: polished bands down the bowl, a shine sweeping across it, sparkles winking around.",
+ tags: ["pickup", "trophy", "cup", "reward", "loop"],
+ size: [40, 44],
+ origin: [20, 40],
+ duration: 1.8,
+ loop: true,
+ fps: 30,
+ bg: "ground",
+ options: { palette: PAL.gold, shadow: true, seed: 9 },
+};
+
+const L = new Layer(40, 40);
+const STAR = ["..a..", ".aba.", "aabaa", ".a.a."];
+
+// polished metal: bands across a round surface, u from -1 (left edge) to 1 (right edge)
+const band = (C, u) => (u < -0.78 ? C[4] : u < -0.4 ? C[6] : u < 0.25 ? C[5] : u < 0.62 ? C[4] : C[3]);
+
+export function draw(p, t, o) {
+ const C = fit(o.palette), ph = t / meta.duration;
+ const cy = Math.round(-21 + bob(ph, 1.5)), TOP = cy - 9, H = 11;
+ const hw = (y) => 7.5 * (1 - 0.58 * ((y - TOP) / H) ** 2);
+ const q = L.begin(-20, cy - 16);
+ // handles: half rings on each side, behind the bowl
+ q.arc(-7, cy - 4, 4.5, 2, Math.PI * 0.5, Math.PI * 1.5, (u, v) => (u < 0.5 ? C[5] : C[3]));
+ q.arc(7, cy - 4, 4.5, 2, -Math.PI * 0.5, Math.PI * 0.5, (u, v) => (u < 0.5 ? C[4] : C[3]));
+ // the bowl
+ L.fill(-9, TOP, 9, TOP + H, (x, y) => {
+ const w = hw(y);
+ if (Math.abs(x) > w) return 0;
+ return band(C, x / w);
+ });
+ // the mouth: a dark opening with a bright lip
+ q.ellipse(0, TOP + 0.5, 6.5, 1.6, C[2]);
+ q.rect(-7, TOP - 1, 15, 1, C[6]);
+ // the stamped star
+ q.sprite(STAR, { a: C[6], b: WHITE }, -2, TOP + 3);
+ // stem, knot and stepped foot
+ for (let y = TOP + H; y < TOP + H + 5; y++) for (let x = -1; x <= 1; x++) q.px(x, y, x < 0 ? C[6] : x === 0 ? C[5] : C[3]);
+ q.ellipse(0, TOP + H + 2, 2.6, 1.2, C[5]);
+ L.fill(-6, TOP + H + 5, 6, TOP + H + 9, (x, y) => {
+ const row = Math.floor(y) - (TOP + H + 5), w = row < 2 ? 4.5 : 6.5;
+ if (Math.abs(x) > w) return 0;
+ return row === 0 || row === 2 ? (x < 0 ? C[6] : C[5]) : band(C, x / w);
+ });
+ L.outline(C[1]);
+ // a shine sweeps across: a slanted white band, then a twinkle at the lip
+ const run = (ph - 0.15) / 0.3;
+ if (run > 0 && run < 1) {
+ const s = -16 + 32 * run;
+ L.map((x, y, c) => {
+ if (c === C[1]) return c;
+ const d = x + 0.5 + (y - cy) * 0.7 - s;
+ return Math.abs(d) < 0.6 ? WHITE : Math.abs(d) < 1.3 || Math.abs(d + 3.2) < 0.6 ? C[6] : c;
+ });
+ }
+ L.draw(p);
+ const g = bump(ph, 0.4, 0.62);
+ if (g > 0) {
+ twinkle(p, 6, TOP - 1, 1 + Math.round(g * 3.5), C[5], C[6]);
+ p.light(6, TOP - 1, C[6], 0.6 * g);
+ }
+ // sparkles wink around it
+ cycle(t, meta.duration, 3, o.seed, 0.45, (age, life, r) => {
+ const a = r.range(0, TAU), rad = r.range(12, 16), k = age / life;
+ twinkle(p, Math.cos(a) * rad, cy - 2 + Math.sin(a) * rad * 0.8, Math.round(1 + 2 * bump(k, 0, 1)), C[4], C[5]);
+ });
+ p.glow(0, cy - 2, 22, C[4], 0.1);
+ if (o.shadow) shadow(p, 0, 7 + bob(ph, 0.6));
+}
diff --git a/src/fx/pickups/xp-orb.js b/src/fx/pickups/xp-orb.js
new file mode 100644
index 0000000..456863c
--- /dev/null
+++ b/src/fx/pickups/xp-orb.js
@@ -0,0 +1,50 @@
+import { PAL, cycle, TAU, WHITE } from "../../core/index.js";
+import { Layer, shadow, pillow, fit } from "./_lib.js";
+
+export const meta = {
+ name: "XP orb",
+ desc: "A green experience orb looping a lazy figure eight, pulsing as it goes, a tapering comet tail behind it with a twinkle riding it, motes shed.",
+ tags: ["pickup", "xp", "experience", "orb", "loop"],
+ size: [44, 40],
+ origin: [22, 36],
+ duration: 1.6,
+ loop: true,
+ fps: 30,
+ bg: "ground",
+ options: { palette: PAL.matrix, radius: 4.5, shadow: true, seed: 6 },
+};
+
+const L = new Layer(48, 40);
+const pos = (ph) => [9 * Math.sin(ph * TAU), -17 + 4 * Math.sin(ph * TAU * 2)];
+
+export function draw(p, t, o) {
+ const C = fit(o.palette), ph = t / meta.duration;
+ const [x, y] = pos(ph), ox = Math.round(x), oy = Math.round(y);
+ // the tail: tapering segments through where it was, cooling down the ramp, with a twinkle riding it
+ let [px0, py0] = [x, y];
+ for (let i = 1; i <= 8; i++) {
+ const [tx, ty] = pos(ph - i * 0.028), w = 2 * (o.radius - 1) * (1 - i / 9);
+ p.beam(px0, py0, tx, ty, Math.max(1, w), i < 3 ? C[5] : i < 6 ? C[4] : C[3]);
+ p.light(tx, ty, C[5], 0.3 * (1 - i / 9));
+ [px0, py0] = [tx, ty];
+ }
+ const tw = Math.floor(ph * 8) % 2, [sx, sy] = pos(ph - (tw ? 0.09 : 0.15));
+ p.px(sx - 1, sy, C[6]), p.px(sx + 1, sy, C[6]), p.px(sx, sy - 1, C[6]), p.px(sx, sy + 1, C[6]), p.px(sx, sy, WHITE);
+ // the orb: a lit sphere with a dark rim, pulsing twice a loop
+ const R = o.radius * (1 + 0.1 * Math.sin(ph * TAU * 2));
+ L.begin(ox - 8, oy - 8);
+ pillow(L, ox - R - 1, oy - R - 1, ox + R + 1, oy + R + 1, (px, py) => Math.hypot(px - ox, py - oy) - R, (b) =>
+ b > 0.92 ? C[7] : b > 0.78 ? C[6] : b > 0.5 ? C[5] : b > 0.2 ? C[4] : C[3], { bevel: R });
+ L.outline(C[2]);
+ L.draw(p);
+ // motes shed from the trail, hanging and fading where they were dropped
+ cycle(t, meta.duration, 6, o.seed, (r) => r.range(0.35, 0.6), (age, life, r) => {
+ const born = (t - age) / meta.duration, [mx, my] = pos(born), k = age / life;
+ const px = mx + r.range(-4, 4), py = my + r.range(-4, 4) + age * 6;
+ if (k > 0.6 && Math.floor(age * 30) % 2) return;
+ p.px(px, py, k < 0.4 ? C[6] : C[4]);
+ });
+ p.glow(ox, oy, 16, C[4], 0.26);
+ p.glow(ox, oy, 6, C[6], 0.16);
+ if (o.shadow) shadow(p, ox, 4 + (y + 17) * 0.2, 0.9);
+}
diff --git a/src/fx/projectiles/_lib.js b/src/fx/projectiles/_lib.js
new file mode 100644
index 0000000..3959f91
--- /dev/null
+++ b/src/fx/projectiles/_lib.js
@@ -0,0 +1,146 @@
+// Shared by the projectile effects: billowing smoke, star-shaped flashes, Bézier paths, rotated sprites and
+// a canvas clip for things that fly off the edge. Files starting with _ are helpers, not effects.
+
+import { at, clamp, hex, noise2, rng, wrap, TAU, WHITE } from "../../core/index.js";
+
+/** A test for local pixel centers that land on the effect's canvas (meta.size around meta.origin). */
+export function onCanvas(meta, pad = 0) {
+ const [W, H] = meta.size, [OX, OY] = meta.origin;
+ return (x, y) => x > -OX + pad && x < W - OX - pad && y > -OY + pad && y < H - OY - pad;
+}
+
+/**
+ * Billowing smoke: puffs [{ x, y, r, v }] (v is density 0..1) drawn as one field, so overlapping puffs merge
+ * into one cloud lit from the top-left. Thin edges and thinning puffs dither away. R is the smoke ramp (dark
+ * to light); base shifts the whole cloud lighter or darker. With dens near 1 and a fire ramp it draws a fireball
+ * whose dense middle runs hot.
+ */
+export function smoke(p, puffs, R, { base = 0.3, seed = 0, inside, lit = 0.18, dens = 0.24, grain = 0.07 } = {}) {
+ const list = puffs.filter((f) => f.r > 0.4 && f.v > 0.01);
+ if (!list.length) return;
+ let x0 = Infinity, y0 = Infinity, x1 = -Infinity, y1 = -Infinity;
+ for (const f of list) {
+ x0 = Math.min(x0, f.x - f.r); x1 = Math.max(x1, f.x + f.r);
+ y0 = Math.min(y0, f.y - f.r); y1 = Math.max(y1, f.y + f.r);
+ }
+ p.shade(x0, y0, x1, y1, (x, y, out) => {
+ if (inside && !inside(x, y)) return;
+ let best = 0, l = 0;
+ for (const f of list) {
+ const dx = x - f.x, dy = y - f.y, d2 = (dx * dx + dy * dy) / (f.r * f.r);
+ if (d2 >= 1) continue;
+ const v = (1 - d2) * f.v;
+ if (v > best) (best = v), (l = (-dx - dy * 1.4) / f.r);
+ }
+ if (best < 0.04) return;
+ out.c = at(R, base + l * lit + best * dens + noise2(x * 0.3, y * 0.3, seed) * grain);
+ out.a = clamp(best * 3);
+ });
+}
+
+/**
+ * Smoke as separate puffs [{ x, y, r, v, tone? }], each lit from the top-left and drawn over the ones before it:
+ * cheaper than smoke() for long trails, and bubblier.
+ */
+export function puffs(p, list, R, { base = 0.3, lit = 0.22, inside } = {}) {
+ for (const f of list) {
+ if (f.r < 0.5 || f.v <= 0.01) continue;
+ const b = base + (f.tone ?? 0);
+ p.circle(f.x, f.y, f.r, (d, a) => at(R, b - d * (Math.cos(a) + 1.4 * Math.sin(a)) * lit + (1 - d * d) * f.v * 0.26),
+ (d, a) => (inside && !inside(f.x + Math.cos(a) * d * f.r, f.y + Math.sin(a) * d * f.r) ? 0 : clamp((1 - d * d) * f.v * 3)));
+ }
+}
+
+/**
+ * Points of a flash shape around (x, y): a disc of radius r0 with spikes [[angle, length, sharpness], ...]
+ * added on top (length * cos(a - angle) ^ sharpness: 4 is a fat lobe, 20 a needle), scaled by k.
+ */
+export function flashPts(x, y, spikes, r0, k = 1, n = 96) {
+ const pts = [];
+ for (let i = 0; i < n; i++) {
+ const a = (i / n) * TAU - Math.PI;
+ let R = r0;
+ for (const [sa, len, sharp] of spikes) R += len * Math.pow(Math.max(0, Math.cos(a - sa)), sharp);
+ pts.push([x + Math.cos(a) * R * k, y + Math.sin(a) * R * k]);
+ }
+ return pts;
+}
+
+/**
+ * A muzzle flash: an outer flame in the ramp's mid step, a hotter inner copy, a white throat. spikes as for
+ * flashPts; s scales it; heat 1 is the hero frame, lower heats cool every layer a step and drop the white.
+ */
+export function muzzleFlash(p, x, y, spikes, s, C, heat = 1) {
+ const cool = (1 - heat) * 0.3;
+ p.poly(flashPts(x, y, spikes, 2.6, s), at(C, 0.56 - cool));
+ p.poly(flashPts(x + 0.8 * s, y, spikes, 1.7, s * 0.62), at(C, 0.8 - cool));
+ if (heat > 0.6) p.ellipse(x + 2.6 * s, y, 3.4 * s, 2.1 * s, WHITE);
+ else p.ellipse(x + 1.8 * s, y, 2 * s, 1.3 * s, at(C, 0.92 - cool));
+}
+
+/** A point on a cubic Bézier P = [[x, y] x 4] at u (0..1). */
+export function bez(P, u) {
+ const v = 1 - u, a = v * v * v, b = 3 * v * v * u, c = 3 * v * u * u, d = u * u * u;
+ return [a * P[0][0] + b * P[1][0] + c * P[2][0] + d * P[3][0], a * P[0][1] + b * P[1][1] + c * P[2][1] + d * P[3][1]];
+}
+/** The Bézier's heading (radians) at u. */
+export function bezAngle(P, u) {
+ const v = 1 - u, d = (i) => 3 * v * v * (P[1][i] - P[0][i]) + 6 * v * u * (P[2][i] - P[1][i]) + 3 * u * u * (P[3][i] - P[2][i]);
+ return Math.atan2(d(1), d(0));
+}
+
+/**
+ * A little sprite (rows and pal as for p.sprite) turned by ang (radians) about its pivot (px, py, in sprite
+ * pixels), with the pivot placed at (x, y). Nearest-pixel sampling keeps it hard-edged. opts: { a, tint, inside }.
+ */
+export function rotSprite(p, rows, pal, x, y, ang, px, py, opts = {}) {
+ const H = rows.length, W = rows[0].length, cs = Math.cos(ang), sn = Math.sin(ang), a = opts.a ?? 1, cache = {};
+ const R = Math.hypot(Math.max(px, W - px), Math.max(py, H - py)) + 1;
+ p.shade(x - R, y - R, x + R, y + R, (lx, ly, out) => {
+ if (opts.inside && !opts.inside(lx, ly)) return;
+ const dx = lx - x, dy = ly - y, i = Math.floor(dx * cs + dy * sn + px), j = Math.floor(-dx * sn + dy * cs + py);
+ if (i < 0 || j < 0 || i >= W || j >= H) return;
+ const ch = rows[j][i];
+ if (ch === "." || ch === " ") return;
+ out.c = opts.tint ?? cache[ch] ?? (cache[ch] = pal[ch] === undefined ? 0 : hex(pal[ch]));
+ out.a = a;
+ });
+}
+
+/**
+ * Like cycle(), but particle i is born exactly at i * period / n: an emitter with a steady beat, so a trail has
+ * no clumps or gaps. Loops seamlessly over period. fn(age, life, r, i).
+ */
+export function beat(t, period, n, seed, life, fn) {
+ for (let i = 0; i < n; i++) {
+ const L = typeof life === "function" ? life(rng(seed, i, 911)) : life;
+ for (let age = wrap(t - (i * period) / n, period); age < L; age += period) fn(age, L, rng(seed, i), i);
+ }
+}
+
+/** A ramp resampled to n steps (picking, never blending), so effects can index steps of any caller's palette. */
+export const steps = (C, n) => Array.from({ length: n }, (_, i) => at(C, (i + 0.5) / n));
+
+/**
+ * An arrow, 25 x 5, pointing right with its tip in the last column of the middle row: shaft, steel head,
+ * fletching (F/f top, G/g underside). ARROW_FLAT is the same arrow with its feathers pressed flat, for flutter.
+ */
+export const ARROW = [
+ "FFf......................",
+ ".fFFf...............hh...",
+ "nwwwwwwwwwwwwwwwwwwwHHHHT",
+ ".gGGg...............ee...",
+ "GGg......................",
+];
+export const ARROW_FLAT = [
+ ".........................",
+ "FFFFf...............hh...",
+ "nwwwwwwwwwwwwwwwwwwwHHHHT",
+ "GGGGg...............ee...",
+ ".........................",
+];
+/** The arrow's palette, its fletching from a ramp (light, mid, shadow, deep). */
+export const arrowPal = (F) => ({
+ F: F[0], f: F[1], G: F[2], g: F[3],
+ n: "#3a2414", w: "#9a6a38", H: "#b4c0d2", T: "#ffffff", h: "#8a96aa", e: "#4a5468",
+});
diff --git a/src/fx/projectiles/arrow-hit.js b/src/fx/projectiles/arrow-hit.js
new file mode 100644
index 0000000..4832f15
--- /dev/null
+++ b/src/fx/projectiles/arrow-hit.js
@@ -0,0 +1,60 @@
+import { PAL, ramp, at, burst, fly, seg, ease, WHITE } from "../../core/index.js";
+import { ARROW, arrowPal, rotSprite, puffs, onCanvas } from "./_lib.js";
+
+export const meta = {
+ name: "Arrow hit",
+ desc: "An arrow streaks in and thunks into the floor, kicking up dirt, quivers back and forth as the wobble dies, then fades.",
+ tags: ["projectile", "arrow", "impact", "ground", "one-shot"],
+ size: [60, 32],
+ origin: [36, 26],
+ duration: 1.4,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ options: { palette: PAL.dust, tilt: 0.55, seed: 13 },
+};
+
+const TH = 0.1; // the moment it lands
+const FLETCH = ["#ffffff", "#e4dccc", "#c42a30", "#7a1820"];
+
+export function draw(p, t, o) {
+ const C = ramp(o.palette), S = o.seed, inside = onCanvas(meta), above = (x, y) => y < 1 && inside(x, y);
+ const pal = arrowPal(FLETCH), rest = o.tilt, dx = Math.cos(rest), dy = Math.sin(rest);
+ const fade = 1 - seg(t, 1.1, 1.36);
+ if (t < TH) {
+ // in flight: a streak and the arrow, sliding down its line into the floor
+ const back = 36 * (1 - t / TH), x = -dx * back, y = -dy * back;
+ p.line(x - dx * 24, y - dy * 24, x - dx * 40, y - dy * 40, (u) => (u < 0.4 ? at(C, 0.85) : at(C, 0.6)), (u) => (inside(x - dx * (24 + u * 16), y - dy * (24 + u * 16)) ? 1 : 0));
+ rotSprite(p, ARROW, pal, x, y, rest, 24.5, 2.5, { inside: above });
+ return;
+ }
+ const te = t - TH;
+ // the floor takes a small dent
+ if (fade > 0) {
+ p.dot(-1, 0, C[1], fade), p.dot(1, 0, C[1], fade), p.dot(0, 1, C[0], fade);
+ }
+ // dirt: a low puff spreading along the floor, clods tossed up and falling back
+ const dust = [];
+ burst(5, S + 1, (r, i) => {
+ const life = r.range(0.35, 0.55), age = te - r.range(0, 0.03);
+ if (age < 0 || age > life) return;
+ const k = age / life, e = ease.outCubic(seg(age, 0, 0.25)), side = i % 2 ? 1 : -1;
+ dust.push({ x: side * (1 + r.range(2, 7) * e), y: -1 - r.range(0.5, 2) * e - k * 2, r: (1.4 + 2 * e) * (1 - k * 0.3), v: 1 - k });
+ });
+ puffs(p, dust, C, { base: 0.5, inside: above });
+ burst(7, S + 2, (r) => {
+ const a = -Math.PI / 2 + r.range(-1.1, 0.7), v = r.range(40, 80), life = r.range(0.3, 0.5);
+ if (te > life) return;
+ const [x, y] = fly(0, -1, Math.cos(a) * v, Math.sin(a) * v, te, 300, 0.5);
+ if (y > 0) return;
+ p.rect(x, y, r.chance(0.4) ? 2 : 1, 1, te / life < 0.6 ? C[3] : C[2]);
+ });
+ // stuck fast, quivering: the shaft swings about the buried tip as the wobble dies
+ const wob = 0.2 * Math.exp(-te * 5.5) * Math.sin(te * Math.PI * 2 * 9);
+ rotSprite(p, ARROW, pal, 0, 0, rest + wob, 21.5, 2.5, { inside: above, a: fade });
+ // the thunk: a white tick where it bit in, for a frame or two
+ if (te < 0.06) {
+ p.px(-2, -1, WHITE), p.px(2, -1, WHITE), p.px(-3, 0, at(C, 0.9)), p.px(3, 0, at(C, 0.9));
+ p.glow(0, -1, 8, at(C, 0.8), 0.25);
+ }
+}
diff --git a/src/fx/projectiles/arrow.js b/src/fx/projectiles/arrow.js
new file mode 100644
index 0000000..996827f
--- /dev/null
+++ b/src/fx/projectiles/arrow.js
@@ -0,0 +1,35 @@
+import { ramp, at, cycle, fract, WHITE } from "../../core/index.js";
+import { ARROW, ARROW_FLAT, arrowPal, steps } from "./_lib.js";
+
+export const meta = {
+ name: "Arrow",
+ desc: "An arrow in flight: a wooden shaft with a steel head, fletching that flutters, wind streaks peeling back along it and a wake behind the nock.",
+ tags: ["projectile", "arrow", "bow", "directional", "loop"],
+ size: [56, 15],
+ origin: [48, 7],
+ duration: 0.4,
+ loop: true,
+ fps: 30,
+ bg: "dark",
+ options: { palette: ["#1c2a3a", "#2e4660", "#4a6e8e", "#7aa0bc", "#b4d0e2", "#e8f4fc"], seed: 12 },
+};
+
+export function draw(p, t, o) {
+ const C = steps(ramp(o.palette), 6), S = o.seed, D = meta.duration, ph = t / D;
+ // wind streaks sliding back past the shaft, the far ones dimmer
+ cycle(t, D, 7, S, (r) => r.range(0.12, 0.17), (age, life, r) => {
+ const k = age / life, far = r.chance(0.5), y = r.sign() * (far ? r.int(4, 5) : r.int(2, 3));
+ const x = -r.range(2, 10) - age * r.range(170, 210), len = r.range(5, 11) * (1 - k * 0.8);
+ p.line(x, y, x - len, y, (u) => (u < 0.25 ? at(C, far ? 0.6 : 0.85) : at(C, far ? 0.35 : 0.6)));
+ });
+ // the wake: dashes left behind the nock, sliding back and fading out
+ for (let x = -26; x >= -46; x--) {
+ const u = (-26 - x) / 20;
+ if (fract(-x / 7 - ph * 4) < 0.45 + u * 0.4) continue;
+ p.px(x, 0, u < 0.4 ? at(C, 0.6) : at(C, 0.38));
+ }
+ // the arrow: feathers flutter flat and back every other frame
+ const flat = Math.floor(ph * 12) % 2 === 1;
+ p.sprite(flat ? ARROW_FLAT : ARROW, arrowPal([C[5], C[4], C[3], C[2]]), -24, -2);
+ p.glow(-1, 0.5, 5, WHITE, 0.15);
+}
diff --git a/src/fx/projectiles/boomerang.js b/src/fx/projectiles/boomerang.js
new file mode 100644
index 0000000..29bbbd6
--- /dev/null
+++ b/src/fx/projectiles/boomerang.js
@@ -0,0 +1,57 @@
+import { PAL, ramp, at, rand, seg, clamp, TAU, WHITE } from "../../core/index.js";
+import { rotSprite, steps } from "./_lib.js";
+
+export const meta = {
+ name: "Boomerang",
+ desc: "A boomerang whirls out in a wide loop, hangs at the far turn, swings back underneath and is caught, a dotted arc of its path fading behind.",
+ tags: ["projectile", "boomerang", "throwing", "return", "one-shot"],
+ size: [104, 50],
+ origin: [8, 26],
+ duration: 1.3,
+ loop: false,
+ fps: 30,
+ bg: "dark",
+ options: { palette: PAL.wood, reach: 42, seed: 16 },
+};
+
+const BOOM = [
+ "LL.........LL",
+ "wLL.......LLw",
+ "dwLL.....LLwd",
+ ".dwLL...LLwd.",
+ "..dwLLLLLwd..",
+ "...ddwwwdd...",
+];
+
+export function draw(p, t, o) {
+ // each throw is a little different: how high the loop swings and where the spin starts
+ const C = steps(ramp(o.palette), 7), A = o.reach, B = 11 + 4 * rand(o.seed, 1), spin0 = rand(o.seed, 2) * TAU;
+ // the loop: out along the top, round the far end slowly, back along the bottom
+ const theta = (tt) => {
+ const u = clamp(tt / meta.duration);
+ return Math.PI + TAU * (u + 0.115 * Math.sin(TAU * u));
+ };
+ const pos = (tt) => {
+ const th = theta(tt);
+ return [A + A * Math.cos(th), B * Math.sin(th)];
+ };
+ if (t >= meta.duration - 0.02) return;
+ // its path: a dotted arc of where it has been, the old end fading first
+ for (let j = 1; j <= 14; j++) {
+ const tt = t - j * 0.035;
+ if (tt < 0) break;
+ const [x, y] = pos(tt);
+ p.px(x, y, j < 5 ? at(C, 0.86) : j < 10 ? at(C, 0.6) : at(C, 0.4));
+ }
+ const [x, y] = pos(t), spin = spin0 + t * TAU * 4.2;
+ // the whirl: two smears trailing its spin
+ p.arc(x, y + 0.5, 7.5, 1.2, spin - 1.9, spin - 0.7, at(C, 0.45));
+ p.arc(x, y + 0.5, 7.5, 1.2, spin - 1.9 + Math.PI, spin - 0.7 + Math.PI, at(C, 0.45));
+ rotSprite(p, BOOM, { w: C[4], L: C[6] ?? C[5], d: C[2] }, x, y + 0.5, spin, 6.5, 3.5);
+ // caught: a little flash as it slaps back into the hand
+ const catchK = seg(t, meta.duration - 0.12, meta.duration - 0.02);
+ if (catchK > 0) {
+ const r = 2 + catchK * 4;
+ for (const [sx, sy] of [[1, 0], [-1, 0], [0, 1], [0, -1]]) p.px(x + sx * r, y + sy * r, WHITE);
+ }
+}
diff --git a/src/fx/projectiles/bullet-tracer.js b/src/fx/projectiles/bullet-tracer.js
new file mode 100644
index 0000000..97cd21a
--- /dev/null
+++ b/src/fx/projectiles/bullet-tracer.js
@@ -0,0 +1,42 @@
+import { PAL, ramp, at, cycle, fly, loopNoise, fract, TAU, WHITE } from "../../core/index.js";
+
+export const meta = {
+ name: "Bullet tracer",
+ desc: "A tracer round: a white-hot slug, a long burning streak that flickers and breaks into dashes as it cools, sparks peeling off behind.",
+ tags: ["projectile", "bullet", "tracer", "gun", "directional", "loop"],
+ size: [58, 15],
+ origin: [52, 7],
+ duration: 0.4,
+ loop: true,
+ fps: 30,
+ bg: "dark",
+ options: { palette: PAL.fire, length: 46, seed: 1 },
+};
+
+const SLUG = [".##..", "####o", ".##.."];
+
+export function draw(p, t, o) {
+ const C = ramp(o.palette), S = o.seed, D = meta.duration, ph = t / D;
+ const L = o.length * (0.86 + 0.14 * loopNoise(ph, 3, S));
+ // the streak: a core line cooling from white to deep red, breaking into dashes that slide back at the tail
+ for (let x = -2; x >= -L; x--) {
+ const u = -x / L;
+ if (u > 0.5 && fract(-x / 11 - ph * 3) > 1.3 - u) continue;
+ p.px(x, 0, u < 0.14 ? WHITE : at(C, 0.92 - u * 0.62));
+ }
+ // a fatter hot end: two shorter rows hugging the core
+ const e1 = Math.round(L * (0.3 + 0.04 * Math.sin(ph * TAU * 3))), e2 = Math.round(L * 0.22);
+ p.line(-2, -1, -e1, -1, (u) => at(C, 0.86 - u * 0.34));
+ p.line(-2, 1, -e2, 1, (u) => at(C, 0.78 - u * 0.34));
+ p.sprite(SLUG, { "#": WHITE, o: at(C, 0.85) }, -4, -1);
+ // sparks shed from the streak, falling behind
+ cycle(t, D, 7, S + 5, (r) => r.range(0.12, 0.26), (age, life, r) => {
+ const k = age / life, [x, y] = fly(-r.range(3, 22), 0, -r.range(70, 150), r.sign() * r.range(8, 22), age, 60, 3);
+ p.px(x, y, k < 0.4 ? at(C, 0.85) : at(C, 0.6));
+ p.light(x, y, at(C, 0.7), 0.4 * (1 - k));
+ });
+ // light: a hot point at the slug and a dim line along the streak
+ const fl = 0.85 + 0.15 * Math.sin(ph * TAU * 6);
+ p.glowLine(-L * 0.55, 0.5, -2, 0.5, 5, at(C, 0.6), 0.22 * fl);
+ p.glow(-1, 0.5, 6, at(C, 0.8), 0.5 * fl);
+}
diff --git a/src/fx/projectiles/cannonball.js b/src/fx/projectiles/cannonball.js
new file mode 100644
index 0000000..c33529f
--- /dev/null
+++ b/src/fx/projectiles/cannonball.js
@@ -0,0 +1,76 @@
+import { PAL, RAMP, ramp, at, burst, stream, fly, seg, ease, clamp, WHITE } from "../../core/index.js";
+import { smoke, puffs, onCanvas, steps } from "./_lib.js";
+
+export const meta = {
+ name: "Cannonball",
+ desc: "Cannon fire: a round blast of flame at the muzzle, the iron ball arcing away trailing a wisp, and a big cloud of gunsmoke rolling out and up.",
+ tags: ["projectile", "cannon", "cannonball", "smoke", "directional", "one-shot"],
+ size: [128, 52],
+ origin: [6, 32],
+ duration: 1.6,
+ loop: false,
+ fps: 30,
+ bg: "dark",
+ options: { palette: PAL.fire, speed: 270, seed: 10 },
+};
+
+const IRON = ["#141820", "#262c3a", "#3a4254", "#5a6478", "#9aa6ba"];
+
+export function draw(p, t, o) {
+ const C = steps(ramp(o.palette), 8), S = o.seed, V = o.speed, inside = onCanvas(meta, 1), cy = 0.5;
+ const I = ramp(IRON);
+ const ball = (tt) => fly(5, cy, V, -45, tt, 130, 0);
+ // the wisp: small puffs the ball leaves in the air, gone in a blink
+ const wisp = [];
+ stream(t, 0.04, 0.5, 80, S + 5, (r) => r.range(0.16, 0.26), (age, life, r, i) => {
+ const [x, y] = ball(0.04 + i / 80), k = age / life;
+ wisp.push({ x: x - 3, y: y - age * 8, r: 1.3 + k * 1.6, v: (1 - k) * 0.85 });
+ });
+ puffs(p, wisp, RAMP.smoke, { base: 0.55, inside });
+ // gunsmoke: a big cloud shoved out of the barrel, rolling forward, rising, slowly thinning
+ const cloud = [];
+ burst(12, S + 4, (r, i) => {
+ const age = t - 0.03 - r.range(0, 0.07), life = r.range(1.1, 1.45);
+ if (age < 0 || age > life) return;
+ const u = age / life, e = ease.outQuart(seg(age, 0, 0.45)), reach = 3 + (i / 11) * 30 + r.range(-3, 3);
+ cloud.push({
+ x: 4 + reach * e + age * 6, y: cy + r.range(-5, 5) * e - u * r.range(12, 22) - (i / 11) * 2,
+ r: (3 + reach * 0.13) * (0.5 + 0.5 * e) * (1 + 0.7 * u), v: (1 - u) ** 1.2,
+ });
+ });
+ smoke(p, cloud, RAMP.smoke, { base: 0.54, lit: 0.14, seed: S, inside });
+ // the blast: a white ball of flame, then a fireball rolling forward and cooling into the cloud
+ if (t < 0.035) {
+ p.circle(6, cy, 7, at(C, 0.62));
+ p.circle(5.5, cy, 4.6, WHITE);
+ } else {
+ const fire = [];
+ burst(5, S + 2, (r, i) => {
+ const life = r.range(0.14, 0.22), age = t - 0.035;
+ if (age > life) return;
+ const q = age / life, e = ease.outCubic(seg(age, 0, 0.15));
+ fire.push({ x: 6 + (i * 3 + r.range(0, 3)) * (0.4 + e), y: cy + r.range(-3, 3) * e - q * 3, r: r.range(3, 4.5) * (1 - q * 0.6), v: 1 - q });
+ });
+ smoke(p, fire, [C[2], C[3], C[4], C[5], C[6], C[7] ?? WHITE], { base: 0, lit: 0.12, dens: 0.95, grain: 0.1, seed: S + 1, inside });
+ }
+ // the ball: dark iron with a hard highlight, arcing off the canvas
+ if (t > 0.02 && t < 0.6) {
+ const [x, y] = ball(t);
+ p.circle(x, y, 3.2, (d, a) => {
+ const l = -d * (Math.cos(a) + Math.sin(a) * 1.2);
+ return l > 0.55 && d > 0.25 ? I[4] : at(I.slice(1, 4), 0.45 + l * 0.5);
+ }, (d, a) => (inside(x + Math.cos(a) * d * 3.2, y + Math.sin(a) * d * 3.2) ? 1 : 0));
+ }
+ // embers: burning wadding thrown out with the ball
+ burst(8, S + 3, (r) => {
+ const a = r.range(-0.6, 0.5), v = r.range(70, 170), life = r.range(0.25, 0.5);
+ if (t > life) return;
+ const k = t / life, [x, y] = fly(7, cy, Math.cos(a) * v, Math.sin(a) * v, t, 160, 3);
+ if (k > 0.6 && Math.floor(t * 30 + r.next() * 3) % 3 === 0) return;
+ p.px(x, y, k < 0.35 ? at(C, 0.9) : k < 0.7 ? at(C, 0.66) : at(C, 0.45));
+ p.light(x, y, at(C, 0.7), 0.35 * (1 - k));
+ });
+ const L = clamp(1 - t / 0.3);
+ p.glow(10, cy, 34, at(C, 0.62), 0.6 * L * L);
+ if (t < 0.035) p.glow(6, cy, 10, WHITE, 0.5);
+}
diff --git a/src/fx/projectiles/energy-disc.js b/src/fx/projectiles/energy-disc.js
new file mode 100644
index 0000000..055a2fc
--- /dev/null
+++ b/src/fx/projectiles/energy-disc.js
@@ -0,0 +1,44 @@
+import { PAL, ramp, at, cycle, fly, fract, TAU, WHITE } from "../../core/index.js";
+import { onCanvas } from "./_lib.js";
+
+export const meta = {
+ name: "Energy disc",
+ desc: "A spinning sawblade of blue energy: a white-hot rim of hooked teeth whirling round a hollow core, motion arcs trailing and sparks flung off.",
+ tags: ["projectile", "disc", "sawblade", "energy", "sci-fi", "directional", "loop"],
+ size: [48, 30],
+ origin: [36, 15],
+ duration: 0.4,
+ loop: true,
+ fps: 30,
+ bg: "dark",
+ options: { palette: PAL.electric, teeth: 5, radius: 9, seed: 14 },
+};
+
+export function draw(p, t, o) {
+ const C = ramp(o.palette), S = o.seed, D = meta.duration, ph = t / D, n = o.teeth, R = o.radius;
+ const cx = -R + 0.5, cy = 0.5, spin = ph * TAU, inside = onCanvas(meta, 1); // one turn a loop
+ // motion arcs: ghost rims sliding off behind
+ for (let i = 1; i <= 2; i++) p.arc(cx - i * 4, cy, R - i, 1, Math.PI * 0.55, Math.PI * 1.45, i === 1 ? C[3] : C[2]);
+ // the disc: hooked teeth on a bright rim, three curved spokes, a hollow dark core
+ p.shade(cx - R - 3, cy - R - 3, cx + R + 3, cy + R + 3, (x, y) => {
+ const dx = x - cx, dy = y - cy, d = Math.hypot(dx, dy), a = Math.atan2(dy, dx);
+ const tooth = fract(((a - spin) * n) / TAU), edge = R - 2.6 + 2.8 * tooth;
+ if (d > edge || d < 2.2) return;
+ if (d > edge - 1.1) return tooth > 0.7 ? WHITE : at(C, 0.86);
+ if (d > R - 3.4) return at(C, 0.7);
+ const spoke = Math.sin((a - spin) * 3 + d * 0.5);
+ if (d < 3.3) return at(C, 0.44);
+ return spoke > 0.55 ? at(C, 0.62) : at(C, 0.32);
+ });
+ // sparks: flung off the teeth, tangent to the spin, falling behind
+ cycle(t, D, 8, S, (r) => r.range(0.1, 0.22), (age, life, r) => {
+ const a = r.range(0, TAU), k = age / life, sx = cx + Math.cos(a) * R, sy = cy + Math.sin(a) * R;
+ const v = r.range(50, 110), [x, y] = fly(sx, sy, -Math.sin(a) * v - 70, Math.cos(a) * v, age, 60, 2);
+ if (!inside(x, y)) return;
+ p.px(x, y, k < 0.4 ? WHITE : at(C, 0.7));
+ p.light(x, y, at(C, 0.6), 0.4 * (1 - k));
+ });
+ const pulse = 0.9 + 0.1 * Math.sin(ph * TAU * 2);
+ p.glow(cx, cy, R * 2, at(C, 0.55), 0.3 * pulse);
+ p.glowRing(cx, cy, R - 1, 3, at(C, 0.75), 0.3 * pulse);
+}
diff --git a/src/fx/projectiles/flare.js b/src/fx/projectiles/flare.js
new file mode 100644
index 0000000..f680ddb
--- /dev/null
+++ b/src/fx/projectiles/flare.js
@@ -0,0 +1,77 @@
+import { RAMP, ramp, at, stream, fly, rand, seg, ease, WHITE } from "../../core/index.js";
+import { puffs, onCanvas } from "./_lib.js";
+
+export const meta = {
+ name: "Signal flare",
+ desc: "A flare streaks up on a thin smoke trail, bursts into a blinding red star at the top, then sinks slowly, dripping sparks under a column of smoke.",
+ tags: ["projectile", "flare", "signal", "light", "smoke", "one-shot"],
+ size: [64, 104],
+ origin: [10, 98],
+ duration: 3.2,
+ loop: false,
+ fps: 30,
+ bg: "sky",
+ options: { palette: ["#2a0610", "#5c0c1a", "#9c1424", "#e0242c", "#ff5a4a", "#ffa08a", "#ffe0d4", "#ffffff"], seed: 11 },
+};
+
+const T1 = 0.7, T2 = 2.3, T3 = 2.55; // ignite at the top, start to gutter, out
+
+/** Where the flare is at time t. */
+function at_(t) {
+ if (t < T1) {
+ const u = seg(t, 0, T1);
+ return [28 * ease.outSine(u), -74 * ease.outQuad(u)];
+ }
+ const s = t - T1;
+ return [28 + Math.sin(s * 2.6) * 2.5 + s * 3, -74 + s * 13];
+}
+
+export function draw(p, t, o) {
+ const C = ramp(o.palette), S = o.seed, inside = onCanvas(meta, 1);
+ // smoke: a thin trail on the way up, then a column left hanging as the flare sinks away from it
+ const list = [];
+ stream(t, 0.02, T1, 50, S, (r) => r.range(0.45, 0.65), (age, life, r, i) => {
+ const [x, y] = at_(0.02 + i / 50), k = age / life;
+ list.push({ x: x + age * 3, y: y + 2, r: 0.8 + k * 1.6, v: (1 - k) * 0.85 });
+ });
+ stream(t, T1 + 0.05, T2 - 0.1, 16, S + 1, (r) => r.range(0.8, 1.05), (age, life, r, i) => {
+ const [x, y] = at_(T1 + 0.05 + i / 16), k = age / life;
+ list.push({ x: x + age * r.range(3, 7), y: y - 3 - age * r.range(5, 9), r: 2 + k * r.range(3.5, 5.5), v: (1 - k) ** 1.2 * 0.95, tone: -0.08 });
+ });
+ if (t < 0.5) list.push({ x: 1 + t * 6, y: -2 - t * 10, r: 2 + t * 5, v: 1 - t / 0.5 });
+ puffs(p, list, RAMP.smoke, { base: 0.58, inside });
+ const [x, y] = at_(Math.min(t, T3));
+ // sparks dripping off the burning flare
+ stream(t, T1, T2, 34, S + 2, (r) => r.range(0.35, 0.6), (age, life, r, i) => {
+ const [x0, y0] = at_(T1 + i / 34), k = age / life, vx = r.range(-16, 16), vy = r.range(-14, 4);
+ const [sx, sy] = fly(x0, y0 + 1, vx, vy, age, 90, 1), [qx, qy] = fly(x0, y0 + 1, vx, vy, Math.max(0, age - 0.03), 90, 1);
+ if (!inside(sx, sy) || !inside(qx, qy) || (k > 0.6 && Math.floor(age * 30 + r.next() * 3) % 3 === 0)) return;
+ p.line(qx, qy, sx, sy, k < 0.3 ? at(C, 0.85) : k < 0.65 ? at(C, 0.62) : at(C, 0.42));
+ });
+ if (t < T1) {
+ // climbing: a hot little streak
+ const [px0, py0] = at_(Math.max(0, t - 0.03));
+ p.line(px0, py0, x, y, (u) => (u > 0.5 ? WHITE : at(C, 0.7)));
+ p.glow(x, y, 9, at(C, 0.6), 0.4);
+ return;
+ }
+ if (t >= T3) return;
+ // burning: a white star in a red flame that flickers every frame, gutters at the end
+ const life = 1 - seg(t, T2, T3), fl = rand(S, Math.floor(t * 30));
+ const R = (2.6 + fl * 1.2) * (0.35 + 0.65 * life);
+ p.circle(x, y + 0.5, R + 1.4, at(C, 0.5), life > 0.5 ? 1 : 0.5);
+ p.circle(x, y + 0.5, R, at(C, 0.7));
+ if (life > 0.3) p.circle(x, y + 0.5, R * 0.55, WHITE);
+ // the ignition: a four-point burst for the first moments at the top
+ const pop = 1 - seg(t, T1, T1 + 0.22);
+ if (pop > 0) {
+ const L = 3 + 10 * ease.outCubic(seg(t, T1, T1 + 0.05)) * pop;
+ p.line(x - L, y, x + L, y, (u) => (Math.abs(u - 0.5) < 0.2 ? WHITE : at(C, 0.75)));
+ p.line(x, y - L, x, y + L, (u) => (Math.abs(u - 0.5) < 0.2 ? WHITE : at(C, 0.75)));
+ p.glow(x, y, 20, WHITE, 0.4 * pop);
+ }
+ // light: a big red pool that breathes with the flicker
+ const k = life * (0.85 + 0.15 * fl);
+ p.glow(x, y, 34, at(C, 0.55), 0.45 * k);
+ p.glow(x, y, 9, at(C, 0.85), 0.45 * k);
+}
diff --git a/src/fx/projectiles/homing-missile.js b/src/fx/projectiles/homing-missile.js
new file mode 100644
index 0000000..5ee5e4e
--- /dev/null
+++ b/src/fx/projectiles/homing-missile.js
@@ -0,0 +1,85 @@
+import { PAL, RAMP, ramp, at, burst, stream, fly, flyV, rand, seg, ease, lerp, TAU, WHITE, hex } from "../../core/index.js";
+import { bez, bezAngle, rotSprite, puffs, smoke, onCanvas, steps } from "./_lib.js";
+
+export const meta = {
+ name: "Homing missile",
+ desc: "A missile launches, curves up and over and dives onto a locked target, a white smoke trail hanging along its path, then a fiery hit.",
+ tags: ["projectile", "missile", "homing", "explosive", "smoke", "one-shot"],
+ size: [128, 80],
+ origin: [8, 62],
+ duration: 1.9,
+ loop: false,
+ fps: 30,
+ bg: "dark",
+ options: { palette: PAL.fire, seed: 8 },
+};
+
+const PATH = [[0, 0], [10, -66], [80, -72], [98, -12]];
+const HIT = 0.9;
+const MISSILE = ["dd........", "ommmmmmllr", "dd........"];
+const MPAL = { d: "#4a5468", o: "#1c2230", m: "#9aa6ba", l: "#d0d8e6", r: "#d42a30" };
+const LOCK = hex("#ff4a48");
+
+/** How far along the path at time t: it leaves the rail slowly and accelerates into the dive. */
+const prog = (t) => {
+ const u = seg(t, 0, HIT);
+ return 0.3 * u + 0.7 * u * u;
+};
+
+export function draw(p, t, o) {
+ const C = steps(ramp(o.palette), 8), S = o.seed, inside = onCanvas(meta, 1), [tx, ty] = PATH[3];
+ // the trail: puffs dropped behind the tail, swelling, sinking a touch and thinning; the newest on top
+ const list = [];
+ stream(t, 0.03, HIT - 0.02, 70, S, (r) => r.range(0.7, 0.95), (age, life, r, i) => {
+ const u = prog(0.03 + i / 70), [x, y] = bez(PATH, u), a = bezAngle(PATH, u), k = age / life;
+ list.push({ x: x - Math.cos(a) * 10 + r.range(-0.5, 0.5), y: y - Math.sin(a) * 10 + age * 4, r: 1 + 2.4 * ease.outCubic(k) * r.range(0.8, 1.2), v: (1 - k) ** 1.4 });
+ });
+ puffs(p, list, RAMP.smoke, { base: 0.62, inside });
+ // the lock-on reticle: brackets closing on the target, blinking until they lock
+ if (t < HIT) {
+ const lock = ease.outCubic(seg(t, 0.05, 0.6)), s = Math.round(lerp(15, 6, lock));
+ if (lock >= 1 || Math.floor(t * 14) % 2 === 0) {
+ for (const [sx, sy] of [[-1, -1], [1, -1], [-1, 1], [1, 1]]) {
+ const cx = tx + sx * s, cy = ty + sy * s;
+ p.line(cx, cy, cx - sx * 3, cy, LOCK);
+ p.line(cx, cy, cx, cy - sy * 3, LOCK);
+ }
+ if (lock >= 1) p.px(tx, ty, LOCK);
+ }
+ }
+ // the missile, its jet flickering behind it
+ if (t < HIT) {
+ const u = prog(t), [x, y] = bez(PATH, u), a = bezAngle(PATH, u), ca = Math.cos(a), sa = Math.sin(a);
+ const jl = 2 + Math.floor(rand(S, Math.floor(t * 30)) * 3);
+ for (let j = 0; j <= jl; j++) p.px(x - ca * (10.5 + j), y - sa * (10.5 + j), j < 1 ? WHITE : j < 2 ? at(C, 0.84) : at(C, 0.6));
+ rotSprite(p, MISSILE, MPAL, x, y, a, 10, 1.5);
+ p.glow(x - ca * 11, y - sa * 11, 9, at(C, 0.62), 0.35);
+ }
+ // the hit: a white frame, a fireball cooling into smoke, a shockwave, sparks
+ const te = t - HIT;
+ if (te < 0) return;
+ const fire = [], smk = [];
+ burst(7, S + 3, (r, i) => {
+ const ang = (i / 7) * TAU + r.range(-0.4, 0.4), reach = i === 0 ? 0 : r.range(3, 8), life = r.range(0.6, 0.85);
+ const age = te - (i ? r.range(0, 0.05) : 0);
+ if (age < 0 || age > life) return;
+ const q = age / life, e = ease.outCubic(seg(age, 0, 0.2)), r0 = r.range(3.5, 5.5) * (0.5 + 0.6 * e);
+ const x = tx + Math.cos(ang) * reach * e, y = ty + Math.sin(ang) * reach * e * 0.8 - age * age * 22;
+ fire.push({ x, y, r: r0 * (1 - 0.5 * seg(q, 0.1, 0.5)), v: 1 - seg(q, 0.04, 0.5) });
+ smk.push({ x, y: y - q * 8, r: r0 * (1.1 + 0.6 * q), v: seg(q, 0.1, 0.32) * (1 - seg(q, 0.6, 1)) });
+ });
+ smoke(p, smk, RAMP.smoke, { base: 0.38, seed: S + 2, inside });
+ smoke(p, fire, [C[2], C[3], C[4], C[5], C[6], C[7] ?? WHITE, WHITE], { base: 0, lit: 0.12, dens: 0.95, grain: 0.1, seed: S + 1, inside });
+ if (te < 0.07) p.circle(tx, ty, 4 + 30 * te, WHITE);
+ const sw = seg(te, 0.02, 0.22);
+ if (sw > 0 && sw < 1) p.ring(tx, ty, 7 + 10 * ease.outCubic(sw), 1, at(C, 0.9), 1 - sw * 0.8);
+ burst(10, S + 4, (r) => {
+ const a = r.range(0, TAU), v = r.range(60, 120), life = r.range(0.25, 0.45);
+ if (te > life) return;
+ const q = te / life, [x, y] = fly(tx, ty, Math.cos(a) * v, Math.sin(a) * v - 30, te, 150, 2.5), [vx, vy] = flyV(Math.cos(a) * v, Math.sin(a) * v - 30, te, 150, 2.5);
+ if (!inside(x, y) || !inside(x - vx * 0.02, y - vy * 0.02)) return;
+ p.line(x, y, x - vx * 0.02, y - vy * 0.02, q < 0.35 ? at(C, 0.92) : q < 0.7 ? at(C, 0.7) : at(C, 0.45));
+ });
+ const L = 1 - seg(te, 0, 0.45);
+ p.glow(tx, ty, 30, at(C, 0.65), 0.55 * L * L);
+}
diff --git a/src/fx/projectiles/laser-bolt.js b/src/fx/projectiles/laser-bolt.js
new file mode 100644
index 0000000..c6c0cfa
--- /dev/null
+++ b/src/fx/projectiles/laser-bolt.js
@@ -0,0 +1,37 @@
+import { ramp, at, fract, cycle, TAU, WHITE } from "../../core/index.js";
+
+export const meta = {
+ name: "Laser bolt",
+ desc: "A red blaster bolt: a white-cored capsule with a hard red rim that throbs, a shimmering tail, afterimage dashes dropping behind.",
+ tags: ["projectile", "laser", "blaster", "sci-fi", "directional", "loop"],
+ size: [52, 15],
+ origin: [47, 7],
+ duration: 0.3,
+ loop: true,
+ fps: 30,
+ bg: "dark",
+ options: { palette: ["#1e0408", "#4a0a12", "#8e1020", "#d81e2c", "#ff4a48", "#ff9e8c", "#ffe4dc", "#ffffff"], length: 16, seed: 2 },
+};
+
+export function draw(p, t, o) {
+ const C = ramp(o.palette), L = o.length, S = o.seed, D = meta.duration, ph = t / D;
+ const fat = fract(ph * 3) < 0.34; // the rim swells one frame in three
+ // tail: a streak behind the bolt whose length shimmers
+ const tl = Math.round(9 + 3 * Math.sin(ph * TAU * 3 + 1));
+ p.line(-L - 1, 0, -L - tl, 0, (u) => (u < 0.4 ? at(C, 0.62) : u < 0.75 ? at(C, 0.46) : at(C, 0.32)));
+ // afterimages: short dashes that drop off the tail and fall back, shrinking
+ cycle(t, D, 3, S + 1, (r) => r.range(0.14, 0.2), (age, life, r) => {
+ const k = age / life, x0 = -L - 6 - age * 80, len = Math.round(6 * (1 - k)) + 1;
+ p.line(x0, 0, x0 - len, 0, k < 0.45 ? at(C, 0.46) : at(C, 0.32));
+ });
+ // the bolt
+ p.beam(-L, 0.5, 0, 0.5, fat ? 5.2 : 3.6, (u, v) => (v < 0.28 ? (u < 0.18 ? at(C, 0.8) : WHITE) : v < 0.68 ? at(C, fat ? 0.8 : 0.7) : at(C, 0.56)));
+ // sparks fizzing off the tail
+ cycle(t, D, 5, S, (r) => r.range(0.1, 0.2), (age, life, r) => {
+ const k = age / life, x = -L + r.range(-2, 6) - age * r.range(60, 110), y = r.sign() * (2 + age * r.range(8, 22));
+ p.px(x, y, k < 0.5 ? at(C, 0.62) : at(C, 0.46));
+ });
+ const pulse = fat ? 1 : 0.8;
+ p.glowLine(-L, 0.5, 0, 0.5, 7, at(C, 0.55), 0.32 * pulse);
+ p.glow(-L * 0.35, 0.5, 5, at(C, 0.85), 0.3 * pulse);
+}
diff --git a/src/fx/projectiles/magic-missile.js b/src/fx/projectiles/magic-missile.js
new file mode 100644
index 0000000..90127f6
--- /dev/null
+++ b/src/fx/projectiles/magic-missile.js
@@ -0,0 +1,76 @@
+import { PAL, ramp, at, burst, stream, fly, seg, ease, clamp, TAU, WHITE } from "../../core/index.js";
+import { onCanvas } from "./_lib.js";
+
+export const meta = {
+ name: "Magic missile",
+ desc: "An arcane bolt darts out, weaving toward its mark in tightening swerves and shedding twinkling sparkles, then bursts into a star of light.",
+ tags: ["projectile", "magic", "arcane", "homing", "sparkle", "one-shot"],
+ size: [112, 48],
+ origin: [6, 25],
+ duration: 1.05,
+ loop: false,
+ fps: 30,
+ bg: "dark",
+ options: { palette: PAL.arcane, distance: 88, seed: 9 },
+};
+
+const HIT = 0.55;
+
+export function draw(p, t, o) {
+ const C = ramp(o.palette), S = o.seed, TX = o.distance, inside = onCanvas(meta, 1);
+ // the path: a straight run with swerves that tighten onto the target
+ const pos = (u) => [TX * u, -Math.sin(u * Math.PI * 2.5) * 11 * Math.pow(1 - u, 1.1) + 0.5];
+ const prog = (tt) => Math.pow(seg(tt, 0, HIT), 1.25);
+ // sparkles shed along the way: they hang, twinkle and fade
+ stream(t, 0.02, HIT - 0.03, 40, S, (r) => r.range(0.3, 0.5), (age, life, r, i) => {
+ const [x0, y0] = pos(prog(0.02 + i / 40)), k = age / life;
+ const x = x0 + r.range(-2.5, 2.5), y = y0 + r.range(-2.5, 2.5) + age * r.range(4, 10);
+ if (k > 0.7 && Math.floor((age + r.next()) * 24) % 2) return;
+ const twinkle = Math.floor((age + r.next()) * 16) % 3 === 0 && k < 0.6;
+ p.px(x, y, k < 0.3 ? WHITE : k < 0.65 ? at(C, 0.8) : at(C, 0.6));
+ if (twinkle) for (const [dx, dy] of [[1, 0], [-1, 0], [0, 1], [0, -1]]) p.px(x + dx, y + dy, at(C, 0.68));
+ });
+ if (t < HIT) {
+ const u = prog(t), [x, y] = pos(u);
+ // the ribbon: where it was a moment ago, thinning and cooling
+ for (let j = 9; j >= 1; j--) {
+ const [qx, qy] = pos(prog(t - j * 0.014)), k = j / 9;
+ if (t - j * 0.014 < 0) continue;
+ p.circle(qx, qy, 2.4 * (1 - k * 0.85), k < 0.3 ? at(C, 0.7) : k < 0.6 ? at(C, 0.56) : at(C, 0.44));
+ }
+ // the bolt: a white heart in a violet shell with a four-point glint that turns
+ p.circle(x, y, 3, (d) => (d < 0.4 ? WHITE : d < 0.75 ? at(C, 0.86) : at(C, 0.66)));
+ const spin = Math.floor(t * 20) % 2, arm = 4;
+ for (let s = 1; s <= arm; s++) {
+ const c = s < 3 ? WHITE : at(C, 0.8);
+ if (spin) (p.px(x + s, y, c), p.px(x - s, y, c), p.px(x, y + s, c), p.px(x, y - s, c));
+ else if (s < 3) (p.px(x + s, y + s, c), p.px(x - s, y - s, c), p.px(x + s, y - s, c), p.px(x - s, y + s, c));
+ }
+ p.glow(x, y, 14, at(C, 0.62), 0.42);
+ p.glow(x, y, 5, at(C, 0.9), 0.4);
+ }
+ // the hit: a white star of rays that shoots out and draws back, a ring, sparkles flung wide
+ const te = t - HIT, [tx, ty] = pos(1);
+ if (te < 0) return;
+ const rays = 1 - seg(te, 0.04, 0.2);
+ if (rays > 0) {
+ // a four-point star of light, long cardinal rays and short diagonal ones, that shoots out and draws back
+ const len = (4 + 11 * ease.outCubic(seg(te, 0, 0.06))) * rays;
+ for (let i = 0; i < 8; i++) {
+ const a = (i / 8) * TAU, l = i % 2 ? len * 0.4 : len;
+ p.line(tx, ty, tx + Math.cos(a) * l, ty + Math.sin(a) * l, (u) => (u < 0.45 ? WHITE : u < 0.8 ? at(C, 0.84) : at(C, 0.66)));
+ }
+ p.circle(tx, ty, 3 * rays + 1, (d) => (d < 0.6 ? WHITE : at(C, 0.86)));
+ }
+ const ring = seg(te, 0.1, 0.38);
+ if (ring > 0 && ring < 1) p.ring(tx, ty, 6 + 10 * ease.outCubic(ring), 1, at(C, 0.7), 1 - ring);
+ burst(12, S + 1, (r) => {
+ const a = r.range(0, TAU), v = r.range(50, 110), life = r.range(0.28, 0.46);
+ if (te > life) return;
+ const k = te / life, [x, y] = fly(tx, ty, Math.cos(a) * v, Math.sin(a) * v, te, 30, 4);
+ if (!inside(x, y) || (k > 0.6 && Math.floor(te * 24 + r.next() * 4) % 2)) return;
+ p.px(x, y, k < 0.3 ? WHITE : k < 0.6 ? at(C, 0.8) : at(C, 0.6));
+ p.light(x, y, at(C, 0.7), 0.4 * (1 - k));
+ });
+ p.glow(tx, ty, 26, at(C, 0.62), 0.6 * clamp(1 - te / 0.4) ** 2);
+}
diff --git a/src/fx/projectiles/muzzle-pistol.js b/src/fx/projectiles/muzzle-pistol.js
new file mode 100644
index 0000000..9d015a2
--- /dev/null
+++ b/src/fx/projectiles/muzzle-pistol.js
@@ -0,0 +1,53 @@
+import { PAL, RAMP, ramp, at, rng, burst, fly, seg, ease, WHITE } from "../../core/index.js";
+import { smoke, muzzleFlash } from "./_lib.js";
+
+export const meta = {
+ name: "Pistol muzzle flash",
+ desc: "One white-hot frame of spiky flash, a fireball tearing off forward and cooling, a few sparks and a small curl of smoke.",
+ tags: ["projectile", "muzzle", "gun", "flash", "directional", "one-shot"],
+ size: [40, 28],
+ origin: [5, 16],
+ duration: 0.45,
+ loop: false,
+ fps: 30,
+ bg: "dark",
+ options: { palette: PAL.fire, size: 1, seed: 4 },
+};
+
+const F = 1 / 30;
+
+export function draw(p, t, o) {
+ const C = ramp(o.palette), S = o.seed, k = o.size, r = rng(S, 1), cy = 0.5;
+ const spikes = [[0, r.range(11, 13), 22], [-0.78, r.range(5, 6.5), 50], [0.78, r.range(5, 6.5), 50], [-1.65, r.range(2, 3), 70], [1.65, r.range(2, 3), 70], [Math.PI, 0.6, 6]];
+ // smoke: a small curl rolling forward off the flash, rising and thinning
+ const puffs = [];
+ burst(4, S + 3, (q, i) => {
+ const age = t - 0.03 - i * 0.02, life = q.range(0.28, 0.36);
+ if (age < 0 || age > life) return;
+ const u = age / life, e = ease.outCubic(seg(age, 0, 0.22));
+ puffs.push({ x: (2 + i * 2.6) * k + 6 * e, y: cy - q.range(0, 1.5) - age * q.range(16, 26), r: (1.6 + 2.2 * e + u) * k, v: 1 - u });
+ });
+ smoke(p, puffs, RAMP.smoke, { base: 0.5, seed: S });
+ // the flash: the full spiky star for one frame, then the tongue tears off forward and gutters out
+ if (t < F) muzzleFlash(p, 0, cy, spikes, k, C, 1);
+ else if (t < 2 * F) {
+ muzzleFlash(p, 0, cy, spikes.map(([a, l, s]) => [a, l * 0.3, s]), k * 0.75, C, 0.3);
+ p.ellipse(10 * k, cy, 4.5 * k, 2.4 * k, at(C, 0.5));
+ p.ellipse(10.5 * k, cy, 2.6 * k, 1.4 * k, at(C, 0.72));
+ } else if (t < 3 * F) {
+ p.ellipse(13 * k, cy - 0.5, 2.6 * k, 1.5 * k, at(C, 0.4));
+ p.px(13 * k, cy - 0.5, at(C, 0.6));
+ }
+ // sparks: grains of powder flung forward, cooling as they fall
+ burst(5, S + 2, (q) => {
+ const a = q.range(-0.5, 0.5), sp = q.range(90, 170) * k, life = q.range(0.12, 0.26);
+ if (t > life) return;
+ const u = t / life, [x, y] = fly(3 * k, cy, Math.cos(a) * sp, Math.sin(a) * sp, t, 120, 4);
+ p.px(x, y, u < 0.35 ? at(C, 0.9) : u < 0.7 ? at(C, 0.65) : at(C, 0.45));
+ p.light(x, y, at(C, 0.7), 0.4 * (1 - u));
+ });
+ // light: blinding for a frame, then let go fast
+ const L = 1 - seg(t, 0, 0.12);
+ p.glow(5 * k, cy, 20 * k, at(C, 0.65), 0.55 * L * L);
+ if (t < F) p.glow(3 * k, cy, 7 * k, WHITE, 0.45);
+}
diff --git a/src/fx/projectiles/muzzle-shotgun.js b/src/fx/projectiles/muzzle-shotgun.js
new file mode 100644
index 0000000..d8e5036
--- /dev/null
+++ b/src/fx/projectiles/muzzle-shotgun.js
@@ -0,0 +1,84 @@
+import { PAL, RAMP, ramp, at, rng, burst, fly, seg, ease, lerp, TAU, WHITE } from "../../core/index.js";
+import { smoke, onCanvas } from "./_lib.js";
+
+export const meta = {
+ name: "Shotgun blast",
+ desc: "A wide cone of flame with a white throat, a spray of pellets streaking out, burning powder and a heavy cloud of smoke that rolls forward and rises.",
+ tags: ["projectile", "muzzle", "gun", "shotgun", "flash", "directional", "one-shot"],
+ size: [80, 46],
+ origin: [5, 25],
+ duration: 0.8,
+ loop: false,
+ fps: 30,
+ bg: "dark",
+ options: { palette: PAL.fire, spread: 0.36, pellets: 9, seed: 5 },
+};
+
+const F = 1 / 30;
+
+/** The cone: a fan as wide as the spread, flat across its front, torn into tongues of flame. Returns points. */
+function conePts(T, spread, L, x0, y0, k, base = 2.6, n = 120) {
+ const pts = [], m = T.length - 1;
+ for (let i = 0; i < n; i++) {
+ const a = (i / n) * TAU - Math.PI, q = Math.abs(a) / spread;
+ let R = base;
+ if (q < 1) {
+ const f = (a / spread * 0.5 + 0.5) * m, j = Math.min(m - 1, Math.floor(f)), w = f - j;
+ const tongue = T[j] + (T[j + 1] - T[j]) * w, notch = 1 - 0.3 * Math.abs(Math.sin(f * Math.PI));
+ R += L * (1 - q ** 5) * tongue * notch;
+ }
+ pts.push([x0 + Math.cos(a) * R * k, y0 + Math.sin(a) * R * k]);
+ }
+ return pts;
+}
+
+export function draw(p, t, o) {
+ const C = ramp(o.palette), S = o.seed, sp = o.spread, inside = onCanvas(meta), cy = 0.5;
+ // smoke: a thick cloud shoved out in front of the barrel, slowing, then rolling up and thinning out
+ const puffs = [];
+ burst(9, S + 4, (q, i) => {
+ const age = t - 0.03 - q.range(0, 0.05), life = q.range(0.6, 0.74);
+ if (age < 0 || age > life) return;
+ const u = age / life, e = ease.outQuart(seg(age, 0, 0.32)), reach = 5 + (i / 8) * 26 + q.range(-2, 2);
+ puffs.push({
+ x: 3 + reach * e + age * 5, y: cy + q.range(-0.5, 0.5) * reach * sp * e - u * u * q.range(10, 18),
+ r: (2.5 + reach * 0.12) * (0.55 + 0.45 * e) * (1 + 0.5 * u), v: 1 - u * u,
+ });
+ });
+ smoke(p, puffs, RAMP.smoke, { base: 0.58, seed: S, inside });
+ // pellets: streaks racing out of the cone, gone off the edge in a few frames
+ burst(o.pellets, S + 2, (q) => {
+ const a = q.range(-sp, sp) * 0.8, v = q.range(520, 700), d = 6 + v * (t + q.range(0, 0.012)), len = q.range(6, 10);
+ const x = Math.cos(a) * d, y = cy + Math.sin(a) * d, x1 = x - Math.cos(a) * len, y1 = y - Math.sin(a) * len;
+ if (!inside(x1, y1)) return;
+ p.line(x, y, x1, y1, (u) => (u < 0.2 ? WHITE : at(C, 0.8 - u * 0.35)), (u) => (inside(lerp(x, x1, u), lerp(y, y1, u)) ? 1 : 0));
+ });
+ // the flash: a fat cone for one frame, a cooler ragged one torn forward the next, then tongues that peel off
+ const r = rng(S, 1), T = Array.from({ length: 9 }, () => r.range(0.75, 1.05));
+ const fan = sp * 2.1;
+ if (t < F) {
+ p.poly(conePts(T, fan, 23, 0, cy, 1), at(C, 0.56));
+ p.poly(conePts(T, fan, 23, 1, cy, 0.66, 2), at(C, 0.8));
+ p.ellipse(3.5, cy, 4, 2.6, WHITE);
+ } else if (t < 2 * F) {
+ p.poly(conePts(T, fan, 23, 3, cy, 1.05), at(C, 0.44), (x) => (x < 10 ? 0 : 1));
+ p.poly(conePts(T, fan, 23, 4, cy, 0.8, 2), at(C, 0.64), (x) => (x < 11 ? 0 : 1));
+ p.circle(1.5, cy, 1.6, at(C, 0.84));
+ } else if (t < 3 * F) {
+ // the flame front carries on alone as a ragged arc, then it's gone
+ p.poly(conePts(T, fan, 24, 0, cy, 1.05), at(C, 0.42), (x, y) => (Math.hypot(x, y - cy) > 15 ? 1 : 0));
+ p.poly(conePts(T, fan, 24, 0, cy, 0.98), at(C, 0.56), (x, y) => (Math.hypot(x, y - cy) > 17.5 ? 1 : 0));
+ }
+ // burning powder: embers thrown forward that fall and wink out
+ burst(9, S + 3, (q) => {
+ const a = q.range(-sp, sp) * 1.2, v = q.range(80, 200), life = q.range(0.2, 0.45);
+ if (t > life) return;
+ const u = t / life, [x, y] = fly(4, cy, Math.cos(a) * v, Math.sin(a) * v, t, 140, 3.5);
+ if (u > 0.6 && (t * 30 + q.next() * 4) % 3 < 1) return;
+ p.px(x, y, u < 0.3 ? at(C, 0.9) : u < 0.65 ? at(C, 0.68) : at(C, 0.48));
+ p.light(x, y, at(C, 0.7), 0.35 * (1 - u));
+ });
+ const L = 1 - seg(t, 0, 0.16);
+ p.glow(10, cy, 28, at(C, 0.66), 0.6 * L * L);
+ if (t < F) p.glow(4, cy, 9, WHITE, 0.5);
+}
diff --git a/src/fx/projectiles/muzzle-smg.js b/src/fx/projectiles/muzzle-smg.js
new file mode 100644
index 0000000..12953b1
--- /dev/null
+++ b/src/fx/projectiles/muzzle-smg.js
@@ -0,0 +1,48 @@
+import { PAL, RAMP, ramp, at, rng, burst, cycle, fly, WHITE } from "../../core/index.js";
+import { smoke, muzzleFlash } from "./_lib.js";
+
+export const meta = {
+ name: "SMG burst",
+ desc: "Rapid fire: four shots a loop, each flash a different spiky star for a frame then a gutter, sparks spitting and a stream of smoke wisps.",
+ tags: ["projectile", "muzzle", "gun", "automatic", "flash", "directional", "loop"],
+ size: [40, 28],
+ origin: [5, 16],
+ duration: 0.4,
+ loop: true,
+ fps: 30,
+ bg: "dark",
+ options: { palette: PAL.volt, shots: 4, seed: 6 },
+};
+
+export function draw(p, t, o) {
+ const C = ramp(o.palette), S = o.seed, D = meta.duration, n = o.shots, gap = D / n, cy = 0.5, F = 1 / 30;
+ const i = Math.floor(t / gap) % n, ts = t - i * gap;
+ // wisps: small puffs leaving the muzzle all the time, drifting forward and up
+ const puffs = [];
+ cycle(t, D, 5, S + 2, (r) => r.range(0.3, 0.4), (age, life, r) => {
+ const u = age / life;
+ puffs.push({ x: 4 + age * r.range(28, 46), y: cy - 1 - age * r.range(12, 22), r: 1.5 + u * r.range(2, 3), v: (1 - u) * 0.8 });
+ });
+ smoke(p, puffs, RAMP.smoke, { base: 0.5, seed: S });
+ // the shot: each one its own shape, full for a frame, then a guttering stub
+ const r = rng(S, i), tilt = r.range(-0.08, 0.08);
+ const spikes = [[tilt, r.range(8, 12), r.range(14, 30)], [-r.range(0.55, 0.95), r.range(3.5, 6), 50], [r.range(0.55, 0.95), r.range(3.5, 6), 50], [-1.65, r.range(1, 2.5), 70], [1.65, r.range(1, 2.5), 70]];
+ if (ts < F) {
+ muzzleFlash(p, 0, cy, spikes, 0.9, C, 1);
+ p.glow(4, cy, 18, at(C, 0.6), 0.5);
+ p.glow(3, cy, 6, WHITE, 0.35);
+ } else if (ts < 2 * F) {
+ muzzleFlash(p, 0, cy, spikes.map(([a, l, s]) => [a, l * 0.45, s]), 0.7, C, 0.3);
+ p.glow(4, cy, 14, at(C, 0.55), 0.2);
+ }
+ // sparks: a few per shot, flung forward
+ for (let s = 0; s < n; s++) {
+ const age = (((t - s * gap) % D) + D) % D;
+ burst(3, S + 10 + s, (q) => {
+ const a = q.range(-0.55, 0.55), v = q.range(100, 180), life = q.range(0.08, 0.16);
+ if (age > life) return;
+ const [x, y] = fly(3, cy, Math.cos(a) * v, Math.sin(a) * v, age, 160, 3);
+ p.px(x, y, age / life < 0.5 ? at(C, 0.9) : at(C, 0.6));
+ });
+ }
+}
diff --git a/src/fx/projectiles/plasma-shot.js b/src/fx/projectiles/plasma-shot.js
new file mode 100644
index 0000000..bde385b
--- /dev/null
+++ b/src/fx/projectiles/plasma-shot.js
@@ -0,0 +1,53 @@
+import { ramp, at, cycle, TAU, WHITE } from "../../core/index.js";
+
+export const meta = {
+ name: "Plasma shot",
+ desc: "A churning teardrop of green plasma, white-hot in the head, its tail tearing into gooey droplets that shrink and boil away behind it.",
+ tags: ["projectile", "plasma", "energy", "sci-fi", "directional", "loop"],
+ size: [52, 23],
+ origin: [42, 11],
+ duration: 0.6,
+ loop: true,
+ fps: 30,
+ bg: "dark",
+ options: { palette: ["#04161a", "#073536", "#0b5e4e", "#119060", "#2ac46e", "#7cf07c", "#d4ffc0", "#ffffff"], size: 5, seed: 3 },
+};
+
+export function draw(p, t, o) {
+ const C = ramp(o.palette), R = o.size, S = o.seed, D = meta.duration, ph = t / D;
+ const hx = -R + 0.5, hy = 0.5, head = [], tail = [];
+ // the head: three lobes rolling around the center at different speeds make the surface churn
+ for (let i = 0; i < 3; i++) {
+ const a = ph * TAU * (i === 1 ? -2 : i + 1) + (i * TAU) / 3, off = R * 0.38;
+ head.push([hx + Math.cos(a) * off, hy + Math.sin(a) * off * 0.85, R * 0.7]);
+ }
+ // the tail: two blobs that wag behind the head, then droplets torn off its end
+ const wag = Math.sin(ph * TAU * 2);
+ tail.push([hx - R * 0.95, hy + wag * 0.6, R * 0.5], [hx - R * 1.65, hy - wag * 0.8, R * 0.32]);
+ cycle(t, D, 6, S, (r) => r.range(0.26, 0.4), (age, life, r) => {
+ const k = age / life, x = hx - R * 1.7 - age * r.range(55, 85), y = hy + r.range(-0.7, 0.7) * R * Math.min(1, k * 2);
+ tail.push([x, y, R * r.range(0.36, 0.5) * (1 - k) ** 0.7]);
+ });
+ const field = (list, x, y) => {
+ let f = 0;
+ for (const [bx, by, br] of list) {
+ const dx = x - bx, dy = y - by;
+ f += (br * br) / (dx * dx + dy * dy + 0.05);
+ }
+ return f;
+ };
+ p.shade(hx - R * 2 - 34, hy - R * 1.6, hx + R * 1.5, hy + R * 1.6, (x, y) => {
+ const h = field(head, x, y), f = h + field(tail, x, y);
+ if (f < 1) return;
+ if (h > 6) return WHITE; // only the head runs white-hot; the goo behind tops out a step lower
+ return Math.min(f, h + 3.5) > 3.4 ? at(C, 0.84) : f > 2 ? at(C, 0.7) : f > 1.35 ? at(C, 0.56) : at(C, 0.42);
+ });
+ // fizz: single motes spat out behind
+ cycle(t, D, 6, S + 1, (r) => r.range(0.15, 0.3), (age, life, r) => {
+ const k = age / life, x = hx - R * 0.8 - age * r.range(40, 90), y = hy + r.sign() * (R * 0.7 + age * r.range(12, 30));
+ if (k < 0.75) p.px(x, y, k < 0.35 ? at(C, 0.8) : at(C, 0.58));
+ });
+ const pulse = 0.88 + 0.12 * Math.sin(ph * TAU * 2);
+ p.glow(hx - 2, hy, R * 3.2, at(C, 0.55), 0.3 * pulse);
+ p.glow(hx, hy, R * 1.4, at(C, 0.8), 0.35 * pulse);
+}
diff --git a/src/fx/projectiles/rocket.js b/src/fx/projectiles/rocket.js
new file mode 100644
index 0000000..05a3ddd
--- /dev/null
+++ b/src/fx/projectiles/rocket.js
@@ -0,0 +1,61 @@
+import { PAL, RAMP, ramp, at, cycle, rand, loopNoise, WHITE } from "../../core/index.js";
+import { smoke, beat, onCanvas, steps } from "./_lib.js";
+
+export const meta = {
+ name: "Rocket",
+ desc: "A rocket in flight: a roaring jet flickering out of the nozzle, a billowing smoke trail streaming back and spreading, sparks spat into it.",
+ tags: ["projectile", "rocket", "missile", "explosive", "smoke", "directional", "loop"],
+ size: [100, 30],
+ origin: [92, 15],
+ duration: 0.6,
+ loop: true,
+ fps: 30,
+ bg: "dark",
+ options: { palette: PAL.fire, seed: 7 },
+};
+
+const BODY = [
+ "dd...........",
+ ".dd..........",
+ "ommmllllllrr.",
+ "ommmmmmmmmrrR",
+ "ommsssssssrr.",
+ ".dd..........",
+ "dd...........",
+];
+const BODY_PAL = { d: "#4a5468", o: "#1c2230", m: "#6e7a90", l: "#aab4c6", s: "#4a5468", r: "#c42a30", R: "#ff6a5a" };
+
+export function draw(p, t, o) {
+ const C = steps(ramp(o.palette), 8), S = o.seed, D = meta.duration, ph = t / D, inside = onCanvas(meta, 1);
+ const step = Math.floor(ph * 18) % 18, J = 8 + rand(S, step) * 5; // the jet's length jumps every frame
+ // smoke: puffs leave the nozzle, stream back, swell, rise a little and thin out
+ const list = [];
+ beat(t, D, 18, S, (r) => r.range(0.5, 0.6), (age, life, r) => {
+ const u = age / life;
+ list.push({
+ x: -15 - J * 0.4 - age * r.range(104, 116), y: 0.5 + r.range(-1, 1) * (0.5 + u * 3) - u * u * r.range(2, 6),
+ r: 1.8 + u * r.range(3.4, 4.8), v: (1 - u) ** 0.8,
+ });
+ });
+ smoke(p, list, RAMP.smoke, { base: 0.5, seed: S, inside });
+ // the jet: white at the nozzle, cooling to red at a ragged tip
+ const F = [C[3], C[4], C[5], C[6], C[7] ?? WHITE];
+ p.shade(-13 - J - 1, -3, -12, 4, (x, y) => {
+ const v = (-12.5 - x) / J;
+ if (v < 0 || v > 1) return;
+ const w = 2.4 * Math.pow(1 - v, 0.75) + 0.3, dy = Math.abs(y - 0.5);
+ if (dy > w) return;
+ const heat = (1 - v) * (1.15 - 0.55 * (dy / w)) + 0.12 * loopNoise(ph * 3 - Math.floor(ph * 3), 1, S + Math.round(x));
+ return heat > 0.95 ? WHITE : at(F, heat);
+ });
+ // sparks spat out of the jet
+ cycle(t, D, 6, S + 1, (r) => r.range(0.12, 0.22), (age, life, r) => {
+ const k = age / life, x = -16 - age * r.range(90, 150), y = 0.5 + r.sign() * age * r.range(10, 30);
+ p.px(x, y, k < 0.4 ? at(C, 0.9) : at(C, 0.62));
+ });
+ p.sprite(BODY, BODY_PAL, -12, -3);
+ // light: the jet's glow flickers with its length
+ const fl = 0.8 + 0.2 * (J - 8) / 5;
+ p.glow(-15, 0.5, 18, at(C, 0.62), 0.35 * fl);
+ p.glow(-13, 0.5, 6, at(C, 0.9), 0.35 * fl);
+}
diff --git a/src/fx/projectiles/shuriken.js b/src/fx/projectiles/shuriken.js
new file mode 100644
index 0000000..810e9c0
--- /dev/null
+++ b/src/fx/projectiles/shuriken.js
@@ -0,0 +1,39 @@
+import { PAL, ramp, at, cycle, star, wrap, TAU, WHITE } from "../../core/index.js";
+import { steps } from "./_lib.js";
+
+export const meta = {
+ name: "Shuriken",
+ desc: "A four-point throwing star spinning fast, its blades lit and shaded by turns, smears trailing each tip and wind streaks behind.",
+ tags: ["projectile", "shuriken", "ninja", "throwing", "metal", "directional", "loop"],
+ size: [46, 22],
+ origin: [36, 11],
+ duration: 0.4,
+ loop: true,
+ fps: 30,
+ bg: "dark",
+ options: { palette: PAL.metal, size: 7.5, seed: 15 },
+};
+
+export function draw(p, t, o) {
+ const C = steps(ramp(o.palette), 8), S = o.seed, D = meta.duration, ph = t / D, R = o.size;
+ const cx = -R + 0.5, cy = 0.5, rot = ph * TAU * 0.75; // three quarter-turns a loop: 22.5 degrees a frame
+ // wind streaks behind
+ cycle(t, D, 5, S, (r) => r.range(0.1, 0.14), (age, life, r) => {
+ const k = age / life, y = cy + r.sign() * r.int(2, 5), x = cx - R + 2 - age * r.range(120, 150), len = r.range(4, 9) * (1 - k * 0.8);
+ p.line(x, y, x - len, y, (u) => (u < 0.3 ? C[4] : C[3]));
+ });
+ // smears: each tip drags a short arc behind it
+ for (let i = 0; i < 4; i++) {
+ const a = rot + (i * TAU) / 4 - Math.PI / 2;
+ p.arc(cx, cy, R + 0.4, 1.3, a - 0.75, a - 0.12, (u) => (u > 0.55 ? C[3] : C[2]));
+ }
+ // the star: each blade split into a lit face and a shaded face, a dark hole in the middle
+ p.poly(star(cx, cy, R * 0.4, R, 4, rot - Math.PI / 2), (x, y) => {
+ const a = wrap(Math.atan2(y - cy, x - cx) - rot + Math.PI / 2, TAU / 4) / (TAU / 4);
+ return a < 0.5 ? at(C, 0.84) : at(C, 0.52);
+ });
+ p.circle(cx, cy, 1.4, C[1]);
+ // a glint that rides the top blade
+ const g = rot - Math.PI / 2 + TAU / 8;
+ p.px(cx + Math.cos(g - 0.6) * R * 0.45, cy + Math.sin(g - 0.6) * R * 0.45, WHITE);
+}
diff --git a/src/fx/projectiles/sniper-trail.js b/src/fx/projectiles/sniper-trail.js
new file mode 100644
index 0000000..63a3851
--- /dev/null
+++ b/src/fx/projectiles/sniper-trail.js
@@ -0,0 +1,53 @@
+import { ramp, at, seg, ease, noise, noise2, clamp, WHITE } from "../../core/index.js";
+import { flashPts } from "./_lib.js";
+
+export const meta = {
+ name: "Sniper trail",
+ desc: "A hitscan shot: a blinding line across the canvas for a frame, a thin trace that cools, then a twisted smoke wake that loosens, drifts and breaks apart.",
+ tags: ["projectile", "sniper", "hitscan", "rifle", "trail", "smoke", "directional", "one-shot"],
+ size: [128, 24],
+ origin: [3, 13],
+ duration: 1.3,
+ loop: false,
+ fps: 30,
+ bg: "dark",
+ options: { palette: ["#141a2a", "#26324a", "#3e5270", "#647c9c", "#9cb4cc", "#d8e8f4", "#ffffff"], seed: 17 },
+};
+
+const F = 1 / 30;
+
+export function draw(p, t, o) {
+ const C = ramp(o.palette), S = o.seed, X1 = meta.size[0] - meta.origin[0] - 2, cy = 0.5;
+ if (t < F) {
+ // the shot: a fat white line all the way across, a star at the muzzle
+ p.rect(0, -1, X1, 3, at(C, 0.8));
+ p.rect(0, 0, X1, 1, WHITE);
+ p.poly(flashPts(1, cy, [[0, 6, 20], [-1.4, 3, 40], [1.4, 3, 40]], 2.2), WHITE);
+ p.glowLine(0, cy, X1, cy, 6, at(C, 0.7), 0.45);
+ p.glow(2, cy, 12, WHITE, 0.4);
+ return;
+ }
+ if (t < 3 * F) {
+ // the trace: a thin bright line cooling a step a frame
+ p.rect(0, 0, X1, 1, t < 2 * F ? WHITE : at(C, 0.84));
+ p.glowLine(0, cy, X1, cy, 4, at(C, 0.6), t < 2 * F ? 0.3 : 0.15);
+ return;
+ }
+ // the wake: two strands of smoke twisted round the line, loosening, drifting up and fraying into gaps
+ const k = seg(t, 3 * F, meta.duration - 0.05), loose = ease.outCubic(k);
+ const A = 2.6 * loose, rise = -4 * k * k;
+ for (let x = 0; x < X1; x++) {
+ const age = clamp(k * 1.15 - (x / X1) * 0.15); // the muzzle end goes a touch before the far end
+ const gone = 0.25 + 0.75 * age;
+ if (noise2(x * 0.12, k * 3, S) * 0.5 + 0.5 < gone * gone * 1.25 - 0.15) continue;
+ const drift = noise(x * 0.07 + k * 2, S + 1) * 2.5 * loose + rise;
+ for (const side of [1, -1]) {
+ const y = cy + drift + side * Math.sin(x * 0.42 + side * 0.4) * A;
+ const c = k < 0.12 ? at(C, 0.8) : k < 0.35 ? at(C, side > 0 ? 0.68 : 0.58) : at(C, side > 0 ? 0.55 : 0.45);
+ p.dot(x, y, c, 1 - age * 0.55);
+ }
+ }
+ // a breath of smoke at the muzzle
+ const m = 1 - seg(t, 0.05, 0.6);
+ if (m > 0) p.circle(1 + k * 6, cy - 1 - k * 6, 1.5 + k * 4, at(C, 0.5), (d) => clamp((1 - d * d) * m * 3));
+}
diff --git a/src/fx/scifi/_lib.js b/src/fx/scifi/_lib.js
new file mode 100644
index 0000000..d77a846
--- /dev/null
+++ b/src/fx/scifi/_lib.js
@@ -0,0 +1,41 @@
+// Shared by the scifi effects. Palettes resampled to a fixed length, a hex grid for shields and floors, and
+// the lightning helpers (bolts, crackles, light along a path) for the effects that spark.
+
+import { ramp } from "../../core/index.js";
+
+export { zap, jagged, glowPath, brokenRing } from "../lightning/_lib.js";
+
+/** The palette as exactly n steps, dark to bright, so an effect can index it the same whatever its length. */
+export function steps(pal, n = 7) {
+ const C = ramp(pal);
+ if (C.length === n) return C;
+ return Array.from({ length: n }, (_, i) => C[Math.round((i * (C.length - 1)) / (n - 1))]);
+}
+
+const R3 = Math.sqrt(3);
+
+/**
+ * The pointy-top hex cell under (x, y) for cells of corner radius s: [q, r, e], the cell's axial coordinates
+ * and how near the point is to the cell's edge (0 at the center, 1 on the edge).
+ */
+export function hexCell(x, y, s) {
+ const fq = ((R3 / 3) * x - y / 3) / s, fr = ((2 / 3) * y) / s, fs = -fq - fr;
+ let q = Math.round(fq), r = Math.round(fr);
+ const S = Math.round(fs), dq = Math.abs(q - fq), dr = Math.abs(r - fr), ds = Math.abs(S - fs);
+ if (dq > dr && dq > ds) q = -r - S;
+ else if (dr > ds) r = -q - S;
+ const cx = s * R3 * (q + r / 2), cy = s * 1.5 * r, ax = Math.abs(x - cx), ay = Math.abs(y - cy);
+ return [q, r, Math.max(ax, 0.5 * ax + 0.866 * ay) / (0.866 * s)];
+}
+
+const cells = new WeakMap();
+/** Every filled pixel of an actor's mask as [x, y, mx, my]: local position and position in the mask. */
+export function maskCells(a) {
+ let list = cells.get(a);
+ if (list) return list;
+ const m = a.mask;
+ list = [];
+ for (let my = 0; my < m.h; my++) for (let mx = 0; mx < m.w; mx++) if (m.data[my * m.w + mx]) list.push([a.x + mx, a.y + my, mx, my]);
+ cells.set(a, list);
+ return list;
+}
diff --git a/src/fx/scifi/cloak.js b/src/fx/scifi/cloak.js
new file mode 100644
index 0000000..c03fd9a
--- /dev/null
+++ b/src/fx/scifi/cloak.js
@@ -0,0 +1,62 @@
+import { seg, ease, rand, lerp, luma, at, WHITE } from "../../core/index.js";
+import { steps, maskCells } from "./_lib.js";
+
+export const meta = {
+ name: "Cloak",
+ desc: "Stealth engaging: the outline flares, a bright seam climbs the body turning it to dark rippling glass, a shimmer clings to the edge, then even that fades.",
+ tags: ["scifi", "stealth", "invisible", "cloak", "status", "buff", "one-shot"],
+ size: [40, 40],
+ origin: [20, 34],
+ duration: 1.1,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ actor: true,
+ options: { palette: ["#06101c", "#0e2236", "#1c3a54", "#2e5a78", "#5a8eac", "#a0d0e8", "#e8f8ff"], seed: 34 },
+};
+
+const SWEEP = [0.06, 0.48], GONE = [0.8, 1.05];
+// the body is glass from the seam on; once it flickers out, the character itself is gone
+export const actorAlpha = (t) => (t < GONE[0] ? 1 : 0);
+
+export function draw(p, t, o) {
+ const C = steps(o.palette, 7), S = o.seed, A = o.actor, beat = Math.floor(t * 20);
+ const cells = maskCells(A), top = A.y - 1;
+ const seam = lerp(1, top, ease.inOutSine(seg(t, SWEEP[0], SWEEP[1])));
+ const gone = seg(t, GONE[0], GONE[1]);
+ if (gone >= 1) return;
+ // going under: the glass flickers out, on for fewer and fewer beats
+ if (gone > 0 && rand(S, beat, 77) < gone * 1.2) {
+ p.outline(A.mask, A.x, A.y, C[4], (mx, my) => (rand(S, mx, my, beat) < 0.25 * (1 - gone) ? 1 : 0));
+ return;
+ }
+
+ // read what's under the body first (the body itself, wherever the game draws it into the same frame)
+ const under = cells.map(([x, y]) => p.get(x, y));
+ // the glass: below the seam the body turns dark and see-through-looking; rows ripple brighter upward
+ const ripple = (y) => Math.sin(y * 0.7 + t * 30) > 0.92;
+ cells.forEach(([x, y, mx, my], i) => {
+ if (y < seam - 1) return;
+ if (Math.abs(y - seam) < 1.2 && t < SWEEP[1] + 0.02) return p.px(x, y, rand(S, mx, beat) < 0.3 ? C[6] : WHITE);
+ const c = under[i], g = c ? at([C[0], C[1], C[2], C[3]], luma(c) * 1.3) : C[1];
+ p.px(x, y, ripple(y) ? C[3] : g);
+ });
+
+ // the edge: a white flare as it engages, then a shimmer that crawls around the outline
+ if (t < 0.1) p.outline(A.mask, A.x, A.y, t < 0.04 ? WHITE : C[5]);
+ else
+ p.outline(A.mask, A.x, A.y, (mx, my) => (rand(S, mx, my, beat) < 0.5 ? C[5] : C[4]), (mx, my) => {
+ const y = A.y + my;
+ if (y < seam - 1) return 0;
+ return rand(S, mx, my, beat >> 1) < 0.45 * (1 - gone) ? 1 : 0;
+ });
+ // glints thrown off the seam as it climbs
+ if (t > SWEEP[0] && t < SWEEP[1]) {
+ for (let i = 0; i < 2; i++) {
+ const s = rand(S, beat, i) < 0.5 ? -1 : 1, x = s * (7 + rand(S, beat, i, 1) * 3);
+ p.px(x, seam - rand(S, beat, i, 2) * 2, C[6]);
+ }
+ p.glowLine(-8, seam, 8, seam, 5, C[5], 0.35);
+ }
+ p.glow(A.chest[0], A.chest[1], 14, C[4], 0.18 * (1 - gone) * (t < 0.5 ? 1 : 0.5));
+}
diff --git a/src/fx/scifi/data-stream.js b/src/fx/scifi/data-stream.js
new file mode 100644
index 0000000..0374919
--- /dev/null
+++ b/src/fx/scifi/data-stream.js
@@ -0,0 +1,39 @@
+import { PAL, rand, wrap } from "../../core/index.js";
+import { steps } from "./_lib.js";
+
+export const meta = {
+ name: "Data stream",
+ desc: "Columns of code fall through a dark panel: bright heads drop cell by cell, trails of glyphs flicker and change behind them and fade out.",
+ tags: ["scifi", "data", "code", "hacker", "digital", "screen", "ambient", "loop"],
+ size: [48, 58],
+ origin: [24, 29],
+ duration: 2,
+ loop: true,
+ fps: 30,
+ bg: "dark",
+ options: { palette: PAL.matrix, columns: 8, seed: 29 },
+};
+
+const GLYPHS = "0123456789+-=<>:/*%#ACEFHKLNRTXZ";
+const ROWS = 9, WRAP = 16, TRAIL = 6, PITCH = 6;
+
+export function draw(p, t, o) {
+ const C = steps(o.palette, 8), S = o.seed, ph = t / meta.duration, n = o.columns;
+ const x0 = -Math.round(((n - 1) * PITCH) / 2), y0 = -27;
+ for (let i = 0; i < n; i++) {
+ const speed = rand(S, i, 1) < 0.4 ? 2 : 1, twin = rand(S, i, 2) < 0.25;
+ for (let s = 0; s < (twin ? 2 : 1); s++) {
+ // the head, in cells; whole laps of WRAP cells a loop, so it comes round seamlessly
+ const head = wrap(rand(S, i, 3, s) * WRAP + s * 8 + ph * speed * WRAP, WRAP) - 2;
+ for (let j = 0; j < ROWS; j++) {
+ const d = Math.floor(head) - j;
+ if (d < 0 || d >= TRAIL) continue;
+ const flip = Math.floor(t * 6 + rand(S, i, j, 4) * 12) % 12, g = GLYPHS[Math.floor(rand(S, i, j, flip) * GLYPHS.length)];
+ const c = d === 0 ? C[7] : d === 1 ? C[6] : d < 3 ? C[5] : d < 4 ? C[4] : C[3];
+ p.text(g, x0 + i * PITCH, y0 + j * 6, c, { font: "mini", align: "center" });
+ if (d === 0) p.glow(x0 + i * PITCH, y0 + j * 6 + 2, 7, C[5], 0.35);
+ }
+ }
+ }
+ p.glow(0, 0, 34, C[3], 0.12);
+}
diff --git a/src/fx/scifi/emp-blast.js b/src/fx/scifi/emp-blast.js
new file mode 100644
index 0000000..87fc816
--- /dev/null
+++ b/src/fx/scifi/emp-blast.js
@@ -0,0 +1,77 @@
+import { PAL, burst, fly, flyV, seg, ease, rng, rand, TAU, WHITE } from "../../core/index.js";
+import { steps, jagged } from "./_lib.js";
+
+export const meta = {
+ name: "EMP blast",
+ desc: "An electromagnetic pulse: a white pop, then a bubble of interference swells out, strobing and crackling over its skin, and shorts out into dead pixels.",
+ tags: ["scifi", "emp", "pulse", "shockwave", "electric", "grenade", "one-shot"],
+ size: [96, 96],
+ origin: [48, 48],
+ duration: 0.9,
+ loop: false,
+ fps: 30,
+ bg: "dark",
+ options: { palette: PAL.electric, radius: 42, seed: 33 },
+};
+
+const OFF = [[0.13, 0.166], [0.3, 0.333], [0.5, 0.533]]; // strobe: frames where the bubble cuts out
+
+export function draw(p, t, o) {
+ const C = steps(o.palette, 7), S = o.seed, R0 = o.radius, beat = Math.floor(t * 20);
+ const R = 4 + (R0 - 4) * ease.outExpo(seg(t, 0, 0.5));
+ const fade = seg(t, 0.45, 0.85), off = OFF.some(([a, b]) => t >= a && t < b);
+
+ // the bubble: interference lines in its outer shell, an equator to round it out, a hard skin that
+ // breaks up as it fades
+ if (fade < 1 && !off) {
+ const scroll = Math.floor(t * 40);
+ p.shade(-R, -R, R, R, (x, y, out) => {
+ const d = (x * x + y * y) / (R * R);
+ if (d > 1) return;
+ if (d > 0.9) {
+ const a = Math.atan2(y, x), gap = rand(S, Math.floor((a + 4) * 7), 7) < fade * 1.3;
+ if (gap) return;
+ out.c = t < 0.1 ? WHITE : fade < 0.3 ? C[5] : fade < 0.6 ? C[4] : C[3];
+ out.k = 0.2 * (1 - fade);
+ return;
+ }
+ if ((Math.floor(y) + scroll) % 3 !== 0 || fade > 0.45 || d < 0.55) return;
+ out.c = d > 0.78 ? C[4] : d > 0.66 ? C[3] : C[2];
+ });
+ if (fade < 0.6) {
+ for (let i = 0; i < 48; i++) {
+ const a0 = (i / 48) * TAU, a1 = ((i + 1) / 48) * TAU, front = Math.sin(a0 + 0.06) > 0;
+ p.line(Math.cos(a0) * R, Math.sin(a0) * R * 0.24, Math.cos(a1) * R, Math.sin(a1) * R * 0.24, front ? C[5] : C[3]);
+ }
+ }
+ }
+
+ // the pop: a white ball and a flash
+ if (t < 0.1) {
+ p.circle(0, 0, 7 - 50 * t, WHITE);
+ p.glow(0, 0, 40, C[5], 0.7 * (1 - t / 0.1));
+ }
+
+ // crackles crawling over the skin
+ if (t > 0.04 && t < 0.7 && !off) {
+ for (let i = 0; i < 4; i++) {
+ const r = rng(S, beat, i), a = r.range(0, TAU), da = r.range(0.2, 0.35) * r.sign();
+ const pts = jagged(r, Math.cos(a) * R, Math.sin(a) * R, Math.cos(a + da) * R, Math.sin(a + da) * R, { step: 3, amp: 1.8 });
+ p.polyline(pts, beat % 2 ? C[5] : WHITE);
+ }
+ }
+
+ // dead pixels and sparks kicked out by the pulse
+ burst(16, S + 5, (r) => {
+ const born = r.range(0.02, 0.3), age = t - born, life = r.range(0.2, 0.35);
+ if (age < 0 || age > life) return;
+ const a = r.range(0, TAU), sp = r.range(60, 120), vx0 = Math.cos(a) * sp, vy0 = Math.sin(a) * sp;
+ const [x, y] = fly(0, 0, vx0, vy0, age, 60, 2.5), [vx, vy] = flyV(vx0, vy0, age, 60, 2.5), q = age / life;
+ if (Math.abs(x) > 45 || Math.abs(y) > 45) return;
+ if (r.chance(0.4)) p.rect(Math.round(x), Math.round(y), 2, 2, q < 0.5 ? C[6] : C[4]);
+ else p.line(x, y, x - vx * 0.03, y - vy * 0.03, q < 0.4 ? WHITE : q < 0.7 ? C[5] : C[3]);
+ });
+
+ const L = 1 - seg(t, 0, 0.6);
+ if (!off) p.glow(0, 0, Math.max(8, R * 0.9), C[4], 0.3 * L * L);
+}
diff --git a/src/fx/scifi/energy-core.js b/src/fx/scifi/energy-core.js
new file mode 100644
index 0000000..11b9d26
--- /dev/null
+++ b/src/fx/scifi/energy-core.js
@@ -0,0 +1,81 @@
+import { PAL, ramp, at, seg, ease, rng, rand, wrap, TAU, WHITE } from "../../core/index.js";
+import { steps, jagged, brokenRing } from "./_lib.js";
+
+export const meta = {
+ name: "Energy core",
+ desc: "A reactor core held in a steel cage: a swirling ball of light swells on every beat and throws off a shock ring, two tilted rings orbit it, arcs jump to the cage.",
+ tags: ["scifi", "reactor", "core", "power", "machine", "prop", "loop"],
+ size: [60, 68],
+ origin: [30, 34],
+ duration: 1.6,
+ loop: true,
+ fps: 30,
+ bg: "dark",
+ options: { palette: PAL.gold, radius: 8, seed: 35 },
+};
+
+const METAL = ramp(["#121119", "#24222f", "#3a3748", "#575369", "#7d7891", "#a7a2b8"]);
+const BEAT = 0.8, RAIL = 16;
+
+// a tilted ring: points around it with their depth (positive is toward us)
+function ringPts(rx, ry, tilt, n = 96) {
+ const out = [], ct = Math.cos(tilt), st = Math.sin(tilt);
+ for (let i = 0; i < n; i++) {
+ const a = (i / n) * TAU, x = Math.cos(a) * rx, y = Math.sin(a) * ry;
+ out.push([x * ct - y * st, x * st + y * ct, Math.sin(a), a]);
+ }
+ return out;
+}
+
+export function draw(p, t, o) {
+ const C = steps(o.palette, 8), S = o.seed, ph = t / meta.duration, bt = wrap(t, BEAT), beat = Math.floor(t * 20);
+ const swell = 1 - ease.outCubic(seg(bt, 0, 0.45)), R = o.radius + 1.6 * swell;
+ const rings = [[17, 5, 0.38, 1], [16, 4.5, -0.42, -1]];
+
+ // the cage: rails, then caps top and bottom
+ for (const s of [-1, 1]) {
+ p.rect(s * RAIL - (s > 0 ? 0 : 1), -22, 2, 44, METAL[2]);
+ p.rect(s * RAIL + (s > 0 ? 1 : -1), -22, 1, 44, METAL[1]);
+ }
+
+ // far halves of the orbit rings
+ const orbit = (front) => rings.forEach(([rx, ry, tilt, dir], k) => {
+ for (const [x, y, z, a] of ringPts(rx, ry, tilt)) {
+ if (z > 0 !== front) continue;
+ const run = wrap(a / TAU - ph * dir * 2 - k * 0.5, 1), hot = run < 0.1 || (run > 0.5 && run < 0.56);
+ p.px(x, y, front ? (hot ? WHITE : C[5]) : hot ? C[5] : C[3]);
+ }
+ });
+ orbit(false);
+
+ // the core: a swirling ball, white at the heart
+ p.circle(0, 0, R, (d, a) => {
+ const sw = Math.sin(a * 3 + ph * TAU * 2 + d * 6) > 0.4 && d > 0.3 ? 0.18 : 0;
+ return at([C[4], C[5], C[6], C[7], WHITE], 1.05 - d * 0.95 + sw + swell * 0.15);
+ });
+
+ orbit(true);
+
+ // the shock ring thrown off on each beat
+ const sk = seg(bt, 0, 0.5);
+ if (sk < 1) brokenRing(p, 0, 0, R + 2 + 11 * ease.outCubic(sk), 1, { n: 8, gap: seg(sk, 0.3, 1), seed: S + Math.floor(t / BEAT), c: sk < 0.25 ? C[7] : sk < 0.55 ? C[6] : C[4] });
+
+ // arcs leaping from the core to the cage now and then
+ if (rand(S, beat, 1) < 0.35) {
+ const r = rng(S, beat, 2), s = r.sign(), y = r.range(-12, 12);
+ const pts = jagged(r, s * (R - 1), y * 0.4, s * (RAIL - 1), y, { step: 3, amp: 1.6 });
+ p.polyline(pts, beat % 2 ? C[6] : WHITE);
+ p.px(s * (RAIL - 1), y, WHITE);
+ }
+
+ // caps with status lights that flash on the beat
+ for (const s of [-1, 1]) {
+ const y0 = s < 0 ? -28 : 22;
+ p.poly(s < 0 ? [[-12, y0], [12, y0], [9, y0 + 6], [-9, y0 + 6]] : [[-9, y0], [9, y0], [12, y0 + 6], [-12, y0 + 6]], (x, y) =>
+ (s < 0 ? y < y0 + 2 : y < y0 + 1) ? METAL[4] : x < -3 ? METAL[3] : METAL[2]);
+ for (const x of [-6, 0, 6]) p.px(x, y0 + 3, swell > 0.5 ? C[7] : C[3]);
+ }
+
+ p.glow(0, 0, 30, C[4], 0.3 + 0.25 * swell);
+ p.glow(0, 0, 11, C[6], 0.35 + 0.2 * swell);
+}
diff --git a/src/fx/scifi/force-field.js b/src/fx/scifi/force-field.js
new file mode 100644
index 0000000..85e46b7
--- /dev/null
+++ b/src/fx/scifi/force-field.js
@@ -0,0 +1,96 @@
+import { PAL, ramp, at, burst, fly, flyV, seg, clamp, rand, wrap, TAU, WHITE } from "../../core/index.js";
+import { steps, hexCell } from "./_lib.js";
+
+export const meta = {
+ name: "Force field",
+ desc: "A hex-plated energy dome over the floor: faint cells shimmer, the rim glows, and a shot from the right strikes it in a white flare that ripples across the plates.",
+ tags: ["scifi", "shield", "barrier", "defense", "hex", "ground", "loop"],
+ size: [88, 60],
+ origin: [44, 54],
+ duration: 2,
+ loop: true,
+ fps: 30,
+ bg: "ground",
+ options: { palette: PAL.electric, width: 36, height: 34, cell: 5, seed: 25 },
+};
+
+const SHOT = ramp(["#a8301a", "#ff8a2a", "#ffd27a", "#ffffff"]);
+const HIT = 0.55; // when the shot lands, each loop
+
+// longitude/latitude on the dome, as arc lengths, so the hex plates keep their size as the surface turns away
+function surf(nx, ny, R) {
+ const nz = Math.sqrt(Math.max(0, 1 - nx * nx - ny * ny));
+ return [Math.atan2(nx, nz) * R, Math.atan2(-ny, Math.sqrt(nx * nx + nz * nz)) * R];
+}
+
+export function draw(p, t, o) {
+ const C = steps(o.palette, 7), S = o.seed, RX = o.width, RY = o.height, D = meta.duration, ph = t / D;
+ const R = (RX + RY) / 2, hitN = [0.74, -0.5], [hu, hv] = surf(hitN[0], hitN[1], R);
+ const hx = hitN[0] * RX, hy = hitN[1] * RY, age = t - HIT;
+ const ripple = age > 0 && age < 0.9 ? age : -1;
+
+ p.shade(-RX - 1, -RY - 1, RX + 1, 0, (x, y, out) => {
+ const nx = x / RX, ny = y / RY, d = Math.sqrt(nx * nx + ny * ny);
+ if (d > 1) return;
+ if (d > 0.955) {
+ // the rim: brightest along the top, a slow shimmer running round it
+ const a = Math.atan2(ny, nx), sh = Math.sin(a * 5 + ph * TAU * 2);
+ out.c = sh > 0.6 ? C[6] : ny < -0.5 ? C[5] : C[4];
+ out.k = 0.25;
+ return;
+ }
+ const [u, v] = surf(nx, ny, R), [q, r, e] = hexCell(u, v, o.cell);
+ // how lit this plate is: a little toward the rim (the dome turns away), twinkles, and the ripple
+ let I = 0.12 + 0.45 * d * d * d;
+ const tw = wrap(t - rand(S, q, r) * D, D);
+ if (rand(S, q, r, 1) < 0.18 && tw < 0.18) I += 0.45 * (1 - tw / 0.18);
+ let fill = 0;
+ if (ripple >= 0) {
+ const s = Math.hypot(u - hu, v - hv), front = 4 + ripple * 62, k = 1 - ripple / 0.9;
+ const band = Math.exp(-(((s - front) / 3.5) ** 2));
+ I += band * 1.1 * k;
+ fill = band * k;
+ if (ripple < 0.07 && s < 6) (I += 1), (fill = 1.2);
+ }
+ if (e > 0.8) {
+ if (I < 0.2) return;
+ out.c = at([C[2], C[3], C[4], C[5], C[6], WHITE], (I - 0.2) * 1.2);
+ out.k = 0.1 + 0.25 * clamp(I - 0.3);
+ return;
+ }
+ if (fill > 0.45) out.c = fill > 1 ? WHITE : fill > 0.75 ? C[4] : C[3];
+ out.l = C[3];
+ out.k = 0.07 + 0.12 * d * d + 0.3 * fill;
+ });
+
+ // where the dome meets the floor
+ for (let i = 0; i < 60; i++) {
+ const a = (i / 60) * TAU, x = Math.cos(a) * RX, y = Math.sin(a) * 3.5;
+ if (y < 0) continue;
+ p.px(x, y, Math.abs(Math.cos(a)) > 0.9 ? C[5] : C[4]);
+ }
+ p.glow(0, 0, RX, C[3], 0.2);
+
+ // the shot: a hot bolt from the right, gone in a flare where it lands, sparks glancing off
+ const sk = seg(t, HIT - 0.12, HIT);
+ if (sk > 0 && sk < 1) {
+ const sx = hx + (36 - hx) * (1 - sk), sy = hy - 5 * (1 - sk);
+ p.line(sx, sy, Math.min(43, sx + 7), sy - 1, SHOT[1]);
+ p.line(sx, sy, sx + 3, sy, SHOT[2]);
+ p.px(sx, sy, WHITE);
+ p.glow(sx, sy, 8, SHOT[1], 0.4);
+ }
+ if (age >= 0 && age < 0.1) {
+ p.circle(hx, hy, 3.5 - age * 20, WHITE);
+ p.glow(hx, hy, 20, C[5], 0.5 * (1 - age / 0.1));
+ }
+ burst(8, S + 3, (r) => {
+ const life = r.range(0.2, 0.4);
+ if (age < 0 || age > life) return;
+ const a = r.range(-1.6, 0.4), sp = r.range(40, 90), vx0 = Math.cos(a) * sp, vy0 = Math.sin(a) * sp;
+ const [x, y] = fly(hx + 1, hy, vx0, vy0, age, 200, 2), [vx, vy] = flyV(vx0, vy0, age, 200, 2), q = age / life;
+ if (x > 43 || y > 0) return;
+ p.line(x, y, x - vx * 0.03, y - vy * 0.03, q < 0.4 ? SHOT[3] : q < 0.7 ? SHOT[2] : SHOT[1]);
+ });
+ if (ripple >= 0) p.glow(hx, hy, 30, C[4], 0.3 * (1 - ripple / 0.9));
+}
diff --git a/src/fx/scifi/glitch.js b/src/fx/scifi/glitch.js
new file mode 100644
index 0000000..bb5dc0a
--- /dev/null
+++ b/src/fx/scifi/glitch.js
@@ -0,0 +1,75 @@
+import { PAL, ramp, rand, rng, WHITE } from "../../core/index.js";
+import { steps } from "./_lib.js";
+
+export const meta = {
+ name: "Glitch",
+ desc: "A body breaking up like a bad signal: red and cyan ghosts split off it, bands of it tear sideways, junk blocks flicker round it in bursts.",
+ tags: ["scifi", "glitch", "digital", "hack", "status", "debuff", "loop"],
+ size: [48, 44],
+ origin: [24, 38],
+ duration: 1.6,
+ loop: true,
+ fps: 30,
+ bg: "ground",
+ actor: true,
+ options: { palette: PAL.cyber, seed: 28 },
+};
+
+const SPLIT = ramp(["#2a0820", "#8a1048", "#ff2a6d", "#ff9ab8"]);
+// bursts of glitching: [start, end] in seconds; quiet in between
+const BURSTS = [[0.12, 0.42], [0.86, 1.02], [1.3, 1.37]];
+const FPS = 30;
+
+function state(t, S) {
+ const f = Math.floor(t * FPS), b = BURSTS.some(([a, z]) => t >= a && t < z);
+ return { f, burst: b, hard: b && rand(S, f, 1) < 0.6 };
+}
+
+// the ghosts: the silhouette in red to one side and cyan to the other, peeking out from behind the body
+export function drawBack(p, t, o) {
+ const C = steps(o.palette, 8), A = o.actor, S = o.seed, { f, burst, hard } = state(t, S);
+ const sx = burst ? (hard ? 3 : 2) : rand(S, f, 2) < 0.3 ? 1 : 0;
+ if (!sx) return;
+ const dy = hard ? Math.round(rand(S, f, 3) * 2 - 1) : 0;
+ p.mask(A.mask, A.x - sx, A.y + dy, SPLIT[2]);
+ p.mask(A.mask, A.x + sx, A.y - dy, C[5]);
+}
+
+export function draw(p, t, o) {
+ const C = steps(o.palette, 8), A = o.actor, S = o.seed, { f, burst, hard } = state(t, S), m = A.mask;
+ if (!burst) {
+ // even quiet, a stray dead line flickers across now and then
+ if (rand(S, f, 9) < 0.12) {
+ const y = A.y + Math.floor(rand(S, f, 10) * A.h);
+ p.line(A.x - 3, y, A.x + A.w + 2, y, C[2]);
+ }
+ return;
+ }
+ const r = rng(S, f);
+ // tears: bands of the body slide sideways; what was there shows as dead signal
+ const bands = hard ? 3 : 1;
+ for (let b = 0; b < bands; b++) {
+ const my0 = r.int(0, m.h - 3), h = r.int(1, hard ? 4 : 2), dx = r.sign() * r.int(2, hard ? 6 : 3);
+ for (let my = my0; my < Math.min(m.h, my0 + h); my++) {
+ const y = A.y + my, row = [];
+ for (let mx = -8; mx < m.w + 8; mx++) row.push(p.get(A.x + mx, y));
+ for (let mx = -8; mx < m.w + 8; mx++) {
+ const sm = mx - dx, inSrc = sm >= 0 && sm < m.w && m.data[my * m.w + sm], inDst = mx >= 0 && mx < m.w && m.data[my * m.w + mx];
+ const src = row[sm + 8];
+ if (inSrc) p.px(A.x + mx, y, src || (b % 2 ? C[5] : SPLIT[2]));
+ else if (inDst) p.px(A.x + mx, y, (mx + my) % 3 ? C[0] : C[2]);
+ }
+ }
+ }
+ // junk blocks and stuck pixels round the body
+ const nb = hard ? 5 : 2;
+ for (let i = 0; i < nb; i++) {
+ const x = Math.round(r.range(-16, 12)), y = Math.round(r.range(-24, -1)), w = r.int(2, 8), h = r.int(1, 2);
+ const c = r.pick([C[5], C[6], SPLIT[2], SPLIT[3], WHITE, C[1]]);
+ p.rect(x, y, w, h, c);
+ }
+ // a scanline of noise across the whole frame
+ const ny = Math.round(r.range(-22, -2));
+ for (let x = -22; x < 22; x++) if (rand(S, f, x) < 0.5) p.px(x, ny, rand(S, f, x, 1) < 0.5 ? C[3] : C[1]);
+ p.glow(A.chest[0], A.chest[1], 18, C[4], 0.2);
+}
diff --git a/src/fx/scifi/hologram.js b/src/fx/scifi/hologram.js
new file mode 100644
index 0000000..7258d8b
--- /dev/null
+++ b/src/fx/scifi/hologram.js
@@ -0,0 +1,88 @@
+import { ramp, cycle, rand, TAU, WHITE } from "../../core/index.js";
+import { steps } from "./_lib.js";
+
+export const meta = {
+ name: "Hologram",
+ desc: "A floor projector throws a cone of light; in it a wireframe cube turns, cut by scanlines, a bright sweep running down it, glitching now and then.",
+ tags: ["scifi", "hologram", "tech", "prop", "ground", "loop"],
+ size: [48, 64],
+ origin: [24, 60],
+ duration: 2.4,
+ loop: true,
+ fps: 30,
+ bg: "ground",
+ options: { palette: ["#061224", "#0c2a4e", "#154e86", "#2484c0", "#4cbce8", "#9ae6ff", "#e6fbff"], size: 7, seed: 21 },
+};
+
+const METAL = ramp(["#121119", "#24222f", "#3a3748", "#575369", "#7d7891"]);
+const CY = -34; // the cube's center
+const EDGES = [[0, 1], [1, 3], [3, 2], [2, 0], [4, 5], [5, 7], [7, 6], [6, 4], [0, 4], [1, 5], [2, 6], [3, 7]];
+
+// the cube turned by `ang` about the vertical and tipped toward us by `tilt`; [x, y, depth] per corner
+function cube(ang, tilt, s) {
+ const ca = Math.cos(ang), sa = Math.sin(ang), ct = Math.cos(tilt), st = Math.sin(tilt);
+ const out = [];
+ for (let i = 0; i < 8; i++) {
+ const x = (i & 1 ? 1 : -1) * s, y = (i & 2 ? 1 : -1) * s, z = (i & 4 ? 1 : -1) * s;
+ const x1 = x * ca + z * sa, z1 = -x * sa + z * ca;
+ out.push([x1, y * ct - z1 * st, y * st + z1 * ct]);
+ }
+ return out;
+}
+
+export function draw(p, t, o) {
+ const C = steps(o.palette, 7), S = o.seed, D = meta.duration, ph = t / D, fi = Math.floor(t * 30);
+
+ // the cone of light, soft (light only), with dotted edges
+ p.shade(-14, -48, 14, -4, (x, y, out) => {
+ const v = (-4 - y) / 44, half = 2 + v * 12;
+ if (Math.abs(x) > half) return;
+ out.l = C[3];
+ out.k = 0.18 * (1 - v * 0.6) * (1 - Math.abs(x) / half * 0.5);
+ });
+ for (const s of [-1, 1]) p.line(s * 2, -5, s * 9, -27, C[2]);
+
+ // glitch: on a few frames the whole picture jumps sideways, or its top half tears off
+ const g = rand(S, fi, 1), jump = g < 0.06 ? 2 : g > 0.97 ? -2 : 0, tear = rand(S, fi, 2) < 0.05;
+ const dim = rand(S, fi, 3) < 0.04;
+ const dx = (y) => jump + (tear && y < CY ? 3 : 0);
+
+ // the base plate the image stands on: a ring with a bright dash running round it
+ for (let i = 0; i < 40; i++) {
+ const a = (i / 40) * TAU, x = Math.cos(a) * 12, y = CY + 15 + Math.sin(a) * 3;
+ const run = (((i / 40 - ph * 2) % 1) + 1) % 1;
+ p.px(x + dx(y), y, run < 0.08 ? WHITE : run < 0.2 ? C[5] : C[3]);
+ }
+
+ // the cube: tumbling slowly; back edges faint, front edges bright with every third row dimmed (scanlines),
+ // and a bright sweep line running down it
+ const V = cube(ph * Math.PI + 0.5, 0.5 + 0.22 * Math.sin(ph * TAU), o.size), sweep = CY - 14 + ((ph * 3) % 1) * 30;
+ const order = EDGES.map(([a, b]) => [a, b, V[a][2] + V[b][2]]).sort((A, B) => A[2] - B[2]);
+ for (const [a, b, z] of order) {
+ const [x0, y0] = V[a], [x1, y1] = V[b];
+ const front = z > -0.5;
+ p.line(x0 + dx(CY + y0), CY + y0, x1 + dx(CY + y1), CY + y1, (u) => {
+ const y = CY + y0 + (y1 - y0) * u;
+ if (!front) return C[2];
+ if (Math.abs(y - sweep) < 1) return WHITE;
+ return dim || Math.floor(y) % 3 === 0 ? C[3] : C[5];
+ });
+ }
+ for (const [x, y, z] of V) if (z > 0) p.px(x + dx(CY + y), CY + y, dim ? C[4] : WHITE);
+ p.glow(0, CY, 22, C[4], dim ? 0.12 : 0.25);
+
+ // motes drifting up the cone
+ cycle(t, D, 8, S + 4, (r) => r.range(0.8, 1.4), (age, life, r) => {
+ const k = age / life, y = -6 - k * 40, x = r.range(-1, 1) * (2 + (-6 - y) * 0.27);
+ p.px(x, y, k < 0.5 ? C[5] : C[4]);
+ });
+
+ // the projector: a squat dark puck with a glowing lens and two status lights
+ p.ellipse(0, -2, 9, 3, (d, a) => (Math.sin(a) < 0 ? (d > 0.8 ? METAL[3] : METAL[2]) : METAL[1]));
+ p.rect(-9, -2, 19, 2, METAL[1]);
+ p.ellipse(0, -3, 3.5, 1.2, C[5]);
+ p.px(0, -3, WHITE);
+ p.px(-6, -1, (fi >> 3) % 2 ? C[5] : C[2]);
+ p.px(6, -1, METAL[4]);
+ p.glow(0, -4, 10, C[5], 0.4);
+}
diff --git a/src/fx/scifi/jetpack.js b/src/fx/scifi/jetpack.js
new file mode 100644
index 0000000..b2487f8
--- /dev/null
+++ b/src/fx/scifi/jetpack.js
@@ -0,0 +1,65 @@
+import { PAL, RAMP, ramp, at, cycle, rand, clamp, loopNoise, tileFbm, WHITE } from "../../core/index.js";
+import { steps } from "./_lib.js";
+
+export const meta = {
+ name: "Jetpack",
+ desc: "Twin thrusters blast straight down: white-hot cores with flickering shock diamonds inside ragged orange flames, smoke billowing out below.",
+ tags: ["scifi", "jetpack", "thrust", "rocket", "fire", "smoke", "flight", "loop"],
+ size: [48, 76],
+ origin: [24, 10],
+ duration: 1,
+ loop: true,
+ fps: 30,
+ bg: "dark",
+ options: { palette: PAL.fire, length: 22, gap: 5, seed: 30 },
+};
+
+const METAL = ramp(["#15141c", "#2b2936", "#47445a", "#6c6884", "#9a96b0"]);
+
+export function draw(p, t, o) {
+ const F = steps(o.palette, 8), SM = RAMP.smoke, S = o.seed, D = meta.duration, ph = t / D, fi = Math.floor(t * 30) % 30;
+ const G = o.gap;
+
+ // smoke first, so the flames sit over it: puffs shed off the flame tips, spreading and cooling as they sink
+ cycle(t, D, 20, S, (r) => r.range(0.55, 0.85), (age, life, r, i) => {
+ const k = age / life, side = i % 2 ? 1 : -1;
+ const x = side * G + side * r.range(-0.3, 1) * age * 18, y = o.length * 0.7 + age * r.range(34, 46);
+ const rad = (1.6 + 3.6 * Math.sqrt(k)) * (k < 0.75 ? 1 : 1 - (k - 0.75) / 0.25) + 0.3;
+ if (Math.abs(x) + rad > 23) return;
+ // lit from the flames above: lighter on top, darker below, the whole puff darkening as it cools
+ p.circle(x, y, rad, (d, a) => {
+ const v = 0.85 - k * 0.65 - Math.sin(a) * d * 0.3;
+ return k < 0.12 && d < 0.5 ? F[3] : at(SM.slice(1, 6), v);
+ });
+ });
+
+ for (const s of [-1, 1]) {
+ const cx = s * G, L = o.length * (0.9 + 0.1 * loopNoise(ph, 1.2, S + s)) + (rand(S, fi, s) - 0.5) * 2;
+ const knots = rand(S, fi, s, 2) < 0.75;
+ // the flame: a narrow cone of heat torn up by noise that streams downward
+ p.shade(cx - 5, 0, cx + 5, L + 3, (x, y) => {
+ const v = y / L, w = 2.6 + 1.6 * Math.sin(Math.min(1, v * 3) * Math.PI * 0.5) - 3.6 * Math.max(0, v - 0.35);
+ if (w <= 0.2) return;
+ const dx = Math.abs(x - cx) / w, n = tileFbm((x - cx) * 0.45, y * 0.3 - ph * 12, 0, 12, S + s, 2);
+ const heat = (1 - dx * dx) * (1.15 - v * 0.9) + n * 0.35;
+ if (heat < 0.1) return;
+ // shock diamonds: bright knots down the core
+ if (knots && dx < 0.35 && v < 0.6 && Math.abs(((y - 3) % 5) - 2.5) < 0.8 && heat > 0.7) return WHITE;
+ return at(F.slice(2), clamp(heat * 0.95));
+ });
+ p.glow(cx, 4, 12, F[5], 0.4);
+ // the nozzle: a steel bell
+ p.poly([[cx - 2, -6], [cx + 2, -6], [cx + 3.2, 0], [cx - 3.2, 0]], (x) => (x < cx - 1 ? METAL[3] : x < cx + 1 ? METAL[2] : METAL[1]));
+ p.rect(cx - 3, -1, 7, 1, METAL[4]);
+ p.rect(cx - 2, -8, 5, 2, METAL[2]);
+ }
+ p.rect(-G + 2, -8, 2 * G - 3, 2, METAL[1]);
+
+ // embers spat out of the plume
+ cycle(t, D, 8, S + 5, (r) => r.range(0.25, 0.45), (age, life, r, i) => {
+ const k = age / life, cx = i % 2 ? G : -G, x = cx + r.range(-1, 1) * age * 50, y = 6 + age * r.range(70, 110);
+ if (Math.abs(x) > 23) return;
+ p.px(x, y, k < 0.4 ? F[6] : k < 0.75 ? F[4] : F[3]);
+ });
+ p.glow(0, 10, 30, F[4], 0.28 * (0.9 + 0.1 * loopNoise(ph, 2, S)));
+}
diff --git a/src/fx/scifi/laser-grid.js b/src/fx/scifi/laser-grid.js
new file mode 100644
index 0000000..fc9fa93
--- /dev/null
+++ b/src/fx/scifi/laser-grid.js
@@ -0,0 +1,74 @@
+import { ramp, cycle, TAU, WHITE } from "../../core/index.js";
+import { steps, zap } from "./_lib.js";
+
+export const meta = {
+ name: "Laser grid",
+ desc: "Security lasers between two posts: red beams slide up and down while two more sweep the floor from the post tops; drifting dust sparkles where it crosses them.",
+ tags: ["scifi", "laser", "security", "trap", "hazard", "ground", "loop"],
+ size: [80, 56],
+ origin: [40, 52],
+ duration: 2.4,
+ loop: true,
+ fps: 30,
+ bg: "ground",
+ options: { palette: ["#1a0408", "#4a0a12", "#8a1020", "#d01c2a", "#ff4a4a", "#ff9a90", "#ffe4e0", "#ffffff"], seed: 31 },
+};
+
+const METAL = ramp(["#121119", "#24222f", "#3a3748", "#575369", "#7d7891"]);
+const X = 31, TOP = -45;
+// the sliding beams: [middle height, swing, cycles per loop, phase]
+const SLIDERS = [[-12, 6, 1, 0], [-24, 9, 2, 1.7], [-35, 6, 1, 3.6]];
+
+export function draw(p, t, o) {
+ const C = steps(o.palette, 8), S = o.seed, ph = t / meta.duration;
+ const beams = [];
+ for (const [m, a, n, f] of SLIDERS) {
+ const y = Math.round(m + a * Math.sin(ph * TAU * n + f));
+ beams.push([-X + 1, y, X - 1, y]);
+ }
+ for (const s of [-1, 1]) {
+ const fx = -s * 6 + s * 20 * Math.sin(ph * TAU + (s > 0 ? 0 : 2.2));
+ beams.push([s * (X - 1), TOP + 2, fx, 0]);
+ }
+
+ // the beams: a hot core in a red halo, their light, and the spot where each one meets something
+ for (const [x0, y0, x1, y1] of beams) {
+ zap(p, [[x0, y0], [x1, y1]], C[6], C[3]);
+ p.glowLine(x0, y0, x1, y1, 5, C[4], 0.28);
+ }
+ for (const [x0, y0, x1, y1] of beams) {
+ p.px(x0, y0, WHITE);
+ p.light(x0, y0, C[5], 0.6);
+ if (y1 === 0) {
+ p.ellipse(x1, 0, 2.5, 1, C[5]);
+ p.px(x1, 0, WHITE);
+ p.glow(x1, -1, 9, C[4], 0.45);
+ }
+ }
+
+ // dust drifting through the room, only seen where a beam catches it
+ cycle(t, meta.duration, 26, S, (r) => r.range(1.6, 2.4), (age, life, r) => {
+ const x = r.range(-X + 2, X - 2) + Math.sin(age * r.range(0.8, 1.6) + r.next() * TAU) * 3;
+ const y = r.range(-44, -2) + age * r.range(2, 5);
+ for (const [x0, y0, x1, y1] of beams) {
+ const dx = x1 - x0, dy = y1 - y0, u = ((x - x0) * dx + (y - y0) * dy) / (dx * dx + dy * dy);
+ if (u < 0 || u > 1) continue;
+ const d = Math.hypot(x0 + dx * u - x, y0 + dy * u - y);
+ if (d < 2.2) {
+ p.px(x, y, d < 1.2 ? WHITE : C[5]);
+ p.light(x, y, C[5], 0.5);
+ break;
+ }
+ }
+ });
+
+ // the posts, with a lit rail on their inner faces
+ for (const s of [-1, 1]) {
+ p.rect(s > 0 ? X : -X - 2, TOP - 2, 3, -TOP + 2, METAL[2]);
+ p.rect(s > 0 ? X + 2 : -X - 2, TOP - 2, 1, -TOP + 2, METAL[1]);
+ p.rect(s > 0 ? X : -X, TOP, 1, -TOP - 2, C[2]);
+ p.rect(s > 0 ? X - 1 : -X - 3, TOP - 3, 5, 2, METAL[3]);
+ p.rect(s > 0 ? X - 1 : -X - 3, -2, 5, 2, METAL[1]);
+ p.px(s > 0 ? X + 1 : -X - 1, TOP - 3, METAL[4]);
+ }
+}
diff --git a/src/fx/scifi/radar-ping.js b/src/fx/scifi/radar-ping.js
new file mode 100644
index 0000000..d3677d5
--- /dev/null
+++ b/src/fx/scifi/radar-ping.js
@@ -0,0 +1,59 @@
+import { rand, wrap, TAU, WHITE } from "../../core/index.js";
+import { steps } from "./_lib.js";
+
+export const meta = {
+ name: "Radar ping",
+ desc: "A round amber scope: the sweep turns, its afterglow trailing; blips flare as it passes and slowly die, each pinging out a small ring.",
+ tags: ["scifi", "radar", "sonar", "ui", "screen", "detect", "loop"],
+ size: [56, 56],
+ origin: [28, 28],
+ duration: 2.4,
+ loop: true,
+ fps: 30,
+ bg: "dark",
+ options: { palette: ["#140802", "#2e1604", "#4e2806", "#7c440c", "#b46a14", "#e89a2a", "#ffcc66", "#fff0c8"], radius: 25, blips: 5, seed: 32 },
+};
+
+export function draw(p, t, o) {
+ const C = steps(o.palette, 8), S = o.seed, R = o.radius, D = meta.duration, ph = t / D;
+ const th = ph * TAU - Math.PI / 2; // the sweep's angle: starts straight up, turns clockwise
+
+ // the scope: dark glass, range rings, crosshair, the trailing afterglow of the sweep
+ p.shade(-R, -R, R, R, (x, y) => {
+ const d = Math.hypot(x, y);
+ if (d > R) return;
+ if (d > R - 2) return d > R - 1 ? C[3] : C[2];
+ const behind = wrap(th - Math.atan2(y, x), TAU);
+ if (behind < 0.09) return d < 1.5 ? WHITE : C[6];
+ if (behind < 0.35) return C[4];
+ if (behind < 0.8) return C[2];
+ const ring = Math.abs(d - R * 0.33) < 0.5 || Math.abs(d - R * 0.66) < 0.5, cross = Math.abs(x) < 0.5 || Math.abs(y) < 0.5;
+ if (ring || cross) return behind < 1.6 ? C[2] : C[1];
+ return behind < 1.6 ? C[1] : C[0];
+ });
+ for (let i = 0; i < 12; i++) {
+ const a = (i / 12) * TAU;
+ p.px(Math.cos(a) * (R - 3), Math.sin(a) * (R - 3), C[3]);
+ }
+
+ // blips: lit as the sweep passes, then dying over most of a turn; one drifts as it's tracked
+ for (let i = 0; i < o.blips; i++) {
+ const a0 = rand(S, i, 1) * TAU, d0 = R * (0.2 + 0.68 * rand(S, i, 2)), drift = i === 0 ? 4 : 0;
+ const x = Math.round(Math.cos(a0) * d0 + drift * Math.cos(ph * TAU)), y = Math.round(Math.sin(a0) * d0 + drift * Math.sin(ph * TAU));
+ const age = (wrap(th - Math.atan2(y, x), TAU) / TAU) * D;
+ if (age < 0.07) {
+ p.rect(x - 1, y - 1, 3, 3, C[6]);
+ p.px(x, y, WHITE);
+ } else if (age < 0.6) p.rect(x, y, 2, 2, C[6]);
+ else if (age < 1.3) p.rect(x, y, 2, 2, C[5]);
+ else if (age < 1.9) p.px(x, y, C[4]);
+ else continue;
+ if (age > 0.03 && age < 0.3) p.ring(x + 0.5, y + 0.5, 2.5 + age * 14, 1, age < 0.15 ? C[6] : C[4]);
+ p.light(x, y, C[5], age < 0.1 ? 0.7 : 0.3 * (1 - age / 1.9));
+ }
+
+ // the sweep's tip and the scope's glow
+ p.glow(Math.cos(th) * R * 0.7, Math.sin(th) * R * 0.7, 14, C[5], 0.3);
+ p.glow(0, 0, R + 6, C[3], 0.15);
+ p.px(0, 0, WHITE);
+}
diff --git a/src/fx/scifi/scanner.js b/src/fx/scifi/scanner.js
new file mode 100644
index 0000000..c562092
--- /dev/null
+++ b/src/fx/scifi/scanner.js
@@ -0,0 +1,58 @@
+import { PAL, ease, rand, WHITE } from "../../core/index.js";
+import { steps } from "./_lib.js";
+
+export const meta = {
+ name: "Scanner",
+ desc: "A scan line sweeps down the body and back up inside blinking target brackets, lighting the slice it crosses and leaving a wireframe outline in its wake.",
+ tags: ["scifi", "scan", "tech", "status", "ui", "loop"],
+ size: [44, 40],
+ origin: [22, 34],
+ duration: 1.6,
+ loop: true,
+ fps: 30,
+ bg: "ground",
+ actor: true,
+ options: { palette: PAL.cyber, seed: 22 },
+};
+
+export function draw(p, t, o) {
+ const C = steps(o.palette, 8), A = o.actor, S = o.seed, D = meta.duration, ph = t / D, fi = Math.floor(t * 30);
+ const x0 = A.x - 4, x1 = A.x + A.w + 3, top = A.y - 2, bot = 0;
+ const m = A.mask, on = (mx, my) => mx >= 0 && my >= 0 && mx < m.w && my < m.h && m.data[my * m.w + mx];
+
+ // the sweep: down in the first half, back up in the second, easing at the turns
+ const down = ph < 0.5, k = ease.inOutSine(down ? ph * 2 : 2 - ph * 2), sy = Math.round(top + (bot - 1 - top) * k);
+
+ // the wake: the outline of what the line has passed this pass, cooling with distance behind it
+ p.outline(m, A.x, A.y, (mx, my) => {
+ const y = A.y + my, behind = down ? sy - y : y - sy;
+ return behind < 3 ? C[6] : behind < 8 ? C[5] : C[4];
+ }, (mx, my) => {
+ const y = A.y + my, behind = down ? sy - y : y - sy;
+ return behind >= 0 && behind < 16 ? 1 : 0;
+ });
+
+ // the slice under the line lights up, the row just behind it in a scanline stipple
+ for (let mx = 0; mx < m.w; mx++) {
+ const my = sy - A.y, back = down ? my - 1 : my + 1;
+ if (on(mx, my)) p.px(A.x + mx, sy, WHITE);
+ if (on(mx, back) && mx % 2 === 0) p.px(A.x + mx, A.y + back, C[6]);
+ }
+ // the line itself, past the body on both sides, and its light
+ for (let x = x0 + 1; x < x1; x++) if (!on(x - A.x, sy - A.y)) p.px(x, sy, C[5]);
+ p.px(x0, sy, WHITE), p.px(x1, sy, WHITE);
+ p.glowLine(x0, sy, x1, sy, 6, C[5], 0.35);
+
+ // target brackets that breathe on the beat
+ const b = (fi >> 3) % 2;
+ const L = 3, X0 = x0 - b, X1 = x1 + b, Y0 = top - 1 - b, Y1 = bot + 1 + b;
+ for (const [cx, cy, sx, sy2] of [[X0, Y0, 1, 1], [X1, Y0, -1, 1], [X0, Y1, 1, -1], [X1, Y1, -1, -1]]) {
+ p.line(cx, cy, cx + sx * L, cy, C[5]);
+ p.line(cx, cy, cx, cy + sy2 * L, C[5]);
+ }
+ // a readout ticking beside the brackets
+ for (let i = 0; i < 4; i++) {
+ const len = 1 + Math.floor(rand(S, i, fi >> 2) * 4);
+ p.line(X1 + 3, Y0 + 2 + i * 2, X1 + 2 + len, Y0 + 2 + i * 2, i === (fi >> 2) % 4 ? C[6] : C[3]);
+ }
+}
diff --git a/src/fx/scifi/teleporter-pad.js b/src/fx/scifi/teleporter-pad.js
new file mode 100644
index 0000000..d4b0f20
--- /dev/null
+++ b/src/fx/scifi/teleporter-pad.js
@@ -0,0 +1,68 @@
+import { PAL, ramp, cycle, wrap, TAU, WHITE } from "../../core/index.js";
+import { steps } from "./_lib.js";
+
+export const meta = {
+ name: "Teleporter pad",
+ desc: "A metal pad on the floor hums with light: rings lift off it one after another, shrinking and dimming as they rise through a soft column full of motes.",
+ tags: ["scifi", "teleport", "pad", "portal", "prop", "ground", "loop"],
+ size: [56, 72],
+ origin: [28, 66],
+ duration: 1.6,
+ loop: true,
+ fps: 30,
+ bg: "ground",
+ options: { palette: PAL.neon, radius: 16, seed: 26 },
+};
+
+const METAL = ramp(["#121119", "#24222f", "#3a3748", "#575369", "#7d7891", "#a7a2b8"]);
+const RINGS = 4, RISE = 1.2, TOP = -54;
+
+export function draw(p, t, o) {
+ const C = steps(o.palette, 8), S = o.seed, R = o.radius, D = meta.duration, ph = t / D;
+
+ // the column: soft light rising off the pad (light only)
+ p.shade(-R + 2, TOP - 4, R - 2, -3, (x, y, out) => {
+ const v = (-3 - y) / (-3 - TOP + 4), w = 1 - Math.abs(x) / (R - 2);
+ out.l = C[4];
+ out.k = 0.22 * w * w * (1 - v) * (0.9 + 0.1 * Math.sin(ph * TAU * 4));
+ });
+
+ // rings lifting off: the far half dim, the near half bright, cooling as they climb
+ const ring = (front) => {
+ for (let i = 0; i < RINGS; i++) {
+ const age = wrap(t - (i * D) / RINGS, D);
+ if (age > RISE) continue;
+ const k = age / RISE, y = -3 + (TOP + 3) * (1 - (1 - k) * (1 - k)), rx = R - 2 - 4 * k, ry = 3.5 - 1.2 * k;
+ const c = k < 0.15 ? WHITE : k < 0.4 ? C[6] : k < 0.7 ? C[5] : C[4];
+ for (let j = 0; j < 32; j++) {
+ const a0 = (j / 32) * TAU, a1 = ((j + 1) / 32) * TAU;
+ if (Math.sin((a0 + a1) / 2) > 0 !== front) continue;
+ p.line(Math.cos(a0) * rx, y + Math.sin(a0) * ry, Math.cos(a1) * rx, y + Math.sin(a1) * ry, front ? c : k < 0.4 ? C[4] : C[3]);
+ }
+ if (front) p.glow(0, y, rx + 4, C[4], 0.12 * (1 - k));
+ }
+ };
+ ring(false);
+
+ // the pad: a dark plinth, a steel rim, a glowing face with a pulse running outward, a hot emitter
+ p.ellipse(0, -1, R + 2, 5, (d, a) => (Math.sin(a) > 0.2 ? METAL[1] : METAL[2]));
+ p.rect(-R - 2, -1, 2 * R + 5, 2, METAL[1]);
+ p.ellipse(0, -2.5, R, 4, (d, a) => {
+ if (d > 0.82) return Math.sin(a) < -0.3 ? METAL[4] : METAL[3];
+ const pulse = wrap(d - ph * 4, 1);
+ return pulse < 0.12 ? C[6] : d > 0.62 ? C[3] : pulse < 0.3 ? C[5] : C[4];
+ });
+ p.ellipse(0, -2.5, 3.5, 1, WHITE);
+ for (const x of [-R + 3, R - 3]) p.px(x, 0, (Math.floor(t * 5) % 2) ? C[6] : C[3]);
+
+ ring(true);
+
+ // motes drifting up the column
+ cycle(t, D, 10, S, (r) => r.range(0.6, 1.1), (age, life, r) => {
+ const k = age / life, x = r.range(-R + 5, R - 5) * (1 - k * 0.4), y = -4 - age * r.range(30, 50);
+ p.px(x, y, k < 0.4 ? WHITE : k < 0.75 ? C[6] : C[4]);
+ });
+
+ p.glow(0, -3, R + 8, C[4], 0.35);
+ p.glow(0, -3, 6, C[6], 0.3);
+}
diff --git a/src/fx/scifi/tractor-beam.js b/src/fx/scifi/tractor-beam.js
new file mode 100644
index 0000000..bbed12f
--- /dev/null
+++ b/src/fx/scifi/tractor-beam.js
@@ -0,0 +1,70 @@
+import { ramp, at, cycle, ease, TAU, WHITE } from "../../core/index.js";
+import { steps } from "./_lib.js";
+
+export const meta = {
+ name: "Tractor beam",
+ desc: "A hovering emitter fans a beam down to the floor; rungs of light climb it and loose rocks and grit tumble upward into the lens.",
+ tags: ["scifi", "beam", "ufo", "abduct", "lift", "ground", "loop"],
+ size: [64, 84],
+ origin: [32, 79],
+ duration: 2,
+ loop: true,
+ fps: 30,
+ bg: "ground",
+ options: { palette: ["#04160e", "#0a2e1c", "#125232", "#1e8048", "#3cb862", "#86eaa0", "#dcffe4"], height: 70, seed: 27 },
+};
+
+const HULL = ramp(["#101018", "#1f1e2b", "#33313f", "#4c4a5c", "#706d84", "#9c99b0"]);
+const ROCK = ramp(["#34352c", "#575645", "#7f7b62"]);
+const ROCKS = [[".##", "###", "##."], ["##.", "###", ".#."], [".#.", "###", ".##"]];
+
+export function draw(p, t, o) {
+ const C = steps(o.palette, 7), S = o.seed, H = o.height, D = meta.duration, ph = t / D;
+ const top = -H + 4, hw = (y) => 6 + 14 * ((y - top) / -top); // the beam's half width at height y
+
+ // the beam: soft light (light only) with a slow shimmer climbing it, hard edges
+ p.shade(-21, top, 21, 0, (x, y, out) => {
+ const w = hw(y);
+ if (Math.abs(x) > w) return;
+ out.l = C[4];
+ out.k = 0.1 + 0.1 * (1 - Math.abs(x) / w) + 0.06 * Math.sin((y / 11) * TAU + ph * TAU * 3);
+ });
+ for (const s of [-1, 1]) p.line(s * 6, top, s * 20, 0, C[3]);
+ // the lift: streaks of light running up the beam, faster as they near the lens
+ cycle(t, D, 16, S + 1, (r) => r.range(0.7, 1.1), (age, life, r) => {
+ const k = age / life, y = -2 - ease.inQuad(k) * (H - 10), x = r.range(-0.85, 0.85) * hw(y), L = 2 + 4 * k;
+ p.line(x, y, x, y + L, k < 0.3 ? C[3] : k < 0.7 ? C[4] : C[5]);
+ });
+
+ // debris: lifted off the floor, drawn in, tumbling faster as it nears the lens
+ cycle(t, D, 7, S, (r) => r.range(1.3, 1.9), (age, life, r, i) => {
+ const k = age / life, e = ease.inQuad(k), x0 = r.range(-15, 15);
+ const x = x0 * (1 - e * 0.85) + Math.sin(age * r.range(3, 6) + r.next() * TAU) * 1.5 * (1 - e);
+ const y = -1 - e * (H - 8);
+ const shape = ROCKS[(i + Math.floor(age * (3 + 9 * k))) % 3], small = i % 3 === 2;
+ if (small) p.rect(x, y, 2, 2, at(ROCK, 0.7));
+ else p.sprite(shape, { "#": at(ROCK, 0.4 + r.next() * 0.6) }, x - 1, y - 1);
+ p.px(x, y - 1, C[5]); // lit by the beam on its upper edge
+ if (k > 0.92) p.px(x, y, WHITE);
+ });
+
+ // where it meets the floor: a pool of light
+ for (let j = 0; j < 40; j++) {
+ const a = (j / 40) * TAU;
+ if (Math.sin(a) < 0 && j % 2) continue;
+ p.px(Math.cos(a) * 20, Math.sin(a) * 3, Math.sin(a) > 0 ? C[5] : C[3]);
+ }
+ p.glow(0, 0, 24, C[4], 0.25);
+
+ // the emitter: a dark hull with a ring of blinking lights over a glowing lens
+ const hy = -H;
+ p.ellipse(0, hy + 1, 17, 4.5, (d, a) => (Math.sin(a) < 0 ? (d > 0.75 ? HULL[4] : HULL[3]) : d > 0.7 ? HULL[1] : HULL[2]));
+ p.ellipse(0, hy - 2, 8, 3, (d, a) => (Math.sin(a) < -0.2 && d > 0.5 ? HULL[5] : HULL[3]));
+ for (let j = 0; j < 5; j++) {
+ const x = -12 + j * 6, on = (Math.floor(t * 10) + j) % 5 === 0;
+ p.px(x, hy + 2, on ? WHITE : C[3]);
+ if (on) p.light(x, hy + 2, C[5], 0.5);
+ }
+ p.ellipse(0, hy + 4, 6, 1.6, (d) => (d < 0.5 ? WHITE : C[5]));
+ p.glow(0, hy + 4, 14, C[5], 0.45);
+}
diff --git a/src/fx/scifi/warp-in.js b/src/fx/scifi/warp-in.js
new file mode 100644
index 0000000..49536ef
--- /dev/null
+++ b/src/fx/scifi/warp-in.js
@@ -0,0 +1,88 @@
+import { burst, seg, ease, rand, TAU, WHITE } from "../../core/index.js";
+import { steps, maskCells } from "./_lib.js";
+
+export const meta = {
+ name: "Warp in",
+ desc: "A column of light slams down and hums, rings running down it; it narrows to a sparkling silhouette that sets into the body from the head down.",
+ tags: ["scifi", "teleport", "warp", "spawn", "beam", "one-shot"],
+ size: [48, 84],
+ origin: [24, 78],
+ duration: 1.3,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ actor: true,
+ options: { palette: ["#0a1430", "#14306a", "#2060b0", "#3aa0e0", "#80dcff", "#d0f6ff", "#ffffff"], height: 76, seed: 23 },
+};
+
+const OPEN = 0.36, SHUT = 0.52; // the column holds full width until OPEN, gone by SHUT
+
+export function draw(p, t, o) {
+ const C = steps(o.palette, 7), S = o.seed, A = o.actor, H = o.height, beat = Math.floor(t * 20);
+
+ // the silhouette: sparkling light that sets into the body pixel by pixel, head first
+ if (t >= OPEN - 0.05) {
+ for (const [x, y, mx, my] of maskCells(A)) {
+ const set = 0.55 + 0.45 * (0.6 * (my / A.h) + 0.4 * rand(S, mx, my));
+ if (t >= set) continue;
+ const left = set - t, twinkle = rand(S, mx, my, beat) < 0.25;
+ p.px(x, y, left < 0.05 ? C[4] : left < 0.12 ? C[5] : twinkle ? C[4] : C[6]);
+ }
+ const ring = seg(t, 0.55, 1.05);
+ if (ring < 1) p.outline(A.mask, A.x, A.y, ring < 0.5 ? C[5] : C[4], (mx, my) => (rand(S, mx, my, 9) < 1 - ring ? 1 : 0));
+ }
+
+ // the column: full height from the first frame, white at the heart, humming, then narrowing away;
+ // rings run down it, their far side hidden behind it
+ const hw = t < OPEN ? 8 + (t < 0.05 ? 2 : rand(S, beat) * 1.2) : 8 * (1 - ease.inQuad(seg(t, OPEN, SHUT)));
+ const rings = [];
+ for (let i = 0; i < 3; i++) {
+ const k = seg(t, 0.04 + i * 0.1, 0.3 + i * 0.1);
+ if (k > 0 && k < 1) rings.push([-H + 6 + (H - 6) * ease.outCubic(k), k]);
+ }
+ const ring = (y, k, front) => {
+ for (let j = 0; j < 44; j++) {
+ const a = (j / 44) * TAU;
+ if (Math.sin(a) > 0 !== front) continue;
+ p.px(Math.cos(a) * (hw + 4), y + Math.sin(a) * 2.5, front ? (k < 0.5 ? WHITE : C[6]) : C[4]);
+ }
+ };
+ if (hw > 0.3) {
+ for (const [y, k] of rings) ring(y, k, false);
+ p.shade(-hw - 1, -H - 2, hw + 1, 0, (x, y, out) => {
+ const v = Math.abs(x) / hw;
+ if (v > 1) return;
+ out.c = t < 0.05 || v < 0.22 ? WHITE : v < 0.6 ? C[6] : v < 0.88 ? C[5] : C[4];
+ });
+ p.glowLine(0, -H + 10, 0, 0, 12, C[4], t < 0.05 ? 0.6 : 0.3);
+ for (const [y, k] of rings) ring(y, k, true);
+ // motes pouring down inside it
+ burst(10, S + beat, (r) => {
+ const x = r.range(-hw * 0.7, hw * 0.7), y = -H + r.range(0, H);
+ p.line(x, y, x, y + 3, C[4]);
+ });
+ }
+
+ // the floor: a white splash where the column lands, a ring spreading out, the light pooling
+ if (t < 0.06) p.ellipse(0, 0, 14, 3, WHITE);
+ const fr = seg(t, 0.02, 0.6);
+ if (fr > 0 && fr < 1) {
+ const rx = 9 + 14 * ease.outCubic(fr);
+ for (let i = 0; i < 48; i++) {
+ const a = (i / 48) * TAU;
+ if (fr > 0.6 && i % 3 === 0) continue;
+ p.px(Math.cos(a) * rx, Math.sin(a) * rx * 0.22, fr < 0.4 ? C[6] : C[5]);
+ }
+ }
+ p.glow(0, -2, 20, C[4], 0.4 * (1 - seg(t, 0.3, 0.9)));
+
+ // twinkles round the body as it sets
+ burst(7, S + 77, (r) => {
+ const born = r.range(0.5, 0.95), k = seg(t, born, born + 0.22);
+ if (k <= 0 || k >= 1) return;
+ const x = r.range(-9, 9), y = r.range(-21, -2) - k * 3, s = k < 0.5 ? 2 : 1;
+ p.line(x - s, y, x + s, y, C[5]);
+ p.line(x, y - s, x, y + s, C[5]);
+ p.px(x, y, WHITE);
+ });
+}
diff --git a/src/fx/scifi/warp-out.js b/src/fx/scifi/warp-out.js
new file mode 100644
index 0000000..946a143
--- /dev/null
+++ b/src/fx/scifi/warp-out.js
@@ -0,0 +1,90 @@
+import { burst, seg, ease, rand, stockActor, TAU, WHITE } from "../../core/index.js";
+import { steps, maskCells } from "./_lib.js";
+
+export const meta = {
+ name: "Warp out",
+ desc: "A body flares into a silhouette of light, comes apart into motes from the feet up, and they stream up a thin beam that snaps shut with a glint.",
+ tags: ["scifi", "teleport", "warp", "despawn", "beam", "one-shot"],
+ size: [48, 84],
+ origin: [24, 78],
+ duration: 1.2,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ options: { palette: ["#0a1430", "#14306a", "#2060b0", "#3aa0e0", "#80dcff", "#d0f6ff", "#ffffff"], height: 76, seed: 24 },
+};
+
+// the stand-in body this effect takes apart: the caller's actor if given, else the stock one
+let stock = null;
+const body = (o) => o.actor ?? (stock ??= stockActor());
+
+export function draw(p, t, o) {
+ const C = steps(o.palette, 7), S = o.seed, A = body(o), H = o.height, beat = Math.floor(t * 20);
+
+ // the beam the motes ride up: thin, brightening, then drawn up off the floor and pinched shut
+ const on = seg(t, 0.2, 0.3), lift = ease.inQuad(seg(t, 0.62, 0.8));
+ if (on > 0 && lift < 1) {
+ const hw = on < 0.5 ? 0.5 : 2.5, bottom = -lift * H;
+ p.shade(-hw - 0.5, -H - 2, hw + 0.5, bottom, (x, y, out) => {
+ const v = Math.abs(x) / hw;
+ if (v > 1) return;
+ out.c = on < 0.5 ? C[5] : v < 0.4 ? WHITE : C[5];
+ });
+ p.glowLine(0, -H, 0, bottom, 10, C[4], 0.35 * on);
+ }
+ // the body: a white flare, then shimmering light; each pixel breaks loose (feet first) and is pulled up
+ for (const [x, y, mx, my] of maskCells(A)) {
+ const go = 0.1 + 0.42 * (0.65 * (1 - my / A.h) + 0.35 * rand(S, mx, my));
+ if (t < go) {
+ const twinkle = rand(S, mx, my, beat) < 0.2;
+ p.px(x, y, t < 0.05 ? WHITE : go - t < 0.06 ? WHITE : twinkle ? C[4] : C[5]);
+ continue;
+ }
+ const age = t - go, life = 0.3 + 0.12 * rand(S, mx, my, 2);
+ if (age > life) continue;
+ const k = age / life, px = x * 1.4 * (1 - k), py = y - 18 * age - 520 * age * age;
+ if (py < -H) continue;
+ p.line(px, py, px, py + 1 + 4 * k, k < 0.25 ? WHITE : k < 0.6 ? C[4] : C[3]);
+ }
+ if (t < 0.12) p.outline(A.mask, A.x, A.y, t < 0.05 ? C[5] : C[4]);
+
+ // rings rising up the body as it goes
+ for (let i = 0; i < 2; i++) {
+ const k = seg(t, 0.06 + i * 0.12, 0.42 + i * 0.12);
+ if (k <= 0 || k >= 1) continue;
+ const y = -ease.inOutSine(k) * (A.h + 4), rx = 9 - 2 * k;
+ for (let j = 0; j < 36; j++) {
+ const a = (j / 36) * TAU;
+ p.px(Math.cos(a) * rx, y + Math.sin(a) * 2, Math.sin(a) > 0 ? (k < 0.6 ? C[6] : C[5]) : C[4]);
+ }
+ }
+
+ // the glint where it closes
+ const gl = seg(t, 0.78, 0.98);
+ if (gl > 0 && gl < 1) {
+ const s = Math.round(6 * Math.sin(Math.PI * gl));
+ p.line(-s, -H + 4, s, -H + 4, C[6]);
+ p.line(0, -H + 4 - Math.round(s / 2), 0, -H + 4 + Math.round(s / 2), C[6]);
+ p.px(0, -H + 4, WHITE);
+ p.glow(0, -H + 4, 12, C[5], 0.5 * Math.sin(Math.PI * gl));
+ }
+
+ // the floor ring where the body stood, fading
+ const fr = seg(t, 0, 0.7);
+ if (fr < 1) {
+ const rx = 8 + 6 * ease.outCubic(fr);
+ for (let j = 0; j < 40; j++) {
+ const a = (j / 40) * TAU;
+ if (fr > 0.5 && j % 2) continue;
+ p.px(Math.cos(a) * rx, Math.sin(a) * rx * 0.22, fr < 0.3 ? C[6] : C[4]);
+ }
+ }
+ p.glow(0, -10, 24, C[4], 0.4 * (1 - seg(t, 0.1, 0.8)));
+
+ // a few last motes drifting up after the beam is gone
+ burst(6, S + 5, (r) => {
+ const born = r.range(0.7, 0.85), age = t - born, life = r.range(0.25, 0.35);
+ if (age < 0 || age > life) return;
+ p.px(r.range(-6, 6), r.range(-30, -8) - age * 30, age / life < 0.5 ? C[5] : C[3]);
+ });
+}
diff --git a/src/fx/shadow/_lib.js b/src/fx/shadow/_lib.js
new file mode 100644
index 0000000..4268a2b
--- /dev/null
+++ b/src/fx/shadow/_lib.js
@@ -0,0 +1,57 @@
+// Shared bits for the shadow effects (files starting with _ are helpers, not effects).
+
+import { ramp } from "../../core/index.js";
+
+/** The palette option resampled to exactly n steps (dark to bright), so fixed indices work for any ramp length. */
+export function steps(list, n = 8) {
+ const r = ramp(list);
+ return Array.from({ length: n }, (_, i) => r[Math.round((i * (r.length - 1)) / (n - 1))]);
+}
+
+// Dark magic: near-black violet through purple to a pale orchid rim. Shadows lean blue, highlights lean pink,
+// so dark shapes keep a bright edge on a dark backdrop.
+export const UMBRA = ["#07040c", "#170b28", "#2c1049", "#481872", "#6e22a0", "#9a3acb", "#cc70ec", "#f6d2ff"];
+// Crimson for dooms and drains.
+export const CRIMSON = ["#0c0306", "#24060e", "#460a16", "#72101e", "#a61c26", "#d83434", "#ff6e58", "#ffc8b0"];
+// Spectral green for the restless dead.
+export const SPECTRAL = ["#03100c", "#082219", "#0e3a2a", "#165a3e", "#228654", "#3cb86c", "#86e69a", "#dcffe0"];
+
+// Skull shapes: # bone, e eye socket, n nose, t gap between teeth. Colors come from a function, so one shape
+// can be shaded, tinted or flashed.
+export const SKULL_11 = [
+ "...#####...",
+ ".#########.",
+ "###########",
+ "###########",
+ "##ee###ee##",
+ "#eee###eee#",
+ "#eee#n#eee#",
+ ".####n####.",
+ "..#######..",
+ "..#t#t#t#..",
+ "...#####...",
+];
+export const SKULL_7 = [
+ ".#####.",
+ "#######",
+ "#ee#ee#",
+ "#ee#ee#",
+ "###n###",
+ ".#####.",
+ ".#t#t#.",
+];
+
+/**
+ * Draw a shape from strings with a color function: fn(ch, mx, my, w, h) returns a color, or 0 to skip.
+ * "." is always empty. Top-left at (x, y); a is a dithered alpha (number or (mx, my) => a).
+ */
+export function shape(p, rows, x, y, fn, a = 1) {
+ const h = rows.length, w = rows[0].length;
+ for (let my = 0; my < h; my++)
+ for (let mx = 0; mx < w; mx++) {
+ const ch = rows[my][mx];
+ if (ch === ".") continue;
+ const c = fn(ch, mx, my, w, h);
+ if (c) p.dot(x + mx, y + my, c, typeof a === "function" ? a(mx, my) : a);
+ }
+}
diff --git a/src/fx/shadow/black-hole.js b/src/fx/shadow/black-hole.js
new file mode 100644
index 0000000..43a2cd0
--- /dev/null
+++ b/src/fx/shadow/black-hole.js
@@ -0,0 +1,87 @@
+import { cycle, tileNoise, ease, at, TAU } from "../../core/index.js";
+import { steps } from "./_lib.js";
+
+export const meta = {
+ name: "Black hole",
+ desc: "A tilted accretion disk spins around a black shadow, its far side lensed up over the top; debris spirals in and is gone.",
+ tags: ["shadow", "void", "space", "gravity", "black hole", "loop"],
+ size: [80, 44],
+ origin: [40, 22],
+ duration: 3,
+ loop: true,
+ fps: 30,
+ bg: "dark",
+ options: {
+ palette: ["#08050e", "#1a0c2c", "#34124e", "#5a1c7c", "#8a2ea6", "#c454c4", "#f496d8", "#fff2fa"],
+ radius: 32, count: 6, seed: 11,
+ },
+};
+
+const TILT = 0.22, RH = 7.5; // disk tilt (y squash) and the shadow's radius
+
+export function draw(p, t, o) {
+ const C = steps(o.palette), S = o.seed, D = meta.duration, ph = t / D, RO = o.radius, RI = RH + 3;
+ const HOT = C.slice(2); // dim outer gas .. white-hot inner edge
+
+ // the disk's brightness at radius r and disk angle th: hot inner edge, a dark lane, clumps that orbit
+ // (inner rings turn faster; every ring turns a whole number of times a loop)
+ const disk = (r, th) => {
+ const q = (r - RI) / (RO - RI), ring = q < 0.3 ? 0 : q < 0.62 ? 1 : 2;
+ const lane = Math.abs(q - 0.46) < 0.055 ? 0.2 : 0;
+ const u = (th / TAU + 1) * 12 - ph * 12 * (3 - ring);
+ const clump = tileNoise(u, ring * 5 + q * 2, 12, 0, S + ring);
+ const beam = 1 - 0.3 * Math.cos(th); // the side turning toward us is brighter
+ return Math.pow(1 - q, 1.6) * 0.98 * beam + clump * 0.14 - lane;
+ };
+ const diskPass = (front) => {
+ p.shade(-RO, -RO * TILT - 1, RO, RO * TILT + 1, (x, y) => {
+ if (y >= 0 !== front) return;
+ const dy = y / TILT, r = Math.hypot(x, dy);
+ if (r < RI || r > RO) return;
+ const v = disk(r, Math.atan2(dy, x)) * Math.min(1, (RO - r) / 3 + 0.35);
+ if (v < 0.17) return;
+ return at(HOT, v);
+ });
+ };
+
+ // debris: hot fragments on decaying orbits in the disk plane, each with a short tail; hidden behind the hole
+ const bits = [];
+ cycle(t, D, o.count, S + 5, (r) => r.range(1.5, 2.3), (age, life, r) => {
+ const r0 = r.range(RO * 0.8, RO + 3), a0 = r.range(0, TAU), spin = r.range(4, 6), lift = r.range(-3, 4);
+ const pos = (a) => {
+ const e = ease.inQuad(Math.max(0, a) / life), rad = r0 + (RH - r0) * e, th = a0 + e * spin;
+ return [Math.cos(th) * rad, Math.sin(th) * rad * TILT - (1 - e) * lift, Math.sin(th) < 0];
+ };
+ const [x, y, back] = pos(age), [x2, y2] = pos(age - 0.08);
+ bits.push({ x, y, x2, y2, back, k: age / life });
+ });
+ const bitPass = (back) => {
+ for (const b of bits) {
+ if (b.back !== back) continue;
+ p.line(b.x2, b.y2, b.x, b.y, (u) => (u > 0.7 ? (b.k > 0.5 ? C[7] : C[6]) : C[4]));
+ p.light(b.x, b.y, C[6], 0.35 * b.k);
+ }
+ };
+
+ diskPass(false);
+ bitPass(true);
+
+ // the far side of the disk, bent up over the shadow (and a thin image under it)
+ p.shade(-RH - 7, -RH - 7, RH + 7, RH + 4, (x, y) => {
+ const d = Math.hypot(x, y), a = Math.atan2(y, x), top = y < 0;
+ const w = top ? 3.6 - 2 * Math.abs(Math.cos(a)) ** 3 : 1.2;
+ if (d < RH + 1.2 || d > RH + 1.2 + w) return;
+ const v = disk(RI + ((d - RH - 1.2) / w) * 9, top ? -a : a) * (top ? 0.9 : 0.75);
+ return v < 0.15 ? undefined : at(HOT, v);
+ });
+ // the shadow and its photon ring
+ p.circle(0, 0, RH + 1, (d) => (d > 0.88 ? C[7] : C[0]));
+
+ bitPass(false);
+ diskPass(true);
+
+ const pulse = 0.9 + 0.1 * Math.sin(ph * TAU * 3);
+ p.glowRing(0, 0, RH + 2, 5, C[6], 0.3 * pulse);
+ p.glow(-10, 0, 30, C[5], 0.12 * pulse);
+ p.glow(0, 0, 42, C[4], 0.07);
+}
diff --git a/src/fx/shadow/curse.js b/src/fx/shadow/curse.js
new file mode 100644
index 0000000..dd5c97b
--- /dev/null
+++ b/src/fx/shadow/curse.js
@@ -0,0 +1,81 @@
+import { burst, seg, ease, clamp, rand, bump, TAU, WHITE } from "../../core/index.js";
+import { steps, UMBRA, SKULL_11, shape } from "./_lib.js";
+
+export const meta = {
+ name: "Curse",
+ desc: "Dark wisps gather over the head, a violet skull stamps in with a flash, eyes burning, the curse drips down over the target, then the skull crumbles.",
+ tags: ["shadow", "curse", "skull", "debuff", "hex", "one-shot"],
+ size: [48, 60],
+ origin: [24, 55],
+ duration: 1.5,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ actor: true,
+ options: { palette: UMBRA, seed: 10 },
+};
+
+const STAMP = 0.28; // the skull lands
+
+export function draw(p, t, o) {
+ const C = steps(o.palette), S = o.seed, a = o.actor;
+ const hx = a.head[0], hy = a.head[1] - 13; // the skull's center, over the head
+ const crumble = seg(t, 1.05, 1.4), bob = Math.round(Math.sin((t - STAMP) * 7) * 1.2);
+
+ // gathering: wisps spiral in to where the skull will be
+ burst(7, S, (r) => {
+ const a0 = r.range(0, TAU), r0 = r.range(14, 20), delay = r.range(0, 0.08), q = clamp((t - delay) / (STAMP - delay));
+ if (q <= 0 || q >= 1) return;
+ for (let j = 3; j >= 0; j--) {
+ const e = ease.inQuad(Math.max(0, q - j * 0.06)), ang = a0 + e * 2.4, rr = r0 * (1 - e);
+ const x = hx + Math.cos(ang) * rr, y = hy + Math.sin(ang) * rr * 0.8;
+ if (j === 0) p.px(x, y, C[7]);
+ else p.circle(x, y, 1.6 - j * 0.35, j === 1 ? C[5] : C[3]);
+ }
+ });
+
+ // the curse falls: drips of shadow slide down from the skull over the target
+ burst(8, S + 1, (r, i) => {
+ const born = STAMP + 0.08 + r.range(0, 0.3), age = t - born, life = r.range(0.45, 0.65);
+ if (age < 0 || age > life) return;
+ const k = age / life, side = i % 2 ? 1 : -1, x0 = hx + side * r.range(1, 5);
+ const y = hy + 4 + ease.inQuad(k) * (-hy - 2), x = x0 + side * Math.sin(k * Math.PI) * r.range(3, 6);
+ p.circle(x, y - 2, 1.2, C[3]);
+ p.circle(x, y, 1.4, k < 0.7 ? C[5] : C[3]);
+ p.px(x, y + 1, C[7]);
+ });
+ // the mark takes: the target's outline flickers violet a few times
+ const mark = bump(t, STAMP + 0.15, STAMP + 0.75);
+ if (mark > 0 && Math.sin(t * 50) > -0.2) p.outline(a.mask, a.x, a.y, mark > 0.5 ? C[6] : C[4]);
+
+ // the skull: a 2x white flash as it lands, then violet, bobbing, eyes burning, crumbling at the end
+ if (t >= STAMP - 0.02 && crumble < 1) {
+ const land = t < STAMP + 0.05;
+ const sx = Math.round(hx) - 5, sy = Math.round(hy) - 5 + (land ? 0 : bob) - Math.round(crumble * 4);
+ if (land) {
+ for (let my = 0; my < 11; my++)
+ for (let mx = 0; mx < 11; mx++) {
+ const ch = SKULL_11[my][mx];
+ if (ch !== ".") p.rect(sx - 5 + mx * 2, sy - 5 + my * 2, 2, 2, ch === "#" ? WHITE : C[6]);
+ }
+ } else {
+ const eye = 0.6 + 0.4 * Math.sin(t * 18);
+ shape(p, SKULL_11, sx, sy, (ch, mx, my) => {
+ if (rand(S, mx, my) < crumble * 1.1) return 0;
+ if (ch === "e") return my === 5 && (mx === 2 || mx === 8) ? (eye > 0.5 ? C[7] : C[6]) : C[0];
+ if (ch === "n" || ch === "t") return C[1];
+ const lit = mx + my;
+ return lit < 6 ? C[7] : lit < 11 ? C[6] : lit < 15 ? C[5] : C[4];
+ });
+ p.light(sx + 2, sy + 5, C[7], 0.5 * eye * (1 - crumble));
+ p.light(sx + 8, sy + 5, C[7], 0.5 * eye * (1 - crumble));
+ }
+ p.glow(hx, hy, 18, C[5], (land ? 0.6 : 0.25) * (1 - crumble));
+ }
+ // dust of the crumbling skull, falling and fading
+ burst(14, S + 2, (r) => {
+ const age = t - 1.05 - r.range(0, 0.12), life = r.range(0.2, 0.28);
+ if (age < 0 || age > life) return;
+ p.px(hx + r.range(-5, 5) + r.range(-8, 8) * age, hy + r.range(-5, 4) + 30 * age * age - 6 * age, age / life < 0.5 ? C[6] : C[4]);
+ });
+}
diff --git a/src/fx/shadow/dark-explosion.js b/src/fx/shadow/dark-explosion.js
new file mode 100644
index 0000000..e6fb2ea
--- /dev/null
+++ b/src/fx/shadow/dark-explosion.js
@@ -0,0 +1,110 @@
+import { burst, fly, flyV, seg, ease, clamp, star, tileNoise, TAU, WHITE } from "../../core/index.js";
+import { steps, UMBRA } from "./_lib.js";
+
+export const meta = {
+ name: "Dark explosion",
+ desc: "Motes are sucked in, then a black star of anti-light rips across a violet flash; a black sphere swells, sheds shards and smoke, and is gone.",
+ tags: ["shadow", "explosion", "void", "dark", "impact", "one-shot"],
+ size: [100, 100],
+ origin: [50, 50],
+ duration: 1.4,
+ loop: false,
+ fps: 30,
+ bg: "dark",
+ options: { palette: UMBRA, size: 1, seed: 6 },
+};
+
+const T0 = 0.16; // the moment it goes off
+
+export function draw(p, t, o) {
+ const C = steps(o.palette), S = o.seed, k = o.size, a = t - T0;
+
+ // anticipation: motes streak inward to a tightening core
+ if (t < T0) {
+ burst(16, S, (r) => {
+ const ang = r.range(0, TAU), r0 = r.range(26, 40) * k, delay = r.range(0, 0.05), q = clamp((t - delay) / (T0 - delay));
+ if (q <= 0) return;
+ const rr = r0 * (1 - ease.inQuad(q)), r2 = r0 * (1 - ease.inQuad(Math.max(0, q - 0.12)));
+ p.line(Math.cos(ang) * r2, Math.sin(ang) * r2, Math.cos(ang) * rr, Math.sin(ang) * rr, (u) => (u > 0.6 ? C[7] : C[5]));
+ });
+ const c = 1.5 + 2.5 * ease.inQuad(t / T0);
+ p.circle(0, 0, c + 1, C[6]);
+ p.circle(0, 0, c, C[0]);
+ p.glow(0, 0, 20 * k, C[5], 0.4 * (t / T0));
+ return;
+ }
+
+ // smoke left as the sphere breaks up: dark puffs lit violet from the top left, darkening as they die
+ const puffs = [];
+ burst(12, S + 1, (r) => {
+ const ang = r.range(0, TAU), born = 0.26 + r.range(0, 0.12), age = a - born, life = r.range(0.6, 0.85);
+ if (age < 0 || age > life) return;
+ const q = age / life, e = ease.outCubic(Math.min(1, age / 0.5)), dist = (r.range(7, 12) + r.range(6, 14) * e) * k;
+ const rr = r.range(4, 7.5) * k * (1 - ease.inQuad(q));
+ if (rr > 1.3) puffs.push({ x: Math.cos(ang) * dist, y: Math.sin(ang) * dist * 0.85 - age * age * 20, r: rr, q });
+ });
+ if (puffs.length) {
+ p.shade(-38 * k, -42 * k, 38 * k, 34 * k, (x, y) => {
+ let best = 0, lit = 0, q = 0;
+ for (const f of puffs) {
+ const dx = x - f.x, dy = y - f.y, d2 = (dx * dx + dy * dy) / (f.r * f.r);
+ if (d2 >= 1) continue;
+ const v = 1 - d2;
+ if (v > best) (best = v), (lit = (-dx - dy) / f.r), (q = f.q);
+ }
+ if (best < 0.06) return;
+ const tone = (best * 0.55 + lit * 0.5) * (1 - 0.55 * seg(q, 0.35, 1));
+ return tone > 0.85 ? C[5] : tone > 0.55 ? C[3] : tone > 0.3 ? C[2] : C[1];
+ });
+ }
+
+ // the flash: a violet halo with a white heart, hollowing out into the shockwave
+ const outer = (29 + 15 * ease.outCubic(seg(a, 0, 0.32)) + 3 * seg(a, 0.3, 0.5)) * k;
+ const inner = a < 0.05 ? 0 : (10 + 34 * ease.outQuart(seg(a, 0.05, 0.3))) * k;
+ if (a < 0.3 && outer - inner > 0.6) p.ring(0, 0, outer, outer - inner, (v) => (v > 0.72 ? C[7] : v > 0.36 ? C[6] : C[5]));
+ if (a < 0.1) p.circle(0, 0, (16 - 40 * Math.max(0, a - 0.04)) * k, (d) => (d > 0.85 ? C[7] : WHITE));
+ if (a > 0.1 && a < 0.5) p.ring(0, 0, outer, 1, a < 0.3 ? C[6] : a < 0.4 ? C[4] : C[3]);
+
+ // the black sphere: swells fast, lumpy, rimmed in violet, then shrinks away into the smoke
+ const grow = ease.outExpo(seg(a, 0.02, 0.28)), shrink = ease.inCubic(seg(a, 0.3, 0.62));
+ const R = (5 + 13 * grow) * (1 - shrink) * k;
+ // anti-light: a black star cut across the flash, its spikes pulled back into the sphere
+ const spikes = (34 - (34 - R) * ease.inQuad(seg(a, 0.06, 0.2))) * k;
+ if (spikes > R + 1) p.poly(star(0, 0, Math.max(5 * k, R * 0.85), spikes, 7, -0.2 + a * 0.8), C[0]);
+ if (R > 0.8) {
+ p.shade(-R - 2, -R - 2, R + 2, R + 2, (x, y) => {
+ const d = Math.hypot(x, y), ang = Math.atan2(y, x);
+ const edge = R + 1.4 * tileNoise((ang / TAU + 0.5) * 9, a * 6, 9, 0, S);
+ if (d > edge) return;
+ if (d > edge - 1.2) return C[7];
+ if (d > edge - 2.4) return C[5];
+ return d > edge - 3.4 ? C[2] : C[0];
+ });
+ }
+
+ // shards: chips of black glass tumbling out once the flash clears, one corner catching the light
+ burst(10, S + 2, (r) => {
+ const ang = r.range(0, TAU), sp = r.range(60, 120) * k, life = r.range(0.35, 0.6), age = a - 0.06 - r.range(0, 0.04);
+ if (age < 0 || age > life) return;
+ const [x, y] = fly(Math.cos(ang) * 16 * k, Math.sin(ang) * 16 * k, Math.cos(ang) * sp, Math.sin(ang) * sp, age, 70, 3.5);
+ const spin = Math.floor(age * r.range(14, 24)) % 4, big = r.next() < 0.5;
+ if (Math.abs(x) > 46 * k || Math.abs(y) > 46 * k) return;
+ p.rect(x, y, big ? 3 : 2, 2, C[1]);
+ p.px(x + (spin === 1 || spin === 2 ? (big ? 2 : 1) : 0), y + (spin > 1 ? 1 : 0), age / life < 0.5 ? C[7] : C[5]);
+ });
+ // sparks: violet streaks along their motion
+ burst(16, S + 3, (r) => {
+ const ang = r.range(0, TAU), sp = r.range(70, 125) * k, life = r.range(0.3, 0.6), age = a - 0.05;
+ if (age < 0 || age > life) return;
+ const vx0 = Math.cos(ang) * sp, vy0 = Math.sin(ang) * sp, [x, y] = fly(Math.cos(ang) * 14 * k, Math.sin(ang) * 14 * k, vx0, vy0, age, 80, 3), [vx, vy] = flyV(vx0, vy0, age, 80, 3);
+ const q = age / life;
+ if (Math.hypot(x, y) < R + 2 || Math.abs(x) > 46 * k || Math.abs(y) > 46 * k) return;
+ p.line(x, y, x - vx * 0.045, y - vy * 0.045, (u) => (u < 0.3 ? (q < 0.4 ? C[7] : C[6]) : C[5]));
+ p.light(x, y, C[6], 0.5 * (1 - q));
+ });
+
+ // light: a hard violet flash that lets go fast
+ const L = 1 - seg(a, 0, 0.45);
+ p.glow(0, 0, 50 * k, C[5], 0.5 * L * L);
+ if (a < 0.07) p.glow(0, 0, 22 * k, C[7], 0.45);
+}
diff --git a/src/fx/shadow/doom-mark.js b/src/fx/shadow/doom-mark.js
new file mode 100644
index 0000000..d58e9cd
--- /dev/null
+++ b/src/fx/shadow/doom-mark.js
@@ -0,0 +1,80 @@
+import { cycle, bump, seg, ease, fract, TAU } from "../../core/index.js";
+import { steps, CRIMSON } from "./_lib.js";
+
+export const meta = {
+ name: "Doom mark",
+ desc: "A crimson rune burns on the floor: a band of glyphs turning one way, a sigil the other, beating like a slow heart as embers rise.",
+ tags: ["shadow", "curse", "rune", "ground", "doom", "marker", "loop"],
+ size: [72, 40],
+ origin: [36, 26],
+ duration: 3,
+ loop: true,
+ fps: 30,
+ bg: "ground",
+ options: { palette: CRIMSON, radius: 26, seed: 2 },
+};
+
+const SQ = 0.4; // floor perspective: circles on the floor are squashed this much
+
+// approximate screen-space distance from (x, y) to an ellipse with radii (rx, ry): negative inside
+function edist(x, y, rx, ry) {
+ const e = Math.hypot(x / rx, y / ry), gx = x / (rx * rx), gy = y / (ry * ry), g = Math.hypot(gx, gy) / (e || 1);
+ return (e - 1) / (g || 1e-6);
+}
+// distance from (x, y) to the segment a-b
+function sdist(x, y, ax, ay, bx, by) {
+ const dx = bx - ax, dy = by - ay, u = Math.max(0, Math.min(1, ((x - ax) * dx + (y - ay) * dy) / (dx * dx + dy * dy)));
+ return Math.hypot(ax + dx * u - x, ay + dy * u - y);
+}
+
+export function draw(p, t, o) {
+ const C = steps(o.palette), S = o.seed, D = meta.duration, ph = t / D, R = o.radius, RB = R - 6, RS = R - 8;
+ // heartbeat: two quick beats, then a long rest
+ const beat = Math.max(bump(ph, 0, 0.07), 0.8 * bump(ph, 0.1, 0.17));
+ const hot = beat > 0.45, line = hot ? C[7] : C[6], mid = hot ? C[6] : C[5];
+ // the sigil: a triangle turning against the band, a third of a turn a loop (so it lands on itself)
+ const tri = [0, 1, 2].map((k) => {
+ const a = Math.PI / 2 - (ph * TAU) / 3 + (k * TAU) / 3;
+ return [Math.cos(a) * RS, Math.sin(a) * RS * SQ];
+ });
+ const wave = seg(ph, 0.02, 0.32), WR = R + 1 + 7 * ease.outCubic(wave);
+
+ p.shade(-WR - 1, -WR * SQ - 1, WR + 1, WR * SQ + 1, (x, y) => {
+ const d1 = edist(x, y, R, R * SQ);
+ // the ring thrown out by the first beat, cooling as it spreads
+ if (wave > 0 && wave < 1 && Math.abs(edist(x, y, WR, WR * SQ)) < 0.55) return wave < 0.3 ? C[6] : wave < 0.65 ? C[4] : C[3];
+ if (d1 > 0.6) return;
+ if (d1 > -0.6) return line;
+ const d2 = edist(x, y, RB, RB * SQ);
+ if (d2 > 0.55) {
+ // the rune band: glyph strokes on dark, 16 cells turning a quarter turn a loop (4 shapes repeat)
+ const a = Math.atan2(y / SQ, x), cell = (a / TAU) * 16 + ph * 4, i = ((Math.floor(cell) % 4) + 4) % 4, u = fract(cell);
+ const v = -d1 / (-d1 + d2); // 0 at the outer line, 1 at the inner
+ const stroke = i === 0 ? Math.abs(u - 0.5) < 0.12
+ : i === 1 ? Math.abs(u - 0.3) < 0.1 || (v > 0.4 && v < 0.65 && u > 0.3 && u < 0.75)
+ : i === 2 ? Math.abs(u - 0.5 - (v - 0.5) * 0.5) < 0.1
+ : Math.abs(u - 0.4) < 0.1 && v < 0.55;
+ return stroke ? mid : C[1];
+ }
+ if (d2 > -0.55) return mid;
+ // the sigil and the eye at its heart
+ for (let k = 0; k < 3; k++) {
+ const [ax, ay] = tri[k], [bx, by] = tri[(k + 1) % 3];
+ if (sdist(x, y, ax, ay, bx, by) < 0.6) return mid;
+ }
+ const e = Math.hypot(x / 4.5, y / 1.8);
+ if (e < 1) return e < 0.4 ? (hot ? C[7] : C[6]) : e < 0.75 ? C[4] : C[2];
+ });
+ p.px(0, 0, C[0]);
+
+ // embers rising off the rune
+ cycle(t, D, 14, S, (r) => r.range(0.8, 1.4), (age, life, r) => {
+ const k = age / life, a = r.range(0, TAU), x = Math.cos(a) * R * r.range(0.3, 1), y0 = Math.sin(a) * R * SQ;
+ const y = y0 - age * r.range(7, 11), sway = Math.sin(age * 6 + r.next() * 6) * 1.2;
+ p.px(x + sway, y, k < 0.4 ? C[7] : k < 0.75 ? C[6] : C[4]);
+ p.light(x + sway, y, C[5], 0.3 * (1 - k));
+ });
+
+ p.glow(0, -1, R + 6, C[5], 0.16 + 0.24 * beat);
+ p.glow(0, 0, 10, C[6], 0.2 + 0.3 * beat);
+}
diff --git a/src/fx/shadow/eclipse.js b/src/fx/shadow/eclipse.js
new file mode 100644
index 0000000..5602e9c
--- /dev/null
+++ b/src/fx/shadow/eclipse.js
@@ -0,0 +1,69 @@
+import { cycle, tileNoise, bump, clamp, TAU, WHITE } from "../../core/index.js";
+import { steps, CRIMSON } from "./_lib.js";
+
+export const meta = {
+ name: "Eclipse",
+ desc: "A black moon over a hidden sun: ragged corona streamers turn and breathe, a diamond bead burns on the rim, red flares loop up and fall back.",
+ tags: ["shadow", "eclipse", "sun", "moon", "sky", "omen", "loop"],
+ size: [72, 72],
+ origin: [36, 36],
+ duration: 3,
+ loop: true,
+ fps: 30,
+ bg: "sky",
+ options: {
+ palette: ["#0a0614", "#1e1236", "#3a2066", "#5c3496", "#8a58c4", "#b88ae4", "#e2c4f8", "#ffffff"],
+ radius: 12, seed: 4,
+ },
+};
+
+const BEAD = -0.75; // where the last sliver of sun shows (radians)
+
+export function draw(p, t, o) {
+ const C = steps(o.palette), F = steps(CRIMSON), S = o.seed, D = meta.duration, ph = t / D, R = o.radius;
+ const breathe = 1 + 0.08 * Math.sin(ph * TAU);
+ const W = R * 2.8;
+
+ // corona: streamers of light around the moon, shifting and breathing (the noise wraps once a loop)
+ const CORONA = [C[2], C[3], C[4], C[5], C[6], C[7]];
+ p.shade(-W, -W, W, W, (x, y) => {
+ const d = Math.hypot(x, y);
+ if (d < R || d > W) return;
+ const a = Math.atan2(y, x), u = (a / TAU + 0.5) * 28;
+ const n = 0.5 + 0.5 * (0.7 * tileNoise(u, ph * 2, 28, 2, S) + 0.3 * tileNoise(u * 2, 3 - ph * 3, 56, 3, S + 1));
+ const reach = R * (0.32 + 1.7 * n * n * n) * breathe;
+ const v = 1 - (d - R) / reach;
+ if (v < 0.05) return;
+ return CORONA[clamp(Math.floor(v * v * 6.4), 0, 5)];
+ });
+
+ // flares: loops of red that rise off the rim and fall back
+ cycle(t, D, 3, S + 3, (r) => r.range(1, 1.6), (age, life, r) => {
+ const k = age / life, a = r.range(0, TAU), h = bump(k, 0, 1) * r.range(5, 8), span = r.range(0.22, 0.34);
+ const pts = [];
+ for (let j = 0; j <= 8; j++) {
+ const s = j / 8, aa = a + (s - 0.5) * span * 2, rr = R + Math.sin(s * Math.PI) * h;
+ pts.push([Math.cos(aa) * rr, Math.sin(aa) * rr]);
+ }
+ p.polyline(pts, k < 0.6 ? F[7] : F[6]);
+ if (h > 2.5) p.polyline(pts.map(([x, y]) => [x * 0.95, y * 0.95]), F[5]);
+ p.light(pts[4][0], pts[4][1], F[6], 0.35 * bump(k, 0, 1));
+ });
+
+ // the moon: black, a hair-thin crescent of sun on the bead side
+ p.circle(0, 0, R, (d, a) => {
+ if (d < 0.9) return C[0];
+ const lit = Math.cos(a - BEAD);
+ return lit > 0.55 ? WHITE : lit > 0.2 ? C[6] : C[1];
+ });
+ // the diamond bead: a hot point with twinkling spikes
+ const bx = Math.cos(BEAD) * R, by = Math.sin(BEAD) * R, tw = 0.6 + 0.4 * Math.abs(Math.sin(ph * TAU * 3));
+ p.circle(bx, by, 1.6, WHITE);
+ const sp = Math.round(3 + 4 * tw);
+ p.line(bx - sp, by, bx + sp, by, (u) => (Math.abs(u - 0.5) < 0.2 ? WHITE : C[6]));
+ p.line(bx, by - sp, bx, by + sp, (u) => (Math.abs(u - 0.5) < 0.2 ? WHITE : C[6]));
+
+ p.glowRing(0, 0, R + 5, 7, C[5], 0.3 * breathe);
+ p.glow(bx + Math.cos(BEAD) * 2, by + Math.sin(BEAD) * 2, 9, C[7], 0.55 * tw);
+ p.glowRing(0, 0, R * 1.9, R, C[4], 0.1);
+}
diff --git a/src/fx/shadow/grasping-hands.js b/src/fx/shadow/grasping-hands.js
new file mode 100644
index 0000000..f7837fd
--- /dev/null
+++ b/src/fx/shadow/grasping-hands.js
@@ -0,0 +1,89 @@
+import { burst, cycle, seg, ease, clamp, TAU } from "../../core/index.js";
+import { steps, UMBRA } from "./_lib.js";
+
+export const meta = {
+ name: "Grasping hands",
+ desc: "Shadow arms burst from a black pool, fingers splayed, then clench like claws toward the middle, tremble, and are dragged back under.",
+ tags: ["shadow", "hands", "grab", "root", "ground", "dark", "one-shot"],
+ size: [84, 54],
+ origin: [42, 48],
+ duration: 1.8,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ options: { palette: UMBRA, height: 22, seed: 12 },
+};
+
+// one hand as segments [x0, y0, x1, y1, width] plus a palm, for an arm of length A leaning by `lean`,
+// with grip g (0 open fan .. 1 curled claw) and facing f (+1: fingers curl to the right)
+function hand(bx, by, A, lean, g, f) {
+ const segs = [], ca = Math.cos(lean - Math.PI / 2), sa = Math.sin(lean - Math.PI / 2);
+ const wx = bx + ca * A, wy = by + sa * A; // wrist
+ segs.push([bx, by + 2, (bx + wx) / 2, (by + 2 + wy) / 2, 6], [(bx + wx) / 2, (by + 2 + wy) / 2, wx, wy, 5]);
+ const px = wx + ca * 3, py = wy + sa * 3; // palm
+ const fingers = [[-0.5, 3.4, 2.8], [-0.17, 4.2, 3.2], [0.17, 4, 3], [0.5, 3.2, 2.6]];
+ for (const [spread, l1, l2] of fingers) {
+ const a1 = lean - Math.PI / 2 + spread * (1.25 - g) + f * g * 0.9, a2 = a1 + f * (0.25 + g * 1.5);
+ const rx = px + Math.cos(lean - Math.PI / 2 + spread * 1.4) * 2.6, ry = py + Math.sin(lean - Math.PI / 2 + spread * 1.4) * 2.6;
+ const kx = rx + Math.cos(a1) * l1, ky = ry + Math.sin(a1) * l1;
+ segs.push([rx, ry, kx, ky, 2.1], [kx, ky, kx + Math.cos(a2) * l2, ky + Math.sin(a2) * l2, 1.5]);
+ }
+ // thumb, curling the other way
+ const ta = lean - Math.PI / 2 - f * (1.1 - g * 0.9), tx = px - f * 2.2 * Math.cos(lean), ty = py + 1;
+ const kx = tx + Math.cos(ta) * 3, ky = ty + Math.sin(ta) * 3, ta2 = ta + f * g * 1.4;
+ segs.push([tx, ty, kx, ky, 2], [kx, ky, kx + Math.cos(ta2) * 2.4, ky + Math.sin(ta2) * 2.4, 1.5]);
+ return { segs, palm: [px, py], tips: segs.filter((_, i) => i > 1 && i % 2 === 1).map((s) => [s[2], s[3]]) };
+}
+
+export function draw(p, t, o) {
+ const C = steps(o.palette), S = o.seed;
+ const open = ease.outCubic(seg(t, 0, 0.14)), close = ease.inQuad(seg(t, 1.45, 1.8));
+ const poolR = 27 * open * (1 - close);
+
+ if (poolR > 0.8) {
+ p.ellipse(0, 0.5, poolR, poolR * 0.18 + 0.8, (d, a) => (d > 0.8 ? (Math.sin(a) < 0 ? C[6] : C[4]) : d > 0.55 ? C[1] : C[0]));
+ p.glow(0, -2, 30 * (1 - close), C[5], 0.28 * open * (1 - close));
+ }
+
+ // three hands, the middle one tallest; each rises, splays, clenches toward the middle, trembles, sinks
+ const hands = [];
+ burst(3, S, (r, i) => {
+ const side = i - 1, born = [0.1, 0.04, 0.16][i] + r.range(0, 0.04), sink = 1.08 + r.range(0, 0.12);
+ const rise = ease.outBack(seg(t, born, born + 0.28), 1.8), down = ease.inQuad(seg(t, sink, sink + 0.36));
+ if (rise <= 1e-3 || down >= 1) return;
+ const A = o.height * (i === 1 ? 1 : r.range(0.68, 0.8)), lean = side * 0.38 + r.range(-0.08, 0.08);
+ const clench = ease.outBack(seg(t, born + 0.42, born + 0.6), 2.2) - 0.25 * seg(t, born + 0.15, born + 0.38) * (1 - seg(t, born + 0.42, born + 0.5));
+ const shake = t > born + 0.6 && t < sink ? Math.sin(t * 70 + i * 2) * 0.35 : 0;
+ const f = side === 0 ? (r.next() < 0.5 ? -1 : 1) : -side;
+ const sunk = (A + 14) * down;
+ hands.push(hand(side * 21 + r.range(-2, 2) + shake, sunk + (1 - rise) * (A + 16), A, lean, clamp(clench, -0.3, 1.15), f));
+ });
+ // stamp in passes so a hand reads as one shape: outline, lit upper left, black body; the floor clips them
+ const FLOOR = 1;
+ const capsule = (x0, y0, x1, y1, r, c) => {
+ const dx = x1 - x0, dy = y1 - y0, L2 = dx * dx + dy * dy || 1e-9;
+ p.shade(Math.min(x0, x1) - r, Math.min(y0, y1) - r, Math.max(x0, x1) + r, Math.min(FLOOR, Math.max(y0, y1) + r), (x, y) => {
+ if (y > FLOOR) return;
+ const u = clamp(((x - x0) * dx + (y - y0) * dy) / L2), ex = x0 + dx * u - x, ey = y0 + dy * u - y;
+ return ex * ex + ey * ey <= r * r ? c : undefined;
+ });
+ };
+ const pass = (dx, dy, grow, c) => {
+ for (const h of hands) {
+ capsule(h.palm[0] + dx, h.palm[1] + dy, h.palm[0] + dx, h.palm[1] + dy, 3.2 + grow, c);
+ for (const [x0, y0, x1, y1, w] of h.segs) capsule(x0 + dx, y0 + dy, x1 + dx, y1 + dy, w / 2 + grow, c);
+ }
+ };
+ pass(0, 0, 0.8, C[3]);
+ pass(-0.6, -0.5, 0, C[6]);
+ pass(0.45, 0.35, -0.05, C[1]);
+ for (const h of hands) for (const [x, y] of h.tips) if (y < FLOOR) p.px(x, y, C[7]);
+ for (const h of hands) if (h.palm[1] < 0) p.light(h.palm[0], h.palm[1], C[6], 0.3);
+
+ // motes rising off the pool while it's open
+ cycle(t, 1.8, 10, S + 2, (r) => r.range(0.5, 0.9), (age, life, r) => {
+ if (poolR < 5) return;
+ const k = age / life, x = r.range(-0.9, 0.9) * poolR, y = -age * r.range(18, 30);
+ p.px(x + Math.sin(age * 9 + r.next() * TAU), y, k < 0.5 ? C[6] : C[5]);
+ });
+}
diff --git a/src/fx/shadow/hex-sigil.js b/src/fx/shadow/hex-sigil.js
new file mode 100644
index 0000000..da98259
--- /dev/null
+++ b/src/fx/shadow/hex-sigil.js
@@ -0,0 +1,133 @@
+import { burst, seg, ease, clamp, rand, bump, TAU, WHITE } from "../../core/index.js";
+import { steps, shape } from "./_lib.js";
+
+export const meta = {
+ name: "Hex sigil",
+ desc: "A burning pen traces a circle and a six-point star in the air, glyphs pop in at its points, it holds, flares white, then crumbles into motes.",
+ tags: ["shadow", "curse", "hex", "sigil", "rune", "cast", "one-shot"],
+ size: [72, 72],
+ origin: [36, 36],
+ duration: 1.9,
+ loop: false,
+ fps: 30,
+ bg: "dark",
+ options: {
+ palette: ["#0e0412", "#24082e", "#3e0c4c", "#62146e", "#8c1e8e", "#c032b0", "#ec6ad2", "#ffd0f4"],
+ radius: 22, seed: 13,
+ },
+};
+
+const GLYPHS = [["#.#", "###", "..#"], [".#.", "#.#", "##."], ["##.", ".##", "#.."], ["#..", "###", ".#."], [".##", "#..", "##."], ["#.#", ".#.", "###"]];
+const FLARE = 1.12; // the moment it flares
+
+// the strokes, in drawing order: [points, start, duration]
+function strokes(R) {
+ const out = [], circle = [];
+ for (let i = 0; i <= 48; i++) {
+ const a = -Math.PI / 2 + (i / 48) * TAU;
+ circle.push([Math.cos(a) * R, Math.sin(a) * R]);
+ }
+ out.push([circle, 0.04, 0.32]);
+ const pt = (k) => [Math.cos(-Math.PI / 2 + (k * TAU) / 6) * (R - 1), Math.sin(-Math.PI / 2 + (k * TAU) / 6) * (R - 1)];
+ out.push([[pt(0), pt(2), pt(4), pt(0)], 0.4, 0.2]);
+ out.push([[pt(3), pt(5), pt(1), pt(3)], 0.62, 0.2]);
+ const inner = [];
+ for (let i = 0; i <= 24; i++) {
+ const a = Math.PI / 2 + (i / 24) * TAU;
+ inner.push([Math.cos(a) * R * 0.32, Math.sin(a) * R * 0.32]);
+ }
+ out.push([inner, 0.84, 0.14]);
+ return out;
+}
+
+// a polyline cut at fraction f of its length; returns [points, tip]
+function partial(pts, f) {
+ let total = 0;
+ const lens = [];
+ for (let i = 1; i < pts.length; i++) total += lens[i - 1] = Math.hypot(pts[i][0] - pts[i - 1][0], pts[i][1] - pts[i - 1][1]);
+ let left = total * clamp(f);
+ const out = [pts[0]];
+ for (let i = 1; i < pts.length; i++) {
+ if (left >= lens[i - 1]) (out.push(pts[i]), (left -= lens[i - 1]));
+ else {
+ const u = left / lens[i - 1];
+ out.push([pts[i - 1][0] + (pts[i][0] - pts[i - 1][0]) * u, pts[i - 1][1] + (pts[i][1] - pts[i - 1][1]) * u]);
+ break;
+ }
+ }
+ return [out, out[out.length - 1]];
+}
+
+export function draw(p, t, o) {
+ const C = steps(o.palette), S = o.seed, R = o.radius;
+ const flare = bump(t, FLARE - 0.02, FLARE + 0.12), cool = seg(t, FLARE + 0.1, 1.7), crumble = seg(t, 1.4, 1.75);
+ const grow = 1 + 0.08 * ease.outCubic(seg(t, FLARE, FLARE + 0.2));
+ const hold = t > 0.98 && t < FLARE ? 0.5 + 0.5 * Math.sin((t - 0.98) * 40) : 0;
+ // after the flare the lines cool down the ramp, then the last of them crumbles away
+ const lineC = flare > 0.3 ? WHITE : cool > 0 ? [C[7], C[6], C[5], C[4], C[3]][Math.min(4, Math.floor(cool * 5))] : hold > 0.5 ? C[7] : C[6];
+
+ // the strokes, drawn as far as the pen has got; once it flares, pixels drop out at random
+ let pen = null, si = 0;
+ for (const [pts0, start, dur] of strokes(R)) {
+ const f = seg(t, start, start + dur);
+ si++;
+ if (f <= 0) continue;
+ const pts = pts0.map(([x, y]) => [x * grow, y * grow]);
+ const [cut, tip] = partial(pts, ease.inOutSine(f));
+ if (f < 1) pen = tip;
+ let idx = 0;
+ for (let i = 1; i < cut.length; i++) {
+ const [x0, y0] = cut[i - 1], [x1, y1] = cut[i], n = Math.max(1, Math.round(Math.hypot(x1 - x0, y1 - y0)));
+ const base = idx;
+ idx += n;
+ p.line(x0, y0, x1, y1, lineC, (u) => (rand(S, si, base + Math.round(u * n)) < crumble * 1.05 ? 0 : 1));
+ if (flare > 0.3) p.line(x0 * 1.03, y0 * 1.03, x1 * 1.03, y1 * 1.03, C[6]);
+ if (i % 3 === 1 || n > 6) p.glowLine(x0, y0, x1, y1, 4, C[6], 0.12 * (1 - cool) + 0.2 * flare);
+ }
+ }
+ // the pen: a white-hot point dropping sparks
+ if (pen) {
+ p.circle(pen[0], pen[1], 1.2, WHITE);
+ p.glow(pen[0], pen[1], 10, C[6], 0.55);
+ }
+ burst(30, S + 1, (r) => {
+ const born = r.range(0.04, 0.98), age = t - born, life = r.range(0.2, 0.35);
+ if (age < 0 || age > life) return;
+ // where the pen was when this spark fell
+ let at = null, si2 = 0;
+ for (const [pts, start, dur] of strokes(R)) {
+ si2++;
+ if (born >= start && born < start + dur) at = partial(pts, ease.inOutSine(seg(born, start, start + dur)))[1];
+ }
+ if (!at) return;
+ p.px(at[0] + r.range(-6, 6) * age, at[1] + 40 * age * age + r.range(-4, 6) * age, age / life < 0.5 ? C[7] : C[5]);
+ });
+
+ // glyphs pop into the pockets between the star's points, one after another
+ for (let k = 0; k < 6; k++) {
+ const born = 0.86 + k * 0.035, g = seg(t, born, born + 0.08);
+ if (g <= 0 || crumble >= 0.5) continue;
+ const a = -Math.PI / 2 + ((k + 0.5) * TAU) / 6, gx = Math.cos(a) * R * 0.8 * grow, gy = Math.sin(a) * R * 0.8 * grow;
+ shape(p, GLYPHS[k], Math.round(gx) - 1, Math.round(gy) - 1, () => (g < 0.5 || flare > 0.3 ? WHITE : lineC));
+ }
+
+ // the flare: a white heart and a ring thrown out
+ if (flare > 0) {
+ p.circle(0, 0, 3 + 4 * flare, (d) => (d < 0.6 ? WHITE : C[7]));
+ p.glow(0, 0, 40, C[6], 0.5 * flare);
+ }
+ const ring = seg(t, FLARE, FLARE + 0.3);
+ if (ring > 0 && ring < 1) p.ring(0, 0, R * grow + 3 + 6 * ease.outCubic(ring), 1, ring < 0.4 ? C[7] : ring < 0.7 ? C[6] : C[4]);
+
+ // motes: the crumbling sigil drifts up
+ burst(26, S + 2, (r) => {
+ const a = r.range(0, TAU), rr = r.next() < 0.6 ? R : r.range(0, R), born = FLARE + 0.15 + r.range(0, 0.4), age = t - born, life = Math.min(r.range(0.3, 0.5), 1.88 - born);
+ if (age < 0 || age > life) return;
+ const x = Math.cos(a) * rr * grow + Math.sin(age * 9 + r.next() * 6) * 1.5, y = Math.sin(a) * rr * grow - age * r.range(18, 32);
+ p.px(x, y, age / life < 0.4 ? C[7] : age / life < 0.75 ? C[6] : C[4]);
+ });
+
+ // light: builds while it's drawn, spikes at the flare, falls away as it crumbles
+ const build = seg(t, 0, 1) * (1 - cool);
+ p.glow(0, 0, R + 14, C[5], (0.12 + 0.18 * build + 0.2 * hold) * (1 - crumble));
+}
diff --git a/src/fx/shadow/life-steal.js b/src/fx/shadow/life-steal.js
new file mode 100644
index 0000000..f3ee26a
--- /dev/null
+++ b/src/fx/shadow/life-steal.js
@@ -0,0 +1,96 @@
+import { burst, seg, ease, clamp, lerp, TAU, WHITE } from "../../core/index.js";
+import { steps, CRIMSON } from "./_lib.js";
+
+export const meta = {
+ name: "Life steal",
+ desc: "A wound bursts open on a target to the right; blood-red orbs pop out, hang a beat, then whip back to the caster, who swells with each one.",
+ tags: ["shadow", "drain", "blood", "vampire", "heal", "directional", "one-shot"],
+ size: [88, 44],
+ origin: [16, 24],
+ duration: 1.5,
+ loop: false,
+ fps: 30,
+ bg: "dark",
+ options: { palette: CRIMSON, count: 6, distance: 58, seed: 8 },
+};
+
+// each orb's timeline: born, thrown out, hangs, flies home, lands
+function plan(S, i, n) {
+ const g = { born: 0, out: 0.16, hang: 0, fly: 0 };
+ burst(1, S * 31 + i, (r) => {
+ g.born = 0.04 + i * (0.36 / n) + r.range(0, 0.03);
+ g.hang = r.range(0.05, 0.12);
+ g.fly = r.range(0.3, 0.4);
+ });
+ g.land = g.born + g.out + g.hang + g.fly;
+ return g;
+}
+
+export function draw(p, t, o) {
+ const C = steps(o.palette), S = o.seed, TX = o.distance, n = o.count;
+
+ // the wound: spikes of red snap out of the target and pull back
+ const w = seg(t, 0, 0.2);
+ if (w > 0 && w < 1) {
+ const reach = 3 + 7 * Math.sin(Math.PI * Math.sqrt(w));
+ for (let k = 0; k < 6; k++) {
+ const a = (k / 6) * TAU + 0.3, r0 = 1.5 + 4 * w;
+ const x0 = TX + Math.cos(a) * r0, y0 = Math.sin(a) * r0, x1 = TX + Math.cos(a) * reach, y1 = Math.sin(a) * reach;
+ p.beam(x0, y0, x1, y1, 2.2 * (1 - w) + 1, C[5]);
+ p.line(x0, y0, x1, y1, w < 0.4 ? C[7] : C[6]);
+ }
+ if (w < 0.25) p.circle(TX, 0, 2.5, WHITE);
+ p.glow(TX, 0, 16, C[5], 0.5 * (1 - w));
+ }
+
+ // orbs: thrown out of the wound, hang, then pulled home along a curve, faster and faster
+ let fed = 0, flash = 0;
+ burst(n, S, (r, i) => {
+ const g = plan(S, i, n), hx = TX + r.range(-6, 10), hy = (i % 2 ? -1 : 1) * r.range(5, 14), bend = r.range(-16, 16);
+ const pos = (tt) => {
+ const a = tt - g.born;
+ if (a < g.out) {
+ const e = ease.outCubic(clamp(a / g.out));
+ return [lerp(TX, hx, e), lerp(0, hy, e)];
+ }
+ const e = ease.inQuad(clamp((a - g.out - g.hang) / g.fly)), cx = hx / 2, cy = hy / 2 + bend;
+ return [(1 - e) * (1 - e) * hx + 2 * (1 - e) * e * cx, (1 - e) * (1 - e) * hy + 2 * (1 - e) * e * cy];
+ };
+ if (t >= g.land) {
+ fed += 1;
+ flash = Math.max(flash, 1 - seg(t, g.land, g.land + 0.12));
+ // sparks kicked out where it lands
+ burst(3, S + 50 + i, (q) => {
+ const a = t - g.land, life = q.range(0.15, 0.25);
+ if (a > life) return;
+ const ang = q.range(-2.2, 2.2) + Math.PI, sp = q.range(40, 70);
+ p.px(Math.cos(ang) * sp * a, Math.sin(ang) * sp * a, a / life < 0.5 ? C[7] : C[5]);
+ });
+ return;
+ }
+ if (t < g.born) return;
+ const [x, y] = pos(t), homing = t - g.born > g.out + g.hang;
+ // a tapered streak behind it on the way home
+ if (homing) {
+ let [ax, ay] = [x, y];
+ for (let j = 1; j <= 4; j++) {
+ const [bx, by] = pos(t - j * 0.025);
+ p.beam(ax, ay, bx, by, 4 - j * 0.75, j < 2 ? C[5] : j < 3 ? C[4] : C[3]);
+ [ax, ay] = [bx, by];
+ }
+ }
+ const s = t - g.born < 0.05 ? 1.2 : 2.3;
+ p.circle(x, y, s, (d) => (d < 0.35 ? C[7] : d < 0.75 ? C[6] : C[4]));
+ p.px(x - 1, y - 1, WHITE);
+ p.light(x, y, C[5], 0.5);
+ p.glow(x, y, 7, C[5], 0.25);
+ });
+
+ // the caster swells with each orb that lands, holds, then the stolen life sinks in
+ const done = plan(S, n - 1, n).land, sink = ease.inCubic(seg(t, done + 0.12, 1.45));
+ if (fed > 0 && sink < 1) {
+ const R = (2 + Math.min(fed, 4) * 0.9 + flash * 1.5) * (1 - sink);
+ p.circle(0, 0, R, (d) => (flash > 0.5 || d < 0.4 ? C[7] : d < 0.78 ? C[6] : C[4]));
+ p.glow(0, 0, 14 + fed * 2, C[5], (0.3 + flash * 0.3) * (1 - sink));
+ }
+}
diff --git a/src/fx/shadow/necro-skulls.js b/src/fx/shadow/necro-skulls.js
new file mode 100644
index 0000000..83e3f8d
--- /dev/null
+++ b/src/fx/shadow/necro-skulls.js
@@ -0,0 +1,76 @@
+import { cycle, rng, TAU } from "../../core/index.js";
+import { steps, SPECTRAL, SKULL_7, shape } from "./_lib.js";
+
+export const meta = {
+ name: "Necro skulls",
+ desc: "Ghostly green skulls circle a point on a tilted orbit, trailing smoke, jaws chattering, dimming as they swing behind.",
+ tags: ["shadow", "necromancy", "skull", "ghost", "undead", "orbit", "loop"],
+ size: [60, 46],
+ origin: [30, 26],
+ duration: 2.4,
+ loop: true,
+ fps: 30,
+ bg: "dark",
+ options: { palette: SPECTRAL, count: 5, radius: 18, seed: 7 },
+};
+
+export function draw(p, t, o) {
+ const C = steps(o.palette), S = o.seed, D = meta.duration, ph = t / D, n = o.count, RX = o.radius, RY = RX * 0.32;
+
+ // where skull i is at loop phase q: one turn a loop, its own wobble in radius and height
+ const where = (i, q) => {
+ const r = rng(S, i), th = q * TAU + (i * TAU) / n + r.range(-0.25, 0.25);
+ const rad = 1 + 0.12 * Math.sin(q * TAU * 2 + r.range(0, TAU));
+ const bob = Math.sin(q * TAU * 3 + r.range(0, TAU)) * 1.6;
+ return [Math.cos(th) * RX * rad, Math.sin(th) * RY * rad + bob, Math.sin(th)];
+ };
+
+ const skulls = [];
+ for (let i = 0; i < n; i++) skulls.push({ i, pos: where(i, ph) });
+ skulls.sort((a, b) => a.pos[2] - b.pos[2]); // far first
+
+ const core = () => {
+ // a cold flame at the center the skulls are bound to
+ const fl = 0.8 + 0.2 * Math.sin(ph * TAU * 6);
+ p.ellipse(0, -1, 2.2 * fl, 3.4 * fl, (d) => (d < 0.45 ? C[7] : d < 0.8 ? C[6] : C[5]));
+ p.glow(0, -1, 26, C[5], 0.22 * fl);
+ p.glow(0, -1, 8, C[6], 0.35 * fl);
+ };
+
+ let coreDone = false;
+ for (const { i, pos } of skulls) {
+ const [x, y, depth] = pos, far = depth < 0;
+ if (!far && !coreDone) (core(), (coreDone = true));
+ // smoke tail: the path it just came along, thinning and darkening
+ for (let j = 6; j >= 1; j--) {
+ const [tx, ty] = where(i, ph - j * 0.018);
+ const rr = 2.8 - j * 0.38, c = j > 4 ? C[2] : j > 2 ? C[3] : C[4];
+ p.circle(tx, ty + 0.5, rr, far ? C[Math.max(1, (j > 4 ? 2 : j > 2 ? 3 : 4) - 1)] : c);
+ }
+ // the skull: pale bone, darker when it swings behind, jaw chattering
+ const chat = Math.sin(ph * TAU * 8 + i * 2.1) > 0.3 ? 1 : 0;
+ const top = far ? C[5] : C[7], body = far ? C[4] : C[6], dark = far ? C[2] : C[4];
+ const sx = Math.round(x) - 3, sy = Math.round(y) - 4;
+ shape(p, SKULL_7, sx, sy, (ch, mx, my) => {
+ if (ch === "e") return C[0];
+ if (ch === "n" || ch === "t") return dark;
+ if (my >= 5) return null;
+ return my === 0 || (my === 1 && mx < 4) ? top : body;
+ });
+ // jaw: drops a pixel when it chatters
+ shape(p, SKULL_7.slice(5), sx, sy + 5 + chat, (ch) => (ch === "t" ? C[0] : ch === "#" ? (far ? C[4] : C[5]) : 0));
+ // eyes burn
+ if (!far || depth > -0.5) {
+ p.px(sx + 1, sy + 3, C[7]), p.px(sx + 4, sy + 3, C[7]);
+ p.light(x, y - 1, C[6], far ? 0.15 : 0.3);
+ }
+ }
+ if (!coreDone) core();
+
+ // motes rising off the circle
+ cycle(t, D, 10, S + 3, (r) => r.range(0.7, 1.2), (age, life, r) => {
+ const k = age / life, a = r.range(0, TAU), x = Math.cos(a) * RX * r.range(0.4, 1.1);
+ const y = Math.sin(a) * RY - age * r.range(10, 17) + Math.sin(age * 7 + r.next() * 6);
+ p.px(x, y, k < 0.5 ? C[6] : C[4]);
+ });
+}
diff --git a/src/fx/shadow/shadow-flames.js b/src/fx/shadow/shadow-flames.js
new file mode 100644
index 0000000..cf40d35
--- /dev/null
+++ b/src/fx/shadow/shadow-flames.js
@@ -0,0 +1,59 @@
+import { cycle, tileFbm, loopNoise, clamp, TAU } from "../../core/index.js";
+import { steps, UMBRA } from "./_lib.js";
+
+export const meta = {
+ name: "Shadow flames",
+ desc: "Inside-out fire: a black heart floating in violet flame that burns pale at the edges and tips, tongues tearing off, embers rising.",
+ tags: ["shadow", "fire", "flame", "dark", "hazard", "ground", "loop"],
+ size: [44, 56],
+ origin: [22, 50],
+ duration: 1.2,
+ loop: true,
+ fps: 30,
+ bg: "ground",
+ options: { palette: UMBRA, height: 26, seed: 3 },
+};
+
+export function draw(p, t, o) {
+ const C = steps(o.palette), S = o.seed, D = meta.duration, ph = t / D;
+ const H = o.height * (0.9 + 0.1 * loopNoise(ph, 1.3, S));
+ // heat to color, inverted: the hottest part is the darkest, the edges burn pale
+ const BAND = [C[7], C[6], C[5], C[4], C[3], C[2], C[1], C[0]];
+ const tone = (h, v) => BAND[clamp(Math.floor((h - 0.12) / 0.12) + (v < 0.45 ? 1 : 0), 0, 7)];
+
+ // the flame: a teardrop of heat torn into tongues by rising noise; the base glows where it feeds
+ p.shade(-13, -H - 8, 13, 1, (x, y) => {
+ const v = clamp(-y / H, 0, 1.4);
+ const sway = (Math.sin(ph * TAU * 2 + v * 2.6) * 0.9 + loopNoise(ph, 0.8, S + 3)) * v * v * 2.6;
+ const w = 8.5 * (v < 0.16 ? Math.sqrt(Math.max(0, 1 - ((0.16 - v) / 0.22) ** 2)) : Math.pow(Math.max(0, 1 - (v - 0.16) / 0.88), 0.7));
+ if (w <= 0.3) return;
+ const d = Math.abs(x - sway) / w;
+ const n = tileFbm(x * 0.36, y * 0.25 + ph * 12, 0, 12, S, 3);
+ const heat = (1 - Math.pow(d, 1.6)) * (1.08 - v * 0.82) + n * (0.3 + v * 0.45);
+ if (heat < 0.12) return;
+ if (v < 0.07 && heat > 0.4) return d < 0.45 ? C[5] : C[3];
+ return tone(heat, v);
+ });
+ // tongues tear off the tip and rise, thin enough to be all edge
+ cycle(t, D, 6, S + 7, (r) => r.range(0.3, 0.42), (age, life, r) => {
+ const k = age / life, x = r.range(-4, 4) + Math.sin(k * 4 + r.next() * 6) * 1.8, y = -H * r.range(0.6, 0.85) - k * 13;
+ const s = (1 - k) * r.range(1.2, 2.1);
+ p.ellipse(x, y, s * 0.75, s * 1.6, k < 0.45 ? C[6] : C[4]);
+ if (s > 1.4 && k < 0.3) p.px(x, y, C[3]);
+ });
+ // embers: bright motes drifting up and sideways, flickering out
+ cycle(t, D, 8, S + 11, (r) => r.range(0.7, 1.2), (age, life, r) => {
+ const k = age / life, x = r.range(-6, 6) + Math.sin(age * r.range(4, 8) + r.next() * TAU) * 3 * k, y = -H * 0.5 - age * r.range(14, 22);
+ if (k > 0.5 && Math.sin(age * 38 + r.next() * 9) < -0.4) return;
+ p.px(x, y, k < 0.4 ? C[7] : k < 0.75 ? C[6] : C[4]);
+ p.light(x, y, C[6], 0.5 * (1 - k));
+ });
+
+ // scorch on the floor
+ p.ellipse(0, 1, 11, 1.4, (d) => (d < 0.7 ? C[1] : C[2]));
+
+ // light: violet, kept off the black heart so it stays dark
+ const flick = 0.85 + 0.15 * loopNoise(ph, 2, S + 5);
+ p.glow(0, -H * 0.45, 30 * flick, C[5], 0.2 * flick);
+ p.glow(0, -2, 12, C[6], 0.3 * flick);
+}
diff --git a/src/fx/shadow/shadow-step.js b/src/fx/shadow/shadow-step.js
new file mode 100644
index 0000000..77fdccf
--- /dev/null
+++ b/src/fx/shadow/shadow-step.js
@@ -0,0 +1,69 @@
+import { burst, seg, ease, rand, WHITE } from "../../core/index.js";
+import { steps, UMBRA } from "./_lib.js";
+
+export const meta = {
+ name: "Shadow step",
+ desc: "A body-sized blur of shadow whips to the right in a few frames, bursting smoke where it leaves and lands; the trail lingers and thins away.",
+ tags: ["shadow", "dash", "blink", "teleport", "smoke", "directional", "one-shot"],
+ size: [92, 48],
+ origin: [16, 43],
+ duration: 1,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ options: { palette: UMBRA, distance: 56, seed: 5 },
+};
+
+export function draw(p, t, o) {
+ const C = steps(o.palette), S = o.seed, L = o.distance, H = 18, cy = -H / 2 - 1;
+ const head = L * ease.outExpo(seg(t, 0.02, 0.16)), tail = L * ease.inCubic(seg(t, 0.03, 0.22));
+
+ // smoke: puffs left where the body passed, plus a burst at each end; one shaded field so they merge
+ const puffs = [];
+ const puff = (x, y, r, born, life, dx, dy) => {
+ const a = t - born;
+ if (a < 0 || a > life) return;
+ const k = a / life, e = ease.outCubic(Math.min(1, a / 0.25));
+ const rr = r * (0.5 + 0.7 * e) * (1 - ease.inQuad(k));
+ if (rr > 1.3) puffs.push({ x: x + dx * e, y: y + dy * e - a * a * 16, r: rr, k });
+ };
+ burst(9, S, (r, i) => {
+ const u = (i + r.range(0, 1)) / 9;
+ puff(u * L, cy + r.range(-6, 6), r.range(2.5, 4.5), 0.03 + u * 0.12, r.range(0.4, 0.65), r.range(-3, 3), r.range(-3, 1));
+ });
+ burst(6, S + 1, (r) => puff(r.range(-2, 2), cy + r.range(-7, 7), r.range(3.5, 5.5), r.range(0, 0.03), r.range(0.5, 0.75), r.range(-8, -2), r.range(-4, 2)));
+ burst(7, S + 2, (r) => puff(L + r.range(-2, 3), cy + r.range(-7, 7), r.range(3.5, 6), r.range(0.13, 0.17), r.range(0.55, 0.85), r.range(2, 9), r.range(-5, 2)));
+ if (puffs.length) {
+ p.shade(-14, -H - 16, L + 20, 0, (x, y) => {
+ let best = 0, lit = 0, age = 0;
+ for (const f of puffs) {
+ const dx = x - f.x, dy = y - f.y, d2 = (dx * dx + dy * dy) / (f.r * f.r);
+ if (d2 >= 1) continue;
+ const v = 1 - d2;
+ if (v > best) (best = v), (lit = (-dx * 0.6 - dy) / f.r), (age = f.k);
+ }
+ if (best < 0.06) return;
+ const tone = (best * 0.6 + lit * 0.5) * (1 - 0.6 * seg(age, 0.45, 1));
+ return tone > 0.85 ? C[5] : tone > 0.55 ? C[3] : tone > 0.3 ? C[2] : C[1];
+ });
+ }
+
+ // the dash: a blur of shadow the height of a body, a streak per row, each its own length;
+ // bright where it leads, black in the middle, violet wisps where it trails off
+ if (head - tail > 0.5) {
+ for (let row = -H / 2; row <= H / 2; row++) {
+ const v = Math.abs(row) / (H / 2 + 0.5), prof = Math.sqrt(1 - v * v);
+ const hx = head - (1 - prof) * 5 - rand(S, row + 40, 1) * 2.5;
+ const tx = hx - (head - tail) * prof * (0.45 + 0.55 * rand(S, row + 40, 2)) - 1;
+ if (hx - tx < 1) continue;
+ p.line(tx, cy + row, hx, cy + row, (u) => (u > 0.93 ? C[7] : u > 0.8 ? C[5] : u > 0.3 ? (v > 0.75 ? C[2] : C[0]) : C[3]),
+ (u) => (u < 0.3 ? 0.35 + u * 2 : 1));
+ }
+ p.glowLine(tail, cy, head, cy, 12, C[5], 0.35);
+ }
+ // flashes at each end
+ if (t < 0.06) p.ellipse(0, cy, 3, 8, WHITE), p.glow(0, cy, 18, C[6], 0.6);
+ const land = seg(t, 0.15, 0.23);
+ if (land > 0 && land < 1) p.ellipse(L + 1, cy, 3 * (1 - land) + 0.5, 9 * (1 - land) + 0.5, land < 0.4 ? WHITE : C[6]);
+ p.glow(L, cy, 24, C[5], 0.4 * (1 - seg(t, 0.15, 0.5)) * (t > 0.12 ? 1 : 0));
+}
diff --git a/src/fx/shadow/shadow-tendrils.js b/src/fx/shadow/shadow-tendrils.js
new file mode 100644
index 0000000..28400d2
--- /dev/null
+++ b/src/fx/shadow/shadow-tendrils.js
@@ -0,0 +1,73 @@
+import { burst, cycle, seg, ease, TAU } from "../../core/index.js";
+import { steps, UMBRA } from "./_lib.js";
+
+export const meta = {
+ name: "Shadow tendrils",
+ desc: "A black pool spreads underfoot, tentacles of shadow lash up out of it with violet rims, curl and writhe, then sink back as it closes.",
+ tags: ["shadow", "tentacle", "ground", "summon", "dark", "one-shot"],
+ size: [72, 60],
+ origin: [36, 53],
+ duration: 1.7,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ options: { palette: UMBRA, count: 4, height: 34, seed: 4 },
+};
+
+export function draw(p, t, o) {
+ const C = steps(o.palette), S = o.seed, n = o.count;
+ const open = ease.outCubic(seg(t, 0, 0.14)), close = ease.inQuad(seg(t, 1.35, 1.7));
+ const poolR = 22 * open * (1 - close);
+
+ // the pool: a hole of black on the floor with a lit far rim
+ if (poolR > 0.8) {
+ p.ellipse(0, 0.5, poolR, poolR * 0.2 + 0.8, (d, a) => (d > 0.8 ? (Math.sin(a) < 0 ? C[6] : C[4]) : d > 0.55 ? C[1] : C[0]));
+ p.glow(0, -2, 28 * (1 - close), C[5], 0.3 * open * (1 - close));
+ }
+
+ // tentacles: a spine integrated from a heading that leans out, writhes, and hooks at the tip
+ const tents = [];
+ burst(n, S, (r, i) => {
+ const side = (i + 0.5) / n - 0.5, hero = i === Math.floor(n / 2);
+ const bx = side * 34 + r.range(-2, 2), H = o.height * (hero ? 1 : r.range(0.62, 0.85));
+ const born = hero ? 0.1 : 0.04 + r.range(0, 0.14), sink = 1.0 + r.range(0, 0.16);
+ const grow = ease.outBack(seg(t, born, born + 0.32), 1.5) * (1 - ease.inQuad(seg(t, sink, sink + 0.34)));
+ if (grow <= 0.02) return;
+ const lean = side * 1.1 + r.range(-0.15, 0.15), curl = (side < 0 ? -1 : 1) * (hero ? 1.6 : r.range(1.1, 1.8));
+ const ph = r.range(0, TAU), sp = r.range(6, 9), w0 = hero ? 3.6 : r.range(2.4, 3.2);
+ const N = 18, ds = (H * grow) / N, pts = [];
+ let x = bx, y = 1;
+ for (let j = 0; j <= N; j++) {
+ const s = j / N;
+ pts.push([x, y, w0 * Math.pow(1 - s, 0.8) + 0.45]);
+ const head = -Math.PI / 2 + lean * s + 0.75 * Math.sin(t * sp + ph - s * 3) * s + curl * s * s * s * (0.6 + 0.4 * grow);
+ x += Math.cos(head) * ds;
+ y += Math.sin(head) * ds;
+ }
+ tents.push(pts);
+ // a splash of shadow as it bursts out of the pool
+ burst(4, S + 10 + i, (q) => {
+ const age = t - born, life = q.range(0.28, 0.4);
+ if (age < 0 || age > life) return;
+ const vx = q.range(-40, 40), vy = -q.range(40, 75), x = bx + vx * age, y = vy * age + 150 * age * age;
+ if (y > 0.5) return;
+ p.rect(x, y, 2, 2, C[1]), p.px(x, y, C[5]);
+ });
+ });
+ // stamp in passes so overlapping tentacles merge: outline, lit left edge, black body, darker core
+ const pass = (dx, dy, grow, c) => {
+ for (const pts of tents) for (const [x, y, w] of pts) p.circle(x + dx, y + dy, Math.max(0.5, w + grow), c);
+ };
+ pass(0, 0, 1, C[3]);
+ pass(-0.7, -0.4, 0, C[6]);
+ pass(0.5, 0.2, -0.05, C[1]);
+ pass(0.9, 0.3, -1.5, C[0]);
+ for (const pts of tents) p.light(pts[18][0], pts[18][1], C[6], 0.4);
+
+ // motes rising off the pool while it's open
+ cycle(t, 1.7, 9, S + 2, (r) => r.range(0.5, 0.9), (age, life, r) => {
+ if (poolR < 5) return;
+ const k = age / life, x = r.range(-0.9, 0.9) * poolR, y = -age * r.range(18, 30);
+ p.px(x + Math.sin(age * 9 + r.next() * 6), y, k < 0.5 ? C[6] : C[5]);
+ });
+}
diff --git a/src/fx/shadow/soul-drain.js b/src/fx/shadow/soul-drain.js
new file mode 100644
index 0000000..bc133bd
--- /dev/null
+++ b/src/fx/shadow/soul-drain.js
@@ -0,0 +1,74 @@
+import { cycle, ease, bump, clamp, tileNoise, at, TAU } from "../../core/index.js";
+import { steps, shape } from "./_lib.js";
+
+export const meta = {
+ name: "Soul drain",
+ desc: "Pale souls are torn from the right and dragged along a funnel of violet streaks into a dark vessel that flares as it feeds.",
+ tags: ["shadow", "drain", "soul", "ghost", "channel", "directional", "loop"],
+ size: [90, 36],
+ origin: [11, 18],
+ duration: 2,
+ loop: true,
+ fps: 30,
+ bg: "dark",
+ options: {
+ palette: ["#0a0614", "#1c0e36", "#341a5c", "#4a3a8a", "#5a72b4", "#7cb4dc", "#c4ecf8", "#ffffff"],
+ length: 70, count: 5, seed: 9,
+ },
+};
+
+const SOUL = [".###.", "#####", "#e#e#", "#####", "#.#.#"];
+
+export function draw(p, t, o) {
+ const C = steps(o.palette), S = o.seed, D = meta.duration, ph = t / D, L = o.length;
+ const center = (x) => Math.sin(x * 0.085 - 0.4 + ph * TAU) * 4.5 * Math.pow(clamp(x / L), 0.7);
+ const width = (x) => 1.2 + 5 * clamp(x / L);
+ const STREAM = C.slice(1, 6);
+
+ // the stream: a funnel of streaks flowing toward the vessel (noise scrolls two whole tiles a loop)
+ p.shade(0, -12, L + 6, 12, (x, y) => {
+ const cy = center(x), v = Math.abs(y - cy) / width(x);
+ if (v > 1.3) return;
+ const n = tileNoise(x * 0.16 + ph * 32, (y - cy) * 0.7 + 9, 16, 0, S);
+ const fade = clamp((L + 6 - x) / 12);
+ const val = ((1 - v) * 0.85 + n * 0.55) * fade;
+ if (val < 0.3) return;
+ return at(STREAM, (val - 0.3) * 1.25 + (x < 12 ? (12 - x) / 20 : 0));
+ });
+
+ // souls: pulled out slowly, then faster, stretching into sparks at the end
+ let feed = 0;
+ cycle(t, D, o.count, S, (r) => r.range(1.15, 1.5), (age, life, r) => {
+ const k = age / life, x0 = L + r.range(-3, 3), off = r.range(-3.5, 3.5);
+ const pos = (kk) => {
+ const e = ease.inQuad(kk), x = x0 * (1 - e);
+ return [x, center(x) + off * (1 - e) * Math.min(1, x / 20)];
+ };
+ const [x, y] = pos(k);
+ feed = Math.max(feed, bump(k, 0.84, 1));
+ // a wavering tail behind it
+ for (let j = 5; j >= 1; j--) {
+ const [tx, ty] = pos(Math.max(0, k - j * 0.022));
+ p.px(tx + 2, ty + Math.round(Math.sin(age * 18 + j * 1.3) * 0.7), j > 3 ? C[4] : C[5]);
+ }
+ if (k < 0.8) {
+ const a = clamp(k / 0.08);
+ shape(p, SOUL, Math.round(x) - 2, Math.round(y) - 2, (ch, mx, my) => (ch === "e" ? C[2] : my === 0 || (my === 1 && mx < 3) ? C[7] : C[6]), a);
+ p.light(x, y, C[6], 0.3 * a);
+ } else {
+ p.line(x, y, x + 3, y, (u) => (u < 0.4 ? C[7] : C[5]));
+ p.light(x, y, C[7], 0.6);
+ }
+ });
+
+ // the vessel: a dark orb, lit on the side facing the stream, flaring each time a soul lands
+ const R = 3.2 + feed * 1.2;
+ p.circle(0, 0, R + 1, (d, a) => (d > 0.74 && Math.cos(a) > -0.3 ? C[6] : d > 0.74 ? C[4] : C[1]));
+ p.circle(-0.5, -0.5, R * 0.45, feed > 0.6 ? C[7] : C[0]);
+ if (feed > 0.4) {
+ const s = 2 + feed * 4;
+ p.line(-R - s, 0, -R - 1, 0, C[6]), p.line(0, -R - s, 0, -R - 1, C[6]), p.line(0, R + 1, 0, R + s, C[6]);
+ }
+ p.glow(0, 0, 14 + feed * 10, C[5], 0.28 + feed * 0.3);
+ p.glow(L * 0.55, 0, 28, C[3], 0.1);
+}
diff --git a/src/fx/shadow/void-orb.js b/src/fx/shadow/void-orb.js
new file mode 100644
index 0000000..0325125
--- /dev/null
+++ b/src/fx/shadow/void-orb.js
@@ -0,0 +1,62 @@
+import { cycle, tileNoise, ease, fract, TAU } from "../../core/index.js";
+import { steps, UMBRA } from "./_lib.js";
+
+export const meta = {
+ name: "Void orb",
+ desc: "A ball of pure black with a crawling violet rim; a dark vortex winds into it and bright motes streak in and vanish.",
+ tags: ["shadow", "void", "orb", "dark", "magic", "loop"],
+ size: [48, 48],
+ origin: [24, 24],
+ duration: 1.6,
+ loop: true,
+ fps: 30,
+ bg: "dark",
+ options: { palette: UMBRA, radius: 8, count: 9, seed: 3 },
+};
+
+const K = 2.2; // how tightly the vortex arms wind
+
+export function draw(p, t, o) {
+ const C = steps(o.palette), R = o.radius, S = o.seed, D = meta.duration, ph = t / D, W = R + 12;
+
+ // the vortex: three arms of dark matter winding in, thinning to points as they leave the orb
+ p.shade(-W, -W, W, W, (x, y) => {
+ const d = Math.hypot(x, y);
+ if (d < R - 1 || d > W) return;
+ const a = Math.atan2(y, x), arm = fract((3 * a) / TAU + (K * Math.log(d)) / 1.4 - ph * 2);
+ const band = 1 - Math.abs(arm - 0.5) * 2, reach = 1 - (d - R) / (W - R);
+ const v = band * (0.35 + 0.75 * reach);
+ if (v < 0.62) return;
+ return v > 0.86 && reach > 0.45 ? C[4] : reach > 0.25 ? C[3] : C[2];
+ });
+
+ // motes ride the arms in, accelerating; each is a short tail that brightens toward its head
+ const at = (r0, a0, e) => {
+ const rad = r0 + (R - 0.5 - r0) * e, ang = a0 + (K / 1.4) * (TAU / 3) * Math.log(r0 / rad) * 0.9;
+ return [Math.cos(ang) * rad, Math.sin(ang) * rad];
+ };
+ cycle(t, D, o.count, S, (r) => r.range(0.6, 0.95), (age, life, r) => {
+ const k = age / life, a0 = r.range(0, TAU), r0 = r.range(R + 8, R + 13);
+ const pts = [0, 0.05, 0.1, 0.16].map((back) => at(r0, a0, ease.inQuad(Math.max(0, k - back * (0.4 + k)))));
+ for (let i = pts.length - 1; i > 0; i--) p.line(...pts[i], ...pts[i - 1], i === 1 ? C[6] : i === 2 ? C[5] : C[4]);
+ p.px(...pts[0], k > 0.55 ? C[7] : C[6]);
+ p.light(...pts[0], C[6], 0.4 * k);
+ });
+
+ // the orb: black, a faint inner swirl, a rim that crawls
+ p.shade(-R - 2, -R - 2, R + 2, R + 2, (x, y) => {
+ const d = Math.hypot(x, y), a = Math.atan2(y, x), u = a / TAU + 0.5;
+ const rim = R + 0.6 * tileNoise(u * 10 + ph * 10, ph * 3, 10, 3, S);
+ if (d > rim) return;
+ if (d > rim - 1) return tileNoise(u * 8 + ph * 16, 0.5, 8, 0, S + 2) > -0.25 ? C[7] : C[6];
+ const thick = tileNoise(u * 6 - ph * 12, 0.5, 6, 0, S + 1) > 0.1;
+ if (d > rim - 2 && thick) return C[5];
+ const swirl = Math.sin(a * 2 + Math.log(d + 0.5) * 3 - ph * TAU * 2);
+ return d > R * 0.35 && swirl > 0.75 ? C[1] : C[0];
+ });
+
+ // light hugs the rim and breathes
+ const pulse = 0.85 + 0.15 * Math.sin(ph * TAU * 2);
+ p.glowRing(0, 0, R, 6, C[5], 0.4 * pulse);
+ p.glow(0, 0, 24, C[4], 0.14 * pulse);
+}
diff --git a/src/fx/spawn/_lib.js b/src/fx/spawn/_lib.js
new file mode 100644
index 0000000..88a6158
--- /dev/null
+++ b/src/fx/spawn/_lib.js
@@ -0,0 +1,96 @@
+// Shared by the spawn and death effects: the actor's own pixels (to break up, burn or shatter), a stretched copy
+// of the silhouette, a cartoon cloud, and the smoke helpers from the projectiles kit. Files starting with _ are
+// helpers, not effects.
+
+import { createFrame, painterFor, drawActor, stockActor, at } from "../../core/index.js";
+
+export { smoke, puffs, beat, onCanvas, rotSprite, steps } from "../projectiles/_lib.js";
+
+const STOCK = stockActor();
+const cache = new WeakMap();
+
+/** The actor an effect works on: the caller's, or the stock character. */
+export const actorOf = (o) => o.actor ?? STOCK;
+
+/**
+ * Every pixel of the actor's silhouette in local space, feet at (0, 0): [{ x, y, mx, my, c }]. The stock
+ * character keeps its own colors; any other mask is shaded from the ramp R (top-lit, darker toward the feet).
+ */
+export function actorPixels(actor, R) {
+ let list = cache.get(actor.mask);
+ if (list && (list.R === R || !list.tinted)) return list;
+ const { mask: m, x: ax, y: ay } = actor, stock = m === STOCK.mask;
+ let color = null;
+ if (stock) {
+ const f = createFrame(m.w, m.h), p = painterFor(f).place(-ax, -ay);
+ drawActor(p, actor);
+ color = f.color;
+ }
+ list = [];
+ for (let my = 0; my < m.h; my++)
+ for (let mx = 0; mx < m.w; mx++)
+ if (m.data[my * m.w + mx]) list.push({ x: ax + mx, y: ay + my, mx, my, c: stock ? color[my * m.w + mx] : at(R, 0.8 - (my / m.h) * 0.5) });
+ list.tinted = !stock;
+ list.R = R;
+ cache.set(actor.mask, list);
+ return list;
+}
+
+/**
+ * A cartoon cloud: balls [{ x, y, r }] merged into one shape with a 1 px outline, a flat body, a highlight on
+ * the top-left of each ball and a shadow on the bottom-right. C is the cloud ramp, dark (outline) to light
+ * (shine). a fades the whole cloud by dither; inside(x, y) can clip it (to keep it above the floor).
+ */
+export function cloud(p, balls, C, { a = 1, inside } = {}) {
+ const L = balls.filter((f) => f.r > 0.6);
+ if (!L.length || a <= 0) return;
+ let x0 = Infinity, y0 = Infinity, x1 = -Infinity, y1 = -Infinity;
+ for (const f of L) {
+ x0 = Math.min(x0, f.x - f.r); x1 = Math.max(x1, f.x + f.r);
+ y0 = Math.min(y0, f.y - f.r); y1 = Math.max(y1, f.y + f.r);
+ }
+ const ink = [at(C, 0.2), at(C, 0.4), at(C, 0.6), at(C, 0.8), at(C, 0.99)];
+ // which ink a point takes: -1 outside, 0 the outline ring, 1..4 shadow to shine by the nearest ball's normal
+ const band = (x, y) => {
+ let sd = -Infinity, nx = 0, ny = 0;
+ for (const f of L) {
+ const dx = x - f.x, dy = y - f.y, s = f.r - Math.sqrt(dx * dx + dy * dy);
+ if (s > sd) (sd = s), (nx = dx / f.r), (ny = dy / f.r);
+ }
+ if (sd <= -1) return -1;
+ if (sd <= 0) return 0;
+ const lit = -(nx + ny * 1.3);
+ return lit > 0.6 ? 4 : lit > 0.05 ? 3 : lit > -0.55 ? 2 : 1;
+ };
+ p.shade(x0 - 1.5, y0 - 1.5, x1 + 1.5, y1 + 1.5, (x, y, out) => {
+ if (inside && !inside(x, y)) return;
+ let b = band(x, y);
+ if (b < 0) return;
+ if (b > 0) {
+ // no lone pixels: a shade that none of its four neighbours share takes the commonest of theirs
+ const n = [band(x + 1, y), band(x - 1, y), band(x, y + 1), band(x, y - 1)].filter((v) => v > 0);
+ if (n.length && !n.includes(b)) b = n.sort((u, v) => n.filter((w) => w === v).length - n.filter((w) => w === u).length)[0];
+ }
+ out.a = a;
+ return ink[b];
+ });
+}
+
+/** Is (mx, my) inside the mask? */
+export const inMask = (m, mx, my) => mx >= 0 && my >= 0 && mx < m.w && my < m.h && m.data[my * m.w + mx] === 1;
+
+/**
+ * The silhouette scaled by (sx, sy) about its feet, drawn at (x, y): fn(mx, my, edge) returns a color for each
+ * covered pixel (mx, my are mask coordinates, edge is true on the outer ring). Return nothing to skip.
+ */
+export function stretchMask(p, actor, x, y, sx, sy, fn) {
+ const m = actor.mask, W = m.w * sx, H = m.h * sy, x0 = x - W / 2 + (actor.x + m.w / 2) * sx;
+ const covered = (lx, ly) => inMask(m, Math.floor((lx - x0) / sx), Math.floor((ly - (y - H)) / sy));
+ p.shade(x0 - 1, y - H - 1, x0 + W + 1, y + 1, (lx, ly, out) => {
+ const mx = Math.floor((lx - x0) / sx), my = Math.floor((ly - (y - H)) / sy);
+ if (!inMask(m, mx, my)) return;
+ const edge = !covered(lx - 1, ly) || !covered(lx + 1, ly) || !covered(lx, ly - 1) || !covered(lx, ly + 1);
+ const c = fn(mx, my, edge, out);
+ if (c) out.c = c;
+ });
+}
diff --git a/src/fx/spawn/coin-drop.js b/src/fx/spawn/coin-drop.js
new file mode 100644
index 0000000..1258955
--- /dev/null
+++ b/src/fx/spawn/coin-drop.js
@@ -0,0 +1,67 @@
+import { PAL, ramp, at, burst, seg, ease, TAU, WHITE } from "../../core/index.js";
+import { cloud } from "./_lib.js";
+
+export const meta = {
+ name: "Coin drop",
+ desc: "Loot: the enemy goes poof and a spray of spinning gold coins arcs out, bounces on the floor, settles with a glint, then blinks away.",
+ tags: ["spawn", "death", "loot", "coins", "gold", "reward", "ground", "one-shot"],
+ size: [84, 52],
+ origin: [42, 46],
+ duration: 2,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ options: { palette: PAL.gold, count: 7, seed: 24 },
+};
+
+// a coin turning: face on, three-quarter, half, edge on
+const SPIN = [
+ ["..ddd..", ".dllld.", "dlwllmd", "dllmlmd", "dlllmmd", ".dmmmd.", "..ddd.."],
+ [".ddd.", "dllmd", "dlwmd", "dllmd", "dlmmd", "dmmmd", ".ddd."],
+ [".d.", "dld", "dwd", "dld", "dmd", "dmd", ".d."],
+ ["d", "l", "l", "m", "m", "m", "d"],
+];
+const TURN = [0, 1, 2, 3, 2, 1];
+const G = 420, FLOOR = -3.5, E = 0.36;
+
+/** A coin's flight: thrown from (x0, y0), bouncing on the floor until it settles. Returns [x, y, bounces]. */
+function hop(t, x0, y0, vx, vy) {
+ let x = x0, y = y0, v = vy, bx = vx, tt = t;
+ for (let n = 0; n < 4; n++) {
+ const T = (-v + Math.sqrt(v * v + 2 * G * (FLOOR - y))) / G;
+ if (tt < T) return [x + bx * tt, y + v * tt + 0.5 * G * tt * tt, n];
+ tt -= T, x += bx * T, y = FLOOR, v = -(v + G * T) * E, bx *= 0.5;
+ if (v > -14) break;
+ }
+ return [x + bx * Math.min(tt, 0.08), FLOOR, 4];
+}
+
+export function draw(p, t, o) {
+ const C = ramp(o.palette), S = o.seed;
+ const pal = { d: at(C, 0.3), m: at(C, 0.55), l: at(C, 0.75), w: at(C, 0.95) };
+ // coins: thrown up and out, spinning while they fly, slowing their spin as they settle, blinking out at the end
+ const blink = (t > 1.45 && Math.floor(t * 16) % 2 === 0) || t > 1.85;
+ if (!blink) burst(o.count, S + 1, (r, i) => {
+ const t0 = 0.04 + i * 0.025, age = t - t0;
+ if (age < 0) return;
+ const [x, y, n] = hop(age, r.range(-2, 2), -9, ((i + 0.5) / o.count - 0.5) * 80 + r.range(-6, 6), -r.range(115, 155));
+ const rate = n >= 4 ? 0 : n > 1 ? 10 : 18, f = rate ? TURN[Math.floor(age * rate + r.next() * 6) % 6] : 0;
+ const frame = SPIN[f], w = frame[0].length;
+ p.sprite(frame, pal, Math.round(x) - (w >> 1), Math.round(y) - 3);
+ // a glint pops on a settled coin now and then
+ const gl = (age * 2.2 + r.next()) % 1;
+ if (n >= 4 && gl < 0.12) {
+ const s = gl < 0.06 ? 2 : 1, gx = Math.round(x) + 1, gy = Math.round(y) - 3;
+ p.line(gx - s, gy, gx + s, gy, WHITE), p.line(gx, gy - s, gx, gy + s, WHITE);
+ }
+ p.light(x, y, at(C, 0.7), 0.2);
+ });
+ // the enemy's last poof, in front so the coins burst out of it
+ const balls = [];
+ burst(6, S, (r, i) => {
+ const a = (i / 6) * TAU + r.range(-0.3, 0.3), e = ease.outCubic(seg(t, 0, 0.1)), gone = seg(t, 0.1 + r.range(0, 0.1), 0.32 + r.range(0, 0.1));
+ balls.push({ x: Math.cos(a) * 7 * e, y: -9 + Math.sin(a) * 5 * e, r: r.range(3.5, 5) * (0.4 + 0.6 * e) * (1 - gone) });
+ });
+ cloud(p, balls, ramp(["#2c2840", "#5a5478", "#8e88aa", "#c4bed8", "#ecebf6"]), { inside: (x, y) => y < 0 });
+}
+
diff --git a/src/fx/spawn/disintegrate.js b/src/fx/spawn/disintegrate.js
new file mode 100644
index 0000000..861ce3c
--- /dev/null
+++ b/src/fx/spawn/disintegrate.js
@@ -0,0 +1,48 @@
+import { PAL, ramp, at, rng, noise, TAU, WHITE } from "../../core/index.js";
+import { actorOf, actorPixels } from "./_lib.js";
+
+export const meta = {
+ name: "Disintegrate",
+ desc: "The character flashes white, then comes apart pixel by pixel from the head down: each bit lights up, lifts off on the wind and winks out.",
+ tags: ["spawn", "death", "disintegrate", "dissolve", "pixels", "energy", "one-shot"],
+ size: [64, 50],
+ origin: [20, 46],
+ duration: 1.9,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ actor: false,
+ options: { palette: PAL.cyber, seed: 26 },
+};
+
+export function draw(p, t, o) {
+ const C = ramp(o.palette), S = o.seed, actor = actorOf(o), top = actor.y, H = actor.h;
+ const flash = t >= 0.05 && t < 0.12;
+ let fx = 0, fy = 0, fn = 0;
+ for (const q of actorPixels(actor, C)) {
+ const r = rng(S, q.mx, q.my);
+ // when this pixel lets go: the head first, the front ragged
+ const v = (q.y - top) / H, go = 0.22 + v * 0.78 + noise(q.mx * 0.6 + 3, S) * 0.07 + r.range(-0.05, 0.05);
+ const age = t - go;
+ if (age < -0.09) {
+ p.px(q.x, q.y, flash ? WHITE : q.c);
+ continue;
+ }
+ if (age < 0) {
+ // the front: pixels about to go light up first
+ p.px(q.x, q.y, age > -0.045 ? at(C, 0.95) : at(C, 0.72));
+ (fx += q.x), (fy += q.y), fn++;
+ continue;
+ }
+ const life = r.range(0.45, 0.8), k = age / life;
+ if (k >= 1) continue;
+ // on the wind: lifting, drifting right faster and faster, fluttering
+ const x = q.x + age * r.range(6, 16) + age * age * r.range(20, 40);
+ const y = q.y - age * r.range(8, 22) + Math.sin(age * r.range(8, 14) + r.next() * TAU) * 1.2;
+ if (k > 0.55 && Math.floor(age * 24 + r.next() * 4) % 3 === 0) continue;
+ p.px(x, y, k < 0.2 ? at(C, 0.95) : k < 0.5 ? at(C, 0.75) : at(C, 0.5));
+ if (k < 0.35) p.light(x, y, at(C, 0.7), 0.3 * (1 - k));
+ }
+ if (flash) p.glow(0, -10, 22, at(C, 0.8), 0.4);
+ if (fn) p.glow(fx / fn, fy / fn, 12, at(C, 0.75), 0.3);
+}
diff --git a/src/fx/spawn/dissolve-burn.js b/src/fx/spawn/dissolve-burn.js
new file mode 100644
index 0000000..72cafef
--- /dev/null
+++ b/src/fx/spawn/dissolve-burn.js
@@ -0,0 +1,58 @@
+import { PAL, ramp, at, rand, stream, seg, noise, scale, TAU, WHITE } from "../../core/index.js";
+import { actorOf, actorPixels, steps } from "./_lib.js";
+
+export const meta = {
+ name: "Dissolve burn",
+ desc: "Burned away from the feet up: a ragged ember line climbs the body, charring it black just ahead, flames licking up, sparks and ash rising off.",
+ tags: ["spawn", "death", "burn", "fire", "dissolve", "one-shot"],
+ size: [48, 56],
+ origin: [22, 50],
+ duration: 2,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ actor: false,
+ options: { palette: PAL.fire, seed: 28 },
+};
+
+export function draw(p, t, o) {
+ const C = steps(ramp(o.palette), 8), S = o.seed, actor = actorOf(o), H = actor.h;
+ const climb = seg(t, 0.12, 1.5), base = 3 - climb * (H + 7), frame = Math.floor(t * 30);
+ const edge = (x) => base + noise(x * 0.5 + t * 1.5, S) * 1.8 + Math.sin(x * 1.7 + t * 11) * 0.45;
+ const burning = climb > 0 && climb < 1;
+ // the body: untouched above, a scorched rim, glowing bands, an ember edge; nothing below the line
+ const cols = new Map();
+ for (const q of actorPixels(actor, C)) {
+ const d = q.y + 0.5 - edge(q.x + 0.5);
+ if (d > 0.6) continue;
+ let c = q.c;
+ if (d > -0.5) c = noise(q.x * 0.8 + t * 9, S + 3) > 0.3 ? WHITE : at(C, 0.9);
+ else if (d > -1.5) c = at(C, 0.6);
+ else if (d > -2.5) c = at(C, 0.3);
+ else if (d > -3.2) c = scale(q.c, 0.6);
+ p.px(q.x, q.y, c);
+ if (d > -1.5 && (!cols.has(q.x) || cols.get(q.x) > q.y)) cols.set(q.x, q.y);
+ }
+ // flames: a flickering tongue on each burning column
+ if (burning)
+ for (const [x, y] of cols) {
+ const h = Math.round(1.2 + 2.6 * (0.5 + 0.5 * noise(x * 0.55 + t * 7, S + 5)) + rand(S, x, frame >> 1) * 0.9 - 0.6);
+ for (let j = 1; j <= h; j++) p.px(x, y - j, j === 1 ? at(C, 0.78) : j === 2 ? at(C, 0.6) : at(C, 0.45));
+ }
+ // embers spat up off the line, swaying and cooling; flakes of ash drifting off slower
+ stream(t, 0.15, 1.5, 22, S + 1, (r) => r.range(0.3, 0.45), (age, life, r, i) => {
+ const t0 = 0.15 + i / 22, c0 = seg(t0, 0.12, 1.5), k = age / life;
+ const x0 = r.range(-5, 5), y0 = Math.max(-H - 1, 3 - c0 * (H + 7)), ash = i % 3 === 0;
+ const x = x0 + Math.sin(age * r.range(5, 9) + r.next() * TAU) * 2 + age * r.range(-4, 10), y = y0 - age * (ash ? r.range(10, 18) : r.range(22, 38));
+ if (ash) return p.rect(x, y, 2, 1, k < 0.5 ? C[2] : C[1]);
+ if (k > 0.6 && (frame + i) % 3 === 0) return;
+ p.px(x, y, k < 0.3 ? at(C, 0.92) : k < 0.65 ? at(C, 0.7) : at(C, 0.45));
+ p.light(x, y, at(C, 0.7), 0.35 * (1 - k));
+ });
+ // light: the burning line throws a warm pool that climbs with it
+ if (burning) {
+ const fl = 0.85 + 0.15 * rand(S, frame);
+ p.glow(0, base, 20, at(C, 0.62), 0.42 * fl);
+ p.glow(0, base, 7, at(C, 0.88), 0.3 * fl);
+ }
+}
diff --git a/src/fx/spawn/egg-hatch.js b/src/fx/spawn/egg-hatch.js
new file mode 100644
index 0000000..168b254
--- /dev/null
+++ b/src/fx/spawn/egg-hatch.js
@@ -0,0 +1,93 @@
+import { ramp, burst, fly, seg, ease, TAU, WHITE } from "../../core/index.js";
+import { rotSprite, cloud, steps } from "./_lib.js";
+
+export const meta = {
+ name: "Egg hatch",
+ desc: "A speckled egg rocks in three nervous bursts, cracking a little more each time, then pops: the cap flies off in a flash of light and shell bits.",
+ tags: ["spawn", "egg", "hatch", "birth", "cartoon", "ground", "one-shot"],
+ size: [52, 56],
+ origin: [26, 50],
+ duration: 1.9,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ options: { palette: ["#3a2a1c", "#6e5438", "#a88a62", "#dcc8a0", "#f6ecd2", "#fffaf0"], spots: "#7a9a4a", seed: 25 },
+};
+
+// the egg in three states of cracking (c marks the crack); the pivot is the middle of its base
+const EGG = [
+ ".....oooo.....",
+ "...ooLLwwoo...",
+ "..oLLLwwwwwo..",
+ ".oLLwwwwwswwo.",
+ ".oLwwwsswwwwo.",
+ "oLwwwwsswwwwwo",
+ "oLwwwwwwwwwwwo",
+ "owwwwwwwwwssmo",
+ "owwswwwwwwssmo",
+ "owwsswwwwwwwmo",
+ "owwwwwwwwwwwmo",
+ "owwwwwwswwwmmo",
+ "owwwwwwwwwwmmo",
+ ".owwwwwwwwmmo.",
+ ".owwwwwwwmmmo.",
+ "..ommmmmmmmo..",
+ "...oommmmoo...",
+ ".....oooo.....",
+];
+const CRACKS = [
+ [],
+ [[5, 8], [6, 9], [7, 8]],
+ [[3, 9], [4, 8], [5, 9], [6, 8], [7, 9], [8, 8], [9, 9]],
+ [[1, 8], [2, 9], [3, 8], [4, 9], [5, 8], [6, 9], [7, 8], [8, 9], [9, 8], [10, 9], [11, 8], [12, 9]],
+];
+const SHAKES = [[0.1, 0.38, 0.13], [0.5, 0.78, 0.2], [0.88, 1.08, 0.28]]; // [start, end, how hard]
+const POP = 1.1;
+
+const withCrack = (n) => EGG.map((row, y) => [...row].map((ch, x) => (CRACKS[n].some(([cx, cy]) => cx === x && cy === y) ? "c" : ch)).join(""));
+const STAGES = [0, 1, 2, 3].map(withCrack);
+
+export function draw(p, t, o) {
+ const C = steps(ramp(o.palette), 6), S = o.seed;
+ const pal = { o: C[1], L: C[5], w: C[4], m: C[3], s: o.spots, c: C[0] };
+ if (t < POP) {
+ // rocking: three bursts, each harder, with a beat of stillness between
+ let ang = 0, cracked = 0;
+ for (const [a, b, k] of SHAKES) {
+ if (t >= a && t < b) ang = k * Math.sin((t - a) * TAU * 6) * Math.sin(Math.PI * seg(t, a, b));
+ if (t >= b - 0.1) cracked++;
+ }
+ rotSprite(p, STAGES[Math.min(3, cracked)], pal, 0, 0, ang, 7, 18);
+ return;
+ }
+ const te = t - POP;
+ // the pop: a cartoon puff, the shell flying apart, a white burst of light on top
+ const balls = [];
+ burst(6, S, (r, i) => {
+ const a = (i / 6) * TAU + r.range(-0.3, 0.3), e = ease.outCubic(seg(te, 0, 0.12)), gone = seg(te, 0.1 + r.range(0, 0.1), 0.4 + r.range(0, 0.1));
+ balls.push({ x: Math.cos(a) * 10 * e, y: -12 + Math.sin(a) * 6 * e - te * 8, r: r.range(3.5, 5.5) * (0.3 + 0.7 * e) * (1 - gone) });
+ });
+ cloud(p, balls, ramp(["#3a3550", "#6a6488", "#a29cbc", "#d8d4ea", "#ffffff"]), { inside: (x, y) => y < 0 });
+ const fade = 1 - seg(te, 0.5, 0.75);
+ // the cradle of shell left on the floor
+ rotSprite(p, STAGES[3].slice(9), pal, 0, 0, 0, 7, 9, { a: fade });
+ // the cap: flung up, tumbling, falling off to the side
+ if (te < 0.7) {
+ const [cx, cy] = fly(0, -13, 26, -120, te, 320, 0.4);
+ rotSprite(p, STAGES[3].slice(0, 10), pal, cx, cy, te * 9, 7, 5, { a: 1 - seg(te, 0.5, 0.7), inside: (x, y) => y < 1 });
+ }
+ // shell bits and sparkles
+ burst(9, S + 1, (r, i) => {
+ const a = -Math.PI / 2 + r.range(-1.3, 1.3), v = r.range(60, 120), life = r.range(0.4, 0.65);
+ if (te > life) return;
+ const [x, y] = fly(0, -12, Math.cos(a) * v, Math.sin(a) * v, te, 300, 0.6), k = te / life;
+ if (y > 0) return;
+ if (x < -24 || x > 24) return;
+ if (i < 5) p.rect(x, y, 2, 1, k < 0.5 ? C[4] : C[3]);
+ else if (k < 0.7) p.px(x, y, WHITE), p.light(x, y, C[5], 0.4);
+ });
+ if (te < 0.08) {
+ p.circle(0, -10, 11 - te * 50, WHITE);
+ p.glow(0, -10, 30, C[4], 0.55);
+ }
+}
diff --git a/src/fx/spawn/ghost-out.js b/src/fx/spawn/ghost-out.js
new file mode 100644
index 0000000..8d3d04a
--- /dev/null
+++ b/src/fx/spawn/ghost-out.js
@@ -0,0 +1,61 @@
+import { ramp, at, cycle, stream, seg, ease, WHITE } from "../../core/index.js";
+import { steps } from "./_lib.js";
+
+export const meta = {
+ name: "Ghost out",
+ desc: "A little sheet ghost pops up out of the fallen, its skirt rippling, sways upward on a lazy wave and fades out, dropping pale wisps.",
+ tags: ["spawn", "death", "ghost", "spirit", "cartoon", "one-shot"],
+ size: [40, 60],
+ origin: [20, 54],
+ duration: 1.8,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ options: { palette: ["#1e1a34", "#3c3660", "#6a6496", "#a8a4cc", "#dcdcf0", "#ffffff"], seed: 22 },
+};
+
+// two frames of a sheet ghost: the skirt's hem ripples between them
+const BODY = [
+ "...ooooo...",
+ "..owwwhho..",
+ ".owwwwwhho.",
+ ".owwwwwwwo.",
+ "owwewwwewwo",
+ "owwewwwewwo",
+ "owwwwwwwwwo",
+ "owwwwmwwwwo",
+ "owwwwwwwwwo",
+ "oswwwwwwwso",
+ "osswwwwwsso",
+];
+const HEM = [
+ ["osossosssoo", ".o..o...o.."],
+ ["oossosssoso", "..o...o..o."],
+];
+
+export function draw(p, t, o) {
+ const C = steps(ramp(o.palette), 6), S = o.seed;
+ const pal = { o: at(C, 0.3), w: at(C, 0.8), h: WHITE, s: at(C, 0.6), e: C[0], m: C[1] };
+ // rise: pops out of the ground with an overshoot, then drifts up on a lazy wave
+ const pop = ease.outBack(seg(t, 0, 0.22), 2), drift = Math.max(0, t - 0.22);
+ const x = Math.round(Math.sin(drift * 4.2) * 4 * seg(t, 0.15, 0.5)), y = Math.round(-1 - 17 * pop - drift * 17);
+ const fade = 1 - seg(t, 1.05, 1.6);
+ // wisps: pale drops shed from the hem, sinking and fading
+ stream(t, 0.25, 1.4, 7, S, (r) => r.range(0.35, 0.55), (age, life, r, i) => {
+ const t0 = 0.25 + i / 7, d0 = Math.max(0, t0 - 0.22), k = age / life;
+ const wx = Math.round(Math.sin(d0 * 4.2) * 4 * seg(t0, 0.15, 0.5) + r.range(-4, 4)), wy = Math.round(-18 - d0 * 17 + 1 + age * r.range(8, 14));
+ if (k > 0.7 && Math.floor(age * 20) % 2) return;
+ p.px(wx, wy, k < 0.4 ? at(C, 0.8) : at(C, 0.6)), p.px(wx, wy - 1, k < 0.4 ? at(C, 0.6) : at(C, 0.4));
+ });
+ const hem = HEM[Math.floor(t * 8) % 2];
+ const rows = [...BODY, ...hem];
+ // squash on landing at the top of the pop, stretch while it springs up
+ p.sprite(rows, pal, x - 5, y - rows.length, { a: fade });
+ p.glow(x, y - 7, 18, at(C, 0.7), 0.25 * fade);
+ // a puff of pale motes where it came out
+ cycle(t, meta.duration, 6, S + 1, 0.5, (age, life, r, i) => {
+ if (t > 0.6) return;
+ const k = age / life, a = r.range(-Math.PI, 0), d = 3 + age * r.range(14, 26);
+ p.px(Math.cos(a) * d, -1 + Math.sin(a) * d * 0.6, k < 0.5 ? WHITE : at(C, 0.7));
+ });
+}
diff --git a/src/fx/spawn/poof.js b/src/fx/spawn/poof.js
new file mode 100644
index 0000000..2fb9cd6
--- /dev/null
+++ b/src/fx/spawn/poof.js
@@ -0,0 +1,52 @@
+import { ramp, at, burst, seg, ease, TAU, WHITE } from "../../core/index.js";
+import { cloud } from "./_lib.js";
+
+export const meta = {
+ name: "Poof",
+ desc: "A cartoon poof: a ring of fat smoke balls pops out with an overshoot behind a white flash and speed lines, puffs up, then shrinks away ball by ball.",
+ tags: ["spawn", "despawn", "smoke", "poof", "cartoon", "one-shot"],
+ size: [52, 42],
+ origin: [26, 38],
+ duration: 0.8,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ options: { palette: ["#2c2840", "#5a5478", "#8e88aa", "#c4bed8", "#ecebf6", "#ffffff"], size: 1, seed: 21 },
+};
+
+export function draw(p, t, o) {
+ const C = ramp(o.palette), S = o.seed, k = o.size, cy = -11 * k;
+ // the balls: a ring around a core, popped out with an overshoot, then each shrinks away on its own beat
+ const balls = [];
+ burst(10, S, (r, i) => {
+ const core = i < 2, a = ((i - 2) / 8) * TAU + r.range(-0.25, 0.25), reach = core ? r.range(0, 2.5) : r.range(8, 11) * k;
+ const pop = ease.outBack(seg(t, 0, 0.14 + r.range(0, 0.04)), 2.4);
+ const gone = ease.inQuad(seg(t, 0.3 + r.range(0, 0.18), 0.66 + r.range(0, 0.1)));
+ const R = r.range(4.5, 6.5) * k * (0.3 + 0.7 * pop) * (1 - gone);
+ const x = Math.cos(a) * reach * pop, y = Math.min(cy + Math.sin(a) * reach * pop * 0.72 - t * r.range(5, 11), -R + 1);
+ balls.push({ x, y, r: R });
+ });
+ cloud(p, balls, C, { inside: (x, y) => y < 0 });
+ // the pop: a white flash for two frames
+ if (t < 0.07) {
+ p.circle(0, cy, (5 + t * 60) * k, WHITE);
+ p.glow(0, cy, 26 * k, at(C, 0.8), 0.5);
+ }
+ // speed lines bursting out from under the cloud
+ const sl = seg(t, 0.02, 0.18);
+ if (sl > 0 && sl < 1) {
+ burst(7, S + 1, (r, i) => {
+ const a = (i / 7) * TAU + r.range(-0.2, 0.2) - 0.3, d0 = (12 + 10 * ease.outCubic(sl)) * k, len = 5 * (1 - sl) + 1;
+ const x0 = Math.cos(a) * d0, y0 = cy + Math.sin(a) * d0 * 0.75;
+ if (y0 > -1) return;
+ p.line(x0, y0, x0 + Math.cos(a) * len, y0 + Math.sin(a) * len * 0.75, at(C, 0.99));
+ });
+ }
+ // twinkles left in the air as it clears
+ burst(3, S + 2, (r) => {
+ const tw = seg(t, r.range(0.25, 0.4), r.range(0.55, 0.7));
+ if (tw <= 0 || tw >= 1) return;
+ const x = r.range(-14, 14) * k, y = cy + r.range(-10, 4) * k, s = tw < 0.5 ? 2 : 1;
+ p.line(x - s, y, x + s, y, at(C, 0.8)), p.line(x, y - s, x, y + s, at(C, 0.8)), p.px(x, y, WHITE);
+ });
+}
diff --git a/src/fx/spawn/respawn-beam.js b/src/fx/spawn/respawn-beam.js
new file mode 100644
index 0000000..70180bf
--- /dev/null
+++ b/src/fx/spawn/respawn-beam.js
@@ -0,0 +1,78 @@
+import { PAL, ramp, at, burst, cycle, fly, seg, ease, WHITE } from "../../core/index.js";
+import { actorOf } from "./_lib.js";
+
+export const meta = {
+ name: "Respawn beam",
+ desc: "A beam slams down onto the spawn point, the character is written in from the feet up as glowing scanlines, flashes white and steps out as the beam closes.",
+ tags: ["spawn", "respawn", "teleport", "beam", "sci-fi", "one-shot"],
+ size: [48, 88],
+ origin: [24, 82],
+ duration: 1.5,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ actor: true,
+ options: { palette: PAL.cyber, seed: 29 },
+};
+
+const FLASH = 0.72; // the written-in silhouette flashes white; the character is there from here on
+
+/** The stand-in (or your own sprite) is hidden until the flash, then shows through as the tint fades off it. */
+export const actorAlpha = (t) => (t < FLASH ? 0 : 1);
+
+export function draw(p, t, o) {
+ const C = ramp(o.palette), S = o.seed, a = actorOf(o), m = a.mask, TOP = -meta.origin[1] + 1;
+ const drop = ease.inQuad(seg(t, 0, 0.07)), open = ease.outCubic(seg(t, 0.05, 0.16)), shut = ease.inCubic(seg(t, 0.84, 1.08));
+ const fill = seg(t, 0.2, FLASH), flash = t >= FLASH && t < FLASH + 0.07, reveal = seg(t, 0.8, 1.04);
+ const rows = Math.floor(fill * (m.h + 1));
+ // the beam: a white core while it lands, then two hard edges, inner rails that flicker and dashes climbing
+ // between them; the body of it is light, so the character being written in reads against it
+ const w = (0.7 + 8 * open) * (1 - shut), tip = TOP * (1 - drop), frame = Math.floor(t * 30);
+ if (w > 0.4 && t < 1.08) {
+ const core = 1 - seg(t, 0.1, 0.26), cw = Math.max(0.6, w * 0.55 * core);
+ if (core > 0) p.rect(-Math.round(cw), TOP, Math.round(cw) * 2, tip - TOP, WHITE);
+ const ew = Math.round(w);
+ p.rect(-ew, TOP, 1, tip - TOP, at(C, 0.86));
+ p.rect(ew - 1, TOP, 1, tip - TOP, at(C, 0.86));
+ if (ew > 3 && frame % 3 !== 0) {
+ p.rect(-ew + 2, TOP, 1, tip - TOP, at(C, 0.6));
+ p.rect(ew - 3, TOP, 1, tip - TOP, at(C, 0.6));
+ }
+ for (let i = 0; i < 9; i++) {
+ const y = tip - ((i * 13 + t * 90) % (tip - TOP)), x = -ew + 2 + ((i * 5) % Math.max(1, ew * 2 - 4));
+ if (y > TOP) p.line(x, y, x, y + 2, at(C, 0.75));
+ }
+ p.glowLine(0, TOP, 0, tip, w * 1.6 + 3, at(C, 0.65), 0.45);
+ }
+ // the landing: a ring racing out across the floor, sparks kicked up
+ const ring = seg(t, 0.06, 0.42);
+ if (ring > 0 && ring < 1) {
+ const e = ease.outCubic(ring);
+ p.ellipse(0, 0.5, 5 + 18 * e, 1.5 + 3 * e, at(C, 0.86), (d) => (d > 0.78 ? 1 - ring : 0));
+ }
+ burst(10, S, (r) => {
+ const age = t - 0.07, life = r.range(0.2, 0.4);
+ if (age < 0 || age > life) return;
+ const ang = -Math.PI / 2 + r.range(-1.3, 1.3), v = r.range(40, 90), [x, y] = fly(r.range(-4, 4), -1, Math.cos(ang) * v, Math.sin(ang) * v, age, 200, 1.5);
+ if (y > 0) return;
+ p.px(x, y, age / life < 0.5 ? WHITE : at(C, 0.75));
+ });
+ // the character, written in row by row from the feet: a white write head, scanlines behind it, then it steps out
+ if (rows > 0 && reveal < 1)
+ for (let my = m.h - rows; my < m.h; my++)
+ for (let mx = 0; mx < m.w; mx++) {
+ if (!m.data[my * m.w + mx]) continue;
+ const head = my === m.h - rows && fill < 1;
+ p.dot(a.x + mx, a.y + my, flash || head ? WHITE : (my & 1) ? at(C, 0.84) : at(C, 0.68), 1 - reveal);
+ }
+ // motes rising through the beam, then off the character as it settles
+ cycle(t, meta.duration, 10, S + 1, (r) => r.range(0.4, 0.7), (age, life, r) => {
+ if (t > 1.3) return;
+ const k = age / life, x = r.range(-5, 5), y = -1 - age * r.range(30, 60);
+ if (Math.abs(x) > w + 2 && t < 1) return;
+ p.px(x, y, k < 0.4 ? WHITE : at(C, 0.7));
+ });
+ const glow = seg(t, 0, 0.1) * (1 - seg(t, 0.9, 1.4));
+ p.glow(0, -10, 24, at(C, 0.62), 0.4 * glow);
+ if (flash) p.glow(0, -10, 16, WHITE, 0.4);
+}
diff --git a/src/fx/spawn/shatter-death.js b/src/fx/spawn/shatter-death.js
new file mode 100644
index 0000000..0c6e3d7
--- /dev/null
+++ b/src/fx/spawn/shatter-death.js
@@ -0,0 +1,113 @@
+import { PAL, ramp, at, rng, burst, fly, seg, luma, TAU, WHITE } from "../../core/index.js";
+import { actorOf, actorPixels, steps } from "./_lib.js";
+
+export const meta = {
+ name: "Shatter death",
+ desc: "Frozen solid from the feet up, cracks race across the ice statue, then it bursts into tumbling shards that bounce across the floor and melt away.",
+ tags: ["spawn", "death", "ice", "freeze", "shatter", "one-shot"],
+ size: [84, 48],
+ origin: [42, 44],
+ duration: 1.8,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ actor: false,
+ options: { palette: PAL.ice, shards: 11, seed: 27 },
+};
+
+const FREEZE = [0.06, 0.3], CRACK = 0.32, BREAK = 0.52, G = 340, E = 0.3;
+const memo = new WeakMap();
+
+/** Cut the silhouette into shards: every pixel goes to its nearest seed point. */
+function shardsOf(actor, n, seed, C) {
+ const key = `${n}:${seed}`;
+ let byMask = memo.get(actor.mask);
+ if (!byMask) memo.set(actor.mask, (byMask = new Map()));
+ if (byMask.has(key)) return byMask.get(key);
+ const px = actorPixels(actor, C), r = rng(seed, 7), seeds = [];
+ for (let i = 0; i < n; i++) seeds.push(px[Math.floor(r.next() * px.length)]);
+ const shards = seeds.map(() => ({ px: [], cx: 0, cy: 0 })), owner = new Map();
+ for (const q of px) {
+ let best = 0, bd = Infinity;
+ seeds.forEach((s, i) => {
+ const d = (q.x - s.x) ** 2 + ((q.y - s.y) * 0.8) ** 2;
+ if (d < bd) (bd = d), (best = i);
+ });
+ shards[best].px.push({ ...q });
+ owner.set(`${q.x},${q.y}`, best);
+ }
+ for (const s of shards) {
+ s.cx = s.px.reduce((a, q) => a + q.x + 0.5, 0) / (s.px.length || 1);
+ s.cy = s.px.reduce((a, q) => a + q.y + 0.5, 0) / (s.px.length || 1);
+ s.grid = new Map(s.px.map((q) => [`${q.x},${q.y}`, q]));
+ s.R = Math.max(...s.px.map((q) => Math.hypot(q.x + 0.5 - s.cx, q.y + 0.5 - s.cy))) + 1;
+ }
+ // pixels on a border between two shards are where the cracks run
+ shards.forEach((s, me) => {
+ for (const q of s.px)
+ q.crack = [[1, 0], [0, 1]].some(([dx, dy]) => {
+ const o = owner.get(`${q.x + dx},${q.y + dy}`);
+ return o !== undefined && o !== me;
+ });
+ });
+ const out = shards.filter((s) => s.px.length);
+ byMask.set(key, out);
+ return out;
+}
+
+/** A shard's flight: launched, falling, bouncing once or twice, then sliding to rest. Returns [x, y, angle]. */
+function tumble(t, s, r) {
+ const dir = Math.sign(s.cx || r.sign()), vx = dir * r.range(12, 34) + s.cx * 2.5, spin = r.range(-7, 7);
+ let x = s.cx, y = s.cy, v = -r.range(40, 90) - (s.cy + 19) * 1.5, bx = vx, tt = t, ang = 0, w = spin;
+ const floor = -s.R * 0.6;
+ for (let n = 0; n < 3; n++) {
+ const T = (-v + Math.sqrt(v * v + 2 * G * (floor - y))) / G;
+ if (tt < T) return [x + bx * tt, y + v * tt + 0.5 * G * tt * tt, ang + w * tt];
+ (tt -= T), (x += bx * T), (y = floor), (ang += w * T), (v = -(v + G * T) * E), (bx *= 0.5), (w *= 0.4);
+ }
+ const slide = 1 - Math.exp(-tt * 6);
+ return [x + (bx / 6) * slide, floor, ang + (w / 6) * slide];
+}
+
+export function draw(p, t, o) {
+ const C = steps(ramp(o.palette), 8), S = o.seed, actor = actorOf(o), top = actor.y, H = actor.h;
+ const ice = (q) => at(C, 0.3 + luma(q.c) * 0.75);
+ if (t < BREAK) {
+ const fr = seg(t, FREEZE[0], FREEZE[1]), cr = seg(t, CRACK, BREAK - 0.04);
+ const shards = shardsOf(actor, o.shards, S, C);
+ for (const s of shards)
+ for (const q of s.px) {
+ const v = 1 - (q.y - top) / H; // 0 at the feet, 1 at the head
+ let c = q.c;
+ if (v < fr * 1.1) c = Math.abs(v - fr * 1.1) < 0.07 && fr < 1 ? WHITE : ice(q);
+ // cracks: borders between shards turn white, spreading out from the middle of the body
+ if (q.crack && cr > 0 && Math.abs(q.y + 10) / 10 < cr * 1.2) c = WHITE;
+ p.px(q.x, q.y, t >= BREAK - 0.035 ? WHITE : c);
+ }
+ if (fr > 0) p.glow(0, -10, 18, C[5], 0.2 * fr);
+ return;
+ }
+ const te = t - BREAK, fade = 1 - seg(te, 0.85, 1.22);
+ // the shards: each tumbles as a rigid piece, catching a highlight as it turns
+ shardsOf(actor, o.shards, S, C).forEach((s, i) => {
+ const r = rng(S, 100 + i), [x, y, ang] = tumble(te, s, r), cs = Math.cos(ang), sn = Math.sin(ang);
+ const shine = Math.sin(ang * 2 + i) > 0.7; // a shard flashes as its face turns to the light
+ p.shade(x - s.R, y - s.R, x + s.R, y + s.R, (lx, ly, out) => {
+ if (ly > 0) return;
+ const dx = lx - x, dy = ly - y, q = s.grid.get(`${Math.floor(s.cx + dx * cs + dy * sn)},${Math.floor(s.cy - dx * sn + dy * cs)}`);
+ if (!q) return;
+ out.a = fade;
+ return te < 0.04 ? WHITE : shine && (q.crack || q.y < s.cy - 1) ? at(C, 0.95) : ice(q);
+ });
+ });
+ // the burst: a white flash, frost glitter flung out
+ if (te < 0.06) p.glow(0, -10, 30, C[6], 0.6);
+ burst(16, S + 3, (r) => {
+ const a = r.range(0, TAU), v = r.range(50, 110), life = r.range(0.3, 0.6);
+ if (te > life) return;
+ const k = te / life, [x, y] = fly(r.range(-4, 4), -10 + r.range(-6, 6), Math.cos(a) * v, Math.sin(a) * v - 30, te, 160, 2.5);
+ if (y > -1 || (k > 0.6 && Math.floor(te * 24 + r.next() * 4) % 2)) return;
+ p.px(x, y, k < 0.4 ? WHITE : at(C, 0.75));
+ p.light(x, y, C[5], 0.35 * (1 - k));
+ });
+}
diff --git a/src/fx/spawn/skull-pop.js b/src/fx/spawn/skull-pop.js
new file mode 100644
index 0000000..87b8e9b
--- /dev/null
+++ b/src/fx/spawn/skull-pop.js
@@ -0,0 +1,60 @@
+import { PAL, ramp, at, burst, seg, ease, bump, WHITE } from "../../core/index.js";
+import { cloud, steps } from "./_lib.js";
+
+export const meta = {
+ name: "Skull pop",
+ desc: "A death marker: a skull springs up out of a puff, bobs while its jaw chatters, then floats higher and blinks out.",
+ tags: ["spawn", "death", "skull", "marker", "cartoon", "one-shot"],
+ size: [36, 48],
+ origin: [18, 44],
+ duration: 1.5,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ options: { palette: PAL.bone, seed: 23 },
+};
+
+const SKULL = [
+ "...ooooo...",
+ "..owwwwho..",
+ ".owwwwwwho.",
+ "owwwwwwwwho",
+ "owddwwwddwo",
+ "owddwwwddwo",
+ "owwwwdwwwwo",
+ ".oswwwwwso.",
+ "..ooooooo..",
+];
+const JAW = [
+ "..owtwtwo..",
+ "...ooooo...",
+];
+
+export function draw(p, t, o) {
+ const C = steps(ramp(o.palette), 7), S = o.seed;
+ const pal = { o: C[1], w: at(C, 0.84), h: WHITE, d: C[0], s: at(C, 0.6), t: at(C, 0.84) };
+ // a quick cartoon puff it springs out of
+ const balls = [];
+ burst(6, S, (r, i) => {
+ const a = (i / 6) * Math.PI * 2 + r.range(-0.3, 0.3), e = ease.outCubic(seg(t, 0, 0.12)), gone = seg(t, 0.12 + r.range(0, 0.08), 0.36 + r.range(0, 0.08));
+ balls.push({ x: Math.cos(a) * 6 * e, y: -8 + Math.sin(a) * 4 * e, r: r.range(3, 4.2) * (0.4 + 0.6 * e) * (1 - gone) });
+ });
+ cloud(p, balls, ramp(["#2c2840", "#5a5478", "#8e88aa", "#c4bed8", "#ecebf6"]), { inside: (x, y) => y < 0 });
+ // the skull: springs up with an overshoot, bobs, then drifts up and blinks out
+ const rise = ease.outBack(seg(t, 0.04, 0.26), 2.2), late = seg(t, 0.95, 1.4);
+ const y = Math.round(-6 - 20 * rise - 8 * ease.inQuad(late) + Math.sin(t * 7) * 1.2 * seg(t, 0.26, 0.4));
+ // its shadow on the floor, shrinking as it rises
+ if (t > 0.04 && late < 1) p.ellipse(0, 0.5, 5 - 2 * rise - 2 * late, 1, C[0], 0.6);
+ if (t < 0.05 || late >= 1 || (late > 0.35 && Math.floor(t * 20) % 2 === 0)) return;
+ const chatter = t > 0.36 && t < 0.86 && Math.floor(t * 15) % 2 === 0 ? 1 : 0;
+ p.sprite(SKULL, pal, -5, y - 11);
+ p.sprite(JAW, pal, -5, y - 2 + chatter);
+ if (chatter) p.line(-2, y - 2, 2, y - 2, C[0]);
+ // a glint on the crown as it snaps into place
+ const g = bump(t, 0.2, 0.42);
+ if (g > 0) {
+ const s = g > 0.5 ? 2 : 1;
+ p.line(3 - s, y - 11, 3 + s, y - 11, WHITE), p.line(3, y - 11 - s, 3, y - 11 + s, WHITE);
+ }
+ p.glow(0, y - 6, 14, at(C, 0.8), 0.2 * (1 - late));
+}
diff --git a/src/fx/spawn/soul-rise.js b/src/fx/spawn/soul-rise.js
new file mode 100644
index 0000000..3883692
--- /dev/null
+++ b/src/fx/spawn/soul-rise.js
@@ -0,0 +1,59 @@
+import { ramp, at, cycle, stream, seg, ease, bump, stockActor, TAU, WHITE } from "../../core/index.js";
+import { actorOf, stretchMask } from "./_lib.js";
+
+export const meta = {
+ name: "Soul rise",
+ desc: "The body's outline flares as a pale copy of it lifts out, legs trailing off into a rippling wisp, sways as it climbs and thins away into motes.",
+ tags: ["spawn", "death", "soul", "spirit", "ghost", "one-shot"],
+ size: [48, 80],
+ origin: [24, 74],
+ duration: 2.1,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ actor: true,
+ options: { palette: ["#14203a", "#24406a", "#3c6aa4", "#64a0d8", "#9cd0f4", "#d8f4ff", "#ffffff"], height: 40, seed: 27 },
+};
+
+// the stock character's eyes, in mask coordinates: the soul keeps them as hollows
+const EYES = new Set(["4,5", "4,6", "7,5", "7,6"]);
+
+export function draw(p, t, o) {
+ const C = ramp(o.palette), S = o.seed, a = actorOf(o), m = a.mask, stock = m === stockActor().mask;
+ // the body gives up its light: an outline that flares and dies away
+ const shine = bump(t, 0, 0.55);
+ if (shine > 0.05) p.outline(m, a.x, a.y, shine > 0.5 ? WHITE : at(C, 0.75), Math.min(1, shine * 1.5));
+ // the soul: lifts out, stretching tall and thin, its legs trailing into a wisp
+ const u = seg(t, 0.1, 1.8), lift = ease.inOutSine(u), fade = 1 - seg(t, 1.2, 1.75);
+ const yb = -lift * o.height, sway = Math.sin(t * 3.4) * 3 * seg(t, 0.15, 0.6), sx = 1 - 0.15 * lift, sy = 1 + 0.25 * lift;
+ const waist = Math.round(m.h * 0.62), legs = m.h - waist, wisp = seg(t, 0.1, 0.5);
+ if (fade > 0)
+ stretchMask(p, a, sway, yb, sx, sy, (mx, my, edge, out) => {
+ let alpha = 1;
+ if (my >= waist) {
+ // below the waist the legs melt into a tapering wisp that ripples
+ const k = (my - waist + 1) / legs, w = (1 - k * wisp) * m.w * 0.5 - k * wisp * 0.5, c = m.w / 2 + Math.sin(my * 0.9 - t * 9) * 1.5 * k * wisp;
+ if (Math.abs(mx + 0.5 - c) > w) return;
+ alpha = 1 - k * wisp * 0.55;
+ }
+ out.a = fade * alpha;
+ if (stock && EYES.has(`${mx},${my}`)) return C[1];
+ if (edge) return at(C, 0.52);
+ return my < 4 ? at(C, 0.92) : my < waist ? at(C, 0.8) : at(C, 0.66);
+ });
+ // motes: a few circling it on the way up, then the rest of it breaks into motes that rise and wink out
+ const cx = sway, cy = yb - m.h * 0.5 * sy;
+ cycle(t, meta.duration, 8, S, (r) => r.range(0.5, 0.8), (age, life, r) => {
+ if (t < 0.2 || t > 1.5) return;
+ const k = age / life, th = r.range(0, TAU) + age * 5, R = 9 - k * 3;
+ p.px(cx + Math.cos(th) * R, cy + Math.sin(th) * R * 1.4 - age * 6, k < 0.5 ? at(C, 0.92) : at(C, 0.7));
+ });
+ stream(t, 1.15, 1.7, 40, S + 1, (r) => r.range(0.25, 0.4), (age, life, r, i) => {
+ const t0 = 1.15 + i / 40, l0 = ease.inOutSine(seg(t0, 0.1, 1.8)), k = age / life;
+ const x = Math.sin(t0 * 3.4) * 3 + r.range(-5, 5), y = -l0 * o.height - r.range(2, m.h * 1.2) - age * r.range(10, 22);
+ if (k > 0.6 && Math.floor(age * 24) % 2) return;
+ p.px(x, y, k < 0.4 ? WHITE : at(C, 0.75));
+ });
+ // light: a cold glow that travels with it
+ p.glow(cx, cy, 22, at(C, 0.7), 0.3 * fade * seg(t, 0.05, 0.3));
+}
diff --git a/src/fx/spawn/spawn-portal.js b/src/fx/spawn/spawn-portal.js
new file mode 100644
index 0000000..1b9f322
--- /dev/null
+++ b/src/fx/spawn/spawn-portal.js
@@ -0,0 +1,64 @@
+import { PAL, ramp, at, burst, fly, seg, ease, fract, clamp, TAU, WHITE } from "../../core/index.js";
+import { smoke, steps } from "./_lib.js";
+
+export const meta = {
+ name: "Spawn portal",
+ desc: "A swirling rift tears open flat on the floor, belches a column of violet smoke and sparks as something comes through, then twists shut with a pop.",
+ tags: ["spawn", "portal", "summon", "arcane", "ground", "one-shot"],
+ size: [64, 64],
+ origin: [32, 56],
+ duration: 1.7,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ options: { palette: PAL.arcane, width: 17, seed: 31 },
+};
+
+const OPEN = [0, 0.3], PUFF = 0.3, SHUT = [1.05, 1.3];
+
+export function draw(p, t, o) {
+ const C = steps(ramp(o.palette), 8), S = o.seed;
+ const open = ease.outBack(seg(t, OPEN[0], OPEN[1]), 1.8) * (1 - ease.inBack(seg(t, SHUT[0], SHUT[1]), 2));
+ const rx = o.width * Math.max(0, open), ry = rx * 0.3;
+ // the rift: a flattened whirl lying on the floor, spiral arms turning into the dark, a bright lip
+ if (rx > 1) {
+ const inner = [C[0], C[1], C[2], C[3], C[4], C[5]];
+ p.shade(-rx - 1, -ry - 1, rx + 1, ry + 1, (x, y, out) => {
+ const dx = x / rx, dy = y / ry, d = Math.sqrt(dx * dx + dy * dy), a = Math.atan2(dy, dx);
+ if (d > 1) return;
+ if (d > 0.84) return d > 0.93 ? at(C, 0.98) : at(C, 0.82);
+ const arm = fract((a / TAU) * 3 - Math.log(d + 0.06) * 0.85 - t * 2.5), band = 0.5 + 0.5 * Math.sin(arm * TAU);
+ return at(inner, d * 0.7 + band * 0.42 - 0.12);
+ });
+ }
+ // the puff: violet smoke shoved up out of the rift, spreading into a mushroom and thinning away
+ const list = [];
+ burst(14, S, (r, i) => {
+ const age = t - PUFF - r.range(0, 0.06), life = r.range(0.6, 0.85);
+ if (age < 0 || age > life) return;
+ const k = i / 13, q = age / life, e = ease.outCubic(seg(age, 0, 0.35)), h = k * r.range(24, 32);
+ // a column that widens as it climbs: low puffs stay narrow, the top ones roll out sideways
+ const spread = (r.next() * 2 - 1) * (1.5 + k * k * 11) * e;
+ list.push({ x: spread, y: -2 - h * e - age * 6, r: (2.6 + k * 3.2) * (0.5 + 0.6 * e) * (1 + 0.4 * q), v: 1 - q * q });
+ });
+ smoke(p, list, [C[1], C[2], C[3], C[4], C[5]], { base: 0.3, lit: 0.25, seed: S, inside: (x, y) => y < 1 });
+ // sparks thrown up with it
+ burst(14, S + 1, (r) => {
+ const age = t - PUFF, life = r.range(0.35, 0.65);
+ if (age < 0 || age > life) return;
+ const a = -Math.PI / 2 + r.range(-0.6, 0.6), v = r.range(60, 120), [x, y] = fly(r.range(-6, 6), -1, Math.cos(a) * v, Math.sin(a) * v, age, 140, 1.2), k = age / life;
+ if (y > -1 || (k > 0.6 && Math.floor(age * 24 + r.next() * 4) % 2)) return;
+ p.px(x, y, k < 0.3 ? WHITE : k < 0.6 ? at(C, 0.86) : at(C, 0.6));
+ p.light(x, y, at(C, 0.75), 0.4 * (1 - k));
+ });
+ // the pop as it closes: a white star on the floor for a few frames
+ const pop = seg(t, SHUT[1] - 0.02, SHUT[1] + 0.12);
+ if (pop > 0 && pop < 1) {
+ const L = Math.round(2 + 6 * (1 - pop));
+ p.line(-L, 0, L, 0, at(C, 0.9)), p.line(0, -L * 0.6, 0, L * 0.4, at(C, 0.9)), p.px(0, 0, WHITE);
+ }
+ // light: the rift lights the air above it, flaring with the puff
+ const lit = clamp(open) * 0.3 + 0.35 * Math.max(0, 1 - Math.abs(t - PUFF - 0.08) / 0.3);
+ p.glow(0, -2, 28, at(C, 0.6), lit);
+ if (pop > 0 && pop < 1) p.glow(0, 0, 12, WHITE, 0.4 * (1 - pop));
+}
diff --git a/src/fx/spawn/summon-rise.js b/src/fx/spawn/summon-rise.js
new file mode 100644
index 0000000..cfd76b0
--- /dev/null
+++ b/src/fx/spawn/summon-rise.js
@@ -0,0 +1,97 @@
+import { PAL, RAMP, ramp, at, burst, fly, seg, ease, bump, rand, TAU, WHITE, hex } from "../../core/index.js";
+import { smoke, onCanvas } from "./_lib.js";
+
+export const meta = {
+ name: "Summon rise",
+ desc: "A rune circle smoulders on the floor, the ground splits, and a hunched horned shape heaves up out of it in a burst of dust, eyes flaring, before it fades.",
+ tags: ["spawn", "summon", "demon", "rise", "dust", "ground", "one-shot"],
+ size: [80, 60],
+ origin: [40, 52],
+ duration: 2.2,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ options: { palette: PAL.lava, seed: 32 },
+};
+
+// a hunched, horned brute: x is body, e the eyes; the rim light is worked out from the shape
+const BEAST = [
+ "x....................x",
+ "xx..................xx",
+ ".xx................xx.",
+ "..xx....xxxxxx....xx..",
+ "...xx..xxxxxxxx..xx...",
+ "....xxxxxxxxxxxxxx....",
+ ".....xxxexxxxexxx.....",
+ "....xxxxxxxxxxxxxx....",
+ "...xxxxxxxxxxxxxxxx...",
+ "..xxxxxxxxxxxxxxxxxx..",
+ ".xxxxxxxxxxxxxxxxxxxx.",
+ ".xxx.xxxxxxxxxxxx.xxx.",
+ "xxx..xxxxxxxxxxxx..xxx",
+ "xx...xxxxxxxxxxxx...xx",
+ "x.x..xxxxxxxxxxxx..x.x",
+ ".....xxxxxxxxxxxx.....",
+ ".....xxxxx..xxxxx.....",
+ ".....xxxx....xxxx.....",
+ "....xxxx......xxxx....",
+ "...xxxxx......xxxxx...",
+];
+const W = BEAST[0].length, H = BEAST.length;
+const BODY = hex("#2a1626");
+const RISE = [0.3, 0.95], FADE = [1.55, 1.95];
+
+export function draw(p, t, o) {
+ const C = ramp(o.palette), S = o.seed, D = RAMP.dust, inside = onCanvas(meta, 2);
+ // the rune circle: a ring and spokes scorched into the floor, smouldering, then cooling
+ const rune = seg(t, 0, 0.25) * (1 - seg(t, 1.5, 2.0)), hot = 0.6 + 0.4 * Math.sin(t * 20) * (1 - seg(t, 0.3, 1));
+ if (rune > 0) {
+ p.ellipse(0, 1, 22 * rune, 4 * rune, (d) => (d > 0.82 ? at(C, 0.4 + 0.35 * hot) : at(C, 0.12)), (d) => (d > 0.82 ? 1 : d > 0.7 ? 0 : 0.35 * rune));
+ for (let i = 0; i < 6; i++) {
+ const a = (i / 6) * TAU + 0.3, L = 20 * rune * (0.6 + 0.4 * rand(S, i));
+ p.line(0, 1, Math.cos(a) * L, 1 + Math.sin(a) * L * 0.18, at(C, 0.3 + 0.3 * hot));
+ }
+ p.glow(0, 0, 26, at(C, 0.55), 0.35 * rune * hot);
+ }
+ // the beast heaves up out of the floor, shaking, only what's above the floor showing
+ const up = ease.outCubic(seg(t, RISE[0], RISE[1])), fade = 1 - seg(t, FADE[0], FADE[1]);
+ const shake = up > 0 && up < 1 ? Math.round(Math.sin(t * 70) * 1) : 0;
+ const top = Math.round(-up * H + (1 - up) * 2), x0 = -W / 2 + shake;
+ if (up > 0 && fade > 0)
+ for (let j = 0; j < H; j++) {
+ const y = top + j;
+ if (y >= 0) break;
+ for (let i = 0; i < W; i++) {
+ const ch = BEAST[j][i];
+ if (ch === ".") continue;
+ // lit by the rune from below and by its glow along the top-left edges; shadowed on the right
+ const lit = i === 0 || BEAST[j][i - 1] === "." || j === 0 || BEAST[j - 1][i] === ".";
+ const dark = i === W - 1 || BEAST[j][i + 1] === ".";
+ let c = lit ? at(C, 0.42) : dark ? at(C, 0.12) : y > -4 && rune > 0.3 ? at(C, 0.2) : BODY;
+ if (ch === "e") c = t > 0.85 ? (bump(t, 0.85, 1.25) > 0.6 ? WHITE : at(C, 0.92)) : at(C, 0.5);
+ p.dot(x0 + i, y, c, fade);
+ }
+ }
+ // the eyes: they flare once it's up, and stay lit
+ if (t > 0.85 && fade > 0) {
+ const ey = top + 6, k = (0.4 + 0.6 * bump(t, 0.85, 1.3)) * fade;
+ p.glow(x0 + 8.5, ey, 6, at(C, 0.8), 0.6 * k), p.glow(x0 + 13.5, ey, 6, at(C, 0.8), 0.6 * k);
+ }
+ // dust: billows thrown out along the floor as it breaks through, rising and thinning
+ const dust = [];
+ burst(12, S + 1, (r, i) => {
+ const age = t - RISE[0] - r.range(0, 0.25), life = r.range(0.7, 1.1);
+ if (age < 0 || age > life) return;
+ const q = age / life, side = i % 2 ? 1 : -1, e = ease.outCubic(seg(age, 0, 0.5));
+ dust.push({ x: side * (8 + r.range(2, 22) * e), y: -2 - r.range(0, 6) * e - q * r.range(4, 10), r: r.range(3, 5.5) * (0.5 + 0.6 * e), v: (1 - q) ** 1.2 });
+ });
+ smoke(p, dust, [D[2], D[3], D[4], D[5], D[6]], { base: 0.3, seed: S, inside: (x, y) => y < 1 });
+ // rubble: chunks of floor flung up and falling back
+ burst(10, S + 2, (r) => {
+ const age = t - RISE[0] - r.range(0, 0.1), life = 0.7;
+ if (age < 0 || age > life) return;
+ const a = -Math.PI / 2 + r.range(-1.2, 1.2), v = r.range(60, 120), [x, y] = fly(r.range(-10, 10), -1, Math.cos(a) * v, Math.sin(a) * v, age, 320, 0.4);
+ if (y > -1 || !inside(x, y)) return;
+ p.rect(x, y, r.chance(0.5) ? 2 : 1, r.chance(0.5) ? 2 : 1, r.chance(0.5) ? D[2] : D[3]);
+ });
+}
diff --git a/src/fx/spawn/teleport-sparkle.js b/src/fx/spawn/teleport-sparkle.js
new file mode 100644
index 0000000..5a0e364
--- /dev/null
+++ b/src/fx/spawn/teleport-sparkle.js
@@ -0,0 +1,69 @@
+import { PAL, ramp, at, burst, fly, seg, ease, lerp, TAU, WHITE } from "../../core/index.js";
+import { actorOf } from "./_lib.js";
+
+export const meta = {
+ name: "Teleport sparkle",
+ desc: "Sparkles spiral in around an empty spot, tightening into a whirling helix, then flash into the character's white silhouette, which fades to reveal them.",
+ tags: ["spawn", "teleport", "sparkle", "magic", "arrive", "one-shot"],
+ size: [52, 56],
+ origin: [26, 50],
+ duration: 1.3,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ actor: true,
+ options: { palette: PAL.neon, count: 14, seed: 30 },
+};
+
+const ARRIVE = 0.62;
+
+/** The stand-in (or your own sprite) isn't here until the sparkles arrive; a white copy covers it, then fades off. */
+export const actorAlpha = (t) => (t < ARRIVE ? 0 : 1);
+
+/** A twinkle: a 4-point star of size s (0: one pixel, 1: a plus, 2: long arms). */
+function twinkle(p, x, y, s, c, core) {
+ if (s >= 1) for (let i = 1; i <= s; i++) p.px(x + i, y, c), p.px(x - i, y, c), p.px(x, y + i, c), p.px(x, y - i, c);
+ p.px(x, y, core);
+}
+
+export function draw(p, t, o) {
+ const C = ramp(o.palette), S = o.seed, a = actorOf(o), m = a.mask, n = o.count;
+ // on arrival a white copy of the character covers it, then fades off to reveal it
+ if (t >= ARRIVE) {
+ const reveal = seg(t, ARRIVE + 0.06, ARRIVE + 0.38);
+ if (reveal < 1) p.mask(m, a.x, a.y, t < ARRIVE + 0.06 ? WHITE : at(C, 0.86), 1 - reveal);
+ }
+ // the helix: sparkles wheel in around the spot, tightening and speeding up, the far side dimmer
+ const conv = ease.inQuad(seg(t, 0, ARRIVE));
+ if (t < ARRIVE)
+ for (let i = 0; i < n; i++) {
+ const h = -2 - (i / (n - 1)) * (m.h - 3), base = (i / n) * TAU * 2.3;
+ const pos = (tt) => {
+ const cv = ease.inQuad(seg(tt, 0, ARRIVE)), th = base + tt * 6 + tt * tt * 14, R = lerp(16, 2, cv);
+ return [Math.cos(th) * R, h + Math.sin(th) * R * 0.22 - (1 - cv) * 3, Math.sin(th)];
+ };
+ const [x, y, z] = pos(t), front = z > 0;
+ for (let j = 2; j >= 1; j--) {
+ const [qx, qy] = pos(Math.max(0, t - j * 0.025));
+ p.px(qx, qy, j === 1 ? at(C, front ? 0.62 : 0.45) : at(C, front ? 0.45 : 0.32));
+ }
+ const tw = Math.floor(t * 20 + i * 1.7) % 4;
+ twinkle(p, x, y, front ? (tw === 0 ? 2 : 1) : tw === 0 ? 1 : 0, front ? at(C, 0.8) : at(C, 0.55), front ? WHITE : at(C, 0.7));
+ }
+ // the arrival: a flash ring, sparkles flung out, twinkling as they slow and fade
+ const te = t - ARRIVE;
+ if (te >= 0) {
+ const ring = seg(te, 0, 0.22);
+ if (ring < 1) p.ring(0, -10, 6 + 9 * ease.outCubic(ring), 1, at(C, 0.86), 1 - ring);
+ burst(12, S, (r, i) => {
+ const ang = r.range(0, TAU), v = r.range(50, 100), life = r.range(0.35, 0.6);
+ if (te > life) return;
+ const k = te / life, [x, y] = fly(0, -10, Math.cos(ang) * v, Math.sin(ang) * v * 0.8, te, 20, 4.5);
+ if (y > -1 || (k > 0.6 && Math.floor(te * 24 + i) % 2)) return;
+ twinkle(p, x, y, k < 0.25 ? 2 : k < 0.6 ? 1 : 0, at(C, 0.8), k < 0.5 ? WHITE : at(C, 0.7));
+ });
+ }
+ // light: gathers with the sparkles, bursts on arrival, lets go
+ const L = t < ARRIVE ? conv * 0.35 : 0.6 * Math.max(0, 1 - te / 0.45) ** 2;
+ p.glow(0, -10, 22, at(C, 0.62), L);
+}
diff --git a/src/fx/status/_lib.js b/src/fx/status/_lib.js
new file mode 100644
index 0000000..b6b1903
--- /dev/null
+++ b/src/fx/status/_lib.js
@@ -0,0 +1,81 @@
+// Shared bits for the status effects (files starting with _ are helpers, not effects).
+
+import { ramp, luma, clamp } from "../../core/index.js";
+
+/** The palette option resampled to exactly n steps (dark to bright), so fixed indices work for any ramp length. */
+export function steps(list, n = 8) {
+ const r = ramp(list);
+ return Array.from({ length: n }, (_, i) => r[Math.round((i * (r.length - 1)) / (n - 1))]);
+}
+
+const GEOM = new WeakMap();
+const M = 14; // how far around the mask the geometry reaches
+
+/**
+ * Geometry of an actor's mask, computed once: for every cell up to M px around it, the vector to the nearest
+ * mask pixel; plus the outline (cells just outside), the rim (mask cells on its edge) and each column's top.
+ * Cells are in mask space (0, 0 = the mask's top-left).
+ */
+export function geom(mask) {
+ let g = GEOM.get(mask);
+ if (g) return g;
+ const { w, h, data } = mask, on = (x, y) => x >= 0 && y >= 0 && x < w && y < h && data[y * w + x] > 0;
+ const pts = [];
+ for (let y = 0; y < h; y++) for (let x = 0; x < w; x++) if (on(x, y)) pts.push([x, y]);
+ const GW = w + 2 * M, GH = h + 2 * M, d = new Float32Array(GW * GH), vx = new Float32Array(GW * GH), vy = new Float32Array(GW * GH);
+ for (let gy = 0; gy < GH; gy++)
+ for (let gx = 0; gx < GW; gx++) {
+ const x = gx - M, y = gy - M, i = gy * GW + gx;
+ if (on(x, y)) continue;
+ let best = Infinity, bx = 0, by = 0;
+ for (const [px, py] of pts) {
+ const dd = (x - px) ** 2 + (y - py) ** 2;
+ if (dd < best) (best = dd), (bx = x - px), (by = y - py);
+ }
+ d[i] = Math.sqrt(best);
+ vx[i] = bx;
+ vy[i] = by;
+ }
+ const outline = [], rim = [], top = [];
+ for (let y = -1; y <= h; y++)
+ for (let x = -1; x <= w; x++) {
+ const n4 = on(x - 1, y) + on(x + 1, y) + on(x, y - 1) + on(x, y + 1);
+ if (!on(x, y) && n4) outline.push([x, y]);
+ if (on(x, y) && n4 < 4) rim.push([x, y]);
+ }
+ for (let x = 0; x < w; x++) {
+ let y = 0;
+ while (y < h && !on(x, y)) y++;
+ top.push(y);
+ }
+ g = {
+ on, outline, rim, top,
+ /** distance from mask cell (x, y) to the silhouette (0 inside), and the vector from the nearest mask pixel */
+ near(x, y) {
+ const gx = Math.floor(x) + M, gy = Math.floor(y) + M;
+ if (gx < 0 || gy < 0 || gx >= GW || gy >= GH) return null;
+ const i = gy * GW + gx;
+ return [d[i], vx[i], vy[i]];
+ },
+ };
+ GEOM.set(mask, g);
+ return g;
+}
+
+/**
+ * Recolor the actor: for every mask pixel, fn(under, mx, my) returns a new color (or 0 to leave it), where
+ * under is the color already drawn there (0 in a sprite sheet, where the character isn't drawn). Call it
+ * before drawing anything else in front, so `under` is the character.
+ */
+export function recolor(p, a, fn, alpha = 1) {
+ const m = a.mask;
+ for (let my = 0; my < m.h; my++)
+ for (let mx = 0; mx < m.w; mx++) {
+ if (!m.data[my * m.w + mx]) continue;
+ const x = a.x + mx, y = a.y + my, c = fn(p.get(x, y), mx, my);
+ if (c) p.dot(x, y, c, typeof alpha === "function" ? alpha(mx, my) : alpha);
+ }
+}
+
+/** Brightness of a drawn color spread to 0..1 (the stock character runs from ink outlines to light skin). */
+export const tone = (c) => clamp((luma(c) - 0.05) / 0.75);
diff --git a/src/fx/status/bleeding.js b/src/fx/status/bleeding.js
new file mode 100644
index 0000000..1eb9754
--- /dev/null
+++ b/src/fx/status/bleeding.js
@@ -0,0 +1,87 @@
+import { PAL, cycle, bump, clamp, TAU } from "../../core/index.js";
+import { steps, geom, recolor, tone } from "./_lib.js";
+
+export const meta = {
+ name: "Bleeding",
+ desc: "Dark red drops swell on the body, run a little, let go and spatter on the floor into a small pool; the target flinches red with each tick.",
+ tags: ["status", "bleed", "blood", "dot", "debuff", "loop"],
+ size: [36, 34],
+ origin: [18, 29],
+ duration: 1.6,
+ loop: true,
+ fps: 30,
+ bg: "ground",
+ actor: true,
+ options: { palette: PAL.blood, count: 5, seed: 8 },
+};
+
+const SPOTS = new WeakMap();
+// where blood runs off: the outermost pixel of each row on the left and right of the body, so drops fall clear of it;
+// and two wounds on the front of the torso
+function wounds(a) {
+ let s = SPOTS.get(a.mask);
+ if (s) return s;
+ const g = geom(a.mask), edges = [], front = [];
+ for (let y = 7; y < a.h * 0.75; y++) {
+ let x0 = -1, x1 = -1;
+ for (let x = 0; x < a.w; x++) if (g.on(x, y)) (x0 < 0 && (x0 = x)), (x1 = x);
+ if (x0 >= 0) edges.push([x0 - 0.5, y], [x1 + 1.5, y]);
+ }
+ for (const [x, y] of [[0.3, 0.64], [0.66, 0.54]]) front.push([Math.floor(a.w * x), Math.floor(a.h * y)]);
+ s = { edges, front };
+ SPOTS.set(a.mask, s);
+ return s;
+}
+
+export function draw(p, t, o) {
+ const B = steps(o.palette), a = o.actor, S = o.seed, D = meta.duration, ph = t / D;
+
+ // the tick: twice a loop the target flinches red for a frame or two
+ const tick = Math.max(bump(ph, 0.02, 0.1), bump(ph, 0.52, 0.6));
+ if (tick > 0.3) recolor(p, a, (c) => (c ? B[clamp(Math.round(2 + tone(c) * 5), 2, 6)] : 0), (mx, my) => (p.get(a.x + mx, a.y + my) ? 1 : 0));
+
+ // the pool at the feet, a pixel wider each time a drop lands
+ const spots = wounds(a);
+ let landed = 0;
+ // wounds on the front: small slashes that flare on the tick
+ for (const [mx, my] of spots.front) {
+ const x = a.x + mx, y = a.y + my;
+ p.px(x, y, tick > 0.3 ? B[6] : B[4]), p.px(x + 1, y - 1, B[3]), p.px(x - 1, y + 1, B[3]);
+ }
+ // drops: swell on a wound, run down a little, let go, fall, spatter
+ cycle(t, D, o.count, S, (r) => r.range(0.85, 1.15), (age, life, r) => {
+ const e = spots.edges, [mx, my] = e[Math.floor(r.next() * e.length)], x = a.x + mx, y0 = a.y + my + 0.5;
+ const run = r.range(1, 3), swell = 0.3, slide = 0.15;
+ if (age < swell) {
+ p.px(x, y0, B[4]);
+ if (age > swell * 0.5) p.px(x, y0 + 1, age > swell * 0.8 ? B[5] : B[4]);
+ return;
+ }
+ if (age < swell + slide) {
+ const yy = y0 + 1 + run * ((age - swell) / slide);
+ p.line(x, y0, x, yy, B[3]);
+ p.px(x, yy, B[5]), p.px(x, yy + 1, B[4]);
+ return;
+ }
+ if (age < swell + slide + 0.3) p.line(x, y0, x, y0 + run, B[3]);
+ const f = age - swell - slide, y = y0 + run + 1 + 160 * f * f, hit = Math.sqrt(Math.max(0, -1 - (y0 + run + 1)) / 160);
+ if (f < hit) {
+ p.px(x, y, B[6]), p.px(x, y - 1, B[4]);
+ if (f > 0.05) p.px(x, y - 2, B[3]);
+ return;
+ }
+ // spatter: two flecks jump out and drop
+ const s = (f - hit) / 0.22;
+ landed += s < 1 ? 1 : 0;
+ if (s >= 1) return;
+ const hop = Math.round(Math.sin(s * Math.PI) * 2);
+ p.px(x - 1 - Math.round(s * 3), -1 - hop, B[4]);
+ p.px(x + 1 + Math.round(s * 2), -1 - Math.round(hop * 0.6), B[3]);
+ p.line(x - 1, 0, x + 1, 0, B[3]);
+ });
+
+ // the pool: dark, with a lit lip, breathing a little
+ const w = 4 + Math.sin(ph * TAU) * 0.6 + landed * 0.5;
+ p.ellipse(1, 0.5, w, 1.3, (d, ang) => (d > 0.7 && Math.sin(ang) < 0 ? B[3] : B[1]));
+ p.light(1, 0, B[4], 0.15);
+}
diff --git a/src/fx/status/burning.js b/src/fx/status/burning.js
new file mode 100644
index 0000000..b3d09c2
--- /dev/null
+++ b/src/fx/status/burning.js
@@ -0,0 +1,66 @@
+import { PAL, cycle, tileFbm, loopNoise, clamp, at, TAU } from "../../core/index.js";
+import { steps, geom } from "./_lib.js";
+
+export const meta = {
+ name: "Burning",
+ desc: "Flames lick up the target's outline, tallest off the head and shoulders, tongues curl over the body, embers spit and drift up.",
+ tags: ["status", "fire", "burn", "dot", "debuff", "loop"],
+ size: [40, 50],
+ origin: [20, 45],
+ duration: 1,
+ loop: true,
+ fps: 30,
+ bg: "ground",
+ actor: true,
+ options: { palette: PAL.fire, seed: 4 },
+};
+
+const heatAt = (g, a, x, y, ph, S, tall) => {
+ const nr = g.near(x - a.x, y - a.y);
+ if (!nr || nr[0] === 0) return -1;
+ const [d, , vy] = nr, up = clamp(-vy / d), src = clamp(1 - (y - a.y - vy) / a.h); // 1 at the head, 0 at the feet
+ const n = tileFbm(x * 0.42, y * 0.28 + ph * 8, 0, 8, S, 2) * 0.5 + 0.5;
+ const reach = 0.5 + up * up * tall * (0.25 + 1.0 * n) * (0.35 + 0.65 * src) + (1 - up) * 4 * Math.max(0, n - 0.42) * (0.4 + src);
+ return [1 - d / reach, n];
+};
+
+// behind the body: the flame field around the silhouette, licking highest off upward-facing edges
+export function drawBack(p, t, o) {
+ const F = steps(o.palette), a = o.actor, g = geom(a.mask), ph = t / meta.duration;
+ const FIRE = [F[2], F[3], F[4], F[5], F[6], F[7]];
+ p.shade(a.x - 6, a.y - 15, a.x + a.w + 6, 0, (x, y) => {
+ const h = heatAt(g, a, x, y, ph, o.seed, 10);
+ if (h === -1 || h[0] <= 0) return;
+ return at(FIRE, h[0] * 0.95 + h[1] * 0.2);
+ });
+ const flick = 0.85 + 0.15 * loopNoise(ph, 2, o.seed);
+ p.glow(0, a.y + 6, 26 * flick, F[4], 0.32 * flick);
+}
+
+// in front: flames curling over the body's edges, tongues rising off it, embers
+export function draw(p, t, o) {
+ const F = steps(o.palette), a = o.actor, g = geom(a.mask), S = o.seed, D = meta.duration, ph = t / D;
+ for (const [mx, my] of g.rim) {
+ const x = a.x + mx, y = a.y + my, n = tileFbm(x * 0.42, y * 0.28 + ph * 8, 0, 8, S, 2);
+ if (n > 0.3 + (my / a.h) * 0.25) p.px(x, y, n > 0.5 ? F[6] : F[5]);
+ p.light(x, y, F[5], 0.2);
+ }
+ // tongues: little flames peeling off the body and rising
+ cycle(t, D, 7, S + 3, (r) => r.range(0.28, 0.4), (age, life, r) => {
+ const k = age / life, mx = Math.floor(r.range(0, a.w)), top = g.top[mx];
+ if (top >= a.h) return;
+ const x = a.x + mx + Math.sin(k * 5 + r.next() * 6) * 1.2, y = a.y + top + r.range(0, 6) - k * r.range(8, 14);
+ const s = (1 - k) * r.range(1.1, 1.8);
+ p.ellipse(x, y, s * 0.7, s * 1.5, k < 0.4 ? F[6] : F[5]);
+ if (k < 0.3) p.px(x, y + 1, F[7]);
+ });
+ // embers spit up and drift
+ cycle(t, D, 8, S + 5, (r) => r.range(0.6, 1), (age, life, r) => {
+ const k = age / life, x = a.x + r.range(-1, a.w + 1) + Math.sin(age * r.range(5, 9) + r.next() * TAU) * 2.5 * k;
+ const y = a.y + r.range(2, 10) - age * r.range(20, 30);
+ if (k > 0.5 && Math.sin(age * 40 + r.next() * 9) < -0.4) return;
+ p.px(x, y, k < 0.35 ? F[7] : k < 0.7 ? F[5] : F[4]);
+ p.light(x, y, F[5], 0.5 * (1 - k));
+ });
+ p.glow(0, a.y + 4, 9, F[6], 0.2);
+}
diff --git a/src/fx/status/charmed.js b/src/fx/status/charmed.js
new file mode 100644
index 0000000..81850f8
--- /dev/null
+++ b/src/fx/status/charmed.js
@@ -0,0 +1,63 @@
+import { bump, rng, TAU } from "../../core/index.js";
+import { steps } from "./_lib.js";
+
+export const meta = {
+ name: "Charmed",
+ desc: "A heart beats over the target's head, glowing pink on each beat, while little hearts bob up around it, sway and pop.",
+ tags: ["status", "charm", "love", "heart", "debuff", "loop"],
+ size: [44, 52],
+ origin: [22, 48],
+ duration: 2,
+ loop: true,
+ fps: 30,
+ bg: "ground",
+ actor: true,
+ options: {
+ palette: ["#2a0614", "#5a0c2c", "#9a1648", "#d62a6a", "#ff5a92", "#ff9ac0", "#ffd6e8", "#ffffff"],
+ count: 4, seed: 9,
+ },
+};
+
+const HEARTS = [
+ ["##.##", "#####", ".###.", "..#.."],
+ [".##.##.", "#######", "#######", ".#####.", "..###..", "...#..."],
+ [".##...##.", "####.####", "#########", "#########", ".#######.", "..#####..", "...###...", "....#...."],
+ [".###...###.", "#####.#####", "###########", "###########", "###########", ".#########.", "..#######..", "...#####...", "....###....", ".....#....."],
+];
+
+// a heart: outlined dark, a pale glint in its top-left lobe, the lower half a step deeper
+function heart(p, size, cx, cy, C, bright = 0) {
+ const rows = HEARTS[size], h = rows.length, w = rows[0].length, x = Math.round(cx - w / 2), y = Math.round(cy - h / 2);
+ const on = (c, r) => r >= 0 && r < h && c >= 0 && c < w && rows[r][c] === "#";
+ for (let r = -1; r <= h; r++)
+ for (let c = -1; c <= w; c++) if (!on(c, r) && (on(c - 1, r) || on(c + 1, r) || on(c, r - 1) || on(c, r + 1))) p.px(x + c, y + r, C[1]);
+ for (let r = 0; r < h; r++)
+ for (let c = 0; c < w; c++) {
+ if (!on(c, r)) continue;
+ const glint = size > 0 && r === 1 && c === 1, deep = r >= h / 2 + 1;
+ p.px(x + c, y + r, glint ? C[7] : deep ? C[3 + bright] : C[4 + bright]);
+ }
+}
+
+export function draw(p, t, o) {
+ const C = steps(o.palette), a = o.actor, D = meta.duration, ph = t / D, n = o.count;
+ const hx = a.head[0], hy = a.head[1] - 9;
+
+ // small hearts: born around the head in turn, popping in, swaying up, shrinking out
+ for (let i = 0; i < n; i++) {
+ const r = rng(o.seed, i), born = (i * D) / n, life = D * 0.7, age = (((t - born) % D) + D) % D;
+ if (age >= life) continue;
+ const k = age / life, side = i % 2 ? 1 : -1;
+ const x = hx + side * (r.range(8, 11) + k * 3) + Math.sin(k * TAU * 1.5 + i) * 1.4, y = hy + 13 - k * r.range(16, 21);
+ const size = k > 0.25 && k < 0.55 && i % 2 === 0 ? 1 : 0;
+ heart(p, size, x, y, C, k < 0.4 ? 1 : 0);
+ p.light(x, y, C[5], 0.2);
+ }
+
+ // the big heart: two beats a loop, swelling for a frame on each and flashing a step brighter
+ const beat = Math.max(bump(ph, 0, 0.1), bump(ph, 0.16, 0.26), bump(ph, 0.5, 0.6), bump(ph, 0.66, 0.76));
+ const bob = Math.sin(ph * TAU) * 1.2;
+ heart(p, beat > 0.5 ? 3 : 2, hx, hy + bob, C, beat > 0.5 ? 1 : 0);
+ p.glow(hx, hy + bob, 16, C[5], 0.25 + 0.3 * beat);
+ p.glow(hx, a.y + 9, 20, C[4], 0.1 + 0.1 * beat);
+}
diff --git a/src/fx/status/confused.js b/src/fx/status/confused.js
new file mode 100644
index 0000000..2fbe909
--- /dev/null
+++ b/src/fx/status/confused.js
@@ -0,0 +1,56 @@
+import { PAL, seg, ease, rng, TAU } from "../../core/index.js";
+import { steps } from "./_lib.js";
+
+export const meta = {
+ name: "Confused",
+ desc: "A swirl spins over the head while question marks pop up on either side in turn, bounce, wobble and fade.",
+ tags: ["status", "confused", "dizzy", "question", "debuff", "loop"],
+ size: [44, 48],
+ origin: [22, 44],
+ duration: 1.8,
+ loop: true,
+ fps: 30,
+ bg: "ground",
+ actor: true,
+ options: { palette: PAL.cyber, count: 3, seed: 7 },
+};
+
+// a question mark, 5 x 7
+const Q = [".###.", "#...#", "....#", "...#.", "..#..", ".....", "..#.."];
+const SPOTS = [[-11, 1], [7, -1], [-3, -9]]; // where each mark pops up, around the swirl
+
+function mark(p, rows, x, y, body, edge) {
+ const h = rows.length, w = rows[0].length, on = (c, r) => r >= 0 && r < h && c >= 0 && c < w && rows[r][c] === "#";
+ for (let r = -1; r <= h; r++)
+ for (let c = -1; c <= w; c++) if (!on(c, r) && (on(c - 1, r) || on(c + 1, r) || on(c, r - 1) || on(c, r + 1))) p.px(x + c, y + r, edge);
+ for (let r = 0; r < h; r++) for (let c = 0; c < w; c++) if (on(c, r)) p.px(x + c, y + r, r < 2 ? body[1] : body[0]);
+}
+
+export function draw(p, t, o) {
+ const C = steps(o.palette), a = o.actor, D = meta.duration, ph = t / D, n = o.count;
+ const cx = a.head[0], cy = a.head[1] - 6;
+
+ // the swirl: a spiral turning twice a loop, squashed into a lazy oval
+ const turn = ph * TAU * 2, pts = [];
+ for (let i = 0; i <= 26; i++) {
+ const s = i / 26, ang = turn + s * TAU * 1.6, r = 0.6 + s * 5.4;
+ pts.push([cx + Math.cos(ang) * r, cy + Math.sin(ang) * r * 0.55]);
+ }
+ for (let i = 1; i < pts.length; i++) p.line(...pts[i - 1], ...pts[i], i > 20 ? C[7] : i > 10 ? C[6] : C[5]);
+ p.light(cx, cy, C[5], 0.3);
+
+ // question marks: one after another, alternating sides, popping in with a bounce, drifting up, fading
+ for (let i = 0; i < n; i++) {
+ const born = (i * D) / n, life = D * 0.62, age = (((t - born) % D) + D) % D;
+ if (age >= life) continue;
+ const r = rng(o.seed, i), k = age / life, pop = ease.outBack(seg(k, 0, 0.18), 3), [sx, sy] = SPOTS[i % SPOTS.length];
+ const wob = Math.round(Math.sin(k * TAU * 2.5 + r.range(0, TAU))) + r.int(-1, 1);
+ const x = cx + sx + wob, y = cy + sy - 3 - k * 5 + (1 - pop) * 4;
+ if (pop <= 0.05) continue;
+ const fade = seg(k, 0.7, 1);
+ if (fade > 0.8) continue;
+ const body = fade > 0.4 ? [C[5], C[6]] : [C[6], C[7]];
+ mark(p, Q, Math.round(x), Math.round(y), body, fade > 0.4 ? C[1] : C[2]);
+ p.light(x + 2, y + 3, C[6], 0.25 * (1 - fade));
+ }
+}
diff --git a/src/fx/status/cursed.js b/src/fx/status/cursed.js
new file mode 100644
index 0000000..483cddf
--- /dev/null
+++ b/src/fx/status/cursed.js
@@ -0,0 +1,74 @@
+import { cycle, bump, rand, clamp, TAU } from "../../core/index.js";
+import { steps, geom, recolor, tone } from "./_lib.js";
+
+export const meta = {
+ name: "Cursed",
+ desc: "Violet wisps curl up off the target and a stain spreads under its feet; twice a loop a skull glitches in over its head and is gone.",
+ tags: ["status", "curse", "shadow", "skull", "debuff", "loop"],
+ size: [44, 52],
+ origin: [22, 47],
+ duration: 2,
+ loop: true,
+ fps: 30,
+ bg: "ground",
+ actor: true,
+ options: { palette: ["#07040c", "#170b28", "#2c1049", "#481872", "#6e22a0", "#9a3acb", "#cc70ec", "#f6d2ff"], seed: 6 },
+};
+
+const SKULL = [".#####.", "#######", "#ee#ee#", "#ee#ee#", "###n###", ".#####.", ".#t#t#."];
+
+// wisps: thin wavering trails of smoke drifting up from all around the silhouette, bright at their heads
+function wisps(p, t, o, back) {
+ const C = steps(o.palette), a = o.actor, g = geom(a.mask), D = meta.duration;
+ const src = g.outline.filter(([, y]) => y < a.h - 3);
+ cycle(t, D, back ? 6 : 5, o.seed + (back ? 0 : 50), (r) => r.range(0.9, 1.4), (age, life, r) => {
+ const [mx, my] = src[Math.floor(r.next() * src.length)], x0 = a.x + mx + 0.5, y0 = a.y + my;
+ const k = age / life, sway = r.range(1.2, 2.4), ph0 = r.range(0, TAU), speed = r.range(7, 11), len = r.range(5, 8);
+ const out = mx < a.w / 2 ? -1 : 1, pts = [];
+ for (let j = 0; j <= 6; j++) {
+ const s = j / 6, yy = y0 - age * speed - (1 - s) * len * Math.min(1, k * 4);
+ const x = x0 + out * age * 3 + Math.sin(yy * 0.45 + ph0 + t * 4) * sway;
+ pts.push([x, yy]);
+ }
+ const fade = k > 0.7 ? 1 : 0;
+ for (let j = 1; j < pts.length; j++) {
+ const c = fade ? (j < 3 ? C[4] : C[2]) : j < 2 ? C[6] : j < 4 ? C[5] : C[3];
+ if (back) p.beam(...pts[j - 1], ...pts[j], 2, j < 3 ? C[4] : C[2]);
+ else p.line(...pts[j - 1], ...pts[j], c);
+ }
+ if (!back && !fade) p.light(...pts[0], C[5], 0.25);
+ });
+}
+
+export function drawBack(p, t, o) {
+ const C = steps(o.palette), a = o.actor;
+ // the stain spreading under the feet
+ const ph = t / meta.duration, w = a.w / 2 + 5 + Math.sin(ph * TAU) * 0.8;
+ p.ellipse(0, 0.5, w, 1.6, (d) => (d > 0.75 ? C[3] : C[1]));
+ wisps(p, t, o, true);
+ p.glow(0, a.y + 8, 22, C[4], 0.16);
+}
+
+export function draw(p, t, o) {
+ const C = steps(o.palette), a = o.actor, S = o.seed, ph = t / meta.duration;
+ // the curse creeping up from the feet: the lowest rows darken toward violet, breathing
+ const reach = a.h * (0.3 + 0.08 * Math.sin(ph * TAU));
+ recolor(p, a, (c, mx, my) => (c && my > a.h - reach ? C[clamp(Math.round(1 + tone(c) * 4), 1, 5)] : 0));
+ wisps(p, t, o, false);
+
+ // the skull: glitches in twice a loop, a few frames each, jumping a pixel and splitting
+ const on = Math.max(bump(ph, 0.1, 0.24), bump(ph, 0.6, 0.72));
+ if (on > 0.15) {
+ const f = Math.floor(t * 30), jit = rand(S, f) < 0.5 ? -1 : 1, hx = a.head[0] - 3 + (on < 0.6 ? jit : 0), hy = a.head[1] - 10;
+ if (rand(S, f, 2) < 0.85) {
+ if (on < 0.7) for (let r = 0; r < 7; r++) for (let c = 0; c < 7; c++) if (SKULL[r][c] !== ".") p.px(hx + c - jit * 2, hy + r, C[3]);
+ for (let r = 0; r < 7; r++)
+ for (let c = 0; c < 7; c++) {
+ const ch = SKULL[r][c];
+ if (ch === ".") continue;
+ p.px(hx + c, hy + r, ch === "e" ? (r === 3 ? C[6] : C[0]) : ch === "n" || ch === "t" ? C[2] : r < 2 ? C[7] : C[6]);
+ }
+ p.glow(hx + 3, hy + 3, 12, C[5], 0.35 * on);
+ }
+ }
+}
diff --git a/src/fx/status/fortified.js b/src/fx/status/fortified.js
new file mode 100644
index 0000000..3faac08
--- /dev/null
+++ b/src/fx/status/fortified.js
@@ -0,0 +1,63 @@
+import { PAL, seg, ease, rand, TAU, WHITE } from "../../core/index.js";
+import { steps } from "./_lib.js";
+
+export const meta = {
+ name: "Fortified",
+ desc: "Three stone shields circle the target, turning edge-on as they swing round behind it; a sheen runs across them once a beat.",
+ tags: ["status", "armor", "defense", "stone", "shield", "buff", "loop"],
+ size: [44, 40],
+ origin: [22, 36],
+ duration: 2.4,
+ loop: true,
+ fps: 30,
+ bg: "ground",
+ actor: true,
+ options: { palette: PAL.stone, count: 3, radius: 11, seed: 1 },
+};
+
+// a heater shield, 6 x 8 at full face
+const SHIELD = ["######", "######", "######", "######", "######", ".####.", "..##.."];
+
+// the shields at loop phase ph: x, y, apparent width, depth (front > 0); they turn 1/n of a turn a loop
+function shields(a, ph, n, R, seed) {
+ const out = [];
+ for (let i = 0; i < n; i++) {
+ const phi = ((i + ph) / n) * TAU, depth = Math.cos(phi);
+ out.push({ x: Math.sin(phi) * R, y: a.y + 11.5 + Math.sin(phi * 2 + rand(seed, i) * TAU) * 0.6, k: Math.abs(depth), depth });
+ }
+ return out.sort((p, q) => p.depth - q.depth);
+}
+
+function shield(p, C, s, shine) {
+ const W = Math.max(1, Math.round(6 * s.k)), x0 = Math.round(s.x - W / 2), y0 = Math.round(s.y - 3), far = s.depth < 0;
+ const on = (i, j) => j >= 0 && j < 7 && i >= 0 && i < W && SHIELD[j][Math.min(5, Math.floor((i * 6) / W))] === "#";
+ // dark outline first, then the face: lit left edge and top, shadowed right edge, a rivet, a sheen when it passes
+ for (let j = -1; j <= 7; j++)
+ for (let i = -1; i <= W; i++) if (!on(i, j) && (on(i - 1, j) || on(i + 1, j) || on(i, j - 1) || on(i, j + 1))) p.px(x0 + i, y0 + j, C[1]);
+ for (let j = 0; j < 7; j++)
+ for (let i = 0; i < W; i++) {
+ if (!on(i, j)) continue;
+ let c = W <= 2 ? C[4] : i === 0 || j === 0 ? C[7] : i === W - 1 || j >= 5 ? C[3] : i === 1 ? C[6] : C[5];
+ if (W >= 4 && i === Math.floor(W / 2) && j === 2) c = C[2];
+ if (far) c = c === C[7] || c === C[6] ? C[4] : c === C[5] ? C[3] : C[2];
+ const band = x0 + i + (y0 + j) * 0.7 - shine;
+ if (!far && W > 2 && band >= 0 && band < 2) c = band < 1 ? WHITE : C[7];
+ p.px(x0 + i, y0 + j, c);
+ }
+}
+
+function layer(p, t, o, front) {
+ const C = steps(o.palette), a = o.actor, ph = t / meta.duration;
+ const shine = -22 + 44 * ease.inOutSine(seg(ph, 0.05, 0.35));
+ for (const s of shields(a, ph, o.count, o.radius, o.seed)) if (s.depth >= 0 === front) shield(p, C, s, shine);
+}
+
+export function drawBack(p, t, o) {
+ layer(p, t, o, false);
+}
+
+export function draw(p, t, o) {
+ layer(p, t, o, true);
+ const C = steps(o.palette), a = o.actor, ph = t / meta.duration;
+ p.glow(0, a.y + 11, 20, C[6], 0.08 + 0.14 * Math.sin(Math.PI * seg(ph, 0.05, 0.4)));
+}
diff --git a/src/fx/status/frozen.js b/src/fx/status/frozen.js
new file mode 100644
index 0000000..b68d680
--- /dev/null
+++ b/src/fx/status/frozen.js
@@ -0,0 +1,83 @@
+import { PAL, cycle, rand, clamp, TAU, WHITE } from "../../core/index.js";
+import { steps, geom, recolor, tone } from "./_lib.js";
+
+export const meta = {
+ name: "Frozen",
+ desc: "The target is frosted blue and crusted in ice: crystals jut from its outline, a block grips its feet, a glint hops between shards, frost drifts.",
+ tags: ["status", "ice", "freeze", "frozen", "stun", "debuff", "loop"],
+ size: [40, 44],
+ origin: [20, 39],
+ duration: 2,
+ loop: true,
+ fps: 30,
+ bg: "ground",
+ actor: true,
+ options: { palette: PAL.ice, count: 7, seed: 3 },
+};
+
+const SHARDS = new WeakMap();
+// crystals: spots on the outline, spread apart, facing up or out, each pointing along its outward normal
+function shards(a, n, seed) {
+ const key = SHARDS.get(a.mask)?.[`${n}:${seed}`];
+ if (key) return key;
+ const g = geom(a.mask), picks = [];
+ const cand = g.outline
+ .map(([x, y]) => ({ x, y, nr: g.near(x, y), r: rand(seed, x, y) }))
+ .filter((c) => c.nr && c.y >= 2 && c.y < a.h - 6 && c.nr[2] <= 0.2)
+ .sort((p, q) => p.r - q.r);
+ for (const c of cand) {
+ if (picks.length >= n) break;
+ if (picks.some((q) => Math.hypot(q.x - c.x, q.y - c.y) < 4.5)) continue;
+ const [d, vx, vy] = c.nr, nx = vx / d, ny = vy / d - 0.35, L = Math.hypot(nx, ny);
+ picks.push({ x: c.x, y: c.y, nx: nx / L, ny: ny / L, len: 3.5 + c.r * 3.5, twin: rand(seed, c.x, c.y, 2) < 0.5 ? -0.6 : 0.6 });
+ }
+ const m = SHARDS.get(a.mask) ?? {};
+ m[`${n}:${seed}`] = picks;
+ SHARDS.set(a.mask, m);
+ return picks;
+}
+
+export function draw(p, t, o) {
+ const C = steps(o.palette), a = o.actor, S = o.seed, D = meta.duration, ph = t / D;
+ // frost: the character recolored down the ice ramp by brightness (a dithered tint where nothing is under it)
+ recolor(p, a, (c, mx, my) => (c ? C[clamp(Math.round(1.4 + tone(c) * 5.6), 1, 7)] : C[mx + my < 12 ? 6 : 5]), (mx, my) => (p.get(a.x + mx, a.y + my) ? 1 : 0.5));
+
+ // ice block gripping the feet: faceted, lit along its top edge
+ const bw = a.w / 2 + 2.5;
+ p.poly([[-bw, 0], [-bw + 1, -3], [-bw + 4, -5], [-1, -4], [2, -5.5], [bw - 2, -4], [bw, -2], [bw, 0]], (x, y) => {
+ const facet = Math.floor((x + y * 0.6 + 20) / 4) % 3;
+ return y < -3.6 ? C[7] : facet === 0 ? C[6] : facet === 1 ? C[5] : C[4];
+ });
+
+ // crystals jutting out of the outline
+ const list = shards(a, o.count, S);
+ const glintAt = Math.floor(ph * list.length * 2) % list.length, glint = (ph * list.length * 2) % 1;
+ const crystal = (bx, by, nx, ny, len, w) => {
+ const tx = bx + nx * len, ty = by + ny * len, px = -ny * w, py = nx * w;
+ p.tri(bx + px, by + py, tx, ty, bx - nx, by - ny, C[6]);
+ p.tri(bx - px, by - py, tx, ty, bx - nx, by - ny, C[3]);
+ p.px(tx, ty, C[7]);
+ return [tx, ty];
+ };
+ list.forEach((s, i) => {
+ const bx = a.x + s.x + 0.5, by = a.y + s.y + 0.5, c = Math.cos(s.twin), sn = Math.sin(s.twin);
+ crystal(bx, by, s.nx * c - s.ny * sn, s.nx * sn + s.ny * c, s.len * 0.6, 1.4);
+ const [tx, ty] = crystal(bx, by, s.nx, s.ny, s.len, 1.9);
+ if (i === glintAt && glint < 0.5) {
+ const k = Math.round(2 * Math.sin(glint * 2 * Math.PI));
+ p.line(tx - k, ty, tx + k, ty, WHITE), p.line(tx, ty - k, tx, ty + k, WHITE);
+ p.light(tx, ty, C[6], 0.6);
+ }
+ });
+
+ // frost motes drifting down, now and then catching the light
+ cycle(t, D, 7, S + 1, (r) => r.range(1.2, 1.9), (age, life, r) => {
+ const k = age / life, x = a.x + r.range(-6, a.w + 6) + Math.sin(age * 2 + r.next() * TAU) * 2, y = a.y - r.range(0, 6) + age * r.range(7, 11);
+ if (y > -1) return;
+ const tw = Math.sin(age * 7 + r.next() * TAU) > 0.75;
+ if (tw) p.px(x - 1, y, C[6]), p.px(x + 1, y, C[6]), p.px(x, y - 1, C[6]), p.px(x, y + 1, C[6]);
+ p.px(x, y, tw ? WHITE : k < 0.6 ? C[6] : C[5]);
+ });
+
+ p.glow(0, a.y + 9, 22, C[5], 0.18);
+}
diff --git a/src/fx/status/haste.js b/src/fx/status/haste.js
new file mode 100644
index 0000000..1198ef5
--- /dev/null
+++ b/src/fx/status/haste.js
@@ -0,0 +1,48 @@
+import { PAL, cycle } from "../../core/index.js";
+import { steps } from "./_lib.js";
+
+export const meta = {
+ name: "Haste",
+ desc: "Striped afterimages shiver behind the target, speed lines stream past it and dust kicks off its heels: it's moving faster than it should.",
+ tags: ["status", "haste", "speed", "buff", "afterimage", "directional", "loop"],
+ size: [52, 32],
+ origin: [32, 28],
+ duration: 0.6,
+ loop: true,
+ fps: 30,
+ bg: "ground",
+ actor: true,
+ options: { palette: PAL.volt, seed: 3 },
+};
+
+// behind the body: afterimages, each a striped copy of the silhouette, trailing and shivering
+export function drawBack(p, t, o) {
+ const C = steps(o.palette), a = o.actor, m = a.mask, f = Math.floor(t * 30);
+ const ghosts = [[-4 - (f % 2), 2, C[2], C[4]], [-9 - (f % 3 === 0 ? 1 : 0), 3, C[1], C[2]]];
+ for (const [dx, every, body, edge] of ghosts) {
+ for (let my = 0; my < m.h; my++) {
+ if ((my + f) % every) continue;
+ for (let mx = 0; mx < m.w; mx++) {
+ if (!m.data[my * m.w + mx]) continue;
+ const right = mx === m.w - 1 || !m.data[my * m.w + mx + 1];
+ p.px(a.x + mx + dx, a.y + my, right ? edge : body);
+ }
+ }
+ }
+ // speed lines streaming back from behind the body
+ cycle(t, meta.duration, 9, o.seed, (r) => r.range(0.14, 0.22), (age, life, r) => {
+ const k = age / life, y = Math.round(a.y + r.range(1, a.h - 2)), len = r.range(4, 10), sp = r.range(100, 150);
+ const x = a.x + r.range(2, a.w) - age * sp;
+ p.line(x, y, x + len * (1 - k * 0.5), y, (u) => (u < 0.3 ? (k < 0.5 ? C[7] : C[6]) : u < 0.7 ? C[5] : C[3]));
+ });
+ p.glow(-4, a.y + 10, 18, C[4], 0.15);
+}
+
+// in front: dust kicked off the heels
+export function draw(p, t, o) {
+ const C = steps(o.palette), D = meta.duration;
+ cycle(t, D, 4, o.seed + 1, (r) => r.range(0.22, 0.32), (age, life, r) => {
+ const k = age / life, x = r.range(-4, 2) - age * r.range(40, 70), y = -1 - Math.sin(k * Math.PI) * r.range(1, 3);
+ p.circle(x, y, 1.4 * (1 - k) + 0.3, k < 0.5 ? C[3] : C[2]);
+ });
+}
diff --git a/src/fx/status/invisible.js b/src/fx/status/invisible.js
new file mode 100644
index 0000000..10ec5d4
--- /dev/null
+++ b/src/fx/status/invisible.js
@@ -0,0 +1,51 @@
+import { cycle, fract, rand, WHITE } from "../../core/index.js";
+import { steps, geom } from "./_lib.js";
+
+export const meta = {
+ name: "Invisible",
+ desc: "The target vanishes, leaving only a faint outline that shimmers as a bright band runs down it, a glassy ripple, and a few sparkles.",
+ tags: ["status", "invisible", "stealth", "cloak", "buff", "loop"],
+ size: [36, 32],
+ origin: [18, 28],
+ duration: 1.6,
+ loop: true,
+ fps: 30,
+ bg: "ground",
+ actor: true,
+ options: {
+ palette: ["#0a1620", "#122a3a", "#1c4258", "#2c6280", "#4a8eae", "#7cbcd6", "#c0e8f4", "#ffffff"],
+ seed: 5,
+ },
+};
+
+// the target itself is hidden: previews drop the stand-in character, and a game hides its own sprite
+export const actorAlpha = () => 0;
+
+export function draw(p, t, o) {
+ const C = steps(o.palette), a = o.actor, g = geom(a.mask), ph = t / meta.duration;
+ // a glassy ripple where the body was: a faint diagonal wave sliding through
+ for (let my = 0; my < a.h; my++)
+ for (let mx = 0; mx < a.w; mx++) {
+ if (!g.on(mx, my)) continue;
+ const w = fract((mx * 0.5 - my) / 9 + ph * 2);
+ if (w < 0.08) p.px(a.x + mx, a.y + my, C[2]);
+ }
+ // the outline: dim, with a bright band running down it twice a loop
+ const band = fract(ph * 2) * (a.h + 8) - 4;
+ for (const [mx, my] of g.outline) {
+ const d = Math.abs(my - band), x = a.x + mx, y = a.y + my;
+ if (d < 1) p.px(x, y, C[7]);
+ else if (d < 3) p.px(x, y, C[6]);
+ else if (d < 6) p.px(x, y, C[4]);
+ else if (rand(o.seed, mx, my, Math.floor(ph * 8)) < 0.75) p.px(x, y, C[3]);
+ if (d < 3) p.light(x, y, C[6], 0.3);
+ }
+ // sparkles blinking on the outline
+ cycle(t, meta.duration, 5, o.seed, (r) => r.range(0.15, 0.3), (age, life, r) => {
+ const [mx, my] = g.outline[Math.floor(r.next() * g.outline.length)], x = a.x + mx, y = a.y + my, k = age / life;
+ const s = k < 0.5 ? 1 : 0;
+ p.px(x, y, WHITE);
+ if (s) p.px(x - 1, y, C[6]), p.px(x + 1, y, C[6]), p.px(x, y - 1, C[6]), p.px(x, y + 1, C[6]);
+ p.light(x, y, C[6], 0.5 * (1 - k));
+ });
+}
diff --git a/src/fx/status/marked.js b/src/fx/status/marked.js
new file mode 100644
index 0000000..0b5d831
--- /dev/null
+++ b/src/fx/status/marked.js
@@ -0,0 +1,49 @@
+import { seg, ease, bump, rand, TAU, WHITE } from "../../core/index.js";
+import { steps } from "./_lib.js";
+
+export const meta = {
+ name: "Marked",
+ desc: "Target brackets slam in around the body and lock with a flash, an aim point tightens on the chest, a marker bobs overhead; then it lets go and locks again.",
+ tags: ["status", "mark", "target", "reticle", "debuff", "loop"],
+ size: [44, 40],
+ origin: [22, 35],
+ duration: 1.4,
+ loop: true,
+ fps: 30,
+ bg: "ground",
+ actor: true,
+ options: {
+ palette: ["#1a0408", "#3a0810", "#6a0e1a", "#a01624", "#d82a2e", "#ff5040", "#ff9a80", "#fff0e8"],
+ seed: 1,
+ },
+};
+
+export function draw(p, t, o) {
+ const C = steps(o.palette), a = o.actor, ph = t / meta.duration;
+ // lock in fast, hold and breathe, ease off; the frame after the last is the first again
+ const lock = ease.outBack(seg(ph, 0, 0.13), 2.2), release = ease.inQuad(seg(ph, 0.8, 1));
+ const gap = 6 * (1 - lock) + 6 * release;
+ const flash = bump(ph, 0.1, 0.2), dim = release > 0.5;
+ const col = flash > 0.5 ? WHITE : dim ? C[3] : C[5], hi = flash > 0.5 ? WHITE : dim ? C[4] : C[7];
+
+ // corner brackets around the body's box
+ const x0 = a.x - 3 - gap, x1 = a.x + a.w + 2 + gap, y0 = a.y - 3 - gap, y1 = 1 + gap * 0.5, L = 3;
+ for (const [cx, cy, sx, sy] of [[x0, y0, 1, 1], [x1, y0, -1, 1], [x0, y1, 1, -1], [x1, y1, -1, -1]]) {
+ p.line(cx, cy, cx + sx * L, cy, col);
+ p.line(cx, cy, cx, cy + sy * L, col);
+ p.px(cx, cy, hi);
+ }
+
+ // the aim point on the chest: four short ticks closing in on a dot
+ const [hx, hy] = [a.chest[0], a.chest[1] + 1], d = Math.round(2 + 4 * (1 - lock) + 3 * release);
+ for (const [sx, sy] of [[1, 0], [-1, 0], [0, 1], [0, -1]]) p.line(hx + sx * d, hy + sy * d, hx + sx * (d + 1), hy + sy * (d + 1), col);
+ p.px(hx, hy, flash > 0.3 ? WHITE : hi);
+ // the marker overhead: a chevron bobbing over the head
+ const my = Math.round(a.head[1] - 6 + Math.sin(ph * TAU * 2 + rand(o.seed) * TAU) * 1.2), mx = a.head[0];
+ p.line(mx - 3, my, mx + 3, my, hi);
+ p.line(mx - 2, my + 1, mx + 2, my + 1, col);
+ p.line(mx - 1, my + 2, mx + 1, my + 2, col);
+ p.px(mx, my + 3, col);
+ p.glow(hx, hy, 10 + 6 * flash, C[5], 0.15 + 0.35 * flash);
+ p.light(mx, my + 1, C[6], 0.4);
+}
diff --git a/src/fx/status/petrified.js b/src/fx/status/petrified.js
new file mode 100644
index 0000000..d93e0a2
--- /dev/null
+++ b/src/fx/status/petrified.js
@@ -0,0 +1,99 @@
+import { PAL, burst, rng, rand, seg, ease, clamp, noise } from "../../core/index.js";
+import { steps, geom, recolor, tone } from "./_lib.js";
+
+export const meta = {
+ name: "Petrified",
+ desc: "Stone creeps up the target from the feet with a crackling edge, holds, splits with a crack, then the shell bursts into tumbling chunks and dust.",
+ tags: ["status", "stone", "petrify", "stun", "debuff", "one-shot"],
+ size: [64, 44],
+ origin: [32, 40],
+ duration: 2.4,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ actor: true,
+ options: { palette: PAL.stone, seed: 7 },
+};
+
+const SHATTER = 1.72;
+// once the statue shatters the character is gone, so the stand-in hides too
+export const actorAlpha = (t) => (t < SHATTER ? 1 : 0);
+
+export function draw(p, t, o) {
+ const C = steps(o.palette), a = o.actor, g = geom(a.mask), S = o.seed;
+ const creep = ease.inOutSine(seg(t, 0.05, 1.0));
+
+ if (t < SHATTER) {
+ // stone: everything under the creeping front turns to stone by brightness; in a sheet, shade it from the shape
+ const front = a.h * (1 - creep);
+ const edge = (mx) => front + noise(mx * 0.9 + t * 6, S) * 1.2;
+ recolor(p, a, (c, mx, my) => {
+ if (my < edge(mx)) return 0;
+ if (my < edge(mx) + 1) return C[7];
+ const rimPx = !g.on(mx - 1, my) || !g.on(mx + 1, my) || !g.on(mx, my - 1);
+ const v = c ? tone(c) : rimPx ? 0.15 : mx < a.w / 2 ? 0.6 : 0.45;
+ return C[clamp(Math.round(2 + v * 5), 2, 7)];
+ });
+ // dust puffing off the front as it climbs
+ burst(10, S, (r) => {
+ const born = r.range(0.1, 0.95), age = t - born, life = r.range(0.3, 0.5);
+ if (age < 0 || age > life) return;
+ const side = r.next() < 0.5 ? -1 : 1, y = a.y + a.h * (1 - ease.inOutSine(seg(born, 0.05, 1))) - age * 10;
+ p.px(side * (a.w / 2 + 1 + age * r.range(8, 16)), y, age / life < 0.5 ? C[5] : C[3]);
+ });
+ // the crack, splitting down the chest once it's set
+ const k = seg(t, 1.12, 1.24);
+ if (k > 0) {
+ const r = rng(S, 99), pts = [[a.chest[0] + r.range(-1, 1), a.y + 3]];
+ for (let i = 1; i <= 6; i++) pts.push([pts[i - 1][0] + r.range(-1.5, 1.5), a.y + 3 + i * 2.2]);
+ const n = Math.max(1, Math.round(k * 6));
+ for (let i = 1; i <= n; i++) {
+ p.line(pts[i - 1][0] + 1, pts[i - 1][1], pts[i][0] + 1, pts[i][1], C[7]);
+ p.line(...pts[i - 1], ...pts[i], C[1]);
+ }
+ if (t > SHATTER - 0.12 && Math.floor(t * 30) % 2) p.outline(a.mask, a.x, a.y, C[6]);
+ }
+ // a glint sweeping up the statue once it's whole
+ const gl = seg(t, 1.3, 1.5);
+ if (gl > 0 && gl < 1) {
+ const gy = a.y + a.h * (1 - gl);
+ for (let mx = 0; mx < a.w; mx++) for (let d = 0; d < 2; d++) {
+ const my = Math.round(gy - a.y - mx * 0.5 + d);
+ if (g.on(mx, my)) p.px(a.x + mx, a.y + my, d ? C[6] : C[7]);
+ }
+ }
+ p.glow(0, a.y + a.h * (1 - creep), 10, C[6], 0.2 * (1 - seg(t, 0.95, 1.1)));
+ return;
+ }
+
+ // the shell bursts: a chunk for every 2 x 2 block of the silhouette, thrown out, bouncing once, fading
+ const age = t - SHATTER, G = 320;
+ for (let my = 0; my < a.h; my += 2)
+ for (let mx = 0; mx < a.w; mx += 2) {
+ const cnt = g.on(mx, my) + g.on(mx + 1, my) + g.on(mx, my + 1) + g.on(mx + 1, my + 1);
+ if (cnt < 2) continue;
+ const r = rng(S, mx, my), x0 = a.x + mx + 1, y0 = a.y + my + 1, life = r.range(0.45, 0.66);
+ if (age > life) continue;
+ const vx = (x0 - a.chest[0]) * r.range(3, 7) + r.range(-8, 8), vy = -r.range(30, 70) - (a.h - my) * 1.2;
+ // first arc to the floor, then one small bounce, then rest
+ const th = (-vy + Math.sqrt(vy * vy - 2 * G * y0)) / G;
+ let x = x0 + vx * Math.min(age, th) + vx * 0.4 * Math.max(0, age - th), y;
+ if (age < th) y = y0 + vy * age + 0.5 * G * age * age;
+ else {
+ const b = age - th, vb = -(vy + G * th) * 0.3;
+ y = Math.min(-1, vb * b + 0.5 * G * b * b - 1);
+ }
+ const k = age / life, s = cnt === 4 && rand(S, mx, my, 3) < 0.6 ? 2 : 1;
+ const top = k < 0.4 ? C[6] : k < 0.7 ? C[4] : C[3], body = k < 0.4 ? C[4] : k < 0.7 ? C[3] : C[2];
+ p.rect(x - 1, y - 1, s, s, body);
+ p.px(x - 1, y - 1, top);
+ }
+ // dust: puffs bursting from the body and settling
+ burst(7, S + 1, (r) => {
+ const life = r.range(0.25, 0.4);
+ if (age > life) return;
+ const k = age / life, x = r.range(-7, 7) * (1 + k * 1.5), y = a.y + r.range(3, a.h - 2) - k * 5, rr = (1 + 1.8 * ease.outCubic(k)) * (1 - k);
+ p.circle(x, y, rr, k < 0.4 ? C[6] : C[4]);
+ });
+ if (age < 0.06) p.glow(0, a.y + 9, 22, C[7], 0.5);
+}
diff --git a/src/fx/status/poisoned.js b/src/fx/status/poisoned.js
new file mode 100644
index 0000000..7ab31f7
--- /dev/null
+++ b/src/fx/status/poisoned.js
@@ -0,0 +1,81 @@
+import { PAL, cycle, clamp, bump, ease, TAU } from "../../core/index.js";
+import { steps, geom, recolor, tone } from "./_lib.js";
+
+export const meta = {
+ name: "Poisoned",
+ desc: "Sickly green seeps through the target in slow pulses, darkest parts first; bubbles rise off it and pop, drips fall and splash.",
+ tags: ["status", "poison", "toxic", "dot", "debuff", "loop"],
+ size: [40, 44],
+ origin: [20, 40],
+ duration: 2,
+ loop: true,
+ fps: 30,
+ bg: "ground",
+ actor: true,
+ options: { palette: PAL.poison, seed: 5 },
+};
+
+const BUBBLE_S = [".#.", "#.#", ".#."];
+const BUBBLE_L = [".##.", "#..#", "#..#", ".##."];
+
+const DRIPS = new WeakMap();
+// where drips fall from: outline spots under the chin and hands (edges that face down, off the ground)
+function dripSpots(a) {
+ let s = DRIPS.get(a.mask);
+ if (s) return s;
+ const g = geom(a.mask);
+ s = g.outline.filter(([x, y]) => {
+ const nr = g.near(x, y);
+ return nr && nr[2] > 0.5 && y < a.h - 5;
+ });
+ DRIPS.set(a.mask, s);
+ return s;
+}
+
+export function draw(p, t, o) {
+ const P = steps(o.palette), a = o.actor, S = o.seed, D = meta.duration, ph = t / D;
+ // the seep: everything darker than a rising threshold turns green; two pulses a loop
+ const pulse = Math.max(bump(ph, 0, 0.42), bump(ph, 0.5, 0.92));
+ const th = 0.22 + 0.56 * ease.inOutSine(pulse);
+ recolor(p, a, (c) => (c && tone(c) < th ? P[clamp(Math.round(1 + tone(c) * 6), 1, 6)] : 0));
+
+ // bubbles rise off the body, wobbling, then pop
+ cycle(t, D, 7, S, (r) => r.range(0.7, 1.1), (age, life, r) => {
+ const k = age / life, big = r.next() < 0.4, x = a.x + r.range(1, a.w - 2) + Math.sin(age * 8 + r.next() * TAU) * 1.2;
+ const y = a.y + r.range(4, 12) - age * r.range(10, 16);
+ if (k < 0.85) {
+ const rows = big ? BUBBLE_L : BUBBLE_S;
+ p.sprite(rows, { "#": k < 0.5 ? P[6] : P[5] }, Math.round(x) - 1, Math.round(y) - 1);
+ p.px(Math.round(x) - (big ? 0 : 1) + (big ? 0 : 1), Math.round(y) - 1 + 1, big ? P[7] : 0);
+ } else {
+ const s = big ? 2 : 1;
+ p.px(x - s, y, P[6]), p.px(x + s + 1, y, P[6]), p.px(x, y - s, P[6]), p.px(x, y + s + 1, P[5]);
+ }
+ });
+
+ // drips: a drop swells under the chin or a hand, lets go, falls and splashes
+ const spots = dripSpots(a);
+ cycle(t, D, 3, S + 1, 0.9, (age, life, r) => {
+ const [mx, my] = spots[Math.floor(r.next() * spots.length)], x = a.x + mx, y0 = a.y + my;
+ const fall = age - 0.35;
+ if (fall < 0) {
+ const s = age / 0.35;
+ p.px(x, y0, P[5]);
+ if (s > 0.5) p.px(x, y0 + 1, s > 0.8 ? P[6] : P[4]);
+ return;
+ }
+ const y = y0 + 1 + 140 * fall * fall;
+ if (y < -0.5) {
+ p.px(x, y, P[6]), p.px(x, y - 1, P[4]);
+ return;
+ }
+ const sp = (fall - Math.sqrt((-1.5 - y0) / 140)) / 0.25;
+ if (sp > 0 && sp < 1) {
+ const w = Math.round(1 + sp * 3);
+ p.px(x - w, -1 - Math.round(bump(sp, 0, 1) * 2), P[5]), p.px(x + w, -1 - Math.round(bump(sp, 0, 1) * 2), P[5]);
+ p.line(x - 1, 0, x + 1, 0, P[4]);
+ }
+ });
+
+ p.glow(0, a.y + 9, 20, P[4], 0.12 + 0.2 * pulse);
+}
diff --git a/src/fx/status/rage.js b/src/fx/status/rage.js
new file mode 100644
index 0000000..b786d66
--- /dev/null
+++ b/src/fx/status/rage.js
@@ -0,0 +1,54 @@
+import { cycle, tileFbm, bump, clamp, at } from "../../core/index.js";
+import { steps, geom, recolor, tone } from "./_lib.js";
+
+export const meta = {
+ name: "Rage",
+ desc: "A red aura roars up behind the target and swells on every heartbeat; its outline flares, streaks shoot upward and an anger mark pops.",
+ tags: ["status", "rage", "berserk", "aura", "buff", "loop"],
+ size: [48, 54],
+ origin: [24, 50],
+ duration: 1,
+ loop: true,
+ fps: 30,
+ bg: "ground",
+ actor: true,
+ options: {
+ palette: ["#1a0306", "#3c060c", "#6e0a12", "#a8121a", "#e0261e", "#ff5a2a", "#ffa060", "#fff0c8"],
+ seed: 2,
+ },
+};
+
+const VEIN = [".##.##.", "###.###", "##...##", ".......", "##...##", "###.###", ".##.##."];
+// two beats a loop, the second softer
+const beatAt = (ph) => Math.max(bump(ph, 0, 0.14), 0.75 * bump(ph, 0.2, 0.34));
+
+// behind: the aura, a flame field around the silhouette that roars upward and swells on the beat
+export function drawBack(p, t, o) {
+ const R = steps(o.palette), a = o.actor, g = geom(a.mask), ph = t / meta.duration, beat = beatAt(ph);
+ // an energy shell rather than fire: dark crimson against the body, burning bright only at its outer edge
+ const AURA = [R[7], R[6], R[5], R[4], R[3], R[2]];
+ p.shade(a.x - 9, a.y - 16, a.x + a.w + 9, 0, (x, y) => {
+ const nr = g.near(x - a.x, y - a.y);
+ if (!nr || nr[0] === 0) return;
+ const [d, , vy] = nr, up = clamp(-vy / d + 0.35);
+ const n = tileFbm(x * 0.5, y * 0.22 + ph * 16, 0, 16, o.seed, 2) * 0.5 + 0.5;
+ const reach = (2.6 + up * 9 * (0.4 + 0.8 * n)) * (1 + 0.32 * beat);
+ const v = 1 - d / reach;
+ if (v <= 0) return;
+ return at(AURA, v * 1.25 + n * 0.15 - beat * 0.15);
+ });
+ p.glow(0, a.y + 8, 30, R[4], 0.18 + 0.22 * beat);
+}
+
+// in front: the body flushes and its outline flares on the beat, streaks shoot up, the anger mark pops
+export function draw(p, t, o) {
+ const R = steps(o.palette), a = o.actor, ph = t / meta.duration, beat = beatAt(ph);
+ if (beat > 0.6) recolor(p, a, (c) => (c && tone(c) < 0.45 ? R[clamp(Math.round(1 + tone(c) * 6), 1, 4)] : 0));
+ p.outline(a.mask, a.x, a.y, beat > 0.5 ? R[7] : R[5]);
+ cycle(t, meta.duration, 8, o.seed, (r) => r.range(0.25, 0.4), (age, life, r) => {
+ const k = age / life, x = a.x + (r.next() < 0.5 ? r.range(-5, -1) : r.range(a.w, a.w + 4)), y = r.range(-2, a.y + 10) - age * r.range(70, 110);
+ p.line(x, y, x, y + r.range(3, 6) * (1 - k * 0.5), (u) => (u < 0.3 ? R[7] : R[5]));
+ });
+ const pop = beat > 0.4 ? 1 : 0, vx = a.head[0] + 4 + pop, vy = a.head[1] - 3 - pop;
+ for (let r = 0; r < 7; r++) for (let c = 0; c < 7; c++) if (VEIN[r][c] === "#") p.px(vx + c, vy + r, pop ? R[7] : r < 3 ? R[6] : R[5]);
+}
diff --git a/src/fx/status/sleep.js b/src/fx/status/sleep.js
new file mode 100644
index 0000000..192e373
--- /dev/null
+++ b/src/fx/status/sleep.js
@@ -0,0 +1,52 @@
+import { seg, ease, rng, TAU } from "../../core/index.js";
+import { steps } from "./_lib.js";
+
+export const meta = {
+ name: "Sleep",
+ desc: "Z letters float up from the sleeper's head one after another, swaying, growing as they rise, fading into the dark.",
+ tags: ["status", "sleep", "zzz", "rest", "debuff", "loop"],
+ size: [44, 52],
+ origin: [16, 48],
+ duration: 2.4,
+ loop: true,
+ fps: 30,
+ bg: "ground",
+ actor: true,
+ options: {
+ palette: ["#0e0c22", "#1c1a40", "#2c2c66", "#40448c", "#5c68b4", "#86a0d8", "#bcd4f4", "#f2f8ff"],
+ count: 3, seed: 2,
+ },
+};
+
+const Z = [
+ ["####", "..#.", ".#..", "####"],
+ ["#####", "...#.", "..#..", ".#...", "#####"],
+ ["######", "....#.", "...#..", "..#...", ".#....", "######"],
+];
+
+function letter(p, rows, x, y, body, top, edge) {
+ const h = rows.length, w = rows[0].length, on = (c, r) => r >= 0 && r < h && c >= 0 && c < w && rows[r][c] === "#";
+ for (let r = -1; r <= h; r++)
+ for (let c = -1; c <= w; c++)
+ if (!on(c, r) && (on(c - 1, r) || on(c + 1, r) || on(c, r - 1) || on(c, r + 1) || on(c - 1, r - 1) || on(c + 1, r + 1))) p.px(x + c, y + r, edge);
+ for (let r = 0; r < h; r++) for (let c = 0; c < w; c++) if (on(c, r)) p.px(x + c, y + r, r === 0 ? top : body);
+}
+
+export function draw(p, t, o) {
+ const C = steps(o.palette), a = o.actor, D = meta.duration, n = o.count;
+ const [hx, hy] = [a.head[0] + 3, a.head[1] + 1];
+ // one letter after another, evenly spaced, each living most of a loop so they overlap
+ for (let i = 0; i < n; i++) {
+ const life = D * 0.92, age = (((t - (i * D) / n) % D) + D) % D;
+ if (age >= life) continue;
+ // a steady climb keeps the letters evenly spaced, just a touch quicker off the head
+ const r = rng(o.seed, i), k = age / life, rise = k * 0.75 + ease.outSine(k) * 0.25;
+ const x = hx + 1 + rise * r.range(11, 14) + Math.sin(k * TAU * 1.2 + r.range(0, TAU)) * 2, y = hy - 1 - rise * 24;
+ const size = k < 0.22 ? 0 : k < 0.55 ? 1 : 2, rows = Z[size], w = rows[0].length;
+ const fade = seg(k, 0.72, 1), pop = k < 0.05 ? 1 : 0;
+ if (fade > 0.85) continue;
+ const body = fade > 0.55 ? C[4] : fade > 0.2 ? C[5] : C[6], top = fade > 0.55 ? C[5] : C[7];
+ letter(p, rows, Math.round(x - w / 2), Math.round(y - rows.length / 2) - pop, body, top, fade > 0.55 ? C[1] : C[2]);
+ }
+ p.glow(hx + 6, hy - 12, 16, C[5], 0.1);
+}
diff --git a/src/fx/status/slowed.js b/src/fx/status/slowed.js
new file mode 100644
index 0000000..f848bd3
--- /dev/null
+++ b/src/fx/status/slowed.js
@@ -0,0 +1,63 @@
+import { cycle, ease, fract, clamp, TAU } from "../../core/index.js";
+import { steps } from "./_lib.js";
+
+export const meta = {
+ name: "Slowed",
+ desc: "A clock dial stands behind the target, its rim turning slowly and its hands ticking in heavy steps, while drops of time sink off it.",
+ tags: ["status", "slow", "time", "clock", "debuff", "loop"],
+ size: [44, 46],
+ origin: [22, 42],
+ duration: 2.4,
+ loop: true,
+ fps: 30,
+ bg: "ground",
+ actor: true,
+ options: {
+ palette: ["#060c1c", "#0c1a38", "#14305e", "#1e4c8c", "#2c70bc", "#4a9ae0", "#86c8f8", "#d8f0ff"],
+ radius: 14, seed: 4,
+ },
+};
+
+const center = (a) => [0, a.y + 5];
+
+// behind the body: the dial
+export function drawBack(p, t, o) {
+ const C = steps(o.palette), a = o.actor, ph = t / meta.duration, R = o.radius, [cx, cy] = center(a);
+ // rim: four arcs with gaps, a quarter turn a loop
+ for (let i = 0; i < 4; i++) {
+ const a0 = ph * (TAU / 4) + (i * TAU) / 4 - Math.PI / 2 + 0.2;
+ p.arc(cx, cy, R, 2, a0, a0 + 1.15, (u, v) => (v > 0.5 ? (u > 0.85 ? C[7] : C[6]) : C[4]));
+ }
+ // ticks
+ for (let i = 0; i < 12; i++) {
+ const th = (i / 12) * TAU, big = i % 3 === 0, r0 = R - (big ? 5 : 4), r1 = R - 3;
+ p.line(cx + Math.cos(th) * r0, cy + Math.sin(th) * r0, cx + Math.cos(th) * r1, cy + Math.sin(th) * r1, big ? C[5] : C[3]);
+ }
+ // hands: tick forward a twelfth at a time and settle with a heavy bounce; the long one laps once a loop
+ const hand = (laps, len, c) => {
+ const s = ph * 12 * laps, k = fract(s), th = ((Math.floor(s) + ease.outBack(clamp(k / 0.3), 2.6)) / 12) * TAU - Math.PI / 2;
+ p.line(cx, cy, cx + Math.cos(th) * len, cy + Math.sin(th) * len, c);
+ p.light(cx + Math.cos(th) * len, cy + Math.sin(th) * len, C[6], 0.35);
+ };
+ hand(1 / 12, R - 8, C[6]);
+ hand(1, R - 5, C[7]);
+ p.px(cx, cy, C[7]);
+ p.glow(cx, cy, R + 8, C[4], 0.16);
+}
+
+// in front: drops of time leaving the bottom of the dial, sinking slowly then faster, splatting
+export function draw(p, t, o) {
+ const C = steps(o.palette), a = o.actor, R = o.radius, [cx, cy] = center(a);
+ cycle(t, meta.duration, 6, o.seed, (r) => r.range(0.9, 1.3), (age, life, r) => {
+ const th = r.range(0.25, Math.PI - 0.25), x = cx + Math.cos(th) * (R - 1), y0 = cy + Math.sin(th) * (R - 1);
+ if (Math.abs(x) < a.w / 2 + 1 && y0 < -1) return; // hidden behind the body
+ const k = age / life, fall = ease.inQuad(clamp(k / 0.85)), y = y0 + (-1 - y0) * fall;
+ if (k < 0.85) {
+ p.px(x, y, C[6]), p.px(x, y - 1, C[4]);
+ if (fall > 0.25) p.px(x, y - 2, C[3]);
+ } else {
+ const s = (k - 0.85) / 0.15, w = Math.round(1 + s * 2);
+ p.line(x - w, -1, x + w, -1, s < 0.5 ? C[5] : C[3]);
+ }
+ });
+}
diff --git a/src/fx/status/stunned.js b/src/fx/status/stunned.js
new file mode 100644
index 0000000..8217469
--- /dev/null
+++ b/src/fx/status/stunned.js
@@ -0,0 +1,33 @@
+import { PAL, fit, TAU, WHITE } from "../../core/index.js";
+
+export const meta = {
+ name: "Stunned",
+ desc: "Three stars circle the head, passing behind it and in front, twinkling as they turn.",
+ tags: ["status", "stun", "dizzy", "debuff", "loop"],
+ size: [40, 40],
+ origin: [20, 36],
+ duration: 1,
+ loop: true,
+ fps: 30,
+ bg: "ground",
+ actor: true,
+ options: { palette: PAL.gold, count: 3, seed: 6 },
+};
+
+const STAR = ["..a..", ".aba.", "abbba", ".aba.", ".a.a."];
+
+function stars(p, t, o, front) {
+ const G = fit(o.palette, 8), a = o.actor, n = o.count, ph = t / meta.duration;
+ const cy = a.head[1] - 3;
+ for (let i = 0; i < n; i++) {
+ const th = ph * TAU + (i * TAU) / n, depth = Math.sin(th);
+ if (depth >= 0 !== front) continue;
+ const x = Math.round(Math.cos(th) * 10), y = Math.round(cy + depth * 2.5);
+ const twinkle = Math.sin(th * 3) > 0.6;
+ p.sprite(STAR, { a: front ? G[5] : G[4], b: twinkle ? WHITE : front ? G[6] : G[5] }, x - 2, y - 2);
+ p.light(x, y, G[5], front ? 0.5 : 0.25);
+ }
+}
+
+export const drawBack = (p, t, o) => stars(p, t, o, false);
+export const draw = (p, t, o) => stars(p, t, o, true);
diff --git a/src/fx/transitions/_lib.js b/src/fx/transitions/_lib.js
new file mode 100644
index 0000000..3c3ae4b
--- /dev/null
+++ b/src/fx/transitions/_lib.js
@@ -0,0 +1,61 @@
+// Shared by the screen transitions: a 160 x 90 screen with its origin at the top-left, a cover that closes by
+// about 45% of the duration, holds, then opens again so the last frame is empty.
+
+import { seg, ramp } from "../../core/index.js";
+
+export const W = 160, H = 90;
+
+/** The accent palette as colors, padded at the dark end to 8 steps so short ramps still fill every role. */
+export function accents(palette) {
+ const C = ramp(palette);
+ while (C.length < 8) C.unshift(C[0]);
+ return C;
+}
+
+/** The meta every transition shares; pass what differs. */
+export function screenMeta({ name, desc, tags, duration, options }) {
+ return {
+ name, desc, tags: ["transition", "screen", ...tags, "one-shot"],
+ size: [W, H], origin: [0, 0], duration, loop: false, fps: 30, bg: "sky",
+ options: { color: "#0b0a10", seed: 1, ...options },
+ };
+}
+
+/**
+ * Where a transition is: `cin` runs 0..1 while the cover closes (0 .. a of the duration), `cout` 0..1 while it
+ * opens (b .. 1), `out` says which half we're in.
+ */
+export function timeline(t, D, a = 0.45, b = 0.58) {
+ const u = t / D;
+ return { u, cin: seg(u, 0, a), cout: seg(u, b, 1), out: u >= b };
+}
+
+/** A pixel shader over the whole screen, clipped to it: fn(x, y, out) gets pixel centers (x + 0.5). */
+export const screen = (p, fn) => p.shade(0, 0, W - 1, H - 1, fn);
+
+/** The whole screen in one color. */
+export const fill = (p, c) => p.rect(0, 0, W, H, c);
+
+/** Is a point on the screen? */
+export const onScreen = (x, y) => x >= 0 && y >= 0 && x < W && y < H;
+
+/** 4x4 Bayer thresholds 0..1 at (i, j). */
+const B4 = [0, 8, 2, 10, 12, 4, 14, 6, 3, 11, 1, 9, 15, 7, 13, 5];
+export const bayer = (i, j) => (B4[((j & 3) << 2) | (i & 3)] + 0.5) / 16;
+
+/** A line clipped to the screen (Liang-Barsky), so no pixel lands off it. */
+export function clipLine(p, x0, y0, x1, y1, c) {
+ const dx = x1 - x0, dy = y1 - y0, X1 = W - 0.01, Y1 = H - 0.01;
+ let t0 = 0, t1 = 1;
+ for (const [q, r] of [[-dx, x0 - 0.01], [dx, X1 - x0], [-dy, y0 - 0.01], [dy, Y1 - y0]]) {
+ if (q === 0) {
+ if (r < 0) return;
+ continue;
+ }
+ const f = r / q;
+ if (q < 0) t0 = Math.max(t0, f);
+ else t1 = Math.min(t1, f);
+ if (t0 > t1) return;
+ }
+ p.line(x0 + dx * t0, y0 + dy * t0, x0 + dx * t1, y0 + dy * t1, c);
+}
diff --git a/src/fx/transitions/blinds.js b/src/fx/transitions/blinds.js
new file mode 100644
index 0000000..cf327b0
--- /dev/null
+++ b/src/fx/transitions/blinds.js
@@ -0,0 +1,45 @@
+import { PAL, hex, ease, seg } from "../../core/index.js";
+import { screenMeta, timeline, screen, fill, W, H, accents } from "./_lib.js";
+
+export const meta = screenMeta({
+ name: "Blinds",
+ desc: "Venetian blinds tilt shut slat by slat from the top, light catching each slat's edge, then tilt open again from the bottom.",
+ tags: ["blinds", "slats", "wipe"],
+ duration: 1.4,
+ options: { palette: PAL.dust, slats: 9 },
+});
+
+export function draw(p, t, o) {
+ const C = accents(o.palette), ink = hex(o.color), n = C.length, N = Math.max(2, o.slats | 0);
+ const { cin, cout, out } = timeline(t, meta.duration);
+ if (!out && cin >= 1) return fill(p, ink);
+ if (out && cout >= 1) return;
+ const sh = H / N, lit = C[n - 2], edge = C[Math.max(0, n - 4)], dim = C[Math.max(0, n - 6)], deep = C[0];
+ // each slat turns about its middle: its face shows sin(angle) of its height. Top slats lead on the way
+ // in, bottom slats on the way out; the light catches the edge that's turning toward it
+ const tilt = new Float32Array(N);
+ for (let i = 0; i < N; i++) {
+ const d = (out ? N - 1 - i : i) / (N - 1) * 0.4;
+ const g = seg(out ? cout : cin, d, d + 0.6);
+ tilt[i] = out ? Math.cos(ease.inOutSine(g) * Math.PI / 2) : Math.sin(ease.inOutSine(g) * Math.PI / 2);
+ }
+ // the ladder cords show in the gaps between slats while any slat is open
+ const cords = [Math.round(W * 0.16), Math.round(W * 0.84) - 1], ca = Math.min(1, (out ? 1 - cout : cin) * 5);
+ screen(p, (x, y, o2) => {
+ const i = Math.min(N - 1, Math.floor(y / sh)), mid = (i + 0.5) * sh, h = tilt[i] * sh / 2;
+ const dy = y - mid;
+ if (h < 0.25 || Math.abs(dy) > h + 0.01) {
+ if (Math.floor(x) !== cords[0] && Math.floor(x) !== cords[1]) return;
+ o2.a = ca;
+ return dim;
+ }
+ const tl = tilt[i];
+ if (tl > 0.97) return ink;
+ // the leading lip glints; the face is lit while the slat is side-on and goes dark as it shuts
+ const lip = out ? dy - (h - 1) : -h + 1 - dy; // >= 0 at the lit edge
+ if (lip >= -0.01) return tl > 0.85 ? edge : lit;
+ const face = tl < 0.45 ? edge : tl < 0.75 ? dim : tl < 0.9 ? deep : ink;
+ if (out ? dy < -h + 1.5 : dy > h - 1.5) return tl < 0.75 ? deep : ink;
+ return face;
+ });
+}
diff --git a/src/fx/transitions/burn-away.js b/src/fx/transitions/burn-away.js
new file mode 100644
index 0000000..d486156
--- /dev/null
+++ b/src/fx/transitions/burn-away.js
@@ -0,0 +1,79 @@
+import { PAL, hex, ease, clamp, fbm, rng, fly } from "../../core/index.js";
+import { screenMeta, timeline, screen, fill, onScreen, W, H, accents } from "./_lib.js";
+
+export const meta = screenMeta({
+ name: "Burn away",
+ desc: "The picture chars and burns in from the edges behind a ragged ember line shedding sparks; then the black burns open from the middle.",
+ tags: ["burn", "fire", "embers", "wipe"],
+ duration: 1.8,
+ options: { palette: PAL.fire, rough: 0.32 },
+});
+
+// the inverse of ease.inOutSine: when the front reaches a spot
+const unSine = (y) => Math.acos(1 - 2 * clamp(y)) / Math.PI;
+
+// the burn order: 0 at the screen's rim, 1 at its center, made ragged by noise (cached: it never changes)
+const cache = new Map();
+function field(seed, rough) {
+ const key = seed + ":" + rough;
+ if (cache.has(key)) return cache.get(key);
+ const f = new Float32Array(W * H);
+ let lo = Infinity, hi = -Infinity;
+ for (let y = 0; y < H; y++)
+ for (let x = 0; x < W; x++) {
+ const m = Math.max(Math.abs(x + 0.5 - W / 2) / (W / 2), Math.abs(y + 0.5 - H / 2) / (H / 2));
+ const v = (1 - m) * (1 - rough) + (fbm(x * 0.06, y * 0.09, seed, 4) * 0.5 + 0.5) * rough;
+ f[y * W + x] = v;
+ lo = Math.min(lo, v);
+ hi = Math.max(hi, v);
+ }
+ for (let i = 0; i < f.length; i++) f[i] = (f[i] - lo) / (hi - lo);
+ cache.set(key, f);
+ return f;
+}
+
+export function draw(p, t, o) {
+ const C = accents(o.palette), ink = hex(o.color), n = C.length, S = o.seed, D = meta.duration;
+ const { cin, cout, out } = timeline(t, D);
+ if (!out && cin >= 1) return fill(p, ink);
+ if (out && cout >= 1) return;
+ const F = field(S, o.rough);
+ // the front sweeps a little past both ends so the edge band enters and leaves cleanly
+ const w = 0.07, front = (k) => -w + (1 + w * 2) * k;
+ const k = out ? front(ease.inOutSine(cout)) : front(ease.inOutSine(cin));
+ // embers: hottest at the front, cooling to char; the scene side scorches just before the fire reaches it
+ const glowC = [C[n - 1], C[n - 2], C[n - 3], C[n - 4], C[Math.max(0, n - 6)]];
+ screen(p, (x, y, o2) => {
+ const v = F[Math.floor(y) * W + Math.floor(x)], b = out ? 1 - v : v;
+ // in: burnt where b < k. out: still covered where b > k (the hole burns outward)
+ const d = out ? b - k : k - b; // > 0 on the cover side
+ if (d < -0.025) return;
+ if (d < 0) {
+ o2.a = 0.5;
+ return C[Math.max(0, n - 7)];
+ }
+ if (d < w) {
+ const q = d / w;
+ o2.l = C[n - 3];
+ o2.k = 0.5 * (1 - q);
+ return glowC[Math.min(4, Math.floor(q * 5))];
+ }
+ return ink;
+ });
+ // sparks: each leaves its spot when the front passes it, drifting up and out as it cools
+ const half = out ? cout : cin, T = (out ? 1 - 0.58 : 0.45) * D;
+ for (let i = 0; i < 48; i++) {
+ const r = rng(S, i, out ? 2 : 1), x0 = r.range(2, W - 2), y0 = r.range(2, H - 2);
+ const v = F[Math.floor(y0) * W + Math.floor(x0)], b = out ? 1 - v : v;
+ const born = unSine((b + w) / (1 + w * 2));
+ const life = r.range(0.18, 0.42), age = (half - born) * T;
+ if (age < 0 || age > life) continue;
+ const vx = r.range(-14, 14), vy = r.range(-46, -18), q = age / life;
+ const [x, y] = fly(x0, y0, vx, vy, age, -30, 1.5);
+ if (!onScreen(x, y)) continue;
+ // fresh sparks are short streaks, older ones single cooling pixels
+ p.px(x, y, q < 0.3 ? C[n - 1] : q < 0.65 ? C[n - 2] : C[n - 4]);
+ if (q < 0.45 && onScreen(x, y + 1)) p.px(x - vx * 0.02, y + 1, C[n - 3]);
+ p.light(x, y, C[n - 3], 0.5 * (1 - q));
+ }
+}
diff --git a/src/fx/transitions/crt-off.js b/src/fx/transitions/crt-off.js
new file mode 100644
index 0000000..5c56431
--- /dev/null
+++ b/src/fx/transitions/crt-off.js
@@ -0,0 +1,60 @@
+import { hex, ease, seg, WHITE } from "../../core/index.js";
+import { screenMeta, timeline, screen, fill, W, H, accents } from "./_lib.js";
+
+export const meta = screenMeta({
+ name: "CRT off",
+ desc: "A tube TV switching off: the picture squeezes into a glowing line, the line into a dot, the dot dies; then it all flicks back on.",
+ tags: ["crt", "tv", "retro", "power"],
+ duration: 1.5,
+ options: { palette: ["#0c2230", "#1a4c5c", "#3a8ea0", "#86d8e6", "#d4fbff", "#ffffff"] },
+});
+
+export function draw(p, t, o) {
+ const C = accents(o.palette), ink = hex(o.color), n = C.length;
+ const { cin, cout, out } = timeline(t, meta.duration);
+ const cy = H / 2, cx = W / 2;
+ // q runs the shut-down 0..1; the switch-on plays it back faster at the start and slower at the end
+ let hh, hw, dot, glowK;
+ if (!out) {
+ hh = (H / 2) * (1 - ease.inQuart(seg(cin, 0, 0.5))); // picture height squeezes
+ hw = (W / 2) * (1 - ease.inCubic(seg(cin, 0.5, 0.78))); // then the line shortens
+ dot = 1 - seg(cin, 0.78, 1); // then the dot fades
+ glowK = seg(cin, 0.25, 0.5) ** 2;
+ } else {
+ dot = seg(cout, 0, 0.12);
+ hw = (W / 2) * ease.outCubic(seg(cout, 0.1, 0.32));
+ hh = (H / 2) * ease.outCubic(seg(cout, 0.32, 0.75));
+ glowK = (1 - seg(cout, 0.32, 0.7)) ** 2;
+ }
+ if (hh >= H / 2 && hw >= W / 2) return;
+ if (dot <= 0) return fill(p, ink);
+ const rim = C[n - 2], mid = C[Math.max(0, n - 4)];
+ if (hh > 1) {
+ // the picture: a window over the scene, brightening as it squeezes, with lit edges
+ screen(p, (x, y, o2) => {
+ const dy = Math.abs(y - cy) - hh;
+ if (dy < -1) {
+ o2.l = C[n - 3];
+ o2.k = 0.55 * glowK * (1 - Math.abs(y - cy) / (hh + 1)) + 0.2 * glowK;
+ return;
+ }
+ if (dy < 0) return rim;
+ if (dy < 1 && glowK > 0.3) return mid;
+ return ink;
+ });
+ return;
+ }
+ // the line, then the dot: hot white on black, with a soft glow
+ fill(p, ink);
+ if (hw > 1.5) {
+ p.rect(cx - hw, cy - 1, hw * 2, 2, WHITE);
+ p.rect(cx - hw * 0.8, cy - 2, hw * 1.6, 1, rim);
+ p.rect(cx - hw * 0.8, cy + 1, hw * 1.6, 1, rim);
+ p.glowLine(cx - hw * 0.85, cy, cx + hw * 0.85, cy, 10, C[n - 3], 0.3);
+ p.glow(cx, cy, Math.min(30, hw * 0.4 + 6), C[n - 2], 0.25);
+ } else {
+ const s = dot > 0.5 ? 2 : 1;
+ p.rect(cx - s, cy - s, s * 2, s * 2, WHITE, Math.min(1, dot * 1.6));
+ p.glow(cx, cy, 6 + 8 * dot, C[n - 3], 0.5 * dot);
+ }
+}
diff --git a/src/fx/transitions/diamond-wipe.js b/src/fx/transitions/diamond-wipe.js
new file mode 100644
index 0000000..59bd0cc
--- /dev/null
+++ b/src/fx/transitions/diamond-wipe.js
@@ -0,0 +1,45 @@
+import { PAL, hex, ease, seg } from "../../core/index.js";
+import { screenMeta, timeline, screen, fill, W, H, accents } from "./_lib.js";
+
+export const meta = screenMeta({
+ name: "Diamond wipe",
+ desc: "A lattice of diamonds swells across the screen from left to right with bright growing rims, then shrinks away in the same sweep.",
+ tags: ["wipe", "diamonds", "pattern", "retro"],
+ duration: 1.4,
+ options: { palette: PAL.arcane, cell: 16 },
+});
+
+export function draw(p, t, o) {
+ const C = accents(o.palette), ink = hex(o.color), n = C.length;
+ const { cin, cout, out } = timeline(t, meta.duration);
+ if (!out && cin >= 1) return fill(p, ink);
+ if (out && cout >= 1) return;
+ const s = Math.max(6, o.cell | 0), cols = Math.ceil(W / s), rows = Math.ceil(H / s);
+ const rim = C[n - 2], mid = C[Math.max(0, n - 4)];
+ // each diamond's radius (L1, in px): it swells to s, which closes every gap, when the sweep reaches it
+ const R = new Float32Array((cols + 2) * (rows + 2));
+ for (let j = -1; j <= rows; j++)
+ for (let i = -1; i <= cols; i++) {
+ const cx = (i + 0.5) * s, cy = (j + 0.5) * s;
+ const d = 0.62 * (cx / W) * 0.8 + 0.62 * (cy / H) * 0.2; // left to right, a little top-down
+ const g = out ? seg(cout, d, d + 0.38) : seg(cin, d, d + 0.38);
+ R[(j + 1) * (cols + 2) + i + 1] = out ? s * 1.02 * (1 - ease.inCubic(g)) : s * 1.02 * ease.outCubic(g);
+ }
+ screen(p, (x, y) => {
+ const i0 = Math.floor(x / s), j0 = Math.floor(y / s);
+ let best = -1e9, br = 0;
+ for (let j = j0 - 1; j <= j0 + 1; j++)
+ for (let i = i0 - 1; i <= i0 + 1; i++) {
+ const r = R[(j + 1) * (cols + 2) + i + 1];
+ if (r <= 0) continue;
+ const depth = r - Math.abs(x - (i + 0.5) * s) - Math.abs(y - (j + 0.5) * s);
+ if (depth > best) (best = depth), (br = r);
+ }
+ if (best <= 0) return;
+ // a bright rim on diamonds still on the move; a settled diamond is plain cover
+ const moving = br < s * 0.98;
+ if (moving && best < 1.2) return rim;
+ if (moving && best < 2.4) return mid;
+ return ink;
+ });
+}
diff --git a/src/fx/transitions/dither-fade.js b/src/fx/transitions/dither-fade.js
new file mode 100644
index 0000000..2a401e8
--- /dev/null
+++ b/src/fx/transitions/dither-fade.js
@@ -0,0 +1,30 @@
+import { PAL, hex, ease, clamp } from "../../core/index.js";
+import { screenMeta, timeline, screen, fill, bayer, W, H, accents } from "./_lib.js";
+
+export const meta = screenMeta({
+ name: "Dither fade",
+ desc: "An old-console fade: chunky ordered dither creeps in from the corners through a deep tint, holds black, then clears from the middle out.",
+ tags: ["fade", "dither", "retro"],
+ duration: 1.4,
+ options: { palette: PAL.arcane, cell: 2, vignette: 0.35, steps: [0] },
+});
+
+export function draw(p, t, o) {
+ const C = accents(o.palette), ink = hex(o.color);
+ const { cin, cout, out } = timeline(t, meta.duration);
+ const k = out ? 1 - ease.inOutSine(cout) : ease.inOutSine(cin);
+ if (k <= 0) return;
+ if (k >= 1) return fill(p, ink);
+ // the fade walks a short ladder of palette steps down to the cover, one full dither pass per rung
+ const cs = Math.max(1, o.cell | 0), v = o.vignette, ladder = [...o.steps.map((i) => C[Math.min(i, C.length - 1)]), ink];
+ const n = ladder.length;
+ screen(p, (x, y) => {
+ const th = bayer(Math.floor(x / cs), Math.floor(y / cs));
+ const dx = (x - W / 2) / (W / 2), dy = (y - H / 2) / (H / 2);
+ // the corners lead and the middle lags; stretched so every pixel still reaches 0 and 1
+ const kk = clamp(k * (1 + v) - v * (1 - Math.min(1, (dx * dx + dy * dy) * 0.5))) * n;
+ const rung = Math.floor(kk), f = kk - rung;
+ const i = f > th ? rung : rung - 1;
+ if (i >= 0) return ladder[Math.min(i, n - 1)];
+ });
+}
diff --git a/src/fx/transitions/glitch-wipe.js b/src/fx/transitions/glitch-wipe.js
new file mode 100644
index 0000000..ac4c00d
--- /dev/null
+++ b/src/fx/transitions/glitch-wipe.js
@@ -0,0 +1,69 @@
+import { PAL, hex, seg, ease, rand, clamp, WHITE } from "../../core/index.js";
+import { screenMeta, timeline, screen, fill, W, H, accents } from "./_lib.js";
+
+export const meta = screenMeta({
+ name: "Glitch wipe",
+ desc: "Torn bands of cover stutter in from both sides at their own speeds, edges split into pink and cyan, data slivers flicker; then they tear back out.",
+ tags: ["wipe", "glitch", "digital", "bands"],
+ duration: 1.3,
+ options: { palette: PAL.neon, split: "#3ce8ff", rate: 15 },
+});
+
+// the bands: chunky random heights down the screen, each with a side, a start and a speed (cached per seed)
+const cache = new Map();
+function bands(seed) {
+ if (cache.has(seed)) return cache.get(seed);
+ const list = [];
+ for (let y = 0, i = 0; y < H; i++) {
+ let h = [4, 6, 8, 10, 14][Math.floor(rand(seed, i, 1) * 5)];
+ if (H - y - h < 4) h = H - y;
+ list.push({
+ y, h, left: i % 2 === 0 ? rand(seed, i, 3) < 0.7 : rand(seed, i, 3) < 0.3,
+ d0: rand(seed, i, 4) * 0.42, l0: 0.32 + rand(seed, i, 5) * 0.26,
+ d1: rand(seed, i, 6) * 0.42, l1: 0.32 + rand(seed, i, 7) * 0.26,
+ });
+ y += h;
+ }
+ cache.set(seed, list);
+ return list;
+}
+
+export function draw(p, t, o) {
+ const C = accents(o.palette), ink = hex(o.color), split = hex(o.split), n = C.length, S = o.seed;
+ const { cin, cout, out } = timeline(t, meta.duration);
+ if (!out && cin >= 1) return fill(p, ink);
+ if (out && cout >= 1) return;
+ // time moves in jerks; on some steps a band jumps ahead or slips back
+ const step = Math.floor(t * o.rate), B = bands(S), pink = C[n - 4];
+ const edgeX = B.map((b, i) => {
+ const jit = rand(S, i, step, 8) < 0.3 ? (rand(S, i, step, 9) - 0.4) * 30 : 0;
+ const k = out ? ease.inQuad(seg(cout, b.d1, b.d1 + b.l1)) : ease.inQuad(seg(cin, b.d0, b.d0 + b.l0));
+ const L = k <= 0 ? 0 : k >= 1 ? W : clamp(Math.round(W * k + jit), 0, W);
+ // in: the cover runs from its side to the edge; out: from the edge on to the far side
+ return b.left ? L : W - L;
+ });
+ const rowBand = new Int16Array(H);
+ B.forEach((b, i) => { for (let y = b.y; y < b.y + b.h; y++) rowBand[y] = i; });
+ screen(p, (x, y) => {
+ const i = rowBand[Math.floor(y)], b = B[i], e = edgeX[i];
+ // which side of the edge is cover: in, the band's own side; out, the other
+ const coverLeft = b.left === !out;
+ const d = coverLeft ? e - x : x - e; // > 0 inside the cover
+ const live = e > 0.5 && e < W - 0.5;
+ if (d > 0) {
+ if (live && d < 3) return pink;
+ return ink;
+ }
+ // the split: a cyan ghost of the edge a few px ahead of it
+ if (live && d > -6 && d <= -3) return split;
+ });
+ // data slivers: a few short bright bars riding next to live edges, one step each
+ const amount = Math.round(Math.sin(Math.PI * (out ? cout : cin)) * 6);
+ for (let j = 0; j < amount; j++) {
+ const r = (k) => rand(S, step, j, k), bi = Math.floor(r(1) * B.length), b = B[bi], e = edgeX[bi];
+ if (e <= 0.5 || e >= W - 0.5) continue;
+ const w = 4 + Math.floor(r(2) * 10), side = r(3) < 0.5 ? -1 : 1, h = Math.min(b.h, 1 + Math.floor(r(4) * 2));
+ const x = clamp(e + side * (4 + r(5) * 16) - (side < 0 ? w : 0), 0, W - w);
+ p.rect(Math.round(x), b.y + Math.floor(r(6) * (b.h - h + 1)), w, h, r(7) < 0.5 ? split : r(7) < 0.85 ? pink : WHITE);
+ }
+}
diff --git a/src/fx/transitions/iris.js b/src/fx/transitions/iris.js
new file mode 100644
index 0000000..3c968d4
--- /dev/null
+++ b/src/fx/transitions/iris.js
@@ -0,0 +1,41 @@
+import { PAL, hex, ease, seg, lerp } from "../../core/index.js";
+import { screenMeta, timeline, screen, fill, W, H, accents } from "./_lib.js";
+
+export const meta = screenMeta({
+ name: "Iris",
+ desc: "A cartoon iris: the circle closes fast onto a small spotlight, holds a beat, snaps shut, then pops open and widens away.",
+ tags: ["iris", "circle", "cartoon"],
+ duration: 1.5,
+ options: { palette: PAL.holy, cx: 80, cy: 45, radius: 13 },
+});
+
+export function draw(p, t, o) {
+ const C = accents(o.palette), ink = hex(o.color), n = C.length;
+ const { cin, cout, out } = timeline(t, meta.duration);
+ const cx = o.cx, cy = o.cy, r0 = o.radius;
+ const R = Math.max(Math.hypot(cx, cy), Math.hypot(W - cx, cy), Math.hypot(cx, H - cy), Math.hypot(W - cx, H - cy)) + 4;
+ let r;
+ if (!out) {
+ // close onto the spotlight, hold it, then a tiny wind-up and shut
+ r = cin < 0.6 ? lerp(R, r0, ease.outCubic(seg(cin, 0, 0.6))) : r0 * (1 - ease.inBack(seg(cin, 0.78, 1), 2.4));
+ } else {
+ // pop open past the spotlight, settle, then accelerate away
+ r = cout < 0.36 ? r0 * ease.outBack(seg(cout, 0, 0.2), 2.2) : lerp(r0, R, ease.inCubic(seg(cout, 0.36, 1)));
+ }
+ if (r <= 0.4) return fill(p, ink);
+ if (r >= R) return;
+ const rim = C[n - 1], mid = C[Math.max(0, n - 3)], deep = C[Math.max(0, n - 5)];
+ const small = 1 - seg(r, r0 * 2, r0 * 5); // the rim shines while the circle is small
+ screen(p, (x, y) => {
+ const d = Math.hypot(x - cx, y - cy) - r;
+ if (d < 0) return;
+ if (d < 1) return rim;
+ if (d < 2) return small > 0.5 ? mid : ink;
+ if (d < 3 && small > 0.5) return deep;
+ return ink;
+ });
+ if (r < R * 0.45) {
+ p.glowRing(cx, cy, r, 5, C[n - 3], 0.3 * (0.4 + 0.6 * small));
+ p.glow(cx, cy, r + 2, C[n - 2], 0.12 * small);
+ }
+}
diff --git a/src/fx/transitions/pixel-dissolve.js b/src/fx/transitions/pixel-dissolve.js
new file mode 100644
index 0000000..4fd28ac
--- /dev/null
+++ b/src/fx/transitions/pixel-dissolve.js
@@ -0,0 +1,58 @@
+import { PAL, hex, ease, seg, clamp, rand, noise2 } from "../../core/index.js";
+import { screenMeta, timeline, screen, fill, W, H, accents } from "./_lib.js";
+
+export const meta = screenMeta({
+ name: "Pixel dissolve",
+ desc: "The screen breaks into blocks in clumpy random order, each winking in through a dim flash, some with a bright speck; then they wink back out.",
+ tags: ["dissolve", "blocks", "random", "retro"],
+ duration: 1.4,
+ options: { palette: PAL.cyber, cell: 5 },
+});
+
+// when each block arrives (in) and leaves (out), as shares of each half: random, nudged by low noise into clumps
+const cache = new Map();
+function times(seed, cols, rows) {
+ const key = `${seed}:${cols}:${rows}`;
+ if (cache.has(key)) return cache.get(key);
+ const n = cols * rows, tin = new Float32Array(n), tout = new Float32Array(n), glint = new Uint8Array(n);
+ for (let j = 0; j < rows; j++)
+ for (let i = 0; i < cols; i++) {
+ const q = j * cols + i;
+ const a = 0.62 * rand(seed, i, j, 1) + 0.38 * (noise2(i * 0.22, j * 0.22, seed) * 0.5 + 0.5);
+ const b = 0.62 * rand(seed, i, j, 2) + 0.38 * (noise2(i * 0.22 + 40, j * 0.22, seed + 1) * 0.5 + 0.5);
+ tin[q] = clamp((a - 0.18) / 0.64);
+ tout[q] = clamp((b - 0.18) / 0.64);
+ glint[q] = rand(seed, i, j, 3) < 0.3 ? 1 : 0;
+ }
+ const v = { tin, tout, glint };
+ cache.set(key, v);
+ return v;
+}
+
+export function draw(p, t, o) {
+ const C = accents(o.palette), ink = hex(o.color), n = C.length;
+ const { cin, cout, out } = timeline(t, meta.duration);
+ if (!out && cin >= 1) return fill(p, ink);
+ if (out && cout >= 1) return;
+ const cs = Math.max(2, o.cell | 0), cols = Math.ceil(W / cs), rows = Math.ceil(H / cs);
+ const { tin, tout, glint } = times(o.seed, cols, rows);
+ const POP = 0.13, hot = C[n - 1], warm = C[Math.max(0, n - 5)];
+ // a block's life: (a glint for some) -> a dim block -> cover, and back again on the way out
+ const stage = (q) => {
+ if (!out) {
+ const g = seg(ease.inOutSine(cin) * (1 + POP), tin[q], tin[q] + POP);
+ return g <= 0 ? 0 : g < 0.4 ? 1 : g < 0.75 ? 2 : 3;
+ }
+ const g = seg(ease.inOutSine(cout) * (1 + POP), tout[q], tout[q] + POP);
+ return g <= 0 ? 3 : g < 0.4 ? 2 : g < 0.75 ? 1 : 0;
+ };
+ screen(p, (x, y) => {
+ const i = Math.floor(x / cs), j = Math.floor(y / cs), s = stage(j * cols + i);
+ if (s === 3) return ink;
+ if (s === 2) return warm;
+ if (s === 1 && glint[j * cols + i]) {
+ const lx = x - i * cs, ly = y - j * cs, m = (cs - 1) / 2;
+ if (Math.abs(lx - 0.5 - m) <= 1 && Math.abs(ly - 0.5 - m) <= 1) return hot;
+ }
+ });
+}
diff --git a/src/fx/transitions/shatter-wipe.js b/src/fx/transitions/shatter-wipe.js
new file mode 100644
index 0000000..3c7b0eb
--- /dev/null
+++ b/src/fx/transitions/shatter-wipe.js
@@ -0,0 +1,207 @@
+import { PAL, hex, ease, seg, clamp, lerp, rand, burst, fly, TAU, WHITE } from "../../core/index.js";
+import { screenMeta, screen, fill, onScreen, clipLine, W, H, accents } from "./_lib.js";
+
+export const meta = screenMeta({
+ name: "Shatter wipe",
+ desc: "A dark pane drops over the screen, cracks race out from an impact with a flash, and the glass breaks into glinting shards that tumble away.",
+ tags: ["shatter", "glass", "break", "wipe"],
+ duration: 2,
+ options: { palette: PAL.ice, rays: 12 },
+});
+
+// where a ray from (cx, cy) leaves the screen, and on which side (0 top, 1 right, 2 bottom, 3 left)
+function exit(cx, cy, a) {
+ const dx = Math.cos(a), dy = Math.sin(a);
+ let best = Infinity, side = 0;
+ if (dy < 0 && -cy / dy < best) (best = -cy / dy), (side = 0);
+ if (dx > 0 && (W - cx) / dx < best) (best = (W - cx) / dx), (side = 1);
+ if (dy > 0 && (H - cy) / dy < best) (best = (H - cy) / dy), (side = 2);
+ if (dx < 0 && -cx / dx < best) (best = -cx / dx), (side = 3);
+ return { d: best, side };
+}
+const CORNER = [[W, 0], [W, H], [0, H], [0, 0]]; // the corner after each side, going clockwise
+
+// a crack from a to b with a kink or two, the same for both shards that share it
+function jag(seed, id, a, b) {
+ const dx = b[0] - a[0], dy = b[1] - a[1], L = Math.hypot(dx, dy), m = L > 22 ? 2 : 1, out = [a];
+ for (let k = 1; k <= m; k++) {
+ const f = k / (m + 1) + (rand(seed, id, k, 1) - 0.5) * 0.15, off = (rand(seed, id, k, 2) - 0.5) * Math.min(10, L * 0.28);
+ out.push([a[0] + dx * f - (dy / (L || 1)) * off, a[1] + dy * f + (dx / (L || 1)) * off]);
+ }
+ out.push(b);
+ return out;
+}
+
+// the break: jagged rays out of the impact, crossed by rings that follow the screen's shape (cached per seed)
+const cache = new Map();
+function pattern(seed, NR) {
+ const key = seed + ":" + NR;
+ if (cache.has(key)) return cache.get(key);
+ const cx = W * (0.38 + 0.14 * rand(seed, 1)), cy = H * (0.34 + 0.18 * rand(seed, 2));
+ const F = [0, 0.17, 0.4, 0.68, 1], J = F.length - 1;
+ const rays = [];
+ for (let i = 0; i < NR; i++) {
+ const a = ((i + (rand(seed, i, 3) - 0.5) * 0.55) / NR) * TAU, ex = exit(cx, cy, a);
+ const vs = F.map((f, j) => {
+ const r = j === 0 ? 0 : j === J ? ex.d : ex.d * f * (0.82 + 0.36 * rand(seed, i, j, 4));
+ return [cx + Math.cos(a) * r, cy + Math.sin(a) * r];
+ });
+ rays.push({ vs, side: ex.side });
+ }
+ // radial cracks rad[i][j]: ring j to j+1 along ray i; ring cracks ring[i][j]: ray i to ray i+1 on ring j
+ const rad = rays.map((ray, i) => F.slice(0, J).map((_, j) => jag(seed, i * 10 + j, ray.vs[j], ray.vs[j + 1])));
+ const ring = rays.map((ray, i) => F.map((_, j) => (j === 0 || j === J ? null : jag(seed, 500 + i * 10 + j, ray.vs[j], rays[(i + 1) % NR].vs[j]))));
+ const shards = [];
+ for (let i = 0; i < NR; i++) {
+ const i1 = (i + 1) % NR;
+ for (let j = 0; j < J; j++) {
+ const pts = [];
+ if (j > 0) pts.push(...ring[i][j].slice(0, -1));
+ pts.push(...rad[i1][j].slice(0, -1));
+ if (j + 1 === J) {
+ // the outer shard follows the screen's border round any corners between its rays
+ pts.push(rays[i1].vs[J]);
+ for (let s = rays[i1].side; s !== rays[i].side; s = (s + 3) % 4) pts.push(CORNER[(s + 3) % 4]);
+ } else pts.push(...ring[i][j + 1].slice(1).reverse());
+ pts.push(...rad[i][j].slice(1).reverse());
+ const mx = pts.reduce((s, v) => s + v[0], 0) / pts.length, my = pts.reduce((s, v) => s + v[1], 0) / pts.length;
+ const r = (k) => rand(seed, i, j, 7, k), near = clamp(Math.hypot((mx - cx) / W, (my - cy) / H) * 1.7);
+ shards.push({
+ pts, mx, my, start: 0.53 + 0.1 * near + 0.03 * r(1),
+ vx: (mx - cx) * 0.7 + (r(2) - 0.5) * 30, vy: -25 * r(3) + (my - cy) * 0.4, spin: (r(4) - 0.5) * 6, ph: r(5) * TAU,
+ });
+ }
+ }
+ // rasterize every shard once: a mask with its edges marked (1 faces up-left, 2 the rest), and which shard
+ // owns each screen pixel
+ const owner = new Int16Array(W * H).fill(-1);
+ shards.forEach((sh, si) => {
+ let x0 = Infinity, y0 = Infinity, x1 = -Infinity, y1 = -Infinity;
+ for (const [x, y] of sh.pts) (x0 = Math.min(x0, x)), (x1 = Math.max(x1, x)), (y0 = Math.min(y0, y)), (y1 = Math.max(y1, y));
+ x0 = Math.max(0, Math.floor(x0)); y0 = Math.max(0, Math.floor(y0)); x1 = Math.min(W - 1, Math.ceil(x1)); y1 = Math.min(H - 1, Math.ceil(y1));
+ const w = x1 - x0 + 1, h = y1 - y0 + 1, m = new Uint8Array(w * h), n = sh.pts.length;
+ for (let y = 0; y < h; y++)
+ for (let x = 0; x < w; x++) {
+ const px = x0 + x + 0.5, py = y0 + y + 0.5;
+ let inside = false;
+ for (let a = 0, b = n - 1; a < n; b = a++) {
+ const [xa, ya] = sh.pts[a], [xb, yb] = sh.pts[b];
+ if (ya > py !== yb > py && px < ((xb - xa) * (py - ya)) / (yb - ya) + xa) inside = !inside;
+ }
+ if (inside) (m[y * w + x] = 1), (owner[(y0 + y) * W + x0 + x] = si);
+ }
+ const In = (x, y) => x >= 0 && y >= 0 && x < w && y < h && m[y * w + x] > 0;
+ for (let y = 0; y < h; y++)
+ for (let x = 0; x < w; x++)
+ if (m[y * w + x]) m[y * w + x] = !In(x, y - 1) || !In(x - 1, y) ? 2 : !In(x, y + 1) || !In(x + 1, y) ? 3 : 1;
+ Object.assign(sh, { x0, y0, w, h, m });
+ });
+ // a pixel center that no shard claimed (right on a crack) goes to its neighbour
+ for (let i = 0; i < owner.length; i++) if (owner[i] < 0) owner[i] = owner[i - 1] ?? owner[i - W] ?? 0;
+ const v = { cx, cy, rad, ring, shards, J, F, NR, owner };
+ cache.set(key, v);
+ return v;
+}
+
+export function draw(p, t, o) {
+ const C = accents(o.palette), ink = hex(o.color), n = C.length, D = meta.duration, u = t / D, S = o.seed;
+ if (u >= 1) return;
+ const { cx, cy, rad, ring, shards, J, F, NR, owner } = pattern(S, Math.max(5, o.rays | 0));
+ const glint = C[n - 2], edge = C[n - 3], dark = C[Math.min(1, n - 1)], deep = C[0];
+ // 1. the pane drops in, lands with one small bounce; a faint sheen rides on it
+ if (u < 0.44) {
+ const s = seg(u, 0.04, 0.4), yb = H * (s < 0.72 ? (s / 0.72) ** 2 : 1 - 0.07 * Math.sin((Math.PI * (s - 0.72)) / 0.28));
+ if (yb < 0.5) return;
+ const sheen = 1 - seg(u, 0.3, 0.4);
+ screen(p, (x, y, o2) => {
+ if (y > yb) return;
+ const q = x - 30 - (y - yb + H) * 0.75;
+ if ((q > 0 && q < 6) || (q > 10 && q < 12)) {
+ if (sheen <= 0) return ink;
+ // the sheen dithers away once the pane has landed (drawn twice: ink under, sheen over)
+ return Math.floor(x) % 2 === Math.floor(y) % 2 || sheen > 0.5 ? dark : ink;
+ }
+ return ink;
+ });
+ if (yb < H - 0.5) p.rect(0, Math.floor(yb), W, 1, edge);
+ return;
+ }
+ // 2. a brief hold, then the cracks race out from the impact
+ if (u < 0.53) {
+ fill(p, ink);
+ const c = ease.outQuart(seg(u, 0.44, 0.5));
+ if (c <= 0) return;
+ const hot = u < 0.48;
+ for (let i = 0; i < NR; i++)
+ for (let j = 0; j < J; j++) {
+ if (c <= F[j]) break;
+ const k = clamp((c - F[j]) / (F[j + 1] - F[j])), path = rad[i][j];
+ // draw the crack only as far as it has run
+ const segs = path.length - 1, upto = k * segs;
+ for (let q = 0; q < segs && q < upto; q++) {
+ const [x0, y0] = path[q], [x1, y1] = path[q + 1], f = clamp(upto - q);
+ clipLine(p, x0, y0, lerp(x0, x1, f), lerp(y0, y1, f), hot ? WHITE : glint);
+ }
+ }
+ // a few ring cracks join up behind them
+ for (let i = 0; i < NR; i++)
+ for (let j = 1; j < J; j++) {
+ if (c < F[j] + 0.15 || rand(S, i, j, 9) > 0.55) continue;
+ const path = ring[i][j];
+ for (let q = 1; q < path.length; q++) clipLine(p, path[q - 1][0], path[q - 1][1], path[q][0], path[q][1], edge);
+ }
+ const fl = 1 - seg(u, 0.44, 0.48);
+ if (fl > 0) {
+ p.circle(cx, cy, 1 + 4 * fl, WHITE);
+ p.glow(cx, cy, 34, C[n - 3], 0.7 * fl);
+ }
+ // glass dust puffs out of the impact
+ burst(10, S + 3, (r) => {
+ const age = (u - 0.44) * D, life = r.range(0.15, 0.3);
+ if (age < 0 || age > life) return;
+ const a = r.range(0, TAU), sp = r.range(30, 70), [x, y] = fly(cx, cy, Math.cos(a) * sp, Math.sin(a) * sp, age, 80, 4);
+ if (onScreen(x, y)) p.px(x, y, age / life < 0.5 ? WHITE : glint);
+ });
+ return;
+ }
+ // 3. the glass falls: shards nearest the impact go first, tumbling and catching the light as they drop
+ const fade = 1 - seg(u, 0.96, 1);
+ screen(p, (x, y) => {
+ const si = owner[Math.floor(y) * W + Math.floor(x)];
+ if (u < shards[si].start) return ink;
+ });
+ // the cracks between shards still in place: radial ones, and the ring ones that showed when it broke
+ const crack = (path) => {
+ for (let q = 1; q < path.length; q++) clipLine(p, path[q - 1][0], path[q - 1][1], path[q][0], path[q][1], edge);
+ };
+ for (let i = 0; i < NR; i++)
+ for (let j = 0; j < J; j++) {
+ const a = shards[i * J + j], b = shards[((i + NR - 1) % NR) * J + j];
+ if (u < a.start || u < b.start) crack(rad[i][j]);
+ if (j > 0 && rand(S, i, j, 9) <= 0.55 && (u < a.start || u < shards[i * J + j - 1].start)) crack(ring[i][j]);
+ }
+ for (const s of shards) {
+ if (u < s.start) continue;
+ const a = (u - s.start) * D, th = s.spin * a, cs = Math.cos(th), sn = Math.sin(th);
+ const ox = s.vx * a, oy = s.vy * a + 0.5 * 950 * a * a, px = s.mx + ox, py = s.my + oy;
+ // where the shard's box lands, then each screen pixel there looks back into the shard's mask
+ let X0 = Infinity, Y0 = Infinity, X1 = -Infinity, Y1 = -Infinity;
+ for (const [qx, qy] of [[s.x0, s.y0], [s.x0 + s.w, s.y0], [s.x0, s.y0 + s.h], [s.x0 + s.w, s.y0 + s.h]]) {
+ const rx = qx - s.mx, ry = qy - s.my, X = px + rx * cs - ry * sn, Y = py + rx * sn + ry * cs;
+ (X0 = Math.min(X0, X)), (X1 = Math.max(X1, X)), (Y0 = Math.min(Y0, Y)), (Y1 = Math.max(Y1, Y));
+ }
+ X0 = Math.max(0, Math.floor(X0)); Y0 = Math.max(0, Math.floor(Y0)); X1 = Math.min(W - 1, Math.ceil(X1)); Y1 = Math.min(H - 1, Math.ceil(Y1));
+ if (X0 > X1 || Y0 > Y1) continue;
+ // as a shard turns it flashes: a lighter fill and bright edges while it faces the light
+ const face = Math.cos(th * 1.6 + s.ph), lit = face > 0.2;
+ const fillC = face > 0.75 ? dark : lit ? deep : ink, upC = lit ? glint : edge, downC = lit ? edge : deep;
+ for (let Y = Y0; Y <= Y1; Y++)
+ for (let X = X0; X <= X1; X++) {
+ const dx = X + 0.5 - px, dy = Y + 0.5 - py;
+ const mx = Math.floor(s.mx + dx * cs + dy * sn) - s.x0, my = Math.floor(s.my - dx * sn + dy * cs) - s.y0;
+ if (mx < 0 || my < 0 || mx >= s.w || my >= s.h) continue;
+ const k = s.m[my * s.w + mx];
+ if (k) p.dot(X, Y, k === 2 ? upC : k === 3 ? downC : fillC, fade);
+ }
+ }
+}
diff --git a/src/fx/transitions/slash-wipe.js b/src/fx/transitions/slash-wipe.js
new file mode 100644
index 0000000..3da82d0
--- /dev/null
+++ b/src/fx/transitions/slash-wipe.js
@@ -0,0 +1,50 @@
+import { PAL, hex, ease, burst, fly, WHITE } from "../../core/index.js";
+import { screenMeta, timeline, screen, fill, onScreen, W, H, accents } from "./_lib.js";
+
+export const meta = screenMeta({
+ name: "Slash wipe",
+ desc: "A blade-bright diagonal edge whips across and drags the cover in behind it, throwing sparks; the cover leaves the same way.",
+ tags: ["wipe", "slash", "diagonal", "fast"],
+ duration: 1.1,
+ options: { palette: PAL.ice, slant: 0.45 },
+});
+
+export function draw(p, t, o) {
+ const C = accents(o.palette), ink = hex(o.color), n = C.length, S = o.seed, D = meta.duration;
+ const { cin, cout, out } = timeline(t, D);
+ if (!out && cin >= 1) return fill(p, ink);
+ if (out && cout >= 1) return;
+ const sl = o.slant, span = sl * H / 2 + 10, nrm = 1 / Math.hypot(1, sl);
+ // the edge crosses at x = e + (H/2 - y) * slant: "/" leaning right, moving right, fast in the middle
+ const edgeAt = (k) => -span + 14 + (W + span * 2 - 14) * ease.inOutSine(k);
+ const e = edgeAt(out ? cout : cin);
+ const hot = C[n - 2], mid = C[Math.max(0, n - 4)], deep = C[Math.max(0, n - 6)];
+ screen(p, (x, y, o2) => {
+ const xe = e + (H / 2 - y) * sl, d = (out ? x - xe : xe - x) * nrm; // > 0 on the cover side
+ if (d < -6) return;
+ if (d < 0) {
+ // light spills a few px ahead of the blade
+ o2.l = C[n - 3];
+ o2.k = 0.35 * (1 + d / 6) ** 2;
+ return;
+ }
+ if (d < 1.2) return WHITE;
+ if (d < 2.4) return hot;
+ if (d < 4) return mid;
+ if (d < 6) return (Math.floor(x) + Math.floor(y)) & 1 ? deep : ink;
+ return ink;
+ });
+ // sparks grind off the edge and spray back over the cover, arcing down as they cool
+ const half = out ? cout : cin, T = (out ? 1 - 0.58 : 0.45) * D, dir = out ? 1 : -1;
+ burst(22, S + (out ? 50 : 0), (r) => {
+ const k0 = r.range(0.15, 0.85), age = (half - k0) * T;
+ const life = r.range(0.14, 0.3);
+ if (age < 0 || age > life) return;
+ const y0 = r.range(6, H - 6), x0 = edgeAt(k0) + (H / 2 - y0) * sl;
+ const vx = dir * r.range(40, 140), vy = r.range(-90, 10);
+ const [x, y] = fly(x0, y0, vx, vy, age, 260, 3), q = age / life, c = q < 0.35 ? WHITE : q < 0.7 ? hot : mid;
+ const [x1, y1] = fly(x0, y0, vx, vy, Math.max(0, age - 0.02), 260, 3);
+ if (onScreen(x, y)) p.px(x, y, c);
+ if (q < 0.6 && onScreen(x1, y1)) p.px(x1, y1, mid);
+ });
+}
diff --git a/src/fx/transitions/spiral-wipe.js b/src/fx/transitions/spiral-wipe.js
new file mode 100644
index 0000000..55106bc
--- /dev/null
+++ b/src/fx/transitions/spiral-wipe.js
@@ -0,0 +1,54 @@
+import { PAL, hex, ease, wrap, TAU } from "../../core/index.js";
+import { screenMeta, timeline, screen, fill, W, H, accents } from "./_lib.js";
+
+export const meta = screenMeta({
+ name: "Spiral wipe",
+ desc: "A glowing spiral arm sweeps clockwise in from the corners and winds the cover shut at the center, then unwinds it from the middle out.",
+ tags: ["wipe", "spiral", "swirl"],
+ duration: 1.6,
+ options: { palette: PAL.volt, turns: 2 },
+});
+
+// the spiral coordinate of every pixel, in (from the rim) and out (from the center): one sweep of a clock
+// hand per turn, ring by ring. It never changes, so it's worked out once per turn count.
+const cache = new Map();
+function spiral(T) {
+ if (cache.has(T)) return cache.get(T);
+ const sIn = new Float32Array(W * H), sOut = new Float32Array(W * H), cx = W / 2, cy = H / 2;
+ for (let y = 0; y < H; y++)
+ for (let x = 0; x < W; x++) {
+ const dx = (x + 0.5 - cx) / cx, dy = (y + 0.5 - cy) / cy, rho = Math.min(1, Math.hypot(dx, dy) / Math.SQRT2);
+ const a = wrap(Math.atan2(dy, dx) / TAU + 0.25, 1); // 0 at twelve o'clock, clockwise
+ sIn[y * W + x] = ((1 - rho) * T + a) / (T + 1);
+ sOut[y * W + x] = (rho * T + a) / (T + 1);
+ }
+ const v = { sIn, sOut };
+ cache.set(T, v);
+ return v;
+}
+
+export function draw(p, t, o) {
+ const C = accents(o.palette), ink = hex(o.color), n = C.length, T = Math.max(0.5, o.turns);
+ const { cin, cout, out } = timeline(t, meta.duration);
+ if (!out && cin >= 1) return fill(p, ink);
+ if (out && cout >= 1) return;
+ const k = out ? ease.inOutSine(cout) : ease.inOutSine(cin);
+ const s = out ? spiral(T).sOut : spiral(T).sIn;
+ const hot = C[n - 2], mid = C[Math.max(0, n - 4)];
+ // in: covered where s < k. out: uncovered where s < k
+ const cov = (x, y) => x < 0 || y < 0 || x >= W || y >= H || (out ? s[y * W + x] >= k : s[y * W + x] < k);
+ const band = 0.022;
+ screen(p, (x, y, o2) => {
+ const ix = Math.floor(x), iy = Math.floor(y), v = s[iy * W + ix];
+ const d = out ? v - k : k - v; // > 0 on the cover side
+ if (d < 0) {
+ if (d > -0.03) (o2.l = C[n - 3]), (o2.k = 0.4 * (1 + d / 0.03));
+ return;
+ }
+ // the rim follows the spiral front and the seam where the arm restarts each turn
+ const seam = !cov(ix - 1, iy) || !cov(ix + 1, iy) || !cov(ix, iy - 1) || !cov(ix, iy + 1);
+ if (d < band * 0.5 || seam) return hot;
+ if (d < band || (!cov(ix - 2, iy) || !cov(ix + 2, iy) || !cov(ix, iy - 2) || !cov(ix, iy + 2))) return mid;
+ return ink;
+ });
+}
diff --git a/src/fx/transitions/star-iris.js b/src/fx/transitions/star-iris.js
new file mode 100644
index 0000000..f127e9e
--- /dev/null
+++ b/src/fx/transitions/star-iris.js
@@ -0,0 +1,55 @@
+import { PAL, hex, seg, lerp, wrap, TAU, WHITE } from "../../core/index.js";
+import { screenMeta, timeline, screen, fill, W, H, accents } from "./_lib.js";
+
+export const meta = screenMeta({
+ name: "Star iris",
+ desc: "A five-point star iris spins shut with a gold rim, twinkles at its tips as it vanishes, then spins back open the other way.",
+ tags: ["iris", "star", "cartoon", "magic"],
+ duration: 1.5,
+ options: { palette: PAL.gold, points: 5, cx: 80, cy: 45, inner: 0.48 },
+});
+
+export function draw(p, t, o) {
+ const C = accents(o.palette), ink = hex(o.color), n = C.length, N = Math.max(3, o.points | 0);
+ const { cin, cout, out } = timeline(t, meta.duration);
+ const cx = o.cx, cy = o.cy, ratio = o.inner;
+ // big enough that the inner corners clear every screen corner
+ const far = Math.max(Math.hypot(cx, cy), Math.hypot(W - cx, cy), Math.hypot(cx, H - cy), Math.hypot(W - cx, H - cy));
+ const Rmax = far / (ratio * Math.cos(Math.PI / N)) + 4;
+ // fast through the huge sizes, slowing as the star gets small (and the reverse on the way out)
+ const k = out ? 1 - cout * cout : 1 - (1 - cin) ** 2.2;
+ const R = Rmax * (1 - k);
+ if (R <= 0.5) return fill(p, ink);
+ if (R >= Rmax) return;
+ const rot = -Math.PI / 2 + (out ? -1 : 1) * 2.4 * k;
+ const sector = TAU / N, half = sector / 2;
+ // the edge from a tip (R, 0) to an inner corner, in the folded sector
+ const ax = R, ay = 0, bx = R * ratio * Math.cos(half), by = R * ratio * Math.sin(half);
+ const ex = bx - ax, ey = by - ay, el = Math.hypot(ex, ey);
+ const rim = C[n - 3], hot = C[n - 2], deep = C[Math.max(0, n - 5)];
+ screen(p, (x, y) => {
+ const dx = x - cx, dy = y - cy, rho = Math.hypot(dx, dy);
+ let f = wrap(Math.atan2(dy, dx) - rot, sector);
+ if (f > half) f = sector - f;
+ const px = rho * Math.cos(f), py = rho * Math.sin(f);
+ const d = ((px - ax) * ey - (py - ay) * ex) / el; // > 0 outside the star
+ if (d <= 0) return;
+ if (d < 1) return hot;
+ if (d < 2) return rim;
+ if (d < 3) return deep;
+ return ink;
+ });
+ // twinkles pop at the tips as the star gets small
+ const tw = seg(R, 40, 8) * (out ? 1 : 1 - seg(R, 8, 2));
+ if (tw > 0) {
+ for (let i = 0; i < N; i++) {
+ const a = rot + i * sector, tx = cx + Math.cos(a) * (R + 4), ty = cy + Math.sin(a) * (R + 4);
+ const s = Math.round(lerp(1, 3, tw) * (0.7 + 0.3 * Math.sin(t * 40 + i * 2)));
+ p.line(tx - s, ty, tx + s, ty, hot);
+ p.line(tx, ty - s, tx, ty + s, hot);
+ p.px(tx, ty, WHITE);
+ p.light(tx, ty, C[n - 3], 0.4 * tw);
+ }
+ }
+ p.glow(cx, cy, Math.min(30, R * 0.8 + 4), C[n - 3], 0.25 * seg(R, 60, 10));
+}
diff --git a/src/fx/ui/_lib.js b/src/fx/ui/_lib.js
new file mode 100644
index 0000000..8feeb54
--- /dev/null
+++ b/src/fx/ui/_lib.js
@@ -0,0 +1,46 @@
+// Helpers for the ui effects: chunky outlined text, per-letter layout, shakes. Not an effect (starts with _).
+
+import { noise } from "../../core/index.js";
+export { Layer, twinkle, fit } from "../pickups/_lib.js";
+
+/**
+ * Text with a thick outline and an optional drop shadow, so it reads over anything. (x, y) is the top of the
+ * text at its center (or left/right with align). w is the outline width in px, sh the shadow's drop in px.
+ */
+export function boldText(p, str, x, y, fill, { font = "big", scale = 1, outline, shadow, w = 1, sh = 1, a = 1, align = "center" } = {}) {
+ const o = { font, scale, align, a };
+ if (shadow !== undefined)
+ for (let dy = -w; dy <= w; dy++) for (let dx = -w; dx <= w; dx++) p.text(str, x + dx, y + dy + sh, shadow, o);
+ if (outline !== undefined)
+ for (let dy = -w; dy <= w; dy++) for (let dx = -w; dx <= w; dx++) if (dx || dy) p.text(str, x + dx, y + dy, outline, o);
+ p.text(str, x, y, fill, o);
+}
+
+/** Where each letter of str sits: [{ ch, x, w }] with x from the left edge, plus the total width. */
+export function letters(p, str, font = "big", scale = 1) {
+ const out = [];
+ let x = 0;
+ for (const ch of str) {
+ const w = p.measure(ch, { font, scale })[0];
+ out.push({ ch, x, w });
+ x += w + scale;
+ }
+ return { list: out, w: Math.max(0, x - scale) };
+}
+
+/** A whole-pixel shake that dies away: [dx, dy] for time t, amplitude amp (px), decaying from t0 over len s. */
+export function shake(t, amp, t0 = 0, len = 0.3, seed = 1, hz = 30) {
+ const k = 1 - Math.min(1, Math.max(0, (t - t0) / len));
+ if (k <= 0 || t < t0) return [0, 0];
+ return [Math.round(noise(t * hz, seed) * amp * k * 1.6), Math.round(noise(t * hz, seed + 7) * amp * k * 1.2)];
+}
+
+/** Stamp a layer slanted like italics: each row above y0 shifts right by k px per row (whole pixels). */
+export function blitSlant(p, L, k, y0, dx = 0, dy = 0, a = 1) {
+ const f = L.f, C = f.color;
+ for (let i = 0; i < C.length; i++) {
+ if (!C[i]) continue;
+ const x = (i % f.w) + f.ox, y = Math.floor(i / f.w) + f.oy;
+ p.dot(x + dx + Math.round((y0 - y) * k), y + dy, C[i], a);
+ }
+}
diff --git a/src/fx/ui/achievement.js b/src/fx/ui/achievement.js
new file mode 100644
index 0000000..3dcda89
--- /dev/null
+++ b/src/fx/ui/achievement.js
@@ -0,0 +1,62 @@
+import { PAL, RAMP, seg, ease, bump, WHITE } from "../../core/index.js";
+import { Layer, boldText, twinkle, fit } from "./_lib.js";
+
+export const meta = {
+ name: "Achievement",
+ desc: "An achievement toast slides in from the right edge with a bump: a gold medal on a ribbon, ACHIEVEMENT UNLOCKED, a shine sweeping across, then it slides away.",
+ tags: ["ui", "achievement", "unlock", "toast", "reward", "text", "one-shot"],
+ size: [100, 40],
+ origin: [50, 20],
+ duration: 2.2,
+ loop: false,
+ fps: 30,
+ bg: "dark",
+ options: { palette: PAL.arcane, title: "ACHIEVEMENT", text: "UNLOCKED", seed: 7 },
+};
+
+const L = new Layer(104, 40);
+const GOLD = RAMP.gold, STAR = ["..a..", ".aba.", "aabaa", ".a.a."];
+const PW = 44, PH = 12; // panel half-width, half-height
+
+export function draw(p, t, o) {
+ const C = fit(o.palette);
+ // slide in from the right edge with a bump, out again at the end
+ const inK = ease.outBack(seg(t, 0, 0.32), 1.2), outK = ease.inBack(seg(t, 1.85, 2.15), 1.4);
+ const x = Math.round(100 * (1 - inK) + 100 * outK);
+ if (x >= 98) return;
+ const q = L.begin(-52, -20);
+ // the panel: a rounded plate, a lit border, a darker lower half
+ for (let y = -PH; y <= PH; y++)
+ for (let xx = -PW; xx <= PW; xx++) {
+ const corner = (Math.abs(y) === PH && Math.abs(xx) >= PW - 1) || (Math.abs(y) === PH - 1 && Math.abs(xx) === PW);
+ if (corner) continue;
+ const edge = Math.abs(y) === PH || Math.abs(xx) === PW || (Math.abs(y) === PH - 1 && Math.abs(xx) === PW - 1);
+ q.px(xx, y, edge ? (y < 0 ? C[5] : C[4]) : y === -PH + 1 ? C[3] : y > 4 ? C[1] : C[2]);
+ }
+ // the medal: ribbon tails behind a gold disc with a star
+ const mx = -PW + 13;
+ q.poly([[mx - 5, 1], [mx - 1, 1], [mx - 2, 11], [mx - 4, 9], [mx - 6, 11]], C[5]);
+ q.poly([[mx + 1, 1], [mx + 5, 1], [mx + 6, 11], [mx + 4, 9], [mx + 2, 11]], C[4]);
+ q.circle(mx, -2, 8.5, GOLD[1]);
+ q.circle(mx, -2, 7.5, (d, a) => (d > 0.8 ? (Math.sin(a) < 0 && Math.cos(a) < 0.6 ? GOLD[6] : GOLD[4]) : d > 0.64 ? GOLD[3] : GOLD[5]));
+ q.sprite(STAR, { a: GOLD[6], b: WHITE }, mx - 2, -4);
+ // the words
+ q.text(o.title, mx + 12, -8, C[6], { font: "mini" });
+ boldText(q, o.text, mx + 12, -1, (gx, gy) => (gy < 3 ? WHITE : C[7] ?? WHITE), { outline: C[0], align: "left" });
+ L.outline(C[0]);
+ // a shine sweeps across the plate once it has landed
+ const sk = seg(t, 0.55, 0.95);
+ if (sk > 0 && sk < 1) {
+ const s = -PW - 12 + (PW * 2 + 24) * ease.inOutSine(sk);
+ L.map((px, py, c) => {
+ if (c === C[0]) return c;
+ const d = px + 0.5 - (py + 0.5) * 0.6 - s;
+ return Math.abs(d) < 1.2 ? WHITE : Math.abs(d) < 2.4 || Math.abs(d + 5) < 0.8 ? (c === WHITE ? c : C[6]) : c;
+ });
+ }
+ L.draw(p, x, 0, 1, [-50, 50]);
+ // the medal glints and the plate glows as it lands
+ const g = bump(t, 0.95, 1.25);
+ if (g > 0 && x === 0) twinkle(p, mx + 5, -8, Math.round(1 + g * 3), GOLD[5], GOLD[6]);
+ p.glow(x, 0, 52, C[4], 0.22 * bump(t, 0.2, 0.9));
+}
diff --git a/src/fx/ui/button-press.js b/src/fx/ui/button-press.js
new file mode 100644
index 0000000..9534390
--- /dev/null
+++ b/src/fx/ui/button-press.js
@@ -0,0 +1,73 @@
+import { PAL, hex, burst, seg, ease, WHITE } from "../../core/index.js";
+import { Layer, fit } from "./_lib.js";
+
+export const meta = {
+ name: "Button press",
+ desc: "A cursor glides onto a chunky PLAY button and clicks: the face sinks into its lip and flashes, ripples run out from its edges, then it springs back up.",
+ tags: ["ui", "button", "click", "press", "menu", "one-shot"],
+ size: [72, 48],
+ origin: [36, 22],
+ duration: 1.4,
+ loop: false,
+ fps: 30,
+ bg: "dark",
+ options: { palette: PAL.leaf, text: "PLAY", seed: 8 },
+};
+
+const L = new Layer(80, 48);
+const HW = 18, HH = 6, LIP = 3; // face half-width, half-height, lip depth
+const CURSOR = ["k.......", "kk......", "kwk.....", "kwwk....", "kwwwk...", "kwwwwk..", "kwwwwwk.", "kwwkkkkk", "kwk.....", "kk......", "k......."];
+const INK = hex("#0b0a10");
+const PRESS = 0.42, RELEASE = 0.58;
+
+// signed distance to a rounded box of half-size (hw, hh), corner radius r
+function box(x, y, hw, hh, r) {
+ const qx = Math.abs(x) - hw + r, qy = Math.abs(y) - hh + r;
+ return Math.hypot(Math.max(qx, 0), Math.max(qy, 0)) + Math.min(Math.max(qx, qy), 0) - r;
+}
+
+export function draw(p, t, o) {
+ const C = fit(o.palette), S = o.seed, fade = 1 - seg(t, 1.15, 1.38);
+ if (fade <= 0) return;
+ // the press: down hard, then up with a little overshoot
+ const down = t < PRESS ? 0 : t < RELEASE ? LIP - 1 : Math.round(-1 * Math.sin(seg(t, RELEASE, RELEASE + 0.12) * Math.PI));
+ const flash = t >= PRESS && t < PRESS + 0.07;
+ const q = L.begin(-40, -24);
+ // the lip (the button's side), then the face on top of it, sunk by `down`
+ L.fill(-HW - 1, -HH + 1, HW + 1, HH + LIP + 1, (x, y) => (box(x, y - LIP, HW, HH, 3) < 0 ? (y > HH + LIP - 1.5 ? C[1] : C[2]) : 0));
+ L.fill(-HW - 1, -HH - 1 + down, HW + 1, HH + 1 + down, (x, y) => {
+ const d = box(x, y - down, HW, HH, 3);
+ if (d >= 0) return 0;
+ if (flash) return d > -1 ? WHITE : C[6];
+ const yy = y - down;
+ return d > -1 ? (yy < 0 ? C[6] : C[4]) : yy < -HH + 2 ? C[5] : down > 0 ? C[3] : C[4];
+ });
+ q.text(o.text, 0, -3 + down + 1, INK, { font: "big", align: "center" });
+ q.text(o.text, 0, -3 + down, flash ? C[3] : WHITE, { font: "big", align: "center" });
+ L.outline(C[0]);
+ L.draw(p, 0, 0, fade);
+ // ripples run out from its edges, two of them
+ for (let i = 0; i < 2; i++) {
+ const k = seg(t, PRESS + i * 0.08, PRESS + 0.4 + i * 0.08);
+ if (k <= 0 || k >= 1) continue;
+ const R = 2 + 12 * ease.outCubic(k);
+ p.shade(-HW - 16, -HH - 16, HW + 16, HH + LIP + 16, (x, y, out) => {
+ if (Math.abs(box(x, y - 1, HW, HH + 1, 4) - R) > 0.55) return;
+ out.c = k < 0.4 ? C[6] : C[5 - i];
+ out.a = (k < 0.6 ? 1 : 0.5) * fade;
+ });
+ }
+ // sparks off the corners
+ burst(4, S, (r, i) => {
+ const k = seg(t, PRESS, PRESS + 0.3);
+ if (k <= 0 || k >= 1) return;
+ const sx = i % 2 ? 1 : -1, sy = i < 2 ? -1 : 1, d = 4 + 8 * ease.outCubic(k);
+ const x = sx * (HW + d), y = sy * (HH + d * 0.6) + 1;
+ p.line(x - sx * 2 * (1 - k), y - sy * 1.2 * (1 - k), x, y, C[6]);
+ });
+ // the cursor glides in from the lower right, dips on the click
+ const ck = ease.outCubic(seg(t, 0, 0.36)), dip = t >= PRESS - 0.04 && t < RELEASE ? 1 : 0;
+ const cx = Math.round(26 - 18 * ck), cy = Math.round(13 - 11 * ck + dip + Math.max(0, down));
+ p.sprite(CURSOR, { k: INK, w: WHITE }, cx, cy, { a: fade * (1 - seg(t, 0.95, 1.15)) });
+ p.glow(0, 1, 30, C[4], (flash ? 0.5 : 0.12) * fade);
+}
diff --git a/src/fx/ui/checkmark.js b/src/fx/ui/checkmark.js
new file mode 100644
index 0000000..23fe3c1
--- /dev/null
+++ b/src/fx/ui/checkmark.js
@@ -0,0 +1,53 @@
+import { PAL, burst, seg, ease, TAU, WHITE } from "../../core/index.js";
+import { Layer, twinkle, fit } from "./_lib.js";
+
+export const meta = {
+ name: "Checkmark",
+ desc: "A green badge pops in, a white check draws itself across it in one stroke, the badge thumps bigger and settles while a ring and sparkles fly off.",
+ tags: ["ui", "check", "success", "confirm", "done", "one-shot"],
+ size: [56, 56],
+ origin: [28, 28],
+ duration: 1.3,
+ loop: false,
+ fps: 30,
+ bg: "dark",
+ options: { palette: PAL.heal, seed: 12 },
+};
+
+const L = new Layer(56, 56);
+const PTS = [[-6, 0], [-2, 4.5], [6.5, -5]];
+const L1 = Math.hypot(4, 4.5), L2 = Math.hypot(8.5, 9.5);
+
+export function draw(p, t, o) {
+ const C = fit(o.palette), S = o.seed;
+ // the badge pops in, thumps when the check lands, shrinks away at the end
+ const inK = ease.outBack(seg(t, 0, 0.16), 2.2), thump = 1 + 0.22 * Math.sin(Math.PI * seg(t, 0.36, 0.5));
+ const sc = inK * thump * (1 - ease.inBack(seg(t, 1.1, 1.28), 2));
+ if (sc <= 0.03) return;
+ const R = 11 * sc;
+ const q = L.begin(-28, -28);
+ q.circle(0, 0, R, (d, a) => (d > 0.82 ? (Math.sin(a) < -0.3 ? C[5] : C[3]) : Math.sin(a) < -0.45 && d > 0.45 ? C[4] : C[3]));
+ // the stroke draws itself: down the short leg, then up the long one
+ const k = ease.outQuad(seg(t, 0.14, 0.36)) * (L1 + L2);
+ if (k > 0) {
+ const [a, b, c] = PTS.map(([x, y]) => [x * sc, y * sc]), w = 3.4 * sc;
+ const u1 = Math.min(1, k / L1), u2 = Math.max(0, (k - L1) / L2);
+ const ex = a[0] + (b[0] - a[0]) * u1, ey = a[1] + (b[1] - a[1]) * u1;
+ q.beam(a[0], a[1] + 1, ex, ey + 1, w, C[1]); // the cast shadow
+ if (u2 > 0) q.beam(b[0], b[1] + 1, b[0] + (c[0] - b[0]) * u2, b[1] + (c[1] - b[1]) * u2 + 1, w, C[1]);
+ q.beam(a[0], a[1], ex, ey, w, WHITE);
+ if (u2 > 0) q.beam(b[0], b[1], b[0] + (c[0] - b[0]) * u2, b[1] + (c[1] - b[1]) * u2, w, WHITE);
+ }
+ L.outline(C[0]);
+ L.draw(p);
+ // the ring and sparkles fly off on the thump
+ const rk = seg(t, 0.36, 0.62);
+ if (rk > 0 && rk < 1) p.ring(0, 0, 13 + 11 * ease.outCubic(rk), rk < 0.4 ? 2 : 1, rk < 0.5 ? C[6] : C[4], rk < 0.7 ? 1 : 0.5);
+ burst(6, S, (r, i) => {
+ const sk = seg(t, 0.38, 0.38 + r.range(0.35, 0.5));
+ if (sk <= 0 || sk >= 1) return;
+ const a = (i / 6) * TAU + r.range(-0.25, 0.25) - Math.PI / 2, d = 14 + 10 * ease.outCubic(sk);
+ twinkle(p, Math.round(Math.cos(a) * d), Math.round(Math.sin(a) * d), Math.round(1 + 2 * (1 - sk)), C[5], C[6]);
+ });
+ p.glow(0, 0, 26, C[4], 0.12 + 0.3 * Math.sin(Math.PI * seg(t, 0.36, 0.7)));
+}
diff --git a/src/fx/ui/coin-collect.js b/src/fx/ui/coin-collect.js
new file mode 100644
index 0000000..0cc68b5
--- /dev/null
+++ b/src/fx/ui/coin-collect.js
@@ -0,0 +1,69 @@
+import { PAL, hex, burst, fly, seg, ease, WHITE } from "../../core/index.js";
+import { boldText, twinkle, fit } from "./_lib.js";
+
+export const meta = {
+ name: "Coin collect",
+ desc: "Coins pop out of a pickup and hop, then streak up into the HUD counter one by one; the icon flashes and the number ticks up and bumps with each.",
+ tags: ["ui", "coin", "collect", "counter", "hud", "money", "one-shot"],
+ size: [96, 72],
+ origin: [56, 64],
+ duration: 1.55,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ options: { palette: PAL.gold, count: 5, from: 12, seed: 18 },
+};
+
+// a small spinning coin: face, three-quarter, edge; k outline, a rim, b face, c shine
+const COIN = [
+ ["..kkk..", ".kaaak.", "kabbbak", "kabcbak", "kabbbak", ".kaaak.", "..kkk.."],
+ [".kkk.", "kaaak", "kabak", "kacak", "kabak", "kaaak", ".kkk."],
+ [".k.", "kak", "kak", "kak", "kak", "kak", ".k."],
+];
+const IX = -44, IY = -52; // the HUD coin icon's center
+const INK = hex("#0b0a10"), PLATE = [hex("#1f1b2b"), hex("#3a3450")];
+
+export function draw(p, t, o) {
+ const C = fit(o.palette), S = o.seed, pal = { k: C[1], a: C[3], b: C[5], c: WHITE };
+ let got = 0, lastHit = -1;
+ // each coin: pops out and hops, then homes in on the icon, faster and faster
+ burst(o.count, S, (r, i) => {
+ const t0 = i * 0.035, th = 0.3 + i * 0.075, tArrive = th + 0.3;
+ if (t >= tArrive) {
+ got++;
+ lastHit = Math.max(lastHit, tArrive);
+ return;
+ }
+ if (t < t0) return;
+ const vx = (i - (o.count - 1) / 2) * 22 + r.range(-8, 8), vy = -r.range(110, 150);
+ let x, y;
+ if (t < th) [x, y] = fly(0, -4, vx, vy, t - t0, 330);
+ else {
+ const [hx, hy] = fly(0, -4, vx, vy, th - t0, 330), k = ease.inQuad(seg(t, th, tArrive));
+ const cx = hx + (IX - hx) * 0.2, cy = Math.min(hy, IY) - 18; // bow the path up and over
+ x = (1 - k) * (1 - k) * hx + 2 * (1 - k) * k * cx + k * k * IX;
+ y = (1 - k) * (1 - k) * hy + 2 * (1 - k) * k * cy + k * k * IY;
+ // a short streak behind it as it speeds up
+ if (k > 0.3) p.line(x + (hx - IX) * 0.08, y + (hy - IY) * 0.04 + 2, x, y, C[4]);
+ }
+ const spin = COIN[[0, 1, 2, 1][Math.floor(t * 18 + i) % 4]], w = spin[0].length;
+ p.sprite(spin, pal, Math.round(x) - (w >> 1), Math.round(y) - 3);
+ p.light(x, y, C[5], 0.3);
+ });
+ // the HUD: the icon flashes and the number bumps as each coin lands; it all blinks away at the end
+ const end = seg(t, 1.3, 1.52);
+ if (end >= 1 || (end > 0 && Math.floor(t * 30) % 2)) return;
+ const hit = lastHit >= 0 && t - lastHit < 0.1, pop = hit ? 1 : 0;
+ // a little HUD plate slides down into place behind the counter
+ const drop = Math.round(-3 * (1 - ease.outBack(seg(t, 0, 0.12), 1.6)));
+ const plateW = 12 + p.measure(String(o.from + got), { font: "big" })[0] + 4;
+ p.rect(IX - 7, IY - 7 + drop, plateW + 2, 14, INK);
+ p.rect(IX - 6, IY - 6 + drop, plateW, 12, PLATE[0]);
+ p.rect(IX - 6, IY - 6 + drop, plateW, 1, PLATE[1]);
+ if (drop) return;
+ p.sprite(COIN[0], hit ? { k: C[1], a: WHITE, b: WHITE, c: WHITE } : pal, IX - 3, IY - 3 - pop);
+ if (hit) p.glow(IX, IY, 12, C[5], 0.6);
+ const n = String(o.from + got);
+ boldText(p, n, IX + 6, IY - 4 - pop, hit ? WHITE : (gx, gy) => (gy < 2 ? WHITE : gy < 5 ? C[6] : C[5]), { outline: C[1], shadow: C[0], align: "left" });
+ if (hit) twinkle(p, IX + 4, IY - 5, 2, C[5], C[6]);
+}
diff --git a/src/fx/ui/combo-counter.js b/src/fx/ui/combo-counter.js
new file mode 100644
index 0000000..d28f4d9
--- /dev/null
+++ b/src/fx/ui/combo-counter.js
@@ -0,0 +1,54 @@
+import { PAL, burst, seg, ease, TAU, WHITE } from "../../core/index.js";
+import { Layer, boldText, blitSlant, shake, fit } from "./_lib.js";
+
+export const meta = {
+ name: "Combo counter",
+ desc: "A slanted x5 COMBO punches in from the left on speed lines, lands with a white flash, a jolt and a ring, pulses, then hops up and blinks out.",
+ tags: ["ui", "combo", "counter", "streak", "text", "directional", "one-shot"],
+ size: [88, 52],
+ origin: [44, 30],
+ duration: 1.3,
+ loop: false,
+ fps: 30,
+ bg: "dark",
+ options: { palette: PAL.neon, count: 5, label: "COMBO", seed: 4 },
+};
+
+const L = new Layer(96, 48);
+const LAND = 0.12;
+
+export function draw(p, t, o) {
+ const C = fit(o.palette), S = o.seed;
+ // in from the left with an overshoot; at the end a hop up while it blinks out
+ const inK = ease.outBack(seg(t, 0, LAND), 1.4), outK = seg(t, 1.0, 1.25);
+ if (t >= 1.25) return;
+ const x = Math.round(-22 * (1 - inK)), y = Math.round(-7 * ease.outCubic(outK));
+ const [sx, sy] = shake(t, 2.5, LAND, 0.3, S);
+ // speed lines stream behind it on the way in
+ const sl = 1 - seg(t, LAND, LAND + 0.2);
+ if (sl > 0)
+ burst(5, S, (r, i) => {
+ const ly = -14 + i * 6 + Math.round(r.range(-1, 1)), x1 = x - 20 + (i % 2) * 3, len = Math.min((8 + r.range(0, 10)) * sl, x1 + 42);
+ if (len >= 2) p.line(x1 - len, ly, x1, ly, (u) => (u > 0.6 ? C[6] : C[i % 2 ? 3 : 4]));
+ });
+ if (outK > 0 && Math.floor(t * 30) % 2) return;
+ // the ring and sparks of the landing, behind the words
+ const lk = seg(t, LAND, LAND + 0.24);
+ if (lk > 0 && lk < 1) {
+ const rx = 18 + 12 * ease.outCubic(lk), ry = 12 + 7 * ease.outCubic(lk);
+ p.ellipse(sx, sy - 4, rx, ry, lk < 0.45 ? WHITE : C[5], (d) => (d > 1 - 1.4 / ry ? (lk < 0.75 ? 1 : 0.5) : 0));
+ burst(6, S + 2, (r, i) => {
+ const a = (i / 6) * TAU + r.range(-0.3, 0.3), d = 1.1 + 0.25 * ease.outCubic(lk), e = d + 0.2 * (1 - lk);
+ p.line(sx + Math.cos(a) * rx * d * 0.9, sy - 4 + Math.sin(a) * ry * d * 0.9, sx + Math.cos(a) * rx * e * 0.9, sy - 4 + Math.sin(a) * ry * e * 0.9, C[6]);
+ });
+ }
+ // the number pulses as it lands, flashing white
+ const beat = t > LAND && t < LAND + 0.07 ? 3 : 2;
+ const flash = t > LAND - 0.02 && t < LAND + 0.07;
+ const fill = flash ? WHITE : (gx, gy) => (gy < 2 ? C[7] : gy < 4 ? C[6] : gy < 6 ? C[5] : C[4]);
+ const q = L.begin(-48, -30);
+ boldText(q, "x" + o.count, 0, -14 - (beat - 2) * 8, fill, { scale: beat, outline: C[1], shadow: C[0], sh: 2 });
+ boldText(q, o.label, 0, 3, flash ? C[6] : (gx, gy) => (gy < 3 ? WHITE : C[6]), { outline: C[1], shadow: C[0] });
+ blitSlant(p, L, 0.25, 0, x + sx, y + sy);
+ p.glow(x, y - 4, 34, C[4], 0.1 + 0.4 * (t > LAND ? 1 - seg(t, LAND, LAND + 0.4) : 0));
+}
diff --git a/src/fx/ui/confetti.js b/src/fx/ui/confetti.js
new file mode 100644
index 0000000..90290c0
--- /dev/null
+++ b/src/fx/ui/confetti.js
@@ -0,0 +1,49 @@
+import { PAL, ramp, burst, fly, seg, scale, TAU, WHITE } from "../../core/index.js";
+
+export const meta = {
+ name: "Confetti",
+ desc: "Two party poppers fire from the lower corners: bright paper bits and curly streamers shoot up, stall, then flutter down tumbling, flashing their backs.",
+ tags: ["ui", "confetti", "celebrate", "party", "reward", "one-shot"],
+ size: [112, 88],
+ origin: [56, 84],
+ duration: 2.6,
+ loop: false,
+ fps: 30,
+ bg: "dark",
+ // hues, not a ramp: each bit takes one and shades its back side darker
+ options: { palette: PAL.candy, count: 36, seed: 17 },
+};
+
+export function draw(p, t, o) {
+ const C = ramp(o.palette), S = o.seed, n = o.count;
+ for (const side of [-1, 1]) {
+ const x0 = side * 50, y0 = -2;
+ // the popper's flash
+ if (t < 0.1) {
+ p.circle(x0 - side * 1, y0 - 3, 4 - t * 30, WHITE);
+ p.glow(x0, y0 - 4, 16, C[2], 0.6 * (1 - t / 0.1));
+ }
+ burst(n, S + (side > 0 ? 100 : 0), (r, i) => {
+ const life = r.range(1.7, 2.5), age = t - r.range(0, 0.06);
+ if (age < 0 || age > life) return;
+ // up and inward, fast; air drag takes the speed, then they drift down slowly
+ const a = -Math.PI / 2 - side * r.range(0.12, 0.95), sp = r.range(220, 430);
+ let [x, y] = fly(x0, y0, Math.cos(a) * sp, Math.sin(a) * sp, age, 120, r.range(4.6, 5.6));
+ if (y > -1 && age > 0.2) return; // landed
+ const slow = seg(age, 0.3, 0.9), ph = r.next() * TAU;
+ x += Math.sin(age * r.range(5, 8) + ph) * 4 * slow; // flutter side to side once they stall
+ if (age > life - 0.3 && Math.floor(age * 30) % 2) return; // blink out at the end
+ const c = C[Math.floor(r.next() * C.length)], dark = scale(c, 0.55);
+ const X = Math.round(x), Y = Math.round(y);
+ if (i % 7 === 0) {
+ // a curly streamer: a short wave trailing behind its head
+ for (let k = 0; k < 8; k++) p.px(X + Math.round(Math.sin(age * 10 + k * 1.1) * 1.6), Y - k, k % 3 === 2 ? dark : c);
+ return;
+ }
+ // a paper bit tumbling: flat, edge-on, turned, edge-on; its back is darker
+ const turn = Math.floor(age * r.range(10, 18) + ph * 4) % 4, size = i % 3 === 0 ? 3 : 2;
+ const [w, h] = turn === 0 ? [size + 1, 2] : turn === 2 ? [2, size + 1] : [2, 2];
+ p.rect(X, Y, w, h, turn < 2 ? c : dark);
+ });
+ }
+}
diff --git a/src/fx/ui/countdown.js b/src/fx/ui/countdown.js
new file mode 100644
index 0000000..ed4f0bf
--- /dev/null
+++ b/src/fx/ui/countdown.js
@@ -0,0 +1,58 @@
+import { PAL, burst, seg, ease, TAU, WHITE } from "../../core/index.js";
+import { boldText, shake, fit } from "./_lib.js";
+
+export const meta = {
+ name: "Countdown",
+ desc: "3, 2, 1 slam in one by one inside a draining timer ring and zoom away; GO! bursts out white with rays and a shockwave, then blinks off.",
+ tags: ["ui", "countdown", "start", "timer", "text", "one-shot"],
+ size: [76, 60],
+ origin: [38, 30],
+ duration: 2.5,
+ loop: false,
+ fps: 30,
+ bg: "dark",
+ options: { palette: PAL.volt, from: 3, go: "GO!", seed: 5 },
+};
+
+const STEP = 0.55;
+
+export function draw(p, t, o) {
+ const C = fit(o.palette), S = o.seed, n = o.from, goAt = n * STEP;
+ const fill = (gx, gy) => (gy < 2 ? WHITE : gy < 4 ? C[5] : gy < 6 ? C[4] : C[3]);
+ if (t < goAt) {
+ const i = Math.floor(t / STEP), k = (t - i * STEP) / STEP, label = String(n - i);
+ // the timer ring drains clockwise around the number
+ const left = 1 - ease.inOutSine(seg(k, 0.05, 0.85));
+ if (k < 0.85) {
+ p.ring(0, -1, 19, 2, C[1]);
+ if (left > 0.01) p.arc(0, -1, 19, 2, -Math.PI / 2, -Math.PI / 2 + TAU * left, (u, v) => (v > 0.5 ? C[5] : C[4]));
+ }
+ // the slam: a frame big and white, then held; it zooms away down the scales at the end
+ const scale = k < 0.06 ? 4 : k < 0.78 ? 3 : k < 0.86 ? 2 : k < 0.93 ? 1 : 0;
+ if (!scale) return;
+ // a pulse ring on the slam, behind the number
+ const rk = seg(k, 0, 0.35);
+ if (rk < 1) p.ring(0, -1, 12 + 14 * ease.outCubic(rk), rk < 0.5 ? 2 : 1, rk < 0.5 ? C[5] : C[3], rk < 0.7 ? 1 : 0.5);
+ const [sx, sy] = shake(t, 2, i * STEP + 0.02, 0.18, S + i);
+ boldText(p, label, sx, sy - Math.round(3.5 * scale) - 1, k < 0.06 ? WHITE : fill, { scale, outline: C[1], shadow: C[0], w: scale > 2 ? 2 : 1, sh: 2 });
+ p.glow(0, -1, 26, C[4], 0.35 * (1 - seg(k, 0, 0.4)));
+ return;
+ }
+ // GO!
+ const g = t - goAt, k = g / (meta.duration - goAt);
+ if (k >= 0.97) return;
+ // rays and a shockwave
+ burst(12, S, (r, i) => {
+ const rk = seg(g, 0, 0.35);
+ if (rk >= 1) return;
+ const a = (i / 12) * TAU + r.range(-0.12, 0.12), d0 = 16 + 14 * ease.outCubic(rk), d1 = d0 + (6 + r.range(0, 6)) * (1 - rk);
+ p.line(Math.cos(a) * d0, Math.sin(a) * d0 * 0.8 - 1, Math.cos(a) * d1, Math.sin(a) * d1 * 0.8 - 1, rk < 0.4 ? WHITE : C[5]);
+ });
+ const wk = seg(g, 0, 0.3);
+ if (wk < 1) p.ellipse(0, -1, 14 + 22 * ease.outCubic(wk), 10 + 16 * ease.outCubic(wk), wk < 0.4 ? WHITE : C[4], (d) => (d > 0.9 ? (wk < 0.7 ? 1 : 0.5) : 0));
+ if (k > 0.7 && Math.floor(t * 30) % 2) return;
+ const scale = g < 0.07 ? 4 : 3, flash = g < 0.12 || (g < 0.3 && Math.floor(t * 30) % 4 === 0);
+ const [sx, sy] = shake(t, 3, goAt + 0.02, 0.3, S + 9);
+ boldText(p, o.go, sx, sy - Math.round(3.5 * scale) - 1, flash ? WHITE : fill, { scale, outline: C[1], shadow: C[0], w: 2, sh: 2 });
+ p.glow(0, -1, 34, C[4], 0.5 * (1 - seg(g, 0, 0.5)) + 0.1);
+}
diff --git a/src/fx/ui/crit-number.js b/src/fx/ui/crit-number.js
new file mode 100644
index 0000000..589e0b5
--- /dev/null
+++ b/src/fx/ui/crit-number.js
@@ -0,0 +1,52 @@
+import { PAL, burst, seg, ease, rng, star, TAU, WHITE } from "../../core/index.js";
+import { boldText, shake, fit } from "./_lib.js";
+
+export const meta = {
+ name: "Crit number",
+ desc: "CRIT 128! slams in over a jagged starburst: triple size for a frame, a hard shake, white flashes, speed lines, then the burst folds away.",
+ tags: ["ui", "critical", "damage", "number", "combat", "text", "one-shot"],
+ size: [88, 70],
+ origin: [44, 38],
+ duration: 1.2,
+ loop: false,
+ fps: 30,
+ bg: "dark",
+ options: { palette: PAL.fire, text: "128!", label: "CRIT", seed: 3 },
+};
+
+export function draw(p, t, o) {
+ const C = fit(o.palette), S = o.seed;
+ const [sx, sy] = shake(t, 3, 0.02, 0.45, S);
+ // the starburst: pops past full size, settles, turns a little, then folds away
+ const grow = ease.outBack(seg(t, 0, 0.12), 3), fold = ease.inBack(seg(t, 0.85, 1.1), 2);
+ const sc = grow * (1 - fold);
+ if (sc > 0.02) {
+ const r = rng(S, 1), rot = -Math.PI / 2 + 0.25 * seg(t, 0, 1.1);
+ const pts = star(sx, sy - 2, 13 * sc, 25 * sc, 9, rot).map(([x, y], i) => {
+ const j = i % 2 ? 1 : r.range(0.85, 1.08);
+ return [sx + (x - sx) * j, sy - 2 + (y - sy + 2) * j];
+ });
+ p.poly(pts, C[2]);
+ p.poly(star(sx, sy - 2, 10 * sc, 19 * sc, 9, rot), C[3]);
+ p.poly(star(sx, sy - 2, 7 * sc, 12 * sc, 9, rot + 0.17), C[4]);
+ }
+ // speed lines flung out at the slam
+ burst(10, S + 1, (r, i) => {
+ const k = seg(t, 0.02, 0.32);
+ if (k <= 0 || k >= 1) return;
+ const a = (i / 10) * TAU + r.range(-0.15, 0.15), d0 = 14 + 26 * ease.outCubic(k), d1 = d0 + 9 * (1 - k);
+ p.line(Math.cos(a) * d0, Math.sin(a) * d0 * 0.75, Math.cos(a) * d1, Math.sin(a) * d1 * 0.75, k < 0.4 ? WHITE : C[6]);
+ });
+ if (t > 1.04 || (t > 0.8 && Math.floor(t * 30) % 3 === 0)) return; // blinking out as the burst folds
+ // the words: the number slams in at triple size, flashing white on alternate frames at first
+ const flash = t < 0.2 && Math.floor(t * 30) % 2 === 0;
+ const scale = t < 0.05 ? 3 : 2;
+ const fill = flash ? WHITE : (gx, gy) => (gy < 2 ? C[7] : gy < 4 ? C[6] : gy < 6 ? C[5] : C[4]);
+ boldText(p, o.text, sx, sy - 6 * scale + 4, fill, { scale, outline: C[1], shadow: C[0], w: 1, sh: 2 });
+ const lk = seg(t, 0.08, 0.2);
+ if (lk > 0) {
+ const ly = sy - 18 - Math.round(4 * (1 - ease.outBack(lk, 3)));
+ boldText(p, o.label, sx, ly, flash ? C[6] : (gx, gy) => (gy < 3 ? WHITE : C[6]), { outline: C[1], shadow: C[0] });
+ }
+ p.glow(sx, sy, 36, C[5], 0.5 * (1 - seg(t, 0, 0.5)) + 0.12);
+}
diff --git a/src/fx/ui/damage-number.js b/src/fx/ui/damage-number.js
new file mode 100644
index 0000000..c5f370b
--- /dev/null
+++ b/src/fx/ui/damage-number.js
@@ -0,0 +1,28 @@
+import { PAL, seg, ease, WHITE } from "../../core/index.js";
+import { boldText, fit } from "./_lib.js";
+
+export const meta = {
+ name: "Damage number",
+ desc: "A hit number punches out double size in white, snaps down to red, hops up and to the right with an overshoot, then sinks and blinks out.",
+ tags: ["ui", "damage", "number", "combat", "text", "one-shot"],
+ size: [48, 40],
+ origin: [18, 30],
+ duration: 0.9,
+ loop: false,
+ fps: 30,
+ bg: "dark",
+ options: { palette: PAL.blood, text: "-27", scale: 1, pop: true, seed: 1 },
+};
+
+export function draw(p, t, o) {
+ const C = fit(o.palette);
+ // it blinks out at the end: pixel text dissolves badly, so it flickers instead
+ if (t >= 0.86 || (t > 0.6 && Math.floor(t * 30) % 3 === 0)) return;
+ // a hop: up fast with an overshoot, a hang, then a slow sink while it fades
+ const x = 9 * ease.outCubic(seg(t, 0, 0.5));
+ const y = -15 * ease.outBack(seg(t, 0, 0.28), 2.4) + 6 * ease.inQuad(seg(t, 0.45, 0.88));
+ const big = o.pop && t < 0.05, scale = o.scale * (big ? 2 : 1), h = 7 * scale;
+ const fill = t < 0.1 ? WHITE : (gx, gy) => (gy < 2 ? C[6] : gy < 5 ? C[5] : C[4]);
+ boldText(p, o.text, Math.round(x), Math.round(y - h / 2), fill, { scale, outline: C[1], shadow: C[0] });
+ if (t < 0.1) p.glow(x, y, 16, C[5], 0.4);
+}
diff --git a/src/fx/ui/error-x.js b/src/fx/ui/error-x.js
new file mode 100644
index 0000000..451cfb4
--- /dev/null
+++ b/src/fx/ui/error-x.js
@@ -0,0 +1,50 @@
+import { PAL, burst, seg, ease, TAU, WHITE } from "../../core/index.js";
+import { Layer, fit } from "./_lib.js";
+
+export const meta = {
+ name: "Error X",
+ desc: "A fat red X slashes in stroke by stroke, white-hot at the tips, then shakes its head no, flashing, with chips flying off; it blinks out.",
+ tags: ["ui", "error", "fail", "wrong", "deny", "one-shot"],
+ size: [56, 52],
+ origin: [28, 24],
+ duration: 1.1,
+ loop: false,
+ fps: 30,
+ bg: "dark",
+ options: { palette: PAL.blood, seed: 13 },
+};
+
+const L = new Layer(56, 48);
+const A = 8; // half-size of the X
+
+export function draw(p, t, o) {
+ const C = fit(o.palette), S = o.seed;
+ if (t >= 1.05 || (t > 0.8 && Math.floor(t * 30) % 3 === 0)) return;
+ // a "no" shake: fast, side to side, dying away
+ const sh = t > 0.2 ? Math.round(4 * Math.sin((t - 0.2) * 44) * Math.max(0, 1 - (t - 0.2) / 0.45)) : 0;
+ const flash = (t > 0.18 && t < 0.24) || (t > 0.3 && t < 0.33);
+ const q = L.begin(-28, -24);
+ const stroke = (x0, y0, x1, y1, k) => {
+ if (k <= 0) return;
+ const ex = x0 + (x1 - x0) * k, ey = y0 + (y1 - y0) * k;
+ q.beam(x0 + sh, y0 + 1, ex + sh, ey + 1, 5, C[1]);
+ q.beam(x0 + sh, y0, ex + sh, ey, 5, (u, v) => (flash ? WHITE : v > 0.55 && u * k > 0.02 ? C[5] : C[4]));
+ if (k < 1) q.beam(ex + sh - (x1 - x0) * 0.12, ey - (y1 - y0) * 0.12, ex + sh, ey, 5, WHITE); // the hot tip
+ };
+ stroke(-A, -A, A, A, ease.outQuart(seg(t, 0, 0.09)));
+ stroke(A, -A, -A, A, ease.outQuart(seg(t, 0.1, 0.19)));
+ L.outline(C[0]);
+ L.draw(p);
+ // chips fly off when the second stroke lands
+ burst(7, S, (r, i) => {
+ const age = t - 0.19, life = r.range(0.22, 0.32);
+ if (age < 0 || age > life) return;
+ const a = (i / 7) * TAU + r.range(-0.3, 0.3), sp = r.range(36, 52);
+ const x = Math.cos(a) * (5 + sp * age), y = Math.sin(a) * (5 + sp * age) + 60 * age * age;
+ p.rect(Math.round(x), Math.round(y), 2, 2, age / life < 0.5 ? C[5] : C[3]);
+ });
+ // a red ring snaps out
+ const rk = seg(t, 0.19, 0.4);
+ if (rk > 0 && rk < 1) p.ring(sh, 0, 12 + 10 * ease.outCubic(rk), rk < 0.4 ? 2 : 1, rk < 0.5 ? C[6] : C[4], rk < 0.7 ? 1 : 0.5);
+ p.glow(sh, 0, 24, C[4], flash ? 0.5 : 0.15);
+}
diff --git a/src/fx/ui/exclamation.js b/src/fx/ui/exclamation.js
new file mode 100644
index 0000000..ce61820
--- /dev/null
+++ b/src/fx/ui/exclamation.js
@@ -0,0 +1,58 @@
+import { seg, ease, WHITE } from "../../core/index.js";
+import { Layer, fit } from "./_lib.js";
+
+export const meta = {
+ name: "Exclamation",
+ desc: "A fat ! springs up over the head: stretched thin on the way up, squashed as it lands, three surprise ticks flicking out; it bobs, then pinches away.",
+ tags: ["ui", "alert", "exclamation", "surprise", "notice", "status", "one-shot"],
+ size: [40, 56],
+ origin: [20, 50],
+ duration: 1.1,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ actor: true,
+ options: { palette: ["#2a1206", "#6a2a0a", "#c0480e", "#f07818", "#ffb02e", "#ffe070", "#fff8d0", "#ffffff"], seed: 16 },
+};
+
+const L = new Layer(40, 40);
+// hand-timed poses, as half-widths per row from the top of the bar, the gap, then the dot's rows and half-width
+const POSE = {
+ tall: { bar: [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0], gap: 2, dot: 3, dw: 1 },
+ normal: { bar: [1, 2, 2, 2, 2, 2, 1, 1, 1, 0], gap: 2, dot: 3, dw: 1 },
+ squash: { bar: [2, 2, 2, 2, 2, 1, 1], gap: 1, dot: 2, dw: 1 },
+ thin: { bar: [0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0], gap: 1, dot: 2, dw: 0 },
+};
+
+function mark(q, C, pose, base) {
+ const { bar, gap, dot, dw } = POSE[pose], top = base - dot - gap - bar.length;
+ const shadeRow = (y, hw, first) => {
+ for (let x = -hw; x <= hw; x++) q.px(x, y, x < 0 || hw === 0 ? (first ? WHITE : C[6]) : x === 0 ? (first ? C[6] : C[5]) : C[4]);
+ };
+ bar.forEach((hw, i) => shadeRow(top + i, hw, i === 0));
+ for (let i = 0; i < dot; i++) shadeRow(base - dot + i, dw, i === 0);
+ return top;
+}
+
+export function draw(p, t, o) {
+ const C = fit(o.palette), head = o.actor.head[1];
+ if (t >= 1.02) return;
+ const pose = t < 0.1 ? "tall" : t < 0.18 ? "squash" : t < 0.22 ? "tall" : t < 0.88 ? "normal" : t < 0.94 ? "squash" : "thin";
+ const rise = ease.outCubic(seg(t, 0, 0.1)), bobY = t > 0.3 && t < 0.88 ? Math.round(Math.sin((t - 0.3) * 9)) : 0;
+ const base = head - 4 + Math.round(4 * (1 - rise)) + bobY; // the bottom of the dot
+ L.begin(-20, base - 26);
+ const top = mark(L.q, C, pose, base);
+ L.outline(C[1]);
+ L.outline(C[0]);
+ L.draw(p);
+ // surprise ticks flick out around its top
+ const tk = seg(t, 0.12, 0.38);
+ if (tk > 0 && tk < 1) {
+ const d = 2 + 4 * ease.outCubic(tk), len = Math.round(3 * (1 - tk)) + 1;
+ for (const [dx, dy] of [[-1, -1], [0, -1], [1, -1]]) {
+ const x0 = dx * (4 + d), y0 = top - 1 + (dx ? 2 : -d * 0.8);
+ p.line(x0, y0, x0 + dx * len, y0 + dy * len, tk < 0.5 ? WHITE : C[5]);
+ }
+ }
+ p.glow(0, base - 7, 14, C[5], 0.3 * (1 - seg(t, 0.1, 0.6)) + 0.08);
+}
diff --git a/src/fx/ui/heal-number.js b/src/fx/ui/heal-number.js
new file mode 100644
index 0000000..3c0c910
--- /dev/null
+++ b/src/fx/ui/heal-number.js
@@ -0,0 +1,45 @@
+import { PAL, burst, seg, ease, bump, WHITE } from "../../core/index.js";
+import { boldText, letters, fit } from "./_lib.js";
+
+export const meta = {
+ name: "Heal number",
+ desc: "A green +15 rises in letter by letter and drifts gently upward, little plus signs floating up beside it, then it blinks away.",
+ tags: ["ui", "heal", "number", "health", "text", "one-shot"],
+ size: [44, 48],
+ origin: [22, 38],
+ duration: 1.3,
+ loop: false,
+ fps: 30,
+ bg: "dark",
+ options: { palette: PAL.heal, text: "+15", seed: 2 },
+};
+
+const PLUS = [".a.", "aba", ".a."];
+
+export function draw(p, t, o) {
+ const C = fit(o.palette), S = o.seed;
+ if (t >= 1.25) return;
+ const blink = t > 0.95 && Math.floor(t * 30) % 3 === 0;
+ // plus signs float up around it, swaying, popping in and out
+ burst(5, S, (r, i) => {
+ const born = 0.05 + i * 0.11, age = t - born, life = r.range(0.55, 0.75);
+ if (age < 0 || age > life) return;
+ const k = age / life, side = i % 2 ? 1 : -1;
+ const x = side * r.range(10, 15) + Math.sin(age * 6 + i) * 1.5, y = -6 - age * r.range(20, 28);
+ if (k > 0.7 && Math.floor(t * 30) % 2) return;
+ p.sprite(PLUS, { a: k < 0.5 ? C[5] : C[4], b: k < 0.3 ? WHITE : C[6] }, Math.round(x) - 1, Math.round(y) - 1);
+ p.light(x, y, C[5], 0.4 * (1 - k));
+ });
+ if (blink) return;
+ // the number: letters rise in one after another, then the whole thing drifts up
+ const drift = -16 * ease.outCubic(seg(t, 0, 1.2)), sway = Math.round(Math.sin(t * 5) * 0.8);
+ const { list, w } = letters(p, o.text);
+ list.forEach(({ ch, x }, i) => {
+ const k = seg(t, i * 0.05 - 0.04, i * 0.05 + 0.18);
+ if (k <= 0) return;
+ const dy = 5 * (1 - ease.outBack(k, 2.2)), fresh = k < 0.4;
+ const fill = fresh ? WHITE : (gx, gy) => (gy < 2 ? C[6] : gy < 5 ? C[5] : C[4]);
+ boldText(p, ch, x - Math.round(w / 2) + sway, Math.round(drift + dy - 4), fill, { outline: C[1], shadow: C[0], align: "left" });
+ });
+ p.glow(0, drift, 16, C[4], 0.22 * bump(t, 0, 1.2));
+}
diff --git a/src/fx/ui/health-bar-hit.js b/src/fx/ui/health-bar-hit.js
new file mode 100644
index 0000000..3561ad9
--- /dev/null
+++ b/src/fx/ui/health-bar-hit.js
@@ -0,0 +1,55 @@
+import { PAL, RAMP, hex, burst, seg, ease, WHITE } from "../../core/index.js";
+import { shake, fit } from "./_lib.js";
+
+export const meta = {
+ name: "Health bar hit",
+ desc: "A segmented health bar takes a hit: it jolts, the lost chunk flashes white and turns to a gold chip that hangs a beat, then drains away to the new value.",
+ tags: ["ui", "health", "bar", "damage", "hud", "one-shot"],
+ size: [76, 28],
+ origin: [38, 14],
+ duration: 1.8,
+ loop: false,
+ fps: 30,
+ bg: "dark",
+ options: { palette: PAL.leaf, from: 0.8, to: 0.45, seed: 14 },
+};
+
+const GOLD = RAMP.gold, RED = RAMP.blood, FRAME = ["#0b0a10", "#2a2638", "#4a4562", "#7a7494"].map(hex);
+const HEART = [".aa.aa.", "abbabba", "abcbbba", "abbbbba", ".abbba.", "..aba..", "...a..."];
+const W = 52, X0 = -24, HIT = 0.2;
+
+export function draw(p, t, o) {
+ const C = fit(o.palette), S = o.seed, fade = 1 - seg(t, 1.55, 1.75);
+ if (fade <= 0) return;
+ const [jx, jy] = shake(t, 2.2, HIT, 0.28, S, 40);
+ const hurt = t >= HIT && t < HIT + 0.07;
+ // the values: the fill drops at once; the chip hangs, then drains after it
+ const now = t < HIT ? o.from : o.to;
+ const chip = t < HIT ? o.from : o.from - (o.from - o.to) * ease.inOutQuad(seg(t, HIT + 0.42, HIT + 0.85));
+ const x = X0 + jx, y = -3 + jy;
+ // the frame: a dark case with a lit top edge; it flashes red on the hit
+ p.rect(x - 2, y - 2, W + 4, 10, FRAME[0], fade);
+ p.rect(x - 1, y - 1, W + 2, 8, hurt ? RED[4] : FRAME[2], fade);
+ p.rect(x - 1, y - 1, W + 2, 1, hurt ? RED[6] : FRAME[3], fade);
+ p.rect(x, y, W, 6, FRAME[1], fade);
+ // the gold chip of lost health, white for the first frames
+ const fw = Math.round(W * now), cw = Math.round(W * chip);
+ if (cw > fw) {
+ const white = t < HIT + 0.1;
+ for (let r = 0; r < 6; r++) p.rect(x + fw, y + r, cw - fw, 1, white ? WHITE : r < 2 ? GOLD[6] : r < 4 ? GOLD[5] : GOLD[4], fade);
+ }
+ // the fill: banded light to dark, cut into segments
+ for (let r = 0; r < 6; r++) p.rect(x, y + r, fw, 1, r === 0 ? C[6] : r < 3 ? C[5] : r < 5 ? C[4] : C[3], fade);
+ for (let s = 10; s < fw; s += 10) p.rect(x + s, y, 1, 6, C[2], fade);
+ if (fw > 0) p.rect(x + fw - 1, y, 1, 6, C[6], fade); // a bright leading edge
+ // the heart badge on the end, jolting with the hit
+ p.sprite(HEART, { a: FRAME[0], b: hurt ? WHITE : RED[4], c: WHITE }, x - 9, y - 2 + (hurt ? -1 : 0), { a: fade });
+ // chips of the bar fly off where it broke
+ burst(6, S, (r, i) => {
+ const age = t - HIT, life = r.range(0.28, 0.4);
+ if (age < 0 || age > life) return;
+ const px = x + fw + r.range(0, (o.from - o.to) * W), vx = r.range(-20, 50), vy = -r.range(40, 80);
+ p.rect(Math.round(px + vx * age), Math.round(y + 2 + vy * age + 130 * age * age), 1 + (i % 2), 1 + (i % 2), age / life < 0.4 ? WHITE : GOLD[5], fade);
+ });
+ if (hurt) p.glow(x + W / 2, y + 3, 30, RED[4], 0.4);
+}
diff --git a/src/fx/ui/heart-lost.js b/src/fx/ui/heart-lost.js
new file mode 100644
index 0000000..f6f568b
--- /dev/null
+++ b/src/fx/ui/heart-lost.js
@@ -0,0 +1,76 @@
+import { PAL, burst, seg, ease, WHITE } from "../../core/index.js";
+import { Layer, fit } from "./_lib.js";
+import { pillow, heartSdf } from "../pickups/_lib.js";
+
+export const meta = {
+ name: "Heart lost",
+ desc: "A HUD heart takes the hit: it flashes and squashes, a crack zigzags down it, then it snaps in two and the halves tumble apart and fall, shards flying.",
+ tags: ["ui", "heart", "life", "damage", "hud", "one-shot"],
+ size: [56, 52],
+ origin: [28, 20],
+ duration: 1.1,
+ loop: false,
+ fps: 30,
+ bg: "dark",
+ options: { palette: PAL.blood, seed: 15 },
+};
+
+const L = new Layer(40, 40);
+const HIT = 0.08, CRACK = 0.22, SPLIT = 0.42;
+// the crack: a zigzag down the middle, as an x offset per row
+const ZIG = [0, -1, 1, -1, 1, 0, -1, 1, 0, -1, 0, 1, 0, 0, 0, 0];
+const crackX = (y) => ZIG[Math.max(0, Math.min(ZIG.length - 1, Math.floor(y) + 7))];
+
+function heart(C, squash, flash) {
+ L.begin(-20, -20);
+ pillow(L, -10, -9, 10, 9, (x, y) => heartSdf(x, y, 0, 0, 7.5 * (1 + squash), 7.5 * (1 - squash)), (b, e) => {
+ if (flash) return e < 1 ? C[6] : WHITE;
+ if (b > 0.93 && e > 1) return WHITE;
+ return b > 0.8 ? C[6] : b > 0.55 ? C[5] : b > 0.3 ? C[4] : b > 0.1 ? C[3] : C[2];
+ }, { bevel: 3.5 });
+}
+
+export function draw(p, t, o) {
+ const C = fit(o.palette), S = o.seed;
+ const flash = t >= HIT && t < HIT + 0.07, squash = t >= HIT && t < HIT + 0.12 ? 0.18 : 0;
+ const jx = t >= HIT && t < SPLIT ? Math.round(Math.sin(t * 90) * 1.5 * (1 - seg(t, HIT, SPLIT))) : 0;
+ heart(C, squash, flash);
+ // the crack runs down from the top notch
+ const ck = seg(t, CRACK, CRACK + 0.12);
+ if (ck > 0) for (let y = -7; y <= -7 + 15 * ck; y++) if (L.get(crackX(y), y)) L.set(crackX(y), y, C[0]);
+ L.outline(C[1]);
+ if (t < SPLIT) {
+ L.draw(p, jx, 0);
+ if (flash) p.glow(0, 0, 18, C[5], 0.5);
+ return;
+ }
+ // split: each half tumbles away, turning about its own middle, and blinks out as it falls. The halves are
+ // re-shaded where they land rather than rotated as pixels, so they stay crisp at any angle.
+ const age = t - SPLIT;
+ if (age > 0.62 || (age > 0.45 && Math.floor(t * 30) % 2)) return;
+ L.begin(-20, -20);
+ for (const side of [-1, 1]) {
+ const dx = side * (2 + 22 * age), dy = -12 * age + 70 * age * age, ang = side * 1.1 * ease.outQuad(Math.min(1, age / 0.6));
+ const px = side * 4, cs = Math.cos(-ang), sn = Math.sin(-ang);
+ const toHeart = (x, y) => {
+ const ux = x - px - dx, uy = y - dy;
+ return [px + ux * cs - uy * sn, ux * sn + uy * cs];
+ };
+ const sdf = (x, y) => heartSdf(...toHeart(x, y), 0, 0, 7.5, 7.5);
+ const clip = (x, y) => {
+ const [hx, hy] = toHeart(x, y);
+ return side < 0 ? hx > crackX(hy) : hx < crackX(hy) + 1;
+ };
+ pillow(L, -19, -19, 19, 19, sdf, (b, e) => (b > 0.93 && e > 1 ? WHITE : b > 0.8 ? C[6] : b > 0.55 ? C[5] : b > 0.3 ? C[4] : b > 0.1 ? C[3] : C[2]), { bevel: 3.5, clip });
+ }
+ L.outline(C[1]);
+ L.draw(p);
+ // shards spit out of the break
+ burst(5, S, (r, i) => {
+ const life = r.range(0.3, 0.5);
+ if (age > life) return;
+ const vx = r.range(-40, 40), vy = -r.range(30, 70), sy = r.range(-6, 6);
+ p.rect(Math.round(crackX(sy) + vx * age), Math.round(sy + vy * age + 150 * age * age), i % 3 ? 1 : 2, 1, age / life < 0.4 ? C[6] : C[4]);
+ });
+ if (age < 0.1) p.glow(0, 0, 16, C[5], 0.4 * (1 - age / 0.1));
+}
diff --git a/src/fx/ui/level-up.js b/src/fx/ui/level-up.js
new file mode 100644
index 0000000..eb157c9
--- /dev/null
+++ b/src/fx/ui/level-up.js
@@ -0,0 +1,66 @@
+import { PAL, fit, at, burst, cycle, seg, ease, bump, clamp, TAU, WHITE, hex } from "../../core/index.js";
+
+export const meta = {
+ name: "Level up",
+ desc: "A golden pillar bursts from the feet, LEVEL UP! drops in letter by letter with a bounce, stars pop, motes rise.",
+ tags: ["ui", "feedback", "level", "reward", "text", "one-shot"],
+ size: [96, 80],
+ origin: [48, 66],
+ duration: 1.8,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ actor: true,
+ options: { palette: PAL.gold, text: "LEVEL UP!", seed: 5 },
+};
+
+const OUTLINE = hex("#2a1406");
+
+export function draw(p, t, o) {
+ const G = fit(o.palette, 8), S = o.seed, out = 1 - seg(t, 1.45, 1.8);
+ // pillar of light: snaps up, then narrows away
+ const pil = seg(t, 0, 0.12), shrink = seg(t, 0.3, 0.9);
+ if (pil > 0 && shrink < 1) {
+ const w = 9 * (1 - ease.inQuad(shrink)), top = -62 * ease.outCubic(pil);
+ p.shade(-w, top, w, 0, (x, y, o2) => {
+ const v = Math.abs(x) / w;
+ if (v > 1) return;
+ o2.c = v < 0.4 ? WHITE : v < 0.75 ? G[6] : G[5];
+ o2.a = clamp((y - top) / 16) * (v < 0.75 ? 1 : 0.6);
+ });
+ p.glowLine(0, top, 0, 0, 14, G[5], 0.5 * (1 - shrink));
+ }
+ // ground ring at the feet
+ const ring = seg(t, 0.02, 0.5);
+ if (ring > 0 && ring < 1) p.ellipse(0, 0, 4 + 22 * ease.outCubic(ring), 2 + 5 * ease.outCubic(ring), G[6], (d) => (d > 0.75 ? 1 - ring : 0));
+ // rising motes
+ cycle(t, 1.8, 14, S, 0.9, (age, life, r) => {
+ if (t > 1.5) return;
+ const k = age / life, x = r.range(-16, 16), y = -age * r.range(30, 55);
+ p.px(x + Math.sin(age * 6 + r.next() * 6), y, k < 0.5 ? G[7] : G[5]);
+ p.light(x, y, G[5], 0.4 * (1 - k));
+ });
+ // the words: each letter drops in with an overshoot, then all float up and dissolve
+ const str = o.text, y0 = -42 - 6 * ease.inQuad(seg(t, 1.35, 1.8));
+ const total = p.measure(str, { font: "big" })[0];
+ let x = -Math.round(total / 2);
+ [...str].forEach((ch, i) => {
+ const w = p.measure(ch, { font: "big" })[0], born = 0.1 + i * 0.045, k = seg(t, born, born + 0.22);
+ if (k > 0) {
+ const dy = -10 * (1 - ease.outBack(k, 2.6));
+ p.text(ch, x, y0 + dy, (gx, gy) => (gy < 2 ? WHITE : gy < 5 ? G[5] : G[4]), { font: "big", outline: OUTLINE, a: out });
+ }
+ x += w + 1;
+ });
+ // stars pop around the words
+ burst(6, S + 1, (r, i) => {
+ const born = 0.35 + i * 0.12, k = seg(t, born, born + 0.35);
+ if (k <= 0 || k >= 1) return;
+ const sx = r.range(-34, 34), sy = r.range(-58, -30), s = Math.round(3 * bump(k, 0, 1));
+ p.line(sx - s, sy, sx + s, sy, G[6]);
+ p.line(sx, sy - s, sx, sy + s, G[6]);
+ p.px(sx, sy, WHITE);
+ p.light(sx, sy, G[5], 0.5 * bump(k, 0, 1));
+ });
+ p.glow(0, -30, 46, G[4], 0.3 * bump(t, 0, 1.4));
+}
diff --git a/src/fx/ui/loading-dots.js b/src/fx/ui/loading-dots.js
new file mode 100644
index 0000000..4cfa390
--- /dev/null
+++ b/src/fx/ui/loading-dots.js
@@ -0,0 +1,39 @@
+import { PAL, clamp } from "../../core/index.js";
+import { fit } from "./_lib.js";
+
+export const meta = {
+ name: "Loading dots",
+ desc: "Three round dots hop one after another: stretched as they leap and fall, round at the top, squashed flat for a beat as they land.",
+ tags: ["ui", "loading", "dots", "wait", "typing", "loop"],
+ size: [48, 28],
+ origin: [24, 20],
+ duration: 1.1,
+ loop: true,
+ fps: 30,
+ bg: "dark",
+ options: { palette: PAL.metal, count: 3, gap: 12, seed: 10 },
+};
+
+// hand-drawn poses: k outline, w highlight, h lit, s shade
+const ROUND = ["..kkkk..", ".khhhhk.", "khwhhhhk", "khhhhhhk", "khhhhhsk", "khhhhssk", ".kshssk.", "..kkkk.."];
+const TALL = ["..kkk..", ".khhhk.", "khwhhhk", "khhhhhk", "khhhhhk", "khhhhsk", "khhhssk", ".khssk.", "..kkk.."];
+const FLAT = ["..kkkkkk..", ".khwhhhhk.", "khhhhhhhsk", "khhhhhhssk", ".kshhhssk.", "..kkkkkk.."];
+
+export function draw(p, t, o) {
+ const C = fit(o.palette), ph = t / meta.duration, n = o.count;
+ const pal = { k: C[1], w: C[7], h: C[6], s: C[4] };
+ for (let i = 0; i < n; i++) {
+ const x = Math.round((i - (n - 1) / 2) * o.gap);
+ // each dot hops in its own slice of the loop; the rest of the time it sits
+ const k = clamp((((ph - i * 0.14) % 1) + 1) % 1 / 0.36);
+ const air = k > 0 && k < 1, h = air ? Math.round(Math.sin(k * Math.PI) * 8) : 0;
+ const fast = air && Math.abs(Math.cos(k * Math.PI)) > 0.45, land = (((ph - i * 0.14 - 0.36) % 1) + 1) % 1 < 0.06;
+ const pose = land ? FLAT : fast ? TALL : ROUND;
+ const w = pose[0].length, hh = pose.length;
+ // a shadow on the floor, shrinking as the dot rises
+ const sw = Math.max(1, 4 - Math.floor(h / 3));
+ p.rect(x - sw, 0, sw * 2, 1, C[1]);
+ p.sprite(pose, pal, x - Math.floor(w / 2), -hh - h + 1);
+ if (air) p.light(x, -h - 3, C[6], 0.2);
+ }
+}
diff --git a/src/fx/ui/loading-spinner.js b/src/fx/ui/loading-spinner.js
new file mode 100644
index 0000000..54ce61e
--- /dev/null
+++ b/src/fx/ui/loading-spinner.js
@@ -0,0 +1,33 @@
+import { PAL, TAU, WHITE } from "../../core/index.js";
+import { fit } from "./_lib.js";
+
+export const meta = {
+ name: "Loading spinner",
+ desc: "Eight chunky blocks in a ring; a bright head steps round them like a clock hand, its tail cooling down the ramp behind it.",
+ tags: ["ui", "loading", "spinner", "wait", "loop"],
+ size: [32, 32],
+ origin: [16, 16],
+ duration: 0.8,
+ loop: true,
+ fps: 30,
+ bg: "dark",
+ options: { palette: PAL.cyber, count: 8, radius: 9, seed: 9 },
+};
+
+export function draw(p, t, o) {
+ const C = fit(o.palette), n = o.count, ph = t / meta.duration;
+ const head = Math.floor(ph * n) % n, sub = (ph * n) % 1;
+ const TAIL = [WHITE, C[6], C[5], C[4], C[3]];
+ for (let i = 0; i < n; i++) {
+ const a = (i / n) * TAU - Math.PI / 2, age = (head - i + n) % n;
+ const x = Math.round(Math.cos(a) * o.radius), y = Math.round(Math.sin(a) * o.radius);
+ const c = TAIL[age] ?? C[2];
+ // the head pops a pixel bigger for the first frame of its step
+ const s = age === 0 && sub < 0.4 ? 5 : age < 3 ? 4 : 3, h = Math.floor(s / 2);
+ p.rect(x - h - 1, y - h - 1, s + 2, s + 2, C[0]);
+ p.rect(x - h, y - h, s, s, c);
+ if (age < 3) p.px(x - h, y - h, age === 0 ? WHITE : C[6]);
+ if (age === 0) p.light(x, y, C[5], 0.6), p.glow(x, y, 8, C[5], 0.3);
+ }
+ p.glow(0, 0, 16, C[4], 0.08);
+}
diff --git a/src/fx/ui/notification.js b/src/fx/ui/notification.js
new file mode 100644
index 0000000..2a07384
--- /dev/null
+++ b/src/fx/ui/notification.js
@@ -0,0 +1,66 @@
+import { PAL, RAMP, seg, ease, bump, WHITE } from "../../core/index.js";
+import { Layer, fit } from "./_lib.js";
+
+export const meta = {
+ name: "Notification",
+ desc: "A gold bell swings hard on its hook and rings, the clapper lagging behind, ping arcs spreading out; a red badge with a 1 pops on its shoulder.",
+ tags: ["ui", "notification", "bell", "alert", "badge", "one-shot"],
+ size: [56, 48],
+ origin: [28, 30],
+ duration: 1.6,
+ loop: false,
+ fps: 30,
+ bg: "dark",
+ options: { palette: PAL.gold, count: "1", seed: 11 },
+};
+
+const L = new Layer(56, 48);
+const RED = RAMP.blood, PY = -20;
+
+// the swing: a hard ring that dies away, the clapper a beat behind
+const swing = (t) => 0.5 * Math.sin(t * 30) * Math.max(0, 1 - t / 0.75) * (t < 0.75 ? 1 : 0);
+
+export function draw(p, t, o) {
+ const C = fit(o.palette), out = seg(t, 1.35, 1.55);
+ if (out >= 1) return;
+ const th = swing(t), tc = swing(Math.max(0, t - 0.05)) * 1.3, cs = Math.cos(th), sn = Math.sin(th);
+ const pop = ease.outBack(seg(t, 0, 0.12), 3), sc = pop * (1 - ease.inBack(out, 2));
+ if (sc <= 0.05) return;
+ L.begin(-28, -30);
+ L.fill(-16, -24, 16, 4, (x, y) => {
+ // into the bell's own space: rotated about its hook, scaled by the pop
+ const dx = x / (sc * 1.2), dy = (y - PY) / (sc * 1.2), xx = dx * cs + dy * sn, yy = -dx * sn + dy * cs;
+ if (Math.hypot(xx, yy) < 1.7) return xx < 0 ? C[6] : C[4]; // the knob
+ const cx = Math.sin(tc - th) * 3;
+ if (Math.hypot(xx - cx, yy - 14.5) < 1.8) return xx - cx < 0 ? C[5] : C[3]; // the clapper
+ if (yy < 1 || yy > 13) return 0;
+ // a domed crown, near-straight waist, a flared lip
+ const v = (yy - 1) / 12, w = 6.4 * (0.4 + 0.6 * Math.sqrt(v)) + (yy > 11.4 ? 1.3 : 0) - (yy < 1.8 ? 1 : 0);
+ if (Math.abs(xx) > w) return 0;
+ const u = xx / w;
+ if (yy > 11.4) return yy < 12.4 ? (u < 0.3 ? C[6] : C[5]) : u < 0.4 ? C[4] : C[3]; // the lip
+ return u < -0.78 ? C[4] : u < -0.4 ? C[6] : u < 0.25 ? C[5] : u < 0.62 ? C[4] : C[3];
+ });
+ L.outline(C[1]);
+ L.draw(p);
+ // ping arcs spread out from both sides while it rings
+ for (let i = 0; i < 3; i++) {
+ const k = seg(t, 0.05 + i * 0.16, 0.45 + i * 0.16);
+ if (k <= 0 || k >= 1) continue;
+ const r = 13 + 9 * ease.outCubic(k), c = k < 0.45 ? C[6] : C[4], a = k < 0.7 ? 1 : 0.5;
+ p.arc(0, -11, r, 1, -0.55, 0.55, c, a);
+ p.arc(0, -11, r, 1, Math.PI - 0.55, Math.PI + 0.55, c, a);
+ }
+ // the badge pops onto its shoulder
+ const bk = seg(t, 0.42, 0.56);
+ if (bk > 0) {
+ const r = 4.5 * ease.outBack(bk, 3) * (1 - ease.inBack(out, 2)), bx = 8, by = -16;
+ if (r > 0.6) {
+ p.circle(bx, by, r + 1, RED[1]);
+ p.circle(bx, by, r, (d, a) => (d > 0.65 && Math.sin(a) < 0 && Math.cos(a) < 0.5 ? RED[6] : RED[4]));
+ if (r > 3.5) p.text(o.count, bx, by - 2, WHITE, { align: "center" });
+ if (bk < 1) p.ring(bx, by, r + 2 + 4 * bk, 1, WHITE, 1 - bk);
+ }
+ }
+ p.glow(0, -9, 24, C[4], 0.2 * bump(t, 0, 0.9));
+}
diff --git a/src/fx/ui/quest-complete.js b/src/fx/ui/quest-complete.js
new file mode 100644
index 0000000..b4f76f3
--- /dev/null
+++ b/src/fx/ui/quest-complete.js
@@ -0,0 +1,84 @@
+import { PAL, RAMP, seg, ease, bump, WHITE, hex } from "../../core/index.js";
+import { Layer, boldText, letters, twinkle, shake, fit } from "./_lib.js";
+
+export const meta = {
+ name: "Quest complete",
+ desc: "A ribbon banner unrolls from the middle, QUEST COMPLETE types on, a gold seal with a check stamps down with a jolt, three stars pop; then it rolls back up.",
+ tags: ["ui", "quest", "complete", "banner", "reward", "text", "one-shot"],
+ size: [144, 60],
+ origin: [72, 34],
+ duration: 2.4,
+ loop: false,
+ fps: 30,
+ bg: "dark",
+ options: { palette: PAL.water, text: "QUEST COMPLETE", seed: 6 },
+};
+
+const L = new Layer(128, 40);
+const GOLD = RAMP.gold, CREAM = hex("#f4ecd0");
+const STAR = ["..a..", ".aba.", "abbba", ".aba.", "a...a"];
+const BIG_STAR = ["....a....", "....a....", "...aba...", "aaabbbaaa", ".abbcbba.", "..abbba..", "..abbba..", ".aba.aba.", ".a.....a."];
+
+export function draw(p, t, o) {
+ const C = fit(o.palette), S = o.seed, str = o.text;
+ const tw = p.measure(str, { font: "big" })[0], HW = Math.ceil(tw / 2) + 14, TX = 8; // the text sits right of the seal
+ // unroll from the middle with an overshoot; roll back up at the end
+ const open = ease.outBack(seg(t, 0, 0.3), 1.3) * (1 - ease.inBack(seg(t, 2.0, 2.3), 1.5));
+ if (open <= 0.02 && t > 0.3) return;
+ const hw = Math.max(1, Math.round(HW * open)), [jx, jy] = shake(t, 2, 0.62, 0.22, S);
+ const q = L.begin(-64, -20);
+ // the tails: notched ends behind the band, sliding out once it is open
+ const tail = Math.round(10 * ease.outCubic(seg(t, 0.26, 0.4)) * (1 - seg(t, 1.95, 2.05)));
+ if (tail > 1)
+ for (const s of [-1, 1])
+ for (let i = 0; i <= tail; i++)
+ for (let y = -3; y <= 10; y++) {
+ const x = s * (hw - 3 + i);
+ if ((i === tail && Math.abs(y - 3.5) < 3) || (i === tail - 1 && Math.abs(y - 3.5) < 1.5)) continue; // the V notch
+ q.px(x, y, i < 3 && y > 5 ? C[1] : y < -1 ? C[4] : y > 8 ? C[2] : C[3]);
+ }
+ // the band: lit top edge, stitching, shaded bottom
+ for (let y = -8; y <= 6; y++)
+ for (let x = -hw; x < hw; x++) {
+ let c = y === -8 ? C[6] : y < -5 ? C[5] : y > 4 ? C[2] : y > 2 ? C[3] : C[4];
+ if ((y === -6 || y === 4) && x % 3 === 0 && Math.abs(x) < hw - 2) c = y < 0 ? C[6] : C[4];
+ q.px(x, y, c);
+ }
+ L.outline(C[0]);
+ L.draw(p, jx, jy);
+ // the words type on, each letter dropping in white then settling cream
+ const { list } = letters(p, str);
+ if (t < 1.98)
+ list.forEach(({ ch, x }, i) => {
+ const k = seg(t, 0.3 + i * 0.022, 0.42 + i * 0.022);
+ if (k <= 0 || ch === " ") return;
+ const lx = TX + x - Math.round(tw / 2), dy = Math.round(-4 * (1 - ease.outBack(k, 2)));
+ if (Math.abs(lx) > hw - 4) return;
+ boldText(p, ch, lx + jx, -5 + dy + jy, k < 0.6 ? WHITE : (gx, gy) => (gy < 3 ? WHITE : CREAM), { outline: C[0], shadow: C[1], align: "left" });
+ });
+ // the seal stamps down on the left end: big, then thump
+ const sk = seg(t, 0.55, 0.65);
+ if (sk > 0 && t < 2.02) {
+ const sx = -Math.round(HW * open) + 9 + jx, sy = -1 + jy, r = 9 + Math.round(5 * (1 - ease.outQuad(sk)));
+ p.circle(sx, sy, r + 1, GOLD[1]);
+ p.circle(sx, sy, r, (d, a) => (d > 0.78 ? (Math.sin(a) < -0.2 || Math.cos(a) < -0.5 ? GOLD[6] : GOLD[4]) : d > 0.62 ? GOLD[3] : GOLD[5]));
+ // the check
+ const k = r / 9;
+ p.beam(sx - 4 * k, sy, sx - 1.5 * k, sy + 3 * k, 2.2 * k, GOLD[1]);
+ p.beam(sx - 1.5 * k, sy + 3 * k, sx + 4.5 * k, sy - 4 * k, 2.2 * k, GOLD[1]);
+ if (sk < 1) p.ring(sx, sy, r + 3 + 6 * sk, 1, WHITE, 1 - sk);
+ }
+ // three stars pop over it, the middle one biggest
+ for (let i = 0; i < 3; i++) {
+ const k = seg(t, 0.75 + i * 0.1, 0.95 + i * 0.1), out = seg(t, 1.9, 2.0);
+ if (k <= 0 || out >= 1) continue;
+ const x = TX + (i - 1) * 16 + jx, y = (i === 1 ? -19 : -15) + jy - Math.round(3 * bump(k, 0, 0.6));
+ const c = { a: GOLD[4], b: k < 0.4 ? WHITE : GOLD[6], c: WHITE };
+ if (i === 1) p.sprite(BIG_STAR, c, x - 4, y - 4);
+ else p.sprite(STAR, c, x - 2, y - 2);
+ const tk = bump(t, 1.2 + i * 0.15, 1.45 + i * 0.15);
+ if (tk > 0) twinkle(p, x + (i === 1 ? 5 : 3), y - (i === 1 ? 4 : 3), Math.round(1 + tk * 2), GOLD[5], GOLD[6]);
+ p.light(x, y, GOLD[5], 0.35);
+ }
+ p.glow(0, -1, 60, C[4], 0.14 * bump(t, 0, 2.2));
+}
diff --git a/src/fx/water/_lib.js b/src/fx/water/_lib.js
new file mode 100644
index 0000000..f48f241
--- /dev/null
+++ b/src/fx/water/_lib.js
@@ -0,0 +1,83 @@
+// Shared by the water effects: palette fitting, flat ellipse outlines (ripples on a surface seen at a low
+// angle), droplets with streaks, and the time a ballistic drop takes to land. Files starting with _ are
+// helpers, not effects.
+
+import { ramp, noise2 } from "../../core/index.js";
+
+const call = (v, ...a) => (typeof v === "function" ? v(...a) : v);
+
+/** Any palette as exactly n steps (nearest step, never blended), so an effect can index W[0..n-1]. */
+export function fit(pal, n = 8) {
+ const r = ramp(pal);
+ return Array.from({ length: n }, (_, i) => r[Math.round((i * (r.length - 1)) / (n - 1))]);
+}
+
+/** A stone ramp for props (basin rims, vent grates), dark to light. */
+export const STONE = ramp(["#15141c", "#26242f", "#3a3745", "#55505f", "#77717f", "#9a94a0"]);
+export const METAL = ramp(["#101219", "#222633", "#3a4052", "#5a6276", "#8590a4"]);
+/** Steam, dark to bright: cool greys that end in white. */
+export const STEAM = ["#232a38", "#3a4456", "#5a6678", "#8590a3", "#b2bccb", "#dbe2ec", "#f6f9fc"];
+
+/**
+ * A 1 px ellipse outline: a ripple on a surface seen at a low angle. c and a may be functions of the angle
+ * around it (y is down, so sin(angle) > 0 is the near side).
+ */
+export function oval(p, cx, cy, rx, ry, c, a = 1) {
+ if (rx < 0.75 || ry < 0.3) {
+ p.dot(cx, cy, call(c, Math.PI / 2), call(a, Math.PI / 2));
+ return;
+ }
+ const iy = 1 / (ry * ry), ix = 1 / (rx * rx);
+ const inside = (x, y) => (x - cx) * (x - cx) * ix + (y - cy) * (y - cy) * iy <= 1;
+ p.shade(cx - rx - 1, cy - ry - 1, cx + rx + 1, cy + ry + 1, (x, y, o) => {
+ if (!inside(x, y) || (inside(x + 1, y) && inside(x - 1, y) && inside(x, y + 1) && inside(x, y - 1))) return;
+ const ang = Math.atan2((y - cy) / ry, (x - cx) / rx);
+ o.c = call(c, ang);
+ o.a = call(a, ang);
+ });
+}
+
+/**
+ * A ripple ring: a crisp 1 px crest, near side in one color and far side in another. keep (0..1) is how much
+ * of it is left: as it drops the ring breaks into dashes (whole pixels, not dither) and then is gone.
+ */
+export function ripple(p, cx, cy, rx, ry, near, far, keep = 1, seed = 0) {
+ if (keep <= 0) return;
+ const f = 0.42;
+ oval(p, cx, cy, rx, ry, (a) => (Math.sin(a) > 0 ? near : far), keep >= 1 ? 1 : (a) =>
+ noise2(Math.cos(a) * rx * f + seed * 7.31, Math.sin(a) * rx * f + seed * 3.7, seed) * 0.62 + 0.5 < keep ? 1 : 0);
+}
+
+/** A droplet in flight: a head pixel with a tail trailing back along its velocity (k seconds of travel). */
+export function drop(p, x, y, vx, vy, head, tail, k = 0.02, a = 1) {
+ const tx = x - vx * k, ty = y - vy * k;
+ if (Math.abs(tx - x) >= 1 || Math.abs(ty - y) >= 1) p.line(tx, ty, x, y, tail, a);
+ p.dot(x, y, head, a);
+}
+
+/**
+ * Draw with everything outside the local box [x0, x1) x [y0, y1) dropped, color and light alike: for
+ * effects that sweep in from off the canvas. (The painter has no clip of its own, so this wraps its two
+ * raw writers for the duration of fn.)
+ */
+export function clip(p, x0, y0, x1, y1, fn) {
+ const inBox = (sx, sy) => {
+ const lx = p.fromX(sx + 0.5, sy + 0.5), ly = p.fromY(sx + 0.5, sy + 0.5);
+ return lx >= x0 && lx < x1 && ly >= y0 && ly < y1;
+ };
+ const put = Object.getPrototypeOf(p).put, add = Object.getPrototypeOf(p).add;
+ p.put = function (sx, sy, c, a) { if (inBox(sx, sy)) put.call(this, sx, sy, c, a); };
+ p.add = function (sx, sy, c, k) { if (inBox(sx, sy)) add.call(this, sx, sy, c, k); };
+ try {
+ fn();
+ } finally {
+ delete p.put;
+ delete p.add;
+ }
+}
+
+/** When a drop launched at height y0 with vertical speed vy under gravity g (no drag) reaches height y1. */
+export function landTime(y0, vy, g, y1) {
+ const d = vy * vy + 2 * g * (y1 - y0);
+ return d < 0 ? Infinity : (-vy + Math.sqrt(d)) / g;
+}
diff --git a/src/fx/water/bubbles.js b/src/fx/water/bubbles.js
new file mode 100644
index 0000000..6bc9eb5
--- /dev/null
+++ b/src/fx/water/bubbles.js
@@ -0,0 +1,64 @@
+import { PAL, rng, seg, wrap, TAU } from "../../core/index.js";
+import { fit, oval } from "./_lib.js";
+
+export const meta = {
+ name: "Bubbles",
+ desc: "Underwater bubbles rise and wobble, big ones faster and squashier, beside a fizzing chain of tiny ones; each pops into a ring of specks.",
+ tags: ["water", "bubbles", "underwater", "ambient", "loop"],
+ size: [40, 64],
+ origin: [20, 60],
+ duration: 2.4,
+ loop: true,
+ fps: 30,
+ bg: "dark",
+ options: { palette: PAL.water, count: 8, seed: 5 },
+};
+
+const SMALL = { 1: ["b"], 2: [".b.", "w.b", ".c."], 3: [".bb.", "bw.b", "b..c", ".cc."] };
+
+function bubble(p, x, y, r, sq, W) {
+ if (r <= 3) {
+ const s = SMALL[r];
+ p.sprite(s, { b: W[5], c: W[4], w: W[7] }, Math.round(x) - (s[0].length >> 1), Math.round(y) - (s.length >> 1));
+ return;
+ }
+ // a crisp rim, lit from the top left, a white shine inside it and a faint bounce of light opposite
+ const rx = r + sq, ry = r - sq;
+ oval(p, x, y, rx, ry, (a) => (Math.cos(a - 3.9) > 0.55 ? W[6] : Math.cos(a - 0.8) > 0.4 ? W[4] : W[5]));
+ p.px(x - rx * 0.45, y - ry * 0.45, W[7]);
+ p.px(x - rx * 0.45 + 1, y - ry * 0.45, W[6]);
+ p.px(x - rx * 0.45, y - ry * 0.45 + 1, W[6]);
+ p.line(x + rx * 0.35, y + ry * 0.62, x + rx * 0.62, y + ry * 0.3, W[4]);
+}
+
+export function draw(p, t, o) {
+ const W = fit(o.palette), S = o.seed, D = meta.duration, n = o.count;
+ for (let i = 0; i < n; i++) {
+ const r = rng(S, i), rad = [5, 2, 3, 4, 2, 3, 6, 2, 3, 4][i % 10], born = ((i + r.range(-0.3, 0.3)) / n) * D;
+ const life = r.range(1.5, 1.9) - rad * 0.08, x0 = r.range(-8, 8), top = -r.range(42, 49);
+ const age = wrap(t - born, D);
+ if (age >= life + 0.1) continue;
+ // rises from rest, then at a steady speed; wobbles more the bigger it is
+ const k = Math.min(age, life), v = -top / (life - 0.2), y = -(v * k - v * 0.2 * (1 - Math.exp(-k / 0.2))) - 2;
+ const w = r.range(5, 8), ph = r.range(0, TAU), x = x0 + Math.sin(k * w + ph) * (0.5 + rad * 0.35);
+ const g = seg(age, 0, 0.25), size = Math.max(1, Math.round(rad * (0.5 + 0.5 * g)));
+ if (age < life) bubble(p, x, y, size, rad > 3 ? Math.sin(k * w * 2 + ph) * 0.5 : 0, W);
+ else {
+ // pop: the rim flies apart into specks for three frames
+ const u = (age - life) / 0.1, R = size + 1 + u * 3;
+ for (let j = 0; j < 6; j++) {
+ const a = (j / 6) * TAU + ph;
+ p.px(x + Math.cos(a) * R, y + Math.sin(a) * R * 0.9, u < 0.5 ? W[7] : W[5]);
+ }
+ p.light(x, y, W[5], 0.3 * (1 - u));
+ }
+ }
+ // a fizzing chain of tiny bubbles from one spot on the floor
+ for (let i = 0; i < 10; i++) {
+ const r = rng(S + 9, i), period = D / 2, age = wrap(t - (i / 10) * period, period) + period * (i % 2);
+ const life = r.range(1.3, 1.7);
+ if (age > life) continue;
+ const y = -2 - age * r.range(30, 36), x = 9 + Math.sin(age * 9 + i * 2.3) * (0.4 + age * 1.1);
+ p.px(x, y, age < life * 0.75 ? W[5] : W[4]);
+ }
+}
diff --git a/src/fx/water/drip.js b/src/fx/water/drip.js
new file mode 100644
index 0000000..d10fecb
--- /dev/null
+++ b/src/fx/water/drip.js
@@ -0,0 +1,82 @@
+import { PAL, seg, ease, wrap, burst } from "../../core/index.js";
+import { fit, ripple, landTime, STONE } from "./_lib.js";
+
+export const meta = {
+ name: "Drip",
+ desc: "A drop swells under a wet ledge, stretches, lets go, falls and plinks into a puddle: droplets hop up and a ring runs out.",
+ tags: ["water", "drip", "drop", "puddle", "cave", "ambient", "loop"],
+ size: [32, 72],
+ origin: [16, 66],
+ duration: 1.8,
+ loop: true,
+ fps: 30,
+ bg: "ground",
+ options: { palette: PAL.water, height: 60, puddle: 11, seed: 3 },
+};
+
+const LET_GO = 1.05, G = 950;
+// the bead as it swells (b body, w shine, c shade, d deep shade), then the pinch just before it lets go
+const BEAD = [
+ ["b"],
+ [".b.", "bwb", ".c."],
+ ["..b..", ".bbb.", ".wbb.", ".bbc.", "..c.."],
+ ["..b..", "..b..", ".bbb.", "bwbbb", "bbbbc", ".bcc.", "..d.."],
+ ["..b..", "..b..", "..b..", ".bbb.", "bwbbb", "bbbbc", ".bcc.", "..d.."],
+];
+const FALL = [".b.", ".b.", "bwb", "bbc", ".c."];
+
+export function draw(p, t, o) {
+ const W = fit(o.palette), S = o.seed, D = meta.duration, top = -o.height, PR = o.puddle;
+ const pal = { b: W[5], w: W[7], c: W[4], d: W[3] };
+ const fall = Math.sqrt((2 * (o.height - 8)) / G), HIT = LET_GO + fall;
+ // the puddle: a dark flat pool with a lit far rim
+ p.ellipse(0.5, 0.5, PR, 2.5, (d, a) => (d > 0.8 ? (Math.sin(a) < 0 ? W[3] : W[1]) : W[2]));
+ p.line(-PR + 4, -1, -3, -1, W[4]);
+ // the ledge it hangs from: a lip of stone with a wet film under it
+ p.rect(-5, top - 3, 11, 1, STONE[2]);
+ p.rect(-4, top - 2, 9, 1, STONE[3]);
+ p.rect(-3, top - 1, 7, 1, STONE[1]);
+ p.rect(-2, top, 5, 1, W[3]);
+ p.px(0, top, W[4]);
+ // forming: the bead swells in steps, holds, pinches
+ if (t < LET_GO) {
+ const g = seg(t, 0.1, 0.8), i = t > 0.9 ? 4 : Math.min(3, Math.floor(g * 4));
+ const sag = t > 0.9 ? Math.round(seg(t, 0.9, LET_GO) * 2) : 0;
+ const s = BEAD[i];
+ p.sprite(s, pal, -(s[0].length >> 1), top + 1 + sag);
+ } else {
+ // the ledge keeps a tiny bead that springs back
+ const s = seg(t, LET_GO, LET_GO + 0.3);
+ if (s < 1) p.px(0, top + 1 + Math.round(1.5 * (1 - ease.outElastic(s))), W[5]);
+ }
+ // falling: stretched, bright head, a speck of tail when fast
+ const tf = t - LET_GO;
+ if (tf >= 0 && t < HIT) {
+ const y = Math.round(top + 6 + 0.5 * G * tf * tf), v = G * tf;
+ p.sprite(FALL, pal, -1, y - 5);
+ if (v > 200) p.line(0, y - 6 - Math.round(v * 0.01), 0, y - 6, W[4]);
+ }
+ // the hit: a tiny crown and a flash, droplets hop out, rings run out (wrapping into the next loop)
+ const age = wrap(t - HIT, D);
+ if (age < 0.07) {
+ p.line(-3, -1, 4, -1, W[7]);
+ p.px(-2, -2, W[6]), p.px(3, -2, W[6]), p.px(-3, -3, W[5]), p.px(4, -3, W[5]), p.px(0.5, -2, W[7]);
+ p.glow(0.5, -2, 10, W[5], 0.3);
+ } else if (age < 0.14) {
+ p.px(-3, -3, W[6]), p.px(4, -3, W[6]), p.px(-4, -4, W[5]), p.px(5, -4, W[5]);
+ }
+ burst(3, S, (r, i) => {
+ const vx = i === 1 ? r.range(-5, 5) : (i ? 1 : -1) * r.range(18, 30), vy = -r.range(i === 1 ? 95 : 55, i === 1 ? 115 : 75);
+ const g = G * 0.7, tl = landTime(-1, vy, g, 0);
+ if (age > tl) return;
+ const x = 0.5 + vx * age, y = -1 + vy * age + 0.5 * g * age * age;
+ p.px(x, y, i === 1 ? W[7] : W[6]);
+ if (i === 1 && vy + g * age < 0) p.px(x, y + 1, W[5]);
+ });
+ for (const [t0, life, rmax] of [[0.03, 0.5, PR - 2], [0.18, 0.45, PR - 5]]) {
+ const u = seg(age, t0, t0 + life);
+ if (u <= 0 || u >= 1) continue;
+ const rr = 2 + (rmax - 2) * ease.outCubic(u);
+ ripple(p, 0.5, 0.5, rr, rr * 0.24, u < 0.3 ? W[7] : W[6], W[5], 1.3 * (1 - seg(u, 0.3, 1)), S + t0 * 9);
+ }
+}
diff --git a/src/fx/water/fountain.js b/src/fx/water/fountain.js
new file mode 100644
index 0000000..70b7be1
--- /dev/null
+++ b/src/fx/water/fountain.js
@@ -0,0 +1,84 @@
+import { PAL, cycle, tileNoise, fract, TAU } from "../../core/index.js";
+import { fit, ripple, drop, landTime, STONE } from "./_lib.js";
+
+export const meta = {
+ name: "Fountain",
+ desc: "A stone basin with a jet shooting up the middle; it blooms at the top and falls back in arcs of droplets that splash and ring the pool.",
+ tags: ["water", "fountain", "jet", "basin", "prop", "ambient", "loop"],
+ size: [72, 72],
+ origin: [36, 66],
+ duration: 1.2,
+ loop: true,
+ fps: 30,
+ bg: "ground",
+ options: { palette: PAL.water, height: 46, seed: 8 },
+};
+
+const BY = -9, BRX = 27, BRY = 6, G = 240; // basin rim height and radii, gravity
+// the steady streams: launch speed (x, y) and depth (- far, + near)
+const STREAMS = [[-24, -16, -0.5], [-15, -26, 0.5], [-8, -34, -0.2], [9, -32, 0.3], [16, -24, -0.4], [23, -15, 0.6]];
+
+export function draw(p, t, o) {
+ const W = fit(o.palette), S = o.seed, D = meta.duration, ph = t / D, A = -o.height;
+ // the basin: a stone drum with a lit rim, the pool inside
+ p.ellipse(0, -3, BRX, BRY, (d, a) => (Math.sin(a) > 0 && d > 0.85 ? STONE[1] : STONE[2]));
+ p.rect(-BRX, BY, BRX * 2, -3 - BY, (/* wall */ STONE[2]));
+ for (let y = BY; y < -3; y++) p.px(-BRX, y, STONE[3]), p.px(BRX - 1, y, STONE[1]);
+ p.ellipse(0, BY, BRX, BRY, (d, a) => (d > 0.82 ? (Math.sin(a) < 0 ? STONE[4] : STONE[5]) : STONE[3]));
+ p.ellipse(0, BY, BRX - 4, BRY - 1.6, (d, a) => (d > 0.86 && Math.sin(a) < 0 ? W[1] : d < 0.55 && Math.sin(a) < -0.2 ? W[3] : W[2]));
+ // rings around the foot of the jet
+ for (let i = 0; i < 2; i++) {
+ const k = fract(ph * 2 + i / 2), rr = 4 + k * 15;
+ ripple(p, 0, BY, rr, rr * 0.2, W[4], W[4], 1.3 * (1 - k), S + i);
+ }
+ // streams: steady arcs from the bloom down into the pool, bright dashes running along them, breaking up low
+ const streams = (front) => STREAMS.forEach(([vx, vy, z], i) => {
+ if (z > 0 !== front) return;
+ const land = BY + z * 2.6, y0 = A + 2, tl = landTime(y0, vy, G, land);
+ let px = null, py = null;
+ for (let s = 0; s <= tl; s += 0.012) {
+ const x = vx * s, y = y0 + vy * s + 0.5 * G * s * s, x1 = Math.round(x), y1 = Math.round(y);
+ if (x1 === px && y1 === py) continue;
+ px = x1, py = y1;
+ const dash = fract(s / 0.1 - ph * 12 + i * 0.37), u = s / tl;
+ if (u > 0.68 && dash > 1.45 - u) continue;
+ p.px(x, y, dash < 0.3 ? (front ? W[7] : W[6]) : front ? W[6] : W[5]);
+ }
+ });
+ // falling droplets: launched from the bloom, arcing out and down into the pool, each ending in a splash
+ const arcs = (front) => cycle(t, D, 30, S, (r) => r.range(0.55, 0.8), (age, life, r) => {
+ const z = r.range(-1, 1), side = r.sign();
+ if (z > 0 !== front) return;
+ const vx = side * r.range(10, 28), vy = -r.range(8, 34), x0 = side * 1, y0 = A + 2, land = BY + z * 2.6;
+ const tl = landTime(y0, vy, G, land);
+ if (age < tl) {
+ const x = x0 + vx * age, y = y0 + vy * age + 0.5 * G * age * age;
+ drop(p, x, y, vx, vy + G * age, front ? W[7] : W[6], front ? W[5] : W[4], 0.03);
+ } else {
+ const a = age - tl, lx = x0 + vx * tl;
+ if (a < 0.05) p.px(lx - 1, land - 1, W[6]), p.px(lx + 1, land - 1, W[6]);
+ else if (a < 0.1) p.px(lx - 2, land - 2, W[5]), p.px(lx + 2, land - 2, W[5]);
+ if (a > 0.03) ripple(p, lx, land, 1 + a * 9, (1 + a * 9) * 0.3, W[5], W[4], 1.4 * (1 - a / (life - tl)), S + vx);
+ }
+ });
+ streams(false);
+ arcs(false);
+ // the jet: a column of streaks racing upward, wider at the foot, blooming at the top
+ p.shade(-3, A - 2, 3, BY, (x, y) => {
+ const v = (BY - y) / (BY - A), w = 1.9 - v * 0.6 + (v > 0.94 ? 1.2 : 0);
+ if (Math.abs(x) > w) return;
+ const n = tileNoise(x * 0.8, y * 0.16 + ph * 12, 0, 12, S);
+ if (Math.abs(x) > w - 0.9) return x < 0 ? W[6] : W[4];
+ return n > 0.15 ? W[7] : W[6];
+ });
+ // the foot: a churn of white where the jet leaves the pool
+ for (let i = 0; i < 5; i++) {
+ const a = ph * TAU * 2 + i * 1.3, r = 3 + Math.sin(a * 1.7) * 0.8;
+ p.px(Math.cos(a) * r, BY - 1 + Math.sin(a) * 0.8, W[7]);
+ }
+ p.rect(-3, BY - 1, 7, 1, W[6]);
+ streams(true);
+ arcs(true);
+ p.glow(0, A + 2, 12, W[6], 0.18);
+ p.glow(0, BY, 20, W[5], 0.1);
+}
diff --git a/src/fx/water/geyser.js b/src/fx/water/geyser.js
new file mode 100644
index 0000000..1faabd5
--- /dev/null
+++ b/src/fx/water/geyser.js
@@ -0,0 +1,96 @@
+import { PAL, stream, burst, seg, ease, clamp, tileNoise, noise2, bump, WHITE } from "../../core/index.js";
+import { fit, ripple, drop, landTime } from "./_lib.js";
+
+export const meta = {
+ name: "Geyser",
+ desc: "The ground burbles, then a column of water blasts skyward with a churning white head, rains droplets all around, and sinks back into a draining puddle.",
+ tags: ["water", "geyser", "eruption", "column", "ground", "one-shot"],
+ size: [80, 112],
+ origin: [40, 106],
+ duration: 2.6,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ options: { palette: PAL.water, height: 86, seed: 9 },
+};
+
+const ERUPT = 0.5, G = 380;
+
+export function draw(p, t, o) {
+ const W = fit(o.palette), S = o.seed, HMAX = o.height;
+ const rise = ease.outExpo(seg(t, ERUPT, ERUPT + 0.28)), fall = ease.inQuad(seg(t, 1.38, 1.95));
+ const H = HMAX * rise * (1 - fall) + 2 * Math.sin(t * 9) * rise * (1 - fall), top = -H;
+ // the puddle it leaves: spreads out, then drains away by dither
+ const drain = ease.inQuad(seg(t, 1.9, 2.5)), prx = (6 + 18 * ease.outCubic(seg(t, ERUPT, 1.2))) * (1 - drain);
+ if (t > ERUPT && prx > 1.5) p.ellipse(0, 0.5, prx, 2.6 * (1 - drain * 0.6), (d, a) => (d > 0.78 ? (Math.sin(a) < 0 ? W[4] : W[3]) : W[2]));
+ // the vent: a dark mouth in the floor
+ if (t < 2.4) p.ellipse(0, 0.5, 5 * (1 - seg(t, 2.1, 2.4)), 1.5, W[0]);
+ // burbling before it blows: a dome of water heaves up and drops back, bigger each time
+ if (t < ERUPT) {
+ const beat = [0.06, 0.2, 0.33].map((b, i) => bump(t, b, b + 0.12 + i * 0.02) * (1.5 + i)).reduce((a, b) => a + b, 0);
+ const heave = beat + ease.inQuad(seg(t, 0.38, ERUPT)) * 4;
+ if (heave > 0.4) p.ellipse(0, 0, 3 + heave * 0.5, heave, (d, a) => (Math.sin(a) < -0.4 && d > 0.5 ? W[6] : W[5]));
+ if (heave > 0.4) p.px(-1, -heave + 0.5, W[7]);
+ burst(4, S + 3, (r, i) => {
+ const t0 = 0.08 + i * 0.1, a = t - t0;
+ if (a < 0) return;
+ const vy = -r.range(40, 70), vx = r.range(-15, 15), tl = landTime(-2, vy, G * 2, 0);
+ if (a < tl) p.px(vx * a, -2 + vy * a + G * a * a, W[6]);
+ });
+ }
+ // droplets rain out of the head while it stands, and out of what's left as it falls
+ const rain = (front) => stream(t, ERUPT + 0.06, 1.62, 72, S, 1.6, (age, life, r, i) => {
+ const z = r.range(-1, 1);
+ if (z > 0 !== front) return;
+ const born = t - age, hb = HMAX * ease.outExpo(seg(born, ERUPT, ERUPT + 0.28)) * (1 - ease.inQuad(seg(born, 1.38, 1.95)));
+ const late = seg(born, 1.2, 1.62), side = r.sign(), vx = side * r.range(12, 34), vy = -r.range(-10, 50 - late * 32);
+ const x0 = side * r.range(4, 9), y0 = -hb + r.range(-2, 10), land = z * 2.5;
+ const tl = landTime(y0, vy, G, land);
+ if (age < tl) {
+ const x = x0 + vx * age, y = y0 + vy * age + 0.5 * G * age * age;
+ drop(p, x, y, vx, vy + G * age, front ? W[7] : W[6], front ? W[5] : W[4], 0.03);
+ } else if (age < tl + 0.2) {
+ const a = (age - tl) / 0.2, lx = x0 + vx * tl;
+ ripple(p, lx, land, 1 + a * 3, (1 + a * 3) * 0.3, W[5], W[4], 1.4 * (1 - a), i);
+ }
+ });
+ rain(false);
+ // the column: streaks shooting up, lit on the left, a churning lumpy head of foam on top
+ if (H > 1) {
+ const hw = (y) => 4.6 + 3 * clamp(-y / HMAX) + 0.9 * tileNoise(y * 0.12 + t * 14, 2, 0, 0, S + 5);
+ const HR = 9 * (1 - ease.inQuad(seg(t, 1.36, 1.62))) * seg(H, 6, 20);
+ p.shade(-16, top - 12, 16, 0, (x, y) => {
+ const head = HR > 1 ? Math.hypot(x * 0.8, (y - top - 3) * 1.05) - (HR + 2.4 * noise2(Math.atan2(y - top - 3, x) * 2.2 + t * 5, t * 3, S + 6)) : 1;
+ const cap = y - top < 3 ? Math.sqrt(Math.max(0, (y - top) / 3)) : 1, w = hw(y) * cap;
+ if (head > 0 && (Math.abs(x) > w || y < top)) return;
+ if (head > 0 && y - top < 2.5) return W[7];
+ if (head <= 0) {
+ // foam: white, shaded low on the right
+ const sh = (x * 0.6 + (y - top - 3) * 0.9) / HR + 0.35 * noise2(x * 0.5, y * 0.5 + t * 4, S + 8);
+ return sh > 0.8 ? W[5] : sh > 0.35 ? W[6] : W[7];
+ }
+ const n = tileNoise(x * 0.7, y * 0.07 + t * 6, 0, 0, S);
+ if (x < -w + 1.5) return W[6];
+ if (x > w - 1.5) return x > w - 0.8 ? W[3] : W[4];
+ return n > 0.25 ? W[7] : n > -0.2 ? W[6] : W[5];
+ });
+ // the skirt: water bursting back out where the column meets the ground
+ const sk = rise * (1 - fall);
+ for (let i = 0; i < 9; i++) {
+ const a = (i / 9) * Math.PI + Math.sin(t * 7 + i) * 0.2, r = 6 + 6 * sk + Math.sin(t * 11 + i * 2) * 1.2;
+ p.circle(-Math.cos(a) * r, -1.5 - Math.sin(a) * 3 * sk, 1.8 + sk * 1.4, i % 2 ? W[7] : W[6]);
+ }
+ }
+ rain(true);
+ // the blast: a white flash and a ring racing out along the ground
+ const fl = seg(t, ERUPT, ERUPT + 0.07);
+ if (fl > 0 && fl < 1) {
+ p.ellipse(0, -2, 11, 4, WHITE);
+ p.rect(-5, -H, 11, H, WHITE);
+ }
+ const ring = seg(t, ERUPT, ERUPT + 0.45);
+ if (ring > 0 && ring < 1) ripple(p, 0, 0, 7 + 26 * ease.outCubic(ring), (7 + 26 * ease.outCubic(ring)) * 0.16, ring < 0.3 ? WHITE : W[6], W[5], 1.4 * (1 - ring), S);
+ const L = rise * (1 - fall);
+ p.glow(0, top + 4, 26, W[5], 0.18 * L);
+ p.glow(0, -2, 22, W[6], 0.45 * (1 - seg(t, ERUPT, ERUPT + 0.3)) * (t > ERUPT ? 1 : 0));
+}
diff --git a/src/fx/water/puddle-step.js b/src/fx/water/puddle-step.js
new file mode 100644
index 0000000..5253f61
--- /dev/null
+++ b/src/fx/water/puddle-step.js
@@ -0,0 +1,64 @@
+import { PAL, burst, seg, ease, WHITE } from "../../core/index.js";
+import { fit, ripple, landTime } from "./_lib.js";
+
+export const meta = {
+ name: "Puddle step",
+ desc: "A foot slaps down in a puddle: a white slap, two low fans of water flung out sideways, droplets pattering down and rings running out.",
+ tags: ["water", "puddle", "step", "footstep", "splash", "one-shot"],
+ size: [64, 32],
+ origin: [32, 26],
+ duration: 0.7,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ actor: true,
+ options: { palette: PAL.water, size: 1, seed: 15 },
+};
+
+const G = 520;
+
+// the puddle and its rings lie under the feet; the far half of the spray goes behind the character
+export function drawBack(p, t, o) {
+ const W = fit(o.palette), k = o.size, gone = ease.inQuad(seg(t, 0.4, 0.7));
+ const rx = 15 * k * (1 - gone);
+ if (rx > 1) p.ellipse(0, 0.5, rx, 2.8 * k * (1 - gone * 0.5), (d, a) => (d > 0.82 ? (Math.sin(a) < 0 ? W[4] : W[2]) : W[2]));
+ for (const [t0, life, r1] of [[0.02, 0.45, 20], [0.12, 0.45, 14]]) {
+ const u = seg(t, t0, t0 + life);
+ if (u <= 0 || u >= 1) continue;
+ const r = (4 + (r1 - 4) * ease.outCubic(u)) * k;
+ ripple(p, 0, 0.5, r, r * 0.2, u < 0.3 ? W[7] : W[6], W[5], 1.4 * (1 - seg(u, 0.35, 1)), o.seed + t0 * 10);
+ }
+ spray(p, t, o, false);
+}
+
+export function draw(p, t, o) {
+ spray(p, t, o, true);
+}
+
+function spray(p, t, o, front) {
+ const W = fit(o.palette), S = o.seed, k = o.size;
+ // the slap: two frames of white where the foot lands
+ if (front && t < 0.07) {
+ p.ellipse(-7, -1, 4, 1.5, WHITE);
+ p.ellipse(7, -1, 4, 1.5, WHITE);
+ p.glow(0, -2, 16, W[6], 0.35);
+ }
+ // the fans: sheets of water flung out low to either side, breaking into drops as they fall
+ burst(22, S, (r, i) => {
+ const z = r.range(-1, 1);
+ if (z > 0 !== front) return;
+ const side = i % 2 ? 1 : -1, vx = side * r.range(22, 62) * k, vy = -r.range(50, 110) * k;
+ const x0 = side * r.range(3, 6) * k, y0 = -1, land = z * 2.2, tl = landTime(y0, vy, G, land);
+ if (Math.abs(vx) * tl > 22 * k) return; // keep the far throws on the canvas
+ if (t < tl) {
+ const x = x0 + vx * t, y = y0 + vy * t + 0.5 * G * t * t, sheet = t < 0.12;
+ const len = sheet ? 0.045 : 0.018;
+ p.line(x - vx * len, y - (vy + G * t) * len, x, y, sheet ? W[6] : W[5]);
+ p.px(x, y, t < 0.2 ? W[7] : W[6]);
+ } else if (t < tl + 0.18) {
+ const u = (t - tl) / 0.18, lx = x0 + vx * tl;
+ if (u < 0.35) p.px(lx, land - 1, W[6]);
+ else ripple(p, lx, land, 1 + u * 2, 0.6, W[5], W[4], 1.3 * (1 - u), i);
+ }
+ });
+}
diff --git a/src/fx/water/rain-splash.js b/src/fx/water/rain-splash.js
new file mode 100644
index 0000000..4ae501c
--- /dev/null
+++ b/src/fx/water/rain-splash.js
@@ -0,0 +1,61 @@
+import { PAL, rng, seg, clamp, wrap } from "../../core/index.js";
+import { fit, ripple, landTime } from "./_lib.js";
+
+export const meta = {
+ name: "Rain splash",
+ desc: "Rain on the ground: slanted drops hit and burst into tiny crowns, flick droplets and leave rings that spread and fade.",
+ tags: ["water", "rain", "weather", "splash", "puddle", "ambient", "loop"],
+ size: [80, 44],
+ origin: [40, 36],
+ duration: 1.2,
+ loop: true,
+ fps: 30,
+ bg: "ground",
+ options: { palette: PAL.water, count: 20, width: 30, seed: 4 },
+};
+
+const G = 520;
+
+export function draw(p, t, o) {
+ const W = fit(o.palette), S = o.seed, D = meta.duration, HW = o.width, n = o.count;
+ for (let i = 0; i < n; i++) {
+ // births spread evenly through the loop and lanes spread across the ground, so it never clumps or gaps
+ const r = rng(S, i), born = ((i + r.range(-0.35, 0.35)) / n) * D, lane = (i * 7) % n;
+ const x0 = -HW + ((lane + r.range(0.1, 0.9)) / n) * HW * 2, depth = r.range(-1.5, 4.5), near = (depth + 1.5) / 6;
+ const fallT = r.range(0.085, 0.1), vy = (28 + depth) / fallT, vx = vy * 0.22, life = fallT + r.range(0.45, 0.6);
+ const age = wrap(t - born, D);
+ if (age >= life) continue;
+ // falling: a slanted streak, nearer drops longer and brighter
+ if (age < fallT) {
+ const x = x0 - vx * (fallT - age), y = depth - vy * (fallT - age), len = 0.014 + near * 0.008;
+ p.line(x - vx * len, y - vy * len, x, y, near > 0.5 ? W[5] : W[4]);
+ p.px(x, y, near > 0.5 ? W[7] : W[6]);
+ continue;
+ }
+ const a = age - fallT, rest = life - fallT, big = near > 0.45;
+ // the crown: a flash, then two flicks that open up and fall away
+ if (a < 0.034) {
+ p.px(x0, depth - 1, W[7]);
+ p.px(x0 - 1, depth, W[6]), p.px(x0 + 1, depth, W[6]);
+ if (big) p.px(x0, depth - 2, W[6]);
+ } else if (a < 0.1) {
+ const h = big ? 3 : 2;
+ p.line(x0 - 1, depth - 1, x0 - 2, depth - h, W[6]);
+ p.line(x0 + 1, depth - 1, x0 + 2, depth - h, W[6]);
+ p.px(x0 - 2, depth - h, W[7]), p.px(x0 + 2, depth - h, W[7]);
+ } else if (a < 0.16) {
+ p.px(x0 - 3, depth - 2, W[5]), p.px(x0 + 3, depth - 2, W[5]);
+ if (big) p.px(x0 - 3, depth - 3, W[6]), p.px(x0 + 3, depth - 3, W[6]);
+ }
+ // a flicked droplet or two
+ for (const side of [-1, 1]) {
+ if (r.next() < 0.4) continue;
+ const dvx = side * r.range(12, 26), dvy = -r.range(50, 80), tl = landTime(depth - 2, dvy, G, depth);
+ if (a < 0.06 || a > tl) continue;
+ p.px(x0 + dvx * a, depth - 2 + dvy * a + 0.5 * G * a * a, W[6]);
+ }
+ // the ring it leaves, spreading and breaking up
+ const u = clamp(a / rest), rr = 1.5 + u * (3 + near * 4);
+ if (a > 0.05) ripple(p, x0, depth, rr, rr * 0.3, big ? W[6] : W[5], W[4], 1.3 * (1 - seg(u, 0.25, 1)), S + i * 3);
+ }
+}
diff --git a/src/fx/water/ripples.js b/src/fx/water/ripples.js
new file mode 100644
index 0000000..cbaf3cf
--- /dev/null
+++ b/src/fx/water/ripples.js
@@ -0,0 +1,45 @@
+import { PAL, fract, ease, seg, rng } from "../../core/index.js";
+import { fit, oval, ripple } from "./_lib.js";
+
+export const meta = {
+ name: "Ripples",
+ desc: "Rings spread over still water from a bobbing point: bright crests over dark troughs, slowing and breaking into dashes as they fade.",
+ tags: ["water", "ripple", "surface", "pond", "ambient", "loop"],
+ size: [80, 24],
+ origin: [40, 12],
+ duration: 2,
+ loop: true,
+ fps: 30,
+ bg: "ground",
+ options: { palette: PAL.water, count: 3, radius: 36, squash: 0.28, seed: 1 },
+};
+
+export function draw(p, t, o) {
+ const W = fit(o.palette), S = o.seed, ph = t / meta.duration, R = o.radius, q = o.squash, n = o.count;
+ for (let i = 0; i < n; i++) {
+ const k = fract(ph + i / n); // this ring's age 0..1: the newest is born as the oldest dies
+ const r = 1.5 + (R - 1.5) * ease.outQuad(k), keep = 1 - seg(k, 0.25, 1);
+ // the trough: a dark arc just inside the crest on the near side, gone before the crest
+ if (r > 5 && k < 0.6) oval(p, 0, 0.7, r - 2.5, (r - 2.5) * q, W[2], (a) => (Math.sin(a) > 0.35 ? 1 : 0));
+ ripple(p, 0, 0, r, r * q, k < 0.2 ? W[7] : W[6], k < 0.2 ? W[6] : W[5], keep * 1.25, S * 13 + i);
+ }
+ // flecks of foam floating on the surface, lifted a pixel as each crest passes under them
+ for (let i = 0; i < 5; i++) {
+ const r = rng(S, i), ang = r.range(0, Math.PI * 2), rho = r.range(8, R - 4), x = Math.cos(ang) * rho, y = Math.sin(ang) * rho * q;
+ let lift = 0;
+ for (let j = 0; j < n; j++) {
+ const k = fract(ph + j / n), rr = 1.5 + (R - 1.5) * ease.outQuad(k);
+ if (Math.abs(rr - rho) < 1.6) lift = 1;
+ }
+ p.px(x, y - lift, lift ? W[7] : W[5]);
+ if (r.next() < 0.5) p.px(x + 1, y - lift, W[4]);
+ }
+ // the source: each time a ring is born the point dips and kicks up a bead of water
+ const beat = fract(ph * n) * (meta.duration / n), hop = beat < 0.3 ? Math.sin((beat / 0.3) * Math.PI) : 0;
+ oval(p, 0, 0, 2.5 - hop, 0.8, W[6]);
+ if (hop > 0.05) {
+ p.px(0, -1 - Math.round(hop * 4), W[7]);
+ if (hop > 0.5) p.px(0, -Math.round(hop * 4), W[5]);
+ }
+ p.glow(0, 0, 10, W[5], 0.1 + 0.1 * hop);
+}
diff --git a/src/fx/water/splash.js b/src/fx/water/splash.js
new file mode 100644
index 0000000..6d68a96
--- /dev/null
+++ b/src/fx/water/splash.js
@@ -0,0 +1,99 @@
+import { PAL, burst, seg, ease, TAU, WHITE } from "../../core/index.js";
+import { fit, oval, ripple, drop, landTime } from "./_lib.js";
+
+export const meta = {
+ name: "Splash",
+ desc: "A drop plunges into water: a white flash, a spiky crown leaps up and sheds droplets, a jet bounces back, rings spread.",
+ tags: ["water", "splash", "impact", "drop", "liquid", "one-shot"],
+ size: [84, 52],
+ origin: [42, 40],
+ duration: 1.2,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ options: { palette: PAL.water, size: 1, seed: 2 },
+};
+
+const T0 = 0.1, Q = 0.3, G = 430; // impact time, how flat the surface looks, gravity
+
+export function draw(p, t, o) {
+ const W = fit(o.palette), S = o.seed, k = o.size, tau = t - T0;
+ // the drop falls in, stretched by its speed
+ if (tau < 0) {
+ const y = -32 + 32 * (t / T0);
+ p.line(0, y - 6, 0, y - 3, W[4]);
+ p.rect(-1, y - 3, 2, 3, W[5]);
+ p.px(0, y - 1, W[7]);
+ return;
+ }
+ // rings spread from the impact and fade
+ for (const [t0, t1, r0, r1] of [[0, 0.95, 6, 30], [0.12, 1.0, 3, 19]]) {
+ const u = seg(tau, t0, t1);
+ if (u <= 0 || u >= 1) continue;
+ const r = (r0 + (r1 - r0) * ease.outCubic(u)) * k;
+ ripple(p, 0, 0, r, r * Q, u < 0.2 ? W[7] : W[6], W[5], 1.3 * (1 - seg(u, 0.3, 1)), S + r0);
+ }
+ // the crown: a wall of water flaring out, its rim torn into spikes, back half darker
+ const grow = ease.outCubic(seg(tau, 0, 0.13)), sink = ease.inQuad(seg(tau, 0.12, 0.42));
+ const H = 15 * k * grow * (1 - sink), R0 = (2.5 + 6 * ease.outCubic(seg(tau, 0, 0.5))) * k, Rt = R0 + H * 0.5;
+ const N = 9, spin = S * 0.7;
+ const tip = (a) => H * (0.55 + 0.45 * Math.pow(Math.abs(Math.cos((a * N) / 2 + spin)), 5));
+ if (H > 0.6) {
+ const da = 0.2 / Rt;
+ for (const front of [false, true])
+ for (let a = -Math.PI; a < Math.PI; a += da) {
+ const s = Math.sin(a);
+ if (s > 0 !== front) continue;
+ const h = tip(a), bx = Math.cos(a) * R0, by = s * R0 * Q, tx = Math.cos(a) * Rt, ty = s * Rt * Q - h;
+ p.line(bx, by, tx, ty, front ? (u) => (u > 0.82 ? W[6] : u > 0.4 ? W[5] : W[4]) : (u) => (u > 0.8 ? W[5] : W[3]));
+ if (front && h > H * 0.9) p.px(tx, ty, W[7]);
+ }
+ }
+ // droplets torn off the spikes: thrown out and up, falling back to the surface with a tiny ring
+ burst(14, S, (r, i) => {
+ const a = (i / 14) * TAU + r.range(-0.2, 0.2), born = r.range(0.07, 0.15), age = tau - born;
+ if (age < 0) return;
+ const g0 = ease.outCubic(seg(born, 0, 0.13)), h0 = 15 * k * g0, R = (2.5 + 6 * ease.outCubic(seg(born, 0, 0.5))) * k + h0 * 0.5;
+ const x0 = Math.cos(a) * R, y0 = Math.sin(a) * R * Q - h0 * r.range(0.8, 1);
+ const vx = Math.cos(a) * r.range(22, 50) * k, vy = -r.range(60, 105) * k, land = Math.sin(a) * (R + 10) * Q;
+ const tl = landTime(y0, vy, G, land);
+ if (age < tl) {
+ const x = x0 + vx * age, y = y0 + vy * age + 0.5 * G * age * age;
+ const big = r.next() < 0.4;
+ drop(p, x, y, vx, vy + G * age, W[7], Math.sin(a) > 0 ? W[5] : W[4], 0.025);
+ if (big) p.px(x + 1, y, W[6]);
+ } else if (age < tl + 0.2) {
+ const u = (age - tl) / 0.2, lx = x0 + vx * tl;
+ ripple(p, lx, land, 1 + u * 2, (1 + u * 2) * Q, W[5], W[4], 1.4 * (1 - u), i);
+ }
+ });
+ // the jet bounces back up the middle and drops a bead
+ const tj = tau - 0.26;
+ if (tj > 0) {
+ const up = ease.outCubic(seg(tj, 0, 0.12)), down = ease.inQuad(seg(tj, 0.12, 0.32)), hj = 13 * k * up * (1 - down);
+ if (hj > 0.5) {
+ p.rect(-1, -hj, 3, hj, W[5]);
+ p.line(0, -hj, 0, -1, W[6]);
+ p.px(0, -hj, W[7]);
+ }
+ const tb = tj - 0.12;
+ if (tb > 0) {
+ const vy = -45 * k, y0 = -13 * k - 2, tl = landTime(y0, vy, G, 0);
+ if (tb < tl) {
+ const y = y0 + vy * tb + 0.5 * G * tb * tb;
+ p.rect(-1, y - 1, 2, 2, W[6]);
+ p.px(0, y - 1, W[7]);
+ } else if (tb < tl + 0.3) {
+ const u = (tb - tl) / 0.3;
+ ripple(p, 0, 0, 2 + u * 7, (2 + u * 7) * Q, W[6], W[5], 1.4 * (1 - u), 5);
+ }
+ }
+ }
+ // the hit: a flat white flash on the surface for two frames
+ if (tau < 0.07) {
+ oval(p, 0, 0, 7 * k, 2, WHITE);
+ p.rect(-4, -1, 9, 2, WHITE);
+ p.glow(0, -2, 22, W[5], 0.35);
+ }
+ p.glow(0, -6, 18, W[5], 0.12 * (1 - seg(tau, 0, 0.5)));
+}
diff --git a/src/fx/water/steam-vent.js b/src/fx/water/steam-vent.js
new file mode 100644
index 0000000..6697da2
--- /dev/null
+++ b/src/fx/water/steam-vent.js
@@ -0,0 +1,66 @@
+import { rng, seg, ease, wrap, noise2, at } from "../../core/index.js";
+import { fit, STEAM, METAL } from "./_lib.js";
+
+export const meta = {
+ name: "Steam vent",
+ desc: "A floor grate hisses: a white jet spits up, then steam billows out in a widening plume that leans downwind and wears away, with wisps between.",
+ tags: ["water", "steam", "vent", "smoke", "industrial", "hazard", "ambient", "loop"],
+ size: [56, 88],
+ origin: [28, 82],
+ duration: 1.6,
+ loop: true,
+ fps: 30,
+ bg: "ground",
+ options: { palette: STEAM, bursts: 1, seed: 10 },
+};
+
+const LIFE = 1.7;
+
+export function draw(p, t, o) {
+ const C = fit(o.palette, 7), S = o.seed, D = meta.duration, nb = o.bursts, P = D / nb;
+ // puffs: each burst pushes out a train of them; each shoots up, slows, swells, leans downwind and wears away
+ const puffs = [];
+ for (let b = 0; b < nb; b++)
+ for (let i = 0; i < 14; i++) {
+ const r = rng(S, b, i), born = b * P + i * 0.035 + r.range(0, 0.02), life = r.range(0.8, 1.15) * Math.min(1, P / 1.3);
+ const age = wrap(t - born, D);
+ if (age >= life) continue;
+ const k = age / life, drag = 2.4, e = (1 - Math.exp(-drag * age)) / drag;
+ const rise = r.range(100, 145) * (1 - i * 0.035) * e + age * 12, out = r.range(-34, 34) * e;
+ const x = r.range(-3, 3) + out + Math.sin(age * 3 + r.range(0, 6)) * k * 2 + k * k * 9;
+ puffs.push({ x, y: -3 - rise, r: 1.6 + 7.5 * ease.outCubic(k) * r.range(0.7, 1.1), f: 1 - ease.inQuad(seg(k, 0.2, 1)), s: i * 7.1 + b * 3.3 });
+ }
+ // the steam: each puff wears away from its edges into ragged islands as it thins; lit from the top left
+ p.shade(-28, -82, 28, 0, (x, y, out) => {
+ let best = 0, lit = 0;
+ for (const f of puffs) {
+ const dx = x - f.x, dy = y - f.y, d2 = (dx * dx + dy * dy) / (f.r * f.r);
+ if (d2 >= 1) continue;
+ const v = 1 - d2 - (1 - f.f) * 0.95 + noise2(dx * 0.45 + f.s, dy * 0.45, S) * 0.3 * (1.2 - f.f);
+ if (v > best) (best = v), (lit = (-dx - dy * 1.3) / f.r);
+ }
+ if (best < 0.1) return;
+ out.c = at(C.slice(3), 0.3 + lit * 0.4 + best * 0.35);
+ });
+ // the jet: a hard white spit straight up at the start of each burst
+ for (let b = 0; b < nb; b++) {
+ const age = wrap(t - b * P, D);
+ if (age > 0.22) continue;
+ const h = 26 * ease.outCubic(seg(age, 0, 0.1)), w = age < 0.12 ? 2 : 1, a = 1 - seg(age, 0.12, 0.22);
+ p.rect(-w + 1, -h, w * 2 - 1, h, C[6], a);
+ p.line(0, -h, 0, -1, C[6], a);
+ p.glow(0, -h * 0.5, 14, C[5], 0.25 * a);
+ }
+ // wisps leaking between bursts: thin curls of vapour rising off the grate
+ for (let i = 0; i < 6; i++) {
+ const r = rng(S + 5, i), born = 0.45 + (i / 6) * (D - 0.5), life = r.range(0.5, 0.7), age = wrap(t - born, D);
+ if (age >= life) continue;
+ const k = age / life, x = r.range(-5, 5) + Math.sin(age * 9 + i) * (0.5 + k * 1.5), y = -2 - age * r.range(22, 30), len = k < 0.5 ? 3 : 2;
+ p.line(x, y, x + Math.sin(age * 9 + i + 1), y - len, k < 0.5 ? C[4] : C[3], 1 - seg(k, 0.6, 1));
+ }
+ // the vent: a slotted grate in the floor
+ p.rect(-7, -1, 15, 1, METAL[3]);
+ p.rect(-7, 0, 15, 2, METAL[0]);
+ for (let x = -6; x <= 6; x += 3) p.rect(x, 0, 1, 2, METAL[2]);
+ p.rect(-7, 2, 15, 1, METAL[1]);
+}
diff --git a/src/fx/water/tidal-wave.js b/src/fx/water/tidal-wave.js
new file mode 100644
index 0000000..457a563
--- /dev/null
+++ b/src/fx/water/tidal-wave.js
@@ -0,0 +1,80 @@
+import { PAL, stream, seg, ease, clamp, noise2, tileNoise } from "../../core/index.js";
+import { fit, drop, landTime, clip } from "./_lib.js";
+
+export const meta = {
+ name: "Tidal wave",
+ desc: "A towering wall of water rolls right across the screen: a white crest curling over a dark face, spray torn off the top, foam boiling at its foot.",
+ tags: ["water", "wave", "tsunami", "flood", "spell", "directional", "one-shot"],
+ size: [128, 80],
+ origin: [16, 74],
+ duration: 2.2,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ options: { palette: PAL.water, height: 56, speed: 100, seed: 14 },
+};
+
+const X0 = -16, X1 = 112, BACK = 66, G = 260; // canvas edges in local x, length of the wave's back
+
+export function draw(p, t, o) {
+ clip(p, X0, -74, X1, 6, () => wave(p, t, o));
+}
+
+function wave(p, t, o) {
+ const W = fit(o.palette), S = o.seed, HW = o.height, V = o.speed;
+ const xf = X0 - 6 + V * t; // the foot of the front face
+ const Hn = HW * (0.6 + 0.4 * ease.outCubic(seg(t, 0, 0.35))) * (1 - 0.35 * ease.inQuad(seg(t, 1.4, 2.0)));
+ // the water's height above x: a plateau behind the wall, sloping away at the back
+ const height = (x) => {
+ const u = (xf - x) / BACK;
+ return u < 0 ? Hn : Hn * (1 - ease.inOutSine(clamp((u - 0.25) / 0.75))) * (1 + 0.03 * Math.sin(x * 0.25 - t * 9));
+ };
+ const lean = (y) => 9 * Math.pow(clamp(-y / Hn), 2.4); // the face bulges forward toward the top
+ p.shade(xf - BACK - 2, -Hn - 4, xf + 10, 1, (x, y) => {
+ const front = xf + lean(y);
+ if (y > 0 || x > front + 0.5) return;
+ const top = -height(Math.min(x, xf));
+ if (y < top) return;
+ const dep = y - top, n = tileNoise(x * 0.3 - t * 12, y * 0.3 + t * 7, 0, 0, S);
+ // the crest: a rolling band of white foam, thickest at the front
+ if (dep < 2.5 + 3 * clamp(1 - (xf - x) / 20) + n * 1.5 && -top > Hn * 0.5) return n > -0.25 ? W[7] : W[6];
+ // the face: in the shadow of the curl, streaked as the water climbs it
+ if (x > xf - 3 + lean(y) * 0.5) {
+ if (x > front - 1) return W[2];
+ return noise2(x * 0.6, y * 0.1 - t * 7, S + 1) > 0.3 ? W[4] : W[3];
+ }
+ // the back: bright under the foam, deeper below, foam streaks slanting back from the crest
+ const streak = Math.sin((x - xf) * 0.32 + y * 0.55 + noise2(x * 0.1, y * 0.1, S + 2) * 2.5);
+ if (streak > 0.93 && dep < -top * 0.7) return W[6];
+ return dep < 5 ? W[5] : dep < Hn * 0.4 ? W[4] : W[3];
+ });
+ // the curl: the top of the wall thrown forward over the face
+ const R = 10, cx = xf + 6, cy = -Hn + R - 1.5;
+ p.arc(cx, cy, R, (u) => Math.max(1.5, 8 * (1 - u * 0.8)), -Math.PI * 1.02, -Math.PI * 1.02 + 2.75,
+ (u, v) => (v > 0.5 ? (noise2(u * 6 - t * 8, v, S + 3) > -0.3 ? W[7] : W[6]) : v > 0.25 ? W[5] : W[3]));
+ // foam boiling at the foot of the wall
+ for (let i = 0; i < 8; i++) {
+ const x = xf + 3 + Math.sin(t * 13 + i * 2.1) * 3 - i * 1.6, y = -2 - (i % 3) * 2.2 - Math.sin(t * 17 + i) * 1.2;
+ p.circle(x, y, 2 + (i % 2), (d, a) => (Math.sin(a) > 0.3 && d > 0.6 ? W[5] : i % 3 ? W[7] : W[6]));
+ }
+ // spray torn off the crest, blown up and left behind the wall
+ stream(t, 0, 1.9, 44, S, 0.55, (age, life, r) => {
+ const born = t - age, bx = X0 - 6 + V * born + r.range(-8, 8);
+ const Hb = HW * (0.6 + 0.4 * ease.outCubic(seg(born, 0, 0.35))) * (1 - 0.35 * ease.inQuad(seg(born, 1.4, 2.0)));
+ const vx = V * r.range(0.2, 0.7), vy = -r.range(30, 75), x = bx + vx * age, y = -Hb - 2 + vy * age + 0.5 * G * age * age;
+ if (y > -2) return;
+ drop(p, x, y, vx, vy + G * age, age / life < 0.5 ? W[7] : W[6], W[5], 0.02);
+ });
+ // droplets kicked out ahead of the foot
+ stream(t, 0.05, 1.7, 30, S + 1, 0.5, (age, life, r) => {
+ const born = t - age, bx = X0 + V * born + 8, vx = V * r.range(1.1, 1.6), vy = -r.range(30, 70);
+ const tl = landTime(-2, vy, G * 1.6, 0);
+ if (age <= tl) p.px(bx + vx * age, -2 + vy * age + 0.8 * G * age * age, W[6]);
+ });
+ // the wash it leaves: short lines of foam on the ground that shrink away
+ for (let i = 0; i < 5; i++) {
+ const xs = xf - BACK - 4 - i * 12, k = clamp((xf - BACK - xs) / 50 + seg(t, 1.8, 2.1)), half = 7 * (1 - k);
+ if (half > 0.5) p.line(xs - half, 0, xs + half, 0, i % 2 ? W[5] : W[6]);
+ }
+ p.glow(xf, -Hn * 0.75, 30, W[5], 0.16);
+}
diff --git a/src/fx/water/water-jet.js b/src/fx/water/water-jet.js
new file mode 100644
index 0000000..b8cf64b
--- /dev/null
+++ b/src/fx/water/water-jet.js
@@ -0,0 +1,64 @@
+import { PAL, cycle, tileNoise, clamp, seg, wrap, rand, TAU } from "../../core/index.js";
+import { fit, drop } from "./_lib.js";
+
+export const meta = {
+ name: "Water jet",
+ desc: "A pressurised stream blasts right from a nozzle: bright streaks race down a wobbling beam that breaks into blobs and spray at the end.",
+ tags: ["water", "jet", "stream", "hose", "beam", "directional", "loop"],
+ size: [96, 32],
+ origin: [4, 16],
+ duration: 0.5,
+ loop: true,
+ fps: 30,
+ bg: "dark",
+ options: { palette: PAL.water, length: 66, width: 2.4, seed: 6 },
+};
+
+const SEG = 7; // length of the blobs the end breaks into, px
+
+export function draw(p, t, o) {
+ const W = fit(o.palette), S = o.seed, ph = t / meta.duration, L = o.length, HW = o.width;
+ const yc = (x) => Math.sin(x * 0.11 - ph * TAU * 2) * 0.9 * clamp(x / L);
+ const end = (x) => seg(x, L * 0.62, L + 14);
+ const hw = (x) => (HW + 1.4 * clamp(x / L) + 0.45 * tileNoise(x * 0.12 - ph * 12, 0.5, 12, 0, S + 4)) * (1 - 0.45 * end(x));
+ // the beam: streaks race along it; toward the end it breaks into blobs that get smaller
+ p.shade(0, -9, L + 16, 9, (x, y) => {
+ const e = end(x);
+ let w = hw(x), dy = 0;
+ if (e > 0) {
+ // the blobs: each its own length and drift, sliding along with the flow, rounder and smaller further out
+ const xs = (x - ph * SEG * 9) / SEG, id = wrap(Math.floor(xs), 9), f = xs - Math.floor(xs);
+ const len = (1 - e * 0.8) * (1 - e * 0.5 * rand(S, id)), c = 0.5 + (rand(S, id, 1) - 0.5) * (1 - len);
+ const u = (f - c) / (len / 2);
+ if (Math.abs(u) >= 1) return;
+ w *= Math.sqrt(1 - u * u * Math.min(1, 0.6 + e * 3)) * (1 - e * 0.4 * rand(S, id, 2));
+ dy = (rand(S, id, 3) - 0.5) * 3 * e;
+ }
+ const v = (y - yc(x) - dy) / w;
+ if (Math.abs(v) > 1) return;
+ const n = tileNoise(x * 0.09 - ph * 16, y * 0.8, 8, 0, S);
+ if (v < -0.72) return W[6];
+ if (v > 0.68) return W[3];
+ if (v > 0.3) return n > 0.25 ? W[5] : W[4];
+ if (Math.abs(v + 0.15) < 0.28) return n > -0.15 ? W[7] : W[6];
+ return n > 0.35 ? W[6] : W[5];
+ });
+ // the nozzle flare: pressure bursting out of the mouth
+ p.rect(-1, -3, 2, 7, W[5]);
+ p.rect(-1, -2, 2, 4, W[6]);
+ p.rect(-1, -1, 3, 2, W[7]);
+ // spray peeling off the beam and the frayed end
+ cycle(t, meta.duration, 24, S, (r) => r.range(0.16, 0.28), (age, life, r) => {
+ const x0 = r.range(10, L + 4), side = r.sign(), y0 = yc(x0) + side * hw(x0) * 0.9;
+ const vx = r.range(70, 130), vy = side * r.range(12, 36) - 8, k = age / life;
+ const x = x0 + vx * age, y = y0 + vy * age + 70 * age * age;
+ if (x > 88) return;
+ drop(p, x, y, vx, vy + 140 * age, k < 0.5 ? W[7] : W[6], W[5], 0.02);
+ });
+ cycle(t, meta.duration, 12, S + 3, (r) => r.range(0.16, 0.3), (age, life, r) => {
+ const x = L + 6 + age * r.range(40, 70), y = r.range(-3, 3) + age * r.range(-24, 30) + 60 * age * age;
+ if (x < 90) p.px(x, y, age / life < 0.5 ? W[6] : W[4]);
+ });
+ p.glowLine(0, 0, L * 0.8, 0, 6, W[5], 0.1);
+ p.glow(0, 0, 8, W[6], 0.3);
+}
diff --git a/src/fx/water/water-orb.js b/src/fx/water/water-orb.js
new file mode 100644
index 0000000..a58df74
--- /dev/null
+++ b/src/fx/water/water-orb.js
@@ -0,0 +1,68 @@
+import { PAL, fract, tileNoise, TAU, bump } from "../../core/index.js";
+import { fit } from "./_lib.js";
+
+export const meta = {
+ name: "Water orb",
+ desc: "A floating sphere of water that bobs and jiggles, a current swirling inside it, a hard shine on top and droplets circling it.",
+ tags: ["water", "orb", "sphere", "magic", "floating", "loop"],
+ size: [52, 52],
+ origin: [26, 26],
+ duration: 2,
+ loop: true,
+ fps: 30,
+ bg: "dark",
+ options: { palette: PAL.water, radius: 13, seed: 12 },
+};
+
+export function draw(p, t, o) {
+ const W = fit(o.palette), S = o.seed, ph = t / meta.duration, R0 = o.radius;
+ const cy = Math.round(Math.sin(ph * TAU) * 1.6);
+ // it breathes: a squash and stretch that turns, plus a small ripple running round the edge
+ const R = (a) => R0 * (1 + 0.06 * Math.sin(ph * TAU * 2) * Math.cos(2 * a)) + 0.3 * Math.sin(4 * a + ph * TAU * 2);
+ // droplets on a tilted orbit: the far half goes behind the orb
+ const orbit = (front) => {
+ for (let i = 0; i < 3; i++) {
+ const th = ph * TAU + (i * TAU) / 3 + i * 0.4, z = Math.sin(th);
+ if (z > 0 !== front) continue;
+ const x = Math.cos(th) * (R0 + 6), y = cy + Math.sin(th) * 4 - Math.cos(th) * 3;
+ p.px(x, y, front ? W[7] : W[4]);
+ if (front) p.px(x - 1, y, W[5]);
+ }
+ };
+ orbit(false);
+ // the body: a ball lit from the top left, deep in the middle, light bending through the bottom right
+ p.shade(-R0 - 2, cy - R0 - 2, R0 + 2, cy + R0 + 2, (x, y) => {
+ const dx = x, dy = y - cy, r = Math.hypot(dx, dy), a = Math.atan2(dy, dx), rr = R(a), d = r / rr;
+ if (d > 1) return;
+ const nz = Math.sqrt(1 - d * d), nx = dx / rr, ny = dy / rr;
+ if (d > 0.91) return nx + ny > 0.55 ? W[4] : nx + ny < -0.6 ? W[3] : W[2];
+ if (d > 0.72 && nx + ny > 0.75) return W[5];
+ // the current: two thin arms curling round the middle, turning once a loop
+ const sw = fract((a / TAU) * 2 + d * 1.1 - ph * 2);
+ const lit = -nx * 0.5 - ny * 0.6 + nz * 0.55;
+ if (d > 0.22 && d < 0.84 && sw < 0.07 + 0.03 * tileNoise((a / TAU) * 8 - ph * 8, d * 3, 8, 0, S)) return lit > 0.45 ? W[6] : W[5];
+ return lit > 0.72 ? W[5] : lit > 0.38 ? W[4] : lit > -0.05 ? W[3] : W[2];
+ });
+ // bubbles drifting up inside it
+ for (let i = 0; i < 3; i++) {
+ const k = fract(ph + i / 3), x = (i - 1) * 4 + Math.sin(k * 9 + i) * 1.2, y = cy + R0 * 0.7 - k * R0 * 1.4;
+ if (Math.hypot(x, y - cy) < R0 - 2.5) p.px(x, y, W[6]);
+ }
+ // the shine: a hard white highlight and a small kick of light opposite
+ const hx = -Math.round(R0 * 0.42), hy = cy - Math.round(R0 * 0.5);
+ p.rect(hx - 1, hy, 3, 2, W[7]);
+ p.px(hx + 2, hy + 1, W[6]);
+ p.px(hx - 1, hy + 2, W[6]);
+ p.px(hx + 3, hy - 1, W[7]);
+ p.px(Math.round(R0 * 0.5), cy + Math.round(R0 * 0.55), W[6]);
+ // a drip sags off the bottom and gets pulled back in
+ const sag = bump(fract(ph + 0.3), 0.1, 0.6), by = cy + R0 + 0.5;
+ if (sag > 0.05) {
+ const len = Math.round(sag * 4);
+ p.line(1, by, 1, by + len, W[3]);
+ p.px(1, by + len, sag > 0.7 ? W[5] : W[4]);
+ }
+ orbit(true);
+ p.glow(0, cy, R0 * 2.2, W[4], 0.2);
+ p.glow(hx, hy, 6, W[6], 0.25);
+}
diff --git a/src/fx/water/waterfall.js b/src/fx/water/waterfall.js
new file mode 100644
index 0000000..dba36b2
--- /dev/null
+++ b/src/fx/water/waterfall.js
@@ -0,0 +1,76 @@
+import { PAL, cycle, tileNoise, clamp, ease, fract, TAU } from "../../core/index.js";
+import { fit, ripple } from "./_lib.js";
+
+export const meta = {
+ name: "Waterfall",
+ desc: "A sheet of water pours over a lip and streaks down into a churning band of white foam, throwing spray and drifting mist.",
+ tags: ["water", "waterfall", "cascade", "foam", "mist", "ambient", "loop"],
+ size: [64, 84],
+ origin: [32, 78],
+ duration: 1,
+ loop: true,
+ fps: 30,
+ bg: "ground",
+ options: { palette: PAL.water, height: 70, width: 10, seed: 7 },
+};
+
+export function draw(p, t, o) {
+ const W = fit(o.palette), S = o.seed, D = meta.duration, ph = t / D, H = o.height, HW = o.width;
+ const half = (y) => HW + 2.5 * clamp((y + H) / H);
+ // mist behind: a fine drift of pale specks rising off the base either side, thinning as it climbs
+ cycle(t, D, 22, S + 5, (r) => r.range(1.2, 2), (age, life, r) => {
+ const k = age / life, side = r.sign(), x = side * (HW + 1 + r.range(0, 4) + k * r.range(6, 16)), y = -2 - k * r.range(14, 26);
+ if (k > 0.55 && r.next() < (k - 0.55) * 2.2) return;
+ p.px(x + Math.sin(age * 3 + r.next() * TAU), y, k < 0.35 ? W[6] : W[5]);
+ if (r.next() < 0.4 && k < 0.6) p.px(x + 1, y, W[5]);
+ });
+ // the pool: dark water spreading from the base, rings running out
+ p.ellipse(0, 1, 30, 3.5, (d, a) => (d > 0.85 ? (Math.sin(a) < 0 ? W[4] : W[2]) : W[3]));
+ for (let i = 0; i < 2; i++) {
+ const k = fract(ph + i / 2), rr = HW + 4 + k * 15;
+ ripple(p, 0, 1, rr, 3.2, W[5], W[5], 1.3 * (1 - k), S + i);
+ }
+ // the sheet: streaks fall the length of it, edges darker, the lip bright where it bends over
+ p.shade(-HW - 4, -H - 2, HW + 4, -1, (x, y) => {
+ const v = (y + H) / H, edge = v > 0.1 ? tileNoise(x > 0 ? 3 : 7, y * 0.16 - ph * 12, 0, 12, S + 6) * 1.1 * v : 0;
+ const w = half(y) + edge, ax = Math.abs(x) / w;
+ if (ax > 1) return;
+ const n = tileNoise(x * 0.55, y * 0.05 - ph * 6, 0, 6, S) * 0.65 + tileNoise(x * 1.1, y * 0.1 - ph * 12, 0, 12, S + 1) * 0.35;
+ if (y < -H + 4) {
+ // the lip: the river's surface curling over the edge, rounded at the corners, white on the bend
+ if (y < -H && ax > 0.8) return;
+ if (y < -H + 1 && ax > 0.93) return;
+ return y < -H ? W[5] : y < -H + 2 ? (n > -0.4 ? W[7] : W[6]) : W[6];
+ }
+ if (ax > 0.86) return x < 0 ? W[4] : W[2];
+ if (v < 0.12) return n > -0.2 ? W[6] : W[5];
+ return n > 0.42 ? W[7] : n > 0.08 ? W[6] : n > -0.3 ? W[5] : W[4];
+ });
+ // foam: a churning white band where the sheet hits, lumpy along its top
+ p.shade(-HW - 9, -14, HW + 9, 3, (x, y) => {
+ const lump = tileNoise(x * 0.3, ph * 4, 0, 4, S + 2) * 3 + tileNoise(x * 0.7, ph * 8 + 3, 0, 8, S + 3) * 1.5;
+ const wide = HW + 7 - Math.max(0, -y - 4) * 0.4, top = -9 + lump + Math.abs(x) * 0.25;
+ if (Math.abs(x) > wide || y < top) return;
+ const n = tileNoise(x * 0.4, y * 0.4 - ph * 8, 0, 8, S + 4);
+ if (y > 1) return n > 0 ? W[5] : W[4];
+ return n > -0.35 ? W[7] : W[6];
+ });
+ // foam puffs rolling out of the base
+ cycle(t, D, 10, S, (r) => r.range(0.5, 0.8), (age, life, r) => {
+ const k = age / life, side = r.sign(), x = side * (r.range(2, HW) + ease.outCubic(k) * r.range(6, 12)), y = -r.range(2, 7) - k * 3;
+ const s = r.range(2, 3.5) * (1 - k * 0.6);
+ p.circle(x, y, s, (d, a) => (Math.sin(a) > 0.3 && d > 0.6 ? W[5] : k < 0.6 ? W[7] : W[6]));
+ });
+ // spray thrown up and out
+ cycle(t, D, 16, S + 1, (r) => r.range(0.3, 0.45), (age, life, r) => {
+ const side = r.sign(), vx = side * r.range(20, 45), vy = -r.range(50, 90), x0 = side * r.range(2, HW), y0 = -8;
+ const x = x0 + vx * age, y = y0 + vy * age + 0.5 * 360 * age * age;
+ if (y > 0) return;
+ p.px(x, y, age / life < 0.5 ? W[7] : W[6]);
+ });
+ // light: a cool shimmer down the sheet and off the foam
+ p.glow(0, -8, 24, W[5], 0.16);
+ p.glow(-HW - 8, -10, 14, W[6], 0.12);
+ p.glow(HW + 8, -10, 14, W[6], 0.12);
+ p.glowLine(0, -H, 0, -6, 9, W[5], 0.08 + 0.03 * Math.sin(ph * TAU));
+}
diff --git a/src/fx/water/wave-crash.js b/src/fx/water/wave-crash.js
new file mode 100644
index 0000000..621c7f0
--- /dev/null
+++ b/src/fx/water/wave-crash.js
@@ -0,0 +1,101 @@
+import { PAL, burst, seg, ease, clamp, noise2, WHITE } from "../../core/index.js";
+import { fit, drop, landTime, ripple } from "./_lib.js";
+
+export const meta = {
+ name: "Wave crash",
+ desc: "A wave swells and rolls right, its lip curls over into a tube and slams down: a white flash, a plume of spray and foam that boils away.",
+ tags: ["water", "wave", "surf", "crash", "foam", "directional", "one-shot"],
+ size: [100, 80],
+ origin: [30, 72],
+ duration: 1.6,
+ loop: false,
+ fps: 30,
+ bg: "ground",
+ options: { palette: PAL.water, height: 38, seed: 13 },
+};
+
+const HIT = 0.66, G = 300;
+
+// the wave at time t: crest x, height, how far the lip has thrown (0..1); and the lip's arc
+function wave(t, H) {
+ const xc = -12 + 26 * ease.inOutSine(seg(t, 0, HIT)) + 6 * ease.outCubic(seg(t, HIT, 1.1));
+ const h = H * (0.22 + 0.78 * ease.outCubic(seg(t, 0, 0.42))) * (1 - ease.inOutSine(seg(t, HIT, 1.05)));
+ const lip = ease.inOutSine(seg(t, 0.2, HIT));
+ const R = h * 0.46, cx = xc + h * 0.12, cy = -h + R, a0 = -Math.PI / 2 - 0.35, a1 = a0 + 0.3 + lip * 3.1;
+ return { xc, h, lip, R, cx, cy, a0, a1 };
+}
+
+export function draw(p, t, o) {
+ const W = fit(o.palette), S = o.seed, H = o.height, w = wave(t, H), { xc, h, lip } = w;
+ const wh = wave(HIT, H), hitX = wh.cx + Math.cos(wh.a1) * wh.R, after = t >= HIT;
+ // the body: a long back slope and a steep face, foam riding the crest, streaks slanting up the back
+ if (h > 1) {
+ const surf = (x) => -h * Math.exp(-(((x - xc) / (x < xc ? h * 0.7 + 4 : 4 + h * 0.18)) ** 2));
+ p.shade(-30, -h - 2, xc + h * 0.6 + 4, 1, (x, y) => {
+ const sy = surf(x);
+ if (y < sy || y > 0) return;
+ const dep = y - sy, back = x < xc;
+ if (sy < -h * 0.6 && dep < 2 + 2 * clamp(1 - Math.abs(x - xc) / 8)) return noise2(x * 0.5 + t * 8, y * 0.5, S) > -0.35 ? W[7] : W[6];
+ if (dep < 1.2) return back ? W[6] : W[5];
+ if (!back) return dep > h * 0.45 ? W[2] : (x - xc) * 3 + dep < 6 ? W[4] : W[3];
+ const streak = noise2((x * 0.9 - y * 1.4) * 0.16 - t * 2.5, (x + y) * 0.05, S + 1);
+ return streak > 0.5 ? W[6] : dep < 5 ? W[5] : dep < h * 0.42 ? W[4] : W[3];
+ });
+ // the lip: thick at the crest, thrown forward and curling down, white outside, dark on the underside
+ if (!after && lip > 0) {
+ const { R, cx, cy, a0, a1 } = w;
+ p.arc(cx, cy, R + 1.5, (u) => Math.max(1.5, R * 0.75 * (1 - u * 0.8)), a0, a1,
+ (u, v) => (v > 0.7 ? (noise2(u * 10 + t * 5, v * 2, S + 2) > -0.25 ? W[7] : W[6]) : v > 0.4 ? W[5] : v > 0.18 ? W[4] : W[3]));
+ // spray streaming off the tip
+ const tx = cx + Math.cos(a1) * (R + 0.5), ty = cy + Math.sin(a1) * (R + 0.5);
+ burst(6, S + 4, (r, i) => {
+ const k = (t * 7 + i / 6) % 1;
+ p.px(tx + r.range(-1, 3) + k * r.range(3, 7), ty - r.range(0, 2) + k * r.range(-4, 2), k < 0.5 ? W[7] : W[6]);
+ });
+ }
+ }
+ if (!after) return;
+ const a = t - HIT;
+ // foam: the lip and the tube under it burst into a heap of foam that boils forward and wears away,
+ // and a plume of it is thrown up where the lip hit
+ burst(18, S + 5, (r, i) => {
+ const plume = i >= 12, life = plume ? r.range(0.55, 0.8) : r.range(0.6, 0.9), k = a / life;
+ if (k >= 1) return;
+ let x0, y0, up, fwd;
+ if (plume) (x0 = hitX + r.range(-3, 3)), (y0 = -3), (up = r.range(45, 95)), (fwd = r.range(-5, 30));
+ else {
+ const u = r.range(0.15, 1), ang = wh.a0 + (wh.a1 - wh.a0) * u;
+ x0 = lerpN(wh.cx + Math.cos(ang) * wh.R, hitX - r.range(0, 10), r.range(0, 0.6));
+ y0 = Math.min(-3, wh.cy + Math.sin(ang) * wh.R * r.range(0.5, 1));
+ up = r.range(5, 25), fwd = r.range(10, 40);
+ }
+ const e = (1 - Math.exp(-3.2 * a)) / 3.2, x = x0 + fwd * e, y = Math.min(-2, y0 - up * e + a * a * (plume ? 40 : 30));
+ const rad = (plume ? 4 : 5.5) * r.range(0.8, 1.2) * (0.55 + 0.6 * ease.outCubic(seg(a, 0, 0.2))) * (1 - 0.3 * k), wear = seg(k, 0.25, 1);
+ p.shade(x - rad, y - rad, x + rad, y + rad, (px, py) => {
+ const dx = px - x, dy = py - y, d = (dx * dx + dy * dy) / (rad * rad);
+ if (d > 1 - wear * 0.95 + noise2(dx * 0.6 + i * 9, dy * 0.6, S + 6) * 0.4 * wear) return;
+ return dx + dy * 1.2 > rad * 0.45 ? W[5] : dx + dy > -rad * 0.25 ? W[6] : W[7];
+ });
+ });
+ // spray droplets flung up and forward, ringing the water where they land
+ burst(24, S + 6, (r, i) => {
+ const ang = -Math.PI / 2 + r.range(-0.6, 1.0), sp = r.range(60, 110), vx = Math.cos(ang) * sp, vy = Math.sin(ang) * sp;
+ const x0 = hitX + r.range(-5, 5), tl = landTime(-4, vy, G, 0);
+ if (a > tl) {
+ const u = (a - tl) / 0.2;
+ if (u < 1) ripple(p, x0 + vx * tl, 0.5, 1 + u * 3, 0.8, W[5], W[4], 1.4 * (1 - u), i);
+ return;
+ }
+ drop(p, x0 + vx * a, -4 + vy * a + 0.5 * G * a * a, vx, vy + G * a, i % 3 ? W[6] : W[7], W[5], 0.025);
+ });
+ // the hit: the lip slams down white, a spout of white shoots up, light that lets go fast
+ if (a < 0.07) {
+ p.arc(wh.cx, wh.cy, wh.R + 2, (u) => Math.max(2, wh.R * 0.8 * (1 - u * 0.7)), wh.a0, wh.a1, WHITE);
+ p.ellipse(hitX, -3, 11, 4, WHITE);
+ p.beam(hitX, -3, hitX + 2, -wh.h * 0.8, 6, WHITE);
+ p.glow(hitX - 4, -10, 32, W[6], 0.5);
+ }
+ p.glow(hitX, -10, 26, W[5], 0.22 * (1 - seg(a, 0, 0.5)));
+}
+
+const lerpN = (a, b, k) => a + (b - a) * k;
diff --git a/src/fx/water/whirlpool.js b/src/fx/water/whirlpool.js
new file mode 100644
index 0000000..f5d97e5
--- /dev/null
+++ b/src/fx/water/whirlpool.js
@@ -0,0 +1,47 @@
+import { PAL, cycle, tileNoise, fract, ease, clamp, TAU } from "../../core/index.js";
+import { fit } from "./_lib.js";
+
+export const meta = {
+ name: "Whirlpool",
+ desc: "A top-down vortex: foam streaks spiral into a dark eye, a churning white rim, flecks of foam sucked in faster and faster.",
+ tags: ["water", "whirlpool", "vortex", "maelstrom", "top-down", "loop"],
+ size: [64, 64],
+ origin: [32, 32],
+ duration: 2,
+ loop: true,
+ fps: 30,
+ bg: "dark",
+ options: { palette: PAL.water, radius: 27, arms: 4, seed: 11 },
+};
+
+export function draw(p, t, o) {
+ const W = fit(o.palette), S = o.seed, ph = t / meta.duration, R = o.radius, N = o.arms;
+ p.shade(-R - 3, -R - 3, R + 3, R + 3, (x, y) => {
+ const r = Math.hypot(x, y), d = r / R, a = Math.atan2(y, x);
+ // the rim: a band of churning foam, ragged on the outside
+ const u = (a / TAU) * 24 - ph * 24, rim = 0.93 + 0.07 * tileNoise(u, ph * 3, 24, 3, S);
+ if (d > rim + 0.06) return;
+ if (d > rim - 0.06) return tileNoise(u * 1.5, d * 6, 36, 0, S + 1) > -0.1 ? W[7] : W[6];
+ // the arms: log spirals turning a full circle a loop, frayed and broken in places, gone near the eye
+ const s = fract((a / TAU) * N - Math.log(d + 0.02) * 1.15 - ph * N);
+ const n = tileNoise((a / TAU) * 16 - ph * 16, Math.log(d + 0.02) * 3, 16, 0, S + 2);
+ if (d < 0.11) return W[0];
+ if (d < 0.17) return W[1];
+ const arm = (0.05 + 0.11 * d) * (0.7 + 0.5 * n) * clamp((d - 0.17) / 0.12);
+ if (s < arm && n > -0.45) return d > 0.55 ? W[7] : d > 0.32 ? W[6] : W[5];
+ // the body: darker the deeper it goes, the bands bent by the swirl
+ const dd = d + 0.06 * Math.sin(s * TAU) + 0.04 * n;
+ return dd < 0.27 ? W[1] : dd < 0.47 ? W[2] : dd < 0.72 ? W[3] : W[4];
+ });
+ // flecks of foam sucked in, turning faster as they near the eye
+ cycle(t, meta.duration, 14, S, (r) => r.range(1.1, 1.8), (age, life, r) => {
+ const k = age / life, a0 = r.range(0, TAU), rr = R * 0.9 * Math.pow(1 - k, 1.3);
+ const a = a0 + 1.6 * k + 4.5 * ease.inQuad(k);
+ if (rr < R * 0.12) return;
+ const x = Math.cos(a) * rr, y = Math.sin(a) * rr;
+ p.px(x, y, k < 0.6 ? W[7] : W[6]);
+ if (k < 0.5) p.px(x - Math.sin(a), y + Math.cos(a), W[6]);
+ });
+ p.glow(0, 0, R * 1.2, W[4], 0.12);
+ p.glowRing(0, 0, R * 0.95, 5, W[6], 0.12);
+}
diff --git a/src/fx/weather/_lib.js b/src/fx/weather/_lib.js
new file mode 100644
index 0000000..fb81bc5
--- /dev/null
+++ b/src/fx/weather/_lib.js
@@ -0,0 +1,38 @@
+// Helpers shared by the weather loops. Weather fills its whole canvas edge to edge, so things enter and
+// leave across the borders: clip() keeps every pixel (and every bit of light) inside the canvas, and
+// drift() moves particles across it a whole number of times a loop, so the loop has no seam.
+
+import { rng, fract } from "../../core/index.js";
+
+/** The canvas in local coordinates: { x0, y0, x1, y1 } (inclusive pixel bounds), w, h. */
+export function box(meta) {
+ const [W, H] = meta.size, [OX, OY] = meta.origin;
+ return { x0: -OX, y0: -OY, x1: W - OX - 1, y1: H - OY - 1, w: W, h: H };
+}
+
+/**
+ * A painter that draws only inside the effect's canvas: the same API, with color and light outside the
+ * canvas dropped. Works under the painter's flip and rotation (the test is done in local space).
+ */
+export function clip(p, meta) {
+ const B = box(meta), q = Object.create(p);
+ const ok = (sx, sy) => {
+ const lx = p.fromX(sx + 0.5, sy + 0.5), ly = p.fromY(sx + 0.5, sy + 0.5);
+ return lx >= B.x0 && lx < B.x1 + 1 && ly >= B.y0 && ly < B.y1 + 1;
+ };
+ q.put = (sx, sy, c, a) => ok(sx, sy) && p.put(sx, sy, c, a);
+ q.add = (sx, sy, c, k) => ok(sx, sy) && p.add(sx, sy, c, k);
+ return q;
+}
+
+/**
+ * n particles that each make `trips` crossings per loop (a number, or [min, max] whole numbers per particle),
+ * each starting at its own phase. fn(u, r, i) gets u, 0..1 along the current crossing, and the particle's
+ * rng (the same numbers every frame). Make u = 0 and u = 1 fall outside the canvas and the loop is seamless.
+ */
+export function drift(t, D, n, seed, trips, fn) {
+ for (let i = 0; i < n; i++) {
+ const r = rng(seed, i), k = Array.isArray(trips) ? r.int(trips[0], trips[1]) : trips;
+ fn(fract(r.next() + (k * t) / D), r, i);
+ }
+}
diff --git a/src/fx/weather/aurora.js b/src/fx/weather/aurora.js
new file mode 100644
index 0000000..aa56093
--- /dev/null
+++ b/src/fx/weather/aurora.js
@@ -0,0 +1,61 @@
+import { ramp, at, clamp, tileNoise, smooth, TAU, hex } from "../../core/index.js";
+import { box, clip } from "./_lib.js";
+
+export const meta = {
+ name: "Aurora",
+ desc: "Northern lights over a night sky: two curtains ripple and fold, bright green hems fading up into violet, rays shimmering along them.",
+ tags: ["weather", "aurora", "night", "sky", "lights", "glow", "ambient", "loop"],
+ size: [128, 72],
+ origin: [64, 36],
+ duration: 8,
+ loop: true,
+ fps: 30,
+ bg: "sky",
+ options: {
+ palette: ["#0a2a2a", "#0e4a3c", "#1a7a50", "#2eb064", "#6ae08a", "#c4ffcc", "#f4fff4"],
+ top: ["#2a1450", "#5a2a8a", "#9a4ab8"],
+ seed: 109,
+ },
+};
+
+// two curtains: base height, fold sizes and speeds (whole turns a loop), ray height, brightness
+const CURTAINS = [
+ { y: -10, a1: 6, a2: 2.5, f1: 0.045, f2: 0.11, m1: 1, m2: 2, h: 18, k: 0.7, s: 0 },
+ { y: 8, a1: 5, a2: 2.5, f1: 0.055, f2: 0.13, m1: -1, m2: 3, h: 24, k: 1, s: 1 },
+];
+
+export function draw(p, t, o) {
+ p = clip(p, meta);
+ const C = ramp(o.palette), TOP = ramp(o.top), S = o.seed, B = box(meta), ph = t / meta.duration;
+ for (const cu of CURTAINS) {
+ // everything but the height above the hem depends only on the column: work it out once per column
+ const cols = [];
+ for (let cx = B.x0; cx <= B.x1; cx++) {
+ const x = cx + 0.5, u = (x - B.x0) / B.w;
+ // the hem: slow folds travelling along the curtain
+ const hem = cu.y + Math.sin(x * cu.f1 + ph * TAU * cu.m1 + cu.s * 2) * cu.a1 + Math.sin(x * cu.f2 - ph * TAU * cu.m2 + cu.s) * cu.a2;
+ // rays: fine vertical striations sliding along the curtain, and broader swells of brightness
+ const fine = tileNoise(u * 48 + ph * 48 * (cu.s ? -1 : 1), ph * 2, 48, 2, S + cu.s);
+ const broad = tileNoise(u * 6 - ph * 6, 0.5 + cu.s * 3, 6, 0, S + 7 + cu.s);
+ const env = smooth(0, 0.15, u) * smooth(1, 0.85, u) * 0.35 + 0.65; // dimmer toward the frame edges
+ cols.push({ hem, fine, tall: cu.h * (0.75 + 0.35 * broad), k: (0.62 + 0.38 * fine) * (0.8 + 0.2 * broad) * env * cu.k });
+ }
+ const reach = cu.a1 + cu.a2;
+ p.shade(B.x0, Math.max(B.y0, cu.y - reach - cu.h * 1.5), B.x1, Math.min(B.y1, cu.y + reach + 1), (x, y, out) => {
+ const c = cols[Math.floor(x) - B.x0];
+ if (!c) return;
+ const d = c.hem - y; // height above the hem
+ if (d < -1 || d > c.tall * 1.5) return;
+ const v = clamp(d / c.tall), I = (d < 0 ? 0.7 : Math.exp(-v * 2.4)) * c.k;
+ if (I < 0.07) return;
+ // the glow fades from green up into violet; only the bright part is drawn as pixels
+ out.l = v > 0.5 ? TOP[2] : C[3];
+ out.k = I > 0.25 ? 0.24 + I * 0.2 : I * 1.1;
+ if (I > 0.62 && d < 2.5) return d < 1 ? C[6] : C[5];
+ if (I > 0.46) return c.fine > 0.25 ? C[4] : C[3];
+ if (I > 0.26 && c.fine > 0.4) return v > 0.5 ? TOP[1] : C[2];
+ });
+ }
+ // a faint glow off the lights over the whole sky
+ p.glow(-10, -4, 70, C[3], 0.08);
+}
diff --git a/src/fx/weather/blizzard.js b/src/fx/weather/blizzard.js
new file mode 100644
index 0000000..d408bca
--- /dev/null
+++ b/src/fx/weather/blizzard.js
@@ -0,0 +1,47 @@
+import { ramp, at, lerp, clamp, fract, rng, tileFbm, TAU } from "../../core/index.js";
+import { box, clip } from "./_lib.js";
+
+export const meta = {
+ name: "Blizzard",
+ desc: "A whiteout: snow driven almost flat across the frame in gusts, streaks of near flakes, and pale sheets of blown snow tearing past.",
+ tags: ["weather", "snow", "blizzard", "wind", "winter", "cold", "ambient", "loop"],
+ size: [128, 72],
+ origin: [64, 36],
+ duration: 2,
+ loop: true,
+ fps: 30,
+ bg: "dark",
+ options: { palette: ["#2a3448", "#4a5a76", "#7e92b0", "#bccce0", "#f0f6fc"], count: 140, seed: 83 },
+};
+
+export function draw(p, t, o) {
+ p = clip(p, meta);
+ const C = ramp(o.palette), S = o.seed, D = meta.duration, B = box(meta), ph = t / D;
+ // gusts: the whole field surges and eases twice a loop
+ const gust = (k) => Math.sin(ph * TAU * 2 + k) * 0.03 + Math.sin(ph * TAU * 3 + k * 2) * 0.015;
+ // sheets of blown snow: stretched noise, tiling the frame's width, scrolled a whole width per pass
+ p.shade(B.x0, B.y0, B.x1 + 1, B.y1 + 1, (x, y, out) => {
+ const u = (x - B.x0) / B.w, v = (y - B.y0) / B.h;
+ const n = tileFbm(u * 4 - ph * 8, v * 14 + Math.sin(u * TAU + ph * TAU) * 0.8, 4, 0, S, 2);
+ // banded haze in the light buffer: flat steps, no dither, never quite clear
+ out.l = C[3];
+ out.k = n > 0.3 ? 0.32 : n > 0.12 ? 0.21 : n > -0.08 ? 0.12 : 0.05;
+ });
+ // flakes: three depths, driven right and a little down; near ones smear into streaks
+ const layers = [
+ { n: 0.45, laps: [2, 3], len: 0, c: 2, dy: 0.18 },
+ { n: 0.35, laps: [3, 4], len: 2, c: 3, dy: 0.22 },
+ { n: 0.2, laps: [4, 6], len: 6, c: 4, dy: 0.28 },
+ ];
+ layers.forEach((L, li) => {
+ const N = Math.round(o.count * L.n);
+ for (let i = 0; i < N; i++) {
+ const r = rng(S + li * 17, i), k = r.int(L.laps[0], L.laps[1]), off = r.next();
+ const u = fract(off + (k * t) / D + gust(off * 6)), span = B.w + 30;
+ const x = B.x0 - 15 + u * span, y = r.range(B.y0 - 10, B.y1) + u * span * L.dy + Math.sin(u * TAU * 2 + i) * 2;
+ const yy = B.y0 + ((y - B.y0) % (B.h + 4) + (B.h + 4)) % (B.h + 4);
+ if (L.len) p.line(x, yy, x - L.len, yy - L.len * L.dy, (q) => (q < 0.4 ? C[L.c] : C[L.c - 1]));
+ else p.px(x, yy, C[L.c]);
+ }
+ });
+}
diff --git a/src/fx/weather/cherry-blossoms.js b/src/fx/weather/cherry-blossoms.js
new file mode 100644
index 0000000..9aa8ee9
--- /dev/null
+++ b/src/fx/weather/cherry-blossoms.js
@@ -0,0 +1,35 @@
+import { ramp, lerp, TAU } from "../../core/index.js";
+import { box, clip, drift } from "./_lib.js";
+
+export const meta = {
+ name: "Cherry blossoms",
+ desc: "Pink petals ride a soft breeze down and across, fluttering and flipping, now and then one catching the light.",
+ tags: ["weather", "spring", "petals", "blossom", "sakura", "wind", "ambient", "loop"],
+ size: [96, 64],
+ origin: [48, 32],
+ duration: 4,
+ loop: true,
+ fps: 30,
+ bg: "sky",
+ options: { palette: ["#5a2448", "#a4446e", "#dc78a2", "#f6b2cc", "#fff0f6"], count: 34, seed: 101 },
+};
+
+// a petal fluttering: face on, turning, edge on, turning back
+const FLUTTER = [["ab", "bc"], [".a", "bc"], ["ab"], ["a.", "bc"]];
+const BIG = [[".ab", "abc", "bc."], ["ab.", "bbc"], [".a.", "abc"], ["ab.", ".bc"]];
+
+export function draw(p, t, o) {
+ p = clip(p, meta);
+ const C = ramp(o.palette), S = o.seed, D = meta.duration, B = box(meta);
+ drift(t, D, o.count, S, [1, 2], (u, r, i) => {
+ // each petal crosses from the upper left to the lower right on the breeze, bobbing as it goes
+ const near = i % 4 === 0, dx = r.range(50, 80) * (near ? 1.3 : 1);
+ const x0 = r.range(B.x0 - 40, B.x1 - 30), y = lerp(B.y0 - 4 - r.range(0, 20), B.y1 + 4, u);
+ const bob = Math.sin(u * TAU * r.range(2, 4) + r.next() * TAU);
+ const x = x0 + u * dx + bob * 3;
+ const frame = Math.floor(u * r.range(30, 50) + i) % 4, glint = Math.sin(u * TAU * 3 + i * 2) > 0.94;
+ const pal = near ? { a: C[4], b: C[3], c: C[2] } : r.chance(0.5) ? { a: C[3], b: C[2], c: C[1] } : { a: C[4], b: C[3], c: C[1] };
+ p.sprite((near ? BIG : FLUTTER)[frame], glint ? { a: C[4], b: C[4], c: C[3] } : pal, x, y + bob * 1.5);
+ if (glint) p.light(x + 1, y, C[3], 0.4);
+ });
+}
diff --git a/src/fx/weather/clouds.js b/src/fx/weather/clouds.js
new file mode 100644
index 0000000..556ca23
--- /dev/null
+++ b/src/fx/weather/clouds.js
@@ -0,0 +1,57 @@
+import { ramp, at, rng, wrap } from "../../core/index.js";
+import { box, clip } from "./_lib.js";
+
+export const meta = {
+ name: "Clouds",
+ desc: "Moonlit clouds drift across a night sky in three layers: small dim ones far off, big billowing ones close by, each with a bright crown and a flat dark belly.",
+ tags: ["weather", "clouds", "sky", "night", "parallax", "ambient", "loop"],
+ size: [128, 72],
+ origin: [64, 36],
+ duration: 12,
+ loop: true,
+ fps: 15,
+ bg: "sky",
+ options: { palette: ["#141626", "#20243a", "#2e3450", "#424a6c", "#5c668a", "#808cae", "#b2bcd6", "#e4eaf6"], seed: 149 },
+};
+
+// layers back to front: how many clouds, their size, their height, how many widths they drift a loop, tone
+const LAYERS = [
+ { n: 4, size: 0.55, y: [-28, -14], laps: 1, lo: 0, hi: 4 },
+ { n: 3, size: 0.85, y: [-16, 2], laps: 2, lo: 1, hi: 5 },
+ { n: 2, size: 1.25, y: [0, 22], laps: 3, lo: 2, hi: 7 },
+];
+
+export function draw(p, t, o) {
+ p = clip(p, meta);
+ const C = ramp(o.palette), S = o.seed, B = box(meta), ph = t / meta.duration, W = B.w;
+ LAYERS.forEach((L, li) => {
+ // each cloud: a few puffs on a flat base, placed around a strip one frame wide that wraps
+ const clouds = [];
+ for (let i = 0; i < L.n; i++) {
+ const r = rng(S + li * 13, i), cx = ((i + r.range(0.1, 0.9)) / L.n) * W, cy = r.range(L.y[0], L.y[1]);
+ const puffs = [], n = r.int(3, 5), w = r.range(14, 22) * L.size;
+ for (let k = 0; k < n; k++) {
+ const u = n === 1 ? 0 : k / (n - 1) - 0.5;
+ puffs.push({ dx: u * w * 1.5 + r.range(-2, 2), dy: -(1 - Math.abs(u) * 1.4) * w * 0.35 - r.range(0, 3) * L.size, r: r.range(0.45, 0.65) * w * (1 - Math.abs(u) * 0.5) });
+ }
+ clouds.push({ cx, cy, puffs, base: cy + w * 0.12 });
+ }
+ const shift = ph * L.laps * W;
+ const top = Math.min(...clouds.map((c) => c.cy)) - 30 * L.size, bottom = Math.max(...clouds.map((c) => c.base)) + 1;
+ p.shade(B.x0, Math.max(B.y0, top), B.x1 + 1, Math.min(B.y1 + 1, bottom), (x, y) => {
+ let best = 0, lit = 0, flat = 0;
+ for (const c of clouds) {
+ if (y > c.base) continue; // the flat belly
+ const dx0 = wrap(x - B.x0 - c.cx - shift + W / 2, W) - W / 2;
+ for (const f of c.puffs) {
+ const dx = dx0 - f.dx, dy = y - c.cy - f.dy, v = 1 - (dx * dx + dy * dy) / (f.r * f.r);
+ if (v > best) (best = v), (lit = (-dx * 0.4 - dy) / f.r), (flat = c.base - y);
+ }
+ }
+ if (best <= 0) return;
+ // moonlight from above: bright crowns, shaded creases, a dark band along the belly
+ if (flat < 1.5) return C[L.lo + 1];
+ return at(C.slice(L.lo, L.hi + 1), 0.35 + lit * 0.42 + best * 0.12 - (flat < 3.5 ? 0.25 : 0));
+ });
+ });
+}
diff --git a/src/fx/weather/falling-leaves.js b/src/fx/weather/falling-leaves.js
new file mode 100644
index 0000000..f49deb3
--- /dev/null
+++ b/src/fx/weather/falling-leaves.js
@@ -0,0 +1,50 @@
+import { ramp, lerp, TAU } from "../../core/index.js";
+import { box, clip, drift } from "./_lib.js";
+
+export const meta = {
+ name: "Falling leaves",
+ desc: "Autumn leaves see-saw down through the air, flipping as they swing, settle on the floor for a moment and fade.",
+ tags: ["weather", "autumn", "fall", "leaves", "wind", "ambient", "loop"],
+ size: [96, 64],
+ origin: [48, 58],
+ duration: 6,
+ loop: true,
+ fps: 30,
+ bg: "ground",
+ options: { palette: ["#2a120c", "#5a1c12", "#962c16", "#cc4a1c", "#e8782a", "#f4a83c", "#fad466"], count: 18, seed: 97 },
+};
+
+// a leaf turning over as it swings: face on, three-quarter, edge on, three-quarter from the back; c is the stem side
+const TUMBLE = [
+ ["..ab..", ".abbb.", "abbbbc", ".bbcc.", "..cc..", "...c.."],
+ [".ab..", "abbb.", ".bbc.", "..cc.", "...c."],
+ [".a", "ab", "bb", "bc", ".c"],
+ ["..ba.", ".bbba", ".cbb.", ".cc..", ".c..."],
+];
+// far leaves: small and dim
+const SMALL = [["ab.", "bbc", ".c."], ["a.", "bc"], ["a", "b", "c"], [".a", "cb"]];
+const FLAT = [".aabb.", "abbbcc"];
+
+export function draw(p, t, o) {
+ p = clip(p, meta);
+ const C = ramp(o.palette), S = o.seed, D = meta.duration, B = box(meta);
+ drift(t, D, o.count, S, [1, 2], (u, r, i) => {
+ const land = r.range(0.6, 0.72); // falling for this share of the trip, then lying on the floor
+ const x0 = r.range(B.x0 + 4, B.x1 - 8), swing = r.range(5, 10), swings = r.int(3, 5), ph0 = r.next() * TAU;
+ const tone = r.int(0, 2), pal = { a: C[4 + tone], b: C[3 + tone], c: C[1 + tone] }, far = i % 3 === 2;
+ if (far && u >= land) return; // far leaves drift down behind the floor line
+ const fy = -r.int(0, 2);
+ if (u < land) {
+ const k = u / land, a = k * TAU * swings * 0.5 + ph0, y = lerp(B.y0 - 6, fy - 1, k);
+ // a pendulum swing: fastest through the bottom, hanging at the ends; the drop slows at the ends too
+ const x = x0 + Math.sin(a) * swing + k * 8, sv = Math.cos(a);
+ const frame = sv > 0.55 ? 0 : sv < -0.55 ? 2 : Math.sin(a) > 0 ? 1 : 3;
+ if (far) p.sprite(SMALL[frame], { a: C[2 + tone], b: C[1 + tone], c: C[0 + tone] }, x - 1, y - 1);
+ else p.sprite(TUMBLE[frame], pal, x - 3, y - 3);
+ return;
+ }
+ // on the floor: lie flat, then fade away
+ const k = (u - land) / (1 - land), x = x0 + Math.sin(TAU * swings * 0.5 + ph0) * swing + 8;
+ p.sprite(FLAT, pal, x - 3, fy - 1, { a: k < 0.6 ? 1 : 1 - (k - 0.6) / 0.4 });
+ });
+}
diff --git a/src/fx/weather/fireflies.js b/src/fx/weather/fireflies.js
new file mode 100644
index 0000000..1d0b555
--- /dev/null
+++ b/src/fx/weather/fireflies.js
@@ -0,0 +1,41 @@
+import { ramp, rng, clamp, TAU } from "../../core/index.js";
+import { box, clip } from "./_lib.js";
+
+export const meta = {
+ name: "Fireflies",
+ desc: "Fireflies wander low over the ground at night, each on its own lazy loop, glowing up and fading out at their own slow rhythms.",
+ tags: ["weather", "night", "fireflies", "bugs", "glow", "ambient", "loop"],
+ size: [96, 64],
+ origin: [48, 58],
+ duration: 6,
+ loop: true,
+ fps: 30,
+ bg: "ground",
+ options: { palette: ["#1e2a10", "#4a6a18", "#a0c838", "#e8f878", "#ffffe0"], count: 12, seed: 103 },
+};
+
+export function draw(p, t, o) {
+ p = clip(p, meta);
+ const C = ramp(o.palette), S = o.seed, B = box(meta), ph = t / meta.duration;
+ for (let i = 0; i < o.count; i++) {
+ const r = rng(S, i);
+ // a wandering path: two slow sines a whole number of turns a loop on each axis, so it closes on itself
+ const cx = r.range(B.x0 + 10, B.x1 - 10), cy = r.range(-40, -8);
+ const x = cx + Math.sin(ph * TAU * r.int(1, 2) + r.next() * TAU) * r.range(6, 14) + Math.sin(ph * TAU * r.int(3, 4) + r.next() * TAU) * 3;
+ const y = cy + Math.sin(ph * TAU * r.int(1, 3) + r.next() * TAU) * r.range(4, 8) + Math.sin(ph * TAU * r.int(4, 6) + r.next() * TAU) * 1.5;
+ // glow: a few slow pulses a loop, eased on and off
+ const blinks = r.int(2, 4), off = r.next();
+ const s = Math.sin((ph * blinks + off) * TAU), b = clamp((s - 0.1) / 0.9);
+ const glow = b * b * (3 - 2 * b);
+ if (glow < 0.05) {
+ p.px(x, y, C[1]); // the bug in the dark
+ continue;
+ }
+ p.px(x, y, glow > 0.6 ? C[4] : glow > 0.25 ? C[3] : C[2]);
+ if (glow > 0.7) {
+ p.px(x - 1, y, C[2]), p.px(x + 1, y, C[2]), p.px(x, y - 1, C[2]), p.px(x, y + 1, C[2]);
+ }
+ p.glow(x, y, 9, C[3], 0.45 * glow);
+ p.glow(x, y, 3, C[4], 0.4 * glow);
+ }
+}
diff --git a/src/fx/weather/fog.js b/src/fx/weather/fog.js
new file mode 100644
index 0000000..673e67b
--- /dev/null
+++ b/src/fx/weather/fog.js
@@ -0,0 +1,52 @@
+import { ramp, clamp, tileFbm, TAU } from "../../core/index.js";
+import { box, clip } from "./_lib.js";
+
+export const meta = {
+ name: "Fog",
+ desc: "Banks of fog roll slowly across in three layers, the far ones slower and darker, a thick pale mist hugging the floor.",
+ tags: ["weather", "fog", "mist", "haze", "ambient", "loop"],
+ size: [128, 72],
+ origin: [64, 64],
+ duration: 12,
+ loop: true,
+ fps: 15,
+ bg: "ground",
+ options: { palette: ["#2a3040", "#465064", "#6c7890", "#9ca8bc", "#d0d8e4"], seed: 89 },
+};
+
+// fog is translucent, so it lives in the light buffer, thickening in flat posterized steps (never a smear,
+// never a dither pattern); each bank's thickest core takes a paler step
+const level = (d) => (d > 0.62 ? 3 : d > 0.38 ? 2 : d > 0.16 ? 1 : 0);
+const HAZE = [0, 0.08, 0.15, 0.23];
+
+export function draw(p, t, o) {
+ p = clip(p, meta);
+ const C = ramp(o.palette), S = o.seed, B = box(meta), ph = t / meta.duration;
+ // [center height, half thickness, laps a loop, color step, seed]: back to front
+ const banks = [
+ [-34, 13, 1, 1, 0],
+ [-18, 11, 2, 2, 1],
+ [-3, 8, 3, 3, 2],
+ ];
+ for (const [cy, hw, laps, ci, k] of banks) {
+ // the band's wave depends only on the column: once per column
+ const wave = [];
+ for (let cx = B.x0; cx <= B.x1; cx++) wave.push(Math.sin(((cx + 0.5 - B.x0) / B.w) * TAU * 2 - ph * TAU * laps + k) * 3);
+ const reach = hw * 1.3 + 3;
+ p.shade(B.x0, Math.max(B.y0, cy - reach), B.x1, Math.min(B.y1, cy + reach), (x, y, out) => {
+ const u = (x - B.x0) / B.w, edge = 1 - Math.abs(y - cy - wave[Math.floor(x) - B.x0]) / hw;
+ if (edge < -0.25) return;
+ // a wavy band; its edges tear into wisps that scroll by a whole width a lap
+ const n = tileFbm(u * 5 - ph * 5 * laps, (y - cy) * 0.09 + k * 7.3, 5, 0, S + k, 2);
+ const lv = level(edge * 0.75 + n * 0.55);
+ if (!lv) return;
+ out.l = C[ci + (lv === 3 ? 1 : 0)];
+ out.k = HAZE[lv] * (0.85 + ci * 0.15);
+ // in the thick of it, streaks of mist drawn as long horizontal dashes that ride along with the bank
+ if (lv === 3 && Math.round(y - cy) % 4 === 0) {
+ const dash = tileFbm(u * 20 - ph * 20 * laps, y * 0.5 + k * 3.1, 20, 0, S + 9 + k, 1);
+ if (dash > 0.12) return C[ci + 1];
+ }
+ });
+ }
+}
diff --git a/src/fx/weather/god-rays.js b/src/fx/weather/god-rays.js
new file mode 100644
index 0000000..25eed44
--- /dev/null
+++ b/src/fx/weather/god-rays.js
@@ -0,0 +1,64 @@
+import { ramp, rng, clamp, TAU } from "../../core/index.js";
+import { box, clip } from "./_lib.js";
+
+export const meta = {
+ name: "God rays",
+ desc: "Shafts of light slant down from a high window into the dark, slowly breathing and swaying; dust motes drift through and flare as they cross the beams.",
+ tags: ["weather", "light", "god rays", "sunbeam", "dust", "interior", "ambient", "loop"],
+ size: [96, 72],
+ origin: [48, 36],
+ duration: 6,
+ loop: true,
+ fps: 30,
+ bg: "dark",
+ options: { palette: ["#3a2a14", "#7a5a28", "#c8a050", "#f4dc96", "#fff8e0"], count: 40, seed: 131 },
+};
+
+// shafts: [offset across, width, strength, breathing phase]
+const SHAFTS = [
+ [-30, 7, 0.8, 0],
+ [-14, 12, 1, 1.7],
+ [6, 5, 0.6, 3.1],
+ [20, 9, 0.85, 4.4],
+];
+
+export function draw(p, t, o) {
+ p = clip(p, meta);
+ const C = ramp(o.palette), S = o.seed, B = box(meta), ph = t / meta.duration;
+ // the beams come in from the top left at a steep slant, swaying a touch
+ const ang = 1.05 + Math.sin(ph * TAU) * 0.03, nx = Math.sin(ang), ny = -Math.cos(ang);
+ const across = (x, y) => x * nx + y * ny; // distance across the beams
+ const along = (x, y) => (x - B.x0) * Math.cos(ang) + (y - B.y0) * Math.sin(ang); // distance down them
+ const beam = (x, y) => {
+ let best = 0;
+ const spread = 0.75 + along(x, y) / 110; // the beams widen as they fall
+ for (const [off, w, k, bp] of SHAFTS) {
+ const d = Math.abs(across(x, y) - off * spread) / ((w * spread) / 2);
+ if (d >= 1) continue;
+ const breathe = 0.75 + 0.25 * Math.sin(ph * TAU * 2 + bp);
+ const v = (d < 0.55 ? 1 : 0.55) * k * breathe;
+ if (v > best) best = v;
+ }
+ // stronger near the window, fading as the light falls
+ return best * clamp(1.25 - along(x, y) / 95);
+ };
+ p.shade(B.x0, B.y0, B.x1 + 1, B.y1 + 1, (x, y, out) => {
+ const b = beam(x, y);
+ if (b < 0.05) return;
+ out.l = b > 0.5 ? C[3] : C[2];
+ out.k = b > 0.75 ? 0.36 : b > 0.5 ? 0.27 : b > 0.28 ? 0.17 : 0.09;
+ });
+ // where it pours in: a warm bloom at the top left
+ p.glow(B.x0 + 6, B.y0, 40, C[3], 0.3 * (0.85 + 0.15 * Math.sin(ph * TAU * 2)));
+ // dust motes: drifting on slow closed loops, bright only while inside a beam
+ for (let i = 0; i < o.count; i++) {
+ const r = rng(S, i);
+ const x = r.range(B.x0, B.x1) + Math.sin(ph * TAU * r.int(1, 2) + r.next() * TAU) * r.range(4, 10);
+ const y = r.range(B.y0, B.y1) + Math.sin(ph * TAU * r.int(1, 2) + r.next() * TAU) * r.range(3, 7) + Math.sin(ph * TAU * 3 + i) * 1;
+ const b = beam(x, y);
+ if (b > 0.3) {
+ p.px(x, y, b > 0.6 ? C[4] : C[3]);
+ p.light(x, y, C[3], 0.35 * b);
+ } else if (i % 2 === 0) p.px(x, y, C[1]);
+ }
+}
diff --git a/src/fx/weather/hail.js b/src/fx/weather/hail.js
new file mode 100644
index 0000000..6a83f8a
--- /dev/null
+++ b/src/fx/weather/hail.js
@@ -0,0 +1,49 @@
+import { ramp, cycle, lerp, TAU } from "../../core/index.js";
+import { box, clip } from "./_lib.js";
+
+export const meta = {
+ name: "Hail",
+ desc: "Hailstones pelt down hard and bounce off the floor in shrinking hops, big ones cracking into chips, then melt away.",
+ tags: ["weather", "hail", "ice", "storm", "winter", "ambient", "loop"],
+ size: [96, 64],
+ origin: [48, 58],
+ duration: 2,
+ loop: true,
+ fps: 30,
+ bg: "ground",
+ options: { palette: ["#1f4f94", "#58b4ec", "#9bdcff", "#d8f4ff", "#ffffff"], count: 60, seed: 137 },
+};
+
+const G = 700; // gravity, px/s²
+
+export function draw(p, t, o) {
+ p = clip(p, meta);
+ const C = ramp(o.palette), S = o.seed, D = meta.duration, B = box(meta);
+ cycle(t, D, o.count, S, (r) => r.range(0.6, 0.75), (age, life, r, i) => {
+ const big = i % 4 === 0, s = big ? 3 : 2, fy = -r.int(0, 2), x0 = r.range(B.x0 + 2, B.x1 - 2);
+ const vy = r.range(230, 290), sl = 0.12, h0 = fy - (B.y0 - 6), tf = h0 / vy; // a straight, fast drop
+ const fade = 1 - (age - (life - 0.12)) / 0.12; // the last frames: melting away
+ if (age < tf) {
+ const y = lerp(B.y0 - 6, fy, age / tf), x = x0 + (y - fy) * sl;
+ p.line(x, y - s - 2, x, y - s, C[1]); // a short streak above it
+ p.rect(x - 1, y - s, s, s, C[2]);
+ p.px(x - 1, y - s, C[4]);
+ return;
+ }
+ // bounces: each hop shorter; the side kick is fixed per stone
+ const a = age - tf, vx = r.range(-28, 28);
+ const v1 = vy * 0.32, t1 = (2 * v1) / G, v2 = v1 * 0.35, t2 = (2 * v2) / G;
+ let y = fy, x = x0;
+ if (a < t1) (y = fy - (v1 * a - 0.5 * G * a * a)), (x = x0 + vx * a);
+ else if (a < t1 + t2) (y = fy - (v2 * (a - t1) - 0.5 * G * (a - t1) ** 2)), (x = x0 + vx * (t1 + (a - t1) * 0.5));
+ else x = x0 + vx * (t1 + t2 * 0.5);
+ // the impact: chips spray off the big ones; a white tick under the small ones
+ if (a < 0.08) {
+ if (big) for (const sx of [-1, 1]) p.px(x0 + sx * (2 + a * 60), fy - 1 - Math.sin((a / 0.08) * Math.PI) * 3, C[3]);
+ else p.px(x0, fy, C[4]);
+ }
+ const sz = big && a > 0.02 ? 2 : s; // the big ones crack down to a smaller lump
+ p.rect(x - 1, y - sz, sz, sz, C[2], fade < 1 ? Math.max(0, fade) : 1);
+ if (fade > 0.5) p.px(x - 1, y - sz, C[4]);
+ });
+}
diff --git a/src/fx/weather/heat-haze.js b/src/fx/weather/heat-haze.js
new file mode 100644
index 0000000..614afef
--- /dev/null
+++ b/src/fx/weather/heat-haze.js
@@ -0,0 +1,51 @@
+import { ramp, rng, clamp, fract, TAU } from "../../core/index.js";
+import { box, clip } from "./_lib.js";
+
+export const meta = {
+ name: "Heat haze",
+ desc: "Hot ground on a still day: wavy heat lines wriggle up off the floor and thin out, and a band of mirage shimmer slides along just above it.",
+ tags: ["weather", "heat", "desert", "summer", "shimmer", "mirage", "ambient", "loop"],
+ size: [96, 48],
+ origin: [48, 42],
+ duration: 3,
+ loop: true,
+ fps: 30,
+ bg: "ground",
+ options: { palette: ["#4a2a10", "#8a4a1a", "#d07a2a", "#f4b860", "#fff0c8"], count: 7, seed: 139 },
+};
+
+export function draw(p, t, o) {
+ p = clip(p, meta);
+ const C = ramp(o.palette), S = o.seed, D = meta.duration, B = box(meta), ph = t / D;
+ // warmth off the floor
+ p.shade(B.x0, -14, B.x1 + 1, 0, (x, y, out) => {
+ out.l = C[2];
+ out.k = y > -3 ? 0.14 : y > -7 ? 0.09 : 0.04;
+ });
+ // mirage shimmer: a few rows of long wavering dashes just over the floor, sliding opposite ways
+ for (let row = 0; row < 3; row++) {
+ const y0 = -2 - row * 3, dir = row % 2 ? 1 : -1;
+ for (let x = B.x0; x <= B.x1; x++) {
+ const u = (x - B.x0) / B.w;
+ const on = Math.sin(u * TAU * (3 + row) + ph * TAU * dir * (1 + row)) + Math.sin(u * TAU * 7 - ph * TAU * 2 + row) * 0.25;
+ if (on < 0.45 + row * 0.15) continue;
+ const y = y0 + Math.round(Math.sin(u * TAU * 5 + ph * TAU * 3 + row) * 0.7);
+ p.dot(x, y, row === 0 ? C[4] : C[3], row < 2 ? 1 : 0.5);
+ }
+ }
+ // heat lines: wavy strokes rising off the ground; each rises a whole number of times a loop
+ for (let i = 0; i < o.count; i++) {
+ const r = rng(S, i), laps = r.int(1, 2), u = fract(r.next() + (laps * t) / D);
+ const x0 = B.x0 + 8 + ((i + r.range(0.1, 0.9)) / o.count) * (B.w - 16), len = r.range(11, 16);
+ const base = -2 - u * 24, amp = r.range(1.4, 2.2), freq = r.range(0.32, 0.42);
+ const fade = clamp(u * 5) * clamp((1 - u) * 2.2);
+ for (let s = 0; s < len; s++) {
+ // the wave travels up the stroke as it rises, so it wriggles
+ const y = base - s, x = x0 + Math.sin(y * freq + ph * TAU * 3 * laps + i) * amp;
+ const k = s / len; // 0 at the bottom of the stroke
+ const a = fade * (k < 0.2 || k > 0.8 ? 0.45 : 0.85);
+ p.dot(x, y, k > 0.3 && k < 0.7 ? C[4] : C[3], a);
+ p.light(x, y, C[3], 0.1 * fade);
+ }
+ }
+}
diff --git a/src/fx/weather/rain.js b/src/fx/weather/rain.js
new file mode 100644
index 0000000..2bb9c9c
--- /dev/null
+++ b/src/fx/weather/rain.js
@@ -0,0 +1,48 @@
+import { ramp, lerp, TAU } from "../../core/index.js";
+import { box, clip, drift } from "./_lib.js";
+
+export const meta = {
+ name: "Rain",
+ desc: "Steady slanted rain in two depths: thin far streaks behind, bright near drops that hit the floor in little crowns and ripples.",
+ tags: ["weather", "rain", "water", "ambient", "loop"],
+ size: [128, 72],
+ origin: [64, 64],
+ duration: 2,
+ loop: true,
+ fps: 30,
+ bg: "ground",
+ options: { palette: ["#1c2c48", "#2e4a72", "#4c78a8", "#86b6de", "#cfe8fa"], count: 60, slant: 0.28, seed: 71 },
+};
+
+export function draw(p, t, o) {
+ p = clip(p, meta);
+ const C = ramp(o.palette), S = o.seed, D = meta.duration, B = box(meta), sl = o.slant;
+ const top = B.y0 - 8;
+ // far rain: short dim streaks that fade out before the floor (they fall behind it)
+ drift(t, D, Math.round(o.count * 0.7), S, [3, 4], (u, r) => {
+ const end = -r.range(2, 30), x0 = r.range(B.x0 - 20, B.x1), y = lerp(top, end + 6, u);
+ if (y > end) return;
+ const x = x0 + (y - top) * sl, len = 3;
+ p.line(x, y, x - len * sl, y - len, C[1]);
+ });
+ // near rain: long bright streaks; the trip ends on the floor, then plays its splash
+ drift(t, D, o.count, S + 1, [4, 6], (u, r) => {
+ const x0 = r.range(B.x0 - 18, B.x1 - 2), fy = r.int(0, 2), fall = 0.82; // the last 18% of the trip is the splash
+ const len = r.range(4, 7), bright = r.chance(0.35);
+ if (u < fall) {
+ const y = lerp(top, fy, u / fall), x = x0 + (y - top) * sl;
+ p.line(x, y, x - len * sl, y - len, (q) => (q < 0.3 ? C[bright ? 4 : 3] : C[2]));
+ return;
+ }
+ // the splash: a two-drop crown jumps up, a flat ripple spreads, both gone in a few frames
+ const k = (u - fall) / (1 - fall), x = x0 + (fy - top) * sl;
+ if (k < 0.55) {
+ const q = k / 0.55, h = Math.sin(q * Math.PI) * 3;
+ p.px(x - 1 - q * 2, fy - h, C[3]);
+ p.px(x + 1 + q * 2, fy - h, C[3]);
+ if (q < 0.3) p.px(x, fy - 1, C[4]);
+ }
+ const w = 1 + k * 3;
+ p.line(x - w, fy, x + w, fy, C[k < 0.5 ? 3 : 2], k < 0.7 ? 1 : 0.5);
+ });
+}
diff --git a/src/fx/weather/sandstorm.js b/src/fx/weather/sandstorm.js
new file mode 100644
index 0000000..cd43bba
--- /dev/null
+++ b/src/fx/weather/sandstorm.js
@@ -0,0 +1,53 @@
+import { ramp, lerp, fract, rng, tileFbm, TAU } from "../../core/index.js";
+import { box, clip } from "./_lib.js";
+
+export const meta = {
+ name: "Sandstorm",
+ desc: "A desert wind tears sand across the frame: gritty dust walls roll past in waves, grains streak by at three depths and sand snakes along the floor.",
+ tags: ["weather", "sand", "dust", "desert", "wind", "storm", "ambient", "loop"],
+ size: [128, 72],
+ origin: [64, 66],
+ duration: 2,
+ loop: true,
+ fps: 30,
+ bg: "ground",
+ options: { palette: ["#2a1c10", "#4e3620", "#7a5a34", "#a8844e", "#d0ac6c", "#ecd09a"], count: 150, seed: 107 },
+};
+
+export function draw(p, t, o) {
+ p = clip(p, meta);
+ const C = ramp(o.palette), S = o.seed, D = meta.duration, B = box(meta), ph = t / D;
+ // dust walls: stretched noise tiling the frame's width, swept right by whole widths; a warm haze in the
+ // light buffer in flat steps, thickest near the ground
+ p.shade(B.x0, B.y0, B.x1 + 1, B.y1 + 1, (x, y, out) => {
+ const u = (x - B.x0) / B.w, v = (y - B.y0) / B.h;
+ const n = tileFbm(u * 4 - ph * 8, v * 6 + Math.sin(u * TAU * 2 - ph * TAU * 2) * 0.35, 4, 0, S, 2) + v * 0.4 - 0.05;
+ out.l = n > 0.3 ? C[4] : C[3];
+ out.k = n > 0.42 ? 0.4 : n > 0.24 ? 0.3 : n > 0.06 ? 0.21 : 0.13;
+ });
+ // grains: far specks, mid dashes, near streaks; each crosses the frame a whole number of times a loop
+ const layers = [
+ { n: 0.45, laps: [2, 3], len: 0, c: 3, dy: 0.06 },
+ { n: 0.35, laps: [3, 5], len: 2, c: 4, dy: 0.1 },
+ { n: 0.2, laps: [5, 7], len: 6, c: 5, dy: 0.14 },
+ ];
+ layers.forEach((L, li) => {
+ const N = Math.round(o.count * L.n);
+ for (let i = 0; i < N; i++) {
+ const r = rng(S + 31 * li, i), k = r.int(L.laps[0], L.laps[1]), off = r.next();
+ const u = fract(off + (k * t) / D), x = B.x0 - 12 + u * (B.w + 24);
+ const y = r.range(B.y0, B.y1 - 4) + u * L.dy * B.w + Math.sin(u * TAU * 3 + i) * 1.5;
+ if (L.len) p.line(x, y, x - L.len, y - L.len * L.dy, (q) => (q < 0.35 ? C[L.c] : C[L.c - 1]));
+ else p.px(x, y, C[L.c]);
+ }
+ });
+ // drifts: sand snaking along the floor in thin wavy lines
+ for (let i = 0; i < 7; i++) {
+ const r = rng(S + 99, i), k = r.int(3, 5), u = fract(r.next() + (k * t) / D);
+ const len = r.range(10, 22), head = B.x0 - 25 + u * (B.w + 50), y0 = -r.int(0, 2);
+ for (let s = 0; s < len; s++) {
+ const x = head - s, y = y0 + Math.round(Math.sin(x * 0.35 + i) * 0.8);
+ p.px(x, y, s < 3 ? C[5] : s < len * 0.6 ? C[4] : C[3]);
+ }
+ }
+}
diff --git a/src/fx/weather/shooting-stars.js b/src/fx/weather/shooting-stars.js
new file mode 100644
index 0000000..98e78ad
--- /dev/null
+++ b/src/fx/weather/shooting-stars.js
@@ -0,0 +1,58 @@
+import { ramp, rng, seg, ease, lerp, clamp, TAU } from "../../core/index.js";
+import { box, clip } from "./_lib.js";
+
+export const meta = {
+ name: "Shooting stars",
+ desc: "A quiet starry sky where now and then a meteor streaks down to the right, its trail burning white to blue, flaring once before it winks out.",
+ tags: ["weather", "night", "sky", "stars", "meteor", "shooting star", "ambient", "loop"],
+ size: [128, 72],
+ origin: [64, 36],
+ duration: 4,
+ loop: true,
+ fps: 30,
+ bg: "sky",
+ options: { palette: ["#1c2a5a", "#3a5aa8", "#7ca4e8", "#c8e0ff", "#fff8e8", "#ffffff"], seed: 113 },
+};
+
+// meteors: [start time, start x, start y, angle, speed, trail length]
+const METEORS = [
+ [0.2, -60, -34, 0.42, 190, 26],
+ [1.75, -10, -38, 0.55, 230, 22],
+ [2.95, -48, -16, 0.3, 160, 30],
+];
+const LIFE = 0.5;
+
+export function draw(p, t, o) {
+ p = clip(p, meta);
+ const C = ramp(o.palette), S = o.seed, B = box(meta), ph = t / meta.duration;
+ // a few bright stars of our own, breathing gently
+ for (let i = 0; i < 9; i++) {
+ const r = rng(S, i), x = r.range(B.x0 + 4, B.x1 - 4), y = r.range(B.y0 + 3, B.y1 - 10);
+ const b = 0.5 + 0.5 * Math.sin(ph * TAU * r.int(1, 2) + r.next() * TAU);
+ p.px(x, y, b > 0.6 ? C[5] : C[3]);
+ if (b > 0.85 && i % 3 === 0) p.px(x - 1, y, C[2]), p.px(x + 1, y, C[2]), p.px(x, y - 1, C[2]), p.px(x, y + 1, C[2]);
+ }
+ for (const [t0, x0, y0, ang, sp, len] of METEORS) {
+ const a = t - t0;
+ if (a < 0 || a > LIFE + 0.25) continue;
+ const dx = Math.cos(ang), dy = Math.sin(ang);
+ const k = clamp(a / LIFE), dist = sp * LIFE * ease.outQuad(k) * 0.9 + sp * a * 0.1;
+ const hx = x0 + dx * dist, hy = y0 + dy * dist;
+ if (a <= LIFE) {
+ // the trail: grows in, then shortens as the meteor burns out
+ const L = len * Math.min(1, a / 0.12) * (1 - ease.inQuad(seg(k, 0.6, 1)));
+ p.line(hx, hy, hx - dx * L, hy - dy * L, (u) => (u < 0.15 ? C[5] : u < 0.4 ? C[4] : u < 0.7 ? C[2] : C[1]), (u) => (u < 0.75 ? 1 : 1 - (u - 0.75) * 3));
+ // the hot end of the trail is two pixels thick
+ p.line(hx - dx, hy - dy + 1, hx - dx * L * 0.35, hy - dy * L * 0.35 + 1, (u) => (u < 0.4 ? C[3] : C[2]));
+ p.glowLine(hx, hy, hx - dx * L * 0.6, hy - dy * L * 0.6, 4, C[2], 0.25);
+ const flare = k > 0.72 && k < 0.86;
+ p.px(hx, hy, C[5]);
+ if (flare) for (const [ox, oy] of [[-1, 0], [1, 0], [0, -1], [0, 1]]) p.px(hx + ox, hy + oy, C[4]);
+ p.glow(hx, hy, flare ? 9 : 5, C[3], flare ? 0.6 : 0.4);
+ } else {
+ // afterglow: a faint line where it passed, gone in a few frames
+ const q = (a - LIFE) / 0.25, L = len * 0.5;
+ p.line(hx - dx * 2, hy - dy * 2, hx - dx * L, hy - dy * L, C[1], 0.5 * (1 - q));
+ }
+ }
+}
diff --git a/src/fx/weather/snow.js b/src/fx/weather/snow.js
new file mode 100644
index 0000000..2d8c962
--- /dev/null
+++ b/src/fx/weather/snow.js
@@ -0,0 +1,43 @@
+import { ramp, lerp, TAU } from "../../core/index.js";
+import { box, clip, drift } from "./_lib.js";
+
+export const meta = {
+ name: "Snow",
+ desc: "Snow drifting down in three depths: faint specks far off, single flakes swaying in the middle, big soft flakes floating close by.",
+ tags: ["weather", "snow", "winter", "cold", "ambient", "loop"],
+ size: [128, 72],
+ origin: [64, 36],
+ duration: 6,
+ loop: true,
+ fps: 30,
+ bg: "sky",
+ options: { palette: ["#3a4660", "#6a7a98", "#a8b8d0", "#e4eef8", "#ffffff"], count: 80, seed: 79 },
+};
+
+const FLAKE = [".a.", "aba", ".a."];
+const BIG = ["..a..", ".aba.", "abcba", ".aba.", "..a.."];
+
+export function draw(p, t, o) {
+ p = clip(p, meta);
+ const C = ramp(o.palette), S = o.seed, D = meta.duration, B = box(meta), n = o.count;
+ // each flake falls from above the frame to below it; a longer trip (more of it hidden) means a faster flake
+ const fall = (u, r, extra) => lerp(B.y0 - 4 - extra * r.next(), B.y1 + 4, u);
+ // far: dim specks, slow, barely swaying
+ drift(t, D, Math.round(n * 0.5), S, 1, (u, r) => {
+ const y = fall(u, r, 20), x0 = r.range(B.x0, B.x1), sw = Math.sin(u * TAU * 1.5 + r.next() * TAU) * 2;
+ p.px(x0 + sw, y, C[1]);
+ });
+ // middle: single bright flakes swaying as they fall
+ drift(t, D, Math.round(n * 0.35), S + 1, [1, 2], (u, r) => {
+ const y = fall(u, r, 40), x0 = r.range(B.x0, B.x1), sw = Math.sin(u * TAU * r.range(1.5, 3) + r.next() * TAU) * r.range(3, 6);
+ p.px(x0 + sw + u * 6, y, r.chance(0.3) ? C[4] : C[3]);
+ });
+ // near: big soft flakes floating down, swinging wide
+ drift(t, D, Math.round(n * 0.15), S + 2, [2, 3], (u, r, i) => {
+ const y = fall(u, r, 60), x0 = r.range(B.x0, B.x1), sw = Math.sin(u * TAU * r.range(1.5, 2.5) + r.next() * TAU) * r.range(6, 10);
+ const big = i % 3 === 0, x = x0 + sw + u * 10;
+ p.sprite(big ? BIG : FLAKE, { a: C[2], b: C[3], c: C[4] }, x - (big ? 2 : 1), y - (big ? 2 : 1));
+ if (!big) p.px(x, y, C[4]);
+ p.light(x, y, C[3], big ? 0.25 : 0.12);
+ });
+}
diff --git a/src/fx/weather/storm.js b/src/fx/weather/storm.js
new file mode 100644
index 0000000..75c30af
--- /dev/null
+++ b/src/fx/weather/storm.js
@@ -0,0 +1,79 @@
+import { ramp, at, lerp, clamp, seg, rng, bolt, forks, tileFbm, hex } from "../../core/index.js";
+import { box, clip, drift } from "./_lib.js";
+
+export const meta = {
+ name: "Storm",
+ desc: "Driving rain under a churning cloud deck; a bolt cracks down in a double flash that lights the whole sky, and far off, lightning glows inside the clouds.",
+ tags: ["weather", "storm", "rain", "lightning", "thunder", "ambient", "loop"],
+ size: [128, 72],
+ origin: [64, 36],
+ duration: 3,
+ loop: true,
+ fps: 30,
+ bg: "sky",
+ options: {
+ palette: ["#0c0e16", "#161a26", "#222838", "#30384c", "#434d66", "#5e6a86", "#8a98b6", "#cfdcf2"],
+ bolt: ["#3a56c8", "#8cb4ff", "#ffffff"],
+ count: 90,
+ seed: 73,
+ },
+};
+
+// the strike: a quick pre-flicker, the bolt, a blink, then the bolt again as the flash dies
+function flash(t) {
+ if (t >= 1.2 && t < 1.24) return 0.25;
+ if (t >= 1.3 && t < 1.4) return 1;
+ if (t >= 1.44 && t < 1.64) return 0.85 * (1 - seg(t, 1.44, 1.64));
+ return 0;
+}
+
+export function draw(p, t, o) {
+ p = clip(p, meta);
+ const C = ramp(o.palette), BO = ramp(o.bolt), S = o.seed, D = meta.duration, B = box(meta), ph = t / D;
+ const f = flash(t), boltOn = (t >= 1.3 && t < 1.4) || (t >= 1.44 && t < 1.56);
+ // sheet lightning: a glow deep in the clouds, far off to one side
+ const sheet = t >= 2.35 && t < 2.6 ? Math.sin(seg(t, 2.35, 2.6) * Math.PI) * (t > 2.43 && t < 2.47 ? 0.4 : 1) : 0;
+ const sx = B.x1 - 30;
+ // rain: two depths, steep and fast; lit up while the sky flashes
+ const sl = 0.42;
+ drift(t, D, Math.round(o.count * 0.6), S, [5, 7], (u, r) => {
+ const x0 = r.range(B.x0 - 40, B.x1), y = lerp(B.y0 - 6, B.y1 + 6, u), x = x0 + (y - B.y0) * sl;
+ p.line(x, y, x - 3 * sl, y - 3, f > 0.5 ? C[5] : C[3]);
+ });
+ drift(t, D, o.count, S + 1, [7, 10], (u, r) => {
+ const x0 = r.range(B.x0 - 40, B.x1), len = r.range(6, 10), y = lerp(B.y0 - 10, B.y1 + 12, u), x = x0 + (y - B.y0) * sl;
+ p.line(x, y, x - len * sl, y - len, (q) => (q < 0.3 ? C[f > 0.5 ? 7 : 6] : C[f > 0.5 ? 6 : 4]));
+ });
+ // the bolt: from the cloud base down out of the bottom of the frame, with forks
+ if (boltOn) {
+ const r = rng(S, 5), x0 = lerp(B.x0 + 30, B.x1 - 40, r.next()), path = bolt(r, x0, B.y0 + 14, x0 + r.range(-14, 14), B.y1 + 2, { jag: 0.2, depth: 5 });
+ const br = forks(r, path, { count: 3, len: 22, jag: 0.3 });
+ const second = t >= 1.44;
+ for (const q of [path, ...br]) {
+ for (let i = 1; i < q.length; i++) p.line(q[i - 1][0] + 1, q[i - 1][1], q[i][0] + 1, q[i][1], BO[0]);
+ }
+ for (const q of br) p.polyline(q, BO[1]);
+ p.polyline(path, second ? BO[1] : BO[2]);
+ if (!second) p.polyline(path.map(([x, y]) => [x - 1, y]), BO[1]);
+ for (let i = 4; i < path.length; i += 4) p.glowLine(path[i - 4][0], path[i - 4][1], path[i][0], path[i][1], 7, BO[1], 0.35);
+ }
+ // the cloud deck: a ragged band across the top whose texture churns; lit from below by the flashes
+ const deck = (x) => 12 + tileFbm(x * 0.05, 0.5, 6.4, 0, S + 2, 2) * 6;
+ p.shade(B.x0, B.y0, B.x1 + 1, B.y0 + 26, (x, y) => {
+ const d = y - B.y0, edge = deck(x);
+ if (d > edge) return;
+ const n = tileFbm(x * 0.07, d * 0.13 + ph * 4, 0, 4, S, 3), v = d / edge; // v: 0 at the top, 1 at the base
+ let k = 0.28 + n * 0.32 - v * 0.08;
+ if (v > 0.82) k += f * 0.45 - 0.06; // the underside catches the flash
+ k += f * 0.2 + (sheet > 0 ? sheet * 0.5 * clamp(1 - Math.abs(x - sx) / 26) : 0);
+ return at(C.slice(1, 8), k);
+ });
+ // the flash: light over everything, strongest under the clouds
+ if (f > 0) {
+ p.shade(B.x0, B.y0, B.x1 + 1, B.y1 + 1, (x, y, out) => {
+ out.l = BO[1];
+ out.k = f * (0.08 + 0.22 * (1 - (y - B.y0) / B.h));
+ });
+ }
+ if (sheet > 0) p.glow(sx, B.y0 + 8, 30, BO[1], 0.25 * sheet);
+}
diff --git a/src/fx/weather/twinkling-stars.js b/src/fx/weather/twinkling-stars.js
new file mode 100644
index 0000000..1b137d8
--- /dev/null
+++ b/src/fx/weather/twinkling-stars.js
@@ -0,0 +1,51 @@
+import { ramp, rng, clamp, TAU, hex } from "../../core/index.js";
+import { box, clip } from "./_lib.js";
+
+export const meta = {
+ name: "Twinkling stars",
+ desc: "A deep starfield: faint dust stars flicker, brighter ones pulse into little crosses, and a few big ones flare out long four-point rays.",
+ tags: ["weather", "night", "sky", "stars", "space", "twinkle", "ambient", "loop"],
+ size: [128, 72],
+ origin: [64, 36],
+ duration: 4,
+ loop: true,
+ fps: 30,
+ bg: "black",
+ options: { palette: ["#1a1c3a", "#3a3e72", "#7a80b8", "#c4c8ec", "#ffffff"], count: 80, seed: 127 },
+};
+
+// stars take a tint: cold blue-white, warm yellow, a few rose
+const TINTS = [hex("#cfe0ff"), hex("#fff2c8"), hex("#ffd0dc")];
+
+export function draw(p, t, o) {
+ p = clip(p, meta);
+ const C = ramp(o.palette), S = o.seed, B = box(meta), ph = t / meta.duration;
+ // each star twinkles a whole number of times a loop, from its own phase
+ const tw = (r) => 0.5 + 0.5 * Math.sin(ph * TAU * r.int(1, 3) + r.next() * TAU);
+ // dust: faint single pixels
+ for (let i = 0; i < o.count; i++) {
+ const r = rng(S, i), x = r.range(B.x0, B.x1), y = r.range(B.y0, B.y1), b = tw(r);
+ if (b < 0.2) continue;
+ p.px(x, y, b > 0.75 ? C[2] : C[1]);
+ }
+ // bright stars: a dot that swells into a small cross at its peak
+ for (let i = 0; i < 16; i++) {
+ const r = rng(S + 1, i), x = Math.round(r.range(B.x0 + 3, B.x1 - 3)), y = Math.round(r.range(B.y0 + 3, B.y1 - 3)), b = tw(r);
+ const tint = TINTS[r.int(0, 2)];
+ p.px(x, y, b > 0.5 ? tint : C[2]);
+ if (b > 0.7) p.px(x - 1, y, C[2]), p.px(x + 1, y, C[2]), p.px(x, y - 1, C[2]), p.px(x, y + 1, C[2]);
+ p.light(x, y, tint, 0.3 * b);
+ }
+ // big stars: long four-point flares that grow and shrink, glowing
+ for (let i = 0; i < 4; i++) {
+ const r = rng(S + 2, i), x = Math.round(r.range(B.x0 + 10, B.x1 - 10)), y = Math.round(r.range(B.y0 + 8, B.y1 - 8));
+ const b = tw(r), tint = TINTS[i % 3], s = Math.round(1 + b * 4);
+ p.px(x, y, C[4]);
+ for (let k = 1; k <= s; k++) {
+ const c = k === 1 ? tint : k < s ? C[3] : C[2];
+ p.px(x - k, y, c), p.px(x + k, y, c), p.px(x, y - k, c), p.px(x, y + k, c);
+ }
+ if (b > 0.6) p.px(x - 1, y - 1, C[2]), p.px(x + 1, y - 1, C[2]), p.px(x - 1, y + 1, C[2]), p.px(x + 1, y + 1, C[2]);
+ p.glow(x, y, 6 + b * 6, tint, 0.15 + 0.3 * b);
+ }
+}
diff --git a/tools/build-gallery.mjs b/tools/build-gallery.mjs
new file mode 100644
index 0000000..0153dff
--- /dev/null
+++ b/tools/build-gallery.mjs
@@ -0,0 +1,38 @@
+#!/usr/bin/env node
+// Bundle the gallery into dist/gallery (a static site: GitHub Pages or any host) and dist/page (one page plus
+// one script, fonts inlined, for hosts that take a page body).
+//
+// node tools/index.mjs && node tools/build-gallery.mjs
+
+import { build } from "esbuild";
+import { readFileSync, writeFileSync, mkdirSync, cpSync } from "node:fs";
+import { join } from "node:path";
+import { ROOT } from "./lib/fxlib.mjs";
+
+const G = join(ROOT, "gallery"), OUT = join(ROOT, "dist", "gallery"), PAGE = join(ROOT, "dist", "page");
+mkdirSync(OUT, { recursive: true });
+mkdirSync(PAGE, { recursive: true });
+
+await build({ entryPoints: [join(G, "app.js")], bundle: true, format: "esm", minify: true, outfile: join(OUT, "app.js"), legalComments: "none" });
+cpSync(join(G, "fonts"), join(OUT, "fonts"), { recursive: true });
+writeFileSync(join(OUT, "style.css"), readFileSync(join(G, "style.css")));
+writeFileSync(join(OUT, "index.html"), readFileSync(join(G, "index.html")));
+
+// the one-page version: <title> and <style> first, then the body markup, the font as a data URI
+const html = readFileSync(join(G, "index.html"), "utf8");
+const body = html.slice(html.indexOf("<!--BODY-->") + 11, html.indexOf("<!--/BODY-->"));
+const font = readFileSync(join(G, "fonts", "PatchPixel-Regular.woff2")).toString("base64");
+const css = readFileSync(join(G, "style.css"), "utf8").replace("url(fonts/PatchPixel-Regular.woff2)", `url(data:font/woff2;base64,${font})`);
+writeFileSync(
+ join(PAGE, "index.html"),
+ [
+ "<title>pixelfx</title>",
+ '<meta name="claude:viewport-fit-sides" content="cover">',
+ '<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Funnel+Sans:wght@400;500&family=Red+Hat+Mono:wght@400;500&display=swap">',
+ `<style>\n${css}\n</style>`,
+ body.trim(),
+ '<script type="module" src="app.js"></script>',
+ ].join("\n"),
+);
+cpSync(join(OUT, "app.js"), join(PAGE, "app.js"));
+console.log(`dist/gallery and dist/page built (${(readFileSync(join(OUT, "app.js")).length / 1024).toFixed(0)} KB of script)`);
diff --git a/tools/check.mjs b/tools/check.mjs
new file mode 100644
index 0000000..2ac01c5
--- /dev/null
+++ b/tools/check.mjs
@@ -0,0 +1,144 @@
+#!/usr/bin/env node
+// Check effects for the mistakes eyes miss: missing meta, drawing outside the canvas, one-shots that don't
+// end clean, loops with a seam, randomness that isn't seeded, slow frames.
+//
+// node tools/check.mjs every effect
+// node tools/check.mjs fire ui/level-up
+
+import { readFileSync } from "node:fs";
+import { resolveIds, allIds, loadEffect } from "./lib/fxlib.mjs";
+import { createFrame, clearFrame, painterFor, createFx, stockActor, resolveOptions, Painter, BACKDROPS } from "../src/core/index.js";
+
+const ids = process.argv.slice(2).length ? resolveIds(process.argv.slice(2)) : allIds();
+const M = 24; // margin around the canvas, to catch pixels drawn outside it
+let fails = 0, warns = 0;
+
+function drawAt(fx, t, frame, opts) {
+ const { mod, meta } = fx, p = painterFor(clearFrame(frame));
+ p.place(meta.origin[0], meta.origin[1]);
+ if (mod.drawBack) mod.drawBack(p, t, opts);
+ mod.draw(p, t, opts);
+}
+const count = (buf, test) => {
+ let n = 0;
+ for (let i = 0; i < buf.length; i++) if (test(buf[i], i)) n++;
+ return n;
+};
+
+for (const id of ids) {
+ const errs = [], notes = [];
+ try {
+ const fx = await loadEffect(id), { meta, mod } = fx;
+ const src = readFileSync(fx.file, "utf8");
+ // meta
+ if (typeof meta.name !== "string" || !meta.name) errs.push("meta.name missing");
+ if (typeof meta.desc !== "string" || meta.desc.length < 12) errs.push("meta.desc missing or too short");
+ if (meta.desc?.length > 180) notes.push(`desc is ${meta.desc.length} chars (keep it under 180)`);
+ if (!Array.isArray(meta.tags) || !meta.tags.length) errs.push("meta.tags missing");
+ if (!Array.isArray(meta.size) || meta.size.some((v) => !Number.isInteger(v) || v < 8 || v > 400)) errs.push("meta.size must be [w, h], whole pixels 8..400");
+ if (!Array.isArray(meta.origin) || meta.origin.length !== 2) errs.push("meta.origin must be [x, y]");
+ if (!(meta.duration > 0 && meta.duration <= 12)) errs.push("meta.duration must be 0..12 s");
+ if (!BACKDROPS.includes(meta.bg)) errs.push(`meta.bg must be one of ${BACKDROPS.join(", ")}`);
+ const taken = Object.keys(meta.options ?? {}).filter((k) => ["x", "y", "flip", "angle", "light"].includes(k));
+ if (taken.length) errs.push(`option ${taken.join(", ")} is reserved for placement and glow: rename it`);
+ if (/Math\.random/.test(src)) errs.push("uses Math.random: use rng/rand/burst/cycle so frames repeat");
+ if (errs.length) throw new Error(errs.join("; "));
+
+ const [W, H] = meta.size, frame = createFrame(W + M * 2, H + M * 2, -M, -M);
+ const fw = frame.w, inside = (i) => {
+ const x = (i % fw) - M, y = Math.floor(i / fw) - M;
+ return x >= 0 && y >= 0 && x < W && y < H;
+ };
+ const opts = { ...(meta.options ?? {}), seed: meta.options?.seed ?? 1 };
+ if (meta.actor) opts.actor = stockActor();
+ const n = Math.max(2, Math.round(meta.duration * meta.fps));
+ let maxPx = 0, spill = 0, spillLight = 0, ms = [], bx0 = Infinity, by0 = Infinity, bx1 = -Infinity, by1 = -Infinity;
+ const bounds = () => frame.color.forEach((c, j) => {
+ if (!(c >>> 24)) return;
+ const x = (j % fw) - M, y = Math.floor(j / fw) - M;
+ bx0 = Math.min(bx0, x); bx1 = Math.max(bx1, x); by0 = Math.min(by0, y); by1 = Math.max(by1, y);
+ });
+ if (!mod.create) {
+ for (let i = 0; i <= n; i++) {
+ const t = meta.loop ? ((i % n) / n) * meta.duration : (i / n) * meta.duration;
+ const t0 = performance.now();
+ drawAt(fx, t, frame, opts);
+ ms.push(performance.now() - t0);
+ maxPx = Math.max(maxPx, count(frame.color, (c, j) => c >>> 24 && inside(j)), count(frame.light, (c, j) => (c & 0xffffff) && inside(j)));
+ spill = Math.max(spill, count(frame.color, (c, j) => c >>> 24 && !inside(j)));
+ bounds();
+ spillLight = Math.max(spillLight, count(frame.light, (c, j) => (c & 255) + ((c >>> 8) & 255) + ((c >>> 16) & 255) > 90 && !inside(j)));
+ }
+ // other seeds can throw particles further: look for spills with a few more
+ for (const seed of [2, 3, 7]) {
+ const o2 = { ...opts, seed };
+ for (let i = 0; i <= n; i += 2) {
+ drawAt(fx, meta.loop ? ((i % n) / n) * meta.duration : (i / n) * meta.duration, frame, o2);
+ const sp = count(frame.color, (c, j) => c >>> 24 && !inside(j));
+ if (sp > spill) (spill = sp), bounds();
+ }
+ }
+ if (maxPx === 0) errs.push("draws nothing");
+ if (spill > 0) notes.push(`${spill} px drawn outside the ${W}x${H} canvas (drawing spans x ${bx0}..${bx1}, y ${by0}..${by1}): grow size or move origin`);
+ if (spillLight > 60) notes.push(`glow spills ${spillLight} px past the canvas`);
+ // one-shots end clean
+ if (!meta.loop) {
+ drawAt(fx, meta.duration, frame, opts);
+ const left = count(frame.color, (c, j) => c >>> 24 && inside(j));
+ if (left > 0) notes.push(`${left} px still drawn at t = duration: one-shots should end empty`);
+ }
+ // loops have no seam: stepping from the last frame back to the first changes no more than a normal step
+ if (meta.loop) {
+ const shots = [];
+ for (let i = 0; i < n; i++) {
+ drawAt(fx, (i / n) * meta.duration, frame, opts);
+ shots.push(frame.color.slice());
+ }
+ const step = (a, b) => count(a, (c, j) => c !== b[j]);
+ const diffs = shots.slice(0, -1).map((a, i) => step(a, shots[i + 1])).sort((x, y) => x - y);
+ const typical = diffs[Math.floor(diffs.length * 0.9)] ?? 0, seam = step(shots[n - 1], shots[0]);
+ if (seam > Math.max(typical * 2, 12)) notes.push(`loop seam: ${seam} px change from the last frame to the first (a normal step is ${typical})`);
+ }
+ // any palette works: a short one (resampled by resolveOptions, as createFx does) leaves no holes
+ let holes = 0;
+ const put = Painter.prototype.put;
+ Painter.prototype.put = function (sx, sy, c, a) {
+ if (typeof c !== "number" || c !== c) holes++;
+ return put.call(this, sx, sy, c, a);
+ };
+ try {
+ const short = resolveOptions(meta, { palette: ["#141024", "#5a3c8c", "#c8a0f0", "#ffffff"] });
+ for (let i = 0; i <= 8; i++) drawAt(fx, (i / 8) * meta.duration * (meta.loop ? 0.999 : 1), frame, short);
+ } finally {
+ Painter.prototype.put = put;
+ }
+ if (holes) errs.push(`${holes} pixels drawn with an undefined color when given a 4-step palette: use fit(o.palette, n)`);
+ // deterministic: the same t twice gives the same frame
+ const tt = meta.duration * 0.37;
+ drawAt(fx, tt, frame, opts);
+ const once = frame.color.slice();
+ drawAt(fx, tt, frame, opts);
+ if (count(once, (c, j) => c !== frame.color[j]) > 0) errs.push("not deterministic: the same t drew different frames");
+ ms.sort((x, y) => x - y);
+ const med = ms[ms.length >> 1];
+ if (med > 4) notes.push(`slow: ${med.toFixed(1)} ms a frame`);
+ } else {
+ const inst = createFx(mod, { x: meta.origin[0], y: meta.origin[1], ...opts });
+ for (let i = 0; i <= n; i++) {
+ if (i) inst.update(1 / meta.fps);
+ clearFrame(frame);
+ inst.draw(frame);
+ maxPx = Math.max(maxPx, count(frame.color, (c) => c >>> 24));
+ }
+ if (maxPx === 0) errs.push("draws nothing");
+ }
+ } catch (e) {
+ errs.push(String(e.message ?? e).split("\n")[0]);
+ }
+ if (errs.length) fails++;
+ if (notes.length) warns++;
+ const tag = errs.length ? "FAIL" : notes.length ? "warn" : "ok ";
+ if (errs.length || notes.length || ids.length < 40) console.log(`${tag} ${id}${[...errs, ...notes].map((s) => "\n " + s).join("")}`);
+}
+console.log(`\n${ids.length} effects: ${ids.length - fails} pass, ${fails} fail, ${warns} with warnings`);
+process.exit(fails ? 1 : 0);
diff --git a/tools/compare.mjs b/tools/compare.mjs
new file mode 100644
index 0000000..61cdda7
--- /dev/null
+++ b/tools/compare.mjs
@@ -0,0 +1,32 @@
+#!/usr/bin/env node
+// Drafts side by side: one row per effect, the same moments in each column, so you can pick the best.
+//
+// node tools/compare.mjs "arcane/my-spell-*" -> records/compare.png
+// node tools/compare.mjs fire/torch fire/campfire --frames 8 --out records/fires.png
+
+import { join } from "node:path";
+import { ROOT, resolveIds, loadEffect, renderFrames, pickFrames, upscale, canvas, save } from "./lib/fxlib.mjs";
+
+const args = process.argv.slice(2), flags = {}, pats = [];
+for (let i = 0; i < args.length; i++) args[i].startsWith("--") ? (flags[args[i].slice(2)] = args[++i]) : pats.push(args[i]);
+const ids = resolveIds(pats), cols = +(flags.frames ?? 8);
+if (!ids.length) process.exit(1);
+const runs = [];
+for (const id of ids) {
+ const fx = await loadEffect(id);
+ runs.push({ id, fx, r: renderFrames(fx) });
+}
+const w = Math.max(...runs.map((x) => x.r.w)), h = Math.max(...runs.map((x) => x.r.h));
+const k = Math.max(1, Math.min(4, Math.floor(1500 / cols / (w + 6))));
+const pad = 6, label = 22, img = canvas(pad + cols * (w * k + pad), runs.length * (h * k + label + pad) + pad);
+runs.forEach(({ id, r }, row) => {
+ const y = pad + row * (h * k + label + pad);
+ img.text(id, pad, y + 2, 3);
+ pickFrames(r.n, cols).forEach((fi, c) => {
+ const x = pad + c * (w * k + pad) + Math.floor(((w - r.w) * k) / 2);
+ img.paste(upscale(r.frames[fi].color, r.w, r.h, k), r.w * k, r.h * k, x, y + label + Math.floor(((h - r.h) * k) / 2));
+ });
+});
+const out = flags.out ?? join(ROOT, "records", "compare.png");
+save(out, img.png());
+console.log(`${runs.length} effects x ${cols} moments -> ${out}`);
diff --git a/tools/index.mjs b/tools/index.mjs
new file mode 100644
index 0000000..7f7cb7a
--- /dev/null
+++ b/tools/index.mjs
@@ -0,0 +1,68 @@
+#!/usr/bin/env node
+// Regenerate the registry (src/fx/index.js) and the catalog (docs/CATALOG.md) from the effect files.
+//
+// node tools/index.mjs
+
+import { writeFileSync, readFileSync } from "node:fs";
+import { join } from "node:path";
+import { ROOT, FX_DIR, allIds, loadEffect } from "./lib/fxlib.mjs";
+import { categories } from "../src/fx/categories.js";
+
+const metas = [];
+for (const id of allIds()) {
+ try {
+ metas.push({ id, ...(await loadEffect(id)).meta });
+ } catch (e) {
+ console.error(`skipping ${id}: ${String(e.message ?? e).split("\n")[0]}`);
+ }
+}
+const ids = metas.map((m) => m.id);
+const order = new Map(categories.map((c, i) => [c.id, i]));
+const rank = (id) => order.get(id.split("/")[0]) ?? 99;
+ids.sort((a, b) => rank(a) - rank(b) || a.localeCompare(b));
+metas.sort((a, b) => rank(a.id) - rank(b.id) || a.id.localeCompare(b.id));
+
+const ident = (id) => id.replace(/[^a-z0-9]+/gi, "_");
+const lines = [
+ "// Generated by tools/index.mjs: every effect, by id. Don't edit; run `node tools/index.mjs`.",
+ "",
+ ...ids.map((id) => `import * as ${ident(id)} from "./${id}.js";`),
+ "",
+ `export { categories } from "./categories.js";`,
+ "",
+ "export const effects = {",
+ ...ids.map((id) => ` "${id}": ${ident(id)},`),
+ "};",
+ "",
+];
+writeFileSync(join(FX_DIR, "index.js"), lines.join("\n"));
+
+const md = [
+ "# Catalog",
+ "",
+ `${ids.length} effects in ${categories.filter((c) => metas.some((m) => m.id.startsWith(c.id + "/"))).length} categories. Every one is a file in`,
+ "`src/fx/<category>/<name>.js`; render any of them with `node tools/render.mjs <id> --gif`.",
+ "",
+];
+for (const c of categories) {
+ const list = metas.filter((m) => m.id.startsWith(c.id + "/"));
+ if (!list.length) continue;
+ md.push(`## ${c.name}`, "", `${c.blurb}.`, "", "| effect | id | | size | what it does |", "|---|---|---|---|---|");
+ for (const m of list)
+ md.push(`| ${m.name} | \`${m.id}\` | ${m.loop ? "loop" : "one-shot"} ${m.duration}s | ${m.size[0]}×${m.size[1]} | ${m.desc.replace(/\|/g, "\\|")} |`);
+ md.push("");
+}
+writeFileSync(join(ROOT, "docs", "CATALOG.md"), md.join("\n"));
+console.log(`${ids.length} effects -> src/fx/index.js, docs/CATALOG.md`);
+
+// README: the count and the category table
+const readme = join(ROOT, "README.md");
+const rows = categories
+ .map((c) => [c, metas.filter((m) => m.id.startsWith(c.id + "/"))])
+ .filter(([, list]) => list.length)
+ .map(([c, list]) => `| **${c.name}** | ${list.length} | ${list.slice(0, 6).map((m) => m.name.toLowerCase()).join(", ")}${list.length > 6 ? "…" : ""} |`);
+const table = ["| category | effects | some of them |", "|---|---|---|", ...rows].join("\n");
+let text = readFileSync(readme, "utf8");
+text = text.replace(/<!-- count -->[\s\S]*?<!-- \/count -->/, `<!-- count -->${ids.length}<!-- /count -->`);
+text = text.replace(/<!-- catalog -->[\s\S]*?<!-- \/catalog -->/, `<!-- catalog -->\n${table}\n<!-- /catalog -->`);
+writeFileSync(readme, text);
diff --git a/tools/lib/fxlib.mjs b/tools/lib/fxlib.mjs
new file mode 100644
index 0000000..cd81632
--- /dev/null
+++ b/tools/lib/fxlib.mjs
@@ -0,0 +1,206 @@
+// Shared by the tools: find effects, render their frames, lay frames out, write PNG, GIF and MP4.
+
+import { readdirSync, existsSync, statSync, writeFileSync, mkdirSync } from "node:fs";
+import { join, dirname, relative, sep } from "node:path";
+import { fileURLToPath, pathToFileURL } from "node:url";
+import { spawnSync } from "node:child_process";
+import { createFrame, clearFrame, createFx, composite, painterFor, drawActor, stockActor, backdrop, actorAlphaOf } from "../../src/core/index.js";
+import { rasterText, textWidth } from "../../src/core/font.js";
+import { encodePNG } from "./png.mjs";
+
+export const ROOT = join(dirname(fileURLToPath(import.meta.url)), "..", "..");
+export const FX_DIR = join(ROOT, "src", "fx");
+
+/** Every effect id ("fire/torch"), sorted. Files starting with _ are helpers, not effects. */
+export function allIds(dir = FX_DIR) {
+ const out = [];
+ if (!existsSync(dir)) return out;
+ for (const cat of readdirSync(dir).sort()) {
+ const d = join(dir, cat);
+ if (cat.startsWith("_") || !statSync(d).isDirectory()) continue;
+ for (const f of readdirSync(d).sort()) if (f.endsWith(".js") && !f.startsWith("_")) out.push(`${cat}/${f.slice(0, -3)}`);
+ }
+ return out;
+}
+
+/** Ids matching patterns: "fire/torch", "fire" (a category), "fire/*", "*torch*", or a file path. */
+export function resolveIds(patterns, dir = FX_DIR) {
+ const all = allIds(dir), out = new Set();
+ for (let p of patterns) {
+ if (p.endsWith(".js")) p = relative(dir, p.startsWith("/") ? p : join(process.cwd(), p)).split(sep).join("/").replace(/\.js$/, "");
+ const re = new RegExp("^" + p.split("*").map((s) => s.replace(/[.+?^${}()|[\]\\]/g, "\\$&")).join(".*") + "$");
+ const hits = all.filter((id) => id === p || id.startsWith(p + "/") || re.test(id));
+ if (!hits.length) console.error(`no effect matches ${p}`);
+ hits.forEach((h) => out.add(h));
+ }
+ return [...out];
+}
+
+/** Import an effect module fresh. */
+export async function loadEffect(id, dir = FX_DIR) {
+ const file = join(dir, id + ".js");
+ const mod = await import(pathToFileURL(file).href + `?v=${statSync(file).mtimeMs}`);
+ const meta = { fps: 30, bg: "dark", loop: false, duration: 1, tags: [], options: {}, ...mod.meta };
+ if (!mod.meta) throw new Error(`${id}: no meta export`);
+ if (!mod.draw && !mod.create) throw new Error(`${id}: exports neither draw nor create`);
+ return { id, file, mod: { ...mod, meta }, meta };
+}
+
+/**
+ * Render an effect's frames. Returns { w, h, fps, n, frames: [{ t, color: RGBA over the backdrop,
+ * clear: RGBA on transparency }] }. opts: { fps, seed, bg, margin, options (passed to the effect) }.
+ */
+export function renderFrames(fx, opts = {}) {
+ const { meta } = fx, [W, H] = meta.size, [OX, OY] = meta.origin, m = opts.margin ?? 0;
+ const w = W + m * 2, h = H + m * 2, fps = opts.fps ?? meta.fps;
+ const n = Math.max(1, Math.round(meta.duration * fps) + (meta.loop ? 0 : 1));
+ const shown = createFrame(w, h, -m, -m), bare = createFrame(w, h, -m, -m);
+ const bgKind = opts.bg ?? meta.bg;
+ const bg = bgKind === "none" ? null : backdrop(bgKind, w, h, OY + m);
+ const inst = createFx(fx.mod, { x: OX, y: OY, ...(opts.seed !== undefined ? { seed: opts.seed } : {}), ...(opts.options ?? {}) });
+ const actor = meta.actor && opts.actor !== false ? inst.options.actor ?? stockActor() : null;
+ const frames = [];
+ for (let i = 0; i < n; i++) {
+ if (i > 0) inst.update(1 / fps);
+ // `shown` has the backdrop and the stand-in actor; `bare` is the effect alone, for sprite sheets
+ clearFrame(shown);
+ clearFrame(bare);
+ inst.draw(bare);
+ inst.draw(shown, "back");
+ if (actor) drawActor(painterFor(shown).place(OX, OY, !!opts.options?.flip), actor, actorAlphaOf(fx.mod, fx.meta.loop ? inst.t % fx.meta.duration : Math.min(inst.t, fx.meta.duration), inst.options));
+ inst.draw(shown, "front");
+ frames.push({
+ t: i / fps,
+ color: composite(shown, new Uint8ClampedArray(w * h * 4), bg),
+ clear: composite(bare, new Uint8ClampedArray(w * h * 4), null),
+ raw: bare.color.slice(),
+ light: bare.light.slice(),
+ });
+ }
+ return { w, h, fps, n, frames, margin: m };
+}
+
+/** Nearest-neighbour upscale of RGBA. */
+export function upscale(rgba, w, h, k) {
+ if (k === 1) return rgba;
+ const out = new Uint8ClampedArray(w * k * h * k * 4), src = new Uint32Array(rgba.buffer, rgba.byteOffset, w * h);
+ const dst = new Uint32Array(out.buffer);
+ for (let y = 0; y < h * k; y++) {
+ const sy = (y / k) | 0;
+ for (let x = 0; x < w * k; x++) dst[y * w * k + x] = src[sy * w + ((x / k) | 0)];
+ }
+ return out;
+}
+
+/** A blank RGBA canvas with helpers to paste images and write labels. */
+export function canvas(w, h, fill = [12, 11, 16, 255]) {
+ const data = new Uint8ClampedArray(w * h * 4);
+ for (let i = 0; i < w * h; i++) data.set(fill, i * 4);
+ return {
+ w, h, data,
+ paste(src, sw, sh, x, y) {
+ for (let yy = 0; yy < sh; yy++) {
+ const ty = y + yy;
+ if (ty < 0 || ty >= h) continue;
+ for (let xx = 0; xx < sw; xx++) {
+ const tx = x + xx;
+ if (tx < 0 || tx >= w) continue;
+ const s = (yy * sw + xx) * 4, d = (ty * w + tx) * 4, a = src[s + 3] / 255;
+ for (let c = 0; c < 3; c++) data[d + c] = src[s + c] * a + data[d + c] * (1 - a);
+ data[d + 3] = Math.max(data[d + 3], src[s + 3]);
+ }
+ }
+ },
+ text(str, x, y, k = 2, rgb = [200, 196, 214], font = "mini") {
+ rasterText(str, font, (gx, gy) => {
+ for (let yy = 0; yy < k; yy++)
+ for (let xx = 0; xx < k; xx++) {
+ const tx = x + gx * k + xx, ty = y + gy * k + yy;
+ if (tx >= 0 && ty >= 0 && tx < w && ty < h) data.set([...rgb, 255], (ty * w + tx) * 4);
+ }
+ });
+ },
+ rect(x, y, rw, rh, rgba) {
+ for (let yy = Math.max(0, y); yy < Math.min(h, y + rh); yy++) for (let xx = Math.max(0, x); xx < Math.min(w, x + rw); xx++) data.set(rgba, (yy * w + xx) * 4);
+ },
+ png() {
+ return encodePNG(w, h, data);
+ },
+ };
+}
+
+export { textWidth };
+
+/** Which frames a contact sheet shows: all of them up to max, else evenly spaced. */
+export function pickFrames(n, max = 16) {
+ if (n <= max) return [...Array(n).keys()];
+ return Array.from({ length: max }, (_, i) => Math.round((i * (n - 1)) / (max - 1)));
+}
+
+/** A contact sheet: frames in a grid, labelled, scaled to stay readable. Returns a PNG buffer. */
+export function contactSheet(fx, r, { max = 16, width = 1600, title, zoom } = {}) {
+ const { w, h, frames, fps } = r, idx = pickFrames(frames.length, max);
+ const k = zoom ?? Math.max(1, Math.min(6, Math.floor((width - 16) / Math.min(idx.length, 6) / (w + 6))));
+ const cw = w * k, ch = h * k, pad = 8, label = 16;
+ const cols = Math.max(1, Math.min(idx.length, Math.floor((Math.max(width, cw + pad * 2) - pad) / (cw + pad))));
+ const rows = Math.ceil(idx.length / cols), head = 30;
+ const img = canvas(pad + cols * (cw + pad), head + rows * (ch + label + pad) + pad);
+ const m = fx.meta;
+ img.text(title ?? `${fx.id} ${m.size[0]}x${m.size[1]} ${m.duration}S ${frames.length}F @${fps} ${m.loop ? "LOOP" : "ONE-SHOT"}`, pad, 8, 3);
+ idx.forEach((fi, j) => {
+ const x = pad + (j % cols) * (cw + pad), y = head + Math.floor(j / cols) * (ch + label + pad);
+ img.text(`${fi} ${frames[fi].t.toFixed(2)}`, x, y, 2, [140, 134, 160]);
+ img.paste(upscale(frames[fi].color, w, h, k), cw, ch, x, y + label);
+ });
+ return img.png();
+}
+
+/** A sprite sheet (transparent frames in a grid) plus Aseprite-style JSON that most engines import. */
+export function spriteSheet(fx, r, name) {
+ const { w, h, frames, fps } = r, n = frames.length;
+ const cols = Math.min(n, Math.max(1, Math.ceil(Math.sqrt((n * h) / w)))), rows = Math.ceil(n / cols);
+ const img = canvas(cols * w, rows * h, [0, 0, 0, 0]);
+ const json = { frames: [], meta: {} };
+ frames.forEach((f, i) => {
+ const x = (i % cols) * w, y = Math.floor(i / cols) * h;
+ img.paste(f.clear, w, h, x, y);
+ json.frames.push({
+ filename: `${name} ${i}`, frame: { x, y, w, h }, rotated: false, trimmed: false,
+ spriteSourceSize: { x: 0, y: 0, w, h }, sourceSize: { w, h }, duration: Math.round(1000 / fps),
+ });
+ });
+ const m = fx.meta;
+ json.meta = {
+ app: "https://github.com/patch-gg/pixelfx", version: "1", image: `${name}.png`, format: "RGBA8888",
+ size: { w: cols * w, h: rows * h }, scale: "1",
+ frameTags: [{ name: name, from: 0, to: n - 1, direction: "forward" }],
+ pixelfx: { id: fx.id, name: m.name, fps, loop: m.loop, frames: n, frameSize: [w, h], pivot: m.origin, columns: cols },
+ };
+ return { png: img.png(), json };
+}
+
+/** Animated preview through ffmpeg (GIF or MP4), scaled k times. Returns false if ffmpeg is missing. */
+export function writeVideo(file, r, k, { loops = 1 } = {}) {
+ const { w, h, frames, fps } = r, W = w * k, H = h * k;
+ const evenW = W + (W % 2), evenH = H + (H % 2), mp4 = file.endsWith(".mp4");
+ const parts = [];
+ for (let l = 0; l < loops; l++) for (const f of frames) parts.push(Buffer.from(upscale(f.color, w, h, k).buffer));
+ const vf = mp4
+ ? `pad=${evenW}:${evenH}:0:0:black,format=yuv420p`
+ : "split[a][b];[a]palettegen=max_colors=255:stats_mode=full[p];[b][p]paletteuse=dither=none";
+ const args = ["-v", "error", "-y", "-f", "rawvideo", "-pix_fmt", "rgba", "-s", `${W}x${H}`, "-r", String(fps), "-i", "-", "-vf", vf];
+ if (mp4) args.push("-c:v", "libx264", "-crf", "14", "-preset", "slow", "-movflags", "+faststart");
+ else args.push("-loop", "0");
+ args.push(file);
+ mkdirSync(dirname(file), { recursive: true });
+ const res = spawnSync("ffmpeg", args, { input: Buffer.concat(parts), maxBuffer: 1 << 30 });
+ if (res.error) return false;
+ if (res.status !== 0) throw new Error(`ffmpeg failed: ${res.stderr}`);
+ return true;
+}
+
+export function save(file, buf) {
+ mkdirSync(dirname(file), { recursive: true });
+ writeFileSync(file, typeof buf === "string" ? buf : buf);
+ return file;
+}
diff --git a/tools/lib/png.mjs b/tools/lib/png.mjs
new file mode 100644
index 0000000..df029bb
--- /dev/null
+++ b/tools/lib/png.mjs
@@ -0,0 +1,43 @@
+// A small PNG writer (RGBA, 8 bits per channel) on node:zlib, so the tools need no packages.
+
+import { deflateSync } from "node:zlib";
+
+const CRC = new Int32Array(256);
+for (let n = 0; n < 256; n++) {
+ let c = n;
+ for (let k = 0; k < 8; k++) c = c & 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1;
+ CRC[n] = c;
+}
+function crc32(buf) {
+ let c = -1;
+ for (let i = 0; i < buf.length; i++) c = CRC[(c ^ buf[i]) & 255] ^ (c >>> 8);
+ return (c ^ -1) >>> 0;
+}
+function chunk(type, data) {
+ const len = Buffer.alloc(4), body = Buffer.concat([Buffer.from(type, "ascii"), data]), crc = Buffer.alloc(4);
+ len.writeUInt32BE(data.length);
+ crc.writeUInt32BE(crc32(body));
+ return Buffer.concat([len, body, crc]);
+}
+
+/** Encode w x h RGBA bytes as a PNG buffer. */
+export function encodePNG(w, h, rgba) {
+ const stride = w * 4, raw = Buffer.alloc((stride + 1) * h);
+ const src = Buffer.from(rgba.buffer, rgba.byteOffset, rgba.byteLength);
+ for (let y = 0; y < h; y++) {
+ const o = y * (stride + 1);
+ raw[o] = 1; // Sub filter: pixel art has long runs, so differences compress well
+ for (let x = 0; x < stride; x++) raw[o + 1 + x] = (src[y * stride + x] - (x >= 4 ? src[y * stride + x - 4] : 0)) & 255;
+ }
+ const ihdr = Buffer.alloc(13);
+ ihdr.writeUInt32BE(w, 0);
+ ihdr.writeUInt32BE(h, 4);
+ ihdr[8] = 8;
+ ihdr[9] = 6;
+ return Buffer.concat([
+ Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]),
+ chunk("IHDR", ihdr),
+ chunk("IDAT", deflateSync(raw, { level: 9 })),
+ chunk("IEND", Buffer.alloc(0)),
+ ]);
+}
diff --git a/tools/list.mjs b/tools/list.mjs
new file mode 100644
index 0000000..540fced
--- /dev/null
+++ b/tools/list.mjs
@@ -0,0 +1,22 @@
+#!/usr/bin/env node
+// Find effects: node tools/list.mjs [words...]
+// Matches ids, names, tags and descriptions; no words lists everything.
+
+import { allIds, loadEffect } from "./lib/fxlib.mjs";
+
+const words = process.argv.slice(2).map((w) => w.toLowerCase());
+let n = 0;
+for (const id of allIds()) {
+ let m;
+ try {
+ m = (await loadEffect(id)).meta;
+ } catch {
+ continue;
+ }
+ const hay = [id, m.name, m.desc, ...m.tags].join(" ").toLowerCase();
+ if (!words.every((w) => hay.includes(w))) continue;
+ n++;
+ const kind = m.loop ? `loop ${m.duration}s` : `once ${m.duration}s`;
+ console.log(`${id.padEnd(30)} ${kind.padEnd(11)} ${(m.size[0] + "x" + m.size[1]).padEnd(8)} ${m.actor ? "actor " : " "}${m.desc}`);
+}
+console.log(`\n${n} effect${n === 1 ? "" : "s"}`);
diff --git a/tools/montage.mjs b/tools/montage.mjs
new file mode 100644
index 0000000..73b9fc8
--- /dev/null
+++ b/tools/montage.mjs
@@ -0,0 +1,78 @@
+#!/usr/bin/env node
+// Many effects playing at once in one grid video, for READMEs and posts.
+//
+// node tools/montage.mjs out.mp4 --ids fire/torch,ice/frost-nova,... --cols 6 --rows 3
+// node tools/montage.mjs out.gif --category fire --cols 5 --rows 3 --seconds 4
+//
+// Options: --ids a,b,c | --category c | --pick N (a spread over every category) --cols --rows
+// --cell WxH (art pixels per cell, default 96x80) --scale N --seconds S --fps N --bg kind (default: each effect's)
+// --stagger S (start offsets for one-shots) --rest S (pause before a one-shot replays) --gap N (px between cells)
+
+import { join } from "node:path";
+import { allIds, loadEffect, writeVideo, save } from "./lib/fxlib.mjs";
+import { createFrame, clearFrame, createFx, composite, backdrop, drawActor, painterFor, stockActor, rand, actorAlphaOf } from "../src/core/index.js";
+import { categories } from "../src/fx/categories.js";
+import { encodePNG } from "./lib/png.mjs";
+
+const args = process.argv.slice(2), flags = {};
+let outFile;
+for (let i = 0; i < args.length; i++) {
+ if (args[i].startsWith("--")) flags[args[i].slice(2)] = args[++i];
+ else outFile = args[i];
+}
+if (!outFile) {
+ console.error("usage: node tools/montage.mjs <out.mp4|out.gif|out.png> [--ids ...|--category c|--pick N] [--cols 6 --rows 3]");
+ process.exit(1);
+}
+const cols = +(flags.cols ?? 6), rows = +(flags.rows ?? 3), [CW, CH] = (flags.cell ?? "96x80").split("x").map(Number);
+const fps = +(flags.fps ?? 30), seconds = +(flags.seconds ?? 5), gap = +(flags.gap ?? 2), stagger = +(flags.stagger ?? 0.35), rest = +(flags.rest ?? 0.35);
+let ids;
+if (flags.ids) ids = flags.ids.split(",");
+else if (flags.category) ids = allIds().filter((id) => id.startsWith(flags.category + "/"));
+else {
+ // a spread: round-robin over categories so every one shows up
+ const by = categories.map((c) => allIds().filter((id) => id.startsWith(c.id + "/")));
+ ids = [];
+ for (let k = 0; ids.length < +(flags.pick ?? cols * rows) && by.some((l) => l.length > k); k++)
+ for (const l of by) if (l[k] && ids.length < +(flags.pick ?? cols * rows)) ids.push(l[k]);
+}
+ids = ids.slice(0, cols * rows);
+
+const W = cols * CW + (cols + 1) * gap, H = rows * CH + (rows + 1) * gap;
+const cells = [];
+for (const [i, id] of ids.entries()) {
+ const fx = await loadEffect(id), m = fx.meta, frame = createFrame(CW, CH);
+ const fit = Math.min(1, CW / m.size[0], CH / m.size[1]);
+ if (fit < 1) console.error(`${id} is ${m.size.join("x")}, bigger than a ${CW}x${CH} cell: it will be cropped`);
+ const x = Math.floor((CW - m.size[0]) / 2) + m.origin[0], y = Math.floor((CH - m.size[1]) / 2) + m.origin[1];
+ const bg = backdrop(flags.bg ?? m.bg, CW, CH, y);
+ cells.push({ id, fx, m, frame, x, y, bg, cx: gap + (i % cols) * (CW + gap), cy: gap + Math.floor(i / cols) * (CH + gap), delay: m.loop ? 0 : rand(i, 7) * stagger, inst: null, born: 0 });
+}
+const n = Math.round(seconds * fps), frames = [], buf = new Uint8ClampedArray(CW * CH * 4);
+for (let f = 0; f < n; f++) {
+ const t = f / fps, out = new Uint8ClampedArray(W * H * 4);
+ for (let i = 0; i < W * H; i++) out.set([0, 0, 0, 255], i * 4);
+ for (const c of cells) {
+ const local = t - c.delay;
+ if (!c.inst || (!c.m.loop && local - c.born > c.m.duration + rest)) {
+ c.inst = createFx(c.fx.mod, { x: c.x, y: c.y });
+ c.born = Math.max(0, local);
+ }
+ clearFrame(c.frame);
+ if (local >= 0) {
+ const tt = local - c.born;
+ while (c.inst.t < tt - 1e-6) c.inst.update(1 / fps);
+ c.inst.draw(c.frame, "back");
+ if (c.m.actor) drawActor(painterFor(c.frame).place(c.x, c.y), c.inst.options.actor ?? stockActor(), actorAlphaOf(c.fx.mod, c.m.loop ? c.inst.t % c.m.duration : Math.min(c.inst.t, c.m.duration), c.inst.options));
+ c.inst.draw(c.frame, "front");
+ }
+ composite(c.frame, buf, c.bg);
+ for (let yy = 0; yy < CH; yy++) out.set(buf.subarray(yy * CW * 4, (yy + 1) * CW * 4), ((c.cy + yy) * W + c.cx) * 4);
+ }
+ frames.push({ color: out });
+}
+const scale = +(flags.scale ?? Math.max(1, Math.floor(1280 / W)));
+if (outFile.endsWith(".png")) {
+ save(outFile, encodePNG(W, H, frames[Math.floor(n * 0.45)].color));
+} else writeVideo(outFile, { w: W, h: H, fps, frames }, scale);
+console.log(`${cells.length} effects, ${W}x${H} art px x${scale}, ${seconds}s -> ${outFile}`);
diff --git a/tools/new.mjs b/tools/new.mjs
new file mode 100644
index 0000000..5b6fbe7
--- /dev/null
+++ b/tools/new.mjs
@@ -0,0 +1,61 @@
+#!/usr/bin/env node
+// Start a new effect from a template: node tools/new.mjs <category>/<name> [--loop]
+// Writes src/fx/<category>/<name>.js and renders it once.
+
+import { existsSync, mkdirSync, writeFileSync } from "node:fs";
+import { join, dirname } from "node:path";
+import { FX_DIR } from "./lib/fxlib.mjs";
+
+const id = process.argv[2], loop = process.argv.includes("--loop");
+if (!id || !/^[a-z0-9-]+\/[a-z0-9-]+$/.test(id)) {
+ console.error("usage: node tools/new.mjs <category>/<name> [--loop] (kebab-case)");
+ process.exit(1);
+}
+const file = join(FX_DIR, id + ".js");
+if (existsSync(file)) {
+ console.error(`${file} already exists`);
+ process.exit(1);
+}
+const name = id.split("/")[1].replace(/-/g, " ").replace(/^./, (c) => c.toUpperCase());
+const body = loop
+ ? ` // a loop: everything is a function of the phase, so t = 0 and t = duration match
+ const C = ramp(o.palette), ph = t / meta.duration;
+ cycle(t, meta.duration, 12, o.seed, 0.8, (age, life, r) => {
+ const k = age / life, a = r.range(0, TAU) + ph * TAU, rad = 6 + k * 12;
+ p.px(Math.cos(a) * rad, Math.sin(a) * rad - 8, at(C.slice(2), 1 - k));
+ });
+ p.circle(0, -8, 4 + Math.sin(ph * TAU) * 1.5, C[5]);
+ p.glow(0, -8, 20, C[4], 0.35);`
+ : ` // a one-shot: a hero frame, then everything falls away and is gone by t = duration
+ const C = ramp(o.palette);
+ if (t < 0.06) p.circle(0, -8, 6, WHITE);
+ burst(14, o.seed, (r) => {
+ const a = r.range(0, TAU), sp = r.range(40, 90), life = r.range(0.3, 0.6);
+ if (t > life) return;
+ const [x, y] = fly(0, -8, Math.cos(a) * sp, Math.sin(a) * sp, t, 120, 2);
+ p.px(x, y, at(C.slice(2), 1 - t / life));
+ p.light(x, y, C[4], 0.5 * (1 - t / life));
+ });
+ p.glow(0, -8, 24, C[4], 0.5 * (1 - seg(t, 0, 0.4)));`;
+const src = `import { PAL, ramp, at, ${loop ? "cycle" : "burst, fly, seg, WHITE"}, TAU } from "../../core/index.js";
+
+export const meta = {
+ name: "${name}",
+ desc: "One line: what it is, how it moves.",
+ tags: ["${id.split("/")[0]}"],
+ size: [48, 48],
+ origin: [24, 32],
+ duration: ${loop ? 1.2 : 0.7},
+ loop: ${loop},
+ fps: 30,
+ bg: "dark",
+ options: { palette: PAL.arcane, seed: 1 },
+};
+
+export function draw(p, t, o) {
+${body}
+}
+`;
+mkdirSync(dirname(file), { recursive: true });
+writeFileSync(file, src);
+console.log(`wrote ${file}\nnext: node tools/render.mjs ${id} then look at records/${id}/contact.png`);
diff --git a/tools/render.mjs b/tools/render.mjs
new file mode 100644
index 0000000..bfb2034
--- /dev/null
+++ b/tools/render.mjs
@@ -0,0 +1,57 @@
+#!/usr/bin/env node
+// Render effects so you can look at them.
+//
+// node tools/render.mjs fire/torch contact sheet: records/fire/torch/contact.png
+// node tools/render.mjs fire --gif every fire effect, plus an animated GIF each
+// node tools/render.mjs "magic/portal*" --mp4 --scale 6
+// node tools/render.mjs ui/level-up --all every frame in the contact sheet
+// node tools/render.mjs fire/torch --opts '{"palette":["#102","#215","#43a","#8cf","#fff"]}'
+//
+// Options: --gif --mp4 --sheet (transparent PNG + JSON) --all --max N (frames in the contact sheet)
+// --zoom N (contact sheet scale) --scale N (GIF/MP4) --bg dark|ground|sky|light|black|none --seed N --fps N --opts JSON --out DIR
+// --no-actor --loops N (repeat a loop in the GIF/MP4)
+
+import { join } from "node:path";
+import { ROOT, resolveIds, loadEffect, renderFrames, contactSheet, spriteSheet, writeVideo, save } from "./lib/fxlib.mjs";
+
+const args = process.argv.slice(2), flags = {}, ids = [];
+for (let i = 0; i < args.length; i++) {
+ const a = args[i];
+ if (!a.startsWith("--")) ids.push(a);
+ else if (["gif", "mp4", "sheet", "all", "no-actor"].includes(a.slice(2))) flags[a.slice(2)] = true;
+ else flags[a.slice(2)] = args[++i];
+}
+if (!ids.length) {
+ console.error("usage: node tools/render.mjs <id|category|pattern>... [--gif] [--mp4] [--sheet] [--all]");
+ process.exit(1);
+}
+
+const out = flags.out ?? join(ROOT, "records");
+let failed = 0;
+for (const id of resolveIds(ids)) {
+ try {
+ const fx = await loadEffect(id);
+ const r = renderFrames(fx, {
+ fps: flags.fps ? +flags.fps : undefined,
+ seed: flags.seed ? +flags.seed : undefined,
+ bg: flags.bg,
+ actor: flags["no-actor"] ? false : undefined,
+ options: flags.opts ? JSON.parse(flags.opts) : undefined,
+ });
+ const dir = join(out, id), made = [];
+ made.push(save(join(dir, "contact.png"), contactSheet(fx, r, { max: flags.all ? 400 : +(flags.max ?? 16), zoom: flags.zoom ? +flags.zoom : undefined })));
+ const k = +(flags.scale ?? Math.max(2, Math.min(8, Math.floor(480 / Math.max(r.w, r.h)))));
+ const loops = +(flags.loops ?? (fx.meta.loop ? 2 : 1));
+ if (flags.gif && writeVideo(join(dir, "anim.gif"), r, k, { loops })) made.push(join(dir, "anim.gif"));
+ if (flags.mp4 && writeVideo(join(dir, "anim.mp4"), r, k, { loops: Math.max(loops, fx.meta.loop ? 3 : 1) })) made.push(join(dir, "anim.mp4"));
+ if (flags.sheet) {
+ const name = id.split("/")[1], s = spriteSheet(fx, r, name);
+ made.push(save(join(dir, `${name}.png`), s.png), save(join(dir, `${name}.json`), JSON.stringify(s.json, null, 1)));
+ }
+ console.log(`${id} ${r.n} frames -> ${made.join(" ")}`);
+ } catch (e) {
+ failed++;
+ console.error(`${id} FAILED: ${e.stack ?? e}`);
+ }
+}
+process.exit(failed ? 1 : 0);
diff --git a/tools/serve.mjs b/tools/serve.mjs
new file mode 100644
index 0000000..d7f8af6
--- /dev/null
+++ b/tools/serve.mjs
@@ -0,0 +1,29 @@
+#!/usr/bin/env node
+// Serve the repo so the gallery can load the effects as modules: node tools/serve.mjs [port]
+// then open http://localhost:8080/gallery/
+
+import { createServer } from "node:http";
+import { readFile } from "node:fs/promises";
+import { join, extname, normalize, sep } from "node:path";
+import { ROOT } from "./lib/fxlib.mjs";
+
+const PORT = +(process.argv[2] ?? 8080);
+const TYPES = {
+ ".html": "text/html; charset=utf-8", ".js": "text/javascript; charset=utf-8", ".mjs": "text/javascript; charset=utf-8",
+ ".css": "text/css; charset=utf-8", ".json": "application/json", ".png": "image/png", ".gif": "image/gif",
+ ".svg": "image/svg+xml", ".woff2": "font/woff2", ".md": "text/plain; charset=utf-8", ".mp4": "video/mp4",
+};
+
+createServer(async (req, res) => {
+ let path = decodeURIComponent(new URL(req.url, "http://x").pathname);
+ if (path === "/") return res.writeHead(302, { location: "/gallery/" }).end();
+ if (path.endsWith("/")) path += "index.html";
+ const file = normalize(join(ROOT, path));
+ if (!file.startsWith(ROOT + sep)) return res.writeHead(403).end();
+ try {
+ const body = await readFile(file);
+ res.writeHead(200, { "content-type": TYPES[extname(file)] ?? "application/octet-stream", "cache-control": "no-store" }).end(body);
+ } catch {
+ res.writeHead(404).end("not found");
+ }
+}).listen(PORT, () => console.log(`gallery: http://localhost:${PORT}/gallery/`));
diff --git a/tools/sheets.mjs b/tools/sheets.mjs
new file mode 100644
index 0000000..6263e86
--- /dev/null
+++ b/tools/sheets.mjs
@@ -0,0 +1,23 @@
+#!/usr/bin/env node
+// Export sprite sheets for every effect (or some): sheets/<category>/<name>.png + .json, and sheets/index.json.
+//
+// node tools/sheets.mjs everything
+// node tools/sheets.mjs fire ice some categories
+
+import { writeFileSync } from "node:fs";
+import { join } from "node:path";
+import { ROOT, allIds, resolveIds, loadEffect, renderFrames, spriteSheet, save } from "./lib/fxlib.mjs";
+
+const ids = process.argv.length > 2 ? resolveIds(process.argv.slice(2)) : allIds();
+const out = join(ROOT, "sheets"), index = [];
+for (const id of ids) {
+ const fx = await loadEffect(id), r = renderFrames(fx, { bg: "none" }), name = id.split("/")[1];
+ const s = spriteSheet(fx, r, name);
+ save(join(out, id + ".png"), s.png);
+ save(join(out, id + ".json"), JSON.stringify(s.json, null, 1));
+ const m = fx.meta;
+ index.push({ id, name: m.name, desc: m.desc, tags: m.tags, loop: m.loop, fps: r.fps, frames: r.n, frameSize: m.size, pivot: m.origin, columns: s.json.meta.pixelfx.columns, image: `${id}.png` });
+ process.stdout.write(".");
+}
+if (process.argv.length <= 2) writeFileSync(join(out, "index.json"), JSON.stringify(index, null, 1));
+console.log(`\n${ids.length} sheets -> sheets/`);