244 pixel art effects, every one a small piece of code. Plus a Claude Code skill to make your own.
Rebuild every effect to Sprite Fusion's quality bar
rehan-remade6b570d82f134
diff --git a/.claude-plugin/plugin.json b/.claude-plugin/plugin.jsonindex 57d757c..1ba7302 100644--- a/.claude-plugin/plugin.json+++ b/.claude-plugin/plugin.json@@ -1,7 +1,7 @@{"name": "pixelfx","displayName": "pixelfx",- "version": "0.1.0",+ "version": "0.2.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",diff --git a/README.md b/README.mdindex 4bbeb8d..5c8c89b 100644--- a/README.md+++ b/README.md@@ -4,7 +4,7 @@# pixelfx.-**<!-- count -->299<!-- /count --> pixel art effects and animations, every one a small piece of code.** Fire,+**<!-- count -->232<!-- /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 intoa browser game, or export sprite sheets for any engine. Plus a Claude Code skill that makes new ones the way apicky pixel artist would: draft, render, look, refine.@@ -22,26 +22,26 @@ set the bar. This repo is our take on the idea at library scale, with a skill to<!-- 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… |+| **fire** | 12 | brazier, campfire, candle, fire breath, fire ring, fire tornado… |+| **explosions** | 12 | barrel explosion, big explosion, cartoon pow, dirt explosion, firework burst, firework rocket… |+| **water** | 12 | bubbles, drip, fountain, geyser, rain splash, ripples… |+| **ice** | 10 | blizzard vortex, freeze, frost breath, frost nova, ice crystal, ice lance… |+| **lightning** | 11 | ball lightning, chain lightning, charge up, electrified, lightning strike, plasma ball… |+| **sci-fi** | 12 | emp blast, energy core, force field, glitch, hologram, jetpack… |+| **melee** | 12 | claw swipe, dagger flurry, double slash, hammer smash, heavy cleave, scythe reap… |+| **impacts** | 11 | blunt hit, bullet impact, critical hit, ground slam, heavy landing, hit flash… |+| **projectiles** | 13 | arrow, bullet tracer, cannon shot, energy disc, signal flare, homing missile… |+| **spawn & death** | 10 | coin drop, disintegrate, dissolve burn, egg hatch, poof, respawn beam… |+| **arcane** | 12 | arcane beam, arcane missiles, arcane orb, blink in, blink out, magic circle cast… |+| **holy** | 10 | blessing, divine shield, feather burst, halo, heal, healing ring… |+| **shadow** | 12 | black hole, curse, dark explosion, eclipse, grasping hands, hex sigil… |+| **status** | 13 | bleeding, burning, charmed, confused, cursed, frozen… |+| **nature** | 13 | acid splash, boulder, earth spike, healing bloom, leaf storm, poison cloud… |+| **weather** | 12 | aurora, blizzard, cherry blossoms, clouds, falling leaves, fireflies… |+| **ui** | 12 | achievement, coin collect, combo counter, confetti, countdown, crit number… |+| **pickups** | 11 | chest open, coin spin, collect burst, crystal shard, gem spin, heart pickup… |+| **transitions** | 10 | blinds, burn away, crt off, diamond wipe, glitch wipe, iris… |+| **critters** | 12 | bat, bird, butterfly, eyeball, fish school, flying skull… |<!-- /catalog -->Every effect is a file in `src/fx/<category>/<name>.js`. The [catalog](docs/CATALOG.md) lists them all.diff --git a/docs/AUTHORING.md b/docs/AUTHORING.mdindex 76e7601..f9b97ce 100644--- a/docs/AUTHORING.md+++ b/docs/AUTHORING.md@@ -1,154 +1,141 @@# 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.+An effect is one file, `src/fx/<category>/<name>.js` (kebab-case), drawing pixel art over time into two buffers.+It has no images and no dependencies beyond `src/core`. It can be played live, recolored, mirrored and rendered+to a sprite sheet for any engine.++The quality bar is Sprite Fusion's open-source pixel art VFX by Hugo Duprez+([spritefusion.com/pixel-art-vfx](https://www.spritefusion.com/pixel-art-vfx), MIT). Every effect here should hold up+next to his at the same size on screen: as much detail, as much light, as much life. `src/core/sim.js` is adapted+from his code; read the three references written to that bar first: `src/fx/melee/sword-slash.js`,+`src/fx/ice/frost-nova.js`, `src/fx/explosions/small-explosion.js`.++## Two kinds of effect++**Simulated** (most one-shots: impacts, explosions, spells, anything with debris, sparks, smoke or fire). Export+`create(o)` returning `{ update(dt), draw(p), drawBack?(p) }`. Spawn particles, debris and lights in `create` and+`update`, keep your own `t`, draw from state. The runtime steps it at 120 Hz or finer, so physics looks the same at+any frame rate. Use the seeded `Rng` from `o.seed` for every random number.```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);+import { Particles, Lights, P, PF, Rng, fit, sparkle, smooth } from "../../core/index.js";++export const meta = { name: "Spark pop", desc: "...", tags: ["impact"], size: [96, 72], origin: [48, 56],+ duration: 1.2, loop: false, fps: 30, bg: "ground", options: { palette: [...], seed: 1 } };++export function create(o) {+ const C = fit(o.palette, 7), R = new Rng(o.seed), floor = () => 0;+ const ps = new Particles({ rng: R, ground: floor }), lights = new Lights();+ lights.add(0, -12, 40, C[4], 0.7, 0.4);+ for (let i = 0; i < 40; i++) {+ const a = R.range(0, Math.PI * 2), sp = R.range(80, 260);+ ps.spawn(P.SPARK, 0, -12, Math.cos(a) * sp, Math.sin(a) * sp - 60, R.range(0.2, 0.6));+ }+ let t = 0;+ return {+ update(dt) { t += dt; ps.update(dt); lights.update(dt); },+ draw(p) { if (t < 0.12) sparkle(p, 0, -12, 9 * (1 - t / 0.12), C[5], C[3]); ps.draw(p); lights.draw(p); },+ };}```+**Pure** (loops, and shapes that are a function of time: auras, portals, waterfalls, beams, critters). Export+`draw(p, t, o)` (and `drawBack(p, t, o)`): the frame at `t` from `t` alone, so it loops with no seam. Particles+that loop come from `cycle`, motion from `fly`, noise from `loopNoise`/`tileFbm`.+## 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.+- **Scale.** The stock character is 24 x 38 px (`actor: 2`): every effect is drawn at that scale, detail at the+ 1 px level. Canvases are as big as the effect needs, often 96 to 320 px wide; transitions are 320 x 180.+- **Local coordinates.** (0, 0) is the anchor: the feet of the character, the point of impact, the base of a+ torch, the muzzle. x right, y down, 1 unit = 1 px. The painter places, mirrors (`flip`) and rotates (`angle`).+ Directional effects face right. Ground effects stand on y = 0, the floor; floor rings, cracks, scorch and+ puddles may draw a little below it as perspective.+- **Time.** One-shots run 0..duration and draw **nothing at t = duration** (set duration long enough for the last+ smoke to clear). Loops are seamless.+- **Options** `o`: `meta.options` merged with the caller's. Honour `o.palette` (main ramp, dark to bright; use+ `fit(o.palette, n)` so any length works) and `o.seed`. Other color ramps as options are resampled too.+ `x`, `y`, `flip`, `angle`, `light` are reserved.+- **Deterministic.** Never `Math.random()` or `Date`.+- **Layers.** `drawBack` for what's behind a character or the far half of a ring; `draw` for the rest.+- **Actor effects** (`actor: 2`) get `o.actor = { mask, pixels, x, y, w, h, head, chest }`: the character's+ silhouette and its own colors (`pixels`, a Uint32Array, 0 where empty) in local space, feet at (0, 0). Recolor+ `pixels` for frozen, poisoned, stone; outline `mask` for auras. Export `actorAlpha(t, o)` (0..1) when the+ character should vanish or appear; previews follow it.+- **Credit.** If you adapt a specific recipe from one of Hugo's files, put a two-line credit at the top of yours:+ `// ... adapted from Sprite Fusion's open-source <name> (https://www.spritefusion.com/pixel-art-vfx/<name>),`+ `// MIT License, Copyright (c) 2026 Hugo Duprez.`++## The toolkit (`src/core/sim.js`, from Sprite Fusion's code)++- `new Particles({ rng, ground: (x) => floorY, sparks: [head..tail colors], haze: color, onLand })`,+ `ps.spawn(kind, x, y, vx, vy, life, color, size, delay, flags)`, `ps.update(dt)`, `ps.draw(p, "back"|"front")`.+ Kinds `P.*`: `SPARK` (speed-stretched two-tone streak, gravity, bounces on the floor, glows), `MOTE` (streak+ with a dark tail, dithers out), `STREAK` (accelerating dotted line: gathering energy), `FLAKE` (drifting+ speck, a cross when big), `VAPOUR` (soft translucent puff that swells and thins, optional haze glow), `DUST`+ (denser puff), `SMOKE` (three soft discs, lit cap, rises and sways; color 0 uses `SMOKE_RAMP`), `FIRE`+ (a ball of flame cooling down `FIRE_RAMP` as it rises; flag `PF.SMOKES` turns it to smoke when it dies,+ `PF.BIG` for bigger slower smoke), `BRAND` (burning chunk that trails flame and calls `onLand`), `GRIT`+ (falling bits that bounce once and settle), `EMBER` (rising, wandering, cooling), `STAR` (twinkling cross).+ `PF.BACK` draws a particle behind. `delay` holds it back.+- `new Bits({ ground })`, `bits.add({ kind: B.SHARD|B.CHUNK|B.DRIP, x, y, vx, vy, a, va, s, c, ramp, g, drag,+ bounce, life })`: rigid debris that tumbles, bounces and settles (`rest`).+- `new Lights()`, `lights.add(x, y, r, color, k, life)`: lights that flare and die (k falls with life²).+- `new Blazes(ps)`, `blazes.add(x, y, life, power)`: small fires that keep feeding flame where something landed.+- `sparkle(p, x, y, arm, c, tip, k)` star glint; `flare(p, x, y, L, k, ramp)` 8-ray flare;+ `band(p, cx, cy, r, sy, thick, alpha, ramp, keep, hot)` a ring on a tilted plane (sy 0.16 lies on the floor;+ keep `(g) => Math.sin(g) < 0` is the far half); `crystal(p, x, base, h, w, lean, ramp, { a, white, glint })` a+ faceted ice/crystal spike with a lit ridge.+- `GRAVITY` = 950 px/s². Hugo's code uses world units (2 per px): halve his speeds, distances and gravity.## 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.+Coordinates local, floats fine. `c` a color number; `a` alpha 0..1 (dithered unless said).| 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).+| `p.px(x, y, c)` / `p.dot(x, y, c, a)` | one pixel, solid / dithered |+| `p.blend(x, y, c, a)` | one pixel, truly translucent |+| `p.disc(x, y, r, c, a)` | translucent disc (smoke, vapour, mist); c, a may be `(d, angle) =>` |+| `p.line(x0, y0, x1, y1, c, a)` | 1 px line; c, a may be `(u) =>` |+| `p.polyline(pts, c, a)`, `p.beam(x0, y0, x1, y1, w, c, a)` | lines through points; thick capsule |+| `p.circle`, `p.ellipse`, `p.ring`, `p.rect`, `p.poly`, `p.tri` | filled shapes; c, a may be functions of the shape's coordinates |+| `p.arc(x, y, r, w, a0, a1, c, a)` | band of a ring, `w` may taper `(u) =>` |+| `p.shade(x0, y0, x1, y1, fn)` | per-pixel shader: `fn(x, y, out)` returns a color or sets `out.c out.a out.l out.k`; x, y are pixel centers |+| `p.glow(x, y, r, c, k)`, `p.glowLine`, `p.glowRing`, `p.light(x, y, c, k)` | additive light |+| `p.sprite(rows, pal, x, y, {scale, a, flip, flipY, tint})` | sprite from strings |+| `p.text(str, x, y, c, {font, scale, align, outline, shadow, a})`, `p.measure` | pixel text (`mini` 3x5, `big` 5x7; use `scale: 2` at this size) |+| `p.mask(m, x, y, c, a)`, `p.outline(m, x, y, c, a)`, `p.get(x, y)` | silhouettes; read back a pixel |++Helpers from `src/core/index.js`: `clamp lerp seg smooth bump ease.* TAU`, `Rng rng rand`, `noise noise2 fbm+loopNoise tileNoise tileFbm`, `fly flyV burst cycle stream`, `bolt forks star ngon trail`, `PAL RAMP ramp fit at+blend mix scale hex rgb luma WHITE`, `stockActor(2) drawActor HERO2 HERO_PAL`.## 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.+What makes Sprite Fusion's effects good, and what every effect here must do:++1. **Lines and light, not fills.** Build with 1 px rims, rings, trails and sparks, and let light carry the+ brightness. A big flat area of saturated color is almost always wrong. White-hot cores and edges, tinted+ middles, deep color only in shadow.+2. **Light everywhere.** A big soft pool at low k, a tight hot one at the core, a light on every spark and+ glint, `Lights` that flare at the moment of impact and fall away, light along arcs and beams, a warm or cold+ pool on the floor while something burns or freezes.+3. **Translucent volumes.** Smoke, vapour, dust and mist are soft (`SMOKE`, `VAPOUR`, `DUST`, `p.disc`), lit on+ top, swelling and thinning. Never a dithered checkerboard for smoke.+4. **Real motion.** Sparks stretch with speed, fall and bounce. Debris tumbles, bounces, settles and fades.+ Fire rises and cools into smoke. Things that land kick up dust. Use drag: fast burst, slow drift.+5. **Choreography in phases.** Anticipation or charge (things gathering in), release (a 1 to 2 frame white+ hero frame, a flare, light, a burst), spread, hold (twinkles, glints, embers), break or melt, a long decay.+ Many small events, each varied in size, speed, timing and life.+6. **Depth.** Rings on the floor are flat ellipses with a far half behind the character and a near half in+ front. Back rows of crystals or flames are dimmer.+7. **Timing.** Fast attack, slow release. Big effects linger 2 to 4 s while smoke clears and sparkles fade;+ hits are snappy (0.3 to 0.8 s) but still have follow-through.+8. **Reads at 1x** with a clear focal point, no speckle noise inside shapes.+9. **Original.** Generic motifs fine; never a specific game's sprite, character or logo. Don't copy one of+ Hugo's effects wholesale: use his techniques, make the design your own.+10. **Clean.** Fits its canvas, ends empty or loops clean, deterministic, under 2 ms a frame (`tools/check.mjs`).## The method@@ -156,14 +143,12 @@ The method is Hugo Duprez's ([How to make (good) pixel art effects withClaude](https://www.spritefusion.com/blog/how-to-make-good-pixel-art-effects-with-claude)): code is clay, trustyour 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.+1. **Reference first.** Find the closest of his effects (`~/patch/pixelfx-ref/sheets/`), look at it, read its+ source (`~/patch/pixelfx-ref/src/<name>.ts`) for the choreography and numbers.+2. **Say it in one line** with the art direction, then draft.+3. **Render and look**: `node tools/render.mjs <id> --zoom 3` (contact sheet in `records/<id>/contact.png`;+ `--all` every frame, `--mp4` motion).+4. **Benchmark**: `node ~/patch/pixelfx-ref/tools/compare.mjs <out.png> <hisSpec> <id> --theirs ... --ours ...`+ puts his and yours at the same height. If his has more detail, light or life, yours isn't done.+5. **Fix the worst thing, render again.** Three rounds minimum; showpieces take more.+6. **Check**: `node tools/check.mjs <id>` until it passes clean.diff --git a/docs/CATALOG.md b/docs/CATALOG.mdindex ad7e73c..74553bb 100644--- a/docs/CATALOG.md+++ b/docs/CATALOG.md@@ -1,6 +1,6 @@# Catalog-299 effects in 20 categories. Every one is a file in+232 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@@ -9,23 +9,18 @@ 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. |+| Brazier | `fire/brazier` | loop 3s | 112×148 | An iron bowl on a tripod heaped with glowing coals and a big roaring fire, sparks and embers streaming up off it, light on the iron and the floor. |+| Campfire | `fire/campfire` | loop 3s | 128×128 | Crossed logs on a bed of coals and a lively fire: tongues that lick and leap, popping sparks, embers drifting up, smoke curling off, a warm pool of light. |+| Candle | `fire/candle` | loop 4s | 56×76 | A wax candle in a brass dish: a calm flame with a blue root that sways and stretches, a halo of light, motes drifting in it, a bead of wax running down a drip. |+| Fire breath | `fire/fire-breath` | loop 1.5s | 160×116 | A roaring cone of fire streaming right from the mouth: white-hot at the lips, billowing out and cooling to red and smoke at its edges, sparks thrown out ahead. |+| Fire ring | `fire/fire-ring` | one-shot 3.9s | 224×128 | A white flash at the feet, then flames race outward along the floor in a ring, flaring as the front passes and burning down behind it over a smouldering scorch. |+| Fire tornado | `fire/fire-tornado` | loop 2s | 120×152 | A spinning funnel of fire: spiral bands turning round it, licks flung off its sides, a ring of flame whirling at its foot, embers orbiting it in and out of view. |+| Fireball | `fire/fireball` | loop 1.2s | 136×56 | A fireball flying right: a churning white-hot head with a corona of flame, a long torn tail of flame puffs cooling into smoke, embers shed behind. |+| Flame pillar | `fire/flame-pillar` | one-shot 5s | 184×256 | The floor cracks and glows, a column of fire erupts white-hot and roars, spewing embers and shedding flame, then collapses into rolling smoke. |+| Flamethrower | `fire/flamethrower` | loop 1.6s | 184×104 | A pressurised jet shooting right: a blue pilot at the nozzle, a tight stream with surges racing down it, a sputter, burning drops falling off, a tip that curls up into smoke. |+| Meteor | `fire/meteor` | one-shot 5s | 272×232 | A burning rock streaks in from the upper left in a comet of fire and smashes into the floor: a white flash, a fireball, rocks and brands thrown, a glowing crater that cools. |+| Spirit flame | `fire/spirit-flame` | loop 3s | 80×124 | A cold blue-teal ghost fire floating in the air: a bright rim round a hollow dark heart, a wave climbing its wispy tail, curls breaking off, cold sparks rising. |+| Torch | `fire/torch` | loop 2s | 72×120 | A wall torch on an iron bracket: a licking flame leaping off a pitch-soaked wrap, licks and puffs torn off its tips, smoke, embers, a flickering light on the wall. |## explosions@@ -33,22 +28,18 @@ 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. |+| Barrel explosion | `explosions/barrel-explosion` | one-shot 5.2s | 300×240 | An explosive barrel shudders, its lid bulging and spitting flame, then blows: a fireball column, staves and the lid flying, burning fuel splashed over the floor. |+| Big explosion | `explosions/big-explosion` | one-shot 7.2s | 360×300 | A huge ground blast in three beats: a white dome, a rolling fireball that climbs into a mushrooming smoke column, heavy rocks, and fires left burning. |+| Cartoon POW | `explosions/cartoon-pow` | one-shot 1.05s | 184×144 | A comic-book hit: a jagged two-tone burst star slams in with a shake and boiling edges, POW! drops in letter by letter, action lines fly, then it all snaps away. |+| Dirt explosion | `explosions/dirt-explosion` | one-shot 3.6s | 260×240 | A buried charge goes off: a flash under the floor, a V of dirt clods and grit thrown high, a brown dust plume that billows and settles, and a crater left behind. |+| Firework burst | `explosions/firework-burst` | one-shot 3.6s | 240×248 | A shell climbs, slows and bursts into a sphere of coloured trailing stars round a gold core; they droop, crackle into white pops and fade, leaving glitter. |+| Firework rocket | `explosions/firework-rocket` | one-shot 3.8s | 300×300 | A rocket fizzes off the ground on a sparkling gold trail, coasts, and bursts into a palm: heavy gold fronds arc out, droop on glittering trails and crackle at the tips. |+| Grenade | `explosions/grenade` | one-shot 4.2s | 300×200 | A grenade is lobbed in, bounces, rolls to a stop with its fuse fizzing, shudders, then blows: a white flash, shrapnel streaks, sparks, a small fireball and a scorch. |+| Implosion | `explosions/implosion` | one-shot 1.65s | 208×184 | Everything is sucked in: streaks and grit rush inward, rings contract and a dark sphere collapses onto a crushed white point; a beat of stillness, then a sharp pop. |+| Nuke | `explosions/nuke` | one-shot 9s | 400×320 | A blinding white frame, then a fireball lifts on a thin stem into a wide rolling cap that glows from inside; a white skirt flashes and a dust surge sweeps the floor. |+| Plasma explosion | `explosions/plasma-explosion` | one-shot 1.7s | 224×200 | A blue-violet energy blast with no smoke: a white flash, a ball of plasma swelling into a thinning shell, shock rings in and out of depth, lightning arcs crackling off it. || Explosion | `explosions/small-explosion` | one-shot 5.4s | 300×240 | A ground blast: a white flash and shock rings, fire that cools into a rolling smoke column, sparks, burning brands that land and keep burning, tumbling rocks and a glowing scorch. |-| 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. |+| Smoke bomb | `explosions/smoke-bomb` | one-shot 5s | 260×176 | A round canister clinks down, fuse sparking, and pops: thick grey-violet smoke gushes out, rolls along the floor, billows into a cloud that hides all, then thins to wisps. |## water@@ -56,21 +47,18 @@ 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. |+| Bubbles | `water/bubbles` | loop 4s | 104×112 | Bubbles stream up from a vent of pebbles, wobbling and swelling as they rise, flare as they cross shafts of light from the surface, then dome up and pop there. |+| Drip | `water/drip` | loop 1.6s | 72×88 | A bead swells under a wet stone tip and catches the light, pinches off, falls stretched by its speed and plinks into a puddle with a crown, a ring and a tiny rebound. |+| Fountain | `water/fountain` | loop 2s | 120×104 | A stone basin; a jet rises from its spout and blooms into glassy arcs that break into beads, fall back and plink into the water with rings. |+| Geyser | `water/geyser` | one-shot 5s | 184×168 | A pool heaves and burbles faster and faster, then blasts a white column of water skyward with a churning foam head; it rains back down in drops and steam, slumps and sputters out. |+| Rain splash | `water/rain-splash` | loop 2.4s | 176×80 | A low close-up on one puddle in the rain: big drops land in crowns that throw beads and a rebound jet, rings spread and interfere, a lamp's reflection wobbles on the water. |+| Ripples | `water/ripples` | loop 2s | 136×52 | A drop plinks on still dark water and rings spread out across it at a low angle: the swell of each ring catches the light, crests glint, and they fade into the calm. |+| Splash | `water/splash` | one-shot 2.5s | 176×100 | A stone drops into still water: a white hit, a crown that tears into droplets arcing out to plink down with rings, a jet that bounces back, foam and drifting mist. |+| Water jet | `water/water-jet` | loop 1s | 188×80 | A pressurised stream blasts right: a tight glassy rod with surges running down it that swells, roughens, bends under its weight and breaks into chunks, spray and mist. |+| Water orb | `water/water-orb` | loop 3s | 100×108 | A sphere of water floats and wobbles: a current circles inside it, the floor shows upside down through it, it shines, light gathers on the floor under it, and drips fall and plink. |+| Waterfall | `water/waterfall` | loop 2s | 144×136 | A river pours from a notch in a rock outcrop: a white curl, a deep sheet that splits into strands, churning foam, spray, drifting mist and rings on a dark pool. |+| Wave crash | `water/wave-crash` | one-shot 3.2s | 224×104 | A swell rolls in and steepens, its lip throws forward and curls over a dark barrel, then crashes into a burst of white foam and spray that surges on and fades to lace. |+| Whirlpool | `water/whirlpool` | loop 3s | 128×84 | Seen from above, dark water winds into a vortex: foam arms spiral in, darkening as they're drawn down into a deep eye with a lit far rim, flecks of foam circling in after them. |## ice@@ -78,19 +66,16 @@ 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. |+| Blizzard vortex | `ice/blizzard-vortex` | loop 2s | 128×116 | A swirling snow tornado: wind bands spin up a leaning funnel, flakes and ice crystals orbit in front and behind, snow boils at its foot and cold light fills its throat. |+| Freeze | `ice/freeze` | one-shot 4s | 176×128 | Frost races in and climbs the character, turning it to ice; a faceted block crystallizes round it pane by pane, glints, cracks and bursts, and the character thaws free. |+| Frost breath | `ice/frost-breath` | loop 1.2s | 184×104 | A cone of icy wind blowing right: frost puffs billow out, swell and sink, wind streaks race through, ice crystals tumble and glint off a white-hot mouth. || Frost nova | `ice/frost-nova` | one-shot 3.4s | 288×192 | Frost spirals into a spinning snowflake, then a wave blooms three rings of ice crystals round the caster; snow drifts, frost creeps, and the ice melts back into the floor. |-| 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. |+| Ice crystal | `ice/ice-crystal` | loop 3s | 96×100 | A floating ice crystal turning slowly in its own cold light: its facets brighten and darken as they turn, glints flash on them, frost motes circle it. |+| Ice lance | `ice/ice-lance` | loop 0.8s | 176×64 | A faceted ice spear flying right: a light pulse runs through its core, rings of cold air shear off the tip, frost peels off into a wake and crystals shed behind it. |+| Ice shatter | `ice/ice-shatter` | one-shot 2.8s | 224×112 | A block of ice takes a hit from the left: it jolts, cracks race over its faces, it flashes white and bursts into chunks that tumble, bounce and skid off in a roll of ice dust. |+| Ice spikes | `ice/ice-spikes` | one-shot 3s | 264×112 | A frost line races along the floor and clusters of jagged ice blades burst up behind it in a rising wave, glint, flash white together and shatter into toppling shards. |+| Icicle fall | `ice/icicle-fall` | one-shot 2.6s | 152×120 | An icicle drips and trembles, snaps off its frosted root, drops, stabs the floor and bursts into skidding shards, splinters and rolling frost. |+| Snowflake burst | `ice/snowflake-burst` | one-shot 3.2s | 140×120 | A cold pop: frost gathers and flashes white in a ring, then crisp six-armed snowflakes spin out, slow, twinkle and drift down to settle and melt. |## lightning@@ -98,20 +83,17 @@ 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. |+| Ball lightning | `lightning/ball-lightning` | loop 4s | 136×104 | A crackling ball of plasma drifts on a wandering loop, spitting arcs off its skin and leaving a wake of fading motes, and zaps the floor when it dips low. |+| Chain lightning | `lightning/chain-lightning` | one-shot 1.8s | 248×104 | A bolt leaps from the caster's hand through three targets in turn; each flashes, sparks and grounds itself to the floor while the arcs between them flicker, then the chain snaps. |+| Charge up | `lightning/charge-up` | one-shot 2.7s | 272×184 | Sparks streak and arcs whip in to a crackling core at the caster's hand that swells and pulses faster, then it flashes and bursts: bolts every way, a ring, a spray of sparks. |+| Electrified | `lightning/electrified` | loop 2s | 108×92 | Current runs through a character: arcs crawl over and leap across the body, sparks spit off, the body flares to an electric silhouette on each jolt, and the feet ground out. |+| Lightning strike | `lightning/lightning-strike` | one-shot 3s | 240×264 | A targeted strike: a sigil charges on the floor, the scene darkens, a thick bolt slams into it, arcs race out along the cracks it splits, the channel crumbles to a scorch. |+| Plasma ball | `lightning/plasma-ball` | loop 3s | 112×104 | A glass globe on a dark pedestal: wandering plasma tendrils reach from the core to the glass and fan out in bright feet where they touch it, lighting the stand and floor. |+| Spark arc | `lightning/spark-arc` | loop 2s | 124×120 | A climbing arc between two rods: it strikes white at their narrow foot, climbs on rising heat as it stretches and bows, sputters and snaps at the top, then strikes again. |+| Storm cloud | `lightning/storm-cloud` | loop 3s | 168×176 | A storm cloud boils overhead, billows lit from inside by flickering discharges, ragged scud under its flat dark base; rain slants down and once a loop a bolt cracks to the floor. |+| Tesla coil | `lightning/tesla-coil` | loop 2.4s | 224×136 | A copper coil under a steel torus throws branching arcs that lash out in volleys and now and then strike the floor in a spray of sparks, lighting the metal and the ground. |+| Thunderclap | `lightning/thunderclap` | one-shot 1.9s | 288×156 | A thunderclap round the caster: a white flash, forked bolts burst out and stab the floor, a heavy shock ring tears across the ground raising dust and grit, sparks streak away. |+| Zap hit | `lightning/zap-hit` | one-shot 0.9s | 144×112 | A contact zap: an arc snaps in from the left, the hit point overloads into a knot of tiny crackling zigzags, a fern of burn marks glows outward, sparks jink away, ozone puffs. |## sci-fi@@ -119,21 +101,18 @@ 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. |+| EMP blast | `scifi/emp-blast` | one-shot 3.2s | 152×116 | A disc charge ticks, pops white, and a bubble of rolling scanlines swells out with arcs crawling its skin; it strobes, tears and shorts out into falling dead pixels. |+| Energy core | `scifi/energy-core` | loop 2.4s | 112×100 | A plasma core beating in a steel cage: it swells and throws a shock ring on each beat, two tilted rings orbit it, and arcs jump to the bars and spark. |+| Force field | `scifi/force-field` | loop 2.4s | 184×104 | A glassy dome of hex plates over the hero: plates glint, tracers from the right slam into it, a ripple and cracks of light race across, sparks glance off. |+| Glitch | `scifi/glitch` | loop 2.4s | 88×64 | The hero's signal breaks up in bursts: an RGB split, slices torn sideways, rows smeared out, junk blocks and dead pixels, then snaps back clean. |+| Hologram | `scifi/hologram` | loop 4s | 112×104 | A floor projector throws a cone of light holding a turning wireframe model: scanlines roll through it, a data ring circles it, and it flickers, tears and jitters. |+| Jetpack | `scifi/jetpack` | loop 2s | 96×116 | Twin thrusters fire straight down: white-hot cores with shock diamonds inside ragged flames, puffs that cool into smoke billowing below, lit by the fire. |+| Laser grid | `scifi/laser-grid` | loop 3s | 128×84 | Security lasers between two steel posts: red beams slide and scissor across, dust and haze light up only where they cut through, and the floor sweepers scorch and spark. |+| Scanner | `scifi/scanner` | loop 3.2s | 112×78 | Brackets snap onto the hero, a scan line sweeps head to toe leaving a cooling outline, and a readout counts up to OK before it all lets go. |+| Teleporter pad | `scifi/teleporter-pad` | loop 2.4s | 96×104 | A steel pad glows on the floor, its rings rippling outward; a soft column of light rises off it and rings of light lift away, sparkles drifting up through them. |+| Tractor beam | `scifi/tractor-beam` | loop 3s | 120×132 | A hovering pod projects a cone of light to the floor; rocks tear loose in puffs of dust and spiral up spinning into the lens while rings of light climb the beam. |+| Warp in | `scifi/warp-in` | one-shot 3s | 192×168 | A beam slams down, rings run down it and a scanline paints the hero in from head to toe, white-hot pixels cooling to their own colors; the beam pinches shut in sparks. |+| Warp out | `scifi/warp-out` | one-shot 2.6s | 128×168 | The hero's outline flickers on, they flash white and break into light from the head down, streaming up a beam that lifts off the floor and pinches shut. |## melee@@ -141,22 +120,18 @@ 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. |+| Claw swipe | `melee/claw-swipe` | one-shot 0.9s | 128×96 | Three claw marks rake down one after another, white-hot, cooling through orange to red, then close up from both ends and leave a dotted scar, with hot flecks and drips. |+| Dagger flurry | `melee/dagger-flurry` | one-shot 0.95s | 148×104 | A flurry of small quick crescents at every angle in front of the fighter, each with a flick of sparks, finished by one big cut that glints and bursts. |+| Double slash | `melee/double-slash` | one-shot 0.8s | 164×108 | A down cut, then an up cut that crosses it: the moment the X closes both strokes flash white, the crossing bursts with light and sparks, and a dotted X lingers. |+| Hammer smash | `melee/hammer-smash` | one-shot 2s | 208×112 | A hammer drops in front in a wedge of motion: a white slam with rays, a dome of force, a dent with cracks, rocks thrown up that bounce and settle, and dust. |+| Heavy cleave | `melee/heavy-cleave` | one-shot 1.9s | 208×116 | A glint over the head, then a thick ember arc accelerates over the top into the floor: a white slam, glowing cracks, dust rolling both ways, grit and rising embers. |+| Scythe reap | `melee/scythe-reap` | one-shot 2.1s | 184×116 | A slow, huge dark crescent reaps round the front with a pale ghostly edge; it hangs, then tears away from the tail into curling wisps and cold vapour. |+| Spear sweep | `melee/spear-sweep` | one-shot 1.5s | 216×84 | A wide low sweep at shin height: a long flat crescent swings from behind the legs round the front, and the wind of it kicks a wake of dust and grit along the floor. |+| Spin slash | `melee/spin-slash` | one-shot 0.8s | 208×104 | The blade whirls once round the waist on a tilted plane, behind the body and back in front; the closed ring flares white, dissolves into a dotted trace and throws sparks. || Sword slash | `melee/sword-slash` | one-shot 0.75s | 136×104 | A tilted crescent whips round in two frames, cools from white to deep blue as it trails off, glints at the tip and throws sparks. |-| 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. |+| Thrust | `melee/thrust` | one-shot 0.75s | 196×76 | A piercing stab: a bundle of streaks shoots out from the hand to a point, a long four-point star flares at the tip with a pierce ring, sparks and speed lines. |+| Uppercut | `melee/uppercut` | one-shot 0.85s | 132×128 | A crescent rises from the floor past the face, and at the top a comic impact star bursts: bold outline, hot core, burst lines, twinkles and sparks. |+| Whip crack | `melee/whip-crack` | one-shot 0.85s | 192×80 | A whip rolls out to the right as a loop running down its length, faster and faster, until the tip flips over and cracks: a white pop, a ring of air, sparks and a puff of smoke. |## impacts@@ -164,20 +139,17 @@ 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. |+| Blunt hit | `impacts/blunt-hit` | one-shot 0.9s | 128×88 | A heavy, soft thud: a white-hot lumpy blob cools to cream in a warm pool of light, inked wedges jab out and snap back, a squashed ring of dust puffs swells and drifts, clods drop. |+| Bullet impact | `impacts/bullet-impact` | one-shot 1.4s | 152×100 | A bullet hits a wall on the right: a hot half-star, sparks sprayed back in a cone, a puff of grit, chips that fall and bounce, a pock mark cooling to soot. |+| Critical hit | `impacts/crit-hit` | one-shot 0.9s | 216×136 | A critical hit: a jagged starburst slams in white and overshoots, a ring breaks into flying arcs, sparks streak off, shards tumble to the floor under a big flare. |+| Ground slam | `impacts/ground-slam` | one-shot 3.2s | 288×208 | Something lands hard: the floor flashes and cracks, two crescent shock waves race out along it, a dust wave and a tall dust cloud rise, rocks erupt, bounce and settle. |+| Heavy landing | `impacts/heavy-landing` | one-shot 1.6s | 176×80 | A character lands hard: the floor dents and cracks under their feet, two rings of dust roll out along the floor one after the other, and pebbles hop away. |+| Hit flash | `impacts/hit-flash` | one-shot 0.5s | 80×64 | The character takes damage: a white frame, then their own colors flushed red and blinking white, cooling off, while comic hit lines jab in at them. |+| Hit spark | `impacts/hit-spark` | one-shot 0.5s | 136×80 | The everyday hit: a sharp, lopsided cross flare with one long ray along the blow round a white diamond core, then a cone of sparks and hot chips that fall and bounce. |+| Impact frame | `impacts/impact-frame` | one-shot 0.3s | 320×180 | An anime impact: two frames of white with black burst lines rushing at the hit, two frames inverted, then the lines pull out past the edges and vanish. |+| Parry | `impacts/parry` | one-shot 1s | 200×112 | Two blades clash: their edges flash in an X, a white four-point star rings out, a ring breaks into arcs and a fan of gold sparks sprays up and rains down. |+| Ricochet | `impacts/ricochet` | one-shot 1.1s | 232×84 | A tracer streaks down onto the floor, glances off with a white-hot star and skips away at an angle, leaving a glowing skid while sparks skitter along the ground. |+| Shield block | `impacts/shield-block` | one-shot 1.1s | 148×104 | A blow is caught on a half-dome of energy in front of the character: its diamond lattice flashes, a ripple runs over it, sparks glance off, then it blinks out cell by cell. |## projectiles@@ -185,23 +157,19 @@ 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. |+| Arrow | `projectiles/arrow` | loop 0.6s | 112×32 | An arrow in flight: a steel broadhead catching the light, a wooden shaft, fletching fluttering in the wind, streaks of air peeling off its head and swirling off its feathers. |+| Bullet tracer | `projectiles/bullet-tracer` | loop 0.6s | 200×40 | A white-hot slug tearing along, its tracer burning behind it in a long streak that sputters and cools from white through gold to red, shedding sparks and a thread of smoke. |+| Cannon shot | `projectiles/cannonball` | one-shot 3.8s | 208×116 | A cannon fires from a muzzle `height` px above the floor (the origin): a white flash, a tongue of flame, the ball arcing off trailing smoke, a big gunsmoke cloud rolling out. |+| Energy disc | `projectiles/energy-disc` | loop 0.5s | 120×52 | A sawblade of crackling energy spinning flat out as it flies: hooked teeth bright on their leading edges, a white hub, spiral arms churning, sparks flung off the teeth. |+| Signal flare | `projectiles/flare` | one-shot 5s | 152×232 | A signal flare streaks up off the ground trailing sparks and smoke, bursts, and hangs as a pulsing red star that drips sparks under its own red-lit smoke, then gutters out. |+| Homing missile | `projectiles/homing-missile` | one-shot 3.8s | 248×140 | A missile kicks off, arcs up, rolls over and dives onto its target (the origin), its smoke trail left hanging in the air, and hits in a fiery blast of flame, sparks and rocks. |+| Laser bolt | `projectiles/laser-bolt` | loop 0.5s | 128×32 | A red laser bolt: a white-hot core in a rounded head, red bands tapering back, pulses racing down it, a tail that shimmers apart into wavering dashes. |+| Magic missile | `projectiles/magic-missile` | one-shot 1.9s | 208×112 | Motes gather into an arcane orb at a hand `height` px above the floor (the origin); it weaves to its target trailing a twisting ribbon and bursts into a star of light. |+| Pistol shot | `projectiles/muzzle-pistol` | one-shot 1.8s | 96×72 | One pistol shot from a muzzle `height` px above the floor (the origin): a spiky white-cored flash, sparks, a curl of smoke hooking up and back, a casing that bounces and settles. |+| Shotgun blast | `projectiles/muzzle-shotgun` | one-shot 3.2s | 160×88 | A shotgun blast from a muzzle `height` px above the floor (the origin): a wide ragged fan of flame, pellet streaks, a heavy rolling smoke cloud, a red shell kicked out on the pump. |+| SMG burst | `projectiles/muzzle-smg` | loop 1s | 112×72 | Sustained fire at twelve rounds a second: each shot a different spiky flash with a white core, sparks, smoke wisps piling up and drifting, brass casings bouncing on the floor. |+| Plasma shot | `projectiles/plasma-shot` | loop 0.8s | 144×60 | A glowing plasma blob: hot knots churning in its core, a corona crackling over its skin, its tail necking into droplets that tear off, cool and wink out behind. |+| Rocket | `projectiles/rocket` | loop 1.2s | 288×76 | A steel rocket roars along: a flickering jet with shock diamonds and a white-hot nozzle, a thick billowing smoke trail lit by the flame, sparks shed behind. |## spawn & death@@ -209,19 +177,16 @@ 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. |+| Coin drop | `spawn/coin-drop` | one-shot 3s | 160×88 | An enemy goes up in a soft poof and gold coins spin out of it, bounce with a glint on each hit, settle on the floor, twinkle, and wink out one by one. |+| Disintegrate | `spawn/disintegrate` | one-shot 3.4s | 176×100 | The character crackles with light, flashes white, then peels away from the head down: each pixel flares white-hot and streams off on the wind as a cooling mote of light. |+| Dissolve burn | `spawn/dissolve-burn` | one-shot 3.6s | 96×112 | An ember seam lights at the feet and climbs the body: above it the body scorches and smoulders, at it flames lick up, below it there's only falling ash, embers and smoke. |+| Egg hatch | `spawn/egg-hatch` | one-shot 3.1s | 120×96 | A speckled egg rocks three times, each rock cracking it further with warm light leaking out, then pops: light pours out of the opening and lit shell halves tumble away. |+| Poof | `spawn/poof` | one-shot 1.6s | 112×92 | A cartoon death poof: a white pop, a ring of soft round smoke balls bursting out between speed lines, little stars spinning off, and the cloud lifting and thinning away. |+| Respawn beam | `spawn/respawn-beam` | one-shot 2.5s | 128×150 | A guide line drops, a pillar of light slams onto the spot, and a scan bar climbs from the feet writing the character back in row by row, white-hot lines cooling to its colors. |+| Shatter death | `spawn/shatter-death` | one-shot 3.3s | 168×96 | Frost races up the body and seals it in faceted ice, a glint sweeps it, cracks spread from the chest, then it bursts into its own facets that tumble, bounce and melt. |+| Soul rise | `spawn/soul-rise` | one-shot 3.2s | 96×140 | The body's outline flares and dims, then a pale glowing copy of it lifts out, stretching as its legs melt into a rippling wisp, shedding motes until it thins into light. |+| Spawn portal | `spawn/spawn-portal` | one-shot 3.8s | 208×150 | A rift tears open on the floor and swirls, belches violet smoke and sparks, spits a fountain of wisps up out of itself, then twists shut with a pop. |+| Summon rise | `spawn/summon-rise` | one-shot 4.6s | 176×116 | A rune circle burns into the floor, the ground bursts, and a horned brute heaves up out of it through dust and rubble, lit from below, until its eyes flare. |## arcane@@ -229,22 +194,18 @@ 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. |+| Arcane beam | `arcane/arcane-beam` | loop 1.2s | 264×100 | A beam fires right from the hand: a white core, strands twisting round it, pulses running down it, a flaring source and an end that sprays sparks. |+| Arcane missiles | `arcane/arcane-missiles` | one-shot 1.75s | 240×116 | A volley of violet bolts fans out of the hand, curls round on twisting ribbons and pops on the target one after another. |+| Arcane orb | `arcane/arcane-orb` | loop 2.4s | 136×112 | A floating orb of smoky violet glass with a swirl turning round a white-hot heart, two tilted rings of light orbiting behind and in front. |+| Blink in | `arcane/blink-in` | one-shot 1.4s | 136×96 | Glittering bits spiral in to a point of light that opens into a line, then into a white silhouette that cools into the caster. |+| Blink out | `arcane/blink-out` | one-shot 1.6s | 136×96 | The caster crackles with gathering light, flashes white, squeezes into a line of light that collapses and pops away in sparks. |+| Magic circle cast | `arcane/magic-circle-cast` | one-shot 3.9s | 200×220 | A circle draws itself on the floor, runes ignite one by one, it flashes, and a column of light fires up and breaks apart into glints. |+| Mana burst | `arcane/mana-burst` | one-shot 1.8s | 208×150 | Energy rushes into a point and blows out in a white flash and rings, flinging glowing runes that flare and pop into sparks one after another. |+| Portal | `arcane/portal` | loop 2.4s | 152×116 | An upright rift: fibrous spiral arms wind down into the dark, a lit rim wobbles, motes and streaks are pulled in, the floor glows. |+| Rune circle | `arcane/rune-circle` | loop 4s | 136×100 | A rune circle turns on the floor in perspective: a carousel of runes lit by chasing light, a turning square, ticks, motes rising off it. |+| Spell charge | `arcane/spell-charge` | loop 1.6s | 120×86 | Energy gathers in the caster's hand: streaks and motes spiral in, rings collapse into a swelling orb that crackles with arcs, ready to fire. |+| Star fall | `arcane/star-fall` | one-shot 2.5s | 232×172 | Stars streak down on long trails across an area, each landing with a white flash, a ring across the floor and a kick of sparks. |+| Time stop | `arcane/time-stop` | one-shot 3.6s | 196×136 | A clock face springs open, ticks slower and slower, freezes drained of colour, cracks, then shatters into falling shards. |## holy@@ -252,18 +213,16 @@ 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. |+| Blessing | `holy/blessing` | loop 3s | 80×128 | A soft cone of light rests on the character from above; sparkles drift down through it, twinkling, and wink out where they land on the head and shoulders. |+| Divine shield | `holy/divine-shield` | loop 2.4s | 88×84 | A bubble of gold light round the character: a bright rim and a thin gold film, meridians turning like a slow globe, a sheen sweeping across and sparkles winking on it. |+| Feather burst | `holy/feather-burst` | one-shot 3s | 160×160 | A white puff pops and throws feathers that brake hard, then rock from side to side as they sink and fade, with down drifting after them. |+| Halo | `holy/halo` | loop 2s | 56×80 | A ring of gold light floats over the head with a glint running round it; fine dust sifts down from it and the hair catches its light. |+| Heal | `holy/heal` | one-shot 1.9s | 80×104 | Petals of light bloom under the feet, a hoop of light rises up the body restoring its colour and leaving sparkles, and motes spiral up and pop into tiny hearts. |+| Healing ring | `holy/heal-aoe` | one-shot 2.9s | 256×136 | A seed of green light sinks into the floor and a soft ring rolls out from it; the floor glows where it passes and plus signs sprout and float up. |+| Holy pillar | `holy/holy-pillar` | one-shot 3.5s | 192×232 | Light breaks through from above: a sun opens at the top and a fan of shafts converges on the mark, pulsing, while a sigil burns on the floor; then the fan folds shut. |+| Resurrection | `holy/resurrection` | one-shot 4.8s | 192×160 | Light pours down on the fallen and life climbs back up the body; wings of light unfold, a halo forms, one great wingbeat, then the wings scatter into feathers. |+| Smite | `holy/smite` | one-shot 2.8s | 224×176 | A glint marks the spot, then a bolt of light drops like a hammer: a white flash, a shockwave over the floor, stone chips flying and cracks that glow and cool. |+| Sunburst | `holy/sunburst` | loop 4s | 128×128 | A white-hot core in a gold corona; long and short rays turn slowly round it, breathing, with glints running out along them that wink at the tips. |## shadow@@ -271,20 +230,18 @@ 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. |+| Black hole | `shadow/black-hole` | loop 4s | 184×132 | A tilted disk of banded rings turns round a black hole, its far side bent up over the top and under the bottom; debris spirals in, stretches and is swallowed. |+| Curse | `shadow/curse` | one-shot 3.4s | 112×124 | Wisps gather over the head, a skull stamps down with a flash, its eyes burn as the curse floods the body violet, then it cracks and crumbles. |+| Dark explosion | `shadow/dark-explosion` | one-shot 3.8s | 280×248 | Motes swirl into a pulsing core, a black star cuts across a violet-white flash, and a black sphere burns at the rim, throws lit shards and smoke, then collapses. |+| Eclipse | `shadow/eclipse` | loop 4s | 160×144 | A black moon over the sun: a breathing pearl corona with long streamers, a thin white rim, and one diamond bead blazing on its edge. |+| Grasping hands | `shadow/grasping-hands` | one-shot 3.1s | 200×116 | Shadow arms burst up out of a dark pool with a splash, clench their hands into claws, strain, and are dragged back under, fingers clawing at the air. |+| Hex sigil | `shadow/hex-sigil` | one-shot 4.2s | 168×128 | A burning pen traces a cursed sigil in the air, its glyphs pop in one by one, then it flares white and crumbles into falling embers. |+| Life steal | `shadow/life-steal` | one-shot 2.2s | 184×100 | A target on the right is struck and bleeds red orbs; they hang a moment, then whip home as comet streaks and flood the caster crimson. |+| Necro skulls | `shadow/necro-skulls` | loop 3s | 136×116 | Spectral skulls circle a cold green flame on a tilted orbit, passing behind and before it, eyes lit, trailing curls of ghost smoke. |+| Shadow flames | `shadow/shadow-flames` | loop 2.4s | 104×112 | Inside-out fire on the floor: a black heart wrapped in violet flame with pale skin and tips, shedding embers and dark smoke. |+| Shadow tendrils | `shadow/shadow-tendrils` | one-shot 3.2s | 208×130 | A dark pool opens on the floor; tentacles with lit rims and hooked tips lash up out of it with a splash, writhe, and sink back as it closes. |+| Soul drain | `shadow/soul-drain` | loop 3.2s | 208×120 | Pale souls are torn loose on the right and dragged down a funnel of streaks into a black crystal vessel, which flares violet as each one lands. |+| Void orb | `shadow/void-orb` | loop 3.2s | 168×160 | A black orb hangs in the air, a pale rim crawling round it; a dark vortex winds into it, motes and streaks are pulled in, and light bends round its edge. |## status@@ -292,22 +249,19 @@ 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. |+| Bleeding | `status/bleeding` | loop 2.4s | 60×56 | Bleeding out: beads swell at three wounds, run, let go and fall to spatter into a glossy pool that ripples; each heartbeat spurts a little and flashes the body red. |+| Burning | `status/burning` | loop 1.2s | 72×80 | Burning over time: small flames lick from four hot spots, trailing sparks and thin smoke; every 0.6 s they flare, the body flashes white then orange, scorch marks spread. |+| Charmed | `status/charmed` | loop 2.4s | 60×76 | Smitten: a big heart beats over the head, throwing a ring and a flush of light with every beat, little hearts float up, the eyes go pink and the cheeks blush. |+| Confused | `status/confused` | loop 2.4s | 60×78 | Head in a spin: a glowing spiral whirls over the head, question marks pop up round it and bob, the eyes dart left and right. |+| Cursed | `status/cursed` | loop 2.4s | 64×84 | Hexed: violet smoke rises off the body in winding trails, a dark stain creeps up from the feet with a glowing edge, the eyes burn, a skull glitches in overhead. |+| Frozen | `status/frozen` | loop 2s | 72×64 | Chilled to the bone: frost ferns creep over the body, icicles hang from chin, hands and hair and drip, breath steams, snow settles, a shiver every second, frost spreads underfoot. |+| Haste | `status/haste` | loop 1.2s | 100×56 | Sped up: striped after-images stream out behind, speed lines whip past, dust kicks off the heels and the leading edge catches the wind. Faces right. |+| Petrified | `status/petrified` | one-shot 3.8s | 120×74 | Turned to stone: grey creeps up from the feet behind a crackling edge that spits grit, the statue holds, cracks run through it, and it bursts into tumbling chunks and dust. |+| Poisoned | `status/poisoned` | loop 1.6s | 72×64 | Sick to the bone: green rolls up the body in waves, dark veins creep from a wound, toxic sweat drips and hisses; every 0.8 s it wobbles, blisters pop and a ring pulses out. |+| Rage | `status/rage` | loop 1.2s | 80×80 | Seething: the body judders on every heartbeat, an anger mark throbs at the temple, eyes burn, steam jets off the head, stress lines flash out and the floor cracks hot underfoot. |+| Sleep | `status/sleep` | loop 2.4s | 60×82 | Fast asleep: eyes shut, soft outlined Zs float up off the head one after another, swaying and growing as they rise, dream motes drift, a slow breathing glow. |+| Slowed | `status/slowed` | loop 2.4s | 64×76 | Dragged through time: a glassy clock dial behind the head ticks round in heavy steps, flashing with each, while drops sink in slow motion and spread slow rings. |+| Stunned | `status/stunned` | loop 2s | 60×64 | Seeing stars: three spinning stars and two little birds circle the head on a tilted ring, ducking behind it and sweeping round in front, trailing glitter. |## nature@@ -315,21 +269,19 @@ 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. |+| Acid splash | `nature/acid-splash` | one-shot 2.8s | 184×116 | A gob of acid bursts into a crown and spatters; it eats a glowing, smoking pit into the floor and boils down into it, spitting bright beads, pale steam curling off. |+| Boulder | `nature/boulder` | one-shot 2.3s | 264×120 | A spinning boulder arcs right shedding dust and pebbles, smashes into the floor in a white flash and bursts into tumbling chunks, gravel and rolling dust. |+| Earth spike | `nature/earth-spike` | one-shot 3.4s | 272×150 | The floor cracks with light and heaves, a faceted stone spike rams up with two side shards in a burst of chips, grit and dust; rubble rains, then it splits and crumbles. |+| Healing bloom | `nature/healing-bloom` | one-shot 3.3s | 124×120 | A sprout pushes up and unfurls, a bud swells and opens round a glowing golden heart in a flare of healing light; its petals lift away one by one as motes. |+| Leaf storm | `nature/leaf-storm` | loop 2.4s | 112×104 | Leaves tumble up a rising spiral round the character, passing behind and in front, turning and flipping, wrapped in bright bands of wind; litter swirls at their feet. |+| Poison cloud | `nature/poison-cloud` | loop 4s | 256×100 | A miasma hugging the floor: ragged sheets of gas lit yellow-green from within, fading to violet, creep out in tongues that curl over at their tips; plumes twist up as ribbons. |+| Quake | `nature/quake` | one-shot 3.1s | 288×104 | The ground jolts three times: a rift tears out along the floor glowing deep inside, slabs of floor heave up and drop back askew, pebbles hop and dust bursts out of the split. |+| Root snare | `nature/root-snare` | one-shot 2.7s | 128×96 | The floor cracks and roots burst up round the character, spiralling round its legs; they cinch tight with a snap, hold, then crack and crumble into bark and dust. |+| Spore burst | `nature/spore-burst` | one-shot 3.2s | 212×132 | A toadstool pushes up, swells and trembles as its gills glow, then squashes and puffs a lumpy cloud of glowing spores that billows up and drifts down twinkling. |+| Thorns | `nature/thorns` | one-shot 2.4s | 232×92 | A seam races along the floor and hooked thorns punch up out of it one after another, each bigger than the last, in bursts of dirt and green light; they hold, then sink. |+| Tornado | `nature/tornado` | loop 2s | 196×168 | A snaking funnel of spinning wind bands under a flared, churning top that flickers with lightning; leaves and debris whirl round it front and back, dust boils at its foot. |+| Toxic puddle | `nature/toxic-puddle` | loop 4s | 176×100 | Black tar lit from inside by chartreuse veins and a glowing rim, an oily sheen drifting on it; glossy bubbles dome, stretch and pop, vapour curls up in fraying ribbons. |+| Vine whip | `nature/vine-whip` | one-shot 1.4s | 216×128 | A thorny vine bursts from the floor, rears back coiled, then lashes out right in a whip crack that sprays sap and tears off leaves, before sliding back into the ground. |## weather@@ -337,22 +289,18 @@ 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. |+| Aurora | `weather/aurora` | loop 12s | 320×180 | Rippling curtains of green-to-violet light over a starfield: folding hems burn bright, rays shimmer up into violet, and the whole sky slowly breathes. |+| Blizzard | `weather/blizzard` | loop 8s | 320×180 | Snow driven almost flat by a gale: streaks at three depths race past, gusts throw translucent sheets of snow across the sky and spindrift streams off the drifts. |+| Cherry blossoms | `weather/cherry-blossoms` | loop 10s | 320×180 | Pink petals flutter down on a spring breeze, tumbling in little spirals and flashing as they catch the light, with a few whole blossoms spinning among them. |+| Clouds | `weather/clouds` | loop 12s | 320×180 | Layers of clouds drift past a bright moon at night: silver-lit tops, dark bellies, edges that flare where they cross the moon, forming and thinning as they go. |+| Falling leaves | `weather/falling-leaves` | loop 10s | 320×180 | Autumn leaves swing down through the air, tilting and flipping to show their pale backs, ride a gust, land flat in the litter and fade. |+| Fireflies | `weather/fireflies` | loop 12s | 320×180 | Fireflies wander over a meadow at night, each glowing up and fading on its own rhythm, trailing light and lighting the grass tips beneath them. |+| Fog | `weather/fog` | loop 12s | 320×180 | Slow banks of moonlit fog at three depths drift past each other, crests catching the light, while thin streaks of mist slide by in front. |+| God rays | `weather/god-rays` | loop 10s | 320×180 | Shafts of light slant down from high on the left, breathing and swaying, pooling on the floor, as drifting dust motes light up whenever they cross a beam. |+| Rain | `weather/rain` | loop 8s | 320×180 | Slanted rain at four depths: far drops fade into the dark, near ones glint and splash, drops ring the puddles and a low mist drifts over the wet floor. |+| Shooting stars | `weather/shooting-stars` | loop 10s | 320×180 | Meteors burn across a starry sky, white heads trailing gold and rose; the big ones flare and break up, and each leaves a glowing train that twists and fades. |+| Snow | `weather/snow` | loop 12s | 320×180 | Snow at three depths in a gusty breeze: far specks, drifting flakes, big near crystals that spin and glow; they settle on a sparkling drift and melt away. |+| Storm | `weather/storm` | loop 10s | 320×180 | Driving rain at two depths under a churning cloud deck; a forked bolt strikes in a double flash that lights the sky and the rain, then sheet lightning glows in the clouds. |## ui@@ -360,25 +308,18 @@ 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. |+| Achievement | `ui/achievement` | one-shot 2.4s | 220×72 | A toast slides in on speed lines and settles; a gold medal pops onto it in a burst of sparkles, a shine sweeps the whole toast, then it slides away. |+| Coin collect | `ui/coin-collect` | one-shot 2.45s | 176×116 | A coin bursts into a fountain of spinning coins that hang, then zip one by one into a HUD counter that pops and ticks up, glints and folds away. |+| Combo counter | `ui/combo-counter` | one-shot 1.45s | 208×100 | x5 COMBO rockets in on streaming speed lines, smearing, and slams to a stop: a white flash, a ring, sparks; it pulses while a timer bar drains, then whooshes out. |+| Confetti | `ui/confetti` | one-shot 3.4s | 200×140 | Two party poppers bang one after the other: paper bits and curly streamers burst out, stall, then tumble and flutter down, flipping, and settle on the floor. |+| Countdown | `ui/countdown` | one-shot 3.1s | 152×136 | 3, 2, 1 slam into a timer ring that drains like a burning fuse, throwing sparks; then GO! bursts out as the ring blows into a shockwave with rays. |+| Crit number | `ui/crit-number` | one-shot 1.5s | 152×120 | CRIT 128! slams in huge and white over a jagged starburst with a hard shake and speed lines, cools to fire, holds with a shine, then pops into sparks. |+| Damage number | `ui/damage-number` | one-shot 1.05s | 76×68 | A red -27 punches out of a hit spark, white for a frame, arcs up, lands with a squash and a little hop, then fades as it lifts away. |+| Exclamation | `ui/exclamation` | one-shot 1.4s | 84×104 | A bold ! springs up off the hero's head, stretching as it shoots up and squashing as it lands; surprise ticks flick out, it wobbles, then pops away. |+| Health bar hit | `ui/health-bar-hit` | one-shot 2s | 160×64 | A segmented health bar takes a hit: it jolts and dips, the lost chunk flashes white and sheds chips, holds, then drains away behind a sparking edge. |+| Heart lost | `ui/heart-lost` | one-shot 1.5s | 96×88 | A HUD heart is hit: it flashes white and jolts, a crack runs down it, it splits into two halves that tumble away, leaving an empty socket that fades. |+| Level up | `ui/level-up` | one-shot 3.2s | 176×138 | Gold gathers at the feet and bursts up as a pillar of light round the hero; rings climb it, LEVEL UP! drops in letter by letter, a shine sweeps it, sparkles twinkle. |+| Quest complete | `ui/quest-complete` | one-shot 2.6s | 204×92 | A stitched ribbon unrolls from the middle, QUEST COMPLETE types on letter by letter, a gold seal stamps down and ticks, stars pop; then it all rolls away. |## pickups@@ -386,21 +327,17 @@ 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. |+| Chest open | `pickups/chest-open` | one-shot 4.6s | 176×112 | A banded chest rattles with gold light leaking from its seam, the lid kicks open, rays fan up, and coins and gems arc out, bounce, glint and get collected. |+| Coin spin | `pickups/coin-spin` | loop 1.6s | 56×56 | A thick gold coin turning on its edge: an embossed star face, a reeded rim showing as it goes edge-on, a flash sweeping the face, bobbing over its shadow. |+| Collect burst | `pickups/collect-burst` | one-shot 1.35s | 112×108 | The moment of pickup: a white flash and a cross of light, a thin ring snapping out ahead of a softer one, twinkles thrown wide on curving paths that brake, hang and wink out. |+| Crystal shard | `pickups/crystal-shard` | loop 3.2s | 64×76 | A broken amber shard hovers and sways: chipped uneven faces, its top sheared off, light pulsing up through glowing cracks and flaring out of the break; splinters orbit it. |+| Gem spin | `pickups/gem-spin` | loop 2.4s | 64×64 | A brilliant-cut ruby turning on its axis: real facets catch the light in turn, flashes roll over the crown, refracted light slides across the floor, sparkles wink round it. |+| Heart pickup | `pickups/heart-pickup` | loop 1.2s | 56×60 | A plump glossy heart hovering over its shadow beats lub-dub: a big squash and stretch, a smaller echo, light and a thin ring pulsing out, tiny hearts drifting off. |+| Key glint | `pickups/key-glint` | loop 2s | 72×60 | An ornate silver key hovering and rocking; a glint runs from its bow down the shaft to the teeth and bursts off the tip as falling sparks. |+| Loot beam | `pickups/loot-beam` | loop 2.4s | 96×176 | A dropped sword in a tall pillar of rarity light: a white core thinning to the sky, rings pulsing across the floor, motes streaming up, a glint racing up the shaft. |+| Potion | `pickups/potion` | loop 2.4s | 56×72 | A round glass flask of glowing brew rocks in the air: the brew sloshes behind the rock, bubbles rise and pop, light glows through the glass, wisps curl off the cork. |+| Power star | `pickups/power-star` | loop 1.6s | 88×84 | A fat bevelled star rocks side to side and swells on each beat, rays of light turning slowly behind it, sparks spinning off its points. |+| XP orb | `pickups/xp-orb` | loop 1.8s | 72×56 | A small glowing orb races a figure-eight, a comet tail tapering behind it along its path, flecks shed from the tail winking out, its light following it over the floor. |## transitions@@ -408,18 +345,16 @@ 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. |+| Blinds | `transitions/blinds` | one-shot 2s | 320×180 | Slats catch the light edge-on, then tilt shut top to bottom, lit rims glinting as warm light squeezes through the closing gaps with dust in it; then they tilt open and fade. |+| Burn away | `transitions/burn-away` | one-shot 3s | 320×180 | The screen burns in from its edges behind a ragged ember line of licking flames, embers and smoke; then the black smoulders and burns open from the middle. |+| CRT off | `transitions/crt-off` | one-shot 2s | 320×180 | The picture squeezes into a white-hot glowing line, the line into a dot that lingers as a fading afterglow; then it switches back on, dot to line to picture, with a warm-up glow. |+| Diamond wipe | `transitions/diamond-wipe` | one-shot 2s | 320×180 | A wave of faceted diamonds swells across the screen, rims bright and ridges lit, cooling to black as they lock; then they rise as gems again and shrink away with glints. |+| Glitch wipe | `transitions/glitch-wipe` | one-shot 1.8s | 320×180 | Torn bands of black stutter across the screen, freezing and jerking back, their ragged edges split into magenta and cyan ghosts spitting data slivers; then they tear on through. |+| Iris | `transitions/iris` | one-shot 2.2s | 320×180 | A lit iris closes onto a warm spotlight where dust drifts, holds as its rim twinkles, snaps shut into a glint, then pops open from a flash with a white-hot rim throwing sparks. |+| Pixel dissolve | `transitions/pixel-dissolve` | one-shot 2.2s | 320×180 | Clumps of blocks wink in, each drawn in a white outline that fills black and cools, with glints; then they wink out, outlines collapsing, the last small ones sparkling away. |+| Shatter wipe | `transitions/shatter-wipe` | one-shot 2.8s | 320×180 | A dark glass pane drops over the screen and bounces; cracks race out from an impact with a flash, then it bursts into tumbling glass shards with lit edges that fall away. |+| Slash wipe | `transitions/slash-wipe` | one-shot 1.7s | 320×180 | A white-hot blade edge slices across the screen, light ahead of it and sparks spraying back over the cover; a second cut flashes through and the cover splits apart. |+| Star iris | `transitions/star-iris` | one-shot 2.2s | 320×180 | A five-point star iris spins shut on the middle of the screen, its gold rim lit and its tips twinkling and shedding motes; it closes on a glint and spins open again from a flash. |## critters@@ -427,17 +362,15 @@ 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. |+| Bat | `critters/bat` | loop 2.4s | 112×80 | A bat flaps in four snappy wing frames along a figure-eight, its body lifting on each downbeat, moonlight on its wing bones, red eyes glowing and glinting. |+| Bird | `critters/bird` | loop 2.4s | 112×80 | A songbird flies in place: bursts of wingbeats that lift its body on each downstroke, a glide on spread wings, its tail fanning, a loose feather drifting away. |+| Butterfly | `critters/butterfly` | loop 3.2s | 128×88 | An iridescent butterfly wanders a loop in bursts of quick wingbeats and open-winged glides, its veined, spotted wings shedding a twinkling trail of glowing dust. |+| Eyeball | `critters/eyeball` | loop 3.2s | 96×108 | A bloodshot eyeball floats in its fleshy lids: its glowing iris snaps from one look to the next, it blinks, and its nerve sways behind it as it bobs. |+| Fish school | `critters/fish-school` | loop 4.8s | 136×80 | A school of fish holds station in two depth rows: bodies wag into swinging tails, one darts ahead now and then, bubbles rise and caustic light ripples over them. |+| Flying skull | `critters/flying-skull` | loop 2.4s | 96×132 | A cracked bone skull bobs in the air, jaw chattering, eyes burning, a fire roaring off its crown that sheds flame puffs, embers and smoke and throws warm light. |+| Frog | `critters/frog` | loop 2.6s | 112×88 | A frog puffs its throat, blinks, crouches and leaps to snap a buzzing fly out of the air, then lands with a squash and a puff of dust, gulps and settles. |+| Ghost | `critters/ghost` | loop 2.4s | 96×100 | A sheet ghost bobs over the floor: its scalloped hem ripples and trails its drift, little arms flutter, it glances about and blinks, motes trickle off its hem. |+| Jellyfish | `critters/jellyfish` | loop 3.2s | 96×120 | A see-through jellyfish pulses: its bell squeezes to shove it up and relaxes as it sinks, frilled arms and long tentacles trailing, a glow inside, bubbles drifting by. |+| Slime | `critters/slime` | loop 1.8s | 112×88 | A glossy slime hops in place: it squashes to wind up, stretches into the jump, rounds out in the air, splats down flinging droplets that creep back, then wobbles and blinks. |+| Snake | `critters/snake` | loop 2.4s | 136×56 | A snake slithers along the floor, head raised: humps rise and roll back down its patterned body to the tail, dust puffs where it touches down, its forked tongue flicks. |+| Wisp | `critters/wisp` | loop 3.2s | 128×104 | A will-o'-the-wisp loops a figure-eight over the floor: a little soul-flame with a face, its flame tail licking up and streaming behind, shedding puffs and sparks. |diff --git a/docs/readme/montage.gif b/docs/readme/montage.gifindex ba02cb2..4e8fa53 100644Binary files a/docs/readme/montage.gif and b/docs/readme/montage.gif differdiff --git a/gallery/app.js b/gallery/app.jsindex 2ac1cf6..f4cb86b 100644--- a/gallery/app.js+++ b/gallery/app.js@@ -10,6 +10,8 @@ const FX = Object.entries(effects).map(([id, mod]) => {return { id, cat: id.split("/")[0], name: meta.name, mod: { ...mod, meta }, meta };});const reduced = matchMedia("(prefers-reduced-motion: reduce)").matches;+// full-screen effects (transitions, weather, impact frames) fill a 16:9 stage edge to edge instead of floating in it+const isScreen = (fx) => fx.meta.size[0] >= 320 && Math.abs(fx.meta.size[0] / fx.meta.size[1] - 16 / 9) < 0.05;const $ = (s) => document.querySelector(s);function el(tag, props = {}, kids = []) {const e = Object.assign(document.createElement(tag), props);@@ -33,6 +35,9 @@ class Player {this.y = Math.floor((this.H - h) / 2) + oy;this.canvas.width = this.W;this.canvas.height = this.H;+ // shrinking pixel art nearest-neighbour drops whole 1 px lines; smooth it only when it has to shrink+ const shown = this.canvas.getBoundingClientRect().width * devicePixelRatio;+ this.canvas.style.imageRendering = shown && shown < this.W ? "auto" : "";this.frame = createFrame(this.W, this.H);this.img = this.ctx.createImageData(this.W, this.H);this.setBg(this.bg);@@ -94,7 +99,8 @@ function build() {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 }, [+ const [fw, fh] = fx.meta.size;+ const fig = el("figure", { className: isScreen(fx) ? "tile big screen" : fw > 200 || fh > 170 ? "tile big" : "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` })]),]);@@ -113,7 +119,7 @@ function build() {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);+ t.player = isScreen(t.fx) ? new Player(t.cv, t.fx, 16 / 9, 1) : new Player(t.cv, t.fx, 6 / 5, 1.25);if (reduced) t.player.seek(t.fx.meta.duration * 0.4);}}@@ -162,8 +168,9 @@ function filter() {let detail = null;function openDetail(fx) {const d = $("#detail");- const big = $("#big");- detail = new Player(big, fx, 16 / 10, 1.6);+ const big = $("#big"), screen = isScreen(fx);+ big.parentElement.classList.toggle("screen", screen);+ detail = screen ? new Player(big, fx, 16 / 9, 1) : new Player(big, fx, 16 / 10, 1.6);const m = fx.meta;$("#d-name").textContent = m.name;$("#d-id").textContent = fx.id;diff --git a/gallery/style.css b/gallery/style.cssindex 8125c46..fa9796a 100644--- a/gallery/style.css+++ b/gallery/style.css@@ -102,8 +102,11 @@ 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; }+.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(176px, 1fr)); grid-auto-flow: dense; gap: 12px; }.tile { margin: 0; cursor: pointer; display: flex; flex-direction: column; gap: 8px; min-width: 0; }+/* big effects (explosions, weather, full-screen transitions) get four cells, so their 1 px lines survive */+.tile.big { grid-column: span 2; grid-row: span 2; }+.tile.screen .stage, .sheet .big.screen { aspect-ratio: 16 / 9; }.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; }@@ -189,3 +192,6 @@ pre {.bar-in { flex-wrap: wrap; }#q { width: 100%; max-width: none; }}+@media (max-width: 330px) {+ .tile.big { grid-column: auto; grid-row: auto; }+}diff --git a/package.json b/package.jsonindex 70dec82..3137e13 100644--- a/package.json+++ b/package.json@@ -1,6 +1,6 @@{"name": "pixelfx",- "version": "0.1.0",+ "version": "0.2.0","description": "Code-driven pixel art effects and animations, and a Claude Code skill to make your own.","type": "module","license": "MIT",diff --git a/src/core/actor.js b/src/core/actor.jsindex fd4b400..d91eb97 100644--- a/src/core/actor.js+++ b/src/core/actor.js@@ -1,3 +1,4 @@+import { hex } from "./color.js";// 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.@@ -25,7 +26,51 @@ const HERO = [const HERO_PAL = {k: "#17121f", h: "#7a4128", s: "#f3c49d", S: "#c98b6c", e: "#17121f",t: "#5f6f94", T: "#46536f", b: "#8a5a32", p: "#38334a", o: "#6a4030",+ // the 2x character's extra detail+ H: "#a35d34", w: "#ffffff", m: "#a3564a", g: "#e8c060", L: "#7f90b6", O: "#8f5a3f",};+// The same character at twice the size (24 x 38): Scale2x of HERO, outline thinned back to 1 px, detail added.+const HERO2 = [+ ".........kkkkkkkk.......",+ ".......kkhhhhhhhhkk.....",+ ".....kkhhhHHhhhhhhk.....",+ "...kkhhHHHhhhhhhhhhkk...",+ "...khhHHhhhhhhhhhhhhk...",+ "..khhHHhhhhhhhhhhhhhhkk.",+ "..khhhhhhhhhhhhhhhhhhhk.",+ "..khhhhhhhhhhhhhhhhhhhhk",+ "..khhhhSSssssssSShhhhhhk",+ "..khhhhsssssssssssshhhhk",+ "..khhhhswessssewssshhhhk",+ "..khhhsseesssseesssshhhk",+ "..khhhsseesssseesssshhhk",+ "...khhsseesssseesssshhk.",+ "...kkhsssssmmssssssshkk.",+ ".....kssssssssssssssk...",+ "......ksssSSSSSSssskk...",+ "......kttSSSSSSSSkkk....",+ ".....ktttttttttttttk....",+ "...kktLLttttttttttttk...",+ "...ktLLtTTttttTTttttk...",+ "..kttLttTTTttTTTtttttk..",+ "..kssttttTTTTTTtttsssk..",+ "..ksssttttTTTTttttsssk..",+ "..kssstttttttttttttttk..",+ "...kssttttttttttttttk...",+ "...kksbbbbbggbbbbbtkk...",+ "....kbbbbbbggbbbbbbk....",+ "....kpppppbbbbpppppk....",+ "....kppppppkkkppppppk...",+ "....kppppppk..kpppppk...",+ "....kppppppk..kppppppk..",+ "....kppppppk..kppppppk..",+ "....kppppppk...kpppppok.",+ "....koOOooook...kpOOook.",+ "....kkoooooook..kkoooook",+ "....kkkoooookk..kkkoookk",+ ".....kkkkkkkk....kkkkkk.",+];+function maskOf(rows, k = 1) {const h = rows.length * k, w = rows[0].length * k, data = new Uint8Array(w * h);@@ -36,22 +81,31 @@ function maskOf(rows, k = 1) {return { w, h, data };}-const MASKS = { 1: maskOf(HERO, 1), 2: maskOf(HERO, 2) };+const MASKS = { 1: maskOf(HERO, 1), 2: maskOf(HERO2, 1) };+const SPRITES = { 1: HERO, 2: HERO2 };+// the character's own colors, row by row (0 where empty), for effects that recolor it: frozen, poisoned, stone+function pixelsOf(rows) {+ const w = rows[0].length, data = new Uint32Array(w * rows.length);+ rows.forEach((r, y) => [...r].forEach((ch, x) => (data[y * w + x] = ch === "." ? 0 : hex(HERO_PAL[ch]))));+ return data;+}+const PIXELS = { 1: pixelsOf(HERO), 2: pixelsOf(HERO2) };/*** The stock actor at scale k (1: 12 x 19 px, 2: 24 x 38 px), in local space with its feet at (0, 0):* { mask, x, y (top-left of the mask), w, h, k, head: [x, y] (top of the head), chest: [x, y] }.*/export function stockActor(k = 1) {- const m = MASKS[k] ?? (MASKS[k] = maskOf(HERO, k)), x = -Math.floor(m.w / 2), y = -m.h;- return { mask: m, x, y, w: m.w, h: m.h, k, head: [0, y], chest: [0, y + 11 * k] };+ k = k === 2 ? 2 : 1;+ const m = MASKS[k], x = -Math.floor(m.w / 2), y = -m.h;+ return { mask: m, pixels: PIXELS[k], x, y, w: m.w, h: m.h, k, head: [0, y], chest: [0, y + 11 * k] };}/** 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, scale: actor.k ?? 1 });+ if (a > 0) p.sprite(SPRITES[actor.k === 2 ? 2 : 1], 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 };+export { HERO, HERO2, HERO_PAL };diff --git a/src/core/index.js b/src/core/index.jsindex 38e65aa..dd662a0 100644--- a/src/core/index.js+++ b/src/core/index.js@@ -8,5 +8,5 @@ export { Particles, Bits, Lights, Blazes, P, PF, B, GRAVITY, FIRE_RAMP, SMOKE_RAexport { 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 { stockActor, drawActor, actorAlphaOf, HERO, HERO2, HERO_PAL } from "./actor.js";export { backdrop, BACKDROPS } from "./scene.js";diff --git a/src/fx/arcane/_lib.js b/src/fx/arcane/_lib.jsindex 89a2b9b..ce40f1a 100644--- a/src/fx/arcane/_lib.js+++ b/src/fx/arcane/_lib.js@@ -1,129 +1,160 @@-// Shared by the arcane effects: palettes, a small rune alphabet, sparkles and a squashable actor silhouette.-// Files starting with _ are helpers, not effects.+// Shared by the arcane effects: a dithered light ramp, closed-form motes and streaks for loops, crackling+// arcs, floor rings and an original rune alphabet. Files starting with _ are helpers, not effects.+// The dithered ramp (tone) is adapted from Sprite Fusion's open-source black hole+// (https://www.spritefusion.com/pixel-art-vfx/black-hole), and the arc drawing from its energy+// (https://www.spritefusion.com/pixel-art-vfx/energy), MIT License, Copyright (c) 2026 Hugo Duprez.-import { ramp, hex, stockActor, WHITE } from "../../core/index.js";-import { HERO, HERO_PAL } from "../../core/actor.js";+import { scale, clamp, bolt, luma, WHITE } from "../../core/index.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))]);-}+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 CROSS = [[1, 0], [-1, 0], [0, 1], [0, -1]];+/** The 4x4 ordered-dither threshold (0..1) of the pixel cell holding (x, y). */+export const bayer = (x, y) => BAYER[((Math.floor(y) & 3) << 2) | (Math.floor(x) & 3)];-// 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"];+/**+ * Light intensity I (0..1) to a step of ramp R (dark to bright), dithering between neighbouring steps so a+ * gradient reads smooth at 1x; below lo it thins out through the dither and returns 0 (draw nothing).+ */+export function tone(R, I, x, y, lo = 0.06, sharp = 0) {+ const b = bayer(x, y);+ if (I < lo && b > I / lo) return 0;+ const n = R.length - 1, f = clamp(I) * n;+ let i = Math.floor(f);+ // sharp (0..1) narrows the dithered zone between two steps, so broad areas stay clean and only edges dither+ const q = sharp > 0 ? clamp((f - i - 0.5) / (1 - sharp) + 0.5) : f - i;+ if (q > b) i = Math.min(n, i + 1);+ return R[i];+}-// Runes: an original angular alphabet. 5x5 for floating glyphs, 3x3 for bands on circles and blades.-export const RUNES = [- ["..#..", ".###.", "#.#.#", "..#..", ".#.#."],- ["#...#", "##.##", "#.#.#", "..#..", "..#.."],- ["####.", "#....", "###..", "#..#.", "#...#"],- ["#.#.#", "#.#.#", ".###.", "..#..", ".###."],- [".###.", "#...#", "..#..", ".#.#.", "#...#"],- ["#..#.", "#.#..", "##...", "#.#..", "#..##"],- ["..#..", "#.#.#", "#####", "..#..", "..#.."],- ["##.##", "..#..", ".#.#.", "#...#", "#...#"],-];-export const RUNES3 = [- ["#.#", ".#.", "#.#"],- ["###", ".#.", ".#."],- ["#..", "###", "..#"],- ["#.#", "###", "#.."],- ["##.", "#.#", ".##"],- [".##", "#..", "##."],- ["#.#", "#.#", ".#."],- ["###", "#.#", "#.."],-];+/** A drifting mote at (x, y) moving (vx, vy) px/s, drawn like the sim's MOTE: bright head, darker tail, light. */+export function mote(p, x, y, vx, vy, c, size = 1, k = 1, glow = 0.4) {+ const sp = Math.hypot(vx, vy) || 1, ux = vx / sp, uy = vy / sp, len = Math.min(16, 0.5 + sp * 0.026) * size, a = k < 0.35 ? k / 0.35 : 1;+ if (len > 1.2) p.line(x - ux * len, y - uy * len, x - ux * len * 0.35, y - uy * len * 0.35, scale(c, 0.55), a);+ p.line(x - ux * len * 0.4, y - uy * len * 0.4, x, y, c, a);+ if (glow > 0) p.glow(x, y, 2.5 + size, c, glow * k);+}-/** 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 });+/** Energy rushing in, drawn like the sim's STREAK: a white tip, a colored body, a dim dotted tail. */+export function streak(p, x, y, vx, vy, c, a = 1, maxLen = 7, glow = 0.4) {+ const sp = Math.hypot(vx, vy) || 1, ux = vx / sp, uy = vy / sp, L = clamp(sp / 30, 1, maxLen);+ for (let d = L; d >= 0; d -= 0.5) p.dot(x - ux * d, y - uy * d, d < 1 ? WHITE : d < L * 0.5 ? c : scale(c, 0.6), (d < L * 0.5 ? 1 : 1.2 - d / L) * a);+ if (glow > 0) p.glow(x, y, 4, c, glow * 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.+ * A crackling arc from (x0, y0) to (x1, y1): a jagged main path plus forks, as [{ pts, w }]. r is an Rng, so+ * re-seed it every couple of frames for flicker.*/-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);+export function arc(r, x0, y0, x1, y1, { jag = 0.3, forks = 1, forkLen = 0.5 } = {}) {+ const L = Math.hypot(x1 - x0, y1 - y0), depth = Math.max(1, Math.min(5, Math.round(Math.log2(L / 1.5)))), main = bolt(r, x0, y0, x1, y1, { jag, depth });+ const out = [{ pts: main, w: 1 }];+ for (let k = 0; k < forks && main.length > 3; k++) {+ if (r.next() > 0.7) continue;+ const i = 1 + Math.floor(r.next() * (main.length - 2)), [x, y] = main[i], [px, py] = main[i - 1];+ const a = Math.atan2(y - py, x - px) + (r.next() < 0.5 ? -1 : 1) * (0.4 + r.next() * 0.6), l = L * forkLen * (0.4 + 0.6 * r.next()) * (1 - i / main.length);+ if (l > 1.5) out.push({ pts: bolt(r, x, y, x + Math.cos(a) * l, y + Math.sin(a) * l, { jag: jag * 1.1, depth: Math.max(1, depth - 2) }), w: 0.55 });}- p.dot(x, y, s >= 1 ? core : arm, a);+ return out;}-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.+ * Draw arc paths the way Sprite Fusion draws its bolts: a dithered halo while it's fresh, a body beside the+ * core, a white core, light along the path. cols: { core, body, halo, glow }; k: 1 fresh .. 0 gone.*/-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;+export function drawArc(p, paths, cols, k = 1, glowK = 0.5) {+ const steps = (fn) => {+ for (const path of paths)+ for (let i = 0; i < path.pts.length - 1; i++) {+ const [ax, ay] = path.pts[i], [bx, by] = path.pts[i + 1], l = Math.max(1, Math.hypot(bx - ax, by - ay));+ for (let d = 0; d <= l; d += 0.5) fn(ax + ((bx - ax) * d) / l, ay + ((by - ay) * d) / l, path, i, d === 0);+ }+ };+ if (k > 0.45) steps((x, y, path) => { if (path.w >= 1) for (const [dx, dy] of CROSS) p.dot(x + dx * 1.5, y + dy * 1.5, cols.halo, (k - 0.45) * 1.6); });+ if (k > 0.25) steps((x, y, path) => { if (path.w > 0.4) (p.dot(x + 1, y, cols.body), p.dot(x, y + 1, cols.body)); });+ steps((x, y, path, i, first) => {+ p.px(x, y, path.w >= 1 && k > 0.3 ? cols.core : cols.body);+ if (first && i % 3 === 0) p.glow(x, y, (path.w >= 1 ? 9 : 5) * (0.5 + k * 0.5), cols.glow, glowK * k * path.w);});}-/**- * 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.+ * A ring lying on the floor (or any tilted plane): centre (cx, cy), radius r, squashed by sy, 1 px thick at+ * any size. c and a may be functions of the angle g around it (sin(g) > 0 is the near side, towards the viewer).+ * keep(g) picks which part to draw: (g) => Math.sin(g) < 0 is the far half, for drawBack.*/-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);+export function floorRing(p, cx, cy, r, sy, c, a = 1, keep = null) {+ if (r < 0.5) return;+ const fc = typeof c === "function", fa = typeof a === "function", ry = r * sy;+ p.shade(cx - r - 1, cy - ry - 1, cx + r + 1, cy + ry + 1, (x, y, o) => {+ const nx = (x - cx) / r, ny = (y - cy) / Math.max(0.3, ry), d = Math.hypot(nx, ny);if (d < 1e-6) return;- const g = Math.hypot(nx / rx, ny / ry) / d;+ const g = Math.hypot(nx / r, ny / Math.max(0.3, ry)) / d;if (Math.abs(d - 1) / g > 0.5) return;const ang = Math.atan2(ny, nx);+ if (keep && !keep(ang)) return;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);+// An original rune alphabet: angular 3 x 5 glyphs that stay readable standing upright at 1x.+export const GLYPHS = [+ [".#.", "#.#", ".#.", ".#.", "#.#"],+ ["#.#", "#.#", ".#.", "#.#", "#.#"],+ ["##.", "#.#", "##.", "#..", "#.."],+ ["#..", "#.#", "###", "#.#", "..#"],+ [".##", "#..", ".#.", "..#", "##."],+ ["###", ".#.", "###", ".#.", ".#."],+ ["#.#", "###", "#.#", "..#", "..#"],+ [".#.", ".##", ".#.", "##.", ".#."],+];/**- * 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.+ * Rune i standing on (x, y): its bottom row sits on y, centred on x. c body color, a alpha (dithered), under an+ * optional darker color drawn a pixel lower so the glyph has a little thickness.*/-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;- });+export function glyph(p, i, x, y, c, a = 1, under = 0) {+ const g = GLYPHS[((i % GLYPHS.length) + GLYPHS.length) % GLYPHS.length], X = Math.round(x) - 1, Y = Math.round(y) - g.length + 1;+ if (under) p.sprite(g, {}, X, Y + 1, { tint: under, a });+ p.sprite(g, {}, X, Y, { tint: c, a });+}++// Larger original sigils, 5 x 7, for runes that fly or hover on their own.+export const SIGILS = [+ ["..#..", ".#.#.", "#.#.#", "..#..", ".###.", "..#..", ".#.#."],+ ["#...#", ".#.#.", "..#..", ".###.", "..#..", ".#.#.", "#...#"],+ ["#....", "##...", "#.#..", "#..#.", "#.#..", "##...", "#...."],+ ["..#..", "#.#.#", ".###.", "..#..", "..#..", ".#.#.", "#...#"],+ ["#.#.#", "#.#.#", "#####", "..#..", "..#..", "..#..", ".###."],+ ["#...#", "##.##", "#.#.#", "#...#", "#.#.#", "##.##", "#...#"],+ ["..#..", ".#.#.", "#...#", ".#.#.", "..#..", "..#..", "..#.."],+ ["#..#.", "#.#..", "##...", "#....", "##...", "#.#..", "#..#."],+];++/** Sigil i centred on (x, y) in color c, ringed by a 1 px edge in a darker color so it reads against anything. */+export function sigil(p, i, x, y, c, a = 1, edge = 0) {+ const g = SIGILS[((i % SIGILS.length) + SIGILS.length) % SIGILS.length], X = Math.round(x) - 2, Y = Math.round(y) - 3;+ if (edge) for (const [dx, dy] of CROSS) p.sprite(g, {}, X + dx, Y + dy, { tint: edge, a });+ p.sprite(g, {}, X, Y, { tint: c, a });+}++/** A character's silhouette shaded by how light each pixel is: 1 its dark outline, 2 mid, 3 light (0 empty). */+export function shades(A) {+ const s = new Uint8Array(A.w * A.h);+ for (let i = 0; i < s.length; i++) if (A.mask.data[i]) s[i] = A.pixels ? (luma(A.pixels[i]) < 0.24 ? 1 : luma(A.pixels[i]) < 0.62 ? 2 : 3) : 2;+ return s;+}++/**+ * Silhouette A (an actor) squeezed to sx of its width about its middle and shifted by dx: body color on its+ * pixels, edge color on its dark outline pixels. sh is shades(A). The blink's squeeze, adapted from Sprite Fusion.+ */+export function squeezed(p, A, sh, sx, body, edge, a = 1, dx = 0) {+ if (sx <= 0.02) return;+ const cx = A.x + A.w / 2, half = A.w / 2 + 1;+ for (let y = 0; y < A.h; y++)+ for (let x = Math.floor(cx - half * sx); x <= Math.ceil(cx + half * sx); x++) {+ const i = Math.round(cx + (x + 0.5 - cx) / sx - 0.5) - A.x, v = i < 0 || i >= A.w ? 0 : sh[y * A.w + i];+ if (v) p.dot(x + dx, A.y + y, v === 1 ? edge : body, a);+ }}diff --git a/src/fx/arcane/arcane-beam.js b/src/fx/arcane/arcane-beam.jsindex 1687982..47891f0 100644--- a/src/fx/arcane/arcane-beam.js+++ b/src/fx/arcane/arcane-beam.js@@ -1,70 +1,102 @@-import { PAL, cycle, clamp, tileNoise, TAU, WHITE } from "../../core/index.js";-import { fit, sparkle } from "./_lib.js";+// The beam (banded across, pulses running down it, sine strands that brighten in front, a source flare with+// spinning rays, an end flare spraying rays and sparks) is adapted from Sprite Fusion's open-source energy beam+// (https://www.spritefusion.com/pixel-art-vfx/energy), MIT License, Copyright (c) 2026 Hugo Duprez.+import { PAL, fit, cycle, fly, flyV, loopNoise, fract, ease, sparkle, TAU, WHITE } from "../../core/index.js";+import { bayer, mote } from "./_lib.js";++const D = 1.2, HX = 15, HY = -24, L = 168, W = 6;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,+ desc: "A beam fires right from the hand: a white core, strands twisting round it, pulses running down it, a flaring source and an end that sprays sparks.",+ tags: ["arcane", "beam", "laser", "ray", "magic", "directional", "loop"],+ size: [264, 100],+ origin: [26, 84],+ duration: D,loop: true,fps: 30,- bg: "dark",- options: { palette: PAL.arcane, length: 104, width: 4, seed: 15 },+ bg: "ground",+ actor: 2,+ options: { palette: PAL.arcane, seed: 10 },};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]));+ const C = fit(o.palette, 8), ph = t / D, S = o.seed, EX = HX + L;+ // the body, built across from a white core out to a dithered violet edge, wobbling and pulsing as it goes+ const LV = [WHITE, C[6], C[5], C[4], C[3], C[2]];+ for (let d = 0; d <= L; d += 0.5) {+ const x = HX + d, w = W * (1 + 0.12 * Math.sin(d * 0.35 - ph * TAU * 8)) * Math.min(1, (d + 3) / 7);+ const pulse = fract(d * 0.025 - ph * 4) < 0.07 ? 1 : 0;+ for (let q0 = -w * 1.3; q0 <= w * 1.3; q0 += 0.5) {+ const q = Math.abs(q0) / w, y = HY + q0;+ let lv = q < 0.2 ? 0 : q < 0.4 ? 1 : q < 0.62 ? 2 : q < 0.85 ? 3 : q < 1 ? 4 : 5;+ lv = Math.max(0, lv - pulse);+ if (lv === 5 && bayer(x, y) > (1.3 - q) / 0.3) continue;+ p.px(x, y, LV[lv]);+ }+ // three strands twisting round it: bright on the near side, gone behind+ for (let s = 0; s < 3; s++) {+ const a = d * 0.17 - ph * TAU * 6 + (s * TAU) / 3, off = Math.sin(a) * w * 1.05;+ if (Math.cos(a) > -0.15) p.dot(x, HY + off, Math.cos(a) > 0.55 ? WHITE : C[6]);+ }+ if ((Math.round(d * 2) & 11) === 0) p.glow(x, HY, w * 2.2 + 4, C[5], 0.2);+ }++ // the source: a flickering flare with spinning rays at the hand+ const fr = 4.2 + Math.sin(ph * TAU * 10) * 0.6;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]);+ const a = ph * TAU * 2.5 + (i * TAU) / 4, l = 7 + 3 * Math.sin(ph * TAU * 6 + i);+ p.line(HX, HY, HX + Math.cos(a) * l, HY + Math.sin(a) * l, (u) => (u < 0.5 ? WHITE : C[6]), (u) => (u < 0.6 ? 1 : 1.6 - u));+ }+ p.circle(HX, HY, fr + 1.5, C[4]);+ p.circle(HX, HY, fr, C[6]);+ p.circle(HX, HY, fr * 0.6, WHITE);+ p.glow(HX, HY, 32, C[5], 0.8);+ // energy drawn into the hand+ cycle(t, D, 10, S * 3 + 1, 0.18, (age, life, r) => {+ const a = r.range(0, TAU), dd = 16 * (1 - age / life) + 3, x = HX + Math.cos(a) * dd, y = HY + Math.sin(a) * dd;+ p.dot(x, y, age / life > 0.6 ? WHITE : C[6]);+ });++ // the end: a hot flare spraying rays, rings shocking out, sparks thrown back and falling+ const ir = 5 + Math.sin(ph * TAU * 12) * 0.8;+ for (let i = 0; i < 7; i++) {+ const a = Math.PI + (i - 3) * 0.36, l = 8 + 8 * Math.abs(loopNoise(ph, 4, S * 7 + i));+ p.line(EX, HY, EX + Math.cos(a) * l, HY + Math.sin(a) * l, (u) => (u < 0.4 ? WHITE : i % 2 ? C[5] : C[6]), (u) => (u < 0.6 ? 1 : 1.6 - u));+ }+ for (let k = 0; k < 3; k++) {+ const q = fract(ph * 3 + k / 3);+ p.ring(EX, HY, 3 + 15 * ease.outCubic(q), Math.max(1, 2 * (1 - q)), q < 0.25 ? WHITE : C[5], 1.1 - q);}- // 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.circle(EX, HY, ir + 1.5, C[4]);+ p.circle(EX, HY, ir, C[6]);+ p.circle(EX, HY, ir * 0.55, WHITE);+ p.glow(EX, HY, 40, C[5], 0.9);+ p.glow(EX, HY, 12, WHITE, 0.6);+ // a fountain of sparks thrown up and back off the end, arcing down+ cycle(t, D, 220, S * 3 + 2, (g) => g.range(0.18, 0.5), (age, life, r) => {+ const a = Math.PI * 1.5 + r.range(-1.7, 0.45), sp = r.range(70, 260), vx = Math.cos(a) * sp, vy = Math.sin(a) * sp - 30;+ const [x, y] = fly(EX, HY, vx, vy, age, 480, 2.2), [ux, uy] = flyV(vx, vy, age, 480, 2.2), k = 1 - age / life;+ if (y > -1) return;+ const head = k > 0.6 ? WHITE : k > 0.3 ? C[6] : C[5], sp2 = Math.hypot(ux, uy) || 1, len = Math.min(8, 1 + sp2 * 0.022);+ p.line(x - (ux / sp2) * len, y - (uy / sp2) * len, x, y, (u) => (u > 0.5 ? head : C[4]));+ p.glow(x, y, 3, head, 0.45 * k);+ });+ cycle(t, D, 6, S * 3 + 3, 0.3, (age, life, r) => {+ const k = Math.sin((age / life) * Math.PI);+ sparkle(p, EX + r.range(-12, 4), HY + r.range(-12, 12), 1 + 2.5 * k, C[6], C[5], 0.4 * k);+ });+ // violet vapour lifting off the end+ cycle(t, D, 7, S * 3 + 5, (g) => g.range(0.8, 1.2), (age, life, r) => {+ const q = age / life, x = EX + r.range(-8, 4) - q * 6, y = HY - 4 - q * r.range(14, 24), rad = r.range(3, 5) * (0.7 + 0.8 * q);+ p.disc(x, y, rad, C[4], (dd) => 0.28 * Math.sin(q * Math.PI) * (1 - dd * dd));+ });+ // motes shed along the beam+ cycle(t, D, 16, S * 3 + 4, (g) => g.range(0.3, 0.6), (age, life, r) => {+ const q = age / life, x = HX + r.range(10, L - 10) + q * 20, y = HY + r.sign() * (W + 1 + q * r.range(4, 10));+ mote(p, x, y, 40, (y - HY) * 1.5, r.chance(0.5) ? C[6] : C[5], 0.6, 1 - q, 0.3);});- 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);+ // the floor beneath catches the light+ p.glow(EX, -1, 30, C[5], 0.25);+ p.glow(HX + L / 2, -1, 60, C[4], 0.12);}diff --git a/src/fx/arcane/arcane-missiles.js b/src/fx/arcane/arcane-missiles.jsindex 63a60ad..50ddf44 100644--- a/src/fx/arcane/arcane-missiles.js+++ b/src/fx/arcane/arcane-missiles.js@@ -1,102 +1,164 @@-import { PAL, burst, fly, seg, ease, bump, rng, TAU, WHITE } from "../../core/index.js";-import { fit, sparkle } from "./_lib.js";+// The bolt and its pop (a layered head with spinning rays, a flash disc, a cross, a ring, plasma sparks and stars)+// are adapted from Sprite Fusion's open-source energy bolt (https://www.spritefusion.com/pixel-art-vfx/energy),+// MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Lights, P, Rng, PAL, fit, sparkle, clamp, smooth, ease, TAU, WHITE } from "../../core/index.js";++const HX = 15, HY = -24, TX = 152, TY = -22, N = 5, TRAIL = 18;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,+ desc: "A volley of violet bolts fans out of the hand, curls round on twisting ribbons and pops on the target one after another.",+ tags: ["arcane", "missile", "projectile", "homing", "volley", "magic", "directional", "one-shot"],+ size: [240, 116],+ origin: [26, 88],+ duration: 1.75,loop: false,fps: 30,- bg: "dark",- options: { palette: PAL.arcane, count: 4, range: 86, seed: 7 },+ bg: "ground",+ actor: 2,+ options: { palette: PAL.arcane, seed: 3 },};-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;-};+export function create(o) {+ const C = fit(o.palette, 8), R = new Rng(o.seed);+ const ps = new Particles({ rng: R, ground: () => 0, sparks: [WHITE, C[6], C[5], C[4]] }), lights = new Lights();+ // each bolt leaves the hand on its own heading, then homes in harder and faster until it lands+ const fan = [-1.05, 0.7, -0.5, 1.1, -1.4];+ const bolts = fan.map((a, i) => {+ a += R.range(-0.12, 0.12);+ const sp = R.range(130, 165);+ return { t0: 0.05 + i * 0.1, x: HX, y: HY, vx: Math.cos(a) * sp, vy: Math.sin(a) * sp, trail: [], hit: -1, on: false, tx: TX + R.range(-3, 3), ty: TY + R.range(-6, 6), tw: R.range(0, TAU), acc: 0 };+ });+ const pops = [];+ let t = 0;-// 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 };-}+ function ribbon(p, b) {+ const pts = b.trail, n = pts.length, fade = b.hit < 0 ? 1 : 1 - clamp((t - b.hit) / 0.16);+ if (n < 2 || fade <= 0) return;+ for (let i = 0; i < n - 1; i++) {+ const [x0, y0] = pts[i], [x1, y1] = pts[i + 1], L = Math.hypot(x1 - x0, y1 - y0) || 1, nx = -(y1 - y0) / L, ny = (x1 - x0) / L;+ for (let d = 0; d < L; d += 0.5) {+ const u = (i + d / L) / (n - 1), x = x0 + ((x1 - x0) * d) / L, y = y0 + ((y1 - y0) * d) / L, a = (1 - u) * 1.7 * fade;+ // the body: a capsule that tapers down the tail, white along its middle near the head, cooling outward+ const w = 2.6 * Math.pow(1 - u, 0.8) + 0.3;+ for (let q = -w; q <= w; q += 0.5) {+ const v = Math.abs(q) / w;+ p.dot(x + nx * q, y + ny * q, v < 0.35 ? (u < 0.25 ? WHITE : C[6]) : v < 0.7 ? (u < 0.4 ? C[6] : C[5]) : u < 0.5 ? C[5] : C[4], a * (v < 0.7 ? 1 : 0.75));+ }+ // two strands twisting round it: bright where they come round the front, dim behind+ for (const s of [0, Math.PI]) {+ const ph = u * 10 - t * 26 + b.tw + s, off = Math.sin(ph) * (w + 1.4);+ if (Math.cos(ph) > -0.2) p.dot(x + nx * off, y + ny * off, Math.cos(ph) > 0.4 ? (u < 0.35 ? WHITE : C[6]) : C[4], a);+ }+ }+ if (i % 3 === 0) p.glow(x0, y0, 9 * (1 - i / n) + 3, C[5], 0.3 * (1 - i / n) * fade);+ }+ }-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);+ function head(p, b) {+ const x = b.x, y = b.y;+ for (let i = 0; i < 4; i++) {+ const a = t * 24 + (i * TAU) / 4 + b.tw, l = 5.5 + 1.5 * Math.sin(t * 50 + i);+ p.line(x + Math.cos(a) * 3.2, y + Math.sin(a) * 3.2, x + Math.cos(a) * l, y + Math.sin(a) * l, C[6]);+ }+ p.circle(x, y, 3.8, C[4]);+ p.circle(x, y, 3, C[5]);+ p.circle(x, y, 2.1, C[6]);+ p.circle(x, y, 1.2, WHITE);+ p.glow(x, y, 24, C[5], 0.6);+ p.glow(x, y, 7, WHITE, 0.4);}- 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);++ function pop(p, q, x, y) {+ if (q < 0.16) {+ const r = 9 * (1 - q / 0.16) + 1.5;+ p.circle(x, y, r + 1.5, C[5]);+ p.circle(x, y, r, WHITE);}- // 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);+ if (q < 0.4) {+ const l = 15 * (1 - q / 0.4) + 3;+ for (let d = -l; d <= l; d++) {+ const a = Math.abs(d) / l, c = a < 0.3 ? WHITE : a < 0.65 ? C[6] : C[5];+ p.dot(x + d, y, c, 1.15 - a);+ p.dot(x, y + d * 0.7, c, 1.15 - a);}- 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));}- });+ const rr = 3 + 18 * ease.outCubic(q);+ p.ring(x, y, rr + 0.5, Math.max(1, 3 * (1 - q)), q < 0.3 ? WHITE : C[6], 1.2 - q);+ }++ // the lock: four brackets close on the target and pulse as each bolt lands+ function lock(p) {+ const k = smooth(0, 0.22, t) * (1 - smooth(1.15, 1.45, t));+ if (k <= 0) return;+ let kick = 0;+ for (const q of pops) kick = Math.max(kick, Math.exp(-(((t - q.t) / 0.06) ** 2)));+ const r = 9 + 10 * (1 - ease.outCubic(smooth(0, 0.22, t))) + 3 * kick, spin = t * 1.5;+ for (let i = 0; i < 4; i++) {+ const a0 = spin + (i * TAU) / 4 - 0.38;+ for (let a = a0; a <= a0 + 0.76; a += 0.06) p.dot(TX + Math.cos(a) * r, TY + Math.sin(a) * r, kick > 0.4 ? WHITE : C[5], k);+ }+ p.glow(TX, TY, 12, C[4], 0.2 * k);+ }++ return {+ update(dt) {+ t += dt;+ for (const b of bolts) {+ if (t < b.t0 || b.hit >= 0) continue;+ if (!b.on) {+ b.on = true;+ lights.add(HX, HY, 28, C[5], 0.7, 0.14);+ for (let i = 0; i < 4; i++) ps.spawn(P.MOTE, HX, HY, Math.cos(Math.atan2(b.vy, b.vx) + R.range(-0.6, 0.6)) * R.range(60, 140), Math.sin(Math.atan2(b.vy, b.vx) + R.range(-0.6, 0.6)) * R.range(60, 140), R.range(0.12, 0.25), C[6], 0.6);+ }+ const age = t - b.t0, dx = b.tx - b.x, dy = b.ty - b.y, d = Math.hypot(dx, dy) || 1;+ const sp = 150 + 560 * age * age, steer = Math.min(1, (1.4 + 15 * age) * dt);+ b.vx += ((dx / d) * sp - b.vx) * steer;+ b.vy += ((dy / d) * sp - b.vy) * steer;+ b.x += b.vx * dt;+ b.y += b.vy * dt;+ b.trail.unshift([b.x, b.y]);+ if (b.trail.length > TRAIL) b.trail.pop();+ if ((b.acc += dt) > 0.012) {+ b.acc = 0;+ if (R.chance(0.6)) ps.spawn(P.MOTE, b.x, b.y, -b.vx * 0.08 + R.range(-25, 25), -b.vy * 0.08 + R.range(-25, 25), R.range(0.2, 0.4), R.chance(0.5) ? C[6] : C[5], 0.55);+ }+ if (d < 3 || age > 1.3) {+ b.hit = t;+ pops.push({ t, x: b.x, y: b.y });+ lights.add(b.x, b.y, 70, C[5], 0.9, 0.3);+ lights.add(b.x, b.y, 24, WHITE, 0.85, 0.09);+ for (let i = 0; i < 16; i++) {+ const a = R.range(0, TAU), v = R.range(80, 230);+ ps.spawn(P.SPARK, b.x, b.y, Math.cos(a) * v, Math.sin(a) * v - 40, R.range(0.15, 0.45));+ }+ for (let i = 0; i < 7; i++) {+ const a = R.range(-Math.PI, 0.3), v = R.range(40, 140);+ ps.spawn(i % 2 ? P.STAR : P.MOTE, b.x, b.y, Math.cos(a) * v, Math.sin(a) * v, R.range(0.25, 0.48), R.pick([WHITE, C[6], C[5]]), R.range(0.8, 1.6));+ }+ }+ }+ ps.update(dt);+ lights.update(dt);+ },+ drawBack(p) {+ // the floor catches the light of each pop+ for (const q of pops) {+ const k = 1 - clamp((t - q.t) / 0.5);+ if (k > 0) p.glow(q.x, -1, 22, C[5], 0.25 * k * k);+ }+ },+ draw(p) {+ lock(p);+ for (const b of bolts) if (b.on) ribbon(p, b);+ for (const b of bolts) if (b.on && b.hit < 0) head(p, b);+ for (const q of pops) {+ const k = (t - q.t) / 0.35;+ if (k < 1) pop(p, k, q.x, q.y);+ }+ if (t < 0.55) sparkle(p, HX, HY, 3 + 2 * Math.sin(t * 40), C[6], C[5], 0.45 * (1 - t / 0.55));+ ps.draw(p);+ lights.draw(p);+ },+ };}diff --git a/src/fx/arcane/arcane-orb.js b/src/fx/arcane/arcane-orb.jsindex 258af05..ed84392 100644--- a/src/fx/arcane/arcane-orb.js+++ b/src/fx/arcane/arcane-orb.js@@ -1,69 +1,132 @@-import { PAL, cycle, TAU, WHITE } from "../../core/index.js";-import { fit, tiltedOval, sparkle } from "./_lib.js";+// The orb (a glassy bubble that thickens towards its rim, a hot core, a double rim, a highlight arc and spot,+// motes orbiting in front and behind) is adapted from Sprite Fusion's open-source energy orb+// (https://www.spritefusion.com/pixel-art-vfx/energy), MIT License, Copyright (c) 2026 Hugo Duprez.+import { PAL, fit, cycle, sparkle, TAU, WHITE } from "../../core/index.js";+import { mote } from "./_lib.js";++const D = 2.4, RAD = 17, Y0 = -52;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,+ desc: "A floating orb of smoky violet glass with a swirl turning round a white-hot heart, two tilted rings of light orbiting behind and in front.",+ tags: ["arcane", "orb", "sphere", "magic", "floating", "loop"],+ size: [136, 112],+ origin: [68, 104],+ duration: D,loop: true,fps: 30,- bg: "dark",- options: { palette: PAL.arcane, radius: 7, seed: 14 },+ bg: "ground",+ options: { palette: PAL.arcane, seed: 6 },};-// the two rings: size, tilt, how fast their beads run (whole laps a loop, so it loops clean)+// two rings, each a circle tilted in depth (sy) and rolled in the picture (rot), beads running round itconst 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 },+ { r: 31, sy: 0.24, rot: 0.36, beads: 3, turn: 2, c: 0 },+ { r: 27, sy: 0.3, rot: -0.55, beads: 2, turn: -3, c: 1 },];-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);+function setup(t) {+ const ph = t / D;+ return { ph, cx: 0, cy: Y0 + Math.sin(ph * TAU) * 2 };+}++// one ring's points on the near (z > 0) or far side; beads brighter, with light+function ring(p, C, s, R, near) {+ const { ph, cx, cy } = s, rot = R.rot + 0.12 * Math.sin(ph * TAU + R.c), cr = Math.cos(rot), sr = Math.sin(rot), n = Math.ceil(R.r * TAU * 1.5);+ const pos = (g) => {+ const lx = Math.cos(g) * R.r, ly = Math.sin(g) * R.r * R.sy;+ return [cx + lx * cr - ly * sr, cy + lx * sr + ly * cr];+ };+ for (let j = 0; j < n; j++) {+ const g = (j / n) * TAU, z = Math.sin(g);+ if (z > 0 !== near) continue;+ const [x, y] = pos(g);+ p.dot(x, y, near ? C[5] : C[4], near ? 0.7 : 0.4);+ }+ for (let b = 0; b < R.beads; b++) {+ const g = ph * TAU * R.turn + (b * TAU) / R.beads;+ for (let k = 0; k < 7; k++) {+ // a bead and its trail along the ring+ const gg = g - Math.sign(R.turn) * k * 0.07, z = Math.sin(gg);+ if (z > 0 !== near) continue;+ const [x, y] = pos(gg);+ p.dot(x, y, k === 0 ? WHITE : k < 3 ? C[6] : C[5], k < 4 ? 1 : 1 - (k - 3) / 4);+ if (k === 0) p.glow(x, y, near ? 7 : 5, C[6], near ? 0.5 : 0.25);}}}-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]);+// the orb itself: smoky glass, the swirl, the heart, the rim, the highlights+function orb(p, C, s) {+ const { ph, cx, cy } = s;+ // the glass: translucent, thicker towards the rim+ p.disc(cx, cy, RAD, (d) => (d > 0.82 ? C[2] : C[1]), (d) => 0.32 + 0.5 * d * d);+ // the swirl: two bright arms and two faint ones turning round the heart, twice a loop+ // the swirl: two bright arms with a lilac edge, and two faint ones between, turning twice a loop+ for (const [s0, main] of [[0, 1], [Math.PI, 1], [Math.PI / 2, 0], [(3 * Math.PI) / 2, 0]])+ for (let u = 0.08; u <= 0.85; u += 0.012) {+ const a = ph * TAU * 2 + s0 + u * 3.4, r = u * RAD * 0.92, x = cx + Math.cos(a) * r, y = cy + Math.sin(a) * r, fade = u < 0.6 ? 1 : 1 - (u - 0.6) / 0.25;+ if (!main) {+ p.dot(x, y, C[4], fade * 0.8);+ continue;+ }+ // the arm's lit edge trails just behind it+ const b = a - 0.16, xb = cx + Math.cos(b) * r, yb = cy + Math.sin(b) * r;+ p.dot(xb, yb, u < 0.4 ? C[6] : C[5], fade);+ p.dot(x, y, u < 0.3 ? WHITE : u < 0.55 ? C[6] : C[5], fade);+ }+ // the heart+ const pulse = 0.85 + 0.15 * Math.sin(ph * TAU * 3);+ p.circle(cx, cy, 3.6 * pulse + 1, C[5]);+ p.circle(cx, cy, 2.8 * pulse, C[6]);+ p.circle(cx, cy, 1.7 * pulse, WHITE);+ // the rim: a bright line just inside a dark one, a highlight arc and spot top left, a glint bottom right+ p.ring(cx, cy, RAD + 0.4, 1, C[5]);+ p.ring(cx, cy, RAD + 1.3, 1, C[2], 0.8);+ for (let a = 3.5; a < 4.7; a += 0.03) p.dot(cx + Math.cos(a) * (RAD - 2.4), cy + Math.sin(a) * (RAD - 2.4), a > 3.85 && a < 4.35 ? WHITE : C[6]);+ p.circle(cx - RAD * 0.42, cy - RAD * 0.5, 1.3, WHITE);+ p.dot(cx + RAD * 0.52, cy + RAD * 0.55, C[6]);+ p.glow(cx, cy, 20, C[6], 0.26 * pulse);+ p.glowRing(cx, cy, RAD, 6, C[5], 0.25);+}++// motes orbiting on tilted paths, and sparks drifting off the orb+function motes(p, C, s, S, near) {+ const { ph, cx, cy } = s;+ for (let i = 0; i < 8; i++) {+ const a = ((i * 2.4 + S) % TAU) + ph * TAU * (i % 2 ? 1 : -1) * (1 + (i % 3)), rr = RAD + 5 + ((i * 0.37) % 1) * 12, tilt = (((i * 0.71) % 1) - 0.5) * 1.4;+ const x0 = Math.cos(a) * rr, z = Math.sin(a);+ if (z > 0 !== near) continue;+ const x = cx + x0 * Math.cos(tilt), y = cy + x0 * Math.sin(tilt) + z * rr * 0.28, dir = i % 2 ? 1 : -1;+ p.dot(x, y, near ? WHITE : C[5]);+ p.dot(x - dir, y, near ? C[6] : C[4], near ? 1 : 0.6);+ if (near) p.dot(x - 2 * dir, y, C[4], 0.6), p.glow(x, y, 5, C[6], 0.35);+ }+ if (!near) return;+ cycle(ph * D, D, 10, S * 3 + 1, (g) => g.range(0.6, 1), (age, life, r) => {+ const a = r.range(0, TAU), q = age / life, d = RAD + 1 + q * r.range(8, 18);+ const x = cx + Math.cos(a) * d, y = cy + Math.sin(a) * d - q * 10;+ mote(p, x, y, Math.cos(a) * 25, Math.sin(a) * 25 - 12, r.chance(0.5) ? C[6] : C[5], 0.6, 1 - q, 0.3);});- 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);}+export function drawBack(p, t, o) {+ const C = fit(o.palette, 8), s = setup(t), lift = (s.cy - Y0) / 2;+ // the light it throws on the floor, stronger as it bobs down+ p.glow(0, -1, 36, C[4], 0.26 - 0.04 * lift);+ for (let x = -20; x <= 20; x++) {+ const u = Math.abs(x + 0.5) / 20;+ p.dot(x, 0, u < 0.3 ? C[6] : C[5], (1.1 - u) * (0.9 - 0.15 * lift));+ }+ p.glow(s.cx, s.cy, 60, C[4], 0.36);+ for (const R of RINGS) ring(p, C, s, R, false);+ motes(p, C, s, o.seed, false);+}++export function draw(p, t, o) {+ const C = fit(o.palette, 8), s = setup(t);+ orb(p, C, s);+ for (const R of RINGS) ring(p, C, s, R, true);+ motes(p, C, s, o.seed, true);+ sparkle(p, s.cx - RAD * 0.42, s.cy - RAD * 0.5, 1.5 + Math.max(0, Math.sin(s.ph * TAU * 2)) * 2, C[6], C[5], 0.3);+}diff --git a/src/fx/arcane/blink-in.js b/src/fx/arcane/blink-in.jsindex 070e6ea..f2def8d 100644--- a/src/fx/arcane/blink-in.js+++ b/src/fx/arcane/blink-in.js@@ -1,70 +1,123 @@-import { PAL, burst, cycle, seg, ease, clamp, stockActor, TAU, WHITE } from "../../core/index.js";-import { fit, silhouette, sparkle } from "./_lib.js";+// The arrival (bits converging, a line of light that opens into the silhouette, a ring on the floor, a burst of+// stars) is adapted from Sprite Fusion's open-source blink (https://www.spritefusion.com/pixel-art-vfx/movement),+// MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Lights, P, Rng, PAL, fit, band, flare, sparkle, clamp, ease, rand, TAU, WHITE } from "../../core/index.js";+import { shades, squeezed } from "./_lib.js";++const LINE = 0.26, GROW = 0.1, OPEN = 0.12, ARRIVE = LINE + GROW + OPEN;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,+ desc: "Glittering bits spiral in to a point of light that opens into a line, then into a white silhouette that cools into the caster.",+ tags: ["arcane", "blink", "teleport", "appear", "movement", "magic", "one-shot"],+ size: [136, 96],+ origin: [68, 80],+ duration: 1.4,loop: false,fps: 30,bg: "ground",- actor: false,- options: { palette: PAL.arcane, seed: 13 },+ actor: 2,+ options: { palette: PAL.arcane, seed: 12 },};-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]);+/** The stand-in character appears once the silhouette has opened. */+export const actorAlpha = (t) => (t < ARRIVE ? 0 : 1);++export function create(o) {+ const C = fit(o.palette, 8), R = new Rng(o.seed), A = o.actor, sh = shades(A);+ const ps = new Particles({ rng: R, ground: () => 0, sparks: [WHITE, C[6], C[5], C[4]] }), lights = new Lights();+ const mx = A.x + A.w / 2, my = A.y + A.h * 0.55, COLS = [WHITE, C[6], C[6], C[5], C[4]];+ const inside = (x, y) => x >= 0 && y >= 0 && x < A.w && y < A.h && A.mask.data[y * A.w + x];+ // the bits: each spirals in from its own spot to a point on the line, arriving as the line forms+ const bits = Array.from({ length: 230 }, () => {+ const a = R.range(0, TAU), d = R.range(16, 46), ty = A.y + R.range(3, A.h - 2);+ let oy = Math.sin(a) * d * 0.8 - 6;+ if (ty + oy > -2) oy = -Math.abs(oy) - 2; // none start under the floor+ return { tx: mx + R.range(-1, 1), ty, ox: Math.cos(a) * d, oy, t0: R.range(0, 0.1), t1: LINE + R.range(-0.02, GROW), spin: R.range(0.8, 1.8) * R.sign(), c: R.pick(COLS) };});- if (a >= 0) p.glow(0, cy, 12, C[4], 0.3 * clamp(1 - (a - 0.1) / 0.4));+ let t = 0, arrived = false;+ const at = (b, tt) => {+ const k = clamp((tt - b.t0) / (b.t1 - b.t0)), e = ease.outCubic(k), r = 1 - e, sp = b.spin * r * 1.2;+ const ox = b.ox * Math.cos(sp) - b.oy * Math.sin(sp), oy = b.ox * Math.sin(sp) + b.oy * Math.cos(sp);+ return [b.tx + ox * r, Math.min(-1, b.ty + oy * r), k];+ };++ return {+ update(dt) {+ t += dt;+ if (t < LINE && R.chance(0.6)) {+ const a = R.range(0, TAU), D = R.range(22, 44), T = R.range(0.12, 0.18), v = (D * 3) / (Math.exp(3 * T) - 1);+ const x = mx + Math.cos(a) * D, y = Math.min(-2, my + Math.sin(a) * D), l = Math.hypot(x - mx, y - my) || 1;+ ps.spawn(P.STREAK, x, y, ((mx - x) / l) * v, ((my - y) / l) * v, T, R.chance(0.5) ? C[6] : C[5]);+ }+ if (!arrived && t >= ARRIVE) {+ arrived = true;+ lights.add(mx, my - 6, 56, C[5], 0.9, 0.35);+ lights.add(mx, my, 24, WHITE, 0.8, 0.1);+ for (let i = 0; i < 30; i++) {+ const a = R.range(0, TAU), sp = R.range(35, 110);+ ps.spawn(R.chance(0.6) ? P.STAR : P.MOTE, mx, my, Math.cos(a) * sp, Math.sin(a) * sp * 0.7 - 30, R.range(0.4, 0.85), R.pick(COLS), R.range(0.6, 1.6));+ }+ for (let i = 0; i < 12; i++) {+ const s = R.sign();+ ps.spawn(P.SPARK, mx + s * R.range(2, 8), -1, s * R.range(60, 180), -R.range(20, 110), R.range(0.2, 0.45));+ }+ }+ ps.update(dt);+ lights.update(dt);+ },+ drawBack(p) {+ const k = (t - ARRIVE + 0.03) / 0.5;+ if (k >= 0 && k < 1) band(p, 0, 0, 4 + 30 * ease.outCubic(k), 0.2, Math.max(1, 3 * (1 - k)), 1.15 - k, [C[3], C[5], C[6], WHITE], (g) => Math.sin(g) < 0, k < 0.25);+ p.glow(0, -1, 26, C[5], 0.3 * (t < ARRIVE ? t / ARRIVE : 1 - clamp((t - ARRIVE) / 0.5)));+ },+ draw(p) {+ // the bits rushing in, streaking as they speed up, white as they land+ for (const b of bits) {+ if (t < b.t0 || t > b.t1 + 0.02) continue;+ const [x, y, k] = at(b, t);+ p.dot(x, y, k > 0.75 ? WHITE : b.c, Math.min(1, 0.35 + k * 2));+ // a short tail once they're rushing+ if (k > 0.55) {+ const [px, py] = at(b, t - 0.015);+ p.dot((x + px) / 2, (y + py) / 2, C[5], 0.8);+ }+ if (k > 0.8) p.glow(x, y, 3, C[6], 0.3);+ }+ if (t >= LINE - 0.04 && t < LINE) {+ // a point of light where it gathers+ const q = (t - LINE + 0.04) / 0.04;+ sparkle(p, mx, my, 2 + 3 * q, C[6], C[5], 0.6);+ } else if (t >= LINE && t < LINE + GROW) {+ // it opens into a line, top to bottom+ const q = ease.outCubic((t - LINE) / GROW), hh = (A.h / 2 + 3) * q;+ for (let y = -hh - 2; y <= hh + 2; y++) p.dot(mx, my + y, Math.abs(y) < hh ? WHITE : C[6], Math.abs(y) < hh ? 1 : 0.7);+ for (let y = -hh * 0.7; y <= hh * 0.7; y++) (p.dot(mx - 1, my + y, C[5], 0.6), p.dot(mx + 1, my + y, C[5], 0.6));+ p.glow(mx, my, 30, C[5], 0.9);+ p.glow(mx, my, 8, WHITE, 0.5);+ } else if (t >= LINE + GROW && t < ARRIVE) {+ // the line opens sideways into the silhouette, white hot+ const q = ease.outCubic((t - LINE - GROW) / OPEN);+ squeezed(p, A, sh, q, WHITE, C[6]);+ p.glow(mx, my, 36, C[5], 0.8);+ } else if (t >= ARRIVE && t < ARRIVE + 0.42) {+ // the caster cools out of the white: its body full of light, an outline crackling round it, both fading+ const k = 1 - (t - ARRIVE) / 0.42, f = Math.floor(t * 30);+ if (k > 0.86) squeezed(p, A, sh, 1, WHITE, C[6]);+ for (let y = 0; y < A.h; y++)+ for (let x = 0; x < A.w; x++)+ if (inside(x, y)) p.light(A.x + x, A.y + y, C[6], k * k * (sh[y * A.w + x] === 1 ? 0.3 : 0.8));+ else if ((inside(x - 1, y) || inside(x + 1, y) || inside(x, y - 1) || inside(x, y + 1)) && rand(x, y, f) < 0.85 * k) p.px(A.x + x, A.y + y, k > 0.5 && rand(x, y, 7) < 0.5 ? WHITE : C[6]);+ p.glow(mx, my, 34, C[5], 0.6 * k);+ }+ if (t >= ARRIVE && t < ARRIVE + 0.2) {+ const q = (t - ARRIVE) / 0.2;+ flare(p, mx, my - 4, 18 * Math.pow(1 - q, 1.5) + 2, 1 - q, C);+ }+ const k = (t - ARRIVE + 0.03) / 0.5;+ if (k >= 0 && k < 1) band(p, 0, 0, 4 + 30 * ease.outCubic(k), 0.2, Math.max(1, 3 * (1 - k)), 1.15 - k, [C[3], C[5], C[6], WHITE], (g) => Math.sin(g) >= 0, k < 0.25);+ ps.draw(p);+ lights.draw(p);+ },+ };}diff --git a/src/fx/arcane/blink-out.js b/src/fx/arcane/blink-out.jsindex e4a098c..4de94bd 100644--- a/src/fx/arcane/blink-out.js+++ b/src/fx/arcane/blink-out.js@@ -1,67 +1,121 @@-import { PAL, burst, fly, seg, ease, clamp, stockActor, TAU, WHITE } from "../../core/index.js";-import { fit, silhouette, sparkle } from "./_lib.js";+// The blink (a crackling outline as it gathers, a white flash, the silhouette squeezed into a line, a ring on the+// floor, a fading afterimage) is adapted from Sprite Fusion's open-source blink+// (https://www.spritefusion.com/pixel-art-vfx/movement), MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Lights, P, Rng, PAL, fit, band, flare, sparkle, clamp, ease, rand, TAU, WHITE } from "../../core/index.js";+import { shades, squeezed } from "./_lib.js";++const OUT = 0.32, SQUEEZE = 0.12, COLLAPSE = 0.08, POP = OUT + SQUEEZE + COLLAPSE;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,+ desc: "The caster crackles with gathering light, flashes white, squeezes into a line of light that collapses and pops away in sparks.",+ tags: ["arcane", "blink", "teleport", "vanish", "movement", "magic", "one-shot"],+ size: [136, 96],+ origin: [68, 80],+ duration: 1.6,loop: false,fps: 30,bg: "ground",- actor: false,- options: { palette: PAL.arcane, seed: 12 },+ actor: 2,+ options: { palette: PAL.arcane, seed: 11 },};-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));- }+/** The stand-in character is hidden from the flash on: the effect draws it from then. */+export const actorAlpha = (t) => (t < OUT ? 1 : 0);++export function create(o) {+ const C = fit(o.palette, 8), R = new Rng(o.seed), A = o.actor, sh = shades(A);+ const ps = new Particles({ rng: R, ground: () => 0, sparks: [WHITE, C[6], C[5], C[4]] }), lights = new Lights();+ const mx = A.x + A.w / 2, my = A.y + A.h * 0.55, COLS = [WHITE, C[6], C[6], C[5], C[4]];+ const inside = (x, y) => x >= 0 && y >= 0 && x < A.w && y < A.h && A.mask.data[y * A.w + x];+ let t = 0, out = false, popped = false;++ return {+ update(dt) {+ t += dt;+ // gathering: streaks rush in to the chest+ if (t < OUT - 0.04 && R.chance(0.7)) {+ const a = R.range(0, TAU), D = R.range(22, 44), T = R.range(0.12, 0.18), v = (D * 3) / (Math.exp(3 * T) - 1);+ const x = mx + Math.cos(a) * D, y = Math.min(-2, my + Math.sin(a) * D), l = Math.hypot(x - mx, y - my) || 1;+ ps.spawn(P.STREAK, x, y, ((mx - x) / l) * v, ((my - y) / l) * v, T, R.chance(0.5) ? C[6] : C[5]);+ }+ if (!out && t >= OUT) {+ out = true;+ lights.add(mx, my - 6, 54, C[5], 0.9, 0.3);+ lights.add(mx, my, 26, WHITE, 0.8, 0.1);+ }+ if (!popped && t >= POP) {+ popped = true;+ lights.add(mx, my - 6, 58, C[5], 0.9, 0.35);+ lights.add(mx, my, 24, WHITE, 0.9, 0.08);+ // the line bursts: bits of the character fly off and drift up, sparks and stars scatter+ for (let i = 0; i < 110; i++) {+ const y = A.y + R.range(2, A.h - 2), s = R.sign();+ ps.spawn(P.EMBER, mx + R.range(-1, 1), y, s * R.range(25, 105), R.range(-70, 10), R.range(0.5, 0.95), R.pick(COLS), R.chance(0.3) ? 2 : 1);+ }+ for (let i = 0; i < 18; i++) {+ const a = R.range(0, TAU), sp = R.range(80, 240);+ ps.spawn(P.SPARK, mx, my, Math.cos(a) * sp, Math.sin(a) * sp - 40, R.range(0.2, 0.5));+ }+ for (let i = 0; i < 14; i++) {+ const a = R.range(0, TAU), sp = R.range(20, 110);+ ps.spawn(i % 2 ? P.STAR : P.MOTE, mx, my, Math.cos(a) * sp, Math.sin(a) * sp * 0.8 - 20, R.range(0.4, 0.9), R.pick([WHITE, C[6], C[5]]), R.range(0.8, 1.8));+ }+ }+ ps.update(dt);+ lights.update(dt);+ },+ drawBack(p) {+ // the afterimage it leaves, and the far half of the ring+ // the afterimage it leaves: a translucent violet ghost that thins away+ if (t > POP && t < POP + 0.6) {+ const k = 0.5 * (1 - (t - POP) / 0.6);+ for (let y = 0; y < A.h; y++) for (let x = 0; x < A.w; x++) if (sh[y * A.w + x]) p.blend(A.x + x, A.y + y, sh[y * A.w + x] === 1 ? C[3] : C[4], k);+ }+ const k = (t - POP) / 0.5;+ if (k >= 0 && k < 1) band(p, 0, 0, 4 + 30 * ease.outCubic(k), 0.2, Math.max(1, 3 * (1 - k)), 1.15 - k, [C[3], C[5], C[6], WHITE], (g) => Math.sin(g) < 0, k < 0.25);+ if (t < POP + 0.3) p.glow(0, -1, 26, C[5], 0.3 * (t < OUT ? t / OUT : 1 - clamp((t - POP) / 0.3)));+ },+ draw(p) {+ const f = Math.floor(t * 30);+ if (t < OUT) {+ // the body brightens and an outline of light crackles round it, thicker as it gathers+ const k = t / OUT;+ for (let y = 0; y < A.h; y++)+ for (let x = 0; x < A.w; x++) {+ if (inside(x, y)) {+ // the body fills with light: its lit pixels most+ p.light(A.x + x, A.y + y, C[6], k * k * (sh[y * A.w + x] === 1 ? 0.3 : 0.75));+ } else if ((inside(x - 1, y) || inside(x + 1, y) || inside(x, y - 1) || inside(x, y + 1)) && rand(x, y, f) < 0.25 + 0.65 * k)+ p.px(A.x + x, A.y + y, k > 0.6 && rand(x, y, 7) < 0.5 ? WHITE : C[6]);+ }+ p.glow(mx, my, 30, C[5], 0.5 * k);+ } else if (t < OUT + 0.05) {+ squeezed(p, A, sh, 1, WHITE, C[6]);+ p.glow(mx, my, 40, C[5], 0.8);+ } else if (t < OUT + SQUEEZE) {+ // squeezed into a line+ const q = ease.inCubic((t - OUT - 0.05) / (SQUEEZE - 0.05));+ squeezed(p, A, sh, 1 - q, WHITE, C[6]);+ p.glow(mx, my, 34, C[5], 0.8);+ } else if (t < POP) {+ // the line shrinks to a point+ const q = (t - OUT - SQUEEZE) / COLLAPSE, hh = (A.h / 2 + 2) * (1 - ease.inQuad(q));+ for (let y = -hh - 3; y <= hh + 3; y++) p.dot(mx, my + y, Math.abs(y) < hh ? WHITE : C[6], Math.abs(y) < hh ? 1 : 0.7);+ if (hh > 4) for (let y = -hh * 0.7; y <= hh * 0.7; y++) (p.dot(mx - 1, my + y, C[5], 0.6), p.dot(mx + 1, my + y, C[5], 0.6));+ p.glow(mx, my, 30, C[5], 0.9);+ p.glow(mx, my, 8, WHITE, 0.5);+ }+ if (t >= POP && t < POP + 0.22) {+ const q = (t - POP) / 0.22;+ flare(p, mx, my, 22 * Math.pow(1 - q, 1.5) + 2, 1 - q, C);+ if (q < 0.3) p.circle(mx, my, 4 * (1 - q / 0.3) + 1, WHITE);+ }+ const k = (t - POP) / 0.5;+ if (k >= 0 && k < 1) band(p, 0, 0, 4 + 30 * ease.outCubic(k), 0.2, Math.max(1, 3 * (1 - k)), 1.15 - k, [C[3], C[5], C[6], WHITE], (g) => Math.sin(g) >= 0, k < 0.25);+ if (t > POP && t < POP + 0.3) sparkle(p, mx, my - 1, 3, C[6], C[5], 0.3 * (1 - (t - POP) / 0.3));+ ps.draw(p);+ lights.draw(p);+ },+ };}diff --git a/src/fx/arcane/enchant.js b/src/fx/arcane/enchant.jsdeleted file mode 100644index b65e7aa..0000000--- a/src/fx/arcane/enchant.js+++ /dev/null@@ -1,89 +0,0 @@-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.jsdeleted file mode 100644index fe28442..0000000--- a/src/fx/arcane/glyph-burst.js+++ /dev/null@@ -1,81 +0,0 @@-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.jsindex 91b23a1..c95d98a 100644--- a/src/fx/arcane/magic-circle-cast.js+++ b/src/fx/arcane/magic-circle-cast.js@@ -1,89 +1,285 @@-import { stream, seg, ease, clamp, tileNoise, TAU, WHITE } from "../../core/index.js";-import { fit, rune, ovalLine, ahead, AZURE } from "./_lib.js";+// The column of light (banded across, strands wandering in it, pulses and halos climbing it, stars thrown off,+// rings shocking out across the floor) is adapted from Sprite Fusion's open-source holy light+// (https://www.spritefusion.com/pixel-art-vfx/holy-light), MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Lights, P, Rng, PAL, fit, band, flare, sparkle, clamp, smooth, ease, noise2, fract, TAU, WHITE } from "../../core/index.js";+import { floorRing, bayer, glyph } from "./_lib.js";++// the circle on the floor (plane px; the floor squashes depth by SY), the column, the beats+const R = 40, R2 = 35, RI = 24, RR = 30, SY = 0.3, TOP = 192, W = 11, NRUNE = 8;+const PEN = [0.04, 0.42], PEN2 = [0.1, 0.48], INNER = [0.3, 0.6], STAR = [0.52, 0.88], RUNES = [0.9, 1.3];+const FLASH = 1.52, BREAK = 2.42, GONE = 3.45, END = 3.9;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,+ desc: "A circle draws itself on the floor, runes ignite one by one, it flashes, and a column of light fires up and breaks apart into glints.",+ tags: ["arcane", "magic", "circle", "rune", "cast", "column", "summon", "ground", "one-shot"],+ size: [200, 220],+ origin: [100, 192],+ duration: END,loop: false,fps: 30,bg: "ground",- options: { palette: AZURE, radius: 27, height: 64, seed: 11 },+ options: { palette: PAL.arcane, seed: 6 },};-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);+const wrap = (a) => ((a % TAU) + TAU) % TAU;+const fromFront = (g) => Math.abs(Math.atan2(Math.sin(g - Math.PI / 2), Math.cos(g - Math.PI / 2)));+// when the pens pass angle g: the outer rings are drawn from the front round both sides to the back, the inner+// ring from the back all the way round+const outerAt = (g, w) => w[0] + (fromFront(g) / Math.PI) * (w[1] - w[0]);+const innerAt = (g) => INNER[0] + (wrap(g + Math.PI / 2) / TAU) * (INNER[1] - INNER[0]);+const runeAngle = (k) => -Math.PI / 2 + ((k + 0.5) * TAU) / NRUNE;+const runeLit = (k) => RUNES[0] + (k * (RUNES[1] - RUNES[0])) / (NRUNE - 1);+const runeOut = (k) => BREAK + 0.2 + k * 0.08;++// how bright the drawn circle burns: settled while it's drawn, swelling as the runes light, white at the flash+function level(t) {+ if (t < RUNES[0]) return 0.55;+ if (t < FLASH) return 0.55 + 0.4 * smooth(RUNES[0], FLASH, t);+ if (t < FLASH + 0.07) return 1.2;+ if (t < BREAK) return 0.92;+ return 0.92 * (1 - smooth(BREAK, GONE, t));+}++export function create(o) {+ const C = fit(o.palette, 8), S = o.seed, Rg = new Rng(S);+ const ps = new Particles({ rng: Rg, ground: () => 0, sparks: [WHITE, C[6], C[5], C[4]] }), lights = new Lights();+ const COL = [WHITE, C[6], C[5], C[4], C[3]];+ const strands = Array.from({ length: 9 }, () => ({ o: Rg.range(-0.85, 0.85), w: Rg.range(0.04, 0.1), f: Rg.range(1, 3) }));+ // the hexagram: two triangles inside the inner ring, each drawn edge by edge+ const tri = (a0) => [0, 1, 2].map((k) => a0 + (k * TAU) / 3).map((a) => [Math.cos(a) * RI, Math.sin(a) * RI]);+ const A = tri(-Math.PI / 2), Bt = tri(Math.PI / 2), edges = [];+ for (let k = 0; k < 3; k++)+ for (const T of [A, Bt]) edges.push({ p0: T[k], p1: T[(k + 1) % 3], t0: STAR[0] + (k * (STAR[1] - STAR[0])) / 3, dur: (STAR[1] - STAR[0]) / 3 });+ let t = 0, flashed = false, broke = false;+ const out = new Array(NRUNE).fill(false);++ const lineCol = (lvl, age) => (age < 0.05 ? WHITE : age < 0.16 ? C[6] : lvl > 1 ? WHITE : lvl > 0.8 ? C[6] : lvl > 0.45 ? C[5] : lvl > 0.28 ? C[4] : C[3]);+ const lineA = (lvl) => clamp(lvl / 0.3);++ // a straight line on the floor plane, drawn by a pen from p0 to p1 over [t0, t0 + dur]; only the far (v < 0) or near part+ function planeLine(p, p0, p1, t0, dur, lvl, far) {+ const s = clamp((t - t0) / dur);+ if (s <= 0) return;+ let u0 = 0, u1 = s;+ const v0 = p0[1], v1 = p1[1];+ if ((v0 < 0) !== (v1 < 0)) {+ const uc = v0 / (v0 - v1);+ if ((v0 < 0) === far) u1 = Math.min(u1, uc);+ else u0 = uc;+ } else if ((v0 < 0) !== far) return;+ if (u1 <= u0) return;+ const P = (u) => [p0[0] + (p1[0] - p0[0]) * u, (v0 + (v1 - v0) * u) * SY];+ const [xa, ya] = P(u0), [xb, yb] = P(u1);+ p.line(xa, ya, xb, yb, (q) => lineCol(lvl, t - (t0 + (u0 + (u1 - u0) * q) * dur)), lineA(lvl));+ }++ function circle(p, far) {+ if (t >= GONE) return;+ const lvl = level(t), keep = far ? (g) => Math.sin(g) < 0 : (g) => Math.sin(g) >= 0, a = lineA(lvl);+ const ring = (r, when, chase) => floorRing(p, 0, 0, r, SY, (g) => (chase && chase(g) ? WHITE : lineCol(lvl, t - when(g))), (g) => (t < when(g) ? 0 : a), keep);+ // from the moment the runes start to light, two sparks of light chase round the outer ring, faster and faster+ const run = t > RUNES[0] && t < BREAK ? (t - RUNES[0]) * 5 + (t - RUNES[0]) ** 2 * 4 : null;+ const chase = run === null ? null : (g) => [0, Math.PI].some((o) => Math.abs(Math.atan2(Math.sin(g - run - o), Math.cos(g - run - o))) < 0.22);+ ring(R, (g) => outerAt(g, PEN), chase);+ ring(R2, (g) => outerAt(g, PEN2));+ ring(RI, innerAt);+ // ticks across the band between the two outer rings+ for (let j = 0; j < 32; j++) {+ const g = ((j + 0.5) * TAU) / 32;+ if (Math.sin(g) < 0 !== far) continue;+ const when = outerAt(g, PEN2) + 0.03;+ if (t < when) continue;+ p.line(Math.cos(g) * R2, Math.sin(g) * R2 * SY, Math.cos(g) * R, Math.sin(g) * R * SY, lineCol(lvl, t - when), a * (j % 2 ? 0.6 : 1));}- // 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);+ for (const e of edges) planeLine(p, e.p0, e.p1, e.t0, e.dur, lvl, far);+ }++ // the runes stand on the circle; dim when the inner pen passes, lit one by one, out one by one+ function runes(p, far) {+ for (let k = 0; k < NRUNE; k++) {+ const g = runeAngle(k);+ if (Math.sin(g) < 0 !== far) continue;+ const x = Math.cos(g) * RR, y0 = Math.sin(g) * RR * SY, lit = t - runeLit(k), gone = clamp((t - runeOut(k)) / 0.25);+ if (t < innerAt(g) || gone >= 1) continue;+ if (lit < 0) {+ glyph(p, k, x, y0 - 1, C[3]);+ continue;+ }+ const rise = 3 * ease.outBack(clamp(lit / 0.2), 2.4), bob = lit > 0.2 ? Math.sin(t * 5 + k) * 0.5 : 0, y = y0 - 1 - rise + bob;+ const hot = lit < 0.07 || (t > FLASH && t < FLASH + 0.07), lvl = level(t);+ glyph(p, k, x, y, hot ? WHITE : lvl > 0.8 ? WHITE : C[6], 1 - gone, hot ? C[6] : C[4]);+ if (lit < 0.1) sparkle(p, x, y - 2, 4 * (1 - lit / 0.1) + 1, C[6], C[5], 0.5);+ p.glow(x, y - 2, 8, C[5], (0.3 + 0.3 * lvl) * (1 - gone));+ p.glow(x, y0, 6, C[4], 0.2 * (1 - gone));+ }+ }++ // the column of light: the thread that climbs first, then the beam that fires up, holds and breaks apart+ function column(p) {+ if (t < FLASH - 0.22 || t > BREAK + 0.6) return;+ if (t < FLASH) {+ const a = smooth(FLASH - 0.22, FLASH - 0.04, t), top = -(TOP - 10) * ease.outCubic(a);+ for (let y = -1; y >= top; y--) p.dot(0, y, y > top + 6 ? C[6] : WHITE, a * (0.35 + 0.65 * (1 + y / TOP)));+ p.glow(0, top, 9, C[6], 0.5 * a);+ p.glow(0, -6, 24, C[5], 0.4 * a);+ return;}- // 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);+ const u = t - FLASH, brk = clamp((t - BREAK) / 0.45), top = -TOP * ease.outExpo(clamp(u / 0.09));+ const w = t < BREAK ? W * (1 + 0.38 * Math.exp(-u * 9)) : W * (1 - ease.outCubic(brk) * 0.85);+ const fade = 1 - smooth(BREAK + 0.25, BREAK + 0.55, t), white = u < 0.067;+ if (fade <= 0) return;+ for (let y = 3; y >= Math.ceil(top); y--) {+ const h = -y, ww = w * (1 + 0.5 * Math.exp(-Math.max(0, h) / 6)), pulse = fract(h * 0.022 - u * 2.6) < 0.07 ? 1 : 0;+ for (let x = Math.floor(-ww * 1.3); x <= Math.ceil(ww * 1.3); x++) {+ const q = Math.abs(x + 0.5) / ww;+ // as it breaks, holes open and grow and drift upward until only shards are left+ if (brk > 0 && noise2(x * 0.32, h * 0.11 - (t - BREAK) * 6, S) * 0.5 + 0.5 < brk * 1.25 - 0.1) continue;+ let lv = q < 0.2 ? 0 : q < 0.42 ? 1 : q < 0.66 ? 2 : q < 0.88 ? 3 : 4;+ for (const s of strands) if (Math.abs((x + 0.5) / ww - s.o - 0.05 * Math.sin(t * s.f + s.o * 9)) < s.w) lv = Math.max(0, lv - 1);+ lv = white ? 0 : Math.max(0, lv - pulse);+ const a = (q < 0.88 ? 1 : (1.3 - q) / 0.42) * fade;+ if (a <= bayer(x, y) * (q < 0.66 ? 0.2 : 1)) continue;+ p.px(x, y, COL[lv]);+ }+ if ((h & 7) === 0 && h < TOP - ww * 2.4 - 8) p.glow(0, y, ww * 2.4 + 6, C[5], 0.3 * fade);}+ // halos climbing it+ for (let i = 0; i < 6; i++) {+ const k = (t - (FLASH + 0.08 + i * 0.16)) / 0.8;+ if (k < 0 || k > 1) continue;+ const rx = w * 1.4 * (1 + k * 0.35), ry = rx * 0.3, yc = -3 - ease.outQuad(k) * 120, n = Math.ceil(rx * 7);+ for (let j = 0; j < n; j++) {+ const g = (j / n) * TAU;+ p.dot(Math.cos(g) * rx, yc + Math.sin(g) * ry, k < 0.3 ? WHITE : C[6], (1 - k) * fade * (Math.sin(g) < 0 ? 0.6 : 1));+ }+ }+ // white-hot where it meets the floor+ p.glow(0, -4, 34, C[6], 0.45 * fade);+ p.glow(0, -60, 70, C[4], 0.25 * fade);}- // 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));++ function shock(p, far) {+ for (const [d, r0, r1, th, dur] of [[0, R * 0.6, R * 2, 6, 0.5], [0.08, R * 0.4, R * 1.4, 3, 0.4]]) {+ const k = (t - FLASH - d) / dur;+ if (k < 0 || k >= 1) continue;+ band(p, 0, 0, r0 + (r1 - r0) * ease.outCubic(k), SY, Math.max(1, th * (1 - k)), 1.15 - k, [C[3], C[5], C[6], WHITE], (g) => Math.sin(g) < 0 === far, k < 0.2);+ }}- // 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);++ return {+ update(dt) {+ t += dt;+ // the pens shed glitter as they write+ if (t > PEN[0] && t < STAR[1] && Rg.chance(0.5)) {+ let x, y;+ if (t < PEN[1]) {+ const g = Math.PI / 2 + Rg.sign() * ((t - PEN[0]) / (PEN[1] - PEN[0])) * Math.PI;+ (x = Math.cos(g) * R), (y = Math.sin(g) * R * SY);+ } else if (t < INNER[1]) {+ const g = -Math.PI / 2 + ((t - INNER[0]) / (INNER[1] - INNER[0])) * TAU;+ (x = Math.cos(g) * RI), (y = Math.sin(g) * RI * SY);+ } else {+ const e = Rg.pick(edges.filter((e) => t >= e.t0 && t < e.t0 + e.dur)) ?? edges[0], s = clamp((t - e.t0) / e.dur);+ (x = e.p0[0] + (e.p1[0] - e.p0[0]) * s), (y = (e.p0[1] + (e.p1[1] - e.p0[1]) * s) * SY);+ }+ ps.spawn(P.EMBER, x, y - 1, Rg.range(-12, 12), Rg.range(-30, -8), Rg.range(0.25, 0.55), C[6], 1);+ }+ // gathering: light rushes in along the floor to the heart of the circle+ if (t > RUNES[1] - 0.1 && t < FLASH - 0.05 && Rg.chance(0.7)) {+ const g = Rg.range(0, TAU), D = Rg.range(R * 0.7, R * 1.1), T = Rg.range(0.16, 0.24), v = (D * 3) / (Math.exp(3 * T) - 1);+ const x = Math.cos(g) * D, y = Math.sin(g) * D * SY - 1, l = Math.hypot(x, y + 2) || 1;+ ps.spawn(P.STREAK, x, y, (-x / l) * v, ((-2 - y) / l) * v, T, Rg.chance(0.5) ? C[6] : C[5]);+ }+ if (!flashed && t >= FLASH) {+ flashed = true;+ lights.add(0, -56, 104, C[5], 0.9, 0.6);+ lights.add(0, -5, 36, WHITE, 0.8, 0.14);+ for (let i = 0; i < 36; i++) {+ const s = Rg.sign(), sp = Rg.range(80, 175);+ ps.spawn(P.SPARK, s * Rg.range(0, R * 0.5), -1, s * sp, -Rg.range(30, 180), Rg.range(0.25, 0.7));+ }+ for (let i = 0; i < 26; i++)+ ps.spawn(P.STAR, Rg.range(-R, R), -Rg.range(1, 6), Rg.range(-20, 20), -Rg.range(40, 130), Rg.range(0.5, 1.1), Rg.pick([WHITE, C[6], C[5]]), Rg.range(0.8, 2.3));+ // and a spray of twinkles flung out low across the floor+ for (let i = 0; i < 34; i++) {+ const s = Rg.sign();+ ps.spawn(P.STAR, s * Rg.range(0, 14), -Rg.range(1, 4), s * Rg.range(50, 140), -Rg.range(10, 90), Rg.range(0.4, 0.95), Rg.pick([WHITE, C[6], C[6], C[5]]), Rg.range(0.7, 2.2));+ }+ }+ // glints pop along the burning circle+ if (t > RUNES[0] && t < BREAK + 0.2 && Rg.chance(0.12)) {+ const g = Rg.range(0, TAU), r = Rg.pick([R, R2, RI]);+ ps.spawn(P.STAR, Math.cos(g) * r, Math.sin(g) * r * SY - 0.5, 0, -Rg.range(2, 8), Rg.range(0.25, 0.45), Rg.pick([WHITE, C[6]]), Rg.range(0.8, 2));+ }+ // the column throws off stars, and light streams up inside it+ if (t > FLASH && t < BREAK) {+ if (Rg.chance(0.5)) ps.spawn(P.STAR, Rg.range(-1, 1) * W * 1.5, -Rg.range(0, 120), Rg.range(-10, 10), -Rg.range(30, 85), Rg.range(0.5, 1.1), Rg.pick([WHITE, C[6], C[5]]), Rg.range(0.7, 2));+ if (Rg.chance(0.35)) ps.spawn(P.MOTE, Rg.range(-1, 1) * W * 0.8, -Rg.range(0, 50), 0, -Rg.range(160, 300), Rg.range(0.2, 0.35), Rg.chance(0.5) ? WHITE : C[6], 0.8);+ }+ // it breaks apart into glints that twinkle as they drift up+ if (!broke && t >= BREAK) {+ broke = true;+ for (let i = 0; i < 46; i++)+ ps.spawn(P.STAR, Rg.range(-1, 1) * W * 0.9, -Rg.range(2, TOP * 0.8), Rg.range(-12, 12), -Rg.range(8, 40), Rg.range(0.5, 1.15), Rg.pick([WHITE, WHITE, C[6], C[5]]), Rg.range(0.6, 2.4));+ }+ if (t > BREAK && t < BREAK + 0.4 && Rg.chance(0.8)) {+ ps.spawn(P.STAR, Rg.range(-1, 1) * W * 0.7, -Rg.range(2, TOP * 0.78), Rg.range(-8, 8), -Rg.range(10, 50), Rg.range(0.4, 0.9), Rg.pick([WHITE, C[6], C[5]]), Rg.range(0.6, 1.8));+ if (Rg.chance(0.4)) ps.spawn(P.MOTE, Rg.range(-1, 1) * W * 0.5, -Rg.range(2, TOP * 0.7), 0, -Rg.range(60, 140), Rg.range(0.2, 0.4), C[6], 0.7);+ }+ // the runes go out one by one, each in a little puff of glints+ for (let k = 0; k < NRUNE; k++)+ if (!out[k] && t >= runeOut(k)) {+ out[k] = true;+ const g = runeAngle(k), x = Math.cos(g) * RR, y = Math.sin(g) * RR * SY - 5;+ for (let i = 0; i < 4; i++) ps.spawn(P.STAR, x + Rg.range(-2, 2), y + Rg.range(-2, 2), Rg.range(-14, 14), -Rg.range(10, 40), Rg.range(0.3, 0.55), Rg.pick([WHITE, C[6]]), Rg.range(0.6, 1.6));+ }+ ps.update(dt);+ lights.update(dt);+ },+ drawBack(p) {+ const lvl = level(t);+ if (t < GONE) {+ const k = lvl * smooth(PEN[0], PEN[1] + 0.2, t);+ p.glow(0, 0, R * 1.3, C[4], 0.28 * k);+ for (const s of [-1, 1]) p.glow(s * R * 0.6, 1, R * 0.7, C[5], 0.12 * k);+ }+ shock(p, true);+ circle(p, true);+ runes(p, true);+ column(p);+ ps.draw(p, "back");+ },+ draw(p) {+ shock(p, false);+ circle(p, false);+ runes(p, false);+ // the pens: white points running round, writing light+ const pen = (x, y) => {+ sparkle(p, x, y, 2, C[6], C[5], 0.5);+ p.glow(x, y, 7, C[6], 0.45);+ };+ if (t > PEN[0] && t < PEN[1]) for (const s of [-1, 1]) {+ const g = Math.PI / 2 + s * ((t - PEN[0]) / (PEN[1] - PEN[0])) * Math.PI;+ pen(Math.cos(g) * R, Math.sin(g) * R * SY);+ }+ if (t > INNER[0] && t < INNER[1]) {+ const g = -Math.PI / 2 + ((t - INNER[0]) / (INNER[1] - INNER[0])) * TAU;+ pen(Math.cos(g) * RI, Math.sin(g) * RI * SY);+ }+ for (const e of edges)+ if (t > e.t0 && t < e.t0 + e.dur) {+ const s = (t - e.t0) / e.dur;+ pen(e.p0[0] + (e.p1[0] - e.p0[0]) * s, (e.p0[1] + (e.p1[1] - e.p0[1]) * s) * SY);+ }+ // the flash+ if (t >= FLASH && t < FLASH + 0.24) {+ const a = (t - FLASH) / 0.24;+ flare(p, 0, -8, 34 * Math.pow(1 - a, 1.5), 1 - a, C);+ p.glow(0, -26, 56, WHITE, 0.5 * (1 - a));+ }+ ps.draw(p, "front");+ lights.draw(p);+ },+ };}diff --git a/src/fx/arcane/mana-burst.js b/src/fx/arcane/mana-burst.jsindex 7eb1290..85b6735 100644--- a/src/fx/arcane/mana-burst.js+++ b/src/fx/arcane/mana-burst.js@@ -1,80 +1,134 @@-import { PAL, burst, fly, seg, ease, rand, clamp, TAU, WHITE } from "../../core/index.js";-import { fit, rune, sparkle } from "./_lib.js";+// The release (a white disc, a cross, two rings, a big light and a spray of motes and stars) is adapted from+// Sprite Fusion's open-source energy charge (https://www.spritefusion.com/pixel-art-vfx/energy),+// MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Lights, P, Rng, PAL, fit, flare, sparkle, clamp, ease, TAU, WHITE } from "../../core/index.js";+import { sigil } from "./_lib.js";++const CY = -28, GATHER = 0.22, N = 9;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,+ desc: "Energy rushes into a point and blows out in a white flash and rings, flinging glowing runes that flare and pop into sparks one after another.",+ tags: ["arcane", "burst", "mana", "rune", "nova", "magic", "ground", "one-shot"],+ size: [208, 150],+ origin: [104, 124],+ duration: 1.8,loop: false,fps: 30,- bg: "dark",- options: { palette: PAL.arcane, count: 8, seed: 9 },+ bg: "ground",+ options: { palette: PAL.arcane, 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);+export function create(o) {+ const C = fit(o.palette, 8), R = new Rng(o.seed);+ const ps = new Particles({ rng: R, ground: () => 0, sparks: [WHITE, C[6], C[5], C[4]] }), lights = new Lights();+ // the runes: flung out round the burst, slowing hard, bobbing while they burn, each popping in its turn+ const runes = Array.from({ length: N }, (_, i) => {+ const a = (i / N) * TAU + R.range(-0.25, 0.25) - Math.PI / 2, sp = R.range(150, 210);+ // thrown less far downward, so the low ones stay clear of the floor+ return { g: i, x: 0, y: CY, vx: Math.cos(a) * sp, vy: Math.sin(a) * sp * (Math.sin(a) > 0 ? 0.42 : 0.85), pop: GATHER + 0.42 + i * 0.065 + R.range(0, 0.05), popped: false, ph: R.range(0, TAU) };});- 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);+ const pops = [];+ let t = 0, released = false;++ return {+ update(dt) {+ t += dt;+ if (t < GATHER - 0.03) {+ // the gather: streaks rush in from all round+ for (let i = 0; i < 2; i++) {+ const a = R.range(0, TAU), D = R.range(24, 52), T = R.range(0.12, 0.18), v = (D * 3) / (Math.exp(3 * T) - 1);+ const x = Math.cos(a) * D, y = Math.min(-2, CY + Math.sin(a) * D * 0.85), l = Math.hypot(x, y - CY) || 1;+ ps.spawn(P.STREAK, x, y, (-x / l) * v, ((CY - y) / l) * v, T, R.chance(0.5) ? C[6] : C[5]);+ }+ }+ if (t >= GATHER && !released) {+ released = true;+ lights.add(0, CY - 12, 96, C[5], 1, 0.5);+ lights.add(0, CY, 40, WHITE, 0.9, 0.1);+ // a spray of motes and stars, thrown less hard at the floor+ for (let i = 0; i < 96; i++) {+ const a = R.range(0, TAU), sp = R.range(100, 250), dn = Math.sin(a) > 0 ? 0.45 : 1;+ ps.spawn(R.chance(0.65) ? P.MOTE : P.STAR, 0, CY, Math.cos(a) * sp, Math.sin(a) * sp * dn, R.range(0.25, 0.55), R.pick([WHITE, C[6], C[5]]), R.range(0.8, 1.8));+ }+ for (let i = 0; i < 20; i++) {+ const a = R.range(0, TAU), sp = R.range(130, 280);+ ps.spawn(P.SPARK, 0, CY, Math.cos(a) * sp, Math.sin(a) * sp, R.range(0.2, 0.45));+ }+ }+ if (released)+ for (const r of runes) {+ if (r.popped) continue;+ r.vx -= r.vx * 4.2 * dt;+ r.vy -= r.vy * 4.2 * dt + 8 * dt;+ r.x += r.vx * dt;+ r.y += r.vy * dt;+ if (R.chance(0.35)) ps.spawn(P.MOTE, r.x + R.range(-1.5, 1.5), r.y, r.vx * 0.2 + R.range(-10, 10), r.vy * 0.2 - R.range(5, 25), R.range(0.2, 0.4), C[5], 0.5);+ if (t >= r.pop) {+ r.popped = true;+ pops.push({ t, x: r.x, y: r.y });+ lights.add(r.x, r.y, 34, C[5], 0.9, 0.22);+ lights.add(r.x, r.y, 12, WHITE, 0.8, 0.06);+ for (let i = 0; i < 9; i++) {+ const a = R.range(0, TAU), sp = R.range(70, 200);+ ps.spawn(P.SPARK, r.x, r.y, Math.cos(a) * sp, Math.sin(a) * sp - 40, R.range(0.15, 0.4));+ }+ for (let i = 0; i < 5; i++) {+ const a = R.range(0, TAU), sp = R.range(20, 80);+ ps.spawn(i % 2 ? P.STAR : P.MOTE, r.x, r.y, Math.cos(a) * sp, Math.sin(a) * sp - 20, R.range(0.3, 0.6), R.pick([WHITE, C[6]]), R.range(0.8, 1.6));+ }+ }+ }+ ps.update(dt);+ lights.update(dt);+ },+ drawBack(p) {+ // the floor beneath catches the burst+ const k = t < GATHER ? 0.4 * (t / GATHER) : Math.max(0, 1 - (t - GATHER) / 1.1);+ if (k > 0) p.glow(0, -1, 50, C[4], 0.3 * k);+ },+ draw(p) {+ if (t < GATHER) {+ // the point it gathers into: a swelling ball with a white heart+ const k = t / GATHER, r = 1 + 3.5 * k * k;+ p.circle(0, CY, r + 1.2, C[4]);+ p.circle(0, CY, r, C[6]);+ p.circle(0, CY, r * 0.5, WHITE);+ p.glow(0, CY, 10 + 20 * k, C[5], 0.4 + 0.4 * k);+ const q = clamp((t - GATHER * 0.35) / (GATHER * 0.65));+ if (q > 0 && q < 1) p.ring(0, CY, r + 2 + 16 * (1 - ease.outCubic(q)), 1, q > 0.6 ? WHITE : C[6], 1 - q * 0.5);+ } else {+ const q = (t - GATHER) / 0.6;+ if (q < 1) {+ const e = ease.outCubic(q);+ if (q < 0.12) {+ p.circle(0, CY, 12 * (1 - q / 0.12) + 2, C[5]);+ p.circle(0, CY, 12 * (1 - q / 0.12), WHITE);+ }+ if (q < 0.32) flare(p, 0, CY, 30 * (1 - q / 0.32) + 4, 1 - q / 0.32, C);+ // the rings, cut off where they meet the floor+ p.ring(0, CY, 4 + 62 * e, Math.max(1, 5 * (1 - q)), q < 0.2 ? WHITE : C[6], (v, ang) => (CY + Math.sin(ang) * (4 + 62 * e) > 0 ? 0 : 1.2 - q));+ p.ring(0, CY, 2 + 38 * ease.outCubic(Math.min(1, q * 1.4)), Math.max(1, 2 * (1 - q)), C[5], (v, ang) => (CY + Math.sin(ang) * 40 > 0 ? 0 : 1 - q));+ p.glow(0, CY, 60 * (0.4 + 0.6 * e), C[5], 0.9 * (1 - q));+ }+ }+ // the runes: white as they fly, settling to lilac, flaring white just before they pop+ for (const r of runes) {+ if (!released || r.popped) continue;+ const left = r.pop - t, hot = t - GATHER < 0.08 || left < 0.06, bob = Math.sin(t * 9 + r.ph) * 0.6;+ sigil(p, r.g, r.x, r.y + bob, hot ? WHITE : C[6], 1, hot ? C[4] : C[3]);+ p.glow(r.x, r.y + bob, 10, C[5], hot ? 0.7 : 0.35);+ if (left < 0.06) sparkle(p, r.x, r.y + bob, 3 + 4 * (1 - left / 0.06), C[6], C[5], 0.5);+ }+ // each pop: a small flare and a ring+ for (const q of pops) {+ const k = (t - q.t) / 0.32;+ if (k >= 1) continue;+ if (k < 0.35) flare(p, q.x, q.y, 11 * (1 - k / 0.35) + 2, 1 - k / 0.35, C);+ p.ring(q.x, q.y, 2 + 11 * ease.outCubic(k), Math.max(1, 2 * (1 - k)), k < 0.3 ? WHITE : C[6], 1.15 - k);+ }+ ps.draw(p);+ lights.draw(p);+ },+ };}diff --git a/src/fx/arcane/mirror-images.js b/src/fx/arcane/mirror-images.jsdeleted file mode 100644index 82430ec..0000000--- a/src/fx/arcane/mirror-images.js+++ /dev/null@@ -1,65 +0,0 @@-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.jsindex 00d1070..ddd71b9 100644--- a/src/fx/arcane/portal.js+++ b/src/fx/arcane/portal.js@@ -1,46 +1,169 @@-import { PAL, fit, at, cycle, tileNoise, fract, ease, TAU } from "../../core/index.js";+// The dithered light ramp and the streaked, knotted disc texture are adapted from Sprite Fusion's open-source+// black hole (https://www.spritefusion.com/pixel-art-vfx/black-hole), MIT License, Copyright (c) 2026 Hugo Duprez.+import { PAL, fit, cycle, tileNoise, smooth, ease, TAU, WHITE } from "../../core/index.js";+import { tone, mote, streak } from "./_lib.js";++const D = 2.4;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,+ desc: "An upright rift: fibrous spiral arms wind down into the dark, a lit rim wobbles, motes and streaks are pulled in, the floor glows.",+ tags: ["arcane", "portal", "rift", "teleport", "magic", "ground", "loop"],+ size: [152, 116],+ origin: [76, 106],+ duration: D,loop: true,fps: 30,bg: "ground",- options: { palette: PAL.arcane, width: 14, height: 22, seed: 4 },+ options: { palette: PAL.arcane, width: 17, height: 29, 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;+const wrapPi = (a) => a - TAU * Math.floor((a + Math.PI) / TAU);++function setup(t, o) {+ const C = fit(o.palette, 8), rx = o.width, ry = o.height, ph = t / D, S = o.seed;+ const CY = -(ry + 5);+ // the rim's radius (1 = the oval) at angle th: slow noise rolling round it, plus a three-lobed breath+ const rim = (th) => 1 + 0.05 * tileNoise((th / TAU) * 10 + ph * 10, ph * 4, 10, 4, S) + 0.018 * Math.sin(th * 3 - ph * TAU * 2);+ // where a point at angle th and radius rho (1 = the rim) sits; outside, the field widens so motes come from round about+ const at = (th, rho) => {+ const out = Math.max(0, rho - 1), k = Math.min(1, rho);+ return [Math.cos(th) * (k * rx + out * 21), Math.min(-1, CY + Math.sin(th) * (k * ry + out * 16))];+ };+ // two hot spots chase round the rim with the spin, and a key light sits at the top left+ const spots = [ph * TAU * 2 - 0.6, ph * TAU * 2 + Math.PI - 0.6];+ const hot = (th) => Math.max(Math.exp(-(wrapPi(th - spots[0]) ** 2) / 0.12), 0.85 * Math.exp(-(wrapPi(th - spots[1]) ** 2) / 0.08)) + 0.35 * Math.max(0, Math.cos(th + 2.3));+ return { C, rx, ry, ph, S, CY, rim, at, hot, spots };+}++// the rift itself: the dark well, the fibrous arms winding down into it, the lit rim+function rift(p, s) {+ const { C, rx, ry, ph, CY, rim, hot } = s;+ p.shade(-rx - 4, CY - ry - 4, rx + 4, CY + ry + 4, (x, y, out) => {+ const u = x / rx, v = (y - CY) / ry, r = Math.hypot(u, v) || 1e-6, th = Math.atan2(v, u), R0 = rim(th);+ const g = Math.hypot(u / rx, v / ry) / r, e = (r - R0) / g, h = hot(th);+ if (e > 2.5) return;+ // outside the rim: a coloured line where it's lit, a dark one elsewhere, a faint halo past it+ if (e > 1.5) {+ if (h > 0.6) (out.c = C[3]), (out.a = 0.5);+ return;+ }+ if (e > 0.5) {+ out.c = h > 0.5 ? C[4] : C[2];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);+ if (e > -0.5) {+ out.c = h > 0.42 ? WHITE : C[6];+ out.k = 0.25 + 0.4 * h;+ return;+ }+ // inside, in ramp steps: clean depth bands falling away to a dark well; three thin bright arms and three+ // faint ones on a log spiral, flowing inward a turn a loop, with knots of light running down them; the light+ // that spills in round the rim+ const d = r / R0, z = -Math.log(Math.max(0.02, d)), phi = 3 * th + 6.5 * z - TAU * 3 * ph;+ const c1 = 0.5 + 0.5 * Math.cos(phi), c2 = 0.5 + 0.5 * Math.cos(phi + Math.PI + 0.6 * z), lit = Math.pow(d, 1.5), sink = smooth(0.2, 0.62, d);+ const knot = Math.pow(Math.max(0, Math.cos(4 * z - phi / 3 + TAU * 5 * ph)), 6);+ let st = smooth(0.4, 0.7, d) + 0.6 * smooth(0.8, 0.95, d);+ const crest = Math.pow(c1, 16) * (0.6 + 5.6 * lit) * (1 + 0.5 * knot) * sink;+ st += crest + Math.pow(c1, 5) * 1.1 * lit;+ st += Math.pow(c2, 18) * (0.3 + 1.8 * lit) * sink;+ // rings of the tunnel shrinking away down the well, two a loop+ st += Math.pow(0.5 + 0.5 * Math.cos(TAU * (z * 1.5 - ph * 2)), 20) * 1.3 * sink * (1 - 0.5 * c1);+ // fine strands between the arms, a step brighter than the dark they run through+ st += Math.pow(0.5 + 0.5 * Math.cos(3 * phi + 2 * z + 1.3), 10) * 1.1 * lit * sink;+ st += 2.2 * Math.pow(smooth(0.8, 1, d), 2) * (0.75 + 0.45 * h);+ out.c = tone(C, st / 7, x, y, 0, 0.65);+ if (crest > 2.2) out.k = 0.12 + 0.05 * crest;+ });+}++// specks of light deep in the well, swept round with the arms and sinking towards the far end+function well(p, s) {+ const { C, rx, ry, ph, S, CY, rim } = s, t = ph * D;+ cycle(t, D, 18, S * 7 + 5, (g) => g.range(1.1, 1.8), (age, life, r) => {+ const q = age / life, th = r.range(0, TAU) + q * 2.6, rho = 0.92 * (1 - ease.inQuad(q) * 0.9), R0 = rim(th);+ const x = Math.cos(th) * rho * R0 * rx, y = CY + Math.sin(th) * rho * R0 * ry, tw = Math.sin(ph * TAU * r.int(14, 22) + r.range(0, TAU));+ const a = Math.min(1, q * 6) * (rho > 0.25 ? 1 : rho / 0.25);+ if (tw > -0.3) p.dot(x, y, rho > 0.6 && tw > 0.6 ? WHITE : rho > 0.45 ? C[6] : C[5], a);+ });+}++// motes riding round just outside the rim, sinking in as they go+function orbit(p, s) {+ const { C, rx, ry, ph, S, CY } = s;+ for (let i = 0; i < 7; i++) {+ const k = (ph * 2 + i / 7) % 1, th = ((i * 2.39 + S) % TAU) + ph * TAU * 2 + k * 2.5, rho = 1.2 + 0.35 * ((i * 0.618) % 1) - 0.3 * ease.inQuad(k);+ const x = Math.cos(th) * rho * rx, y = CY + Math.sin(th) * rho * ry, a = Math.min(1, Math.sin(k * Math.PI) * 2.2);+ mote(p, x, y, -Math.sin(th) * rx * 10, Math.cos(th) * ry * 10, i % 3 ? C[6] : WHITE, 0.6, a, 0.3);+ }+}++// motes and streaks pulled in from round about, spinning faster as they fall; inside they sink into the dark+function infall(p, s) {+ const { C, ph, S, rim, at } = s, t = ph * D;+ cycle(t, D, 60, S * 7 + 1, (g) => g.range(0.3, 0.5), (age, life, r) => {+ const a0 = r.range(0, TAU), d0 = r.range(1.8, 3), spin = r.range(0.8, 1.8) * (r.chance(0.8) ? 1 : 0.35), size = r.range(0.8, 1.5), hue = r.next();+ const pos = (q) => at(a0 + spin * q * q, d0 * (1 - Math.pow(q, 1.4)));+ const q = age / life, [x, y] = pos(q), [x2, y2] = pos(Math.min(1, q + 0.015)), vx = (x2 - x) / (0.015 * life), vy = (y2 - y) / (0.015 * life);+ const rho = d0 * (1 - Math.pow(q, 1.4)), R0 = rim(a0 + spin * q * q), fade = Math.min(1, q * 5);+ if (rho > R0 + 0.06) mote(p, x, y, vx, vy, hue < 0.25 ? WHITE : hue < 0.55 ? C[6] : hue < 0.8 ? C[5] : C[4], hue < 0.8 ? size : size * 1.4, fade, hue < 0.8 ? 0.4 : 0.15);+ else if (rho > 0.3) p.dot(x, y, rho > 0.65 ? C[6] : C[5], rho);+ });+ cycle(t, D, 12, S * 7 + 2, (g) => g.range(0.36, 0.5), (age, life, r) => {+ const a0 = r.range(0, TAU), d0 = r.range(2.3, 3), spin = r.range(0.2, 0.5);+ const qc = Math.sqrt(1 - 1.05 / d0), q = age / life;+ const pos = (q) => at(a0 + spin * q * q, d0 * (1 - q * q));+ if (q < qc) {+ const [x, y] = pos(q), [x2, y2] = pos(q + 0.015);+ streak(p, x, y, (x2 - x) / (0.015 * life), (y2 - y) / (0.015 * life), C[6], Math.min(1, q * 5));+ } else {+ // it hits the rim: a pinprick of white+ const k = 1 - (q - qc) / (1 - qc), [x, y] = pos(qc);+ if (k > 0.55) p.px(x, y, WHITE);+ p.glow(x, y, 7, C[6], 0.6 * k * k);+ }});- // 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);+}++// grit and sparks skating in along the floor, lifting into the foot of the rift+function skaters(p, s) {+ const { C, ph, S, CY, ry } = s, t = ph * D, foot = CY + ry;+ cycle(t, D, 14, S * 7 + 3, (g) => g.range(0.7, 1.1), (age, life, r) => {+ const side = r.sign(), x0 = side * r.range(22, 50), y0 = -1 - r.range(0, 1.5), q = age / life, e = ease.inCubic(q);+ const x = x0 * (1 - e), y = y0 + (foot + 2) * smooth(0.55, 1, q);+ const [xb, yb] = [x0 * (1 - ease.inCubic(Math.max(0, q - 0.04))), y0 + (foot + 2) * smooth(0.55, 1, q - 0.04)];+ const big = r.chance(0.3);+ mote(p, x, y, (x - xb) * 25, (y - yb) * 25, big ? C[6] : C[5], big ? 0.9 : 0.6, Math.min(1, q * 4) * (1 - smooth(0.85, 1, q)), 0.3);});- 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);+}++function floor(p, s) {+ const { C, ph } = s, pulse = 0.85 + 0.15 * Math.sin(ph * TAU * 2);+ for (let x = -36; x <= 36; x++) {+ const u = Math.abs(x + 0.5) / 36, a = (u < 0.55 ? 1 : 1 - (u - 0.55) / 0.45) * (0.8 + 0.2 * pulse);+ p.dot(x, 0, u < 0.2 ? WHITE : u < 0.5 ? C[6] : C[5], a);+ if (u < 0.3) p.dot(x, 1, u < 0.15 ? C[5] : C[4], u < 0.15 ? 1 : 0.5);+ }+}++export function drawBack(p, t, o) {+ floor(p, setup(t, o));+}++export function draw(p, t, o) {+ const s = setup(t, o), { C, CY, rx, ry, ph, rim, spots } = s, pulse = 0.85 + 0.15 * Math.sin(ph * TAU * 2);+ rift(p, s);+ well(p, s);+ orbit(p, s);+ infall(p, s);+ skaters(p, s);+ // light comes off the rim, not the void: a big soft pool, a halo hugging the rim, hot spots that shine, the floor lit+ p.glow(0, CY, ry * 5, C[4], 0.17 * pulse);+ p.glow(0, CY, ry * 2.6, C[4], 0.1 * pulse);+ for (let i = 0; i < 16; i++) {+ const th = (i / 16) * TAU, R0 = rim(th) * 1.08;+ p.glow(Math.cos(th) * R0 * rx, CY + Math.sin(th) * R0 * ry, 15, C[4], 0.15 * pulse);+ }+ for (const th of spots) p.glow(Math.cos(th) * rim(th) * rx, CY + Math.sin(th) * rim(th) * ry, 16, C[6], 0.42);+ for (let i = -3; i <= 3; i++) p.glow(i * 7, -1, 16, C[5], 0.12 * pulse);}diff --git a/src/fx/arcane/rune-circle.js b/src/fx/arcane/rune-circle.jsindex e8b32a9..6520ffd 100644--- a/src/fx/arcane/rune-circle.js+++ b/src/fx/arcane/rune-circle.js@@ -1,70 +1,101 @@-import { PAL, cycle, TAU, WHITE } from "../../core/index.js";-import { fit, rune, ovalLine, ahead } from "./_lib.js";+// The floor glow and the specks rising off it follow Sprite Fusion's open-source mana heal+// (https://www.spritefusion.com/pixel-art-vfx/heal), MIT License, Copyright (c) 2026 Hugo Duprez.+import { PAL, fit, cycle, smooth, ease, sparkle, TAU, WHITE } from "../../core/index.js";+import { floorRing, glyph, mote } from "./_lib.js";++// turning a quarter a loop keeps every part seamless: 16 ticks, a square, and 12 runes in a pattern of three+const D = 4, R = 46, RR = 39, RI = 23, RC = 7, SY = 0.3, NR = 12;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,+ desc: "A rune circle turns on the floor in perspective: a carousel of runes lit by chasing light, a turning square, ticks, motes rising off it.",+ tags: ["arcane", "rune", "circle", "magic", "aura", "ground", "loop"],+ size: [136, 100],+ origin: [68, 80],+ duration: D,loop: true,fps: 30,bg: "ground",- options: { palette: PAL.arcane, radius: 27, seed: 10 },+ options: { palette: PAL.arcane, seed: 8 },};-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]));+const at = (g, r) => [Math.cos(g) * r, Math.sin(g) * r * SY];+const gap = (a, b) => Math.abs(Math.atan2(Math.sin(a - b), Math.cos(a - b)));++function circle(p, C, t, far) {+ const ph = t / D, spin = (ph * TAU) / 4, keep = far ? (g) => Math.sin(g) < 0 : (g) => Math.sin(g) >= 0;+ // two sparks of light chase round the outer ring, twice a loop+ const chase = ph * TAU * 2, lit = (g, w) => gap(g, chase) < w || gap(g, chase + Math.PI) < w;+ const tone = (g, hi, lo) => (Math.sin(g) < 0 ? lo : hi);+ floorRing(p, 0, 0, R, SY, (g) => (lit(g, 0.22) ? WHITE : lit(g, 0.5) ? C[6] : tone(g, C[6], C[5])), 1, keep);+ floorRing(p, 0, 0, RI, SY, (g) => tone(g, C[5], C[4]), 1, keep);+ floorRing(p, 0, 0, RC, SY, (g) => tone(g, C[6], C[5]), 1, keep);+ // studs set round the outside of the ring, turning with it+ for (let j = 0; j < 16; j++) {+ const g = spin + ((j + 0.5) * TAU) / 16;+ if (Math.sin(g) < 0 !== far) continue;+ const [x, y] = at(g, R + 3.5), hot = lit(g, 0.3);+ p.px(x, y, hot ? WHITE : tone(g, j % 2 ? C[5] : C[6], C[4]));+ if (j % 2 === 0) for (const [dx, dy] of [[1, 0], [-1, 0]]) p.px(x + dx, y + dy, hot ? C[6] : tone(g, C[4], C[3]));}- 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);+ // a square turning the other way inside the inner ring, its corners touching it+ const pts = [0, 1, 2, 3].map((k) => at(-spin + (k * TAU) / 4 + Math.PI / 4, RI));+ for (let k = 0; k < 4; k++) {+ let [ax, ay] = pts[k], [bx, by] = pts[(k + 1) % 4];+ if ((ay < 0) !== (by < 0)) {+ const u = ay / (ay - by), mx = ax + (bx - ax) * u;+ if ((ay < 0) === far) (bx = mx), (by = 0);+ else (ax = mx), (ay = 0);+ } else if ((ay < 0) !== far) continue;+ p.line(ax, ay, bx, by, far ? C[4] : C[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));+ // the runes stand in the band, riding round; bright at the front, dim behind, flaring as the light passes+ const gs = [...Array(NR).keys()].map((k) => [k, spin + ((k + 0.5) * TAU) / NR]).filter(([, g]) => Math.sin(g) < 0 === far);+ gs.sort((a, b) => Math.sin(a[1]) - Math.sin(b[1]));+ for (const [k, g] of gs) {+ const [x, y] = at(g, RR), hot = lit(g, 0.2), bob = Math.sin(ph * TAU * 4 + 4 * g) * 0.5;+ glyph(p, [0, 3, 5][k % 3], x, y - 1 + bob, hot ? WHITE : far ? C[5] : C[6], 1, hot ? C[5] : far ? C[2] : C[3]);+ p.glow(x, y - 3, hot ? 10 : 6, C[5], hot ? 0.5 : far ? 0.12 : 0.22);+ p.glow(x, y, 5, C[4], 0.15);+ }+}++// motes rising off the circle on a slow helix round its axis, swaying in; twinkles hanging over it+function motes(p, C, t, S, far) {+ cycle(t, D, 76, S * 5 + 1, (g) => g.range(1.1, 1.9), (age, life, r) => {+ const g0 = r.range(0, TAU), r0 = r.pick([R, R, RR, RR, RI]), q = age / life, g = g0 + q * r.range(0.6, 1.4);+ if (Math.sin(g) < 0 !== far) return;+ const rr = r0 * (1 - 0.35 * q), h = 2 + ease.outQuad(q) * r.range(26, 52), x = Math.cos(g) * rr, y = Math.sin(g) * rr * SY - h;+ const a = Math.min(1, q * 5) * (1 - smooth(0.65, 1, q)), big = r.chance(0.2);+ mote(p, x, y, -Math.sin(g) * rr * 0.8, -36 * (1 - q) - 10, r.chance(0.3) ? WHITE : r.chance(0.6) ? C[6] : C[5], big ? 1.1 : r.range(0.55, 0.9), a, big ? 0.5 : 0.3);+ });+ cycle(t, D, 14, S * 5 + 2, 0.45, (age, life, r) => {+ const g = r.range(0, TAU);+ if (Math.sin(g) < 0 !== far) return;+ const rr = r.range(8, R), x = Math.cos(g) * rr, y = Math.sin(g) * rr * SY - r.range(6, 34), k = Math.sin((age / life) * Math.PI);+ sparkle(p, x, y, 1 + 2.4 * k, C[6], C[5], 0.35 * k);});- p.glow(0, -3, RX + 8, C[4], 0.14 * pulse);+}++export function drawBack(p, t, o) {+ const C = fit(o.palette, 8), pulse = 0.85 + 0.15 * Math.sin((t / D) * TAU * 4);+ // the floor glows under the circle, and a soft light stands over it+ p.glow(0, 0, R * 1.4, C[4], 0.24 * pulse);+ for (const s of [-1, 1]) p.glow(s * R * 0.55, 1, R * 0.7, C[5], 0.12 * pulse);+ // a soft column of light standing over it, fading as it rises+ for (let h = 0; h < 66; h += 6) p.glow(0, -h, 26, C[4], 0.11 * pulse * (1 - h / 80));+ circle(p, C, t, true);+ motes(p, C, t, o.seed, true);+}++export function draw(p, t, o) {+ const C = fit(o.palette, 8), chase = (t / D) * TAU * 2;+ circle(p, C, t, false);+ motes(p, C, t, o.seed, false);+ // the two sparks of light running round the ring+ for (const g of [chase, chase + Math.PI]) {+ const [x, y] = at(g, R);+ sparkle(p, x, y, 2.5 + Math.sin(t * 30) * 0.8, C[6], C[5], 0.5);+ p.glow(x, y, 14, C[5], 0.4);+ }}diff --git a/src/fx/arcane/sparkle-swirl.js b/src/fx/arcane/sparkle-swirl.jsdeleted file mode 100644index 5e0945e..0000000--- a/src/fx/arcane/sparkle-swirl.js+++ /dev/null@@ -1,51 +0,0 @@-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.jsindex 5a12538..ce223cf 100644--- a/src/fx/arcane/spell-charge.js+++ b/src/fx/arcane/spell-charge.js@@ -1,52 +1,121 @@-import { PAL, cycle, fract, ease, clamp, TAU, WHITE } from "../../core/index.js";-import { fit } from "./_lib.js";+// The charge recipe (motes spiralling in, pulse rings collapsing onto a layered ball with flickering rays, short+// crackling sparks) is adapted from Sprite Fusion's open-source energy charge+// (https://www.spritefusion.com/pixel-art-vfx/energy), MIT License, Copyright (c) 2026 Hugo Duprez.+import { PAL, fit, cycle, rng, loopNoise, smooth, ease, sparkle, TAU, WHITE } from "../../core/index.js";+import { mote, streak, arc, drawArc } from "./_lib.js";++const D = 1.6, HX = 15, HY = -22, RINGS = 4, RT = 0.5;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,+ desc: "Energy gathers in the caster's hand: streaks and motes spiral in, rings collapse into a swelling orb that crackles with arcs, ready to fire.",+ tags: ["arcane", "charge", "spell", "orb", "cast", "magic", "loop"],+ size: [120, 86],+ origin: [44, 80],+ duration: D,loop: true,fps: 30,- bg: "dark",- options: { palette: PAL.arcane, radius: 24, seed: 8 },+ bg: "ground",+ actor: 2,+ options: { palette: PAL.arcane, seed: 5 },};-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));+// each ring is born at k * D / RINGS and lands RT later; the times it lands, wrapped into the loop+const landings = Array.from({ length: RINGS }, (_, k) => (k * D) / RINGS + RT);+const sinceLast = (t) => Math.min(...landings.map((l) => ((((t - l) % D) + D) % D)));++function orb(p, C, x, y, r, t, ph) {+ // rays flickering round the ball, turning three steps a loop+ for (let i = 0; i < 8; i++) {+ const a = (i / 8) * TAU + ph * (TAU / 8) * 3, l = (1.5 + 4.5 * Math.abs(loopNoise(ph, 3, i * 7 + 1))) * (i % 2 ? 0.7 : 1);+ const x0 = x + Math.cos(a) * (r + 1.2), y0 = y + Math.sin(a) * (r + 1.2);+ p.line(x0, y0, x0 + Math.cos(a) * l, y0 + Math.sin(a) * l, (u) => (u < 0.4 ? C[6] : i % 2 ? C[4] : C[5]), (u) => (u < 0.6 ? 1 : 1.6 - u));}- // 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];+ // the ball: a violet rim, a bright body lit from the top left, a big white heart+ p.circle(x, y, r + 1.3, C[4]);+ p.circle(x, y, r + 0.3, C[5]);+ p.circle(x - r * 0.12, y - r * 0.12, r * 0.8, C[6]);+ p.circle(x, y, r * 0.5, WHITE);+ // filaments crackling out from the heart through the body to the shell, new ones every other frame+ const R = rng(Math.floor(t * 15), 77);+ for (let i = 0; i < 3; i++) {+ const a = R.range(0, TAU), pts = arc(R, x + Math.cos(a) * r * 0.4, y + Math.sin(a) * r * 0.4, x + Math.cos(a + R.range(-0.6, 0.6)) * (r + 0.6), y + Math.sin(a + R.range(-0.6, 0.6)) * (r + 0.6), { jag: 0.45, forks: 0 })[0].pts;+ p.polyline(pts, (u) => (u < 0.6 ? WHITE : C[6]));+ }+ // a glint on the shell+ p.px(x - r * 0.5, y - r * 0.62, WHITE);+}++function ringAt(p, C, x, y, rr, sy, rot, q) {+ const n = Math.ceil(rr * TAU * 1.4), c = Math.cos(rot), s = Math.sin(rot);+ const col = q > 0.85 ? WHITE : q > 0.55 ? C[6] : C[5], a = Math.min(1, q * 3);+ for (let j = 0; j < n; j++) {+ const g = (j / n) * TAU, lx = Math.cos(g) * rr, ly = Math.sin(g) * rr * sy, px = x + lx * c - ly * s, py = y + lx * s + ly * c;+ if (py > -0.5) continue; // the floor hides the bottom of a big ring+ p.dot(px, py, col, a);+ if (j % 10 === 0) p.glow(px, py, 5, C[5], 0.12 * a);+ }+}++export function draw(p, t, o) {+ const C = fit(o.palette, 8), ph = t / D, S = o.seed, f = Math.floor(t * 30);+ const since = sinceLast(t), swell = Math.exp(-((since / 0.07) ** 2)) + 0.5 * Math.exp(-((since / 0.18) ** 2));+ const r = 6.1 + 0.5 * Math.sin(ph * TAU * 4) + 1.4 * swell;+ // unstable: it shivers a pixel as each ring lands+ const jit = swell > 0.4 ? (f % 2 ? 1 : -1) : 0, x = HX + jit, y = HY;++ // streaks spiralling in from all round, faster as they near the hand+ cycle(t, D, 110, S * 3 + 1, (g) => g.range(0.2, 0.34), (age, life, R) => {+ // they come from the left, above and the upper right; the swirl would carry the rest into the floor+ const a0 = R.range(2.8, 5.75), d0 = R.range(20, 52), spin = R.range(0.6, 1.3);+ const pos = (q) => {+ const a = a0 + spin * q * q, d = d0 * (1 - q * q) + r;+ return [HX + Math.cos(a) * d, HY + Math.sin(a) * d * 0.92];};- 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);+ const q = age / life, [px, py] = pos(q), [qx, qy] = pos(Math.min(1, q + 0.02));+ // their light dies as they reach the orb, so it isn't washed out by them+ streak(p, px, py, (qx - px) / (0.02 * life), (qy - py) / (0.02 * life), R.chance(0.55) ? C[6] : C[5], Math.min(1, q * 4) * (1 - smooth(0.9, 1, q)), 7, 0.4 * (1 - smooth(0.6, 0.9, q)));});- // 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];+ // slower motes, drifting in on the same swirl+ cycle(t, D, 56, S * 3 + 2, (g) => g.range(0.4, 0.7), (age, life, R) => {+ const a0 = R.range(2.6, 5.2), d0 = R.range(12, 32), spin = R.range(1, 2.2), size = R.range(0.6, 1);+ const pos = (q) => {+ const a = a0 + spin * q, d = d0 * (1 - ease.inQuad(q)) + r;+ return [HX + Math.cos(a) * d, HY + Math.sin(a) * d];+ };+ const q = age / life, [px, py] = pos(q), [qx, qy] = pos(Math.min(1, q + 0.02));+ mote(p, px, py, (qx - px) / (0.02 * life), (qy - py) / (0.02 * life), R.pick([C[5], C[6], C[6], WHITE]), size, Math.min(1, q * 3) * (q > 0.9 ? (1 - q) / 0.1 : 1), 0.3 * (1 - smooth(0.55, 0.85, q)));});- 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);++ // rings collapsing onto the orb, each tilted its own way+ for (let k = 0; k < RINGS; k++)+ for (const off of [-D, 0]) {+ const q = (t - (k * D) / RINGS - off) / RT;+ if (q < 0 || q >= 1) continue;+ const rr = r + 1.5 + 22 * (1 - ease.inQuad(q)), shape = [[1, 0], [0.38, 0.55], [1, 0], [0.42, -0.7]][k];+ ringAt(p, C, x, y, rr, shape[0], shape[1], q);+ }++ orb(p, C, x, y, r, t, ph);++ // arcs crackling off it, new ones every other frame+ const w = Math.floor(f / 2), Rw = rng(S, w, 3), n = (Rw.next() < 0.6 ? 1 : 0) + (swell > 0.3 ? 1 : 0), fresh = f % 2 === 0 ? 0.8 : 0.4;+ for (let i = 0; i < n; i++) {+ const a = Rw.range(0, TAU), L = Rw.range(5, 10) * (1 + swell * 0.4), a1 = a + Rw.range(-0.5, 0.5);+ const x0 = x + Math.cos(a) * (r + 0.5), y0 = y + Math.sin(a) * (r + 0.5), x1 = x0 + Math.cos(a1) * L, y1 = Math.min(-2, y0 + Math.sin(a1) * L);+ drawArc(p, arc(Rw, x0, y0, x1, y1, { jag: 0.35, forks: Rw.next() < 0.5 ? 1 : 0 }), { core: WHITE, body: C[5], halo: C[3], glow: C[5] }, fresh, 0.3);+ }+ // glints winking round it+ cycle(t, D, 7, S * 3 + 4, 0.22, (age, life, R) => {+ const a = R.range(0, TAU), d = R.range(r + 5, r + 15), k = Math.sin((age / life) * Math.PI);+ sparkle(p, x + Math.cos(a) * d, y + Math.sin(a) * d * 0.9, 1 + 2.5 * k, C[6], C[4], 0.4 * k);+ });+ if (since < 0.07) sparkle(p, x, y, 4 + 6 * (1 - since / 0.07), C[6], C[5], 0.5);++ // light: a wide pool that lights the caster, a hot heart, the floor beneath the hand+ const pulse = 0.85 + 0.15 * Math.sin(ph * TAU * 4) + 0.2 * swell;+ p.glow(x, y, 46, C[4], 0.26 * pulse);+ p.glowRing(x, y, r + 3, 8, C[5], 0.3 * pulse);+ p.glow(x, y, r, C[6], 0.12);+ p.glow(HX, -1, 22, C[5], 0.16 * pulse);}diff --git a/src/fx/arcane/star-fall.js b/src/fx/arcane/star-fall.jsindex b3c3156..cb62831 100644--- a/src/fx/arcane/star-fall.js+++ b/src/fx/arcane/star-fall.js@@ -1,70 +1,118 @@-import { burst, fly, seg, ease, clamp, rng, WHITE } from "../../core/index.js";-import { fit, sparkle, ovalLine, STARLIGHT } from "./_lib.js";+// The slanted streaks landing with a ring and a kick of bits follow Sprite Fusion's open-source rain+// (https://www.spritefusion.com/pixel-art-vfx/rain), MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Lights, P, Rng, PAL, fit, band, flare, sparkle, clamp, ease, TAU, WHITE } from "../../core/index.js";++const N = 11, SPREAD = 46, H = 124, SLANT = 0.38, TRAIL = 0.17;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,+ desc: "Stars streak down on long trails across an area, each landing with a white flash, a ring across the floor and a kick of sparks.",+ tags: ["arcane", "star", "meteor", "rain", "aoe", "magic", "ground", "one-shot"],+ size: [232, 172],+ origin: [124, 150],+ duration: 2.5,loop: false,fps: 30,bg: "ground",- options: { palette: STARLIGHT, count: 7, spread: 28, seed: 16 },+ options: { palette: PAL.arcane, seed: 13 },};-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 create(o) {+ const C = fit(o.palette, 8), R = new Rng(o.seed);+ const ps = new Particles({ rng: R, ground: () => 0, sparks: [WHITE, C[6], C[5], C[4]] }), lights = new Lights();+ // where they land: spread over the area in a shuffled order, a little in front of or behind the line+ const xs = Array.from({ length: N }, (_, i) => -SPREAD + ((i + R.range(0.2, 0.8)) * 2 * SPREAD) / N);+ for (let i = N - 1; i > 0; i--) {+ const j = R.int(0, i);+ [xs[i], xs[j]] = [xs[j], xs[i]];+ }+ const stars = xs.map((x, i) => {+ const y = R.range(-3, 2), h = H * R.range(0.85, 1);+ return { x, y, sx: x - h * SLANT, sy: y - h, t0: 0.04 + i * 0.105 + R.range(0, 0.05), T: R.range(0.3, 0.4), landed: false, big: R.chance(0.35), ph: R.range(0, TAU) };+ });+ const hits = [];+ let t = 0;+ const at = (s, tt) => {+ const q = clamp((tt - s.t0) / s.T), e = q * (0.35 + 0.65 * q);+ return [s.sx + (s.x - s.sx) * e, s.sy + (s.y - s.sy) * e, q];+ };-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);+ function star(p, s) {+ const [x, y, q] = at(s, t);+ // the trail: a long tapered streak back up its path, white at the head, thinning into violet+ const n = 20;+ for (let k = n; k >= 1; k--) {+ const [ax, ay] = at(s, t - (k * TRAIL) / n), [bx, by] = at(s, t - ((k - 1) * TRAIL) / n), u = k / n;+ if (t - (k * TRAIL) / n < s.t0) continue;+ const c = u < 0.15 ? WHITE : u < 0.4 ? C[6] : u < 0.7 ? C[5] : C[4];+ // a second line beside the first near the head gives it body; the tail thins to a dithered thread+ if (u < (s.big ? 0.55 : 0.35)) p.line(ax + 1, ay, bx + 1, by, u < 0.2 ? C[6] : C[5], 1.1 - u * 1.4);+ p.line(ax, ay, bx, by, c, 1.3 - u);+ if (k % 3 === 0) p.glow(ax, ay, 7 * (1 - u) + 2, C[5], 0.3 * (1 - u));}- 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));+ // the head: a twinkling four-point star+ if (s.big) flare(p, x, y, 7 + 1.5 * Math.sin(t * 40 + s.ph), 0.8, C);+ else sparkle(p, x, y, 3.5 + Math.sin(t * 40 + s.ph), C[6], C[5], 0.6);+ p.circle(x, y, s.big ? 1.6 : 1.1, WHITE);+ p.glow(x, y, s.big ? 18 : 13, C[5], 0.6);+ p.glow(x, y, 5, WHITE, 0.35);+ return q;}++ function hit(p, h, far) {+ const k = (t - h.t) / 0.45;+ if (k < 0 || k >= 1) return;+ band(p, h.x, h.y, 3 + (h.big ? 22 : 16) * ease.outCubic(k), 0.26, Math.max(1, 2.5 * (1 - k)), 1.15 - k, [C[3], C[5], C[6], WHITE], (g) => Math.sin(g) < 0 === far, k < 0.2);+ }++ return {+ update(dt) {+ t += dt;+ for (const s of stars) {+ if (t < s.t0 || s.landed) continue;+ const [x, y, q] = at(s, t);+ if (R.chance(0.55)) ps.spawn(P.STAR, x + R.range(-1.5, 1.5), y + R.range(-1.5, 1.5), R.range(-12, 12), R.range(-8, 4), R.range(0.35, 0.7), R.pick([WHITE, C[6], C[5]]), R.chance(0.7) ? R.range(0.4, 0.9) : R.range(1.2, 1.8));+ if (q >= 1) {+ s.landed = true;+ hits.push({ x: s.x, y: s.y, t, big: s.big });+ lights.add(s.x, s.y - 12, s.big ? 46 : 38, C[5], 0.9, 0.32);+ lights.add(s.x, s.y - 3, 16, WHITE, 0.8, 0.08);+ for (let i = 0; i < (s.big ? 14 : 9); i++) {+ const a = -Math.PI / 2 + R.range(-1.35, 1.35), sp = R.range(50, 150);+ ps.spawn(P.SPARK, s.x, Math.min(-1, s.y - 1), Math.cos(a) * sp, Math.sin(a) * sp, R.range(0.2, 0.5));+ }+ for (let i = 0; i < 4; i++) ps.spawn(P.STAR, s.x + R.range(-4, 4), s.y - R.range(2, 8), R.range(-15, 15), -R.range(10, 35), R.range(0.4, 0.8), R.pick([WHITE, C[6]]), R.range(0.8, 2));+ }+ }+ ps.update(dt);+ lights.update(dt);+ },+ drawBack(p) {+ // the area lit beneath while they fall+ const k = clamp(t / 0.3) * (1 - clamp((t - 1.7) / 0.7));+ if (k > 0) for (const x of [-36, 0, 36]) p.glow(x, -1, 40, C[4], 0.14 * k);+ for (const h of hits) hit(p, h, true);+ // a glowing mark where each landed, cooling away+ for (const h of hits) {+ const k2 = 1 - (t - h.t) / 0.7;+ if (k2 <= 0) continue;+ p.dot(h.x, h.y, k2 > 0.6 ? WHITE : C[6], k2 * 1.5);+ for (const dx of [-1, 1]) p.dot(h.x + dx, h.y, C[5], k2 * 1.2);+ p.glow(h.x, h.y - 1, 10, C[5], 0.35 * k2);+ }+ ps.draw(p, "back");+ },+ draw(p) {+ for (const s of stars) if (t >= s.t0 && !s.landed) star(p, s);+ for (const h of hits) {+ hit(p, h, false);+ const k = (t - h.t) / 0.22;+ if (k < 0 || k >= 1) continue;+ if (k < 0.35) p.circle(h.x, h.y - 2, 5 * (1 - k / 0.35) + 1, WHITE);+ flare(p, h.x, h.y - 2, (h.big ? 16 : 12) * Math.pow(1 - k, 1.5) + 2, 1 - k, C);+ }+ ps.draw(p, "front");+ lights.draw(p);+ },+ };}diff --git a/src/fx/arcane/time-stop.js b/src/fx/arcane/time-stop.jsindex 6e7dcb0..c617f57 100644--- a/src/fx/arcane/time-stop.js+++ b/src/fx/arcane/time-stop.js@@ -1,102 +1,202 @@-import { burst, fly, seg, ease, clamp, rgb, red, green, blue, luma, TAU, WHITE } from "../../core/index.js";-import { fit, sparkle, CHRONO } from "./_lib.js";+// The cracks walking out from a point and the burst into tumbling shards, glints and light are adapted from+// Sprite Fusion's open-source ice shatter (https://www.spritefusion.com/pixel-art-vfx/ice), MIT License,+// Copyright (c) 2026 Hugo Duprez.+import { Particles, Bits, Lights, P, B, Rng, PAL, fit, flare, clamp, smooth, ease, luma, rgb, TAU, WHITE } from "../../core/index.js";++const CY = -42, RC = 26, OPEN = 0.3, FREEZE = 1.75, CRACK = 2.2, SHATTER = 2.42;+// the second hand ticks, each wait longer than the last, until time stops+const TICKS = [0.36, 0.46, 0.57, 0.7, 0.85, 1.03, 1.24, 1.49];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,+ desc: "A clock face springs open, ticks slower and slower, freezes drained of colour, cracks, then shatters into falling shards.",+ tags: ["arcane", "time", "clock", "freeze", "stop", "shatter", "magic", "one-shot"],+ size: [196, 136],+ origin: [98, 118],+ duration: 3.6,loop: false,fps: 30,- bg: "dark",- options: { palette: CHRONO, radius: 24, seed: 17 },+ bg: "ground",+ options: { palette: PAL.arcane, seed: 14 },};-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);-};+// how far the hand has gone: a snap with a little overshoot at each tick+function hand(t) {+ let a = 0;+ for (const tk of TICKS) if (t > tk) a += ease.outBack(clamp((t - tk) / 0.07), 3);+ return -Math.PI / 2 + a * (TAU / 12);+}+// how fast time flows: full speed, slowing to nothing at the freeze+const flow = (t) => (t < OPEN ? 1 : Math.max(0, 1 - (t - OPEN) / (FREEZE - OPEN)) ** 1.6);+// the motes' clock: time itself, slowing down (integrated flow)+function clockTime(t) {+ let s = 0;+ for (let u = 0; u < Math.min(t, FREEZE); u += 1 / 120) s += flow(u) / 120;+ return s;+}-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)];+export function create(o) {+ const C = fit(o.palette, 8), R = new Rng(o.seed);+ // the drained ramp: each step's own lightness, cold grey+ const G = C.map((c) => {+ const l = luma(c) * 255;+ return rgb(l * 0.92, l * 0.96, Math.min(255, l * 1.06));+ });+ const ps = new Particles({ rng: R, ground: () => 0, sparks: [WHITE, C[6], C[5], C[4]] }), bits = new Bits({ ground: () => 0 }), lights = new Lights();+ const motes = Array.from({ length: 14 }, (_, i) => ({ a: R.range(0, TAU), r: RC + R.range(5, 14), w: R.range(1.4, 2.6) * (i % 2 ? 1 : -1), tilt: R.range(-0.5, 0.5), c: R.pick([WHITE, C[6], C[5]]) }));+ // cracks: jagged walks out from a point on the face+ const ix = R.range(-6, 6), iy = R.range(-6, 6), cracks = [];+ const walk = (x, y, a, len, depth) => {+ const pts = [[x, y]];+ for (let s = 0; s < len; s++) {+ a += R.range(-0.55, 0.55);+ x += Math.cos(a) * R.range(1.6, 2.6);+ y += Math.sin(a) * R.range(1.6, 2.6);+ if (Math.hypot(x, y) > RC - 0.5) break;+ pts.push([x, y]);+ if (depth < 1 && pts.length > 3 && R.chance(0.14)) walk(x, y, a + R.sign() * R.range(0.6, 1.1), len / 2, depth + 1);+ }+ cracks.push(pts);};- 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]));+ for (let i = 0; i < 7; i++) walk(ix, iy, (i / 7) * TAU + R.range(-0.3, 0.3), 16, 0);+ let t = 0, tc = 0, ticked = 0, shattered = false, frozen = false;++ // the face, in ramp K: glass, rims, ticks and dots, hands, hub+ function face(p, K, s, cracked) {+ const cy = CY, r = RC * s;+ if (r < 1) return;+ p.disc(0, cy, r, K[1], (d) => 0.3 + 0.35 * d * d);+ p.ring(0, cy, r + 0.5, 1, K[6]);+ p.ring(0, cy, r - 1.5, 1, K[4]);+ p.ring(0, cy, r + 2, 1, K[3], 0.6);+ // minute dots and hour ticks; the quarters long and bright+ for (let i = 0; i < 60; i++) {+ const a = (i / 60) * TAU;+ if (i % 5) p.dot(Math.cos(a) * (r - 3.5), cy + Math.sin(a) * (r - 3.5), K[4], 0.8);+ else {+ const q = i % 15 === 0, r0 = r - (q ? 8 : 6.5);+ p.line(Math.cos(a) * r0, cy + Math.sin(a) * r0, Math.cos(a) * (r - 3), cy + Math.sin(a) * (r - 3), q ? K[7] : K[6]);+ }}- // 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);+ p.ring(0, cy, r * 0.3, 1, K[4], 0.8);+ // the hour hand, then the second hand with its tail, then the hub+ const ha = -Math.PI / 2 + (hand(t) + Math.PI / 2) / 12 + 0.9, sa = hand(t) + (frozen ? Math.sin(t * 70) * 0.012 : 0);+ p.beam(0, cy, Math.cos(ha) * r * 0.48, cy + Math.sin(ha) * r * 0.48, 2.6, (u, v) => (v < 0.5 ? K[6] : K[4]));+ p.line(-Math.cos(sa) * 5, cy - Math.sin(sa) * 5, Math.cos(sa) * (r - 4), cy + Math.sin(sa) * (r - 4), (u) => (u > 0.75 ? K[7] : K[6]));+ p.line(-Math.cos(sa) * 5 + 0.5, cy - Math.sin(sa) * 5, -Math.cos(sa) * 2, cy - Math.sin(sa) * 2, K[5]);+ p.circle(0, cy, 2.2, K[5]);+ p.circle(0, cy, 1.2, K[7]);+ if (cracked > 0)+ for (const pts of cracks)+ for (let i = 0, n = Math.floor(pts.length * cracked); i < n; i++) {+ const [x, y] = pts[i], fresh = i > n - 3 && cracked < 1;+ p.px(x, cy + y, fresh ? WHITE : K[7]);+ if (!fresh) p.px(x, cy + y - 1, K[2]);+ }}- // 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);++ return {+ update(dt) {+ t += dt;+ tc = clockTime(t);+ // each tick sends a ripple and a spark off the hand's tip+ while (ticked < TICKS.length && t >= TICKS[ticked]) {+ ticked++;+ const a = hand(t + 0.1);+ lights.add(Math.cos(a) * (RC - 4), CY + Math.sin(a) * (RC - 4), 22, C[6], 0.6, 0.12);+ for (let i = 0; i < 3; i++) ps.spawn(P.STAR, Math.cos(a) * (RC + 1), CY + Math.sin(a) * (RC + 1), Math.cos(a) * 30 + R.range(-15, 15), Math.sin(a) * 30 + R.range(-15, 15), R.range(0.2, 0.4), R.pick([WHITE, C[6]]), R.range(0.7, 1.3));+ }+ if (!frozen && t >= FREEZE) {+ frozen = true;+ lights.add(0, CY, 70, WHITE, 0.7, 0.2);+ }+ if (!shattered && t >= SHATTER) {+ shattered = true;+ lights.add(0, CY, 80, WHITE, 0.8, 0.16);+ lights.add(0, CY, 100, C[5], 0.6, 0.6);+ // the face bursts into shards and chunks, cold grey; colour sparks back into the world around them+ for (let i = 0; i < 64; i++) {+ const a = R.range(0, TAU), d = R.range(0, RC), x = Math.cos(a) * d, y = CY + Math.sin(a) * d, sp = R.range(40, 140);+ const dx = x - ix, dy = y - CY - iy, l = Math.hypot(dx, dy) || 1;+ bits.add({ kind: B.SHARD, x, y, vx: (dx / l) * sp + R.range(-25, 25), vy: (dy / l) * sp * 0.7 - R.range(40, 120), g: 0.9, drag: 0.5, bounce: 0.25, life: R.range(0.8, 1.15), a: R.range(0, TAU), va: R.range(-22, 22), s: R.range(1.5, 3.6), c: R.pick([G[7], G[6], G[6], G[5]]) });+ }+ for (let i = 0; i < 10; i++) {+ const a = R.range(0, TAU), sp = R.range(40, 110);+ bits.add({ kind: B.CHUNK, x: Math.cos(a) * RC * 0.6, y: CY + Math.sin(a) * RC * 0.6, vx: Math.cos(a) * sp, vy: Math.sin(a) * sp * 0.6 - R.range(60, 130), g: 1, drag: 0.4, bounce: 0.3, life: R.range(0.9, 1.15), a: R.range(0, TAU), va: R.range(-14, 14), s: R.range(1.6, 3), ramp: [G[1], G[3], G[4], G[6], G[7]] });+ }+ for (let i = 0; i < 26; i++) {+ const a = R.range(0, TAU), sp = R.range(30, 110);+ ps.spawn(i % 2 ? P.STAR : P.MOTE, 0, CY, Math.cos(a) * sp, Math.sin(a) * sp, R.range(0.4, 0.8), R.pick([WHITE, C[6], C[5]]), R.range(0.8, 1.8));+ }+ for (let i = 0; i < 18; i++) {+ const a = R.range(0, TAU), sp = R.range(90, 200);+ ps.spawn(P.SPARK, 0, CY, Math.cos(a) * sp, Math.sin(a) * sp, R.range(0.2, 0.45));+ }+ // the stopped time it held lifts away as a cold vapour+ for (let i = 0; i < 12; i++) {+ const a = R.range(0, TAU), d = R.range(0, RC * 0.8);+ ps.spawn(P.VAPOUR, Math.cos(a) * d, CY + Math.sin(a) * d, Math.cos(a) * R.range(10, 40), Math.sin(a) * R.range(10, 30) - R.range(5, 20), R.range(0.6, 1), R.chance(0.5) ? G[5] : C[4], R.range(3, 6));+ }+ }+ bits.update(dt);+ ps.update(dt);+ lights.update(dt);+ },+ drawBack(p) {+ // the floor lit beneath the clock while it stands+ const k = smooth(0, OPEN, t) * (1 - smooth(SHATTER, SHATTER + 0.5, t)), cold = t >= FREEZE;+ if (k > 0) p.glow(0, -1, 40, cold ? G[5] : C[4], 0.25 * k);+ // the motes behind the face+ if (t < SHATTER) for (const m of motes) drawMote(p, m, true);+ },+ draw(p) {+ const cold = t >= FREEZE, s = t < OPEN ? ease.outBack(t / OPEN, 2.6) : 1;+ if (t < SHATTER) {+ // white for a beat as it freezes, then cold grey; white again in the moment it bursts+ const white = (t >= FREEZE && t < FREEZE + 0.06) || t >= SHATTER - 0.05;+ face(p, white ? G.map(() => WHITE) : cold ? G : C, s, clamp((t - CRACK) / 0.18));+ p.glow(0, CY, RC * 1.9, cold ? G[5] : C[4], 0.32 * s);+ p.glowRing(0, CY, RC, 7, cold ? G[6] : C[5], 0.28 * s);+ for (const m of motes) drawMote(p, m, false);+ }+ // springing open: a ring thrown out and a flare+ if (t < 0.35) {+ const q = t / 0.35;+ p.ring(0, CY, RC * (0.4 + 1.2 * ease.outCubic(q)), Math.max(1, 3 * (1 - q)), q < 0.3 ? WHITE : C[6], 1.2 - q);+ if (q < 0.5) flare(p, 0, CY, 26 * (1 - q * 2) + 2, 1 - q * 2, C);+ }+ // a ripple of time off each tick; ripples run on the clock's own slowing time, so they drag to a halt and+ // hang there, drained, until it all breaks+ if (t < SHATTER)+ for (const tk of TICKS) {+ if (t < tk) continue;+ const q = (tc - clockTime(tk)) / 0.32;+ if (q >= 1) continue;+ p.ring(0, CY, RC + 3 + 24 * ease.outCubic(q), 1, cold ? G[5] : C[5], (cold ? 0.6 : 0.8) * Math.pow(1 - q, 1.6));+ }+ if (t >= SHATTER && t < SHATTER + 0.2) {+ const q = (t - SHATTER) / 0.2;+ flare(p, 0, CY, 34 * (1 - q) + 2, 1 - q, C);+ p.ring(0, CY, RC + 30 * ease.outCubic(q), Math.max(1, 3 * (1 - q)), WHITE, 1.2 - q);+ }+ bits.draw(p);+ ps.draw(p);+ lights.draw(p);+ },};- 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);++ // a mote circling the clock on a tilted orbit, slowing with time; drained and still once it stops+ function drawMote(p, m, back) {+ const a = m.a + m.w * tc, z = Math.sin(a);+ if (z < 0 !== back) return;+ const x = Math.cos(a) * m.r, y = CY + Math.cos(a) * m.r * m.tilt + z * m.r * 0.3, cold = t >= FREEZE, v = flow(t) * m.w;+ const c = cold ? G[6] : m.c;+ p.dot(x, y, c, back ? 0.6 : 1);+ // a tail while it still moves+ if (Math.abs(v) > 0.2) for (let k = 1; k <= 3; k++) {+ const b = a - Math.sign(m.w) * k * 0.05 * Math.min(1, Math.abs(v));+ p.dot(Math.cos(b) * m.r, CY + Math.cos(b) * m.r * m.tilt + Math.sin(b) * m.r * 0.3, k < 2 ? C[5] : C[4], (back ? 0.5 : 0.9) * (1 - k / 4));}+ if (!back) p.glow(x, y, 5, cold ? G[6] : C[6], 0.3);}- 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/critters/_lib.js b/src/fx/critters/_lib.jsindex be2be4f..4505e39 100644--- a/src/fx/critters/_lib.js+++ b/src/fx/critters/_lib.js@@ -1,115 +1,140 @@-// 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.+// The critters' kit. A creature is built in a small offscreen grid from shaded parts, given a 1 px outline+// (picked per side, so it can be darker in shadow and break into a highlight), then put on the painter, opaque+// or translucent. Pure loops also get loop-safe noise, springs, closed-form flight with a floor, and the+// toolkit's own particle looks for particles whose state is a function of time.+// The flame tongue and fire puff recipes are adapted from Sprite Fusion's open-source fire+// (https://www.spritefusion.com/pixel-art-vfx/fire), and the bubble from its open-source bubbles+// (https://www.spritefusion.com/pixel-art-vfx/bubbles), MIT License, Copyright (c) 2026 Hugo Duprez.-import { hex, ramp, clamp, wrap } from "../../core/index.js";+import { Particles, Rng, hex, clamp, wrap, tileNoise, TAU, WHITE } 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);+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))]);+/** A curve through keyframes [[x, value], ...] that doesn't wrap: held flat before the first and after the last. */+export function curve(x, list) {+ if (x <= list[0][0]) return list[0][1];+ for (let i = 1; i < list.length; i++) {+ const [x0, v0] = list[i - 1], [x1, v1] = list[i];+ if (x <= x1) {+ const u = (x - x0) / (x1 - x0 || 1);+ return v0 + (v1 - v0) * u * u * (3 - 2 * u);+ }+ }+ return list[list.length - 1][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.+ * Smooth noise in -1..1 that repeats every D seconds: F bumps a loop (a whole number), off shifts it along,+ * so lnoise(t, D, F, r * 0.4) wobbles along a flame and still loops.*/-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);-}+export const lnoise = (t, D, F, off = 0, seed = 0) => tileNoise((t / D) * F + off, 0.5, F, 0, seed);-/** 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 damped spring's swing after a kick: 1 at age 0, ringing at hz, dying at rate damp. */+export const spring = (age, hz, damp) => (age < 0 ? 0 : Math.exp(-age * damp) * Math.cos(age * hz * TAU));++/**+ * A ballistic body thrown from (x, y) at (vx, vy) px/s under gravity g, stopping on the floor y = floor.+ * Returns { x, y, vx, vy, landed, at (time it landed), lx (where) }.+ */+export function toss(x, y, vx, vy, age, g, floor = 0) {+ const tl = g > 0 ? (-vy + Math.sqrt(Math.max(0, vy * vy + 2 * g * (floor - y)))) / g : Infinity;+ if (age < tl) return { x: x + vx * age, y: y + vy * age + 0.5 * g * age * age, vx, vy: vy + g * age, landed: false, at: tl, lx: x + vx * tl };+ return { x: x + vx * tl, y: floor, vx: 0, vy: 0, landed: true, at: tl, lx: x + vx * tl };}-/** A creature-sized canvas in local coordinates: cells [x0, x0 + w) x [y0, y0 + h). */+/** A creature-sized canvas in local coordinates: cells [x0, x0 + w) x [y0, y0 + h), each a color and an alpha. */export class Grid {constructor(x0, y0, w, h) {- this.x0 = x0; this.y0 = y0; this.w = w; this.h = h;+ this.x0 = Math.floor(x0); this.y0 = Math.floor(y0); this.w = w; this.h = h;this.c = new Uint32Array(w * h);+ this.a = new Float32Array(w * h);+ this.tag = new Uint8Array(w * h);+ this.o = { a: 1, t: 0 };}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) {+ /** Paint a cell: color c, alpha a (below 1 is drawn translucent), tag (any 0..255 label for later passes). */+ set(x, y, c, a = 1, tag = 0) {const i = this.idx(x, y);- if (i >= 0) this.c[i] = c;+ if (i >= 0 && c) (this.c[i] = c), (this.a[i] = a), (this.tag[i] = tag);}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). */+ tagAt(x, y) {+ const i = this.idx(x, y);+ return i < 0 ? 0 : this.tag[i];+ }+ erase(x, y) {+ const i = this.idx(x, y);+ if (i >= 0) this.c[i] = 0;+ }+ /**+ * fn(x, y, out) at each cell center in the box returns a color (or 0 / undefined to leave it); it may set+ * out.a (alpha) and out.t (tag).+ */shade(x0, y0, x1, y1, fn) {+ const o = this.o;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);+ o.a = 1; o.t = 0;+ const c = fn(x + 0.5, y + 0.5, o);+ if (c) this.set(x, y, c, o.a, o.t);}}/** Filled ellipse; c may be fn(nx, ny) of the normalized offset (-1..1), returning a color. */- ellipse(cx, cy, rx, ry, c) {+ 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) => {+ this.shade(cx - rx, cy - ry, cx + rx, cy + ry, (x, y, o) => {const nx = (x - cx) / rx, ny = (y - cy) / ry;if (nx * nx + ny * ny > 1) return 0;+ o.a = a;return typeof c === "function" ? c(nx, ny) : c;});}- /** 1 px line. */- line(x0, y0, x1, y1, c) {+ /** 1 px line; c may be fn(u). */+ line(x0, y0, x1, y1, c, a = 1) {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);+ 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);}/** 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) {+ tube(pts, r, c, a = 1) {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);+ this.set(x, y, typeof c === "function" ? c(u, 0) : c, a);continue;}- this.shade(x - rr, y - rr, x + rr, y + rr, (px, py) => {+ this.shade(x - rr, y - rr, x + rr, y + rr, (px, py, o) => {const d = Math.hypot(px - x, py - y) / rr;+ o.a = a;return d > 1 ? 0 : typeof c === "function" ? c(u, d) : c;});}}}/** Filled polygon (even-odd); c may be fn(x, y). */- poly(pts, c) {+ poly(pts, c, a = 1) {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) => {+ 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;}+ o.a = a;return inside ? (typeof c === "function" ? c(x, y) : c) : 0;});}@@ -141,22 +166,191 @@ export class Grid {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;+ /**+ * How deep each filled cell sits: 1 on the edge (next to an empty cell, 4-neighbour), 2 one in, ... up to max.+ * Returns a Uint8Array over the grid (0 where empty); depth(x, y) reads it.+ */+ depths(max = 4) {+ const { w, h, c } = this, d = new Uint8Array(w * h), q = [];+ for (let i = 0; i < w * h; i++) {+ if (!c[i]) continue;+ const x = i % w, y = (i / w) | 0;+ if (x === 0 || y === 0 || x === w - 1 || y === h - 1 || !c[i - 1] || !c[i + 1] || !c[i - w] || !c[i + w]) (d[i] = 1), q.push(i);+ }+ for (let k = 0; k < q.length; k++) {+ const i = q[k], v = d[i];+ if (v >= max) continue;+ for (const j of [i - 1, i + 1, i - w, i + w]) if (j >= 0 && j < w * h && c[j] && !d[j]) (d[j] = v + 1), q.push(j);+ }+ for (let i = 0; i < w * h; i++) if (c[i] && !d[i]) d[i] = max;+ this.d = d;+ return d;+ }+ depth(x, y) {+ const i = this.idx(x, y);+ return i < 0 || !this.d ? 0 : this.d[i];+ }+ /**+ * Wrap everything drawn so far in a 1 px outline (4-neighbour). c is a color, or fn(x, y, nx, ny) with+ * (nx, ny) the outward direction there (summed from the filled neighbours), so the outline can be picked+ * per side: darker under the light, broken where a highlight touches it. Return 0 to leave a gap.+ */+ outline(c, a = 1) {+ const src = this.c.slice(), w = this.w, h = this.h, fn = typeof c === "function";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;+ const l = x > 0 && src[i - 1], r = x < w - 1 && src[i + 1], u = y > 0 && src[i - w], d = y < h - 1 && src[i + w];+ if (!(l || r || u || d)) continue;+ const col = fn ? c(this.x0 + x, this.y0 + y, (l ? 1 : 0) - (r ? 1 : 0), (u ? 1 : 0) - (d ? 1 : 0)) : c;+ if (col) (this.c[i] = col), (this.a[i] = a), (this.tag[i] = 255);}}- /** Put the grid on the painter (a < 1 dithers it out). */- draw(p, a = 1) {+ /** Rework every filled cell: fn(x, y, color, alpha, tag) returns its new color (0 erases it). */+ recolor(fn) {+ for (let i = 0; i < this.w * this.h; i++) {+ if (!this.c[i]) continue;+ this.c[i] = fn(this.x0 + (i % this.w), this.y0 + ((i / this.w) | 0), this.c[i], this.a[i], this.tag[i]) || 0;+ }+ }+ /** Put the grid on the painter, moved by (dx, dy): opaque cells dithered by fade, translucent ones blended. */+ draw(p, fade = 1, dx = 0, dy = 0) {+ const X = this.x0 + Math.round(dx), Y = this.y0 + Math.round(dy);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);+ const i = y * this.w + x, c = this.c[i];+ if (!c) continue;+ const a = this.a[i];+ if (a >= 0.999) p.dot(X + x, Y + y, c, fade);+ else p.blend(X + x, Y + y, c, a * fade);}}+ clear() {+ this.c.fill(0);+ this.tag.fill(0);+ this.d = null;+ return this;+ }+}++/**+ * The toolkit's particle looks for particles whose state is a function of time (pure loops): begin(t), then+ * add(kind, x, y, vx, vy, age, life, color, size, flag, seed) for each one alive now, then draw(p, layer).+ * opts as for core Particles: { sparks: [head..tail], haze }.+ */+export class Swarm {+ constructor(opts = {}) {+ this.ps = new Particles({ rng: new Rng(1), ...opts });+ }+ begin(t) {+ this.ps.list.length = 0;+ this.ps.t = t;+ return this;+ }+ add(k, x, y, vx, vy, age, life, col = WHITE, size = 1, flag = 0, seed = 0) {+ if (age < 0 || age >= life) return;+ this.ps.list.push({ k, x, y, vx, vy, life: life - age, max: life, col: col ? hex(col) : 0, size, seed, delay: 0, flag });+ }+ draw(p, layer) {+ this.ps.draw(p, layer);+ }+}++// Hugo's flame layers: [width, height, ramp step] from the widest dark outer flame to the white-hot heart+const LAYERS = [[1, 1, 6], [0.76, 0.86, 4], [0.54, 0.68, 2], [0.3, 0.42, 0]];++/**+ * A tongue of flame standing on (x, y), h tall, w half-wide at its root, its tip swaying sx px; four nested+ * layers down a 9-step fire ramp given bright-first (heat[0] white). n seeds its flicker; t, D keep it looping.+ * only: draw just that layer (0 outer .. 3 heart), so a bunch of tongues can be laid down layer by layer and+ * merge into one flame with one dark rim.+ */+export function tongue(p, x, y, h, w, sx, t, D, n, heat, only = -1) {+ if (h < 1) return;+ const F1 = Math.max(1, Math.round(9 * D)), F2 = Math.max(1, Math.round(4 * D));+ for (let li = 0; li < LAYERS.length; li++) {+ if (only >= 0 && li !== only) continue;+ const [lw, lh, ri] = LAYERS[li];+ const H = h * lh, col = heat[ri];+ for (let r = 0; r <= H; r++) {+ const u = r / Math.max(1, H);+ const half = w * lw * Math.pow(1 - u, 0.85) * Math.min(1, (r + 1.5) / 3.5) + lnoise(t, D, F1, r * 0.45, n) * 0.5;+ const cx = x + sx * u * u * lh + lnoise(t, D, F2, r * 0.2, n + 7) * u * 1.1;+ if (half < 0.3) continue;+ for (let px = Math.round(cx - half); px <= Math.round(cx + half); px++) p.px(px, Math.round(y - r), col);+ }+ }+}++/**+ * A puff of flame k of its life left (1 new .. 0 gone), size px, cooling down heat (bright-first, 9 steps):+ * a darker rim, a lit core, a tongue on top, light.+ */+export function firePuff(p, x, y, k, size, seed, heat) {+ const age = 1 - k, n = heat.length, hot = Math.min(0.999, Math.pow(age, 0.62) + (seed % 1) * 0.1);+ const idx = Math.min(n - 2, Math.floor(hot * (n - 1)));+ const r = size * (0.55 + 0.45 * Math.min(1, age * 7)) * (1 - age * 0.55), c = heat[idx];+ if (idx >= n - 2) return p.disc(x, y, r, c, Math.min(1, k * 3) * 0.85);+ p.circle(x, y, r, heat[Math.min(n - 1, idx + 2)]);+ p.circle(x - r * 0.16, y - r * 0.22, r * 0.78, c);+ if (r > 1.6) p.circle(x, y - r * 0.9, r * 0.42, c);+ if (idx <= 3 && r > 1.8) p.circle(x - r * 0.28, y - r * 0.34, r * 0.36, heat[Math.max(0, idx - 1)]);+ if (idx < 6) p.glow(x, y, r * 2.4 + 2, c, 0.18 * k);+}++/**+ * A bubble of radius r: a rim lit top-left and shaded bottom-right, a faint fill, a white glint, light.+ * cols: [highlight, lit, rim, shade]. Adapted from Sprite Fusion's open-source bubbles+ * (https://www.spritefusion.com/pixel-art-vfx/bubbles), MIT License, Copyright (c) 2026 Hugo Duprez.+ */+export function bubble(p, cx, cy, r, cols, a = 1, wob = 0) {+ const [HI, LIT, RIM, SHADE] = cols;+ if (r < 0.9) return p.dot(cx, cy, r < 0.7 ? RIM : LIT, a);+ if (r < 1.5) {+ const px = Math.floor(cx), py = Math.floor(cy);+ p.dot(px, py, HI, a); p.dot(px + 1, py, LIT, a); p.dot(px, py + 1, RIM, a); p.dot(px + 1, py + 1, SHADE, a);+ p.glow(cx + 0.5, cy + 0.5, 3, LIT, 0.12 * a);+ return;+ }+ const rx = r * (1 + wob), ry = r * (1 - wob);+ for (let y = Math.floor(cy - ry - 1); y <= Math.ceil(cy + ry + 1); y++)+ for (let x = Math.floor(cx - rx - 1); x <= Math.ceil(cx + rx + 1); x++) {+ const dx = (x + 0.5 - cx) / rx, dy = (y + 0.5 - cy) / ry, d = Math.sqrt(dx * dx + dy * dy) * r;+ if (d > r + 0.5) continue;+ const l = (-dx - dy) / Math.SQRT2 / Math.max(0.01, d / r);+ if (d > r - 0.6) p.dot(x, y, l > 0.45 ? LIT : l < -0.55 ? SHADE : RIM, a);+ }+ const hx = Math.round(cx - rx * 0.45), hy = Math.round(cy - ry * 0.45);+ p.dot(hx, hy, HI, a);+ if (r >= 2.5) p.dot(hx + 1, hy, LIT, a), p.dot(hx, hy + 1, LIT, a);+ if (r >= 2) p.dot(Math.round(cx + rx * 0.5), Math.round(cy + ry * 0.5), LIT, a);+ p.glow(cx, cy, r * 2.4 + 2, RIM, 0.14 * a);+}++/** A soft shadow: an ellipse blended over what's there, a alpha at the center fading to nothing at the rim. */+export function shadow(p, cx, cy, rx, ry, c, a) {+ if (rx <= 0 || ry <= 0 || a <= 0) return;+ for (let y = Math.floor(cy - ry); y <= Math.ceil(cy + ry); y++)+ for (let x = Math.floor(cx - rx); x <= Math.ceil(cx + rx); x++) {+ const d = ((x + 0.5 - cx) / rx) ** 2 + ((y + 0.5 - cy) / ry) ** 2;+ if (d < 1) p.blend(x, y, c, a * (1 - d) ** 0.7);+ }+}++/**+ * A ballistic body thrown from (x, y) at (vx, vy) under gravity g that bounces on the floor y = floor, keeping+ * e of its speed each bounce (and 70% of its run), until it rests. Returns { x, y, vx, vy, hops, rest }.+ */+export function bounce(x, y, vx, vy, age, g, floor = 0, e = 0.45) {+ let hops = 0;+ for (; hops < 6; hops++) {+ const f = toss(x, y, vx, vy, age, g, floor);+ if (!f.landed) return { x: f.x, y: f.y, vx: f.vx, vy: f.vy, hops, rest: false };+ const vl = vy + g * f.at;+ age -= f.at;+ x = f.lx; y = floor - 0.01; vx *= 0.7; vy = -vl * e;+ if (Math.abs(vy) < 25) break;+ }+ return { x, y: floor - 0.25, vx: 0, vy: 0, hops, rest: true };}diff --git a/src/fx/critters/bat.js b/src/fx/critters/bat.jsindex a3d3731..bb60862 100644--- a/src/fx/critters/bat.js+++ b/src/fx/critters/bat.js@@ -1,62 +1,107 @@-import { hex, TAU } from "../../core/index.js";-import { Grid, shades, lit, shift } from "./_lib.js";+import { fit, hex, mix, clamp, wrap, lerp, sparkle, cycle, TAU } from "../../core/index.js";+import { Grid, 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,+ desc: "A bat flaps in four snappy wing frames along a figure-eight, its body lifting on each downbeat, moonlight on its wing bones, red eyes glowing and glinting.",+ tags: ["critter", "bat", "night", "flying", "spooky", "loop"],+ size: [112, 80],+ origin: [56, 40],+ duration: 2.4,loop: true,fps: 30,- bg: "dark",- options: { palette: ["#130d1c", "#2f2245", "#57437a", "#8c74ad", "#d4a2c4"], eyes: "#ffd23c", flaps: 3, seed: 1 },+ bg: "sky",+ options: { palette: ["#0c0912", "#1f1629", "#382645", "#5b3f66", "#866089", "#b88fb0", "#e8cfe0"], eyes: ["#8a1020", "#ff3b30", "#ffb04a", "#fff0c0"], 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]];+const D = meta.duration, FLAPS = 6, GRID = new Grid(-24, -22, 48, 40);+// the four wing frames for the right wing: arm angle and length, three fingers' angles and lengths, the lift+const FRAMES = [+ { arm: -58, al: 8, f: [-112, -76, -38], fl: [9, 11, 9], lift: 1 },+ { arm: -18, al: 9, f: [-40, -12, 16], fl: [10, 11, 9], lift: 0 },+ { arm: 28, al: 8, f: [50, 72, 94], fl: [9, 10, 8], lift: -2 },+ { arm: -42, al: 6, f: [-66, -38, -10], fl: [7, 8, 6], lift: -1 },+];+const rad = (d) => (d * Math.PI) / 180;++// figure-eight flight, and which wing frame it's on+function at(t) {+ const a = (t / D) * TAU;+ return { x: 22 * Math.sin(a), y: 7 * Math.sin(2 * a), vx: Math.cos(a) };+}+const frameAt = (t) => Math.floor(wrap((t / D) * FLAPS, 1) * 4) % 4;++function wingPts(F, s) {+ const sh = [s * 2.5, -2], ar = rad(F.arm), wr = [sh[0] + s * Math.cos(ar) * F.al, sh[1] + Math.sin(ar) * F.al];+ const tips = F.f.map((d, i) => [wr[0] + s * Math.cos(rad(d)) * F.fl[i], wr[1] + Math.sin(rad(d)) * F.fl[i]]);+ const pull = (a, b, k) => [lerp((a[0] + b[0]) / 2, wr[0], k), lerp((a[1] + b[1]) / 2, wr[1], k)];+ const hip = [s * 2, 3.5];+ return { sh, wr, tips, hip, poly: [sh, wr, tips[0], pull(tips[0], tips[1], 0.22), tips[1], pull(tips[1], tips[2], 0.22), tips[2], pull(tips[2], hip, 0.38), hip] };+}++function bat(g, C, E, F, t) {+ g.clear();+ // wings: a membrane, darker near the body, lit along the leading edge; finger bones over it+ for (const s of [-1, 1]) {+ const w = wingPts(F, s), lead = (x, y) => {+ const [ax, ay] = w.wr, [bx, by] = w.tips[0], dx = bx - ax, dy = by - ay, L = Math.hypot(dx, dy) || 1;+ return Math.abs(((x - ax) * dy - (y - ay) * dx) / L);+ };+ g.poly(w.poly, (x, y) => {+ const near = Math.hypot(x - w.sh[0], y - w.sh[1]);+ if (lead(x, y) < 1.2 && F.arm < 20) return C[3];+ return near < 4.5 ? C[1] : C[2];+ });+ g.line(w.sh[0], w.sh[1], w.wr[0], w.wr[1], C[4]);+ for (const tip of w.tips) g.line(w.wr[0], w.wr[1], tip[0], tip[1], (u) => (u < 0.6 ? C[4] : C[3]));+ g.set(w.wr[0], w.wr[1] - 1, C[5]);+ }+ // the body: fur lit top-left, a paler belly, big ears with pink insides+ g.ellipse(0, 0.5, 3.8, 4.8, (nx, ny) => (nx * -0.6 + ny * -0.8 > 0.45 ? C[4] : nx * 0.6 + ny * 0.8 > 0.55 ? C[2] : ny > 0.1 && Math.abs(nx) < 0.5 ? C[4] : C[3]));+ for (const s of [-1, 1]) {+ g.poly([[s * 0.6, -3.5], [s * 3.6, -9.5], [s * 3.8, -3]], s < 0 ? C[4] : C[3]);+ g.line(s * 2.6, -4, s * 3.2, -7.5, C[5]);+ }+ // eyes, a snout, two fangs, tucked feet+ g.set(-2, -1, E[1]); g.set(1, -1, E[1]);+ g.set(-1, 0, C[1]); g.set(0, 0, C[1]);+ g.set(-1, 1, C[6]); g.set(0, 1, C[6]);+ g.set(-2, 5, C[3]); g.set(1, 5, C[3]);+ g.outline(C[0]);+}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]);+ const t = shift(time, D, o.seed), C = fit(o.palette, 7), E = fit(o.eyes, 4), S = at(t), fi = frameAt(t), F = FRAMES[fi];+ const X = Math.round(S.x), Y = Math.round(S.y + F.lift);+ // its glowing eyes leave a fading streak of red light along its flight+ for (let k = 2; k <= 16; k++) {+ const A = at(t - (k - 1) * 0.022), B2 = at(t - k * 0.022), u = 1 - k / 17;+ for (const ex of [-1.5, 1.5]) p.glowLine(A.x + ex, A.y - 0.5, B2.x + ex, B2.y - 0.5, 2.6, E[1], 0.16 * u);+ }+ // moonlit dust drifting in the night air+ cycle(t, D, 9, o.seed * 11 + 1, D, (age, L, r) => {+ const x = r.range(-50, 50) + Math.sin(age * 1.1 + r.next() * 6) * 3, y = r.range(-34, 34) + age * r.range(-2, 3);+ const tw = Math.sin(age * 2.6 + r.next() * 6), a = Math.min(1, age * 2, (L - age) * 2) * (0.4 + 0.5 * tw);+ p.dot(x, y, tw > 0.7 ? C[6] : C[5], a);+ if (tw > 0.5) p.glow(x, y, 3, C[5], 0.2 * a);+ });+ const g = GRID;+ // on the downbeat the wings leave a see-through echo of where they just were+ if (fi === 2) {+ bat(g, C, E, FRAMES[1], t);+ g.recolor((x, y, c) => mix(c, C[4], 0.35));+ g.a.fill(0.35);+ g.draw(p, 1, X, Y - FRAMES[1].lift + F.lift);}- // 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]);+ bat(g, C, E, F, t);+ g.draw(p, 1, X, Y);+ // moonlight catches the top of the head and wings+ p.glow(X - 3, Y - 6, 10, C[5], 0.12);+ // the eyes glow, and glint now and then+ for (const ex of [-1.5, 1.5]) p.glow(X + ex, Y - 0.5, 7, E[1], 0.6), p.glow(X + ex, Y - 0.5, 2.5, E[2], 0.5);+ p.glow(X, Y, 22, E[0], 0.25);+ for (const g0 of [0.3, 1.5]) {+ const k = (wrap(t - g0, D)) / 0.24;+ if (k < 1) sparkle(p, X - 2, Y - 1, 1 + 2.5 * Math.sin(Math.PI * k), E[3], E[2], 0.4 * Math.sin(Math.PI * k));}- // 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.jsindex cf82098..e07fc40 100644--- a/src/fx/critters/bird.js+++ b/src/fx/critters/bird.js@@ -1,65 +1,125 @@-import { hex, TAU, WHITE } from "../../core/index.js";-import { Grid, shades, lit, shift } from "./_lib.js";+import { fit, hex, mix, clamp, wrap, lerp, smooth, ease, TAU } from "../../core/index.js";+import { Grid, 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,+ desc: "A songbird flies in place: bursts of wingbeats that lift its body on each downstroke, a glide on spread wings, its tail fanning, a loose feather drifting away.",+ tags: ["critter", "bird", "flying", "animal", "loop"],+ size: [112, 80],+ origin: [56, 40],+ duration: 2.4,loop: true,fps: 30,- bg: "dark",- options: { palette: ["#0b1330", "#1d3c7c", "#3a74ca", "#7cb6f2", "#e4f2ff"], breast: "#f0a050", beak: "#f6c344", seed: 1 },+ bg: "sky",+ options: {+ palette: ["#0a0e1e", "#18244a", "#24407a", "#3466aa", "#5a94d4", "#9cc8f0", "#eaf6ff"],+ breast: ["#4a1a0e", "#a8441c", "#e8783a", "#ffb070"],+ 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];+const D = meta.duration, GRID = new Grid(-26, -26, 52, 46), BEAK = hex("#f0b030"), BEAKD = hex("#a86a18");+// the near wing's key poses, points from the shoulder: leading edge to the tip, then the trailing feathers back+const POSE = {+ up: [[0, 0], [-1, -8], [-5, -15], [-8, -13.5], [-10.5, -10.5], [-11, -7], [-9, -3], [-6, 1]],+ mid: [[0, 0], [-3, -2.5], [-9, -2.5], [-10.5, -0.5], [-10, 1.2], [-8.5, 2], [-7, 2.2], [-5, 2]],+ down: [[0, 0], [-1, 6], [-3.5, 12], [-6, 11], [-7.5, 8.5], [-8, 6], [-7, 3], [-5, 2]],+ fold: [[0, 0], [-3, -4], [-10, -5.5], [-11, -4], [-10, -2.5], [-8.5, -1], [-7, 0.5], [-5, 1.5]],+ glide: [[0, 0], [-2, -5], [-7, -10], [-10, -9], [-12, -6.5], [-11.5, -3.5], [-9, -1], [-6, 1]],+};+const mixPose = (a, b, u) => a.map(([x, y], i) => [lerp(x, b[i][0], u), lerp(y, b[i][1], u)]);+// flapping until GLIDE, then a glide on spread wings+const FLAPS = 4, GLIDE = 1.5;+function wing(t) {+ t = wrap(t, D);+ if (t < GLIDE) {+ const u = ((t / GLIDE) * FLAPS) % 1;+ // a quick downstroke through the stretched-out middle, a slower upstroke folded close+ if (u < 0.4) {+ const k = ease.inOutSine(u / 0.4);+ return { pts: k < 0.5 ? mixPose(POSE.up, POSE.mid, k * 2) : mixPose(POSE.mid, POSE.down, k * 2 - 1), down: true, u };+ }+ const k = ease.inOutSine((u - 0.4) / 0.6);+ return { pts: k < 0.5 ? mixPose(POSE.down, POSE.fold, k * 2) : mixPose(POSE.fold, POSE.up, k * 2 - 1), down: false, u };+ }+ const g = (t - GLIDE) / (D - GLIDE), into = smooth(0, 0.15, g), out = smooth(0.85, 1, g);+ return { pts: mixPose(mixPose(POSE.up, POSE.glide, into), POSE.up, out), down: false, u: 0 };+}+// the body rises as the wings push down, and sinks a touch through the glide+function lift(t) {+ t = wrap(t, D);+ let y = 0;+ for (let k = 0; k < 6; k++) if (wing(t - k * 0.02).down) y -= 0.45;+ if (t >= GLIDE) y += 2.2 * Math.sin(Math.PI * ((t - GLIDE) / (D - GLIDE)));+ return y + 1.2;+}++const SH = [1, -2];+const wingPts = (w, far) => w.pts.map(([x, y]) => [SH[0] + x - (far ? 1 : 0), SH[1] + y * (far ? 0.85 : 1) - (far ? 1 : 0)]);-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);+function bird(g, C, Br, t, w) {+ g.clear();+ // the far wing, behind the body and in shadow+ g.poly(wingPts(w, true), C[1]);+ // the tail: three feathers fanning as it brakes and lifts+ const tf = 0.25 + 0.35 * Math.sin((t / D) * TAU * 2);+ for (let i = 0; i < 3; i++) {+ const a = Math.PI + (i - 1) * tf * 0.5 + 0.1, L = 9 - Math.abs(i - 1);+ g.poly([[-7, -2.4], [-7 + Math.cos(a) * L, -1 + Math.sin(a) * L - 1.2], [-7 + Math.cos(a) * L, -1 + Math.sin(a) * L + 1.2], [-7, 0.6]], i === 0 ? C[3] : C[2]);}+ // body and head: a blue back lit from above, a rust breast, a pale belly+ const inBody = (x, y) => ((x + 1) / 8.5) ** 2 + (y / 5.2) ** 2 <= 1 || (x - 6.5) ** 2 + (y + 3) ** 2 <= 4.6 ** 2;+ g.shade(-10, -9, 12, 6, (x, y) => {+ if (!inBody(x, y)) return 0;+ const top = !inBody(x, y - 2.2), under = !inBody(x + 0.5, y + 1.6);+ if (y > -0.5 && x > -2.5) return under ? Br[1] : x > 3 && y < 2 ? Br[3] : Br[2];+ if (y > 1.5) return under ? C[4] : C[5];+ return top ? (x > 2 ? C[5] : C[4]) : y < -3.5 && x > 3 ? C[4] : C[3];+ });+ // beak, eye with a glint, a dark cap stripe+ g.poly([[10.5, -4.5], [14.5, -3], [10.5, -2]], (x, y) => (y < -3 ? BEAK : BEAKD));+ g.set(8, -4, C[0]); g.set(8, -5, C[6]); g.set(9, -4, C[0]);+ g.line(5, -7, 9, -6.5, C[2]);+ // the near wing: lit along its leading edge, the flight feathers splayed at the tips+ const wp = wingPts(w, false);+ const edge = (x, y) => {+ let m = Infinity;+ for (let i = 1; i < 3; i++) {+ const [ax, ay] = wp[i - 1], [bx, by] = wp[i], dx = bx - ax, dy = by - ay, L2 = dx * dx + dy * dy || 1, u = clamp(((x - ax) * dx + (y - ay) * dy) / L2);+ m = Math.min(m, Math.hypot(ax + dx * u - x, ay + dy * u - y));+ }+ return m;+ };+ g.poly(wp, (x, y) => {+ const d = edge(x, y);+ return d < 1.2 ? C[5] : d < 3 ? C[4] : C[3];+ });+ // the flight feathers: dark lines splaying from the wrist to the trailing edge+ for (let i = 3; i < 7; i++) g.line(wp[1][0], wp[1][1], lerp(wp[1][0], wp[i][0], 0.92), lerp(wp[1][1], wp[i][1], 0.92), C[2]);+ g.outline(C[0]);}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);+ const t = shift(time, D, o.seed), C = fit(o.palette, 7), Br = fit(o.breast, 4), w = wing(t), y = lift(t);+ const g = GRID;+ // on the downstroke, a see-through echo of the wing a moment before smears the beat+ if (w.down && w.u > 0.1) {+ const s = t - 0.05, ws = wing(s);+ g.clear();+ g.poly(wingPts(ws, false), C[6]);+ g.a.fill(0.42);+ g.draw(p, 1, 0, Math.round(lift(s)));+ }+ bird(g, C, Br, t, w);+ g.draw(p, 1, 0, Math.round(y));+ // a loose feather drifts off and rocks down out of sight+ const fa = wrap(t - 0.45, D);+ if (fa < 1.8) {+ const fx = -6 - 14 * fa - 3 * Math.sin(fa * 5), fy = 4 + 9 * fa + 1.5 * Math.cos(fa * 5) * fa, rock = Math.sin(fa * 5) * 0.8;+ const a = Math.min(1, (1.8 - fa) * 2);+ for (let i = -2; i <= 2; i++) p.dot(fx + i * Math.cos(rock), fy + i * Math.sin(rock) * 0.8, i < 0 ? C[5] : C[4], a);+ p.dot(fx + 2.6 * Math.cos(rock), fy + 2.6 * Math.sin(rock) * 0.8, C[3], a);+ }+ // a little moonlight on its back+ p.glow(2, y - 6, 16, C[5], 0.12);}diff --git a/src/fx/critters/butterfly.js b/src/fx/critters/butterfly.jsindex bdb1af1..ebb916c 100644--- a/src/fx/critters/butterfly.js+++ b/src/fx/critters/butterfly.js@@ -1,64 +1,139 @@-import { hex, TAU, WHITE } from "../../core/index.js";-import { Grid, shades, shift } from "./_lib.js";+import { fit, mix, clamp, wrap, lerp, cycle, sparkle, TAU } from "../../core/index.js";+import { Grid, 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,+ desc: "An iridescent butterfly wanders a loop in bursts of quick wingbeats and open-winged glides, its veined, spotted wings shedding a twinkling trail of glowing dust.",+ tags: ["critter", "butterfly", "insect", "flying", "magic", "glow", "loop"],+ size: [128, 88],+ origin: [64, 44],+ duration: 3.2,loop: true,fps: 30,- bg: "dark",- options: { palette: ["#0b0f2c", "#18296e", "#2a5fc4", "#4fa4f2", "#c6ecff"], body: "#3a2c40", beats: 9, seed: 1 },+ bg: "sky",+ options: {+ palette: ["#0b0f24", "#16224f", "#1f3f8a", "#2f74c8", "#4fb4f0", "#a0e6ff", "#ffffff"],+ spots: ["#3a1a08", "#c8641a", "#ffb43c", "#fff0b0"],+ 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];+const D = meta.duration, GRID = new Grid(-22, -20, 44, 40);+// the right wings, unfolded, in px from the wing root (y forward is negative)+const FORE = [[0, -1], [3, -6], [8, -11], [13, -12.5], [16.5, -10.5], [16.5, -6], [13, -1.5], [7, 1], [2, 1.5]];+const HIND = [[0, 1], [6, 1.5], [11, 4], [12.5, 8.5], [10.5, 12.5], [6.5, 13.5], [3, 11], [0.5, 6]];-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];+// flight: bursts of wingbeats (rising) and glides (sinking), wandering round a loop+const BURSTS = [[0, 0.95], [1.5, 2.55]];+function flapping(t) {+ for (const [a, b] of BURSTS) if (t >= a && t < b) return true;+ return false;+}+// the wing's fold, 1 flat open .. 0 edge-on: quick beats while flapping, held open while gliding+function fold(t) {+ t = wrap(t, D);+ for (const [a, b] of BURSTS)+ if (t >= a && t < b) {+ const n = Math.round((b - a) * 6.3), ph = ((t - a) / (b - a)) * n;+ return 0.14 + 0.86 * (0.5 + 0.5 * Math.cos(ph * TAU));}- if (ux < 1.2 || d < 0.3) return S[2];- return u < -0.1 && v < 0.2 ? S[4] : S[3];- });+ return 1;+}+function at(t) {+ t = wrap(t, D);+ const a = (t / D) * TAU;+ // a lift while it beats, a sink while it glides, so the path bobs in steps+ let lift = 0;+ for (const [s, e] of BURSTS) lift += -3 * Math.sin(Math.PI * clamp((t - s) / (e - s)));+ return { x: 30 * Math.sin(a) + 6 * Math.sin(3 * a), y: 12 * Math.sin(2 * a + 0.4) + lift, vx: Math.cos(a) };}-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]);+const inPoly = (pts, x, y) => {+ let inside = false;+ for (let i = 0, j = pts.length - 1; i < pts.length; 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;+};+function edgeDist(pts, x, y) {+ let m = Infinity;+ for (let i = 0, j = pts.length - 1; i < pts.length; j = i++) {+ const [ax, ay] = pts[j], [bx, by] = pts[i], dx = bx - ax, dy = by - ay, L2 = dx * dx + dy * dy || 1;+ const u = clamp(((x - ax) * dx + (y - ay) * dy) / L2), px = ax + dx * u - x, py = ay + dy * u - y;+ m = Math.min(m, Math.hypot(px, py));+ }+ return m;+}++// a wing's pattern at an unfolded point: dark at the root, iridescent blue brightest along the leading edge,+// thin dark veins, a black apex dotted white on the forewing, a gold eyespot on the hindwing+const FSPOTS = [[13.2, -10.2], [15.2, -8.4], [14.6, -5.6], [11.6, -11.4]];+function wingColor(C, Sp, hind, u, v) {+ const pts = hind ? HIND : FORE, e = edgeDist(pts, u, v), r = Math.hypot(u, v), ang = Math.atan2(v, u);+ if (e < 1) return C[0];+ if (!hind) {+ if (u + v * -0.45 > 14.2 || (r > 12.5 && v < -4)) {+ for (const [sx, sy] of FSPOTS) if (Math.hypot(u - sx, v - sy) < 0.9) return C[6];+ return C[0];+ }+ } else {+ if (e < 2 && r > 8) return Math.sin(ang * 10) > 0.5 ? C[5] : C[1];+ const d = Math.hypot(u - 7.6, v - 9.4);+ if (d < 0.7) return C[6];+ if (d < 1.4) return C[0];+ if (d < 2.2) return Sp[2];+ }+ for (const va of hind ? [0.5, 1.0, 1.45] : [-1.2, -0.75, -0.3]) if (Math.abs(ang - va) * r < 0.45 && r > 3.5) return C[1];+ if (r < 3) return C[2];+ if (r < 6) return C[3];+ if (!hind && e < 2.4 && v < -3) return C[5];+ return C[4];+}++function butterfly(g, C, Sp, w, t) {+ g.clear();+ for (const s of [-1, 1])+ for (const hind of [true, false]) {+ const pts = hind ? HIND : FORE;+ g.shade(-20, -15, 20, 16, (x, y) => {+ if (Math.sign(x + 0.001) !== s) return 0;+ const u = (Math.abs(x) - 1) / w, v = y;+ if (u < 0 || !inPoly(pts, u, v)) return 0;+ let c = wingColor(C, Sp, hind, u, v);+ // folding up, the far side of each wing turns away from the light+ if (w < 0.5 && c !== C[0]) c = mix(c, C[1], (0.5 - w) * 1.6);+ return c;+ });+ }+ // the body: a fuzzy thorax, a tapering abdomen, a round head, curled antennae with bright tips+ g.ellipse(0, 0.5, 1.6, 2.6, (nx, ny) => (nx + ny < -0.4 ? C[3] : C[1]));+ for (let y = 3; y < 10; y++) g.set(-1, y, y < 6 ? C[2] : C[1]), y < 8 && g.set(0, y, C[1]);+ g.set(-1, -3, C[3]); g.set(0, -3, C[2]); g.set(-1, -4, C[2]); g.set(0, -4, C[1]);+ for (const s of [-1, 1]) {+ const tip = [s * 4 - (s > 0 ? 0 : 1), -9.5];+ g.line(s > 0 ? 0 : -1, -5, tip[0], tip[1], C[2]);+ g.set(tip[0], tip[1], C[6]);}- // 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);+ g.outline((x, y, nx, ny) => C[0]);+}++export function draw(p, time, o) {+ const t = shift(time, D, o.seed), C = fit(o.palette, 7), Sp = fit(o.spots, 4), S = at(t), w = fold(t);+ // a trail of glowing dust shaken off the wings, drifting down and twinkling out+ cycle(t, D, 56, o.seed * 7 + 1, (r) => r.range(1, 1.8), (age, L, r, i) => {+ const born = wrap(t - age, D), B = at(born), k = age / L;+ if (!flapping(born) && r.chance(0.45)) return;+ const x = B.x + r.range(-9, 9) + Math.sin(age * 3 + i) * 1.5, y = B.y + r.range(-4, 8) + 7 * age + 3 * age * age;+ const tw = 0.5 + 0.5 * Math.sin(age * 11 + i * 2.1), a = Math.min(1, k * 8) * (1 - k);+ p.dot(x, y, tw > 0.7 ? C[6] : r.chance(0.3) ? Sp[2] : C[5], a * 1.2);+ p.glow(x, y, 6, C[4], 0.5 * a * tw);+ if (i % 9 === 0 && tw > 0.85 && k < 0.5) sparkle(p, x, y, 2, C[6], C[5], 0.3 * a);+ });+ const g = GRID;+ butterfly(g, C, Sp, w, t);+ g.draw(p, 1, S.x, S.y);+ // the wings shine: a soft blue light round it, brighter when they open+ p.glow(S.x, S.y, 38, C[4], 0.16 + 0.14 * w);+ p.glow(S.x, S.y, 12, C[5], 0.12 + 0.1 * w);}diff --git a/src/fx/critters/crab.js b/src/fx/critters/crab.jsdeleted file mode 100644index c1b0568..0000000--- a/src/fx/critters/crab.js+++ /dev/null@@ -1,80 +0,0 @@-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.jsindex c7a762f..54f541c 100644--- a/src/fx/critters/eyeball.js+++ b/src/fx/critters/eyeball.js@@ -1,72 +1,147 @@-import { hex, seg, TAU, WHITE } from "../../core/index.js";-import { Grid, shades, lit, keys, shift } from "./_lib.js";+import { fit, hex, mix, clamp, wrap, lerp, ease, rng, TAU } from "../../core/index.js";+import { Grid, shift, shadow, curve } 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],+ desc: "A bloodshot eyeball floats in its fleshy lids: its glowing iris snaps from one look to the next, it blinks, and its nerve sways behind it as it bobs.",+ tags: ["critter", "eyeball", "eye", "monster", "spooky", "float", "loop"],+ size: [96, 108],+ origin: [48, 100],duration: 3.2,loop: true,fps: 30,- bg: "dark",- options: { palette: ["#0d2418", "#1d6232", "#36a648", "#8ede6e", "#e2ffb4"], seed: 1 },+ bg: "ground",+ options: {+ palette: ["#2a1420", "#6a3040", "#b07078", "#dcbcb4", "#f4e9de", "#ffffff"],+ flesh: ["#1e0c16", "#4a1a2c", "#7c2c40", "#b04a58", "#e07a80"],+ iris: ["#0c2a14", "#1f6a2a", "#3fae3a", "#9be05a", "#e8ffb0"],+ hover: 48,+ 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]];+const D = meta.duration, GRID = new Grid(-18, -18, 36, 38), NERVE = new Grid(-20, -70, 40, 64), R = 13, VEIN = hex("#c42a3a");+// where it looks: snaps between targets with a little overshoot, holds, snaps on+const LOOKS = [[0, 0, 0], [0.55, 4.2, -1.2], [1.15, -4.4, 0.8], [1.95, 1.2, 3.4], [2.5, -2, -3.4], [3.0, 0, 0]];+function look(t) {+ let i = LOOKS.length - 1;+ while (i > 0 && t < LOOKS[i][0]) i--;+ const [t0, x1, y1] = LOOKS[i], [, x0, y0] = LOOKS[(i + LOOKS.length - 1) % LOOKS.length], u = ease.outBack(clamp((t - t0) / 0.08), 2.2);+ return [lerp(x0, x1, u), lerp(y0, y1, u)];+}+// the lids: open at rest, a quick blink before it looks down+const lid = (t) => (t > 1.74 && t < 1.92 ? Math.sin(Math.PI * ((t - 1.74) / 0.18)) : 0);+function at(t, hover) {+ const a = (t / D) * TAU;+ return { x: 1.5 * Math.sin(a), y: -hover - 3 * Math.sin(2 * a + 0.4) };+}-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: branching red threads creeping in from the rim, fixed to the eyeball's surface+function veins(seed) {+ const out = [], r = rng(seed, 77);+ for (let i = 0; i < 7; i++) {+ let a = (i / 7) * TAU + r.range(-0.3, 0.3), d = R - 0.5;+ const pts = [[Math.cos(a) * d, Math.sin(a) * d]];+ for (let k = 0; k < 4; k++) {+ a += r.range(-0.35, 0.35);+ d -= r.range(1.2, 2.1);+ pts.push([Math.cos(a) * d, Math.sin(a) * d]);+ }+ out.push(pts);+ }+ return out;+}++function eye(g, C, Fl, I, t, seed) {+ g.clear();+ const [lx, ly] = look(t), L = lid(t), V = veins(seed);+ const lit = (x, y, k) => Math.hypot(-4 + (x + 4) / k, -4.5 + (y + 4.5) / k) <= R;+ // the sclera: a wet sphere lit from the top-left, pinker in its shadow+ g.shade(-R, -R, R, R, (x, y) => {+ const d = Math.hypot(x, y);+ if (d > R) return 0;+ if (!(Math.hypot(x + 2, y + 2.2) <= R)) return C[2];+ return lit(x, y, 0.5) ? C[5] : lit(x, y, 0.8) ? C[4] : C[3];});- // 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);+ // veins ride the eyeball as it turns+ for (const pts of V) {+ const sh = pts.map(([x, y]) => [x + lx * 0.35 * (1 - Math.hypot(x, y) / R), y + ly * 0.35 * (1 - Math.hypot(x, y) / R)]);+ for (let k = 1; k < sh.length; k++) g.line(sh[k - 1][0], sh[k - 1][1], sh[k][0], sh[k][1], k < 2 ? VEIN : mix(VEIN, C[3], 0.45));}- // 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];+ // the iris, foreshortened as it turns away, a dark ring, a green that brightens toward the pupil+ const off = Math.hypot(lx, ly), fx = 1 - 0.32 * (Math.abs(lx) / R) ** 1.4 * 3, fy = 1 - 0.32 * (Math.abs(ly) / R) ** 1.4 * 3;+ const ir = 6.4, pr = 2 + 0.4 * Math.sin((t / D) * TAU * 2);+ g.shade(lx - ir - 1, ly - ir - 1, lx + ir + 1, ly + ir + 1, (x, y) => {+ const dx = (x - lx) / (ir * fx), dy = (y - ly) / (ir * fy), d = Math.hypot(dx, dy);+ if (d > 1 || Math.hypot(x, y) > R - 0.5) return 0;+ const pd = Math.hypot((x - lx) / fx, (y - ly) / fy);+ if (pd < pr) return C[0];+ if (d > 0.86) return I[0];+ const ang = Math.atan2(dy, dx), streak = Math.sin(ang * 9 + d * 4) > 0.5;+ if (d < 0.5) return streak ? I[4] : I[3];+ if (d < 0.7) return streak ? I[3] : I[2];+ return streak ? I[2] : I[1];+ });+ // a fixed glint from the light, whichever way it looks+ if (L < 0.5) g.set(-4, -5, C[5]), g.set(-3, -5, C[5]), g.set(-4, -4, C[5]), g.set(1, -2, C[5]);+ // the lids: fleshy shells over the top and bottom, lit like the ball they wrap, the upper one sweeping down to blink+ const up = lerp(-R + 3, R * 0.42, L), dn = lerp(R - 2.2, R * 0.42, L);+ const flit = (x, y, k) => Math.hypot(-4 + (x + 4) / k, -5 + (y + 5) / k) <= R + 0.6;+ g.shade(-R - 1, -R - 1, R + 1, R + 1, (x, y) => {+ const d = Math.hypot(x, y);+ if (d > R + 0.6) return 0;+ const ue = up + 1.8 * (x / R) ** 2, de = dn - 1.4 * (x / R) ** 2;+ const tone = !(Math.hypot(x + 2, y + 2.2) <= R + 0.6) ? Fl[1] : flit(x, y, 0.55) ? Fl[4] : flit(x, y, 0.85) ? Fl[3] : Fl[2];+ if (y < ue) return y > ue - 1.2 ? Fl[0] : tone;+ if (y > de) return y < de + 1.1 ? Fl[0] : tone === Fl[4] ? Fl[3] : tone;+ return 0;});- 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(C[0]);+}++export function draw(p, time, o) {+ const t = shift(time, D, o.seed), C = fit(o.palette, 6), Fl = fit(o.flesh, 5), I = fit(o.iris, 5), S = at(t, o.hover);+ // the optic nerve hangs from the back, trailing the bob a beat behind: one tube, lit down its left side+ const ng = NERVE.clear();+ for (let s = 0; s <= 20; s += 0.5) {+ const B = at(t - s * 0.035, o.hover), sw = 2.6 * (s / 20) ** 1.3 * Math.sin((t / D) * TAU * 2 - s * 0.16), r = lerp(2, 0.6, s / 20);+ const cx = B.x + 1 + sw, cy = B.y + R - 2 + s;+ ng.shade(cx - r - 1, cy - 1, cx + r + 1, cy + 1, (x, y) => {+ const v = (x - cx) / Math.max(0.6, r);+ if (Math.abs(v) > 1 || Math.abs(y - cy) > 0.5) return 0;+ return v < -0.35 ? Fl[4] : v < 0.4 ? Fl[3] : Fl[2];});}- g.outline(WHITES[0]);- g.draw(p);+ ng.outline(Fl[0]);+ ng.draw(p);+ const g = GRID;+ eye(g, C, Fl, I, t, o.seed);+ g.draw(p, 1, S.x, S.y);+ // the iris glows, an eerie halo round the whole eye, motes circling it+ const [lx, ly] = look(t), snap = Math.max(...LOOKS.map(([t0]) => Math.max(0, 1 - Math.abs(wrap(t - t0 + D / 2, D) - D / 2) / 0.2)));+ const open = 1 - lid(t);+ p.glow(S.x + lx, S.y + ly, 15, I[3], (0.5 + 0.3 * snap) * open);+ p.glow(S.x + lx, S.y + ly, 5, I[4], 0.4 * open);+ p.glow(S.x, S.y, 50, I[1], 0.3);+ // motes of green light wheel round it on a tilted orbit, trailing short streaks+ for (let i = 0; i < 8; i++) {+ const sp = (i % 2 ? 1 : -1) * (i % 3 ? 1 : 2), a0 = (i * TAU) / 8, rr = 19 + (i % 3) * 2;+ let prev = null;+ for (let k = 5; k >= 0; k--) {+ const a = (t / D) * TAU * sp + a0 - sp * k * 0.035, z = Math.sin(a), x = S.x + Math.cos(a) * rr, y = S.y + z * 5 - Math.cos(a) * 3;+ if (z < 0 && Math.hypot(x - S.x, y - S.y) < R + 1) {+ prev = null;+ continue;+ }+ if (prev && k > 0) p.line(prev[0], prev[1], x, y, I[2], 0.4 + (5 - k) * 0.12);+ if (k === 0) p.px(x, y, z > 0 ? I[4] : I[3]), p.glow(x, y, 5, I[3], 0.45);+ prev = [x, y];+ }+ }+}++export function drawBack(p, time, o) {+ const t = shift(time, D, o.seed), I = fit(o.iris, 5), S = at(t, o.hover);+ shadow(p, S.x, 0, 10, 1.5, hex("#0d0a12"), 0.5);+ for (let x = -26; x <= 26; x += 6) p.glow(S.x + x, -1, 18, I[2], 0.15 * (1 - Math.abs(x) / 34));}diff --git a/src/fx/critters/fish-school.js b/src/fx/critters/fish-school.jsindex 666b7f7..7b626af 100644--- a/src/fx/critters/fish-school.js+++ b/src/fx/critters/fish-school.js@@ -1,68 +1,114 @@-import { hex, loopNoise, cycle, TAU, WHITE } from "../../core/index.js";-import { Grid, shades, shift } from "./_lib.js";+// The caustic light and the bubbles are adapted from Sprite Fusion's open-source bubbles+// (https://www.spritefusion.com/pixel-art-vfx/bubbles), MIT License, Copyright (c) 2026 Hugo Duprez.+import { fit, mix, clamp, wrap, lerp, smooth, ease, rng, cycle, TAU } from "../../core/index.js";+import { Grid, shift, bubble } 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,+ desc: "A school of fish holds station in two depth rows: bodies wag into swinging tails, one darts ahead now and then, bubbles rise and caustic light ripples over them.",+ tags: ["critter", "fish", "school", "sea", "underwater", "swim", "loop"],+ size: [136, 80],+ origin: [68, 40],+ duration: 4.8,loop: true,fps: 30,bg: "dark",- options: { palette: ["#0a1a2c", "#17496c", "#2b88aa", "#70ccd8", "#dcfbff"], fin: "#f2b33c", count: 6, seed: 3 },+ options: {+ palette: ["#0a1a2a", "#123552", "#1d5a7e", "#2f8aa8", "#62bccc", "#bfe8e6", "#f4fff8"],+ stripe: ["#5a1e14", "#d8582a", "#ffa04a"],+ seed: 1,+ },};-// 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]];+const D = meta.duration, GRID = new Grid(-28, -12, 34, 24);+// the school: [x, y, size, back row?, phase]+const SCHOOL = [+ [-34, -16, 0.72, true, 0.1], [2, -20, 0.68, true, 0.55], [30, -10, 0.7, true, 0.3],+ [-22, 4, 1, false, 0.8], [12, -4, 1, false, 0.2], [-40, -2, 0.95, false, 0.45], [26, 14, 0.96, false, 0.65],+];-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];+// one fish, its nose at (0, 0), facing right, its body trailing back to the left+function fish(g, C, Sp, s, t, ph, dart) {+ g.clear();+ const L = 15 * s, H = 8 * s, beats = 12 + (dart > 0 ? 6 : 0), w = (t / D) * TAU * beats + ph * TAU;+ const amp = (1.3 + 1.2 * dart) * s, bend = (u) => amp * u ** 1.8 * Math.sin(w - 4 * u);+ const prof = (u) => (u < 0.3 ? Math.sqrt(u / 0.3) : 1 - ((u - 0.3) / 0.7) ** 1.5 * 0.72);+ const hh = (u) => (H / 2) * prof(u);+ // body: dark back, lighter flank, silver belly; a stripe down the side; light rippling on its back+ g.shade(-L, -H, 0, H, (x, y, o) => {+ const u = -x / L, dy = y - bend(u), h = hh(u);+ if (u < 0 || u > 1 || Math.abs(dy) > h) return 0;+ const v = dy / h;+ if (v > -0.12 && v < 0.12 && u > 0.22 && u < 0.92) return u < 0.3 ? Sp[1] : Sp[v < 0 ? 2 : 1];+ if (v < -0.6) return u < 0.5 && v < -0.8 ? C[3] : C[2];+ if (v < -0.12) return C[3];+ if (v < 0.5) return C[4];+ return v > 0.86 ? C[4] : C[5];});- // 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);+ // the tail: a forked fin swinging off the end of the wave, lit along its upper lobe+ const tb = bend(1), ta = Math.atan(amp * 1.8 * 0.9 * Math.cos(w - 4)) * 0.8, TL = 6 * s, hb = hh(1);+ const rot = (dx, dy) => [-(L + dx * Math.cos(ta) - dy * Math.sin(ta)), tb + dx * Math.sin(ta) + dy * Math.cos(ta)];+ g.poly([rot(-0.5, -hb), rot(TL, -hb - 3.4 * s), rot(TL * 0.62, 0), rot(TL, hb + 3.4 * s), rot(-0.5, hb)], (x, y) => (y < tb - 1 ? C[4] : C[3]), 0.88);+ // the dorsal fin: swept back, ribbed; a pectoral fin paddling, the gill, the eye+ const d0 = 0.34, d1 = 0.66;+ g.poly([[-d0 * L, bend(d0) - hh(d0) + 0.5], [-(d0 + 0.08) * L, bend(d0) - hh(d0) - 3.6 * s], [-d1 * L, bend(d1) - hh(d1) + 0.5]], (x) => (Math.round(x) % 2 ? C[3] : C[4]), 0.85);+ const pf = Math.sin(w * 0.5) * 1.2;+ g.set(-0.34 * L, bend(0.34) + 1.5 * s + pf * 0.3, C[4], 0.85); g.set(-0.34 * L - 1, bend(0.34) + 2 * s + pf * 0.6, C[4], 0.85);+ for (let y = -2; y <= 1; y++) g.set(-0.26 * L, bend(0.26) + y * s, C[2]);+ const ex = -0.13 * L - 1, ey = bend(0.13) - 0.25 * H;+ g.set(ex, ey, C[0]); g.set(ex + 1, ey, C[0]); g.set(ex, ey + 1, C[1]); g.set(ex + 1, ey + 1, C[0]);+ g.set(ex + 1, ey, C[6]);+ g.outline(C[0]);+}++// where a fish is: holding station in the current, swaying; one darts ahead and drifts back once a loop+function place(f, i, t) {+ const [bx, by, , , ph] = f, a = (t / D) * TAU;+ const dt = wrap(t - (i * 0.71 * D) % D, D), dart = i === 4 ? (dt < 0.25 ? ease.outCubic(dt / 0.25) : dt < 1.6 ? 1 - ease.inOutSine((dt - 0.25) / 1.35) : 0) : 0;+ return { x: bx + 3 * Math.sin(a + ph * TAU) + 8 * dart, y: by + 1.8 * Math.sin(2 * a + ph * 5), dart: i === 4 && dt < 0.6 ? 1 - dt / 0.6 : 0 };+}++// caustics: the light that comes down through rippling water, as bright crossing lines+function caustics(p, C, t) {+ const a = (t / D) * TAU;+ for (let y = -38; y < 38; y++)+ for (let x = -66; x < 66; x++) {+ const fall = clamp(1 - ((x / 64) ** 2 + (y / 40) ** 2)) * (0.6 + 0.4 * clamp(-y / 40 + 0.6));+ if (fall <= 0) continue;+ const u = x * 0.16 + 1.9 * Math.sin(y * 0.12 + a), v = y * 0.19 + 1.9 * Math.sin(x * 0.1 - a);+ const n1 = Math.sin(u) + Math.sin(v), sh = 0.75 + 0.25 * Math.sin(x * 0.05 - y * 0.04 + 2 * a);+ const f = Math.max(0, 1 - Math.abs(n1) * 5) * fall * sh;+ if (f > 0.55) p.light(x, y, C[4], 0.3);+ else if (f > 0.25) p.light(x, y, C[3], 0.14);+ }}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);+ const t = shift(time, D, o.seed), C = fit(o.palette, 7), Sp = fit(o.stripe, 3), g = GRID;+ // shafts of light slanting down through the water+ for (const [x0, w, ph] of [[-30, 10, 0], [14, 7, 2.1], [44, 12, 4]]) {+ const sw = Math.sin((t / D) * TAU + ph) * 4;+ p.glowLine(x0 + sw - 12, -40, x0 + sw + 8, 40, w, C[4], 0.05);}+ // the back row first, dimmed into the water; then the front row+ for (const back of [true, false])+ SCHOOL.forEach((f, i) => {+ if (f[3] !== back) return;+ const P = place(f, i, t);+ fish(g, C, Sp, f[2], t, f[4], P.dart);+ if (back) {+ g.recolor((x, y, c) => mix(c, C[1], 0.42));+ }+ g.draw(p, 1, P.x, P.y);+ });+ // bubbles let go from their mouths now and then+ cycle(t, D, 9, o.seed * 13 + 1, (r) => r.range(1.6, 2.6), (age, L, r, i) => {+ const f = SCHOOL[i % SCHOOL.length], P = place(f, i % SCHOOL.length, wrap(t - age, D)), rad = r.range(0.6, 1.6) * f[2];+ const ph = r.next() * TAU, x = P.x + 1 + Math.sin(age * (4 + 2 / rad) + ph) * (0.5 + rad * 0.7), y = P.y - 1 - (16 + 12 * rad) * age;+ if (y < -38) return;+ bubble(p, x, y, rad, [C[6], C[5], C[4], C[3]], Math.min(1, age * 4, (L - age) * 3, (y + 38) / 4));+ });+ caustics(p, C, t);+ p.glow(0, -8, 74, C[2], 0.2);+ p.glow(-6, -18, 40, C[3], 0.1);}diff --git a/src/fx/critters/flying-skull.js b/src/fx/critters/flying-skull.jsindex e6950b6..0e2ff5f 100644--- a/src/fx/critters/flying-skull.js+++ b/src/fx/critters/flying-skull.js@@ -1,76 +1,222 @@-import { hex, ramp, at, clamp, cycle, tileFbm, PAL, TAU } from "../../core/index.js";-import { Grid, lit, shift } from "./_lib.js";+// The fire (nested flame tongues with leaps and flicker, licks, flame puffs cooling to smoke, wandering embers,+// layered warm light) is adapted from Sprite Fusion's open-source fire+// (https://www.spritefusion.com/pixel-art-vfx/fire), MIT License, Copyright (c) 2026 Hugo Duprez.+import { fit, hex, mix, clamp, wrap, lerp, rand, rng, cycle, fly, P, PF, TAU } from "../../core/index.js";+import { Grid, Swarm, shift, lnoise, tongue, firePuff, shadow, bounce } 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,+ desc: "A cracked bone skull bobs in the air, jaw chattering, eyes burning, a fire roaring off its crown that sheds flame puffs, embers and smoke and throws warm light.",+ tags: ["critter", "skull", "undead", "fire", "flying", "monster", "loop"],+ size: [96, 132],+ origin: [48, 120],+ duration: 2.4,loop: true,fps: 30,- bg: "dark",- options: { palette: PAL.fire, seed: 1 },+ bg: "ground",+ options: {+ palette: ["#4a1712", "#8a1f17", "#c9281f", "#f2561d", "#ff8a2a", "#ffc23d", "#ffe26b", "#fff3a6", "#ffffff"],+ bone: ["#1a1114", "#3e2b2a", "#6b5144", "#9e8467", "#cdb892", "#efe2bf", "#fffaea"],+ hover: 40,+ floor: true,+ seed: 1,+ },};-const BONE = ["#2a2018", "#6e6250", "#ada186", "#e0d6bc", "#fffaf0"].map(hex);-const HOLE = hex("#140c10");+const D = meta.duration, GRID = new Grid(-14, -20, 28, 40), SOCKET = hex("#120a0c");+const SWARM = new Swarm();-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);+// where the skull is at loop time t: a slow figure-eight bob, and its velocity (for the flames to trail)+function at(t, hover) {+ const a = (t / D) * TAU;+ return {+ x: 3 * Math.sin(a),+ y: -hover + 3 * Math.sin(2 * a + 0.5),+ vx: (3 * TAU * Math.cos(a)) / D,+ vy: (6 * TAU * Math.cos(2 * a + 0.5)) / D,+ };+}+// the jaw: two bursts of chatter a loop, a wide gape at the end of the second+function jaw(t) {+ const ch = Math.max(0, Math.sin((t / D) * TAU * 22)), b1 = burst(t, 0.15, 0.75), b2 = burst(t, 1.3, 1.95);+ const gape = burst(t, 1.95, 2.3);+ return Math.round(Math.max(ch * 2.4 * Math.max(b1, b2), gape * 3.4));+}+const burst = (t, a, b) => (t <= a || t >= b ? 0 : Math.sin(Math.PI * ((t - a) / (b - a))) ** 0.5);+const flick = (t) => 0.74 + 0.16 * lnoise(t, D, 18, 0, 1) + 0.1 * lnoise(t, D, 46, 0, 2);++// the skull's shape, centered on (0, 0): a cranium, cheekbones narrowing to the upper jaw+const inCranium = (x, y) => (x / 11) ** 2 + ((y + 6) / 10.5) ** 2 <= 1;+const inFace = (x, y) => y >= -3 && y <= 6.5 && Math.abs(x) <= lerp(10.2, 7.2, (y + 3) / 9.5);+const inSkull = (x, y) => inCranium(x, y) || inFace(x, y);+const browY = (x) => -6.6 + (8.5 - Math.abs(x)) * 0.3;+const inSocket = (x, y) => ((Math.abs(x) - 5.1) / 3.3) ** 2 + ((y + 2.9) / 3.3) ** 2 <= 1 && y > browY(x);+const NOSE = [[-1, 1], [0, 1], [-2, 2], [-1, 2], [0, 2], [1, 2], [-2, 3], [1, 3]];+const CRACK = [[4, -16], [4, -15], [5, -14], [5, -13], [4, -12], [5, -11], [6, -10], [6, -9]];+const topY = (x) => -6 - 10.5 * Math.sqrt(Math.max(0, 1 - (x / 11) ** 2));++function skull(g, B, F, open, t) {+ const warm = mix(B[6], F[6], 0.45), rim = mix(B[5], F[5], 0.3);+ const lx = -4, ly = -15, lit = (x, y, k) => inSkull(lx + (x - lx) / k, ly + (y - ly) / k);+ g.clear();+ g.shade(-12, -17, 12, 8, (x, y, o) => {+ if (!inSkull(x, y)) return 0;+ let c = lit(x, y, 0.45) ? B[5] : lit(x, y, 0.74) ? B[4] : B[3];+ // temples pinch in behind the sockets+ if (Math.abs(x) > 8.2 && y > -7 && y < -1) c = x < 0 ? B[3] : B[2];+ if (!inSkull(x + 2, y + 2.2) || (x > 0 && !inSkull(x + 2.6, y))) c = B[2];+ if (!inSkull(x + 1, y + 1.2) && y > 2) c = B[1];+ // the crown catches the fire+ if (!inSkull(x, y - 1.5)) c = Math.abs(x) < 7 ? warm : rim;+ else if (!inSkull(x, y - 2.5) && Math.abs(x) < 6) c = rim;+ // under the brow, the bone drops into shadow+ if (y > browY(x) - 1.2 && y < browY(x) + 0.4 && Math.abs(x) > 1.6 && Math.abs(x) < 8.6) c = x < 0 ? B[4] : B[3];+ // cheekbones+ if (Math.abs(x) > 6.2 && Math.abs(x) < 9.2 && y > 0 && y < 2) c = x < 0 ? B[5] : B[3];+ // the upper teeth+ if (y > 6) {+ if (Math.abs(x) > 6.4) return 0;+ const cx = Math.floor(x), gap = cx === -6 || cx === -3 || cx === 2 || cx === 5;+ c = gap ? B[1] : y < 7 ? (x < 0 ? B[5] : B[4]) : cx === -1 || cx === 0 ? B[3] : B[4];+ }+ return c;});- 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: dark hollows with an ember glow catching their lower rim+ g.shade(-9, -7, 9, 1, (x, y) => {+ if (!inSocket(x, y)) return 0;+ if (!inSocket(x, y + 1.3)) return mix(B[2], F[4], 0.55);+ return SOCKET;});- // 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]);+ for (const [x, y] of NOSE) g.set(x, y, y === 3 ? B[1] : SOCKET);+ g.set(-1, 3, B[2]); g.set(0, 3, B[2]);+ for (const [x, y] of CRACK) g.set(x, y, B[1]), g.set(x - 1, y, B[5]);+ g.set(7, -7, B[1]); g.set(8, -6, B[1]);+ // the jaw hangs below: rami up the sides, a row of teeth, the chin+ const jy = 8 + open;+ g.shade(-8, 4, 8, jy + 6, (x, y) => {+ const ax = Math.abs(x);+ if (ax > 6.6 && ax < 8.1 && y > 4 && y < jy + 2) return x < 0 ? B[3] : B[2];+ if (y < jy || y > jy + 5.5) return 0;+ const v = y - jy, hw = 7.4 - v * 0.45 - (v > 4 ? (v - 4) * 1.2 : 0);+ if (ax > hw) return 0;+ if (v < 1.5) {+ if (ax > 6) return x < 0 ? B[4] : B[3];+ const cx = Math.floor(x), gap = cx === -5 || cx === -2 || cx === 1 || cx === 4;+ return gap ? B[1] : v < 1 ? B[5] : B[4];+ }+ return !inJaw(x + 1.6, y + 1.6, jy) ? B[1] : v < 2.5 ? (x < 0 ? B[4] : B[3]) : B[3];+ });+ if (open > 0) for (let y = 8; y < jy; y++) for (let x = -6; x <= 5; x++) g.set(x, y, y === jy - 1 ? mix(SOCKET, F[3], 0.5) : SOCKET);+ g.outline((x, y, nx, ny) => (ny < 0 ? mix(B[0], F[1], 0.75) : B[0]));+}+function inJaw(x, y, jy) {+ const v = y - jy, hw = 7.4 - v * 0.45 - (v > 4 ? (v - 4) * 1.2 : 0);+ return v >= 0 && v <= 5.5 && Math.abs(x) <= hw;+}++// the tongues of fire on the crown: one every 2 px, tallest in the middle, leaping now and then+function crown(seed) {+ const out = [];+ for (let x = -10; x <= 10; x += 2) out.push({ x, h: 13 + 13 * (1 - (x / 11) ** 2), w: 2.3 + rand(x + 20, seed, 3) * 0.8, n: 37 + x * 3 + seed * 11, front: false });+ // and up the temples+ for (const s of [-1, 1]) out.push({ x: s * 11, y: -5, h: 10, w: 1.8, n: 61 + s * 13 + seed * 5, front: false });+ for (let x = -5; x <= 5; x += 2.5) out.push({ x, h: 5 + 3 * rand(x * 4 + 20, seed, 5), w: 1.6, n: 91 + x * 5 + seed * 7, front: true });+ return out;+}+function height(f, t, k) {+ const leap = Math.max(0, lnoise(t, D, 6, f.n * 3.1, 70) - 0.55) * 1.6;+ return (f.h + 0.25 * f.h * lnoise(t, D, 8, f.n * 1.7, 5) + f.h * leap) * (0.9 + 0.1 * k);+}++export function draw(p, time, o) {+ const t = shift(time, D, o.seed), F = fit(o.palette, 9), heat = [...F].reverse(), B = fit(o.bone, 7);+ const S = at(t, o.hover), k = flick(t), lean = clamp(-S.vx / 60, -0.8, 0.8), stretch = clamp(S.vy / 90, -0.3, 0.45);+ const tongues = crown(o.seed).sort((a, b) => Math.abs(b.x) - Math.abs(a.x));+ const X = Math.round(S.x), Y = Math.round(S.y);+ const lick = (f) => lnoise(t, D, 5, f.n, 40) * 2 + lean * height(f, t, k) * 0.9 - clamp(f.x * 0.25, -2, 2);+ // the fire behind: tall tongues off the back of the crown+ for (let li = 0; li < 4; li++)+ for (const f of tongues) if (!f.front) tongue(p, X + f.x, Y + (f.y ?? topY(f.x) + 3), height(f, t, k) * (1 + stretch), f.w * (1 - 0.25 * Math.abs(lean)), lick(f), t, D, f.n, heat, li);+ // embers and flame puffs behind it+ particles(p, t, o, heat, F, true);+ const g = GRID;+ skull(g, B, F, jaw(t), t);+ g.draw(p, 1, X, Y);+ // the burning eyes+ for (const s of [-1, 1]) {+ const ex = X + s * 5.1 - 0.5, ey = Y - 2.4, fl = 0.75 + 0.25 * lnoise(t, D, 30, s * 9, 12);+ p.px(ex, ey, heat[0]); p.px(ex + 1, ey, heat[1]); p.px(ex, ey + 1, heat[2]); p.px(ex + 1, ey + 1, heat[3]);+ if (fl > 0.8) p.px(ex, ey - 1, heat[3]), p.px(ex + 1, ey - 1, heat[5]);+ p.glow(ex + 1, ey + 1, 6, F[5], 0.45 * fl);+ p.glow(ex + 1, ey + 0.5, 3, F[7], 0.5 * fl);+ }+ // fire in the mouth when it gapes, and a gout of flame breathed out+ const open = jaw(t);+ if (open > 0) p.glow(X, Y + 8 + open * 0.5, 4 + open * 2, F[5], 0.25 * open);+ for (let i = 0; i < 9; i++) {+ const r = rng(o.seed, i, 21), born = 1.98 + i * 0.03, age = wrap(t - born, D), L = r.range(0.25, 0.45);+ if (age >= L) continue;+ const S0 = at(born, o.hover), [x, y] = fly(S0.x + r.range(-3, 3), S0.y + 11, r.range(-22, 22), r.range(40, 75), age, -70, 3.5);+ firePuff(p, x, y, 1 - age / L, r.range(1.1, 2), r.next() * 100, heat);+ }+ // the front flames, over the crown+ for (let li = 0; li < 4; li++)+ for (const f of tongues) if (f.front) tongue(p, X + f.x, Y + topY(f.x) + 1.5, height(f, t, k) * (1 + stretch), f.w, lick(f) * 0.6, t, D, f.n, heat, li);+ particles(p, t, o, heat, F, false);+ // light: a big warm pool, a hot core over the crown, the eyes+ const br = 0.92 + 0.08 * Math.sin((t / D) * TAU * 2);+ p.glow(X + lean * 4, Y - 20, 74 * br * (0.9 + 0.1 * k), mix(F[4], F[5], 0.5), 0.48 * k);+ p.glow(X, Y - 21, 24, F[6], 0.3 * k);+ p.glow(X, Y - 15, 9, F[8], 0.16 * k);+}++// flame puffs off the tongue tips that cool into smoke, licks of flame breaking away, embers wandering up+function particles(p, t, o, heat, F, back) {+ const sw = SWARM.begin(t);+ sw.ps.sparks = [F[7], F[6], F[4], F[2]];+ if (back) {+ // smoke from the tips, born where the skull was+ cycle(t, D, 15, o.seed * 7 + 1, (r) => r.range(1.7, 2.5), (age, L, r) => {+ const S0 = at(wrap(t - age, D), o.hover), x0 = S0.x + r.range(-6, 6), y0 = S0.y - 22 - r.range(0, 8);+ const [x, y] = fly(x0, y0, r.range(-5, 5), -r.range(16, 26), age, -12, 1.2);+ sw.add(P.SMOKE, x + Math.sin(age * 1.3 + r.next() * 6) * 3 * age, y, 0, 0, age, L, mix(hex("#5b5566"), F[2], 0.3), r.range(2.8, 4.4), PF.BIG);+ });+ sw.draw(p);+ return;}- 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];+ // flame puffs: bright, fast, cooling down the ramp as they rise+ cycle(t, D, 40, o.seed * 7 + 2, (r) => r.range(0.18, 0.36), (age, L, r) => {+ const S0 = at(wrap(t - age, D), o.hover), side = r.chance(0.3), a = side ? r.sign() * r.range(0.9, 1.45) : r.range(-0.8, 0.8);+ const x0 = S0.x + Math.sin(a) * 10.5, y0 = S0.y - 6 - Math.cos(a) * 10 - (side ? 0 : r.range(2, 10));+ const [x, y] = fly(x0, y0, r.range(-6, 6) + Math.sin(a) * 6, -r.range(18, 34), age, -95, 3.2);+ firePuff(p, x + Math.sin(age * 17 + r.next() * 6) * 0.8, y, 1 - age / L, r.range(1, 2.2), r.next() * 100, heat);+ });+ // licks: little blobs of flame breaking off the tips+ cycle(t, D, 18, o.seed * 7 + 3, 0.26, (age, L, r) => {+ const S0 = at(wrap(t - age, D), o.hover), fx = r.range(-10, 10), x0 = S0.x + fx, y0 = S0.y + topY(fx) - r.range(4, 16) * (1 - Math.abs(fx) / 14);+ const kk = 1 - age / L, x = x0 + r.range(-3, 3) * age, y = y0 - r.range(12, 20) * age, rr = r.range(0.9, 1.7) * (0.4 + 0.6 * kk);+ p.circle(x, y, rr + 0.6, kk > 0.5 ? heat[5] : heat[6]);+ if (kk > 0.35) p.circle(x, y - 0.3, rr * 0.6, kk > 0.7 ? heat[2] : heat[4]);});- 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));+ // embers wander up and cool+ cycle(t, D, 24, o.seed * 7 + 4, (r) => r.range(1, 2.4), (age, L, r) => {+ const S0 = at(wrap(t - age, D), o.hover), x0 = S0.x + r.range(-11, 11), y0 = S0.y - r.range(6, 24), s = r.next() * 100;+ const [x, y] = fly(x0, y0, r.range(-22, 22), -r.range(25, 70), age, -20, 1.6);+ sw.add(P.EMBER, x + Math.sin(age * 2.3 + s) * 4 * Math.min(1, age), y, 0, 0, age, L, F[4], r.chance(0.3) ? 2 : 1, 0, s);});- p.glow(0, cy - 10, 26, F[n - 4], 0.25);- p.glow(0, cy - 6, 9, F[n - 2], 0.18);+ // sparks pop out of the fire now and then, fall, and skip along the floor+ if (o.floor)+ cycle(t, D, 5, o.seed * 7 + 5, (r) => r.range(0.9, 1.4), (age, L, r) => {+ const S0 = at(wrap(t - age, D), o.hover), b = bounce(S0.x + r.range(-6, 6), S0.y - r.range(10, 18), r.range(-28, 28), -r.range(50, 110), age, 430, -0.5, 0.42);+ sw.add(P.SPARK, b.x, b.y, b.rest ? 0.1 : b.vx, b.rest ? 0 : b.vy, age, L, 0, 1, 0, r.next() * 100);+ });+ sw.draw(p);+}++export function drawBack(p, time, o) {+ if (!o.floor) return;+ const t = shift(time, D, o.seed), F = fit(o.palette, 9), S = at(t, o.hover), k = flick(t);+ // its shadow on the floor, and the floor lit warm around it+ shadow(p, S.x, 0, 9, 1.6, hex("#0d0a12"), 0.6);+ for (let x = -30; x <= 30; x += 6) p.glow(S.x + x, -1, 20, mix(F[4], F[5], 0.5), 0.15 * k * (1 - Math.abs(x) / 40));}diff --git a/src/fx/critters/frog.js b/src/fx/critters/frog.jsindex 997e8d7..5c116ce 100644--- a/src/fx/critters/frog.js+++ b/src/fx/critters/frog.js@@ -1,101 +1,168 @@-import { seg, clamp, lerp, hex, RAMP, TAU, WHITE } from "../../core/index.js";-import { Grid, shades, lit, shift } from "./_lib.js";+import { fit, hex, mix, clamp, wrap, lerp, smooth, seg, ease, rng, P, TAU } from "../../core/index.js";+import { Grid, Swarm, shift, shadow, toss, spring } 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,+ desc: "A frog puffs its throat, blinks, crouches and leaps to snap a buzzing fly out of the air, then lands with a squash and a puff of dust, gulps and settles.",+ tags: ["critter", "frog", "animal", "hop", "ground", "loop"],+ size: [112, 88],+ origin: [56, 80],+ duration: 2.6,loop: true,fps: 30,bg: "ground",- options: { palette: ["#0e2416", "#23592b", "#47993b", "#9bd35b", "#eef6b6"], seed: 1 },+ options: {+ palette: ["#0a160c", "#173a18", "#256024", "#3a8a2e", "#62b440", "#a8e070", "#e8ffc0"],+ belly: ["#5e5a24", "#bdb45a", "#efe9a8"],+ seed: 1,+ },};-const EYE = hex("#f2c84a");+const D = meta.duration, GRID = new Grid(-22, -40, 44, 44), SWARM = new Swarm();+const T_CROUCH = 0.95, T_UP = 1.2, T_LAND = 1.62, T_SNAP = 1.4, T_BACK = 1.95, G = 1000, HOP = (G * (T_LAND - T_UP) ** 2) / 8;+const EYE = ["#3a2a08", "#c89420", "#ffd860"].map(hex), TONGUE = hex("#e8607a"), FLY = hex("#141018"), WINGS = hex("#c8d0e0"), DUST = hex("#8a7f92");-// 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"]];+// the pose at loop time t: lift off the floor, nose tilt, squash, hind legs out, throat puffed, eye shut+function pose(t) {+ let by = 0, rot = 0, sq = 0, leg = 0, throat = 0, shut = 0;+ const age = wrap(t - T_LAND, D);+ for (const [a, b] of [[0.05, 0.45], [0.5, 0.85], [1.75, 1.95]]) if (t > a && t < b) throat = Math.sin(Math.PI * ((t - a) / (b - a))) ** 0.7 * (a > 1 ? 0.6 : 1);+ if (t > 0.88 && t < 0.95) shut = 1;+ if (t >= T_CROUCH && t < T_UP) {+ const u = ease.inOutSine(seg(t, T_CROUCH, T_UP));+ sq = -0.18 * u;+ rot = -0.12 * u;+ } else if (t >= T_UP && t < T_LAND) {+ const q = (t - T_UP) / (T_LAND - T_UP);+ by = -HOP * 4 * q * (1 - q);+ rot = lerp(0.42, -0.25, q);+ sq = lerp(0.18, 0.02, Math.min(1, q * 2));+ leg = q < 0.75 ? 1 : 1 - (q - 0.75) / 0.25;+ } else {+ sq = -0.24 * spring(age, 2.4, 6.5);+ rot = -0.08 * Math.exp(-age * 6);+ }+ return { by, rot, sq, leg, throat, shut, air: t >= T_UP && t < T_LAND };+}+// the fly: buzzing a little loop over the frog, snapped up at T_SNAP, buzzing back in from the side at T_BACK+function fly(t) {+ if (t > T_SNAP && t < T_BACK) return null;+ const a = (t / D) * TAU * 3, home = [16 + 6 * Math.sin(a), -40 + 3 * Math.sin(2 * a)];+ const inn = wrap(t - T_BACK, D);+ if (inn < 0.45) {+ const u = ease.outCubic(inn / 0.45);+ return [lerp(-52, home[0], u), lerp(-46, home[1], u) + Math.sin(inn * 30) * 1.5];+ }+ return home;+}-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])) };+function frog(g, C, Bl, Pz, t) {+ g.clear();+ const cs = Math.cos(Pz.rot), sn = Math.sin(Pz.rot), sx = 1 + Pz.sq * -0.6, sy = 1 + Pz.sq;+ // into the frog's own frame: centred on its body, turned with it, squashed with it+ const local = (x, y) => {+ const dx = x, dy = y + 7;+ return [(dx * cs + dy * sn) / sx, (-dx * sn + dy * cs) / sy - 7];+ };+ const inBody = (x, y) => ((x + 1) / 10.5) ** 2 + ((y + 7) / 6) ** 2 <= 1 || ((x - 6) / 6.2) ** 2 + ((y + 8.6) / 4.8) ** 2 <= 1;+ const inEye = (x, y) => (x - 5.5) ** 2 + (y + 13.2) ** 2 <= 3.2 ** 2;+ // the body and head: lit on top, a pale belly, dark spots on the back+ const lit = (x, y, k) => inBody(-4 + (x + 4) / k, -13 + (y + 13) / k);+ g.shade(-15, -22, 15, 1, (x, y) => {+ const [u, v] = local(x, y);+ if (!inBody(u, v) && !inEye(u, v)) return 0;+ if (inEye(u, v)) {+ const d = Math.hypot(u - 5.5, v - 13.2 * -1);+ if (Pz.shut) return v < -13.2 ? C[4] : C[3];+ if (Math.abs(v + 13) < 0.7 && Math.abs(u - 6) < 1.8) return C[0];+ if (u < 4.7 && v < -14) return EYE[2];+ return d < 2.4 ? EYE[1] : EYE[0];+ }+ if (v > -5 && u > -6) return v > -3 ? Bl[1] : Bl[2];+ for (const [px, py, r] of [[-5, -10, 1.6], [0, -11.5, 1.3], [-8, -7, 1.2], [3, -12.5, 0.9]]) if (Math.hypot(u - px, v - py) < r) return C[2];+ if (!inBody(u + 2, v + 2.4)) return C[2];+ return lit(u, v, 0.5) ? C[5] : lit(u, v, 0.8) ? C[4] : C[3];+ });+ // hind leg: a thigh folded at the rump, or kicked out straight when it leaps+ const legs = [];+ if (Pz.leg < 0.5) {+ g.ellipse(-7.5, -4.5 + (1 - sy) * 3, 5, 3.6, (nx, ny) => (nx * -0.6 + ny * -0.8 > 0.35 ? C[4] : ny > 0.4 ? C[2] : C[3]));+ legs.push([[-4, -1.5], [-9, -1], [-3, -0.5], [4, -0.5]]);+ } else {+ const ex = -8 - 10 * Pz.leg, ey = 4 + 6 * Pz.leg;+ legs.push([[-6, -5], [-10, 0], [ex, ey], [ex - 5, ey + 2]]);+ }+ for (const L of legs) {+ // a tapering tube: a thick thigh, a thinner shin, a long foot; lit along its top+ g.tube(L, (u) => lerp(2, 0.7, u), (u, v) => (v > 0.55 ? C[2] : u > 0.66 ? C[3] : C[4]));+ // webbed toes spread at the end of the foot+ const [fx, fy] = L[L.length - 1], [px, py] = L[L.length - 2], dx = fx - px, dy = fy - py, l = Math.hypot(dx, dy) || 1;+ for (const k of [-1, 0, 1]) g.line(fx, fy, fx + (dx / l) * 2 - (dy / l) * k * 1.6, fy + (dy / l) * 2 + (dx / l) * k * 1.6, C[3]);}- return P.sit;+ // glint in the eye, the mouth line+ if (!Pz.shut) {+ const [gx, gy] = [4.6, -14.4], X = gx * cs - (gy + 7) * sn * 1, Y = gx * sn + (gy + 7) * cs - 7;+ g.set(X, Y, C[6]);+ }+ for (let u = 3; u <= 11; u++) {+ const v = -7.8 + (u - 3) * 0.05, X = (u * sx) * cs - ((v + 7) * sy) * sn, Y = (u * sx) * sn + ((v + 7) * sy) * cs - 7;+ g.set(X, Y, C[1]);+ }+ // the front leg props it up, or tucks in when it leaps+ const fl = Pz.air ? [[7, -4], [9, -1]] : [[7, -4], [8, -0.5]];+ g.line(fl[0][0], fl[0][1], fl[1][0], fl[1][1], C[3]);+ g.set(fl[1][0] + 1, fl[1][1], C[3]); g.set(fl[1][0] - 1, fl[1][1], C[3]);+ // the throat sac swells into a glossy bubble under the chin+ if (Pz.throat > 0.05) {+ const r = 0.8 + 2.8 * Pz.throat, cx = 7, cy = -5.2 + r * 0.25;+ g.ellipse(cx, cy, r * 1.1, r, (nx, ny) => (nx * -0.6 + ny * -0.8 > 0.55 ? Bl[2] : ny > 0.5 ? Bl[1] : mix(Bl[2], C[5], 0.4)), 0.9);+ g.set(cx - r * 0.4, cy - r * 0.45, C[6]);+ }+ g.outline(C[0]);}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]);+ const t = shift(time, D, o.seed), C = fit(o.palette, 7), Bl = fit(o.belly, 3), Pz = pose(t);+ const g = GRID;+ frog(g, C, Bl, Pz, t);+ g.draw(p, 1, 0, Math.round(Pz.by));+ // the tongue whips out to the fly and back+ const ts = (t - T_SNAP + 0.06) / 0.14;+ if (ts > 0 && ts < 1) {+ const f = fly(T_SNAP - 0.001), e = Math.sin(Math.PI * ts), mx = 11, my = Pz.by - 8;+ const x1 = lerp(mx, f[0], e), y1 = lerp(my, f[1], e);+ p.line(mx, my, x1, y1, TONGUE);+ p.line(mx, my + 1, x1, y1 + 1, mix(TONGUE, C[0], 0.4));+ p.circle(x1, y1, 1.4, TONGUE);}- 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));+ // the fly, buzzing+ const f = fly(t);+ if (f) {+ const flap = Math.sin(t * 90) > 0;+ p.px(f[0], f[1], FLY); p.px(f[0] + 1, f[1], FLY);+ p.dot(f[0], f[1] - (flap ? 1 : 0), WINGS, 0.8); p.dot(f[0] + 1, f[1] - (flap ? 0 : 1), WINGS, 0.8);+ p.glow(f[0], f[1], 3, WINGS, 0.15);+ }+ // dust thrown out along the floor as it takes off and lands, and grit bouncing+ const sw = SWARM.begin(t);+ for (const [t0, n, pow] of [[T_UP, 7, 0.6], [T_LAND, 18, 1]]) {+ const age = wrap(t - t0, D);+ for (let i = 0; i < n; i++) {+ const r = rng(o.seed, i, t0 * 100), L = r.range(0.6, 1.1) * pow;+ if (age > L) continue;+ const s = r.sign(), v = r.range(24, 70) * pow, x = s * (7 + (v / 3.5) * (1 - Math.exp(-age * 3.5))), y = -1.5 - r.range(1, 5) * age;+ sw.add(P.SMOKE, x, y, 0, 0, age, L, DUST, r.range(2.2, 4.2) * (0.65 + 0.35 * pow), 2);}+ if (pow === 1)+ for (let i = 0; i < 8; i++) {+ const r = rng(o.seed, i, 909), b = toss(r.range(-8, 8), -1, r.range(-40, 40), -r.range(30, 70), age, 700, -0.5);+ if (age < 0.7) p.dot(b.x, b.y, i % 2 ? hex("#6a6074") : hex("#9a90a4"), b.landed ? 1.4 - age * 2 : 1);+ }+ }+ sw.draw(p);+}++export function drawBack(p, time, o) {+ const t = shift(time, D, o.seed), C = fit(o.palette, 7), Pz = pose(t), hgt = clamp(-Pz.by / HOP);+ shadow(p, 0, -0.2, 13 * (1 - 0.35 * hgt), 1.6, C[0], 0.6 - 0.3 * hgt);}diff --git a/src/fx/critters/ghost.js b/src/fx/critters/ghost.jsindex 02fb5a4..d50863c 100644--- a/src/fx/critters/ghost.js+++ b/src/fx/critters/ghost.js@@ -1,68 +1,126 @@-import { cycle, fract, TAU } from "../../core/index.js";-import { Grid, shades, lit, shift } from "./_lib.js";+import { fit, clamp, wrap, lerp, rng, cycle, TAU } from "../../core/index.js";+import { Grid, shift, shadow } 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,+ desc: "A sheet ghost bobs over the floor: its scalloped hem ripples and trails its drift, little arms flutter, it glances about and blinks, motes trickle off its hem.",+ tags: ["critter", "ghost", "spirit", "undead", "spooky", "float", "loop"],+ size: [96, 100],+ origin: [48, 90],+ duration: 2.4,loop: true,fps: 30,- bg: "dark",- options: { palette: ["#1e1838", "#5a5490", "#a6a8d8", "#dfe4fa", "#ffffff"], seed: 1 },+ bg: "ground",+ options: { palette: ["#10142a", "#232c52", "#3e4f86", "#6b84bb", "#a3b8e2", "#d8e4ff", "#ffffff"], hover: 14, 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 D = meta.duration, GRID = new Grid(-20, -40, 40, 46), R = 10.5;++// where the ghost is: a lazy drift side to side and a bob, both looping+function at(t, hover) {+ const a = (t / D) * TAU;+ return { x: 4 * Math.sin(a), y: -hover - 3 * Math.sin(2 * a + 0.8) };+}++// the sheet's half-width v px above the hem (0 hem .. 1 crown): a dome over a body that flares toward the hem+function halfW(h) {+ const top = 2 * R + 9;+ if (h > top || h < -1) return -1;+ if (h > top - R) return Math.sqrt(Math.max(0, R * R - (h - (top - R)) ** 2));+ return lerp(R + 2.2, R, (h / (top - R)) ** 0.7);+}++function sheet(g, C, t, o, lagX) {+ g.clear();+ const top = 2 * R + 9, ph = (t / D) * TAU * 2, NL = 4, HW = R + 2.2, LW = (2 * HW) / NL;+ // the lower sheet trails behind the head as it drifts+ const off = (h) => lagX * (1 - clamp(h / top)) ** 1.4;+ // four rounded lobes along the hem, lifting one after another in a ripple+ const lobe = (X) => {+ const j = clamp(Math.floor((X + HW) / LW), 0, NL - 1), c = -HW + (j + 0.5) * LW, u = (X - c) / (LW / 2);+ return { j, u, d: (2.2 + 1.1 * Math.sin(ph - j * 1.5)) * Math.sqrt(Math.max(0, 1 - u * u)) };+ };+ const inside = (x, y) => {+ const h = -y, X = x - off(h);+ if (h < 0 && -h > lobe(X).d) return false;+ const hw = halfW(Math.max(0, h));+ return hw >= 0 && Math.abs(X) <= hw;+ };+ // little arms: rounded nubs that flutter+ const arm = (x, y) => {+ for (const s of [-1, 1]) {+ const ax = s * (R + 1.2) + off(13), ay = -13 + 1.6 * Math.sin(ph + s * 1.3);+ if (((x - ax) / 3) ** 2 + ((y - ay) / 2.2) ** 2 <= 1) return true;+ }+ return false;+ };+ const any = (x, y) => inside(x, y) || arm(x, y);+ const lx = -9, ly = -top - 1;+ const lit = (x, y, k) => any(lx + (x - lx) / k, ly + (y - ly) / k);+ g.shade(-19, -top - 2, 19, 5, (x, y, o2) => {+ if (!any(x, y)) return 0;+ const h = -y, X = x - off(h);+ let i = lit(x, y, 0.62) ? 5 : 4;+ if (!any(x + 2.4, y + 1.8)) i = 3;+ if (!any(x + 1.2, y + 1) && X > 2) i = 2;+ // the gloss: a thin bright arc just inside the top-left of the dome+ if (h > top - R - 2 && X < 1 && !any(x - 1.5, y - 1.5) && any(x - 0.6, y - 0.6)) i = 6;+ // the hem: each lobe darker underneath and to its right, a crease where two lobes meet+ if (h < 1) {+ const L = lobe(X);+ if (L.u > 0.1 || -h > L.d - 1.2) i = Math.min(i, 3);+ }+ // folds: short creases running down into the notches between the lobes, lit on their left+ if (h < 7 && h >= -0.5) {+ for (let j = 1; j < NL; j++) {+ const cx = -HW + j * LW + 0.6 * Math.sin(ph - j), w = (7 - h) * 0.09;+ if (Math.abs(X - cx) <= w + 0.3) i = Math.min(i, 3);+ else if (cx - X > w + 0.3 && cx - X < w + 1.3 && i === 4) i = 5;+ }}- 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];+ o2.a = h < 2 ? 0.86 : 0.95;+ return C[i];});- // 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]);+ return { inside, off, top };+}++export function draw(p, time, o) {+ const t = shift(time, D, o.seed), C = fit(o.palette, 7), S = at(t, o.hover), lagX = at(t - 0.3, o.hover).x - S.x;+ const g = GRID;+ const sh = sheet(g, C, t, o, lagX), top = sh.top;+ // the face: two eyes that glance about and blink, a little mouth that oohs+ const look = wrap(t, D) < 0.7 ? 0 : wrap(t, D) < 1.3 ? 1 : wrap(t, D) < 1.9 ? -1 : 0, blink = wrap(t, D) > 1.95 && wrap(t, D) < 2.03;+ const ey = -top + R - 1, mo = 0.5 + 0.5 * Math.sin((t / D) * TAU * 2);+ for (const s of [-1, 1]) {+ const ex = s * 4 - (s > 0 ? 1 : 0) + look;+ if (blink) g.set(ex, ey + 2, C[1]), g.set(ex + 1, ey + 2, C[1]);+ else {+ for (let k = 0; k < 4; k++) g.set(ex, ey + k, C[0]), g.set(ex + 1, ey + k, C[0]);+ g.set(ex + (look < 0 ? 0 : 1), ey, C[2]);+ }}- 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);+ const my = ey + 6;+ g.set(look - 1, my, C[1]); g.set(look, my, C[1]);+ if (mo > 0.4) g.set(look - 1, my + 1, C[0]), g.set(look, my + 1, C[0]);+ g.outline((x, y, nx, ny) => (ny > 0 ? C[2] : C[1]), 0.95);+ g.draw(p, 1, S.x, S.y);+ // motes trickle off the hem and fade as they sink and drift+ cycle(t, D, 12, o.seed * 3 + 1, (r) => r.range(1, 1.7), (age, L, r, i) => {+ const S0 = at(wrap(t - age, D), o.hover), k = age / L, x0 = S0.x + r.range(-10, 10), y0 = S0.y + 1.5;+ const x = x0 + Math.sin(age * 2.2 + i) * 2.4, y = y0 + r.range(5, 11) * age - 3 * age * age;+ const a = Math.min(1, k * 6) * Math.min(1, (1 - k) * 2.2), tw = 0.6 + 0.4 * Math.sin(age * 8 + i * 1.7);+ p.dot(x, y, tw > 0.8 ? C[6] : C[5], a);+ if (r.chance(0.3)) p.dot(x, y - 1, C[4], a * 0.7);+ p.glow(x, y, 7, C[4], 0.42 * a * tw);});- g.draw(p);- p.glow(0, hy + 4, 22, S[2], 0.16);+ // a cold glow round it+ p.glow(S.x, S.y - top * 0.55, 54, C[3], 0.3);+ p.glow(S.x - 3, S.y - top * 0.72, 14, C[5], 0.12);+}++export function drawBack(p, time, o) {+ const t = shift(time, D, o.seed), C = fit(o.palette, 7), S = at(t, o.hover), hgt = clamp((-S.y - 8) / 16);+ // its shadow on the floor, and the floor lit cold under it+ shadow(p, S.x, 0, 11 - 3 * hgt, 1.6, C[0], 0.55 - 0.2 * hgt);+ for (let x = -24; x <= 24; x += 6) p.glow(S.x + x, -1, 16, C[4], 0.14 * (1 - Math.abs(x) / 34) * (1 - 0.4 * hgt));}diff --git a/src/fx/critters/jellyfish.js b/src/fx/critters/jellyfish.jsindex 5b46399..4b4ae31 100644--- a/src/fx/critters/jellyfish.js+++ b/src/fx/critters/jellyfish.js@@ -1,72 +1,226 @@-import { ease, seg, lerp, cycle, TAU } from "../../core/index.js";-import { Grid, shades, lit, shift } from "./_lib.js";+// The bubbles are adapted from Sprite Fusion's open-source bubbles (https://www.spritefusion.com/pixel-art-vfx/bubbles),+// MIT License, Copyright (c) 2026 Hugo Duprez.+import { fit, mix, clamp, wrap, lerp, seg, ease, rng, cycle, TAU } from "../../core/index.js";+import { Grid, shift, bubble } 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,+ desc: "A see-through jellyfish pulses: its bell squeezes to shove it up and relaxes as it sinks, frilled arms and long tentacles trailing, a glow inside, bubbles drifting by.",+ tags: ["critter", "jellyfish", "sea", "underwater", "glow", "swim", "loop"],+ size: [96, 120],+ origin: [48, 38],+ duration: 3.2,loop: true,fps: 30,bg: "dark",- options: { palette: ["#1d0b2e", "#5b2276", "#a24aac", "#e88ad2", "#ffdcf6"], pulses: 2, tentacles: 6, seed: 1 },+ options: {+ palette: ["#140b2b", "#2a1650", "#4b2386", "#7a3cb8", "#b066e0", "#e09cf5", "#ffd6ff", "#ffffff"],+ glow: ["#0b3550", "#1f7fa8", "#4fd2e8", "#b8fbff"],+ 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 D = meta.duration, BEAT = D / 2, GRID = new Grid(-22, -28, 44, 36), W0 = 32, H0 = 18;++// the bell's squeeze (1 squeezed, below 0 flared out past rest) and its height through one beat+function squeeze(u) {+ if (u < 0.16) return ease.outCubic(u / 0.16);+ if (u < 0.22) return 1;+ if (u < 0.72) return lerp(1, -0.14, ease.inOutSine((u - 0.22) / 0.5));+ return lerp(-0.14, 0, ease.inOutSine((u - 0.72) / 0.28));+}+function lift(u) {+ return u < 0.42 ? -6 * ease.outCubic(seg(u, 0.04, 0.42)) : -6 + 6 * ease.inOutSine((u - 0.42) / 0.58);+}+// the bell at loop time t: rim center (x, y), width, height, squeeze+function bell(t) {+ t = wrap(t, D);+ const u = (t % BEAT) / BEAT, c = squeeze(u);+ return { x: 2 * Math.sin((t / D) * TAU), y: lift(u), c, W: W0 * (1 - 0.3 * c), H: H0 * (1 + 0.24 * c) };+}++// the bell's half-width h px above its rim: a dome whose margin pulls in as it squeezes+function halfW(h, B) {+ if (h > B.H) return -1;+ let hw = (B.W / 2) * Math.sqrt(Math.max(0, 1 - (Math.max(0, h) / B.H) ** 2));+ if (h < B.H * 0.3) hw -= B.c * 2.4 * (1 - h / (B.H * 0.3));+ return hw;+}+// the margin hangs in little scallops+const scallop = (dx, B) => 1.1 * Math.max(0, Math.sin((dx / (B.W / 2)) * Math.PI * 4 + Math.PI / 2));++function drawBell(p, C, G, B, t) {+ const g = GRID.clear(), bx = Math.round(B.x), by = Math.round(B.y);+ const inside = (x, y) => {+ const dx = x - B.x, h = B.y - y;+ if (h < -scallop(dx, B)) return false;+ const hw = halfW(Math.max(0, h), B);+ return hw >= 0 && Math.abs(dx) <= hw;+ };+ g.shade(-20, -26, 20, 3, (x, y, o) => {+ const X = x + bx, Y = y + by;+ if (!inside(X, Y)) return 0;+ o.t = 1;+ return C[3];+ });+ g.depths(4);+ // the subumbrella: the hollow under the bell, seen through it as a fainter inner dome+ const iw = B.W * 0.36, ih = B.H * 0.66, lx = B.x - B.W * 0.22, ly = B.y - B.H * 0.78;+ g.recolor((x, y, c, a, tag) => {+ if (tag !== 1) return c;+ const X = x + bx + 0.5, Y = y + by + 0.5, d = g.depth(x, y), dx = X - B.x, h = B.y - Y, v = h / B.H;+ const i = g.idx(x, y);+ let col = C[3], al = 0.26 + 0.2 * clamp(v);+ const ie = (dx / iw) ** 2 + (Math.max(0, h) / ih) ** 2;+ if (ie > 0.8 && ie < 1.12 && h > 0.5) (col = C[4]), (al = 0.55);+ if (h < 1) (col = C[5]), (al = 0.85);+ if (d === 2) (col = v > 0.5 && dx < 0 ? C[5] : C[4]), (al = 0.75);+ if (d === 1) (col = dx < 0 && v > 0.25 ? C[6] : C[5]), (al = 0.92);+ // the gloss on the top-left of the dome+ const gx = X - lx, gy = Y - ly;+ if (d === 2 && dx < -1 && v > 0.45 && gx * gx + gy * gy < 26) (col = C[7]), (al = 1);+ g.a[i] = al;+ return col;+ });+ // radial canals running down from the crown+ for (const s of [-0.62, 0.62]) {+ for (let h = 2; h < B.H - 2; h++) {+ const hw = halfW(h, B), x = B.x + s * hw * 0.9, y = B.y - h;+ if (g.depth(x - bx, y - by) >= 3) g.set(x - bx, y - by, C[4], 0.5);+ }+ }+ // the stomach and gonads: a soft glowing mass hung in the bell, brighter as it squeezes+ const pulse = 0.5 + 0.5 * B.c, cy = B.y - B.H * 0.42, rx = B.W * 0.2, ry = B.H * 0.2;+ for (let y = Math.floor(cy - ry); y <= cy + ry; y++)+ for (let x = Math.floor(B.x - rx); x <= B.x + rx; x++) {+ const d = ((x + 0.5 - B.x) / rx) ** 2 + ((y + 0.5 - cy) / ry) ** 2;+ if (d > 1 || g.depth(x - bx, y - by) < 2) continue;+ g.set(x - bx, y - by, d < 0.3 ? C[6] : d < 0.65 ? C[5] : C[4], d < 0.3 ? 0.9 : 0.6);}+ g.outline((x, y, nx, ny) => (ny > 0 ? 0 : C[1]), 0.9);+ g.draw(p, 1, bx, by);+ // the light inside, and the little lamps round the margin+ p.glow(B.x, B.y - B.H * 0.45, 30 + 6 * B.c, C[4], 0.22 + 0.12 * pulse);+ p.glow(B.x, B.y - B.H * 0.45, 11, C[6], 0.14 + 0.16 * pulse);+ for (const s of [-1, 1])+ for (const q of [0.14, 0.42, 0.78]) {+ const x = B.x + s * halfW(0.5, B) * q, y = B.y + 1, tw = 0.6 + 0.4 * Math.sin((t / D) * TAU * 3 + q * 9 + s);+ p.px(x, y, tw > 0.85 ? G[3] : G[2]);+ p.glow(x, y, 4, G[2], 0.4 * tw);+ }+}++// a strand hanging from the bell: each point follows where its root was a moment ago, so the strand trails+// behind every thrust and billows as the bell sinks; a slow wave runs down it+function strand(t, off, len, step, lag, sway, ph, pull) {+ const pts = [], B1 = bell(t), o1 = off(B1);+ for (let s = 0; s <= len; s += step) {+ const B = bell(t - s * lag), relax = 1 - clamp(B.c), ox = lerp(o1[0], off(B)[0], 0.4);+ const w = (0.3 + s * sway) * (0.55 + 0.65 * relax) * Math.sin((t / D) * TAU * 2 - s * 0.11 + ph);+ pts.push([B.x + ox + w + ox * s * (0.009 * relax - 0.005 * pull * B.c), B.y + o1[1] + s * (0.88 + 0.05 * B.c)]);+ }+ return pts;+}++function drawTentacle(p, C, G, pts, back, t, i) {+ const n = pts.length;+ for (let k = 1; k < n; k++) {+ const u = k / (n - 1), [x0, y0] = pts[k - 1], [x1, y1] = pts[k];+ const c = back ? (u < 0.3 ? C[3] : u < 0.7 ? C[2] : C[1]) : u < 0.2 ? C[5] : u < 0.45 ? C[4] : u < 0.78 ? C[3] : C[2];+ p.line(x0, y0, x1, y1, c);}- 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]));+ // stinging cells glinting along it+ if (back) return;+ for (let k = 3; k < n; k += 4) {+ const tw = Math.sin((t / D) * TAU * 2 - k * 0.5 + i * 1.7);+ if (tw < 0.3) continue;+ const [x, y] = pts[k];+ p.px(x, y, tw > 0.8 ? G[3] : G[2]);+ p.glow(x, y, 3.5, G[2], 0.35 * tw);}- // 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];+}++// a frilled oral arm: a ribbon lit down its left edge, darker on its right, ruffled along both sides+const ARMS = new Grid(-40, -40, 80, 100);+function drawArms(p, C, list, back) {+ const g = ARMS.clear(), a = back ? 0.6 : 0.88;+ for (const arm of list) {+ if (arm.back !== back) continue;+ const pts = arm.pts, n = pts.length;+ let lastRow = -1e9;+ for (let k = 1; k < n; k++) {+ const [x0, y0] = pts[k - 1], [x1, y1] = pts[k], m = Math.max(1, Math.ceil(Math.abs(y1 - y0) * 2));+ for (let j = 0; j < m; j++) {+ const q = j / m, x = lerp(x0, x1, q), y = lerp(y0, y1, q), u = (k - 1 + q) / (n - 1), wd = lerp(2.2, 0.6, u);+ for (let i = -Math.ceil(wd); i <= Math.ceil(wd); i++) {+ if (Math.abs(i) > wd + 0.2) continue;+ g.set(x + i, y, i < 0 ? C[back ? 4 : 6] : i > 0 ? C[back ? 2 : 4] : C[back ? 3 : 5], a);+ }+ const row = Math.floor(y);+ if (row !== lastRow && row % 3 === 0 && u < 0.85) g.set(x + ((row / 3) % 2 ? -wd - 1.2 : wd + 1.2), y, C[back ? 4 : 6], a);+ lastRow = row;+ }}- 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));+}++export function draw(p, time, o) {+ const t = shift(time, D, o.seed), C = fit(o.palette, 8), G = fit(o.glow, 4), B = bell(t);+ // specks drifting in the water+ cycle(t, D, 16, o.seed * 5 + 1, D, (age, L, r) => {+ const x = r.range(-42, 42) + Math.sin(age * 0.8 + r.next() * 6) * 3, y = r.range(-34, 66) + age * r.range(1, 4);+ const tw = Math.sin(age * 2.2 + r.next() * 6), a = Math.min(1, age * 2, (L - age) * 2) * (0.35 + 0.35 * tw);+ p.dot(x, y, tw > 0.8 ? G[2] : C[3], a);+ });+ const tents = [], arms = [];+ for (let i = 0; i < 9; i++) {+ const r = rng(o.seed, i, 4), q = -0.88 + (1.76 * i) / 8 + r.range(-0.05, 0.05), back = i % 2 === 1;+ tents.push({ back, i, pts: strand(t, (b) => [q * halfW(0.5, b), 0.5], r.range(36, 50), 1.5, 0.022, 0.065, r.range(0, TAU), 1) });+ }+ for (let i = 0; i < 4; i++) {+ const r = rng(o.seed, i, 9), q = [-0.32, -0.1, 0.12, 0.3][i], back = i === 1 || i === 2;+ arms.push({ back, pts: strand(t, (b) => [q * b.W * 0.5, -1], r.range(20, 27), 1, 0.03, 0.06, r.range(0, TAU) + i, 0.4) });+ }+ // each squeeze shoves a ring of water out under the bell: a soft swirl of light that swells and thins+ for (let b = 0; b < 2; b++) {+ const age = wrap(t - b * BEAT - 0.05, D);+ if (age > 0.9) continue;+ const B0 = bell(b * BEAT + 0.05), e = ease.outCubic(age / 0.9), k = 1 - age / 0.9;+ const cx = B0.x, cy = B0.y + 3 + 14 * e, rx = B0.W * 0.32 + 9 * e, ry = 1.5 + 2.5 * e;+ for (let j = 0; j < 8; j++) {+ const a = (j / 8) * TAU + e * 0.8;+ p.glow(cx + Math.cos(a) * rx, cy + Math.sin(a) * ry, 5 + 3 * e, C[5], 0.14 * k);+ }+ // plankton caught in the swirl, glinting as it spins+ for (let j = 0; j < 7; j++) {+ const a = (j / 7) * TAU + e * 2.4 + b, x = cx + Math.cos(a) * rx * 1.05, y = cy + Math.sin(a) * ry * 1.4 - Math.cos(a * 2) * 0.6;+ if (k < 0.15 && j % 2) continue;+ p.dot(x, y, Math.sin(a) > 0 ? G[3] : G[2], Math.min(1, k * 2.5));+ p.glow(x, y, 3, G[2], 0.3 * k);+ }+ // and a few bubbles squeezed out of the margin+ for (let i = 0; i < 4; i++) {+ const r = rng(o.seed, b, i, 13), L = r.range(1.4, 2.2), ag = wrap(t - b * BEAT - 0.08 - i * 0.04, D);+ if (ag > L) continue;+ const rad = r.range(0.6, 1.5), sx = r.sign(), x = B0.x + sx * (B0.W * 0.4 + r.range(0, 4) + ag * r.range(4, 10)), y = B0.y + 2 - (14 + 10 * rad) * ag + 6 * Math.exp(-ag * 4);+ if (y < -33) continue;+ bubble(p, x + Math.sin(ag * 5 + i) * 0.8, y, rad, [G[3], G[3], G[2], G[1]], Math.min(1, ag * 6, (L - ag) * 3, (y + 33) / 6));+ }+ }+ for (const a of tents) if (a.back) drawTentacle(p, C, G, a.pts, true, t, a.i);+ drawArms(p, C, arms, true);+ drawBell(p, C, G, B, t);+ drawArms(p, C, arms, false);+ for (const a of tents) if (!a.back) drawTentacle(p, C, G, a.pts, false, t, a.i);+ // bubbles wobbling up past it+ cycle(t, D, 7, o.seed * 5 + 2, (r) => r.range(1.8, 3), (age, L, r) => {+ const rad = r.chance(0.6) ? r.range(0.6, 1.4) : r.range(1.6, 2.6), x0 = r.range(-30, 30), y0 = r.range(10, 70), v = 20 + 13 * rad;+ const end = Math.min(L, (y0 + 30) / v);+ if (age > end) return;+ const ph = r.next() * TAU, x = x0 + Math.sin(age * (4 + 2 / rad) + ph) * (0.6 + rad * 0.8), y = y0 - v * age;+ bubble(p, x, y, rad, [G[3], G[3], G[2], G[1]], Math.min(1, age * 3, (end - age) * 3), 0.1 * Math.sin(age * 9 + ph));});+ // a soft cool glow all round+ p.glow(B.x, B.y + 6, 58, C[3], 0.14);}diff --git a/src/fx/critters/slime.js b/src/fx/critters/slime.jsindex 468f32b..a1a6d37 100644--- a/src/fx/critters/slime.js+++ b/src/fx/critters/slime.js@@ -1,73 +1,275 @@-import { RAMP, seg, clamp, hex, WHITE } from "../../core/index.js";-import { Grid, shades, lit, keys, shift } from "./_lib.js";+// The puddle (a domed wet surface with glints sliding along it, bubbles that swell and pop) is adapted from+// Sprite Fusion's open-source poison puddle (https://www.spritefusion.com/pixel-art-vfx/poison),+// MIT License, Copyright (c) 2026 Hugo Duprez.+import { fit, clamp, wrap, smooth, seg, ease, lerp, rng, cycle, sparkle, TAU } from "../../core/index.js";+import { Grid, shift, curve, spring, toss, lnoise } 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,+ desc: "A glossy slime hops in place: it squashes to wind up, stretches into the jump, rounds out in the air, splats down flinging droplets that creep back, then wobbles and blinks.",+ tags: ["critter", "slime", "monster", "hop", "goo", "loop"],+ size: [112, 88],+ origin: [56, 72],+ duration: 1.8,loop: true,fps: 30,bg: "ground",- options: { palette: ["#123a2c", "#1f6b3c", "#3aa64a", "#8edc5a", "#effcc4"], height: 14, seed: 1 },+ options: { palette: ["#061412", "#0b2f2b", "#12594a", "#1f8f4f", "#47c752", "#a6f06a", "#f0ffd2"], hop: 24, seed: 1 },};-const SHADOW = hex("#141019");+const GRID = new Grid(-30, -64, 60, 66);+const D = meta.duration, T_SQ = 0.5, T_UP = 0.84, T_LIFT = 0.9, T_LAND = 1.44, SNAP = 0.965;+const W0 = 30, H0 = 22, VC = 0.4, G = 640, NDROP = 12;-// 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;+// the body's shape and squash at loop time t: s > 0 stretched tall, s < 0 squashed flat+function pose(t, hop) {+ const age = wrap(t - T_LAND, D);+ let s, by = 0, lean = 0, round = 0.1, q = -1;+ if (t >= T_LIFT && t < T_LAND) {+ q = (t - T_LIFT) / (T_LAND - T_LIFT);+ by = -hop * 4 * q * (1 - q);+ s = curve(q, [[0, 0.36], [0.4, 0.02], [0.55, -0.05], [0.85, 0.08], [1, 0.16]]);+ round = 0.1 + 0.8 * smooth(0, 0.16, q) * (1 - smooth(0.86, 1, q));+ } else if (t >= T_UP && t < T_LIFT) s = lerp(-0.3, 0.36, ease.outCubic(seg(t, T_UP, T_LIFT)));+ else if (t >= T_SQ && t < T_UP) {+ const u = seg(t, T_SQ, T_UP);+ s = -0.3 * ease.inOutSine(u) + 0.018 * Math.sin(t * TAU * 16) * smooth(0.55, 1, u);+ } else {+ // the splat holds for a beat, then rings out into a wobble; the top sways a little as it settles+ s = age < 0.06 ? -0.46 : -0.46 * spring(age - 0.06, 2.1, 4.6);+ lean = 0.07 * Math.exp(-age * 4) * Math.sin(age * TAU * 1.9);+ if (t < T_SQ) s += 0.02 * Math.sin((t / T_SQ) * TAU);+ }+ return { s, by, lean, round, q, age, W: W0 / Math.sqrt(1 + s), H: H0 * (1 + s) };+}-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];+// half the body's width at height v (0 base .. 1 top): a dome over a soft foot with rounded corners+function halfW(v, P) {+ if (v < 0 || v > 1) return -1;+ const { W, H, round } = P;+ if (v >= VC) {+ const q = (v - VC) / (1 - VC);+ return (W / 2) * Math.sqrt(1 - q * q);+ }+ const q = (VC - v) / VC, hb = v * H, rc = 3;+ let hw = (W / 2) * Math.sqrt(Math.max(0, 1 - round * q * q));+ if (hb < rc) hw -= rc - Math.sqrt(rc * rc - (rc - hb) ** 2);+ return hw;+}+const inside = (P, x, y) => {+ const v = (P.by - 1 - y) / P.H, hw = halfW(v, P);+ return hw >= 0 && Math.abs(x - P.lean * v * P.H) <= hw;+};++// shaded the way a pixel artist shades jelly: a dark dome over light pooling low inside the body, a shadow+// crescent (the rim the body leaves bare when nudged toward the light), a glossy streak hugging the top-left+// contour with a hot spot under it, light bounced up off the floor caught just inside the lower rim+function body(g, C, P) {+ const yb = P.by - 1, half = P.W / 2 + 3;+ const cx = P.lean * 0.45 * P.H, cy = yb - P.H * 0.5, lx = cx - P.W * 0.24, ly = cy - P.H * 0.36;+ const lit = (x, y, k) => inside(P, lx + (x - lx) / k, ly + (y - ly) / k);+ g.clear();+ g.shade(-half, yb - P.H - 1, half, yb, (x, y, o) => {+ if (!inside(P, x, y)) return 0;+ o.t = 1;+ o.a = 0.92;+ let i = lit(x, y, 0.42) ? 5 : lit(x, y, 0.7) ? 4 : 3;+ // light pooled in the jelly along the bottom, brightest just inside the rim+ const v = (yb - y) / P.H;+ if (v < 0.3 && inside(P, x, y + 1.4)) i = !inside(P, x, y + 2.4) ? 5 : v < 0.2 ? 4 : i;+ if (!inside(P, x + 2, y + 2.4)) (i = 2), (o.a = 1);+ const ang = Math.atan2(y - cy, (x - cx) * (P.H / P.W));+ if (!inside(P, x - 1.6, y - 1.6) && inside(P, x - 0.7, y - 0.7) && ang > -2.75 && ang < -1.55) (i = ang > -2.45 && ang < -1.8 ? 6 : 5), (o.a = 1);+ if (i === 2 && inside(P, x + 1, y + 1.2) && !inside(P, x + 2, y + 2.4) && ang > 0.3 && ang < 1.5) i = 4;+ return C[i];});- // 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)));+ // the hot spot: a tiny bright window reflection under the streak+ const hx = Math.round(cx - P.W * 0.27), hy = Math.round(cy - P.H * 0.14);+ if (inside(P, hx - 1, hy) && inside(P, hx + 1, hy + 1)) g.set(hx, hy, C[6]), g.set(hx, hy + 1, C[5]);+}++// the eyes ride the squash: squint while winding up, wide in the air, screwed shut on the splat, a blink at rest+function face(g, C, P, t) {+ const yb = P.by - 1, ev = 0.47, ey = Math.round(yb - P.H * ev), ex = Math.max(3, Math.round(P.W * 0.16)), xc = Math.round(P.lean * ev * P.H);+ const air = P.q >= 0, shut = P.age < 0.16 && !air, blink = t > 0.22 && t < 0.29;+ const wind = t >= T_SQ && t < T_LIFT ? seg(t, T_SQ, T_UP) : 0, look = air ? (P.q < 0.45 ? -1 : P.q > 0.7 ? 1 : 0) : 0;+ const eh = clamp(Math.round(4 * (1 + P.s * 0.8) - wind * 2 + (air && P.q < 0.6 ? 1 : 0)), 1, 5);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);+ const x = xc + side * ex - (side > 0 ? 1 : 0);+ if (shut) {+ const a = side < 0 ? 0 : 1, b = 1 - a;+ g.set(x + a, ey - 1, C[0]); g.set(x + b, ey, C[0]); g.set(x + a, ey + 1, C[0]);+ continue;+ }if (blink) {- g.set(ex, ey + 1, S[0]), g.set(ex + 1, ey + 1, S[0]);+ g.set(x, ey + 1, C[0]); g.set(x + 1, ey + 1, C[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);+ const top = ey + 2 - eh + look;+ for (let k = 0; k < eh; k++) g.set(x, top + k, C[0]), g.set(x + 1, top + k, C[0]);+ g.set(x + (look > 0 ? 1 : 0), top + (look > 0 ? 1 : 0), C[6]);+ if (eh >= 4) g.set(x + 1, top + eh - 1, C[2]);}- g.outline(S[0]);+ const my = Math.round(yb - P.H * 0.31);+ if (air && P.q < 0.75) g.set(xc, my, C[0]), g.set(xc - 1, my, C[0]), g.set(xc, my + 1, C[1]), g.set(xc - 1, my + 1, C[1]);+ else if (!shut) g.set(xc, my, C[1]), g.set(xc - 1, my, C[1]);+}++// a bubble works its way up through the jelly while it rests and pops at the top+const POP = 0.4;+function bubbleIn(g, C, P, t) {+ if (t > POP) return;+ const v = lerp(0.18, 0.86, ease.inQuad(t / POP)), hw = halfW(v, P), x = P.lean * v * P.H - hw * lerp(0.35, 0.05, t / POP), y = P.by - 1 - v * P.H;+ g.set(x, y, C[6]); g.set(x + 1, y, C[5]); g.set(x, y + 1, C[5]); g.set(x + 1, y + 1, C[4]);+}++// droplets flung off the splat: they arc, land with a little splat, and creep back to the body to rejoin it+function droplet(i, o, age) {+ const r = rng(o.seed, i, 7), a = -Math.PI / 2 + r.range(-1.2, 1.2), sp = r.range(60, 118), size = r.chance(0.35) ? 1 : r.chance(0.7) ? 2 : 3;+ const fa = a + Math.PI / 2, x0 = Math.sin(fa) * 21, y0 = -1 - Math.cos(fa) * 12.5;+ const f = toss(x0, y0, Math.cos(a) * sp * 0.75, Math.sin(a) * sp, age, G, -1);+ f.size = size;+ if (f.landed) {+ const home = Math.sign(f.lx || 1) * (W0 / 2 - 2), dur = Math.min(0.55, 0.22 + Math.abs(f.lx - home) / 60), u = seg(age - f.at - 0.14, 0, dur);+ f.x = lerp(f.lx, home, ease.inOutSine(u));+ f.k = 1 - u;+ f.gone = u >= 1;+ f.splat = clamp(1 - (age - f.at) / 0.14);+ }+ return f;+}++// the wet patch it sits in: wider while squashed, splashed out on landing, left behind while it jumps+function puddleR(t, P) {+ if (P.q >= 0) return (W0 / Math.sqrt(1.36) / 2 + 3) * (1 - 0.22 * P.q);+ return P.W / 2 + 3 + 9 * Math.exp(-P.age * 5) * (1 - Math.exp(-P.age * 40)) * (t >= T_LAND || t < T_SQ ? 1 : 0);+}++export function draw(p, time, o) {+ const t = shift(time, D, o.seed), C = fit(o.palette, 7), P = pose(t, o.hop), yb = P.by - 1, age = P.age;+ const g = GRID;+ body(g, C, P);+ face(g, C, P, t);+ bubbleIn(g, C, P, t);+ g.outline((x, y, nx, ny) => (ny < 0 && nx <= 0 && y < yb - P.H * 0.5 ? C[1] : C[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));- }++ // the bubble pops out of the top: a ring and two flecks+ if (t >= POP && t < POP + 0.16) {+ const k = (t - POP) / 0.16, x = P.lean * P.H - halfW(0.86, P) * 0.05, y = yb - P.H - 0.5;+ for (let a = 0; a < TAU; a += 0.6) p.dot(x + Math.cos(a) * (1 + k * 3), y + Math.sin(a) * (1 + k * 3) * 0.7, C[6], 1.2 - k);+ for (const s of [-1, 1]) p.dot(x + s * (1 + k * 4), y - 1 - k * 6 + k * k * 4, C[5], 1.3 - k);+ p.glow(x, y, 6, C[5], 0.4 * (1 - k));+ }+ // droplets in flight+ for (let i = 0; i < NDROP; i++) {+ const f = droplet(i, o, age);+ if (f.landed || inside(P, f.x, f.y)) continue;+ const sv = Math.hypot(f.vx, f.vy) || 1, ux = f.vx / sv, uy = f.vy / sv, L = Math.min(2.5, sv / 50);+ p.line(f.x - ux * L, f.y - uy * L, f.x, f.y, C[3]);+ if (f.size >= 2) p.px(f.x - 1, f.y, C[4]), p.px(f.x - 1, f.y + 1, C[3]), p.px(f.x, f.y + 1, C[2]);+ if (f.size >= 3) p.px(f.x + 1, f.y, C[3]), p.px(f.x - 1, f.y - 1, C[4]), p.px(f.x, f.y - 1, C[5]);+ p.px(f.x, f.y, f.size >= 2 ? C[6] : C[5]);+ p.glow(f.x, f.y, 5 + f.size, C[4], 0.32);+ }+ // spores drifting up out of the puddle, glowing+ cycle(t, D, 7, o.seed * 13 + 1, (r) => r.range(1.2, 1.8), (ag, L, r, i) => {+ const k = ag / L, x = r.range(-24, 24) + Math.sin(ag * 2.1 + i * 1.7) * 3, y = -2 - r.range(9, 17) * ag - 5 * ag * ag;+ const a = Math.min(1, k * 4) * Math.min(1, (1 - k) * 2.5), tw = 0.6 + 0.4 * Math.sin(ag * 7 + i * 2.3), big = r.chance(0.35);+ p.dot(x, y, tw > 0.8 ? C[6] : C[5], a);+ if (big) p.dot(x + 1, y, C[5], a), p.dot(x, y + 1, C[4], a), p.dot(x + 1, y + 1, C[4], a * 0.6);+ p.glow(x, y, big ? 9 : 6, C[5], (big ? 0.45 : 0.32) * a * tw);+ });+ // drips let go of its underside while it's in the air and plop into the puddle+ for (const [t0, dx] of DRIPS) {+ const a2 = wrap(t - t0, D);+ if (a2 > 0.6) continue;+ const P0 = pose(t0, o.hop), f = toss(dx, P0.by - 0.5, 0, 12, a2, G, -1);+ if (!f.landed) p.px(dx, f.y, C[5]), p.px(dx, f.y - 1, C[4]), p.glow(dx, f.y, 4, C[4], 0.3);+ else if (a2 - f.at < 0.14) {+ const k = (a2 - f.at) / 0.14;+ for (const s2 of [-1, 1]) p.dot(dx + s2 * (1 + k * 3), -2 - k * 3 + k * k * 3, C[5], 1.2 - k);+ }+ }+ // a glint on the dome at the top of the hop+ if (P.q > 0.4 && P.q < 0.64) {+ const k = Math.sin(Math.PI * seg(P.q, 0.4, 0.64));+ sparkle(p, P.lean * 0.8 * P.H - P.W * 0.21, yb - P.H * 0.8, 1 + 2.5 * k, C[6], C[5], 0.5 * k);+ }+ // light: the slime glows through and tints the air round it, the puddle lights the floor, a flash on the splat+ const cx = P.lean * P.H * 0.4, cy = yb - P.H * 0.45, near = clamp(1 + P.by / (o.hop * 1.1));+ const R = puddleR(t, P), br = 0.9 + 0.1 * Math.sin((t / D) * TAU * 2);+ p.glow(cx * 0.5, -14, 64, C[3], 0.3 * br);+ p.glow(cx, cy, 30 + P.W * 0.3, C[4], 0.2);+ p.glow(cx, cy + 3, 14, C[5], 0.16);+ p.glow(0, -2, R * 1.3 + 6, C[4], 0.12 + 0.08 * near);+ if (t >= T_LAND || t < T_SQ) p.glow(0, -3, 40, C[5], 0.42 * Math.exp(-age * 9));+}++const DRIPS = [[1.02, -4], [1.18, 3]];++export function drawBack(p, time, o) {+ const t = shift(time, D, o.seed), C = fit(o.palette, 7), P = pose(t, o.hop), age = P.age;+ // the puddle: a low dome of goo, lit along its top with glints sliding over it, darker where it meets the floor+ const R = puddleR(t, P), hp = Math.min(2.4, 0.9 + R * 0.06);+ for (let x = Math.floor(-R); x <= Math.ceil(R); x++) {+ const d = Math.abs(x + 0.5) / R;+ if (d > 1) continue;+ const top = -1 - Math.round(Math.sqrt(1 - d * d) * hp);+ for (let y = top; y <= 0; y++) {+ let c = y === top ? C[5] : y === 0 ? C[2] : C[4];+ if (d > 0.88) c = y === top ? C[4] : C[3];+ if (y === top && d < 0.88) {+ const n = lnoise(t, D, 7, x * 0.18, 3) + lnoise(t, D, 4, x * 0.07, 4) * 0.6;+ if (n > 0.55) c = C[6];+ } else if (y === top + 1 && d < 0.8 && lnoise(t, D, 3, x * 0.12, 5) > 0.3) c = C[5];+ p.px(x, y, c);+ }+ if (d > 0.96) p.px(x, top - 1, C[1]);+ }+ // bubbles swell out of the puddle and pop, flicking flecks+ cycle(t, D, 4, o.seed * 17 + 3, (r) => r.range(0.45, 0.75), (ag, L, r) => {+ const x = r.range(-0.85, 0.85) * R, k = ag / L, rb = r.range(1.4, 2.6) * (0.3 + 0.7 * ease.outCubic(Math.min(1, k * 1.25)));+ if (Math.abs(x) < P.W / 2 + 1 && P.q < 0) return;+ const sy = -1 - Math.round(Math.sqrt(Math.max(0, 1 - (x / R) ** 2)) * hp);+ if (k < 0.85) {+ for (let y = Math.floor(sy - rb); y <= sy; y++)+ for (let xx = Math.floor(x - rb - 1); xx <= Math.ceil(x + rb + 1); xx++) {+ const dx = xx + 0.5 - x, dy = y + 0.5 - sy, dd = Math.hypot(dx, dy);+ if (dd > rb + 0.5) continue;+ if (dd > rb - 0.7) p.px(xx, y, dx < 0 && dy < -rb * 0.3 ? C[6] : C[4]);+ else p.blend(xx, y, C[5], 0.3);+ }+ p.glow(x, sy - rb * 0.5, rb * 2 + 3, C[5], 0.2);+ } else {+ const q = (k - 0.85) / 0.15;+ for (const [dx, dy] of [[1, 0], [-1, 0], [0.6, -0.7], [-0.6, -0.7], [0, -1]]) p.dot(x + dx * (2 + 3 * q), sy + dy * (2 + 3 * q), C[6], 1.2 - q);+ }+ });+ // landed droplets: a flattened splat, then a bead of goo creeping home, a wet trail behind it+ for (let i = 0; i < NDROP; i++) {+ const f = droplet(i, o, age);+ if (!f.landed || f.gone) continue;+ const x = Math.round(f.x), w = f.size + (f.splat > 0 ? 1 : 0);+ for (let j = 0; j < w; j++) p.px(x - (w >> 1) + j, -1, j === 0 ? C[5] : C[4]);+ if (f.size >= 2 && f.splat <= 0) p.px(x, -2, C[5]), p.px(x - 1, -2, C[4]);+ p.px(x, 0, C[3]);+ const dir = Math.sign(f.lx - f.x);+ for (let j = 1; j < Math.min(8, Math.abs(f.lx - f.x)); j++) p.dot(x + dir * j, 0, C[2], 0.7 - j * 0.08);+ p.glow(x, -1, 5, C[4], 0.25 * f.k + 0.1);+ }+ // the goo string it pulls off the floor as it leaves; when it snaps, a drip falls back and the rest pulls up+ if (t >= T_LIFT && t < SNAP) {+ const bot = P.by - 1, u = (t - T_LIFT) / (SNAP - T_LIFT);+ for (let y = Math.floor(bot); y < 0; y++) {+ const m = Math.sin(((y - bot) / -bot) * Math.PI);+ p.px(-1, y, C[4]);+ if (m * u < 0.45) p.px(0, y, C[3]);+ }+ } else if (t >= SNAP && t < SNAP + 0.3) {+ const a2 = t - SNAP, ys = pose(SNAP, o.hop).by - 1, f = toss(-1, ys * 0.45, 0, 0, a2, G * 1.3, -2);+ if (!f.landed) p.px(-1, f.y, C[5]), p.px(-1, f.y - 1, C[3]);+ const nub = 3 * (1 - a2 / 0.12);+ for (let j = 0; j < nub; j++) p.px(-1, P.by + j, j === 0 ? C[3] : C[4]);}}diff --git a/src/fx/critters/snake.js b/src/fx/critters/snake.jsindex 5d4ae22..d9fc950 100644--- a/src/fx/critters/snake.js+++ b/src/fx/critters/snake.js@@ -1,81 +1,110 @@-import { hex, smooth, seg, fract, TAU, WHITE } from "../../core/index.js";-import { Grid, shades, shift } from "./_lib.js";+import { fit, hex, mix, clamp, wrap, lerp, smooth, cycle, P, TAU } from "../../core/index.js";+import { Grid, Swarm, shift, shadow } 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,+ desc: "A snake slithers along the floor, head raised: humps rise and roll back down its patterned body to the tail, dust puffs where it touches down, its forked tongue flicks.",+ tags: ["critter", "snake", "reptile", "ground", "loop"],+ size: [136, 56],+ origin: [68, 48],+ duration: 2.4,loop: true,fps: 30,bg: "ground",- options: { palette: ["#0f2414", "#245c24", "#46a032", "#94d24c", "#e8f2a4"], tongue: "#e8344c", seed: 1 },+ options: {+ palette: ["#081410", "#123a1e", "#1d5e2a", "#2f8a36", "#5cb848", "#a8e070", "#e8ffc0"],+ belly: ["#4a3a14", "#b08a34", "#f0d878"],+ 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]);+const D = meta.duration, HEAD = 30, LEN = 70, GRID = new Grid(-44, -24, 88, 26), SWARM = new Swarm();+const TONGUE = hex("#e8304a"), DUST = hex("#8a7f92");+const K = TAU / 30, W = (TAU * 2) / D;++// the body's centre height u px behind the head: humps rolling back toward the tail, the neck raised to the head+function lift(u, t) {+ const wave = Math.max(0, Math.sin(K * u - W * t)) ** 0.85, env = smooth(8, 18, u) * (1 - smooth(LEN - 14, LEN - 2, u));+ const neck = u < 12 ? 6 * (1 - u / 12) ** 2 : 0;+ return 7 * wave * env + neck;+}+const radius = (u) => (u < 6 ? 3.3 : lerp(3.4, 0.6, ((u - 6) / (LEN - 6)) ** 1.3));+// the head's bob with the rhythm, and the tongue's flicks: two bursts of three a loop+const bob = (t) => 0.8 * Math.sin(W * t);+function tongue(t) {+ for (const t0 of [0.3, 1.5]) {+ const k = (t - t0) / 0.5;+ if (k >= 0 && k < 1) return Math.max(0, Math.sin(k * Math.PI * 3)) ** 0.6;}- return { pts, hx, hy };+ return 0;}-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);+function snake(g, C, B, t) {+ g.clear();+ const hb = bob(t);+ // the body, column by column from the tail to the neck: lit along its back, a gold belly, dark diamonds, glints on the humps+ for (let u = LEN; u >= 2; u -= 0.5) {+ const x = HEAD - u, r0 = radius(u), cy = -r0 - lift(u, t) + (u < 12 ? hb * (1 - u / 12) : 0), hump = lift(u, t);+ // keep the body as thick across its slope as along the floor+ const slope = (lift(u + 0.5, t) - lift(u - 0.5, t)), r = r0 * Math.sqrt(1 + slope * slope);+ for (let y = Math.floor(cy - r); y <= Math.ceil(cy + r); y++) {+ const v = (y + 0.5 - cy) / r;+ if (Math.abs(v) > 1) continue;+ let c = v < -0.5 ? C[4] : v < 0.1 ? C[3] : v < 0.45 ? C[2] : v < 0.8 ? B[1] : B[0];+ const dm = Math.abs(((u + 2) % 7) - 3.5) / 3.5 + Math.abs(v + 0.25) / 0.55;+ if (dm < 0.85 && v < 0.35 && u > 4) c = dm < 0.5 ? C[1] : C[2];+ if (v < -0.62 && hump > 4.5 && dm >= 0.85) c = hump > 6 ? C[6] : C[5];+ if (v > 0.45 && v < 0.8 && Math.floor(u) % 3 === 0) c = B[2];+ g.set(x, y, c);}- 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];+ }+ // the head: a blunt wedge raised off the floor, lit on top, an eye with a slit pupil, a nostril, a mouth line+ const hx = HEAD + 2, hy = -9.5 + hb;+ g.shade(hx - 5, hy - 4, hx + 6, hy + 4, (x, y) => {+ const dx = (x - hx) / (x > hx ? 5.6 : 4.6), dy = (y - hy) / (3.6 - Math.max(0, x - hx) * 0.18);+ if (dx * dx + dy * dy > 1) return 0;+ if (dy > 0.55) return B[1];+ return dy < -0.3 ? (dx < 0.3 ? C[5] : C[4]) : C[3];});- 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.line(hx - 1, hy + 1.5, hx + 5, hy + 1.2, C[1]);+ g.set(hx + 1, hy - 2, C[0]); g.set(hx + 2, hy - 2, B[2]); g.set(hx + 1, hy - 1, B[2]); g.set(hx + 2, hy - 1, C[0]);+ g.set(hx + 1, hy - 3, C[6]);+ g.set(hx + 5, hy - 1, C[1]);+ g.outline(C[0]);+}++export function draw(p, time, o) {+ const t = shift(time, D, o.seed), C = fit(o.palette, 7), B = fit(o.belly, 3), hb = bob(t);+ // the tongue darts out, forked, and flicks back+ const e = tongue(t), tx = HEAD + 7.5, ty = -8.2 + hb;+ if (e > 0.05) {+ const L = 7 * e, wig = Math.sin(t * 60) * 0.6 * e;+ p.line(tx, ty, tx + L, ty + wig, TONGUE);+ if (L > 3) p.px(tx + L + 1, ty + wig - 1, TONGUE), p.px(tx + L + 1, ty + wig + 1, TONGUE);}+ const g = GRID;+ snake(g, C, B, t);g.draw(p);+ // dust scuffed along the floor where each hump presses back down, drifting off low and thin+ const sw = SWARM.begin(t);+ cycle(t, D, 26, o.seed * 7 + 1, (r) => r.range(0.6, 1.1), (age, L, r) => {+ const born = wrap(t - age, D), m = r.int(0, 2), u = (Math.PI + W * born + m * TAU) / K;+ if (u < 18 || u > LEN - 10) return;+ const x = HEAD - u + r.range(-2, 2) - r.range(6, 16) * age;+ sw.add(P.SMOKE, x, -0.5 - age * r.range(3, 8), 0, 0, age, L, DUST, r.range(1.8, 3.4));+ });+ sw.draw(p);+ // a glint in its eye+ p.glow(HEAD + 3.5, -11 + hb, 4, B[2], 0.35);+}++export function drawBack(p, time, o) {+ const t = shift(time, D, o.seed), C = fit(o.palette, 7);++ // a shadow along its length, softer under the humps+ for (let u = 2; u <= LEN; u += 2) {+ const h = lift(u, t), r = radius(u);+ shadow(p, HEAD - u, -0.2, 2.2 + r * 0.4, 1.2, C[0], 0.5 * (1 - clamp(h / 10)) + 0.1);+ }+ shadow(p, HEAD + 2, -0.2, 5, 1.2, C[0], 0.35);}diff --git a/src/fx/critters/spider.js b/src/fx/critters/spider.jsdeleted file mode 100644index 72841e3..0000000--- a/src/fx/critters/spider.js+++ /dev/null@@ -1,56 +0,0 @@-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.jsindex 684d9ec..64e5504 100644--- a/src/fx/critters/wisp.js+++ b/src/fx/critters/wisp.js@@ -1,63 +1,79 @@-import { cycle, tileFbm, loopNoise, TAU } from "../../core/index.js";-import { Grid, shades, shift } from "./_lib.js";+// The flame tail, puffs and embers are adapted from Sprite Fusion's open-source fire+// (https://www.spritefusion.com/pixel-art-vfx/fire), MIT License, Copyright (c) 2026 Hugo Duprez.+import { fit, clamp, wrap, lerp, cycle, fly, P, TAU } from "../../core/index.js";+import { Swarm, shift, lnoise, tongue, firePuff, shadow } 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,+ desc: "A will-o'-the-wisp loops a figure-eight over the floor: a little soul-flame with a face, its flame tail licking up and streaming behind, shedding puffs and sparks.",+ tags: ["critter", "wisp", "spirit", "flame", "magic", "flying", "loop"],+ size: [128, 104],+ origin: [64, 96],+ duration: 3.2,loop: true,fps: 30,- bg: "dark",- options: { palette: ["#061e2a", "#0e5668", "#1ea4ae", "#6deed8", "#e8fffa"], seed: 2 },+ bg: "ground",+ options: { palette: ["#0a1f2e", "#0f3d52", "#14707e", "#1fa8a8", "#4fe0c8", "#a8fff0", "#ffffff"], hover: 36, seed: 1 },};-const path = (ph) => [Math.sin(ph * TAU) * 8, Math.sin(ph * TAU * 2) * 4 + 2];+const D = meta.duration, SWARM = new Swarm();+function at(t, hover) {+ const a = (t / D) * TAU;+ return { x: 34 * Math.sin(a), y: -hover - 10 * Math.sin(2 * a), vx: ((34 * TAU) / D) * Math.cos(a), vy: ((-20 * TAU) / D) * Math.cos(2 * a) };+}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);+ const t = shift(time, D, o.seed), C = fit(o.palette, 7), S = at(t, o.hover);+ const heat = [C[6], C[6], C[5], C[5], C[4], C[4], C[3], C[3], C[3]];+ const lean = clamp(-S.vx / 80, -0.9, 0.9), stretch = clamp(S.vy / 120, -0.3, 0.4), X = S.x, Y = S.y;+ // flame puffs shed along its path, cooling down the ramp as they drift up+ cycle(t, D, 30, o.seed * 7 + 1, (r) => r.range(0.3, 0.6), (age, L, r) => {+ const S0 = at(wrap(t - age, D), o.hover), [x, y] = fly(S0.x + r.range(-3, 3), S0.y - r.range(0, 4), r.range(-8, 8), -r.range(6, 16), age, -40, 2.5);+ firePuff(p, x, y, 1 - age / L, r.range(1.2, 2.6), r.next() * 100, heat);+ });+ // the tail: three tongues off the top of its head, streaming back as it flies+ const tails = [[-3.5, 13, 2.5, 3], [3.5, 14, 2.5, 7], [0, 20, 3.2, 11]];+ for (let li = 0; li < 4; li++)+ for (const [dx, h, w, n] of tails) {+ const hh = (h + 0.25 * h * lnoise(t, D, 9, n, 5)) * (1 + stretch);+ tongue(p, X + dx, Y - 2, hh, w, lnoise(t, D, 6, n, 40) * 1.5 + lean * hh * 0.9, t, D, n, heat, li);}- 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;+ // the head: a ball of cold fire, white at the heart, its rim flickering+ const R = 7.5;+ p.shade(X - R - 2, Y - R - 2, X + R + 2, Y + R + 2, (x, y, out) => {+ const dx = x - X, dy = y - Y, ang = Math.atan2(dy, dx), rr = R + 0.7 * lnoise(t, D, 16, ang * 1.6 + 10, 3) + (dy > 0 ? -0.6 : 0);+ const d = Math.hypot(dx, dy) / rr;+ if (d > 1) return 0;+ return d < 0.42 ? C[6] : d < 0.68 ? C[5] : d < 0.88 ? C[4] : C[3];});- // 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));+ // its face: eyes looking where it's going, a blink, a little mouth+ const look = Math.round(clamp(S.vx / 60, -1, 1)), blink = wrap(t, D) > 2.2 && wrap(t, D) < 2.28;+ for (const s of [-1, 1]) {+ const ex = Math.round(X) + s * 2 - (s > 0 ? 0 : 1) + look, ey = Math.round(Y) - 1;+ if (blink) p.px(ex, ey + 1, C[1]), p.px(ex + 1, ey + 1, C[1]);+ else {+ for (let k = 0; k < 3; k++) p.px(ex, ey + k, C[1]), p.px(ex + 1, ey + k, C[1]);+ p.px(ex + (look > 0 ? 1 : 0), ey, C[6]);+ }+ }+ p.px(Math.round(X) + look, Math.round(Y) + 3, C[2]); p.px(Math.round(X) - 1 + look, Math.round(Y) + 3, C[2]);+ // sparks wander up off it+ const sw = SWARM.begin(t);+ sw.ps.sparks = [C[6], C[5], C[4], C[3]];+ cycle(t, D, 26, o.seed * 7 + 2, (r) => r.range(0.8, 1.6), (age, L, r) => {+ const S0 = at(wrap(t - age, D), o.hover), s = r.next() * 100, [x, y] = fly(S0.x + r.range(-5, 5), S0.y - r.range(4, 12), r.range(-20, 20), -r.range(20, 45), age, -15, 1.6);+ sw.add(P.EMBER, x + Math.sin(age * 2.3 + s) * 3 * Math.min(1, age), y, 0, 0, age, L, C[4], r.chance(0.3) ? 2 : 1, 0, s);});- p.glow(hx, hy, 20, S[3], 0.3);- p.glow(hx, hy, 7, S[4], 0.3);+ sw.draw(p);+ // light: a cold glow round it, a hot heart+ const fl = 0.85 + 0.15 * lnoise(t, D, 22, 0, 9);+ p.glow(X + lean * 3, Y - 6, 46 * fl, C[4], 0.38);+ p.glow(X, Y - 1, 13, C[5], 0.35 * fl);+}++export function drawBack(p, time, o) {+ const t = shift(time, D, o.seed), C = fit(o.palette, 7), S = at(t, o.hover), near = clamp(1 - (-S.y - 24) / 30);+ // the floor lit cold beneath it, brighter as it dips+ shadow(p, S.x, 0, 7, 1.2, C[0], 0.4);+ for (let x = -24; x <= 24; x += 6) p.glow(S.x + x, -1, 16, C[4], (0.08 + 0.1 * near) * (1 - Math.abs(x) / 32));}diff --git a/src/fx/explosions/_lib.js b/src/fx/explosions/_lib.jsindex 00da5f6..5fef53c 100644--- a/src/fx/explosions/_lib.js+++ b/src/fx/explosions/_lib.js@@ -1,189 +1,454 @@-// 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).+// Shared by the explosions. Not an effect (the leading _ keeps the tools away).+// The fire balls, rocks and scorch are adapted from Sprite Fusion's open-source explosion+// (https://www.spritefusion.com/pixel-art-vfx/explosion), MIT License, Copyright (c) 2026 Hugo Duprez.-import { at, burst, fly, flyV, seg, ease, clamp, noise2, TAU, WHITE } from "../../core/index.js";-export { fit, pool } from "../fire/_lib.js";+import { P, PF, clamp, smooth, rand, TAU, WHITE, hex, mix, scale, rgb } from "../../core/index.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];+export const OUTLINE = hex("#1a1422"), SOOT = hex("#0d0a12"), SOOT2 = hex("#17121d");+/** Stone colors from one body color: a lit face, the body, a shaded face, and the dust it makes. */+export function stone(c) {+ c = hex(c);+ return { light: mix(scale(c, 1.35), WHITE, 0.08), body: c, shade: scale(c, 0.64), dust: mix(scale(c, 1.2), rgb(150, 140, 150), 0.3) };+}++/** A 9-step fire ramp, white-hot down to smouldering (the shape of FIRE_RAMP), from an 8-step palette (dark to bright). */+export const fireRamp = (F) => [F[7], F[6], F[5], F[4], F[3], F[2], F[1], mix(F[1], F[0], 0.5), F[0]];++/** One FIRE particle drawn in the fire ramp FR: a darker rim, a lit core, a tongue on top, a hot heart. */+export function fireBall(p, q, FR) {+ const k = q.life / q.max, age = 1 - k, n = FR.length, x = q.x, y = q.y;+ const heat = Math.min(0.999, Math.pow(age, 0.62) + (q.seed % 1) * 0.1), idx = Math.min(n - 2, Math.floor(heat * (n - 1)));+ const r = q.size * (0.55 + 0.45 * Math.min(1, age * 7)) * (1 - age * 0.55), c = FR[idx];+ if (idx >= n - 2) return p.disc(x, y, r, c, Math.min(1, k * 3) * 0.85);+ // the hottest puffs get a rim a step darker still, so a mass of them reads as separate balls+ p.circle(x, y, r, FR[Math.min(n - 1, idx + (idx <= 2 ? 3 : 2))]);+ p.circle(x - r * 0.16, y - r * 0.22, r * 0.78, c);+ if (r > 1.6) p.circle(x, y - r * 0.9, r * 0.42, c);+ if (idx <= 3 && r > 1.8) p.circle(x - r * 0.28, y - r * 0.34, r * 0.36, FR[Math.max(0, idx - 1)]);+ if (idx < 6) p.glow(x, y, r * 2.4 + 2, c, 0.18 * k);+}++/** A particle system's layer ("back" or "front") with its FIRE puffs in the fire ramp FR, so a palette recolors them. */+export function drawPs(p, ps, layer, FR) {+ const all = ps.list, fires = [], rest = [];+ for (const q of all) (q.k === P.FIRE ? fires : rest).push(q);+ const back = layer === "back";+ if (!back) for (const q of fires) if (q.delay <= 0 && !(q.flag & PF.BACK)) fireBall(p, q, FR);+ ps.list = rest;+ ps.draw(p, layer);+ ps.list = all;+ if (back) for (const q of fires) if (q.delay <= 0 && q.flag & PF.BACK) fireBall(p, q, FR);+}++const LIFTS = new Set([P.SMOKE, P.DUST, P.FIRE, P.EMBER, P.VAPOUR]);/**- * 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.+ * An updraft column at x: smoke, dust, fire and embers below `top` and within w of the axis are carried up+ * (up px/s²) and squeezed toward it; near the floor (within `low` px) they're drawn in from as far as `reach`:+ * the afterwinds that feed a blast's column. k scales it all.*/-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);+export function draft(ps, dt, { x = 0, top = -Infinity, w = 12, up = 150, squeeze = 4, pull = 0, low = 10, reach = 100, k = 1 }) {+ if (k <= 0) return;+ for (const q of ps.list) {+ if (q.delay > 0 || !LIFTS.has(q.k) || q.y < top) continue;+ const dx = q.x - x, ax = Math.abs(dx), u = ax / w;+ if (u < 1) {+ const f = (1 - u * u) * k;+ q.vy -= up * f * dt;+ q.vx -= dx * squeeze * f * dt;}- if (best > 0) return color(best, lit, x, y, out, bf);- });+ if (pull && q.y > -low && ax > w * 0.4 && ax < reach) q.vx -= Math.sign(dx) * pull * k * (1 - ax / reach) * dt;+ }}+/** Drop particles that leave the box (local px), so nothing is drawn past the canvas. */+export function cull(ps, x0, y0, x1, y1) {+ const L = ps.list;+ for (let i = L.length - 1; i >= 0; i--) {+ const q = L[i];+ if (q.x < x0 || q.x > x1 || q.y < y0 || q.y > y1) L.splice(i, 1);+ }+}++const SOFT = new Set([P.SMOKE, P.DUST, P.VAPOUR]);/**- * 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.+ * Soft particles (smoke, dust, vapour) fade out over w px as they near the sides x0, x1 and go before they reach+ * them; y1, a bottom edge, gets a thin w of 6 (keep things off it by design).*/-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));+export function fadeEdges(ps, x0, x1, w = 30, y1 = Infinity) {+ const L = ps.list;+ for (let i = L.length - 1; i >= 0; i--) {+ const q = L[i];+ if (!SOFT.has(q.k)) continue;+ const r = q.size * 1.65, e = Math.min((Math.min(q.x - x0, x1 - q.x) - r) / w, (y1 - q.y - r) / 6);+ if (e <= 0) L.splice(i, 1);+ else if (e < 1) q.life = Math.min(q.life, q.max * 0.42 * e);+ }+}++/** A soft pool of light, an ellipse rx by ry at (x, y): light falling on the floor (keep ry small, it's perspective). */+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;+ });+}++/** A translucent ellipse (blended, never dithered): c and a may be functions of d (0 centre .. 1 rim). */+export function haze(p, x, y, rx, ry, c, a) {+ if (rx < 0.5 || ry < 0.5) return;+ const fc = typeof c === "function", fa = typeof a === "function";+ p.each(x - rx, y - ry, x + rx, y + ry, (lx, ly, sx, sy) => {+ const dx = (lx - x) / rx, dy = (ly - y) / ry, d2 = dx * dx + dy * dy;+ if (d2 > 1) return;+ const d = Math.sqrt(d2);+ p.blendPx(sx, sy, fc ? c(d) : c, fa ? a(d) : a);});}+/** Heat for a scorch, from a fire ramp (bright to dark) down to cinders. */+export const heatRamp = (FR) => [...FR.slice(0, 8), mix(FR[8], SOOT, 0.3), mix(FR[8], SOOT, 0.65)];+/**- * 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].+ * The floor under a blast: a burn that spreads out in a blink, glows white-hot and cools through the heat ramp+ * HR to soot over `cool` seconds; a few cracks hold their glow twice as long. rows deep, fade 0..1.*/-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];- }+export function scorch(p, HR, t, rx0, cool, fade, rows = 3) {+ if (fade <= 0) return;+ const rx = rx0 * Math.min(1, t / 0.08), ry = rows + 1.5, n = HR.length;+ for (let y = 0; y < rows; y++)+ for (let x = Math.floor(-rx); x <= Math.ceil(rx); x++) {+ const dx = (x + 0.5) / rx, dy = (y + 0.5) / ry, d = Math.sqrt(dx * dx + dy * dy);+ if (d > 1) continue;+ const k = rand(x * 31 + y, 3), T = Math.pow(clamp(1 - t / cool), 1.4) * (1.25 - d) - k * 0.35;+ const crack = k > 0.88 && d < 0.85 ? Math.pow(clamp(1 - t / (cool * 2)), 1.2) * (1.15 - d) * 0.8 : 0, H = Math.max(T, crack);+ if (H > 0.06) {+ const c = HR[Math.min(n - 1, Math.floor((1 - Math.min(1, H)) * (n - 1)))];+ p.dot(x, y, c, fade);+ if ((x & 3) === 0 || crack > T) p.glow(x + 0.5, y, 6, c, 0.18 * H * fade);+ } else p.dot(x, y, d < 0.5 ? SOOT : SOOT2, (d < 0.95 - k * 0.3 ? 1 : 1 - d) * fade);+ }}/**- * 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.+ * A rock (a Bits CHUNK): a lit side, a shaded side and an outline, turning as it spins. b.heat (0..1) makes+ * it molten: its heart and shaded side glow through the fire ramp FR and it gives off light, cooling to stone.*/-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);+export function rock(p, b, st, FR) {+ const r = 0.6 + b.s * 0.75, fade = Math.min(1, b.life / 0.5), lx = Math.cos(b.a) * r * 0.4, ly = Math.sin(b.a) * r * 0.4, heat = b.heat ?? 0;+ p.shade(b.x - r - 1, b.y - r - 1, b.x + r + 1, b.y + r + 1, (x, y, out) => {+ const dx = x - b.x, dy = y - b.y, d = Math.hypot(dx * 1.15, dy);+ if (d > r + 0.9) return;+ out.a = fade;+ if (d > r) return OUTLINE;+ const lit = dx * lx + dy * ly;+ if (heat > 0.08) {+ const g = heat * (1.1 - d / (r + 0.5)) + (lit > 0.3 ? heat * 0.45 : 0);+ if (g > 0.5) return FR[g > 1 ? 1 : g > 0.8 ? 2 : g > 0.62 ? 3 : 4];+ if (g > 0.32) return FR[5];+ }+ return lit < -0.4 ? st.light : lit > 0.6 ? st.shade : st.body;});+ if (heat > 0.05) p.glow(b.x, b.y, r * 2 + 3, FR[3], 0.32 * heat * fade);}-/** 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;+/**+ * Light hugging the upper half of a circle of radius R at (x, y) (a dome's shock), falling off over width w.+ * box [x0, y0, x1, y1] (local) keeps it inside a canvas.+ */+export function glowDome(p, x, y, R, w, c, k, box = [-Infinity, -Infinity, Infinity, Infinity]) {+ if (k <= 0.004 || w < 1) return;+ p.shade(Math.max(box[0], x - R - w), Math.max(box[1], y - R - w), Math.min(box[2], x + R + w), Math.min(box[3], y + 0.5), (px, py, out) => {+ const d = Math.abs(Math.hypot(px - x, py - y) - R) / 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 burning thing's trail: pts [{ x, y, t }] (oldest first) at time t, drawn as a ribbon that is fire near the+ * head (fire ramp FR) and swells into thin smoke behind (smoke ramp SM, light to dark) over life seconds.+ */+export function trail(p, pts, t, FR, SM, life = 0.5, w = 1, heat = 1) {+ let lx = NaN, ly = NaN;+ for (let i = pts.length - 1; i >= 0; i--) {+ const q = pts[i], age = (t - q.t) / life;+ if (age >= 1) break;+ if (Math.hypot(q.x - lx, q.y - ly) < 1.6) continue;+ lx = q.x;+ ly = q.y;+ const r = w * (0.7 + age * 2.6);+ if (age < 0.12 * heat) p.circle(q.x, q.y - age * 6, r * 0.8, FR[age < 0.05 ? 3 : 5]);+ else p.disc(q.x, q.y - age * 6, r, SM[Math.min(SM.length - 1, 1 + Math.floor(age * 3))], 0.55 * (1 - age));+ }}-/** 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));+/**+ * Draw a particle system's GRIT as dirt in flight: fast bits stretch into short streaks (a darker tail, the bit at+ * the head), slow ones are the usual 1 or 2 px chips. The rest of the system draws as usual. layer as in draw.+ */+export function drawDirt(p, ps, layer) {+ const all = ps.list, grit = [], rest = [];+ for (const q of all) (q.k === P.GRIT ? grit : rest).push(q);+ ps.list = rest;+ ps.draw(p, layer);+ ps.list = all;+ if (layer === "back") return;+ for (const q of grit) {+ if (q.delay > 0) continue;+ const k = q.life / q.max, sp = Math.hypot(q.vx, q.vy);+ if (k < 0.25 && k * 4 < 0.5) continue;+ if (sp > 140) {+ const L = Math.min(5, sp * 0.012), ux = q.vx / sp, uy = q.vy / sp;+ p.line(q.x - ux * L, q.y - uy * L, q.x, q.y, (u) => (u < 0.5 ? scale(q.col, 0.7) : q.col));+ } else {+ p.px(q.x, q.y, q.col);+ if (q.size >= 2) p.px(q.x + 1, q.y, q.col), p.px(q.x, q.y + 1, scale(q.col, 0.8)), p.px(q.x + 1, q.y + 1, scale(q.col, 0.7));+ }}}-/**- * 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).+ * A crater in the floor at x: a dark pit (an ellipse in perspective) with its far wall lit, dirt heaped in a lip on+ * either side, and loose earth scattered round it. E: an earth ramp (dark to bright, 5+ steps); r: half-width;+ * k: 0..1 how far it has opened; a: alpha (fade it out).*/-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)) });+export function crater(p, E, x, r, k, a = 1) {+ if (k <= 0 || a <= 0) return;+ const n = E.length, rx = r * k, ry = Math.max(1.5, r * 0.17 * k);+ for (let py = -1; py <= Math.ceil(ry) + 1; py++)+ for (let px = Math.floor(-rx - 1); px <= Math.ceil(rx + 1); px++) {+ const dx = (px + 0.5) / rx, dy = (py + 0.5 - ry * 0.35) / ry, d = Math.sqrt(dx * dx + dy * dy);+ if (d > 1.08) continue;+ // the pit: darkest at its far side under the lit rim, the near wall a step lighter+ const c = d > 0.92 ? (dy < 0 ? E[n - 2] : E[2]) : dy < -0.2 ? E[0] : dy < 0.35 ? E[1] : E[2];+ p.dot(x + px, py, c, a);+ }+ // the lip: dirt heaped up either side, lit on top, and a scatter of loose earth+ for (const s of [-1, 1])+ for (let i = 0; i < 9; i++) {+ const u = i / 8, h = Math.round(Math.sin(Math.PI * u) * 2.2 * k + (rand(i, s > 0 ? 3 : 4) < 0.4 ? 1 : 0) * k);+ const hx = x + s * (rx * 0.82 + u * r * 0.55);+ for (let j = 0; j <= h; j++) p.dot(hx, -j, j === h ? E[n - 2] : j === h - 1 ? E[3] : E[2], a);+ }+ for (let i = 0; i < 26; i++) {+ const s = rand(i, 7) < 0.5 ? -1 : 1, d = rx * (1.05 + rand(i, 8) * 1.4), y = Math.round(rand(i, 9) * 3) - 1;+ if (rand(i, 10) < k) p.dot(x + s * d, y, rand(i, 11) < 0.5 ? E[3] : E[2], a);+ }+}++/** A hemisphere of white-hot air on the floor at x, radius r: an orange rim, a hot body, a white core; k 1 → 0 as it dies. */+export function dome(p, F, x, r, k) {+ const e = 1.4 / r;+ p.shade(x - r - 1.5, -r - 1.5, x + r + 1.5, 0.5, (px, py) => {+ const d = Math.hypot(px - x, py) / r;+ if (d > 1 + e) return;+ return d > 1 ? F[2] : d > 0.8 ? (k > 0.45 ? F[6] : F[5]) : d > 0.5 ? (k > 0.45 ? WHITE : F[6]) : k > 0.2 ? WHITE : F[6];});- 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.+ * A lobe of a billowing cloud, shaded like a ball. The sky lights it from the top left through the smoke ramp SM+ * (light to dark); fire (0..1) burns in its heart in the fire ramp FR (bright to dark), shrinking toward the+ * middle as it cools, with a darker band and a dark orange-red seam at its edge so a mass of burning lobes reads+ * apart; glow (0..1) lights its underside from below in fire colors. a: opacity (smoke edges stay soft); z: -1 far+ * .. 1 near (the far side sits a step darker); dark shifts the smoke down the ramp. style 1 cel-shades the smoke:+ * a lit crescent on top, a mid tone, a dark underside the fire tints while it's hot.*/-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);- });+export function lobe(p, x, y, r, FR, SM, fire, glow, a, z = 0, dark = 0, style = 0) {+ if (r < 0.7 || a <= 0.01) return;+ const n = FR.length, m = SM.length, back = z < -0.35 ? 1 : 0, rim = 1 - Math.min(0.35, 1.6 / r), seam = 1 - Math.min(0.3, 1.3 / r);+ // the soft edge: a step more see-through than the body, less of a step as the whole lobe thins (no bubble rims)+ const D = (i) => SM[Math.min(m - 1, i + back + dark)], soft = 0.55 + 0.4 * (1 - Math.min(1, a));+ const px = (lx, ly, sx, sy) => {+ const dx = (lx - x) / r, dy = (ly - y) / r, d2 = dx * dx + dy * dy;+ if (d2 > 1) return;+ const d = Math.sqrt(d2), nz = Math.sqrt(1 - d2), sky = -0.5 * dx - 0.66 * dy + 0.56 * nz;+ const v = fire * (1.32 - 0.78 * d) + 0.14 * sky * fire;+ let c, k = 0, solid = false;+ if (v > 0.44) {+ let i = Math.min(n - 3, Math.max(0, Math.floor((1.3 - v) * (n - 1) * 0.78)));+ if (d > seam) i = Math.min(6, Math.max(4, i + 2));+ else if (d > seam - 0.22) i = Math.min(n - 3, i + 1);+ c = FR[i];+ k = 0.05 * fire;+ solid = true;+ } else if (style) {+ const lam = -0.42 * dx - 0.78 * dy + 0.46 * nz;+ if (lam > 0.66 && d > 0.4) c = D(0);+ else if (lam > 0.16) c = D(1);+ else if (lam > -0.3) c = D(2);+ else {+ c = D(lam < -0.64 ? 4 : 3);+ const g = glow * (0.6 + 0.4 * dy);+ if (g > 0.55) (c = FR[g > 0.8 ? 5 : 6]), (k = 0.08 * g);+ else if (g > 0.34) c = mix(c, FR[6], 0.6);+ else if (g > 0.16) c = mix(c, FR[7], 0.45);+ }+ } else {+ const g = glow * (0.82 * dy + 0.3 * nz);+ if (g > 0.45) (c = FR[g > 0.66 ? 4 : 5]), (k = 0.1 * glow);+ else if (g > 0.3) c = FR[6];+ else if (g > 0.2) c = FR[7];+ else {+ const s = sky * 0.5 + 0.5;+ c = D(s > 0.8 ? 0 : s > 0.62 ? 1 : s > 0.42 ? 2 : s > 0.22 ? 3 : 4);+ }+ }+ p.blendPx(sx, sy, c, solid || d <= rim ? a : a * soft);+ if (k > 0) p.add(sx, sy, c, k);+ };+ if (p.sn !== 0 || p.cs !== 1) return p.each(x - r, y - r, x + r, y + r, px);+ // unrotated (the usual case): walk the screen pixels directly+ const ax = p.tx + (x - r) * p.fx, bx = p.tx + (x + r) * p.fx;+ const sx0 = Math.max(p.ox, Math.floor(Math.min(ax, bx))), sx1 = Math.min(p.ox + p.w - 1, Math.ceil(Math.max(ax, bx)));+ const sy0 = Math.max(p.oy, Math.floor(p.ty + y - r)), sy1 = Math.min(p.oy + p.h - 1, Math.ceil(p.ty + y + r));+ for (let sy = sy0; sy <= sy1; sy++) {+ const ly = sy + 0.5 - p.ty, q = (ly - y) / r;+ if (q * q >= 1) continue;+ // only the span of this row inside the circle+ const hw = r * Math.sqrt(1 - q * q), cx = p.tx + x * p.fx;+ for (let sx = Math.max(sx0, Math.floor(cx - hw - 0.5)), e = Math.min(sx1, Math.ceil(cx + hw)); sx <= e; sx++) px((sx + 0.5 - p.tx) * p.fx, ly, sx, sy);+ }+}++/**+ * A rolling fireball. n lobes ride a vortex ring that climbs (rise px, slowing with time constant tau, then+ * drifting up at drift px/s), swells (tube and ring radii grow with time constant grow) and rolls (up through+ * the middle, out over the top, down the outside, back in underneath), while it cools from white-hot fire+ * into smoke that glows from inside, then thins away. Seen from a little below: the near side sits lower.+ * update(dt); draw(p, FR (fire ramp, bright to dark), SM (smoke ramp, light to dark), { mid }) (mid() is drawn+ * between the far and near lobes: a stem going up into it); shape() its centre and radii; hot() how hot its heart+ * still is; ember() how strongly its inside still glows. Options for a nuclear cap: style 1 (cel-shaded lobes),+ * inner (a glow that lingers inside and draws back to the middle as it cools), hollow (the underside sits a step+ * darker), fray [t0, rate, t1] with onFray(x, y, r, ux, uy) (the rim sheds small puffs late on).+ */+export class Plume {+ constructor(R, o = {}) {+ this.o = o = {+ x: 0, y: -20, rise: 100, tau: 1.2, drift: 4, tube: [8, 20], ring: [1, 18], grow: 0.9, n: 40, size: [5, 10], swell: 0.5,+ spin: 2.4, spinTau: 1.6, heat: 1.15, cool: 0.45, under: 0.5, tilt: 0.2, squash: 0.7, fade: [4, 6], glow: 1, spread: 10,+ style: 0, inner: false, hollow: false, fray: null, ...o,+ };+ this.R = R;+ this.t = 0;+ this.roll = 0;+ this.onFray = null;+ // spread over the ring evenly: the roll angle on a golden-ratio walk, the turn round the axis in order+ this.lobes = Array.from({ length: o.n }, (_, i) => ({+ th: TAU * ((i * 0.618034 + R.range(-0.08, 0.08)) % 1), ph: (TAU * (i + R.range(-0.35, 0.35))) / o.n,+ j: R.range(-0.55, 0.12), s: R.range(o.size[0], o.size[1]), h: R.range(-0.22, 0.08), dx: R.range(-1, 1), dy: R.range(-1, 0.4),+ f: R.range(-0.9, 0.5), gv: R.range(0.55, 1.15),+ }));+ }+ shape(t = this.t) {+ const o = this.o, u = Math.max(0, t), g = 1 - Math.exp(-u / o.grow);+ return { x: o.x, y: o.y - o.rise * (1 - Math.exp(-u / o.tau)) - o.drift * u, tube: o.tube[0] + (o.tube[1] - o.tube[0]) * g, ring: o.ring[0] + (o.ring[1] - o.ring[0]) * g, g };+ }+ hot(t = this.t) {+ return clamp(this.o.heat - this.o.cool * t + 0.3);+ }+ /** How strongly the inside still glows (0..1), lingering well after the fire has gone. */+ ember(t = this.t) {+ return clamp((this.o.heat - this.o.cool * t + 1) / 1.1);+ }+ // where every lobe is at time t+ lobesAt(t) {+ const o = this.o, S = this.shape(t), base = o.heat - o.cool * t, span = S.ring + S.tube || 1, list = [];+ for (const q of this.lobes) {+ const fade = 1 - smooth(o.fade[0] + q.f, o.fade[1] + q.f * 0.5, t), loose = Math.pow(smooth(o.fade[0] - 1.8 + q.f, o.fade[1], t), 1.5) * o.spread;+ if (fade <= 0) continue;+ const th = q.th - this.roll, rt = S.tube * (1 + q.j), rho = S.ring + rt * Math.cos(th), up = Math.sin(th);+ const X = rho * Math.cos(q.ph), Z = rho * Math.sin(q.ph);+ // the outside cools first; the underside keeps its heat, fed from below+ const heat = base + q.h - 0.18 * Math.max(0, Math.cos(th)) * clamp(t * 2) + o.under * Math.max(0, -up) * clamp(base + 0.6);+ const r = q.s * (0.5 + 0.5 * S.g) * (1 + o.swell * clamp(1 - heat)) * (1 + 0.35 * (1 - fade));+ list.push({ x: S.x + X + q.dx * loose, y: S.y - rt * up * o.squash + Z * o.tilt + q.dy * loose, z: Z / span, up, out: Math.cos(th), heat, q, fade, r, d: Math.hypot(X, Z) / span, c: 1 - Math.min(1, Math.abs(X) / span) });+ }+ return list.sort((a, b) => a.z - b.z);+ }+ update(dt) {+ const o = this.o;+ this.t += dt;+ this.roll += o.spin * (0.12 + 0.88 * Math.exp(-this.t / o.spinTau)) * dt;+ // late on, the rim frays: lobes on the outside shed small puffs that drift off and thin+ if (o.fray && this.onFray && this.t > o.fray[0] && this.t < (o.fray[2] ?? Infinity)) {+ const S = this.shape(), k = o.fray[1] * dt * smooth(o.fray[0], o.fray[0] + 1, this.t);+ for (const e of this.lobesAt(this.t)) {+ if (e.out < 0.2 || !this.R.chance(k * e.fade)) continue;+ const ux = e.x - S.x, uy = e.y - S.y, l = Math.hypot(ux, uy) || 1;+ this.onFray(e.x + (ux / l) * e.r * 0.6, e.y + (uy / l) * e.r * 0.6, e.r, ux / l, uy / l);+ }+ }+ }+ draw(p, FR, SM, { mid } = {}) {+ const o = this.o, t = this.t;+ if (t >= o.fade[1] + 0.5) return;+ const S = this.shape(t), base = o.heat - o.cool * t, span = S.ring + S.tube || 1, list = this.lobesAt(t), age = clamp(t / o.fade[1]);+ const E = this.ember(t), reach = 0.3 + 1.15 * E;+ let drawn = false;+ for (const e of list) {+ if (!drawn && e.z >= 0 && mid) (drawn = true), mid();+ const h = e.heat, fade = e.fade, fire = clamp((h - 0.2) / 0.75);+ // the glow from inside: strongest under the middle, uneven from lobe to lobe; with inner, it draws back to the+ // middle as the cap cools+ const glow = o.inner+ ? E * clamp((reach - e.d) / 0.45) * (0.45 + 0.55 * Math.max(0, -e.up)) * e.q.gv * o.glow+ : clamp((base + 0.45) / 0.85) * o.glow * (0.4 + 0.35 * Math.max(0, -e.up) + 0.4 * e.c) * e.q.gv;+ lobe(p, e.x, e.y, e.r, FR, SM, fire, glow, fade * (0.82 + 0.18 * fire), e.z, (age > 0.72 ? 1 : 0) + (o.hollow && e.up < -0.35 ? 1 : 0), o.style);+ if (fire > 0.25) p.glow(e.x, e.y, e.r * 1.25 + 2, FR[2], 0.07 * fire);+ }+ if (!drawn && mid) mid();+ const hot = this.hot(t);+ if (hot > 0) p.glow(S.x, S.y, span * 1.8 + 14, FR[3], 0.32 * hot * o.glow);+ if (o.inner && E > 0.05) p.glow(S.x, S.y + S.tube * 0.3, span * (0.5 + 0.7 * E) + 8, FR[4], 0.22 * E * E);+ }+}++/**+ * A rising column: lobes boil up a stem from the floor into whatever sits on top, wide at the foot, swaying,+ * cooling from fire to smoke and dust. update(dt, top, feed): top is the y the stem rises to, feed 0..1 how+ * strongly it's still being fed (new lobes stop when it's 0, and the stem breaks up from the bottom).+ * draw(p, FR, SM, fire (0..1 heat at the foot), glow (0..1 under-light)).+ */+export class Column {+ constructor(R, o = {}) {+ this.R = R;+ this.o = o = { w: 7, foot: 16, speed: 70, size: [5, 8], n: 18, sway: 2.5, fade: 0.5, style: 0, ...o };+ this.t = 0;+ this.lobes = [];+ this.acc = 0;+ }+ spawn(y) {+ const R = this.R, o = this.o;+ this.lobes.push({ y, x: R.range(-1, 1), s: R.range(o.size[0], o.size[1]), ph: R.range(0, TAU), a: 0, v: R.range(0.8, 1.2) });+ }+ update(dt, top, feed) {+ const o = this.o, L = Math.max(10, -top);+ this.t += dt;+ if (feed > 0) for (this.acc += dt * feed * o.n * (o.speed / L); this.acc > 1; this.acc--) this.spawn(-1);+ for (let i = this.lobes.length - 1; i >= 0; i--) {+ const b = this.lobes[i], u = clamp(-b.y / L);+ b.y -= o.speed * b.v * (0.45 + 0.55 * Math.min(1, -b.y / 24)) * dt;+ b.a = Math.min(1, b.a + dt * 4);+ if (b.y < top || (feed <= 0 && (b.a -= dt * (2 - u)) <= 0)) this.lobes.splice(i, 1);+ }+ }+ draw(p, top, FR, SM, fire, glow) {+ const o = this.o, L = Math.max(10, -top);+ // draw from the top down so the foot sits in front+ const list = [...this.lobes].sort((a, b) => a.y - b.y);+ for (const b of list) {+ const u = clamp(-b.y / L), foot = Math.pow(1 - u, 4), w = o.w + o.foot * foot;+ const x = b.x * w * 0.45 + Math.sin(this.t * 1.7 + b.ph + u * 3) * o.sway * u;+ const r = b.s * (0.75 + 0.5 * foot + 0.35 * u) * Math.min(1, b.a * 1.5);+ const end = 1 - smooth(0.85, 1, u);+ lobe(p, x, b.y - r * 0.3 * foot, r, FR, SM, clamp(fire * (1.1 - u * 0.9)), glow * smooth(0.55, 1, u), Math.min(1, b.a) * end * 0.9, 0, u > 0.5 ? 0 : 1, o.style);+ }+ }}diff --git a/src/fx/explosions/barrel-explosion.js b/src/fx/explosions/barrel-explosion.jsindex c1c9e55..626b63b 100644--- a/src/fx/explosions/barrel-explosion.js+++ b/src/fx/explosions/barrel-explosion.js@@ -1,85 +1,223 @@-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";+// The blast (fire puffs that cool into smoke, sparks, embers, burning brands that land and keep burning, grit, scorch,+// rings) is adapted from Sprite Fusion's open-source explosion (https://www.spritefusion.com/pixel-art-vfx/explosion),+// MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Bits, Lights, Blazes, P, PF, B, Rng, fit, band, flare, clamp, smooth, ease, rand, TAU, WHITE, hex, mix, scale, rgb } from "../../core/index.js";+import { fireRamp, heatRamp, drawPs, cull, fadeEdges, scorch, pool, OUTLINE } from "./_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,+ desc: "An explosive barrel shudders, its lid bulging and spitting flame, then blows: a fireball column, staves and the lid flying, burning fuel splashed over the floor.",+ tags: ["explosion", "barrel", "fire", "smoke", "debris", "ground", "one-shot"],+ size: [300, 240],+ origin: [150, 204],+ duration: 5.2,loop: false,fps: 30,bg: "ground",- options: { palette: PAL.fire, seed: 32 },+ options: {+ palette: ["#4a1712", "#c9281f", "#f2561d", "#ff8a2a", "#ffc23d", "#ffe26b", "#fff3a6", "#ffffff"],+ barrel: ["#1c0a0e", "#4a1218", "#7c1a1e", "#b02a26", "#d8483a", "#f08a70"],+ seed: 8,+ },};-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;+const BLOW = 0.8, BW = 8, BH = 22;-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);+export function create(o) {+ const F = fit(o.palette, 8), FR = fireRamp(F), HR = heatRamp(FR), C = fit(o.barrel, 6), R = new Rng(o.seed), floor = () => 0;+ const [W, H] = meta.size, [OX, OY] = meta.origin, X0 = -OX + 3, X1 = W - OX - 3, Y0 = -OY + 3, Y1 = H - OY - 3;+ let blazes;+ const ps = new Particles({ rng: R, ground: floor, sparks: [F[6], F[5], F[3], F[2]], onLand: (x, y) => blazes.add(x, y - 0.25, R.range(1.2, 2.2), R.range(0.6, 1)) });+ blazes = new Blazes(ps);+ const lights = new Lights(), staves = new Bits({ ground: floor });+ const OIL = hex("#221a22"), SOOT = hex("#1f1a24");+ const lid = { x: 0, y: -BH, vx: 0, vy: 0, a: 0, va: 0, on: false, rest: false };+ // the fuel splashed over the floor: a puddle and the spots that keep burning in it+ const pools = [];+ let t = 0, blown = false;++ const blow = () => {+ blown = true;+ const y = -BH * 0.5;+ lights.add(0, y - 20, 90, mix(F[3], F[6], 0.45), 0.85, 0.9);+ lights.add(0, y, 44, WHITE, 0.7, 0.09);+ // the fireball: bursting out, then a column of fire driven up out of the drum+ for (let i = 0; i < 5; i++) ps.spawn(P.FIRE, R.range(-3, 3), y + R.range(-3, 3), R.range(-20, 20), R.range(-40, -10), R.range(0.18, 0.28), 0, R.range(9, 12));+ for (let i = 0; i < 30; i++) {+ const a = R.range(-Math.PI - 0.15, 0.15), d = R.range(0, 8), sp = R.range(50, 190);+ ps.spawn(P.FIRE, Math.cos(a) * d, y + Math.sin(a) * d, Math.cos(a) * sp, Math.sin(a) * sp * 0.8 - 40, R.range(0.55, 1.05), 0, R.range(5, 10), 0, R.chance(0.5) ? PF.SMOKES | PF.BIG : 0);}- }- for (let x = -4; x <= 3; x++) p.px(x + dx, -17, x < -1 ? METAL[2] : METAL[1]);+ for (let i = 0; i < 12; i++) ps.spawn(P.FIRE, R.range(-6, 6), y - R.range(0, 10), R.range(-14, 14), -R.range(170, 300), R.range(0.7, 1.15), 0, R.range(6, 10), R.range(0, 0.12), R.chance(0.7) ? PF.SMOKES | PF.BIG : 0);+ // oily black smoke+ for (let i = 0; i < 12; i++) {+ const a = R.range(-Math.PI, 0), d = R.range(4, 16);+ ps.spawn(P.SMOKE, Math.cos(a) * d, y + Math.sin(a) * d, Math.cos(a) * 30, -R.range(30, 90), R.range(1.6, 2.6), SOOT, R.range(8, 13), R.range(0.1, 0.4), PF.BIG);+ }+ for (let i = 0; i < 90; i++) {+ const a = R.range(0, TAU), sp = R.range(160, 400);+ ps.spawn(P.SPARK, 0, y, Math.cos(a) * sp, Math.sin(a) * sp - 70, R.range(0.2, 0.6));+ }+ for (let i = 0; i < 40; i++) {+ const a = R.range(0, TAU), sp = R.range(30, 140);+ ps.spawn(P.EMBER, Math.cos(a) * 8, y + Math.sin(a) * 8, Math.cos(a) * sp, Math.sin(a) * sp - 70, R.range(1.2, 2.6), F[3]);+ }+ // burning fuel flung out in arcs: it lands and keeps burning+ for (let i = 0; i < 14; i++) {+ const a = -Math.PI / 2 + R.range(-1.2, 1.2), sp = R.range(120, 300);+ ps.spawn(P.BRAND, R.range(-4, 4), y, Math.cos(a) * sp, Math.sin(a) * sp, R.range(0.8, 1.4));+ }+ // the staves: the drum's plates torn off and thrown out, tumbling+ for (let i = 0; i < 9; i++) {+ const side = i % 2 ? 1 : -1, a = -Math.PI / 2 + side * R.range(0.25, 1.15), sp = R.range(170, 330);+ staves.add({ kind: B.CHUNK, x: side * R.range(2, 6), y: -R.range(4, BH - 4), vx: Math.cos(a) * sp, vy: Math.sin(a) * sp, g: 1, drag: 0.5, bounce: 0.35, life: R.range(3, 3.8), a: R.range(0, TAU), va: R.range(-16, 16), s: R.range(9, 13), heat: R.range(0.4, 0.9) });+ }+ // the lid, flung high and spinning+ Object.assign(lid, { on: true, x: 0, y: -BH, vx: R.range(-40, 40), vy: -R.range(430, 480), a: 0, va: R.sign() * R.range(10, 14) });+ // the fuel on the floor, and the floor's own dust and grit+ for (let i = 0; i < 7; i++) {+ const x = R.range(-34, 34);+ pools.push({ x, w: R.range(5, 10) });+ blazes.add(x, -0.25, R.range(2.2, 3), R.range(0.8, 1.3));+ }+ for (let i = 0; i < 12; i++) {+ const s = R.sign();+ ps.spawn(P.SMOKE, s * R.range(0, 10), -R.range(1, 4), s * R.range(80, 220), -R.range(2, 12), R.range(1.1, 1.8), hex("#7d7280"), R.range(6, 9), R.range(0, 0.05), PF.BIG);+ }+ for (let i = 0; i < 60; i++) {+ const u = R.range(-1, 1), a = -Math.PI / 2 + u * 0.7, sp = R.range(120, 330) * (1 - 0.4 * Math.abs(u));+ ps.spawn(P.GRIT, u * 6, -1, Math.cos(a) * sp, Math.sin(a) * sp, R.range(1.1, 1.9), R.pick([hex("#5a4f6b"), hex("#3e3650"), hex("#776c88")]), R.chance(0.4) ? 2 : 1);+ }+ };++ return {+ update(dt) {+ t += dt;+ if (!blown) {+ // the drum strains: flame and smoke spitting from the seam under the lid, quicker as it goes+ const k = t / BLOW;+ if (R.chance((6 + 30 * k * k) * dt)) {+ const s = R.sign();+ ps.spawn(P.FIRE, s * R.range(4, 7), -BH + 1, s * R.range(20, 60), -R.range(20, 60), R.range(0.15, 0.3), 0, R.range(1.5, 3));+ ps.spawn(P.SPARK, s * 6, -BH + 1, s * R.range(40, 140), -R.range(20, 120), R.range(0.1, 0.25));+ }+ if (R.chance(10 * dt)) ps.spawn(P.SMOKE, R.range(-5, 5), -BH, R.range(-8, 8), -R.range(15, 35), R.range(0.8, 1.3), 0, R.range(2.5, 4));+ if (t >= BLOW) blow();+ }+ if (lid.on && !lid.rest) {+ lid.vy += 950 * dt;+ lid.vx -= lid.vx * 0.4 * dt;+ lid.x += lid.vx * dt;+ lid.y += lid.vy * dt;+ lid.a += lid.va * dt;+ if (lid.y >= -1 && lid.vy > 0) {+ // a clank: sparks and dust where it lands, then it bounces flat and settles+ for (let i = 0; i < 6; i++) ps.spawn(P.SPARK, lid.x, -1, R.range(-90, 90), -R.range(40, 140), R.range(0.1, 0.25));+ for (let i = 0; i < 5; i++) ps.spawn(P.DUST, lid.x + R.range(-4, 4), -0.5, R.sign() * R.range(15, 60), -R.range(4, 18), R.range(0.35, 0.7), hex("#7d7280"), R.range(1.8, 3));+ lid.y = -1;+ if (lid.vy > 160) (lid.vy *= -0.3), (lid.vx *= 0.5), (lid.va *= 0.5);+ else (lid.rest = true), (lid.a = Math.PI / 2);+ }+ }+ staves.update(dt);+ for (let i = staves.list.length - 1; i >= 0; i--) {+ const b = staves.list[i];+ if (b.x < X0 + 8 || b.x > X1 - 8) staves.list.splice(i, 1);+ else if (b.heat > 0) b.heat = Math.max(0, b.heat - dt * 0.35);+ }+ blazes.update(dt);+ ps.update(dt);+ cull(ps, X0, Y0, X1, Y1);+ fadeEdges(ps, X0, X1, 24, Y1);+ lights.update(dt);+ },+ drawBack(p) {+ if (blown) {+ const u = t - BLOW, out = 1 - smooth(meta.duration - BLOW - 1, meta.duration - BLOW - 0.2, u);+ scorch(p, HR, u, 30, 2.2, out, 3);+ // the spilled fuel: a dark slick on the floor, lit by its own fire, shrinking as it burns off+ const left = 1 - smooth(1.6, 3.4, u);+ if (left > 0)+ for (const q of pools)+ for (let x = Math.floor(-q.w * left); x <= Math.ceil(q.w * left); x++) {+ const e = Math.abs(x) / (q.w * left + 0.01);+ p.dot(q.x + x, 1, rand(Math.floor(q.x + x), Math.floor(t * 12)) < 0.25 ? F[4] : OIL, out * (e < 0.8 ? 1 : 0.6));+ if (e < 0.6) p.dot(q.x + x, 2, OIL, out * 0.8);+ }+ const k = u / 0.45;+ if (k < 1) band(p, 0, 0.5, 100 * ease.outCubic(k), 0.16, Math.max(1, 4.5 * (1 - k)), 1.15 - k, [hex("#4a3f69"), hex("#6e6390"), F[3], F[6]], (g) => Math.sin(g) < 0);+ }+ drawPs(p, ps, "back", FR);+ blazes.drawBack(p);+ },+ draw(p) {+ if (!blown) {+ // the barrel, shaking harder, its lid bulging+ const k = t / BLOW, jx = Math.sin(t * 70) * k * k * 1.4, jy = Math.abs(Math.sin(t * 53)) * k * k * 0.8;+ drawBarrel(p, C, jx, -jy, k);+ p.glow(0, -BH, 10 + 8 * k, F[4], 0.25 + 0.35 * k * k * (0.6 + 0.4 * Math.sin(t * 40)));+ } else {+ const u = t - BLOW, k = u / 0.45;+ if (k < 1) band(p, 0, 0.5, 100 * ease.outCubic(k), 0.16, Math.max(1, 4.5 * (1 - k)), 1.15 - k, [hex("#4a3f69"), hex("#6e6390"), F[3], F[6]], (g) => Math.sin(g) >= 0);+ }+ drawPs(p, ps, "front", FR);+ for (const b of staves.list) stave(p, b, C, FR);+ if (lid.on) drawLid(p, C, lid, Math.min(1, (meta.duration - t) / 0.4));+ if (blown) {+ const u = t - BLOW;+ if (u < 0.08) {+ const k2 = 1 - u / 0.08, r = 18 * (0.85 + 0.15 * k2), y = -BH * 0.5;+ p.circle(0, y, r + 1.4, F[2]);+ p.circle(0, y, r, k2 > 0.45 ? F[6] : F[5]);+ p.circle(0, y, r * 0.6, k2 > 0.45 ? WHITE : F[6]);+ }+ if (u < 0.22) flare(p, 0, -BH * 0.5, 54 * Math.pow(1 - u / 0.22, 1.4), 1 - u / 0.22, F);+ // the burning fuel lights the floor+ pool(p, 0, 1, 90, 14, F[3], 0.5 * Math.max(0, 1 - u / 0.7) + 0.22 * (1 - smooth(1.6, 3.4, u)));+ }+ lights.draw(p);+ },+ };}-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);+// a steel drum standing on the floor at x: red, two ribs, a lit left side, a dark right side, an outline, a pale+// band; the lid bulges with k+function drawBarrel(p, C, x, y, k) {+ const bulge = Math.round(k * k * 2);+ p.shade(x - BW - 1, y - BH - 3, x + BW + 1, y + 0.5, (px, py) => {+ const dx = (px - x) / BW, v = (y - py) / BH; // dx -1..1 across, v 0 at the floor .. 1 at the top+ if (Math.abs(dx) > 1.1 || v < 0 || v > 1.05) return;+ const edge = Math.abs(dx) > 0.92 || v > 0.97 || v < 0.04;+ if (edge) return OUTLINE;+ const rib = Math.abs(v - 0.33) < 0.035 || Math.abs(v - 0.67) < 0.035, ribLit = Math.abs(v - 0.31) < 0.03 || Math.abs(v - 0.65) < 0.03;+ const band = v > 0.44 && v < 0.56;+ const lit = -dx; // light from the left+ let i = lit > 0.55 ? 5 : lit > 0.15 ? 4 : lit > -0.35 ? 3 : lit > -0.75 ? 2 : 1;+ if (band) return lit > 0.3 ? hex("#e8d8b0") : lit > -0.4 ? hex("#b8a888") : hex("#6e6050");+ if (rib) i = Math.max(1, i - 2);+ else if (ribLit) i = Math.min(5, i + 1);+ return C[i];});- {- 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));- }+ // the lid: a dark ellipse with a lit rim, pushed up as the drum swells+ p.ellipse(x, y - BH - bulge * 0.5, BW - 0.5, 2.2 + bulge * 0.4, (d, a) => (d > 0.7 ? (Math.sin(a) < 0 ? C[4] : C[2]) : C[1]));+}++// a stave: a curved plate torn from the drum, its painted face and its dark inside showing as it turns; hot edges glow+function stave(p, b, C, FR) {+ const fade = Math.min(1, b.life / 0.5), ca = Math.cos(b.a), sa = Math.sin(b.a), L = b.s, face = Math.cos(b.a * 1.7) > 0;+ for (let d = -L / 2; d <= L / 2; d += 0.5) {+ const bow = (1 - (2 * d / L) ** 2) * 1.2, x = b.x + ca * d - sa * bow, y = b.y + sa * d + ca * bow;+ const hot = b.heat > 0.3 && Math.abs(d) > L / 2 - 1;+ p.dot(x + sa, y - ca, OUTLINE, fade);+ p.dot(x, y, hot ? FR[b.heat > 0.6 ? 3 : 5] : face ? C[4] : C[1], fade);+ p.dot(x - sa, y + ca, face ? C[2] : OUTLINE, fade);}- 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));+ if (b.heat > 0.3) p.glow(b.x, b.y, 6, FR[4], 0.25 * b.heat * fade);+}++// the lid: a disc turning as it flies (an ellipse whose width follows its spin), lying flat once it lands+function drawLid(p, C, lid, a) {+ const w = Math.max(0.8, Math.abs(Math.cos(lid.a)) * 7.5), h = Math.max(1.2, Math.abs(Math.sin(lid.a)) * 7.5);+ const rx = lid.rest ? 7.5 : w, ry = lid.rest ? 1.6 : h;+ p.ellipse(lid.x, lid.y - (lid.rest ? 0.5 : 0), rx + 0.8, ry + 0.8, OUTLINE, a);+ p.ellipse(lid.x, lid.y - (lid.rest ? 0.5 : 0), rx, ry, (d, an) => (d > 0.65 ? (Math.sin(an) < 0 ? C[4] : C[2]) : C[3]), a);}diff --git a/src/fx/explosions/big-explosion.js b/src/fx/explosions/big-explosion.jsindex d1cffd6..c65b9b2 100644--- a/src/fx/explosions/big-explosion.js+++ b/src/fx/explosions/big-explosion.js@@ -1,70 +1,194 @@-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";+// The blast recipe (fire puffs that cool into smoke, sparks, embers, burning brands, grit, rocks, scorch, rings) is+// adapted from Sprite Fusion's open-source explosion (https://www.spritefusion.com/pixel-art-vfx/explosion),+// MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Bits, Lights, Blazes, P, PF, B, Rng, fit, band, flare, smooth, ease, TAU, WHITE, hex, mix } from "../../core/index.js";+import { stone, fireRamp, heatRamp, drawPs, draft, cull, scorch, rock, dome, glowDome, pool, trail, Plume, Column } 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,+ desc: "A huge ground blast in three beats: a white dome, a rolling fireball that climbs into a mushrooming smoke column, heavy rocks, and fires left burning.",+ tags: ["explosion", "fire", "smoke", "debris", "mushroom", "big", "ground", "one-shot"],+ size: [360, 300],+ origin: [180, 262],+ duration: 7.2,loop: false,fps: 30,bg: "ground",- options: { palette: PAL.fire, size: 1, seed: 21 },+ options: { palette: ["#4a1712", "#c9281f", "#f2561d", "#ff8a2a", "#ffc23d", "#ffe26b", "#fff3a6", "#ffffff"], stone: "#4a3f69", seed: 11 },};-const ROCK = [hex("#5a4648"), hex("#2e2228"), hex("#1a1218")];-const CHAR = [hex("#100c10"), hex("#211619")];+const RAD = 30, POWER = 1.45, EARTH = 1.6;+// the plume's smoke, lit on top to sooty underneath+const SM = ["#83777f", "#6e6470", "#575060", "#3f3947", "#29242f"].map(hex);+// three detonations, a beat apart, climbing as they go+const BLASTS = [+ { t: 0, x: 0, y: -9, rad: RAD, power: POWER, main: true },+ { t: 0.13, x: -17, y: -30, rad: 17, power: 0.9 },+ { t: 0.25, x: 15, y: -46, rad: 15, power: 0.8 },+];-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) });+export function create(o) {+ const F = fit(o.palette, 8), FR = fireRamp(F), HR = heatRamp(FR), st = stone(o.stone), R = new Rng(o.seed), floor = () => 0, WARM = mix(F[3], F[6], 0.45);+ const [W, H] = meta.size, [OX, OY] = meta.origin, X0 = -OX + 3, X1 = W - OX - 3, Y0 = -OY + 3, Y1 = H - OY - 3;+ let blazes;+ const ps = new Particles({ rng: R, ground: floor, sparks: [F[6], F[5], F[3], F[2]], onLand: (x, y) => blazes.add(x, y - 0.25, R.range(3, 4.4), R.range(0.7, 1.25)) });+ blazes = new Blazes(ps);+ const rocks = new Bits({ ground: floor }), lights = new Lights(), flashes = [], rings = [];+ const plume = new Plume(R, {+ x: 0, y: -34, rise: 118, tau: 1.25, drift: 4, tube: [9, 21], ring: [2, 19], grow: 1.0, n: 42, size: [6, 11], swell: 0.9,+ spin: 2.6, spinTau: 1.7, heat: 1.2, cool: 0.42, under: 0.5, tilt: 0.22, squash: 0.72, fade: [4.4, 6.4], spread: 22,});- // 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 column = new Column(R, { w: 5, foot: 18, speed: 85, size: [7, 11], n: 28, sway: 2.5 });+ const top = () => { const S = plume.shape(); return S.y + S.tube * 0.45; };+ let t = 0, next = 0;++ const blast = ({ x, y, rad, power, main }) => {+ // the later beats flash and ring in the air; the first is a dome on the floor (drawn from t)+ if (!main) flashes.push({ x, y, r: rad * 1.05, life: 0.06, max: 0.06 });+ if (!main) rings.push({ x, y, r0: rad * 0.45, r1: rad * 2.7, life: 0.36, max: 0.36, thick: 3, c: F[5] }, { x, y, r0: rad * 0.3, r1: rad * 1.6, life: 0.24, max: 0.24, thick: 1.8, c: F[3] });+ // light: a big warm flare (raised for a ground blast, so it lights the air and the floor gets a pool)+ lights.add(x, main ? y - 24 : y, main ? 72 : rad * 3.4, WARM, 0.6 * power, 0.8);+ lights.add(x, main ? y - 12 : y, main ? 44 : rad * 1.6, WHITE, 0.6, 0.1);+ const down = main ? 0.25 : Math.PI; // a ground blast throws nothing into the floor+ for (let i = 0; i < 5; i++) ps.spawn(P.FIRE, x + R.range(-2.5, 2.5), y + R.range(-2.5, 2.5), R.range(-20, 20), R.range(-40, -10), R.range(0.18, 0.3), 0, R.range(rad * 0.4, rad * 0.55));+ for (let i = 0; i < Math.round(26 * power); i++) {+ const a = main ? R.range(-Math.PI - down, down) : R.range(0, TAU), d = R.range(0, rad * 0.55), sp = R.range(40, 200) * power;+ ps.spawn(P.FIRE, x + Math.cos(a) * d, y + Math.sin(a) * d, Math.cos(a) * sp, Math.sin(a) * sp * 0.8 - 40, R.range(0.55, 1.15), 0, R.range(rad * 0.22, rad * 0.46), 0, R.chance(0.45) ? PF.SMOKES | PF.BIG : 0);}- 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);+ for (let i = 0; i < 5; i++) {+ const a = R.range(-Math.PI, 0), d = R.range(rad * 0.1, rad * 0.5);+ ps.spawn(P.SMOKE, x + Math.cos(a) * d, y + Math.sin(a) * d, Math.cos(a) * 30, Math.sin(a) * 20 - 30, R.range(0.9, 1.5), hex("#221d26"), R.range(rad * 0.15, rad * 0.26), R.range(0.06, 0.2), PF.BIG);+ }+ for (let i = 0; i < Math.round(8 * power); i++) {+ const a = R.range(-Math.PI, 0), d = R.range(0, rad * 0.7), sp = R.range(15, 90);+ ps.spawn(P.SMOKE, x + Math.cos(a) * d, y + Math.sin(a) * d, Math.cos(a) * sp, Math.sin(a) * sp * 0.6 - 35, R.range(1.8, 2.8), 0, R.range(rad * 0.26, rad * 0.4), R.range(0.12, 0.45), PF.BIG);+ }+ for (let i = 0; i < Math.round(80 * power); i++) {+ const a = R.range(0, TAU), sp = R.range(170, main ? 470 : 380);+ ps.spawn(P.SPARK, x, y, Math.cos(a) * sp, Math.sin(a) * sp - 70, R.range(0.2, 0.65));+ }+ for (let i = 0; i < Math.round(30 * power); i++) {+ const a = R.range(0, TAU), sp = R.range(30, 150);+ ps.spawn(P.EMBER, x + Math.cos(a) * rad * 0.4, y + Math.sin(a) * rad * 0.4, Math.cos(a) * sp, Math.sin(a) * sp - 75, R.range(1.4, 3), F[3]);+ }+ if (!main) return;+ // burning brands that land and keep the ground on fire+ for (let i = 0; i < 14; i++) {+ const a = -Math.PI / 2 + R.range(-1.3, 1.3), sp = R.range(160, 340);+ ps.spawn(P.BRAND, x, y, Math.cos(a) * sp, Math.sin(a) * sp, R.range(0.8, 1.5));+ }+ // the ground's part: dust rolling out along the floor, a dust column, grit and heavy rocks thrown up+ for (let i = 0; i < 18; i++) {+ const s = R.sign();+ ps.spawn(P.SMOKE, s * R.range(0, RAD * 0.6), -R.range(1, 6), s * R.range(3, 9) * RAD, -R.range(2, 15), R.range(1.3, 2.2), st.dust, R.range(8, 12), R.range(0, 0.06), PF.BIG);+ }+ for (let i = 0; i < Math.round(EARTH * 12); i++)+ ps.spawn(P.SMOKE, R.range(-0.3, 0.3) * RAD, -R.range(2, RAD * 0.6), R.range(-15, 15), -R.range(60, 190) * EARTH * 0.6, R.range(1.6, 2.6), st.dust, R.range(8, 12), R.range(0, 0.15), PF.BIG);+ for (let i = 0; i < Math.round(EARTH * RAD * 4); i++) {+ const u = R.range(-1, 1), a = -Math.PI / 2 + u * 0.55, sp = R.range(5, 15) * RAD * (1 - 0.45 * Math.abs(u));+ ps.spawn(P.GRIT, u * 0.25 * RAD, -1, Math.cos(a) * sp, Math.sin(a) * sp, R.range(1.4, 2.4), R.pick([st.light, st.body, st.body, st.shade]), R.chance(0.45) ? 2 : 1);+ }+ for (let i = 0; i < 26; i++) {+ const big = i < 10, hot = R.chance(0.45), sx = R.sign();+ rocks.add({ kind: B.CHUNK, x: R.range(-0.4, 0.4) * RAD, y: -4, vx: sx * R.range(30, big ? 120 : 150), vy: -R.range(big ? 280 : 320, big ? 480 : 560), g: 1, drag: 0.3, bounce: 0.3, life: R.range(3.6, 5), a: R.range(0, TAU), va: R.range(-14, 14), s: big ? R.range(2.6, 3.8) : R.range(1.2, 2.4), heat: hot ? R.range(0.6, 1) : 0 });+ }+ };++ return {+ update(dt) {+ t += dt;+ while (next < BLASTS.length && t >= BLASTS[next].t) blast(BLASTS[next++]);+ if (t > 0.08) plume.update(dt);+ const S = plume.shape(), k = 1 - smooth(2.2, 3.1, t);+ // the column: smoke and fire boil up off the floor into the fireball, dust is drawn in along the ground+ if (t > 0.2 && t < 3.1) {+ if (R.chance(8 * k * dt)) ps.spawn(P.SMOKE, R.range(-10, 10), -R.range(1, 6), R.range(-8, 8), -R.range(40, 80), R.range(1.5, 2.3), st.dust, R.range(5, 8), 0, PF.BIG);+ if (t < 1.5 && R.chance(16 * dt)) ps.spawn(P.FIRE, R.range(-6, 6), -R.range(4, 14), R.range(-10, 10), -R.range(90, 150), R.range(0.5, 0.8), 0, R.range(4, 7.5), 0, R.chance(0.5) ? PF.SMOKES | PF.BIG : 0);+ if (t > 0.45 && R.chance(12 * k * dt)) {+ const s = R.sign();+ ps.spawn(P.SMOKE, s * R.range(40, 120), -R.range(1, 4), -s * R.range(10, 30), -R.range(0, 5), R.range(1.3, 1.9), st.dust, R.range(3.5, 5.5), 0, PF.BIG);+ }+ }+ // the fireball sheds embers, then ash drifts down out of the cloud+ if (t > 0.3 && t < 3 && R.chance(10 * plume.hot() * dt)) {+ const a = R.range(0, TAU);+ ps.spawn(P.EMBER, S.x + Math.cos(a) * (S.ring + S.tube), S.y + Math.sin(a) * S.tube * 0.5, Math.cos(a) * R.range(40, 90), -R.range(10, 60), R.range(1.2, 2.4), F[3]);+ }+ if (t > 1.4 && t < 4.6 && R.chance(7 * dt)) ps.spawn(P.FLAKE, S.x + R.range(-1, 1) * (S.ring + S.tube), S.y + S.tube * 0.6, R.range(-6, 6), R.range(0, 10), R.range(2, 3), R.pick([SM[1], SM[2], F[2]]), R.range(0.6, 1.2));+ column.update(dt, top(), t > 0.22 && t < 2.5 ? 1 : 0);+ draft(ps, dt, { x: 0, top: S.y + S.tube * 0.4, w: 9 + 7 * Math.min(1, t), up: 170, pull: 130, low: 12, reach: 130, k: 1 - smooth(2.5, 3.8, t) });+ for (const a of [flashes, rings]) for (let i = a.length - 1; i >= 0; i--) if ((a[i].life -= dt) <= 0) a.splice(i, 1);+ // rocks: molten ones cool and trail smoke and flame; every hard landing kicks up dust+ for (const b of rocks.list) b.pvy = b.vy;+ rocks.update(dt);+ for (let i = rocks.list.length - 1; i >= 0; i--) {+ const b = rocks.list[i];+ if (b.x < X0 + 4 || b.x > X1 - 4) {+ rocks.list.splice(i, 1);+ continue;+ }+ if (b.heat > 0) {+ b.heat = Math.max(0, b.heat - dt * 0.3);+ if (!b.rest && b.heat > 0.25) {+ (b.pts ??= []).push({ x: b.x, y: b.y, t });+ if (R.chance(14 * dt)) ps.spawn(P.FIRE, b.x, b.y, b.vx * 0.1, b.vy * 0.1 - 8, R.range(0.16, 0.3), 0, R.range(1.2, 2.2));+ } else if (b.rest && R.chance(3 * b.heat * dt)) ps.spawn(P.SMOKE, b.x, b.y - 1, R.range(-3, 3), -R.range(5, 12), R.range(0.8, 1.4), 0, R.range(1.6, 2.6));+ }+ const landed = (b.pvy > 0 && b.vy <= 0) || (b.rest && !b.dusted);+ if (landed && b.pvy > 60) {+ for (let j = 0; j < 2 + Math.round(b.s); j++) ps.spawn(P.DUST, b.x + R.range(-1.5, 1.5), -0.5, R.sign() * R.range(10, 50), -R.range(2, 20), R.range(0.3, 0.7), st.dust, R.range(1.3, 1 + b.s));+ if (b.heat > 0.5 && !b.dusted) blazes.add(b.x, -0.25, R.range(1.2, 2.2), 0.45);+ }+ if (b.rest) b.dusted = true;+ if (b.pts) while (b.pts.length && t - b.pts[0].t > 0.45) b.pts.shift();+ }+ blazes.update(dt);+ ps.update(dt);+ cull(ps, X0, Y0, X1, Y1);+ lights.update(dt);+ },+ drawBack(p) {+ scorch(p, HR, t, 52, 3.4, 1 - smooth(meta.duration - 1.6, meta.duration - 0.3, t), 3);+ const k = t / 0.6;+ if (k < 1) band(p, 0, 0.5, 132 * ease.outCubic(k), 0.16, Math.max(1, 6 * (1 - k)), 1.15 - k, [st.body, st.light, F[3], F[6]], (g) => Math.sin(g) < 0);+ drawPs(p, ps, "back", FR);+ column.draw(p, top(), FR, SM, 1 - t / 1.4, plume.hot());+ plume.draw(p, FR, SM);+ blazes.drawBack(p);+ },+ draw(p) {+ const k = t / 0.6;+ if (k < 1) band(p, 0, 0.5, 132 * ease.outCubic(k), 0.16, Math.max(1, 6 * (1 - k)), 1.15 - k, [st.body, st.light, F[3], F[6]], (g) => Math.sin(g) >= 0);+ // the first beat: a white hero frame, a dome of white-hot air that cools into the fire, a flare, a shell of light+ if (t < 0.04) {+ dome(p, F, 0, 44, 1);+ p.glow(0, -30, 68, WHITE, 0.6);+ } else if (t < 0.11) dome(p, F, 0, 38 - (t - 0.04) * 120, 1 - (t - 0.04) / 0.07);+ for (const b of rocks.list) {+ if (b.pts) trail(p, b.pts, t, FR, SM, 0.45, 0.6 + b.s * 0.3, b.heat);+ rock(p, b, st, FR);+ }+ drawPs(p, ps, "front", FR);+ if (t < 0.24) flare(p, 0, -14, 70 * Math.pow(1 - t / 0.24, 1.4), 1 - t / 0.24, F);+ if (t < 0.5) {+ const u = t / 0.5, r = 34 + 80 * ease.outCubic(u);+ p.ring(0, 0, r, Math.max(1, 3 * (1 - u) + 0.5), u < 0.3 ? F[6] : u < 0.6 ? F[5] : F[3], (v, a) => (Math.sin(a) > 0 ? 0 : Math.min(1, (1 - u) * 1.6)));+ glowDome(p, 0, 0, r, 6, F[4], 0.35 * (1 - u));+ }+ for (const f of flashes) {+ const k2 = f.life / f.max, r = f.r * (0.8 + 0.2 * k2);+ p.circle(f.x, f.y, r + 1.2, F[2]);+ p.circle(f.x, f.y, r, k2 > 0.45 ? F[6] : F[5]);+ p.circle(f.x, f.y, r * 0.6, k2 > 0.45 ? WHITE : F[6]);+ }+ for (const r of rings) {+ const k2 = r.life / r.max, e = 1 - Math.pow(k2, 3);+ p.ring(r.x, r.y, r.r0 + (r.r1 - r.r0) * e, Math.max(1, r.thick * k2 + 0.4), r.c, Math.min(1, k2 * 1.6));+ }+ // the fireball lights the floor under it while it burns+ const hot = plume.hot(), flash = Math.max(0, 1 - t / 0.9);+ pool(p, 0, 1, 150, 22, F[3], 0.24 * hot + 0.5 * flash * flash);+ lights.draw(p);+ },+ };}diff --git a/src/fx/explosions/cartoon-pow.js b/src/fx/explosions/cartoon-pow.jsindex 8cc2d3e..69d44c8 100644--- a/src/fx/explosions/cartoon-pow.js+++ b/src/fx/explosions/cartoon-pow.js@@ -1,60 +1,97 @@-import { ramp, seg, ease, rng, burst, star, TAU } from "../../core/index.js";-import { fit } from "./_lib.js";+import { Particles, P, Rng, fit, sparkle, clamp, smooth, ease, rand, TAU, WHITE, hex } from "../../core/index.js";+import { cull } 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,+ desc: "A comic-book hit: a jagged two-tone 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: ["cartoon", "comic", "pow", "hit", "impact", "text", "one-shot"],+ size: [184, 144],+ origin: [92, 72],+ duration: 1.05,loop: false,fps: 30,bg: "dark",- options: { palette: ["#1a0810", "#5a0c1c", "#b81c28", "#f0461e", "#ff9a26", "#ffd84a", "#fff6c4"], text: "POW!", seed: 26 },+ options: { palette: ["#1a0e14", "#6e1a12", "#c8361a", "#f47a24", "#ffc23c", "#fff07a", "#ffffff"], text: "POW!", seed: 5 },};-// 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;-}+const N = 14, IN = 0.05, GO = 0.66, END = 0.8;-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] });+export function create(o) {+ const C = fit(o.palette, 7), R = new Rng(o.seed), INK = C[0];+ const ps = new Particles({ rng: R, sparks: [C[6], C[5], C[4], C[3]] });+ // the star's spikes: long and short in turn, each its own length, boiling a little every few frames+ const spikes = Array.from({ length: N * 2 }, (_, i) => ({ r: i % 2 ? R.range(0.5, 0.6) : R.range(0.85, 1.05), j: R.next() * 100 }));+ const lines = Array.from({ length: 16 }, (_, i) => ({ a: ((i + R.range(0.2, 0.8)) / 16) * TAU, r: R.range(0.92, 1.08), L: R.range(10, 17), t0: R.range(0, 0.06) }));+ let t = 0, popped = false, burst = false;+ return {+ update(dt) {+ t += dt;+ if (!burst && t >= IN) {+ burst = true;+ for (let i = 0; i < 22; i++) {+ const a = R.range(0, TAU), sp = R.range(180, 360);+ ps.spawn(P.SPARK, Math.cos(a) * 14, Math.sin(a) * 10, Math.cos(a) * sp, Math.sin(a) * sp, R.range(0.12, 0.3));+ }+ }+ // it snaps away into a scatter of little stars+ if (!popped && t >= GO) {+ popped = true;+ for (let i = 0; i < 14; i++) {+ const a = R.range(0, TAU), sp = R.range(60, 150);+ ps.spawn(P.STAR, Math.cos(a) * 26, Math.sin(a) * 18, Math.cos(a) * sp, Math.sin(a) * sp, R.range(0.25, 0.42), R.pick([C[6], C[5], C[4]]), R.range(1.2, 2.4));+ }+ }+ ps.update(dt);+ cull(ps, -meta.origin[0] + 3, -meta.origin[1] + 3, meta.size[0] - meta.origin[0] - 3, meta.size[1] - meta.origin[1] - 3);+ },+ draw(p) {+ const k = clamp(t / IN);+ // the slam: it punches in past full size, shudders and settles; then it squeezes and snaps away+ const s = t < IN ? 0.25 + 0.95 * ease.outCubic(k) : t < GO ? 1 + 0.18 * Math.exp(-(t - IN) * 18) * Math.cos((t - IN) * 40) : 1 - ease.inBack(clamp((t - GO) / (END - GO)), 2);+ const shake = t < 0.3 ? (1 - t / 0.3) * 2.2 : 0, sx = Math.round(Math.sin(t * 97) * shake), sy = Math.round(Math.cos(t * 83) * shake);+ if (s > 0.02) {+ // the burst star, in one pass: its edge at each angle runs straight from spike tip to notch. An inked edge, a+ // yellow body with halftone dots on its shaded side, an inked orange heart and a yellow core+ const boil = Math.floor(t * 12), outer = 50 * s, rot = -0.1 + (t > GO ? (t - GO) * 3 : 0), M = N * 2;+ const rad = spikes.map((q, i) => q.r * (1 + (rand(i, boil, 7) - 0.5) * 0.08));+ p.shade(sx - outer - 4, sy - outer - 4, sx + outer + 4, sy + outer + 4, (x, y) => {+ const dx = x - sx, dy = (y - sy) / 0.82, d = Math.hypot(dx, dy);+ let u = (((Math.atan2(dy, dx) - rot) / TAU) % 1 + 1) % 1 * M;+ const i = Math.floor(u) % M, f = u - Math.floor(u), r = rad[i] + (rad[(i + 1) % M] - rad[i]) * f, e = d / r;+ if (e > outer + 2.5) return;+ if (e > outer) return INK;+ if (e > outer * 0.66 + 2) return dx * 0.6 + dy * 0.8 > outer * 0.25 && (Math.floor(x) + Math.floor(y) * 2) % 4 === 0 && Math.floor(y) % 2 === 0 ? C[4] : C[5];+ if (e > outer * 0.66) return INK;+ return e > outer * 0.44 ? C[3] : C[4];+ });+ p.glow(sx, sy, outer * 1.3, C[5], 0.3 * Math.min(1, s));+ }+ // action lines flying out, and a ring of impact+ for (const q of lines) {+ const u = (t - IN - q.t0) / 0.32;+ if (u <= 0 || u >= 1) continue;+ const r0 = (46 + 22 * ease.outCubic(u)) * q.r, L = q.L * 0.7 * (1 - u), ca = Math.cos(q.a), sa = Math.sin(q.a) * 0.82;+ p.line(ca * r0, sa * r0, ca * (r0 + L), sa * (r0 + L), (v) => (v < 0.5 ? WHITE : C[5]));}- x += w + 2;- });- }- p.glow(cx, cy, 34 * s, P[4], 0.3 * (1 - seg(t, 0.1, 0.8)));+ const ru = (t - IN) / 0.24;+ if (ru > 0 && ru < 1) p.ring(0, 0, 30 + 34 * ease.outCubic(ru), Math.max(1, 2.5 * (1 - ru)), ru < 0.4 ? WHITE : C[5], 1.1 - ru);+ // the word: letters dropping in one after another, inked, with a deep red extrusion, then a squash as it goes+ const word = String(o.text ?? "POW!"), scale = 3, widths = [...word].map((ch) => p.measure(ch, { font: "big", scale })[0]);+ let x = -(widths.reduce((a, w) => a + w + scale, -scale)) / 2;+ [...word].forEach((ch, i) => {+ const u = (t - IN - 0.04 - i * 0.05) / 0.12, away = clamp((t - GO) / (END - GO - 0.04));+ if (u > 0 && away < 1) {+ const drop = (1 - ease.outBack(clamp(u), 2.4)) * -14, y = Math.round(-11 + drop - i * 1.5 + sy + away * 6);+ const lx = Math.round(x + sx), a = 1 - away;+ // a thick ink edge, a deep red extrusion, a white face going warm toward its foot+ for (let d = 4; d >= 1; d--) p.text(ch, lx + d, y + d, d >= 3 ? INK : C[1], { font: "big", scale, a, outline: d === 4 ? INK : undefined });+ for (const [ox, oy] of [[-2, 0], [2, 0], [0, -2], [0, 2], [-1, -1], [1, -1], [-1, 1], [1, 1]]) p.text(ch, lx + ox, y + oy, INK, { font: "big", scale, a });+ p.text(ch, lx, y, (gx, gy) => (gy < 4 ? C[6] : gy < 6 ? C[5] : C[4]), { font: "big", scale, a });+ }+ x += widths[i] + scale;+ });+ ps.draw(p);+ if (t > IN && t < IN + 0.12) sparkle(p, sx + 34, sy - 22, 6 * (1 - (t - IN) / 0.12), C[6], C[5], 0.6);+ },+ };}diff --git a/src/fx/explosions/chain-explosions.js b/src/fx/explosions/chain-explosions.jsdeleted file mode 100644index 9843097..0000000--- a/src/fx/explosions/chain-explosions.js+++ /dev/null@@ -1,44 +0,0 @@-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.jsindex 2a2201f..9873026 100644--- a/src/fx/explosions/dirt-explosion.js+++ b/src/fx/explosions/dirt-explosion.js@@ -1,56 +1,106 @@-import { PAL, RAMP, ramp, at, seg, ease, clamp, burst, fly, noise2, WHITE, hex } from "../../core/index.js";-import { fit, billow, debris } from "./_lib.js";+// The earth recipe (grit thrown in a fan, rocks that bounce and kick up dust, a dust column and dust rolling out along+// the floor) is adapted from Sprite Fusion's open-source explosion (https://www.spritefusion.com/pixel-art-vfx/explosion),+// MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Bits, Lights, P, PF, B, Rng, fit, band, smooth, ease, TAU, WHITE, hex, mix, rgb } from "../../core/index.js";+import { drawDirt, crater, rock, dome, pool, cull, fadeEdges } 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,+ desc: "A buried charge goes off: a flash under the floor, a V of dirt clods and grit thrown high, a brown dust plume that billows and settles, and a crater left behind.",+ tags: ["explosion", "dirt", "earth", "dust", "debris", "ground", "one-shot"],+ size: [260, 240],+ origin: [130, 206],+ duration: 3.6,loop: false,fps: 30,bg: "ground",- options: { palette: PAL.dust, seed: 22 },+ options: {+ palette: ["#1c1610", "#33281c", "#4f3f2c", "#6e5a40", "#927a58", "#b89f78", "#dcc8a2"],+ fire: ["#4a1712", "#c9281f", "#f2561d", "#ff8a2a", "#ffc23d", "#ffe26b", "#fff3a6", "#ffffff"],+ seed: 3,+ },};-const HOLE = [hex("#0e0b0c"), hex("#1d1614")];+export function create(o) {+ const E = fit(o.palette, 7), F = fit(o.fire, 8), R = new Rng(o.seed), floor = () => 0;+ const [W, H] = meta.size, [OX, OY] = meta.origin, X0 = -OX + 3, X1 = W - OX - 3, Y0 = -OY + 3, Y1 = H - OY - 3;+ const clod = { light: E[5], body: E[3], shade: E[2] }, DUST = mix(E[4], rgb(150, 140, 150), 0.2), SOIL = mix(E[3], rgb(90, 80, 90), 0.2), DARK = mix(E[2], rgb(60, 52, 60), 0.3);+ const ps = new Particles({ rng: R, ground: floor, sparks: [F[6], F[5], F[3], F[2]] }), lights = new Lights();+ const clods = new Bits({ ground: floor });+ let t = 0;-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);+ lights.add(0, -10, 56, F[4], 0.7, 0.22);+ lights.add(0, -4, 26, WHITE, 0.6, 0.06);+ // the charge: a few sparks out of the hole+ for (let i = 0; i < 14; i++) {+ const a = -Math.PI / 2 + R.range(-0.7, 0.7), sp = R.range(160, 320);+ ps.spawn(P.SPARK, 0, -2, Math.cos(a) * sp, Math.sin(a) * sp, R.range(0.15, 0.35));}- // 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));+ // the fountain: grit in a V, clods thrown high, a few pebbles+ for (let i = 0; i < 300; i++) {+ const side = R.sign(), a = -Math.PI / 2 + side * R.range(0.05, 0.62), sp = R.range(150, 470) * (1 - 0.3 * Math.abs(a + Math.PI / 2));+ ps.spawn(P.GRIT, R.range(-4, 4), -1, Math.cos(a) * sp, Math.sin(a) * sp, R.range(1.2, 2.2), R.pick([E[1], E[2], E[2], E[3], E[3], E[4], E[5]]), R.chance(0.45) ? 2 : 1, R.range(0, 0.06));}+ for (let i = 0; i < 30; i++) {+ const side = R.sign(), a = -Math.PI / 2 + side * R.range(0.1, 0.6), sp = R.range(200, 430);+ clods.add({ kind: B.CHUNK, x: R.range(-5, 5), y: -2, vx: Math.cos(a) * sp, vy: Math.sin(a) * sp, g: 1, drag: 0.35, bounce: 0.25, life: R.range(2.2, 3), a: R.range(0, TAU), va: R.range(-12, 12), s: i < 12 ? R.range(2.6, 3.8) : R.range(1.4, 2.4) });+ }+ // the dust: a plume punched straight up, two lobes riding the V, and a skirt rolling out along the floor+ for (let i = 0; i < 22; i++)+ ps.spawn(P.SMOKE, R.range(-7, 7), -R.range(2, 12), R.range(-25, 25), -R.range(70, 180), R.range(1.8, 2.6), R.chance(0.6) ? SOIL : DUST, R.range(9, 14), R.range(0, 0.14), PF.BIG);+ for (let i = 0; i < 14; i++) {+ const side = R.sign(), a = -Math.PI / 2 + side * R.range(0.35, 0.6), sp = R.range(110, 210);+ ps.spawn(P.SMOKE, side * R.range(2, 8), -R.range(2, 8), Math.cos(a) * sp, Math.sin(a) * sp, R.range(1.6, 2.4), R.chance(0.5) ? SOIL : DUST, R.range(8, 12), R.range(0.02, 0.1), PF.BIG);+ }+ for (let i = 0; i < 16; i++) {+ const s = R.sign();+ ps.spawn(P.SMOKE, s * R.range(4, 16), -R.range(1, 5), s * R.range(70, 200), -R.range(2, 12), R.range(1.4, 2.2), DUST, R.range(6, 9), R.range(0.02, 0.1), PF.BIG);+ }+ // dark soil thrown up with it, heavier and lower+ for (let i = 0; i < 8; i++) ps.spawn(P.SMOKE, R.range(-8, 8), -R.range(2, 8), R.range(-40, 40), -R.range(40, 110), R.range(1.2, 1.8), DARK, R.range(6, 9), R.range(0, 0.05));++ return {+ update(dt) {+ t += dt;+ for (const b of clods.list) b.pvy = b.vy;+ clods.update(dt);+ // clods thud down: a puff of dust and a spray of crumbs where they land, the big ones break up+ for (let i = clods.list.length - 1; i >= 0; i--) {+ const b = clods.list[i];+ if (b.x < X0 + 4 || b.x > X1 - 4) {+ clods.list.splice(i, 1);+ continue;+ }+ const landed = (b.pvy > 0 && b.vy <= 0) || (b.rest && !b.thud);+ if (!landed || b.pvy < 80) {+ if (b.rest) b.thud = true;+ continue;+ }+ b.thud = b.rest;+ for (let j = 0; j < 2 + Math.round(b.s); j++) ps.spawn(P.DUST, b.x + R.range(-2, 2), -0.5, R.sign() * R.range(15, 55), -R.range(4, 22), R.range(0.35, 0.7), DUST, R.range(1.6, 1.2 + b.s));+ for (let j = 0; j < Math.round(b.s * 3); j++) ps.spawn(P.GRIT, b.x, -1, R.range(-70, 70), -R.range(40, 140), R.range(0.8, 1.4), R.pick([E[2], E[3], E[4]]), 1);+ if (b.s > 2.2 && b.pvy > 200) b.s *= 0.6;+ }+ ps.update(dt);+ cull(ps, X0, Y0, X1, Y1);+ fadeEdges(ps, X0, X1, 24, Y1);+ lights.update(dt);+ },+ drawBack(p) {+ crater(p, E, 0, 28, ease.outCubic(Math.min(1, t / 0.12)), 1 - smooth(meta.duration - 0.7, meta.duration - 0.1, t));+ const k = t / 0.45;+ if (k < 1) band(p, 0, 0.5, 90 * ease.outCubic(k), 0.16, Math.max(1, 3 * (1 - k)), 1.1 - k, [E[2], E[4], E[5], E[6]], (g) => Math.sin(g) < 0);+ drawDirt(p, ps, "back");+ },+ draw(p) {+ const k = t / 0.45;+ if (k < 1) band(p, 0, 0.5, 90 * ease.outCubic(k), 0.16, Math.max(1, 3 * (1 - k)), 1.1 - k, [E[2], E[4], E[5], E[6]], (g) => Math.sin(g) >= 0);+ // the flash out of the ground: a squat dome of white-hot air for a frame or two+ if (t < 0.09) dome(p, F, 0, 15 * (1 - t * 3), 1 - t / 0.09);+ for (const b of clods.list) rock(p, b, clod, F);+ drawDirt(p, ps, "front");+ pool(p, 0, 1, 60, 10, F[3], 0.5 * Math.max(0, 1 - t / 0.3));+ lights.draw(p);+ },+ };}diff --git a/src/fx/explosions/dust-cloud.js b/src/fx/explosions/dust-cloud.jsdeleted file mode 100644index 9dac744..0000000--- a/src/fx/explosions/dust-cloud.js+++ /dev/null@@ -1,46 +0,0 @@-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.jsindex 5a7730c..dc7475a 100644--- a/src/fx/explosions/firework-burst.js+++ b/src/fx/explosions/firework-burst.js@@ -1,44 +1,147 @@-import { PAL, RAMP, ramp, seg, burst, fly, rand, TAU, WHITE } from "../../core/index.js";-import { fit } from "./_lib.js";+// The flare, the twinkling crosses and the glitter are adapted from Sprite Fusion's open-source sparkle+// (https://www.spritefusion.com/pixel-art-vfx/sparkle), MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Lights, P, Rng, fit, sparkle, ease, TAU, WHITE, hex, mix } from "../../core/index.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,+ desc: "A shell climbs, slows and bursts into a sphere of coloured trailing stars round a gold core; they droop, crackle into white pops and fade, leaving glitter.",+ tags: ["firework", "celebration", "sparkle", "sky", "burst", "one-shot"],+ size: [240, 248],+ origin: [120, 100],+ duration: 3.6,loop: false,fps: 30,bg: "sky",- options: { palette: PAL.neon, count: 60, seed: 28 },+ options: {+ palette: ["#3d0a33", "#701560", "#b0228f", "#f53cd1", "#ff86e6", "#ffd2f6", "#ffffff"],+ core: ["#4a2c08", "#86520c", "#c48412", "#f0b424", "#ffe066", "#fff6c4", "#ffffff"],+ seed: 9,+ },};-// 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));- });+const RISE = 0.42, Y0 = 72, DRAG = 2.6, G = 88, TRAIL = 0.34, TURN = 0.22;++export function create(o) {+ const C = fit(o.palette, 7), K = fit(o.core, 7), R = new Rng(o.seed);+ const ps = new Particles({ rng: R, sparks: [K[6], K[5], K[4], K[3]] }), lights = new Lights();+ const stars = [], pops = [];+ let t = 0, burst = false;++ // a shell of stars thrown over a sphere: seen side-on, the ones flying at us or away look slower+ // the outer stars burn gold for a beat, then turn to their color+ const shell = (n, speed, ramp, life, first) => {+ for (let i = 0; i < n; i++) {+ const z = R.range(-1, 1), a = R.range(0, TAU), s = Math.sqrt(1 - z * z), v = speed * R.range(0.93, 1.05);+ stars.push({ x: 0, y: 0, vx: Math.cos(a) * s * v, vy: Math.sin(a) * s * v, life: R.range(life[0], life[1]), age: 0, ramp, first, big: R.chance(0.2), pts: [], acc: R.next(), seed: R.range(0, 100) });+ }+ };++ return {+ update(dt) {+ t += dt;+ // the shell climbs, slowing, shedding a fizz of gold sparks+ if (t < RISE) {+ const y = Y0 * (1 - ease.outCubic(t / RISE));+ if (R.chance(50 * dt)) ps.spawn(P.SPARK, R.range(-0.5, 0.5), y + 2, R.range(-25, 25), R.range(20, 70), R.range(0.15, 0.35));+ if (R.chance(14 * dt)) ps.spawn(P.VAPOUR, R.range(-1, 1), y + 3, R.range(-3, 3), R.range(5, 15), R.range(0.5, 0.8), hex("#4a4458"), R.range(1.5, 2.5));+ }+ if (!burst && t >= RISE) {+ burst = true;+ lights.add(0, 0, 110, C[4], 0.6, 1.5);+ lights.add(0, 0, 30, WHITE, 0.5, 0.07);+ shell(66, 236, C, [1.35, 1.9], K);+ shell(26, 120, K, [1.0, 1.4], K);+ // the burst charge's smoke, drifting where the shell broke+ for (let i = 0; i < 7; i++) {+ const a = R.range(0, TAU), d = R.range(0, 8);+ ps.spawn(P.VAPOUR, Math.cos(a) * d, Math.sin(a) * d, Math.cos(a) * R.range(10, 30), Math.sin(a) * R.range(10, 30), R.range(2.2, 3), hex("#4a4458"), R.range(6, 11));+ }+ for (let i = 0; i < 24; i++) {+ const a = R.range(0, TAU), sp = R.range(40, 140);+ ps.spawn(P.SPARK, 0, 0, Math.cos(a) * sp, Math.sin(a) * sp, R.range(0.15, 0.35));+ }+ }+ for (let i = stars.length - 1; i >= 0; i--) {+ const s = stars[i];+ s.age += dt;+ const k = s.age / s.life;+ if (k >= 1) {+ // the star crackles out in a few white pops+ for (let j = 0; j < 2 + (s.big ? 1 : 0); j++) pops.push({ x: s.x + R.range(-3, 3), y: s.y + R.range(-3, 3), t0: t + R.range(0, 0.18), life: R.range(0.06, 0.12), c: R.chance(0.6) ? WHITE : s.ramp[5] });+ stars.splice(i, 1);+ continue;+ }+ s.vx -= s.vx * DRAG * dt;+ s.vy -= s.vy * DRAG * dt - G * dt;+ s.x += s.vx * dt;+ s.y += s.vy * dt;+ s.pts.push(s.x, s.y, t);+ while (s.pts.length > 3 && t - s.pts[2] > TRAIL) s.pts.splice(0, 3);+ // glitter shed along the way: specks that hang, twinkle and fall+ for (s.acc += dt * (k < 0.25 ? 4 : 11); s.acc > 1; s.acc--) ps.spawn(P.STAR, s.x, s.y, s.vx * 0.15 + R.range(-6, 6), s.vy * 0.15 + R.range(0, 10), R.range(0.35, 0.8), R.chance(0.5) ? K[5] : WHITE, R.chance(0.15) ? R.range(1, 1.6) : 0.5);+ }+ for (let i = pops.length - 1; i >= 0; i--) if (t > pops[i].t0 + pops[i].life) pops.splice(i, 1);+ ps.update(dt);+ lights.update(dt);+ },+ drawBack(p) {+ ps.draw(p, "back");+ },+ draw(p) {+ if (t < RISE) {+ // the shell: a hot dot with a short tail+ const u = t / RISE, y = Y0 * (1 - ease.outCubic(u));+ p.line(0, y, 0, y + 3 + 6 * (1 - u), (q) => (q < 0.3 ? K[5] : K[3]));+ p.px(0, y, WHITE);+ p.glow(0, y, 7, K[4], 0.5);+ }+ for (const s of stars) {+ const k = s.age / s.life, P2 = s.pts, n = P2.length / 3;+ // the trail: a 1 px line from the head back along where it has been, cooling and dithering out; the part+ // laid while the star burned gold stays gold+ for (let j = n - 1; j > 0; j--) {+ const u = (t - P2[j * 3 + 2]) / TRAIL;+ if (u >= 1) break;+ const ramp = s.age - (t - P2[j * 3 + 2]) < TURN ? s.first : s.ramp;+ const c = u < 0.3 ? ramp[5] : u < 0.6 ? ramp[4] : ramp[3];+ p.line(P2[j * 3], P2[j * 3 + 1], P2[j * 3 - 3], P2[j * 3 - 2], c, Math.pow(1 - u, 0.8) * (1.3 - k * 0.6));+ }+ // the head: white-hot, then its color; late on it flickers before it crackles out+ if (k > 0.72 && Math.sin(t * 60 + s.seed) < -0.2) continue;+ // white only on the burst frame; the glow comes in as the stars spread, so the heart never blooms into a blob+ const ramp = s.age < TURN ? s.first : s.ramp, head = s.age < 0.04 ? WHITE : k < 0.55 ? ramp[s.age < TURN ? 5 : 6] : ramp[5];+ p.px(s.x, s.y, head);+ if (s.big && k < 0.6 && s.age > 0.06) for (const [dx, dy] of [[1, 0], [-1, 0], [0, 1], [0, -1]]) p.px(s.x + dx, s.y + dy, ramp[5]);+ p.glow(s.x, s.y, s.big ? 7 : 5, ramp[4], (s.big ? 0.7 : 0.5) * (1 - k * 0.6) * Math.min(1, s.age / 0.2));+ }+ for (const q of pops) {+ const u = (t - q.t0) / q.life;+ if (u < 0 || u > 1) continue;+ sparkle(p, q.x, q.y, 2.6 * Math.sin(Math.PI * u), q.c, mix(q.c, C[3], 0.5), 0.5);+ }+ // the burst: a flare and a white heart, the sky lit up behind it+ const b = t - RISE;+ if (b >= 0 && b < 0.28) {+ const u = b / 0.28, L = 32 * Math.pow(1 - u, 1.3);+ flareRays(p, 0, 0, L, u * 0.6, C, K);+ if (b < 0.07) p.circle(0, 0, 2.6 - b * 20, WHITE);+ }+ ps.draw(p, "front");+ lights.draw(p);+ },+ };}-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));+// an 8-ray flare: long rays on the axes with a white core and tinted ends, short gold diagonals, turning slowly+function flareRays(p, x, y, L, ang, C, K) {+ if (L < 1) return;+ for (let i = 0; i < 8; i++) {+ const diag = i % 2 === 1, an = ang + (i * TAU) / 8, len = diag ? L * 0.42 : L, ca = Math.cos(an), sa = Math.sin(an);+ for (let d = 0; d <= len; d += 0.5) {+ const u = d / len;+ p.dot(x + ca * d, y + sa * d, diag ? (u < 0.5 ? K[5] : K[4]) : u < 0.3 ? WHITE : u < 0.65 ? C[5] : C[4], u < 0.7 ? 1 : 1 - (u - 0.7) / 0.35);+ }}- 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);+ p.glow(x, y, 4 + L * 1.2, C[4], 0.3);+ p.glow(x, y, 2 + L * 0.3, WHITE, 0.25);}diff --git a/src/fx/explosions/firework-rocket.js b/src/fx/explosions/firework-rocket.jsindex cd7db48..6e11a9b 100644--- a/src/fx/explosions/firework-rocket.js+++ b/src/fx/explosions/firework-rocket.js@@ -1,85 +1,143 @@-import { PAL, RAMP, ramp, seg, ease, burst, stream, fly, rand, TAU, WHITE, hex } from "../../core/index.js";-import { fit } from "./_lib.js";+// The flare, the twinkling glitter and the crackle are adapted from Sprite Fusion's open-source sparkle+// (https://www.spritefusion.com/pixel-art-vfx/sparkle), MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Lights, P, Rng, fit, sparkle, clamp, ease, TAU, WHITE, hex, mix } from "../../core/index.js";+import { cull } 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,+ desc: "A rocket fizzes off the ground on a sparkling gold trail, coasts, and bursts into a palm: heavy gold fronds arc out, droop on glittering trails and crackle at the tips.",+ tags: ["firework", "rocket", "celebration", "sparkle", "sky", "one-shot"],+ size: [300, 300],+ origin: [150, 288],+ duration: 3.8,loop: false,fps: 30,bg: "sky",- options: { palette: PAL.gold, height: 100, arms: 11, seed: 29 },+ options: {+ palette: ["#2a1406", "#6a3a0c", "#b8701a", "#f0a830", "#ffd860", "#fff2b0", "#ffffff"],+ tips: ["#0c2a3a", "#1a5a78", "#36a2c8", "#7cd8f0", "#c8f4ff", "#ffffff"],+ seed: 12,+ },};-const SHELL = [hex("#7a1c24"), hex("#d23a3a"), hex("#ff8a6a")], STICK = hex("#6a4a2a");-const UP = 0.1, TOP = 0.95;+const FLY = 1.05, HIGH = 192, DRAG = 1.35, G = 105, TRAIL = 1.15;-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);+export function create(o) {+ const C = fit(o.palette, 7), T = fit(o.tips, 6), R = new Rng(o.seed);+ const ps = new Particles({ rng: R, sparks: [C[6], C[5], C[4], C[3]] }), lights = new Lights();+ const fronds = [], pops = [];+ const at = (t) => [Math.sin(t * 8) * 1.6 * (t / FLY), -8 - HIGH * ease.outQuad(clamp(t / FLY))];+ let t = 0, burst = false, bx = 0, by = 0, acc = 0;+ lights.add(0, -14, 24, C[4], 0.7, 0.35);+ // ignition: a puff of smoke and a spray of sparks off the ground+ for (let i = 0; i < 18; i++) {+ const a = -Math.PI / 2 + R.range(-1.2, 1.2), sp = R.range(60, 180);+ ps.spawn(P.SPARK, 0, -2, Math.cos(a) * sp, Math.sin(a) * sp * 0.6, R.range(0.15, 0.4));}- 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);+ for (let i = 0; i < 5; i++) ps.spawn(P.VAPOUR, R.range(-3, 3), -2, R.range(-20, 20), -R.range(2, 10), R.range(0.6, 1), hex("#5a5468"), R.range(3, 5));+ return {+ update(dt) {+ t += dt;+ if (t < FLY) {+ // the climb: a hot tail spitting gold sparks, glitter left hanging, a thread of smoke+ const [x, y] = at(t), [x2, y2] = at(Math.max(0, t - 0.02)), vy = (y - y2) / 0.02, vx = (x - x2) / 0.02;+ for (acc += dt * 90; acc > 1; acc--) {+ const a = Math.PI / 2 + R.range(-0.45, 0.45), sp = R.range(30, 110);+ ps.spawn(P.SPARK, x, y + 4, Math.cos(a) * sp + vx * 0.2, Math.sin(a) * sp + vy * 0.15, R.range(0.15, 0.4));+ if (R.chance(0.25)) ps.spawn(P.STAR, x + R.range(-1.5, 1.5), y + R.range(2, 6), R.range(-6, 6), R.range(5, 20), R.range(0.4, 0.9), R.chance(0.5) ? C[5] : WHITE, R.chance(0.15) ? 1.2 : 0.5);+ if (R.chance(0.18)) ps.spawn(P.VAPOUR, x, y + 5, R.range(-4, 4), R.range(4, 12), R.range(0.6, 1.1), hex("#4a4458"), R.range(1.2, 2.2));+ }+ } else if (!burst) {+ burst = true;+ [bx, by] = at(FLY);+ lights.add(bx, by, 82, C[4], 0.8, 1.6);+ lights.add(bx, by, 40, WHITE, 0.6, 0.08);+ // the palm: heavy comets thrown up and out, a few low ones to the sides+ for (let i = 0; i < 9; i++) {+ const a = -Math.PI / 2 + ((i - 4) / 4) * 1.4 + R.range(-0.1, 0.1), sp = R.range(180, 210) * (1 - 0.12 * Math.abs(i - 4) / 4);+ fronds.push({ x: bx, y: by, vx: Math.cos(a) * sp, vy: Math.sin(a) * sp, age: 0, life: R.range(1.8, 2.15), pts: [], acc: R.next(), seed: R.range(0, 100) });+ }+ for (let i = 0; i < 6; i++) ps.spawn(P.VAPOUR, bx + R.range(-4, 4), by + R.range(-4, 4), R.range(-20, 20), R.range(-15, 15), R.range(1.8, 2.6), hex("#4a4458"), R.range(6, 10));+ for (let i = 0; i < 30; i++) {+ const a = R.range(0, TAU), sp = R.range(40, 160);+ ps.spawn(P.SPARK, bx, by, Math.cos(a) * sp, Math.sin(a) * sp, R.range(0.15, 0.35));+ }+ }+ for (let i = fronds.length - 1; i >= 0; i--) {+ const f = fronds[i];+ f.age += dt;+ const k = f.age / f.life;+ if (k >= 1) {+ for (let j = 0; j < 4; j++) pops.push({ x: f.x + R.range(-5, 5), y: f.y + R.range(-5, 5), t0: t + R.range(0, 0.2), life: R.range(0.06, 0.12), c: R.chance(0.5) ? WHITE : T[3] });+ fronds.splice(i, 1);+ continue;+ }+ f.vx -= f.vx * DRAG * dt;+ f.vy -= f.vy * DRAG * dt - G * dt;+ f.x += f.vx * dt;+ f.y += f.vy * dt;+ f.pts.push(f.x, f.y, t);+ while (f.pts.length > 3 && t - f.pts[2] > TRAIL) f.pts.splice(0, 3);+ // glitter shed all along: specks that hang, twinkle and drift down+ for (f.acc += dt * 34; f.acc > 1; f.acc--) ps.spawn(P.STAR, f.x + R.range(-1, 1), f.y + R.range(-1, 1), f.vx * 0.1 + R.range(-5, 5), R.range(0, 14), R.range(0.5, 1.1), R.chance(0.6) ? C[5] : WHITE, R.chance(0.12) ? R.range(1, 1.5) : 0.5);+ }+ for (let i = pops.length - 1; i >= 0; i--) if (t > pops[i].t0 + pops[i].life) pops.splice(i, 1);+ ps.update(dt);+ cull(ps, -meta.origin[0] + 2, -meta.origin[1] + 2, meta.size[0] - meta.origin[0] - 2, meta.size[1] - meta.origin[1] - 2);+ lights.update(dt);+ },+ drawBack(p) {+ ps.draw(p, "back");+ },+ draw(p) {+ if (t < FLY) {+ // the rocket: a little tube on a stick, a white-hot tail flickering under it+ const [x, y] = at(t);+ p.line(x, y + 4, x, y + 12, hex("#5a4030"));+ p.rect(x - 1, y - 3, 3, 7, hex("#b8303a"));+ p.px(x - 1, y - 3, hex("#e86070"));+ p.px(x, y - 4, hex("#d8d0c0"));+ const fl = 2 + (Math.sin(t * 70) > 0 ? 1 : 0);+ p.line(x, y + 4, x, y + 4 + fl, (u) => (u < 0.4 ? WHITE : C[5]));+ p.glow(x, y + 5, 9, C[4], 0.6);+ }+ for (const f of fronds) {+ const k = f.age / f.life, P2 = f.pts, n = P2.length / 3;+ // the frond: a thick gold trail, hot near the head, cooling and dithering out behind+ for (let j = n - 1; j > 0; j--) {+ const u = (t - P2[j * 3 + 2]) / TRAIL;+ if (u >= 1) break;+ const c = u < 0.08 ? C[6] : u < 0.25 ? C[5] : u < 0.5 ? C[4] : u < 0.75 ? C[3] : C[2], a = Math.pow(1 - u, 0.6) * (1.25 - k * 0.45);+ p.line(P2[j * 3], P2[j * 3 + 1], P2[j * 3 - 3], P2[j * 3 - 2], c, a);+ if (u < 0.7) p.line(P2[j * 3] + 1, P2[j * 3 + 1], P2[j * 3 - 3] + 1, P2[j * 3 - 2], u < 0.25 ? C[5] : u < 0.5 ? C[3] : C[2], a * 0.85);+ if (u < 0.35) p.line(P2[j * 3], P2[j * 3 + 1] + 1, P2[j * 3 - 3], P2[j * 3 - 2] + 1, C[3], a * 0.6);+ }+ if (k > 0.8 && Math.sin(t * 55 + f.seed) < 0) continue;+ p.rect(f.x - 0.5, f.y - 0.5, 2, 2, k < 0.5 ? WHITE : C[6]);+ if (k < 0.6) for (const [dx, dy] of [[-1, 0], [2, 0], [0, -1], [0, 2]]) p.px(f.x + dx, f.y + dy, C[5]);+ p.glow(f.x, f.y, 10, C[4], 0.6 * (1 - k * 0.5));+ }+ for (const q of pops) {+ const u = (t - q.t0) / q.life;+ if (u < 0 || u > 1) continue;+ sparkle(p, q.x, q.y, 2.8 * Math.sin(Math.PI * u), q.c, T[2], 0.5);+ }+ // the burst: a white heart for two frames, a flare turning+ const b = t - FLY;+ if (b >= 0 && b < 0.26) {+ const u = b / 0.26, L = 30 * Math.pow(1 - u, 1.3);+ for (let i = 0; i < 8; i++) {+ const diag = i % 2 === 1, an = u * 0.5 + (i * TAU) / 8, len = diag ? L * 0.45 : L, ca = Math.cos(an), sa = Math.sin(an);+ for (let d = 0; d <= len; d += 0.5) {+ const v = d / len;+ p.dot(bx + ca * d, by + sa * d, v < 0.3 ? WHITE : v < 0.65 ? C[5] : C[4], v < 0.7 ? 1 : 1 - (v - 0.7) / 0.35);+ }+ }+ if (b < 0.07) p.circle(bx, by, 2.5, WHITE);+ p.glow(bx, by, 4 + L * 1.2, C[4], 0.35);+ }+ ps.draw(p, "front");+ lights.draw(p);+ },+ };}diff --git a/src/fx/explosions/gas-explosion.js b/src/fx/explosions/gas-explosion.jsdeleted file mode 100644index d64ec3a..0000000--- a/src/fx/explosions/gas-explosion.js+++ /dev/null@@ -1,68 +0,0 @@-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.jsindex 7357ba0..9445937 100644--- a/src/fx/explosions/grenade.js+++ b/src/fx/explosions/grenade.js@@ -1,70 +1,186 @@-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";+// The blast (fire puffs that cool into smoke, sparks, grit, scorch, rings, lights) is adapted from Sprite Fusion's+// open-source explosion (https://www.spritefusion.com/pixel-art-vfx/explosion), MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Bits, Lights, P, PF, B, Rng, fit, band, flare, clamp, smooth, ease, TAU, WHITE, hex, mix, scale, rgb } from "../../core/index.js";+import { fireRamp, heatRamp, drawPs, cull, fadeEdges, scorch, pool, OUTLINE } 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,+ desc: "A grenade is lobbed in, bounces, rolls to a stop with its fuse fizzing, shudders, then blows: a white flash, shrapnel streaks, sparks, a small fireball and a scorch.",+ tags: ["explosion", "grenade", "shrapnel", "fire", "smoke", "ground", "one-shot"],+ size: [300, 200],+ origin: [160, 170],+ duration: 4.2,loop: false,fps: 30,bg: "ground",- options: { palette: PAL.fire, seed: 23 },+ options: {+ palette: ["#4a1712", "#c9281f", "#f2561d", "#ff8a2a", "#ffc23d", "#ffe26b", "#fff3a6", "#ffffff"],+ body: ["#141a10", "#2c3a1e", "#4a5c30", "#6e8446", "#9ab06a"],+ seed: 6,+ },};-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;+const BLOW = 1.62, RB = 6.2;-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);+export function create(o) {+ const F = fit(o.palette, 8), FR = fireRamp(F), HR = heatRamp(FR), G = fit(o.body, 5), R = new Rng(o.seed), floor = () => 0;+ const [W, H] = meta.size, [OX, OY] = meta.origin, X0 = -OX + 3, X1 = W - OX - 3, Y0 = -OY + 3, Y1 = H - OY - 3;+ const ps = new Particles({ rng: R, ground: floor, sparks: [F[6], F[5], F[3], F[2]] }), lights = new Lights(), bits = new Bits({ ground: floor });+ const DUST = hex("#7d7280"), METAL = [hex("#3a3c46"), hex("#6a6e7c"), hex("#a8acb8")];+ // the grenade: lobbed from the left, it bounces, rolls and settles+ const g = { x: -140, y: -70, vx: 168, vy: -150, a: 0, va: -9, rest: false };+ let t = 0, blown = false, bx = 0;++ const blast = () => {+ blown = true;+ bx = g.x;+ const y = -5;+ lights.add(bx, y - 10, 70, mix(F[3], F[6], 0.45), 0.85, 0.5);+ lights.add(bx, y, 30, WHITE, 0.7, 0.07);+ // shrapnel: hot streaks flying straight and far, sparks that fall and bounce+ for (let i = 0; i < 38; i++) {+ const a = R.range(-Math.PI + 0.04, -0.04), sp = R.range(380, 640);+ ps.spawn(P.MOTE, bx, y, Math.cos(a) * sp, Math.sin(a) * sp, R.range(0.12, 0.26), R.pick([F[7], F[6], F[5]]), R.range(0.6, 0.9));}- 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));+ for (let i = 0; i < 60; i++) {+ const a = R.range(0, TAU), sp = R.range(140, 360);+ ps.spawn(P.SPARK, bx, y, Math.cos(a) * sp, Math.sin(a) * sp - 60, R.range(0.2, 0.55));+ }+ // a small fireball that cools into smoke+ for (let i = 0; i < 4; i++) ps.spawn(P.FIRE, bx + R.range(-2, 2), y + R.range(-2, 2), R.range(-15, 15), R.range(-30, -8), R.range(0.16, 0.26), 0, R.range(6, 8));+ for (let i = 0; i < 16; i++) {+ const a = R.range(-Math.PI - 0.2, 0.2), d = R.range(0, 6), sp = R.range(40, 150);+ ps.spawn(P.FIRE, bx + Math.cos(a) * d, y + Math.sin(a) * d, Math.cos(a) * sp, Math.sin(a) * sp * 0.8 - 30, R.range(0.45, 0.9), 0, R.range(3.5, 7), 0, R.chance(0.5) ? PF.SMOKES : 0);+ }+ for (let i = 0; i < 9; i++) {+ const a = R.range(-Math.PI, 0), d = R.range(2, 10);+ ps.spawn(P.SMOKE, bx + Math.cos(a) * d, y + Math.sin(a) * d, Math.cos(a) * 25, -R.range(20, 60), R.range(1.4, 2.1), 0, R.range(6, 10), R.range(0.05, 0.3), PF.BIG);+ }+ for (let i = 0; i < 30; i++) {+ const a = R.range(0, TAU), sp = R.range(30, 120);+ ps.spawn(P.EMBER, bx, y, Math.cos(a) * sp, Math.sin(a) * sp - 50, R.range(0.8, 1.8), F[3]);+ }+ // the casing in pieces, and the floor's grit and dust+ for (let i = 0; i < 12; i++) {+ const a = R.range(-Math.PI + 0.2, -0.2), sp = R.range(150, 330);+ bits.add({ kind: B.SHARD, x: bx, y, vx: Math.cos(a) * sp, vy: Math.sin(a) * sp, g: 1, drag: 0.5, bounce: 0.3, life: R.range(1.4, 2.1), a: R.range(0, TAU), va: R.range(-24, 24), s: R.range(2, 3.5), c: R.pick(METAL) });+ }+ for (let i = 0; i < 70; i++) {+ const u = R.range(-1, 1), a = -Math.PI / 2 + u * 0.8, sp = R.range(100, 300) * (1 - 0.4 * Math.abs(u));+ ps.spawn(P.GRIT, bx + u * 4, -1, Math.cos(a) * sp, Math.sin(a) * sp, R.range(1, 1.8), R.pick([hex("#5a4f6b"), hex("#3e3650"), hex("#776c88")]), R.chance(0.35) ? 2 : 1);+ }+ for (let i = 0; i < 10; i++) {+ const s = R.sign();+ ps.spawn(P.SMOKE, bx + s * R.range(0, 6), -R.range(1, 4), s * R.range(60, 180), -R.range(2, 10), R.range(1, 1.7), DUST, R.range(5, 8), R.range(0, 0.05), PF.BIG);+ }+ };++ return {+ update(dt) {+ t += dt;+ if (!blown) {+ // the lob, the bounces, the roll+ if (!g.rest) {+ g.vy += 900 * dt;+ g.x += g.vx * dt;+ g.y += g.vy * dt;+ if (g.y >= -RB && g.vy > 0) {+ g.y = -RB;+ if (g.vy > 90) {+ // a clink, a puff of dust+ for (let i = 0; i < 4; i++) ps.spawn(P.DUST, g.x + R.range(-2, 2), -0.5, R.sign() * R.range(10, 40), -R.range(4, 16), R.range(0.3, 0.6), DUST, R.range(1.5, 2.6));+ for (let i = 0; i < 3; i++) ps.spawn(P.SPARK, g.x, -1, R.range(-60, 60), -R.range(40, 120), R.range(0.08, 0.16));+ g.vy = -g.vy * 0.36;+ g.vx *= 0.8;+ } else g.vy = 0;+ }+ if (g.y >= -RB - 0.01 && g.vy === 0) {+ g.vx -= g.vx * 2.4 * dt;+ g.va = -g.vx / RB;+ if (Math.abs(g.vx) < 3) (g.rest = true), (g.vx = 0);+ }+ g.a += g.va * dt;+ }+ // the fuse: sparks spitting off its tip, a thread of smoke, faster as it runs down+ const tip = fuse(g), hurry = smooth(BLOW - 0.5, BLOW, t);+ if (R.chance((24 + 50 * hurry) * dt)) ps.spawn(P.SPARK, tip[0], tip[1], R.range(-50, 50), -R.range(30, 110), R.range(0.08, 0.2));+ if (R.chance(9 * dt)) ps.spawn(P.VAPOUR, tip[0], tip[1] - 1, R.range(-4, 4), -R.range(10, 20), R.range(0.5, 0.9), hex("#8a8494"), R.range(1.2, 2));+ if (t >= BLOW) blast();+ }+ bits.update(dt);+ for (let i = bits.list.length - 1; i >= 0; i--) if (bits.list[i].x < X0 + 3 || bits.list[i].x > X1 - 3 || bits.list[i].y < Y0 + 3) bits.list.splice(i, 1);+ ps.update(dt);+ cull(ps, X0, Y0, X1, Y1);+ fadeEdges(ps, X0, X1, 24, Y1);+ lights.update(dt);+ },+ drawBack(p) {+ if (blown) {+ const u = t - BLOW;+ scorch(p, HR, u, 22, 1.6, 1 - smooth(meta.duration - BLOW - 0.8, meta.duration - BLOW - 0.15, u), 2);+ const k = u / 0.4;+ if (k < 1) band(p, bx, 0.5, 70 * ease.outCubic(k), 0.16, Math.max(1, 3.5 * (1 - k)), 1.15 - k, [hex("#4a3f69"), hex("#6e6390"), F[3], F[6]], (g2) => Math.sin(g2) < 0);+ }+ drawPs(p, ps, "back", FR);+ },+ draw(p) {+ if (!blown) {+ // the grenade, shuddering in its last half second, the fuse glowing+ const shake = smooth(BLOW - 0.45, BLOW, t), jx = shake * Math.sin(t * 90) * 0.8;+ drawGrenade(p, G, g.x + jx, g.y, g.a);+ const tip = fuse({ ...g, x: g.x + jx });+ p.px(tip[0], tip[1], Math.sin(t * 50) > 0 ? F[6] : F[5]);+ p.glow(tip[0], tip[1], 6 + 3 * shake, F[4], 0.5 + 0.3 * Math.sin(t * 37));+ } else {+ const u = t - BLOW, k = u / 0.4;+ if (k < 1) band(p, bx, 0.5, 70 * ease.outCubic(k), 0.16, Math.max(1, 3.5 * (1 - k)), 1.15 - k, [hex("#4a3f69"), hex("#6e6390"), F[3], F[6]], (g2) => Math.sin(g2) >= 0);+ }+ bits.draw(p);+ drawPs(p, ps, "front", FR);+ if (blown) {+ const u = t - BLOW;+ // the flash: a hot disc for two frames, a flare, a ring of light+ if (u < 0.07) {+ const k2 = 1 - u / 0.07, r = 11 * (0.8 + 0.2 * k2);+ p.circle(bx, -6, r + 1.2, F[2]);+ p.circle(bx, -6, r, k2 > 0.45 ? F[6] : F[5]);+ p.circle(bx, -6, r * 0.6, k2 > 0.45 ? WHITE : F[6]);+ }+ if (u < 0.2) flare(p, bx, -6, 40 * Math.pow(1 - u / 0.2, 1.4), 1 - u / 0.2, F);+ if (u < 0.3) {+ const k3 = u / 0.3, e = 1 - Math.pow(1 - k3, 3);+ const r = 8 + 40 * e;+ p.ring(bx, -6, r, Math.max(1, 2.5 * (1 - k3) + 0.4), F[5], (v, an) => (Math.sin(an) * r > 9 ? 0 : Math.min(1, (1 - k3) * 1.6)));+ }+ pool(p, bx, 1, 70, 12, F[3], 0.55 * Math.max(0, 1 - u / 0.6));+ }+ lights.draw(p);+ },+ };+}++// where the fuse's tip is: on top of the grenade, turning with it+function fuse(g) {+ const ca = Math.cos(g.a), sa = Math.sin(g.a);+ return [g.x + sa * 10.4, g.y - ca * 10.4];+}++// a pineapple grenade turned by a (about 11 x 15 px): an oval body with grooves, lit from the top left, an+// outline, a metal cap with a ring pin, a lever down its side+function drawGrenade(p, G, x, y, a) {+ const ca = Math.cos(a), sa = Math.sin(a), M = [hex("#2a2c36"), hex("#5e6270"), hex("#9a9eac"), hex("#d0d4de")];+ p.shade(x - 13, y - 13, x + 13, y + 13, (px, py) => {+ const dx = px - x, dy = py - y, u = dx * ca + dy * sa, v = -dx * sa + dy * ca; // u across, v along (cap at v < 0)+ // the cap, its ring, and the lever pressed down the side+ if (v < -5 && v > -10.2 && Math.abs(u) < 2.4) return v < -9.4 || Math.abs(u) > 1.7 ? M[0] : u < -0.6 ? M[3] : M[2];+ if (Math.hypot(u + 3.4, v + 8) < 1.9 && Math.hypot(u + 3.4, v + 8) > 0.9) return M[2];+ if (u > 2.2 && u < 3.6 && v > -8.6 && v < 2) return u > 3 ? M[0] : M[1];+ const e = (u / 5.1) ** 2 + ((v - 0.6) / 6.4) ** 2;+ if (e > 1.2) return;+ if (e > 1) return OUTLINE;+ // grooves cut the body into knobbly segments; light from the top left in world space+ const lit = -(dx * 0.6 + dy * 0.8) / 6, gv = Math.abs(((v + 30) % 3.1) - 1.55) < 0.45, gu = Math.abs(((u + 30) % 3.4) - 1.7) < 0.45;+ const i = Math.max(0, Math.min(4, Math.round(2 + lit * 1.7 - (gv || gu ? 1 : 0) + (e < 0.3 && lit > 0.3 ? 1 : 0))));+ return G[i];});- 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.jsindex 1394dd0..a5688ab 100644--- a/src/fx/explosions/implosion.js+++ b/src/fx/explosions/implosion.js@@ -1,65 +1,112 @@-import { ramp, seg, ease, burst, clamp, TAU, WHITE } from "../../core/index.js";-import { fit } from "./_lib.js";+// The gathering streaks, the pulse rings and the release (cross flare, rings, light) are adapted from Sprite Fusion's+// open-source energy charge (https://www.spritefusion.com/pixel-art-vfx/energy), MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Lights, P, Rng, fit, sparkle, clamp, smooth, ease, TAU, WHITE, hex, mix } from "../../core/index.js";+import { cull } 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,+ desc: "Everything is sucked in: streaks and grit rush inward, rings contract and a dark sphere collapses onto a crushed white point; a beat of stillness, then a sharp pop.",+ tags: ["implosion", "energy", "magic", "collapse", "pop", "one-shot"],+ size: [208, 184],+ origin: [104, 92],+ duration: 1.65,loop: false,fps: 30,bg: "dark",- options: { palette: ["#07050f", "#1a1030", "#33265e", "#574ea0", "#928cdc", "#d4d0ff", "#ffffff"], radius: 34, seed: 30 },+ options: { palette: ["#0a0614", "#1c1236", "#3a2470", "#6a44c0", "#a080f0", "#d8c8ff", "#ffffff"], seed: 2 },};-const POP = 1.05;+const SUCK = 0.8, STILL = 1.02, VOID = hex("#05040a");-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);+export function create(o) {+ const C = fit(o.palette, 7), R = new Rng(o.seed);+ const ps = new Particles({ rng: R, sparks: [C[6], C[5], C[4], C[3]] }), lights = new Lights();+ // grit pulled in: specks that spiral toward the middle, faster and faster+ const grit = Array.from({ length: 70 }, () => {+ const t0 = R.range(0, 0.4);+ return { a: R.range(0, TAU), d: R.range(40, 86), t0, T: R.range(0.3, SUCK - 0.04 - t0), spin: R.sign() * R.range(0.6, 1.6), c: R.pick([C[2], C[3], C[4], hex("#4a4458"), hex("#6e6880")]) };});- // 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);+ const rays = Array.from({ length: 4 }, (_, i) => (i * TAU) / 4 + Math.PI / 4);+ let t = 0, popped = false;+ return {+ update(dt) {+ t += dt;+ if (t < SUCK - 0.26) {+ // streaks of light rushing in from all round, accelerating, more of them as it goes+ const k = t / SUCK;+ for (let n = 0; n < 1 + Math.floor(k * 4); n++) {+ if (!R.chance(0.9)) continue;+ const a = R.range(0, TAU), D = R.range(34, 82) * (1 - 0.3 * k), T = R.range(0.14, 0.24), v = (D * 3) / (Math.exp(3 * T) - 1);+ ps.spawn(P.STREAK, Math.cos(a) * D, Math.sin(a) * D, -Math.cos(a) * v, -Math.sin(a) * v, T, R.chance(0.5) ? C[5] : C[4]);+ }+ // vapour drawn in along the way+ if (R.chance(14 * dt)) {+ const a = R.range(0, TAU), D = R.range(50, 80);+ ps.spawn(P.VAPOUR, Math.cos(a) * D, Math.sin(a) * D, -Math.cos(a) * 90, -Math.sin(a) * 90, R.range(0.4, 0.6), C[3], R.range(3, 5));+ }+ }+ if (!popped && t >= STILL) {+ popped = true;+ lights.add(0, 0, 90, C[4], 1, 0.4);+ lights.add(0, 0, 30, WHITE, 0.9, 0.08);+ for (let i = 0; i < 34; i++) {+ const a = R.range(0, TAU), sp = R.range(120, 330);+ ps.spawn(R.chance(0.6) ? P.MOTE : P.STAR, 0, 0, Math.cos(a) * sp, Math.sin(a) * sp, R.range(0.2, 0.45), R.pick([C[6], C[5], C[4]]), R.range(0.8, 1.8));+ }+ }+ ps.update(dt);+ cull(ps, -meta.origin[0] + 3, -meta.origin[1] + 3, meta.size[0] - meta.origin[0] - 3, meta.size[1] - meta.origin[1] - 3);+ lights.update(dt);+ },+ draw(p) {+ const k = clamp(t / SUCK);+ if (t < STILL) {+ // the void: a dark sphere edged with light, collapsing onto the core+ const vr = 64 * (1 - ease.inCubic(k)) + 3;+ if (k < 1) {+ p.disc(0, 0, vr, VOID, 0.35 + 0.35 * k);+ p.ring(0, 0, vr + 1, 1, k < 0.5 ? C[3] : C[4], 0.5 + 0.5 * k);+ p.glowRing(0, 0, vr, 5, C[4], 0.18 + 0.3 * k);+ }+ // rings pulled in after it, one after another, brighter as they go+ for (let i = 0; i < 4; i++) {+ const u = (t - i * 0.17) / 0.34;+ if (u <= 0 || u >= 1) continue;+ const r = (70 - i * 8) * (1 - ease.inQuad(u)) + 2;+ p.ring(0, 0, r, u > 0.7 ? 2 : 1, u > 0.6 ? C[5] : C[3], 0.4 + 0.6 * u);+ }+ // the grit, spiralling in+ for (const q of grit) {+ const u = (t - q.t0) / q.T;+ if (u <= 0 || u >= 1) continue;+ const d = q.d * (1 - ease.inCubic(u)), a = q.a + q.spin * ease.inQuad(u) * 2, x = Math.cos(a) * d, y = Math.sin(a) * d;+ const x2 = Math.cos(a - q.spin * 0.1) * (d + 4 * u * u + 0.5), y2 = Math.sin(a - q.spin * 0.1) * (d + 4 * u * u + 0.5);+ p.line(x2, y2, x, y, (v) => (v < 0.5 ? mix(q.c, VOID, 0.4) : q.c));+ }+ // the core: growing hotter as it's crushed, then a white point trembling in the stillness+ const still = t > SUCK, jit = still ? (Math.floor(t * 40) % 2 ? 0.5 : -0.5) : 0, cr = still ? 1.6 : 1 + 3.5 * (1 - k) * k * 4;+ p.disc(jit, 0, cr + 3.5, VOID, 0.85);+ p.circle(jit, 0, cr + 1.2, C[4]);+ p.circle(jit, 0, cr, WHITE);+ p.glow(0, 0, 10 + 26 * k, C[4], 0.3 + 0.5 * k);+ if (still) p.glow(0, 0, 8, WHITE, 0.4 + 0.2 * Math.sin(t * 60));+ } else {+ // the pop: a white point bursting, a cross flare, a fast thin ring and a slower one+ const q = (t - STILL) / 0.5, e = ease.outCubic(clamp(q));+ if (q < 0.08) p.circle(0, 0, 6 * (1 - q / 0.08) + 1, WHITE);+ if (q < 0.35) {+ const L = (1 - q / 0.35) * 34 + 3;+ for (const a of rays) for (let d = 0; d <= L; d += 0.5) p.dot(Math.cos(a) * d, Math.sin(a) * d, d < L * 0.4 ? WHITE : C[5], d < L * 0.7 ? 1 : 1 - (d / L - 0.7) / 0.3);+ for (const a of rays) for (let d = 0; d <= L * 0.45; d += 0.5) p.dot(Math.cos(a + Math.PI / 4) * d, Math.sin(a + Math.PI / 4) * d, C[5], 1 - d / (L * 0.45));+ }+ if (q < 1) {+ p.ring(0, 0, 4 + 74 * e, Math.max(1, 2.5 * (1 - q)), q < 0.2 ? WHITE : C[5], 1.15 - q);+ p.ring(0, 0, 2 + 40 * ease.outCubic(clamp(q * 1.4)), 1, C[4], 1 - q);+ }+ if (q < 0.6) sparkle(p, 0, 0, 5 * (1 - q / 0.6), WHITE, C[5], 0.6);+ }+ ps.draw(p);+ lights.draw(p);+ },+ };}diff --git a/src/fx/explosions/mine-blast.js b/src/fx/explosions/mine-blast.jsdeleted file mode 100644index 2859b7a..0000000--- a/src/fx/explosions/mine-blast.js+++ /dev/null@@ -1,76 +0,0 @@-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.jsindex b292bc9..b06c5b8 100644--- a/src/fx/explosions/nuke.js+++ b/src/fx/explosions/nuke.js@@ -1,95 +1,182 @@-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";+// The fire puffs, sparks and embers are adapted from Sprite Fusion's open-source explosion+// (https://www.spritefusion.com/pixel-art-vfx/explosion), MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Lights, P, PF, Rng, fit, band, clamp, smooth, ease, lerp, TAU, WHITE, hex, mix } from "../../core/index.js";+import { fireRamp, drawPs, draft, cull, fadeEdges, pool, haze, glowDome, Plume, Column } 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.",+ desc: "A blinding white frame, then a fireball lifts on a thin stem into a wide rolling cap that glows from inside; a white skirt flashes and a dust surge sweeps the floor.",tags: ["explosion", "nuke", "mushroom", "cloud", "big", "ground", "one-shot"],- size: [176, 172],- origin: [88, 156],- duration: 4.4,+ size: [400, 320],+ origin: [200, 284],+ duration: 9,loop: false,fps: 30,bg: "ground",- options: { palette: PAL.fire, size: 1, seed: 35 },+ options: { palette: ["#4a1712", "#c9281f", "#f2561d", "#ff8a2a", "#ffc23d", "#ffe26b", "#fff3a6", "#ffffff"], dust: "#8a7466", seed: 5 },};-// 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]];+const FLASH = 0.05, LIFT = 0.07, SKIRT = [0.55, 1.75];+// the cap's smoke: a lit crescent, two mid tones, a dark underside, the darkest hollow+const CAP = ["#a0918c", "#7c6f6e", "#5f5458", "#40373f", "#271f27"].map(hex);-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);+export function create(o) {+ const F = fit(o.palette, 8), FR = fireRamp(F), R = new Rng(o.seed), floor = () => 0, dust = hex(o.dust);+ const DUST = [mix(dust, WHITE, 0.22), dust, mix(dust, hex("#3a3040"), 0.35), mix(dust, hex("#2a2330"), 0.6), mix(dust, hex("#1c1720"), 0.8)];+ const [W, H] = meta.size, [OX, OY] = meta.origin, X0 = -OX + 3, X1 = W - OX - 3, Y0 = -OY + 3, Y1 = H - OY - 3;+ const ps = new Particles({ rng: R, ground: floor, sparks: [F[6], F[5], F[3], F[2]] }), lights = new Lights();+ // a wide, flat cap rolling like a torus: lobes go up the middle, out over the top and curl under at the rim+ const plume = new Plume(R, {+ x: 0, y: -26, rise: 152, tau: 1.7, drift: 3, tube: [14, 26], ring: [4, 46], grow: 1.6, n: 50, size: [9.5, 14.5], swell: 0.45,+ spin: 2.4, spinTau: 2.4, heat: 1.25, cool: 0.42, under: 0.6, tilt: 0.16, squash: 0.48, fade: [6.0, 8.3], spread: 26,+ style: 1, inner: true, hollow: true, fray: [4, 1.6, 6.4],});- // ---- 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) });+ plume.onFray = (x, y, r, ux, uy) => ps.spawn(P.SMOKE, x, y, ux * R.range(10, 26), uy * R.range(4, 12) - R.range(2, 8), R.range(1, 1.7), CAP[R.int(0, 1)], r * R.range(0.3, 0.45));+ // a thin stem that keeps feeding the cap, then breaks up from the bottom+ const column = new Column(R, { w: 3.5, foot: 22, speed: 125, size: [5.5, 7], n: 84, sway: 1.4, style: 1 });+ const top = () => { const S = plume.shape(); return S.y + S.tube * 0.3; };+ // the condensation skirt: a veil arching over the cap and a bell flaring round the stem+ const veil = Array.from({ length: 72 }, (_, i) => ({ a: -Math.PI * ((i + R.range(0.2, 0.8)) / 72), s: R.range(6, 10), w: R.range(0.97, 1.06), e: R.range(0.6, 1.3), dx: R.range(-1, 1), dy: R.range(-1, 0.2) }));+ const skirt = Array.from({ length: 110 }, () => ({ ph: R.range(0, TAU), v: R.range(0, 1), s: R.range(5, 9), w: R.range(0.9, 1.06), e: R.range(0.6, 1.3), dx: R.range(-1, 1), dy: R.range(-1, 0.4) }));+ let t = 0, boomed = false;++ const boom = () => {+ lights.add(0, -60, 150, F[4], 0.7, 1.6);+ // the fireball's first fire, sparks and embers+ for (let i = 0; i < 26; i++) {+ const a = R.range(-Math.PI, 0), d = R.range(4, 22), sp = R.range(40, 160);+ ps.spawn(P.FIRE, Math.cos(a) * d, -26 + Math.sin(a) * d, Math.cos(a) * sp, Math.sin(a) * sp * 0.7 - 30, R.range(0.6, 1.1), 0, R.range(7, 12), 0, R.chance(0.5) ? PF.SMOKES | PF.BIG : 0);}- }- 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);+ for (let i = 0; i < 90; i++) {+ const a = R.range(-Math.PI - 0.3, 0.3), sp = R.range(200, 420);+ ps.spawn(P.SPARK, Math.cos(a) * 18, -26 + Math.sin(a) * 18, Math.cos(a) * sp, Math.sin(a) * sp - 60, R.range(0.3, 0.8));+ }+ for (let i = 0; i < 50; i++) {+ const a = R.range(-Math.PI, 0), sp = R.range(30, 140);+ ps.spawn(P.EMBER, Math.cos(a) * 20, -26 + Math.sin(a) * 20, Math.cos(a) * sp, Math.sin(a) * sp - 60, R.range(1.6, 3.4), F[3]);}- // 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);+ // the base surge: dust thrown out along the floor in every direction, racing to the edges; a slower ring behind+ for (let i = 0; i < 120; i++) {+ const slow = i >= 92, a = R.range(0, TAU), c = Math.cos(a), s = Math.sin(a), sp = slow ? R.range(110, 200) : R.range(240, 440);+ ps.spawn(P.SMOKE, c * 14, s * 14 * 0.16 - R.range(1, 3), c * sp, s * sp * (s > 0 ? 0.06 : 0.14) - R.range(0, slow ? 6 : 3), R.range(1.8, 3), dust, slow ? R.range(8, 11) : R.range(5, 9), R.range(0.05, 0.2));}- return at(SMK, 0.18 + lit * 0.3 + v * 0.3 + n * 0.12);+ for (let i = 0; i < 40; i++) {+ const u = R.range(-1, 1), a = -Math.PI / 2 + u * 0.7, sp = R.range(150, 380) * (1 - 0.4 * Math.abs(u));+ ps.spawn(P.GRIT, u * 12, -1, Math.cos(a) * sp, Math.sin(a) * sp, R.range(1.2, 2), R.pick(DUST.slice(0, 3)), R.chance(0.4) ? 2 : 1);+ }+ };++ return {+ update(dt) {+ t += dt;+ if (!boomed && t >= LIFT) (boomed = true), boom();+ if (t >= LIFT) plume.update(dt);+ const S = plume.shape(), hot = plume.hot();+ column.update(dt, top(), t > 0.35 && t < 4.9 ? 1 : 0);+ // afterwinds: dust drawn in along the floor and up the stem+ if (t > 0.9 && t < 4.6 && R.chance(9 * dt)) {+ const s = R.sign();+ ps.spawn(P.VAPOUR, s * R.range(50, 160), -R.range(2, 6), -s * R.range(20, 45), -R.range(0, 6), R.range(1.2, 1.8), DUST[1], R.range(5, 8));+ }+ if (t > 0.3 && t < 3.4 && R.chance(14 * hot * dt)) {+ const a = R.range(0, TAU);+ ps.spawn(P.EMBER, S.x + Math.cos(a) * (S.ring + S.tube), S.y + Math.sin(a) * S.tube * 0.5, Math.cos(a) * R.range(30, 80), -R.range(10, 50), R.range(1.4, 2.6), F[3]);+ }+ draft(ps, dt, { x: 0, top: S.y + S.tube * 0.3, w: 9, up: 160, pull: 120, low: 14, reach: 170, k: 1 - smooth(4.4, 5.4, t) });+ ps.update(dt);+ cull(ps, X0, Y0, X1, Y1);+ fadeEdges(ps, X0, X1, 34, Y1);+ lights.update(dt);+ },+ drawBack(p) {+ if (t < FLASH) return;+ const S = plume.shape();+ // the ground shock: a ring racing out along the floor ahead of the dust (far half)+ const k = (t - LIFT) / 0.8;+ if (k > 0 && k < 1) band(p, 0, 0.5, 196 * ease.outCubic(k), 0.16, Math.max(1, 5 * (1 - k)), 1.15 - k, [DUST[2], DUST[0], F[5], F[7]], (g) => Math.sin(g) < 0);+ drawPs(p, ps, "back", FR);+ skirtDraw(p, t, S, veil, skirt, true);+ plume.draw(p, FR, CAP);+ // the dark hollow under the cap where the stem goes in, its heart still warm while the inside glows+ const E = plume.ember(), gone = smooth(plume.o.fade[0], plume.o.fade[1] - 0.6, t - LIFT);+ if (gone < 1) {+ const hy = S.y + S.tube * 0.42, rx = S.ring * 0.7 + 5, ry = S.tube * 0.28 + 2;+ haze(p, 0, hy, rx, ry, (d) => (d < 0.55 * E ? mix(CAP[4], FR[d < 0.3 * E ? 5 : 6], 0.75 * E) : CAP[4]), (d) => (d < 0.6 ? 0.8 : d < 0.85 ? 0.5 : 0.22) * (1 - gone));+ }+ column.draw(p, top(), FR, DUST, clamp(1 - t / 1.8), E * 0.8);+ skirtDraw(p, t, S, veil, skirt, false);+ pool(p, 0, 1, 140, 16, F[3], 0.3 * plume.hot());+ },+ draw(p) {+ // the blinding frame: a white-hot core in a wash of white light that fades out before the canvas edges+ if (t < FLASH) {+ wash(p, OX, OY, W, H, 0, -40, WHITE, 1.6);+ return p.circle(0, -40, 64, WHITE);+ }+ const k = (t - LIFT) / 0.8;+ if (k > 0 && k < 1) band(p, 0, 0.5, 196 * ease.outCubic(k), 0.16, Math.max(1, 5 * (1 - k)), 1.15 - k, [DUST[2], DUST[0], F[5], F[7]], (g) => Math.sin(g) >= 0);+ // out of the white: a crisp white-hot sphere, cooling into the fireball+ const f = (t - FLASH) / 0.13;+ if (f < 1) {+ const r = 22 + 8 * f;+ p.circle(0, -26, r + 1.5, F[2]);+ p.circle(0, -26, r, f < 0.5 ? F[6] : F[5]);+ p.circle(0, -26, r * 0.62, f < 0.5 ? WHITE : F[6]);+ }+ drawPs(p, ps, "front", FR);+ // the shock in the air: a thin bright shell racing out from the fireball, cut off by the floor and the canvas+ const u = (t - FLASH) / 0.7;+ if (u < 1) {+ const r = 30 + 250 * ease.outCubic(u), cy = -26;+ const out = (a) => cy + Math.sin(a) * r > 0 || Math.abs(Math.cos(a) * r) > OX - 3 || cy + Math.sin(a) * r < 3 - OY;+ p.ring(0, cy, r, Math.max(1, 2.5 * (1 - u)), u < 0.3 ? WHITE : F[6], (v, a) => (out(a) ? 0 : 1.1 - u));+ glowDome(p, 0, cy, r, 7, F[5], 0.3 * (1 - u), [3 - OX, 3 - OY, W - OX - 4, 0]);+ }+ // the light of it: everything washed white, falling away fast, then the fireball's own warm light+ const w = Math.exp(-(t - FLASH) / 0.13);+ if (w > 0.02) wash(p, OX, OY, W, H, 0, -40, WHITE, 0.9 * w);+ lights.draw(p);+ },+ };+}++// light over most of the canvas, brightest near (cx, cy), falling to nothing just inside the canvas edges so it+// never shows the canvas as a box+function wash(p, OX, OY, W, H, cx, cy, c, k) {+ const rx = Math.min(OX + cx, W - OX - cx) - 4, up = OY + cy - 4, down = H - OY - cy - 4;+ p.shade(-OX, -OY, W - OX - 1, H - OY - 1, (x, y, out) => {+ const d = Math.hypot((x - cx) / rx, (y - cy) / (y < cy ? up : down));+ out.l = c;+ out.k = k * (1 - smooth(0, 1, d));});- // ---- 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);+}++// the condensation skirt: a white veil that flashes over the cap and a bell that flares round the stem, edged with a+// crisp white rim, then evaporates into wisps that drift apart and thin; far half behind the cloud, near in front+function skirtDraw(p, t, S, veil, skirt, back) {+ const u = (t - SKIRT[0]) / (SKIRT[1] - SKIRT[0]);+ if (u <= 0 || u >= 1) return;+ const a = Math.min(1, u / 0.06) * Math.pow(1 - u, 1.5) * 0.6, capR = (S.ring + S.tube) * 1.1, y0 = S.y + S.tube * 0.3, y1 = S.y * 0.55;+ if (!back) {+ for (const q of veil) {+ const ev = u * u * q.e, R = capR * q.w * (1 + ev * 0.2);+ p.disc(Math.cos(q.a) * R + q.dx * ev * 10, S.y + Math.sin(q.a) * (S.tube * 1.15 + 6) * q.w + q.dy * ev * 8, q.s * (1 - 0.5 * u), WHITE, a * 0.38);+ }+ }+ for (const q of skirt) {+ const z = Math.sin(q.ph);+ if (z < 0 !== back) continue;+ const R = lerp(capR * 0.82, 13, Math.pow(q.v, 0.6)) * q.w, ev = u * u * q.e;+ const x = Math.cos(q.ph) * R * (1 + ev * 0.25) + q.dx * ev * 10, y = lerp(y0, y1, q.v) + z * R * 0.18 + q.dy * ev * 8;+ p.disc(x, y, q.s * (1 - 0.55 * u), WHITE, a * (back ? 0.3 : 0.55) * (1 - q.v * 0.3));+ }+ // the bell's crisp lower edge, dithering away as it evaporates+ if (u < 0.7) {+ const R = 13 * 1.25, k = 1 - u / 0.7;+ for (let i = 0; i < 64; i++) {+ const g = (i / 64) * TAU, z = Math.sin(g);+ if (z < 0 !== back) continue;+ p.dot(Math.cos(g) * R * (1 + u * 0.6), y1 + 2 + z * R * 0.22, WHITE, k * (back ? 0.6 : 1));+ }}- 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.jsindex 61c42d7..5ab1c80 100644--- a/src/fx/explosions/plasma-explosion.js+++ b/src/fx/explosions/plasma-explosion.js@@ -1,68 +1,128 @@-import { PAL, RAMP, ramp, at, seg, ease, burst, fly, flyV, fbm, rng, bolt, TAU, WHITE } from "../../core/index.js";-import { fit } from "./_lib.js";+// The release (flash, rings, flare, light) and the arcs are adapted from Sprite Fusion's open-source energy+// (https://www.spritefusion.com/pixel-art-vfx/energy), MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Lights, P, Rng, rng, fit, band, bolt, forks, flare, sparkle, clamp, smooth, ease, noise, TAU, WHITE } from "../../core/index.js";+import { cull } 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,+ desc: "A blue-violet energy blast with no smoke: a white flash, a ball of plasma swelling into a thinning shell, shock rings in and out of depth, lightning arcs crackling off it.",+ tags: ["explosion", "plasma", "energy", "electric", "magic", "sci-fi", "one-shot"],+ size: [224, 200],+ origin: [112, 100],+ duration: 1.7,loop: false,fps: 30,bg: "dark",- options: { palette: PAL.electric, radius: 30, seed: 31 },+ options: {+ palette: ["#0a0828", "#1a1c6e", "#2c3cc0", "#4a7cf0", "#7cc0ff", "#c8ecff", "#ffffff"],+ accent: ["#1c0a30", "#4a1a8c", "#8a3ce0", "#c48cff", "#f0d8ff"],+ seed: 7,+ },};-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);- });+const BALL = 0.55;++export function create(o) {+ const C = fit(o.palette, 7), V = fit(o.accent, 5), R = new Rng(o.seed);+ const ps = new Particles({ rng: R, sparks: [C[6], C[5], C[4], V[3]] }), lights = new Lights();+ lights.add(0, 0, 96, C[4], 1, 0.6);+ lights.add(0, 0, 40, WHITE, 0.9, 0.1);+ lights.add(0, 0, 70, V[2], 0.5, 1.1);+ for (let i = 0; i < 46; i++) {+ const a = R.range(0, TAU), sp = R.range(140, 360);+ ps.spawn(P.MOTE, Math.cos(a) * 4, Math.sin(a) * 4, Math.cos(a) * sp, Math.sin(a) * sp, R.range(0.2, 0.42), R.pick([C[6], C[5], C[4], V[3]]), R.range(0.7, 1.1));}- // 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));+ for (let i = 0; i < 26; i++) {+ const a = R.range(0, TAU), sp = R.range(40, 140);+ ps.spawn(P.FLAKE, Math.cos(a) * 10, Math.sin(a) * 10, Math.cos(a) * sp, Math.sin(a) * sp, R.range(0.8, 1.5), R.pick([C[5], V[3], V[4]]), R.range(0.6, 1.6));}- // 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);- }+ let t = 0;+ return {+ update(dt) {+ t += dt;+ // the shell sheds sparkles and motes as it thins+ if (t > 0.12 && t < 0.9 && R.chance(30 * dt)) {+ const a = R.range(0, TAU), r = shell(t);+ ps.spawn(P.STAR, Math.cos(a) * r, Math.sin(a) * r, Math.cos(a) * R.range(10, 40), Math.sin(a) * R.range(10, 40), R.range(0.3, 0.6), R.chance(0.5) ? C[5] : V[4], R.range(0.5, 1.8));+ }+ ps.update(dt);+ cull(ps, -meta.origin[0] + 3, -meta.origin[1] + 3, meta.size[0] - meta.origin[0] - 3, meta.size[1] - meta.origin[1] - 3);+ lights.update(dt);+ },+ drawBack(p) {+ // the tilted ring's far half, behind the ball+ tilted(p, t, C, V, true);+ },+ draw(p) {+ // the ball: a white heart, cyan and blue bands, a violet rim boiling at the edge; it swells, then hollows out+ if (t < BALL) {+ const u = t / BALL, r = shell(t), hollow = smooth(0.35, 1, u), boil = Math.floor(t * 20);+ p.shade(-r - 3, -r - 3, r + 3, r + 3, (x, y, out) => {+ const d = Math.hypot(x, y), a = Math.atan2(y, x), edge = r * (1 + 0.1 * noise(a * 3 + boil * 0.7, 3));+ if (d > edge) return;+ const v = d / edge;+ if (v < hollow * 0.92) return;+ // turbulent bands swirling round the heart, and bright filaments twisting through them+ const n = noise(a * 4 + d * 0.25 + boil * 0.5, 5), w = v + n * 0.14, fil = Math.abs(Math.sin(a * 5 + d * 0.32 - t * 14 + n * 2.5)) < 0.1;+ out.k = 0.25 * (1 - u);+ if (v > 0.9) return V[2];+ if (fil && v > 0.3) return u < 0.5 ? WHITE : C[5];+ return w < 0.32 - u * 0.25 ? WHITE : w < 0.52 ? C[5] : w < 0.72 ? C[4] : w < 0.86 ? (u < 0.5 ? C[3] : V[3]) : V[2];+ });+ p.glow(0, 0, r * 1.6 + 6, C[4], 0.6 * (1 - u));+ }+ if (t < 0.07) p.circle(0, 0, 9 - t * 60, WHITE);+ if (t < 0.25) flare(p, 0, 0, 52 * Math.pow(1 - t / 0.25, 1.3), 1 - t / 0.25, C);+ // shock rings: a fast bright one, a slower violet one+ const u1 = t / 0.42;+ if (u1 < 1) {+ p.ring(0, 0, 8 + 84 * ease.outCubic(u1), Math.max(1, 3 * (1 - u1)), u1 < 0.25 ? WHITE : C[5], 1.15 - u1);+ p.glowRing(0, 0, 8 + 84 * ease.outCubic(u1), 5, C[4], 0.35 * (1 - u1));+ }+ const u2 = (t - 0.06) / 0.6;+ if (u2 > 0 && u2 < 1) p.ring(0, 0, 6 + 60 * ease.outCubic(u2), Math.max(1, 2 * (1 - u2)), V[3], 1.1 - u2);+ // arcs: lightning crackling out of the heart, re-struck every few frames, shorter as the charge runs out+ const left = 1 - smooth(0.15, 0.85, t), strike = Math.floor(t * 18);+ if (left > 0) {+ const r = rng(o.seed, strike, 17), n = 2 + Math.round(4 * left);+ for (let i = 0; i < n; i++) {+ const a = r.range(0, TAU), L = r.range(26, 58) * (0.45 + 0.55 * left), path = bolt(r, 0, 0, Math.cos(a) * L, Math.sin(a) * L, { jag: 0.28, depth: 4 });+ arc(p, path, C, V, 0.8 * left);+ if (r.chance(0.5)) for (const f of forks(r, path, { count: 1, len: 14, jag: 0.35 })) arc(p, f, C, V, 0.5 * left);+ }+ // and little arcs crawling over the shell+ const rs = shell(t);+ for (let i = 0; i < 3; i++) {+ const a = r.range(0, TAU), b = a + r.range(0.3, 0.6);+ arc(p, bolt(r, Math.cos(a) * rs, Math.sin(a) * rs, Math.cos(b) * rs, Math.sin(b) * rs, { jag: 0.4, depth: 3 }), C, V, 0.6 * left);+ }+ }+ tilted(p, t, C, V, false);+ ps.draw(p);+ lights.draw(p);+ },+ };+}++// the ball's radius: punched out fast, then easing+function shell(t) {+ return 5 + 30 * ease.outCubic(clamp(t / BALL));+}++// a ring on a tilted plane racing out round the blast: far half behind, near half in front+function tilted(p, t, C, V, back) {+ const u = (t - 0.03) / 0.5;+ if (u <= 0 || u >= 1) return;+ band(p, 0, 4, 12 + 86 * ease.outCubic(u), 0.28, Math.max(1, 4 * (1 - u)), 1.15 - u, [V[1], V[2], C[4], C[5]], (g) => (Math.sin(g) < 0) === back, u < 0.15);+}++// one arc: a soft glow along it, a cyan halo line, a white core+function arc(p, path, C, V, k) {+ if (k <= 0.05) return;+ for (let i = 1; i < path.length; i++) {+ const [ax, ay] = path[i - 1], [bx, by] = path[i];+ p.glowLine(ax, ay, bx, by, 5, V[2], 0.18 * k);+ p.line(ax + 1, ay, bx + 1, by, C[4], k * 0.8);+ p.line(ax, ay, bx, by, i < path.length * 0.6 ? WHITE : C[5], Math.min(1, k * 1.4));}- // 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/smoke-bomb.js b/src/fx/explosions/smoke-bomb.jsnew file mode 100644index 0000000..e6b0cad--- /dev/null+++ b/src/fx/explosions/smoke-bomb.js@@ -0,0 +1,189 @@+import { Particles, Lights, P, Rng, fit, flare, clamp, smooth, TAU, WHITE, hex } from "../../core/index.js";+import { lobe, cull, fadeEdges, pool, OUTLINE } from "./_lib.js";++export const meta = {+ name: "Smoke bomb",+ desc: "A round canister clinks down, fuse sparking, and pops: thick grey-violet smoke gushes out, rolls along the floor, billows into a cloud that hides all, then thins to wisps.",+ tags: ["smoke", "smoke-bomb", "ninja", "vanish", "escape", "ground", "one-shot"],+ size: [260, 176],+ origin: [130, 156],+ duration: 5,+ loop: false,+ fps: 30,+ bg: "ground",+ options: {+ palette: ["#0e0b14", "#1e1828", "#30283e", "#463c58", "#62567a", "#867a9e", "#aea4c4"],+ canister: ["#16121e", "#2a2434", "#443c52", "#686078", "#9c94ac"],+ sparks: ["#fff3a6", "#ffe26b", "#ff8a2a", "#f2561d"],+ seed: 3,+ },+};++const POP = 0.95, R0 = 4, BAND = [hex("#3a1418"), hex("#7a2a24"), hex("#b84a34")];+const GRIT = [hex("#5a4f6b"), hex("#3e3650"), hex("#776c88")];++// the canister's flight: it arcs down, bounces with a clink, rolls and stops. hit(x, speed) on each bounce+function step(c, dt, hit) {+ if (c.rest) return;+ c.vy += 900 * dt;+ c.x += c.vx * dt;+ c.y += c.vy * dt;+ if (c.y >= -R0 && c.vy > 0) {+ c.y = -R0;+ if (c.vy > 80) {+ hit?.(c.x, c.vy);+ c.vy = -c.vy * 0.38;+ c.vx *= 0.78;+ } else c.vy = 0;+ }+ if (c.vy === 0 && c.y >= -R0 - 0.01) {+ c.vx -= c.vx * 3 * dt;+ if (Math.abs(c.vx) < 2) (c.vx = 0), (c.rest = true);+ }+ c.a += (c.vy === 0 ? c.vx / R0 : c.va) * dt;+}++export function create(o) {+ const C = fit(o.palette, 7), K = fit(o.canister, 5), R = new Rng(o.seed), floor = () => 0;+ const SM = [C[5], C[4], C[3], C[2], C[1]];+ const [W, H] = meta.size, [OX, OY] = meta.origin, X0 = -OX + 3, X1 = W - OX - 3, Y0 = -OY + 3, Y1 = H - OY - 3;+ const ps = new Particles({ rng: R, ground: floor, sparks: o.sparks }), lights = new Lights();+ // thrown in from the left so that it comes to rest on the anchor: run its path once to see where it stops+ const start = { x: -70, y: -60, vx: 125, vy: -80, va: 7, a: 0, rest: false };+ const sim = { ...start };+ for (let i = 0; i < 2400 && !sim.rest; i++) step(sim, 1 / 240);+ const can = { ...start, x: start.x - sim.x };+ // the smoke, gushing out front-loaded: rollers that slide out low along the floor, a fat core that stays over the+ // canister, a plume driven up, and a low trickle that keeps the base filled; they rise as they billow+ const N = 52, lobes = Array.from({ length: N }, (_, i) => {+ const kind = [0, 0, 1, 1, 2, 3][i % 6], side = R.sign();+ const ang = kind === 0 || kind === 3 ? (side > 0 ? -R.range(0, 0.25) : Math.PI + R.range(0, 0.25)) : -Math.PI / 2 + R.range(-0.6, 0.6);+ const sp = [R.range(70, 170), R.range(0, 25), R.range(45, 95), R.range(20, 60)][kind];+ const r1 = [R.range(12, 17), R.range(16, 22), R.range(13, 18), R.range(14, 19)][kind];+ const t0 = kind === 3 ? POP + R.range(0.45, 1.5) : POP + 0.6 * Math.pow(i / (N - 1), 1.6) + R.range(0, 0.03);+ return { kind, t0, vx: Math.cos(ang) * sp, vh: -Math.sin(ang) * sp, d: R.range(-1, 1), r0: R.range(5, 8), r1, f: R.range(-0.45, 0.4), wob: R.range(0, TAU), on: false, x: 0, h: 0, age: 0 };+ });+ let t = 0, popped = false;+ const fuseTip = () => [can.x + Math.sin(can.a) * (R0 + 2.5), can.y - Math.cos(can.a) * (R0 + 2.5)];+ const radius = (b) => (b.r0 + (b.r1 - b.r0) * (1 - Math.exp(-b.age / 0.28))) * (1 + 0.05 * Math.sin(t * 3 + b.wob)) * (1 + 0.35 * thin(b));+ const thin = (b) => smooth(2.5 + b.f, 3.9 + b.f * 0.6, t);++ return {+ update(dt) {+ t += dt;+ step(can, dt, (x, sp) => {+ // a clink: a few bright specks and a puff of dust+ for (let i = 0; i < 3; i++) ps.spawn(P.SPARK, x, -1, R.range(-70, 70), -R.range(40, 110), R.range(0.06, 0.14));+ for (let i = 0; i < 3; i++) ps.spawn(P.DUST, x + R.range(-2, 2), -0.5, R.sign() * R.range(10, 40), -R.range(4, 14), R.range(0.3, 0.55), GRIT[2], R.range(1.4, 2.4));+ });+ if (t < POP) {+ // the fuse: sparks spitting off its tip, quicker as it burns down, and a thread of smoke+ const [fx, fy] = fuseTip(), hurry = smooth(POP - 0.4, POP, t);+ if (R.chance((26 + 50 * hurry) * dt)) ps.spawn(P.SPARK, fx, fy, R.range(-50, 50), -R.range(30, 100), R.range(0.08, 0.18));+ if (R.chance(8 * dt)) ps.spawn(P.VAPOUR, fx, fy - 1, R.range(-4, 4), -R.range(10, 18), R.range(0.5, 0.8), C[5], R.range(1, 1.8));+ } else if (!popped) {+ popped = true;+ // the pop: a flash, a soft light that dies fast, sparks and grit, the canister jolted+ lights.add(can.x, -9, 64, C[6], 0.75, 0.22);+ lights.add(can.x, -5, 22, WHITE, 0.7, 0.06);+ for (let i = 0; i < 30; i++) {+ const a = R.range(-Math.PI - 0.35, 0.35), sp = R.range(120, 300);+ ps.spawn(P.SPARK, can.x, -5, Math.cos(a) * sp, Math.sin(a) * sp - 40, R.range(0.15, 0.4));+ }+ for (let i = 0; i < 26; i++) {+ const u = R.range(-1, 1), a = -Math.PI / 2 + u * 0.9, sp = R.range(80, 220) * (1 - 0.35 * Math.abs(u));+ ps.spawn(P.GRIT, can.x + u * 4, -1, Math.cos(a) * sp, Math.sin(a) * sp, R.range(0.9, 1.6), R.pick(GRIT), R.chance(0.35) ? 2 : 1);+ }+ Object.assign(can, { vy: -95, vx: R.range(-25, 25), va: R.sign() * 9, rest: false });+ }+ // the cloud: lobes slide out low, slow, then rise as they billow; a breeze takes them late on+ const wind = 6 * smooth(1.8, 3.2, t);+ for (const b of lobes) {+ if (!b.on) {+ if (t < b.t0) continue;+ (b.on = true), (b.x = can.x + R.range(-2, 2)), (b.h = 1);+ }+ b.age += dt;+ b.vx -= b.vx * 2.4 * dt;+ // rollers hug the floor for a while; everything rises as it billows, gently+ b.vh += [14 * smooth(0.7, 1.6, b.age), 3 + 9 * smooth(0.8, 1.8, b.age), 6 + 12 * smooth(0.3, 1.4, b.age), 10 * smooth(0.8, 1.6, b.age)][b.kind] * dt;+ b.vh -= b.vh * 1.6 * dt;+ b.x += (b.vx + wind) * dt;+ b.h = Math.max(0, b.h + b.vh * dt);+ // thinning, it sheds wisps that drift off+ const k = thin(b);+ if (k > 0.12 && k < 0.85 && R.chance(1.8 * dt)) {+ const r = radius(b), life = Math.min(R.range(1, 1.6), meta.duration - 0.15 - t);+ if (life > 0.3) ps.spawn(P.VAPOUR, b.x + R.range(-r, r) * 0.5, -(b.h + r * 1.4), wind + R.range(-6, 10), -R.range(8, 20), life, C[4], r * R.range(0.3, 0.45));+ }+ }+ // the spent canister keeps smoking a little+ if (t > POP + 0.5 && t < 4.1 && R.chance(4 * dt)) ps.spawn(P.VAPOUR, can.x, can.y - 3, R.range(-3, 3), -R.range(8, 16), R.range(0.6, 0.9), C[4], R.range(1.5, 2.5));+ ps.update(dt);+ cull(ps, X0, Y0, X1, Y1);+ fadeEdges(ps, X0, X1, 20, Y1);+ lights.update(dt);+ },+ drawBack(p) {+ ps.draw(p, "back");+ clouds(p, true);+ },+ draw(p) {+ // the canister: live with its fuse burning, then spent; it fades as the last smoke clears+ const fade = 1 - smooth(4.3, 4.8, t);+ if (fade > 0) drawCanister(p, K, can, t < POP, fade);+ if (t < POP) {+ const [fx, fy] = fuseTip();+ p.px(fx, fy, Math.sin(t * 50) > 0 ? WHITE : hex(o.sparks[1]));+ p.glow(fx, fy, 6, hex(o.sparks[2]), 0.45 + 0.2 * Math.sin(t * 37));+ }+ clouds(p, false);+ ps.draw(p, "front");+ // the flash of the pop+ const u = t - POP;+ if (u >= 0 && u < 0.067) {+ p.circle(can.x, -5, 6.5, C[5]);+ p.circle(can.x, -5, 4.5, WHITE);+ }+ if (u >= 0 && u < 0.16) flare(p, can.x, -5, 22 * (1 - u / 0.16), 1 - u / 0.16, [C[3], C[4], C[5], C[6]]);+ if (u >= 0 && u < 0.35) pool(p, can.x, 1, 50, 8, C[6], 0.5 * (1 - u / 0.35));+ lights.draw(p);+ },+ };++ // far lobes behind, near ones in front; each a cel-shaded ball: a lit crescent on top, a mid tone, a dark underside.+ // The cloud is lit from above, so lobes low in it sit in its shadow a step darker; anything nearing the top of the+ // canvas thins out+ function clouds(p, back) {+ const on = lobes.filter((b) => b.on);+ if (!on.length) return;+ let top = 0;+ for (const b of on) top = Math.min(top, -(b.h + radius(b) * 1.92));+ for (const b of on.filter((b) => b.d < -0.35 === back).sort((a, b) => a.d - b.d)) {+ const r = radius(b), y = -(b.h + r * 0.92) + b.d * 2.5, k = thin(b);+ const a = Math.min(1, b.age / 0.05) * Math.pow(1 - k, 1.4) * 0.97 * (1 - smooth(-OY + 34, -OY + 6, y - r));+ if (a <= 0.01) continue;+ const shade = (y - top) / Math.max(20, -top) > 0.55 ? 1 : 0;+ lobe(p, b.x, y, r, SM, SM, 0, 0, a, b.d, Math.min(2, shade + (k > 0.6 ? 1 : 0)), 1);+ }+ }+}++// a round canister turned by its roll: dark metal lit from the top left, a red band, an outline, and a fuse on top+// while it's live (spent, its cap is blown off)+function drawCanister(p, K, c, live, a) {+ const ca = Math.cos(c.a), sa = Math.sin(c.a);+ p.shade(c.x - R0 - 2, c.y - R0 - 2, c.x + R0 + 2, c.y + R0 + 2, (px, py, out) => {+ const dx = px - c.x, dy = py - c.y, d = Math.hypot(dx, dy);+ if (d > R0 + 1) return;+ out.a = a;+ if (d > R0) return OUTLINE;+ const v = -dx * sa + dy * ca, lit = -(dx * 0.6 + dy * 0.8) / R0;+ if (Math.abs(v) < 0.9) return BAND[lit > 0.3 ? 2 : lit > -0.4 ? 1 : 0];+ if (d < R0 * 0.5 && lit > 0.45) return K[4];+ return K[lit > 0.5 ? 3 : lit > 0 ? 2 : lit > -0.5 ? 1 : 0];+ });+ const cx = c.x + sa * R0, cy = c.y - ca * R0;+ if (live) p.line(cx, cy, cx + sa * 2.5, cy - ca * 2.5, hex("#8a6a48"), a);+ else p.dot(cx, cy, K[0], a);+}diff --git a/src/fx/explosions/smoke-puff.js b/src/fx/explosions/smoke-puff.jsdeleted file mode 100644index a721679..0000000--- a/src/fx/explosions/smoke-puff.js+++ /dev/null@@ -1,53 +0,0 @@-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.jsindex 2389faa..f39107f 100644--- a/src/fx/fire/_lib.js+++ b/src/fx/fire/_lib.js@@ -1,101 +1,228 @@-// 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).+// Shared by the fire effects (the leading _ keeps the tools from listing it as an effect).+// Flame tongues, licks, flame puffs that cool into smoke, embers and sparks, with their motion in closed form so+// looping effects can draw them from t alone and stay seamless. The tongue, lick, puff, smoke, ember and spark+// recipes are adapted from Sprite Fusion's open-source fire (https://www.spritefusion.com/pixel-art-vfx/fire),+// MIT License, Copyright (c) 2026 Hugo Duprez.-import { at, cycle, tileFbm, loopNoise, TAU } from "../../core/index.js";+import { rand, rng, wrap, noise, mix, hex, clamp, WHITE, SMOKE_RAMP, P, PF } 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))]);+/** Smooth value noise in [-1, 1] that repeats every `period` cells (a whole number). */+export function pnoise(x, period, seed = 0) {+ const i = Math.floor(x), f = x - i, u = f * f * (3 - 2 * f);+ const a = rand(wrap(i, period), seed), b = rand(wrap(i + 1, period), seed);+ return (a + (b - a) * u) * 2 - 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);+/**+ * Noise for a loop D seconds long: N(tt, rate, seed, off) wobbles about `rate` times a second and is the same at+ * tt and tt + D. Pass D = 0 for one-shots (plain noise, no repeat).+ */+export function noiseFor(D) {+ if (!D) return (tt, rate, seed = 0, off = 0) => noise(tt * rate + off, seed);+ return (tt, rate, seed = 0, off = 0) => {+ const P = Math.max(1, Math.round(rate * D));+ return pnoise((tt / D) * P + off, P, seed);+ };+}++/**+ * Seamless particles for a loop D seconds long: count particles, each born at its own phase and reborn every D.+ * make(r, i) builds particle i from its own rng (the same every frame) and returns it with a .life (which may+ * be longer than D); draw(q, age, i) is called for every live copy.+ */+export function looped(t, D, count, seed, make, draw) {+ for (let i = 0; i < count; i++) {+ const r = rng(seed, i), born = r.next() * D, q = make(r, i);+ for (let age = wrap(t - born, D); age < q.life; age += D) draw(q, age, i);}- return v >= 1.05 ? 0 : Math.pow(1 - (v - 0.2) / 0.85, 0.7);}+/** Hugo's flicker, 0.74 to 1: a slow breath and a fast crackle. N(rate, seed) at the current time. */+export const flicker = (N, s = 0) => 0.74 + 0.16 * N(7.3, 1 + s) + 0.1 * N(19, 2 + s);++/** A fire ramp hot-first (H[0] white .. H[8] smouldering) from a palette dark to bright, any length. */+export const hotFirst = (F) => [...F].reverse();++/** Tongue layers [width share, height share, step of the hot-first ramp]: red rim, orange, yellow, white heart. */+export const LAYERS = [[1, 1, 6], [0.76, 0.86, 4], [0.54, 0.68, 2], [0.3, 0.42, 0]];++/** Layers for big tongues: more orange and a smaller white heart, so the light doesn't wash them out. */+export const BIG_LAYERS = [[1, 1, 6], [0.8, 0.9, 5], [0.62, 0.78, 4], [0.44, 0.6, 3], [0.26, 0.4, 1], [0.12, 0.22, 0]];++/** The same layers a step cooler, for flames further back: dark red rim, deep orange, gold, yellow. */+export const BACK_LAYERS = [[1, 1, 7], [0.76, 0.86, 5], [0.54, 0.68, 3], [0.3, 0.42, 2]];+/**- * 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().+ * A flame tongue standing at (x, y), h tall, w its half-width at the base, its tip swept sx px sideways: a red+ * rim round orange round yellow round a white heart, every row's width and centre jittered by noise so the+ * edges crackle. N(rate, seed, off) is the effect's noise at this frame; n seeds this tongue. H: hot-first ramp.+ * jit: how far the edges crackle (px); wob: how far the tip wanders (px).*/-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,- };+export function flameTongue(p, x, y, h, w, sx, N, n, H, layers = LAYERS, jit = 0.5, wob = 1.1) {+ if (h < 1) return;+ for (const [lw, lh, ri] of layers) {+ const L = h * lh, c = H[ri];+ for (let r = 0; r <= L; r++) {+ const u = r / Math.max(1, L);+ const half = w * lw * Math.pow(1 - u, 0.85) * Math.min(1, (r + 1.5) / 3.5) + N(9, n, r * 0.45) * jit;+ if (half < 0.3) continue;+ const cx = x + sx * u * u * lh + N(4, n + 7, r * 0.2) * u * wob, Y = Math.round(y - r);+ for (let px = Math.round(cx - half), x1 = Math.round(cx + half); px <= x1; px++) p.px(px, Y, c);+ }+ }}/**- * 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) }.+ * The same tongue lying along any direction (ux, uy) from its root (x, y): for jets, breath and comet tails.+ * len long, w half-width at the root, bend: px the tip is swept sideways (to the left of the direction).*/-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);+export function flameBlade(p, x, y, ux, uy, len, w, bend, N, n, H, layers = LAYERS, jit = 0.5, wob = 1.1) {+ if (len < 1) return;+ const nx = -uy, ny = ux;+ for (const [lw, lh, ri] of layers) {+ const L = len * lh, c = H[ri];+ for (let r = 0; r <= L; r += 0.5) {+ const u = r / Math.max(1, L);+ const half = w * lw * Math.pow(1 - u, 0.85) * Math.min(1, (r + 1.5) / 3.5) + N(9, n, r * 0.45) * jit;+ if (half < 0.3) continue;+ const off = bend * u * u * lh + N(4, n + 7, r * 0.2) * u * wob, cx = x + ux * r + nx * off, cy = y + uy * r + ny * off;+ for (let q = -half; q <= half; q += 0.5) p.px(cx + nx * q, cy + ny * q, c);}- 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);- });+ }+}++/** A solid disc drawn straight in screen space (fast; a disc looks the same mirrored or turned). */+export function solid(p, x, y, r, c) {+ if (r < 0.6) return p.px(x, y, c);+ const cx = p.toX(x, y), cy = p.toY(x, y), r2 = r * r;+ for (let sy = Math.floor(cy - r); sy <= Math.ceil(cy + r); sy++) {+ const dy = sy + 0.5 - cy, s2 = r2 - dy * dy;+ if (s2 < 0) continue;+ const s = Math.sqrt(s2);+ for (let sx = Math.ceil(cx - s - 0.5); sx <= Math.floor(cx + s - 0.5); sx++) p.put(sx, sy, c, 1);+ }+}++/** A translucent disc in screen space: smoke and haze. */+export function soft(p, x, y, r, c, a) {+ if (a <= 0.004) return;+ if (r < 0.5) return p.blend(x, y, c, a);+ const cx = p.toX(x, y), cy = p.toY(x, y), r2 = r * r;+ for (let sy = Math.floor(cy - r); sy <= Math.ceil(cy + r); sy++) {+ const dy = sy + 0.5 - cy, s2 = r2 - dy * dy;+ if (s2 < 0) continue;+ const s = Math.sqrt(s2);+ for (let sx = Math.ceil(cx - s - 0.5); sx <= Math.floor(cx + s - 0.5); sx++) p.blendPx(sx, sy, c, a);+ }}/**- * 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.+ * A ball of flame with life left k (1 new, 0 gone) cooling down the hot-first ramp H as it ages: a darker rim,+ * a lit core up and to the left, a little tongue on top, a hot heart while it's young, and its light.+ * frac (0..1) nudges how hot it starts. (tx, ty): which way its tongue points (up, unless it's streaming).*/-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));- });+export function firePuff(p, x, y, k, size, frac, H, glowK = 0.18, tx = 0, ty = -1) {+ const age = 1 - k, n = H.length, heat = Math.min(0.999, Math.pow(age, 0.62) + frac * 0.1);+ const idx = Math.min(n - 2, Math.floor(heat * (n - 1)));+ const r = size * (0.55 + 0.45 * Math.min(1, age * 7)) * (1 - age * 0.55), c = H[idx];+ if (idx >= n - 2) return soft(p, x, y, r, c, Math.min(1, k * 3) * 0.85);+ solid(p, x, y, r, H[Math.min(n - 1, idx + 2)]);+ if (r > 1.6 && ty > -0.99) solid(p, x + tx * r * 1.5, y + ty * r * 1.5, r * 0.3, H[Math.min(n - 1, idx + 1)]);+ solid(p, x - r * 0.16, y - r * 0.22, r * 0.78, c);+ if (r > 1.6) solid(p, x + tx * r * 0.9, y + ty * r * 0.9, r * 0.42, c);+ if (idx <= 3 && r > 1.8) solid(p, x - r * 0.28, y - r * 0.34, r * 0.36, H[Math.max(0, idx - 1)]);+ if (idx < 6) p.glow(x, y, r * 2.4 + 2, c, glowK * k);}+/** A lick: a blob of flame torn off a tongue's tip, a red rim round a yellow heart, shrinking as it rises. */+export function lick(p, x, y, k, s, H) {+ const r = s * (0.4 + 0.6 * k);+ solid(p, x, y, r + 0.6, k > 0.5 ? H[5] : H[6]);+ if (k > 0.35) solid(p, x, y - 0.3, r * 0.6, k > 0.7 ? H[2] : H[4]);+}++const rampAt = (r, t) => r[Math.min(r.length - 1, Math.max(0, Math.floor(t * r.length)))];+/**- * 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.+ * A puff of smoke with life left k: three soft discs (a body, a denser core sitting low, a lit cap while it's+ * young), swelling and thinning. col tints it (0 for plain smoke); big for slower, fuller smoke.*/-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));- });+export function smokePuff(p, x, y, k, size, col = 0, big = false, aMul = 1) {+ const age = 1 - k;+ const r = size * (0.65 + Math.min(1, age * 2.5) * 0.45 + age * (big ? 0.5 : 0.4));+ const a = Math.min(1, age * 12) * Math.min(1, k * 2.4) * (big ? 0.7 : 0.58) * aMul;+ const c = col ? mix(col, rampAt(SMOKE_RAMP, age), age) : rampAt(SMOKE_RAMP, age * 1.05);+ soft(p, x, y, r, c, a * 0.45);+ soft(p, x + r * 0.05, y + r * 0.06, r * 0.74, c, a * 0.62);+ if (age < 0.5) soft(p, x - r * 0.22, y - r * 0.3, r * 0.5, mix(c, WHITE, 0.12), a * 0.4 * (1 - age * 2));+}++/**+ * An ember with life left k: a hot pixel cooling through cols [hot, warm, cool, rim], flickering out near the+ * end (ph: its flicker phase), with its own light. Big ones (size 2) are a little cross with a darker rim.+ */+export function ember(p, x, y, k, size, cols, ph) {+ if (k < 0.25 && Math.sin(ph) < 0) return;+ const c = k > 0.6 ? cols[0] : k > 0.3 ? cols[1] : cols[2];+ if (size >= 2) {+ const rim = k > 0.45 ? cols[2] : cols[3];+ p.px(x - 1, y, rim), p.px(x + 1, y, rim), p.px(x, y - 1, rim), p.px(x, y + 1, rim);+ p.px(x, y, c);+ p.glow(x, y, 8, c, 0.4 * k);+ return;+ }+ p.px(x, y, c);+ if (size > 1.4) p.px(x, y + 1, cols[3]);+ p.glow(x, y, 3 + size, c, 0.35 * k);+}++/** A spark: a streak stretched along its velocity, a hot head and a cooler tail, and a point of light. */+export function spark(p, x, y, vx, vy, k, cols) {+ const sp = Math.hypot(vx, vy) || 1, ux = vx / sp, uy = vy / sp, len = Math.min(9, 1 + sp * 0.022);+ const head = k > 0.6 ? cols[0] : k > 0.3 ? cols[1] : cols[2];+ p.line(x - ux * len, y - uy * len, x - ux * len * 0.4, y - uy * len * 0.4, k > 0.5 ? head : cols[cols.length - 1]);+ p.line(x - ux * len * 0.45, y - uy * len * 0.45, x, y, head);+ p.glow(x, y, 3, head, 0.45 * k);+}++function along(x, v, a, k, t) {+ if (k <= 0) return [x + v * t + 0.5 * a * t * t, v + a * t];+ const e = Math.exp(-k * t), vt = a / k;+ return [x + vt * t + ((v - vt) * (1 - e)) / k, vt + (v - vt) * e];+}++/**+ * Where a body is t seconds after launch from (x, y) at (vx, vy), under acceleration (ax, ay) px/s² and linear+ * drag kx, ky (1/s): [x, y, vx, vy]. The particle kinds' own numbers: FIRE (0, -95, 5, 3.2), SMOKE+ * (0, -16, 1.6, 1.2), EMBER (0, -30, 1.6, 1.6), SPARK (0, 427, 2.2, 2.2).+ */+export function drift(x, y, vx, vy, t, ax, ay, kx, ky) {+ const X = along(x, vx, ax, kx, t), Y = along(y, vy, ay, ky, t);+ return [X[0], Y[0], X[1], Y[1]];+}++/** A spark's flight: falls, drags, and bounces off the floor at y = floor, losing speed each time. */+export function sparkAt(x, y, vx, vy, t, floor = 0, g = 427, k = 2.2) {+ let s = [x, y, vx, vy], left = t;+ for (let b = 0; b < 3; b++) {+ const e = drift(s[0], s[1], s[2], s[3], left, 0, g, k, k);+ if (e[1] < floor || s[1] >= floor) return e;+ let lo = 0, hi = left;+ for (let i = 0; i < 16; i++) {+ const m = (lo + hi) / 2;+ if (drift(s[0], s[1], s[2], s[3], m, 0, g, k, k)[1] < floor) lo = m;+ else hi = m;+ }+ const c = drift(s[0], s[1], s[2], s[3], hi, 0, g, k, k);+ s = [c[0], floor - 0.25, c[2] * 0.7, -Math.abs(c[3]) * 0.45];+ left -= hi;+ }+ const e = drift(s[0], s[1], s[2], s[3], left, 0, g, k, k);+ return e[1] < floor ? e : [e[0], floor - 0.25, e[2], 0];}-/** 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) {+/** A pool of light on the floor: an ellipse of glow, k at its middle falling to 0 at its rim. */+export function floorLight(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;@@ -105,3 +232,95 @@ export function pool(p, x, y, rx, ry, c, k) {out.k = f * f * k;});}++/**+ * A core Particles system drawn with its flame puffs recoloured down the hot-first ramp H (the core draws them+ * in its own fire colours): smoke and back particles, then the flames, then sparks and the rest on top.+ */+export function simDraw(p, ps, H, layer) {+ const all = ps.list, rest = [], fire = [];+ for (const q of all) (q.k === P.FIRE ? fire : rest).push(q);+ const puffs = (back) => {+ for (const q of fire) if (q.delay <= 0 && !!(q.flag & PF.BACK) === back) firePuff(p, q.x, q.y, q.life / q.max, q.size, q.seed % 1, H);+ };+ ps.list = rest;+ if (layer !== "front") ps.draw(p, "back"), puffs(true);+ if (layer !== "back") puffs(false), ps.draw(p, "front");+ ps.list = all;+}++const SMOKE1 = hex("#5b5566");++/**+ * A fire for loops, drawn from t alone. Tongues T: [[dx, dy, height share, half-width, back row?], ...] from the+ * base (o.x, o.y), back row first then outer to inner; licks torn off their tips, flame puffs that burn out into+ * smoke, a smoke plume curling off with the draught, embers, and the fire's light.+ * o: { H, D, NL (noiseFor(D)), S (seed), height, lean, rates per second: puffs and licks (per tongue), smoke,+ * embers; spread (how wide embers and smoke leave), glow (light strength), glowR, mid() (called after the+ * tongues, before what flies off them: draw what the fire burns out of there) }. Wide tongues get BIG_LAYERS.+ * Returns { tip(i, tt), fl (this frame's flicker) }.+ */+export function burn(p, t, T, o) {+ const { H, D, NL, S } = o, HC = o.height, X = o.x ?? 0, Y = o.y ?? 0, W = o.spread ?? 6, G = o.glow ?? 1;+ const N = (rate, seed = 0, off = 0) => NL(t, rate, seed, off);+ const fla = (tt) => 0.74 + 0.16 * NL(tt, 7.3, S + 1) + 0.1 * NL(tt, 19, S + 2), fl = fla(t);+ const SMOKE = mix(SMOKE1, H[6], 0.25), EMB = [H[1], H[2], H[4], H[6]], GLOW = mix(mix(H[3], H[4], 0.5), WHITE, 0.25);+ const R = rng(S, 77), count = (rate) => Math.round(rate * D);+ const TT = T.map(([dx, dy, h, w, back], i) => ({ dx: dx + R.range(-0.3, 0.3), y: dy, h: 2 + HC * h * R.range(0.92, 1.08), w: w * R.range(0.92, 1.08), back, env: h, n: (S * 7 + i) * 13 }));+ const lean = (tt) => NL(tt, 0.67, S + 90) * (o.lean ?? 0.1);+ const height = (i, tt) => {+ const { h, n } = TT[i], leap = Math.max(0, NL(tt, 2.6, n + 70) - 0.55) * 1.4;+ return (h + 0.25 * h * NL(tt, 3.3, n) + h * leap) * (0.9 + 0.1 * fla(tt));+ };+ const sweep = (i, tt, h) => NL(tt, 2.2, TT[i].n + 40) * (1 + h * 0.08) + lean(tt) * h * 0.9 - clamp(TT[i].dx * 0.3, -2.5, 2.5);+ const tip = (i, tt) => {+ const h = height(i, tt);+ return [X + TT[i].dx + sweep(i, tt, h) * 0.85, Y + TT[i].y - h * 0.88 + 3, h];+ };+ const tongueAt = (i) => {+ const { dx, y, w, n, back } = TT[i], h = height(i, t);+ flameTongue(p, X + dx, Y + y, h, w, sweep(i, t, h), N, n, H, back ? BACK_LAYERS : w > 2.2 ? BIG_LAYERS : LAYERS, 0.5, 1.1 + h * 0.04);+ };++ // the plume: each puff keeps the sway the plume had when it left, so the wiggle climbs it+ looped(t, D, count(o.smoke ?? 12), S + 300, (r) => ({ x: r.range(-W, W) * 0.7, y: -HC * 0.8 - r.range(0, 6), vx: r.range(-2, 2), vy: -r.range(10, 17), life: r.range(...(o.smokeLife ?? [1.6, 2.6])), s: r.range(0.7, 1.1) * (o.smokeSize ?? 3) }), (q, age) => {+ const [x, y] = drift(q.x, q.y, q.vx, q.vy, age, o.wind ?? 3, -20, 1.6, 1);+ smokePuff(p, X + x + NL(t - age, 0.8, S + 60) * (1.5 + 2.5 * age), Y + y, 1 - age / q.life, q.s, SMOKE);+ });+ // flame puffs shed from the tips+ const puffs = [];+ looped(t, D, TT.length * count(o.puffs ?? 8), S + 200, (r, j) => {+ const i = j % TT.length, fire = r.range(0.14, 0.3), smokes = r.chance(0.45);+ return { i, fire, smokes, sl: r.range(0.8, 1.4), ox: r.range(-1, 1), oy: r.range(0, 4), vx: r.range(-4, 4), vy: -r.range(15, 30), s: r.range(0.8, 1.6) * (0.8 + 0.6 * TT[i].env), f: r.next(), life: fire + (smokes ? 1.4 : 0) };+ }, (q, age) => {+ const [tx, ty] = tip(q.i, t - age);+ const [x, y, vx, vy] = drift(tx + q.ox, ty + q.oy, q.vx, q.vy, Math.min(age, q.fire), 0, -95, 5, 3.2);+ if (age < q.fire) return puffs.push([x, y, 1 - age / q.fire, q.s, q.f]);+ if (age - q.fire > q.sl) return;+ const [sx, sy] = drift(x, y, vx * 0.6, vy * 0.6 - 6, age - q.fire, o.wind ?? 3, -16, 1.6, 1.2);+ smokePuff(p, sx, sy, 1 - (age - q.fire) / q.sl, q.s * 0.7, 0);+ });+ for (let i = 0; i < TT.length; i++) if (TT[i].back) tongueAt(i);+ for (let i = 0; i < TT.length; i++) if (!TT[i].back) tongueAt(i);+ o.mid?.(fl);+ // licks torn off the tips, rising and shrinking+ looped(t, D, TT.length * count(o.licks ?? 4), S + 220, (r, j) => ({ i: j % TT.length, vx: r.range(-3, 3), vy: -r.range(12, 22), s: r.range(0.9, 1.6) * (0.8 + 0.5 * TT[j % TT.length].env), life: 0.26 }), (q, age) => {+ const [tx, ty] = tip(q.i, t - age);+ lick(p, tx + q.vx * age, ty - 2 + q.vy * age, 1 - age / q.life, q.s, H);+ });+ for (const [x, y, k, s, f] of puffs) firePuff(p, x, y, k, s, f, H);+ // embers carried up by the heat, wandering and cooling+ looped(t, D, count(o.embers ?? 8), S + 500, (r) => ({ x: r.range(-W, W), y: -r.range(HC * 0.3, HC * 0.8), vx: r.range(-15, 15), vy: -r.range(25, 60), life: r.range(1.1, 2.4), s: r.chance(0.15) ? 2 : r.range(1, 1.6), a: r.range(0, 6.3), b: r.range(0, 6.3) }), (q, age) => {+ const [x, y] = drift(q.x, q.y, q.vx, q.vy, age, 0, -30, 1.6, 1.6);+ ember(p, X + x + 7 * (Math.sin(age * 2.3 + q.a) - Math.sin(q.a)), Y + y + 2 * (Math.sin(age * 3 + q.b) - Math.sin(q.b)), 1 - age / q.life, q.s, EMB, age * 40 + q.a);+ });+ // light: a broad warm wash, lights on the flames, a hot heart at the base+ if (G > 0) {+ const R1 = o.glowR ?? 46, lx = X + lean(t) * 12;+ p.glow(lx, Y - HC * 0.35, R1 * 1.5, GLOW, 0.22 * fl * G);+ p.glow(lx, Y - HC * 0.75, R1, GLOW, 0.34 * fl * G);+ p.glow(X, Y - HC * 0.2, R1 * 0.32, H[2], 0.2 * fl * G);+ p.glow(X, Y - 2, 8, H[0], 0.14 * fl * G);+ }+ return { tip, fl };+}diff --git a/src/fx/fire/brazier.js b/src/fx/fire/brazier.jsindex a29bf17..0f9ab2b 100644--- a/src/fx/fire/brazier.js+++ b/src/fx/fire/brazier.js@@ -1,62 +1,113 @@-import { PAL, ramp, rand, loopNoise } from "../../core/index.js";-import { fit, tongue, flames, embers, pool } from "./_lib.js";+// The tongue, lick, flame-puff, smoke, ember and spark recipe is adapted from Sprite Fusion's open-source fire+// (https://www.spritefusion.com/pixel-art-vfx/fire), MIT License, Copyright (c) 2026 Hugo Duprez.+import { fit, mix, rand, clamp, WHITE } from "../../core/index.js";+import { noiseFor, hotFirst, burn, looped, drift, spark, ember, floorLight } 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,+ desc: "An iron bowl on a tripod heaped with glowing coals and a big roaring fire, sparks and embers streaming up off it, light on the iron and the floor.",+ tags: ["fire", "brazier", "prop", "light", "sparks", "ambient", "loop"],+ size: [112, 148],+ origin: [56, 136],+ duration: 3,loop: true,fps: 30,bg: "ground",- options: { palette: PAL.fire, height: 34, seed: 3 },+ options: {+ palette: ["#4a1712", "#8a1f17", "#c9281f", "#f2561d", "#ff8a2a", "#ffc23d", "#ffe26b", "#fff3a6", "#ffffff"],+ iron: ["#0b0910", "#1c1924", "#302c3a", "#4c4658", "#78708a"],+ seed: 8,+ },};-const IRON = ramp(["#100f15", "#24222c", "#383542", "#55515f", "#7a7585"]);+const D = meta.duration, NL = noiseFor(D), RIM = -25, RX = 15, RY = 3;+// the fire: [x, y from the rim, height share, half-width, back row?]+const TONGUES = [+ [-7, -1.5, 0.5, 2.0, 1],+ [7.2, -1.5, 0.55, 2.0, 1],+ [-3, -2.5, 0.84, 2.2, 1],+ [3.3, -2.5, 0.86, 2.2, 1],+ [-11.5, 0.5, 0.2, 1.5, 0],+ [11.5, 0.5, 0.22, 1.5, 0],+ [-8.3, 0, 0.34, 2.0, 0],+ [8.5, 0, 0.38, 2.0, 0],+ [-4.7, -0.5, 0.6, 2.8, 0],+ [4.9, -0.5, 0.64, 2.8, 0],+ [0, -1, 1, 3.6, 0],+];++// the tripod: two legs splayed out and one coming at us, curled feet, a ring holding them together+function stand(p, I, H, fl) {+ const leg = (x0, y0, x1, y1) => {+ p.line(x0, y0, x1, y1, I[0]);+ p.line(x0 + 1, y0, x1 + 1, y1, I[2]);+ p.line(x0 + 2, y0, x1 + 2, y1, I[0]);+ };+ // the ring: its far half behind the front leg+ p.ellipse(0, -9, 9, 1.8, (d) => (d > 0.6 ? I[2] : 0));+ leg(-6, -17, -12, -1);+ leg(4, -17, 10, -1);+ p.rect(-14, -1, 5, 1, I[2]), p.rect(-15, 0, 6, 1, I[0]), p.px(-15, -1, I[3]);+ p.rect(9, -1, 5, 1, I[2]), p.rect(9, 0, 6, 1, I[0]), p.px(13, -1, I[3]);+ p.rect(-1, -16, 3, 15, I[0]);+ p.rect(0, -16, 1, 15, mix(I[3], H[4], 0.15 * fl));+ p.rect(-2, -1, 5, 1, I[2]), p.rect(-2, 0, 5, 1, I[0]);+ p.ellipse(0, -9, 9, 1.8, (d, a) => (Math.sin(a) > 0 && d > 0.55 ? (d > 0.85 ? I[0] : I[3]) : 0));+}++// the bowl, front half: a band of rivets under a rim lit by the fire, rounding down to a dark belly+function bowl(p, I, H, fl) {+ p.shade(-RX - 1, RIM - 1, RX + 1, RIM + 9, (x, y) => {+ const v = (y - RIM) / 9, hw = RX * Math.sqrt(Math.max(0, 1 - v * v * 0.9)) - (v > 0.5 ? (v - 0.5) * 6 : 0);+ if (Math.abs(x) > hw + 0.5 || y < RIM) return;+ if (Math.abs(x) > hw - 0.5 || v > 0.92) return I[0];+ if (y < RIM + 1) return mix(I[3], H[4], 0.5 * fl);+ if (y < RIM + 2) return I[2];+ if (y < RIM + 3) return Math.round(x) % 4 === 0 ? mix(I[4], H[4], 0.25 * fl) : I[0];+ return x < -RX * 0.45 ? I[2] : x < RX * 0.25 ? I[1] : I[0];+ });+}++// coals heaped in the bowl, showing over the rim, breathing in the heat+function coals(p, I, H, t, S) {+ p.shade(-RX, RIM - 6, RX, RIM + 1, (x, y, out) => {+ // a mound: highest in the middle, standing proud of the rim+ const top = RIM - 1 - 4 * Math.max(0, 1 - (x / (RX - 1)) ** 2);+ if (y < top || y > RIM + 0.5 || Math.abs(x) > RX - 0.5) return;+ const lump = rand(Math.floor((x + Math.floor(y) * 1.5) / 3), Math.floor(y / 2), S + 20), edge = y < top + 1;+ // the gaps between lumps stay dark; the lumps breathe, hottest deep in the heap+ if (rand(Math.floor(x), Math.floor(y), S + 21) < 0.16 || (edge && lump < 0.3)) return I[0];+ const g = (0.5 + 0.5 * Math.sin((t / D) * Math.PI * 4 + lump * 40)) * (edge ? 0.7 : 1);+ out.k = 0.3 * g;+ return g > 0.72 ? H[2] : g > 0.5 ? H[3] : g > 0.3 ? H[4] : g > 0.15 ? H[5] : H[6];+ });+}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];+ const F = fit(o.palette, 9), H = hotFirst(F), I = fit(o.iron, 5), S = o.seed;+ const fl = 0.74 + 0.16 * NL(t, 7.3, S + 1) + 0.1 * NL(t, 19, S + 2), GLOW = mix(mix(H[3], H[4], 0.5), WHITE, 0.25);+ const SPARKS = [H[1], H[2], H[4], H[5]], EMB = [H[1], H[2], H[4], H[6]];+ floorLight(p, 0, 0.5, 40, 7, GLOW, 0.32 * fl);+ stand(p, I, H, fl);+ // the back of the rim, behind the fire+ p.ellipse(0, RIM, RX, RY, (d, a) => (Math.sin(a) < 0 && d > 0.7 ? (d > 0.88 ? I[0] : mix(I[3], H[4], 0.3 * fl)) : 0));+ burn(p, t, TONGUES, {+ H, D, NL, S, x: 0, y: RIM, height: 32, lean: 0.1, spread: 7,+ puffs: 8, licks: 4, smoke: 14, smokeSize: 3, smokeLife: [1.6, 2.4], embers: 10, glowR: 58, glow: 1.4, wind: 3,+ mid: () => {+ coals(p, I, H, t, S);+ bowl(p, I, H, fl);+ },+ });+ // sparks streaming up in the draught: fast streaks that slow, wander and cool to embers high above+ looped(t, D, 60, S + 600, (r) => {+ const side = r.range(-1, 1);+ return { x: side * 8, y: RIM - r.range(4, 18), vx: side * r.range(10, 40), vy: -r.range(70, 150), life: r.range(0.7, 1.7), a: r.range(0, 6.3), w: r.range(1.8, 3.2), m: r.range(3, 8), big: r.chance(0.12) };+ }, (q, age) => {+ const [x, y, vx, vy] = drift(q.x, q.y, q.vx, q.vy, age, 0, -22, 1.9, 1.9), k = 1 - age / q.life;+ // they bend and wander as the draught slows them+ const wob = q.m * (Math.sin(age * q.w + q.a) - Math.sin(q.a)) * Math.min(1, age * 1.5), wv = q.m * q.w * Math.cos(age * q.w + q.a) * Math.min(1, age * 1.5);+ if (Math.hypot(vx + wv, vy) > 40) spark(p, x + wob, y, vx + wv, vy, k, SPARKS);+ else ember(p, x + wob, y, k, q.big ? 2 : 1, EMB, age * 40 + q.a);});- 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.jsindex 0637aed..2ff5b49 100644--- a/src/fx/fire/campfire.js+++ b/src/fx/fire/campfire.js@@ -1,69 +1,187 @@-import { PAL, RAMP, ramp, cycle, fly, loopNoise, rand } from "../../core/index.js";-import { fit, tongue, flames, embers, wisps, pool } from "./_lib.js";+// The tongue, lick, flame-puff, smoke and ember recipe is adapted from Sprite Fusion's open-source fire+// (https://www.spritefusion.com/pixel-art-vfx/fire), MIT License, Copyright (c) 2026 Hugo Duprez.+import { Rng, fit, mix, hex, rand, clamp, WHITE } from "../../core/index.js";+import { noiseFor, hotFirst, flameTongue, firePuff, lick, smokePuff, ember, spark, drift, sparkAt, floorLight, looped, LAYERS, BACK_LAYERS } 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,+ desc: "Crossed logs on a bed of coals and a lively fire: tongues that lick and leap, popping sparks, embers drifting up, smoke curling off, a warm pool of light.",+ tags: ["fire", "campfire", "prop", "light", "smoke", "ambient", "loop"],+ size: [128, 128],+ origin: [64, 112],+ duration: 3,loop: true,fps: 30,bg: "ground",- options: { palette: PAL.fire, height: 24, seed: 1 },+ options: {+ palette: ["#4a1712", "#8a1f17", "#c9281f", "#f2561d", "#ff8a2a", "#ffc23d", "#ffe26b", "#fff3a6", "#ffffff"],+ wood: ["#0e080a", "#24130f", "#3b2216", "#5a3520", "#8a5a34", "#b9884f"],+ height: 22,+ seed: 3,+ },};-const BARK = ramp(["#170d0b", "#3a2318", "#5c3a24", "#835a37"]);-const GRAIN = ramp(["#6e4428", "#b4824f", "#e2b77c"]);+const D = meta.duration, NL = noiseFor(D), SMOKE1 = hex("#5b5566"), ASH = [hex("#2a2530"), hex("#4a4350"), hex("#6b6270")];-// 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;+// the logs, near end first: they cross in an X over the coals, their near ends showing the cut grain and their+// far ends poking out past the flames+const LOGS = [+ [-19, 2, 15, -12, 3.4],+ [19, 2, -15, -12, 3.4],+];+const CROSS = 0.56;+// big tongues keep more orange and a smaller white heart, so the light doesn't wash them out+const BIG_LAYERS = [[1, 1, 6], [0.8, 0.9, 5], [0.62, 0.78, 4], [0.44, 0.6, 3], [0.26, 0.4, 1], [0.12, 0.22, 0]]; // the crossing, as a share of each log's length++// the fire: [x, base, height (share of o.height), half-width, back row?]+const TONGUES = [+ [-7.5, -7, 0.42, 1.8, 1],+ [7.5, -7, 0.46, 1.8, 1],+ [-3, -9, 0.78, 2.0, 1],+ [3.2, -9, 0.82, 2.0, 1],+ [-12, -3, 0.14, 1.3, 0],+ [12.5, -3, 0.16, 1.3, 0],+ [-9.5, -4.5, 0.3, 1.9, 0],+ [9.5, -4.5, 0.34, 1.9, 0],+ [-5, -6, 0.6, 2.6, 0],+ [5.2, -6, 0.66, 2.6, 0],+ [0, -7, 1, 3.4, 0],+];++// a log from its near end (x0, y0) to its far end, radius r, drawn between u0 and u1 along it: a 1 px dark rim,+// a lit top, grooves running along the grain, a shadowed underside; charred with glowing cracks in the fire+function log(p, L, W, H, u0, u1, t, S) {+ const [x0, y0, x1, y1, r] = L, dx = x1 - x0, dy = y1 - y0, len = Math.hypot(dx, dy), ax = dx / len, ay = dy / len;+ let nx = -ay, ny = ax;+ if (ny < 0) (nx = -nx), (ny = -ny);+ const rim = 1 - 1.05 / r;+ p.shade(Math.min(x0, x1) - r - 1, Math.min(y0, y1) - r - 1, Math.max(x0, x1) + r + 1, Math.max(y0, y1) + r + 1, (x, y, out) => {+ const along = (x - x0) * ax + (y - y0) * ay, u = along / len, s = ((x - x0) * nx + (y - y0) * ny) / r;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];+ const burn = clamp(1.2 - Math.abs(x) / 8), lane = Math.round(s * r * 0.85), run = rand(Math.floor(along / 3), lane, S);+ if (Math.abs(s) > rim || along > len - 1) return s < 0 && burn > 0.4 ? H[7] : W[0];+ if (burn > 0.35 && lane < 2) {+ // charred: black, with embers breathing in the cracks along the grain+ if (run < 0.55 && lane > -2) {+ const g = 0.5 + 0.5 * Math.sin((t / D) * Math.PI * 6 + rand(Math.floor(along / 2), lane, S + 1) * 6.3);+ out.k = 0.3 * burn * g;+ return g > 0.72 ? H[3] : g > 0.4 ? H[4] : H[5];+ }+ return lane < -1 ? W[1] : W[0];+ }+ if (lane <= -2) return run < 0.25 ? W[2] : mix(W[3], H[4], 0.45 * burn);+ if (lane === -1) return run < 0.45 ? W[1] : W[2];+ if (lane === 0) return run < 0.2 ? W[1] : W[2];+ return run < 0.4 ? W[0] : W[1];+ });+ // the near end's cut face: a dark rim, pale sapwood, growth rings round a dark heart+ if (u0 <= 0) p.ellipse(x0, y0, r * 0.62, r + 0.2, (d) => (d > 0.78 ? W[0] : d > 0.56 ? W[5] : d > 0.32 ? W[4] : W[3]));+}++// the bed of coals under the logs: coals that breathe in the heat, grey ash round the rim+function coals(p, W, H, t, S) {+ p.shade(-15, -3, 15, 2, (x, y, out) => {+ const dx = x / 14, dy = (y + 0.3) / 2.2, d = dx * dx + dy * dy;+ if (d > 1) return;+ const h = rand(Math.floor(x / 2), Math.floor(y), S + 20);+ if (d > 0.55 && h < 0.55) return ASH[h < 0.15 ? 2 : h < 0.32 ? 1 : 0];+ if (h > 0.5) {+ const g = (0.5 + 0.5 * Math.sin((t / D) * Math.PI * 4 + h * 40)) * (1.1 - d);+ out.k = 0.35 * g;+ return g > 0.7 ? H[2] : g > 0.5 ? H[3] : g > 0.3 ? H[4] : H[5];+ }+ return h > 0.3 ? W[1] : W[0];});- // 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));+ const F = fit(o.palette, 9), H = hotFirst(F), W = fit(o.wood, 6), S = o.seed, R = new Rng(S), HC = o.height;+ const N = (rate, seed = 0, off = 0) => NL(t, rate, seed, off);+ const fla = (tt) => 0.74 + 0.16 * NL(tt, 7.3, S + 1) + 0.1 * NL(tt, 19, S + 2), fl = fla(t);+ const GLOW = mix(mix(H[3], H[4], 0.5), WHITE, 0.25), SMOKE = mix(SMOKE1, H[6], 0.25);+ const SPARKS = [H[1], H[2], H[4], H[5]], EMB = [H[1], H[2], H[4], H[6]];++ const T = TONGUES.map(([dx, y, h, w, back], i) => ({ dx: dx + R.range(-0.4, 0.4), y, h: 3 + HC * h * R.range(0.92, 1.08), w: w * R.range(0.9, 1.1), back, env: h, n: (S * 7 + i) * 13 }));+ const lean = (tt) => NL(tt, 0.67, S + 90) * 0.12;+ const height = (i, tt) => {+ const { h, n } = T[i], leap = Math.max(0, NL(tt, 2.6, n + 70) - 0.55) * 1.4;+ return (h + 0.25 * h * NL(tt, 3.3, n) + h * leap) * (0.9 + 0.1 * fla(tt));+ };+ const sweep = (i, tt, h) => NL(tt, 2.2, T[i].n + 40) * (1 + h * 0.08) + lean(tt) * h * 0.9 - clamp(T[i].dx * 0.3, -2.5, 2.5);+ const tip = (i, tt) => {+ const h = height(i, tt);+ return [T[i].dx + sweep(i, tt, h) * 0.85, T[i].y - h * 0.88 + 3, h];+ };+ const tongueAt = (i) => {+ const { dx, y, w, n, back } = T[i], h = height(i, t);+ flameTongue(p, dx, y, h, w, sweep(i, t, h), N, n, H, back ? BACK_LAYERS : w > 2.2 ? BIG_LAYERS : LAYERS, 0.5, 1.1 + h * 0.04);+ };++ // smoke curling off the top, behind everything: each puff keeps the sway the plume had when it left the+ // flames, so the wiggle climbs the plume, and the draught bends it over as it rises+ looped(t, D, 48, S + 300, (r) => ({ x: r.range(-5, 5), y: -HC * 0.8 - r.range(0, 8), vx: r.range(-2, 2), vy: -r.range(10, 17), life: r.range(2, 2.9), s: r.range(2.4, 3.8) }), (q, age) => {+ const [x, y] = drift(q.x, q.y, q.vx, q.vy, age, 4, -20, 1.6, 1);+ smokePuff(p, x + NL(t - age, 0.8, S + 60) * (2 + 3 * age), y, 1 - age / q.life, q.s, SMOKE);+ });+ // flame puffs shed from the tips: they burn out above the fire, some into smoke+ const puffs = [];+ looped(t, D, T.length * 24, S + 200, (r, j) => {+ const i = j % T.length, fire = r.range(0.14, 0.3), smokes = r.chance(0.45);+ return { i, fire, smokes, sl: r.range(0.8, 1.4), ox: r.range(-1, 1), oy: r.range(0, 4), vx: r.range(-4, 4), vy: -r.range(15, 30), s: r.range(0.8, 1.6) * (0.8 + 0.6 * T[i].env), f: r.next(), life: fire + (smokes ? 1.4 : 0) };+ }, (q, age) => {+ const [tx, ty] = tip(q.i, t - age);+ const [x, y, vx, vy] = drift(tx + q.ox, ty + q.oy, q.vx, q.vy, Math.min(age, q.fire), 0, -95, 5, 3.2);+ if (age < q.fire) return puffs.push([x, y, 1 - age / q.fire, q.s, q.f]);+ if (age - q.fire > q.sl) return;+ const [sx, sy] = drift(x, y, vx * 0.6, vy * 0.6 - 6, age - q.fire, 2, -16, 1.6, 1.2);+ smokePuff(p, sx, sy, 1 - (age - q.fire) / q.sl, q.s * 0.7, 0);});- 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);++ coals(p, W, H, t, S);+ for (const L of LOGS) log(p, L, W, H, CROSS, 1, t, S + 11);+ for (let i = 0; i < T.length; i++) if (T[i].back) tongueAt(i);+ // flames licking up off the burning wood+ looped(t, D, 90, S + 210, (r) => ({ x: r.range(-10, 10), y: -r.range(3, 8), vx: r.range(-5, 5), vy: -r.range(20, 40), life: r.range(0.16, 0.3), s: r.range(1, 1.8), f: r.next() }), (q, age) => {+ const [x, y] = drift(q.x, q.y, q.vx, q.vy, age, 0, -95, 5, 3.2);+ firePuff(p, x, y, 1 - age / q.life, q.s, q.f, H);+ });+ for (let i = 0; i < T.length; i++) if (!T[i].back) tongueAt(i);+ // licks torn off the tips, rising and shrinking+ looped(t, D, T.length * 12, S + 220, (r, j) => ({ i: j % T.length, vx: r.range(-3, 3), vy: -r.range(12, 22), s: r.range(0.9, 1.6) * (0.8 + 0.5 * T[j % T.length].env), life: 0.26 }), (q, age) => {+ const [tx, ty] = tip(q.i, t - age);+ lick(p, tx + q.vx * age, ty - 2 + q.vy * age, 1 - age / q.life, q.s, H);+ });+ for (const [x, y, k, s, f] of puffs) firePuff(p, x, y, k, s, f, H);+ for (const L of LOGS) log(p, L, W, H, 0, CROSS, t, S + 11);++ // pops: a crack, a flash, and a fistful of sparks thrown up out of the wood that bounce on the floor+ looped(t, D, 4, S + 400, (r) => ({ x: r.range(-9, 9), y: -r.range(4, 9), n: r.int(3, 5), seed: r.int(0, 1e6), life: 0.7 }), (q, age) => {+ if (age < 0.08) {+ p.px(q.x, q.y, WHITE);+ p.glow(q.x, q.y, 12, H[1], 0.7 * (1 - age / 0.08));+ }+ const r = new Rng(q.seed);+ for (let j = 0; j < q.n; j++) {+ const a = -Math.PI / 2 + r.range(-0.8, 0.8), sp = r.range(110, 220), life = r.range(0.25, 0.6);+ if (age >= life) continue;+ const [x, y, vx, vy] = sparkAt(q.x, q.y, Math.cos(a) * sp, Math.sin(a) * sp, age, 0);+ spark(p, x, y, vx, vy, 1 - age / life, SPARKS);+ }+ });+ // embers carried up by the heat, wandering and cooling+ looped(t, D, 36, S + 500, (r) => ({ x: r.range(-7, 7), y: -r.range(8, 18), vx: r.range(-15, 15), vy: -r.range(25, 60), life: r.range(1.1, 2.5), s: r.chance(0.15) ? 2 : r.range(1, 1.6), a: r.range(0, 6.3), b: r.range(0, 6.3) }), (q, age) => {+ const [x, y] = drift(q.x, q.y, q.vx, q.vy, age, 0, -30, 1.6, 1.6);+ ember(p, x + 7 * (Math.sin(age * 2.3 + q.a) - Math.sin(q.a)), y + 2 * (Math.sin(age * 3 + q.b) - Math.sin(q.b)), 1 - age / q.life, q.s, EMB, age * 40 + q.a);+ });++ // light: a big warm room light, a hot heart, a pool on the floor, all breathing with the flames+ const br = 0.92 + 0.08 * N(0.67, S + 3);+ const lx = lean(t) * 12;+ p.glow(lx, -8, 74 * br * (0.9 + 0.1 * fl), GLOW, 0.3 * fl);+ for (const [x, y, k] of [[-6, -17, 0.85], [0, -21, 1], [6, -17, 0.85]]) {+ p.glow(x + lx, y, 46 * br, GLOW, 0.3 * k * fl);+ p.glow(x * 0.6, y + 13, 15, H[2], 0.16 * k * fl);+ }+ p.glow(0, -3, 9, H[0], 0.16 * fl);+ floorLight(p, 0, 0.5, 48, 8, GLOW, 0.3 * fl);}diff --git a/src/fx/fire/candle.js b/src/fx/fire/candle.jsindex 5798cd8..a2b32ee 100644--- a/src/fx/fire/candle.js+++ b/src/fx/fire/candle.js@@ -1,72 +1,120 @@-import { PAL, ramp, at, clamp, seg, ease, loopNoise, tileNoise, TAU, hex } from "../../core/index.js";-import { fit, pool } from "./_lib.js";+// The layered flame tongue is adapted from Sprite Fusion's open-source fire+// (https://www.spritefusion.com/pixel-art-vfx/fire), MIT License, Copyright (c) 2026 Hugo Duprez.+import { fit, mix, hex, rand, clamp, smooth, WHITE } from "../../core/index.js";+import { noiseFor, hotFirst, flameTongue, smokePuff, looped, drift, floorLight } 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,+ desc: "A wax candle in a brass dish: a calm flame with a blue root that sways and stretches, a halo of light, motes drifting in it, a bead of wax running down a drip.",+ tags: ["fire", "candle", "prop", "light", "calm", "ambient", "loop"],+ size: [56, 76],+ origin: [28, 64],+ duration: 4,loop: true,fps: 30,bg: "ground",- options: { palette: PAL.fire, height: 14, seed: 2 },+ options: {+ palette: ["#4a1712", "#8a1f17", "#c9281f", "#f2561d", "#ff8a2a", "#ffc23d", "#ffe26b", "#fff3a6", "#ffffff"],+ root: ["#1b2a8a", "#3a62e0", "#7fb4ff"],+ wax: ["#2e201e", "#5e4436", "#8e6e58", "#b8957a", "#d8b896", "#f0dcc0"],+ brass: ["#2a1a10", "#6a4a1e", "#b4862e", "#e8c060", "#fff0b0"],+ seed: 2,+ },};-const WAX = ramp(["#4a2f37", "#9a7468", "#d8bfa6", "#f1e4cc", "#fffaee"]);-const WICK = hex("#2a1716"), BLUE = hex("#3a5cd0"), BLUE_DARK = hex("#24307a");+const D = meta.duration, NL = noiseFor(D), TOP = -16, WICK = TOP - 3;+// a calm flame: an orange rim round gold, yellow, a pale heart and a small white core low down+const CALM = [[1, 1, 5], [0.8, 0.88, 3], [0.6, 0.72, 2], [0.38, 0.52, 1], [0.18, 0.3, 0]];+// the bead runs down this drip, from the rim to its bulb+const DRIP = { x: 4, y0: TOP + 2, y1: -7 };++function dish(p, B, H, fl) {+ p.ellipse(0, 1, 10, 2.6, (d, a) => (d > 0.82 ? B[0] : Math.sin(a) < -0.2 ? (d > 0.6 ? mix(B[3], H[3], 0.3 * fl) : B[2]) : d > 0.55 ? B[1] : B[2]));+ p.rect(-8, 2, 17, 1, B[1]);+ p.rect(-7, 3, 15, 1, B[0]);+}++// the candle: a wax pillar with a dark outline, a highlight band on the lit side, a shadow side, a pool of+// melted wax lit by the flame, a long glossy drip down the right ending in a bulb and a short one on the left+function candle(p, X, H, fl) {+ const L = TOP, cols = [X[1], X[4], X[5], X[4], X[4], X[3], X[3], X[2], X[0]];+ for (let i = 0; i < 9; i++) {+ const x = i - 4;+ p.rect(x, L + 1, 1, -L - 2, cols[i]);+ if (i === 2) p.rect(x, -8, 1, 7, X[4]);+ }+ p.rect(-3, -1, 7, 1, X[2]);+ p.px(-4, -1, X[0]);+ p.px(4, -1, X[0]);+ // the rim and the pool of melted wax round the wick, lit by the flame+ p.rect(-3, L, 7, 1, mix(X[5], H[2], 0.25 * fl));+ p.px(-4, L, X[1]);+ p.px(4, L, X[1]);+ p.rect(-2, L + 1, 5, 1, mix(X[5], H[1], 0.5 * fl));+ p.rect(-1, L + 1, 3, 1, mix(X[4], H[2], 0.45 * fl));+ // the long drip: a lighter, glossy run down the right that bulges past the side into a bulb+ const y1 = DRIP.y1;+ p.rect(3, L + 1, 1, y1 - L - 1, X[4]);+ p.rect(4, L + 2, 1, y1 - L - 2, X[3]);+ p.px(5, L + 3, X[0]);+ p.rect(5, L + 4, 1, y1 - L - 4, X[0]);+ p.rect(3, y1, 2, 2, X[4]);+ p.px(5, y1, X[3]);+ p.px(5, y1 + 1, X[2]);+ p.px(6, y1, X[0]);+ p.px(6, y1 + 1, X[0]);+ p.rect(3, y1 + 2, 3, 1, X[0]);+ p.px(3, L + 2, X[5]);+ // the short drip on the left+ p.rect(-4, L + 1, 1, 4, X[4]);+ p.px(-5, L + 3, X[1]);+ p.px(-5, L + 4, X[1]);+ p.px(-4, L + 5, X[3]);+}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);+ const F = fit(o.palette, 9), H = hotFirst(F), RT = fit(o.root, 3), X = fit(o.wax, 6), B = fit(o.brass, 5), S = o.seed;+ // calm: everything moves slowly, the flame now and then stretches tall+ const N = (rate, seed = 0, off = 0) => NL(t, rate * 0.35, seed, off);+ const fl = 0.86 + 0.08 * NL(t, 2, S + 1) + 0.06 * NL(t, 7, S + 2), stretch = Math.max(0, NL(t, 0.75, S + 3) - 0.3) * 0.6;+ const h = 12 * (1 + stretch) * (0.94 + 0.06 * fl), sway = NL(t, 0.5, S + 4) * 1.6 + NL(t, 1.5, S + 5) * 0.5;+ const GLOW = mix(mix(H[3], H[4], 0.5), WHITE, 0.3), cy = WICK - h * 0.4;++ // a pool of warm light on the floor and the halo behind the flame+ floorLight(p, 0, 1, 26, 5, GLOW, 0.3 * fl);+ p.glow(sway * 0.3, cy, 38 * fl, GLOW, 0.42 * fl);+ p.glowRing(sway * 0.3, cy, 10, 4, H[2], 0.12 * fl);+ dish(p, B, H, fl);+ candle(p, X, H, fl);+ // the bead of wax: it swells at the rim, runs down the drip and sets into its bulb+ const run = (t % D) / D, swell = smooth(0, 0.3, run), slide = smooth(0.3, 0.85, run), set = smooth(0.85, 1, run);+ if (set < 1 && swell > 0.15) {+ const by = Math.round(DRIP.y0 + (DRIP.y1 - DRIP.y0) * slide);+ p.px(DRIP.x, by, mix(X[5], H[1], 0.4 * fl));+ if (swell > 0.6 && set < 0.5) p.px(DRIP.x + 1, by, X[4]), p.px(DRIP.x + 1, by + 1, X[2]);}- // 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];+ // the wick, glowing at its tip+ p.line(0, TOP, 0, WICK + 1, X[0]);+ p.px(0, WICK + 1, H[4]);+ // the flame and its blue root+ flameTongue(p, 0, WICK + 1, h, 2.6, sway, N, S * 31, H, CALM, 0.25, 0.6);+ for (let dx = -2; dx <= 2; dx++) {+ const a = 1 - Math.abs(dx) * 0.2;+ p.dot(dx, WICK + 1, Math.abs(dx) === 2 ? RT[0] : RT[1], a);+ if (Math.abs(dx) <= 1) p.dot(dx, WICK + 2, RT[0], 0.7);+ }+ p.px(0, WICK, RT[2]);+ // a thread of smoke now and then off the tip+ looped(t, D, 6, S + 300, (r) => ({ vx: r.range(-1.5, 1.5), vy: -r.range(8, 12), life: r.range(1.4, 2.2), s: r.range(0.8, 1.2) }), (q, age) => {+ const [x, y] = drift(sway, WICK - h, q.vx, q.vy, age, 1, -6, 1, 0.8);+ smokePuff(p, x + NL(t - age, 0.6, S + 60) * (1 + age * 2), y, 1 - age / q.life, q.s, 0, false, 0.6);+ });+ // motes drifting in the candlelight, catching it as they pass close+ looped(t, D, 10, S + 400, (r) => ({ x: r.range(-20, 20), y: r.range(-44, -8), vx: r.range(-3, 3), vy: r.range(-4, 2), life: r.range(2.5, 4), ph: r.range(0, 6.3) }), (q, age) => {+ const x = q.x + q.vx * age + Math.sin(age * 1.3 + q.ph) * 2, y = q.y + q.vy * age, d = Math.hypot(x, y - cy);+ const k = Math.min(1, age * 2, (q.life - age) * 2) * clamp(1.2 - d / 26);+ if (k > 0.15) p.dot(x, y, k > 0.6 ? H[1] : H[3], k), p.glow(x, y, 3, H[2], 0.2 * k);});- // 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);+ // the hot core of the light+ p.glow(sway * 0.5, WICK - h * 0.3, 10, H[1], 0.35 * fl);}diff --git a/src/fx/fire/ember-burst.js b/src/fx/fire/ember-burst.jsdeleted file mode 100644index 6494ab7..0000000--- a/src/fx/fire/ember-burst.js+++ /dev/null@@ -1,48 +0,0 @@-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.jsindex d16ff17..70d1a94 100644--- a/src/fx/fire/fire-breath.js+++ b/src/fx/fire/fire-breath.js@@ -1,52 +1,100 @@-import { PAL, RAMP, ramp, at, cycle, tileFbm, loopNoise, TAU, WHITE } from "../../core/index.js";-import { fit } from "./_lib.js";+// The flame-puff, smoke and spark recipe is adapted from Sprite Fusion's open-source explosion+// (https://www.spritefusion.com/pixel-art-vfx/explosion), MIT License, Copyright (c) 2026 Hugo Duprez.+import { fit, mix, hex, clamp, WHITE } from "../../core/index.js";+import { noiseFor, hotFirst, flameBlade, flameTongue, firePuff, smokePuff, spark, ember, drift, looped, LAYERS, BACK_LAYERS } 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,+ desc: "A roaring cone of fire streaming right from the mouth: white-hot at the lips, billowing out and cooling to red and smoke at its edges, sparks thrown out ahead.",+ tags: ["fire", "breath", "dragon", "stream", "cone", "directional", "loop"],+ size: [160, 116],+ origin: [12, 72],+ duration: 1.5,loop: true,fps: 30,bg: "dark",- options: { palette: PAL.fire, length: 92, spread: 0.25, seed: 7 },+ options: {+ palette: ["#4a1712", "#8a1f17", "#c9281f", "#f2561d", "#ff8a2a", "#ffc23d", "#ffe26b", "#fff3a6", "#ffffff"],+ spread: 0.24,+ speed: 320,+ seed: 6,+ },};+const D = meta.duration, NL = noiseFor(D), SMOKE1 = hex("#5b5566");+// the dying licks: red and deep orange, no white heart+const COOL_LAYERS = [[1, 1, 7], [0.72, 0.82, 6], [0.44, 0.58, 5]];+// the jet at the lips: [length, half-width, angle]+const JET = [[42, 4.2, 0], [32, 3.8, -0.08], [30, 3.8, 0.08], [20, 4.6, 0]];+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]));+ const F = fit(o.palette, 9), H = hotFirst(F), S = o.seed, A = o.spread, V = o.speed;+ const N = (rate, seed = 0, off = 0) => NL(t, rate, seed, off);+ const GLOW = mix(mix(H[3], H[4], 0.5), WHITE, 0.25), SMOKE = mix(SMOKE1, H[6], 0.3), SPARKS = [H[1], H[2], H[4], H[5]], EMB = [H[1], H[2], H[4], H[6]];+ // the roar: the stream surges and the cone sways a little+ const roar = (tt) => 0.85 + 0.15 * NL(tt, 3, S + 1), sway = (tt) => NL(tt, 1.3, S + 2) * 0.05;++ // the cone: puffs of flame blown out of the mouth that slow, swell, rise and cool; those near the edges+ // cool first, and many burn out into rolling smoke+ const fire = [], smoke = [];+ looped(t, D, 260, S + 100, (r) => {+ const e = r.range(-1, 1), fl = r.range(0.42, 0.8) * (1 - 0.3 * Math.abs(e)), sm = r.chance(0.2 + 0.4 * Math.abs(e));+ return { e, sp: r.range(0.75, 1.1), fl, sm, sl: r.range(0.5, 0.85), s: r.range(3, 5.2), f: r.next(), ox: r.range(4, 10), life: fl + (sm ? 0.85 : 0) };+ }, (q, age) => {+ const tb = t - age, a = q.e * A + sway(tb) - 0.04, v = V * q.sp * roar(tb);+ const ta = Math.min(age, q.fl), [x, y, vx, vy] = drift(q.ox, q.e * 1.5, Math.cos(a) * v, Math.sin(a) * v, ta, 0, -100, 2, 2.4);+ if (age < q.fl) return fire.push([age, x, y, q]);+ if (!q.sm || age - q.fl > q.sl) return;+ const sa = age - q.fl, [sx, sy] = drift(x, y, vx * 0.5, vy * 0.6 - 8, sa, 0, -26, 1.8, 1.2);+ smoke.push([sa, sx, sy, q]);+ });+ for (const [sa, x, y, q] of smoke) smokePuff(p, x, y, 1 - sa / q.sl, q.s * 1.1, SMOKE, true, 0.7);+ fire.sort((a, b) => b[0] - a[0]);+ for (const [age, x, y, q] of fire) {+ const u = age / q.fl, edge = Math.abs(q.e), size = q.s * (0.75 + 1.6 * u);+ // the heart of the stream stays hot longer than its edges+ const heat = Math.min(0.999, Math.pow(u, 1.5) * (0.85 + 0.2 * edge) + 0.3 * edge * edge);+ // near the mouth the fire rolls in round billows; further out each billow tears into a tongue licking up+ // and back, thinning to a lick as it cools, before the smoke takes it+ const tear = clamp((u - 0.32) / 0.2);+ firePuff(p, x, y, 1 - heat, size * (1 - 0.55 * tear), q.f, H, 0.1, -0.5, -0.86);+ if (tear > 0) {+ const n = Math.floor(q.f * 1e5), h = size * (1.5 + 0.5 * N(4, n)) * (1.2 - heat * 0.6) * tear;+ flameTongue(p, x, y + size * 0.3, h, size * 0.5 * (1.1 - heat * 0.5), -h * 0.4 + N(2.5, n + 1) * 2, N, n, H, heat < 0.45 ? LAYERS : heat < 0.72 ? BACK_LAYERS : COOL_LAYERS);+ }+ }+ // licks curling off the edges of the cone+ for (let i = 0; i < 6; i++) {+ const n = (S * 3 + i) * 19, side = i % 2 ? 1 : -1, d = 18 + (i >> 1) * 16 + N(2, n) * 4, L = (9 + 5 * (0.5 + 0.5 * N(5, n + 1))) * (1 - d / 120);+ const ex = d, ey = side * d * A * 0.85 - d * 0.06;+ flameBlade(p, ex, ey, 0.75, side * 0.45 - 0.48, L, 1.6 + L * 0.08, -side * 3, N, n, H, LAYERS);+ }+ // the roar: bright streaks racing out through the heart of the cone+ looped(t, D, 70, S + 250, (r) => ({ e: r.range(-0.6, 0.6), v: r.range(330, 470), life: r.range(0.12, 0.26), l: r.range(4, 9) }), (q, age) => {+ const a = q.e * A - 0.03, [x, y, vx, vy] = drift(6, q.e * 2, Math.cos(a) * q.v, Math.sin(a) * q.v, age, 0, -60, 2, 2);+ const sp = Math.hypot(vx, vy), k = 1 - age / q.life, L = q.l * (sp / 400);+ p.line(x - (vx / sp) * L, y - (vy / sp) * L, x, y, (u) => (u > 0.6 ? (k > 0.5 ? H[0] : H[1]) : k > 0.5 ? H[2] : H[3]));});- // 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);+ // the jet at the lips: white-hot, overlapping tongues that flutter as the breath roars+ JET.forEach(([len, w, a], i) => {+ const n = (S * 5 + i) * 17, L = len * roar(t) * (0.85 + 0.2 * N(5, n)), aa = a + sway(t);+ flameBlade(p, 0, 0, Math.cos(aa), Math.sin(aa), L, w, N(3, n + 3) * 3, N, n, H, LAYERS, 0.5, 1.5);});- // 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));++ // sparks flung out ahead and falling; embers lifting off the far end+ looped(t, D, 40, S + 300, (r) => ({ d: r.range(4, 60), e: r.range(-1, 1), v: r.range(140, 280), life: r.range(0.25, 0.55) }), (q, age) => {+ const a = q.e * A * 1.8 - 0.12, [x, y, vx, vy] = drift(q.d, q.e * q.d * A, Math.cos(a) * q.v, Math.sin(a) * q.v - 30, age, 0, 190, 2, 2);+ spark(p, x, y, vx, vy, 1 - age / q.life, SPARKS);+ });+ looped(t, D, 18, S + 400, (r) => ({ x: r.range(50, 100), y: r.range(-14, 6), vx: r.range(10, 40), vy: -r.range(20, 50), life: r.range(0.8, 1.4), s: r.chance(0.2) ? 2 : 1, ph: r.range(0, 6.3) }), (q, age) => {+ const [x, y] = drift(q.x, q.y, q.vx, q.vy, age, 0, -30, 1.6, 1.6);+ ember(p, x + 5 * (Math.sin(age * 2.3 + q.ph) - Math.sin(q.ph)), y, 1 - age / q.life, q.s, EMB, age * 40 + q.ph);});- p.glowLine(4, 0, L * 0.75, 0, 22, F[4], 0.3 * roar);- p.glow(4, 0, 12, F[6], 0.45);++ // light: a flare at the lips, light all along the cone widening with it, a broad halo+ const k = roar(t);+ p.glow(3, 0, 34 * k, GLOW, 0.75 * k);+ p.glow(3, 0, 10, H[0], 0.55);+ for (let d = 10; d < 126; d += 8) p.glow(d, -d * 0.1, 10 + d * 0.2, GLOW, 0.32 * k * (1 - d / 150));+ p.glow(64, -12, 96, GLOW, 0.16 * k);}diff --git a/src/fx/fire/fire-ring.js b/src/fx/fire/fire-ring.jsindex 2a12410..2f9f9c3 100644--- a/src/fx/fire/fire-ring.js+++ b/src/fx/fire/fire-ring.js@@ -1,66 +1,141 @@-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";+// The flame-puff, smoke and spark recipe and the floor ring are adapted from Sprite Fusion's open-source explosion+// (https://www.spritefusion.com/pixel-art-vfx/explosion), and the tongue from its fire+// (https://www.spritefusion.com/pixel-art-vfx/fire), MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Lights, P, PF, Rng, fit, band, clamp, smooth, ease, noise, rand, TAU, WHITE, hex, mix, rgb } from "../../core/index.js";+import { hotFirst, flameTongue, simDraw, LAYERS, BACK_LAYERS } from "./_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,+ desc: "A white flash at the feet, then flames race outward along the floor in a ring, flaring as the front passes and burning down behind it over a smouldering scorch.",+ tags: ["fire", "ring", "nova", "aoe", "spell", "ground", "one-shot"],+ size: [224, 128],+ origin: [112, 92],+ duration: 3.9,loop: false,fps: 30,bg: "ground",- options: { palette: PAL.fire, radius: 52, height: 20, count: 30, seed: 12 },+ actor: 2,+ options: {+ palette: ["#4a1712", "#8a1f17", "#c9281f", "#f2561d", "#ff8a2a", "#ffc23d", "#ffe26b", "#fff3a6", "#ffffff"],+ reach: 92,+ seed: 6,+ },};-const SQ = 0.2; // how flat the ring lies on the floor-const CHAR = [hex("#141014"), hex("#2a1c1c")];+const SY = 0.2, CHARGE = 0.32, SPREAD = 0.75, SOOT = hex("#0d0a12"), SOOT2 = hex("#17121d"), WARM = rgb(255, 176, 96);+// the dying flames: deep orange and red, no white heart+const EMBER_LAYERS = [[1, 1, 7], [0.7, 0.8, 6], [0.4, 0.55, 5]];-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];- });+export function create(o) {+ const F = fit(o.palette, 9), H = hotFirst(F), REACH = o.reach, R = new Rng(o.seed), floor = () => 0, S = o.seed * 7;+ const ps = new Particles({ rng: R, ground: floor, sparks: [H[1], H[2], H[4], H[5]] }), lights = new Lights();+ const GLOW = mix(mix(H[3], H[4], 0.5), WHITE, 0.25);+ const front = (t) => REACH * ease.outCubic(clamp((t - CHARGE) / SPREAD));+ const reachedAt = (d) => CHARGE + SPREAD * (1 - Math.cbrt(1 - Math.min(1, d / REACH)));+ // the flames: rings of tongues on the floor, each lit as the front reaches it, flaring then burning down+ const sites = [];+ for (let r = 10; r <= REACH; r += 9) {+ const per = TAU * Math.sqrt((r * r + (r * SY) ** 2) / 2), n = Math.max(5, Math.round(per / 8.5));+ for (let k = 0; k < n; k++) {+ const a = ((k + R.range(0.15, 0.85)) / n) * TAU, rr = r + R.range(-3, 3), q = Math.min(1, rr / REACH);+ // near the middle they flash and go out as the front passes; the rim, where it stops, burns on and down+ sites.push({ x: Math.cos(a) * rr, y: Math.sin(a) * rr * SY, back: Math.sin(a) < 0, t0: reachedAt(rr) + R.range(0, 0.04), life: (0.3 + 1.0 * q * q) * R.range(0.85, 1.2), h: R.range(9, 15) * (0.6 + 0.55 * q), w: R.range(1.8, 2.7) * (0.75 + 0.3 * q), n: R.int(0, 1e5) });+ }}- // 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);+ sites.sort((a, b) => a.y - b.y);+ let t = 0, burst = false;++ const flames = (p, back) => {+ const NZ = (rate, seed = 0, off = 0) => noise(t * rate + off, seed);+ for (const s of sites) {+ if (s.back !== back) continue;+ const age = t - s.t0;+ if (age < 0 || age > s.life) continue;+ const u = age / s.life, rise = ease.outBack(clamp(age / 0.08), 2), fade = 1 - Math.pow(Math.max(0, (u - 0.1) / 0.9), 1.3);+ const h = s.h * rise * fade * (0.85 + 0.15 * noise(t * 3.3, s.n)) * (1 + 0.5 * Math.max(0, noise(t * 2.6, s.n + 70) - 0.55));+ if (h < 1) continue;+ // fresh flames white-hot, then cooling as they burn down; the far ones a step dimmer+ const L = u < 0.3 ? (back ? BACK_LAYERS : LAYERS) : u < 0.65 ? BACK_LAYERS : EMBER_LAYERS;+ flameTongue(p, s.x, s.y, h, s.w * (0.6 + 0.4 * fade), NZ(2.2, s.n + 40) * 1.5 - s.x * 0.02, NZ, s.n, H, L);+ }+ };+ // the scorch: a translucent stain of soot where the fire has crossed, sparse embers cooling in it+ const scorch = (p) => {+ const fr = front(t), end = 1 - smooth(meta.duration - 1.2, meta.duration - 0.15, t);+ if (fr < 1 || end <= 0) return;+ for (let y = Math.floor(-fr * SY); y <= Math.ceil(fr * SY); y++)+ for (let x = Math.floor(-fr); x <= Math.ceil(fr); x++) {+ const d = Math.hypot(x + 0.5, (y + 0.5) / SY);+ if (d > fr) continue;+ const since = t - reachedAt(d), h = rand(x, y, S), hot = 1 - since / (1.2 + h * 0.9);+ if (hot > 0 && h < 0.03 + 0.06 * hot) {+ p.px(x, y, hot > 0.7 ? H[3] : hot > 0.45 ? H[4] : hot > 0.2 ? H[5] : H[6]);+ p.light(x, y, H[4], 0.3 * hot);+ continue;+ }+ p.blend(x, y, h < 0.5 ? SOOT : SOOT2, Math.min(1, since * 3) * (0.55 - (d / REACH) * 0.25) * end);+ }+ };+ const ring = (p, back) => {+ const k = (t - CHARGE) / (SPREAD + 0.1);+ if (k < 0 || k >= 1) return;+ band(p, 0, 0, front(t) + 1.5, SY, Math.max(1.5, 6 * (1 - k)), k < 0.75 ? 1 : (1 - k) / 0.25, [H[6], H[4], H[2], H[1]], (g) => Math.sin(g) < 0 === back, k < 0.12);+ };++ return {+ update(dt) {+ t += dt;+ // the charge: streaks of fire spiral in to the feet, heat building there+ if (t < CHARGE - 0.05 && R.chance(0.9 * dt * 60)) {+ const a = R.range(0, TAU), d = R.range(26, 54), T = R.range(0.18, 0.26), v = (d * 3) / (Math.exp(3 * T) - 1);+ const x = Math.cos(a) * d, y = Math.min(-2, -6 + Math.sin(a) * d * 0.45), l = Math.hypot(x, y + 4) || 1;+ ps.spawn(P.STREAK, x, y, (-x / l) * v, ((-4 - y) / l) * v, T, R.chance(0.5) ? H[2] : H[3]);+ }+ if (t < CHARGE && R.chance(0.5 * dt * 60 * (t / CHARGE))) ps.spawn(P.FIRE, R.range(-4, 4), -1, R.range(-8, 8), -R.range(20, 40), R.range(0.12, 0.24), 0, R.range(1, 2.2));+ if (!burst && t >= CHARGE) {+ burst = true;+ lights.add(0, -18, 64, WARM, 0.85, 0.5);+ lights.add(0, -6, 30, WHITE, 0.8, 0.08);+ for (let i = 0; i < 40; i++) {+ const a = R.range(0, TAU), sp = R.range(80, 220);+ ps.spawn(P.SPARK, Math.cos(a) * 3, -2, Math.cos(a) * sp, Math.sin(a) * sp * 0.4 - R.range(40, 120), R.range(0.2, 0.5));+ }+ }+ // fire shed off the burning ring: puffs that rise and some cool into smoke, and embers+ if (t > CHARGE && t < CHARGE + SPREAD + 1.2)+ for (let i = 0; i < 3; i++) {+ if (!R.chance(0.75 * dt * 60)) continue;+ const s = R.pick(sites), age = t - s.t0;+ if (age < 0 || age > s.life * 0.7) continue;+ ps.spawn(P.FIRE, s.x + R.range(-1, 1), s.y - s.h * 0.6, R.range(-5, 5), -R.range(20, 40), R.range(0.2, 0.4), 0, R.range(1.2, 2.4), 0, R.chance(0.5) ? PF.SMOKES | (s.back ? PF.BACK : 0) : s.back ? PF.BACK : 0);+ if (R.chance(0.12)) ps.spawn(P.EMBER, s.x, s.y - s.h * 0.5, R.range(-15, 15), -R.range(30, 70), R.range(0.6, 1.3), H[3], 1, 0, s.back ? PF.BACK : 0);+ }+ ps.update(dt);+ lights.update(dt);+ },+ drawBack(p) {+ scorch(p);+ ring(p, true);+ flames(p, true);+ simDraw(p, ps, H, "back");+ // light on the floor running with the front+ const fr = front(t), k = t < CHARGE ? 0 : 1 - smooth(CHARGE + SPREAD, CHARGE + SPREAD + 1.4, t);+ if (k > 0) for (let i = 0; i < 16; i++) p.glow(Math.cos((i / 16) * TAU) * fr, Math.sin((i / 16) * TAU) * fr * SY - 3, 16, GLOW, 0.2 * k);+ },+ draw(p) {+ ring(p, false);+ flames(p, false);+ simDraw(p, ps, H, "front");+ // the charge glowing at the feet, then the white flash as it goes+ if (t < CHARGE) p.glow(0, -3, 8 + 22 * (t / CHARGE), GLOW, 0.6 * (t / CHARGE));+ if (t >= CHARGE && t < CHARGE + 0.1) {+ const k = 1 - (t - CHARGE) / 0.1;+ p.ellipse(0, -1, 14 * (0.6 + 0.4 * k), 4, H[2]);+ p.ellipse(0, -1, 9 * (0.6 + 0.4 * k), 2.6, k > 0.5 ? WHITE : H[1]);+ }+ const k = smooth(CHARGE - 0.05, CHARGE, t) * (1 - smooth(CHARGE + SPREAD * 0.5, CHARGE + SPREAD + 1.2, t));+ if (k > 0) p.glow(0, -6, 92, GLOW, 0.3 * k);+ lights.draw(p);+ },+ };}diff --git a/src/fx/fire/fire-tornado.js b/src/fx/fire/fire-tornado.jsindex 4fb3778..97f818d 100644--- a/src/fx/fire/fire-tornado.js+++ b/src/fx/fire/fire-tornado.js@@ -1,58 +1,103 @@-import { PAL, RAMP, ramp, at, clamp, tileFbm, rng, wrap, TAU, WHITE } from "../../core/index.js";-import { fit, pool } from "./_lib.js";+// The flame-puff, smoke and ember recipe is adapted from Sprite Fusion's open-source fire+// (https://www.spritefusion.com/pixel-art-vfx/fire), MIT License, Copyright (c) 2026 Hugo Duprez.+import { fit, mix, hex, clamp, WHITE, TAU } from "../../core/index.js";+import { noiseFor, pnoise, hotFirst, flameTongue, firePuff, smokePuff, looped, drift, floorLight, LAYERS, BACK_LAYERS } 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,+ desc: "A spinning funnel of fire: spiral bands turning round it, licks flung off its sides, a ring of flame whirling at its foot, embers orbiting it in and out of view.",+ tags: ["fire", "tornado", "vortex", "spell", "aoe", "loop"],+ size: [120, 152],+ origin: [60, 136],+ duration: 2,loop: true,fps: 30,bg: "ground",- options: { palette: PAL.fire, height: 86, seed: 10 },+ options: {+ palette: ["#4a1712", "#8a1f17", "#c9281f", "#f2561d", "#ff8a2a", "#ffc23d", "#ffe26b", "#fff3a6", "#ffffff"],+ height: 80,+ seed: 4,+ },};+const D = meta.duration, NL = noiseFor(D), SMOKE1 = hex("#5b5566"), SPIN = 3; // turns of the surface a loop+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);+ const F = fit(o.palette, 9), H = hotFirst(F), S = o.seed, HT = o.height, ph = t / D;+ const N = (rate, seed = 0, off = 0) => NL(t, rate, seed, off);+ const GLOW = mix(mix(H[3], H[4], 0.5), WHITE, 0.25), SMOKE = mix(SMOKE1, H[6], 0.25), EMB = [H[1], H[2], H[4], H[6]];+ // the funnel: narrow at the foot, flaring at the top, its spine snaking as it turns+ const cx = (v, tt = t) => 3.2 * Math.sin(v * 4.2 - (tt / D) * TAU * 2) * v + 2 * Math.sin((tt / D) * TAU) * v;+ const rad = (v) => 3.5 + 15 * Math.pow(v, 1.35);+ const spin = (v, tt = t) => (tt / D) * TAU * SPIN + v * 5.5; // the surface turns, twisted up the column++ // embers orbiting: behind the column first, in front after it+ const orbit = [];+ looped(t, D, 30, S + 500, (r) => ({ v0: r.range(0.02, 0.7), rise: r.range(0.12, 0.3), a: r.range(0, TAU), w: r.range(4, 7), out: r.range(4, 12), life: r.range(1.2, 2.4), big: r.chance(0.2) }), (q, age) => {+ const v = q.v0 + q.rise * age, R = rad(Math.min(1, v)) + q.out + age * 4, a = q.a + q.w * age, k = 1 - age / q.life;+ const x = cx(Math.min(1, v), t) + Math.cos(a) * R, y = -v * HT + Math.sin(a) * R * 0.28, z = Math.sin(a);+ orbit.push({ x, y, z, k, vx: -Math.sin(a) * R * q.w, vy: Math.cos(a) * R * q.w * 0.28, big: q.big });+ });+ const embers = (front) => {+ for (const e of orbit) {+ if (e.z >= 0 !== front || e.k <= 0) continue;+ const sp = Math.hypot(e.vx, e.vy) || 1, L = Math.min(5, 1 + sp * 0.025), c = e.k > 0.6 ? EMB[0] : e.k > 0.3 ? EMB[1] : EMB[2];+ p.line(e.x - (e.vx / sp) * L, e.y - (e.vy / sp) * L, e.x, e.y, (u) => (u > 0.6 ? c : front ? EMB[3] : H[7]));+ if (front) p.glow(e.x, e.y, 4, c, 0.4 * e.k);+ else p.glow(e.x, e.y, 3, c, 0.15 * e.k);+ }+ };+ // the ring of flame whirling at the foot: tongues round an ellipse, the far half dimmer+ const ring = (front) => {+ for (let i = 0; i < 12; i++) {+ const a = (i / 12) * TAU + (t / D) * TAU * 2, z = Math.sin(a);+ if (z >= 0 !== front) continue;+ const n = (S * 3 + i) * 19, R = 12 + 2 * N(2, n), x = Math.cos(a) * R, y = z * R * 0.25, h = (5 + 5 * (0.5 + 0.5 * N(5, n + 1))) * (front ? 1 : 0.8);+ flameTongue(p, x, y, h, 1.6, -Math.cos(a + Math.PI / 2) * 3, N, n, H, front ? LAYERS : BACK_LAYERS);}};- 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);++ // smoke spiralling off the top+ looped(t, D, 20, S + 300, (r) => ({ a: r.range(0, TAU), life: r.range(1.2, 2), s: r.range(2.5, 4), vy: -r.range(12, 22) }), (q, age) => {+ const R = rad(1) * (0.8 + age * 0.5), a = q.a + age * 3, x = cx(1, t - age) + Math.cos(a) * R, y = -HT - 2 + q.vy * age + Math.sin(a) * R * 0.25;+ smokePuff(p, x, y, 1 - age / q.life, q.s, SMOKE);});- 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]);+ floorLight(p, 0, 0.5, 40, 8, GLOW, 0.4);+ embers(false);+ ring(false);++ // the column: each pixel's place round the funnel picks its heat; spiral bands turn up it; licks at its edges+ const fl = 0.85 + 0.15 * N(7, S + 1);+ for (let y = 0; y >= -HT * 1.2; y--) {+ const v = -y / HT, vv = Math.min(1, v), c = cx(vv), r = rad(vv) * (1 + 0.08 * N(3, S + 2, y * 0.1)), sp = spin(v);+ // near the top the funnel comes apart into spiral strands of flame climbing past its rim+ const cut = clamp((v - 0.72) / 0.42);+ const lickL = 0.3 * Math.max(0, pnoise(-y * 0.22 + ph * 18, 18, S + 3)), lickR = 0.3 * Math.max(0, pnoise(-y * 0.22 + ph * 18 + 9, 18, S + 4));+ for (let x = Math.floor(c - r * 1.35); x <= Math.ceil(c + r * 1.35); x++) {+ const dx = (x + 0.5 - c) / r, edge = 1 + (dx < 0 ? lickL : lickR);+ if (Math.abs(dx) > edge) continue;+ const th = Math.asin(clamp(dx, -1, 1)), depth = Math.cos(th), tear = 0.18 * pnoise(y * 0.45 + dx * 2 - ph * 30, 30, S + 6);+ const band = 0.5 + 0.5 * Math.sin((th + sp + tear) * 3), streak = band * band * band;+ if (cut > 0 && band < 0.35 + cut * 0.6 + 0.1 * pnoise(x * 0.7 + ph * 20, 20, S + 5)) continue;+ // a darker body with thin bright streaks spiralling up it, hottest where it faces us, cooling up the column+ let heat = 0.22 + 0.36 * depth + 0.5 * streak - 0.22 * vv + 0.1 * (1 - vv) - 0.25 * cut;+ if (Math.abs(dx) > 1) heat = 0.3 - (Math.abs(dx) - 1) * 1.5;+ heat *= fl;+ const col = heat > 0.95 ? H[0] : heat > 0.82 ? H[1] : heat > 0.7 ? H[2] : heat > 0.58 ? H[3] : heat > 0.46 ? H[4] : heat > 0.34 ? H[5] : heat > 0.2 ? H[6] : H[7];+ p.px(x, y, col);+ }+ if (y % 10 === 0 && v <= 1) p.glow(c, y, r * 2 + 8, GLOW, 0.22 * fl);}- 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);++ // flame flung off the spinning sides, cooling as it flies, some into smoke+ looped(t, D, 70, S + 200, (r) => ({ v: r.range(0.05, 0.95), side: r.sign(), sp: r.range(20, 50), life: r.range(0.25, 0.5), s: r.range(1.4, 2.8), f: r.next() }), (q, age) => {+ const tb = t - age, x0 = cx(q.v, tb) + q.side * rad(q.v), y0 = -q.v * HT;+ const [x, y] = drift(x0, y0, q.side * q.sp, -q.sp * 0.6, age, 0, -60, 3, 3);+ firePuff(p, x, y, 1 - age / q.life, q.s, q.f, H, 0.1, -q.side * 0.6, -0.8);+ });+ ring(true);+ embers(true);+ // light: the column's own glow and a wash round it+ p.glow(0, -HT * 0.5, 80, GLOW, 0.28 * fl);+ p.glow(0, -6, 18, H[2], 0.3 * fl);}diff --git a/src/fx/fire/fireball.js b/src/fx/fire/fireball.jsindex 399c01f..cacac87 100644--- a/src/fx/fire/fireball.js+++ b/src/fx/fire/fireball.js@@ -1,61 +1,108 @@-import { PAL, RAMP, ramp, at, cycle, clamp, tileFbm, tileNoise, loopNoise, TAU, WHITE } from "../../core/index.js";-import { fit } from "./_lib.js";+// The flame-puff, smoke and spark recipe is adapted from Sprite Fusion's open-source explosion+// (https://www.spritefusion.com/pixel-art-vfx/explosion), MIT License, Copyright (c) 2026 Hugo Duprez.+import { fit, mix, hex, clamp, WHITE, TAU } from "../../core/index.js";+import { noiseFor, pnoise, hotFirst, flameBlade, firePuff, smokePuff, spark, ember, drift, looped, LAYERS } 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,+ desc: "A fireball flying right: a churning white-hot head with a corona of flame, a long torn tail of flame puffs cooling into smoke, embers shed behind.",+ tags: ["fire", "fireball", "projectile", "magic", "directional", "loop"],+ size: [136, 56],+ origin: [112, 28],+ duration: 1.2,loop: true,fps: 30,bg: "dark",- options: { palette: PAL.fire, radius: 6.5, length: 48, seed: 6 },+ options: {+ palette: ["#4a1712", "#8a1f17", "#c9281f", "#f2561d", "#ff8a2a", "#ffc23d", "#ffe26b", "#fff3a6", "#ffffff"],+ radius: 5,+ speed: 120,+ seed: 5,+ },};+const D = meta.duration, NL = noiseFor(D), SMOKE1 = hex("#5b5566");+// the comet body: tongues rooted in the head streaming back, the longest behind [length, half-width, y offset]+const BODY = [[30, 4.2, 0], [23, 4.4, -1.6], [22, 4.4, 1.6], [15, 4.6, 0]];+// the corona: thin licks peeling back off the head [angle on the head (0 is the nose), length, half-width]+const CORONA = [[-1.3, 6, 1.1], [-1.8, 8, 1.2], [-2.3, 7, 1.1], [1.3, 6, 1.1], [1.8, 8, 1.2], [2.3, 7, 1.1]];++// the head: a ball whose outline churns and whose heat swirls in a spiral, white at the heart, swept back+function head(p, H, t, R0, S, hx, hy) {+ const ph = t / D;+ p.shade(hx - R0 * 2.4, hy - R0 * 1.7, hx + R0 * 1.5, hy + R0 * 1.7, (x, y, out) => {+ x -= hx;+ y -= hy;+ const d = Math.hypot(x, y), th = Math.atan2(y, x), back = Math.max(0, -Math.cos(th)), a = th / TAU;+ const bump = 0.55 * pnoise(a * 9 + ph * 9, 9, S) + 0.35 * pnoise(a * 5 - ph * 10, 5, S + 1);+ const rim = R0 * (1 + 0.55 * back * back) + bump;+ if (d > rim) return;+ const swirl = pnoise(a * 5 - ph * 10 + d * 0.45, 5, S + 2);+ const h = 1 - d / rim + 0.26 * swirl + 0.1 * (1 - back);+ // the leading edge: a crisp hot rim where it cuts the air+ if (rim - d < 1 && back < 0.3) return h > 0.3 ? H[3] : H[5];+ return h > 0.74 ? H[0] : h > 0.58 ? H[1] : h > 0.42 ? H[2] : h > 0.27 ? H[4] : h > 0.13 ? H[5] : H[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]));+ const F = fit(o.palette, 9), H = hotFirst(F), S = o.seed, R0 = o.radius, V = o.speed;+ const N = (rate, seed = 0, off = 0) => NL(t, rate, seed, off);+ const GLOW = mix(mix(H[3], H[4], 0.5), WHITE, 0.25), SMOKE = mix(SMOKE1, H[6], 0.3), SPARKS = [H[1], H[2], H[4], H[5]], EMB = [H[1], H[2], H[4], H[6]];+ // the head bobs a hair as it flies+ const hx = N(3, S + 50) * 0.5, hy = N(2.5, S + 51) * 0.7;++ // the tail: flame puffs thrown off the back that the head leaves behind; they cool, swell, rise and some+ // burn out into smoke. Positions are relative to the head, which outruns them.+ const fire = [], smoke = [];+ looped(t, D, 130, S + 100, (r) => {+ const fl = r.range(0.22, 0.55), sm = r.chance(0.55), x = -r.range(2, 24);+ return { x, y: r.range(-1, 1) * (R0 - 0.1 * -x), v: V * r.range(0.3, 0.6), vy: r.range(-16, 16), fl, sm, sl: r.range(0.25, 0.45), s: r.range(1.3, 2.9), f: r.next() * 0.5 + 0.5 * (-x / 24), life: fl + (sm ? 0.45 : 0) };+ }, (q, age) => {+ const ta = Math.min(age, q.fl), [wx, y, wvx, vy] = drift(0, q.y, q.v, q.vy, ta, 0, -70, 4.5, 3);+ const x = q.x + wx - V * ta;+ if (age < q.fl) return fire.push([age, x, y, q]);+ if (!q.sm || age - q.fl > q.sl) return;+ const sa = age - q.fl, [sx, sy] = drift(x, y, wvx - V, vy * 0.6 - 6, sa, V * 2, -30, 2, 1.2);+ smoke.push([sa, sx, sy, q]);});- // 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);+ for (const [sa, x, y, q] of smoke) smokePuff(p, x, y, 1 - sa / q.sl, q.s * 0.9, SMOKE);+ fire.sort((a, b) => b[0] - a[0]);+ for (const [age, x, y, q] of fire) {+ const u = age / q.fl;+ firePuff(p, x, y, 1 - u, q.s * (1 + 1.3 * u), q.f, H, 0.07, -0.86, -0.5);+ }++ // the body: tongues of flame rooted in the head streaming back, and a corona licking round it+ BODY.forEach(([len, w, dy], i) => {+ const n = (S * 5 + i) * 17, L = len * (0.82 + 0.25 * N(4, n)) * (1 + 0.3 * Math.max(0, N(2.4, n + 3)));+ flameBlade(p, hx + 1, hy + dy * 0.5, -1, dy * 0.02, L, w * R0 / 5, N(3, n + 5) * 3 + dy, N, n, H, LAYERS, 0.5, 1.1 + L * 0.05);+ });+ CORONA.forEach(([a, len, w], i) => {+ const n = (S * 5 + i + 20) * 17, L = len * (0.7 + 0.4 * (0.5 + 0.5 * N(6, n))), ox = Math.cos(a) * R0 * 0.85, oy = Math.sin(a) * R0 * 0.85;+ const dx = Math.cos(a) * 0.55 - 1, dy = Math.sin(a) * 0.55, l = Math.hypot(dx, dy);+ flameBlade(p, hx + ox, hy + oy, dx / l, dy / l, L, w, -Math.sign(a) * 1.5, N, n, H, LAYERS);});- // 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);+ head(p, H, t, R0, S, hx, hy);++ // motes flicked off the head's skin: short hot streaks that die at once+ looped(t, D, 26, S + 200, (r) => ({ a: r.range(-2.4, 2.4), v: r.range(30, 70), life: r.range(0.08, 0.18) }), (q, age) => {+ const ca = Math.cos(q.a), sa = Math.sin(q.a), d = R0 * 0.9 + q.v * age, x = hx + ca * d - V * 0.4 * age, y = hy + sa * d;+ const k = 1 - age / q.life, L = 1 + 2 * k;+ p.line(x - ca * L + V * 0.02, y - sa * L, x, y, k > 0.5 ? H[1] : H[3]);+ p.glow(x, y, 3, H[2], 0.4 * k);});- // 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));+ // embers left behind: streaks that the head outruns, falling as they cool+ looped(t, D, 30, S + 300, (r) => ({ x: -r.range(2, 16), y: r.range(-3, 3), v: V * r.range(0.3, 0.8), vy: r.range(-20, 20), life: r.range(0.25, 0.55), big: r.chance(0.25), ph: r.range(0, 6.3) }), (q, age) => {+ const [wx, y, wvx, vy] = drift(0, q.y, q.v, q.vy, age, 0, 50, 3, 2);+ const x = q.x + wx - V * age, k = 1 - age / q.life;+ if (q.big) ember(p, x, y, k, 2, EMB, age * 40 + q.ph);+ else spark(p, x, y, wvx - V, vy, k, SPARKS);});- 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);++ // light: a hot heart, a warm halo, light running down the tail+ const fl = 0.85 + 0.15 * N(9, S + 7);+ p.glowLine(hx - 6, hy, -50, -2, 12, GLOW, 0.2 * fl);+ p.glow(hx - 2, hy, 42, GLOW, 0.42 * fl);+ p.glow(hx, hy, 13, H[1], 0.3 * fl);}diff --git a/src/fx/fire/flame-pillar.js b/src/fx/fire/flame-pillar.jsindex 88b9c04..c840c42 100644--- a/src/fx/fire/flame-pillar.js+++ b/src/fx/fire/flame-pillar.js@@ -1,74 +1,198 @@-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";+// The flame-puff, smoke, spark, debris and floor-ring recipe is adapted from Sprite Fusion's open-source explosion+// (https://www.spritefusion.com/pixel-art-vfx/explosion), and the column's levels, pulses and strands from its+// holy light (https://www.spritefusion.com/pixel-art-vfx/holy-light), MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Bits, Lights, P, PF, B, Rng, fit, band, clamp, smooth, ease, noise, rand, TAU, WHITE, hex, mix, scale, rgb } from "../../core/index.js";+import { hotFirst, flameTongue, simDraw, floorLight, LAYERS } 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.",+ desc: "The floor cracks and glows, a column of fire erupts white-hot and roars, spewing embers and shedding flame, then collapses into rolling smoke.",tags: ["fire", "pillar", "eruption", "spell", "ground", "one-shot"],- size: [64, 116],- origin: [32, 108],- duration: 1.8,+ size: [184, 256],+ origin: [92, 232],+ duration: 5,loop: false,fps: 30,bg: "ground",- options: { palette: PAL.fire, height: 90, width: 8, seed: 11 },+ options: {+ palette: ["#4a1712", "#8a1f17", "#c9281f", "#f2561d", "#ff8a2a", "#ffc23d", "#ffe26b", "#fff3a6", "#ffffff"],+ stone: "#4a3f69",+ height: 140,+ seed: 5,+ },};-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]));+const ERUPT = 0.55, RISE = 0.12, FALL = 1.95, GONE = 2.45, SOOT = hex("#0d0a12"), OUTLINE = hex("#1a1422"), WARM = rgb(255, 176, 96);++function stone(c) {+ c = hex(c);+ return { light: mix(scale(c, 1.35), WHITE, 0.08), body: c, shade: scale(c, 0.64), dust: mix(scale(c, 1.2), rgb(150, 140, 150), 0.3) };+}+function rock(p, b, st) {+ const r = 0.6 + b.s * 0.75, fade = Math.min(1, b.life / 0.5), lx = Math.cos(b.a) * r * 0.4, ly = Math.sin(b.a) * r * 0.4;+ p.shade(b.x - r - 1, b.y - r - 1, b.x + r + 1, b.y + r + 1, (x, y, out) => {+ const dx = x - b.x, dy = y - b.y, d = Math.hypot(dx * 1.15, dy);+ if (d > r + 0.9) return;+ const lit = dx * lx + dy * ly;+ out.c = d > r ? OUTLINE : lit < -0.4 ? st.light : lit > 0.6 ? st.shade : st.body;+ out.a = fade;});- // 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];- });+}++export function create(o) {+ const F = fit(o.palette, 9), H = hotFirst(F), HMAX = o.height, st = stone(o.stone), R = new Rng(o.seed), floor = () => 0;+ const ps = new Particles({ rng: R, ground: floor, sparks: [H[1], H[2], H[4], H[5]] });+ const bits = new Bits({ ground: floor }), lights = new Lights();+ const GLOW = mix(mix(H[3], H[4], 0.5), WHITE, 0.25), S = o.seed * 13;+ // the cracks: jagged lines racing out from the middle across the floor (squashed for perspective), with branches+ const cracks = [];+ const crack = (x, y, a, len, t0, w) => {+ const pts = [[x, y]];+ for (let d = 0; d < len; d += 2) (a += R.range(-0.55, 0.55)), (x += Math.cos(a) * 2), (y += Math.sin(a) * 0.76), pts.push([x, y]);+ cracks.push({ pts, t0, grow: R.range(0.22, 0.36), w });+ return pts;+ };+ for (let i = 0; i < 9; i++) {+ const a = (i / 9) * TAU + R.range(-0.25, 0.25), pts = crack(R.range(-1, 1), R.range(-0.3, 0.3), a, R.range(20, 40), R.range(0, 0.16), 1);+ const j = 3 + R.int(0, pts.length - 6);+ if (pts.length > 8) crack(pts[j][0], pts[j][1], a + R.sign() * R.range(0.5, 1), R.range(6, 14), 0.18 + R.range(0, 0.15), 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 });+ // strands of hotter flame running up the column+ const strands = Array.from({ length: 7 }, (_, i) => ({ o: (rand(i, S, 1) - 0.5) * 1.4, w: 0.05 + rand(i, S, 2) * 0.06, f: 1 + rand(i, S, 3) * 2 }));+ let t = 0, erupted = false, fell = false;++ const height = (tt) => (tt < ERUPT ? 0 : tt < ERUPT + RISE ? HMAX * ease.outCubic((tt - ERUPT) / RISE) : tt < FALL ? HMAX * (1 + 0.05 * noise(tt * 3, S)) : HMAX * (1 - ease.inQuad(clamp((tt - FALL) / (GONE - FALL)))));+ const width = (tt) => (tt < ERUPT ? 0 : tt < FALL ? 12 * (1 + 0.45 * Math.exp(-(tt - ERUPT) * 7)) * (0.94 + 0.06 * noise(tt * 9, S + 1)) : 12 * (1 - smooth(FALL, GONE, tt)) + 1.5 * (1 - smooth(GONE - 0.1, GONE, tt)));+ const heat = (tt) => smooth(0, ERUPT, tt) * 0.75 + 0.25 * smooth(ERUPT - 0.05, ERUPT + 0.1, tt) - smooth(GONE - 0.3, meta.duration - 0.6, tt) * 1.05;++ function column(p) {+ const h = height(t), w0 = width(t);+ if (h < 1 || w0 < 0.3) return;+ // a crown of tongues where the column breaks into the air, drawn first so the column flows up into them+ if (t < FALL + 0.25) {+ const k = clamp(w0 / 12), NZ = (rate, seed, off) => noise(t * rate + off, seed);+ for (let i = 0; i < 5; i++) {+ const n = (S + i) * 17, dx = (i - 2) * w0 * 0.4, th = (12 + 12 * (0.5 + 0.5 * noise(t * 3.3 + i, n))) * k * (i === 2 ? 1.2 : i % 4 === 0 ? 0.6 : 0.9);+ flameTongue(p, dx + noise(t * 2, n + 2) * 1.5, -h + 12, th, 3.4 * k * (i % 4 === 0 ? 0.7 : 1), -dx * 0.3 + noise(t * 2.2, n + 1) * 3, NZ, n, H, LAYERS);+ }+ }+ const lvlC = [H[0], H[1], H[2], H[3], H[4], H[5], H[6], H[7]];+ for (let y = 0; y >= -h; y--) {+ const v = -y / h, cx = noise(-y * 0.04 + t * 1.6, S + 2) * 1.6 * v;+ // licks bulge out of the sides and run up them; a wider splash at the foot; the top thins into tongues+ const foot = 1 + 0.7 * Math.max(0, 1 - -y / 12) ** 2, top = 1 - smooth(0.82, 1, v) * 0.7;+ const wl = w0 * foot * top * (1 + 0.65 * Math.max(0, noise(y * 0.2 + t * 8, S + 3)) ** 1.5), wr = w0 * foot * top * (1 + 0.65 * Math.max(0, noise(y * 0.2 + t * 8, S + 4)) ** 1.5);+ const pulse = ((-y * 0.032 + t * 3.6) % 1) < 0.09 ? 1 : 0;+ for (let x = Math.floor(cx - wl * 1.15); x <= Math.ceil(cx + wr * 1.15); x++) {+ const dx = x + 0.5 - cx, q = Math.abs(dx) / (dx < 0 ? wl : wr);+ if (q > 1.15) continue;+ let lvl = q < 0.12 ? 0 : q < 0.26 ? 1 : q < 0.42 ? 2 : q < 0.56 ? 3 : q < 0.7 ? 4 : q < 0.84 ? 5 : q < 0.96 ? 6 : 7;+ for (const s of strands) if (Math.abs(dx / w0 - s.o - 0.06 * Math.sin(t * s.f * 3 + s.o * 9)) < s.w) lvl = Math.max(0, lvl - 1);+ lvl = Math.max(0, lvl - pulse);+ if (lvl === 7 && rand(x, y, Math.floor(t * 20)) < 0.5) continue;+ p.px(x, y, lvlC[lvl]);+ }+ if (y % 12 === 0) p.glow(cx, y, w0 * 2.4 + 8, GLOW, 0.28 * clamp(w0 / 12));+ }+ p.glow(0, -h * 0.45, 92, GLOW, 0.3 * clamp(w0 / 12));}- // 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);- });++ function cracksDraw(p) {+ const k = heat(t);+ if (k <= -0.05) return;+ for (const c of cracks) {+ const n = Math.floor(c.pts.length * clamp((t - c.t0) / c.grow));+ for (let i = 1; i < n; i++) {+ const u = i / c.pts.length, hot = k * (1 - 0.45 * u), [x0, y0] = c.pts[i - 1], [x1, y1] = c.pts[i];+ if (hot < 0) {+ // cooled: soot that fades away+ const a = 1 + hot * 3;+ if (a > 0) p.line(x0, y0, x1, y1, SOOT, a);+ continue;+ }+ const col = hot > 0.85 ? H[1] : hot > 0.65 ? H[2] : hot > 0.45 ? H[4] : hot > 0.25 ? H[5] : hot > 0.1 ? H[6] : H[7];+ // the crack: a hot seam with a darker glowing lip, wider near the middle+ if (c.w && i < c.pts.length * 0.5 && hot > 0.2) p.line(x0, y0 + 1, x1, y1 + 1, hot > 0.6 ? H[5] : H[6]), p.line(x0, y0 - 1, x1, y1 - 1, H[7]);+ p.line(x0, y0, x1, y1, col);+ if (i % 2 === 0) p.glow(x1, y1, 5 + 7 * hot, GLOW, 0.3 * hot);+ }+ }+ // the floor glows from beneath while it's hot+ if (k > 0) floorLight(p, 0, 0.5, 44, 8, GLOW, 0.35 * k);}- // 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);++ return {+ update(dt) {+ t += dt;+ // the charge: the crust in the middle glows, little flames lick out of it, heat leaks up the cracks+ if (t < ERUPT && R.chance(0.6 * dt * 60 * smooth(0.15, ERUPT, t))) ps.spawn(P.FIRE, R.range(-5, 5), -1, R.range(-6, 6), -R.range(20, 45), R.range(0.15, 0.3), 0, R.range(1, 2.2));+ if (t < ERUPT && R.chance(0.5 * dt * 60 * smooth(0, ERUPT, t))) {+ const c = R.pick(cracks), i = R.int(0, Math.floor(c.pts.length * clamp((t - c.t0) / c.grow)) - 1);+ if (i >= 0) {+ const [x, y] = c.pts[i];+ if (R.chance(0.5)) ps.spawn(P.FIRE, x, y - 1, R.range(-5, 5), -R.range(15, 35), R.range(0.15, 0.3), 0, R.range(0.8, 1.6));+ else ps.spawn(P.EMBER, x, y - 1, R.range(-15, 15), -R.range(30, 70), R.range(0.5, 1), H[3], 1);+ }+ }+ if (!erupted && t >= ERUPT) {+ erupted = true;+ lights.add(0, -40, 90, WARM, 0.7, 0.6);+ lights.add(0, -8, 44, WHITE, 0.7, 0.1);+ for (let i = 0; i < 70; i++) {+ const a = -Math.PI / 2 + R.range(-1.1, 1.1), sp = R.range(100, 260);+ ps.spawn(P.SPARK, R.range(-4, 4), -2, Math.cos(a) * sp, Math.sin(a) * sp, R.range(0.25, 0.7));+ }+ for (let i = 0; i < 18; i++) bits.add({ kind: B.CHUNK, x: R.range(-6, 6), y: -2, vx: R.range(-110, 110), vy: -R.range(150, 330), g: 1, drag: 0.4, bounce: 0.3, life: R.range(1.6, 2.4), a: R.range(0, TAU), va: R.range(-16, 16), s: R.int(1, 3) });+ for (let i = 0; i < 60; i++) {+ const a = -Math.PI / 2 + R.range(-0.9, 0.9), sp = R.range(80, 260);+ ps.spawn(P.GRIT, R.range(-5, 5), -1, Math.cos(a) * sp, Math.sin(a) * sp, R.range(1, 1.8), R.pick([st.light, st.body, st.body, st.shade]), R.chance(0.4) ? 2 : 1);+ }+ for (let i = 0; i < 14; i++) {+ const s = R.sign();+ ps.spawn(P.SMOKE, s * R.range(2, 10), -R.range(1, 4), s * R.range(40, 110), -R.range(2, 10), R.range(1, 1.8), st.dust, R.range(4, 7), R.range(0, 0.06), PF.BIG);+ }+ }+ // the roar: flame shed off the sides, a billowing cap, embers spewed high+ const h = height(t), w = width(t);+ if (t > ERUPT && t < GONE && h > 4) {+ if (R.chance(0.9 * dt * 60)) {+ const s = R.sign(), y = -R.range(4, h * 0.9);+ ps.spawn(P.FIRE, s * w * R.range(0.7, 1.1), y, s * R.range(15, 40), -R.range(30, 70), R.range(0.25, 0.5), 0, R.range(1.6, 3.2), 0, R.chance(0.35) ? PF.SMOKES : 0);+ }+ if (R.chance(0.7 * dt * 60)) ps.spawn(P.FIRE, R.range(-w, w), -h + R.range(0, 6), R.range(-20, 20), -R.range(30, 80), R.range(0.35, 0.7), 0, R.range(3, 5.5), 0, R.chance(0.6) ? PF.SMOKES | (t < FALL - 0.3 ? PF.BIG : 0) : 0);+ if (t < FALL && R.chance(0.5 * dt * 60)) ps.spawn(P.EMBER, R.range(-w, w) * 0.6, -h + 4, R.range(-60, 60), -R.range(50, 110), R.range(0.7, 1.3), H[3], R.chance(0.2) ? 2 : 1);+ }+ // the collapse: the falling top breaks into puffs that roll off as smoke+ if (t >= FALL && !fell) fell = true;+ if (fell && t < GONE - 0.1 && R.chance(1.6 * dt * 60)) ps.spawn(P.FIRE, R.range(-w - 2, w + 2), -h - R.range(0, 8), R.range(-30, 30), -R.range(10, 50), R.range(0.4, 0.75), 0, R.range(3.5, 6.5), 0, PF.SMOKES);+ bits.update(dt);+ for (const b of bits.list)+ if (b.rest && !b.dusted) {+ b.dusted = true;+ for (let i = 0; i < 3; i++) ps.spawn(P.DUST, b.x + R.range(-1.5, 1.5), -0.5, R.sign() * R.range(8, 35), -R.range(2, 18), R.range(0.3, 0.6), st.dust, R.range(1.3, 2.6));+ }+ ps.update(dt);+ lights.update(dt);+ },+ drawBack(p) {+ cracksDraw(p);+ simDraw(p, ps, H, "back");+ const k = (t - ERUPT) / 0.45;+ if (k > 0 && k < 1) band(p, 0, 0.5, 84 * ease.outCubic(k), 0.18, Math.max(1, 4 * (1 - k)), 1.15 - k, [st.body, st.light, H[4], H[1]], (g) => Math.sin(g) < 0);+ },+ draw(p) {+ column(p);+ for (const b of bits.list) rock(p, b, st);+ simDraw(p, ps, H, "front");+ const k = (t - ERUPT) / 0.45;+ if (k > 0 && k < 1) band(p, 0, 0.5, 84 * ease.outCubic(k), 0.18, Math.max(1, 4 * (1 - k)), 1.15 - k, [st.body, st.light, H[4], H[1]], (g) => Math.sin(g) >= 0, k < 0.15);+ // the eruption's white flash at the foot+ const f = (t - ERUPT) / 0.08;+ if (f > 0 && f < 1) {+ p.ellipse(0, -2, 16 * (1 - f * 0.3), 6, H[2]);+ p.ellipse(0, -3, 11 * (1 - f * 0.3), 4, f < 0.5 ? WHITE : H[1]);+ }+ lights.draw(p);+ },+ };}diff --git a/src/fx/fire/flamethrower.js b/src/fx/fire/flamethrower.jsindex f54ce2d..fd7a2da 100644--- a/src/fx/fire/flamethrower.js+++ b/src/fx/fire/flamethrower.js@@ -1,66 +1,129 @@-import { PAL, RAMP, ramp, at, cycle, smooth, wrap, tileFbm, fly, TAU, WHITE, hex } from "../../core/index.js";-import { fit } from "./_lib.js";+// The flame-puff, smoke and spark recipe is adapted from Sprite Fusion's open-source explosion+// (https://www.spritefusion.com/pixel-art-vfx/explosion), MIT License, Copyright (c) 2026 Hugo Duprez.+import { fit, mix, hex, clamp, smooth, WHITE } from "../../core/index.js";+import { noiseFor, pnoise, hotFirst, flameTongue, firePuff, smokePuff, spark, drift, looped, solid, LAYERS } 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,+ desc: "A pressurised jet shooting right: a blue pilot at the nozzle, a tight stream with surges racing down it, a sputter, burning drops falling off, a tip that curls up into smoke.",+ tags: ["fire", "flamethrower", "stream", "weapon", "directional", "loop"],+ size: [184, 104],+ origin: [30, 60],+ duration: 1.6,loop: true,fps: 30,bg: "dark",- options: { palette: PAL.fire, length: 96, seed: 8 },+ options: {+ palette: ["#4a1712", "#8a1f17", "#c9281f", "#f2561d", "#ff8a2a", "#ffc23d", "#ffe26b", "#fff3a6", "#ffffff"],+ pilot: ["#1b2a8a", "#3a62e0", "#a8d4ff"],+ reach: 112,+ speed: 280,+ seed: 3,+ },};-const BLUE = [hex("#2438a8"), hex("#4f7cff"), hex("#b8dcff")];+const D = meta.duration, NL = noiseFor(D), SOOT = hex("#2a2430");+// the sputter: the jet coughs once a loop, then surges back+const COUGH = 0.55;+const flow = (te) => {+ const u = ((te % D) + D) % D;+ return 1 - smooth(COUGH, COUGH + 0.04, u) * (1 - smooth(COUGH + 0.1, COUGH + 0.16, u)) + 0.25 * Math.exp(-(((u - COUGH - 0.2) / 0.05) ** 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, 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]));+ const F = fit(o.palette, 9), H = hotFirst(F), PL = fit(o.pilot, 3), S = o.seed, L = o.reach, V = o.speed;+ const N = (rate, seed = 0, off = 0) => NL(t, rate, seed, off);+ const GLOW = mix(mix(H[3], H[4], 0.5), WHITE, 0.25), SPARKS = [H[1], H[2], H[4], H[5]], SMOKE = mix(SOOT, H[7], 0.3);+ // the stream's centre line: dead straight at the nozzle, sagging and wavering as it runs out+ const cy = (x) => 5 * (x / L) ** 2 + N(1.2, S + 9, x * 0.02) * 2.2 * (x / L) ** 1.5;+ const width = (x) => (2.1 + 5 * Math.pow(x / L, 0.7)) * flow(t - x / V);++ // the curl: where the stream runs out of push, burning fuel rolls up and back on itself and turns to smoke+ const fire = [], smoke = [];+ looped(t, D, 80, S + 100, (r) => ({ a0: r.range(-0.3, 0.5), R: r.range(9, 15), w: r.range(5, 7.5), up: r.range(4, 12), dx: r.range(-6, 2), fl: r.range(0.38, 0.62), sl: r.range(0.6, 1.0), s: r.range(2.4, 4.4), f: r.next(), life: 1.6 }), (q, age) => {+ const tb = t - age, k = flow(tb - L / V);+ if (k < 0.4) return;+ // round a curl: forward, up and back over the top, rising as it goes+ const x0 = L + q.dx, y0 = cy(L), a = Math.min(age, q.fl) * q.w + q.a0;+ const x = x0 + q.R * Math.sin(a), y = y0 - q.R * (1 - Math.cos(a)) - q.up * age;+ if (age < q.fl) return fire.push([age / q.fl, x, y, q, k]);+ if (age - q.fl < q.sl) smoke.push([(age - q.fl) / q.sl, x - (age - q.fl) * 6, y - (age - q.fl) * 16, q]);+ });+ for (const [u, x, y, q] of smoke) smokePuff(p, x, y, 1 - u, q.s * 1.2, SMOKE, true, 0.85);+ fire.sort((a, b) => b[0] - a[0]);+ for (const [u, x, y, q, k] of fire) firePuff(p, x, y, 1 - u, q.s * (0.8 + 1.1 * u) * k, q.f, H, 0.1);++ // flames licking up off the burning fuel, riding along the stream, swept back by the wind of it+ for (let i = 0; i < 13; i++) {+ const n = (S * 3 + i) * 19, ph = ((i * 0.618 + t / D) % 1), x = 10 + ph * (L - 14), k = flow(t - x / V);+ if (k < 0.35) continue;+ const h = (2 + 11 * (x / L)) * (0.55 + 0.6 * (0.5 + 0.5 * N(5, n + 1))) * k * Math.min(1, (1 - ph) * 6);+ flameTongue(p, x, cy(x) - width(x) * 0.6, h, 1.1 + 1.6 * (x / L), -h * 0.55, N, n, H, LAYERS);+ }+ // the stream: a white core in yellow, orange and a red skin, surges racing down it+ const P = Math.round(D * 3);+ for (let x = 0; x <= L; x++) {+ const c = cy(x), w = width(x) * (1 + 0.15 * pnoise(x * 0.4 - (t / D) * 24, 24, S + 4));+ if (w < 0.4) continue;+ const surge = ((x * 0.035 - (t / D) * P) % 1 + 1) % 1 < 0.12 ? 1 : 0;+ for (let y = Math.floor(c - w - 1); y <= Math.ceil(c + w + 1); y++) {+ const q = Math.abs(y + 0.5 - c) / w;+ if (q > 1.15) continue;+ // a white core near the nozzle cooling to yellow down the stream; ragged red skin+ let lvl = (q < 0.3 ? 0 : q < 0.55 ? 1 : q < 0.78 ? 2 : q < 1 ? 3 : 4) + (x > L * 0.45 && q < 0.55 ? 1 : 0);+ lvl = Math.max(0, Math.min(4, lvl - surge));+ if (lvl === 4 && pnoise(x * 0.5 + y * 7.3 - (t / D) * 40, 40, S + 6) < 0) continue;+ p.px(x, y, [H[0], H[2], H[4], H[6], H[7]][lvl]);+ }+ // two hot strands twisting through the fuel, racing downstream+ for (const ph of [0, Math.PI]) {+ const a = x * 0.22 - (t / D) * Math.PI * 2 * 9 + ph, sy = c + Math.sin(a) * w * 0.55;+ if (Math.cos(a) > -0.1 && w > 1.2) p.px(x, sy, Math.cos(a) > 0.55 ? H[0] : H[1]);+ }+ }+ // the pilot at the nozzle: a blue cone of gas where it lights+ const pk = flow(t);+ for (let x = 0; x < 6; x++) for (let y = -2; y <= 2; y++) if (Math.abs(y) <= 2 - x * 0.3) p.px(x, y, Math.abs(y) < 1 ? (x < 2 ? PL[2] : PL[1]) : PL[0]);+ solid(p, 1, 0, 1.6 * pk, WHITE);++ // burning drops shaken off the stream: they arc down trailing flame and burn out+ looped(t, D, 10, S + 200, (r) => ({ d: r.range(20, 95), vx: r.range(0.3, 0.6), vy: r.range(-25, 15), life: r.range(0.35, 0.6) }), (q, age) => {+ const tb = t - age;+ if (flow(tb - q.d / V) < 0.5) return;+ const at = (a) => drift(q.d, cy(q.d), V * q.vx, q.vy, a, 0, 260, 1.2, 0.5);+ for (let j = 4; j >= 1; j--) {+ const a = age - j * 0.035;+ if (a < 0) continue;+ const [x, y] = at(a);+ firePuff(p, x, y, 1 - Math.min(0.99, j * 0.18 + age / q.life * 0.4), 1.8 - j * 0.25, 0.3, H, 0.06);+ }+ const [x, y] = at(age), k = 1 - age / q.life;+ p.px(x, y, k > 0.5 ? H[0] : H[2]);+ p.px(x + 1, y, H[3]);+ p.glow(x, y, 6, H[3], 0.45 * k);});- // 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);+ // the cough: when the jet sputters the nozzle spits sparks and a puff of smoke+ looped(t, D, 12, S + 300, (r) => ({ born: COUGH + r.range(0, 0.08), a: r.range(-0.8, 0.8), v: r.range(120, 240), life: r.range(0.2, 0.45) }), (q, age) => {+ const u = ((t - age) % D + D) % D;+ if (Math.abs(u - q.born) > 0.06) return;+ const [x, y, vx, vy] = drift(4, 0, Math.cos(q.a) * q.v, Math.sin(q.a) * q.v, age, 0, 300, 2.5, 2.5);+ spark(p, x, y, vx, vy, 1 - age / q.life, SPARKS);});- // 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));+ // and spits a few blobs of burning fuel that fall short+ looped(t, D, 5, S + 350, (r) => ({ born: COUGH + r.range(0.01, 0.1), v: r.range(90, 170), vy: r.range(-30, 10), life: r.range(0.25, 0.4), s: r.range(1.6, 2.6) }), (q, age) => {+ const u = ((t - age) % D + D) % D;+ if (Math.abs(u - q.born) > 0.05) return;+ const [x, y] = drift(4, 0, q.v, q.vy, age, 0, 200, 2, 1);+ firePuff(p, x, y, 1 - age / q.life, q.s, 0.2, H, 0.1, -0.86, -0.5);});- 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);+ {+ const u = ((t % D) + D) % D, a = u - COUGH;+ if (a > 0 && a < 0.7) smokePuff(p, 8 + a * 20, -a * 18, 1 - a / 0.7, 3, SMOKE, false, 0.8);+ }++ // light: the pilot, the stream, the burning tip+ p.glow(2, 0, 34 * pk, GLOW, 0.8 * pk);+ p.glow(2, 0, 9, PL[2], 0.45 * pk);+ for (let d = 8; d <= L; d += 8) p.glow(d, cy(d), 12 + d * 0.16, GLOW, 0.3 * flow(t - d / V));+ p.glow(L, cy(L) - 10, 52, GLOW, 0.34 * flow(t - L / V));}diff --git a/src/fx/fire/ground-fire.js b/src/fx/fire/ground-fire.jsdeleted file mode 100644index 923fe31..0000000--- a/src/fx/fire/ground-fire.js+++ /dev/null@@ -1,48 +0,0 @@-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.jsdeleted file mode 100644index 9341db3..0000000--- a/src/fx/fire/ignite.js+++ /dev/null@@ -1,69 +0,0 @@-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.jsdeleted file mode 100644index 7cc7586..0000000--- a/src/fx/fire/inferno-wall.js+++ /dev/null@@ -1,47 +0,0 @@-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.jsindex 7969672..8b88172 100644--- a/src/fx/fire/meteor.js+++ b/src/fx/fire/meteor.js@@ -1,96 +1,197 @@-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";+// The impact's particle recipe (fire puffs that cool into smoke, sparks, embers, burning brands that land and+// keep burning, rocks, grit, dust, scorch) is adapted from Sprite Fusion's open-source explosion+// (https://www.spritefusion.com/pixel-art-vfx/explosion), MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Bits, Lights, Blazes, P, PF, B, Rng, fit, band, flare, clamp, smooth, ease, noise, rand, TAU, WHITE, hex, mix, scale, rgb } from "../../core/index.js";+import { hotFirst, flameBlade, simDraw, floorLight, LAYERS } from "./_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,+ desc: "A burning rock streaks in from the upper left in a comet of fire and smashes into the floor: a white flash, a fireball, rocks and brands thrown, a glowing crater that cools.",+ tags: ["fire", "meteor", "impact", "explosion", "spell", "debris", "one-shot"],+ size: [272, 232],+ origin: [150, 208],+ duration: 5,loop: false,fps: 30,bg: "ground",- options: { palette: PAL.fire, seed: 16 },+ options: {+ palette: ["#4a1712", "#8a1f17", "#c9281f", "#f2561d", "#ff8a2a", "#ffc23d", "#ffe26b", "#fff3a6", "#ffffff"],+ stone: "#4a3f69",+ rock: ["#120e16", "#2a2230", "#463a4a", "#6a5a66"],+ seed: 9,+ },};-const ROCK = [hex("#160f14"), hex("#33242a"), hex("#54393a")];-const HIT = 0.38, X0 = -70, Y0 = -84;+const HIT = 0.62, FROM = [-112, -142], SOOT = hex("#0d0a12"), SOOT2 = hex("#17121d"), OUTLINE = hex("#1a1422"), WARM = rgb(255, 176, 96);-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]));+function stone(c) {+ c = hex(c);+ return { light: mix(scale(c, 1.35), WHITE, 0.08), body: c, shade: scale(c, 0.64), dust: mix(scale(c, 1.2), rgb(150, 140, 150), 0.3) };+}+function rock(p, b, st) {+ const r = 0.6 + b.s * 0.75, fade = Math.min(1, b.life / 0.5), lx = Math.cos(b.a) * r * 0.4, ly = Math.sin(b.a) * r * 0.4;+ p.shade(b.x - r - 1, b.y - r - 1, b.x + r + 1, b.y + r + 1, (x, y, out) => {+ const dx = x - b.x, dy = y - b.y, d = Math.hypot(dx * 1.15, dy);+ if (d > r + 0.9) return;+ const lit = dx * lx + dy * ly;+ out.c = d > r ? OUTLINE : lit < -0.4 ? st.light : lit > 0.6 ? st.shade : st.body;+ out.a = fade;});- 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];+}++export function create(o) {+ const F = fit(o.palette, 9), H = hotFirst(F), RK = fit(o.rock, 4), st = stone(o.stone), R = new Rng(o.seed), floor = () => 0, S = o.seed * 11;+ let blazes;+ const ps = new Particles({ rng: R, ground: floor, sparks: [H[1], H[2], H[4], H[5]], onLand: (x, y) => blazes.add(x, y - 0.25, R.range(0.9, 1.6), R.range(0.5, 0.85)) });+ blazes = new Blazes(ps);+ const bits = new Bits({ ground: floor }), lights = new Lights(), GLOW = mix(mix(H[3], H[4], 0.5), WHITE, 0.25);+ const len = Math.hypot(FROM[0], FROM[1]), ux = -FROM[0] / len, uy = -FROM[1] / len;+ // the flight: speeding up a touch as it falls+ const pos = (tt) => {+ const k = ease.inQuad(clamp(tt / HIT)) * 0.35 + clamp(tt / HIT) * 0.65;+ return [FROM[0] * (1 - k), FROM[1] * (1 - k)];+ };+ let t = 0, hit = false, last = pos(0);++ // the meteor: a lumpy rock, white-hot on its leading face, cracks glowing over the dark back, an outline+ const meteor = (p, x, y, R0, cool, alpha = 1) => {+ p.shade(x - R0 - 2, y - R0 - 2, x + R0 + 2, y + R0 + 2, (px, py, out) => {+ out.a = alpha;+ const dx = px - x, dy = py - y, d = Math.hypot(dx, dy), a = Math.atan2(dy, dx), rr = R0 * (1 + 0.18 * noise(a * 2.2 + 3, S) + 0.1 * noise(a * 5, S + 1));+ if (d > rr + 1) return;+ if (d > rr) return OUTLINE;+ const face = (dx * ux + dy * uy) / Math.max(1, d), heat = (1 - cool) * (face * 0.6 + 0.5 - (d / rr) * 0.25);+ if (heat > 0.62) return heat > 0.85 ? H[0] : heat > 0.74 ? H[1] : H[2];+ if (heat > 0.42) return H[4];+ const h = rand(Math.floor(px - x), Math.floor(py - y), S + 3);+ if (h < 0.22 * (1 - cool * 0.7)) return (1 - cool) > 0.5 ? H[4] : H[6];+ return dx * -0.6 + dy * -0.8 > 0 ? RK[2] : d / rr > 0.6 ? RK[0] : RK[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);+ };+ // the crater: hot rock pooled in the dent cooling to soot, a lip of broken floor+ const crater = (p) => {+ if (t < HIT) return;+ const a = t - HIT, end = 1 - smooth(meta.duration - 1, meta.duration - 0.15, t), rx = 36 * Math.min(1, a / 0.08), ry = 6;+ for (let y = -1; y <= 3; y++)+ for (let x = Math.floor(-rx); x <= Math.ceil(rx); x++) {+ const dx = (x + 0.5) / rx, dy = (y + 0.5) / ry, d = Math.sqrt(dx * dx + dy * dy);+ if (d > 1) continue;+ const k = rand(x * 31 + y, S + 5), T = Math.pow(clamp(1 - a / 2.6), 1.3) * (1.25 - d) - k * 0.35;+ if (T > 0.06) {+ const ramp = [H[0], H[1], H[2], H[3], H[4], H[5], H[6], H[7], H[8]], c = ramp[Math.min(8, Math.floor((1 - Math.min(1, T)) * 8))];+ p.dot(x, y, c, end);+ if ((x & 3) === 0) p.glow(x + 0.5, y, 7, c, 0.2 * T * end);+ } else p.dot(x, y, d < 0.55 ? SOOT : SOOT2, (d < 0.95 - k * 0.3 ? 1 : 1 - d) * end);+ }+ // the lip: broken floor heaped round the edge, lit by the glow inside+ for (let x = -40; x <= 40; x++) {+ const e = Math.abs(x) / 40, hh = e < 0.7 ? 0 : Math.round(2.4 * Math.sin(((e - 0.7) / 0.3) * Math.PI) * (0.6 + 0.4 * rand(x, S + 7)));+ for (let j = 0; j < hh; j++) p.dot(x, -1 - j, j === hh - 1 ? mix(st.light, H[4], 0.5 * clamp(1 - a / 2)) : st.shade, end);+ if (hh) p.dot(x, 0, OUTLINE, end);+ }+ };++ return {+ update(dt) {+ t += dt;+ if (t < HIT) {+ // the flight: a comet of fire shed behind, smoke, sparks, embers+ const [x, y] = pos(t), vx = (x - last[0]) / dt, vy = (y - last[1]) / dt;+ last = [x, y];+ for (let i = 0; i < 3; i++) {+ if (!R.chance(0.8 * dt * 60)) continue;+ ps.spawn(P.FIRE, x - ux * R.range(2, 8) + R.range(-3, 3), y - uy * R.range(2, 8) + R.range(-3, 3), vx * 0.15 + R.range(-20, 20), vy * 0.15 + R.range(-30, 10), R.range(0.3, 0.6), 0, R.range(3, 6), 0, R.chance(0.65) ? PF.SMOKES | PF.BIG : 0);+ }+ if (R.chance(0.6 * dt * 60)) ps.spawn(P.SPARK, x, y, vx * 0.35 + R.range(-80, 80), vy * 0.35 + R.range(-80, 40), R.range(0.2, 0.5));+ if (R.chance(0.3 * dt * 60)) ps.spawn(P.EMBER, x, y, vx * 0.1 + R.range(-30, 30), vy * 0.1 + R.range(-40, 0), R.range(0.8, 1.6), H[3], R.chance(0.2) ? 2 : 1);+ } else if (!hit) {+ hit = true;+ // the impact: flash, fireball thrown up and forward with the rock's momentum, a column, smoke, sparks+ lights.add(0, -40, 100, WARM, 0.95, 0.9);+ lights.add(0, -20, 46, WHITE, 0.9, 0.12);+ for (let i = 0; i < 34; i++) {+ const a = -Math.PI / 2 + R.range(-1.3, 1.3) + 0.25, sp = R.range(50, 210);+ ps.spawn(P.FIRE, R.range(-6, 6), -R.range(2, 10), Math.cos(a) * sp, Math.sin(a) * sp * 0.75 - 30, R.range(0.5, 1.1), 0, R.range(5, 9), 0, R.chance(0.5) ? PF.SMOKES | PF.BIG : 0);+ }+ for (let i = 0; i < 9; i++) ps.spawn(P.FIRE, R.range(-6, 6), -6, R.range(-14, 14), -R.range(130, 220), R.range(0.8, 1.2), 0, R.range(6, 8.5), R.range(0, 0.12), PF.SMOKES | PF.BIG);+ for (let i = 0; i < 20; i++) {+ const a = R.range(-Math.PI, 0), d = R.range(4, 18);+ ps.spawn(P.SMOKE, Math.cos(a) * d, -R.range(6, 24), Math.cos(a) * R.range(10, 40), -R.range(30, 110), R.range(1.8, 2.8), 0, R.range(8, 12), R.range(0.15, 0.5), PF.BIG);+ }+ for (let i = 0; i < 16; i++) {+ const s = R.sign();+ ps.spawn(P.SMOKE, s * R.range(4, 18), -R.range(1, 5), s * R.range(60, 130) + 10, -R.range(2, 12), R.range(1.2, 2.0), st.dust, R.range(5, 8), R.range(0, 0.06), PF.BIG);+ }+ for (let i = 0; i < 90; i++) {+ const a = -Math.PI / 2 + R.range(-1.3, 1.3) + 0.15, sp = R.range(100, 300);+ ps.spawn(P.SPARK, 0, -4, Math.cos(a) * sp, Math.sin(a) * sp, R.range(0.2, 0.7));+ }+ for (let i = 0; i < 36; i++) {+ const a = R.range(0, TAU), sp = R.range(40, 150);+ ps.spawn(P.EMBER, Math.cos(a) * 8, -8 + Math.sin(a) * 6, Math.cos(a) * sp, Math.sin(a) * sp - 70, R.range(1.2, 2.6), H[3]);+ }+ for (let i = 0; i < 10; i++) {+ const a = -Math.PI / 2 + R.range(-1, 1.05), sp = R.range(130, 240);+ ps.spawn(P.BRAND, 0, -6, Math.cos(a) * sp, Math.sin(a) * sp, R.range(0.7, 1.3));+ }+ for (let i = 0; i < 28; i++)+ bits.add({ kind: B.CHUNK, x: R.range(-8, 8), y: -3, vx: R.range(-80, 110), vy: -R.range(140, 340), g: 1, drag: 0.4, bounce: 0.3, life: R.range(1.8, 2.8), a: R.range(0, TAU), va: R.range(-16, 16), s: R.int(1, 3), ramp: [OUTLINE, st.shade, st.body, st.light, mix(st.light, WHITE, 0.3)] });+ for (let i = 0; i < 80; i++) {+ const u = R.range(-1, 1), a = -Math.PI / 2 + u * 0.7 + 0.15, sp = R.range(90, 270) * (1 - 0.4 * Math.abs(u));+ ps.spawn(P.GRIT, u * 6, -1, Math.cos(a) * sp, Math.sin(a) * sp, R.range(1.2, 2.2), R.pick([st.light, st.body, st.body, st.shade]), R.chance(0.45) ? 2 : 1);+ }+ }+ bits.update(dt);+ for (const b of bits.list)+ if (b.rest && !b.dusted) {+ b.dusted = true;+ for (let i = 0; i < 3; i++) ps.spawn(P.DUST, b.x + R.range(-1.5, 1.5), -0.5, R.sign() * R.range(8, 35), -R.range(2, 18), R.range(0.3, 0.6), st.dust, R.range(1.3, 2.6));+ }+ blazes.update(dt);+ ps.update(dt);+ lights.update(dt);+ },+ drawBack(p) {+ crater(p);+ simDraw(p, ps, H, "back");+ blazes.drawBack(p);+ const k = (t - HIT) / 0.5;+ if (k > 0 && k < 1) band(p, 0, 0.5, 110 * ease.outCubic(k), 0.16, Math.max(1, 5 * (1 - k)), 1.15 - k, [st.body, st.light, H[4], H[1]], (g) => Math.sin(g) < 0);+ },+ draw(p) {+ const k = (t - HIT) / 0.5;+ if (k > 0 && k < 1) band(p, 0, 0.5, 110 * ease.outCubic(k), 0.16, Math.max(1, 5 * (1 - k)), 1.15 - k, [st.body, st.light, H[4], H[1]], (g) => Math.sin(g) >= 0, k < 0.12);+ for (const b of bits.list) rock(p, b, st);+ if (t < HIT) {+ // the comet: tongues of flame streaming back off the rock, the rock, its light; the floor lights up below+ const [x, y] = pos(t), NZ = (rate, seed = 0, off = 0) => noise(t * rate + off, seed);+ floorLight(p, 0, 0.5, 30 + 40 * (t / HIT), 7, GLOW, 0.5 * (t / HIT) ** 2);+ [[36, 7, 0], [26, 7.5, -2.5], [26, 7.5, 2.5], [16, 8, 0]].forEach(([L, w, off], i) => {+ const n = (S + i) * 13;+ flameBlade(p, x - uy * off, y + ux * off, -ux, -uy, L * (0.85 + 0.25 * NZ(5, n)), w, NZ(3, n + 3) * 3, NZ, n, H, LAYERS, 0.5, 1.6);+ });+ meteor(p, x, y, 6.5, 0);+ p.glow(x, y, 46, GLOW, 0.55);+ p.glow(x, y, 12, H[1], 0.4);+ } else {+ // the core of the meteor sits half-buried in the crater, cooling+ const a = t - HIT, cool = clamp(a / 2.8), end = 1 - smooth(meta.duration - 1.1, meta.duration - 0.2, t);+ if (end > 0) {+ meteor(p, 0, 0, 5.5, cool, end);+ p.glow(0, -2, 22, GLOW, 0.4 * (1 - cool) * end);+ }+ }+ simDraw(p, ps, H, "front");+ // the hero frame: a white-hot flash and a flare of rays+ const f = (t - HIT) / 0.08;+ if (f > 0 && f < 1) {+ p.circle(0, -6, 11 * (1 - f * 0.3) + 1.5, H[3]);+ p.circle(0, -6, 11 * (1 - f * 0.3), f < 0.5 ? H[1] : H[2]);+ p.circle(0, -6, 7 * (1 - f * 0.3), f < 0.5 ? WHITE : H[1]);+ }+ const fr = (t - HIT) / 0.24;+ if (fr > 0 && fr < 1) flare(p, 0, -6, 44 * Math.pow(1 - fr, 1.4), 1 - fr, [H[6], H[4], H[2], H[1]]);+ lights.draw(p);+ },+ };}diff --git a/src/fx/fire/molotov.js b/src/fx/fire/molotov.jsdeleted file mode 100644index 8c75c64..0000000--- a/src/fx/fire/molotov.js+++ /dev/null@@ -1,97 +0,0 @@-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.jsindex 2d3153e..1142e5c 100644--- a/src/fx/fire/spirit-flame.js+++ b/src/fx/fire/spirit-flame.js@@ -1,59 +1,88 @@-import { ramp, cycle, clamp, tileFbm, loopNoise, TAU } from "../../core/index.js";-import { fit } from "./_lib.js";+// The layered tongue, its noise-torn edges and the shed puffs are adapted from Sprite Fusion's open-source fire+// (https://www.spritefusion.com/pixel-art-vfx/fire), MIT License, Copyright (c) 2026 Hugo Duprez.+import { fit, mix, clamp, WHITE, TAU } from "../../core/index.js";+import { noiseFor, hotFirst, looped, drift, soft } 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,+ desc: "A cold blue-teal ghost fire floating in the air: a bright rim round a hollow dark heart, a wave climbing its wispy tail, curls breaking off, cold sparks rising.",+ tags: ["fire", "spirit", "ghost", "magic", "cold", "ambient", "loop"],+ size: [80, 124],+ origin: [40, 94],+ duration: 3,loop: true,fps: 30,bg: "dark",- options: { palette: ["#0c0a2a", "#182462", "#1e4d9a", "#2584c4", "#38bede", "#7ceeea", "#d2fff6", "#ffffff"], height: 26, seed: 9 },+ options: {+ palette: ["#040a16", "#08203a", "#0b3a52", "#0f5e6e", "#16908e", "#2cc4b4", "#7ef0dc", "#c8fff2", "#ffffff"],+ seed: 7,+ },};+const D = meta.duration, NL = noiseFor(D);+// inverted layers: the rim burns brightest, a teal band inside it, a dark hollow heart, a pale core low down+const GHOST = [[1, 1, 1], [0.8, 0.92, 3], [0.6, 0.78, 6], [0.3, 0.42, 2], [0.14, 0.22, 0]];++// a tongue whose centre line carries a wave climbing it: drawn row by row in layers like a fire tongue+function ghostTongue(p, x, y, h, w, centre, N, n, H, layers, jit = 0.5) {+ for (const [lw, lh, ri] of layers) {+ const L = h * lh, c = H[ri];+ for (let r = 0; r <= L; r++) {+ const u = r / Math.max(1, L), v = r / h;+ // a teardrop: round at the bottom, swelling, then drawn out thin+ const half = w * lw * Math.pow(1 - u, 0.75) * Math.min(1, (r + 1.5) / 4) + N(6, n, r * 0.4) * jit * u;+ if (half < 0.3) continue;+ const cx = x + centre(v, r), Y = Math.round(y - r);+ for (let px = Math.round(cx - half), x1 = Math.round(cx + half); px <= x1; px++) p.px(px, Y, c);+ }+ }+}+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+ const F = fit(o.palette, 9), H = hotFirst(F), S = o.seed, ph = t / D;+ const N = (rate, seed = 0, off = 0) => NL(t, rate, seed, off);+ const COLD = mix(H[3], WHITE, 0.15), bob = Math.sin(ph * TAU) * 1.5;+ // the wave: it climbs the flame twice a loop, growing toward the tip, and the whole flame leans with a slow drift+ const lean = N(0.67, S + 2) * 3;+ const wave = (v, r, k = 0) => (Math.sin(r * 0.24 - ph * TAU * 2 + k) * 2.2 + Math.sin(r * 0.11 - ph * TAU + k * 0.5) * 3.2) * v * v + lean * v * v;+ const H0 = 44 * (0.92 + 0.08 * N(1.3, S + 3)), y0 = bob;++ // the glow it casts, cold and slow+ const br = 0.9 + 0.1 * N(2, S + 4);+ p.glow(0, y0 - 16, 60, COLD, 0.36 * br);+ p.glow(wave(0.5, 20) * 0.5, y0 - 20, 26, H[2], 0.2 * br);+ // curls breaking off the tips and drifting up, thinning out+ looped(t, D, 40, S + 300, (r) => ({ x: r.range(-4, 4), y: -H0 * r.range(0.55, 0.95), vx: r.range(-7, 7), vy: -r.range(10, 22), life: r.range(1, 1.9), s: r.range(1.4, 2.8), a: r.range(0, TAU), w: r.range(2, 3.5) }), (q, age) => {+ const tb = t - age, [x, y] = drift(q.x + wave(0.9, 26, 0) * 0.5, q.y + y0, q.vx, q.vy, age, 0, -6, 1.2, 0.6), k = 1 - age / q.life;+ const cx = x + Math.sin(age * q.w + q.a) * 3 * (age + 0.2), a = Math.min(1, age * 5) * k;+ soft(p, cx, y, q.s * (0.8 + age * 0.8), H[4], 0.35 * a);+ soft(p, cx - 0.4, y - 0.6, q.s * 0.5 * (0.8 + age * 0.5), H[2], 0.4 * a * k);+ p.glow(cx, y, 6, H[3], 0.15 * a);});- // 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));+ // two thin wisps trailing off the sides, then the body+ // side wisps that flicker out and curl, now long, now gone+ const wl = Math.max(0, 0.25 + 0.55 * N(1.7, S + 6)), wr = Math.max(0, 0.25 + 0.55 * N(1.7, S + 7));+ if (wl > 0.12) ghostTongue(p, -4, y0 - 4, H0 * wl, 2.4, (v, r) => wave(v, r, 2.1) - 6 * v * v + 3 * Math.sin(v * 5 - ph * TAU * 2) * v, N, S * 11 + 1, H, GHOST);+ if (wr > 0.12) ghostTongue(p, 4.2, y0 - 4, H0 * wr, 2.4, (v, r) => wave(v, r, -1.8) + 6 * v * v - 3 * Math.sin(v * 5 - ph * TAU * 2 + 1) * v, N, S * 11 + 2, H, GHOST);+ ghostTongue(p, 0, y0, H0, 8.6, (v, r) => wave(v, r), N, S * 11, H, GHOST, 0.6);+ // bright strands drifting up through the hollow heart+ for (const k of [0, 1]) {+ for (let r = 4; r < H0 * 0.72; r++) {+ const v = r / H0, x = wave(v, r) + Math.sin(r * 0.35 - ph * TAU * 3 + k * Math.PI) * 2.2 * (1 - v), on = Math.sin(r * 0.2 - ph * TAU * 4 + k * 2) > 0.2;+ if (on) p.px(x, y0 - r, k ? H[2] : H[1]);+ }+ }+ // light along the body+ for (const v of [0.2, 0.45, 0.7]) p.glow(wave(v, H0 * v), y0 - H0 * v, 12, H[2], 0.16 * br);+ // the pale heart breathing low in the flame+ p.glow(0, y0 - 4, 9, H[1], 0.22 + 0.06 * N(3, S + 5));+ // cold sparks rising off it, twinkling+ looped(t, D, 34, S + 400, (r) => ({ x: r.range(-7, 7), y: -r.range(4, 28), vx: r.range(-12, 12), vy: -r.range(14, 34), life: r.range(0.9, 1.8), a: r.range(0, TAU) }), (q, age) => {+ const [x, y] = drift(q.x, q.y + y0, q.vx, q.vy, age, 0, -10, 1.2, 1.2), k = 1 - age / q.life, tw = 0.5 + 0.5 * Math.sin(age * 14 + q.a);+ const sx = x + Math.sin(age * 3 + q.a) * 3;+ if (k * (0.4 + 0.6 * tw) < 0.2) return;+ p.px(sx, y, tw > 0.7 && k > 0.5 ? H[0] : k > 0.5 ? H[1] : H[3]);+ if (tw > 0.85 && k > 0.6) p.px(sx - 1, y, H[3]), p.px(sx + 1, y, H[3]), p.px(sx, y - 1, H[3]), p.px(sx, y + 1, H[3]);+ p.glow(sx, y, 4, H[2], 0.3 * k);});- 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.jsindex 7d124ac..e4fc006 100644--- a/src/fx/fire/torch.js+++ b/src/fx/fire/torch.js@@ -1,62 +1,91 @@-import { PAL, ramp, fit, at, cycle, tileFbm, loopNoise, clamp, TAU } from "../../core/index.js";+// The tongue, lick, flame-puff, smoke and ember recipe is adapted from Sprite Fusion's open-source fire+// (https://www.spritefusion.com/pixel-art-vfx/fire), MIT License, Copyright (c) 2026 Hugo Duprez.+import { fit, mix, hex, rand, clamp } from "../../core/index.js";+import { noiseFor, hotFirst, burn } from "./_lib.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,+ desc: "A wall torch on an iron bracket: a licking flame leaping off a pitch-soaked wrap, licks and puffs torn off its tips, smoke, embers, a flickering light on the wall.",+ tags: ["fire", "torch", "prop", "light", "wall", "dungeon", "loop"],+ size: [72, 120],+ origin: [36, 94],+ duration: 2,loop: true,fps: 30,bg: "dark",- options: { palette: PAL.fire, handle: true, height: 22, seed: 1 },+ options: {+ palette: ["#4a1712", "#8a1f17", "#c9281f", "#f2561d", "#ff8a2a", "#ffc23d", "#ffe26b", "#fff3a6", "#ffffff"],+ wood: ["#0e080a", "#24130f", "#3b2216", "#5a3520", "#8a5a34", "#b9884f"],+ iron: ["#0d0b12", "#1e1b26", "#363242", "#5b5566", "#8a8396"],+ seed: 4,+ },};-const WOOD = ramp(["#2a160c", "#4a2a16", "#6e4222", "#8e5a30"]);-const IRON = ramp(["#1b1a22", "#34323f", "#55525f", "#807c8a"]);+const D = meta.duration, NL = noiseFor(D), BASE = -16;+// the flame: [x, y from the wrap's top, height share, half-width, back row?]+const TONGUES = [+ [-1.9, -1, 0.74, 2.0, 1],+ [2.1, -1, 0.7, 2.0, 1],+ [-3.4, 0.5, 0.42, 1.6, 0],+ [3.6, 0.5, 0.46, 1.6, 0],+ [0, 0, 1, 2.9, 0],+];-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);+// the bracket: a bevelled iron plate on the wall with two rivets, and a ring round the handle+function plate(p, I, H, fl) {+ p.shade(-5.5, -5.5, 5.5, 11.5, (x, y) => {+ if (x < -5 || x > 5 || y < -5 || y > 11) return I[0];+ const rv = Math.abs(x) < 0.6 && (Math.abs(y + 3.5) < 0.6 || Math.abs(y - 9.5) < 0.6);+ if (rv) return mix(I[4], H[3], 0.35 * fl);+ if (y < -4 || x < -4) return mix(I[3], H[4], 0.3 * fl);+ if (y > 10 || x > 4) return I[1];+ return y < 2 ? I[2] : I[1];+ });+}+function handle(p, W) {+ p.shade(-3, -12, 3, 15, (x, y) => {+ const half = 1.3 + clamp((14 - y) / 26) * 0.9;+ if (Math.abs(x) > half + 0.5 || y > 14.5) return;+ if (Math.abs(x) > half - 0.5 || y > 13.5) return W[0];+ const g = rand(Math.floor(y / 3), Math.round(x), 9);+ return x < -0.3 ? (g < 0.3 ? W[2] : W[4]) : g < 0.4 ? W[1] : W[2];});- // 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]);+}+function ring(p, I, H, fl) {+ p.rect(-3, -2, 7, 4, I[0]);+ p.rect(-2, -1, 5, 1, mix(I[4], H[3], 0.3 * fl));+ p.rect(-2, 0, 5, 1, I[2]);+}+// the head: rags bound with cord and soaked in pitch, flaring into a cup at the top, charred where it burns+// with embers breathing in the folds+function wrap(p, W, I, H, t) {+ p.shade(-6, BASE - 2, 6, -9, (x, y, out) => {+ const v = (y - (BASE - 1.5)) / 7.5, half = 4.6 - v * 1.9;+ if (Math.abs(x) > half + 0.5 || y < BASE - 1.5 || y > -9.5) return;+ if (Math.abs(x) > half - 0.5 || y > -10.5) return W[0];+ const cord = Math.floor(y - x * 0.6 + 40) % 3 === 0, h = rand(Math.floor(x), Math.floor(y), 31);+ if (v < 0.45) {+ if (h < 0.42) {+ const g = 0.5 + 0.5 * Math.sin((t / D) * Math.PI * 4 + h * 40);+ out.k = 0.3 * g;+ return g > 0.66 ? H[2] : g > 0.33 ? H[4] : H[5];+ }+ return h < 0.75 ? W[0] : W[1];+ }+ if (cord) return I[2];+ return x < -1 ? W[3] : x < 1.5 ? W[2] : W[1];});- // 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));+}++export function draw(p, t, o) {+ const F = fit(o.palette, 9), H = hotFirst(F), W = fit(o.wood, 6), I = fit(o.iron, 5), S = o.seed;+ const fl0 = 0.74 + 0.16 * NL(t, 7.3, S + 1) + 0.1 * NL(t, 19, S + 2);+ plate(p, I, H, fl0);+ handle(p, W);+ ring(p, I, H, fl0);+ burn(p, t, TONGUES, {+ H, D, NL, S, x: 0, y: BASE, height: 20, lean: 0.12, spread: 4,+ puffs: 10, licks: 5, smoke: 7, smokeSize: 2.3, smokeLife: [1.3, 2.1], embers: 7, glowR: 48, glow: 1.25, wind: 2,+ mid: () => wrap(p, W, I, H, t),});- // 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.jsindex 29e0287..fbf39af 100644--- a/src/fx/holy/_lib.js+++ b/src/fx/holy/_lib.js@@ -1,54 +1,188 @@-// Shared by the holy effects: plus signs, feathers, and the generic helpers the arcane effects use.+// The plus sign's lit and shaded bevel is adapted from Sprite Fusion's open-source heal (https://www.spritefusion.com/pixel-art-vfx/heal),+// MIT License, Copyright (c) 2026 Hugo Duprez.+// Shared by the holy effects: gold, green and ash ramps, the character's silhouette and recolors, floor ovals,+// feathers of light (drawn, and simulated as they rock and sink) and plus signs.// Files starting with _ are helpers, not effects.-import { WHITE } from "../../core/index.js";-export { fit, sparkle, ovalLine, tiltedOval, silhouette, ahead } from "../arcane/_lib.js";+import { WHITE, TAU, clamp, smooth, luma } from "../../core/index.js";-// Light ramps for things that are white rather than gold: feathers, wings.-export const FEATHER = ["#2a2440", "#4d4566", "#7f7898", "#b5b0c8", "#e4e1ee", "#fffdf6"];+/** Holy gold, dark to bright: a plum shadow, rust, amber, gold, pale gold, cream, white. */+export const GOLD = ["#3b1d2a", "#7a3a2c", "#c4652e", "#f0a040", "#ffd25e", "#fff0a0", "#fffbe0", "#ffffff"];+/** Healing green, warm: deep pine, leaf, spring green, a yellow-green highlight, cream. */+export const GREEN = ["#0e2a24", "#14472f", "#1d6e3a", "#2f9a45", "#5cc654", "#a0e46c", "#dcffb4", "#ffffff"];+/** Ash: the colour of the fallen, a cool grey-violet, dark to light. */+export const ASH = ["#16131c", "#26222f", "#3a3546", "#524c5e", "#6e6878", "#8c8796"];-// 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.."],-];+// ---- the character-/** 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 });+const SHAPES = new WeakMap();+/**+ * The actor's silhouette as local points, cached per mask: edge (its own rim pixels), out (the 1 px ring just+ * outside it), at(x, y) (inside?), top and bottom (y of the first row and one past the last).+ */+export function shapeOf(A) {+ let s = SHAPES.get(A.mask);+ if (s && s.x === A.x && s.y === A.y) return s;+ const m = A.mask, inside = (i, j) => i >= 0 && j >= 0 && i < m.w && j < m.h && m.data[j * m.w + i] > 0;+ const edge = [], out = [];+ for (let j = -1; j <= m.h; j++)+ for (let i = -1; i <= m.w; i++) {+ const nb = inside(i - 1, j) + inside(i + 1, j) + inside(i, j - 1) + inside(i, j + 1);+ if (inside(i, j)) {+ if (nb < 4) edge.push([A.x + i, A.y + j]);+ } else if (nb) out.push([A.x + i, A.y + j]);+ }+ s = { x: A.x, y: A.y, edge, out, top: A.y, bottom: A.y + m.h, at: (x, y) => inside(Math.floor(x) - A.x, Math.floor(y) - A.y) };+ SHAPES.set(A.mask, s);+ return s;+}++/**+ * Draw the actor's own pixels recolored: fn(c, x, y) gives the new color for its pixel c at (x, y), or 0 to+ * leave that pixel alone (the character shows through). a: alpha, or a function of (x, y).+ */+export function recolor(p, A, fn, a = 1) {+ const m = A.mask, P = A.pixels, fa = typeof a === "function";+ if (!P) return;+ for (let j = 0; j < m.h; j++)+ for (let i = 0; i < m.w; i++) {+ const c = P[j * m.w + i];+ if (!c) continue;+ const x = A.x + i, y = A.y + j, n = fn(c, x, y);+ if (n) p.dot(x, y, n, fa ? a(x, y) : a);+ }+}++/** A color mapped onto a ramp by its brightness (a tint that keeps the character's shading). */+export const toneOf = (R, c, lift = 0) => R[clamp(Math.floor((luma(c) * 1.1 + lift) * R.length), 0, R.length - 1)];++// ---- floor and ovals++/**+ * A 1 px oval (a ring on a tilted plane): centre (cx, cy), radii rx, ry. c and a may be functions of the angle+ * g round it (sin(g) > 0 is the near side). keep(g) picks the part to draw.+ */+export function oval(p, cx, cy, rx, ry, c, a = 1, keep = null) {+ if (rx < 0.5) return;+ const n = Math.ceil(Math.max(rx, ry) * TAU * 1.5) + 6, fc = typeof c === "function", fa = typeof a === "function";+ for (let j = 0; j < n; j++) {+ const g = (j / n) * TAU;+ if (keep && !keep(g)) continue;+ p.dot(cx + Math.cos(g) * rx, cy + Math.sin(g) * ry, fc ? c(g) : c, fa ? a(g) : a);+ }}+export const FAR = (g) => Math.sin(g) < 0;+export const NEAR = (g) => Math.sin(g) >= 0;-// 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."],-];+// ---- feathers/**- * 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).+ * A feather of light from its quill at (x, y) pointing along ang, len px long, with a rounded tip; the+ * trailing vane, wid px wide, falls on side (1: clockwise of the shaft, -1: the other way), the leading vane+ * is under half that. R: a ramp, dark to bright (6+ steps). a: alpha. hot 0..1 whitens it (a flash). A white+ * shaft, a lit leading rim, a warm dark trailing edge that parts it from the next feather, a body that cools+ * from cream at the quill to gold, and a tip that thins into light.*/-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 });+export function feather(p, x, y, ang, len, wid, R, a = 1, side = 1, hot = 0, quill = 0.02) {+ if (len < 1.5 || a <= 0.02) return;+ const n = R.length, ca = Math.cos(ang), sa = Math.sin(ang), x1 = x + ca * len, y1 = y + sa * len, pad = wid + 1.2, h = hot > 0.5;+ const edge = h ? R[n - 3] : R[n - 5], lead = h ? WHITE : R[n - 2], B = h ? [WHITE, WHITE, R[n - 2]] : [R[n - 2], R[n - 3], R[n - 4]];+ p.each(Math.min(x, x1) - pad, Math.min(y, y1) - pad, Math.max(x, x1) + pad, Math.max(y, y1) + pad, (px, py, sx, sy) => {+ const dx = px - x, dy = py - y, u = (dx * ca + dy * sa) / len;+ if (u < 0 || u > 1.05) return;+ const v = (-dx * sa + dy * ca) * side, av = Math.abs(v);+ const w = wid * Math.sqrt(clamp((u - quill) / 0.22)) * Math.sqrt(Math.max(0, 1 - Math.pow(Math.max(0, (u - 0.55) / 0.47), 2)));+ const lim = v < 0 ? w * 0.42 : w, fade = u < 0.72 ? 1 : 1 - (u - 0.72) * 1.6;+ if (av < 0.5 && u < 0.9) return p.put(sx, sy, u < 0.5 ? WHITE : B[0], a);+ if (av > lim + 0.05 || w < 0.5) return;+ if (lim - av < 1) return v > 0 ? p.put(sx, sy, u > 0.85 ? B[2] : edge, a * fade) : p.put(sx, sy, lead, a);+ if (u < 0.72) return p.put(sx, sy, u < 0.38 ? B[0] : B[1], a);+ p.blendPx(sx, sy, B[2], a * fade);+ });}-const flipped = new Map();-function flipV(rows) {- if (!flipped.has(rows)) flipped.set(rows, [...rows].reverse());- return flipped.get(rows);+/**+ * Loose feathers that are thrown, brake hard, then rock like a pendulum as they sink, tilting with each swing+ * and sinking fastest through the bottom of it; on the floor they lie flat and fade.+ * add({ x, y (centre), vx, vy, a (angle), len, wid, life, delay, back }); update(dt); draw(p, R, layer).+ */+export class Feathers {+ constructor(rng, floor = 0) {+ this.R = rng;+ this.floor = floor;+ this.list = [];+ }+ add(f) {+ const R = this.R;+ this.list.push({ vx: 0, vy: 0, a: 0, len: 7, wid: 2, delay: 0, back: false, side: R.sign(), ph: R.range(0, TAU), w: R.range(3.2, 4.6), amp: R.range(6, 11), sink: R.range(14, 24), va: R.range(-9, 9), tilt: R.range(-0.35, 0.35), ...f, max: f.life, age: 0, landed: false });+ }+ get count() {+ return this.list.length;+ }+ update(dt) {+ for (let i = this.list.length - 1; i >= 0; i--) {+ const f = this.list[i];+ if (f.delay > 0) {+ f.delay -= dt;+ continue;+ }+ if ((f.life -= dt) <= 0) {+ this.list.splice(i, 1);+ continue;+ }+ f.age += dt;+ if (f.landed) {+ f.a += (Math.round(f.a / Math.PI) * Math.PI - f.a) * Math.min(1, dt * 10);+ continue;+ }+ // the throw: drag kills it fast while it spins+ f.vx -= f.vx * 3.4 * dt;+ f.vy -= f.vy * 3.4 * dt;+ const s = smooth(0.1, 0.6, f.age), ph = f.age * f.w + f.ph, c = Math.cos(ph);+ // the flutter: a swing across, a sink that's fastest through the bottom of each swing+ f.x += (f.vx + Math.sin(ph) * f.amp * s * 0.9) * dt;+ f.y += (f.vy + f.sink * s * (c * c * 1.5 - 0.2)) * dt;+ // it lies along its swing, tipping up at each end+ const rest = Math.round(f.a / Math.PI) * Math.PI + f.tilt + Math.sin(ph) * 0.6;+ f.a += f.va * dt * (1 - s) + (rest - f.a) * Math.min(1, dt * 5 * s);+ if (f.y >= this.floor - 0.5) {+ f.y = this.floor - 0.5;+ f.landed = true;+ f.life = Math.min(f.life, 0.6);+ }+ }+ }+ draw(p, R, layer) {+ for (const f of this.list) {+ if (f.delay > 0 || (layer && (f.back ? "back" : "front") !== layer)) continue;+ const k = f.life / f.max, a = Math.min(1, f.life / 0.45, f.age / 0.06), ca = Math.cos(f.a), sa = Math.sin(f.a);+ feather(p, f.x - (ca * f.len) / 2, f.y - (sa * f.len) / 2, f.a, f.len, f.wid, R, a, f.side, f.age < 0.06 ? 1 : 0, 0.2);+ p.glow(f.x, f.y, 4 + f.len * 0.5, R[R.length - 3], 0.22 * a * (0.4 + 0.6 * k));+ }+ }}+// ---- plus signs++/**+ * A plus sign of light centred on (x, y): arm length L (1..4) and thickness th (1 or 3): a white heart and+ * spine, colored arms lit on the top and left, shaded on the bottom and right. R: a ramp, dark to bright.+ */+export function plus(p, x, y, L, th, R, a = 1, glint = false) {+ const n = R.length, X = Math.round(x), Y = Math.round(y), w = th > 1 ? 1 : 0;+ const ins = (i, j) => (Math.abs(i) <= w && Math.abs(j) <= L) || (Math.abs(j) <= w && Math.abs(i) <= L);+ for (let j = -L - 1; j <= L + 1; j++)+ for (let i = -L - 1; i <= L + 1; i++) {+ if (!ins(i, j)) {+ if (w && (ins(i - 1, j) || ins(i + 1, j) || ins(i, j - 1) || ins(i, j + 1))) p.dot(X + i, Y + j, R[Math.max(0, n - 6)], a * 0.9);+ continue;+ }+ let c;+ if (!w) c = i === 0 && j === 0 ? WHITE : Math.abs(i) + Math.abs(j) >= L ? R[n - 3] : R[n - 2];+ else if (i === 0 && j === 0) c = WHITE;+ else if (i === 0 || j === 0) c = Math.abs(i) + Math.abs(j) < L ? R[n - 2] : R[n - 3];+ else c = i < 0 || j < 0 ? R[n - 3] : R[n - 5];+ if (glint && ((i === 0 && j === -L) || (i === -L && j === 0))) c = WHITE;+ p.dot(X + i, Y + j, c, a);+ }+}diff --git a/src/fx/holy/blessing.js b/src/fx/holy/blessing.jsindex c310189..fe56527 100644--- a/src/fx/holy/blessing.js+++ b/src/fx/holy/blessing.js@@ -1,49 +1,115 @@-import { PAL, cycle, clamp, TAU, WHITE } from "../../core/index.js";-import { fit, sparkle } from "./_lib.js";+import { fit, sparkle, cycle, rng, clamp, smooth, lerp, TAU, WHITE, mix, luma } from "../../core/index.js";+import { GOLD, shapeOf } 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,+ desc: "A soft cone of light rests on the character from above; sparkles drift down through it, twinkling, and wink out where they land on the head and shoulders.",+ tags: ["holy", "blessing", "buff", "light", "sparkle", "character", "loop"],+ size: [80, 128],+ origin: [40, 108],+ duration: 3,loop: true,fps: 30,bg: "ground",- actor: true,- options: { palette: PAL.holy, count: 16, seed: 39 },+ actor: 2,+ options: { palette: GOLD, seed: 7 },};-const TOP = -46;+const TOP = -108, T = 3;+const halfW = (y) => lerp(5, 20, (y - TOP) / -TOP);+// the rays in the cone, each shimmering a whole number of times a loop so it closes+const RAYS = [[-0.62, 0.16, 1, 0.3], [-0.2, 0.2, 2, 1.7], [0.22, 0.14, 1, 4.1], [0.6, 0.18, 2, 2.6]];+const ray = (q, t) => {+ let I = 0.3 * Math.max(0, 1 - q * q);+ for (const [o, w, k, ph] of RAYS) I += Math.exp(-(((q - o) / w) ** 2)) * (0.55 + 0.45 * Math.sin((t / T) * TAU * k + ph)) * 0.6;+ return I * smooth(1.25, 0.75, Math.abs(q));+};-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));- });+// where each falling sparkle meets the character or the floor (cached per seed and character)+const LANDS = new Map();+function landings(o, S) {+ const key = `${o.seed}:${S.x}:${S.y}`;+ if (LANDS.has(key)) return LANDS.get(key);+ const out = [];+ for (let i = 0; i < 20; i++) {+ const R = rng(o.seed, i), q = R.range(-0.9, 0.9), v = R.range(22, 34), sway = R.range(1, 3), ph = R.range(0, TAU), size = R.range(0.8, 2.4);+ let land = Infinity;+ for (let a = 0; a < 6; a += 0.02) {+ const y = TOP + 6 + v * a, x = q * halfW(y) + Math.sin(a * 2.2 + ph) * sway;+ if (y >= -1 || S.at(x, y)) {+ land = a;+ break;+ }+ }+ out.push({ q, v, sway, ph, size, land });+ }+ LANDS.set(key, out);+ return out;}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);+ const C = fit(o.palette, 8);+ // the cone: soft light with a faint gold haze in it+ p.each(-24, TOP, 24, 0.5, (x, y, sx, sy) => {+ const I = ray(x / halfW(y), t) * (0.6 + 0.4 * smooth(TOP, 0, y));+ if (I < 0.02) return;+ p.blendPx(sx, sy, C[6], I * 0.13);+ p.add(sx, sy, C[4], I * 0.22);});- shower(p, t, o, false);+ // two of the rays show as fine lines, light running slowly down them+ for (const [o2, , k, ph] of [RAYS[1], RAYS[2]])+ for (let y = TOP; y < -1; y++) {+ const pulse = 0.5 + 0.5 * Math.sin(y * 0.11 - (t / T) * TAU * 3 + ph);+ p.dot(o2 * halfW(y), y, pulse > 0.85 ? WHITE : C[6], (0.1 + 0.45 * pulse) * (0.5 + 0.5 * Math.sin((t / T) * TAU * k + ph)) * smooth(TOP, TOP + 20, y));+ }+ p.glow(0, -4, 30, C[4], 0.22);}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);+ const C = fit(o.palette, 8), A = o.actor, S = A ? shapeOf(A) : null;+ // light catching the top of the head and the shoulders+ if (A) {+ const m = A.mask;+ for (let i = 0; i < m.w; i++)+ for (let j = 0; j < m.h; j++) {+ const c = A.pixels[j * m.w + i];+ if (!c || luma(c) < 0.15) continue;+ p.px(A.x + i, A.y + j, mix(c, C[6], 0.35));+ break;+ }+ p.glow(0, -30, 20, C[5], 0.22);+ }+ // the floor catches it: a lit line and a pool fading out into the stone+ for (let y = 0; y <= 3; y++)+ for (let x = -24; x <= 24; x++) {+ const u = Math.hypot(x / 24, y / 4);+ if (u >= 1) continue;+ p.dot(x, y, u < 0.3 ? (y ? C[5] : WHITE) : u < 0.6 ? C[5] : u < 0.85 ? C[4] : C[3], y === 0 ? Math.sqrt(1 - u) : (1 - u) * 0.7);+ }+ // sparkles drifting down, twinkling, winking out where they land+ if (S) {+ const L = landings(o, S);+ cycle(t, T, L.length, o.seed, (g) => 3, (age, life, R, i) => {+ const s = L[i], y = TOP + 6 + s.v * age, x = s.q * halfW(y) + Math.sin(age * 2.2 + s.ph) * s.sway, fade = Math.min(1, age / 0.3);+ if (age > s.land) {+ const w = (age - s.land) / 0.14;+ if (w < 1) {+ const ly = TOP + 6 + s.v * s.land, lx = s.q * halfW(ly) + Math.sin(s.land * 2.2 + s.ph) * s.sway;+ sparkle(p, lx, ly, 3 * (1 - w) + 1, WHITE, C[6], 0.5 * (1 - w));+ }+ return;+ }+ const tw = 0.6 + 0.4 * Math.sin(age * (7 + (i % 4)) + s.ph);+ if (s.size > 1.2) sparkle(p, x, y, s.size * tw * fade, tw > 0.85 ? WHITE : C[6], C[5], 0.35 * fade);+ else {+ p.dot(x, y, tw > 0.8 ? WHITE : C[6], fade);+ p.glow(x, y, 3, C[5], 0.35 * fade);+ }+ });+ }+ // fine motes hanging in the light+ cycle(t, T, 16, o.seed + 9, (g) => g.range(1.2, 2.4), (age, life, R) => {+ const u = age / life, y = TOP + 10 + R.range(0, 90) + u * R.range(6, 14), q = R.range(-1, 1), x = q * halfW(y) + Math.sin(age * 1.7 + q * 5) * 1.5, k = Math.sin(u * Math.PI) * ray(q, t);+ if (k > 0.12) p.dot(x, y, k > 0.45 ? WHITE : C[6], Math.min(1, k * 2.2));+ });}diff --git a/src/fx/holy/divine-shield.js b/src/fx/holy/divine-shield.jsindex a12af74..5f8e505 100644--- a/src/fx/holy/divine-shield.js+++ b/src/fx/holy/divine-shield.js@@ -1,58 +1,124 @@-import { PAL, cycle, TAU, WHITE } from "../../core/index.js";-import { fit, sparkle, ovalLine } from "./_lib.js";+import { fit, sparkle, cycle, clamp, smooth, TAU, WHITE } from "../../core/index.js";+import { GOLD, oval, shapeOf } 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,+ desc: "A bubble of gold light round the character: a bright rim and a thin gold film, meridians turning like a slow globe, a sheen sweeping across and sparkles winking on it.",+ tags: ["holy", "shield", "bubble", "barrier", "buff", "character", "loop"],+ size: [88, 84],+ origin: [44, 68],+ duration: 2.4,loop: true,fps: 30,bg: "ground",- actor: true,- options: { palette: PAL.holy, radius: 13, seed: 35 },+ actor: 2,+ options: { palette: GOLD, radius: 29, seed: 8 },};-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);+const CY = -22, TILT = 0.34, N = 4, FLOOR_SY = 0.26;++// a point of the sphere (lat, lon) seen from a little above: screen x, y and depth z (> 0 faces us)+function onSphere(r, lat, lon) {+ const X = r * Math.cos(lat) * Math.sin(lon), Y = r * Math.sin(lat), Z = r * Math.cos(lat) * Math.cos(lon);+ return [X, CY - (Y * Math.cos(TILT) - Z * Math.sin(TILT)), Y * Math.sin(TILT) + Z * Math.cos(TILT)];+}++// the sheen: a diagonal band crossing the bubble once a loop, then a rest+const sheen = (t, T) => -1.7 + 3.4 * clamp(((t / T) % 1) / 0.55);++function lattice(p, t, o, back) {+ const C = fit(o.palette, 8), r = o.radius, T = meta.duration, phi = (t / T) * (Math.PI / N), sw = sheen(t, T), seen = new Map();+ // gather the lines' pixels first, so each is drawn once+ const dot = (x, y, z) => {+ if (z < 0 !== back) return;+ const key = Math.floor(x) * 1000 + Math.floor(y), f = Math.abs(z) / r, q = (x - (y - CY)) / (r * 1.414), hot = Math.abs(q - sw) < 0.12 ? 1 : 0, v = seen.get(key);+ if (!v || f < v[2]) seen.set(key, [x, y, f, hot || (v ? v[3] : 0)]);+ };+ // meridians, turning+ for (let k = 0; k < 2 * N; k++) {+ const lon = phi + (k * Math.PI) / N;+ for (let lat = -Math.PI / 2; lat <= Math.PI / 2; lat += 0.7 / r) dot(...onSphere(r, lat, lon));+ }+ // the equator+ for (let lon = 0; lon < TAU; lon += 0.7 / r) dot(...onSphere(r, 0, lon));+ // behind: faint and broken. In front: bright where the surface turns away, a translucent wash of gold+ // where it faces us, so the character still shows through+ for (const [x, y, f, hot] of seen.values()) {+ if (back) p.blend(x, y, C[4], 0.32);+ else if (hot) p.px(x, y, WHITE);+ else if (f < 0.4) p.px(x, y, C[6]);+ else p.blend(x, y, f < 0.7 ? C[6] : C[5], f < 0.7 ? 0.8 : 0.55);}- 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);+function film(p, t, o, back) {+ const C = fit(o.palette, 8), r = o.radius, sw = sheen(t, meta.duration);+ p.each(-r - 1, CY - r - 1, r + 1, CY + r + 1, (x, y, sx, sy) => {+ const d = Math.hypot(x, y - CY) / r;+ if (d >= 1) return;+ const q = (x - (y - CY)) / (r * 1.414), hot = Math.max(0, 1 - Math.abs(q - sw) / 0.22);+ const a = (back ? 0.07 : 0.03) + 0.26 * Math.pow(d, 6) + 0.2 * hot * (back ? 0.3 : 1);+ p.blendPx(sx, sy, hot > 0.5 && !back ? C[6] : C[5], a);+ });+}++export function drawBack(p, t, o) {+ const C = fit(o.palette, 8), r = o.radius, rf = Math.sqrt(r * r - CY * CY);+ film(p, t, o, true);+ lattice(p, t, o, true);+ // where it meets the floor: the far half of a bright seal+ oval(p, 0, 0, rf, rf * FLOOR_SY, C[5], 0.8, (g) => Math.sin(g) < 0);+ p.glow(0, CY, r * 1.1, C[4], 0.14);+}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];+ const C = fit(o.palette, 8), r = o.radius, T = meta.duration, rf = Math.sqrt(r * r - CY * CY), A = o.actor;+ // the bubble lights the character from all round+ if (A) for (const [x, y] of shapeOf(A).out) p.light(x, y, C[5], 0.3);+ film(p, t, o, false);+ lattice(p, t, o, false);+ // the rim: bright where the light sits (top left) and where the sheen crosses it+ const sw = sheen(t, T);+ for (let j = 0, n = Math.ceil(r * TAU * 1.4); j < n; j++) {+ const g = (j / n) * TAU, x = Math.cos(g) * r, y = CY + Math.sin(g) * r, q = (x - (y - CY)) / (r * 1.414);+ const lit = Math.cos(g + 2.36), hot = Math.abs(q - sw) < 0.15;+ p.dot(x, y, hot || lit > 0.75 ? WHITE : lit > -0.2 ? C[6] : C[5], 1);+ p.dot(Math.cos(g) * (r - 1), CY + Math.sin(g) * (r - 1), C[4], 0.35 + 0.3 * lit);+ }+ p.glowRing(0, CY, r, 6, C[4], 0.32);+ // where the meridians cross the equator, and at the pole they all turn round, the lattice catches the light+ const phi = (t / T) * (Math.PI / N);+ for (let k = 0; k < 2 * N; k++) {+ const [x, y, z] = onSphere(r, 0, phi + (k * Math.PI) / N);+ if (z < r * 0.15) continue;+ p.px(x, y, WHITE);+ if (z > r * 0.45) for (const [dx, dy] of [[1, 0], [-1, 0], [0, 1], [0, -1]]) p.blend(x + dx, y + dy, C[6], 0.7);+ p.glow(x, y, 4, C[5], 0.3);+ }+ const [px0, py0] = onSphere(r, Math.PI / 2, 0);+ sparkle(p, px0, py0, 2 + Math.round(1.5 + 1.5 * Math.sin((t / T) * TAU * 2)), WHITE, C[6], 0.45);+ // two glints chase each other round the rim+ for (const off of [0, Math.PI]) {+ const g = (t / T) * TAU + off + 0.8;+ sparkle(p, Math.cos(g) * r, CY + Math.sin(g) * r, 2, WHITE, C[6], 0.4);+ }+ // a bubble's shine: a bright curl up on the left, a dot under it, a faint one low on the right+ for (let g = 3.55; g < 4.2; g += 0.04) p.px(Math.cos(g) * r * 0.74, CY + Math.sin(g) * r * 0.74, g > 3.7 && g < 4.05 ? WHITE : C[6]);+ p.px(Math.cos(3.4) * r * 0.62, CY + Math.sin(3.4) * r * 0.62, WHITE);+ for (let g = 0.45; g < 0.8; g += 0.05) p.dot(Math.cos(g) * r * 0.8, CY + Math.sin(g) * r * 0.8, C[5], 0.6);+ // the near half of the floor seal and a pool of light+ oval(p, 0, 0, rf, rf * FLOOR_SY, (g) => (Math.sin(g) > 0.6 ? WHITE : C[6]), 1, (g) => Math.sin(g) >= 0);+ for (let i = -2; i <= 2; i++) p.glow(i * rf * 0.5, 0, 12, C[4], 0.18);+ // sparkles winking on its skin as it turns, motes rising inside+ cycle(t, T, 9, o.seed, (g) => g.range(0.35, 0.6), (age, life, R) => {+ const [x, y, z] = onSphere(r, R.range(-1.2, 1.3), R.range(0, TAU) + phi), k = Math.sin((age / life) * Math.PI);+ if (z < 0) return;+ sparkle(p, x, y, 1 + 2.5 * k * R.range(0.6, 1), WHITE, C[6], 0.45 * k);});- 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);+ cycle(t, T, 12, o.seed + 1, (g) => g.range(1.2, 2.2), (age, life, R) => {+ const x0 = R.range(-0.7, 0.7) * r, u = age / life, x = x0 + Math.sin(u * 6 + R.range(0, 6)) * 2, y = CY + r * 0.75 - u * r * 1.4;+ if (Math.hypot(x, y - CY) > r - 2) return;+ p.dot(x, y, u < 0.5 ? C[6] : C[5], Math.sin(u * Math.PI));+ p.light(x, y, C[5], 0.4 * Math.sin(u * Math.PI));});- 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.jsindex cf3a1c2..16c0cd2 100644--- a/src/fx/holy/feather-burst.js+++ b/src/fx/holy/feather-burst.js@@ -1,49 +1,91 @@-import { burst, fly, flyV, seg, ease, TAU, WHITE } from "../../core/index.js";-import { fit, sparkle, feather, FEATHER } from "./_lib.js";+import { Particles, Lights, P, Rng, fit, sparkle, clamp, smooth, ease, TAU, WHITE, hex, mix } from "../../core/index.js";+import { Feathers } 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,+ desc: "A white puff pops and throws feathers that brake hard, then rock from side to side as they sink and fade, with down drifting after them.",+ tags: ["holy", "feather", "burst", "poof", "angel", "bird", "one-shot"],+ size: [160, 160],+ origin: [80, 60],+ duration: 3,loop: false,fps: 30,bg: "dark",- options: { palette: FEATHER, count: 16, seed: 38 },+ options: { palette: ["#4a4560", "#7a7494", "#aaa5c2", "#d6d3e6", "#f4f3fa", "#ffffff"], glow: "#fff0c0", seed: 4 },};-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);+export function create(o) {+ const F = fit(o.palette, 6), G = hex(o.glow), R = new Rng(o.seed);+ const ps = new Particles({ rng: R, ground: () => Infinity, sparks: [WHITE, F[4], F[3], F[2]] });+ const lights = new Lights(), loose = new Feathers(R, 1e6);+ // the puff: soft lobes thrown out from the pop, swelling and thinning+ const lobes = Array.from({ length: 11 }, (_, i) => {+ const a = (i / 11) * TAU + R.range(-0.25, 0.25), d = R.range(5, 14);+ return { x: Math.cos(a) * d, y: Math.sin(a) * d * 0.8, r0: R.range(2.5, 4), r1: R.range(6, 9.5), life: R.range(0.45, 0.8) };});+ for (let i = 0; i < 20; i++) {+ const a = (i / 20) * TAU + R.range(-0.15, 0.15), sp = R.range(110, 230), up = Math.sin(a) < 0 ? 0.7 : 0.9;+ loose.add({ x: Math.cos(a) * 3, y: Math.sin(a) * 3, vx: Math.cos(a) * sp, vy: Math.sin(a) * sp * up - 20, a: a + R.range(-0.5, 0.5), len: R.range(10, 14), wid: R.range(2.6, 3.4), life: R.range(1.9, 2.6), delay: R.range(0, 0.03), sink: R.range(26, 38), amp: R.range(8, 13) });+ }+ // small feathers and down, slower+ for (let i = 0; i < 10; i++) {+ const a = R.range(0, TAU), sp = R.range(50, 130);+ loose.add({ x: 0, y: 0, vx: Math.cos(a) * sp, vy: Math.sin(a) * sp - 20, a: R.range(0, TAU), len: R.range(6, 8), wid: R.range(1.8, 2.2), life: R.range(1.6, 2.4), back: true, sink: R.range(18, 28) });+ }+ for (let i = 0; i < 26; i++) {+ const a = R.range(0, TAU), sp = R.range(30, 140);+ ps.spawn(P.FLAKE, R.range(-3, 3), R.range(-3, 3), Math.cos(a) * sp, Math.sin(a) * sp - 15, R.range(1.4, 2.6), R.chance(0.6) ? WHITE : F[4], R.range(0.6, 1.6));+ }+ for (let i = 0; i < 10; i++) {+ const a = R.range(0, TAU), sp = R.range(60, 160);+ ps.spawn(P.STAR, 0, 0, Math.cos(a) * sp, Math.sin(a) * sp, R.range(0.3, 0.6), R.chance(0.5) ? WHITE : G, R.range(0.8, 2.2));+ }+ lights.add(0, 0, 50, G, 0.75, 0.45);+ lights.add(0, 0, 20, WHITE, 0.7, 0.1);+ let t = 0;++ function puff(p) {+ for (const l of lobes) {+ const u = t / l.life;+ if (u >= 1) continue;+ const e = ease.outCubic(u), x = l.x * (0.4 + e * 1.3), y = l.y * (0.4 + e * 1.3) - u * 5;+ const r = (l.r0 + (l.r1 - l.r0) * ease.outCubic(Math.min(1, u * 3))) * (1 - ease.inQuad(u));+ if (r < 0.6) continue;+ p.circle(x, y, r + 0.8, F[2]);+ p.circle(x, y, r, (d, a) => (d > 0.55 && Math.sin(a + 0.8) > 0.3 ? F[3] : d < 0.45 && Math.sin(a + 0.8) < -0.2 ? WHITE : F[4]));+ }+ }++ return {+ update(dt) {+ t += dt;+ // feathers catch the light as they turn+ if (t > 0.3 && t < 2.2 && loose.count && R.chance(0.14)) {+ const q = R.pick(loose.list);+ if (q.delay <= 0) ps.spawn(P.STAR, q.x + R.range(-2, 2), q.y + R.range(-1, 1), 0, 0, R.range(0.2, 0.4), R.chance(0.5) ? WHITE : G, R.range(1, 2.2));+ }+ ps.update(dt);+ loose.update(dt);+ lights.update(dt);+ },+ drawBack(p) {+ loose.draw(p, F, "back");+ ps.draw(p, "back");+ puff(p);+ },+ draw(p) {+ // the pop: a white flash and a ring of air+ if (t < 0.07) p.circle(0, 0, 9 * (1 - t / 0.14), WHITE);+ if (t < 0.25) {+ const u = t / 0.25;+ p.ring(0, 0, 6 + 24 * ease.outCubic(u), Math.max(1, 2.5 * (1 - u)), (v) => (v > 0.5 ? WHITE : mix(F[4], G, 0.4)), 1.1 - u);+ }+ if (t < 0.2) sparkle(p, 0, 0, 10 * (1 - t / 0.2), WHITE, G, 0.6);+ // the burst's warmth lingers a moment+ p.glow(0, 4, 46, G, 0.28 * (1 - smooth(0, 1.3, t)));+ loose.draw(p, F, "front");+ ps.draw(p, "front");+ lights.draw(p);+ },+ };}diff --git a/src/fx/holy/halo.js b/src/fx/holy/halo.jsindex a91bbeb..7b12065 100644--- a/src/fx/holy/halo.js+++ b/src/fx/holy/halo.js@@ -1,40 +1,70 @@-import { PAL, cycle, TAU, WHITE } from "../../core/index.js";-import { fit, ovalLine, ahead, sparkle } from "./_lib.js";+import { fit, sparkle, cycle, TAU, WHITE, mix, luma } from "../../core/index.js";+import { GOLD } 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],+ desc: "A ring of gold light floats over the head with a glint running round it; fine dust sifts down from it and the hair catches its light.",+ tags: ["holy", "halo", "saint", "buff", "glow", "character", "loop"],+ size: [56, 80],+ origin: [28, 70],duration: 2,loop: true,fps: 30,bg: "ground",- actor: true,- options: { palette: PAL.holy, radius: 6, seed: 37 },+ actor: 2,+ options: { palette: GOLD, seed: 5 },};+const HY = -46, RX = 9.5, RY = 2.6;+// how far apart two angles are (0..π)+const apart = (a, b) => Math.abs(((a - b + Math.PI) % TAU + TAU) % TAU - Math.PI);+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);+ const C = fit(o.palette, 8), T = meta.duration, ph = (t / T) * TAU, A = o.actor;+ const y0 = HY + (Math.sin(ph) > 0.55 ? -1 : 0), gl = Math.PI / 2 + ph;+ // the hair under it catches the light+ if (A) {+ // a warm rim on the top edge of each column of the head, and light falling off below it+ const m = A.mask;+ for (let i = 0; i < m.w; i++)+ for (let j = 0; j < Math.min(m.h, 9); j++) {+ const c = A.pixels[j * m.w + i];+ // skip empty space and the dark outline, light the first pixel of hair under it+ if (!c || luma(c) < 0.15) continue;+ const x = A.x + i, y = A.y + j;+ p.px(x, y, mix(c, C[6], 0.45));+ const c2 = A.pixels[(j + 1) * m.w + i];+ if (c2 && luma(c2) >= 0.15) p.px(x, y + 1, mix(c2, C[5], 0.18));+ for (let d = 0; d <= 4; d++) p.light(x, y + d, C[4], 0.3 * (1 - d / 5));+ break;+ }+ }+ // the ring: a thick bright near side, a thin far side, a slow shimmer running round, the glint+ for (let j = 0, n = 92; j < n; j++) {+ const g = (j / n) * TAU, x = Math.cos(g) * RX, y = y0 + Math.sin(g) * RY, near = Math.sin(g) >= 0;+ const shimmer = Math.sin(g * 3 - ph * 2) > 0.7, hot = apart(g, gl) < 0.3;+ if (near) {+ p.px(x, y, hot ? WHITE : shimmer ? WHITE : C[6]);+ p.px(x, y + 1, hot ? C[6] : C[4]);+ } else p.dot(x, y, hot ? WHITE : shimmer ? C[6] : C[5], 0.9);+ }+ p.glow(0, y0, 20, C[4], 0.4);+ p.glow(0, y0 + 1, 9, WHITE, 0.16);+ const gx = Math.cos(gl) * RX, gy = y0 + Math.sin(gl) * RY;+ if (Math.sin(gl) > -0.2) sparkle(p, gx, gy + 0.5, 1.5 + 2.5 * Math.max(0, Math.sin(gl)), WHITE, C[6], 0.45);+ else p.glow(gx, gy, 5, C[6], 0.3);+ // light falls from it onto the head+ p.glowLine(0, y0 + 2, 0, y0 + 9, 9, C[4], 0.16);+ // little stars wink on and off about the ring+ cycle(t, T, 6, o.seed + 3, (g) => g.range(0.3, 0.5), (age, life, R) => {+ const g = R.range(0, TAU), d = R.range(1.1, 1.5), k = Math.sin((age / life) * Math.PI);+ sparkle(p, Math.cos(g) * RX * d, y0 + Math.sin(g) * RY * d - R.range(1, 4), 1 + 2 * k, WHITE, C[6], 0.4 * k);+ });+ // dust sifting down off the ring+ cycle(t, T, 16, o.seed, (g) => g.range(0.8, 1.5), (age, life, R) => {+ const g = R.range(0, TAU), u = age / life, x = Math.cos(g) * RX * R.range(0.8, 1) + Math.sin(u * 5 + g) * 1.2, y = y0 + Math.sin(g) * RY + 1 + u * R.range(7, 14);+ const tw = 0.6 + 0.4 * Math.sin(age * 18 + g * 7), k = Math.sin(u * Math.PI) * tw;+ p.dot(x, y, tw > 0.85 ? WHITE : C[6], Math.min(1, k * 1.5));+ p.light(x, y, C[5], 0.5 * k);});- // 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.jsindex 19fd088..5e7c9d9 100644--- a/src/fx/holy/heal-aoe.js+++ b/src/fx/holy/heal-aoe.js@@ -1,51 +1,156 @@-import { PAL, burst, seg, ease, clamp, TAU, WHITE } from "../../core/index.js";-import { fit, plus, ovalLine } from "./_lib.js";+import { Particles, Lights, P, Rng, fit, sparkle, flare, band, clamp, smooth, seg, ease, rand, TAU, WHITE } from "../../core/index.js";+import { GREEN, plus, oval } 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,+ desc: "A seed of green light sinks into the floor and a soft ring rolls out from it; the floor glows where it passes and plus signs sprout and float up.",+ tags: ["holy", "heal", "aoe", "ring", "plus", "ground", "one-shot"],+ size: [256, 136],+ origin: [128, 104],+ duration: 2.9,loop: false,fps: 30,bg: "ground",- options: { palette: PAL.heal, accent: PAL.gold, radius: 42, count: 14, seed: 32 },+ options: { palette: GREEN, reach: 104, seed: 6 },};-const SQ = 0.34; // floor squash-const T_RING = 0.75;+const SY = 0.2, SEED = 0.3, ROLL = 1.0;-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));+export function create(o) {+ const C = fit(o.palette, 8), REACH = o.reach, R = new Rng(o.seed);+ const ps = new Particles({ rng: R, ground: () => 0, sparks: [WHITE, C[6], C[5], C[4]] });+ const lights = new Lights();+ const front = (tt) => (tt < SEED ? 0 : REACH * ease.outCubic(seg(tt, SEED, SEED + ROLL)));+ const passed = (d) => SEED + ROLL * (1 - Math.cbrt(1 - Math.min(0.999, d / REACH)));+ // where plus signs sprout: scattered over the floor, each waiting for the ring to reach it+ const sites = Array.from({ length: 26 }, (_, i) => {+ const a = R.range(0, TAU), d = REACH * Math.sqrt(R.range(0.04, 0.92)), big = i % 5 < 2;+ return { x: Math.cos(a) * d, z: Math.sin(a) * d, t0: passed(d) + R.range(0, 0.06), rise: R.range(18, 34), life: R.range(0.9, 1.3), sway: R.range(0, TAU), L: big ? 3 + (i % 5 === 0 ? 1 : 0) : i % 5 === 2 ? 1 : 2, thick: big ? 3 : 1, popped: false };+ });+ // the rolling ring carries little lights round with it+ const riders = Array.from({ length: 14 }, (_, i) => ({ a: (i / 14) * TAU + R.range(-0.2, 0.2), w: R.range(0.6, 1.1) * (i % 2 ? 1 : -1) }));+ let t = 0, released = false;++ function wash(p) {+ // the floor glows behind the front and fades after it+ const fr = front(t);+ if (fr < 2 || t > 2.6) return;+ p.shade(-fr - 1, -fr * SY - 1, fr + 1, fr * SY + 1, (x, y, out) => {+ const d = Math.hypot(x, y / SY);+ if (d > fr) return;+ const age = t - passed(d), k = Math.exp(-age / 0.35) * smooth(fr, fr - 6, d) * (1 - smooth(1.4, 1.9, t));+ if (k < 0.04) return;+ out.l = C[4];+ out.k = 0.32 * k;});- // 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)));++ function ring(p, back) {+ if (t < SEED) return;+ const u = seg(t, SEED, SEED + ROLL + 0.25), fr = front(t), k = u < 0.7 ? 1 : (1 - u) / 0.3;+ if (k <= 0) return;+ const keep = back ? (g) => Math.sin(g) < 0 : (g) => Math.sin(g) >= 0;+ band(p, 0, 0, fr, SY, Math.max(2, 7 * (1 - u * 0.7)), k, C.slice(2), keep, t < SEED + 0.08);+ oval(p, 0, 0, fr + 1, (fr + 1) * SY, (g) => (Math.sin(g) > 0.3 ? WHITE : C[6]), k * (back ? 0.7 : 1), keep);+ // a crest of light blades flickers up along the front as it rolls+ for (let j = 0, n = Math.ceil(fr * 0.9); j < n; j++) {+ const g = (j / n) * TAU, near = Math.sin(g) >= 0;+ if (near === back || rand(j, Math.floor(t * 20)) > 0.45) continue;+ const x = Math.cos(g) * fr, y = Math.sin(g) * fr * SY, h = (1 + rand(j, 7) * 4) * k * (near ? 1 : 0.6);+ for (let i = 1; i <= h; i++) p.dot(x, y - i, i > h - 1 ? WHITE : C[6], k * (1.2 - i / (h + 1)));+ }+ // lights riding round the ring as it rolls+ for (const r of riders) {+ const g = r.a + r.w * (t - SEED) * 2.2, near = Math.sin(g) >= 0;+ if (near === back) continue;+ const x = Math.cos(g) * fr, y = Math.sin(g) * fr * SY;+ if (near) sparkle(p, x, y - 1, 2 + (Math.sin(t * 9 + r.a * 5) > 0.3 ? 1 : 0), WHITE, C[6], 0.35 * k);+ else p.dot(x, y, C[6], k);+ }+ if (!back) for (let i = 0; i < 8; i++) {+ const g = (i / 8) * TAU;+ p.glow(Math.cos(g) * fr, Math.sin(g) * fr * SY - 2, 16, C[4], 0.22 * k);+ }+ }++ function sprouts(p, back) {+ for (const s of sites) {+ const a = t - s.t0;+ if (a < 0 || a > s.life || s.z < 0 !== back) continue;+ const u = a / s.life, h = s.rise * ease.outCubic(u), x = s.x + Math.sin(a * 4 + s.sway) * 1.5 * u, y = s.z * SY - 2 - h;+ const pop = ease.outBack(clamp(a / 0.12), 2.6), end = s.life - 0.15, L = Math.max(1, Math.round(s.L * pop - (back ? 1 : 0)));+ if (a < 0.04) sparkle(p, x, y, 3, WHITE, C[6], 0.5);+ else if (a < end) plus(p, x, y, L, back && L < 3 ? 1 : s.thick, back ? C.slice(0, 7) : C, back ? 0.8 : 1, !back && Math.sin(a * 12 + s.sway * 3) > 0.8);+ else {+ const v = (a - end) / 0.15;+ for (const [dx, dy] of [[1, 1], [1, -1], [-1, 1], [-1, -1]]) p.dot(x + dx * (2 + v * 5), y + dy * (2 + v * 5) - v * 2, v < 0.4 ? WHITE : C[6], 1 - v);+ }+ // a thread of light still ties it to the floor while it rises+ if (u < 0.5) for (let j = 1; j < h * (1 - u * 2); j += 1.5) p.dot(s.x, s.z * SY - 2 - h + j + 3, C[5], (1 - j / h) * (1 - u * 2) * (back ? 0.5 : 0.8));+ p.glow(x, y, 7 + L * 2, C[5], (back ? 0.2 : 0.34) * (a < end ? 1 : 1 - (a - end) / 0.15));+ }+ }++ return {+ update(dt) {+ t += dt;+ // the seed gathers: motes slide in over the floor to a point that brightens+ if (t < SEED - 0.04 && R.chance(0.7)) {+ const a = R.range(0, TAU), D = R.range(24, 48), x = Math.cos(a) * D, y = Math.sin(a) * D * SY - R.range(1, 8);+ const T = R.range(0.16, 0.24), l = Math.hypot(x, y + 3) || 1, v = (l * 3) / (Math.exp(3 * T) - 1);+ ps.spawn(P.STREAK, x, y, (-x / l) * v, ((-3 - y) / l) * v, T, R.chance(0.5) ? C[6] : C[5]);+ }+ if (!released && t >= SEED) {+ released = true;+ lights.add(0, -16, 76, C[5], 0.85, 0.55);+ lights.add(0, -6, 28, WHITE, 0.8, 0.12);+ for (let i = 0; i < 10; i++) ps.spawn(P.MOTE, R.range(-2, 2), -R.range(2, 10), R.range(-25, 25), -R.range(80, 170), R.range(0.3, 0.6), R.chance(0.5) ? WHITE : C[6], R.range(0.6, 1));+ for (let i = 0; i < 16; i++) {+ const a = R.range(Math.PI * 1.05, Math.PI * 1.95), sp = R.range(40, 120);+ ps.spawn(P.STAR, 0, -3, Math.cos(a) * sp, Math.sin(a) * sp, R.range(0.4, 0.8), R.chance(0.5) ? WHITE : C[6], R.range(0.6, 2));+ }+ }+ for (const s of sites)+ if (!s.popped && t >= s.t0) {+ s.popped = true;+ // a splash of dew where each one breaks the floor+ for (let i = 0; i < 3; i++) ps.spawn(P.STAR, s.x + R.range(-3, 3), s.z * SY - 1, R.range(-10, 10), -R.range(15, 40), R.range(0.3, 0.6), R.chance(0.5) ? WHITE : C[6], R.range(0.5, 1.2), 0, s.z < 0 ? 4 : 0);+ }+ // dew rising off the glowing floor behind the ring+ if (t > SEED + 0.1 && t < 1.9 && R.chance(0.35)) {+ const fr = front(t), a = R.range(0, TAU), d = fr * Math.sqrt(R.next());+ ps.spawn(P.EMBER, Math.cos(a) * d, Math.sin(a) * d * SY - 1, R.range(-5, 5), -R.range(10, 30), R.range(0.5, 1), C[5], 1, 0, Math.sin(a) < 0 ? 4 : 0);+ }+ ps.update(dt);+ lights.update(dt);+ },+ drawBack(p) {+ wash(p);+ ring(p, true);+ sprouts(p, true);+ ps.draw(p, "back");+ },+ draw(p) {+ ring(p, false);+ // the seed: a point of light pulsing on the floor, then a flare as it lets go+ if (t < SEED) {+ const k = t / SEED;+ sparkle(p, 0, -3, 2 + 4 * k * k, WHITE, C[6], 0.3 + 0.4 * k);+ p.glow(0, -3, 10 + 16 * k, C[4], 0.5 * k);+ } else if (t < SEED + 0.2) flare(p, 0, -3, 22 * Math.pow(1 - (t - SEED) / 0.2, 1.5), 1 - (t - SEED) / 0.2, C.slice(3));+ // as it lets go, a jet of light leaps out of the floor, lets go of it and dissolves upward+ const g = seg(t, SEED, SEED + 0.5);+ if (g > 0 && g < 1) {+ const top = -4 - 46 * ease.outCubic(Math.min(1, g * 2.2)) - 10 * g, bot = -2 - 50 * ease.inQuad(seg(g, 0.35, 1)), w = 1 + 2.4 * (1 - g);+ if (bot - top > 2) {+ p.beam(0, bot, 0, top, w * 2, (u, v) => (v < 0.45 ? WHITE : u > 0.8 ? C[5] : C[6]));+ p.glowLine(0, bot, 0, top, 12, C[5], 0.55 * (1 - g));+ sparkle(p, 0, top, 4 * (1 - g) + 1, WHITE, C[6], 0.5 * (1 - g));+ }+ }+ sprouts(p, false);+ ps.draw(p, "front");+ lights.draw(p);+ },+ };}diff --git a/src/fx/holy/heal.js b/src/fx/holy/heal.jsindex f5f0f5e..d570bc8 100644--- a/src/fx/holy/heal.js+++ b/src/fx/holy/heal.js@@ -1,64 +1,175 @@-import { PAL, burst, stream, seg, ease, TAU, WHITE } from "../../core/index.js";-import { fit, plus, ovalLine } from "./_lib.js";+import { Particles, Lights, P, Rng, fit, sparkle, clamp, smooth, seg, lerp, ease, TAU, WHITE, mix, luma, rgb } from "../../core/index.js";+import { shapeOf, recolor, oval } 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,+ desc: "Petals of light bloom under the feet, a hoop of light rises up the body restoring its colour and leaving sparkles, and motes spiral up and pop into tiny hearts.",+ tags: ["holy", "heal", "restore", "buff", "petals", "hearts", "character", "one-shot"],+ size: [80, 104],+ origin: [40, 92],+ duration: 1.9,loop: false,fps: 30,bg: "ground",- actor: true,- options: { palette: PAL.heal, accent: PAL.gold, count: 8, seed: 31 },+ actor: 2,+ options: { palette: ["#3d2027", "#7d3f35", "#c97a4a", "#f2b46a", "#ffd994", "#fff0cf", "#fffaf2", "#ffffff"], seed: 2 },};-// 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));- });-}+const SY = 0.3, NP = 8, PR = 16, LIFT0 = 0.16, LIFT1 = 0.74, TOPY = -43;+const HEART = [".#.#.", "#####", ".###.", "..#.."];-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));+// a tiny heart of light: cream body, a white glint, a warm rim+function heart(p, x, y, C, a) {+ const X = Math.round(x) - 2, Y = Math.round(y) - 2, at = (i, j) => j >= 0 && j < 4 && i >= 0 && i < 5 && HEART[j][i] === "#";+ for (let j = -1; j <= 4; j++)+ for (let i = -1; i <= 5; i++) {+ if (at(i, j)) p.dot(X + i, Y + j, i === 1 && j === 1 ? WHITE : j >= 2 ? C[5] : C[6], a);+ else if (at(i - 1, j) || at(i + 1, j) || at(i, j - 1) || at(i, j + 1)) p.dot(X + i, Y + j, C[3], a * 0.9);+ }+ p.glow(x, y, 6, C[5], 0.4 * a);}-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));+export function create(o) {+ const C = fit(o.palette, 8), A = o.actor, S = shapeOf(A), R = new Rng(o.seed);+ const ps = new Particles({ rng: R, ground: () => 0, sparks: [WHITE, C[6], C[5], C[4]] });+ const lights = new Lights();+ const rows = new Map();+ for (const [x, y] of S.edge) (rows.get(y) ?? rows.set(y, []).get(y)).push(x);+ // petals, each blooming on its own beat round the ring+ const petals = Array.from({ length: NP }, (_, k) => ({ a: (k / NP) * TAU + 0.2, t0: 0.02 + ((k * 3) % NP) * 0.035, w: R.range(4.2, 5.2) }));+ // motes riding a spiral up round the body: from the petal tips as they open, and from the hoop when it bursts+ const motes = [];+ for (let k = 0; k < NP; k++) motes.push({ t0: 0.2 + k * 0.05, th0: petals[k].a, r0: PR * 0.9, y0: -1, w: 4.2 * (k % 2 ? 1 : -1), v: R.range(46, 58), life: R.range(0.75, 0.95), kind: k % 2 });+ for (let k = 0; k < 8; k++) motes.push({ t0: LIFT1 + R.range(0, 0.06), th0: (k / 8) * TAU, r0: R.range(12, 18), y0: TOPY + R.range(-2, 4), w: 3.6 * (k % 2 ? 1 : -1), v: R.range(14, 34), life: R.range(0.35, 0.6), kind: (k + 1) % 2 });+ let t = 0, burst = false, lastRow = 1;++ const hoopY = (tt) => lerp(0, TOPY, ease.inOutSine(seg(tt, LIFT0, LIFT1)));+ const hoopR = (tt) => lerp(PR, 12, seg(tt, LIFT0, LIFT1));++ function bloom(k, tt) {+ const pe = petals[k];+ return ease.outBack(seg(tt, pe.t0, pe.t0 + 0.3), 1.8) * (1 - ease.inBack(seg(tt, 1.25 + k * 0.02, 1.6 + k * 0.02), 1.4));+ }++ // a petal of a lotus of light round the feet: rooted on a ring on the floor, leaning out as it opens,+ // foreshortened as it turns away; a lit rim, a white vein, a translucent warm body, a white tip+ function petal(p, k, back) {+ const pe = petals[k], g = pe.a + t * 0.4, near = Math.sin(g) >= 0, b = bloom(k, t);+ if (near === back || b <= 0.02) return;+ const ca = Math.cos(g), sa = Math.sin(g), rb = 6, rt = rb + 9 * Math.min(1.2, b), h = (k % 2 ? 7 : 9) * b;+ const bx = ca * rb, by = sa * rb * SY, tx = ca * rt, ty = sa * rt * SY - h, L = Math.hypot(tx - bx, ty - by);+ if (L < 1.5) return;+ const ux = (tx - bx) / L, uy = (ty - by) / L, W = pe.w * Math.min(1, b) * (0.35 + 0.65 * Math.abs(sa)), pad = W + 1;+ p.each(Math.min(bx, tx) - pad, Math.min(by, ty) - pad, Math.max(bx, tx) + pad, Math.max(by, ty) + pad, (x, y, sx, sy) => {+ const dx = x - bx, dy = y - by, u = (dx * ux + dy * uy) / L;+ if (u < 0 || u > 1) return;+ const hw = W * Math.pow(Math.sin(Math.PI * Math.pow(u, 0.6)), 0.7) + 0.2, v = Math.abs(-dx * uy + dy * ux) / hw;+ if (v > 1) return;+ if (u > 0.9) return p.put(sx, sy, WHITE, 1);+ if (v > 0.7) return p.put(sx, sy, u < 0.3 ? C[3] : u < 0.7 ? C[5] : C[6], 1);+ if (v < 0.2 && u > 0.15 && u < 0.85) return p.put(sx, sy, u < 0.55 ? C[5] : C[6], back ? 0.75 : 0.85);+ p.blendPx(sx, sy, u < 0.45 ? C[3] : C[4], back ? 0.6 : 0.45);+ });+ p.glow(tx, ty, 5, C[5], 0.35 * Math.min(1, b));}- // 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]);++ // the hoop of light rising up the body: far half behind, near half in front, a soft glow round it+ function hoop(p, back) {+ if (t < LIFT0 || t > LIFT1 + 0.12) return;+ const y = hoopY(t), r = hoopR(t) * (t > LIFT1 ? 1 - (t - LIFT1) / 0.12 : 1), keep = back ? (g) => Math.sin(g) < 0 : (g) => Math.sin(g) >= 0;+ oval(p, 0, y, r, r * SY, (g) => (Math.sin(g) > 0.5 ? WHITE : C[6]), back ? 0.8 : 1, keep);+ if (!back) {+ oval(p, 0, y + 1, r - 0.5, r * SY, C[4], 1, keep);+ for (let i = -2; i <= 2; i++) p.glow(i * r * 0.45, y, 8, C[5], 0.32);+ }+ }++ return {+ update(dt) {+ t += dt;+ // the hoop leaves sparkles on the body as it passes each row+ if (t > LIFT0 && t < LIFT1) {+ const Y = Math.round(hoopY(t));+ for (let y = lastRow; y > Y; y--) {+ const xs = rows.get(y);+ if (!xs || !R.chance(0.45)) continue;+ ps.spawn(P.STAR, R.pick(xs) + R.range(-1, 1) * 2, y, R.range(-4, 4), -R.range(4, 12), R.range(0.3, 0.55), R.chance(0.5) ? WHITE : C[6], R.range(0.6, 1.6));+ }+ lastRow = Math.min(lastRow, Y);+ }+ if (!burst && t >= LIFT1) {+ burst = true;+ lights.add(0, TOPY, 26, C[5], 0.55, 0.3);+ lights.add(0, TOPY, 10, WHITE, 0.45, 0.08);+ }+ ps.update(dt);+ lights.update(dt);+ },+ drawBack(p) {+ // a warm pool under the flower+ const pool = smooth(0, 0.2, t) * (1 - smooth(1.3, 1.75, t));+ if (pool > 0) p.glow(0, -2, 30, C[4], 0.3 * pool);+ for (let k = 0; k < NP; k++) petal(p, k, true);+ hoop(p, true);+ ps.draw(p, "back");+ riders(p, true);+ },+ draw(p) {+ // drained of colour above the hoop, restored below it with a warm glow at the line+ const drain = smooth(0, 0.08, t);+ if (t < LIFT1 + 0.35) {+ const Y = t < LIFT0 ? 1 : hoopY(t), done = t >= LIFT1;+ recolor(p, A, (c, x, y) => {+ const d = y - Y;+ if (!done && d < -0.5) {+ const l = luma(c) * 0.88;+ return mix(c, rgb(l * 236, l * 226, l * 222), 0.68 * drain);+ }+ if (!done && d < 1) return WHITE;+ if (!done && d < 2.5) return C[6];+ const k = (done ? 0.45 * (1 - seg(t, LIFT1, LIFT1 + 0.35)) : 0.5 * Math.exp(-(d - 2.5) / 5));+ return k > 0.05 ? mix(c, C[5], k) : 0;+ });+ if (t > LIFT0 && !done) p.glow(0, Y, 18, C[5], 0.35);+ }+ for (let k = 0; k < NP; k++) petal(p, k, false);+ hoop(p, false);+ if (t >= LIFT1 && t < LIFT1 + 0.25) sparkle(p, 0, TOPY, 8 * (1 - (t - LIFT1) / 0.25), WHITE, C[5], 0.6);+ riders(p, false);+ ps.draw(p, "front");+ lights.draw(p);+ },+ };++ // the spiralling motes, each popping into a heart or a sparkle at the end of its ride+ function riders(p, back) {+ for (const m of motes) {+ const a = t - m.t0;+ if (a < 0) continue;+ const at = (aa) => {+ const th = m.th0 + m.w * aa, r = m.r0 * (1 - 0.45 * (aa / m.life));+ return [Math.cos(th) * r, m.y0 - m.v * aa, Math.sin(th)];+ };+ if (a < m.life) {+ const [x, y, z] = at(a);+ if (z < 0 !== back) continue;+ for (let j = 0; j < 7; j++) {+ const aj = a - j * 0.03;+ if (aj < 0) break;+ const [tx, ty, tz] = at(aj);+ if (tz < 0 !== back) continue;+ p.dot(tx, ty, j === 0 ? WHITE : j < 3 ? C[6] : C[5], (1 - j / 7) * (back ? 0.6 : 1));+ }+ p.glow(x, y, 4, C[5], back ? 0.2 : 0.4);+ continue;+ }+ // the pop: a quick sparkle, then a heart (or a star) that floats up and fades+ const u = (a - m.life) / 0.36;+ if (u >= 1 || back) continue;+ const [x, y] = at(m.life), k = 1 - smooth(0.5, 1, u);+ if (u < 0.12) sparkle(p, x, y, 3, WHITE, C[6], 0.5);+ else if (m.kind) heart(p, x, y - u * 6, C, k);+ else sparkle(p, x, y - u * 5, 1 + 2 * k * (0.7 + 0.3 * Math.sin(a * 30)), WHITE, C[5], 0.45 * k);+ }}- 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.jsindex b6aa3a7..0bb153e 100644--- a/src/fx/holy/holy-pillar.js+++ b/src/fx/holy/holy-pillar.js@@ -1,85 +1,212 @@-import { PAL, burst, stream, fly, seg, ease, clamp, tileNoise, WHITE } from "../../core/index.js";-import { fit, ovalLine, sparkle } from "./_lib.js";+import { Particles, Lights, P, Rng, fit, sparkle, clamp, smooth, seg, lerp, ease, rand, TAU, WHITE } from "../../core/index.js";+import { GOLD, Feathers, oval } 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,+ desc: "Light breaks through from above: a sun opens at the top and a fan of shafts converges on the mark, pulsing, while a sigil burns on the floor; then the fan folds shut.",+ tags: ["holy", "pillar", "light", "rays", "aoe", "sigil", "ground", "one-shot"],+ size: [192, 232],+ origin: [96, 204],+ duration: 3.5,loop: false,fps: 30,bg: "ground",- options: { palette: PAL.holy, width: 10, seed: 33 },+ options: { palette: GOLD, shafts: 7, seed: 3 },};-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);+const TOP = -204, PY = -1, SUN = TOP + 38, SY = 0.24, RX = 26;+// the sun opens, the fan unfolds and pours down, it holds and pulses, folds shut, the light lifts away+const OPEN = 0.3, HIT = 0.66, FOLD = 2.05, SHUT = 2.45, LIFT = 2.75;+const frac = (x) => x - Math.floor(x);++export function create(o) {+ const C = fit(o.palette, 8), N = Math.max(3, o.shafts | 0), R = new Rng(o.seed), mid = (N - 1) / 2;+ const WING = [C[2], C[3], C[4], C[5], C[6], WHITE];+ const ps = new Particles({ rng: R, ground: () => 0, sparks: [WHITE, C[6], C[5], C[3]] });+ const lights = new Lights(), feathers = new Feathers(R, 0);+ // the shafts: spread angle, how fast each widens, how bright, its pulse offset+ const shafts = Array.from({ length: N }, (_, i) => {+ const off = i - mid, far = Math.abs(off) / mid;+ return { th: off * (0.4 / mid) + R.range(-0.02, 0.02), spread: R.range(0.05, 0.085) * (1 - far * 0.25), b: (1 - far * 0.35) * R.range(0.8, 1), ph: R.range(0, 1), far };+ });+ const motes = Array.from({ length: 72 }, () => ({ x: R.range(-80, 80), y: R.range(0, 1), v: R.range(7, 18), amp: R.range(0.5, 2.5), f: R.range(0.6, 1.5), ph: R.range(0, TAU) }));+ for (let i = 0; i < 6; i++)+ feathers.add({ x: R.range(-46, 46), y: R.range(-150, -100), vx: R.range(-8, 8), vy: R.range(0, 8), a: R.range(-0.4, 0.4), len: R.range(7, 9), wid: R.range(1.9, 2.3), life: R.range(1.4, 1.7), sink: R.range(26, 36), back: i % 3 === 0, delay: HIT + 0.1 + i * 0.16 + R.range(0, 0.08) });+ const DMAX = PY - TOP, row = new Float32Array(192), core = new Uint8Array(192);+ let t = 0, hit = false, shut = false, glinted = false;++ // each shaft's angle now: unfolding from the middle with an overshoot, folding back shut at the end+ const angle = (s, tt) => {+ const st = s.far * 0.1, open = ease.outBack(seg(tt, OPEN + st, OPEN + st + 0.42), 1.5), fold = ease.inOutCubic(seg(tt, FOLD - s.far * 0.1, SHUT));+ return s.th * open * (1 - fold);+ };+ // how far down each shaft the light reaches (it pours from the sky), and where it lifts away at the end+ const frontD = (s, tt) => DMAX * (1 - ease.inQuad(seg(tt, OPEN + s.far * 0.06, HIT + s.far * 0.06)));+ const liftD = (tt) => DMAX * ease.inQuad(seg(tt, SHUT + 0.05, LIFT));+ const fade = (tt) => smooth(OPEN, OPEN + 0.1, tt) * (1 - smooth(LIFT - 0.05, LIFT + 0.05, tt));+ const width = (s, d, tt) => (1.4 + d * s.spread) * lerp(1, 0.25, smooth(SHUT, LIFT, tt));+ // brightness along a shaft: a pulse of light runs down each one, one after another+ const pulse = (s, d, tt) => {+ if (tt < HIT || tt > SHUT) return 1;+ const D = DMAX * (1 - frac((tt - HIT) / 0.6 + s.ph));+ return 1 + 0.9 * Math.exp(-(((d - D) / 12) ** 2));+ };+ // light of all the shafts at a point (for motes)+ const lightAt = (x, y) => {+ const dy = PY - y;+ if (dy <= 0) return 0;+ let I = 0;+ for (const s of shafts) {+ const a = angle(s, t), d = dy / Math.cos(a), xc = Math.tan(a) * dy, hw = width(s, d, t) / 2 / Math.cos(a);+ if (d < liftD(t) || d < frontD(s, t)) continue;+ const v = (x - xc) / hw;+ if (Math.abs(v) < 1) I += (1 - v * v) * s.b;+ }+ return I * fade(t);+ };++ function fan(p) {+ const k = fade(t);+ if (k <= 0) return;+ const lift = liftD(t);+ for (let y = Math.ceil(TOP); y < PY; y++) {+ const dy = PY - (y + 0.5);+ row.fill(0);+ core.fill(0);+ let any = false;+ for (const s of shafts) {+ const a = angle(s, t), ca = Math.cos(a), d = dy / ca;+ if (d < lift || d < frontD(s, t) - 6) continue;+ const xc = Math.tan(a) * dy, hw = width(s, d, t) / 2 / ca, soft = smooth(frontD(s, t) - 6, frontD(s, t) + 4, d) * smooth(lift, lift + 6, d);+ const I0 = s.b * pulse(s, d, t) * soft * k;+ for (let x = Math.floor(xc - hw); x <= Math.ceil(xc + hw); x++) {+ const v = (x + 0.5 - xc) / hw, i = x + 96;+ if (i < 0 || i >= 192 || Math.abs(v) >= 1) continue;+ row[i] += I0 * Math.pow(1 - v * v, 1.3);+ any = true;+ }+ const ci = Math.round(xc - 0.5) + 96;+ if (ci >= 0 && ci < 192) core[ci] = Math.max(core[ci], Math.min(255, I0 * 200));+ }+ if (!any) continue;+ for (let i = 0; i < 192; i++) {+ const I = row[i];+ if (I < 0.02) continue;+ const x = i - 96;+ p.blend(x, y, C[6], Math.min(0.6, I * 0.38));+ p.light(x, y, C[4], Math.min(0.9, I * 0.32));+ // a fine bright line runs down the middle of each shaft+ if (core[i]) p.dot(x, y, core[i] > 150 ? WHITE : C[6], Math.min(1, core[i] / 180));+ }+ }+ // where the shafts converge, the light gathers to a point+ if (t > HIT - 0.05) p.glow(0, PY - 3, 20, C[5], 0.5 * k);}- // 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));++ // the sun: a halo that opens at the top like an iris, rays ticking round it, then closes with a glint+ function sun(p) {+ const r = 15 * ease.outBack(seg(t, 0.02, 0.45), 1.8) * (1 - ease.inBack(seg(t, SHUT, LIFT + 0.1), 1.5));+ if (r > 0.5) {+ const spin = t * 0.6;+ p.glow(0, SUN, Math.min(32, r * 3), C[4], 0.5);+ p.glow(0, SUN, r * 1.4, WHITE, 0.35);+ p.circle(0, SUN, r * 0.45, WHITE);+ oval(p, 0, SUN, r * 0.62, r * 0.62, C[6], 1);+ oval(p, 0, SUN, r, r, (g) => (Math.sin(g * 6 + spin * 4) > 0.5 ? WHITE : C[5]), 1);+ for (let j = 0; j < 16; j++) {+ const g = spin + (j * TAU) / 16, l = j % 2 ? 3 : 6;+ p.line(Math.cos(g) * (r + 2), SUN + Math.sin(g) * (r + 2), Math.cos(g) * (r + 2 + l), SUN + Math.sin(g) * (r + 2 + l), (u) => (u < 0.4 ? C[6] : C[4]), (u) => 1.1 - u);+ }+ }+ if (t > LIFT && t < LIFT + 0.3) sparkle(p, 0, SUN, 10 * (1 - (t - LIFT) / 0.3), WHITE, C[5], 0.6);}- // 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);++ // the sigil burning on the floor: two rings and a turning band of marks; white-hot, then gold, then cooling+ function sigil(p, back) {+ if (t < HIT) return;+ const u = seg(t, HIT, HIT + 0.2), heat = 1 - smooth(SHUT, SHUT + 0.8, t), out = 1 - smooth(SHUT + 0.4, SHUT + 1, t);+ if (out <= 0) return;+ const keep = back ? (g) => Math.sin(g) < 0 : (g) => Math.sin(g) >= 0;+ // it burns in round from the front, both ways+ const burnt = (g) => Math.abs(((g - Math.PI / 2 + Math.PI) % TAU + TAU) % TAU - Math.PI) <= u * Math.PI + 0.01;+ const col = (g, hot) => {+ if (!burnt(g)) return 0;+ const flick = rand(Math.round(g * 40), Math.floor(t * 20)) < 0.18;+ return t < HIT + 0.08 || (flick && heat > 0.4) ? WHITE : heat > 0.6 ? (hot ? C[6] : C[5]) : heat > 0.3 ? C[4] : heat > 0.1 ? C[3] : C[2];+ };+ oval(p, 0, 0, RX, RX * SY, (g) => col(g, true), out, (g) => keep(g) && burnt(g));+ oval(p, 0, 0, RX * 0.72, RX * 0.72 * SY, (g) => col(g, false), out, (g) => keep(g) && burnt(g));+ // marks between the rings, turning slowly+ for (let j = 0; j < 12; j++) {+ const g = t * 0.35 + (j * TAU) / 12;+ if (!keep(g) || !burnt(g)) continue;+ const c = col(g, j % 2 === 0), r0 = RX * 0.78, r1 = RX * (j % 3 === 0 ? 0.95 : 0.88);+ if (c) p.line(Math.cos(g) * r0, Math.sin(g) * r0 * SY, Math.cos(g) * r1, Math.sin(g) * r1 * SY, c, out);}- 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]);+ if (!back) {+ for (let i = -2; i <= 2; i++) p.glow(i * RX * 0.45, -2, 16, C[4], (0.34 - Math.abs(i) * 0.05) * out * (0.5 + 0.5 * heat));+ p.glow(0, -1, 10, WHITE, 0.3 * heat * out);}- 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);- });++ return {+ update(dt) {+ t += dt;+ // light gathers to the sun as it opens+ if (t < OPEN + 0.1 && R.chance(0.5)) {+ const a = R.range(0, TAU), D = R.range(22, 34), x = Math.cos(a) * D, y = SUN + Math.sin(a) * D, T = R.range(0.18, 0.28), v = ((D - 10) * 3) / (Math.exp(3 * T) - 1);+ ps.spawn(P.STREAK, x, y, (-x / D) * v, ((SUN - y) / D) * v, T, R.chance(0.5) ? C[6] : C[5]);+ }+ if (!hit && t >= HIT) {+ hit = true;+ lights.add(0, -30, 64, C[5], 0.85, 0.5);+ lights.add(0, -6, 30, WHITE, 0.8, 0.12);+ for (let i = 0; i < 26; i++) {+ const a = -Math.PI / 2 + R.range(-1.2, 1.2), sp = R.range(70, 190);+ ps.spawn(P.SPARK, R.range(-3, 3), -2, Math.cos(a) * sp, Math.sin(a) * sp, R.range(0.25, 0.6));+ }+ }+ // while it holds: embers off the burning sigil, a few feathers drifting down through the shafts+ if (t > HIT && t < SHUT + 0.1 && R.chance(0.35)) {+ const g = R.range(0, TAU), r = RX * (R.chance(0.5) ? 1 : 0.72);+ ps.spawn(P.EMBER, Math.cos(g) * r, Math.sin(g) * r * SY - 1, R.range(-6, 6), -R.range(12, 30), R.range(0.5, 0.8), C[5], 1, 0, Math.sin(g) < 0 ? 4 : 0);+ }+ if (t > HIT && t < FOLD && R.chance(0.05)) ps.spawn(P.STAR, R.range(-1, 1) * 40, -R.range(20, 160), 0, R.range(2, 8), R.range(0.3, 0.6), R.chance(0.5) ? WHITE : C[6], R.range(0.8, 1.8));+ // the fan snaps shut on the mark: a flash where the shafts become one+ if (!shut && t >= SHUT) {+ shut = true;+ lights.add(0, -60, 70, C[5], 0.7, 0.35);+ for (let i = 0; i < 12; i++) ps.spawn(P.STAR, R.range(-4, 4), -R.range(10, 170), R.range(-25, 25), R.range(-10, 10), R.range(0.4, 0.8), R.chance(0.5) ? WHITE : C[6], R.range(0.8, 2));+ }+ if (!glinted && t >= LIFT) {+ glinted = true;+ lights.add(0, SUN, 40, WHITE, 0.6, 0.2);+ }+ ps.update(dt);+ feathers.update(dt);+ lights.update(dt);+ },+ drawBack(p) {+ fan(p);+ sigil(p, true);+ feathers.draw(p, WING, "back");+ ps.draw(p, "back");+ },+ draw(p) {+ sigil(p, false);+ // dust motes drifting down, lit only where a shaft catches them+ for (const m of motes) {+ const y = TOP + ((((m.y * DMAX + t * m.v) % DMAX) + DMAX) % DMAX), x = m.x + Math.sin(t * m.f + m.ph) * m.amp, I = lightAt(x, y);+ if (I < 0.2) continue;+ p.dot(x, y, I > 0.7 ? WHITE : C[6], Math.min(1, I * 1.3));+ p.light(x, y, C[5], 0.4 * Math.min(1, I));+ }+ sun(p);+ if (t > HIT - 0.02 && t < HIT + 0.25) sparkle(p, 0, PY - 2, 12 * (1 - (t - HIT) / 0.25), WHITE, C[5], 0.7);+ if (t > SHUT && t < SHUT + 0.2) sparkle(p, 0, PY - 2, 8 * (1 - (t - SHUT) / 0.2), WHITE, C[5], 0.5);+ feathers.draw(p, WING, "front");+ ps.draw(p, "front");+ lights.draw(p);+ },+ };}diff --git a/src/fx/holy/purify.js b/src/fx/holy/purify.jsdeleted file mode 100644index 1bf2712..0000000--- a/src/fx/holy/purify.js+++ /dev/null@@ -1,89 +0,0 @@-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.jsdeleted file mode 100644index e90d931..0000000--- a/src/fx/holy/regen.js+++ /dev/null@@ -1,50 +0,0 @@-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.jsindex 7955694..dec7bd8 100644--- a/src/fx/holy/resurrection.js+++ b/src/fx/holy/resurrection.js@@ -1,113 +1,388 @@-import { PAL, burst, stream, seg, ease, bump, clamp, rng, lerp, TAU, WHITE } from "../../core/index.js";-import { fit, ovalLine, sparkle, feather } from "./_lib.js";+// The lit floor line is adapted from Sprite Fusion's open-source heal (https://www.spritefusion.com/pixel-art-vfx/heal),+// MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Lights, P, Rng, fit, sparkle, flare, band, clamp, smooth, seg, lerp, ease, TAU, WHITE, mix } from "../../core/index.js";+import { GOLD, ASH, shapeOf, recolor, toneOf, feather, Feathers, oval, FAR, NEAR } 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,+ desc: "Light pours down on the fallen and life climbs back up the body; wings of light unfold, a halo forms, one great wingbeat, then the wings scatter into feathers.",+ tags: ["holy", "revive", "resurrect", "wings", "halo", "light", "character", "one-shot"],+ size: [192, 160],+ origin: [96, 140],+ duration: 4.8,loop: false,fps: 30,bg: "ground",- actor: true,- options: { palette: PAL.holy, seed: 34 },+ actor: 2,+ options: { palette: GOLD, ash: ASH, seed: 5 },};-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) };-});+const TOP = -140;+// the story: the light pours, life climbs the body, wings and halo, the beat, the wings come apart+const POUR = 0.34, CL0 = 0.5, CL1 = 1.15, W0 = 1.1, H0 = 1.24, H1 = 1.5, B0 = 1.95, B1 = 2.25, B2 = 2.37, B3 = 2.8, SC = 2.95, GONE = 3.85;+const HX = 0, HY = -47, HRX = 9.5, HRY = 2.6;-// 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) };+// the right wing (the left mirrors it), from its shoulder: the arm folded and spread, then each feather+// [where along the arm 0..1, angle spread, length, width, kind]: 0 primary, 1 secondary, 2 covert+const SHOULDER = [4, -20];+const ARM_OPEN = [[0, 0], [7, -9], [15, -19], [20, -27]];+const ARM_FOLD = [[0, 0], [2, -2], [3, -3], [4, -3]];+const QUILLS = [+ [0.14, 1.35, 11, 2.6, 1], [0.26, 1.12, 14, 2.8, 1], [0.38, 0.88, 17, 3, 1], [0.5, 0.62, 19, 3.1, 1], [0.62, 0.35, 21, 3.2, 1], [0.72, 0.08, 23, 3.3, 1],+ [0.8, -0.2, 26, 3.4, 0], [0.85, -0.45, 29, 3.5, 0], [0.9, -0.72, 31, 3.6, 0], [0.95, -1, 30, 3.6, 0], [1, -1.3, 26, 3.4, 0],+ [0.22, 1.2, 7, 2.2, 2], [0.34, 0.98, 8, 2.3, 2], [0.46, 0.75, 9, 2.4, 2], [0.58, 0.5, 10, 2.5, 2], [0.7, 0.22, 10, 2.5, 2], [0.81, -0.1, 11, 2.6, 2], [0.92, -0.5, 11, 2.6, 2],+];+const FLEX = [1, 0.5, 0.3];++function along(pts, s) {+ let L = 0;+ const seglen = [];+ for (let i = 1; i < pts.length; i++) L += seglen[i - 1] = Math.hypot(pts[i][0] - pts[i - 1][0], pts[i][1] - pts[i - 1][1]);+ let d = s * L;+ for (let i = 0; i < seglen.length; i++) {+ if (d <= seglen[i] || i === seglen.length - 1) {+ const f = seglen[i] ? clamp(d / seglen[i]) : 0;+ return [lerp(pts[i][0], pts[i + 1][0], f), lerp(pts[i][1], pts[i + 1][1], f)];+ }+ d -= seglen[i];+ }+ return pts[pts.length - 1];}-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];+// the beat: a slow raise, a hard fast downstroke, a recovery that overshoots a touch+function beat(t) {+ if (t < B0) return 0;+ if (t < B1) return -0.34 * ease.inOutSine(seg(t, B0, B1));+ if (t < B2) return lerp(-0.34, 0.66, ease.inQuad(seg(t, B1, B2)));+ return 0.66 * (1 - ease.outBack(seg(t, B2, B3), 1.3));}-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];- });+export function create(o) {+ const C = fit(o.palette, 8), AS = fit(o.ash, 6), A = o.actor, S = shapeOf(A), R = new Rng(o.seed);+ const WING = [C[2], C[3], C[4], C[5], C[6], WHITE];+ const ps = new Particles({ rng: R, ground: () => 0, sparks: [WHITE, C[6], C[5], C[3]], haze: C[4] });+ const lights = new Lights(), loose = new Feathers(R, 0);+ const rows = new Map();+ for (const [x, y] of S.edge) (rows.get(y) ?? rows.set(y, []).get(y)).push(x);+ // the shaft of light: a few rays of their own width and shimmer+ const rays = Array.from({ length: 6 }, (_, i) => ({ o: -0.75 + i * 0.3 + R.range(-0.08, 0.08), w: R.range(0.1, 0.2), b: R.range(0.55, 1), f: R.range(1.5, 3.5), ph: R.range(0, TAU) }));+ const cores = [...rays].sort((a, b) => b.b - a.b).slice(0, 2);+ const motes = Array.from({ length: 34 }, () => ({ q: R.range(-1, 1), y: R.range(0, 1), v: R.range(4, 11), amp: R.range(0.6, 2.4), ph: R.range(0, TAU), f: R.range(0.6, 1.4) }));+ // each feather opens on its own beat, outer ones last, and comes off at its own time, tips first+ const reach = QUILLS.map(([s, ang, len]) => { const b = along(ARM_OPEN, s); return Math.hypot(b[0] + Math.cos(ang) * len, b[1] + Math.sin(ang) * len); }), far = Math.max(...reach);+ const quills = QUILLS.map(([s, ang, len, wid, kind], i) => {+ const off = () => SC + (1 - reach[i] / far) * 0.2 + R.range(0, 0.04);+ return { s, ang, len, wid, kind, fold: 1.45 + (i % 6) * 0.04, open: kind === 0 ? 0.06 + (s - 0.8) * 0.45 : kind === 1 ? s * 0.06 : 0.03 + s * 0.05, off: [off(), off()], gone: [false, false] };+ });+ const profile = new Float32Array(121);+ let t = 0, poured = false, flashed = false, formed = false, beaten = false;++ const climbY = (tt) => lerp(1, S.top - 2, ease.inOutSine(seg(tt, CL0, CL1)));+ const shaftK = (tt) => smooth(0, 0.12, tt) * (1 - smooth(3.0, 3.75, tt));+ const shaftW = (tt) => lerp(0.4, 1, ease.outCubic(seg(tt, 0, 0.6))) * lerp(1, 0.12, ease.inCubic(seg(tt, 2.9, 3.6)));+ const halfW = (y, tt) => lerp(8, 25, (y - TOP) / -TOP) * shaftW(tt);++ // the pose of every feather of one wing at time tt: quill base (x, y), angle, length, width, alpha, hot+ function wing(tt, side) {+ const oa = ease.outBack(seg(tt, W0, W0 + 0.4), 1.6), rot = beat(tt), om = (beat(tt) - beat(tt - 0.03)) / 0.03;+ const arm = ARM_FOLD.map((f, i) => [lerp(f[0], ARM_OPEN[i][0], oa), lerp(f[1], ARM_OPEN[i][1], oa)]);+ const cr = Math.cos(rot), sr = Math.sin(rot), place = ([x, y]) => [side * (SHOULDER[0] + x * cr - y * sr), SHOULDER[1] + x * sr + y * cr];+ const a0 = smooth(W0, W0 + 0.1, tt), out = [];+ quills.forEach((q, i) => {+ if (tt >= q.off[side > 0 ? 0 : 1] + 0.05) return;+ const of = ease.outBack(seg(tt, W0 + q.open, W0 + q.open + 0.42), 2), [bx, by] = place(along(arm, q.s));+ const ang = lerp(q.fold, q.ang, of) + rot - clamp(om * 0.045 * FLEX[q.kind], -0.5, 0.5);+ out.push({ i, q, x: bx, y: by, ang: side > 0 ? ang : Math.PI - ang, len: q.len * lerp(0.3, 1, of), wid: q.wid, a: a0, hot: tt < W0 + q.open + 0.07 || tt >= q.off[side > 0 ? 0 : 1] ? 1 : 0 });});- // 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]);+ return { out, arm: arm.map(place) };}- 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);-}+ function drawWing(p, side) {+ const { out, arm } = wing(t, side);+ if (!out.length) return;+ const order = [...out].sort((a, b) => b.q.ang - a.q.ang);+ // the lowest feathers first, so each one above lays its warm trailing edge over the next; coverts on top+ for (const f of order) if (f.q.kind !== 2) feather(p, f.x, f.y, f.ang, f.len, f.wid, WING, f.a, side, f.hot);+ for (const f of order) if (f.q.kind === 2) feather(p, f.x, f.y, f.ang, f.len, f.wid, WING, f.a, side, f.hot);+ // the leading edge: a white bone of light with a gold underside+ const k = out.length / quills.length;+ if (k > 0.5) {+ p.polyline(arm.map(([x, y]) => [x, y + 1]), C[5], out[0].a);+ p.polyline(arm, WHITE, out[0].a);+ }+ p.glow(side * 28, -36, 38, C[4], 0.26 * out[0].a * k);+ const g = ((t - W0 - 0.45) * 1.3) % 1;+ if (k > 0.9 && t > W0 + 0.45 && g < 0.8) {+ const [gx, gy] = along(arm, g / 0.8);+ sparkle(p, gx, gy, 2 + Math.sin((g / 0.8) * Math.PI) * 2, WHITE, C[6], 0.4);+ }+ p.glowLine(arm[0][0], arm[0][1], arm[3][0], arm[3][1], 7, C[5], 0.25 * out[0].a * k);+ // the tips of the primaries leave trails of light as they come down+ if (t > B1 + 0.03 && t < B2 + 0.14)+ for (const i of [6, 8, 10]) {+ const pts = [];+ for (let j = 0; j < 10; j++) {+ const tt = Math.max(B1 + 0.01, t - j * 0.012), w = wing(tt, side).out.find((f) => f.i === i);+ if (w) pts.push([w.x + Math.cos(w.ang) * (w.len - 1), w.y + Math.sin(w.ang) * (w.len - 1)]);+ }+ const fade = 1 - smooth(B2, B2 + 0.14, t);+ for (let j = 1; j < pts.length; j++) p.line(pts[j - 1][0], pts[j - 1][1], pts[j][0], pts[j][1], j < 3 ? WHITE : j < 6 ? C[6] : C[4], fade * (1.1 - j / 10));+ }+ }-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);+ function shaft(p) {+ const k = shaftK(t);+ if (k <= 0) return;+ for (let i = 0; i < profile.length; i++) {+ const q = (i - 60) / 40;+ let I = 0;+ for (const r of rays) {+ const d = (q - r.o) / r.w;+ I += r.b * Math.exp(-d * d) * (0.72 + 0.28 * Math.sin(t * r.f + r.ph));+ }+ profile[i] = (I * 0.6 + 0.35 * Math.max(0, 1 - q * q)) * smooth(1.25, 0.7, Math.abs(q));+ }+ const front = lerp(TOP, 1, ease.inQuad(seg(t, 0, POUR))), w0 = halfW(0, t) * 1.3;+ p.each(-w0 - 1, TOP, w0 + 1, Math.min(front, 0.5), (x, y, sx, sy) => {+ const w = halfW(y, t), q = x / w;+ if (q < -1.5 || q > 1.5) return;+ const I = profile[Math.round(q * 40) + 60] * k * (0.75 + 0.25 * smooth(TOP, 0, y)) * smooth(front, front - 10, y);+ if (I <= 0.01) return;+ p.blendPx(sx, sy, C[6], I * 0.24);+ p.add(sx, sy, C[4], I * 0.3);+ });+ // the brightest rays show as fine lines, light running down them+ for (const r of cores) {+ const sh = 0.75 + 0.25 * Math.sin(t * r.f + r.ph);+ for (let y = TOP; y < Math.min(front, 0); y++) {+ const pulse = 0.5 + 0.5 * Math.sin(y * 0.13 - t * 11 + r.ph);+ p.dot(r.o * halfW(y, t), y, pulse > 0.8 ? WHITE : C[6], k * sh * (0.15 + 0.55 * pulse) * smooth(front, front - 10, y));+ }+ }+ // the head of the pour+ if (t < POUR + 0.05 && front > TOP + 14) {+ const fy = Math.min(front, 0);+ p.glow(0, fy, 14, C[5], 0.7 * k);+ for (let dy = -6; dy <= 0; dy++) p.dot(0, fy + dy, dy > -3 ? WHITE : C[6], 1 + dy / 7);+ }+ // dust motes lit where they cross a ray+ for (const m of motes) {+ const y = TOP + ((((m.y * -TOP + t * m.v) % -TOP) + -TOP) % -TOP);+ if (y > front) continue;+ const w = halfW(y, t), x = m.q * w + Math.sin(t * m.f + m.ph) * m.amp, I = profile[Math.round((x / w) * 40) + 60] * k;+ if (I < 0.25) continue;+ p.dot(x, y, I > 0.75 ? WHITE : I > 0.5 ? C[6] : C[5], Math.min(1, I * 1.4));+ p.light(x, y, C[5], I * 0.5);+ }}- // 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));++ function pool(p, back) {+ const k = shaftK(t) * smooth(POUR - 0.05, POUR + 0.1, t), w = halfW(0, t) * 1.25;+ if (k <= 0) return;+ if (back) {+ p.glow(0, -2, w * 1.6, C[4], 0.3 * k);+ return;+ }+ // the floor catches the light: a bright line, and a pool fading into the stone in front+ for (let y = 0; y <= 3; y++)+ for (let x = Math.floor(-w); x <= w; x++) {+ const u = Math.hypot(x / w, y / 4);+ if (u >= 1) continue;+ const a = k * (y === 0 ? Math.sqrt(1 - u) * 1.2 : (1 - u) * 0.9);+ p.dot(x, y, u < 0.3 ? (y ? C[5] : WHITE) : u < 0.6 ? C[5] : u < 0.85 ? C[4] : C[3], a);+ }}- 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)));++ function halo(p) {+ const form = ease.outCubic(seg(t, H0, H1)), k = 1 - smooth(3.35, 3.9, t);+ if (form <= 0 || k <= 0) return;+ const white = t >= H1 && t < H1 + 0.06, gl = (t - H1) * 4.2 + Math.PI / 2, n = 96;+ for (let j = 0; j < n; j++) {+ const g = (j / n) * TAU, fromFront = Math.abs(((g - Math.PI / 2 + Math.PI) % TAU + TAU) % TAU - Math.PI);+ if (fromFront > form * Math.PI + 0.02) continue;+ const x = HX + Math.cos(g) * HRX * (0.9 + 0.1 * form), y = HY + Math.sin(g) * HRY, near = Math.sin(g) >= 0;+ const dg = Math.abs(((g - gl + Math.PI) % TAU + TAU) % TAU - Math.PI), hot = white || dg < 0.22 || fromFront > form * Math.PI - 0.3;+ if (near) {+ p.dot(x, y, hot ? WHITE : C[6], k);+ p.dot(x, y + 1, hot ? C[6] : C[4], k);+ } else p.dot(x, y, hot ? C[6] : C[5], k * 0.9);+ }+ p.glow(HX, HY, 20, C[4], 0.4 * k * form);+ p.glow(HX, HY + 1, 9, WHITE, 0.2 * k * form);+ const gx = HX + Math.cos(gl) * HRX, gy = HY + Math.sin(gl) * HRY;+ if (t > H1 && Math.sin(gl) > 0.2) sparkle(p, gx, gy + 0.5, 2 + 2 * Math.sin(gl), C[6], C[4], 0.35 * k);+ if (t >= H1 && t < H1 + 0.3) sparkle(p, HX, HY + HRY + 0.5, 7 * (1 - (t - H1) / 0.3), WHITE, C[5], 0.6);+ }++ function body(p) {+ if (t >= CL1 + 0.6) return;+ const Ly = climbY(t);+ if (t < CL1) {+ recolor(p, A, (c, x, y) => {+ const d = y - Ly;+ if (d < -0.5) return toneOf(AS, c);+ if (d < 0.5) return WHITE;+ if (d < 1.5) return C[6];+ const k = Math.exp(-(d - 1.5) / 4) * 0.7;+ return k > 0.08 ? mix(c, C[5], k) : 0;+ });+ // the outline catches the light where the glow has been+ for (const [x, y] of S.out) {+ const d = y - Ly;+ if (d < -0.5 || d > 12) continue;+ p.dot(x, y, d < 1 ? WHITE : d < 5 ? C[5] : C[4], d < 1 ? 1 : 1.1 - d / 12);+ }+ if (t > CL0) {+ p.glow(0, Ly, 26, C[4], 0.5);+ p.glow(0, Ly, 8, WHITE, 0.3);+ p.glow(0, -18, 36, C[5], 0.16 * seg(t, CL0, CL1));+ }+ return;+ }+ // the hero frame: the body flashes white, then cools through gold back to itself+ const u = t - CL1;+ recolor(p, A, (c) => (u < 0.06 ? WHITE : u < 0.45 ? mix(c, C[5], 0.55 * Math.pow(1 - u / 0.45, 2)) : 0));+ if (u < 0.25) for (const [x, y] of S.out) p.dot(x, y, u < 0.08 ? WHITE : C[5], 1 - u / 0.25);+ }++ return {+ update(dt) {+ t += dt;+ // light streaks pour down the shaft, faster as they fall+ if (t > 0.05 && t < 2.9 && R.chance(0.16)) {+ const q = R.range(-0.9, 0.9), y = TOP + R.range(8, 24), v0 = R.range(50, 90), life = Math.log(1 + (3 * (-y - 2)) / v0) / 3;+ ps.spawn(P.STREAK, q * halfW(y, t), y, q * 2, v0, life, R.chance(0.5) ? C[6] : C[5]);+ }+ if (t > 0.3 && t < 2.8 && R.chance(0.05)) ps.spawn(P.STAR, R.range(-1, 1) * halfW(-30, t), -R.range(4, 90), R.range(-3, 3), R.range(-4, 6), R.range(0.4, 0.8), R.chance(0.5) ? C[6] : WHITE, R.range(0.6, 1.8));+ if (!poured && t >= POUR) {+ poured = true;+ lights.add(0, -12, 42, C[5], 0.9, 0.4);+ lights.add(0, -6, 16, WHITE, 0.6, 0.1);+ for (let i = 0; i < 14; i++) ps.spawn(P.STAR, R.range(-18, 18), -R.range(0, 6), R.range(-20, 20), -R.range(10, 50), R.range(0.5, 1.1), R.chance(0.5) ? WHITE : C[6], R.range(0.6, 2.2));+ for (let i = 0; i < 10; i++) {+ const a = -Math.PI / 2 + R.range(-1.2, 1.2), sp = R.range(60, 150);+ ps.spawn(P.SPARK, R.range(-3, 3), -1, Math.cos(a) * sp, Math.sin(a) * sp, R.range(0.25, 0.5));+ }+ }+ // life climbs the body: bits of light peel off the rim at the front+ if (t > CL0 && t < CL1) {+ const Ly = Math.round(climbY(t));+ for (const y of [Ly, Ly + 1]) {+ const xs = rows.get(y);+ if (!xs || !R.chance(0.35)) continue;+ const x = R.pick(xs), s = Math.sign(x + 0.5);+ ps.spawn(R.chance(0.6) ? P.MOTE : P.STAR, x + s, y, s * R.range(8, 30), -R.range(15, 45), R.range(0.35, 0.7), R.chance(0.5) ? C[6] : C[5], R.range(0.5, 1.1));+ }+ }+ if (!flashed && t >= CL1) {+ flashed = true;+ lights.add(0, -24, 64, C[5], 0.7, 0.5);+ lights.add(0, -30, 28, WHITE, 0.7, 0.1);+ for (let i = 0; i < 18; i++) {+ const a = R.range(0, TAU), sp = R.range(30, 110);+ ps.spawn(P.STAR, Math.cos(a) * 6, -24 + Math.sin(a) * 12, Math.cos(a) * sp, Math.sin(a) * sp * 0.7 - 20, R.range(0.4, 0.9), R.chance(0.5) ? WHITE : C[6], R.range(0.6, 2));+ }+ }+ // motes spiral in to make the halo+ if (t > H0 - 0.2 && t < H0 + 0.1 && R.chance(0.6)) {+ const g = R.range(0, TAU), D = R.range(14, 24), x = HX + Math.cos(g) * D, y = HY + Math.sin(g) * D * 0.5, tx = HX + Math.cos(g + 0.6) * HRX, ty = HY + Math.sin(g + 0.6) * HRY;+ const T = R.range(0.16, 0.24), l = Math.hypot(tx - x, ty - y) || 1, v = (l * 3) / (Math.exp(3 * T) - 1);+ ps.spawn(P.STREAK, x, y, ((tx - x) / l) * v, ((ty - y) / l) * v, T, R.chance(0.5) ? C[6] : C[5]);+ }+ if (!formed && t >= H1) {+ formed = true;+ lights.add(HX, HY, 30, C[6], 0.8, 0.3);+ }+ // the wings burst open with a scatter of light+ if (t > W0 && t < W0 + 0.35 && R.chance(0.5))+ for (const side of [-1, 1]) {+ const f = R.pick(wing(t, side).out);+ if (f) ps.spawn(P.STAR, f.x + Math.cos(f.ang) * f.len, f.y + Math.sin(f.ang) * f.len, side * R.range(5, 25), -R.range(5, 25), R.range(0.3, 0.6), R.chance(0.5) ? WHITE : C[6], R.range(0.6, 1.6));+ }+ // while the wings hold, light twinkles on the tips and motes lift off them+ if (t > W0 + 0.45 && t < SC)+ for (const side of [-1, 1]) {+ if (R.chance(0.045)) {+ const f = R.pick(wing(t, side).out.filter((w) => w.q.kind === 0));+ if (f) ps.spawn(P.STAR, f.x + Math.cos(f.ang) * (f.len - 2), f.y + Math.sin(f.ang) * (f.len - 2), 0, -R.range(2, 8), R.range(0.3, 0.6), R.chance(0.5) ? WHITE : C[6], R.range(1, 2.4));+ }+ if (R.chance(0.03)) {+ const f = R.pick(wing(t, side).out);+ if (f) ps.spawn(P.EMBER, f.x + Math.cos(f.ang) * f.len * 0.7, f.y + Math.sin(f.ang) * f.len * 0.7, R.range(-8, 8), -R.range(8, 25), R.range(0.6, 1.1), C[5]);+ }+ }+ // the downstroke: a gust along the floor, light flung off the tips, a few feathers shaken loose+ if (!beaten && t >= B2 - 0.03) {+ beaten = true;+ for (const side of [-1, 1]) {+ lights.add(side * 30, -34, 46, C[5], 0.6, 0.4);+ // the gust skims out along the floor as streaks of lit dust+ for (let i = 0; i < 7; i++) ps.spawn(P.MOTE, side * R.range(8, 22), -R.range(1, 4), side * R.range(90, 160), -R.range(0, 8), R.range(0.25, 0.45), R.chance(0.5) ? C[6] : C[5], R.range(0.6, 1));+ for (const f of wing(t, side).out)+ if (f.q.kind === 0) {+ const tx = f.x + Math.cos(f.ang) * f.len, ty = f.y + Math.sin(f.ang) * f.len;+ ps.spawn(P.SPARK, tx, ty, side * R.range(30, 90), R.range(60, 160), R.range(0.3, 0.6));+ }+ for (let i = 0; i < 3; i++) {+ const f = R.pick(wing(t, side).out.filter((w) => w.q.kind === 1));+ if (f) loose.add({ x: f.x + Math.cos(f.ang) * f.len * 0.6, y: f.y + Math.sin(f.ang) * f.len * 0.6, vx: side * R.range(20, 70), vy: R.range(10, 50), a: f.ang, len: R.range(9, 12), wid: R.range(2.2, 2.8), life: R.range(1.2, 1.6), side });+ }+ }+ }+ // the wings come apart, tips first: each feather flashes and breaks into small ones and motes+ for (const side of [-1, 1]) {+ const si = side > 0 ? 0 : 1;+ for (const q of quills) {+ if (q.gone[si] || t < q.off[si]) continue;+ q.gone[si] = true;+ const f = wing(q.off[si] - 0.001, side).out.find((w) => w.q === q);+ if (!f) continue;+ const ca = Math.cos(f.ang), sa = Math.sin(f.ang), n = q.kind === 2 ? 0 : 1;+ for (let j = 0; j < n; j++) {+ const u = 0.55, x = f.x + ca * f.len * u, y = f.y + sa * f.len * u, ox = x - side * 4, oy = y + 20, l = Math.hypot(ox, oy) || 1, sp = R.range(60, 150);+ loose.add({ x, y, vx: (ox / l) * sp + R.range(-15, 15), vy: (oy / l) * sp * 0.5 - R.range(20, 50), a: f.ang + R.range(-0.4, 0.4), len: R.range(9, 12), wid: R.range(2.2, 2.8), life: R.range(1, 1.45), side, back: R.chance(0.35) });+ }+ for (let j = 0; j < 2; j++) ps.spawn(P.EMBER, f.x + ca * f.len * R.range(0.3, 1), f.y + sa * f.len * R.range(0.3, 1), R.range(-15, 15), -R.range(10, 40), R.range(0.6, 1.1), C[5]);+ if (R.chance(0.6)) ps.spawn(P.STAR, f.x + ca * f.len, f.y + sa * f.len, 0, -R.range(5, 15), R.range(0.3, 0.6), WHITE, R.range(1, 2));+ }+ }+ // the halo melts into rising motes+ if (t > 3.35 && t < 3.75 && R.chance(0.4)) {+ const g = R.range(0, TAU);+ ps.spawn(P.EMBER, HX + Math.cos(g) * HRX, HY + Math.sin(g) * HRY, R.range(-6, 6), -R.range(10, 25), R.range(0.5, 0.9), C[5]);+ }+ ps.update(dt);+ lights.update(dt);+ loose.update(dt);+ },+ drawBack(p) {+ shaft(p);+ pool(p, true);+ if (t > POUR && t < POUR + 0.4) band(p, 0, 0, 4 + 32 * ease.outCubic(seg(t, POUR, POUR + 0.4)), 0.18, 2.5 * (1 - seg(t, POUR, POUR + 0.4)) + 0.5, 1.1 - seg(t, POUR, POUR + 0.4), C.slice(3), FAR, t < POUR + 0.06);+ for (const side of [-1, 1]) drawWing(p, side);+ loose.draw(p, WING, "back");+ ps.draw(p, "back");+ },+ draw(p) {+ pool(p, false);+ if (t > POUR && t < POUR + 0.4) band(p, 0, 0, 4 + 32 * ease.outCubic(seg(t, POUR, POUR + 0.4)), 0.18, 2.5 * (1 - seg(t, POUR, POUR + 0.4)) + 0.5, 1.1 - seg(t, POUR, POUR + 0.4), C.slice(3), NEAR, t < POUR + 0.06);+ body(p);+ // the downstroke sends a ripple of light out along the floor+ if (t > B2 - 0.03 && t < B2 + 0.45) {+ const u = seg(t, B2 - 0.03, B2 + 0.45), fx = 10 + 70 * ease.outCubic(u);+ for (const s of [-1, 1]) for (let d = 0; d < 12; d++) p.dot(s * (fx - d), 0, d < 2 ? WHITE : d < 5 ? C[6] : C[4], (1 - u) * (1 - d / 12) * 1.3);+ }+ // the wings light the character from behind+ const wk = smooth(W0, W0 + 0.2, t) * (1 - smooth(SC, SC + 0.3, t));+ if (wk > 0) {+ for (const [x, y] of S.out) if (y < -8) p.light(x, y, C[5], 0.55 * wk);+ p.glow(0, -34, 76, C[4], 0.14 * wk);+ }+ halo(p);+ if (t >= CL1 && t < CL1 + 0.22) flare(p, 0, S.top - 1, 22 * (1 - (t - CL1) / 0.22), 1 - (t - CL1) / 0.22, C.slice(3));+ loose.draw(p, WING, "front");+ ps.draw(p, "front");+ lights.draw(p);+ },+ };}diff --git a/src/fx/holy/smite.js b/src/fx/holy/smite.jsindex bf59327..bbfe382 100644--- a/src/fx/holy/smite.js+++ b/src/fx/holy/smite.js@@ -1,82 +1,179 @@-import { PAL, RAMP, burst, fly, seg, ease, rng, bolt, TAU, WHITE } from "../../core/index.js";-import { fit, ovalLine, sparkle } from "./_lib.js";+import { Particles, Bits, Lights, P, PF, B, Rng, fit, sparkle, band, bolt, clamp, smooth, seg, lerp, ease, TAU, WHITE, hex, mix, scale } from "../../core/index.js";+import { GOLD, oval } 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.",+ desc: "A glint marks the spot, then a bolt of light drops like a hammer: a white flash, a shockwave over the floor, stone chips flying and cracks that glow and cool.",tags: ["holy", "smite", "strike", "impact", "light", "ground", "one-shot"],- size: [92, 108],- origin: [46, 94],- duration: 0.85,+ size: [224, 176],+ origin: [112, 148],+ duration: 2.8,loop: false,fps: 30,bg: "ground",- options: { palette: PAL.holy, seed: 36 },+ options: { palette: GOLD, stone: "#5a5066", seed: 9 },};-const T_FALL = 0.12, T_HIT = 0.19;+const TOP = -148, SY = 0.38, MARK = 0.42, HIT = 0.54, LEN = 44;+const OUTLINE = hex("#1a1422");-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]);+// a chip of stone: lit side, shaded side, outline+function chip(p, b, st) {+ const r = 0.6 + b.s * 0.7, fade = Math.min(1, b.life / 0.5), lx = Math.cos(b.a) * r * 0.4, ly = Math.sin(b.a) * r * 0.4;+ p.shade(b.x - r - 1, b.y - r - 1, b.x + r + 1, b.y + r + 1, (x, y, out) => {+ const dx = x - b.x, dy = y - b.y, d = Math.hypot(dx * 1.2, dy);+ if (d > r + 0.9) return;+ const lit = dx * lx + dy * ly;+ out.c = d > r ? OUTLINE : lit < -0.3 ? st[3] : lit > 0.5 ? st[1] : st[2];+ out.a = fade;});- 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));+}++export function create(o) {+ const C = fit(o.palette, 8), R = new Rng(o.seed), s0 = hex(o.stone);+ const st = [scale(s0, 0.5), scale(s0, 0.75), s0, mix(scale(s0, 1.4), WHITE, 0.1)], dust = mix(s0, hex("#8a8094"), 0.4);+ const ps = new Particles({ rng: R, ground: () => 0, sparks: [WHITE, C[6], C[5], C[3]] });+ const chips = new Bits({ ground: () => 0 }), lights = new Lights();+ // cracks across the floor, mostly out to the sides and towards us, each its own length+ const cracks = Array.from({ length: 7 }, (_, i) => {+ const a = 0.12 + (i / 6) * (Math.PI - 0.24) + R.range(-0.12, 0.12), L = R.range(30, 54) * (Math.abs(Math.sin(a)) > 0.7 ? 0.6 : 1);+ const pts = bolt(R, 0, 0, Math.cos(a) * L, Math.sin(a) * L, { jag: 0.28, depth: 4 }).map(([x, z]) => [x, z * SY]);+ const fork = pts.length > 6 ? bolt(R, ...pts[Math.floor(pts.length * 0.5)], pts[Math.floor(pts.length * 0.5)][0] + Math.cos(a + R.sign() * 0.7) * L * 0.35, pts[Math.floor(pts.length * 0.5)][1] + Math.sin(a + R.sign() * 0.7) * L * 0.35 * SY, { jag: 0.3, depth: 3 }) : null;+ return { pts, fork, L, cool: R.range(1.6, 2.1) };});- p.glow(0, -4, 30, C[4], 0.45 * Math.pow(1 - seg(a, 0, 0.5), 2));+ let t = 0, hit = false;++ // the hammer of light: a heavy blunt bolt that falls faster and faster+ const tipY = (tt) => lerp(TOP - 6, 0, ease.inCubic(seg(tt, MARK, HIT)));++ function hammer(p) {+ if (t < MARK || t >= HIT + 0.06) return;+ const y1 = t >= HIT ? 0 : tipY(t), y0 = Math.max(TOP + 5, y1 - LEN * (t >= HIT ? 1 - (t - HIT) / 0.06 : 1)), white = t >= HIT;+ if (y1 < TOP + 12) return;+ // speed lines above it+ for (const [dx, k] of [[-5, 0.6], [-2, 0.9], [2, 0.8], [5, 0.5]]) if (y0 > TOP + 2) p.line(dx, Math.max(TOP, y0 - 70), dx, y0, (u) => (u > 0.7 ? C[6] : C[4]), (u) => u * k);+ if (y1 - 3 > y0) p.beam(0, y0, 0, y1 - 3, 9, (u, v) => (white || v < 0.35 ? WHITE : v < 0.7 ? C[6] : C[5]));+ // the head: wider, white hot+ p.beam(0, y1 - 6, 0, y1 - 1, 13, (u, v) => (v < 0.6 || white ? WHITE : C[6]));+ p.glowLine(0, y0 + 10, 0, y1, 16, C[5], 0.6);+ p.glow(0, y1 - 4, Math.min(22, y1 - TOP - 6), WHITE, 0.5);+ }++ function crack(p) {+ if (t < HIT) return;+ const grow = ease.outCubic(seg(t, HIT, HIT + 0.1));+ for (const c of cracks) {+ for (const path of c.fork ? [c.pts, c.fork] : [c.pts]) {+ const n = Math.max(1, Math.round((path.length - 1) * grow));+ for (let i = 0; i < n; i++) {+ const [x0, y0] = path[i], [x1, y1] = path[i + 1], d = Math.hypot(x0, y0 / SY) / c.L, heat = clamp(1 - (t - HIT) / c.cool - d * 0.5);+ if (heat <= 0) continue;+ const col = heat > 0.85 ? WHITE : heat > 0.65 ? C[6] : heat > 0.45 ? C[5] : heat > 0.3 ? C[4] : heat > 0.18 ? C[3] : C[2];+ p.line(x0, y0, x1, y1, col, heat < 0.12 ? heat / 0.12 : 1);+ // wide and deep near the heart, a hairline at the tips+ if (d < 0.45 && path === c.pts) p.line(x0, y0 + 1, x1, y1 + 1, heat > 0.5 ? C[4] : C[2], heat < 0.12 ? heat / 0.12 : 1);+ if (i % 2 === 0) p.glow(x0, y0, 10, C[4], 0.45 * heat);+ }+ }+ }+ // the crater glows at the heart and cools+ const h = clamp(1 - (t - HIT) / 1.6);+ if (h > 0) {+ oval(p, 0, 0, 5, 1.6, h > 0.6 ? WHITE : h > 0.3 ? C[5] : C[3], Math.min(1, h * 3));+ p.glow(0, 0, 18, C[4], 0.45 * h);+ }+ }++ return {+ update(dt) {+ t += dt;+ if (t < MARK && R.chance(0.25)) ps.spawn(P.STAR, R.range(-10, 10), -R.range(0, 18), 0, -R.range(4, 12), R.range(0.2, 0.4), R.chance(0.5) ? WHITE : C[6], R.range(0.5, 1.2));+ // sparks shed off the sides of the falling hammer+ if (t > MARK && t < HIT && tipY(t) > TOP + 50 && R.chance(0.6)) ps.spawn(P.MOTE, R.sign() * R.range(4, 7), tipY(t) - R.range(4, 30), R.range(-20, 20), -R.range(10, 40), R.range(0.15, 0.3), C[6], 0.7);+ if (!hit && t >= HIT) {+ hit = true;+ lights.add(0, -24, 92, C[5], 1, 0.6);+ lights.add(0, -8, 40, WHITE, 0.9, 0.12);+ for (let i = 0; i < 60; i++) {+ const a = -Math.PI / 2 + R.range(-1.25, 1.25), sp = R.range(110, 280);+ ps.spawn(P.SPARK, R.range(-3, 3), -2, Math.cos(a) * sp, Math.sin(a) * sp, R.range(0.25, 0.75));+ }+ for (let i = 0; i < 16; i++) {+ const a = -Math.PI / 2 + R.range(-1, 1), sp = R.range(60, 160);+ ps.spawn(P.STAR, R.range(-4, 4), -4, Math.cos(a) * sp, Math.sin(a) * sp, R.range(0.4, 0.9), R.chance(0.5) ? WHITE : C[6], R.range(0.8, 2.4));+ }+ for (let i = 0; i < 14; i++) {+ const a = -Math.PI / 2 + R.range(-1.2, 1.2), sp = R.range(90, 230);+ chips.add({ kind: B.CHUNK, x: R.range(-5, 5), y: -2, vx: Math.cos(a) * sp, vy: Math.sin(a) * sp, g: 1, drag: 0.4, bounce: 0.35, life: R.range(1.2, 1.8), a: R.range(0, TAU), va: R.range(-14, 14), s: R.int(1, 3) });+ }+ for (let i = 0; i < 34; i++) {+ const a = -Math.PI / 2 + R.range(-1, 1), sp = R.range(60, 220);+ ps.spawn(P.GRIT, R.range(-4, 4), -1, Math.cos(a) * sp, Math.sin(a) * sp, R.range(0.9, 1.5), R.pick(st.slice(1)), R.chance(0.4) ? 2 : 1);+ }+ // dust rolls out along the floor, a little smoke lifts off the crater+ for (let i = 0; i < 9; i++) {+ const s = R.sign();+ ps.spawn(P.SMOKE, s * R.range(2, 10), -R.range(1, 4), s * R.range(50, 130), -R.range(2, 12), R.range(0.7, 1.2), mix(dust, C[4], 0.18), R.range(3.5, 6), R.range(0, 0.06), PF.BIG);+ }+ for (let i = 0; i < 4; i++) ps.spawn(P.SMOKE, R.range(-4, 4), -R.range(2, 8), R.range(-8, 8), -R.range(20, 45), R.range(1.2, 1.8), mix(dust, C[5], 0.25), R.range(4, 6), R.range(0.05, 0.3));+ }+ // the cracks spit embers while they're hot+ if (t > HIT && t < HIT + 1.3 && R.chance(0.5)) {+ const c = R.pick(cracks), q = R.pick(c.pts);+ if (R.chance(0.75)) ps.spawn(P.EMBER, q[0], q[1] - 1, R.range(-8, 8), -R.range(15, 35), R.range(0.5, 0.9), C[5]);+ else ps.spawn(P.STAR, q[0], q[1] - 2, 0, -R.range(4, 12), R.range(0.3, 0.6), R.chance(0.5) ? WHITE : C[6], R.range(0.8, 1.8));+ }+ chips.update(dt);+ ps.update(dt);+ lights.update(dt);+ },+ drawBack(p) {+ crack(p);+ ps.draw(p, "back");+ const k = seg(t, HIT, HIT + 0.42);+ if (t >= HIT && k < 1) band(p, 0, 0, 6 + 84 * ease.outCubic(k), SY * 0.8, Math.max(1, 5 * (1 - k)), 1.15 - k, C.slice(3), (g) => Math.sin(g) < 0, k < 0.12);+ },+ draw(p) {+ // the mark: a glint on the floor and a ring closing on it+ if (t < HIT) {+ const u = seg(t, 0, MARK), k = smooth(0, 0.08, t), spin = t * 3, rr = lerp(26, 8, ease.inOutCubic(u));+ oval(p, 0, 0, rr, rr * SY, (g) => (Math.sin(g * 4 + spin) > 0 ? WHITE : C[5]), k * (0.65 + 0.35 * Math.sin(t * 40)));+ oval(p, 0, 1, rr, rr * SY, C[3], k * 0.6, (g) => Math.sin(g) > 0);+ const L = (3 + 8 * ease.outBack(clamp(t / 0.2), 2)) * (t > MARK ? 1 + 0.6 * seg(t, MARK, HIT) : 1);+ for (let i = 0; i < 4; i++) {+ const a = spin * 0.3 + (i * Math.PI) / 2, len = i % 2 ? L * 0.6 : L;+ p.line(0, -2, Math.cos(a) * len, -2 + Math.sin(a) * len, (v) => (v < 0.4 ? WHITE : C[5]), (v) => 1.2 - v);+ }+ p.px(0, -2, WHITE);+ p.glow(0, -2, 14 + 10 * u, C[5], 0.5 * k);+ p.glowLine(0, TOP + 6, 0, -2, 5, C[4], 0.12 * u);+ }+ hammer(p);+ // the bolt's afterimage: a thread of light from the sky to the mark, thinning out+ const ai = seg(t, HIT + 0.04, HIT + 0.55);+ if (t > HIT + 0.04 && ai < 1) {+ const w = 1 + 4 * Math.pow(1 - ai, 2);+ p.beam(0, TOP + 4, 0, -4, w, (u, v) => (v < 0.5 ? WHITE : C[5]), (u) => (0.3 + 0.7 * u) * (1 - ai * 0.5));+ p.glowLine(0, TOP + 16, 0, -6, 10, C[5], 0.4 * (1 - ai));+ }+ const k = seg(t, HIT, HIT + 0.42);+ if (t >= HIT && k < 1) band(p, 0, 0, 6 + 84 * ease.outCubic(k), SY * 0.8, Math.max(1, 5 * (1 - k)), 1.15 - k, C.slice(3), (g) => Math.sin(g) >= 0, k < 0.12);+ // the air shock: a dome of light thrown up over the hit+ const d = seg(t, HIT, HIT + 0.28);+ if (t >= HIT && d < 1) {+ const r = 8 + 40 * ease.outCubic(d);+ p.arc(0, 0, r, Math.max(1, 3 * (1 - d)), Math.PI, TAU, (u, v) => (d < 0.2 || v > 0.6 ? WHITE : C[5]), 1.1 - d);+ for (let g = Math.PI * 1.1; g < TAU - 0.2; g += 0.5) p.glow(Math.cos(g) * r, Math.sin(g) * r, 8, C[5], 0.3 * (1 - d));+ }+ // the white hero frame+ if (t >= HIT && t < HIT + 0.07) {+ p.circle(0, -6, 16, WHITE);+ p.circle(0, -6, 19, C[6], 0.6);+ }+ for (const b of chips.list) chip(p, b, st);+ ps.draw(p, "front");+ if (t >= HIT && t < HIT + 0.25) sparkle(p, 0, -8, 16 * (1 - (t - HIT) / 0.25), WHITE, C[5], 0.7);+ lights.draw(p);+ },+ };}diff --git a/src/fx/holy/sunburst.js b/src/fx/holy/sunburst.jsindex bfb095e..2083d4e 100644--- a/src/fx/holy/sunburst.js+++ b/src/fx/holy/sunburst.js@@ -1,45 +1,70 @@-import { PAL, cycle, TAU, WHITE } from "../../core/index.js";-import { fit, sparkle } from "./_lib.js";+import { fit, sparkle, cycle, clamp, TAU, WHITE } from "../../core/index.js";+import { GOLD } 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,+ desc: "A white-hot core in a gold corona; long and short rays turn slowly round it, breathing, with glints running out along them that wink at the tips.",+ tags: ["holy", "sun", "radiant", "rays", "light", "glow", "loop"],+ size: [128, 128],+ origin: [64, 64],+ duration: 4,loop: true,fps: 30,bg: "dark",- options: { palette: PAL.holy, rays: 12, length: 28, seed: 41 },+ options: { palette: GOLD, rays: 8, seed: 3 },};+const CORE = 4.5, RING = 7.5, R0 = 9;+const frac = (x) => x - Math.floor(x);++// one tapered ray from radius R0 out to R0 + L at angle a: white at the root, cooling to gold, thinning into light+function ray(p, C, a, L, w0, k) {+ const ca = Math.cos(a), sa = Math.sin(a), x1 = ca * (R0 + L), y1 = sa * (R0 + L), pad = w0 + 1;+ p.shade(Math.min(0, x1) - pad, Math.min(0, y1) - pad, Math.max(0, x1) + pad, Math.max(0, y1) + pad, (x, y, out) => {+ const along = x * ca + y * sa - R0, u = along / L;+ if (u < 0 || u > 1) return;+ const across = Math.abs(-x * sa + y * ca), w = (w0 / 2) * (1 - u * 0.85) + 0.25;+ if (across > w) return;+ const spine = across < 0.5, rim = across > w - 0.6 && w > 0.9;+ out.c = spine ? (u < 0.4 ? WHITE : u < 0.75 ? C[6] : C[5]) : rim && u > 0.15 ? C[3] : u < 0.3 ? C[6] : u < 0.62 ? C[5] : C[4];+ out.a = u < 0.72 ? k : k * (1 - (u - 0.72) / 0.28) * 1.2;+ });+ p.glowLine(ca * R0, sa * R0, ca * (R0 + L * 0.8), sa * (R0 + L * 0.8), 5, C[5], 0.16 * k);+}+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);+ const C = fit(o.palette, 8), N = o.rays * 2, T = meta.duration, rot = (t / T) * ((2 * TAU) / N);+ p.glow(0, 0, 62, C[4], 0.3 + 0.06 * Math.sin((t / T) * TAU * 2));+ // fine threads of light between the rays+ for (let i = 0; i < N; i++) {+ const a = rot + ((i + 0.5) * TAU) / N, L = 14 + 6 * Math.sin(a * 3 + (t / T) * TAU);+ p.line(Math.cos(a) * (R0 + 1), Math.sin(a) * (R0 + 1), Math.cos(a) * (R0 + L), Math.sin(a) * (R0 + L), (u) => (u < 0.3 ? C[6] : C[5]), (u) => 0.7 - u * 0.8);+ }+ // the rays, long and short by turns, breathing as a wave runs round them+ for (let i = 0; i < N; i++) {+ const a = rot + (i * TAU) / N, long = i % 2 === 0, breathe = 0.86 + 0.14 * Math.sin(a * 3 - (t / T) * TAU * 2);+ const L = (long ? 36 : 21) * breathe;+ ray(p, C, a, L, long ? 4 : 2.6, 1);+ // a glint runs out along each long ray and winks at the tip+ if (long) {+ const g = frac((t / T) * 2 + (a * 3) / TAU), r = R0 + g * L;+ if (g < 0.9) {+ p.px(Math.cos(a) * r, Math.sin(a) * r, WHITE);+ p.glow(Math.cos(a) * r, Math.sin(a) * r, 5, C[6], 0.45 * (1 - g));+ } else sparkle(p, Math.cos(a) * (R0 + L), Math.sin(a) * (R0 + L), 1 + 3 * Math.sin(((g - 0.9) / 0.1) * Math.PI), WHITE, C[6], 0.5);+ }}- // 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);+ // the corona and the core+ p.shade(-RING - 2, -RING - 2, RING + 2, RING + 2, (x, y, out) => {+ const d = Math.hypot(x, y);+ if (d > RING) return;+ const flick = 0.5 + 0.5 * Math.sin(Math.atan2(y, x) * 5 + (t / T) * TAU * 3);+ out.c = d < CORE ? WHITE : d < CORE + 1.5 ? (flick > 0.6 ? WHITE : C[6]) : flick > 0.5 ? C[5] : C[4];+ });+ p.glow(0, 0, 16, WHITE, 0.28);+ // twinkles round it+ cycle(t, T, 10, o.seed, (g) => g.range(0.35, 0.7), (age, life, R) => {+ const a = R.range(0, TAU), d = R.range(16, 44), k = Math.sin((age / life) * Math.PI);+ sparkle(p, Math.cos(a) * d, Math.sin(a) * d, 1 + 2.4 * k * R.range(0.5, 1), WHITE, C[5], 0.4 * k);});- 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.jsindex e7ea4f9..1a65e9d 100644--- a/src/fx/ice/_lib.js+++ b/src/fx/ice/_lib.js@@ -1,99 +1,355 @@-// Shared by the ice effects: palette fitting, faceted spikes and shards, snowflakes and glints.-// Files starting with _ are helpers, not effects.+// Shared by the ice effects: panes of ice that tumble and skid, polygon helpers, a character turned to ice,+// cracks that race through a shape. Files starting with _ are helpers, not effects.+// The crack walk and the faceted crystal shading are adapted from Sprite Fusion's open-source ice+// (https://www.spritefusion.com/pixel-art-vfx/ice), MIT License, Copyright (c) 2026 Hugo Duprez.-import { ramp, TAU } from "../../core/index.js";+import { GRAVITY, clamp, luma, TAU, WHITE } 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))]);+/** Is (x, y) inside the polygon pts [[x, y], ...]? (even-odd rule) */+export function inPoly(pts, x, y) {+ let inside = false;+ for (let i = 0, j = pts.length - 1; i < pts.length; 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;}-/**- * 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 polygon's centroid and area: { x, y, area }. */+export function centroid(pts) {+ let a = 0, cx = 0, cy = 0;+ for (let i = 0, j = pts.length - 1; i < pts.length; j = i++) {+ const [x0, y0] = pts[j], [x1, y1] = pts[i], k = x0 * y1 - x1 * y0;+ a += k;+ cx += (x0 + x1) * k;+ cy += (y0 + y1) * k;+ }+ if (Math.abs(a) < 1e-6) {+ const n = pts.length;+ return { x: pts.reduce((s, q) => s + q[0], 0) / n, y: pts.reduce((s, q) => s + q[1], 0) / n, area: 0 };+ }+ return { x: cx / (3 * a), y: cy / (3 * a), area: Math.abs(a) / 2 };+}++/** Cut a polygon along the line through (x, y) at angle a: the pieces with three corners or more. */+export function splitPoly(pts, x, y, a) {+ const nx = -Math.sin(a), ny = Math.cos(a), side = (q) => (q[0] - x) * nx + (q[1] - y) * ny, L = [], Rt = [];+ for (let i = 0; i < pts.length; i++) {+ const p = pts[i], q = pts[(i + 1) % pts.length], sp = side(p), sq = side(q);+ (sp >= 0 ? L : Rt).push(p);+ if (sp >= 0 !== sq >= 0) {+ const u = sp / (sp - sq), m = [p[0] + (q[0] - p[0]) * u, p[1] + (q[1] - p[1]) * u];+ L.push(m);+ Rt.push(m);+ }+ }+ return [L, Rt].filter((s) => s.length >= 3);+}++/** A color turned to ice: its brightness picks a step of the ice ramp C (dark to bright), never the darkest. */+export function iceOf(c, C) {+ const n = C.length, l = luma(c);+ return C[clamp(Math.round(((l < 0.12 ? 2 : 2 + l * 5.2) * (n - 1)) / 7), 1, n - 1)];+}++/** Fill a polygon with translucent color (true blending, no dither): glass, ice, light. */+export function glassPoly(p, pts, c, a) {+ 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));+ for (let y = Math.floor(y0); y <= Math.ceil(y1); y++)+ for (let x = Math.floor(x0); x <= Math.ceil(x1); x++) if (inPoly(pts, x + 0.5, y + 0.5)) p.blend(x, y, c, 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.+ * Panes of ice: flat polygons that fly, spin and tumble end over end (they squash as they turn edge-on and+ * flash as they square up to the light), bounce on the floor, skid, settle and fade. Drawn as glass: a+ * translucent face, edges lit where they face the light, a glint.+ * add({ pts (corners around 0, 0), x, y, vx, vy, a (turn), va, f (tumble), vf, lit (0..1: how much light its+ * face catches), g, drag, bounce, life, brittle (breaks on that many hard landings), crumble (seconds it lies+ * still before it crumbles), solid (opaque: one `tone` 0..1, or shaded like a blade split along `ridge`, an angle) });+ * update(dt); draw(p, C)+ * with an ice ramp, dark to bright. onLand(q, x, y, speed) when one hits the floor hard, onCrumble(q) when one+ * that lay still crumbles away, onSkid(q, x, y) while one slides along the floor.*/-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);+export class Panes {+ constructor(opts = {}) {+ this.list = [];+ this.ground = opts.ground ?? (() => Infinity);+ this.onLand = opts.onLand ?? null;+ this.onCrumble = opts.onCrumble ?? null;+ this.onSkid = opts.onSkid ?? null;+ }+ add(q) {+ const life = q.life ?? 1;+ this.list.push({ vx: 0, vy: 0, a: 0, va: 0, f: 0, vf: 0, lit: 0.6, g: 1, drag: 0.3, bounce: 0.35, rest: false, brittle: false, ...q, life, max: life });+ }+ get count() {+ return this.list.length;+ }+ /** The pane's corners as drawn: tumbled (squashed across its own width), turned and placed. */+ corners(q) {+ const ca = Math.cos(q.a), sa = Math.sin(q.a), k = Math.cos(q.f);+ return q.pts.map(([x, y]) => {+ const yy = y * k;+ return [q.x + x * ca - yy * sa, q.y + x * sa + yy * ca];+ });+ }+ seat(q) {+ let low = -Infinity;+ for (const c of this.corners(q)) low = Math.max(low, c[1]);+ return low;+ }+ update(dt) {+ for (let i = this.list.length - 1; i >= 0; i--) {+ const q = this.list[i];+ if ((q.life -= dt) <= 0) {+ this.list.splice(i, 1);+ continue;+ }+ const floor = this.ground(q.x) - 0.5;+ if (q.rest && q.crumble !== undefined && (q.restT = (q.restT ?? 0) + dt) > q.crumble) {+ this.onCrumble?.(q);+ this.list.splice(i, 1);+ continue;+ }+ if (q.rest) {+ // skidding: friction slows the slide and the spin, the pane stays seated on the floor+ if (Math.abs(q.vx) > 8) this.onSkid?.(q, q.x, floor + 0.5);+ q.x += q.vx * dt;+ q.vx -= q.vx * 7 * dt;+ q.a += q.va * dt;+ q.va -= q.va * 9 * dt;+ q.vf -= q.vf * 9 * dt;+ q.f += q.vf * dt;+ q.y -= this.seat(q) - floor;+ continue;+ }+ q.vy += GRAVITY * q.g * dt;+ q.vx -= q.vx * q.drag * dt;+ q.vy -= q.vy * q.drag * dt;+ q.x += q.vx * dt;+ q.y += q.vy * dt;+ q.a += q.va * dt;+ q.f += q.vf * dt;+ const low = this.seat(q);+ if (q.g <= 0 || low < floor || q.vy <= 0) continue;+ q.y -= low - floor;+ if (q.vy > 70) (q.hits = (q.hits ?? 0) + 1), this.onLand?.(q, q.x, floor + 0.5, q.vy);+ if (q.brittle && q.vy > 70 && q.hits >= q.brittle) {+ this.list.splice(i, 1);+ continue;+ }+ if (q.vy > 70 && q.bounce > 0) {+ q.vy = -q.vy * q.bounce;+ q.vx *= 0.75;+ q.va *= 0.6;+ q.vf *= 0.5;+ } else {+ q.rest = true;+ q.vy = 0;+ }+ }+ }+ draw(p, C) {+ const n = C.length;+ for (const q of this.list) {+ const a = Math.min(1, q.life / 0.35), pts = this.corners(q), k = Math.cos(q.f), face = Math.abs(k);+ // the face: glassy, brighter the more it faces us and the more light it catches; it flashes as it squares up+ const lv = q.lit * (0.35 + 0.65 * face), flash = face > 0.97 && !q.rest;+ if (face > 0.25) {+ if (q.solid && q.tone !== undefined) {+ // a chunk of one face: its tone, brighter as it squares up to the light+ p.poly(pts, flash ? C[n - 1] : C[clamp(Math.round(1 + q.tone * 5 * (0.6 + 0.4 * face)), 1, n - 2)], a);+ } else if (q.solid) {+ // shaded like the blade it broke from: a lit side, a pale ridge, a deep side+ const rr = q.ridge ?? -Math.PI / 2, cr = Math.cos(rr), sr = Math.sin(rr), ca = Math.cos(q.a), sa = Math.sin(q.a);+ const rx = cr * ca - sr * k * sa, ry = cr * sa + sr * k * ca;+ let nx = -ry, ny = rx;+ if (nx * -0.55 + ny * -0.84 < 0) (nx = -nx), (ny = -ny);+ const lit = flash ? C[n - 1] : C[clamp(Math.round(3 + lv * 3), 3, n - 2)], deep = C[clamp(Math.round(1 + lv * 2), 1, 3)];+ p.poly(pts, (x, y) => {+ const d = (x - q.x) * nx + (y - q.y) * ny;+ return d > 0.6 ? lit : d > -0.6 ? C[n - 2] : deep;+ }, a);+ } else glassPoly(p, pts, flash ? C[n - 1] : C[clamp(Math.round(3 + lv * 3), 3, n - 2)], (0.3 + 0.35 * lv + (flash ? 0.3 : 0)) * a);+ }+ let cx = 0, cy = 0, top = 0;+ for (const [x, y] of pts) (cx += x), (cy += y);+ cx /= pts.length;+ cy /= pts.length;+ // edges: lit where they face the light (up and left), cool where they face away+ for (let i = 0; i < pts.length; i++) {+ const [x0, y0] = pts[i], [x1, y1] = pts[(i + 1) % pts.length];+ let nx = y1 - y0, ny = x0 - x1;+ if (nx * ((x0 + x1) / 2 - cx) + ny * ((y0 + y1) / 2 - cy) < 0) (nx = -nx), (ny = -ny);+ const l = Math.hypot(nx, ny) || 1, lit = (-nx * 0.55 - ny * 0.84) / l;+ p.line(x0, y0, x1, y1, face < 0.25 || lit > 0.35 ? C[n - 1] : lit > -0.25 ? C[n - 2] : q.solid ? C[1] : C[Math.max(2, n - 4)], a);+ if (pts[i][1] < pts[top][1]) top = i;+ }+ if (face > 0.7) p.dot(pts[top][0], pts[top][1], WHITE, a);+ p.glow(cx, cy, 5, C[n - 3], (flash ? 0.5 : 0.14) * 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;+/**+ * A jagged ice blade standing on its base (bx, by), tip at (tx, ty), w wide at the base. Shaded in an ice ramp+ * C (dark to bright, 8 steps): a lit facet on the left with a pale edge, a bright ridge, a deep facet on the+ * right, a white tip, a dark rim, and a notch cut into one side so it reads as a shard, not a cone.+ * opts: { a (alpha), white (flash it white), glint (0..1: a highlight across it at that height, or -1),+ * jag (0..1: where the notch starts, or -1), dim (steps darker, for back rows) }.+ */+export function blade(p, bx, by, tx, ty, w, C, opts = {}) {+ const dx = tx - bx, dy = ty - by, L = Math.hypot(dx, dy);+ if (L < 1.5 || w < 0.5) return;+ const ux = dx / L, uy = dy / L, nx = -uy, ny = ux, a = opts.a ?? 1, dim = opts.dim ?? 0, jag = opts.jag ?? -1, glint = opts.glint ?? -1;+ const K = (i) => C[clamp(i - dim, 0, C.length - 1)], hw = w / 2;+ // half widths on the left (lit) and right (shadow) sides at height u; the notch steps the right side in+ const left = (u) => hw * (1 - u) + 0.35, right = (u) => hw * (1 - u) * (jag >= 0 && u > jag ? 0.55 : 1) + 0.35, ridge = (u) => -w * 0.12 * (1 - u);+ const pad = hw + 2;+ p.shade(Math.min(bx, tx) - pad, Math.min(by, ty) - pad, Math.max(bx, tx) + pad, Math.max(by, ty), (x, y, o) => {+ const rx = x - bx, ry = y - by, u = (rx * ux + ry * uy) / L, s = rx * nx + ry * ny;+ if (u < 0) return;+ const l = left(Math.min(u, 1)), r = right(Math.min(u, 1));+ if (u > 1 || s < -l || s > r) {+ // a dark rim just outside the blade+ const over = u > 1 ? (u - 1) * L : 0, out = Math.max(over, s < -l ? -l - s : s - r);+ if (out < 1 && u < 1 + 1 / L) {+ o.c = K(0);+ o.a = a;+ }+ return;+ }+ o.a = a;+ if (opts.white) return (o.c = WHITE);+ const rd = ridge(u);+ let c;+ if (u > 0.88) c = WHITE;+ else if (Math.abs(s - rd) < 0.55) c = K(6);+ else if (s < rd) c = s + l < 1 ? K(6) : (s + l) / Math.max(1, rd + l) > 0.55 ? K(5) : K(4);+ else c = r - s < 1.1 ? K(1) : (s - rd) / Math.max(1, r - rd) > 0.5 ? K(2) : K(3);+ // the notch's ledge catches light; a little glitter in the lit facet+ if (jag >= 0 && Math.abs(u - jag) * L < 0.8 && s > rd) c = K(6);+ else if (s < rd && c !== K(6) && ((Math.floor(x) * 73856093) ^ (Math.floor(y) * 19349663)) % 997 < 30) c = K(7);+ if (glint >= 0 && s <= rd + 0.6) {+ const g = Math.abs(u - glint) * L;+ if (g < 0.8) c = WHITE;+ else if (g < 1.8) c = K(6);+ }+ o.c = c;+ });}-// 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 snowflake design, seeded: pairs of side branches along each arm ([where 0..1, length 0..1 of the arm]),+ * maybe a hexagonal plate round the heart, maybe forked tips.+ */+export function flakeDesign(R) {+ const n = R.int(1, 3), branches = [];+ for (let i = 0; i < n; i++) branches.push([0.38 + (0.4 * (i + R.range(0.2, 0.8))) / n, R.range(0.24, 0.36) * (1 - i * 0.15)]);+ return { branches, plate: R.chance(0.45), fork: R.chance(0.45) };+}/**- * 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.+ * A six-armed snowflake of radius r turned by rot, crisp 1 px lines: pale arms, side branches at 60 degrees,+ * a plate or forked tips by design, a white heart, light. hot (0..1) makes it twinkle white.*/-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);+export function snowflake(p, x, y, r, rot, d, C, opts = {}) {+ const n = C.length, a = opts.a ?? 1, hot = opts.hot ?? 0;+ rot = Math.round(rot / (Math.PI / 18)) * (Math.PI / 18); // turn in 10 degree ticks, like sprite frames+ if (r < 1.2) {+ p.dot(x, y, WHITE, 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 });+ if (r < 2.6) {+ // too small for branches: a six-point star that flips between two poses as it turns+ const pose = Math.floor(((rot % (Math.PI / 3)) + Math.PI / 3) / (Math.PI / 6)) % 2;+ const pts = pose ? [[1, 0], [-1, 0], [0, 1], [0, -1]] : [[1, 1], [-1, -1], [1, -1], [-1, 1]];+ for (const [dx, dy] of pts) p.dot(x + dx, y + dy, hot > 0.5 ? WHITE : C[n - 3], a);+ p.dot(x, y, WHITE, a);+ p.glow(x, y, 4, C[n - 3], 0.2 * a);return;}+ // detail by size: a bare star when small, one pair of branches when middling, the full design when big+ const arm = hot > 0.5 ? WHITE : C[n - 2], br = hot > 0.5 ? C[n - 2] : C[n - 3], big = r >= 7;+ const branches = r < 4 ? [] : big ? d.branches.slice(0, 2) : [[0.58, 0.36]];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);- }+ const g = rot + (k * TAU) / 6, ca = Math.cos(g), sa = Math.sin(g);+ p.line(x, y, x + ca * r, y + sa * r, arm, a);+ for (const [u, l] of branches) {+ const bx = x + ca * r * u, by = y + sa * r * u, bl = Math.max(1, r * l);+ for (const s of [-1, 1]) p.line(bx, by, bx + Math.cos(g + (s * Math.PI) / 3) * bl, by + Math.sin(g + (s * Math.PI) / 3) * bl, br, a);+ }+ if (d.fork && big && !d.plate)+ for (const s of [-1, 1]) p.dot(x + ca * r + Math.cos(g + s * 0.9) * 1.2, y + sa * r + Math.sin(g + s * 0.9) * 1.2, br, a);+ p.dot(x + ca * r, y + sa * r, WHITE, a);+ }+ if (d.plate && big) {+ const q = r * 0.34;+ for (let k = 0; k < 6; k++) {+ const g0 = rot + Math.PI / 6 + (k * TAU) / 6, g1 = g0 + TAU / 6;+ p.line(x + Math.cos(g0) * q, y + Math.sin(g0) * q, x + Math.cos(g1) * q, y + Math.sin(g1) * q, C[n - 3], 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);+ p.px(x, y, WHITE);+ p.glow(x, y, 3 + r * 1.2, C[n - 4], (0.14 + 0.35 * hot) * a);+ if (hot > 0.3) p.glow(x, y, 2 + r * 0.5, WHITE, 0.3 * hot * 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);- }+/** Nothing outlives the effect: trims the life of every particle, bit and pane that would last past D. */+export function endBy(t, D, ...systems) {+ const left = Math.max(0.001, D - 0.05 - t);+ for (const sys of systems) for (const q of sys.list) if (q.life > left) q.life = left;+}++/**+ * Cracks racing out from (x, y) through a shape: n jagged lines that wander, fork now and then and stop at+ * the shape's edge (inside(x, y) says what's in it). Each point carries its distance from the start along the+ * crack, so drawFractures can grow them at a speed. Returns polylines [[x, y, d], ...].+ */+export function fractures(R, inside, x, y, n, opts = {}) {+ const out = [], step = opts.step ?? [1.6, 2.6], len = opts.len ?? 18, fork = opts.fork ?? 0.16, a0 = opts.a0 ?? R.range(0, TAU), spread = opts.spread ?? TAU;+ const walk = (x, y, d, a, len, depth) => {+ const pts = [[x, y, d]];+ for (let s = 0; s < len; s++) {+ a += R.range(-0.55, 0.55);+ const st = R.range(step[0], step[1]), nx = x + Math.cos(a) * st, ny = y + Math.sin(a) * st;+ if (!inside(nx, ny)) break;+ (x = nx), (y = ny), (d += st);+ pts.push([x, y, d]);+ if (depth < 2 && pts.length > 2 && R.chance(fork)) walk(x, y, d, a + R.sign() * R.range(0.6, 1.2), Math.ceil(len * 0.5), depth + 1);+ }+ if (pts.length > 1) out.push(pts);+ };+ for (let i = 0; i < n; i++) walk(x, y, 0, a0 + (i / n) * spread + R.range(-0.3, 0.3) * Math.min(1, spread / TAU), len, 0);+ return out;+}++/**+ * Draw cracks grown out to distance `reach` from their start: a bright line over a dark one a pixel lower (an+ * engraved fracture), a white-hot tip while they run, light leaking out along them. ox, oy shift them.+ */+export function drawFractures(p, cracks, reach, C, opts = {}) {+ const n = C.length, ox = opts.ox ?? 0, oy = opts.oy ?? 0, hot = opts.hot ?? true, a = opts.a ?? 1;+ const seg = (pts, i) => {+ const [x0, y0, d0] = pts[i - 1], [x1, y1, d1] = pts[i];+ if (d0 >= reach) return null;+ const u = Math.min(1, (reach - d0) / Math.max(0.01, d1 - d0));+ return [x0 + ox, y0 + oy, x0 + ox + (x1 - x0) * u, y0 + oy + (y1 - y0) * u, reach - d1 < 3];+ };+ for (const pts of cracks)+ for (let i = 1; i < pts.length; i++) {+ const s = seg(pts, i);+ if (!s) break;+ p.line(s[0], s[1] + 1, s[2], s[3] + 1, C[Math.min(2, n - 1)], a);+ }+ for (const pts of cracks)+ for (let i = 1; i < pts.length; i++) {+ const s = seg(pts, i);+ if (!s) break;+ const tip = hot && s[4];+ p.line(s[0], s[1], s[2], s[3], tip ? WHITE : C[n - 2], a);+ if (tip) p.glow(s[2], s[3], 5, C[n - 3], 0.5 * a);+ else if (i % 2) p.glow(s[2], s[3], 3, C[n - 3], 0.18 * a);+ }}diff --git a/src/fx/ice/blizzard-vortex.js b/src/fx/ice/blizzard-vortex.jsindex ad8e943..bd397bf 100644--- a/src/fx/ice/blizzard-vortex.js+++ b/src/fx/ice/blizzard-vortex.js@@ -1,58 +1,130 @@-import { PAL, cycle, fract, clamp, tileNoise, TAU, WHITE } from "../../core/index.js";-import { fit } from "./_lib.js";+// Particles and bands that pass behind and in front of a centre (dim far half drawn back, bright near half+// drawn front) follow the recipe in Sprite Fusion's open-source black hole+// (https://www.spritefusion.com/pixel-art-vfx/black-hole), MIT License, Copyright (c) 2026 Hugo Duprez.+import { fit, cycle, clamp, rand, TAU, WHITE, mix } from "../../core/index.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,+ desc: "A swirling snow tornado: wind bands spin up a leaning funnel, flakes and ice crystals orbit in front and behind, snow boils at its foot and cold light fills its throat.",+ tags: ["ice", "snow", "blizzard", "tornado", "vortex", "wind", "loop"],+ size: [128, 116],+ origin: [64, 102],+ duration: 2,loop: true,fps: 30,bg: "ground",- options: { palette: PAL.ice, height: 80, width: 24, seed: 29 },+ options: { palette: ["#151a3d", "#212f6b", "#2c58aa", "#3a8bd8", "#62c8f4", "#a6ecff", "#dcfbff", "#ffffff"], height: 80, seed: 17 },};-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;+const TILT = 0.24; // how flat the funnel's rings look++// the funnel: radius by height (narrow foot, wide mouth) and an axis that sways (one full sway a loop)+const radius = (h, H) => 4 + 28 * Math.pow(clamp(h / H), 1.35);+const axis = (h, H, ph) => (5 * Math.sin(TAU * ph + h * 0.05) + 1.5 * Math.sin(TAU * ph * 2 - h * 0.11)) * (h / H) - 2 * (h / H);++// wind streaks: arcs of snow-laden air swirling round the funnel and climbing it, a bright head and a fading+// tail, faster low down; the far half of each arc goes behind, the near half in front+function streaks(p, C, t, o, front) {+ const D = meta.duration, H = o.height, ph = t / D;+ cycle(t, D, 58, o.seed + 9, (g) => g.range(0.5, 0.9), (age, life, r) => {+ const h0 = r.range(2, H), w = r.range(8, 12) * (1.45 - h0 / H), th = r.range(0, TAU) + age * w, k = age / life;+ const fade = Math.min(1, age / 0.08) * (k > 0.7 ? (1 - k) / 0.3 : 1), L = r.range(0.7, 1.5), m = Math.ceil(L / 0.07);+ for (let j = 0; j <= m; j++) {+ const a = th - j * 0.07, s = Math.sin(a);+ if (s >= 0 !== front) continue;+ const h = Math.min(H + 4, h0 + age * 16 - j * 0.25), R = radius(Math.min(h, H), H) * (1 + Math.min(0.3, Math.max(0, h - H * 0.84) * 0.03)), u = j / m;+ const x = axis(Math.min(h, H), H, ph) + Math.cos(a) * R, y = -h + s * R * TILT;+ const c = front ? (u < 0.15 ? WHITE : u < 0.5 ? C[6] : C[5]) : u < 0.3 ? C[5] : u < 0.6 ? C[4] : C[3];+ p.dot(x, y, c, fade * (u < 0.6 ? 1 : 1.5 - u * 1.2) * (front ? 1 : 0.85));+ }+ });+}++// the body: a translucent column of snow-filled air, densest at the edges where you look through more of it+function body(p, C, ph, H) {+ p.each(-44, -H - 6, 44, 2, (x, y, sx, sy) => {+ const h = -y;+ if (h < 0 || h > H + 4) return;+ const R = radius(h, H), dx = x - axis(h, H, ph), u = dx / R;+ if (u * u >= 1) return;+ const k = h / H, rim = Math.pow(Math.abs(u), 3), swirl = Math.sin(Math.asin(u) * 3 - TAU * ph * 2 + h * 0.2) * 0.5 + 0.5;+ const a = (0.07 + 0.24 * rim + 0.12 * swirl) * clamp((1 - Math.abs(u)) / 0.18) * (k > 0.7 ? Math.max(0, (1 - k) / 0.3) : 1) * (h < 4 ? h / 4 : 1);+ if (a < 0.03) return;+ p.blendPx(sx, sy, rim > 0.5 ? C[6] : swirl > 0.6 ? C[5] : C[4], a);+ if (rim > 0.3 || swirl > 0.75) p.add(sx, sy, C[5], 0.16 * Math.max(rim, swirl - 0.5) * (1 - k * 0.5));+ });+}++// snow and ice carried round: rising on a spiral, faster low down, flung out at the top+function orbiters(p, C, t, o, front) {+ const D = meta.duration, H = o.height, ph = t / D;+ cycle(t, D, 76, o.seed, (g) => g.range(0.9, 1.6), (age, life, r, i) => {+ const h0 = r.range(0, H * 0.6), h = h0 + age * r.range(14, 30), k = age / life;+ if (h > H + 8) return;+ const w = r.range(7, 11) * (1.5 - h / H), th = r.range(0, TAU) + age * w, out = 1 + r.range(0.05, 0.3) + Math.min(0.35, Math.max(0, h - H * 0.82) * 0.04);+ const R = radius(Math.min(h, H), H) * out, s = Math.sin(th);+ if (s >= 0 !== front) return;+ const x = axis(Math.min(h, H), H, ph) + Math.cos(th) * R, y = -h + s * R * TILT, big = i % 5 === 0;+ const fade = Math.min(1, age / 0.1) * (k > 0.8 ? (1 - k) / 0.2 : 1);+ if (fade <= 0) return;+ // a streak back along its path, a bright head+ const th2 = th - 0.25, x2 = axis(Math.min(h, H), H, ph) + Math.cos(th2) * R, y2 = -h + 2 + Math.sin(th2) * R * TILT;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]);+ p.line(x2, y2, x, y, (u) => (u > 0.6 ? C[6] : C[4]), (u) => u * fade);+ p.dot(x, y, big ? WHITE : r.chance(0.5) ? WHITE : C[6], fade);+ if (big) {+ for (const [dx, dy] of [[1, 0], [-1, 0], [0, 1], [0, -1]]) p.dot(x + dx, y + dy, C[6], fade);+ p.glow(x, y, 5, C[5], 0.35 * fade);+ }+ } else {+ p.line(x2, y2, x, y, C[3], (u) => u * fade * 0.8);+ p.dot(x, y, big ? C[5] : C[4], fade);+ }});- 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];+}++// snow boiling at the foot: soft puffs spinning round the base, lit on top+function foot(p, C, t, o, front) {+ const D = meta.duration, ph = t / D;+ cycle(t, D, 12, o.seed + 5, (g) => g.range(0.8, 1.2), (age, life, r) => {+ const th = r.range(0, TAU) + age * r.range(4, 6), R = 9 + age * r.range(8, 16), s = Math.sin(th), k = age / life;+ if (s >= 0 !== front) return;+ const x = axis(0, 1, ph) + Math.cos(th) * R, y = -2 - age * r.range(4, 10) + s * R * 0.2, rad = 2 + 4 * k, a = 0.5 * (1 - k) ** 1.2 * Math.min(1, age / 0.1);+ p.disc(x, y, rad, front ? C[6] : C[5], (d) => a * (1 - d * d));+ p.disc(x - rad * 0.25, y - rad * 0.3, rad * 0.5, WHITE, (d) => a * 0.5 * (1 - d * d) * (1 - k));});- // 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]);+}++export function drawBack(p, t, o) {+ const C = fit(o.palette, 8), H = o.height, ph = t / meta.duration;+ // a snow drift on the floor, swept round+ for (let x = -30; x <= 30; x++) {+ const d = Math.abs(x) / 30, hgt = Math.round((1 - d * d) * (1.5 + rand(x, 3) * 1.5));+ for (let j = 0; j < hgt; j++) p.px(x, -j, j === hgt - 1 ? WHITE : C[5]);+ p.dot(x, 0, C[6], 1 - d * 0.5);+ p.dot(x, 1, C[4], 0.8 - d * 0.6);}- 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);+ p.glow(0, -2, 40, C[4], 0.22);+ foot(p, C, t, o, false);+ streaks(p, C, t, o, false);+ orbiters(p, C, t, o, false);+}++export function draw(p, t, o) {+ const C = fit(o.palette, 8), H = o.height, ph = t / meta.duration;+ body(p, C, ph, H);+ // cold light in its throat+ p.glow(axis(H * 0.45, H, ph), -H * 0.45, 40, C[4], 0.3);+ p.glow(axis(H * 0.15, H, ph), -H * 0.15, 18, C[5], 0.4 + 0.1 * Math.sin(TAU * ph * 4));+ p.glow(axis(H * 0.05, H, ph), -3, 10, WHITE, 0.3);+ streaks(p, C, t, o, true);+ orbiters(p, C, t, o, true);+ foot(p, C, t, o, true);+ // snow thrown off the mouth, spreading into a thin cloud+ cycle(t, meta.duration, 10, o.seed + 3, (g) => g.range(0.9, 1.3), (age, life, r) => {+ const th = r.range(0, TAU), R = radius(H, H) * (0.6 + age * 0.9), k = age / life, rad = 3 + 6 * k;+ const Rc = Math.min(R, 36), x = axis(H, H, ph) + Math.cos(th) * Rc, y = -H - 2 - age * 4 + Math.sin(th) * Rc * TILT, a = 0.24 * (1 - k) * Math.min(1, age / 0.15);+ p.disc(x, y, rad * 0.8, C[6], (d) => a * (1 - d * d));+ p.glow(x, y, rad * 1.5, C[4], 0.08 * (1 - k));+ });}diff --git a/src/fx/ice/cold-mist.js b/src/fx/ice/cold-mist.jsdeleted file mode 100644index 35ba98a..0000000--- a/src/fx/ice/cold-mist.js+++ /dev/null@@ -1,39 +0,0 @@-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.jsindex 1175fa0..401d23d 100644--- a/src/fx/ice/freeze.js+++ b/src/fx/ice/freeze.js@@ -1,105 +1,388 @@-import { PAL, burst, rng, seg, ease, fly, bolt, TAU, WHITE } from "../../core/index.js";-import { fit, shard, shardPts, glint } from "./_lib.js";+// The crack-and-burst recipe (cracks walking out from a point, a white frame, the ice flung apart as shards+// with ice dust and glints) is adapted from Sprite Fusion's open-source ice+// (https://www.spritefusion.com/pixel-art-vfx/ice), MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Bits, Lights, P, B, Rng, fit, flare, sparkle, clamp, smooth, seg, ease, rand, mix, TAU, WHITE } from "../../core/index.js";+import { Panes, endBy, inPoly, centroid, splitPoly, iceOf, fractures, drawFractures } 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.",+ desc: "Frost races in and climbs the character, turning it to ice; a faceted block crystallizes round it pane by pane, glints, cracks and bursts, and the character thaws free.",tags: ["ice", "freeze", "frozen", "status", "crowd-control", "one-shot"],- size: [64, 52],- origin: [32, 44],- duration: 2.4,+ size: [176, 128],+ origin: [88, 108],+ duration: 4,loop: false,fps: 30,bg: "ground",- actor: true,- options: { palette: PAL.ice, seed: 23 },+ actor: 2,+ options: { palette: ["#151a3d", "#212f6b", "#2c58aa", "#3a8bd8", "#62c8f4", "#a6ecff", "#dcfbff", "#ffffff"], seed: 5 },};-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+const SNAP = 0.16; // frost lines race in along the floor to the feet+const CLIMB = [0.14, 0.62]; // and climb the character+const SEAL = 0.6; // the block crystallizes, pane by pane+const SWEEPS = [1.12, 1.82]; // light slides across the faces while it holds+const CRACK = 2.2, CRACK2 = 2.34, FLASH = 2.46, BURST = 2.52, THAW = 0.36;+const MELT = [2.95, 3.7]; // the floor frost goes+const REACH = 38, CORE = [0, -21];-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]);+// the block: a crown of three crystal points over straight sides, eleven corners round the character and+// eight inside, cut into thirteen panes. Each pane: its corners, how much light it catches (0 shadow .. 1 lit)+// and when it crystallizes after SEAL (from the floor up).+const V = {+ l0: [-15, 0], l1: [-17, -10], l2: [-17, -31], p1: [-12, -45], n1: [-6, -42], p2: [0, -52], n2: [6, -43], p3: [12, -47], r2: [17, -30], r1: [16, -9], r0: [14, 0],+ i0: [-6, -36], i1: [6, -35], i2: [-9, -21], i3: [3, -25], i4: [9, -13], i5: [-5, -8], i6: [2, 0], i7: [0, -40],+};+const FACETS = [+ ["l0 l1 i5 i6", 0.62, 0], ["i5 i4 i6", 0.42, 0.03], ["i4 r2 r1 r0 i6", 0.2, 0.05], ["l1 l2 i2 i5", 0.74, 0.08], ["i2 i3 i4 i5", 0.5, 0.1],+ ["i1 r2 i4 i3", 0.28, 0.13], ["l2 i0 i2", 0.7, 0.15], ["i0 i1 i3 i2", 0.58, 0.18], ["n1 i7 n2 i1 i0", 0.52, 0.2], ["i1 n2 p3 r2", 0.4, 0.23],+ ["l2 p1 n1 i0", 0.88, 0.25], ["p2 n2 i7", 0.66, 0.28], ["n1 p2 i7", 1, 0.31],+].map(([k, lit, at], i) => ({ pts: k.split(" ").map((v) => V[v]), lit, at: SEAL + at, i }));+const OUTLINE = "l0 l1 l2 p1 n1 p2 n2 p3 r2 r1 r0".split(" ").map((v) => V[v]);+const X0 = -18, X1 = 18, Y0 = -53, Y1 = 0, BW = X1 - X0;++// frost on the floor: a crust on the floor line, rime ferns standing up from it, a cold bloom under the surface+function floorFrost(p, C, t, out) {+ for (let x = -REACH; x <= REACH; x++) {+ const d = Math.abs(x + 0.5) / REACH, arrive = SNAP * (1 - d), age = t - arrive;+ if (age < 0) continue;+ const a = out * clamp((1.12 - d) / 0.2), g = smooth(0, 0.4, age), h = rand(x, 31), s = x < 0 ? -1 : 1;+ if (a <= 0) continue;+ p.dot(x, 0, age < 0.05 || h < 0.3 ? WHITE : C[6], a);+ if (h < 0.55) {+ const L = Math.round(g * (1 + rand(x, 7) * 3.4) * (1 - d * 0.55));+ for (let j = 1; j <= L; j++) p.dot(x, -j, j === L ? WHITE : C[5], a);+ if (L >= 2) p.dot(x + s, -L + 1, C[6], a);+ if (L >= 4) p.dot(x - s, -L + 2, C[5], a);+ }+ const D = g * (2 + rand(x, 11) * 4) * (1 - d * 0.5);+ for (let j = 1; j <= D; j++) p.dot(x, j, rand(x * 13 + j, 5) < 0.07 ? WHITE : j < 2 ? C[5] : j < 4 ? C[4] : C[3], a * (1.05 - j / (D + 1)));}}-const blockRise = (t) => ease.outBack(seg(t, SNAP[0], SNAP[1]), 1.6);+export function create(o) {+ const C = fit(o.palette, 8), R = new Rng(o.seed), A = o.actor, floor = () => 0;+ const ps = new Particles({ rng: R, ground: floor, sparks: [C[7], C[6], C[5], C[4]], haze: C[5] });+ const bits = new Bits({ ground: floor }), lights = new Lights();+ const panes = new Panes({+ ground: floor,+ onLand: (q, x, y, v) => {+ // a pane that lands breaks into splinters that skip along the floor, with a puff of ice dust and a glint+ for (let i = 0; i < 3; i++) bits.add({ kind: B.SHARD, x: x + R.range(-2, 2), y: y - 1, vx: q.vx * 0.6 + R.range(-50, 50), vy: -R.range(30, 100), g: 0.8, drag: 0.6, bounce: 0.35, life: R.range(0.4, 0.8), a: R.range(0, TAU), va: R.range(-18, 18), s: R.range(1.2, 2.4), c: C[R.int(5, 7)] });+ ps.spawn(P.VAPOUR, x, y - 1, R.range(-25, 25), -R.range(2, 10), R.range(0.4, 0.7), C[6], R.range(1.4, 2.4));+ if (R.chance(0.4)) ps.spawn(P.STAR, x, y - 2, 0, -6, R.range(0.2, 0.4), WHITE, R.range(0.8, 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);+ // ---- the character: each pixel's frozen color and when the frost reaches it. A randomized flood up from the+ // feet, quicker round the outline, so the front creeps up the edges first in ragged fingers.+ const W = A.w, H = A.h, N = W * H, on = (x, y) => x >= 0 && y >= 0 && x < W && y < H && A.mask.data[y * W + x] > 0;+ const dist = new Float32Array(N).fill(Infinity), ice = new Uint32Array(N), rim = new Uint8Array(N);+ const open = [];+ for (let y = 0; y < H; y++)+ for (let x = 0; x < W; x++) {+ if (!on(x, y)) continue;+ const i = y * W + x;+ rim[i] = !on(x - 1, y) || !on(x + 1, y) || !on(x, y - 1) ? 1 : 0;+ const up = !on(x - 1, y) || !on(x, y - 1);+ ice[i] = mix(up ? C[Math.min(7, C.indexOf(iceOf(A.pixels[i], C)) + 1)] : iceOf(A.pixels[i], C), C[6], 0.2);+ if (y === H - 1 || !on(x, y + 1)) if (y >= H - 4) (dist[i] = R.range(0, 1.5)), open.push(i);+ }+ const done = new Uint8Array(N);+ while (open.length) {+ let bi = 0;+ for (let j = 1; j < open.length; j++) if (dist[open[j]] < dist[open[bi]]) bi = j;+ const i = open[bi];+ open[bi] = open[open.length - 1];+ open.pop();+ if (done[i]) continue;+ done[i] = 1;+ const x = i % W, y = (i / W) | 0;+ for (const [dx, dy] of [[1, 0], [-1, 0], [0, -1], [0, 1]]) {+ const nx = x + dx, ny = y + dy;+ if (!on(nx, ny)) continue;+ const j = ny * W + nx, w = (rim[j] ? 0.55 : 1) * (dy < 0 ? 1 : 1.3) + R.range(0, 1.5);+ if (dist[i] + w < dist[j]) (dist[j] = dist[i] + w), open.push(j);+ }}- 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);+ let maxD = 0;+ for (let i = 0; i < N; i++) if (dist[i] < Infinity) maxD = Math.max(maxD, dist[i]);+ const reach = new Float32Array(N), order = [];+ for (let i = 0; i < N; i++)+ if (dist[i] < Infinity) {+ reach[i] = CLIMB[0] + (CLIMB[1] - CLIMB[0]) * Math.pow(dist[i] / maxD, 0.85);+ order.push(i);}+ order.sort((a, b) => reach[a] - reach[b]);+ // rime feathers: little ticks of frost standing out from the outline once the frost has passed+ const feathers = [];+ for (const i of order) {+ const x = i % W, y = (i / W) | 0;+ if (!rim[i] || rand(i, o.seed, 3) > 0.42 || y > H - 3) continue;+ const dx = !on(x - 1, y) ? -1 : !on(x + 1, y) ? 1 : rand(i, 9) < 0.5 ? -1 : 1, dy = !on(x, y - 1) ? -1 : rand(i, 4) < 0.5 ? -1 : 0;+ feathers.push({ x: A.x + x + dx, y: A.y + y + dy, dx, dy, L: 1 + Math.floor(rand(i, 7) * 2.6), at: reach[i] + 0.04 });}- // 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]);++ // ---- the block: which pane every pixel belongs to, the panes' looks, the edges they share+ const fid = new Int8Array(BW * (Y1 - Y0)).fill(-1), inBlock = (x, y) => inPoly(OUTLINE, x, y);+ for (let y = Y0; y < Y1; y++)+ for (let x = X0; x < X1; x++) {+ if (!inBlock(x + 0.5, y + 0.5)) continue;+ let f = FACETS.findIndex((F) => inPoly(F.pts, x + 0.5, y + 0.5));+ if (f < 0) f = FACETS.reduce((b, F, k) => (Math.hypot(centroid(F.pts).x - x, centroid(F.pts).y - y) < Math.hypot(centroid(FACETS[b].pts).x - x, centroid(FACETS[b].pts).y - y) ? k : b), 0);+ fid[(y - Y0) * BW + (x - X0)] = f;+ }+ const at = (x, y) => (x < X0 || x >= X1 || y < Y0 || y >= Y1 ? -1 : fid[(y - Y0) * BW + (x - X0)]);+ for (const F of FACETS) {+ F.c = centroid(F.pts);+ F.tint = C[3 + Math.round(F.lit * 3)];+ F.alpha = 0.2 + 0.24 * F.lit;+ F.d = clamp((F.c.x + 0.55 * F.c.y + 36) / 46);+ F.len = F.pts.reduce((s, q, k) => s + Math.hypot(F.pts[(k + 1) % F.pts.length][0] - q[0], F.pts[(k + 1) % F.pts.length][1] - q[1]), 0);+ }+ // every edge once: its ends, the panes it borders, whether it's on the outline and how it faces the light+ const EDGES = [];+ for (const F of FACETS)+ F.pts.forEach((a, k) => {+ const b = F.pts[(k + 1) % F.pts.length];+ let e = EDGES.find((e) => (e.a === a && e.b === b) || (e.a === b && e.b === a));+ if (!e) EDGES.push((e = { a, b, fs: [] }));+ e.fs.push(F);});- p.glow(0, -12, 30, I[5], 0.45 * (1 - seg(b, 0, 0.35)));+ for (const e of EDGES) {+ const [x0, y0] = e.a, [x1, y1] = e.b, c = e.fs[0].c;+ let nx = y1 - y0, ny = x0 - x1;+ if (nx * ((x0 + x1) / 2 - c.x) + ny * ((y0 + y1) / 2 - c.y) < 0) (nx = -nx), (ny = -ny);+ e.outer = e.fs.length === 1;+ e.lit = (-nx * 0.55 - ny * 0.84) / Math.hypot(nx, ny);+ e.floor = y0 === 0 && y1 === 0;+ e.at = Math.min(...e.fs.map((F) => F.at));}- p.glow(0, -12, 24, I[4], 0.15 * seg(t, 0.4, 0.6) * (1 - seg(t, BREAK, BREAK + 0.2)));+ const VERTS = Object.values(V);+ const cracks = fractures(R, (x, y) => inBlock(x, y), CORE[0], CORE[1], 3, { len: 9, a0: -2.2, spread: 3.6 });+ const cracks2 = fractures(R, (x, y) => inBlock(x, y), CORE[0] + 1, CORE[1] - 2, 6, { len: 16, fork: 0.22 });++ let t = 0, formed = 0, sealed = false, struck = 0, burst = false, white = false;+ const jolt = () => (t >= CRACK && t < CRACK + 0.06 ? 1 : t >= CRACK2 && t < FLASH ? (Math.floor(t * 40) % 2 ? 1 : -1) : 0);++ // the frozen character: each pixel turns as the frost reaches it, white at the front; after the burst the+ // ice runs off it from the top down+ const drawCharacter = (p) => {+ const thaw = t >= BURST ? ease.inQuad(seg(t, BURST, BURST + THAW)) * (H + 2) - 2 : -1;+ for (const i of order) {+ const age = t - reach[i];+ if (age < 0) break;+ const x = i % W, y = (i / W) | 0;+ if (y < thaw) continue;+ p.px(A.x + x, A.y + y, y < thaw + 1.2 && t >= BURST ? C[7] : age < 0.016 ? WHITE : age < 0.045 ? C[6] : ice[i]);+ if (age < 0.03) p.light(A.x + x, A.y + y, C[6], 0.3);+ }+ if (t >= BURST) return;+ for (const f of feathers) {+ const g = clamp((t - f.at) / 0.08);+ if (g <= 0) continue;+ const L = Math.round(f.L * g);+ for (let j = 0; j < L; j++) p.px(f.x + f.dx * j, f.y + f.dy * j, j === L - 1 ? WHITE : C[6]);+ }+ };++ // the block: panes fill in as they crystallize (edges traced in white, a white flash, then glassy), a light+ // sweep that breaks at every facet, cracks, the white frame before it bursts+ const drawBlock = (p) => {+ if (t >= BURST || t < SEAL - 0.08) return;+ const jx = jolt(), wh = t >= FLASH;+ // light slides across the block: each facet flashes whole as the light passes it, the lit ones brightest+ for (const F of FACETS) F.g = SWEEPS.reduce((g, s0) => Math.max(g, Math.sin(Math.PI * clamp((t - s0 - F.d * 0.32) / 0.13))), 0) * (0.35 + 0.65 * F.lit);+ for (let y = Y0; y < Y1; y++)+ for (let x = X0; x < X1; x++) {+ const f = at(x, y);+ if (f < 0) continue;+ const F = FACETS[f], age = t - F.at;+ if (age < 0) continue;+ if (wh) {+ p.px(x + jx, y, WHITE);+ continue;+ }+ if (age < 0.03) {+ p.blend(x + jx, y, C[7], 0.55);+ continue;+ }+ const fresh = 1 - clamp((age - 0.03) / 0.1), g = F.g;+ p.blend(x + jx, y, fresh > 0.5 || g > 0.5 ? C[6] : F.tint, F.alpha + 0.25 * fresh + 0.15 * g);+ if (g > 0.05) p.light(x + jx, y, C[5], 0.42 * g);+ }+ // edges: the outline lit where it faces up and left, cool on the shadow side with a deep rim outside it;+ // inner edges pale; any pane that has just set rings white+ for (const e of EDGES) {+ if (e.floor || t < e.at) continue;+ const [x0, y0] = e.a, [x1, y1] = e.b, fresh = e.fs.some((F) => t - F.at < 0.1 || F.g > 0.6);+ if (e.outer && e.lit < 0 && !wh) p.line(x0 + jx + 1, y0, x1 + jx + 1, y1, C[1]);+ if (e.outer) p.glowLine(x0 + jx, y0, x1 + jx, y1, 5, C[4], 0.1);+ p.line(x0 + jx, y0, x1 + jx, y1, wh ? C[6] : fresh ? WHITE : e.outer ? (e.lit > 0.3 ? WHITE : e.lit > -0.2 ? C[6] : C[4]) : (y0 + y1) / 2 < -30 ? C[6] : C[5]);+ }+ // a pane about to set: its edges traced in white from its first corner round, a bead of light at the head+ for (const F of FACETS) {+ const age = t - F.at;+ if (age < -0.07 || age >= 0) continue;+ let left = ((age + 0.07) / 0.07) * F.len;+ for (let k = 0; k < F.pts.length && left > 0; k++) {+ const [x0, y0] = F.pts[k], [x1, y1] = F.pts[(k + 1) % F.pts.length], L = Math.hypot(x1 - x0, y1 - y0), v = Math.min(1, left / L);+ left -= L;+ p.line(x0 + jx, y0, x0 + jx + (x1 - x0) * v, y0 + (y1 - y0) * v, WHITE);+ if (v < 1) p.glow(x0 + jx + (x1 - x0) * v, y0 + (y1 - y0) * v, 6, C[6], 0.6);+ }+ }+ if (t >= CRACK && !wh) drawFractures(p, cracks, (t - CRACK) * 150, C, { ox: jx });+ if (t >= CRACK2 && !wh) drawFractures(p, cracks2, (t - CRACK2) * 190, C, { ox: jx });+ };++ return {+ update(dt) {+ t += dt;+ // frost lines race in along the floor from both sides, vapour riding them+ if (t < SNAP)+ for (const s of [-1, 1]) {+ const x = s * REACH * (1 - t / SNAP);+ if (R.chance(0.12)) ps.spawn(P.VAPOUR, x, -R.range(0, 2), -s * R.range(40, 90), -R.range(0, 5), R.range(0.3, 0.5), C[6], R.range(1.4, 2.4));+ if (R.chance(0.45)) ps.spawn(P.STREAK, x + s * R.range(0, 6), -R.range(1, 4), -s * R.range(50, 90), 0, R.range(0.1, 0.16), R.chance(0.5) ? C[6] : C[5]);+ }+ // stars and motes kicked off the climbing front+ if (t > CLIMB[0] && t < CLIMB[1] + 0.03) {+ let lo = 0;+ while (lo < order.length && reach[order[lo]] < t - 0.06) lo++;+ let hi = lo;+ while (hi < order.length && reach[order[hi]] <= t) hi++;+ if (hi > lo && R.chance(0.45)) {+ const i = order[R.int(lo, hi - 1)];+ ps.spawn(P.STAR, A.x + (i % W) + 0.5, A.y + ((i / W) | 0), R.range(-8, 8), -R.range(0, 18), R.range(0.2, 0.42), R.chance(0.5) ? C[6] : WHITE, R.range(0.6, 1.9));+ }+ if (hi > lo && R.chance(0.12)) {+ const i = order[R.int(lo, hi - 1)];+ ps.spawn(P.FLAKE, A.x + (i % W), A.y + ((i / W) | 0), R.range(-20, 20), -R.range(10, 30), R.range(0.5, 0.9), C[6], R.range(0.5, 1.2));+ }+ }+ // each pane snaps into place with a chip of shards, a puff and a glint+ while (formed < FACETS.length && t >= FACETS[formed].at) {+ const F = FACETS[formed++], c = centroid(F.pts);+ for (let i = 0; i < 3; i++) {+ const a = Math.atan2(c.y - CORE[1], c.x - CORE[0]) + R.range(-0.7, 0.7), sp = R.range(50, 120);+ bits.add({ kind: B.SHARD, x: c.x, y: c.y, vx: Math.cos(a) * sp, vy: Math.sin(a) * sp - 40, g: 0.8, drag: 0.8, bounce: 0.3, life: R.range(0.35, 0.7), a: R.range(0, TAU), va: R.range(-18, 18), s: R.range(1, 2.2), c: C[R.int(5, 7)] });+ }+ if (c.y > -14) ps.spawn(P.VAPOUR, c.x, -1, Math.sign(c.x || 1) * R.range(10, 30), -R.range(2, 8), R.range(0.5, 0.8), C[6], R.range(2.2, 3.4));+ ps.spawn(P.STAR, c.x + R.range(-2, 2), c.y + R.range(-2, 2), 0, -4, R.range(0.25, 0.45), WHITE, R.range(1.2, 2.2));+ lights.add(c.x, c.y, 16, C[6], 0.4, 0.12);+ }+ if (!sealed && formed === FACETS.length) {+ sealed = true;+ lights.add(0, -26, 70, C[5], 0.6, 0.4);+ for (let i = 0; i < 5; i++) ps.spawn(P.STAR, R.range(-15, 15), -R.range(6, 44), R.range(-6, 6), -R.range(0, 8), R.range(0.3, 0.6), R.chance(0.5) ? WHITE : C[6], R.range(1, 2.2));+ }+ // while it holds: glints wink on the corners, cold vapour rolls off the foot, a little snow+ if (sealed && t < CRACK2) {+ if (R.chance(0.035)) {+ const [x, y] = R.pick(VERTS);+ ps.spawn(P.STAR, x + R.range(-1, 1), y + R.range(-1, 1), 0, -2, R.range(0.3, 0.6), R.chance(0.6) ? C[6] : WHITE, R.range(0.8, 2.2));+ }+ if (R.chance(0.025)) {+ const s = R.sign();+ ps.spawn(P.VAPOUR, s * R.range(12, 18), -R.range(1, 3), s * R.range(8, 24), -R.range(1, 5), R.range(0.7, 1.1), C[6], R.range(1.8, 3));+ }+ if (R.chance(0.012)) ps.spawn(P.FLAKE, R.range(-30, 30), -R.range(56, 76), R.range(-4, 4), R.range(4, 10), R.range(1.2, 1.8), R.chance(0.5) ? WHITE : C[6], R.range(0.5, 1.4));+ }+ // it cracks: a jolt, chips spall off, light leaks from the cracks+ if (struck === 0 && t >= CRACK) {+ struck = 1;+ lights.add(CORE[0], CORE[1], 26, WHITE, 0.4, 0.1);+ for (let i = 0; i < 4; i++) bits.add({ kind: B.SHARD, x: R.range(-14, 14), y: -R.range(10, 40), vx: R.range(-40, 40), vy: -R.range(10, 60), g: 0.9, drag: 0.6, bounce: 0.3, life: R.range(0.5, 0.9), a: R.range(0, TAU), va: R.range(-20, 20), s: R.range(1, 2), c: C[R.int(5, 7)] });+ }+ if (struck === 1 && t >= CRACK2) {+ struck = 2;+ lights.add(CORE[0], CORE[1], 40, C[6], 0.35, 0.16);+ for (let i = 0; i < 3; i++) ps.spawn(P.STAR, R.range(-12, 12), -R.range(8, 40), 0, -3, R.range(0.15, 0.3), WHITE, R.range(1, 2));+ }+ if (!white && t >= FLASH) {+ white = true;+ lights.add(CORE[0], CORE[1], 60, WHITE, 0.9, 0.1);+ }+ // it bursts: the panes fly off tumbling, shards and ice dust, glints, a flurry, a flash of light+ if (!burst && t >= BURST) {+ burst = true;+ lights.add(CORE[0], CORE[1], 64, WHITE, 0.85, 0.14);+ lights.add(CORE[0], CORE[1] - 4, 72, C[4], 0.55, 0.6);+ const chop = (pts, depth) => {+ const c = centroid(pts);+ return c.area < 20 || depth > 2 ? [pts] : splitPoly(pts, c.x, c.y, R.range(0, Math.PI)).flatMap((q) => chop(q, depth + 1));+ };+ for (const F of FACETS) {+ for (const part of chop(F.pts, 0)) {+ const m = centroid(part), dx = m.x - CORE[0], dy = m.y - CORE[1], d = Math.hypot(dx, dy) || 1, sp = R.range(40, 85) * (1.2 - Math.min(0.5, m.area / 120));+ panes.add({+ pts: part.map(([x, y]) => [x - m.x, y - m.y]), x: m.x, y: m.y, vx: (dx / d) * sp + R.range(-15, 15), vy: (dy / d) * sp * 0.6 - R.range(90, 190),+ a: 0, va: R.range(-9, 9), f: R.range(-0.8, 0.8), vf: R.sign() * R.range(5, 13), lit: F.lit, g: 0.85, drag: 0.7, brittle: true, life: R.range(1, 1.45),+ });+ }+ }+ for (let i = 0; i < 50; i++) {+ let x = 0, y = 0;+ for (let k = 0; k < 12 && at(x, y) < 0; k++) (x = R.int(X0, X1 - 1)), (y = R.int(Y0, Y1 - 1));+ const dx = x - CORE[0], dy = y - CORE[1], d = Math.hypot(dx, dy) || 1, sp = R.range(50, 130);+ bits.add({ kind: B.SHARD, x, y, vx: (dx / d) * sp, vy: (dy / d) * sp * 0.7 - R.range(60, 170), g: 0.85, drag: 0.9, bounce: 0.3, life: R.range(0.8, 1.4), a: R.range(0, TAU), va: R.range(-22, 22), s: R.range(1.5, 3.2), c: C[R.int(4, 7)] });+ }+ for (const f of feathers)+ if (R.chance(0.5)) bits.add({ kind: B.SHARD, x: f.x, y: f.y, vx: f.dx * R.range(20, 70), vy: -R.range(20, 90), g: 0.8, drag: 0.8, bounce: 0.3, life: R.range(0.4, 0.8), a: R.range(0, TAU), va: R.range(-20, 20), s: R.range(1, 1.8), c: WHITE });+ for (let i = 0; i < 12; i++) {+ const s = R.sign();+ ps.spawn(P.VAPOUR, s * R.range(2, 16), -R.range(1, 6), s * R.range(30, 90), -R.range(4, 16), R.range(0.6, 1.1), C[6], R.range(2.2, 4));+ }+ for (let i = 0; i < 8; i++) ps.spawn(P.VAPOUR, R.range(-14, 14), -R.range(8, 40), R.range(-30, 30), -R.range(10, 30), R.range(0.6, 1), C[6], R.range(3, 5));+ for (let i = 0; i < 18; i++) {+ const a = R.range(-Math.PI, 0), sp = R.range(40, 130);+ ps.spawn(P.FLAKE, R.range(-10, 10), CORE[1] + R.range(-12, 12), Math.cos(a) * sp, Math.sin(a) * sp, R.range(1, 1.5), R.chance(0.6) ? WHITE : C[6], R.range(0.5, 1.6));+ }+ for (let i = 0; i < 7; i++) ps.spawn(P.STAR, R.range(-26, 26), -R.range(6, 52), R.range(-12, 12), -R.range(4, 16), R.range(0.4, 0.8), R.chance(0.5) ? WHITE : C[6], R.range(1, 2.4));+ }+ // glints wink on the debris as it settles+ if (burst && t < BURST + 0.9 && R.chance(0.07)) {+ const b = R.pick(bits.list.length ? bits.list : [{ x: 0, y: -10 }]);+ ps.spawn(P.STAR, b.x, b.y - 1, 0, -3, R.range(0.2, 0.4), R.chance(0.5) ? WHITE : C[6], R.range(0.6, 1.6));+ }+ // the last of the ice runs off the character+ if (burst && t < BURST + THAW && R.chance(0.12)) {+ const y = -H + ease.inQuad(seg(t, BURST, BURST + THAW)) * H;+ bits.add({ kind: B.DRIP, x: R.range(-9, 9), y, vy: 10, g: 0.5, life: 0.8, c: C[5] });+ }+ ps.update(dt);+ bits.update(dt);+ panes.update(dt);+ lights.update(dt);+ endBy(t, meta.duration, ps, bits, panes);+ },+ drawBack(p) {+ const out = 1 - smooth(MELT[0], MELT[1], t);+ if (out > 0) floorFrost(p, C, t, out);+ ps.draw(p, "back");+ },+ draw(p) {+ drawCharacter(p);+ drawBlock(p);+ // the cold light: a pool under the ice, a glow in it that brightens as it cracks, the climbing front's light+ const hold = smooth(CLIMB[0], SEAL, t) * (1 - smooth(BURST, BURST + 0.6, t)), crk = smooth(CRACK, FLASH, t);+ if (hold > 0) {+ p.glow(0, -2, 34, C[4], 0.22 * hold * (0.85 + 0.15 * Math.sin(t * 3)));+ p.glow(CORE[0], CORE[1] - 4, 40, C[3], (0.22 + 0.1 * crk) * hold);+ }+ if (t > CLIMB[0] && t < CLIMB[1]) p.glow(0, -38 * ease.outQuad(seg(t, CLIMB[0], CLIMB[1])), 18, C[5], 0.28);+ // the seal: a star at the crown as the last pane sets+ const top = FACETS[FACETS.length - 1].at, g = t - top;+ if (g > 0 && g < 0.3) sparkle(p, V.p2[0], V.p2[1], 8 * ease.outBack(Math.min(1, g / 0.06)) * (1 - g / 0.3), C[6], C[4], 0.6);+ if (t >= FLASH && t < BURST + 0.16) {+ const a = clamp((t - FLASH) / 0.22);+ flare(p, CORE[0], CORE[1], 34 * Math.pow(1 - a, 1.4), 1 - a, C);+ }+ panes.draw(p, C);+ bits.draw(p);+ ps.draw(p, "front");+ lights.draw(p);+ },+ };}diff --git a/src/fx/ice/frost-breath.js b/src/fx/ice/frost-breath.jsindex 1db432c..0afac88 100644--- a/src/fx/ice/frost-breath.js+++ b/src/fx/ice/frost-breath.js@@ -1,60 +1,106 @@-import { PAL, cycle, rng, seg, ease, wrap, noise2, TAU, WHITE } from "../../core/index.js";-import { fit, glint } from "./_lib.js";+// Soft puffs drawn as a body, a denser core and a lit cap, and streaks with a hot head and a cool tail, follow+// the recipes in Sprite Fusion's open-source pixel art VFX (https://www.spritefusion.com/pixel-art-vfx),+// MIT License, Copyright (c) 2026 Hugo Duprez.+import { fit, cycle, fly, flyV, loopNoise, tileFbm, clamp, TAU, WHITE, mix } from "../../core/index.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.",+ desc: "A cone of icy wind blowing right: frost puffs billow out, swell and sink, wind streaks race through, ice crystals tumble and glint off a white-hot mouth.",tags: ["ice", "breath", "frost", "cone", "wind", "directional", "loop"],- size: [104, 44],- origin: [4, 22],- duration: 1,+ size: [184, 104],+ origin: [12, 50],+ duration: 1.2,loop: true,fps: 30,bg: "dark",- options: { palette: PAL.ice, length: 92, spread: 0.2, seed: 27 },+ options: { palette: ["#151a3d", "#212f6b", "#2c58aa", "#3a8bd8", "#62c8f4", "#a6ecff", "#dcfbff", "#ffffff"], spread: 0.21, power: 1, seed: 11 },};+const SINK = 9; // cold air is heavy: it sags a little as it slows++// a puff of frost: a soft body, a denser core sitting low, a lit cap while it's young, a cold haze of light+function puff(p, C, x, y, r, a, k, front) {+ const body = front ? C[5] : C[4], cap = front ? C[7] : C[6], soft = (q) => (d) => q * (1 - d * d);+ p.disc(x, y, r, body, soft(a * 0.6));+ p.disc(x + r * 0.06, y + r * 0.12, r * 0.68, mix(body, C[3], 0.3), soft(a * 0.5));+ if (k < 0.55) p.disc(x - r * 0.25, y - r * 0.3, r * 0.5, cap, soft(a * 0.7 * (1 - k / 0.55)));+ p.glow(x, y, r * 1.7, C[4], 0.1 * a);+}++// the body of the gust: a cone of turbulent, translucent cold air streaming right, brightest at its heart.+// The noise scrolls exactly one tile per loop, so it never seams.+function gust(p, C, t, o) {+ const ph = t / meta.duration, sp = Math.tan(o.spread) * 1.08, S = o.seed;+ p.each(2, -46, 170, 46, (x, y, sx, sy) => {+ const u = x / 170, hw = 2.5 + x * sp, yc = 7 * u * u, v = (y - yc) / hw;+ if (v * v >= 1 || u >= 1) return;+ const n = tileFbm(x * 0.055 - ph * 10, (y - yc) * 0.15 + 7, 10, 0, S, 2), edge = (1 - v * v) * (u < 0.08 ? u / 0.08 : 1) * (1 - u) ** 0.8;+ // denser and brighter down its heart near the mouth+ const d = clamp(0.5 + n * 1.3 + (1 - Math.abs(v)) * 0.35 * (1 - u) ** 1.5) * edge;+ if (d < 0.08) return;+ p.blendPx(sx, sy, d > 0.72 ? C[7] : d > 0.52 ? C[6] : d > 0.32 ? C[5] : C[4], Math.min(0.78, d * 0.95) * clamp((d - 0.08) / 0.3));+ if (d > 0.3) p.add(sx, sy, d > 0.6 ? C[6] : C[5], 0.2 * d);+ });+}++export function drawBack(p, t, o) {+ const C = fit(o.palette, 8), D = meta.duration, S = o.seed, sp = o.spread;+ gust(p, C, t, o);+ // the big slow billows behind+ cycle(t, D, 12, S, (g) => g.range(1, 1.25), (age, life, r) => {+ const th = r.range(-sp, sp), v = r.range(170, 230) * o.power, [x, y] = fly(3, r.range(-1, 1), v * Math.cos(th), v * Math.sin(th), age, SINK, 1.4);+ const k = age / life, rad = 2 + 12 * Math.pow(k, 0.75);+ puff(p, C, x, Math.min(y, 40 - rad), rad, 0.75 * Math.pow(1 - k, 1.2) * Math.min(1, age / 0.08), k, false);+ });+}+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];+ const C = fit(o.palette, 8), D = meta.duration, S = o.seed, sp = o.spread, ph = t / D;+ // light down the cone+ p.glowLine(4, 0, 120, 6, 24, C[4], 0.26);+ p.glowLine(2, 0, 50, 1, 9, C[6], 0.3);+ p.glow(60, 4, 44, C[3], 0.16);+ // brighter puffs in front, smaller and quicker+ cycle(t, D, 10, S + 1, (g) => g.range(0.7, 0.95), (age, life, r) => {+ const th = r.range(-sp * 0.8, sp * 0.8), v = r.range(190, 260) * o.power, [x, y] = fly(3, r.range(-1, 1), v * Math.cos(th), v * Math.sin(th), age, SINK, 1.6);+ const k = age / life, rad = 1.5 + 8 * Math.pow(k, 0.7);+ puff(p, C, x, Math.min(y, 40 - rad), rad, 0.85 * Math.pow(1 - k, 1.3) * Math.min(1, age / 0.06), k, true);+ });+ // snow carried along, swaying+ cycle(t, D, 18, S + 2, (g) => g.range(0.8, 1.1), (age, life, r) => {+ const th = r.range(-sp * 1.1, sp * 1.1), v = r.range(120, 190), [x, y] = fly(4, 0, v * Math.cos(th), v * Math.sin(th), age, SINK * 1.4, 1.5);+ const k = age / life, sw = Math.sin(age * 9 + r.range(0, TAU)) * 1.5;+ if (k < 0.85 || (age * 30) % 2 < 1) p.px(x, y + sw, r.chance(0.5) ? WHITE : C[6]);});- // 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]);+ // wind streaks: a white head, a pale body, a cool tail+ cycle(t, D, 26, S + 3, (g) => g.range(0.22, 0.36), (age, life, r) => {+ const th = r.range(-sp * 0.9, sp * 0.9), v = r.range(280, 380), [x, y] = fly(6, r.range(-2, 2), v * Math.cos(th), v * Math.sin(th), age, 0, 0.9);+ const [vx, vy] = flyV(v * Math.cos(th), v * Math.sin(th), age, 0, 0.9), s = Math.hypot(vx, vy), L = 4 + s * 0.03, ux = vx / s, uy = vy / s, k = age / life;+ p.line(x - ux * L, y - uy * L, x, y, (u) => (u > 0.8 ? WHITE : u > 0.4 ? C[6] : C[4]), (u) => (u > 0.35 ? 1 : u / 0.35) * (k < 0.75 ? 1 : (1 - k) / 0.25));+ p.glow(x, y, 3, C[5], 0.3 * (1 - k));});- // 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]);+ // ice crystals tumbling through: a short shard with a white edge, glinting as it turns+ cycle(t, D, 9, S + 4, (g) => g.range(0.65, 0.9), (age, life, r) => {+ const th = r.range(-sp, sp), v = r.range(150, 230), [x, y] = fly(5, 0, v * Math.cos(th), v * Math.sin(th), age, SINK, 1.1);+ const k = age / life, a = r.range(0, TAU) + age * r.range(9, 15) * r.sign(), L = r.range(1.5, 2.6), ca = Math.cos(a), sa = Math.sin(a);+ if (k > 0.85 && (age * 30) % 2 < 1) return;+ p.line(x - ca * L, y - sa * L, x + ca * L, y + sa * L, C[5]);+ p.px(x + ca * L, y + sa * L, WHITE);+ const gl = Math.cos(a * 2);+ if (gl > 0.92) {+ for (const [dx, dy] of [[1, 0], [-1, 0], [0, 1], [0, -1]]) p.px(x + dx, y + dy, C[6]);+ p.px(x, y, WHITE);+ p.glow(x, y, 6, C[5], 0.5);+ } else p.glow(x, y, 3, C[5], 0.2);});- // 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);+ // the mouth: a white-hot core, a flickering jet of cold+ for (let i = 0; i < 3; i++) {+ const L = 9 + 6 * loopNoise(ph, 1.2, S + i * 7), dy = (i - 1) * 1.4;+ p.line(2, dy * 0.5, 2 + L, dy, (u) => (u < 0.5 ? WHITE : C[6]), (u) => (u < 0.6 ? 1 : 1 - (u - 0.6) / 0.4));+ }+ p.ellipse(2.5, 0, 4.6, 3, C[6]);+ p.ellipse(2, 0, 3, 1.8, WHITE);+ const fl = 0.85 + 0.15 * Math.sin(ph * TAU * 3);+ p.glow(2, 0, 24, C[5], 0.7 * fl);+ p.glow(2, 0, 9, WHITE, 0.5 * fl);}diff --git a/src/fx/ice/frozen-ground.js b/src/fx/ice/frozen-ground.jsdeleted file mode 100644index 62ac594..0000000--- a/src/fx/ice/frozen-ground.js+++ /dev/null@@ -1,60 +0,0 @@-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.jsdeleted file mode 100644index 76d6d69..0000000--- a/src/fx/ice/hail-impact.js+++ /dev/null@@ -1,71 +0,0 @@-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.jsindex 8c08e6a..cf0330c 100644--- a/src/fx/ice/ice-crystal.js+++ b/src/fx/ice/ice-crystal.js@@ -1,72 +1,124 @@-import { PAL, TAU, fract, WHITE } from "../../core/index.js";-import { fit, glint } from "./_lib.js";+// A floating pickup that bobs, glints, glows and has motes circling in front and behind follows the recipe+// in Sprite Fusion's open-source pickup gem (https://www.spritefusion.com/pixel-art-vfx/pickup),+// MIT License, Copyright (c) 2026 Hugo Duprez.+import { fit, cycle, sparkle, clamp, TAU, WHITE } from "../../core/index.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,+ desc: "A floating ice crystal turning slowly in its own cold light: its facets brighten and darken as they turn, glints flash on them, frost motes circle it.",+ tags: ["ice", "crystal", "gem", "pickup", "float", "magic", "loop"],+ size: [96, 100],+ origin: [48, 92],+ duration: 3,loop: true,fps: 30,- bg: "dark",- options: { palette: PAL.ice, size: 1.2, seed: 31 },+ bg: "ground",+ options: { palette: ["#151a3d", "#212f6b", "#2c58aa", "#3a8bd8", "#62c8f4", "#a6ecff", "#dcfbff", "#ffffff"], height: 34, seed: 21 },};-// 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); })();+const TIP = 0.28; // how far it leans toward us, so the upper facets show+const LIGHT = norm([-0.55, -0.75, -0.45]); // toward the light: upper left, in front+function norm([x, y, z]) {+ const l = Math.hypot(x, y, z) || 1;+ return [x / l, y / l, z / 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+// the crystal: a hexagonal prism with a tall point above and a shorter one below, turned by th, tipped toward+// the viewer. Returns the visible faces (projected corners, brightness, glint) and the silhouette.+function crystalFaces(th, R) {+ const ct = Math.cos(TIP), st = Math.sin(TIP);+ const P = (x, y, z) => [x, y * ct - z * st, y * st + z * ct]; // tip toward the viewer (z toward us is negative)+ const ring = (y) => Array.from({ length: 6 }, (_, k) => P(Math.cos(th + (k * TAU) / 6) * R, y, Math.sin(th + (k * TAU) / 6) * R));+ const top = ring(-R * 0.45), bot = ring(R * 0.45), A = P(0, -R * 2.2, 0), Z = P(0, R * 1.7, 0);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]);+ for (let k = 0; k < 6; k++) {+ const j = (k + 1) % 6;+ faces.push([A, top[j], top[k]], [top[k], top[j], bot[j], bot[k]], [bot[k], bot[j], Z]);}- const sweep = fract(ph * 2) * 70 - 30;+ const out = [];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]));+ const [a, b, c] = f, u = [b[0] - a[0], b[1] - a[1], b[2] - a[2]], v = [c[0] - a[0], c[1] - a[1], c[2] - a[2]];+ let n = norm([u[1] * v[2] - u[2] * v[1], u[2] * v[0] - u[0] * v[2], u[0] * v[1] - u[1] * v[0]]);+ const cx = f.reduce((s, q) => s + q[0], 0) / f.length, cy = f.reduce((s, q) => s + q[1], 0) / f.length, cz = f.reduce((s, q) => s + q[2], 0) / f.length;+ if (n[0] * cx + n[1] * cy + n[2] * cz < 0) n = n.map((q) => -q); // outward+ if (n[2] >= -0.02) continue; // facing away+ const lit = Math.max(0, n[0] * LIGHT[0] + n[1] * LIGHT[1] + n[2] * LIGHT[2]);+ // a glint where the face mirrors the light toward the viewer (half way between the light and the eye)+ const h = norm([LIGHT[0], LIGHT[1], LIGHT[2] - 1]), spec = Math.max(0, n[0] * h[0] + n[1] * h[1] + n[2] * h[2]);+ out.push({ pts: f.map((q) => [q[0], q[1]]), lit, spec, cx, cy });+ }+ return out;+}++// the convex hull of a set of points (monotone chain), for the crystal's silhouette+function hullOf(pts) {+ const P = [...pts].sort((a, b) => a[0] - b[0] || a[1] - b[1]), cross = (o, a, b) => (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0]);+ const lo = [], hi = [];+ for (const q of P) {+ while (lo.length >= 2 && cross(lo[lo.length - 2], lo[lo.length - 1], q) <= 0) lo.pop();+ lo.push(q);+ }+ for (const q of P.reverse()) {+ while (hi.length >= 2 && cross(hi[hi.length - 2], hi[hi.length - 1], q) <= 0) hi.pop();+ hi.push(q);}- // 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]);+ return lo.slice(0, -1).concat(hi.slice(0, -1));+}++export function drawBack(p, t, o) {+ const C = fit(o.palette, 8), ph = t / meta.duration, bob = Math.sin(TAU * ph) * 2.5, Y = -o.height + bob;+ // its shadow on the floor, smaller and darker as it dips, and a cold pool of light+ const s = 1 - bob / 12, rx = 11 * s;+ for (let x = Math.floor(-rx); x <= rx; x++) {+ const f = 1 - (x / rx) ** 2;+ p.blend(x + 0.5, 0, C[0], 0.65 * f);+ if (Math.abs(x) < rx * 0.6) p.blend(x + 0.5, 1, C[0], 0.4 * f);}- 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);+ p.glow(0, -1, 24, C[4], 0.2 + 0.05 * Math.sin(TAU * ph * 2));+ motes(p, C, t, o, Y, false);+}++function motes(p, C, t, o, Y, front) {+ const D = meta.duration;+ cycle(t, D, 16, o.seed, (g) => g.range(1.6, 2.6), (age, life, r, i) => {+ const th = r.range(0, TAU) + age * r.range(1.6, 2.6), R = r.range(14, 22), y = Y + r.range(-14, 12) - age * r.range(3, 7), s = Math.sin(th), k = age / life;+ if (s >= 0 !== front) return;+ const x = Math.cos(th) * R, yy = y + s * R * 0.3, a = Math.min(1, age / 0.2) * (k > 0.75 ? (1 - k) / 0.25 : 1);+ if (front) {+ p.dot(x, yy, i % 4 === 0 ? WHITE : C[6], a);+ if (i % 4 === 0) for (const [dx, dy] of [[1, 0], [-1, 0], [0, 1], [0, -1]]) p.dot(x + dx, yy + dy, C[5], a);+ p.glow(x, yy, 4, C[5], 0.3 * a);+ } else p.dot(x, yy, C[4], a * 0.9);+ });+}++export function draw(p, t, o) {+ const C = fit(o.palette, 8), ph = t / meta.duration, bob = Math.sin(TAU * ph) * 2.5, Y = -o.height + bob, R = 8;+ // its own cold light+ p.glow(0, Y, 34, C[3], 0.26);+ p.glow(0, Y, 14, C[5], 0.18 + 0.08 * Math.sin(TAU * ph * 3));+ // a sixth of a turn a loop: a hexagon looks the same after it, so the loop never seams+ const faces = crystalFaces((TAU / 6) * ph, R);+ // a dark rim round the silhouette, then the facets: deep in shadow, pale toward the light, white in a glint+ const hull = hullOf(faces.flatMap((f) => f.pts));+ let mx = 0, my = 0;+ for (const [x, y] of hull) (mx += x), (my += y);+ (mx /= hull.length), (my /= hull.length);+ p.poly(hull.map(([x, y]) => { const d = Math.hypot(x - mx, y - my) || 1; return [x + ((x - mx) / d) * 1.2, y + Y + ((y - my) / d) * 1.2]; }), C[1]);+ for (const f of faces) {+ const c = f.spec > 0.985 ? WHITE : C[clamp(Math.round(1 + Math.pow(f.lit, 1.4) * 6.6), 1, 7)];+ p.poly(f.pts.map(([x, y]) => [x, y + Y]), c);+ }+ // edges: pale where two faces meet, a dark rim round the outside, a white ridge on the lit side+ for (const f of faces)+ for (let i = 0; i < f.pts.length; i++) {+ const [x0, y0] = f.pts[i], [x1, y1] = f.pts[(i + 1) % f.pts.length];+ p.line(x0, y0 + Y, x1, y1 + Y, f.lit > 0.6 ? C[7] : f.lit > 0.3 ? C[6] : C[4]);+ }+ // glints: a star flashes on a face as it turns into the light+ for (const f of faces) if (f.spec > 0.96) sparkle(p, f.cx, f.cy + Y, Math.round(2 + (f.spec - 0.96) * 150), C[6], C[4], 0.5);+ // a glint at the tip now and then+ const g = (ph * 2) % 1;+ if (g < 0.12) sparkle(p, 0, Y - R * 2.2 * Math.cos(TIP), Math.round(5 * Math.sin((g / 0.12) * Math.PI)), C[6], C[4], 0.6);+ motes(p, C, t, o, Y, true);}diff --git a/src/fx/ice/ice-lance.js b/src/fx/ice/ice-lance.jsindex fa73c76..f9541cd 100644--- a/src/fx/ice/ice-lance.js+++ b/src/fx/ice/ice-lance.js@@ -1,79 +1,98 @@-import { PAL, cycle, rng, seg, ease, wrap, noise2, fract, WHITE } from "../../core/index.js";-import { fit, glint } from "./_lib.js";+// The projectile recipe (a hot head, a trail that thins behind it, motes shed along the way, light riding the+// head) is adapted from Sprite Fusion's open-source energy bolt (https://www.spritefusion.com/pixel-art-vfx/energy),+// MIT License, Copyright (c) 2026 Hugo Duprez.+import { fit, cycle, fly, clamp, TAU, WHITE } from "../../core/index.js";+import { blade } 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,+ desc: "A faceted ice spear flying right: a light pulse runs through its core, rings of cold air shear off the tip, frost peels off into a wake and crystals shed behind it.",+ tags: ["ice", "lance", "spear", "projectile", "directional", "magic", "loop"],+ size: [176, 64],+ origin: [146, 32],+ duration: 0.8,loop: true,fps: 30,bg: "dark",- options: { palette: PAL.ice, seed: 28 },+ options: { palette: ["#151a3d", "#212f6b", "#2c58aa", "#3a8bd8", "#62c8f4", "#a6ecff", "#dcfbff", "#ffffff"], length: 40, seed: 13 },};-const TIP = 6, NECK = -8, TAIL = -28;+// the spear: a hexagonal shaft seen from the side, row by row (a white top edge, a lit upper facet, a bright+// ridge, a cool lower facet, a deep keel, a dark rim), a long cutting point, a light pulse running through+// its ridge to the tip, a glint sliding back along the top+function spear(p, C, L, pulse, glint) {+ const T = 16, H = 3.5;+ const half = (x) => (x > -T ? H * (-x / T) + 0.3 : x < -L + 3 ? H * (0.7 + 0.3 * ((x + L) / 3)) : H);+ p.shade(-L - 1, -H - 2, 1, H + 2, (x, y, o) => {+ if (x > 0 || x < -L) return;+ const h = half(x);+ if (Math.abs(y) > h + 0.5) {+ if (Math.abs(y) < h + 1.5) o.c = C[1];+ return;+ }+ const v = y / Math.max(0.5, h);+ if (x > -1.5) return (o.c = WHITE);+ // three faces lit from above: a pale top facet, a mid front facet with a bright ridge, a deep underside+ if (v > -0.3 && v < 0.35 && Math.abs(x - pulse) < 2.5) return (o.c = WHITE);+ if (v < -0.3 && Math.abs(x - glint) < 1) return (o.c = WHITE);+ o.c = v < -0.72 ? WHITE : v < -0.36 ? C[6] : v < -0.18 ? C[7] : v < 0.38 ? C[4] : v < 0.78 ? C[2] : C[1];+ });+}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];+ const C = fit(o.palette, 8), D = meta.duration, S = o.seed, L = o.length, ph = t / D;+ // the wake: a ribbon of frost narrowing behind the spear, with cold light in it+ p.each(-L - 100, -12, -L + 4, 12, (x, y, sx, sy) => {+ const u = (-L + 4 - x) / 104, w = 4.5 * (1 - u) ** 0.7 + 0.5 + 1.5 * Math.sin(u * 9 - ph * TAU * 2) * u, v = Math.abs(y) / w;+ if (v >= 1) return;+ const a = (1 - v * v) * (1 - u) ** 1.4;+ if (a < 0.04) return;+ p.blendPx(sx, sy, v < 0.25 && u < 0.4 ? C[6] : v < 0.6 ? C[5] : C[4], a * 0.7);+ if (a > 0.3) p.add(sx, sy, C[5], 0.12 * a);});- // 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]);+ p.glowLine(-L - 60, 0, 0, 0, 14, C[4], 0.22);+ // frost peeling off the shaft into soft puffs left behind+ cycle(t, D, 14, S, (g) => g.range(0.35, 0.55), (age, life, r) => {+ const x0 = r.range(-L + 2, -8), [x, y] = fly(x0, r.range(-2.5, 2.5), -r.range(150, 230), r.sign() * r.range(8, 30), age, 0, 2.2);+ const k = age / life, rad = 1.2 + 5.5 * k, a = 0.5 * (1 - k) ** 1.3;+ p.disc(x, y, rad, k < 0.3 ? C[6] : C[5], (d) => a * (1 - d * d));+ p.glow(x, y, rad * 1.6, C[4], 0.1 * (1 - k));});- // 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]);+ // crystals shed along the way: short tumbling shards with a white edge, glinting, falling back+ cycle(t, D, 9, S + 1, (g) => g.range(0.4, 0.6), (age, life, r) => {+ const [x, y] = fly(r.range(-L, -6), r.range(-3, 3), -r.range(170, 260), r.range(-35, 35), age, 60, 1.2);+ const k = age / life, a = r.range(0, TAU) + age * r.range(10, 18) * r.sign(), l = r.range(1.2, 2.2), ca = Math.cos(a), sa = Math.sin(a);+ if (k > 0.85 && (age * 30) % 2 < 1) return;+ p.line(x - ca * l, y - sa * l, x + ca * l, y + sa * l, C[5]);+ p.px(x + ca * l, y + sa * l, WHITE);+ if (Math.cos(a * 2) > 0.9) {+ for (const [dx, dy] of [[1, 0], [-1, 0], [0, 1], [0, -1]]) p.px(x + dx, y + dy, C[6]);+ p.glow(x, y, 6, C[5], 0.45);+ }});- // 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];+ // speed lines: the air streaming past above and below+ cycle(t, D, 12, S + 2, (g) => g.range(0.16, 0.26), (age, life, r) => {+ const y = r.sign() * r.range(4, 13), x = r.range(-20, 0) - age * r.range(280, 380), l = r.range(6, 16), k = age / life;+ p.line(x, y, x + l, y, (u) => (u > 0.7 ? C[6] : C[4]), (u) => u * (1 - k) * 1.4);});- // 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);+ // rings of cold air shearing off the point and sliding back along the shaft: the near arc bright, the far dim+ for (let i = 0; i < 3; i++) {+ const q = (ph * 3 + i / 3) % 1, x = -4 - q * (L + 20), ry = 4.5 + q * 8, rx = 1.2 + q * 2.6;+ if (q > 0.8) continue;+ for (let k = 0; k < 40; k++) {+ const an = (k / 40) * TAU, px = x + Math.cos(an) * rx, py = Math.sin(an) * ry;+ if (Math.abs(py) < 4.6 && px > -L - 2) continue;+ p.px(px, py, Math.cos(an) > 0 ? (q < 0.35 ? WHITE : C[6]) : q < 0.4 ? C[5] : C[4]);+ }+ p.glowRing(x, 0, ry * 0.75, 3, C[5], 0.14 * (1 - q));+ }+ // the ice fletching at the back: three shards fanning out behind the shaft+ for (const [dy, l, w] of [[-1, 10, 4], [1, 9, 4], [-0.2, 6, 3]]) blade(p, -L + 3, dy * 1.5, -L + 3 - l, dy * (2 + l * 0.5), w, C);+ // the spear itself, a pulse of light running through it, a glint sliding back along the top+ const pulse = -L + ((ph * 2) % 1) * (L + 6), glint = -((ph * 2 + 0.5) % 1) * L * 1.2;+ spear(p, C, L, pulse, glint);+ p.glowLine(-L, 0, 0, 0, 10, C[4], 0.1);+ p.glow(pulse, 0, 8, C[6], 0.3);+ p.glow(0, 0, 8, WHITE, 0.4);+ p.glow(-L * 0.4, 0, 30, C[3], 0.16);}diff --git a/src/fx/ice/ice-shatter.js b/src/fx/ice/ice-shatter.jsindex 0605744..0167dbb 100644--- a/src/fx/ice/ice-shatter.js+++ b/src/fx/ice/ice-shatter.js@@ -1,79 +1,237 @@-import { PAL, burst, rng, seg, ease, bolt, TAU, WHITE } from "../../core/index.js";-import { fit, shard, shardPts, glint } from "./_lib.js";+// The crack-and-burst recipe (cracks walking out from the point of impact, a white frame, the ice flung apart+// as shards with ice dust and glints) is adapted from Sprite Fusion's open-source ice+// (https://www.spritefusion.com/pixel-art-vfx/ice), MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Bits, Lights, P, B, Rng, fit, sparkle, flare, clamp, smooth, seg, ease, rand, TAU, WHITE } from "../../core/index.js";+import { Panes, endBy, inPoly, centroid, splitPoly, fractures, drawFractures } 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,+ desc: "A block of ice takes a hit from the left: it jolts, cracks race over its faces, it flashes white and bursts into chunks that tumble, bounce and skid off in a roll of ice dust.",+ tags: ["ice", "shatter", "break", "destroy", "impact", "directional", "one-shot"],+ size: [224, 112],+ origin: [68, 90],+ duration: 2.8,loop: false,fps: 30,bg: "ground",- options: { palette: PAL.ice, size: 1, seed: 24 },+ options: { palette: ["#151a3d", "#212f6b", "#2c58aa", "#3a8bd8", "#62c8f4", "#a6ecff", "#dcfbff", "#ffffff"], seed: 6 },};-const BREAK = 0.2, G = 420, BW = 8, BH = 15, D = 4; // block half-width, height, depth of its top face+const HIT = 0.26, CRACK2 = 0.4, SHIVER = 0.54, FLASH = 0.62, BURST = 0.68;+// the block, seen from the front and a little above: a front face, a top, a side in shadow+const FRONT = [[-16, 0], [-16, -28], [12, -28], [12, 0]];+const TOP = [[-16, -28], [-8, -34], [20, -34], [12, -28]];+const SIDE = [[12, 0], [12, -28], [20, -34], [20, -6]];+const SIL = [[-16, 0], [-16, -28], [-8, -34], [20, -34], [20, -6], [12, 0]];+const HIT_AT = [-16, -15];+const PLANE = [[-16, -21], [-5, -28], [3, -13], [-16, -9]]; // a fracture plane inside, lighter+const SHADE = [[5, -28], [12, -28], [12, -10]]; // the far corner in shadow-// 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 create(o) {+ const C = fit(o.palette, 8), R = new Rng(o.seed), floor = () => 0;+ const ps = new Particles({ rng: R, ground: floor, sparks: [C[7], C[6], C[5], C[4]], haze: C[5] });+ const bits = new Bits({ ground: floor }), lights = new Lights(), scuffs = [];+ const splinter = (x, y, vx, n) => {+ for (let i = 0; i < n; i++) bits.add({ kind: B.SHARD, x: x + R.range(-2, 2), y: y - 1, vx: vx * 0.6 + R.range(-35, 45), vy: -R.range(30, 100), g: 0.8, drag: 0.6, bounce: 0.35, life: R.range(0.4, 0.8), a: R.range(0, TAU), va: R.range(-18, 18), s: R.range(1.2, 2.4), c: C[R.int(4, 7)] });+ };+ const panes = new Panes({+ ground: floor,+ onLand: (q, x, y, v) => {+ // a chunk hitting the floor: a puff of ice dust, a few splinters, sometimes a glint+ if (v < 100) return;+ ps.spawn(P.VAPOUR, x, y - 1, q.vx * 0.3 + R.range(-15, 15), -R.range(2, 10), R.range(0.4, 0.7), C[6], R.range(1.6, 2.8));+ splinter(x, y, q.vx, 2);+ if (R.chance(0.3)) ps.spawn(P.STAR, x, y - 3, 0, -5, R.range(0.2, 0.4), WHITE, R.range(0.8, 1.6));+ },+ onSkid: (q, x) => {+ // sliding chunks scuff frost onto the floor+ if (R.chance(0.5)) scuffs.push({ x: Math.round(x + R.range(-1, 1)), t: 0 });+ },+ onCrumble: (q) => {+ splinter(q.x, 0, q.vx, 3);+ ps.spawn(P.VAPOUR, q.x, -1, R.range(-10, 14), -R.range(2, 6), R.range(0.4, 0.7), C[6], R.range(1.2, 2));+ },+ });-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);+ // the ice's insides: veins of frost and trapped bubbles in the front face+ const veins = [], bubbles = [];+ for (let k = 0; k < 3; k++) {+ let x = R.range(-12, 8), y = R.range(-24, -6), a = R.range(0, TAU);+ for (let i = 0; i < 9; i++) {+ a += R.range(-0.6, 0.6);+ x += Math.cos(a) * 1.5;+ y += Math.sin(a) * 1.2;+ if (x < -14 || x > 10 || y < -26 || y > -2) break;+ veins.push([Math.floor(x), Math.floor(y)]);}- 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)));+ for (let k = 0; k < 5; k++) bubbles.push([R.int(-12, 8), R.int(-23, -4), R.chance(0.4) ? 1 : 0]);+ const inside = (x, y) => inPoly(SIL, x, y);+ const cracks = fractures(R, inside, HIT_AT[0] + 1, HIT_AT[1], 4, { len: 8, a0: -0.9, spread: 1.9 });+ const cracks2 = fractures(R, inside, HIT_AT[0] + 1, HIT_AT[1], 6, { len: 18, a0: -1.3, spread: 2.7, fork: 0.16 });++ let t = 0, struck = false, burst = false, wave2 = false, white = false;+ const jolt = () => (t >= HIT && t < HIT + 0.05 ? 2 : t >= HIT + 0.05 && t < HIT + 0.12 ? 1 : t >= SHIVER && t < FLASH ? (Math.floor(t * 40) % 2 ? 1 : 0) : 0);++ // the block: shaded faces, frost veins and bubbles inside, lit edges, a dark rim+ const drawBlock = (p) => {+ if (t >= BURST) return;+ const jx = jolt(), wh = t >= FLASH, sweep = -40 + 70 * seg(t, 0.04, 0.3);+ const sh = (pts) => pts.map(([x, y]) => [x + jx, y]);+ // rim+ p.poly(sh([[-17, 1], [-17, -28.5], [-8.3, -35.2], [21, -35.2], [21, -5.6], [12.5, 1]]), C[0]);+ if (wh) {+ p.poly(sh(SIL), WHITE);+ return;+ }+ // the front: lit at the top, deep at the foot, the far edges showing through, a fracture plane catching+ // light, reflections streaked across the upper left+ p.poly(sh(FRONT), (x, y) => {+ const lx = x - jx, d = lx + y * 0.8;+ if (Math.abs(d - sweep) < 1.3 && y < -6) return WHITE;+ if (y < -9 && (Math.abs(d + 21) < 1.1 || Math.abs(d + 16.5) < 0.6)) return C[6];+ if (((Math.abs(lx + 7.5) < 0.5 && y < -6) || (Math.abs(y + 5.5) < 0.5 && lx > -8)) && (Math.floor(lx) + Math.floor(y)) % 2 === 0) return C[5];+ if (inPoly(PLANE, lx, y)) return y < -25.5 ? C[6] : C[5];+ if (inPoly(SHADE, lx, y)) return C[3];+ return y < -25.5 ? C[5] : y < -8 ? C[4] : y < -2.5 ? C[3] : C[2];+ });+ p.poly(sh(TOP), (x, y) => (y > -29.5 ? C[7] : y < -32.5 ? C[5] : rand(Math.floor(x), Math.floor(y), 3) < 0.08 ? C[7] : C[6]));+ p.poly(sh(SIDE), (x, y) => {+ const lx = x - jx;+ return lx < 13.5 ? C[3] : Math.abs(lx - 16.5) < 0.6 && y < -8 ? C[3] : y > (lx - 12) * -0.75 - 3 ? C[1] : C[2];+ });+ for (const [x, y] of veins) p.px(x + jx, y, C[5]);+ for (const [x, y, big] of bubbles) {+ p.px(x + jx, y, C[6]);+ if (big) p.px(x + jx + 1, y, C[5]), p.px(x + jx, y + 1, C[5]);+ }+ const E = (a, b, c) => p.line(a[0] + jx, a[1], b[0] + jx, b[1], c);+ E([-16, -28], [12, -28], WHITE);+ E([-16, -28], [-8, -34], C[6]);+ E([-8, -34], [20, -34], C[5]);+ E([12, -28], [20, -34], C[7]);+ E([-16, -1], [-16, -28], C[5]);+ E([12, -1], [12, -28], C[6]);+ E([20, -6], [20, -34], C[3]);+ E([13, -1], [20, -6], C[1]);+ if (t >= HIT) drawFractures(p, cracks, (t - HIT) * 170, C, { ox: jx });+ if (t >= CRACK2) drawFractures(p, cracks2, (t - CRACK2) * 200, C, { ox: jx });+ };++ // the floor: a frost patch where the block stands, frost scuffed along by sliding chunks+ const drawFloor = (p) => {+ const out = 1 - smooth(BURST + 0.6, BURST + 1.5, t);+ if (out > 0)+ for (let x = -22; x <= 26; x++) {+ const d = Math.abs(x - 2) / 24, h = rand(x, 41), a = out * clamp((1.1 - d) / 0.25);+ if (a <= 0) continue;+ p.dot(x, 0, h < 0.35 ? WHITE : C[6], a);+ if (h < 0.4 && (x < -16 || x > 20)) p.dot(x, -1, C[5], a);+ for (let j = 1; j <= 1 + Math.round(rand(x, 7) * 3 * (1 - d)); j++) p.dot(x, j, j < 2 ? C[5] : C[4], a * (1 - j / 5));+ }+ for (const s of scuffs) {+ const a = 1 - s.t / 0.9;+ if (a > 0) p.dot(s.x, 0, s.t < 0.15 ? WHITE : C[6], a), p.dot(s.x, 1, C[4], a * 0.6);+ }+ };++ const explode = () => {+ // chunks of each face, cut at random, flung away from the hit, mostly right and up+ const chop = (pts, max, depth) => {+ const c = centroid(pts);+ return c.area < max || depth > 4 ? [pts] : splitPoly(pts, c.x + R.range(-1, 1), c.y + R.range(-1, 1), R.range(0, Math.PI)).flatMap((q) => chop(q, max, depth + 1));+ };+ for (const [face, tone, max] of [[FRONT, 0.6, 46], [TOP, 1, 40], [SIDE, 0.3, 46]])+ for (const part of chop(face, max, 0)) {+ const m = centroid(part), dx = m.x - HIT_AT[0], dy = m.y - HIT_AT[1], d = Math.hypot(dx, dy) || 1, sp = R.range(50, 150) * (0.7 + 0.3 * (1 - d / 40));+ panes.add({+ pts: part.map(([x, y]) => [x - m.x, y - m.y]), x: m.x, y: m.y, vx: (dx / d) * sp * 0.9 + R.range(40, 110), vy: (dy / d) * sp * 0.4 - R.range(60, 200),+ a: 0, va: R.range(-10, 10), f: R.range(-0.9, 0.9), vf: R.range(-7, 7), tone, lit: tone, g: 0.9, drag: 0.5, bounce: 0.38, solid: true, brittle: 3, crumble: R.range(0.25, 0.6), life: R.range(1.5, 1.9),+ });+ }+ for (let i = 0; i < 46; i++) {+ const x = R.range(-15, 19), y = -R.range(1, 33), dx = x - HIT_AT[0], dy = y - HIT_AT[1], d = Math.hypot(dx, dy) || 1, sp = R.range(60, 200);+ if (!inside(x, y)) continue;+ bits.add({ kind: R.chance(0.15) ? B.CHUNK : B.SHARD, x, y, vx: (dx / d) * sp * 0.8 + R.range(20, 90), vy: (dy / d) * sp * 0.4 - R.range(60, 240), g: 0.85, drag: 0.6, bounce: 0.32, life: R.range(0.8, 1.4), a: R.range(0, TAU), va: R.range(-22, 22), s: R.range(1.2, 3.4), c: C[R.int(4, 7)], ramp: [C[1], C[3], C[4], C[6], C[7]] });+ }+ // ice dust rolls out along the floor, vapour hangs where it stood, a flurry, glints, a flash of light+ for (let i = 0; i < 9; i++) ps.spawn(P.VAPOUR, R.range(-6, 18), -R.range(1, 6), R.range(10, 130), -R.range(2, 12), R.range(0.6, 1.1), C[6], R.range(2.2, 3.8));+ for (let i = 0; i < 5; i++) ps.spawn(P.DUST, R.range(-6, 16), -R.range(1, 4), R.range(30, 110), -R.range(2, 8), R.range(0.5, 0.9), C[5], R.range(1.6, 2.8));+ for (let i = 0; i < 4; i++) ps.spawn(P.VAPOUR, R.range(-8, 18), -R.range(8, 28), R.range(-10, 50), -R.range(8, 24), R.range(0.6, 1), C[6], R.range(2.6, 4));+ for (let i = 0; i < 16; i++) {+ const a = R.range(-Math.PI * 0.9, -0.1), sp = R.range(40, 140);+ ps.spawn(P.FLAKE, R.range(-8, 16), -R.range(6, 28), Math.cos(a) * sp + 20, Math.sin(a) * sp, R.range(1, 1.6), R.chance(0.6) ? WHITE : C[6], R.range(0.5, 1.6));+ }+ for (let i = 0; i < 7; i++) ps.spawn(P.STAR, R.range(-14, 40), -R.range(4, 40), R.range(-8, 16), -R.range(4, 16), R.range(0.4, 0.8), R.chance(0.5) ? WHITE : C[6], R.range(1, 2.4));+ lights.add(2, -17, 64, WHITE, 0.85, 0.14);+ lights.add(16, -18, 86, C[4], 0.5, 0.55);+ };++ return {+ update(dt) {+ t += dt;+ // the hit: a flash on the left face, chips and sparks thrown back, the block jolts+ if (!struck && t >= HIT) {+ struck = true;+ lights.add(HIT_AT[0], HIT_AT[1], 24, WHITE, 0.6, 0.08);+ lights.add(HIT_AT[0] + 6, HIT_AT[1], 40, C[5], 0.4, 0.3);+ for (let i = 0; i < 12; i++) {+ const a = Math.PI + R.range(-0.9, 0.9), sp = R.range(50, 120);+ ps.spawn(P.SPARK, HIT_AT[0] - 1, HIT_AT[1], Math.cos(a) * sp, Math.sin(a) * sp - 40, R.range(0.15, 0.4));+ }+ for (let i = 0; i < 6; i++) {+ const a = Math.PI + R.range(-1, 0.8), sp = R.range(40, 100);+ bits.add({ kind: B.SHARD, x: HIT_AT[0] - 1, y: HIT_AT[1] + R.range(-2, 2), vx: Math.cos(a) * sp, vy: Math.sin(a) * sp - 60, g: 0.85, drag: 0.6, bounce: 0.3, life: R.range(0.5, 0.9), a: R.range(0, TAU), va: R.range(-20, 20), s: R.range(1.2, 2.4), c: C[R.int(5, 7)] });+ }+ }+ if (!wave2 && t >= CRACK2) {+ wave2 = true;+ lights.add(0, -16, 36, C[6], 0.35, 0.15);+ for (let i = 0; i < 3; i++) bits.add({ kind: B.SHARD, x: R.range(-14, 18), y: -R.range(4, 30), vx: R.range(-30, 30), vy: -R.range(10, 50), g: 0.85, drag: 0.6, bounce: 0.3, life: R.range(0.4, 0.7), a: R.range(0, TAU), va: R.range(-20, 20), s: R.range(1, 2), c: C[R.int(5, 7)] });+ }+ if (!white && t >= FLASH) {+ white = true;+ lights.add(2, -17, 44, WHITE, 0.7, 0.08);+ }+ if (!burst && t >= BURST) {+ burst = true;+ explode();+ }+ // glints wink on the settling debris+ if (burst && t < BURST + 1 && R.chance(0.08) && bits.list.length) {+ const b = R.pick(bits.list);+ ps.spawn(P.STAR, b.x, b.y - 1, 0, -3, R.range(0.2, 0.4), R.chance(0.5) ? WHITE : C[6], R.range(0.6, 1.5));+ }+ for (let i = scuffs.length - 1; i >= 0; i--) if ((scuffs[i].t += dt) > 0.9) scuffs.splice(i, 1);+ ps.update(dt);+ bits.update(dt);+ panes.update(dt);+ lights.update(dt);+ endBy(t, meta.duration, ps, bits, panes);+ },+ drawBack(p) {+ drawFloor(p);+ ps.draw(p, "back");+ },+ draw(p) {+ drawBlock(p);+ // the hit: a star and a short flare on the left face+ const h = t - HIT;+ if (h >= 0 && h < 0.2) {+ sparkle(p, HIT_AT[0] - 1, HIT_AT[1], 9 * ease.outBack(Math.min(1, h / 0.04)) * (1 - h / 0.2), C[6], C[4], 0.7);+ if (h < 0.08) flare(p, HIT_AT[0] - 1, HIT_AT[1], 14 * (1 - h / 0.08), 1 - h / 0.08, C);+ }+ // cold light in the ice, brighter as it cracks; a pool on the floor+ const k = 1 - smooth(BURST, BURST + 0.4, t), crk = smooth(HIT, FLASH, t);+ if (k > 0) {+ p.glow(2, -17, 34, C[4], (0.16 + 0.22 * crk) * k);+ p.glow(2, -2, 30, C[4], 0.14 * k);+ }+ if (t >= FLASH && t < BURST + 0.12) flare(p, 2, -17, 26 * (1 - clamp((t - FLASH) / 0.18)), 1 - clamp((t - FLASH) / 0.18), C);+ panes.draw(p, C);+ bits.draw(p);+ ps.draw(p, "front");+ lights.draw(p);+ },+ };}diff --git a/src/fx/ice/ice-spikes.js b/src/fx/ice/ice-spikes.jsindex e2d752e..3dfab7e 100644--- a/src/fx/ice/ice-spikes.js+++ b/src/fx/ice/ice-spikes.js@@ -1,67 +1,219 @@-import { PAL, burst, rng, seg, ease, fly, TAU, WHITE } from "../../core/index.js";-import { fit, spike, shard, shardPts, glint } from "./_lib.js";+// The eruption recipe (a frost line racing ahead, each spike punching up white with a spray of shards, a puff+// and a glint, the floor frosting behind) is adapted from Sprite Fusion's open-source ice+// (https://www.spritefusion.com/pixel-art-vfx/ice), MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Bits, Lights, P, B, Rng, fit, sparkle, clamp, smooth, seg, ease, rand, TAU, WHITE } from "../../core/index.js";+import { Panes, endBy, blade, splitPoly } 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,+ desc: "A frost line races along the floor and clusters of jagged ice blades burst up behind it in a rising wave, glint, flash white together and shatter into toppling shards.",+ tags: ["ice", "spikes", "ground", "wave", "directional", "magic", "one-shot"],+ size: [264, 112],+ origin: [24, 96],+ duration: 3,loop: false,fps: 30,bg: "ground",- options: { palette: PAL.ice, count: 6, spacing: 18, seed: 21 },+ options: { palette: ["#151a3d", "#212f6b", "#2c58aa", "#3a8bd8", "#62c8f4", "#a6ecff", "#dcfbff", "#ffffff"], reach: 172, height: 56, seed: 3 },};-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);+const START = 0.04, RUN = 0.44; // the frost line runs out+const SHIMMER = 0.74; // a glint runs down the line+const TREMBLE = 1.2, FLASH = 1.36, SHATTER = 1.42; // they shiver, flash white together and break+const MELT = 1.75; // the frost goes, oldest first++export function create(o) {+ const C = fit(o.palette, 8), R = new Rng(o.seed), REACH = o.reach, floor = () => 0;+ const ps = new Particles({ rng: R, ground: floor, sparks: [C[7], C[6], C[5], C[4]], haze: C[5] });+ const bits = new Bits({ ground: floor }), lights = new Lights();+ const splinter = (x, y, vx, n) => {+ for (let i = 0; i < n; i++) bits.add({ kind: B.SHARD, x: x + R.range(-2, 2), y: y - 1, vx: vx * 0.5 + R.range(-45, 45), vy: -R.range(30, 100), g: 0.8, drag: 0.6, bounce: 0.35, life: R.range(0.4, 0.75), a: R.range(0, TAU), va: R.range(-18, 18), s: R.range(1.2, 2.4), c: C[R.int(4, 7)] });+ };+ const panes = new Panes({+ ground: floor,+ onCrumble: (q) => {+ splinter(q.x, 0, 0, 3);+ ps.spawn(P.VAPOUR, q.x, -1, R.range(-12, 12), -R.range(2, 8), R.range(0.4, 0.7), C[6], R.range(1.4, 2.2));+ },+ onLand: (q, x, y, v) => {+ if (v < 110) return;+ ps.spawn(P.VAPOUR, x, y - 1, R.range(-20, 20), -R.range(2, 8), R.range(0.4, 0.7), C[6], R.range(1.4, 2.4));+ splinter(x, y, q.vx, 3);+ if (R.chance(0.3)) ps.spawn(P.STAR, x, y - 2, 0, -5, R.range(0.2, 0.4), WHITE, R.range(0.8, 1.6));+ },+ });+ const front = (t) => REACH * (1 - Math.pow(1 - seg(t, START, START + RUN), 1.7));+ const reachedAt = (x) => START + RUN * (1 - Math.pow(1 - clamp(x / REACH), 1 / 1.7));++ // clusters along the line: a main blade leaning into the wave and two to four splayed round it, heights+ // swelling to a crest past the middle and falling off at the end+ const env = (q) => 0.28 + 0.72 * Math.exp(-(((q - 0.64) / 0.3) ** 2));+ const clusters = [];+ for (let x = 10; x < REACH - 2; x += R.range(20, 26)) {+ const q = x / REACH, H = o.height * env(q) * R.range(0.88, 1.06), W = clamp(H * 0.36, 5, 14), lean = H * R.range(0.2, 0.34);+ // a big blade leaning into the wave, a smaller one behind it leaning further, a stub in front of its foot+ const list = [+ { dx: W * R.range(0.35, 0.6), h: H * R.range(0.5, 0.7), w: W * 0.7, lean: H * R.range(0.4, 0.6), back: true, delay: R.range(0.02, 0.05), jag: R.chance(0.5) ? R.range(0.35, 0.6) : -1 },+ { dx: 0, h: H, w: W, lean, back: false, delay: 0, jag: R.chance(0.7) ? R.range(0.32, 0.58) : -1, main: true },+ ];+ if (H > 14) list.push({ dx: -W * R.range(0.35, 0.55), h: H * R.range(0.24, 0.4), w: W * 0.55, lean: -H * R.range(0, 0.12), back: false, delay: R.range(0.03, 0.07), jag: -1 });+ clusters.push({ x, q, H, W, blades: list, main: list[1], t0: reachedAt(x) + 0.012, up: false });+ }+ const crest = clusters.reduce((a, c) => (c.H > a.H ? c : a), clusters[0]);+ let t = 0, broke = false, trembled = false;++ // a blade's base, tip and look right now+ const pose = (c, b) => {+ const g = ease.outBack(clamp((t - c.t0 - b.delay) / 0.09), 2.2), x = c.x + b.dx;+ return { g, x, tx: x + b.lean * g, ty: -b.h * g, white: t - c.t0 - b.delay < 0.03 || (t >= FLASH && t < SHATTER) };+ };+ const drawClusters = (p) => {+ if (t >= SHATTER) return;+ for (const pass of [0, 1, 2])+ for (const c of clusters) {+ if (t < c.t0) continue;+ const jx = t >= TREMBLE && t < FLASH ? ((Math.floor(t * 40) + Math.round(c.x)) % 2 ? 1 : 0) : 0;+ for (const b of c.blades) {+ if ((pass === 0) !== b.back || (pass === 1) !== !!b.main) continue;+ const s = pose(c, b);+ if (s.g <= 0) continue;+ const gl = (t - SHIMMER - c.q * 0.34) / 0.2;+ blade(p, s.x + jx, 0, s.tx + jx, s.ty, b.w, C, { white: s.white, jag: b.jag, dim: b.back ? 1 : 0, glint: gl >= 0 && gl <= 1 ? gl : -1 });+ }+ if (pass === 2) {+ // light: a pop at the base as it bursts, a cold glow up its length while it stands+ const pop = clamp(1 - (t - c.t0) / 0.15), wh = t >= FLASH;+ p.glow(c.x + c.main.lean * 0.4, -c.H * 0.45, c.H * 0.9 + 10, C[4], (0.16 + 0.42 * pop + (wh ? 0.4 : 0)) * (0.85 + 0.15 * Math.sin(t * 3 + c.x)));+ if (pop > 0) p.glow(c.x, -2, 14, WHITE, 0.55 * pop);+ }+ }+ };++ // the frosted floor: a crust with rime tufts, a bloom under the surface, a white-hot head while it runs+ const drawFrost = (p) => {+ const fr = front(t);+ for (let x = -3; x <= Math.min(fr, REACH + 6); x++) {+ const q = clamp(x / REACH), age = t - reachedAt(Math.max(0, x)), a = 1 - smooth(MELT + q * 0.35, MELT + q * 0.35 + 0.6, t);+ if (a <= 0 || age < 0) continue;+ const h = rand(x, 17), grow = smooth(0, 0.3, age), head = fr - x < 3 && fr < REACH;+ p.dot(x, 0, head || age < 0.06 || h < 0.3 ? WHITE : C[6], a);+ const L = h < 0.45 ? Math.round(grow * (1 + rand(x, 5) * 2.6)) : 0;+ for (let j = 1; j <= L; j++) p.dot(x, -j, j === L ? WHITE : C[5], a);+ if (L > 1 && rand(x, 9) < 0.5) p.dot(x + 1, -L + 1, C[6], a);+ const D = grow * (2 + rand(x, 11) * 4) * (1 - q * 0.3);+ for (let j = 1; j <= D; j++) p.dot(x, j, rand(x * 31 + j, 7) < 0.06 ? WHITE : j < 2 ? C[5] : j < 4 ? C[4] : C[3], a * (1.1 - j / (D + 1)));+ if (head) p.dot(x, -1, 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);+ if (fr < REACH && t > START) {+ p.glow(fr, -2, 16, C[6], 0.6);+ p.glow(fr, -1, 7, WHITE, 0.6);}- 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));+ };++ const breakBlade = (c, b) => {+ const s = pose(c, b), ax = s.tx - s.x, ay = s.ty, L = Math.hypot(ax, ay) || 1, nx = -ay / L, ny = ax / L, hw = b.w / 2;+ const tri = [[s.x - nx * hw, -ny * hw], [s.tx, s.ty], [s.x + nx * hw, ny * hw]];+ const ang = Math.atan2(ay, ax) + Math.PI / 2;+ let parts = [tri];+ if (b.h > 9) parts = parts.flatMap((poly) => splitPoly(poly, s.x + ax * 0.4, ay * 0.4, ang));+ if (b.h > 22) parts = parts.flatMap((poly) => (poly.some(([, y]) => y < ay * 0.5) ? splitPoly(poly, s.x + ax * 0.72, ay * 0.72, ang) : [poly]));+ for (const part of parts) {+ let mx = 0, my = 0;+ for (const [x, y] of part) (mx += x), (my += y);+ (mx /= part.length), (my /= part.length);+ const up = clamp(-my / 40);+ panes.add({+ pts: part.map(([x, y]) => [x - mx, y - my]), x: mx, y: my, vx: R.range(-25, 60), vy: -R.range(40, 130) * (0.5 + up), a: 0, va: R.range(-8, 8), f: R.range(-0.7, 0.7), vf: R.range(-6, 6),+ lit: b.back ? 0.45 : 0.75, g: 0.9, drag: 0.6, bounce: 0.3, solid: true, ridge: Math.atan2(ay, ax), brittle: b.h > 30 ? 2 : 1, crumble: R.range(0.12, 0.4), life: R.range(1, 1.4),});- 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)));+ for (let i = 0; i < 2 + b.h / 7; i++) {+ const u = R.next();+ bits.add({ kind: R.chance(0.15) ? B.CHUNK : B.SHARD, x: s.x + ax * u + R.range(-1.5, 1.5), y: ay * u, vx: R.range(-60, 90), vy: -R.range(60, 230), g: 0.9, drag: 0.6, bounce: 0.3, life: R.range(0.7, 1.3), a: R.range(0, TAU), va: R.range(-20, 20), s: R.range(1.2, 3.2), c: C[R.int(4, 7)], ramp: [C[1], C[3], C[4], C[6], C[7]] });+ }+ };++ return {+ update(dt) {+ t += dt;+ // the cast: a puff and a spray where the line starts+ if (t - dt <= START && t > START) {+ for (let i = 0; i < 4; i++) ps.spawn(P.VAPOUR, R.range(0, 6), -R.range(0, 3), R.range(10, 60), -R.range(2, 12), R.range(0.4, 0.7), C[6], R.range(2, 3.2));+ lights.add(4, -4, 26, C[5], 0.6, 0.25);+ }+ // the running front throws frost: streaks along the floor, motes, vapour+ const fr = front(t);+ if (t > START && fr < REACH - 1) {+ if (R.chance(0.5)) ps.spawn(P.STREAK, fr - R.range(4, 12), -R.range(1, 3), R.range(40, 80), -R.range(0, 6), R.range(0.08, 0.14), R.chance(0.5) ? C[6] : WHITE);+ if (R.chance(0.3)) ps.spawn(P.FLAKE, fr, -1, R.range(10, 50), -R.range(20, 70), R.range(0.5, 0.9), R.chance(0.5) ? WHITE : C[6], R.range(0.5, 1.2));+ if (R.chance(0.12)) ps.spawn(P.VAPOUR, fr, -R.range(0, 3), R.range(20, 60), -R.range(2, 10), R.range(0.4, 0.7), C[6], R.range(1.6, 2.8));+ }+ for (const c of clusters) {+ if (c.up || t < c.t0) continue;+ c.up = true;+ // each cluster bursts up: shards sprayed forward, a puff, motes, a glint at the tip once it stands+ const big = c === crest, n = 3 + Math.round(c.H / 8);+ for (let i = 0; i < n; i++) {+ const a = -Math.PI / 2 + R.range(-1.1, 1.0), sp = R.range(60, 190) * (0.45 + c.H / 44);+ bits.add({ kind: B.SHARD, x: c.x + R.range(-3, 3), y: -1, vx: Math.cos(a) * sp + 25, vy: Math.sin(a) * sp, g: 0.8, drag: 0.6, bounce: 0.3, life: R.range(0.6, 1.1), a: R.range(0, TAU), va: R.range(-18, 18), s: R.range(1.2, 3), c: C[R.int(5, 7)] });+ }+ ps.spawn(P.VAPOUR, c.x, -1, R.range(-10, 40), -R.range(2, 10), R.range(0.5, 0.9), C[6], R.range(2.2, 3.4) * (0.6 + c.H / 60));+ for (let i = 0; i < 2; i++) ps.spawn(P.FLAKE, c.x + R.range(-4, 4), -R.range(2, c.H * 0.5), R.range(-20, 40), -R.range(20, 60), R.range(0.6, 1.1), R.chance(0.5) ? WHITE : C[6], R.range(0.5, 1.3));+ if (c.H > 16) ps.spawn(P.STAR, c.x + c.main.lean, -c.H * 0.96, 0, -4, R.range(0.3, 0.5), WHITE, R.range(1.4, 2.6), 0.08);+ lights.add(c.x, -c.H * 0.4, 16 + c.H * 0.6, C[5], 0.5, 0.18);+ if (big) {+ lights.add(c.x, -c.H * 0.5, 54, WHITE, 0.5, 0.14);+ for (let i = 0; i < 4; i++) ps.spawn(P.VAPOUR, c.x + R.range(-6, 6), -R.range(0, 4), R.range(-40, 60), -R.range(4, 16), R.range(0.6, 1), C[6], R.range(3, 4.5));+ }+ }+ // while they stand: glints wink on the blades+ if (t > START + RUN && t < TREMBLE && R.chance(0.09)) {+ const c = R.pick(clusters), b = R.pick(c.blades), s = pose(c, b), u = R.range(0.3, 0.95);+ ps.spawn(P.STAR, s.x + (s.tx - s.x) * u, s.ty * u, 0, -3, R.range(0.25, 0.5), R.chance(0.6) ? WHITE : C[6], R.range(0.6, 2));+ }+ // they shiver: chips fall+ if (!trembled && t >= TREMBLE) {+ trembled = true;+ for (const c of clusters)+ for (let i = 0; i < 2; i++) bits.add({ kind: B.SHARD, x: c.x + R.range(-4, 4), y: -R.range(4, c.H * 0.8), vx: R.range(-20, 20), vy: -R.range(0, 30), g: 0.8, drag: 0.5, bounce: 0.3, life: R.range(0.3, 0.6), a: R.range(0, TAU), va: R.range(-18, 18), s: R.range(1, 1.8), c: C[R.int(5, 7)] });+ }+ if (!broke && t >= SHATTER) {+ broke = true;+ // all at once: every blade breaks into toppling pieces, splinters and ice dust, light along the line+ for (const c of clusters) {+ for (const b of c.blades) breakBlade(c, b);+ for (let i = 0; i < 2; i++) ps.spawn(P.VAPOUR, c.x + R.range(-6, 6), -R.range(1, 8), R.range(-30, 50), -R.range(4, 18), R.range(0.6, 1.1), C[6], R.range(2.4, 4) * (0.7 + c.H / 60));+ if (R.chance(0.7)) ps.spawn(P.STAR, c.x + R.range(-6, 6), -R.range(4, c.H), R.range(-10, 10), -R.range(6, 20), R.range(0.4, 0.8), R.chance(0.5) ? WHITE : C[6], R.range(1, 2.2));+ for (let i = 0; i < 2; i++) ps.spawn(P.FLAKE, c.x + R.range(-6, 6), -R.range(4, c.H), R.range(-30, 60), -R.range(30, 90), R.range(0.9, 1.5), R.chance(0.6) ? WHITE : C[6], R.range(0.5, 1.5));+ lights.add(c.x, -c.H * 0.5, 22 + c.H, WHITE, 0.45, 0.12);+ }+ for (let i = 0; i < 5; i++) lights.add((REACH * (i + 0.5)) / 5, -18, 40, C[4], 0.4, 0.5);+ }+ // the shatter's dust settles; glints on the debris+ if (broke && t < SHATTER + 0.8 && R.chance(0.1) && bits.list.length) {+ const b = R.pick(bits.list);+ ps.spawn(P.STAR, b.x, b.y - 1, 0, -3, R.range(0.2, 0.4), R.chance(0.5) ? WHITE : C[6], R.range(0.6, 1.5));+ }+ ps.update(dt);+ bits.update(dt);+ panes.update(dt);+ lights.update(dt);+ endBy(t, meta.duration, ps, bits, panes);+ },+ drawBack(p) {+ drawFrost(p);+ ps.draw(p, "back");+ },+ draw(p) {+ drawClusters(p);+ // the cold light the frosted floor gives off+ const k = (1 - smooth(MELT, MELT + 0.9, t)) * smooth(START, START + 0.3, t), fr = front(t);+ for (let i = 0; i < 6; i++) p.glow((fr * (i + 0.5)) / 6, -3, 26, C[4], 0.15 * k);+ if (t >= FLASH && t < SHATTER + 0.1) for (const c of clusters) sparkle(p, c.x + c.main.lean, -c.H, 6 * (1 - clamp((t - FLASH) / 0.16)), C[6], C[4], 0.4);+ panes.draw(p, C);+ bits.draw(p);+ ps.draw(p, "front");+ lights.draw(p);+ },+ };}diff --git a/src/fx/ice/icicle-fall.js b/src/fx/ice/icicle-fall.jsindex e79a8c9..108d204 100644--- a/src/fx/ice/icicle-fall.js+++ b/src/fx/ice/icicle-fall.js@@ -1,82 +1,208 @@-import { PAL, burst, seg, ease, fly, TAU, WHITE } from "../../core/index.js";-import { fit, shard, shardPts } from "./_lib.js";+// The break recipe (a white frame, the ice flung apart as shards with ice dust and glints) is adapted from+// Sprite Fusion's open-source ice (https://www.spritefusion.com/pixel-art-vfx/ice), MIT License,+// Copyright (c) 2026 Hugo Duprez.+import { Particles, Bits, Lights, P, B, Rng, fit, sparkle, band, clamp, smooth, seg, ease, rand, TAU, WHITE, GRAVITY } from "../../core/index.js";+import { Panes, splitPoly, centroid, endBy } 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,+ desc: "An icicle drips and trembles, snaps off its frosted root, drops, stabs the floor and bursts into skidding shards, splinters and rolling frost.",+ tags: ["ice", "icicle", "fall", "trap", "shatter", "one-shot"],+ size: [152, 120],+ origin: [76, 100],+ duration: 2.6,loop: false,fps: 30,bg: "ground",- options: { palette: PAL.ice, length: 26, seed: 25 },+ options: { palette: ["#151a3d", "#212f6b", "#2c58aa", "#3a8bd8", "#62c8f4", "#a6ecff", "#dcfbff", "#ffffff"], seed: 4 },};-const LOOSE = 0.42, G = 1500, TOP = -80;+const ROOT = -80, LEN = 36, W = 12; // where it hangs, how long, how wide at the root+const DRIP = 0.16, TREMBLE = 0.3, SNAP = 0.6, FREE = SNAP + 0.04;+const FALL_T = Math.sqrt((2 * (-ROOT - LEN)) / GRAVITY), IMPACT = FREE + FALL_T;-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];+// the icicle: a rippled taper hanging from (x, top), lit down its left side with a bright core streak, rings of+// light at the ripples, deep on the right, a dark rim. white flashes it; cut hides the top rows (snapped root).+function icicle(p, C, x, top, len, w, opts = {}) {+ const hw = (u) => (w / 2) * Math.pow(1 - u, 0.75) * (1 + 0.14 * Math.sin(u * 13 + 0.5)) * (u < 0.08 ? 1.15 : 1) + 0.3;+ const tilt = opts.tilt ?? 0, cut = opts.cut ?? 0;+ p.shade(x - w / 2 - 4, top - 1, x + w / 2 + 4 + Math.abs(tilt) * len, top + len + 1, (px, py, o) => {+ const u = (py - top) / len, cx = x + tilt * len * u + 0.7 * Math.sin(u * 6 + 1), s = px - cx;+ if (u < cut || u > 1) return;+ const h = hw(u);+ if (Math.abs(s) > h + 1) return;+ if (Math.abs(s) > h) {+ o.c = C[1];+ return;+ }+ if (opts.white) return (o.c = WHITE);+ const q = s / h, ring = Math.sin(u * 13 + 0.5) > 0.7;+ let c = u > 0.88 ? WHITE : q < -0.72 ? C[6] : q < -0.2 ? (ring ? C[7] : C[5]) : q < 0.18 ? (u < 0.72 ? C[7] : C[6]) : q > 0.8 ? C[2] : Math.abs(q - 0.45) < 0.1 && u > 0.15 && u < 0.6 ? C[5] : q < 0.6 ? C[4] : C[3];+ if (opts.glint >= 0 && q < 0.25 && Math.abs(u - opts.glint) < 0.06) c = WHITE;+ o.c = c;});- 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);+export function create(o) {+ const C = fit(o.palette, 8), R = new Rng(o.seed), floor = () => 0;+ const ps = new Particles({ rng: R, ground: floor, sparks: [C[7], C[6], C[5], C[4]], haze: C[5] });+ const bits = new Bits({ ground: floor }), lights = new Lights();+ const splinter = (x, y, vx, n) => {+ for (let i = 0; i < n; i++) bits.add({ kind: B.SHARD, x: x + R.range(-2, 2), y: y - 1, vx: vx * 0.5 + R.range(-45, 45), vy: -R.range(30, 100), g: 0.8, drag: 0.6, bounce: 0.35, life: R.range(0.4, 0.75), a: R.range(0, TAU), va: R.range(-18, 18), s: R.range(1.2, 2.4), c: C[R.int(4, 7)] });+ };+ const panes = new Panes({+ ground: floor,+ onLand: (q, x, y, v) => {+ if (v < 100) return;+ ps.spawn(P.VAPOUR, x, y - 1, R.range(-15, 15), -R.range(2, 8), R.range(0.4, 0.6), C[6], R.range(1.4, 2.2));+ splinter(x, y, q.vx, 2);+ },+ onCrumble: (q) => splinter(q.x, 0, q.vx, 3),});- // 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)));+ // the rime it hangs from: a frosted crust with stubs of older icicles+ const rime = [];+ for (let x = -18; x <= 18; x++) {+ const h = rand(x, o.seed, 2), d = Math.abs(x) / 18;+ rime.push({ x, h: 1 + Math.round((0.6 + h * 1.8) * (1 - d * 0.7)), stub: h < 0.3 && Math.abs(x) > 7 ? 2 + Math.round(rand(x, 5) * 5 * (1 - d * 0.5)) : 0 });+ }+ let t = 0, snapped = false, landed = false, dripped = false, y = 0;+ const top = () => ROOT + (t < FREE ? 0 : 0.5 * GRAVITY * (t - FREE) ** 2);++ return {+ update(dt) {+ t += dt;+ // a drop of meltwater swells at the tip and falls+ if (!dripped && t >= DRIP) {+ dripped = true;+ bits.add({ kind: B.DRIP, x: 0.5, y: ROOT + LEN + 1, vy: 20, g: 0.9, life: 1.2, c: C[6] });+ }+ // it trembles: frost sifts down from the root+ if (t > TREMBLE && t < SNAP && R.chance(0.25)) ps.spawn(P.FLAKE, R.range(-6, 6), ROOT + R.range(0, 3), R.range(-8, 8), R.range(5, 20), R.range(0.6, 1.1), R.chance(0.5) ? WHITE : C[6], R.range(0.5, 1.1));+ // it snaps: a crack flashes across the root, chips and a puff burst off+ if (!snapped && t >= SNAP) {+ snapped = true;+ lights.add(0, ROOT + 4, 24, WHITE, 0.6, 0.1);+ lights.add(0, ROOT + 4, 32, C[5], 0.4, 0.3);+ for (let i = 0; i < 7; i++) {+ const a = R.range(0, TAU), sp = R.range(30, 110);+ bits.add({ kind: B.SHARD, x: R.range(-4, 4), y: ROOT + 2, vx: Math.cos(a) * sp, vy: Math.sin(a) * sp - 20, g: 0.8, drag: 0.8, bounce: 0.3, life: R.range(0.5, 0.9), a: R.range(0, TAU), va: R.range(-20, 20), s: R.range(1, 2), c: C[R.int(5, 7)] });+ }+ for (let i = 0; i < 3; i++) ps.spawn(P.VAPOUR, R.range(-5, 5), ROOT + 2, R.range(-25, 25), R.range(-5, 5), R.range(0.4, 0.7), C[6], R.range(1.6, 2.6));+ for (let i = 0; i < 5; i++) ps.spawn(P.FLAKE, R.range(-6, 6), ROOT + 2, R.range(-30, 30), R.range(-20, 20), R.range(0.6, 1.2), R.chance(0.5) ? WHITE : C[6], R.range(0.5, 1.3));+ }+ // falling: it sheds frost motes that hang in the air behind it+ if (t > FREE && t < IMPACT && R.chance(0.5)) {+ const tp = top();+ ps.spawn(P.MOTE, R.range(-3, 3), tp + R.range(0, LEN * 0.6), R.range(-10, 10), R.range(-40, -10), R.range(0.2, 0.35), R.chance(0.5) ? C[6] : C[5], 0.6);+ }+ // it stabs the floor and bursts+ if (!landed && t >= IMPACT) {+ landed = true;+ const tp = -LEN;+ lights.add(0, -16, 46, WHITE, 0.85, 0.12);+ lights.add(0, -16, 58, C[4], 0.5, 0.5);+ // the icicle in pieces: cut across its length, then down the middle+ let parts = [[[-W / 2, tp], [W / 2, tp], [0.5, 0]]];+ for (const v of [0.3, 0.58, 0.8]) parts = parts.flatMap((poly) => splitPoly(poly, 0, tp + LEN * v + R.range(-2, 2), R.range(-0.4, 0.4)));+ parts = parts.flatMap((poly) => (centroid(poly).area > 22 ? splitPoly(poly, centroid(poly).x, centroid(poly).y, Math.PI / 2 + R.range(-0.5, 0.5)) : [poly]));+ for (const part of parts) {+ const m = centroid(part), side = m.x < 0.5 ? -1 : 1, low = clamp(-m.y / LEN);+ panes.add({+ pts: part.map(([x, y]) => [x - m.x, y - m.y]), x: m.x, y: m.y, vx: side * R.range(30, 110) + R.range(-15, 15), vy: -R.range(70, 200) * (0.4 + low), a: 0, va: R.range(-12, 12), f: R.range(-0.7, 0.7), vf: R.range(-8, 8),+ lit: 0.75, g: 0.9, drag: 0.6, bounce: 0.35, solid: true, ridge: Math.PI / 2, brittle: 2, crumble: R.range(0.15, 0.45), life: R.range(1, 1.4),+ });+ }+ for (let i = 0; i < 52; i++) {+ const a = -Math.PI / 2 + R.range(-1.25, 1.25), sp = R.range(60, 230);+ bits.add({ kind: R.chance(0.15) ? B.CHUNK : B.SHARD, x: R.range(-3, 3), y: -R.range(1, 10), vx: Math.cos(a) * sp, vy: Math.sin(a) * sp, g: 0.85, drag: 0.6, bounce: 0.32, life: R.range(0.6, 1.2), a: R.range(0, TAU), va: R.range(-22, 22), s: R.range(1.2, 3), c: C[R.int(4, 7)], ramp: [C[1], C[3], C[4], C[6], C[7]] });+ }+ for (let i = 0; i < 10; i++) {+ const s = R.sign();+ ps.spawn(P.VAPOUR, s * R.range(0, 8), -R.range(1, 6), s * R.range(25, 90), -R.range(2, 14), R.range(0.6, 1.1), C[6], R.range(2.2, 3.8));+ }+ for (let i = 0; i < 12; i++) ps.spawn(P.FLAKE, R.range(-6, 6), -R.range(2, 16), R.range(-70, 70), -R.range(30, 110), R.range(1, 1.5), R.chance(0.6) ? WHITE : C[6], R.range(0.5, 1.5));+ for (let i = 0; i < 6; i++) ps.spawn(P.STAR, R.range(-24, 24), -R.range(4, 34), R.range(-10, 10), -R.range(4, 14), R.range(0.4, 0.8), R.chance(0.5) ? WHITE : C[6], R.range(1, 2.2));+ }+ if (landed && t < IMPACT + 0.9 && R.chance(0.08) && bits.list.length) {+ const b = R.pick(bits.list);+ ps.spawn(P.STAR, b.x, b.y - 1, 0, -3, R.range(0.2, 0.4), R.chance(0.5) ? WHITE : C[6], R.range(0.6, 1.4));+ }+ ps.update(dt);+ bits.update(dt);+ panes.update(dt);+ lights.update(dt);+ endBy(t, meta.duration, ps, bits, panes);+ },+ drawBack(p) {+ // its shadow gathers on the floor as it comes down+ if (t > TREMBLE && t < IMPACT + 0.05) {+ const k = t < FREE ? seg(t, TREMBLE, FREE) * 0.35 : 0.35 + 0.65 * seg(t, FREE, IMPACT), rx = 3 + 7 * k;+ for (let x = Math.floor(-rx); x <= rx; x++) {+ const f = 1 - (x / rx) ** 2;+ p.blend(x + 0.5, 0, C[0], 0.7 * k * f);+ if (Math.abs(x) < rx * 0.7) p.blend(x + 0.5, 1, C[0], 0.45 * k * f);+ }+ }+ // frost splashed across the floor where it struck, melting away+ if (t >= IMPACT) {+ const g = ease.outCubic(seg(t, IMPACT, IMPACT + 0.25)), out = 1 - smooth(IMPACT + 0.8, IMPACT + 1.5, t);+ for (let x = -26; x <= 26; x++) {+ const d = Math.abs(x + 0.5) / 26, h = rand(x, 23), a = out * clamp((g * 1.15 - d) / 0.15);+ if (a <= 0) continue;+ p.dot(x, 0, h < 0.35 || d > g - 0.12 ? WHITE : C[6], a);+ if (h < 0.4) for (let j = 1; j <= Math.round((1 + rand(x, 3) * 2.5) * (1 - d)); j++) p.dot(x + Math.sign(x) * (j > 1 ? 1 : 0), -j, j > 1 ? WHITE : C[5], a);+ for (let j = 1; j <= Math.round((2 + rand(x, 7) * 3) * (1 - d * 0.6)); j++) p.dot(x, j, j < 2 ? C[5] : C[4], a * (1.1 - j / 6));+ }+ const k = seg(t, IMPACT, IMPACT + 0.35);+ if (k < 1) band(p, 0, 0.5, 6 + 34 * ease.outCubic(k), 0.18, Math.max(1, 4 * (1 - k)), 1.1 - k, [C[3], C[4], C[5], C[6]], (a) => Math.sin(a) < 0);+ }+ ps.draw(p, "back");+ },+ draw(p) {+ // the rime it hangs from, fading at the end+ const ra = 1 - smooth(meta.duration - 0.7, meta.duration - 0.2, t);+ for (const r of rime) {+ // a lumpy crust: white on top, pale below, a deep underside; little icicles hang off it+ for (let j = 0; j < r.h + 1; j++) p.dot(r.x, ROOT - 1 - j, j === r.h ? WHITE : j === r.h - 1 ? C[6] : j === 0 ? C[3] : C[5], ra);+ for (let j = 0; j < r.stub; j++) p.dot(r.x, ROOT + j, j === r.stub - 1 ? WHITE : j === 0 ? C[5] : C[4], ra);+ if (r.stub > 4) p.dot(r.x + 1, ROOT, C[3], ra);+ }+ // the snapped root: a jagged stub left behind+ if (snapped)+ for (let x = -W / 2 + 1; x <= W / 2 - 1; x++) {+ const L = 1 + Math.round(rand(x, 77) * 2.5);+ for (let j = 0; j < L; j++) p.dot(x, ROOT + j, j === L - 1 ? (t < SNAP + 0.15 ? WHITE : C[6]) : x < 0 ? C[5] : C[3], ra);+ }+ p.glow(0, ROOT, 18, C[4], 0.3 * ra);+ if (t >= IMPACT) {+ const k = seg(t, IMPACT, IMPACT + 0.35);+ if (k < 1) band(p, 0, 0.5, 6 + 34 * ease.outCubic(k), 0.18, Math.max(1, 4 * (1 - k)), 1.1 - k, [C[3], C[4], C[5], C[6]], (a) => Math.sin(a) >= 0, k < 0.15);+ if (t < IMPACT + 0.22) sparkle(p, 0.5, -3, 10 * ease.outBack(Math.min(1, (t - IMPACT) / 0.05)) * (1 - (t - IMPACT) / 0.22), C[6], C[4], 0.7);+ }+ if (t < IMPACT) {+ // the icicle: trembling before it snaps, then falling with a streak of air behind it+ const tp = top(), jx = t > TREMBLE && t < SNAP ? (Math.floor(t * 36) % 2 ? 1 : 0) * Math.round(seg(t, TREMBLE, SNAP) * 1.4 + 0.4) : 0;+ const falling = t >= FREE, sp = falling ? GRAVITY * (t - FREE) : 0;+ if (falling)+ for (const [dx, k] of [[-3, 0.7], [0.5, 1], [4, 0.6]]) {+ const L = Math.min(30, sp * 0.07) * k;+ if (L > 2) p.line(dx, tp - L, dx, tp + 3, (u) => (u > 0.75 ? C[6] : u > 0.4 ? C[4] : C[3]));+ }+ const gl = (t - 0.04) / 0.3;+ icicle(p, C, jx + 0.5, tp, LEN, W, { white: t >= IMPACT - 0.025 || (t >= SNAP && t < SNAP + 0.03), glint: gl >= 0 && gl <= 1 ? gl : -1 });+ if (snapped && t < SNAP + 0.12) p.line(-W / 2 - 1, ROOT + 1, W / 2 + 1, ROOT + 1, WHITE);+ p.glow(0.5, tp + LEN * 0.5, 20, C[4], 0.28);+ // the drop of meltwater swelling at the tip+ if (t < DRIP) {+ const s = seg(t, 0, DRIP);+ p.dot(0.5, ROOT + LEN + 1, C[6], s);+ if (s > 0.6) p.px(0.5, ROOT + LEN + 2, WHITE);+ }+ }+ panes.draw(p, C);+ bits.draw(p);+ ps.draw(p, "front");+ lights.draw(p);+ },+ };}diff --git a/src/fx/ice/snowflake-burst.js b/src/fx/ice/snowflake-burst.jsindex 0b2d168..26d60c7 100644--- a/src/fx/ice/snowflake-burst.js+++ b/src/fx/ice/snowflake-burst.js@@ -1,55 +1,130 @@-import { PAL, burst, seg, ease, TAU, WHITE } from "../../core/index.js";-import { fit, flake, glint } from "./_lib.js";+// The pop recipe (a gathering, a white flash with a ring and flares, twinkling motes that linger and fade) is+// adapted from Sprite Fusion's open-source sparkle (https://www.spritefusion.com/pixel-art-vfx/sparkle),+// MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Lights, P, Rng, fit, flare, sparkle, clamp, smooth, seg, ease, TAU, WHITE } from "../../core/index.js";+import { flakeDesign, snowflake, endBy } 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,+ desc: "A cold pop: frost gathers and flashes white in a ring, then crisp six-armed snowflakes spin out, slow, twinkle and drift down to settle and melt.",+ tags: ["ice", "snow", "snowflake", "burst", "magic", "one-shot"],+ size: [140, 120],+ origin: [70, 106],+ duration: 3.2,loop: false,fps: 30,- bg: "dark",- options: { palette: PAL.ice, count: 6, seed: 26 },+ bg: "ground",+ options: { palette: ["#151a3d", "#212f6b", "#2c58aa", "#3a8bd8", "#62c8f4", "#a6ecff", "#dcfbff", "#ffffff"], count: 9, seed: 8 },};-const STEP = TAU / 24; // turn in 15 degree steps so the arms stay crisp+const POP = 0.16, CY = -48;-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);+export function create(o) {+ const C = fit(o.palette, 8), R = new Rng(o.seed), floor = () => 0;+ const ps = new Particles({ rng: R, ground: floor, sparks: [C[7], C[6], C[5], C[4]], haze: C[5] });+ const lights = new Lights();+ // the flakes: two big, a few middling, the rest small; small ones fly further+ const flakes = [];+ const SIZES = [2, 0, 1, 0, 2, 0, 1, 0, 1];+ for (let i = 0; i < o.count; i++) {+ const z = SIZES[i % SIZES.length], r = z === 2 ? R.range(9.5, 11.5) : z === 1 ? R.range(6, 7.5) : R.range(3, 4.5);+ const a = (i / o.count) * TAU + R.range(-0.3, 0.3) + 0.4, sp = R.range(80, 120) * (1.4 - r / 14);+ flakes.push({+ x: 0, y: CY, vx: Math.cos(a) * sp, vy: Math.sin(a) * sp * 0.85 - 20, r, rot: R.range(0, TAU), w0: R.sign() * R.range(7, 12), w1: R.sign() * R.range(0.4, 1),+ d: flakeDesign(R), life: R.range(2.1, 2.8), age: 0, ph: R.range(0, TAU), tw: R.range(0.5, 0.85), tw0: R.range(0.15, 0.6), rest: false, popped: false,+ });}- // 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)));+ let t = 0, popped = false;+ const sz = (f) => f.r * Math.min(1, ease.outBack(clamp(f.age / 0.18), 2)) * Math.min(1, (f.life - f.age) / 0.35);++ return {+ update(dt) {+ t += dt;+ // the cold gathers: streaks of frost spiral in, snow motes drift in+ if (t < POP - 0.03 && R.chance(0.8)) {+ const a = R.range(0, TAU), D = R.range(22, 44), T = R.range(0.12, 0.16), v = (D * 3) / (Math.exp(3 * T) - 1);+ ps.spawn(P.STREAK, Math.cos(a) * D, CY + Math.sin(a) * D, -Math.cos(a) * v, -Math.sin(a) * v, T, R.chance(0.5) ? C[6] : C[5]);+ }+ if (!popped && t >= POP) {+ popped = true;+ lights.add(0, CY, 44, WHITE, 0.8, 0.1);+ lights.add(0, CY, 72, C[4], 0.5, 0.6);+ // frost thrown out: streaking motes, snow, glints that come and go round it+ for (let i = 0; i < 22; i++) {+ const a = R.range(0, TAU), sp = R.range(80, 150);+ ps.spawn(P.MOTE, 0, CY, Math.cos(a) * sp, Math.sin(a) * sp, R.range(0.25, 0.5), R.chance(0.5) ? C[6] : C[5], R.range(0.6, 1));+ }+ for (let i = 0; i < 18; i++) {+ const a = R.range(-Math.PI, 0.2), sp = R.range(30, 110);+ ps.spawn(P.FLAKE, 0, CY, Math.cos(a) * sp, Math.sin(a) * sp, R.range(1, 1.6), R.chance(0.6) ? WHITE : C[6], R.range(0.5, 1.5));+ }+ for (let i = 0; i < 12; i++) {+ const a = R.range(0, TAU), d = R.range(10, 44);+ ps.spawn(P.STAR, Math.cos(a) * d, CY + Math.sin(a) * d * 0.85, 0, R.range(2, 6), R.range(0.3, 0.6), R.chance(0.5) ? WHITE : C[6], R.range(0.8, 2.2), R.range(0.08, 1.6));+ }+ }+ if (popped)+ for (const f of flakes) {+ f.age += dt;+ if (f.age >= f.life) continue;+ if (!f.rest) {+ f.vx -= f.vx * 2.8 * dt;+ f.vy -= f.vy * 2.8 * dt - 26 * dt;+ f.x += f.vx * dt + Math.sin(t * 1.8 + f.ph) * 5 * dt;+ f.y += f.vy * dt;+ f.rot += (f.w1 + (f.w0 - f.w1) * Math.exp(-f.age * 2.5)) * dt;+ // it settles on the floor, flat and still, and melts there+ if (f.y > -sz(f) * 0.3) {+ f.rest = true;+ f.y = -1;+ f.life = Math.min(f.life, f.age + 0.6);+ }+ }+ // a melted or spent flake goes out with a glint or two+ if (!f.popped && f.life - f.age < 0.1) {+ f.popped = true;+ for (let i = 0; i < 2; i++) ps.spawn(P.STAR, f.x + R.range(-2, 2), f.y + R.range(-2, 2), R.range(-6, 6), -R.range(2, 8), R.range(0.2, 0.4), R.chance(0.5) ? WHITE : C[6], R.range(0.8, 1.6));+ }+ }+ ps.update(dt);+ lights.update(dt);+ endBy(t, meta.duration, ps);+ },+ draw(p) {+ // the gathering: a tiny flake spins up at the heart, faster and brighter+ if (t < POP) {+ const k = t / POP;+ snowflake(p, 0, CY, 1 + 3.2 * k * k, t * 20, flakes[0].d, C, { hot: k });+ p.glow(0, CY, 8 + 14 * k, C[5], 0.3 + 0.4 * k);+ }+ // the pop: a white flash, a flare and a ring of frost running out+ const q = t - POP;+ if (q >= 0 && q < 0.4) {+ if (q < 0.07) p.circle(0, CY, 6 * (1 - q / 0.07) + 1, WHITE);+ flare(p, 0, CY, 28 * Math.pow(Math.max(0, 1 - q / 0.26), 1.5), 1 - q / 0.26, C);+ const e = ease.outCubic(q / 0.4), r = 5 + 34 * e;+ p.ring(0, CY, r, Math.max(1, 2.4 * (1 - e)), q < 0.08 ? WHITE : q < 0.2 ? C[6] : C[5], 1.15 - e);+ p.glowRing(0, CY, r, 5, C[5], 0.4 * (1 - e));+ }+ // the cold light left where it burst, fading+ if (popped) p.glow(0, CY, 46, C[4], 0.3 * (1 - smooth(POP, POP + 1.6, t)));+ // the flakes: spinning out, twinkling now and then, landing and melting+ for (const f of flakes) {+ if (!popped || f.age >= f.life) continue;+ const r = sz(f), tw = Math.max(0, Math.sin(((f.age - f.tw0) / f.tw) * TAU)) ** 8 * (f.age > f.tw0 ? 1 : 0);+ if (f.rest) {+ // lying on the floor: flattened to a sparkling smear that shrinks away+ const L = Math.max(1, Math.round(r * 1.2 * ((f.life - f.age) / 0.6)));+ for (let i = -L; i <= L; i++) p.px(f.x + i, -1, Math.abs(i) === L ? C[5] : i === 0 ? WHITE : C[6]);+ p.glow(f.x, -1, 3 + L, C[4], 0.3);+ continue;+ }+ snowflake(p, f.x, f.y, r, f.rot, f.d, C, { hot: Math.max(tw, 1 - clamp(f.age / 0.12)) });+ p.glow(f.x, f.y, 6 + r * 1.4, C[4], 0.12);+ if (tw > 0.5) flare(p, f.x, f.y, (3 + r * 0.7) * tw, tw, C);+ }+ ps.draw(p);+ lights.draw(p);+ },+ };}diff --git a/src/fx/impacts/_lib.js b/src/fx/impacts/_lib.jsindex 34436a4..3f042cb 100644--- a/src/fx/impacts/_lib.js+++ b/src/fx/impacts/_lib.js@@ -1,57 +1,197 @@-// Shared bits for the impacts category: sharp ray stars, streak sparks and shaded dust puffs.+// Shared by the impacts: the hit star, a ring that breaks into flying arcs, floor cracks that glow and cool,+// standing shock fronts, soft lumpy dust rings, faceted tumbling rocks, and the stone colors they share.+// The star and flying-arc recipes are adapted from Sprite Fusion's open-source impact+// (https://www.spritefusion.com/pixel-art-vfx/impact), and the stone colors from its explosion+// (https://www.spritefusion.com/pixel-art-vfx/explosion), MIT License, Copyright (c) 2026 Hugo Duprez.// Files starting with _ are helpers, not effects.-import { at, clamp, TAU } from "../../core/index.js";+import { clamp, rand, TAU, hex, mix, scale, rgb, WHITE } from "../../core/index.js";++export const SOOT = hex("#0d0a12");+export const OUTLINE = hex("#1a1422");+const LIGHT = Math.atan2(-1, -1); // light comes from the top left++/** Stone colors from one body color: light, body, shade, dust (lighter and greyer), lip (a lit broken edge). */+export function stone(c) {+ c = hex(c);+ return { light: mix(scale(c, 1.35), WHITE, 0.08), body: c, shade: scale(c, 0.64), dust: mix(scale(c, 1.2), rgb(150, 140, 150), 0.3), lip: mix(scale(c, 1.55), WHITE, 0.12) };+}++/**+ * Spikes for a hit star: n of them round the circle, longer towards aim (fwd) and a little behind it (back).+ * len and w: [min, max] base length and root half-width; jag scales every other spike (short teeth between).+ */+export function spikes(R, n, aim, { len = [7, 10], w = [1.5, 2.1], fwd = 1.8, back = 0.6, jag = 1, jit = 0.18 } = {}) {+ return Array.from({ length: n }, (_, i) => {+ const a = aim + (i / n) * TAU + R.range(-jit, jit), cb = Math.cos(a - aim);+ const L = R.range(len[0], len[1]) * (1 + fwd * Math.pow(Math.max(0, cb), 3) + back * Math.pow(Math.max(0, -cb), 3)) * (i % 2 ? jag : 1);+ return { a, len: L, w: R.range(w[0], w[1]) * (i % 2 ? Math.sqrt(jag) : 1) };+ });+}/**- * 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.+ * A hit star: tapered spikes in three passes (a rim, a body that's paler near the root, a hot core) round a+ * hot heart. sc stretches the spikes, th thins them, cols [rim, body, inner, core], a dithers it out.*/-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)));+export function star(p, x, y, list, sc, th, [rim, body, inner, core], a = 1, heart = 2.4) {+ for (let pass = 0; pass < 3; pass++)+ for (const s of list) {+ const c = Math.cos(s.a), sn = Math.sin(s.a), L = s.len * sc;+ for (let d = 0; d <= L; d += 0.5) {+ if (pass === 2 && d > L * 0.55) break;+ const hw0 = s.w * th * (1 - d / L) * Math.min(1, 0.5 + d / 3);+ const hw = pass === 0 ? hw0 + 0.8 : pass === 1 ? hw0 : hw0 * 0.45;+ const col = pass === 0 ? rim : pass === 1 ? (d < L * 0.35 ? inner : body) : core;+ for (let o = -hw; o <= hw; o += 0.5) p.dot(x + c * d - sn * o, y + sn * d + c * o, col, a);+ }}- p.line(x, y, x + dx * r.len, y + dy * r.len, (u) => col(u));+ const r = heart * sc * Math.sqrt(th);+ p.circle(x, y, r + 0.8, inner, a);+ p.circle(x, y, r, core, a);+}++/**+ * A ring that breaks into arcs: segs [{ a (centre angle), gap (0..1), dr (how fast it flies out), w (thickness+ * scale, default 1) }] evenly round the ring. brk 0 draws a whole ring th thick; as brk grows each arc shrinks,+ * tapers at both ends into a crescent and drifts out at its own speed. c is the outer edge's color, c2 the+ * inner's; sy squashes it onto a plane; nothing is drawn below maxY (a floor).+ */+export function brokenRing(p, x, y, r, th, segs, brk, c, c2 = c, k = 1, sy = 1, maxY = Infinity) {+ if (r <= 0 || k <= 0) return;+ const full = TAU / segs.length;+ for (const s of segs) {+ const span = full * (1 - s.gap * brk) + 0.02, rr = r * (1 + s.dr * brk), m = Math.max(4, Math.ceil(rr * span * 1.8));+ for (let j = 0; j <= m; j++) {+ const u = j / m, ang = s.a + (u - 0.5) * span, w = Math.max(0.5, th * (s.w ?? 1) * (1 - brk * Math.pow(Math.abs(2 * u - 1), 1.6)));+ const ca = Math.cos(ang), sa = Math.sin(ang);+ for (let o = -w / 2; o <= w / 2 + 0.01; o += 0.5) if (y + sa * (rr + o) * sy < maxY) p.dot(x + ca * (rr + o), y + sa * (rr + o) * sy, o > -0.26 ? c : c2, k);+ }+ }+}++// a jagged walk from (x, y) heading a for L px; each point is [x, y, distance along]+function walk(R, x, y, a, L, { jit = 0.55, steer = 0.45, step = [2, 4], maxY = Infinity, d0 = 0 } = {}) {+ const pts = [[x, y, d0]];+ let d = 0, cur = a;+ while (d < L - 0.01) {+ const s = Math.min(L - d, R.range(step[0], step[1]));+ cur += R.range(-jit, jit) + (a - cur) * steer;+ x += Math.cos(cur) * s;+ y = clamp(y + Math.sin(cur) * s, 0.5, maxY);+ d += s;+ pts.push([x, y, d0 + d]);}+ return pts;}/**- * 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 }].+ * Cracks in the floor face below (0, 0): n jagged lines, alternately left and right, mostly shallow, a few+ * diving steeply, some forked. len [min, max], maxY how deep they may go, forks 0..1.*/-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]];+export function makeCracks(R, n, { len = [14, 40], dive = 0.85, maxY = 22, forks = 0.5, x0 = [1, 5] } = {}) {+ const out = [];+ for (let i = 0; i < n; i++) {+ const side = i % 2 ? 1 : -1, dip = 0.06 + Math.pow(R.next(), 1.7) * dive, L = R.range(len[0], len[1]) * (1 - (0.5 * dip) / (dive + 0.06));+ const a = side > 0 ? dip : Math.PI - dip, pts = walk(R, side * R.range(x0[0], x0[1]), R.range(0.5, 1.5), a, L, { maxY });+ const c = { pts, len: L, t0: R.range(0, 0.035), kids: [] };+ for (let j = 2; j < pts.length - 1; j++)+ if (R.chance(forks * 0.4)) {+ const [fx, fy, fd] = pts[j];+ c.kids.push(walk(R, fx, fy, a + R.sign() * R.range(0.45, 1), R.range(3, 9) * (1 - (0.5 * j) / pts.length), { maxY, d0: fd, jit: 0.7, step: [1.5, 3] }));+ }+ out.push(c);}- 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;+ return out;}-/** 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);+/**+ * Draw cracks grown to g(c) px of their length. heat(d) 0..1 at distance d along a crack lights it from the+ * hot ramp (bright to dark) before it cools to dark; lip is the lit lower edge; k dithers them out.+ * Returns nothing; adds a glow along the hot parts.+ */+export function drawCracks(p, cracks, g, heat, hot, dark, lip, k = 1) {+ if (k <= 0) return;+ const col = (d) => {+ const h = heat(d);+ return h > 0.75 ? hot[0] : h > 0.5 ? hot[1] : h > 0.3 ? hot[2] : h > 0.12 ? hot[3] : dark;+ };+ for (const c of cracks) {+ const G = g(c);+ if (G <= 0) continue;+ for (const path of [c.pts, ...c.kids]) {+ for (let i = 1; i < path.length; i++) {+ const [x0, y0, d0] = path[i - 1], [x1, y1, d1] = path[i];+ if (d0 >= G) break;+ const f = d1 > G ? (G - d0) / (d1 - d0) : 1, ex = x0 + (x1 - x0) * f, ey = y0 + (y1 - y0) * f;+ p.line(x0, y0 + 1, ex, ey + 1, lip, (u) => (rand(Math.round(x0 + (ex - x0) * u), Math.round(y0 + (ey - y0) * u), 5) < 0.3 ? k * 0.8 : 0));+ p.line(x0, y0, ex, ey, (u) => col(d0 + (d1 - d0) * f * u), k);+ const h = heat(d0);+ if (h > 0.12) p.glow((x0 + ex) / 2, (y0 + ey) / 2, 4 + h * 4, hot[2], 0.22 * h * k);+ }+ }+ }+}++/**+ * A standing crescent shock front on the floor (y = 0): it leans back from a leading edge low at x, dir 1+ * racing right ")", -1 left "(". h tall, w thick at its widest (thick where it meets the floor, a point at+ * the top); cols [edge, body, back] bright to dark; k dithers it out.+ */+export function frontCrescent(p, x, dir, h, w, cols, k = 1) {+ if (h < 1 || w < 0.3 || k <= 0) return;+ const ry = h * 0.8, cy = -h * 0.2, rx = Math.max(2, h * 0.55);+ const x0 = dir > 0 ? x - rx - w - 1 : x - 1, x1 = dir > 0 ? x + 1 : x + rx + w + 1;+ p.shade(x0, -h - 1, x1, 0, (px, py, out) => {+ if (py > 0) return;+ const ey = (py - cy) / ry;+ if (ey <= -1 || ey >= 1) return;+ const e2 = 1 - ey * ey, edge = rx * Math.sqrt(e2) - rx, wt = w * Math.pow(e2, 0.45), q = (edge - (px - x) * dir) / Math.max(0.5, wt);+ if (q < 0 || q > 1) return;+ out.c = q < 0.28 ? cols[0] : q < 0.62 ? cols[1] : cols[2];+ out.a = k * (ey < -0.8 ? 0.7 : 1) * (q > 0.7 ? 1.25 - q * 0.8 : 1);+ });}/**- * 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).+ * A soft, lumpy ring of dust round (cx, cy): radius r, w thick (lumps swell it), alpha k, translucent and lit+ * on its upper side. sy squashes it onto the floor; brk 0..1 tears it into clumps as it thins; ph varies it;+ * nothing is drawn below maxY; half -1 draws only the far half (above cy), 1 only the near half.+ */+export function dustRing(p, cx, cy, r, w, k, c, { sy = 1, ph = 0, brk = 0, lit = 0.35, maxY = Infinity, half = 0 } = {}) {+ if (k <= 0.01 || r <= 0) return;+ const W = w * 1.6, lite = mix(c, WHITE, lit);+ for (let y = Math.floor(cy - (r + W) * sy) - 1; y <= Math.min(maxY - 1, Math.ceil(cy + (r + W) * sy) + 1); y++)+ for (let x = Math.floor(cx - r - W) - 1; x <= Math.ceil(cx + r + W) + 1; x++) {+ const dx = x + 0.5 - cx, dy = (y + 0.5 - cy) / sy, d = Math.hypot(dx, dy), g = Math.atan2(dy, dx);+ if ((half < 0 && dy >= 0) || (half > 0 && dy < 0)) continue;+ const lumpy = 0.6 + 0.3 * Math.sin(5 * g + ph) + 0.18 * Math.sin(11 * g + ph * 2.1) + 0.12 * Math.sin(17 * g + ph * 0.7);+ const wt = w * lumpy, off = Math.abs(d - r - w * 0.25 * Math.sin(7 * g + ph));+ if (off >= wt) continue;+ const tear = brk > 0 ? clamp((0.55 + 0.45 * Math.sin(6 * g + ph * 1.7) - brk) / 0.25) : 1;+ const a = k * (1 - Math.pow(off / wt, 2)) * tear;+ if (a > 0.01) p.blend(x, y, dy < 0 && d > r - wt * 0.3 ? lite : c, a);+ }+}++/** A rock's outline: n vertex radii round its centre. */+export const rockShape = (R, n = 6) => Array.from({ length: n }, () => R.range(0.7, 1.12));++/**+ * A faceted rock tumbling at angle b.a: every facet shaded by how it faces the light, a lit top face, a dark+ * outline, dithering out over its last half second. b: { x, y, a, s (1..3), life, pts }, st: stone().*/-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));+export function rock(p, b, st) {+ const r = 0.75 + b.s * 0.8, n = b.pts.length, fade = Math.min(1, b.life / 0.5), ca = Math.cos(b.a), sa = Math.sin(b.a);+ p.shade(b.x - r - 2, b.y - r - 2, b.x + r + 2, b.y + r + 2, (x, y, out) => {+ const dx = x - b.x, dy = y - b.y, u = dx * ca + dy * sa, v = -dx * sa + dy * ca, d = Math.hypot(u, v);+ let ang = Math.atan2(v, u);+ if (ang < 0) ang += TAU;+ const f = (ang / TAU) * n, i = Math.floor(f) % n, w = f - Math.floor(f), edge = r * (b.pts[i] * (1 - w) + b.pts[(i + 1) % n] * w);+ if (d > edge + 0.85) return;+ out.a = fade;+ if (d > edge) return OUTLINE;+ const lit = Math.cos(((i + 0.5) / n) * TAU + b.a - LIGHT);+ if (d < edge * 0.42) return lit > 0.55 ? st.light : st.body;+ return lit > 0.35 ? st.light : lit < -0.4 ? st.shade : st.body;+ });}diff --git a/src/fx/impacts/blunt-hit.js b/src/fx/impacts/blunt-hit.jsindex 91919f5..f213171 100644--- a/src/fx/impacts/blunt-hit.js+++ b/src/fx/impacts/blunt-hit.js@@ -1,47 +1,114 @@-import { PAL, ramp, burst, seg, ease, clamp, TAU, WHITE } from "../../core/index.js";-import { puff } from "./_lib.js";+// The clods and the dust they kick up are adapted from Sprite Fusion's open-source explosion+// (https://www.spritefusion.com/pixel-art-vfx/explosion), MIT License, Copyright (c) 2026 Hugo Duprez.+import { Bits, Lights, B, Rng, fit, clamp, ease, TAU, WHITE, mix, hex } from "../../core/index.js";+import { stone, rock, rockShape } 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,+ desc: "A heavy, soft thud: a white-hot lumpy blob cools to cream in a warm pool of light, inked wedges jab out and snap back, a squashed ring of dust puffs swells and drifts, clods drop.",+ tags: ["impact", "hit", "blunt", "punch", "club", "thump", "dust", "comic", "one-shot"],+ size: [128, 88],+ origin: [64, 72],+ duration: 0.9,loop: false,fps: 30,- bg: "dark",- options: { palette: PAL.dust, count: 9, size: 1, seed: 9 },+ bg: "ground",+ options: { palette: ["#1d1620", "#4a3a3c", "#7d6a66", "#b09c90", "#dccab4", "#f6ead2", "#ffffff"], warm: "#ffc98a", dust: "#b7a8a6", clod: "#6e5a5a", height: 22, 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);+// a lumpy outline: radius at angle a for a blob of radius r+const lump = (r, a, ph) => r * (1 + 0.15 * Math.sin(5 * a + ph) + 0.08 * Math.sin(9 * a + ph * 2.3));++export function create(o) {+ const C = fit(o.palette, 7), R = new Rng(o.seed), X = 0, Y = -o.height, PH = R.range(0, TAU), floor = () => 0;+ const WARM = hex(o.warm), DUST = hex(o.dust), st = stone(o.clod);+ const lights = new Lights(), bits = new Bits({ ground: floor });+ // a warm pool of light, a white-hot heart, and a glow on the floor below+ lights.add(X, Y, 48, WARM, 0.6, 0.4);+ lights.add(X, Y, 16, WHITE, 0.6, 0.07);+ lights.add(X, -2, 36, WARM, 0.25, 0.4);+ // inked wedges: each jabs out at its own length and pace, then snaps back+ const wedges = Array.from({ length: 9 }, (_, i) => ({ a: (i / 9) * TAU + R.range(-0.2, 0.2), len: R.range(6, 15), w: R.range(3.2, 5), r0: R.range(13, 16), t0: R.range(0.015, 0.04), out: R.range(0.04, 0.06), back: R.range(0.09, 0.14) }));+ // the squash ring: soft puffs flung out from the blob's rim, wider than tall, each its own size, pace and life+ const puffs = Array.from({ length: 30 }, (_, i) => {+ const a = (i / 30) * TAU + R.range(-0.12, 0.12), side = Math.abs(Math.cos(a)), v = R.range(40, 140) * (0.6 + 0.5 * side);+ return { x: X + Math.cos(a) * 9, y: Y + Math.sin(a) * 6, vx: Math.cos(a) * v, vy: Math.sin(a) * v * 0.5, r: R.range(2.4, 6.2) * (0.75 + 0.35 * side), life: R.range(0.35, 0.85), max: 0, t0: R.range(0.03, 0.1), lift: R.range(4, 16) };});- // 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);+ // and a few that billow up off the top and hang longer+ for (let i = 0; i < 5; i++)+ puffs.push({ x: X + R.range(-6, 6), y: Y - R.range(3, 6), vx: R.range(-30, 30), vy: -R.range(20, 45), r: R.range(3.5, 5.5), life: R.range(0.6, 0.85), max: 0, t0: R.range(0.05, 0.1), lift: R.range(14, 24) });+ for (const q of puffs) q.max = q.life;+ // heavier clods knocked loose: they arc out, drop to the floor, bounce once and settle+ for (let i = 0; i < 5; i++) {+ const s = R.sign(), a = -Math.PI / 2 + s * R.range(0.5, 1.3), v = R.range(70, 140);+ bits.add({ kind: B.CHUNK, x: X + s * R.range(4, 8), y: Y + R.range(-3, 3), vx: Math.cos(a) * v, vy: Math.sin(a) * v, g: 1, drag: 0.6, bounce: 0.28, life: R.range(0.65, 0.85), a: R.range(0, TAU), va: s * R.range(8, 16), s: R.chance(0.4) ? 2 : 1, pts: rockShape(R), pvy: 0 });+ }+ const kicks = [];++ let t = 0;+ return {+ update(dt) {+ t += dt;+ for (const q of puffs) {+ if (t < q.t0) continue;+ q.life -= dt;+ q.vx -= q.vx * 4.5 * dt;+ q.vy -= q.vy * 4.5 * dt + (q.lift ?? 6) * dt; // they slow, and lift a little as they thin+ q.x += q.vx * dt;+ q.y += q.vy * dt;+ }+ for (const b of bits.list) b.pvy = b.vy;+ bits.update(dt);+ // a clod hitting the floor kicks a little dust+ for (const b of bits.list)+ if (b.pvy > 60 && b.vy <= 0) {+ for (let i = 0; i < 2; i++) kicks.push({ x: b.x, y: -1, vx: R.sign() * R.range(8, 22), vy: -R.range(3, 10), r: R.range(1.2, 2), life: 0.4, max: 0.4, t0: 0 });+ b.pvy = 0;+ }+ for (const q of kicks) {+ q.life -= dt;+ q.vx -= q.vx * 4 * dt;+ q.vy -= q.vy * 4 * dt;+ q.x += q.vx * dt;+ q.y += q.vy * dt;+ }+ lights.update(dt);+ },+ draw(p) {+ // dust: each puff swells and thins, warm-lit at first, its top catching the light+ for (const q of [...puffs, ...kicks]) {+ const k = q.life / q.max;+ if (t < q.t0 || k <= 0) continue;+ const r = q.r * (0.7 + (1 - k) * 0.85), a = Math.pow(k, 1.25) * Math.min(1, (t - q.t0) / 0.03), c = mix(DUST, WARM, clamp(1 - (t - 0.03) / 0.25) * 0.55);+ p.disc(q.x, q.y, r, c, (d) => 0.58 * a * (1 - d * d * 0.75));+ p.disc(q.x - r * 0.22, q.y - r * 0.32, r * 0.58, mix(c, WHITE, 0.55), (d) => 0.48 * a * (1 - d * d));+ }+ for (const b of bits.list) rock(p, b, st);+ // the blob: white-hot and lumpy for a frame, then cream and a little bigger, then gone into the dust+ if (t < 0.058) {+ const f = t < 0.025 ? 0 : 1, R0 = f ? 13.5 : 11.5;+ p.shade(X - R0 * 1.4, Y - R0 * 1.4, X + R0 * 1.4, Y + R0 * 1.4, (x, y) => {+ const dx = x - X, dy = (y - Y) * (f ? 1.25 : 1.1), d = Math.hypot(dx, dy), ro = lump(R0, Math.atan2(dy, dx), PH + f * 0.6);+ if (d > ro) return;+ const q = d / ro;+ return f === 0 ? (q < 0.55 ? WHITE : q < 0.86 ? C[5] : C[4]) : q < 0.3 ? WHITE : q < 0.72 ? C[5] : q < 0.9 ? C[4] : C[3];+ });+ }+ // inked wedges jab out from the blob and snap back+ for (const w of wedges) {+ const u = t - w.t0;+ if (u < 0 || u > w.out + w.back) continue;+ const s = u < w.out ? ease.outCubic(u / w.out) : 1 - ease.inQuad((u - w.out) / w.back), L = w.len * s;+ if (L < 1.5) continue;+ const ca = Math.cos(w.a), sa = Math.sin(w.a), r0 = w.r0 + 2 * s, hw = (w.w * (0.6 + 0.4 * s)) / 2;+ const tip = [X + ca * r0, Y + sa * r0], end = [X + ca * (r0 + L), Y + sa * (r0 + L)], n = [-sa * hw, ca * hw];+ const wedge = (g) => [[tip[0] - ca * g, tip[1] - sa * g], [end[0] + n[0] * (1 + g * 0.45) + ca * g, end[1] + n[1] * (1 + g * 0.45) + sa * g], [end[0] - n[0] * (1 + g * 0.45) + ca * g, end[1] - n[1] * (1 + g * 0.45) + sa * g]];+ p.poly(wedge(1), C[1]);+ p.poly(wedge(0), u < w.out + 0.02 ? WHITE : C[5]);+ }+ const pop = Math.exp(-t / 0.06);+ if (pop > 0.02) p.glow(X, Y, 28, WARM, 0.5 * pop);+ lights.draw(p);+ },+ };}diff --git a/src/fx/impacts/bullet-impact.js b/src/fx/impacts/bullet-impact.jsindex 2226718..88ac954 100644--- a/src/fx/impacts/bullet-impact.js+++ b/src/fx/impacts/bullet-impact.js@@ -1,64 +1,101 @@-import { PAL, ramp, burst, fly, flyV, seg, ease, clamp, WHITE } from "../../core/index.js";-import { rayStar, streak, puff } from "./_lib.js";+// The open-sided star, the spark cone off the surface, the chips, dust and smoke are adapted from Sprite Fusion's+// open-source impact (https://www.spritefusion.com/pixel-art-vfx/impact), MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Lights, P, Rng, fit, clamp, smooth, ease, rand, TAU, WHITE, mix } from "../../core/index.js";+import { stone, spikes, star, SOOT } 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,+ desc: "A bullet hits a wall on the right: a hot half-star, sparks sprayed back in a cone, a puff of grit, chips that fall and bounce, a pock mark cooling to soot.",+ tags: ["impact", "bullet", "gun", "wall", "sparks", "debris", "directional", "one-shot"],+ size: [152, 100],+ origin: [116, 84],+ duration: 1.4,loop: false,fps: 30,- bg: "dark",- options: { palette: PAL.volt, dust: PAL.stone, count: 12, seed: 10 },+ bg: "ground",+ options: { palette: ["#4a1712", "#c9281f", "#f2561d", "#ff8a2a", "#ffe26b", "#fff3a6", "#ffffff"], stone: "#5b5079", height: 24, seed: 6 },};-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);+export function create(o) {+ const C = fit(o.palette, 7), st = stone(o.stone), R = new Rng(o.seed), X = 0, Y = -o.height, floor = () => 0, D = meta.duration;+ const ps = new Particles({ rng: R, ground: floor, sparks: [C[6], C[5], C[4], C[2]] });+ const lights = new Lights();+ // the wall's face looks left (N); the bullet came in level, a touch downward, and the spray bounces back off it+ const N = Math.PI, IN = 0.08, B = Math.PI - IN, open = (a) => Math.cos(a - N) > -0.25;+ const sp = spikes(R, 9, B, { len: [7, 10.5], w: [1.6, 2.1], fwd: 1.8, back: 0.4 });+ for (const s of sp) if (Math.cos(s.a - N) < -0.2) s.len *= 0.3;+ // the pock mark: a ragged hole with a rim that glows and cools+ const rim = [];+ for (let y = -2; y <= 2; y++)+ for (let x = 0; x <= 3; x++) {+ const d = Math.hypot((x - 1) / 1.6, y / 2.1) + rand(x, y, o.seed) * 0.35;+ if (d < 0.75) rim.push([x, y, 0]);+ else if (d < 1.25) rim.push([x, y, 1]);+ }+ const cracks = [0, 1, 2].map(() => {+ const a = R.range(-1.2, 1.2), L = R.range(2, 4.5);+ return [Math.cos(a) * 2.2 + 1, Math.sin(a) * 2.2, Math.cos(a) * (2.2 + L) + 1, Math.sin(a) * (2.2 + L)];});- // 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));++ lights.add(X - 4, Y, 40, C[4], 0.6, 0.22);+ lights.add(X - 2, Y, 14, WHITE, 0.6, 0.06);+ // sparks bounce back off the wall in a cone+ for (let i = 0; i < 18; i++) {+ const a = B + R.range(-1, 1) * 0.8, v = R.range(170, 450);+ ps.spawn(P.SPARK, X - 1, Y, Math.cos(a) * v, Math.sin(a) * v - 30, R.range(0.12, 0.4), WHITE, 1, i > 13 ? R.range(0.01, 0.04) : 0);}- // 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);+ // chips of the wall: flung out, falling, bouncing once and settling+ for (let i = 0; i < 8; i++) {+ const a = N + R.range(-0.8, 0.6), v = R.range(60, 190);+ ps.spawn(P.GRIT, X - 1, Y + R.range(-1, 1), Math.cos(a) * v, Math.sin(a) * v - R.range(20, 70), R.range(0.9, 1.3), R.pick([st.light, st.body, st.body, st.lip]), i < 3 ? 2 : 1);}- 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);+ // a puff of grit dust and a wisp of smoke drifting off+ for (let i = 0; i < 9; i++) {+ const a = N + R.range(-1.1, 1.1), v = R.range(15, 60);+ ps.spawn(P.DUST, X - 2, Y + R.range(-1.5, 1.5), Math.cos(a) * v, Math.sin(a) * v, R.range(0.3, 0.55), R.chance(0.5) ? st.dust : mix(st.dust, WHITE, 0.25), R.range(1.2, 2.3));+ }+ ps.spawn(P.SMOKE, X - 4, Y, R.range(-10, -4), R.range(-16, -8), R.range(0.8, 1.2), st.dust, R.range(1.8, 2.4), 0.05);++ let t = 0;+ return {+ update(dt) {+ t += dt;+ ps.update(dt);+ lights.update(dt);+ },+ drawBack(p) {+ ps.draw(p, "back");+ },+ draw(p) {+ // the pock mark: white-hot, cooling through the ramp to a dark rim, fading at the very end+ const heat = Math.pow(clamp(1 - t / 0.9), 1.3), fade = 1 - smooth(D - 0.45, D - 0.1, t);+ if (fade > 0) {+ for (const [x0, y0, x1, y1] of cracks) p.line(X + x0, Y + y0, X + x1, Y + y1, heat > 0.5 ? C[3] : st.shade, fade * (heat > 0.5 ? 1 : 0.85));+ for (const [x, y, k] of rim) {+ const h = heat * (k ? 0.85 : 1.15);+ p.dot(X + x, Y + y, k === 0 && h < 0.75 ? SOOT : h > 0.85 ? WHITE : h > 0.6 ? C[5] : h > 0.4 ? C[4] : h > 0.22 ? C[3] : h > 0.1 ? C[2] : st.shade, fade);+ }+ if (heat > 0) p.glow(X + 1, Y, 6 + 6 * heat, C[3], 0.5 * heat);+ }+ // a half ring opening away from the wall+ const u = (t - 0.03) / 0.18;+ if (u >= 0 && u < 1) {+ const r = 5 + 12 * ease.outCubic(u), c = u < 0.3 ? C[5] : u < 0.6 ? C[4] : C[3];+ for (let j = 0, n = Math.ceil(r * TAU * 1.3); j < n; j++) {+ const g = (j / n) * TAU;+ if (open(g)) p.dot(X + Math.cos(g) * r, Y + Math.sin(g) * r, c, 1.15 - u);+ }+ }+ ps.draw(p, "front");+ if (t < 0.03) star(p, X, Y, sp, 1, 1, [C[2], C[5], C[4], WHITE], 1, 2.2);+ else if (t < 0.06) star(p, X, Y, sp, 1.25, 0.55, [C[1], C[4], C[3], C[5]], 1, 2.2);+ const pop = Math.exp(-t / 0.045);+ if (pop > 0.02) {+ p.glow(X - 2, Y, 22, C[3], 0.6 * pop);+ p.glow(X - 1, Y, 8, WHITE, 0.5 * pop);+ p.glowLine(X + 1, Y - 16, X + 1, Y + 16, 4, C[4], 0.4 * pop); // light grazing the wall's face+ }+ lights.draw(p);+ },+ };}diff --git a/src/fx/impacts/combo-hit.js b/src/fx/impacts/combo-hit.jsdeleted file mode 100644index 942e5c5..0000000--- a/src/fx/impacts/combo-hit.js+++ /dev/null@@ -1,76 +0,0 @@-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.jsindex 8bff55c..53c1bff 100644--- a/src/fx/impacts/crit-hit.js+++ b/src/fx/impacts/crit-hit.js@@ -1,100 +1,114 @@-import { ramp, rng, burst, fly, seg, ease, clamp, TAU, WHITE } from "../../core/index.js";-import { streak } from "./_lib.js";+// The star, its key frames and the spark spray are adapted from Sprite Fusion's open-source impact+// (https://www.spritefusion.com/pixel-art-vfx/impact), MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Bits, Lights, P, B, Rng, fit, clamp, smooth, ease, TAU, WHITE } from "../../core/index.js";+import { spikes, star, brokenRing } 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,+ desc: "A critical hit: a jagged starburst slams in white and overshoots, a ring breaks into flying arcs, sparks streak off, shards tumble to the floor under a big flare.",+ tags: ["impact", "hit", "crit", "critical", "combat", "directional", "one-shot"],+ size: [216, 136],+ origin: [84, 106],+ duration: 0.9,loop: false,fps: 30,- bg: "dark",- options: {- palette: ["#2a0508", "#7a0d14", "#c81c1c", "#ff5a1a", "#ffb424", "#fff07a", "#ffffff"],- spikes: 12,- size: 1,- seed: 8,- },+ bg: "ground",+ options: { palette: ["#2a0510", "#5c0a1c", "#a3142a", "#e0302c", "#ff7a2a", "#ffc23d", "#fff09a", "#ffffff"], height: 26, aim: 0.12, seed: 3 },};-// 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;-}+// the star's key frames: [from t, scale, thickness, alpha, colors (rim, body, inner, core) as steps of the ramp]+const KEYS = [+ [0, 1, 1, 1, [6, 7, 7, 7]],+ [0.025, 1.3, 1, 1, [2, 5, 6, 7]],+ [0.058, 1.05, 0.72, 1, [2, 4, 5, 6]],+ [0.092, 1.22, 0.3, 1, [1, 2, 3, 4]],+ [0.125],+];-// 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;+// a lens flare: a long level streak, thick and white at the heart, a shorter upright one, on a bed of light+function flare(p, x, y, L, k, C) {+ for (const [dx, dy, len] of [[1, 0, L], [0, 1, L * 0.45], [0.7, 0.7, L * 0.16], [0.7, -0.7, L * 0.16]])+ for (const s of [-1, 1])+ for (let d = 1; d <= len; d++) {+ const u = d / len, a = u < 0.7 ? 1 : k * (1.6 - u);+ p.dot(x + s * dx * d, y + s * dy * d, u < 0.35 ? WHITE : u < 0.7 ? C[6] : C[5], a);+ if (dy === 0 && u < 0.42) for (const e of [-1, 1]) p.dot(x + s * d, y + e, u < 0.2 ? C[6] : C[5], u < 0.3 ? 1 : k);+ }+ p.glowLine(x - L, y, x + L, y, 6, C[6], 0.5 * k);+ p.glowLine(x, y - L * 0.45, x, y + L * 0.45, 4, C[6], 0.3 * k);}-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;- });+export function create(o) {+ const C = fit(o.palette, 8), R = new Rng(o.seed), X = 0, Y = -o.height, A = o.aim, floor = () => 0;+ const ps = new Particles({ rng: R, ground: floor, sparks: [C[7], C[6], C[5], C[3]] });+ const bits = new Bits({ ground: floor }), lights = new Lights();+ const sp = spikes(R, 14, A, { len: [11, 15], w: [1.8, 2.5], fwd: 1.4, back: 0.6, jag: 0.5 });+ [...sp].sort((a, b) => b.len - a.len).slice(0, 2).forEach((s) => (s.len *= 1.3));+ const segs = Array.from({ length: 7 }, (_, i) => {+ const a = A + (i / 7) * TAU;+ return { a, gap: R.range(0.55, 0.85), dr: R.range(0.08, 0.4) + 0.15 * Math.max(0, Math.cos(a - A)), w: 0.7 + 0.5 * Math.max(0, Math.cos(a - A)) };+ });++ lights.add(X, Y, 84, C[5], 0.6, 0.5);+ lights.add(X, Y, 30, WHITE, 0.7, 0.1);+ lights.add(X, -4, 44, C[4], 0.3, 0.45);+ // sparks: most sprayed on along the blow, a few kicked back+ for (let i = 0; i < 36; i++) {+ const back = R.chance(0.22), a = (back ? A + Math.PI : A) + R.range(-1, 1) * (back ? 0.6 : 0.8), v = R.range(170, 430) * (back ? 0.6 : 1);+ ps.spawn(P.SPARK, X, Y, Math.cos(a) * v, Math.sin(a) * v - 50, R.range(0.15, 0.5), WHITE, 1, R.chance(0.3) ? R.range(0, 0.04) : 0);}- // 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));+ // shards: bright splinters that tumble down, bounce and settle+ for (let i = 0; i < 10; i++) {+ const a = A + R.range(-1, 1) * 1.1 - 0.35, v = R.range(110, 280);+ bits.add({ kind: B.SHARD, x: X, y: Y, vx: Math.cos(a) * v, vy: Math.sin(a) * v - 40, g: 0.8, drag: 0.7, bounce: 0.35, life: R.range(0.55, 0.85), a: R.range(0, TAU), va: R.range(-25, 25), s: R.range(2, 4.5), c: R.pick([C[7], C[6], C[6], C[5]]) });}- // 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);+ // embers of light drifting up and off, and glints that pop round the ring after the hit+ for (let i = 0; i < 12; i++) {+ const a = A - Math.PI / 2 + R.range(-1.4, 1.4), v = R.range(35, 110);+ ps.spawn(P.MOTE, X + Math.cos(a) * 4, Y + Math.sin(a) * 4, Math.cos(a) * v, Math.sin(a) * v - 15, R.range(0.35, 0.7), R.pick([C[6], C[5], C[5]]), 0.6, R.range(0, 0.05));+ }+ for (let i = 0; i < 5; i++) {+ const a = R.range(0, TAU), d = R.range(14, 34);+ ps.spawn(P.STAR, X + Math.cos(a) * d, Y + Math.sin(a) * d * 0.8, 0, -4, R.range(0.22, 0.38), R.chance(0.5) ? C[6] : WHITE, R.range(1.6, 3), R.range(0.08, 0.32));+ }++ let t = 0;+ return {+ update(dt) {+ t += dt;+ ps.update(dt);+ bits.update(dt);+ lights.update(dt);+ },+ draw(p) {+ // the ring: it swells off the star, then breaks into arcs that fly on and cool+ const u = clamp((t - 0.03) / 0.37);+ if (t >= 0.03 && u < 1) {+ const r = 10 + 30 * ease.outCubic(u), brk = smooth(0.12, 0.6, u), th = Math.max(1, 3.6 * Math.pow(1 - u, 1.2));+ const i = u < 0.12 ? 7 : u < 0.3 ? 6 : u < 0.5 ? 5 : u < 0.75 ? 4 : 3;+ brokenRing(p, X, Y, r, th, segs, brk, C[i], C[Math.max(2, i - 2)], u < 0.6 ? 1 : (1 - u) / 0.4, 1, 0);+ if (u < 0.6) p.glowRing(X, Y, r, 6, C[5], 0.35 * Math.pow(1 - u / 0.6, 2));+ }+ bits.draw(p);+ ps.draw(p);+ // the flare blooms as the star collapses+ const f = (t - 0.04) / 0.28;+ if (f > 0 && f < 1) {+ flare(p, X, Y, 64 * Math.pow(1 - f, 1.3), 1 - f, C);+ p.glow(X, Y, 56, C[5], 0.4 * (1 - f));+ }+ // the starburst slams in: a white frame, an overshoot, a settle, then it breaks up+ for (let i = 0; i < KEYS.length - 1; i++)+ if (t >= KEYS[i][0] && t < KEYS[i + 1][0]) {+ const [, sc, th, a, cols] = KEYS[i];+ star(p, X, Y, sp, sc, th, cols.map((j) => C[j]), a, 2.6);+ }+ const pop = Math.exp(-t / 0.05);+ if (pop > 0.02) {+ p.glow(X, Y, 44, C[5], 0.4 * pop);+ p.glow(X, Y, 12, WHITE, 0.6 * pop);+ }+ lights.draw(p);+ },+ };}diff --git a/src/fx/impacts/ground-slam.js b/src/fx/impacts/ground-slam.jsindex 9e56525..880a0bc 100644--- a/src/fx/impacts/ground-slam.js+++ b/src/fx/impacts/ground-slam.js@@ -1,121 +1,164 @@-import { PAL, ramp, hex, burst, fly, seg, ease, clamp, TAU, WHITE } from "../../core/index.js";-import { puff } from "./_lib.js";+// The rocks, grit, rolling floor dust and dust column are adapted from Sprite Fusion's open-source explosion+// (https://www.spritefusion.com/pixel-art-vfx/explosion), MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Bits, Lights, P, PF, B, Rng, fit, band, clamp, smooth, ease, TAU, WHITE, mix } from "../../core/index.js";+import { stone, star, makeCracks, drawCracks, frontCrescent, rock, rockShape, SOOT } 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,+ desc: "Something lands hard: the floor flashes and cracks, two crescent shock waves race out along it, a dust wave and a tall dust cloud rise, rocks erupt, bounce and settle.",+ tags: ["impact", "ground", "slam", "shockwave", "quake", "rocks", "dust", "one-shot"],+ size: [288, 208],+ origin: [144, 164],+ duration: 3.2,loop: false,fps: 30,bg: "ground",- options: { palette: PAL.stone, dust: PAL.dust, radius: 56, count: 9, seed: 12 },+ options: { palette: ["#2a1712", "#5e2c1c", "#a4502a", "#e8893a", "#ffc764", "#fff0b4", "#ffffff"], stone: "#4a3f69", reach: 104, seed: 5 },};-const HOT = hex("#ffe2a0");+const WAVE = 0.6; // seconds for the shock fronts to run out-// 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];+// the dent: the floor's edge caves into a shallow dish, its bottom glowing while hot, lips thrown up either side+function crater(p, st, hot, C, k) {+ for (let x = -12; x <= 11; x++) {+ const q = Math.abs(x + 0.5) / 12, dep = Math.round(2.6 * (1 - q * q));+ if (q < 0.84) {+ for (let y = 0; y < dep; y++) p.dot(x, y, SOOT, k);+ p.dot(x, dep, hot > 0.5 ? C[5] : hot > 0.2 ? C[4] : st.lip, k);+ } else {+ p.dot(x, -1, q > 0.93 ? st.light : st.lip, k);+ if (q < 0.9) p.dot(x, -2, st.light, k * 0.8);+ }+ }}-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+export function create(o) {+ const C = fit(o.palette, 7), st = stone(o.stone), REACH = o.reach, R = new Rng(o.seed), floor = () => 0, D = meta.duration;+ const ps = new Particles({ rng: R, ground: floor, sparks: [C[6], C[5], C[4], C[3]] });+ const bits = new Bits({ ground: floor }), lights = new Lights(), HOT = [WHITE, C[5], C[4], C[3]];+ const dustLit = mix(st.dust, WHITE, 0.2), cracks = makeCracks(R, 10, { len: [22, 58], dive: 0.55, maxY: 22, forks: 0.7, x0: [2, 9] });+ const front = (t) => 7 + (REACH - 7) * ease.outCubic(clamp((t - 0.015) / WAVE));+ const heat = (t) => Math.pow(clamp(1 - t / 0.8), 1.4);+ const crest = (u) => [6 + 28 * Math.pow(1 - u, 0.75), 1.5 + 5 * Math.pow(1 - u, 0.9)]; // a front's height and thickness+ // the flash: a flat half-star hugging the floor, long rays along it, short ones up+ const burst = [+ { a: -0.07, len: R.range(34, 40), w: 1.9 }, { a: Math.PI + 0.07, len: R.range(34, 40), w: 1.9 },+ { a: -0.42 + R.range(-0.08, 0.08), len: R.range(15, 20), w: 1.5 }, { a: -Math.PI + 0.42 + R.range(-0.08, 0.08), len: R.range(15, 20), w: 1.5 },+ { a: -Math.PI / 2 + R.range(-0.15, 0.15), len: R.range(18, 24), w: 1.7 },+ { a: -1.05 + R.range(-0.1, 0.1), len: R.range(10, 14), w: 1.2 }, { a: -Math.PI + 1.05 + R.range(-0.1, 0.1), len: R.range(10, 14), w: 1.2 },+ ];+ // embers caught in the cracks, flickering as they cool+ const embers = [];+ for (const c of cracks)+ for (const [x, y, d] of c.pts) if (d > 3 && d < 32 && R.chance(0.25)) embers.push({ x, y, d, life: R.range(0.8, 2.2), ph: R.range(0, TAU) });++ // contact: light floods out, sparks fly off the stone and skitter along the floor+ lights.add(0, -12, 96, C[4], 0.6, 0.6);+ lights.add(0, -4, 50, WHITE, 0.9, 0.14);+ for (let i = 0; i < 56; i++) {+ const low = i < 14, s = R.sign(), a = low ? (s > 0 ? -R.range(0.04, 0.6) : Math.PI + R.range(0.04, 0.6)) : -Math.PI / 2 + R.range(-1.15, 1.15);+ const sp = low ? R.range(150, 380) : R.range(200, 500);+ ps.spawn(P.SPARK, R.range(-4, 4), -1, Math.cos(a) * sp, Math.sin(a) * sp, low ? R.range(0.2, 0.5) : R.range(0.25, 0.65), WHITE, 1, low ? 0 : R.range(0, 0.05));+ }+ // rocks erupt from the dent: three heavy ones that barely clear it, the rest thrown high+ for (let i = 0; i < 20; i++) {+ const s = i < 3 ? 4 : R.int(1, 3), a = -Math.PI / 2 + R.range(-0.5, 0.5), sp = s > 3 ? R.range(110, 190) : R.range(170, 380) * (s > 2 ? 0.8 : 1);+ bits.add({ kind: B.CHUNK, x: R.range(-7, 7), y: -2, vx: Math.cos(a) * sp, vy: Math.sin(a) * sp, g: 1, drag: 0.4, bounce: 0.38, life: R.range(1.9, 2.7), a: R.range(0, TAU), va: R.range(-14, 14), s, pts: rockShape(R), pvy: 0 });+ }+ // grit: a fan of floor bits that bounce once and settle+ for (let i = 0; i < 110; i++) {+ const u = R.range(-1, 1), a = -Math.PI / 2 + u * 0.65, sp = R.range(110, 380) * (1 - 0.35 * Math.abs(u));+ ps.spawn(P.GRIT, u * 6, -1, Math.cos(a) * sp, Math.sin(a) * sp, R.range(1, 2.2), R.pick([st.light, st.body, st.body, st.shade, st.shade, st.lip]), R.chance(0.35) ? 2 : 1);}- // 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 dust cloud: a column that shoots up and spreads at the top, lit on top, and a heavy bank at its foot+ for (let i = 0; i < 28; i++) {+ const core = i < 14, s = R.sign();+ ps.spawn(P.SMOKE, core ? R.range(-5, 5) : s * R.range(4, 12), -R.range(2, 10), core ? R.range(-12, 12) : s * R.range(14, 38), -R.range(50, 130) * (core ? 1 : R.range(0.3, 0.6)), R.range(1.9, 2.7), R.chance(0.35) ? dustLit : st.dust, core ? R.range(4.5, 9) : R.range(4, 7.5), R.range(0.02, 0.22), PF.BIG);}- // 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));+ for (let i = 0; i < 10; i++) {+ const s = R.sign();+ ps.spawn(P.SMOKE, s * R.range(2, 14), -R.range(2, 6), s * R.range(20, 70), -R.range(4, 20), R.range(1.4, 2.3), st.dust, R.range(6, 9), R.range(0, 0.08), PF.BIG);}- // 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);+ // fine dust settling out of the cloud while it hangs+ for (let i = 0; i < 26; i++)+ ps.spawn(P.FLAKE, R.range(-22, 22), -R.range(14, 80), R.range(-12, 12), R.range(-10, 4), R.range(1.2, 2), R.chance(0.5) ? st.lip : dustLit, R.range(0.5, 1.2), R.range(0.25, 1));++ let t = 0;+ const acc = [R.next(), R.next()];+ const ring = (p, back) => {+ const u = clamp((t - 0.015) / (WAVE + 0.1));+ if (t < 0.015 || u >= 0.9) return;+ band(p, 0, 0.5, front(t) + 1, 0.16, Math.max(1, 4 * Math.pow(1 - u, 0.8)), u < 0.55 ? 1.1 : (0.9 - u) / 0.35,+ u < 0.35 ? [C[3], C[4], C[5], C[6]] : [st.body, st.light, C[4], C[5]], (g) => Math.sin(g) < 0 === back, t < 0.09);+ };+ const fronts = (p) => {+ const u = clamp((t - 0.03) / (WAVE + 0.16));+ if (t < 0.03 || u >= 1) return;+ const fr = front(t), [h, w] = crest(u), k = u < 0.7 ? 1 : (1 - u) / 0.3;+ const cols = u < 0.14 ? [WHITE, C[6], C[5]] : u < 0.34 ? [C[6], C[5], C[4]] : u < 0.55 ? [C[5], C[4], st.lip] : [st.lip, st.light, st.dust];+ for (const s of [-1, 1]) {+ frontCrescent(p, s * fr, s, h, w, cols, k);+ p.glow(s * fr, -h * 0.3, 8 + h * 0.7, C[4], 0.5 * (1 - u) * k);+ }+ };++ return {+ update(dt) {+ t += dt;+ // dust kicked up behind the racing fronts, and spray off their crests+ const u = clamp((t - 0.015) / WAVE);+ if (u > 0 && u < 1) {+ const fr = front(t), [h] = crest(u);+ for (let k = 0; k < 2; k++) {+ const s = k ? 1 : -1;+ for (acc[k] += dt * 120 * (1 - u * 0.7); acc[k] > 1; acc[k]--) {+ ps.spawn(P.SMOKE, s * (fr - R.range(1, 7)), -R.range(0.5, 3), s * R.range(15, 70) * (1 - u), -R.range(2, 12), R.range(1, 2.1), R.chance(0.3) ? dustLit : st.dust, R.range(2.5, 6.5) * (1 - 0.4 * u), 0, PF.BIG);+ if (R.chance(0.5)) ps.spawn(P.DUST, s * (fr - R.range(0, 3)), -R.range(0.3, 0.9) * h, s * R.range(-15, 25), -R.range(8, 35), R.range(0.3, 0.6), R.chance(0.5) ? dustLit : st.dust, R.range(1.2, 2.4));+ if (R.chance(0.4)) ps.spawn(P.GRIT, s * fr, -1, s * R.range(10, 60), -R.range(40, 140) * (1 - u), R.range(0.5, 1), R.pick([st.light, st.body, st.lip]), 1);+ if (u < 0.45 && R.chance(0.2)) ps.spawn(P.SPARK, s * fr, -1, s * R.range(60, 200), -R.range(30, 160), R.range(0.12, 0.3));+ }+ }+ }+ for (const b of bits.list) b.pvy = b.vy;+ bits.update(dt);+ // rocks that land hard kick up dust+ for (const b of bits.list)+ if (b.pvy > 70 && b.vy <= 0) {+ const n = b.pvy > 200 ? 3 : 2;+ for (let i = 0; i < n; i++) ps.spawn(P.DUST, b.x + R.range(-1.5, 1.5), -0.5, R.sign() * R.range(8, 35), -R.range(2, 16), R.range(0.3, 0.65), st.dust, R.range(1.3, 2.4) * (0.7 + b.s * 0.25));+ b.pvy = 0;+ }+ ps.update(dt);+ lights.update(dt);+ },+ drawBack(p) {+ const fade = 1 - smooth(D - 0.9, D - 0.15, t), H = heat(t);+ if (t > 0.02) crater(p, st, H, C, fade);+ drawCracks(p, cracks, (c) => c.len * ease.outCubic(clamp((t - c.t0) / 0.1)), (d) => H * clamp(1.2 - d / 40), HOT, SOOT, st.light, fade);+ for (const e of embers) {+ const k = 1 - (t - 0.1) / e.life;+ if (t < 0.1 || k <= 0) continue;+ const f = 0.6 + 0.4 * Math.sin(t * 23 + e.ph);+ p.px(e.x, e.y, k * f > 0.55 ? C[5] : k * f > 0.25 ? C[4] : C[3]);+ p.glow(e.x, e.y, 4, C[4], 0.35 * k * f);+ }+ ring(p, true);+ ps.draw(p, "back");+ },+ draw(p) {+ ring(p, false);+ fronts(p);+ for (const b of bits.list) rock(p, b, st);+ ps.draw(p, "front");+ if (t < 0.035) {+ p.ellipse(0, 0, 30, 4.5, (d) => (d > 0.8 ? C[4] : d > 0.5 ? C[6] : WHITE));+ star(p, 0, -1, burst, 1, 1, [C[4], C[6], WHITE, WHITE]);+ } else if (t < 0.07) star(p, 0, -1, burst, 1.25, 0.5, [C[3], C[5], C[6], WHITE]);+ // the floor flashes along its length, then the dent glows while the cracks are hot+ if (t < 0.14) p.glowLine(-80, 0, 80, 0, 10, C[5], 0.55 * (1 - t / 0.14));+ const H = heat(t);+ if (H > 0) p.glow(0, 1, 46, C[4], 0.35 * H);+ lights.draw(p);+ },+ };}diff --git a/src/fx/impacts/heavy-landing.js b/src/fx/impacts/heavy-landing.jsindex de03c9c..8636f49 100644--- a/src/fx/impacts/heavy-landing.js+++ b/src/fx/impacts/heavy-landing.js@@ -1,86 +1,103 @@-import { PAL, ramp, rng, burst, fly, seg, ease, clamp, noise, WHITE } from "../../core/index.js";-import { puff } from "./_lib.js";+// The rocks, grit and dust are adapted from Sprite Fusion's open-source explosion+// (https://www.spritefusion.com/pixel-art-vfx/explosion), MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Bits, P, B, Rng, fit, band, clamp, smooth, ease, TAU, WHITE, mix, hex } from "../../core/index.js";+import { stone, makeCracks, drawCracks, dustRing, rock, rockShape, SOOT } 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,+ desc: "A character lands hard: the floor dents and cracks under their feet, two rings of dust roll out along the floor one after the other, and pebbles hop away.",+ tags: ["impact", "landing", "ground", "stomp", "dust", "rocks", "actor", "one-shot"],+ size: [176, 80],+ origin: [88, 60],+ duration: 1.6,loop: false,fps: 30,bg: "ground",- options: { palette: PAL.dust, stone: PAL.stone, size: 1, seed: 16 },+ actor: 2,+ options: { palette: ["#1c1a24", "#2f2a3a", "#4a4258", "#6b6280", "#9088a4", "#bdb6cc", "#e6e1ee"], stone: "#4a3f69", seed: 14 },};-// 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)]);+// the dent: the floor's edge pressed into a shallow dish, scuffed lips either side+function dent(p, st, k) {+ for (let x = -10; x <= 9; x++) {+ const q = Math.abs(x + 0.5) / 10, dep = Math.round(1.8 * (1 - q * q));+ if (q < 0.82) {+ for (let y = 0; y < dep; y++) p.dot(x, y, SOOT, k);+ p.dot(x, dep, st.lip, k);+ } else p.dot(x, -1, q > 0.92 ? st.light : st.lip, k);}- 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);+export function create(o) {+ const C = fit(o.palette, 7), st = stone(o.stone), R = new Rng(o.seed), floor = () => 0, D = meta.duration;+ // the rings' far halves go behind the character, the near halves and all the debris in front+ const back = new Particles({ rng: R, ground: floor }), front = new Particles({ rng: R, ground: floor });+ const bits = new Bits({ ground: floor }), cracks = makeCracks(R, 6, { len: [8, 20], dive: 0.7, maxY: 12, forks: 0.4, x0: [2, 6] });+ const DUST = mix(st.dust, C[5], 0.4), LIT = mix(DUST, WHITE, 0.3), PH = R.range(0, TAU);+ // puffs riding each ring out along the floor+ const ring = (n, v0, v1, size, delay) => {+ for (let i = 0; i < n; i++) {+ const g = (i / n) * TAU + R.range(-0.1, 0.1), v = R.range(v0, v1), far = Math.sin(g) < 0;+ (far ? back : front).spawn(P.DUST, Math.cos(g) * 4, Math.sin(g) * 0.7 - 1, Math.cos(g) * v, Math.sin(g) * v * 0.16 - R.range(2, 10), R.range(0.45, 0.8), R.chance(0.45) ? LIT : DUST, R.range(size[0], size[1]), delay + R.range(0, 0.03));+ }+ };+ ring(20, 140, 190, [2.2, 3.4], 0.01);+ ring(18, 70, 110, [3.4, 5.4], 0.12);+ // and a low cloud at the feet that rises a little and hangs+ for (let i = 0; i < 12; i++) {+ const s = R.sign(), up = i < 6;+ (i % 2 ? front : back).spawn(P.DUST, s * R.range(2, 10), -R.range(1, 4), s * R.range(10, 35) * (up ? 0.6 : 1), -(up ? R.range(25, 60) : R.range(4, 12)), R.range(0.55, 0.9), R.chance(0.5) ? LIT : DUST, R.range(3, 5), R.range(0.02, 0.1));+ }+ // pebbles that hop away along the floor, and grit+ for (let i = 0; i < 12; i++) {+ const s = R.sign(), v = R.range(50, 130);+ bits.add({ kind: B.CHUNK, x: s * R.range(3, 8), y: -1, vx: s * v, vy: -R.range(140, 230), g: 1, drag: 0.5, bounce: 0.55, life: R.range(1, 1.45), a: R.range(0, TAU), va: s * R.range(8, 16), s: R.chance(0.3) ? 2 : 1, pts: rockShape(R) });}- // 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]);- });+ for (let i = 0; i < 24; i++) {+ const s = R.sign(), a = -Math.PI / 2 + s * R.range(0.3, 1.2), v = R.range(60, 170);+ front.spawn(P.GRIT, s * R.range(2, 7), -1, Math.cos(a) * v, Math.sin(a) * v, R.range(0.6, 1.1), R.pick([st.light, st.body, st.lip]), R.chance(0.3) ? 2 : 1);+ }++ let t = 0;+ // the two dust rings themselves: soft bands on the floor, the second slower, lumpier and later+ const rings = (p, far) => {+ for (const [t0, dur, r1, w, k0, edge] of [[0.01, 0.45, 58, 4.5, 0.75, 1], [0.12, 0.85, 42, 6, 0.8, 0]]) {+ const g = (t - t0) / dur;+ if (g <= 0 || g >= 1) continue;+ const r = 6 + r1 * ease.outCubic(g);+ dustRing(p, 0, 0, r, w * (1 + g), k0 * Math.pow(1 - g, 1.2) * Math.min(1, g / 0.06), DUST, { sy: 0.2, ph: PH + t0 * 10, brk: g * 0.8, half: far ? -1 : 1 });+ // the fast ring's leading edge: a crisp lit band on the floor+ if (edge && g < 0.75) band(p, 0, 0.5, r + 2, 0.2, Math.max(1, 2.5 * (1 - g)), 1.1 - g / 0.75, [st.body, st.light, LIT, WHITE], (a) => Math.sin(a) < 0 === far);+ }+ };+ return {+ update(dt) {+ t += dt;+ for (const b of bits.list) b.pvy = b.vy;+ bits.update(dt);+ for (const b of bits.list)+ if (b.pvy > 80 && b.vy <= 0) {+ front.spawn(P.DUST, b.x, -0.5, R.sign() * R.range(6, 20), -R.range(2, 10), R.range(0.25, 0.45), DUST, R.range(1, 1.8));+ b.pvy = 0;+ }+ back.update(dt);+ front.update(dt);+ },+ drawBack(p) {+ const fade = 1 - smooth(D - 0.5, D - 0.1, t);+ dent(p, st, fade);+ drawCracks(p, cracks, (c) => c.len * ease.outCubic(clamp((t - c.t0) / 0.08)), () => 0, [WHITE, WHITE, WHITE, WHITE], SOOT, st.light, fade);+ rings(p, true);+ back.draw(p);+ },+ draw(p) {+ rings(p, false);+ front.draw(p);+ for (const b of bits.list) rock(p, b, st);+ // the thud: a flat streak of light along the floor for a frame or two+ if (t < 0.035) p.ellipse(0, 0, 15, 2.5, (d) => (d < 0.55 ? WHITE : C[6]));+ else if (t < 0.07) for (let x = -22; x <= 22; x++) p.dot(x, 0, Math.abs(x) < 10 ? WHITE : C[5], 1 - Math.abs(x) / 24);+ if (t < 0.12) p.glowLine(-20, 0, 20, 0, 8, C[6], 0.45 * (1 - t / 0.12));+ },+ };}diff --git a/src/fx/impacts/hit-flash.js b/src/fx/impacts/hit-flash.jsindex 6c7a1a9..309367d 100644--- a/src/fx/impacts/hit-flash.js+++ b/src/fx/impacts/hit-flash.js@@ -1,44 +1,90 @@-import { PAL, ramp, burst, seg, ease, WHITE } from "../../core/index.js";+import { Lights, Rng, fit, clamp, ease, TAU, WHITE, mix, luma, red, green, blue, rgb } 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,+ desc: "The character takes damage: a white frame, then their own colors flushed red and blinking white, cooling off, while comic hit lines jab in at them.",+ tags: ["impact", "hit", "damage", "hurt", "flash", "blink", "actor", "comic", "one-shot"],+ size: [80, 64],+ origin: [40, 54],+ duration: 0.5,loop: false,fps: 30,bg: "ground",- actor: true,- options: { palette: PAL.blood, lines: 6, seed: 17 },+ actor: 2,+ options: { palette: ["#14040a", "#3a0a14", "#6a101c", "#a01824", "#d42a30", "#ff5a50", "#ff9a8a"], lines: 7, side: 1, 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]));- });+// the beats, by frame at 30 fps: white, white, red, red, white rim, red cooling off+const BEATS = [[0.025, "white"], [0.058, "white2"], [0.125, "red"], [0.158, "rim"], [0.36, "cool"]];++export function create(o) {+ const C = fit(o.palette, 7), R = new Rng(o.seed), A = o.actor, M = A.mask, PX = A.pixels, S = o.side;+ const [cx, cy] = A.chest, hx = cx + S * 12, hy = cy - 5; // where the blow lands: the character's front, chest high+ const lights = new Lights();+ lights.add(hx, hy, 34, WHITE, 0.6, 0.1);+ lights.add(cx, cy, 30, C[4], 0.5, 0.35);+ // the hurt colors: each pixel's own light and shade carried into the red ramp+ const reds = new Uint32Array(PX.length), tints = new Uint32Array(PX.length);+ for (let i = 0; i < PX.length; i++) {+ if (!PX[i]) continue;+ const l = luma(PX[i] | 0xff000000);+ reds[i] = C[clamp(Math.round(2 + l * 5), 2, 6)];+ tints[i] = mix(PX[i] | 0xff000000, C[4], 0.55);}- 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);+ // hit lines all round the top and sides, jabbing in at the body+ const lines = Array.from({ length: o.lines }, (_, i) => {+ const a = -Math.PI - 0.3 + ((i + R.range(0.25, 0.75)) / o.lines) * (Math.PI + 0.6);+ return { a, d: R.range(15, 19), len: R.range(6, 9), t0: R.range(0, 0.04) };+ });+ let t = 0;+ const beat = () => {+ for (const [end, b] of BEATS) if (t < end) return b;+ return null;+ };+ const body = (p, color) => p.mask(M, A.x, A.y, (mx, my) => color(my * M.w + mx));+ return {+ update(dt) {+ t += dt;+ lights.update(dt);+ },+ draw(p) {+ const b = beat();+ if (b === "white" || b === "white2") {+ body(p, () => WHITE);+ p.outline(M, A.x, A.y, b === "white" ? C[6] : C[5]);+ } else if (b === "red") {+ body(p, (i) => reds[i]);+ p.outline(M, A.x, A.y, C[5]);+ } else if (b === "rim") p.outline(M, A.x, A.y, WHITE);+ else if (b === "cool") {+ const k = 1 - (t - 0.158) / (0.36 - 0.158);+ body(p, (i) => mix(PX[i] | 0xff000000, tints[i], k));+ if (k > 0.5) p.outline(M, A.x, A.y, C[4], (k - 0.5) * 2);+ }+ // the blow: a small hot burst on the side it came from+ if (t < 0.07) {+ const big = t < 0.035 ? 1 : 1.3, k = t < 0.035 ? 0 : 1;+ for (let i = 0; i < 8; i++) {+ const a = (i / 8) * TAU + 0.2, L = (i % 2 ? 4 : 9) * big;+ p.line(hx + Math.cos(a) * L * 0.45 * k, hy + Math.sin(a) * L * 0.45 * k, hx + Math.cos(a) * L, hy + Math.sin(a) * L, (u) => (u < 0.45 && !k ? WHITE : u < 0.75 ? C[6] : C[4]));+ }+ if (!k) for (const [dx, dy] of [[0, 0], [1, 0], [-1, 0], [0, 1], [0, -1]]) p.px(hx + dx, hy + dy, WHITE);+ p.glow(hx, hy, 14, C[6], 0.5 * (1 - t / 0.07));+ }+ // comic hit lines jab in toward the body, then are gone+ for (const l of lines) {+ const u = (t - l.t0) / 0.16;+ if (u < 0 || u >= 1) continue;+ const d0 = l.d - 6 * ease.outCubic(u), L = l.len * (1 - u), ca = Math.cos(l.a), sa = Math.sin(l.a) * 1.15;+ if (L < 1) continue;+ // a wedge, its point at the body and its fat end out, white with a red edge+ const w = (2.8 - 1.6 * u) / 2, nx = -sa * w, ny = ca * w, ex = cx + ca * (d0 + L), ey = cy + sa * (d0 + L), px0 = cx + ca * d0, py0 = cy + sa * d0;+ p.poly([[px0 - ca, py0 - sa], [ex + nx * 1.5 + ca, ey + ny * 1.5 + sa], [ex - nx * 1.5 + ca, ey - ny * 1.5 + sa]], C[3]);+ p.poly([[px0, py0], [ex + nx, ey + ny], [ex - nx, ey - ny]], u < 0.5 ? WHITE : C[6]);+ }+ const k = Math.exp(-t / 0.08);+ if (k > 0.02) p.glow(cx, cy, 26, b === "white" || b === "white2" ? WHITE : C[5], 0.35 * k);+ lights.draw(p);+ },+ };}diff --git a/src/fx/impacts/hit-spark.js b/src/fx/impacts/hit-spark.jsindex 602a92a..970f6a1 100644--- a/src/fx/impacts/hit-spark.js+++ b/src/fx/impacts/hit-spark.js@@ -1,45 +1,98 @@-import { PAL, ramp, rng, burst, fly, flyV, seg, clamp, WHITE } from "../../core/index.js";-import { rayStar, starRays, streak } from "./_lib.js";+// The two-tone spark spray and the light pop are adapted from Sprite Fusion's open-source impact+// (https://www.spritefusion.com/pixel-art-vfx/impact), MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Lights, P, Rng, fit, WHITE } from "../../core/index.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,+ desc: "The everyday hit: a sharp, lopsided cross flare with one long ray along the blow round a white diamond core, then a cone of sparks and hot chips that fall and bounce.",+ tags: ["impact", "hit", "spark", "combat", "directional", "one-shot"],+ size: [136, 80],+ origin: [44, 64],+ duration: 0.5,loop: false,fps: 30,- bg: "dark",- options: { palette: PAL.volt, points: 8, size: 1, seed: 7 },+ bg: "ground",+ options: { palette: ["#4a1712", "#c9281f", "#f2561d", "#ff8a2a", "#ffe26b", "#fff3a6", "#ffffff"], height: 20, aim: 0.1, seed: 4 },};-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]);+// one ray of the cross: fat at the root, a hair at the tip, white cooling outward; from..to draws a stretch of it+function ray(p, x, y, a, L, w, C, from = 0) {+ const c = Math.cos(a), s = Math.sin(a);+ for (let d = from * L; d <= L; d += 0.5) {+ const u = d / L, hw = w * Math.pow(1 - u, 1.6);+ const col = u < 0.3 ? WHITE : u < 0.62 ? C[5] : u < 0.88 ? C[4] : C[3];+ p.px(x + c * d, y + s * d, col);+ if (hw > 0.45) for (let o = 0.5; o <= hw; o += 0.5) for (const e of [-o, o]) p.px(x + c * d - s * e, y + s * d + c * e, u < 0.3 && o < 1 ? C[5] : C[4]);}- // 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);+}++// the core: a crisp white diamond with a pale rim+function diamond(p, x, y, r, C) {+ for (let dy = -r - 1; dy <= r + 1; dy++)+ for (let dx = -r - 1; dx <= r + 1; dx++) {+ const m = Math.abs(dx) + Math.abs(dy);+ if (m <= r) p.px(x + dx, y + dy, WHITE);+ else if (m === r + 1) p.px(x + dx, y + dy, C[3]);+ }+}++export function create(o) {+ const C = fit(o.palette, 7), R = new Rng(o.seed), X = 0, Y = -o.height, A = o.aim, floor = () => 0;+ const ps = new Particles({ rng: R, ground: floor, sparks: [C[6], C[5], C[4], C[2]] });+ const lights = new Lights();+ // the cross: a long thin ray along the blow, a stub behind, two unequal arms across, and a glint between+ const tilt = R.range(-0.08, 0.08);+ const rays = [+ { a: A + tilt, L: R.range(33, 37), w: 2.2 },+ { a: A + Math.PI + tilt, L: R.range(8, 10), w: 2.2 },+ { a: A - Math.PI / 2 + tilt, L: R.range(15, 18), w: 2.6 },+ { a: A + Math.PI / 2 + tilt, L: R.range(10, 12), w: 2.3 },+ { a: A - Math.PI / 4 + tilt, L: R.range(5, 7), w: 1 },+ ];++ lights.add(X, Y, 38, C[4], 0.35, 0.18);+ lights.add(X + Math.cos(A) * 10, Y + Math.sin(A) * 10, 22, C[5], 0.45, 0.1);+ lights.add(X, -2, 26, C[3], 0.22, 0.22);+ // a cone of sparks sprayed on along the blow: they fall, bounce off the floor and die+ for (let i = 0; i < 9; i++) {+ const a = A + R.range(-0.6, 0.6) - 0.15, v = R.range(170, 360);+ ps.spawn(P.SPARK, X + 1, Y, Math.cos(a) * v, Math.sin(a) * v - 40, R.range(0.25, 0.45), WHITE, 1, i > 6 ? R.range(0.01, 0.03) : 0);+ }+ // hot pixel chips knocked off, tumbling down to tick off the floor+ for (let i = 0; i < 6; i++) {+ const a = A + R.range(-1.1, 0.5) - 0.3, v = R.range(70, 170);+ ps.spawn(P.GRIT, X + 1, Y, Math.cos(a) * v, Math.sin(a) * v - R.range(30, 80), R.range(0.35, 0.45), R.pick([C[5], C[4], C[4], C[3]]), 1);+ }++ let t = 0;+ return {+ update(dt) {+ t += dt;+ ps.update(dt);+ lights.update(dt);+ },+ draw(p) {+ ps.draw(p);+ if (t < 0.025) {+ // the flash: the whole cross round the diamond+ for (const r of rays) ray(p, X, Y, r.a, r.L, r.w, C);+ diamond(p, X, Y, 4, C);+ } else if (t < 0.058) {+ // reaching further and thinning, the diamond still crisp+ for (const r of rays) ray(p, X, Y, r.a, r.L * 1.2, r.w * 0.55, C, 0.12);+ diamond(p, X, Y, 3, C);+ } else if (t < 0.092) {+ // only the long ray lingers, its root burning away+ const r = rays[0];+ ray(p, X, Y, r.a, r.L * 1.3, 0.6, [C[0], C[1], C[2], C[3], C[3], C[4]], 0.4);+ }+ const pop = Math.exp(-t / 0.045);+ if (pop > 0.02) {+ p.glow(X, Y, 22, C[4], 0.3 * pop);+ p.glow(X, Y, 7, WHITE, 0.15 * pop);+ p.glowLine(X, Y, X + Math.cos(A) * 26, Y + Math.sin(A) * 26, 4, C[5], 0.25 * pop);+ }+ lights.draw(p);+ },+ };}diff --git a/src/fx/impacts/impact-frame.js b/src/fx/impacts/impact-frame.jsindex 3966da3..4cd616d 100644--- a/src/fx/impacts/impact-frame.js+++ b/src/fx/impacts/impact-frame.js@@ -1,52 +1,76 @@-import { ramp, rng, clamp, TAU } from "../../core/index.js";+import { Rng, fit, clamp, ease, 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.",+ desc: "An anime impact: two frames of white with black burst lines rushing at the hit, two frames inverted, then the lines pull out past the edges and vanish.",tags: ["impact", "hit", "anime", "manga", "flash", "speed-lines", "screen", "one-shot"],- size: [96, 64],- origin: [48, 32],- duration: 0.2,+ size: [320, 180],+ origin: [160, 90],+ duration: 0.3,loop: false,fps: 30,bg: "black",- options: { palette: ["#000000", "#ffffff"], lines: 26, seed: 19 },+ options: { palette: ["#000000", "#ffffff"], lines: 64, 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+const FRAME = 1 / 30; // the beats are whole frames: 2 white, 2 inverted, 4 pulling out++// burst lines: wedges aimed at the hit from past the edges, each its own width and reach, in angle order+function burst(R, n) {+ return Array.from({ length: n }, (_, i) => {+ const thick = R.chance(0.18);+ return { a: ((i + R.range(0.1, 0.9)) / n) * TAU, inner: thick ? R.range(30, 48) : R.range(18, 70), w: thick ? R.range(5, 8) : R.range(1.2, 3.6) };+ });}-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;+// the jagged burst at the middle: a spiky star whose points shift every frame+const spikes = (a, ph) => 10 + 6 * Math.abs(Math.sin(a * 5 + ph)) + 4 * Math.abs(Math.sin(a * 11 + ph * 2.7)) + 2 * Math.sin(a * 23 + ph);++export function create(o) {+ const C = fit(o.palette, 3), R = new Rng(o.seed), INK = C[0], PAPER = C[2];+ const [W, H] = meta.size, [OX, OY] = meta.origin, x0 = -OX, y0 = -OY;+ const sets = [burst(R, o.lines), burst(R, o.lines)], jit = [[Math.round(R.range(-2, 2)), Math.round(R.range(-1, 1))], [Math.round(R.range(-2, 2)), Math.round(R.range(-1, 1))]];+ const ph = [R.range(0, TAU), R.range(0, TAU), R.range(0, TAU), R.range(0, TAU)];+ // every frame is fixed, so work each one out once: which pixels are ink (1) or paper (2), 0 for nothing+ const masks = [];+ for (let f = 0; f < 8; f++) {+ const m = new Uint8Array(W * H), set = sets[f % 2], n = set.length, [jx, jy] = f < 4 ? jit[f % 2] : [0, 0];+ const reach = f < 4 ? 0 : Math.pow((f - 3) / 4.5, 1.5), thin = f < 4 ? 1 : 1 - (f - 3) / 5.5;+ for (let j = 0; j < H; j++)+ for (let i = 0; i < W; i++) {+ const X = x0 + i + 0.5 - jx, Y = y0 + j + 0.5 - jy, rho = Math.hypot(X, Y * 1.35), ang = Math.atan2(Y * 1.35, X);+ const slot = Math.floor((((ang % TAU) + TAU) % TAU) / (TAU / n));+ let line = false;+ for (let k = -1; k <= 1 && !line; k++) {+ const l = set[(slot + k + n) % n];+ let d = (((ang - l.a) % TAU) + TAU) % TAU;+ if (d > Math.PI) d = TAU - d;+ const inner = l.inner + reach * 150, hw = l.w * clamp((rho - inner) / 40) * thin;+ line = rho > inner && d * rho < Math.max(0.5, hw);+ }+ if (f < 4) {+ const r2 = Math.hypot(X, Y * 1.1), core = spikes(Math.atan2(Y * 1.1, X), ph[f]) * (f === 0 ? 0.85 : 1 + f * 0.08);+ m[j * W + i] = r2 < core ? (r2 < 4 + f ? 2 : 1) : line ? 1 : 2;+ } else m[j * W + i] = line ? 2 : 0;}- }- if (line) return ink;- if (field && rho < spikes(ang + f * 0.4)) return ink;- if (field) return paper;- });+ masks.push(m);+ }+ let t = 0;+ return {+ update(dt) {+ t += dt;+ },+ draw(p) {+ const f = Math.floor(t / FRAME + 1e-6);+ if (f >= 8) return;+ // two frames of ink on paper, two inverted, then paper lines pulling out over the scene+ const m = masks[f], inv = f === 2 || f === 3, ink = inv ? PAPER : INK, paper = inv ? INK : PAPER;+ p.shade(x0, y0, x0 + W, y0 + H, (x, y) => {+ const i = Math.floor(x - x0), j = Math.floor(y - y0);+ if (i < 0 || j < 0 || i >= W || j >= H) return;+ const v = m[j * W + i];+ return v === 1 ? ink : v === 2 ? (f < 4 ? paper : PAPER) : 0;+ });+ },+ };}diff --git a/src/fx/impacts/knockback-wind.js b/src/fx/impacts/knockback-wind.jsdeleted file mode 100644index b02e04f..0000000--- a/src/fx/impacts/knockback-wind.js+++ /dev/null@@ -1,55 +0,0 @@-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.jsindex 654ab97..4c9960e 100644--- a/src/fx/impacts/parry.js+++ b/src/fx/impacts/parry.js@@ -1,61 +1,84 @@-import { PAL, ramp, burst, fly, flyV, seg, ease, clamp, TAU, WHITE } from "../../core/index.js";-import { rayStar, streak } from "./_lib.js";+// The star's key frames and the spark spray are adapted from Sprite Fusion's open-source impact+// (https://www.spritefusion.com/pixel-art-vfx/impact), MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Lights, P, Rng, fit, clamp, smooth, ease, TAU, WHITE } from "../../core/index.js";+import { star, brokenRing } 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,+ desc: "Two blades clash: their edges flash in an X, a white four-point star rings out, a ring breaks into arcs and a fan of gold sparks sprays up and rains down.",+ tags: ["impact", "parry", "block", "clash", "sword", "metal", "sparks", "one-shot"],+ size: [200, 112],+ origin: [100, 96],+ duration: 1,loop: false,fps: 30,- bg: "dark",- options: { palette: PAL.gold, blade: PAL.metal, count: 18, seed: 13 },+ bg: "ground",+ options: { palette: ["#2a1a08", "#6a4410", "#b07a1a", "#e8b030", "#ffe066", "#fff6c4", "#ffffff"], height: 30, seed: 11 },};-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));+export function create(o) {+ const C = fit(o.palette, 7), R = new Rng(o.seed), X = 0, Y = -o.height, floor = () => 0;+ const ps = new Particles({ rng: R, ground: floor, sparks: [C[4], C[4], C[3], C[2]] });+ const lights = new Lights();+ // a hard four-point star: long arms on the axes, short ones between+ const sp = [];+ for (let i = 0; i < 8; i++) sp.push({ a: (i * Math.PI) / 4 + R.range(-0.04, 0.04), len: i % 2 ? R.range(6, 8) : i % 4 === 0 ? R.range(19, 22) : R.range(14, 17), w: i % 2 ? 1.2 : 2.2 });+ const segs = Array.from({ length: 6 }, (_, i) => ({ a: (i / 6) * TAU + R.range(-0.1, 0.1), gap: R.range(0.55, 0.8), dr: R.range(0.1, 0.35) }));+ // the two edges that met: lines crossing in an X+ const edges = [-0.62 + R.range(-0.08, 0.08), Math.PI + 0.62 + R.range(-0.08, 0.08)];++ lights.add(X, Y, 60, C[4], 0.65, 0.4);+ lights.add(X, Y, 22, WHITE, 0.8, 0.08);+ // the fan: sparks thrown up and out to both sides, arcing over and raining down to bounce on the floor+ for (let i = 0; i < 24; i++) {+ const s = i % 2 ? 1 : -1, a = -Math.PI / 2 + s * R.range(0.3, 1.3), v = R.range(130, 290);+ ps.spawn(P.SPARK, X + s * R.range(1, 3), Y, Math.cos(a) * v, Math.sin(a) * v, R.range(0.45, 0.85), WHITE, 1, i > 17 ? R.range(0.02, 0.07) : 0);+ }+ for (let i = 0; i < 8; i++) {+ const a = R.range(0, TAU), v = R.range(40, 110);+ ps.spawn(P.MOTE, X, Y, Math.cos(a) * v, Math.sin(a) * v - 20, R.range(0.3, 0.55), R.pick([C[5], C[6]]), 0.6, R.range(0, 0.04));}- // 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);+ for (let i = 0; i < 3; i++) {+ const a = R.range(0, TAU), d = R.range(12, 26);+ ps.spawn(P.STAR, X + Math.cos(a) * d, Y + Math.sin(a) * d, 0, -3, R.range(0.22, 0.34), WHITE, R.range(1.6, 2.6), R.range(0.1, 0.3));}- 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);++ let t = 0;+ return {+ update(dt) {+ t += dt;+ ps.update(dt);+ lights.update(dt);+ },+ draw(p) {+ // the ring: rings out off the star and breaks into arcs that fly on and cool+ const u = (t - 0.03) / 0.36;+ if (u >= 0 && u < 1) {+ const r = 8 + 24 * ease.outCubic(u), brk = smooth(0.15, 0.6, u), i = u < 0.15 ? 6 : u < 0.35 ? 5 : u < 0.6 ? 4 : 3;+ brokenRing(p, X, Y, r, Math.max(1, 2.6 * Math.pow(1 - u, 1.2)), segs, brk, C[i], C[Math.max(2, i - 2)], u < 0.6 ? 1 : (1 - u) / 0.4, 1, 0);+ if (u < 0.5) p.glowRing(X, Y, r, 5, C[4], 0.3 * (1 - u / 0.5));+ }+ ps.draw(p);+ // the edges flash where they met+ if (t < 0.058)+ for (const a of edges) {+ const ca = Math.cos(a), sa = Math.sin(a), L = t < 0.025 ? 26 : 32, k = t < 0.025 ? 1 : 0.6;+ for (let d = -L; d <= L; d += 0.5) {+ const q = Math.abs(d) / L;+ p.dot(X + ca * d, Y + sa * d, q < 0.4 ? WHITE : q < 0.75 ? C[5] : C[4], q < 0.6 ? 1 : k * (1.3 - q));+ }+ p.glowLine(X - ca * L, Y - sa * L, X + ca * L, Y + sa * L, 4, C[5], 0.35 * k);+ }+ // the star: white, then bigger and gold as it thins, then just a glint+ if (t < 0.025) star(p, X, Y, sp, 1, 1, [C[4], WHITE, WHITE, WHITE], 1, 2.6);+ else if (t < 0.058) star(p, X, Y, sp, 1.25, 0.65, [C[2], C[5], C[6], WHITE], 1, 2.6);+ else if (t < 0.092) star(p, X, Y, sp, 1.4, 0.3, [C[2], C[4], C[5], C[6]], 1, 2);+ const pop = Math.exp(-t / 0.05);+ if (pop > 0.02) {+ p.glow(X, Y, 30, C[4], 0.5 * pop);+ p.glow(X, Y, 10, WHITE, 0.4 * pop);+ }+ lights.draw(p);+ },+ };}diff --git a/src/fx/impacts/ricochet.js b/src/fx/impacts/ricochet.jsindex be7ccfd..1bc4202 100644--- a/src/fx/impacts/ricochet.js+++ b/src/fx/impacts/ricochet.js@@ -1,69 +1,112 @@-import { PAL, ramp, burst, fly, flyV, seg, ease, clamp, WHITE } from "../../core/index.js";-import { rayStar, streak, puff } from "./_lib.js";+// The glancing star, the tracer that streaks off, the skid on the surface and the spark spray are adapted from+// Sprite Fusion's open-source impact (https://www.spritefusion.com/pixel-art-vfx/impact), MIT License,+// Copyright (c) 2026 Hugo Duprez.+import { Particles, Lights, P, Rng, fit, clamp, smooth, TAU, WHITE, mix } from "../../core/index.js";+import { stone, spikes, star, SOOT } 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,+ desc: "A tracer streaks down onto the floor, glances off with a white-hot star and skips away at an angle, leaving a glowing skid while sparks skitter along the ground.",+ tags: ["impact", "ricochet", "bullet", "tracer", "sparks", "ground", "directional", "one-shot"],+ size: [232, 84],+ origin: [64, 60],+ duration: 1.1,loop: false,fps: 30,bg: "ground",- options: { palette: ["#3a0e0a", "#8a2a10", "#d85a14", "#ff9a2a", "#ffd86a", "#fff6c8", "#ffffff"], dust: PAL.dust, skip: 0.32, seed: 11 },+ options: { palette: ["#4a1712", "#c9281f", "#f2561d", "#ff8a2a", "#ffe26b", "#fff3a6", "#ffffff"], stone: "#5b5079", seed: 8 },};-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));+const HIT = 0.05, SPEED = 760, IN = 0.32, OUT = -0.21; // when it lands, how fast it flies, the angles in and out++// a tracer: a white head, a hot body cooling to a dim tail, from (hx, hy) back along angle a for L px+function tracer(p, hx, hy, a, L, C, k = 1) {+ const c = Math.cos(a), s = Math.sin(a);+ for (let d = 0; d <= L; d += 0.5) {+ const u = d / L;+ p.dot(hx - c * d, hy - s * d, u < 0.12 ? WHITE : u < 0.45 ? C[5] : u < 0.75 ? C[4] : C[2], u < 0.45 ? 1 : k * (1.25 - u));}- // 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);+ p.glow(hx, hy, 9, C[4], 0.6 * k);+}++export function create(o) {+ const C = fit(o.palette, 7), st = stone(o.stone), R = new Rng(o.seed), floor = () => 0, D = meta.duration;+ const ps = new Particles({ rng: R, ground: floor, sparks: [C[6], C[5], C[4], C[2]] });+ const lights = new Lights();+ // the star leans hard along the way out, and barely digs into the floor+ const sp = spikes(R, 9, OUT, { len: [6, 9], w: [1.4, 1.9], fwd: 2.6, back: 0.6 });+ for (const s of sp) {+ if (Math.sin(s.a) > 0.2) s.len *= 0.3;+ if (Math.abs(Math.sin(s.a - OUT)) > 0.6) s.len *= 0.65;}- 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);+ let t = 0, hit = false;+ return {+ update(dt) {+ t += dt;+ if (!hit && t >= HIT) {+ hit = true;+ lights.add(0, -2, 44, C[4], 0.65, 0.25);+ lights.add(0, -1, 14, WHITE, 0.6, 0.06);+ // sparks skitter on along the floor, skipping, and a few spray higher+ for (let i = 0; i < 18; i++) {+ const low = i < 12, a = OUT + (low ? R.range(-0.22, 0.12) : R.range(-0.7, 0.25)), v = R.range(260, 520) * (low ? 1 : 0.7);+ ps.spawn(P.SPARK, R.range(-1, 2), -1, Math.cos(a) * v, Math.sin(a) * v, R.range(0.15, 0.42) * (low ? 1.3 : 1), WHITE, 1, low ? R.range(0, 0.05) : 0);+ }+ // grit kicked up and a scuff of dust+ for (let i = 0; i < 7; i++) {+ const a = -Math.PI / 2 + R.range(-0.2, 0.9), v = R.range(60, 170);+ ps.spawn(P.GRIT, R.range(0, 4), -1, Math.cos(a) * v, Math.sin(a) * v, R.range(0.6, 0.95), R.pick([st.light, st.body, st.lip]), i < 2 ? 2 : 1);+ }+ for (let i = 0; i < 4; i++) ps.spawn(P.DUST, R.range(0, 8), -1, R.range(20, 70), -R.range(4, 16), R.range(0.25, 0.45), mix(st.dust, WHITE, R.range(0.1, 0.3)), R.range(1.2, 2));+ }+ ps.update(dt);+ lights.update(dt);+ },+ drawBack(p) {+ // the skid: a gouge along the floor that glows where the round dragged, cooling from its far end+ const u = t - HIT;+ if (u >= 0) {+ const heat = Math.pow(clamp(1 - u / 0.85), 1.2), fade = 1 - smooth(D - 0.4, D - 0.05, t), L = 12 * Math.min(1, u / 0.03);+ for (let x = -3; x <= L; x++) {+ const q = (x + 3) / 15, h = heat * (1.15 - q * 0.6);+ p.dot(x, 0, h > 0.8 ? WHITE : h > 0.55 ? C[5] : h > 0.35 ? C[4] : h > 0.18 ? C[3] : h > 0.08 ? C[2] : SOOT, fade);+ if (x > -2 && x < L - 2 && (x & 1) === 0) p.dot(x, 1, h > 0.4 ? C[3] : SOOT, fade * 0.7);+ }+ if (heat > 0) p.glowLine(-3, 0, L, 0, 5, C[3], 0.45 * heat);+ }+ ps.draw(p, "back");+ },+ draw(p) {+ ps.draw(p, "front");+ if (t < HIT) {+ // incoming: the tracer races down to the floor+ const d = (HIT - t) * SPEED;+ tracer(p, -Math.cos(IN) * d, -Math.sin(IN) * d, IN, 22, C);+ } else {+ const u = t - HIT;+ // glancing off: a stretched star, then the round skips away, its tail stretching out behind it+ if (u < 0.03) star(p, 0, -1, sp, 1, 1, [C[2], C[5], C[4], WHITE], 1, 2);+ else if (u < 0.06) star(p, 0, -1, sp, 1.25, 0.55, [C[1], C[4], C[3], C[5]], 1, 2);+ if (u < 0.2) {+ const head = 4 + u * SPEED, k = 1 - u / 0.2;+ tracer(p, Math.cos(OUT) * head, -1 + Math.sin(OUT) * head, OUT, Math.min(head - 2, 18 + u * 200), C, k);+ }+ // a thin half ring hugging the floor, swelling and cooling+ const g = (u - 0.02) / 0.2;+ if (g >= 0 && g < 1) {+ const r = 5 + 12 * (1 - Math.pow(1 - g, 3)), c = g < 0.3 ? C[5] : g < 0.6 ? C[4] : C[3];+ for (let j = 0, n = Math.ceil(r * Math.PI * 1.3); j <= n; j++) {+ const a = -Math.PI + (j / n) * Math.PI;+ p.dot(Math.cos(a) * r, -1 + Math.sin(a) * r, c, 1.15 - g);+ }+ }+ const pop = Math.exp(-u / 0.045);+ if (pop > 0.02) {+ p.glow(0, -2, 22, C[3], 0.75 * pop);+ p.glow(0, -1, 8, WHITE, 0.5 * pop);+ }+ }+ lights.draw(p);+ },+ };}diff --git a/src/fx/impacts/shield-block.js b/src/fx/impacts/shield-block.jsindex 03e854d..b9a472c 100644--- a/src/fx/impacts/shield-block.js+++ b/src/fx/impacts/shield-block.js@@ -1,73 +1,110 @@-import { PAL, ramp, burst, fly, flyV, seg, ease, clamp, TAU, WHITE } from "../../core/index.js";-import { rayStar, streak } from "./_lib.js";+// Mapping a lattice onto a dome by longitude and latitude, the ripple measured over its surface, the rim light+// and the glancing sparks are adapted from Sprite Fusion's open-source shield+// (https://www.spritefusion.com/pixel-art-vfx/shield), MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Lights, P, Rng, fit, clamp, smooth, rand, TAU, WHITE } from "../../core/index.js";+import { star, spikes } 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,+ desc: "A blow is caught on a half-dome of energy in front of the character: its diamond lattice flashes, a ripple runs over it, sparks glance off, then it blinks out cell by cell.",+ tags: ["impact", "block", "shield", "barrier", "energy", "ripple", "actor", "one-shot"],+ size: [148, 104],+ origin: [40, 88],+ duration: 1.1,loop: false,fps: 30,bg: "ground",- actor: true,- options: { palette: PAL.cyber, radius: 15, hit: -0.25, seed: 14 },+ actor: 2,+ options: {+ palette: ["#151a3d", "#212f6b", "#2c58aa", "#3a8bd8", "#62c8f4", "#a6ecff", "#dcfbff", "#ffffff"],+ sparks: ["#fff3a6", "#ffe26b", "#ff8a2a", "#f2561d"],+ seed: 12,+ },};-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 CX = 3, RX = 28, RY = 44, GRID = 3.4; // the dome's flat face, its depth and height, lattice density+const HIT = { lon: 1.18, lat: 0.5 }, GONE = 0.5; // where the blow lands; when the dome starts to blink out++// a point on the dome's surface (lon round from facing us, lat up from the floor) to local space+const onDome = (lon, lat) => [CX + RX * Math.cos(lat) * Math.sin(lon), -RY * Math.sin(lat)];++export function create(o) {+ const C = fit(o.palette, 8), S = fit(o.sparks, 4), R = new Rng(o.seed), floor = () => 0;+ const ps = new Particles({ rng: R, ground: floor, sparks: S });+ const lights = new Lights();+ const [hx, hy] = onDome(HIT.lon, HIT.lat), sp = spikes(R, 8, 0.2, { len: [5, 8], w: [1.4, 1.9], fwd: 1.2, back: 0.3 });++ lights.add(hx, hy, 40, S[1], 0.7, 0.2);+ lights.add(hx, hy, 12, WHITE, 0.7, 0.06);+ // sparks glance off the dome: out and along its surface, mostly upward+ const nA = Math.atan2(-Math.sin(HIT.lat) / RY, (Math.cos(HIT.lat) * Math.sin(HIT.lon)) / RX); // the outward normal, roughly+ for (let i = 0; i < 14; i++) {+ const a = nA + R.range(-1.2, 0.9), v = R.range(130, 300);+ ps.spawn(P.SPARK, hx + 1, hy, Math.cos(a) * v, Math.sin(a) * v - 30, R.range(0.15, 0.42), WHITE, 1, i > 10 ? R.range(0.01, 0.04) : 0);}- 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);++ let t = 0;+ // the dome, front (back = false) or the far side seen through it (back = true): a glassy fill, a diamond+ // lattice, a bright rim where it turns away, a sheen sweeping up it+ const dome = (p, back) => {+ const fade = 1 - smooth(GONE + 0.35, GONE + 0.55, t);+ if (fade <= 0) return;+ for (let y = -RY - 1; y < 0; y++)+ for (let x = CX; x <= CX + RX + 1; x++) {+ const u = (x + 0.5 - CX) / RX, v = -(y + 0.5) / RY, q = u * u + v * v;+ if (q > 1 || u < 0 || v < 0) continue;+ const z = Math.sqrt(1 - q) * (back ? -1 : 1), lon = Math.atan2(u, z), lat = Math.asin(clamp(v));+ // the lattice, and which cell this is: each cell keeps its own clock for blinking out+ const a = (lon + lat) * GRID, b = (lon - lat) * GRID, fa = a - Math.floor(a), fb = b - Math.floor(b);+ const cell = rand(Math.floor(a), Math.floor(b), 31), line = Math.min(fa, 1 - fa, fb, 1 - fb) < 0.13;+ const gone = GONE + cell * 0.35;+ if (t > gone) continue;+ // how far over the surface from the blow, and the two ripples running out from it+ const d = Math.acos(clamp(Math.cos(lat) * Math.cos(HIT.lat) * Math.cos(lon - HIT.lon) + Math.sin(lat) * Math.sin(HIT.lat), -1, 1));+ let hit = 0;+ for (const [t0, k0] of [[0, 1], [0.12, 0.55]]) {+ const k = t - t0, front = k * 3.6;+ if (k < 0 || k > 0.55) continue;+ if (Math.abs(d - front) < 0.2) hit = Math.max(hit, k0 * (1 - k / 0.55));+ else if (d < front) hit = Math.max(hit, 0.3 * k0 * (1 - k / 0.55));+ }+ const rim = 1 - Math.abs(z), flash = t < 0.05, blink = t > gone - 0.06, sheen = Math.abs(((lat * 0.8 - lon * 0.3 - t * 1.6) % 1 + 1) % 1 - 0.5) < 0.05;+ if (back) {+ if (line) p.dot(x, y, C[3], 0.5 * fade);+ continue;+ }+ if (q > 0.9) p.dot(x, y, flash || hit > 0.5 ? WHITE : C[6], fade);+ else if (line) p.dot(x, y, flash || blink || hit > 0.5 ? WHITE : hit > 0.2 || sheen ? C[6] : rim > 0.7 ? C[5] : rim > 0.35 ? C[4] : C[3], fade);+ else p.blend(x, y, flash || hit > 0.35 ? C[6] : C[3], fade * Math.min(0.85, (flash ? 0.35 : 0.1 + 0.25 * rim * rim) + hit * 0.65));+ if (((x * 7 + y * 3) & 15) === 0) p.light(x, y, C[4], 0.15 + 0.5 * hit);+ }+ };++ return {+ update(dt) {+ t += dt;+ // as cells blink out, little motes of light lift off+ if (t > GONE && t < GONE + 0.38 && R.chance(0.5)) {+ const lon = R.range(0, Math.PI / 2), lat = R.range(0.05, 1.4), [x, y] = onDome(lon, lat);+ ps.spawn(P.STAR, x, y, R.range(-10, 10), -R.range(10, 40), R.range(0.2, 0.36), R.chance(0.5) ? C[6] : C[5], R.range(0.6, 1.4));+ }+ ps.update(dt);+ lights.update(dt);+ },+ drawBack(p) {+ dome(p, true);+ },+ draw(p) {+ dome(p, false);+ // where the dome meets the floor+ const fade = 1 - smooth(GONE + 0.3, GONE + 0.55, t);+ if (fade > 0) for (let x = CX; x <= CX + RX; x++) p.dot(x, 0, t < 0.05 ? WHITE : C[5], fade * (0.6 + 0.4 * ((x - CX) / RX)));+ // the blow: a hot star where it lands, then the sparks glancing off+ if (t < 0.03) star(p, hx, hy, sp, 1, 1, [S[3], S[0], S[1], WHITE], 1, 2);+ else if (t < 0.06) star(p, hx, hy, sp, 1.25, 0.55, [S[3], S[1], S[2], S[0]], 1, 2);+ ps.draw(p);+ p.glow(CX + RX * 0.5, -RY * 0.45, RY * 0.9, C[4], 0.2 * (1 - smooth(GONE, GONE + 0.55, t)) + 0.35 * Math.exp(-t / 0.08));+ lights.draw(p);+ },+ };}diff --git a/src/fx/impacts/stomp-dust.js b/src/fx/impacts/stomp-dust.jsdeleted file mode 100644index 63a12f7..0000000--- a/src/fx/impacts/stomp-dust.js+++ /dev/null@@ -1,39 +0,0 @@-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.jsindex 1b8fb1d..126b49b 100644--- a/src/fx/index.js+++ b/src/fx/index.js@@ -3,58 +3,43 @@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 explosions_smoke_bomb from "./explosions/smoke-bomb.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";@@ -64,19 +49,14 @@ 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";@@ -84,21 +64,16 @@ 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";@@ -108,21 +83,16 @@ 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";@@ -135,34 +105,25 @@ 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";@@ -173,22 +134,18 @@ 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";@@ -197,11 +154,8 @@ 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";@@ -216,13 +170,11 @@ 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";@@ -231,34 +183,22 @@ 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";@@ -267,28 +207,22 @@ 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";@@ -297,7 +231,6 @@ 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";@@ -306,58 +239,43 @@ 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,+ "explosions/smoke-bomb": explosions_smoke_bomb,"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,@@ -367,19 +285,14 @@ export const effects = {"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,@@ -387,21 +300,16 @@ export const effects = {"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,@@ -411,21 +319,16 @@ export const effects = {"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,@@ -438,34 +341,25 @@ export const effects = {"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,@@ -476,22 +370,18 @@ export const effects = {"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,@@ -500,11 +390,8 @@ export const effects = {"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,@@ -519,13 +406,11 @@ export const effects = {"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,@@ -534,34 +419,22 @@ export const effects = {"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,@@ -570,28 +443,22 @@ export const effects = {"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,@@ -600,6 +467,5 @@ export const effects = {"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.jsindex 039886d..0d41c83 100644--- a/src/fx/lightning/_lib.js+++ b/src/fx/lightning/_lib.js@@ -1,122 +1,206 @@-// 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.+// The bolt shape and the way a bolt is inked (a deep halo, a pale body, a white core, light along it) are+// adapted from Sprite Fusion's open-source lightning (https://www.spritefusion.com/pixel-art-vfx/lightning),+// MIT License, Copyright (c) 2026 Hugo Duprez.+//+// Shared by the lightning effects: bolts that fork and thin as they split, inked at the 2x character scale,+// thin crackles, bowed arcs, heat scorch, and trajectories for pure loops.-import { ramp, bolt, clamp, rand } from "../../core/index.js";+import { clamp, rand, rng, hash, Rng, GRAVITY, FIRE_RAMP, SMOKE_RAMP, hex, mix } 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))]);-}+/** Default palette, dark to bright: deep violet shadow, electric blue, icy white. */+export const VOLT = ["#120a33", "#2a1b78", "#4630c0", "#5a62f0", "#58a6ff", "#9ed8ff", "#e4f6ff", "#ffffff"];+/** Plasma sparks, head to tail: cyan that reads apart from the violet bolt. */+export const PLASMA = ["#ffffff", "#c8f8ff", "#7ff3ff", "#1ab8e6"];+export const SOOT = hex("#110c16"), SOOT2 = hex("#1c1522");-const HALO = [[-1, 0], [1, 0], [0, -1], [0, 1]];+/**+ * A bolt from (x0, y0) to (x1, y1): midpoint displacement down to ~3 px segments (jag: how far the first+ * midpoint may swing, as a share of the length), with forks that split off along the way, each thinner (w)+ * and forking again up to two levels. Returns { paths: [{ pts: [[x, y], ...], w }] }, the trunk first.+ */+export function zigzag(R, x0, y0, x1, y1, jag = 0.32, forks = 0.35, w = 1, depth = 0) {+ const out = { paths: [] }, L = Math.hypot(x1 - x0, y1 - y0);+ let pts = [[x0, y0], [x1, y1]], off = L * jag;+ while (pts.length < 2 + L / 3) {+ const nxt = [pts[0]];+ for (let i = 0; i < pts.length - 1; i++) {+ const [ax, ay] = pts[i], [bx, by] = pts[i + 1], l = Math.hypot(bx - ax, by - ay) || 1, o = R.range(-off, off);+ nxt.push([(ax + bx) / 2 + (-(by - ay) / l) * o, (ay + by) / 2 + ((bx - ax) / l) * o], [bx, by]);+ }+ pts = nxt;+ off *= 0.52;+ }+ out.paths.push({ pts, w });+ if (depth < 2)+ for (let i = 2; i < pts.length - 3; i++)+ if (R.chance(forks / (1 + depth) / Math.max(4, pts.length / 6))) {+ const [ax, ay] = pts[i], [bx, by] = pts[Math.min(pts.length - 1, i + 3)];+ const a = Math.atan2(by - ay, bx - ax) + R.sign() * R.range(0.35, 0.9), l = (L - (i / pts.length) * L) * R.range(0.25, 0.55);+ out.paths.push(...zigzag(R, ax, ay, ax + Math.cos(a) * l, ay + Math.sin(a) * l, jag * 1.1, forks, w * 0.55, depth + 1).paths);+ }+ return out;+}-/** 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);+/** A bolt bowed off the straight line by `bow` px at its middle (negative: up for a left-to-right arc). */+export function bowed(R, x0, y0, x1, y1, bow, jag = 0.22, forks = 0.4) {+ const L = Math.hypot(x1 - x0, y1 - y0) || 1, nx = -(y1 - y0) / L, ny = (x1 - x0) / L;+ const mx = (x0 + x1) / 2 + nx * bow + R.range(-2, 2), my = (y0 + y1) / 2 + ny * bow;+ const a = zigzag(R, x0, y0, mx, my, jag, forks), b = zigzag(R, mx, my, x1, y1, jag, forks);+ return { paths: [{ pts: [...a.paths[0].pts, ...b.paths[0].pts.slice(1)], w: 1 }, ...a.paths.slice(1), ...b.paths.slice(1)] };}-/** 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;+/** Move every point of a bolt: fn(x, y) => [x, y]. */+export function bend(b, fn) {+ return { paths: b.paths.map((q) => ({ w: q.w, pts: q.pts.map(([x, y]) => fn(x, y)) })) };}-/**- * 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;+// ---- inking. Pixels are gathered in a grid at a level (higher wins), then drawn once each, so a fork's+// halo never covers the trunk's body and overlapping passes cost nothing extra.+const N = 1024, HALF = 512, GRID = new Uint8Array(N * N), HIT = [];+function mark(x, y, lvl) {+ const X = Math.floor(x) + HALF, Y = Math.floor(y) + HALF;+ if (X < 0 || Y < 0 || X >= N || Y >= N) return;+ const i = Y * N + X, v = GRID[i];+ if (!v) HIT.push(i);+ if (lvl > v) GRID[i] = lvl;+}+function stamp(x, y, r, lvl) {+ if (r <= 0.5) return mark(Math.round(x), Math.round(y), lvl);+ const r2 = r * r;+ for (let py = Math.floor(y - r); py <= Math.ceil(y + r); py++) {+ const dy = py + 0.5 - y;+ for (let px = Math.floor(x - r); px <= Math.ceil(x + r); px++) {+ const dx = px + 0.5 - x;+ if (dx * dx + dy * dy <= r2) mark(px, py, lvl);}- 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 });+/** Draw what was gathered: level n in cols[n - 1] at alpha alphas[n - 1] (dithered below 1). */+function flush(p, cols, alphas) {+ for (const i of HIT) {+ const v = GRID[i];+ GRID[i] = 0;+ const x = (i % N) - HALF, y = ((i / N) | 0) - HALF, a = alphas ? alphas[v - 1] : 1;+ if (a >= 1) p.px(x, y, cols[v - 1]);+ else if (a > 0) p.dot(x, y, cols[v - 1], a);+ }+ HIT.length = 0;}+const walk = (pts, fn) => {+ for (let i = 0; i < pts.length - 1; i++) {+ const [ax, ay] = pts[i], [bx, by] = pts[i + 1], l = Math.max(1, Math.hypot(bx - ax, by - ay));+ for (let d = 0; d <= l; d += 0.5) fn(ax + ((bx - ax) * d) / l, ay + ((by - ay) * d) / l, i);+ }+};/**- * 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.+ * A bolt at full power: a deep halo, a pale body, a white core on the trunk, light every few points. k is the+ * stroke's brightness (forks drop out below 0.5, the trunk thins below 0.6), s scales the thickness.+ * o: { hero (a white frame: the body goes white), light (glow strength), a (alpha), upTo (draw the trunk only+ * to this share of its length), core (radius of a thicker white core), minY (no glow above this y) }.*/-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 }));+export function stroke(p, b, k, C, s = 1, o = {}) {+ if (k <= 0.02) return;+ const lk = o.light ?? 0.5;+ for (const q of b.paths) {+ const trunk = q.w >= 1;+ if (!trunk && k < 0.5) continue;+ const rh = (trunk ? (k > 0.6 ? 2.1 : 1.6) : 1.1) * s, rb = (trunk ? (k > 0.6 ? 1.3 : 0.8) : 0.5) * s;+ const pts = o.upTo !== undefined && trunk ? q.pts.slice(0, Math.max(2, Math.ceil(q.pts.length * o.upTo))) : q.pts;+ walk(pts, (x, y) => {+ stamp(x, y, rh, 1);+ stamp(x, y, rb, trunk ? 3 : 2);+ if (trunk && k > 0.3) o.core ? stamp(x, y, o.core, 4) : mark(x, y, 4);+ });+ for (let i = 0; i < pts.length - 1; i += 3) if (o.minY === undefined || pts[i][1] > o.minY) p.glow(pts[i][0], pts[i][1], (trunk ? 14 : 7) * s, C[4], lk * k * q.w);}- return out;+ const a = o.a ?? 1;+ flush(p, o.hero ? [C[3], C[6], C[7], C[7]] : [C[2], C[4], C[5], C[7]], [a, a, a, a]);}-/** 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 thin crackle: a 1 px core (white on the trunk while bright), a 2 px pale body, a dithered halo while k is+ * high, light along it. For short arcs that live a frame or two.+ */+export function crackle(p, b, k, C, glowK = 0.5, a = 1) {+ if (k <= 0.02) return;+ for (const q of b.paths) {+ const thick = q.w >= 1;+ walk(q.pts, (x, y) => {+ if (k > 0.45 && thick) for (const [dx, dy] of CROSS) mark(x + dx * 1.5, y + dy * 1.5, 1);+ if (k > 0.25 && (thick || q.w > 0.4)) (mark(x + 1, y, 2), mark(x, y + 1, 2));+ mark(x, y, thick && k > 0.3 ? 4 : 3);+ });+ for (let i = 0; i < q.pts.length - 1; i += 3) p.glow(q.pts[i][0], q.pts[i][1], (thick ? 9 : 5) * (0.5 + k * 0.5), C[4], glowK * k * q.w);}+ flush(p, [C[3], C[5], C[5], C[7]], [Math.min(1, (k - 0.45) * 1.6) * a, a, a, a]);+}+const CROSS = [[1, 0], [-1, 0], [0, 1], [0, -1]];++/** A bolt's trunk as a 1 px line in one color (leaders, afterimages, cooling channels). */+export function trace(p, pts, c, a = 1, from = 0, to = pts.length - 1) {+ for (let i = Math.max(0, from); i < Math.min(to, pts.length - 1); i++) p.line(pts[i][0], pts[i][1], pts[i + 1][0], pts[i + 1][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).+ * Heat left on the floor: a flat ellipse, white-hot in the middle cooling through the fire ramp to soot.+ * T0 is the heat (1 fresh, 0 cold), fade takes the soot away.*/-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;+export function scorch(p, cx, cy, rx, T0, fade = 1, ry = Math.max(2.5, rx * 0.12)) {+ if (fade <= 0) return;+ for (let y = Math.floor(cy); y <= cy + ry; y++)+ for (let x = Math.floor(cx - rx); x <= Math.ceil(cx + rx); x++) {+ const dx = (x + 0.5 - cx) / rx, dy = (y + 0.5 - cy) / ry, d = Math.sqrt(dx * dx + dy * dy);+ if (d > 1) continue;+ const n = rand(x, y, 41), T = T0 * (1.25 - d) - n * 0.35;+ if (T > 0.06) {+ const c = FIRE_RAMP[Math.min(FIRE_RAMP.length - 1, Math.floor((1 - Math.min(1, T)) * (FIRE_RAMP.length - 1)))];+ p.dot(x, y, c, fade);+ if ((x & 3) === 0) p.glow(x + 0.5, y, 6, c, 0.18 * T * fade);+ } else p.dot(x, y, d < 0.5 ? SOOT : SOOT2, (d < 0.95 - n * 0.3 ? 1 : 1 - d) * fade);+ }}+/** A heat-ramp color for T (1 white-hot .. 0 cold), or 0 when it's cold. */+export const heat = (T) => (T > 0.06 ? FIRE_RAMP[Math.min(FIRE_RAMP.length - 1, Math.floor((1 - Math.min(1, T)) * (FIRE_RAMP.length - 1)))] : 0);+/**- * 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.+ * Where a spark launched at (x, y, vx, vy) is after `age` seconds, stepped like the simulation's SPARK (gravity,+ * drag, bouncing on a floor at `floor`), so pure loops get the same physics. Returns [x, y, vx, vy].*/-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);+export function flight(x, y, vx, vy, age, { g = 0.45, drag = 2.2, floor = Infinity, bounce = 0.45 } = {}) {+ const dt = 1 / 120;+ for (let s = 0; s < age; s += dt) {+ const h = Math.min(dt, age - s);+ vy += GRAVITY * g * h;+ vx -= vx * drag * h;+ vy -= vy * drag * h;+ const ny = y + vy * h;+ x += vx * h;+ if (vy > 0 && y <= floor && ny >= floor) (vy = -vy * bounce), (vx *= 0.7), (y = floor - 0.25);+ else y = ny;}+ return [x, y, vx, vy];+}++/** A spark drawn the way the simulation draws one (a streak stretched by speed, a hot head, light), for pure loops. */+export function spark(p, x, y, vx, vy, k, S) {+ const sp = Math.hypot(vx, vy) || 1, ux = vx / sp, uy = vy / sp, head = k > 0.6 ? S[0] : k > 0.3 ? S[1] : S[2], len = Math.min(9, 1 + sp * 0.022);+ p.line(x - ux * len, y - uy * len, x - ux * len * 0.4, y - uy * len * 0.4, k > 0.5 ? head : S[S.length - 1]);+ p.line(x - ux * len * 0.45, y - uy * len * 0.45, x, y, head);+ p.glow(x, y, 3, head, 0.45 * k);+}++/** A soft smoke puff at age u (0..1) of its life, drawn like the simulation's SMOKE, for pure loops. */+export function puff(p, x, y, size, u, c) {+ const k = 1 - u, r = size * (0.65 + Math.min(1, u * 2.5) * 0.45 + u * 0.4), a = Math.min(1, u * 12) * Math.min(1, k * 2.4) * 0.58;+ if (a <= 0.01) return;+ const col = mix(c, SMOKE_RAMP[Math.min(SMOKE_RAMP.length - 1, Math.floor(u * SMOKE_RAMP.length))], u);+ p.disc(x, y, r, col, a * 0.45);+ p.disc(x + r * 0.05, y + r * 0.06, r * 0.74, col, a * 0.62);+ if (u < 0.5) p.disc(x - r * 0.22, y - r * 0.3, r * 0.5, mix(col, hex("#ffffff"), 0.12), a * 0.4 * (1 - u * 2));}-/** 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)]);+/** A seeded generator for frame f of a loop (new shapes every frame, the same shapes every time). */+export const frameRng = (seed, f, salt = 0) => rng(seed, salt, f);+export { rand, rng, hash, Rng, clamp };diff --git a/src/fx/lightning/ball-lightning.js b/src/fx/lightning/ball-lightning.jsindex 92f3e1a..4c73317 100644--- a/src/fx/lightning/ball-lightning.js+++ b/src/fx/lightning/ball-lightning.js@@ -1,59 +1,83 @@-import { PAL, rand, rng, TAU, WHITE } from "../../core/index.js";-import { steps, glowPath, jagged } from "./_lib.js";+// The layered ball, its tapering wake and the zap to the floor with stars where it lands follow Sprite Fusion's+// open-source energy orb and bolt (https://www.spritefusion.com/pixel-art-vfx/energy),+// MIT License, Copyright (c) 2026 Hugo Duprez.+import { fit, clamp, rng, cycle, TAU, WHITE, hex } from "../../core/index.js";+import { VOLT, PLASMA, zigzag, stroke, crackle, flight, spark } 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,+ desc: "A crackling ball of plasma drifts on a wandering loop, spitting arcs off its skin and leaving a wake of fading motes, and zaps the floor when it dips low.",+ tags: ["lightning", "electric", "plasma", "orb", "wisp", "ambient", "loop"],+ size: [136, 104],+ origin: [68, 92],+ duration: 4,loop: true,fps: 30,- bg: "dark",- options: { palette: PAL.cyber, radius: 4, seed: 15 },+ bg: "ground",+ options: { palette: VOLT, sparks: PLASMA, seed: 9 },};-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),-];+const FPS = 30, N = 120, P = 4, ZAP = 62;+// where the ball is: a closed, wandering path that dips toward the floor once a loop+const at = (t) => {+ const a = (t / P) * TAU;+ return [38 * Math.sin(a) + 9 * Math.sin(2 * a + 1), -42 + 13 * Math.sin(2 * a + 0.4) + 6 * Math.sin(3 * a + 0.5)];+};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);+ const C = fit(o.palette, 8), S = o.sparks.map(hex), f = Math.floor(t * FPS + 1e-6) % N, r = rng(o.seed, 1, f), [x, y] = at(t);+ // light under the ball on the floor, stronger as it comes low+ p.glow(x, -2, 30, C[3], 0.12 + 0.3 * clamp((y + 60) / 40));+ // the wake: where it has been, shrinking and cooling, and motes shed along it, drifting and dying+ for (let i = 14; i >= 1; i--) {+ const [wx, wy] = at(t - i * 0.034), u = i / 14, rr = 3 * (1 - u) + 0.3;+ if (u > 0.6 && (i + f) % 2) continue;+ p.circle(wx, wy, rr + 0.8, u < 0.35 ? C[3] : C[2]);+ p.circle(wx, wy, rr, u < 0.35 ? C[6] : u < 0.7 ? C[5] : C[4]);+ p.glow(wx, wy, 7 * (1 - u) + 3, C[4], 0.25 * (1 - u));}-- // 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]);+ cycle(t, P, 40, o.seed + 5, (g) => g.range(0.5, 1), (age, life, q) => {+ const born = t - age, [bx, by] = at(born), k = 1 - age / life, a = q.range(0, TAU), sp = q.range(4, 14);+ const mx = bx + Math.cos(a) * sp * age + q.range(-3, 3), my = by + Math.sin(a) * sp * age + 6 * age + q.range(-3, 3);+ if (k > 0.25 || f % 2) p.px(mx, my, k > 0.6 ? C[6] : k > 0.3 ? C[4] : C[3]);+ p.glow(mx, my, 3, C[4], 0.3 * k);+ });+ // the ball: a churning skin with hot spots rolling round it, a white heart, corona bristling off it+ const R0 = 5.2 + 0.6 * Math.sin(t * 9) + 0.4 * r.range(-1, 1);+ p.circle(x, y, R0 + 1.3, C[2]);+ p.circle(x, y, R0, C[4]);+ p.circle(x - 0.4, y - 0.4, R0 * 0.72, C[5]);+ for (let i = 0; i < 3; i++) {+ const a = t * (5 + i * 2.3) + i * 2.1, d = R0 * 0.6;+ p.circle(x + Math.cos(a) * d, y + Math.sin(a) * d * 0.8, 1.2, i ? C[6] : WHITE);}- // 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);+ p.circle(x - 0.6, y - 0.6, R0 * 0.32, WHITE);+ for (let i = 0; i < 8; i++) {+ if (r.next() < 0.35) continue;+ const a = (i / 8) * TAU + t * 2 + r.range(-0.2, 0.2), l = r.range(1.5, 4);+ p.line(x + Math.cos(a) * (R0 + 1), y + Math.sin(a) * (R0 + 1), x + Math.cos(a) * (R0 + 1 + l), y + Math.sin(a) * (R0 + 1 + l), i % 2 ? C[5] : C[4]);+ }+ p.glow(x, y, 30, C[4], 0.3);+ p.glow(x, y, 9, C[6], 0.1);+ // arcs spat off its skin, re-struck every frame+ for (let i = 0; i < 2 + (r.next() < 0.4 ? 1 : 0); i++) {+ const a = r.range(0, TAU), l = r.range(5, 11), x0 = x + Math.cos(a) * (R0 + 1), y0 = y + Math.sin(a) * (R0 + 1), b = a + r.range(-0.7, 0.7);+ crackle(p, zigzag(r, x0, y0, x0 + Math.cos(b) * l, y0 + Math.sin(b) * l, 0.4, 0.3), r.range(0.4, 0.7), C, 0.25);+ }+ // once a loop, low over the floor, it zaps down: a bolt, the floor lit, sparks kicked up+ const za = f - ZAP, [zx] = at(ZAP / FPS), gx = zx + rng(o.seed, 3).range(-10, 10);+ if (za >= 0 && za < 4) {+ const k = [1, 0.6, 0.9, 0.4][za];+ stroke(p, zigzag(rng(o.seed, 4, f), x, y + R0, gx, 0, 0.28, 0.4), k, C, 0.7, { hero: za === 0 });+ p.circle(gx, -1, 2.5 * k + 1, C[5]);+ p.px(gx, -1, WHITE);+ p.glow(gx, -4, 34, C[4], 0.6 * k);+ }+ const sa = (((t - ZAP / FPS) % P) + P) % P;+ for (let j = 0; j < 14; j++) {+ const q = rng(o.seed, 7, j), life = q.range(0.25, 0.55);+ if (sa >= life) continue;+ const a = -Math.PI / 2 + q.range(-1.3, 1.3), sp = q.range(50, 170), [sx, sy, vx, vy] = flight(gx, -1, Math.cos(a) * sp, Math.sin(a) * sp, sa, { floor: 0 });+ spark(p, sx, sy, vx, vy, 1 - sa / life, S);}-- // 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.jsindex 1686cd4..b9c1132 100644--- a/src/fx/lightning/chain-lightning.js+++ b/src/fx/lightning/chain-lightning.js@@ -1,81 +1,171 @@-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";+// The hop timing, the link shapes that re-strike every other frame, the glowing nodes and the crawling arcs+// follow Sprite Fusion's open-source lightning (https://www.spritefusion.com/pixel-art-vfx/lightning),+// MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Lights, P, Rng, fit, sparkle, clamp, smooth, ease, rng, lerp, TAU, WHITE, hex, mix } from "../../core/index.js";+import { VOLT, PLASMA, zigzag, bowed, stroke, crackle, trace, scorch } 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,+ desc: "A bolt leaps from the caster's hand through three targets in turn; each flashes, sparks and grounds itself to the floor while the arcs between them flicker, then the chain snaps.",+ tags: ["lightning", "electric", "chain", "spell", "combat", "directional", "one-shot"],+ size: [248, 104],+ origin: [40, 82],+ duration: 1.8,loop: false,fps: 30,- bg: "dark",- options: { palette: ["#100c34", "#241c7c", "#3c3cd0", "#6a78ff", "#a8b8ff", "#e0e6ff", "#ffffff"], targets: 3, spacing: 30, seed: 8 },+ bg: "ground",+ actor: 2,+ options: { palette: VOLT, sparks: PLASMA, seed: 3 },};-const HOP = 0.09, LIFE = 0.34;+const HAND = [10, -16], HOPS = [[58, -22], [104, -30], [150, -19]];+const WIND = 0.12, LEAP = 0.05, GAP = 0.075, HOLD = 0.78, BREAK = 0.16, ASH = hex("#5b5566");+const on = (i) => WIND + i * GAP + LEAP; // when link i lands on its target+const off = (i) => HOLD + i * 0.05; // when it starts to give out-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);- }+// a link's strength: a hard first flash, a restless hum, then it stutters out+function level(i, t) {+ const a = t - on(i);+ if (a < 0) return 0;+ const hum = a < 0.1 ? [1, 0.55, 1][Math.floor(a * 30)] ?? 1 : 0.78 + 0.22 * Math.sin(t * 61 + i) * Math.sin(t * 23 + i * 2);+ const b = t - off(i);+ return b < 0 ? hum : b < BREAK ? hum * (1 - b / BREAK) * (Math.floor(b * 60) % 3 === 1 ? 0.5 : 1) : 0;+}- 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]);+export function create(o) {+ const C = fit(o.palette, 8), R = new Rng(o.seed), floor = () => 0;+ const ps = new Particles({ rng: R, ground: floor, sparks: o.sparks }), hot = new Particles({ rng: R, ground: floor }), lights = new Lights();+ const pts = [HAND, ...HOPS], hit = HOPS.map(() => false), popped = HOPS.map(() => false);+ // where each target grounds itself: a spot on the floor below it+ const ground = HOPS.map(([x]) => x + R.range(-5, 5));+ let t = 0;+ const shape = (i, f, salt = 0) => {+ const r = rng(o.seed, 31 + salt, i, f), [x0, y0] = pts[i], [x1, y1] = pts[i + 1], L = Math.hypot(x1 - x0, y1 - y0);+ return bowed(r, x0, y0, x1, y1, -L * r.range(0.05, 0.15), 0.2, 0.08);+ };+ return {+ update(dt) {+ t += dt;+ // the charge gathers at the hand+ if (t < WIND && R.chance(70 * dt)) {+ const a = R.range(0, TAU), d = R.range(10, 24), T = R.range(0.06, 0.1), v = (d * 3) / (Math.exp(3 * T) - 1);+ ps.spawn(P.STREAK, HAND[0] + Math.cos(a) * d, HAND[1] + Math.sin(a) * d, -Math.cos(a) * v, -Math.sin(a) * v, T, R.chance(0.5) ? C[6] : C[5]);+ }+ for (const [i, [x, y]] of HOPS.entries()) {+ if (!hit[i] && t >= on(i)) {+ hit[i] = true;+ const [px, py] = pts[i], dir = Math.atan2(y - py, x - px);+ lights.add(x, y, 56, C[4], 0.85, 0.22);+ lights.add(x, y, 16, WHITE, 0.7, 0.08);+ if (i === 0) lights.add(HAND[0], HAND[1], 40, C[4], 0.6, 0.15);+ for (let j = 0; j < 18; j++) {+ const a = R.chance(0.6) ? dir + R.range(-1.1, 1.1) : R.range(0, TAU), sp = R.range(70, 230);+ ps.spawn(P.SPARK, x, y, Math.cos(a) * sp, Math.sin(a) * sp - 40, R.range(0.15, 0.4));+ }+ for (let j = 0; j < 5; j++) hot.spawn(P.SPARK, x + R.range(-2, 2), y + 2, R.range(-50, 50), R.range(-60, 20), R.range(0.5, 0.9));+ ps.spawn(P.STAR, x + R.range(-4, 4), y - R.range(3, 7), 0, -6, R.range(0.25, 0.4), C[6], R.range(1.5, 2.5));+ for (let j = 0; j < 2; j++) ps.spawn(P.SMOKE, x + R.range(-4, 4), y + R.range(-2, 3), R.range(-6, 6), -R.range(8, 16), R.range(0.7, 1), mix(ASH, C[2], 0.35), R.range(2, 3.5), R.range(0.1, 0.25));+ }+ // while the chain holds: sparks shed off the links, spit from the floor where each target grounds+ if (hit[i] && t < off(i)) {+ if (R.chance(9 * dt)) {+ const u = R.next(), [x0, y0] = pts[i];+ ps.spawn(P.SPARK, lerp(x0, x, u), lerp(y0, y, u) - 2, R.range(-60, 60), R.range(-90, 20), R.range(0.1, 0.25));+ }+ if (R.chance(7 * dt)) ps.spawn(P.SPARK, ground[i], -1, R.range(-70, 70), -R.range(40, 140), R.range(0.12, 0.3));+ if (R.chance(2 * dt)) hot.spawn(P.SPARK, x + R.range(-3, 3), y + 3, R.range(-30, 30), R.range(-30, 10), R.range(0.5, 0.8));+ }+ // when it gives out, the target pops once more and smokes+ if (!popped[i] && t >= off(i) + BREAK) {+ popped[i] = true;+ for (let j = 0; j < 7; j++) {+ const a = R.range(0, TAU), sp = R.range(40, 140);+ ps.spawn(P.SPARK, x, y, Math.cos(a) * sp, Math.sin(a) * sp - 30, R.range(0.12, 0.3));+ }+ ps.spawn(P.SMOKE, x, y, R.range(-4, 4), -R.range(10, 16), R.range(0.55, 0.7), mix(ASH, C[2], 0.35), R.range(2.5, 3.5));+ lights.add(x, y, 30, C[4], 0.5, 0.12);+ }+ }+ ps.update(dt);+ hot.update(dt);+ lights.update(dt);+ },+ drawBack(p) {+ // the floor scorches where the targets ground themselves+ for (const [i] of HOPS.entries()) {+ const a = t - on(i);+ if (a < 0) continue;+ const T0 = Math.min(1, a / 0.2) * Math.pow(clamp(1 - (t - off(i)) / 0.7), 1.3) * 0.9;+ scorch(p, ground[i], 0, 7, T0, 1 - smooth(1.35, 1.75, t));+ }+ ps.draw(p, "back");+ hot.draw(p, "back");+ },+ draw(p) {+ const f = Math.floor(t * 30 + 1e-4), f2 = f >> 1;+ // the hand: a node that swells while the charge gathers and holds the chain+ const kh = t < WIND ? t / WIND : level(0, t);+ if (kh > 0.02) {+ const r = (1.2 + 1.6 * kh + Math.sin(t * 53) * 0.4) * Math.min(1, kh * 1.5);+ p.circle(HAND[0], HAND[1], r + 1.2, C[4]);+ p.circle(HAND[0], HAND[1], r, C[6]);+ p.circle(HAND[0], HAND[1], r * 0.5, WHITE);+ p.glow(HAND[0], HAND[1], 18, C[4], 0.6 * kh);+ if (t > WIND * 0.5) {+ const r2 = rng(o.seed, 5, f), a = r2.range(0, TAU), d = r2.range(4, 8);+ crackle(p, zigzag(r2, HAND[0], HAND[1], HAND[0] + Math.cos(a) * d, HAND[1] + Math.sin(a) * d, 0.4, 0.3), 0.6 * kh, C, 0.3);+ }}- 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));+ for (const [i, [x, y]] of HOPS.entries()) {+ const t0 = WIND + i * GAP, [x0, y0] = pts[i];+ // the leap: the bolt races out from the last node with a hot head+ if (t >= t0 && t < on(i)) {+ const u = ease.outQuad((t - t0) / LEAP), b = shape(i, -1), trunk = { paths: [b.paths[0]] };+ stroke(p, trunk, 1, C, 0.75, { upTo: u });+ const tp = b.paths[0].pts, [hx, hy] = tp[Math.min(tp.length - 1, Math.floor(u * (tp.length - 1)))];+ p.circle(hx, hy, 2, WHITE);+ p.glow(hx, hy, 16, C[5], 0.7);+ }+ const k = level(i, t);+ if (k > 0) {+ stroke(p, shape(i, f2), k, C, 0.75);+ } else if (t >= off(i) + BREAK && t < off(i) + BREAK + 0.35) {+ // the spent channel: a dotted trace that cools and goes+ const g = 1 - (t - off(i) - BREAK) / 0.35, b = shape(i, Math.floor((off(i) + BREAK) * 15));+ trace(p, b.paths[0].pts, g > 0.5 ? C[4] : C[2], g * 0.9);+ }+ // the target: a flash as the bolt lands, then a node with arcs crawling over it and down to the floor+ const a = t - on(i);+ if (a >= 0 && a < 0.09) {+ const q = a / 0.09;+ p.circle(x, y, 6 * (1 - q) + 1.5, C[5]);+ p.circle(x, y, 5 * (1 - q), WHITE);+ sparkle(p, x, y, Math.round(10 * (1 - q)), C[6], C[4], 0.6);+ }+ if (k > 0.05) {+ const r = (2.6 + Math.sin(t * 47 + i) * 0.7) * k;+ p.circle(x, y, r + 1.5, C[2]);+ p.circle(x, y, r + 0.7, C[5]);+ p.circle(x, y, r * 0.6, WHITE);+ p.glow(x, y, 26, C[4], 0.6 * k);+ p.glow(x, y, 8, C[6], 0.5 * k);+ // arcs crawl over the target as if over a body caught in the current+ const r2 = rng(o.seed, 11, i, f);+ for (let j = 0; j < (t - on(i) < 0.12 ? 2 : 1); j++) {+ const a0 = r2.range(0, TAU), a1 = a0 + r2.sign() * r2.range(0.5, 1), d0 = r2.range(4, 6), d1 = r2.range(5, 8);+ crackle(p, zigzag(r2, x + Math.cos(a0) * d0, y + Math.sin(a0) * d0, x + Math.cos(a1) * d1, y + Math.sin(a1) * d1, 0.35, 0), r2.range(0.45, 0.7) * k, C, 0.25);+ }+ if (r2.next() < 0.3 * k) {+ const gx = ground[i] + r2.range(-3, 3);+ crackle(p, zigzag(r2, x + r2.range(-2, 2), y + 3, gx, -0.5, 0.3, 0.35), 0.75 * k, C, 0.35);+ p.glow(gx, -1, 12, C[5], 0.5 * k);+ p.px(gx, -1, WHITE);+ }+ }}- }- }+ ps.draw(p, "front");+ hot.draw(p, "front");+ lights.draw(p);+ },+ };}diff --git a/src/fx/lightning/charge-up.js b/src/fx/lightning/charge-up.jsindex de6deed..5c59fe0 100644--- a/src/fx/lightning/charge-up.js+++ b/src/fx/lightning/charge-up.js@@ -1,86 +1,156 @@-import { PAL, burst, fly, flyV, seg, ease, rng, rand, TAU, WHITE } from "../../core/index.js";-import { steps, zap, jagged, brokenRing } from "./_lib.js";+// The charge (streaks spiralling in, a core that swells with an accelerating pulse, little arcs spitting off+// it) and the release (flash, rings, a spray of motes and stars) follow Sprite Fusion's open-source energy charge+// (https://www.spritefusion.com/pixel-art-vfx/energy), MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Lights, P, Rng, fit, flare, sparkle, clamp, smooth, ease, rng, TAU, WHITE, hex, mix } from "../../core/index.js";+import { VOLT, PLASMA, zigzag, stroke, crackle } 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,+ desc: "Sparks streak and arcs whip in to a crackling core at the caster's hand that swells and pulses faster, then it flashes and bursts: bolts every way, a ring, a spray of sparks.",+ tags: ["lightning", "electric", "charge", "spell", "power-up", "actor", "one-shot"],+ size: [272, 184],+ origin: [124, 148],+ duration: 2.7,loop: false,fps: 30,- bg: "dark",- options: { palette: PAL.electric, radius: 30, seed: 20 },+ bg: "ground",+ actor: 2,+ options: { palette: VOLT, sparks: PLASMA, charge: 1.6, seed: 4 },};-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));- }+const CX = 15, CY = -21, BK = [1, 0.7, 0.95, 0.5, 0.8, 0.35], ASH = hex("#5b5566");+const edges = new WeakMap();+function edgeOf(A) {+ let e = edges.get(A.mask);+ if (e) return e;+ const m = A.mask, on = (x, y) => x >= 0 && y >= 0 && x < m.w && y < m.h && m.data[y * m.w + x];+ e = [];+ for (let y = 0; y < m.h; y++) for (let x = 0; x < m.w; x++) if (on(x, y) && (!on(x - 1, y) || !on(x + 1, y) || !on(x, y - 1) || !on(x, y + 1))) e.push([A.x + x, A.y + y]);+ edges.set(A.mask, e);+ return e;+}- // 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));+export function create(o) {+ const C = fit(o.palette, 8), R = new Rng(o.seed), REL = o.charge, floor = () => 0;+ const ps = new Particles({ rng: R, ground: floor, sparks: o.sparks }), lights = new Lights();+ const bolts = Array.from({ length: 8 }, (_, i) => {+ const a = (i / 8) * TAU + R.range(-0.25, 0.25), L = R.range(44, 72), x1 = CX + Math.cos(a) * L, y1 = Math.min(0, CY + Math.sin(a) * L);+ return { x1, y1, t0: REL + R.range(0, 0.05) };});+ const arcs = [];+ let t = 0, released = false, phase = 0, beats = [];+ const level = () => clamp(t / REL);+ return {+ update(dt) {+ t += dt;+ const k = level(), e = k * k;+ if (t < REL) {+ // energy rushes in: long streaks spiralling in from all round, more and more of them+ for (let acc = (60 + 360 * e) * dt; acc > 0; acc--) {+ if (acc < 1 && !R.chance(acc)) break;+ const a = R.range(0, TAU), d = R.range(30, 72) * (1 - 0.35 * k), life = R.range(0.16, 0.26), sp = (d / life) * 0.95;+ ps.spawn(P.MOTE, CX + Math.cos(a) * d, Math.min(-2, CY + Math.sin(a) * d), -Math.cos(a) * sp - Math.sin(a) * sp * 0.4, -Math.sin(a) * sp + Math.cos(a) * sp * 0.4, life, R.pick([C[7], C[6], C[5]]), 1);+ }+ // arcs whip in from the air, more and more of them+ if (k > 0.2 && R.chance((2 + 16 * e) * dt)) {+ const a = R.range(0, TAU), d = R.range(20, 40);+ arcs.push({ x: CX + Math.cos(a) * d, y: Math.min(-3, CY + Math.sin(a) * d), t, seed: R.int(0, 1e6) });+ }+ // the pulse quickens+ phase += (1.5 + 11 * e) * dt;+ if (phase >= 1) (phase -= 1), beats.push(t);+ if (R.chance(4 * e * dt)) ps.spawn(P.STAR, CX + R.range(-14, 14), CY + R.range(-14, 10), 0, -4, R.range(0.2, 0.35), C[6], R.range(1, 2));+ } else if (!released) {+ released = true;+ lights.add(CX, CY, 110, C[4], 0.8, 0.5);+ lights.add(CX, CY, 28, WHITE, 0.6, 0.08);+ for (let i = 0; i < 70; i++) {+ const a = R.range(0, TAU), sp = R.range(140, 330) * (Math.sin(a) > 0.4 ? 0.55 : 1);+ ps.spawn(Math.sin(a) < -0.2 && R.chance(0.35) ? P.MOTE : P.SPARK, CX, CY, Math.cos(a) * sp, Math.sin(a) * sp, R.range(0.25, 0.55), R.pick([C[7], C[6], C[5]]), R.range(0.8, 1.4));+ }+ for (let i = 0; i < 10; i++) {+ const a = R.range(0, TAU), sp = R.range(60, 160);+ ps.spawn(P.STAR, CX, CY, Math.cos(a) * sp, Math.sin(a) * sp, R.range(0.4, 0.8), R.chance(0.5) ? C[6] : C[5], R.range(1.2, 2.4));+ }+ for (let i = 0; i < 4; i++) ps.spawn(P.SMOKE, CX + R.range(-5, 5), CY + R.range(-4, 4), R.range(-12, 12), -R.range(8, 18), R.range(0.6, 0.85), mix(ASH, C[4], 0.3), R.range(3, 5), R.range(0.05, 0.15));+ }+ beats = beats.filter((b) => t - b < 0.22);+ for (let i = arcs.length - 1; i >= 0; i--) if (t - arcs[i].t > 0.07) arcs.splice(i, 1);+ ps.update(dt);+ lights.update(dt);+ },+ drawBack(p) {+ const k = level();+ if (t < REL) p.glow(CX * 0.5, -3, 40, C[3], 0.3 * k * k);+ ps.draw(p, "back");+ },+ draw(p) {+ const k = level(), e = k * k, f = Math.floor(t * 30 + 1e-4), A = o.actor;+ if (t < REL) {+ const jit = k > 0.85 ? (f % 2 ? 1 : -1) * ((k - 0.85) / 0.15) : 0, x = CX + jit, y = CY, pr = 0.5 + 0.5 * Math.sin(phase * TAU);+ // the body catches the core's light along its near edge+ for (const [ex, ey] of edgeOf(A)) {+ const d = Math.hypot(ex + 0.5 - x, ey + 0.5 - y);+ if (d < 6 + 10 * k && e > 0.08) p.px(ex, ey, d < 4 + 6 * k && e > 0.4 ? C[6] : C[4]);+ }+ // rings fall inward to the core on every beat+ for (const b of beats) {+ const q = (t - b) / 0.22;+ p.ring(x, y, 4 + 20 * (1 - ease.inQuad(q)) * (0.5 + k), 1, q > 0.6 ? C[6] : C[4], 0.4 + 0.6 * q);+ }+ // arcs whipping in to the core+ for (const a of arcs) crackle(p, zigzag(rng(a.seed, f), a.x, a.y, x, y, 0.35, 0.4), 0.85, C, 0.4);+ // the core: swelling, layered, with arcs racing round its skin+ const r = 1.2 + 6.5 * e + pr * (0.5 + 1.2 * k);+ p.circle(x, y, r + 1.3, C[2]);+ p.circle(x, y, r, C[4]);+ p.circle(x - r * 0.12, y - r * 0.12, r * 0.7, C[5]);+ p.circle(x, y, r * 0.38, WHITE);+ if (r > 3)+ for (const s of [0, Math.PI])+ for (let a = 0; a < 1.3; a += 0.12) {+ const ang = t * 10 + s + a, rr = r * (0.62 + 0.1 * Math.sin(a * 3));+ p.dot(x + Math.cos(ang) * rr, y + Math.sin(ang) * rr, a < 0.5 ? WHITE : C[6]);+ }+ if (k > 0.35) {+ const q = rng(o.seed, 5, f), a = q.range(0, TAU), l = q.range(3, 6) * (0.5 + k);+ crackle(p, zigzag(q, x + Math.cos(a) * r, y + Math.sin(a) * r, x + Math.cos(a) * (r + l), y + Math.sin(a) * (r + l), 0.4, 0.3), 0.7, C, 0.3);+ }+ p.glow(x, y, 12 + 30 * k, C[4], 0.35 + 0.45 * k);+ p.glow(x, y, 6 + 6 * k, C[6], 0.25 + 0.3 * k);+ } else {+ const a = t - REL;+ // the release: the caster flashed white, a flare, a white core blown open+ if (a < 0.07) p.mask(A.mask, A.x, A.y, a < 0.035 ? WHITE : C[6]);+ if (a < 0.22) {+ const q = a / 0.22;+ flare(p, CX, CY, 46 * Math.pow(1 - q, 1.4), 1 - q, C);+ if (q < 0.3) p.circle(CX, CY, 12 * (1 - q * 2.5) + 1.5, WHITE);+ }+ // bolts every way, struck and flickering+ for (const [i, b] of bolts.entries()) {+ const ba = Math.floor((t - b.t0) * 30 + 1e-4);+ if (t < b.t0 || ba >= BK.length) continue;+ stroke(p, zigzag(rng(o.seed, 3, i, ba >> 1), CX, CY, b.x1, b.y1, 0.25, 0.75), BK[ba], C, ba === 0 ? 0.95 : 0.75, { hero: ba === 0 });+ if (b.y1 > -1) p.glow(b.x1, -3, 18, C[5], 0.5 * BK[ba]);+ }+ // a ring bursting out with a fainter echo inside it+ const q = a / 0.45;+ if (q < 1) {+ const r = 8 + 80 * ease.outCubic(q), hide = (rr) => (v, g) => (CY + Math.sin(g) * rr > -1 ? 0 : 1.1 - q);+ p.ring(CX, CY, r, Math.max(1, 3 * (1 - q)), q < 0.25 ? WHITE : C[5], hide(r));+ const r2 = 6 + 56 * ease.outCubic(Math.min(1, q * 1.3));+ p.ring(CX, CY, r2, 1, C[4], (v, g) => (CY + Math.sin(g) * r2 > -1 ? 0 : 0.8 - q));+ p.glow(CX, CY - 6, Math.min(r * 0.9, 46), C[3], 0.42 * (1 - q) * (1 - q));+ }+ // the charge bleeds off in a few last crackles at the hand+ if (a > 0.15 && a < 0.5) {+ const qq = rng(o.seed, 8, f), ang = qq.range(0, TAU), l = qq.range(5, 10);+ crackle(p, zigzag(qq, CX, CY, CX + Math.cos(ang) * l, CY + Math.sin(ang) * l, 0.45, 0.3), 0.8 * (1 - (a - 0.15) / 0.35) + 0.15, C, 0.3);+ }+ }+ ps.draw(p, "front");+ lights.draw(p);+ },+ };}diff --git a/src/fx/lightning/electric-field.js b/src/fx/lightning/electric-field.jsdeleted file mode 100644index e03aac8..0000000--- a/src/fx/lightning/electric-field.js+++ /dev/null@@ -1,75 +0,0 @@-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.jsindex 852e8d1..33530d5 100644--- a/src/fx/lightning/electrified.js+++ b/src/fx/lightning/electrified.js@@ -1,74 +1,94 @@-import { PAL, cycle, clamp, rng, rand, TAU, WHITE } from "../../core/index.js";-import { steps, glowPath, jagged } from "./_lib.js";+// Arcs leaping between points of the silhouette's edge, re-struck every other frame, grounding to the floor, and+// the periodic jolt that throws sparks follow Sprite Fusion's open-source lightning crackle+// (https://www.spritefusion.com/pixel-art-vfx/lightning), MIT License, Copyright (c) 2026 Hugo Duprez.+import { fit, clamp, rng, cycle, TAU, WHITE, hex, luma } from "../../core/index.js";+import { VOLT, PLASMA, zigzag, crackle, flight, spark } 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,+ desc: "Current runs through a character: arcs crawl over and leap across the body, sparks spit off, the body flares to an electric silhouette on each jolt, and the feet ground out.",+ tags: ["lightning", "electric", "status", "shock", "stun", "actor", "loop"],+ size: [108, 92],+ origin: [54, 76],+ duration: 2,loop: true,fps: 30,bg: "ground",- actor: true,- options: { palette: PAL.volt, arcs: 3, seed: 13 },+ actor: 2,+ options: { palette: VOLT, sparks: PLASMA, seed: 5 },};-const RATE = 15;-const rims = new WeakMap();+const FPS = 30, N = 60, P = 2, JOLTS = [[3, 1], [22, 0.7], [41, 0.9]];+const edges = new WeakMap();+// the silhouette's edge pixels, in local space+function edgeOf(A) {+ let e = edges.get(A.mask);+ if (e) return e;+ const m = A.mask, on = (x, y) => x >= 0 && y >= 0 && x < m.w && y < m.h && m.data[y * m.w + x];+ e = [];+ for (let y = 0; y < m.h; y++) for (let x = 0; x < m.w; x++) if (on(x, y) && (!on(x - 1, y) || !on(x + 1, y) || !on(x, y - 1) || !on(x, y + 1))) e.push([A.x + x + 0.5, A.y + y + 0.5]);+ edges.set(A.mask, e);+ return e;+}+const jolt = (f) => {+ for (const [f0, k] of JOLTS) if (f >= f0 && f < f0 + 3) return { a: f - f0, k };+ return null;+};-// 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 drawBack(p, t, o) {+ const C = fit(o.palette, 8), A = o.actor, f = Math.floor(t * FPS + 1e-6) % N, j = jolt(f), r = rng(o.seed, 4, f);+ // a cold aura: a broken outline that flickers round the body, light pooling at the feet+ p.outline(A.mask, A.x, A.y, j ? C[4] : r.next() < 0.5 ? C[2] : C[1]);+ p.glow(0, -18, 30, C[3], (j ? 0.55 * j.k : 0.16 + 0.1 * r.next()));+ p.glow(0, -2, 22, C[4], 0.18);}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; }+ const C = fit(o.palette, 8), S = o.sparks.map(hex), A = o.actor, E = edgeOf(A), f = Math.floor(t * FPS + 1e-6) % N, j = jolt(f);+ // the jolt: the body flares to an electric silhouette, then fades back through its own shading+ if (j) {+ const lift = [1.1, 0.6, -0.2][j.a] * j.k, ramp = [C[1], C[2], C[3], C[4], C[5], C[6], C[7]];+ for (let y = 0; y < A.h; y++)+ for (let x = 0; x < A.w; x++) {+ const c = A.pixels[y * A.w + x];+ if (c) p.px(A.x + x, A.y + y, ramp[clamp(Math.round(0.4 + luma(c) * 6 + lift), 0, 6)]);+ }+ p.glow(0, -19, 26, C[5], 0.5 * j.k * (1 - j.a / 3));+ }+ // arcs: two or three at a time, re-struck every other frame, leaping between nearby points of the edge+ const r = rng(o.seed, 7, f >> 1), n = 2 + (j ? 2 : r.int(0, 1));+ for (let i = 0; i < n; i++) {+ const a = r.pick(E), ang = r.range(0, TAU), d = r.range(6, 14);+ let b = [a[0] + Math.cos(ang) * d, a[1] + Math.sin(ang) * d];+ for (let k = 0; k < 10; k++) {+ const c = r.pick(E);+ if (Math.hypot(c[0] - b[0], c[1] - b[1]) < 5 && Math.hypot(c[0] - a[0], c[1] - a[1]) > 4) b = c;+ }+ const k = (f & 1 ? 0.75 : 0.95) * r.range(0.6, 1);+ crackle(p, zigzag(rng(o.seed, 8, f, i), a[0], a[1], b[0], b[1], 0.42, 0.35), k, C, 0.4);+ // the edge catches the light where an arc touches it+ for (const [x, y] of E) if (Math.hypot(x - a[0], y - a[1]) < 3.5 || Math.hypot(x - b[0], y - b[1]) < 3) p.px(x - 0.5, y - 0.5, C[5]);+ }+ // the feet ground out to the floor now and then+ if (r.next() < (j ? 0.9 : 0.35)) {+ const s = r.sign(), x0 = s * r.range(3, 8);+ crackle(p, zigzag(rng(o.seed, 9, f), x0, -1.5, x0 + s * r.range(5, 12), -0.5, 0.45, 0.3), 0.7, C, 0.35);+ p.glow(x0, -1, 10, C[5], 0.35);+ }+ // sparks: a spray off the edge with every jolt, and a few spat out between them+ for (const [f0, k] of JOLTS) {+ const age = (((t - f0 / FPS) % P) + P) % P;+ for (let i = 0; i < 9; i++) {+ const q = rng(o.seed, 21, f0, i), life = q.range(0.18, 0.4);+ if (age >= life) continue;+ const [x0, y0] = E[Math.floor(q.next() * E.length)], ang = Math.atan2(y0 + 19, x0) + q.range(-0.7, 0.7), sp = q.range(60, 150) * k;+ const [x, y, vx, vy] = flight(x0, y0, Math.cos(ang) * sp, Math.sin(ang) * sp - 30, age, { floor: 0 });+ spark(p, x, y, vx, vy, 1 - age / life, S);}- 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]);+ cycle(t, P, 8, o.seed + 3, (g) => g.range(0.15, 0.3), (age, life, q) => {+ const [x0, y0] = E[Math.floor(q.next() * E.length)], ang = Math.atan2(y0 + 19, x0) + q.range(-0.6, 0.6), sp = q.range(50, 110);+ const [x, y, vx, vy] = flight(x0, y0, Math.cos(ang) * sp, Math.sin(ang) * sp - 20, age, { floor: 0 });+ spark(p, x, y, vx, vy, 1 - age / life, S);});- // 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.jsdeleted file mode 100644index fb6f95a..0000000--- a/src/fx/lightning/lightning-dash.js+++ /dev/null@@ -1,71 +0,0 @@-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.jsindex f3dd6cf..252bdc8 100644--- a/src/fx/lightning/lightning-strike.js+++ b/src/fx/lightning/lightning-strike.js@@ -1,126 +1,259 @@-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";+// The stepped leader, the stroke flicker, the cooling channel and the scorch follow Sprite Fusion's open-source+// lightning (https://www.spritefusion.com/pixel-art-vfx/lightning), MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Lights, P, Rng, fit, sparkle, clamp, smooth, ease, rand, rng, TAU, WHITE, hex, mix } from "../../core/index.js";+import { VOLT, PLASMA, SOOT, SOOT2, zigzag, bend, stroke, crackle, trace, scorch, heat } 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,+ desc: "A targeted strike: a sigil charges on the floor, the scene darkens, a thick bolt slams into it, arcs race out along the cracks it splits, the channel crumbles to a scorch.",+ tags: ["lightning", "electric", "strike", "spell", "target", "impact", "ground", "one-shot"],+ size: [240, 264],+ origin: [120, 228],+ duration: 3,loop: false,fps: 30,bg: "ground",- options: { palette: PAL.electric, height: 104, seed: 7 },+ options: { palette: VOLT, sparks: PLASMA, seed: 5 },};-const CHAR = ramp(["#0c090c", "#191215", "#2a1d1c"]);-const EMBER = ramp(["#5a1a10", "#a83a18", "#e8782a", "#ffc870"]);-const SMOKE = ramp(["#2a2734", "#3b3747", "#4d485a"]);+const W = 120, TOP = -224, RX = 28, SY = 0.22, REACH = 52, LEAD0 = 0.48, STEPS = 9, MEET = -30;+const STROKES = [{ t: 0.76, k: 1 }, { t: 1.04, k: 0.8 }, { t: 1.26, k: 0.55 }];+const FLICK = [1, 0.72, 0.3, 0.95, 0.5, 0.8, 0.22];+const level = (a) => (a < 0 ? 0 : FLICK[Math.floor(a * 30 + 1e-4)] ?? 0);+const NIGHT = hex("#04030a"), DUST = hex("#6e6382"), ASH = hex("#5b5566"), STONE = ["#655b7a", "#4a4263", "#342d45"].map(hex);+const S1 = STROKES[0].t;-// 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;+// the cracks the strike splits in the floor: Lichtenberg branches lying on the floor's face+function cracks(R) {+ const out = [];+ const grow = (x, y, a, len, w, d, depth) => {+ const pts = [[x, y, d]];+ for (let s = 0; s < len; s += 1.5) {+ a += R.range(-0.32, 0.32);+ x += Math.cos(a) * 1.5;+ y = clamp(y + Math.sin(a) * 0.45, 0, 5);+ d += 1.5;+ pts.push([x, y, d]);+ if (depth < 2 && s > 3 && R.chance(0.09)) grow(x, y, a + R.sign() * R.range(0.5, 1.2), (len - s) * R.range(0.3, 0.6), w * 0.6, d, depth + 1);+ }+ out.push({ pts, w });+ };+ for (let i = 0; i < 6; i++) grow(R.range(-1, 1), R.range(0, 1), i % 2 ? R.range(-0.5, 0.7) : Math.PI + R.range(-0.7, 0.5), REACH * R.range(0.55, 1), 1, 0, 0);+ return out;}-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 sigil on the floor: a ring of dashes turning slowly, crosshair ticks, an inner ring and a heart; drawn in+// from the front, charging brighter; half picks the far (behind) or near part+function sigil(p, t, C, k, near) {+ const reveal = clamp(t / 0.22), spin = t * 0.8, burnt = t > S1 ? t - S1 : -1;+ if (burnt > 0.45) return;+ const a0 = burnt < 0 ? 1 : burnt < 0.07 ? 1 : 1 - (burnt - 0.07) / 0.38, hot = burnt >= 0 && burnt < 0.07;+ const on = (a) => Math.sin(a) >= 0 === near;+ const from = (a) => Math.abs((((a - Math.PI / 2) % TAU) + TAU + Math.PI) % TAU - Math.PI) / Math.PI;+ for (let i = 0; i < 22; i++) {+ const a = (i / 22) * TAU + spin;+ if (!on(a) || from(a) > reveal) continue;+ for (const da of [0, 0.06, 0.12]) {+ const x = Math.cos(a + da) * RX, y = Math.sin(a + da) * RX * SY;+ p.dot(x, y, hot ? WHITE : near ? (k > 0.7 ? C[6] : C[5]) : k > 0.7 ? C[4] : C[3], a0);+ if (near) p.dot(x, y + 1, hot ? C[6] : C[2], a0);}+ if (i % 3 === 0) p.glow(Math.cos(a) * RX, Math.sin(a) * RX * SY, 5, C[4], 0.3 * k * a0);}-- // 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);+ for (let j = 0; j < 4; j++) {+ const a = spin * -0.5 + (j * TAU) / 4 + Math.PI / 4;+ if (!on(a) || reveal < 1) continue;+ p.line(Math.cos(a) * (RX - 5), Math.sin(a) * (RX - 5) * SY, Math.cos(a) * (RX + 5), Math.sin(a) * (RX + 5) * SY, hot ? WHITE : near ? C[6] : C[4], a0);}-- // 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]);- });+ if (t > 0.3)+ for (let a = 0; a < TAU; a += 0.09) {+ if (!on(a)) continue;+ p.dot(Math.cos(a) * 14, Math.sin(a) * 14 * SY, hot ? WHITE : near ? C[4] : C[2], a0 * clamp((t - 0.3) / 0.12));+ }+ if (near && burnt < 0) {+ const pulse = 0.6 + 0.4 * Math.sin(t * (10 + 30 * k));+ p.px(0, 0, k > 0.5 ? WHITE : C[6]);+ for (const [dx, dy] of [[1, 0], [-1, 0], [0, -1]]) p.px(dx, dy, C[5]);+ p.glow(0, -1, 10 + 10 * k, C[5], 0.3 + 0.4 * k * pulse);}+}- // 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));- });+// keep forks on the canvas and above the floor+function keep(b) {+ const paths = [];+ for (const q of b.paths) {+ const pts = [];+ for (const pt of q.pts) {+ if (Math.abs(pt[0]) > W - 5 || pt[1] > -3 || pt[1] < TOP + 6) break;+ pts.push(pt);+ }+ if (q.w >= 1 || pts.length > 3) paths.push({ w: q.w, pts: q.w >= 1 ? q.pts : pts });}+ return { paths };+}++export function create(o) {+ const C = fit(o.palette, 8), R = new Rng(o.seed), floor = () => 0;+ const ps = new Particles({ rng: R, ground: floor, sparks: o.sparks }), hot = new Particles({ rng: R, ground: floor }), lights = new Lights();+ const X0 = R.range(8, 18) * (R.chance(0.5) ? 1 : -1);+ const main = keep(zigzag(R, X0, TOP, 0, -1, 0.17, 0.5)), trunk = main.paths[0].pts;+ const drift = (dx) => (x, y) => [x + dx * Math.sin((Math.PI * y) / TOP), y];+ const bolts = [main, bend({ paths: [{ pts: trunk, w: 1 }] }, drift(1.5)), bend({ paths: [{ pts: trunk, w: 1 }] }, drift(3))];+ const chan = (i) => bolts[i].paths[0].pts, last = STROKES[STROKES.length - 1], end = chan(STROKES.length - 1);+ const tree = cracks(R);+ // the spent channel breaks up from the top down, each piece at its own moment+ const gone = end.map(([, y], i) => last.t + 0.25 + 0.75 * (0.55 * rand(o.seed, i, 5) + 0.45 * (1 - y / TOP)));+ let t = 0, struck = -1;+ const now = () => {+ for (let i = STROKES.length - 1; i >= 0; i--) if (t >= STROKES[i].t) return { i, s: STROKES[i], a: t - STROKES[i].t, k: level(t - STROKES[i].t) * STROKES[i].k };+ return null;+ };+ const charge = () => clamp(t / S1) ** 1.5;+ const heatAt = () => (struck < 0 ? 0 : Math.max(...STROKES.slice(0, struck + 1).map((s) => s.k * Math.pow(clamp(1 - (t - s.t) / 1.6), 1.4))));- // 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));- });+ return {+ update(dt) {+ t += dt;+ for (const [i, s] of STROKES.entries()) {+ if (struck >= i || t < s.t) continue;+ struck = i;+ const k = s.k;+ lights.add(0, -50, 120, C[4], 0.55 * k, 0.4);+ lights.add(0, -3, 24, WHITE, 0.5 * k, 0.1);+ for (let j = 0; j < Math.round(44 * k); j++) {+ const a = -Math.PI / 2 + R.range(-1.3, 1.3), sp = R.range(110, 320) * (0.65 + 0.35 * k);+ ps.spawn(P.SPARK, R.range(-1.5, 1.5), -2, Math.cos(a) * sp, Math.sin(a) * sp, R.range(0.2, 0.55));+ }+ for (let j = 0; j < Math.round(12 * k); j++) {+ const a = -Math.PI / 2 + R.range(-1.2, 1.2), sp = R.range(70, 220);+ hot.spawn(P.SPARK, R.range(-2, 2), -1, Math.cos(a) * sp, Math.sin(a) * sp, R.range(0.5, 1));+ }+ for (let j = 0; j < Math.round(5 * k); j++) hot.spawn(P.EMBER, R.range(-4, 4), -2, R.range(-25, 25), -R.range(30, 80), R.range(0.8, 1.5));+ for (let j = 0; j < Math.round(18 * k); j++) {+ const a = -Math.PI / 2 + R.range(-1.1, 1.1), sp = R.range(50, 190);+ ps.spawn(P.GRIT, R.range(-3, 3), -1, Math.cos(a) * sp, Math.sin(a) * sp, R.range(1, 1.5), R.pick(STONE), R.chance(0.35) ? 2 : 1);+ }+ for (let j = 0; j < 8; j++) ps.spawn(P.DUST, R.range(-3, 3), -1, R.sign() * R.range(30, 110), -R.range(4, 24), R.range(0.4, 0.8), DUST, R.range(1.5, 3));+ for (let j = 0; j < Math.round(4 * k); j++) ps.spawn(P.SMOKE, R.range(-8, 8), -4, R.range(-10, 10), -R.range(10, 25), R.range(1.1, 1.6), mix(ASH, C[2], 0.3), R.range(3, 6), R.range(0.05, 0.25));+ }+ if (struck >= 0 && t < 1.7 && R.chance(6 * dt)) ps.spawn(P.SMOKE, R.range(-8, 8), -2, R.range(-4, 4), -R.range(9, 17), R.range(1, 1.3), 0, R.range(2, 3.5));+ for (let i = 0; i < gone.length - 1; i++)+ if (gone[i] <= t && gone[i] > t - dt && rand(o.seed, i, 6) < 0.5) {+ const [x, y] = end[i];+ ps.spawn(P.MOTE, x, y, R.range(-8, 8), R.range(6, 22), R.range(0.4, 0.8), R.chance(0.5) ? C[5] : C[4], R.range(0.5, 0.9));+ }+ ps.update(dt);+ hot.update(dt);+ lights.update(dt);+ },+ drawBack(p) {+ // the scene darkens a beat before the strike: a soft veil, deepest round the bolt's path, gone at the flash+ const dark = 0.5 * smooth(0.46, 0.66, t) * (1 - smooth(S1 - 0.01, S1 + 0.02, t));+ if (dark > 0.01)+ for (let y = -228; y < 36; y++)+ for (let x = -W; x < W; x++) {+ const d = Math.hypot(x / W, (y + 96) / 132), a = dark * (1 - smooth(0.55, 1, d));+ if (a > 0.01) p.blend(x + 0.5, y + 0.5, NIGHT, a);+ }+ sigil(p, t, C, charge(), false);+ // the cracks: arcs race out along them white, they glow with heat, cool to soot and fade+ if (struck >= 0) {+ const s = now(), front = REACH * ease.outCubic(clamp((t - S1) / 0.35)), T0 = heatAt(), fade = 1 - smooth(2.3, 2.95, t);+ const elec = s.a < 0.14 ? s.s.k * (1 - s.a / 0.14) : 0;+ for (const br of tree)+ for (const [x, y, d] of br.pts) {+ if (d > front) break;+ const q = d / REACH, n = rand(Math.round(x * 2), Math.round(y * 2), 9), fresh = d > front - 6 && front < REACH;+ const T = T0 * (1.15 - q) * (br.w < 1 ? 0.8 : 1) - n * 0.25, c = fresh || (elec > 0.3 && n < 0.85) ? (q < 0.5 ? WHITE : C[6]) : heat(T) || SOOT2;+ p.dot(x, y + 1, SOOT, fade);+ p.dot(x, y, c, fade);+ if (br.w >= 1 && d < 9) p.dot(x, y + 2, SOOT, fade);+ if ((fresh || elec > 0.3) && (Math.round(d) & 3) === 0) p.glow(x, y, 7, C[5], 0.4);+ else if (T > 0.2 && (Math.round(d) & 3) === 0) p.glow(x, y, 5, c, 0.2 * T);+ }+ scorch(p, 0, 0, 12, T0, fade);+ if (T0 > 0) p.glow(0, -2, 34, heat(0.55), 0.3 * T0);+ }+ ps.draw(p, "back");+ hot.draw(p, "back");+ },+ draw(p) {+ const s = now(), f = Math.floor(t * 30 + 1e-4), k = charge();+ sigil(p, t, C, k, true);+ // static rising off the charging sigil, more and more of it+ if (t > 0.15 && t < S1) {+ const r = rng(o.seed, 61, f);+ for (let i = 0; i < Math.round(1 + 4 * k); i++) {+ const a = r.range(0, TAU), x = Math.cos(a) * RX, y = Math.sin(a) * RX * SY;+ crackle(p, zigzag(r, x, y, x + r.range(-2.5, 2.5), y - r.range(4, 9) * (0.6 + k), 0.45, 0.3), 0.45 + 0.4 * k, C, 0.3);+ }+ p.glow(0, -2, 36, C[4], 0.12 + 0.3 * k);+ }+ // the stepped leader feels down from above; a streamer climbs out of the sigil to meet it+ if (t >= LEAD0 && t < S1) {+ const u = clamp((t - LEAD0) / (S1 - LEAD0)), st = Math.min(STEPS, Math.floor(u * STEPS) + 1), fresh = 1 - ((u * STEPS) % 1);+ const reach = TOP + (MEET - TOP) * Math.pow(st / STEPS, 1.2), prev = TOP + (MEET - TOP) * Math.pow((st - 1) / STEPS, 1.2);+ for (const q of main.paths) {+ const tk = q.w >= 1;+ for (let i = 0; i < q.pts.length - 1; i++) {+ const [ax, ay] = q.pts[i], [bx, by] = q.pts[i + 1];+ if (by > reach) {+ if (ay <= reach && i > 0) (p.px(ax, ay, WHITE), p.glow(ax, ay, 7, C[5], 0.5 * fresh + 0.15));+ break;+ }+ const young = by > prev;+ p.line(ax, ay, bx, by, young ? (fresh > 0.4 ? (tk ? C[6] : C[5]) : C[4]) : tk ? C[3] : C[2]);+ if (i % 4 === 0 && ay > TOP + 14) p.glow(ax, ay, young ? 8 : 5, C[4], young ? 0.3 * fresh + 0.1 : 0.12);+ }+ }+ if (t > 0.62) {+ const h = -MEET * ease.outQuad((t - 0.62) / (S1 - 0.62)), r = rng(o.seed, 77, f);+ const b = zigzag(r, 0, -1, r.range(-2, 2), -Math.max(3, h), 0.3, 0.3), tip = b.paths[0].pts.at(-1);+ crackle(p, b, 0.85, C, 0.45);+ p.px(tip[0], tip[1], WHITE);+ p.glow(tip[0], tip[1], 9, C[5], 0.5);+ }+ }+ // the strokes, the dart that runs down the channel before each flicker, the channel cooling and crumbling+ const next = STROKES.find((q) => q.t > t);+ if (next && next !== STROKES[0] && t > next.t - 0.06) {+ const tr = chan(STROKES.indexOf(next)), u = (t - (next.t - 0.06)) / 0.06, i1 = Math.floor(u * tr.length);+ trace(p, tr, C[3], 1);+ trace(p, tr, C[6], 1, i1 - 18, i1);+ for (let i = Math.max(0, i1 - 18); i < Math.min(tr.length, i1); i += 4) if (tr[i][1] > TOP + 14) p.glow(tr[i][0], tr[i][1], 9, C[4], 0.35);+ } else if (s && s.k > 0) {+ const hero = s.i === 0 && s.a < 1 / 30;+ stroke(p, bolts[s.i], s.k, C, s.i === 0 ? 1.5 : 1.2, { hero, core: s.k > 0.6 ? (hero ? 1.2 : 0.8) : 0, minY: TOP + 14 });+ const r = 4.5 * s.k;+ p.circle(0, -1, r + 1.5, C[2]);+ p.circle(0, -1, r + 0.5, C[5]);+ p.circle(0, -1, r * 0.65, WHITE);+ if (s.a < 0.07) sparkle(p, 0, -2, Math.round(12 * s.k * (1 - s.a / 0.07)), C[6], C[4], 0.25);+ p.glow(0, -16, 96, C[3], 0.42 * s.k);+ p.glow(0, -3, 22, C[5], 0.3 * s.k);+ if (hero) p.glow(X0 * 0.5, -110, 170, C[3], 0.3);+ } else if (s) {+ const crumble = s.i === STROKES.length - 1, cool = clamp((s.a - 0.23) / 0.45), tr = chan(s.i);+ for (let i = 0; i < tr.length - 1; i++) {+ if (crumble && t >= gone[i]) continue;+ const h = crumble ? 1 - clamp((t - last.t - 0.23) / (gone[i] - last.t - 0.23)) : 1 - cool;+ p.line(tr[i][0], tr[i][1], tr[i + 1][0], tr[i + 1][1], h > 0.7 ? C[5] : h > 0.4 ? C[4] : h > 0.15 ? C[3] : C[2]);+ if (i % 6 === 0 && h > 0.3 && tr[i][1] > TOP + 14) p.glow(tr[i][0], tr[i][1], 6, C[4], 0.15 * h);+ }+ }+ // arcs crawl out along the cracks as they split, and again with every flicker+ if (s && s.a < 0.4) {+ const r = rng(o.seed, 91, f), run = s.i === 0 ? REACH * ease.outCubic(clamp(s.a / 0.35)) : REACH * clamp(s.a / 0.22);+ for (const br of tree) {+ if (br.w < 1 || r.next() < 0.3) continue;+ const i1 = br.pts.findIndex(([, , d]) => d > run), j1 = i1 < 0 ? br.pts.length : i1, j0 = Math.max(0, j1 - r.int(7, 13));+ const pts = br.pts.slice(j0, j1).map(([x, y]) => [x + r.range(-0.6, 0.6), y - 1.5 - r.range(0, 2.5)]);+ if (pts.length > 1) crackle(p, { paths: [{ pts, w: 1 }] }, 0.9 * (1 - s.a / 0.4) + 0.1, C, 0.35);+ }+ }+ ps.draw(p, "front");+ hot.draw(p, "front");+ lights.draw(p);+ },+ };}diff --git a/src/fx/lightning/plasma-ball.js b/src/fx/lightning/plasma-ball.jsindex 599df8e..e62a656 100644--- a/src/fx/lightning/plasma-ball.js+++ b/src/fx/lightning/plasma-ball.js@@ -1,78 +1,101 @@-import { ramp, rand, rng, loopNoise, TAU, WHITE } from "../../core/index.js";-import { steps, glowPath } from "./_lib.js";+// The re-struck filaments, the glass shell with its specular arc and the core follow Sprite Fusion's open-source+// energy orb (https://www.spritefusion.com/pixel-art-vfx/energy), MIT License, Copyright (c) 2026 Hugo Duprez.+import { fit, clamp, rng, TAU, WHITE, hex, mix, loopNoise } from "../../core/index.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,+ desc: "A glass globe on a dark pedestal: wandering plasma tendrils reach from the core to the glass and fan out in bright feet where they touch it, lighting the stand and floor.",+ tags: ["lightning", "electric", "plasma", "lamp", "prop", "loop"],+ size: [112, 104],+ origin: [56, 96],+ duration: 3,loop: true,fps: 30,- bg: "dark",- options: {- palette: ["#12061e", "#2a0b46", "#521880", "#8a2cb8", "#c84ae0", "#f08af0", "#ffd0fa", "#ffffff"],- radius: 17, tendrils: 6, seed: 9,- },+ bg: "ground",+ options: { palette: ["#1a0828", "#3b0f5e", "#6a1d9c", "#a03ad6", "#d46cf2", "#f2a8ff", "#ffe2ff", "#ffffff"], tendrils: 9, seed: 6 },};-const BASE = ramp(["#0f0d16", "#1d1a27", "#2f2b3c", "#454057", "#625c78"]);+const FPS = 30, N = 90, GX = 0, GY = -55, RG = 24, BASE = ["#0d0b12", "#17131f", "#231d2d", "#342b43", "#4b3f60", "#6b5c87"].map(hex);-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 };+// a tendril at phase ph: its end wanders over the glass, front ones end on the near face, back ones on the far+function tendril(i, n, ph, seed) {+ const a = ((i + 0.5) / n) * TAU + 0.9 * loopNoise(ph, 0.9, seed + i * 7), z = loopNoise(ph, 0.7, seed + i * 7 + 3);+ const rho = RG * (0.72 + 0.28 * Math.sqrt(1 - Math.min(1, z * z * 1.6)));+ return { a, front: z > -0.15, ex: GX + Math.cos(a) * rho, ey: GY + Math.sin(a) * rho, rim: rho > RG * 0.93, w1: loopNoise(ph, 1.1, seed + i * 7 + 5), w2: loopNoise(ph, 1.3, seed + i * 7 + 6) };}-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 pedestal: a flared stand lit from above by the globe, a collar under the glass+function pedestal(p, C, glow) {+ p.shade(-18, -32, 18, 0, (x, y, o) => {+ const hw = y < -27 ? 7 : y < -2 ? 9 + ((y + 27) / 25) * 6 : 16;+ if (Math.abs(x) > hw) return;+ const u = (x / hw + 1) / 2;+ if (y < -27) return (o.c = y < -30 ? (u < 0.6 ? C[4] : BASE[5]) : u < 0.3 ? BASE[5] : u < 0.75 ? BASE[3] : BASE[1]);+ if (y >= -2) return (o.c = y < -1 ? (u < 0.55 ? BASE[4] : BASE[2]) : BASE[1]);+ // glossy body: a lit flank, a specular stripe, the far side in shadow, plasma light on the upper rim+ const i = u < 0.1 ? 2 : u < 0.2 ? 3 : u < 0.3 ? 5 : u < 0.42 ? 4 : u < 0.6 ? 3 : u < 0.8 ? 2 : u < 0.92 ? 1 : 0;+ o.c = y < -24 && u < 0.5 ? mix(BASE[i], C[4], 0.3 * glow) : y > -5 ? BASE[Math.max(0, i - 1)] : BASE[i];});+ p.px(9, -9, C[5]);+ p.glow(9, -9, 3, C[5], 0.5);+}- // 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);+export function draw(p, t, o) {+ const C = fit(o.palette, 8), f = Math.floor(t * FPS + 1e-6) % N, ph = f / N, n = o.tendrils, R = rng(o.seed, 3, f);+ const pulse = 0.85 + 0.15 * Math.sin(ph * TAU * 6) + 0.1 * (R.next() - 0.5), ts = Array.from({ length: n }, (_, i) => tendril(i, n, ph, o.seed));+ // light the floor and the stand, then the stand+ p.glow(0, -6, 52, C[3], 0.22 * pulse);+ pedestal(p, C, pulse);+ // the glass: a faint tint over what's behind, the plasma's glow inside it+ p.shade(GX - RG, GY - RG, GX + RG, GY + RG, (x, y) => {+ const d = Math.hypot(x - GX, y - GY);+ if (d < RG - 0.5) p.blend(x, y, d > RG - 4 ? C[1] : C[0], 0.22 + 0.4 * (d / RG) ** 4);+ });+ p.glow(GX, GY, RG + 14, C[3], 0.32 * pulse);+ p.glowRing(GX, GY, RG - 1, 5, C[3], 0.22 * pulse);+ const drawTendril = (q, i, bright) => {+ const sx = GX + Math.cos(q.a) * 4.5, sy = GY + Math.sin(q.a) * 4.5, dx = q.ex - sx, dy = q.ey - sy, L = Math.hypot(dx, dy), nx = -dy / L, ny = dx / L;+ const r = rng(o.seed, 17, i, f), pts = [], m = Math.max(4, Math.round(L / 2.2));+ for (let j = 0; j <= m; j++) {+ const u = j / m, w = 3.2 * q.w1 * Math.sin(Math.PI * u) + 1.6 * q.w2 * Math.sin(TAU * u + i), jit = j && j < m ? r.range(-0.7, 0.7) : 0;+ pts.push([sx + dx * u + nx * (w + jit), sy + dy * u + ny * (w + jit)]);+ }+ // the foot: the filament fans into short fingers where it meets the glass+ const paths = [{ pts, w: 1 }];+ for (let k = 0; k < 3; k++) {+ const [bx, by] = pts[m - 2], a = q.a + (k - 1) * r.range(0.25, 0.45), l = r.range(2.5, 5);+ paths.push({ pts: [[bx, by], [bx + Math.cos(a) * l * 0.5 + r.range(-0.6, 0.6), by + Math.sin(a) * l * 0.5 + r.range(-0.6, 0.6)], [bx + Math.cos(a) * l, by + Math.sin(a) * l]], w: 0.5 });+ }+ const hot = r.next() < 0.2;+ for (const q2 of paths)+ for (let j = 0; j < q2.pts.length - 1; j++) {+ const [ax, ay] = q2.pts[j], [bx, by] = q2.pts[j + 1], u = j / (q2.pts.length - 1);+ if (bright && q2.w >= 1) p.line(ax + 1, ay + 1, bx + 1, by + 1, C[3]);+ const c = !bright ? (q2.w >= 1 ? C[3] : C[2]) : q2.w < 1 ? C[6] : hot || u > 0.75 ? C[6] : u < 0.2 ? C[6] : C[5];+ p.line(ax, ay, bx, by, c);+ if (q2.w >= 1 && j % 3 === 0) p.glow(ax, ay, bright ? 6 : 4, C[4], bright ? (hot ? 0.4 : 0.24) : 0.12);+ }+ // where it touches, the glass flares+ if (bright) {+ p.circle(q.ex, q.ey, 1.6, C[6]);+ p.px(q.ex, q.ey, WHITE);+ p.glow(q.ex, q.ey, 9, C[5], 0.55);+ if (q.rim) for (let s = -1; s <= 1; s += 2) p.px(GX + Math.cos(q.a + s * 0.09) * (RG - 0.5), GY + Math.sin(q.a + s * 0.09) * (RG - 0.5), C[6]);+ } else p.glow(q.ex, q.ey, 6, C[4], 0.25);+ };+ ts.forEach((q, i) => !q.front && drawTendril(q, i, false));+ // the core: an electrode ball, pulsing+ const cr = 3.6 + 0.5 * pulse;+ p.circle(GX, GY, cr + 1.3, C[3]);+ p.circle(GX, GY, cr, C[5]);+ p.circle(GX - 0.6, GY - 0.6, cr * 0.55, C[6]);+ p.circle(GX - 0.8, GY - 0.8, cr * 0.25, WHITE);+ p.glow(GX, GY, 16, C[5], 0.65 * pulse);+ ts.forEach((q, i) => q.front && drawTendril(q, i, true));+ // the glass shell: a thin rim, a bright specular arc upper left, a faint reflection lower right+ p.ring(GX, GY, RG + 1.6, 1, C[1]);+ p.ring(GX, GY, RG + 0.6, 1.1, (v, a) => (a > 2.2 && a < 3.3 ? C[5] : a > 0.3 && a < 1.3 ? C[4] : C[3]));+ p.arc(GX, GY, RG - 1.6, 1.3, 3.55, 4.55, (u) => (u > 0.25 && u < 0.7 ? WHITE : C[6]));+ for (let a = 0.35; a < 1.15; a += 0.045) p.dot(GX + Math.cos(a) * (RG - 2.6), GY + Math.sin(a) * (RG - 2.6), C[4], 0.85);+ p.px(GX - RG * 0.42, GY - RG * 0.62, WHITE);}diff --git a/src/fx/lightning/spark-arc.js b/src/fx/lightning/spark-arc.jsindex dc5f928..d63414f 100644--- a/src/fx/lightning/spark-arc.js+++ b/src/fx/lightning/spark-arc.js@@ -1,76 +1,95 @@-import { ramp, burst, fly, flyV, seg, ease, clamp, lerp, rng, rand, WHITE } from "../../core/index.js";-import { steps, zap, glowPath, jagged } from "./_lib.js";+// The arc's re-struck bowed shape, its halo-body-core inking, its flicker and the nodes where it roots follow+// Sprite Fusion's open-source lightning (https://www.spritefusion.com/pixel-art-vfx/lightning),+// MIT License, Copyright (c) 2026 Hugo Duprez.+import { fit, clamp, rng, TAU, WHITE, hex, mix, ease } from "../../core/index.js";+import { VOLT, PLASMA, bowed, stroke, crackle, zigzag, flight, spark, puff, heat } 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,+ desc: "A climbing arc between two rods: it strikes white at their narrow foot, climbs on rising heat as it stretches and bows, sputters and snaps at the top, then strikes again.",+ tags: ["lightning", "electric", "arc", "jacobs-ladder", "machine", "prop", "loop"],+ size: [124, 120],+ origin: [62, 108],+ duration: 2,loop: true,fps: 30,- bg: "dark",- options: { palette: ["#140a30", "#2e1a78", "#5a38c8", "#8a70ff", "#bcb0ff", "#e8e2ff", "#ffffff"], seed: 10 },+ bg: "ground",+ options: { palette: VOLT, sparks: PLASMA, seed: 2 },};-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)))]);-}+const FPS = 30, N = 60, P = 2, SNAP = 1.42, H = 58, STEEL = ["#151823", "#262c3b", "#3d4558", "#5f6a82", "#8f9bb2", "#d2daea"].map(hex);+const CERAMIC = ["#4b4458", "#857d96", "#c9c1d6", "#efe9f6"].map(hex), ASH = hex("#6a6478");+// the rods: a V from the insulators up; where the arc roots at height h above the gap+const rodAt = (s, h) => [s * (4.5 + (h / 60) * 19.5), -9 - h];+const height = (t) => 1.5 + H * Math.pow(clamp(t / SNAP), 1.35);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+ const C = fit(o.palette, 8), S = o.sparks.map(hex), f = Math.floor(t * FPS + 1e-6) % N, r = rng(o.seed, 1, f);+ const climbing = t < SNAP, h = height(t), u = clamp(t / SNAP), a = t - SNAP;+ // the floor and the stand: a pool of cold light while it burns, a plate, two ribbed insulators+ p.glow(0, -14, 50, C[3], climbing ? 0.2 + 0.15 * (1 - u) : 0.06);+ p.rect(-18, -3, 36, 3, STEEL[1]);+ p.line(-18, -3, 17, -3, STEEL[3]);+ for (const s of [-1, 1])+ for (let y = -9; y < -3; y++) {+ const rib = (y & 1) === 0;+ for (let x = 2; x <= 6; x++) p.px(s * x - (s < 0 ? 1 : 0), y, rib ? CERAMIC[x < 4 ? 3 : x < 6 ? 2 : 1] : CERAMIC[x < 5 ? 1 : 0]);+ }+ // the rods: steel, a lit edge, glowing where the arc has passed and cooling behind itfor (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));+ for (let hh = 0; hh <= 60; hh += 0.5) {+ // when the arc passed this point; not yet this time round, it is still cooling from the last+ const [x, y] = rodAt(s, hh), tp = SNAP * Math.pow(clamp((hh - 1.5) / H), 1 / 1.35), age = t >= tp ? t - tp : t - tp + P;+ const hot = hh > H + 2 ? 0 : Math.exp(-age / 0.26), c = heat(hot * 1.05 - 0.12);+ p.px(x, y, c || (s < 0 ? STEEL[4] : STEEL[3]));+ p.px(x + s, y, c && hot > 0.35 ? heat(hot * 0.6) || STEEL[2] : s < 0 ? STEEL[2] : STEEL[1]);+ if (hot > 0.3 && (Math.round(hh * 2) & 3) === 0) p.glow(x, y, 5, c || C[4], 0.25 * hot);}- 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);+ const [tx, ty] = rodAt(s, 60);+ p.circle(tx + s * 0.5, ty, 1.6, STEEL[4]);+ p.px(tx + s * 0.5 - 0.5, ty - 1, STEEL[5]);+ }+ // the arc: struck white at the foot, flickering as it climbs and stretches, sputtering at the top+ if (climbing) {+ const [xl, yl] = rodAt(-1, h), [xr, yr] = rodAt(1, h), k0 = t < 1 / FPS ? 1 : 1 - 0.22 * u, sput = u > 0.88 && r.next() < 0.25 ? 0.4 : 1;+ const k = k0 * sput * (0.82 + 0.18 * r.next()), bow = -(1.5 + 13 * u * u) * (0.8 + 0.4 * r.next());+ stroke(p, bowed(r, xl, yl, xr, yr, bow, 0.18 + 0.12 * u, 0.12 + 0.25 * u), k, C, t < 1 / FPS ? 0.95 : 0.8, { hero: t < 1 / FPS, light: 0.7 });+ p.glowLine(xl, yl + bow * 0.5, xr, yr + bow * 0.5, 12, C[4], 0.22 * k);+ for (const [x, y] of [[xl, yl], [xr, yr]]) {+ p.circle(x, y, 1.8 + 0.6 * k, C[5]);+ p.px(x, y, WHITE);+ p.glow(x, y, 12, C[5], 0.55 * k);}+ if (t < 0.1) p.glow(0, -11, 26, C[6], 0.45 * (1 - t / 0.1));+ } else if (a < 2 / FPS) {+ // the snap: two stubs left clinging to the rods, a flash where it broke+ const [xl, yl] = rodAt(-1, H + 1.5), [xr, yr] = rodAt(1, H + 1.5);+ for (const [x0, y0, s] of [[xl, yl, 1], [xr, yr, -1]]) crackle(p, zigzag(r, x0, y0, x0 + s * r.range(5, 9), y0 - r.range(2, 6), 0.4, 0.3), 0.7, C, 0.4);+ p.glow(0, yl - 8, 30, C[4], 0.5);+ } else if (t > P - 0.16) {+ // anticipation: little sparks jump the narrow gap before it strikes again+ if (r.next() < 0.7) crackle(p, zigzag(r, -4.5, -10.5 - r.range(0, 2), 4.5, -10.5 - r.range(0, 2), 0.5, 0), 0.4 + 0.3 * r.next(), C, 0.35);}- p.glow(0, Y0 - 2, 10, C[3], 0.2);+ // ozone and smoke rise off the arc while it climbs, and from where it snapped+ for (let j = 0; j < 3; j++) {+ const born = ((j + 1) / 3.2) * SNAP, age = (((t - born) % P) + P) % P, life = 1;+ if (age >= life) continue;+ const y0 = -9 - height(born) - 6;+ puff(p, (j % 2 ? 3 : -3) + Math.sin(age * 3 + j) * 2, y0 - age * 20, 1.8 + j * 0.3, age / life, mix(ASH, C[5], 0.3));+ }+ // sparks: thrown from the roots as it strikes, sprayed up where it snaps, molten drips off the rods+ const burst = (t0, n, salt, from) => {+ const age = (((t - t0) % P) + P) % P;+ for (let j = 0; j < n; j++) {+ const q = rng(o.seed, salt, j), life = q.range(0.25, 0.6);+ if (age >= life) continue;+ const [x0, y0, a0, spread, sp0, sp1] = from(q, j), ang = a0 + q.range(-spread, spread), sp = q.range(sp0, sp1);+ const [x, y, vx, vy] = flight(x0, y0, Math.cos(ang) * sp, Math.sin(ang) * sp, age, { floor: 0 });+ spark(p, x, y, vx, vy, 1 - age / life, S);+ }+ };+ burst(0, 12, 11, (q, j) => [...rodAt(j % 2 ? 1 : -1, 1.5), -Math.PI / 2 + (j % 2 ? 0.6 : -0.6), 1, 60, 170]);+ burst(SNAP, 14, 12, (q, j) => [rodAt(1, H)[0] * q.range(-0.8, 0.8), -9 - H - 6, -Math.PI / 2, 1.3, 50, 160]);+ for (const [k, tt] of [[0, 0.45], [1, 0.8], [2, 1.15]]) burst(tt, 2, 20 + k, (q, j) => [...rodAt(j % 2 ? 1 : -1, height(tt)), Math.PI / 2, 0.5, 5, 30]);+ if (climbing || a < 0.25) p.glow(0, -9 - h - 3, 26, C[4], climbing ? 0.25 : 0.4 * (1 - a / 0.25));}diff --git a/src/fx/lightning/static-pops.js b/src/fx/lightning/static-pops.jsdeleted file mode 100644index 64eeca4..0000000--- a/src/fx/lightning/static-pops.js+++ /dev/null@@ -1,47 +0,0 @@-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.jsindex 878e54e..ba59824 100644--- a/src/fx/lightning/storm-cloud.js+++ b/src/fx/lightning/storm-cloud.js@@ -1,86 +1,152 @@-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";+// The bolt's forked shape, its halo-body-core inking and its flicker follow Sprite Fusion's open-source+// lightning (https://www.spritefusion.com/pixel-art-vfx/lightning), MIT License, Copyright (c) 2026 Hugo Duprez.+import { fit, clamp, rng, cycle, smooth, WHITE, hex, loopNoise, tileNoise } from "../../core/index.js";+import { VOLT, PLASMA, zigzag, stroke, crackle, flight, spark } 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,+ desc: "A storm cloud boils overhead, billows lit from inside by flickering discharges, ragged scud under its flat dark base; rain slants down and once a loop a bolt cracks to the floor.",+ tags: ["lightning", "storm", "weather", "cloud", "rain", "ambient", "loop"],+ size: [168, 176],+ origin: [84, 164],+ duration: 3,loop: true,fps: 30,- bg: "sky",- options: { palette: PAL.electric, seed: 12 },+ bg: "ground",+ options: { palette: VOLT, sparks: PLASMA, cloud: ["#09070f", "#120f1e", "#1b182e", "#252640", "#323758", "#464d78", "#646b9c"], rain: ["#2b3250", "#46527a", "#6d7cab", "#a5b5e0"], seed: 8 },};-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];+const FPS = 30, N = 90, P = 3, BASE = -100, TOP = -156, TH = 0.35, VIS = Math.sqrt(1 - Math.sqrt(TH));+// the billows: [x, y, visible radius, squash]; a tower leaning into a flat anvil sheared off to the right, big+// billows of all sizes below it, smaller shoulders, a flat run along the base+const BILLOWS = [+ [-6, -132, 17], [18, -127, 14], [-28, -122, 12], [38, -118, 10], [0, -142, 12],+ [14, -149, 19, 0.38], [40, -148, 14, 0.34],+ [-48, -113, 10], [55, -110, 9], [-17, -115, 13], [22, -113, 12],+ [-42, -104, 11], [-10, -104, 12], [20, -104, 11], [48, -103, 9], [-63, -104, 7], [66, -103, 6],+];+// discharges inside: [frame, billow, strength]; the bolt to the floor at frame BOLT, out of billow BOLT_B+const FLASHES = [[7, 2, 0.8], [8, 9, 0.55], [29, 1, 0.75], [31, 10, 1], [33, 3, 0.5], [70, 0, 0.8], [71, 4, 0.55], [72, 5, 0.35]];+const BOLT = 52, BOLT_B = 12, BK = [1, 0.7, 0.3, 0.95, 0.5, 0.75, 0.2];+const W0 = -84, H0 = TOP - 6, GW = 168, GH = BASE + 8 - H0;+const FIELD = new Float32Array(GW * GH), GX = new Float32Array(GW * GH), GY = new Float32Array(GW * GH), LIT = new Float32Array(GW * GH);-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;+// where each billow is this frame: drifting, breathing and boiling up on its own clock, all seamless over the loop+function billows(seed, ph) {+ return BILLOWS.map(([x, y, v, sq = 1], i) => {+ const top = y < -112 && sq === 1, boil = 0.82 + 0.3 * Math.sin(Math.PI * ((ph + i * 0.37) % 1)) ** 2;+ return { sq, x: x + 3.5 * loopNoise(ph, 0.7, seed + i) + (sq < 1 ? 4 * loopNoise(ph, 0.5, seed + i + 90) : 0), y: y + 2 * loopNoise(ph, 0.7, seed + i + 30) - (top ? 4 * (boil - 0.97) : 0), r: (v * (top ? boil : 1 + 0.08 * loopNoise(ph, 0.6, seed + i + 60))) / VIS };+ });}-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 cloud as one field: billows summed so they fuse, clipped flat at the base, its edge ragged with drifting+// noise; shaded as one mass (a lit top, a cool middle, a dark belly), discharges lighting whole billows from inside+function cloud(p, B, ph, seed, K, C, flashes) {+ FIELD.fill(0);+ GX.fill(0);+ GY.fill(0);+ LIT.fill(0);+ for (const [i, b] of B.entries()) {+ const k = flashes.get(i) ?? 0, r2 = b.r * b.r, ry = b.r * b.sq;+ for (let y = Math.max(0, Math.floor(b.y - ry - H0)); y < Math.min(GH, Math.ceil(b.y + ry - H0)); y++)+ for (let x = Math.max(0, Math.floor(b.x - b.r - W0)); x < Math.min(GW, Math.ceil(b.x + b.r - W0)); x++) {+ const dx = x + W0 + 0.5 - b.x, dy = (y + H0 + 0.5 - b.y) / b.sq, d2 = (dx * dx + dy * dy) / r2;+ if (d2 >= 1) continue;+ const j = y * GW + x, u = 1 - d2, c = u * u;+ FIELD[j] += c;+ GX[j] += (-4 * u * dx) / r2;+ GY[j] += (-4 * u * dy) / (r2 * b.sq);+ if (k) LIT[j] += k * (0.25 + 0.75 * c) * (d2 < 1 ? 1 : 0);+ }+ }+ const ramp = [...K, C[3], C[4], C[5], C[6]], n = K.length;+ for (let y = 0; y < GH; y++) {+ const cy = y + H0 + 0.5;+ for (let x = 0; x < GW; x++) {+ const j = y * GW + x;+ if (FIELD[j] < TH - 0.06) continue;+ const cx = x + W0 + 0.5, base = BASE + 1.5 * tileNoise(cx * 0.12 + 9 * ph, 3, 9, 0, seed + 5);+ const F = FIELD[j] * (1 - smooth(base - 3, base, cy)) + 0.05 * tileNoise(cx * 0.21 + 18 * ph, cy * 0.21, 18, 0, seed);+ if (F < TH) continue;+ // the field's slope rounds each billow's top; height does the rest: lit above, cool in the middle, dark below+ const gl = Math.hypot(GX[j], GY[j]) || 1, lam = -(GX[j] * 0.42 + GY[j] * 0.9) / gl, edge = Math.min(1, gl * 5) * (F < TH + 0.08 ? 1 : 0.55);+ const h = 1 - 2 * clamp((cy - TOP) / (BASE - TOP));+ let i = 2.7 + 2.2 * h + 1.3 * lam * edge + 0.4 * tileNoise(cx * 0.16 + 12 * ph, cy * 0.16, 12, 0, seed + 9);+ if (F < TH + 0.05 && lam > 0.3 && h > -0.5) i += 1;+ if (cy > base - 6) i -= 1;+ i = clamp(Math.round(i), 0, n - 1);+ // lit from inside: brightest deep in the billow, breaking up through the cloud's own lumps toward its edges+ const L = LIT[j] * (0.7 + 0.6 * tileNoise(cx * 0.2 - 14 * ph, cy * 0.2, 14, 0, seed + 3));+ if (L > 0.12) i = Math.min(ramp.length - 1, i + Math.round(L * 5.5));+ p.px(cx, cy, ramp[i]);+ }+ }+}- // 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);+// scud: ragged wisps that form under the base, drift off on the wind and fray away+function scud(p, ph, seed, K) {+ const r = rng(seed, 13);+ for (let w = 0; w < 6; w++) {+ const x0 = r.range(-60, 60), y0 = BASE + r.range(3, 9), rx = r.range(10, 20), ry = r.range(1.3, 2.2), off = r.next(), u = (ph + off) % 1, a = Math.sin(Math.PI * u) ** 0.8;+ const xc = x0 + 16 * (u - 0.5);+ for (let y = Math.floor(y0 - ry - 1); y <= y0 + ry + 1; y++)+ for (let x = Math.floor(xc - rx - 1); x <= xc + rx + 1; x++) {+ const dx = (x + 0.5 - xc) / rx, dy = (y + 0.5 - y0) / ry, nz = tileNoise((x + 0.5) * 0.35 + 10 * ph + w * 7, (y + 0.5) * 0.5, 10, 0, seed + 20 + w);+ const v = (1 - dx * dx - dy * dy) * a + 0.6 * nz - 0.25;+ if (v > 0) p.blend(x + 0.5, y + 0.5, v > 0.4 ? K[2] : K[3], Math.min(0.6, 0.2 + v * 0.7));+ }}+}- // 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);+export function draw(p, t, o) {+ const C = fit(o.palette, 8), K = fit(o.cloud, 7), RN = fit(o.rain, 4), S = o.sparks.map(hex), f = Math.floor(t * FPS + 1e-6) % N, ph = f / N;+ const B = billows(o.seed, ph), br = rng(o.seed, 5, BOLT), ba = f - BOLT;+ const bx0 = BILLOWS[BOLT_B][0] + br.range(-4, 4), bx1 = br.range(-24, 24);+ // what's lighting the cloud this frame: discharges inside billows, and the billow the bolt leaves from+ const flashes = new Map(FLASHES.filter(([ff]) => ff === f).map(([, b, k]) => [b, k]));+ if (ba >= 0 && ba < BK.length) flashes.set(BOLT_B, Math.max(flashes.get(BOLT_B) ?? 0, BK[ba]));+ const lights = [...flashes].map(([b, k]) => ({ x: B[b].x, y: B[b].y, k, r: B[b].r * VIS * (B[b].sq < 1 ? 1.6 : 2.2) }));+ const flash = lights.reduce((s, l) => Math.max(s, l.k), 0);++ // rain: slanting streaks from the belly, splashing on the floor, lit when the sky flashes+ cycle(t, P, 150, o.seed + 11, (g) => g.range(0.5, 0.62), (age, life, r) => {+ const x0 = r.range(-62, 62), vy = r.range(190, 240), vx = -vy * 0.18, tf = (0 - (BASE + 4)) / vy;+ if (age < tf) {+ const x = x0 + vx * age, y = BASE + 4 + vy * age, l = r.range(4, 6.5);+ p.line(x - vx * 0.018 * (l / 4), y - l, x, y, (u) => (u > 0.7 ? (flash > 0.5 ? C[5] : RN[3]) : flash > 0.5 ? C[3] : RN[u > 0.35 ? 2 : 1]));+ } else if (age < tf + 0.12) {+ const x = x0 + vx * tf, a = (age - tf) / 0.12;+ for (const s of [-1, 1]) p.px(x + s * (1 + a * 2.5), -1 - Math.sin(a * Math.PI) * 2.5, a < 0.5 ? RN[3] : RN[2]);+ if (a < 0.4) p.px(x, 0, RN[3]);}- 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);+ // the scud hanging under the base, the cloud, then the light of whatever burns inside it+ scud(p, ph, o.seed, K);+ cloud(p, B, ph, o.seed, K, C, flashes);+ for (const l of lights) p.glow(l.x, l.y, l.r, C[4], 0.4 * l.k);+ p.glow(0, -122, 80, C[2], 0.05 + 0.22 * flash);+ // a discharge crawls along the belly now and then+ for (const [ff, b, k] of FLASHES)+ if (ff === f && k > 0.6) {+ const r = rng(o.seed, 7, ff), x = B[b].x;+ crackle(p, zigzag(r, x - r.range(12, 22), BASE - r.range(2, 6), x + r.range(12, 22), BASE - r.range(1, 5), 0.25, 0.5), 0.6, C, 0.4);+ }+ // the bolt: struck once a loop, forked, flickering, the floor lit and sparks thrown where it lands+ if (ba >= 0 && ba < BK.length) {+ const k = BK[ba];+ stroke(p, zigzag(rng(o.seed, 9, BOLT), bx0, BASE - 3, bx1, 0, 0.22, 0.7), k, C, ba === 0 ? 1.15 : 1, { hero: ba === 0 });+ p.circle(bx1, -1, 3 * k + 1.5, C[2]);+ p.circle(bx1, -1, 3 * k + 0.5, C[5]);+ p.circle(bx1, -1, 2 * k, WHITE);+ p.glow(bx1, -22, 78, C[3], 0.5 * k);+ p.glow(bx1, -3, 18, C[5], 0.45 * k);+ p.glow(bx0, BASE, 84, C[4], 0.3 * k);+ }+ const sa = (((t - BOLT / FPS) % P) + P) % P;+ for (let j = 0; j < 16; j++) {+ const q = rng(o.seed, 31, j), life = q.range(0.25, 0.6);+ if (sa >= life) continue;+ const a = -Math.PI / 2 + q.range(-1.3, 1.3), sp = q.range(60, 200), [x, y, vx, vy] = flight(bx1, -1, Math.cos(a) * sp, Math.sin(a) * sp, sa, { floor: 0 });+ spark(p, x, y, vx, vy, 1 - sa / life, S);}}diff --git a/src/fx/lightning/tesla-coil.js b/src/fx/lightning/tesla-coil.jsindex d30990a..0096de9 100644--- a/src/fx/lightning/tesla-coil.js+++ b/src/fx/lightning/tesla-coil.js@@ -1,71 +1,205 @@-import { PAL, ramp, at, seg, clamp, rng, rand, TAU, WHITE } from "../../core/index.js";-import { steps, zap, glowPath, jagged, branches, fence } from "./_lib.js";+// The arcs (forking bolts re-struck every frame, inked with halo, body, core and light), their flicker and the+// zaps that strike the floor in a spray of sparks follow Sprite Fusion's open-source lightning and energy orb+// (https://www.spritefusion.com/pixel-art-vfx/lightning), MIT License, Copyright (c) 2026 Hugo Duprez.+import { fit, clamp, rng, rand, TAU, WHITE, hex, mix, ease } from "../../core/index.js";+import { VOLT, PLASMA, zigzag, stroke, crackle, flight, spark, puff, scorch } 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,+ desc: "A copper coil under a steel torus throws branching arcs that lash out in volleys and now and then strike the floor in a spray of sparks, lighting the metal and the ground.",+ tags: ["lightning", "electric", "tesla", "machine", "prop", "loop"],+ size: [224, 136],+ origin: [112, 120],+ duration: 2.4,loop: true,fps: 30,bg: "ground",- options: { palette: PAL.electric, arcs: 3, seed: 11 },+ options: {+ palette: VOLT,+ sparks: PLASMA,+ copper: ["#2a120c", "#5a2814", "#8e4a1e", "#c4772f", "#eaa65a", "#ffd9a0"],+ steel: ["#0f121c", "#1f2433", "#353d52", "#556078", "#7f8ba3", "#b8c3d6", "#f2f6ff"],+ seed: 4,+ },};-const COPPER = ramp(["#2e140c", "#5c2a14", "#91481f", "#c4733a", "#eaa76a"]);-const STEEL = ramp(["#17161e", "#2f2d3a", "#4e4b5c", "#7b788c", "#b2afc2", "#e2e0ec"]);-const TOP = -52, RATE = 15;+const FPS = 30, N = 72, P = N / FPS, TY = -57, RR = 12, TR = 3.6, SY = 0.45, CTOP = -50, CBOT = -12;+const IRON = ["#120f18", "#1e1a27", "#2c2637", "#3f374d", "#5a5068"].map(hex), ASH = hex("#5b5566");+// an arc's brightness over the frames it lives: struck, flickered, re-struck, gone+const FL = [1, 0.7, 0.95, 0.55, 0.85, 0.45, 0.7, 0.35];-export function draw(p, t, o) {- const C = steps(o.palette, 7), S = o.seed, beat = Math.floor(t * RATE), sub = t * RATE - beat;+// the loop's events, frame by frame: volleys of arcs off the torus, and two zaps to the floor+function plan(seed) {+ const r = rng(seed, 1), arcs = [], strikes = [];+ for (const [v, n] of [[2, 3], [20, 3], [30, 1], [38, 3], [56, 3], [66, 1]])+ for (let j = 0; j < n + r.int(0, 1); j++) {+ const side = r.chance(0.5) ? 1 : -1, front = r.chance(0.55), a = r.range(0.15, 1.1);+ const phi = side > 0 ? (front ? a : -a) : front ? Math.PI - a : Math.PI + a, th0 = r.range(-1.15, 0.35);+ arcs.push({ f0: (v + j * r.int(2, 4)) % N, len: r.int(3, 7), side, phi, front, th0, th1: th0 + r.range(-0.6, 0.6), L: r.range(24, 52) });+ }+ for (const [f0, side] of [[14, 1], [47, -1]]) strikes.push({ f0, side, x: side * r.range(38, 56), phi: side > 0 ? 0.4 : Math.PI - 0.4 });+ return { arcs, strikes };+}+const ageOf = (f, f0) => (((f - f0) % N) + N) % N;+const root = (phi, up = 0) => [Math.cos(phi) * (RR + TR * 0.6), TY + Math.sin(phi) * RR * SY - up];- // 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 coil: an iron plinth, two thick primary turns, the secondary wound in copper wire, catching arc light+function drawCoil(p, Cu, lit, C) {+ const n = Cu.length;+ p.shade(-14, -8, 14, 0, (x, y, o) => {+ if (x < -13 || x > 13 || y < -7) return;+ const edge = x < -12 ? 2 : x > 12 ? 0 : 1;+ o.c = y < -6 ? IRON[4] : y < -5 ? IRON[3] : y > -1 ? IRON[0] : IRON[edge + 1 > 2 ? 2 : edge + (y < -3 ? 1 : 0)];+ });+ for (const rx of [-10, 10]) (p.px(rx, -4, IRON[4]), p.px(rx, -3, IRON[0]));+ const turn = (y, front) => {+ for (let a = 0; a < TAU; a += 0.04) {+ if (Math.sin(a) >= 0 !== front) continue;+ const x = Math.cos(a) * 10, yy = y + Math.sin(a) * 2.2, l = 0.5 - 0.4 * Math.cos(a) + (front ? 0.25 : -0.2);+ p.px(x, yy, Cu[clamp(Math.round(l * (n - 1)), 0, n - 1)]);+ p.px(x, yy + 1, Cu[clamp(Math.round(l * (n - 1)) - 2, 0, n - 1)]);}- // 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)));+ };+ turn(-10.5, false);+ turn(-13.5, false);+ // the secondary: wire on every other row, lit from the left, a bright band down the front, arc light on the rims+ p.shade(-6, CTOP, 6, CBOT, (x, y, o) => {+ if (x < -5 || x > 5) return;+ const u = (x + 5.5) / 11, nx = u * 2 - 1, wire = (Math.floor(y) & 1) === 0;+ let l = 0.62 - 0.55 * nx - 0.35 * nx * nx + (Math.abs(nx + 0.35) < 0.12 ? 0.3 : 0);+ if (!wire) l -= 0.32;+ o.c = Cu[clamp(Math.round(l * (n - 1)), 0, n - 1)];+ if (wire && ((nx < -0.75 && lit[0] > 0.25) || (nx > 0.75 && lit[1] > 0.25))) o.c = nx < 0 ? (lit[0] > 0.6 ? C[6] : C[4]) : lit[1] > 0.6 ? C[6] : C[4];});- p.line(-8, TOP - 3, -3, TOP - 4, STEEL[5]);+ p.line(-5, CTOP - 1, 5, CTOP - 1, IRON[3]);+ p.line(-4, CTOP - 2, 4, CTOP - 2, IRON[2]);+ turn(-10.5, true);+ turn(-13.5, true);+}++// the torus, solved once: for every pixel, the normal of the nearest point of a ring tube seen from a little above+let TORUS = null;+function torusMap() {+ if (TORUS) return TORUS;+ const sa = SY, ca = Math.sqrt(1 - SY * SY), X0 = -Math.ceil(RR + TR) - 1, Y0 = Math.floor(TY - RR * SY - TR) - 2;+ const W = 2 * -X0 + 2, H = Math.ceil(TY + RR * SY + TR) + 3 - Y0, z = new Float32Array(W * H).fill(-1e9), n = new Float32Array(W * H * 3);+ for (let i = 0; i < 480; i++) {+ const phi = (i / 480) * TAU, cp = Math.cos(phi), sp = Math.sin(phi);+ for (let j = 0; j < 96; j++) {+ const psi = (j / 96) * TAU, cs = Math.cos(psi), ss = Math.sin(psi), rr = RR + TR * cs, X = rr * cp, Y = TR * ss, Z = rr * sp;+ const px = Math.floor(X) - X0, py = Math.floor(TY - Y * ca + Z * sa) - Y0, d = Z * ca + Y * sa;+ if (px < 0 || py < 0 || px >= W || py >= H) continue;+ const k = py * W + px;+ if (d > z[k]) (z[k] = d), (n[k * 3] = cs * cp), (n[k * 3 + 1] = ss), (n[k * 3 + 2] = cs * sp);+ }+ }+ return (TORUS = { X0, Y0, W, H, z, n, ca, sa });+}+const norm = (x, y, z) => { const l = Math.hypot(x, y, z); return [x / l, y / l, z / l]; };+const KEY = norm(-0.55, 0.75, 0.45);- // 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);+// steel shaded by a key light from the upper left, a hard specular, dark inner faces, the arcs' light on the sides+function drawTorus(p, St, C, lit) {+ const T = torusMap(), m = St.length, HALF = norm(KEY[0], KEY[1] + T.sa, KEY[2] + T.ca);+ const on = (x, y) => x >= 0 && y >= 0 && x < T.W && y < T.H && T.z[y * T.W + x] > -1e8;+ for (let y = 0; y < T.H; y++)+ for (let x = 0; x < T.W; x++) {+ const k = y * T.W + x;+ if (T.z[k] < -1e8) continue;+ const nx = T.n[k * 3], ny = T.n[k * 3 + 1], nz = T.n[k * 3 + 2];+ const dif = Math.max(0, nx * KEY[0] + ny * KEY[1] + nz * KEY[2]), spec = Math.pow(Math.max(0, nx * HALF[0] + ny * HALF[1] + nz * HALF[2]), 28);+ const inner = nx * (x + T.X0 + 0.5) + nz * 0 < 0 && Math.abs(x + T.X0 + 0.5) < RR ? 0.75 : 1;+ let c = spec > 0.55 ? St[m - 1] : St[clamp(Math.floor((0.12 + 0.8 * dif * inner + spec) * (m - 1.01)), 0, m - 2)];+ for (const [s, l] of [[-1, lit[0]], [1, lit[1]]]) {+ const r = Math.max(0, s * nx * 0.85 + ny * 0.25 + nz * 0.45) * Math.min(1, l);+ if (r > 0.88) c = C[6];+ else if (r > 0.62) c = mix(c, C[5], 0.6);+ else if (r > 0.38) c = mix(c, C[4], 0.3);+ }+ if (!on(x, y + 1) && ny < 0.3) c = St[0];+ p.px(x + T.X0, y + T.Y0, c);}- 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);+}++export function draw(p, t, o) {+ const C = fit(o.palette, 8), Cu = fit(o.copper, 6), St = fit(o.steel, 7), S = o.sparks.map(hex), f = Math.floor(t * FPS + 1e-6) % N;+ const { arcs, strikes } = plan(o.seed), lit = [0, 0];+ const live = arcs.filter((a) => ageOf(f, a.f0) < a.len);+ for (const a of live) lit[a.side > 0 ? 1 : 0] += FL[ageOf(f, a.f0)] * 0.6;+ for (const s of strikes) {+ const a = ageOf(f, s.f0);+ if (a < 6) lit[s.side > 0 ? 1 : 0] += 1;+ }+ const act = Math.min(1, (lit[0] + lit[1]) * 0.5);++ // the floor: a cold pool of light under the coil, scorches and smoke where zaps landed+ p.glow(0, -10, 58, C[3], 0.14 + 0.25 * act);+ p.ellipse(0, 0.5, 15, 1.6, IRON[0]);+ for (const s of strikes) {+ const age = (((t - s.f0 / FPS) % P) + P) % P;+ scorch(p, s.x, 0, 7, Math.pow(clamp(1 - age / 1.1), 1.3), 1 - clamp((age - 1.4) / 0.6));+ for (let j = 0; j < 2; j++) {+ const u = (age - 0.12 - j * 0.18) / 1.2;+ if (u > 0 && u < 1) puff(p, s.x + (j ? 3 : -2) + u * 5 * s.side, -3 - u * 16 - j * 2, 2.6 + j, u, mix(ASH, C[2], 0.3));+ }+ }++ const drawArc = (a) => {+ const age = ageOf(f, a.f0), u = age / Math.max(1, a.len - 1), th = a.th0 + (a.th1 - a.th0) * ease.outQuad(u), ang = a.side > 0 ? th : Math.PI - th;+ const [x0, y0] = root(a.phi), L = a.L * (age === 0 ? 0.75 : 1), r = rng(o.seed, 21, a.f0, f);+ stroke(p, zigzag(r, x0, y0, x0 + Math.cos(ang) * L, y0 + Math.sin(ang) * L, 0.32, 0.75), FL[age], C, 0.6, { light: 0.4 });+ p.glow(x0, y0, 10, C[5], 0.5 * FL[age]);+ };+ // arcs off the back of the torus go behind the coil+ for (const a of live) if (!a.front) drawArc(a);+ drawCoil(p, Cu, lit, C);+ drawTorus(p, St, C, lit);+ // corona: a faint violet fuzz crawling over the torus+ const rc = rng(o.seed, 9, f);+ for (let i = 0; i < 6; i++) {+ const phi = rc.range(0, TAU), d = rc.range(1, 3), x = Math.cos(phi) * (RR + TR + d), y = TY + Math.sin(phi) * (RR * SY + TR + d * 0.7);+ p.px(x, y, rc.chance(0.3) ? C[5] : C[3]);+ if (rc.chance(0.4)) p.px(x + Math.cos(phi), y + Math.sin(phi) * 0.6, C[2]);+ p.glow(x, y, 4, C[3], 0.3);+ }+ // brush discharge: short streamers hiss off the rim every frame+ for (let i = 0; i < 2; i++) {+ const phi = rc.range(0, TAU), x0 = Math.cos(phi) * (RR + TR * 0.8), y0 = TY + Math.sin(phi) * (RR * SY + TR * 0.6), a = Math.atan2(Math.sin(phi) * 0.6 - 0.5, Math.cos(phi)) + rc.range(-0.5, 0.5), l = rc.range(4, 10);+ crackle(p, zigzag(rc, x0, y0, x0 + Math.cos(a) * l, y0 + Math.sin(a) * l, 0.4, 0.4), rc.range(0.35, 0.65), C, 0.3);+ }+ p.glow(0, TY, 34, C[3], 0.18 + 0.3 * act);+ for (const a of live) if (a.front) drawArc(a);++ // zaps to the floor: a full bolt, a flash where it lands, sparks thrown and bouncing+ for (const s of strikes) {+ const age = ageOf(f, s.f0);+ if (age < 6) {+ const k = [1, 0.75, 1, 0.6, 0.85, 0.4][age], [x0, y0] = root(s.phi, -2), r = rng(o.seed, 41, s.f0, f);+ stroke(p, zigzag(r, x0, y0, s.x, 0, 0.22, 0.55), k, C, age === 0 ? 0.95 : 0.8, { hero: age === 0 });+ p.circle(s.x, -1, 3 * k + 1.5, C[2]);+ p.circle(s.x, -1, 3 * k + 0.5, C[5]);+ p.circle(s.x, -1, 2 * k, WHITE);+ p.glow(s.x, -10, 40, C[4], 0.55 * k);+ p.glow(s.x, -3, 12, C[6], 0.5 * k);+ if (age < 2) p.glow(0, -50, 120, C[3], 0.25 * k);+ }+ const st = (((t - s.f0 / FPS) % P) + P) % P;+ for (let j = 0; j < 18; j++) {+ const r = rng(o.seed, 51, s.f0, j), life = r.range(0.3, 0.65);+ if (st >= life) continue;+ const a = -Math.PI / 2 + r.range(-1.3, 1.3), sp = r.range(50, 190), [x, y, vx, vy] = flight(s.x, -1, Math.cos(a) * sp, Math.sin(a) * sp, st, { floor: 0 });+ spark(p, x, y, vx, vy, 1 - st / life, S);+ }+ }+ // sparks spat off the arc tips as they strike+ for (const a of arcs) {+ const age = (((t - a.f0 / FPS) % P) + P) % P, ang = a.side > 0 ? a.th0 : Math.PI - a.th0, [x0, y0] = root(a.phi);+ for (let j = 0; j < 3; j++) {+ const r = rng(o.seed, 61, a.f0, j), life = r.range(0.15, 0.35);+ if (age >= life) continue;+ const tx = x0 + Math.cos(ang) * a.L * 0.75, ty = y0 + Math.sin(ang) * a.L * 0.75, b = ang + r.range(-0.9, 0.9), sp = r.range(50, 150);+ const [x, y, vx, vy] = flight(tx, ty, Math.cos(b) * sp, Math.sin(b) * sp, age, { floor: 0 });+ spark(p, x, y, vx, vy, 1 - age / life, S);}}- // 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.jsindex 60a6d97..1f6d9ad 100644--- a/src/fx/lightning/thunderclap.js+++ b/src/fx/lightning/thunderclap.js@@ -1,72 +1,127 @@-import { burst, fly, flyV, seg, ease, rand, TAU, WHITE } from "../../core/index.js";-import { steps, zap, glowPath, jagged } from "./_lib.js";+// The flash and flare, the bolts and their flicker, the plasma spray, the scorch where bolts land and the dust+// thrown along the floor follow Sprite Fusion's open-source lightning and explosion+// (https://www.spritefusion.com/pixel-art-vfx/lightning), MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Lights, P, PF, Rng, fit, band, flare, sparkle, clamp, smooth, ease, rng, TAU, WHITE, hex, mix } from "../../core/index.js";+import { VOLT, PLASMA, zigzag, stroke, crackle, scorch } 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,+ desc: "A thunderclap round the caster: a white flash, forked bolts burst out and stab the floor, a heavy shock ring tears across the ground raising dust and grit, sparks streak away.",+ tags: ["lightning", "electric", "nova", "aoe", "spell", "shockwave", "one-shot"],+ size: [288, 156],+ origin: [144, 124],+ duration: 1.9,loop: false,fps: 30,- bg: "dark",- options: { palette: ["#0e1430", "#1f2f66", "#3b58a8", "#6a8ee0", "#a6c4f6", "#dfeaff", "#ffffff"], radius: 40, seed: 16 },+ bg: "ground",+ actor: 2,+ options: { palette: VOLT, sparks: PLASMA, reach: 104, seed: 6 },};-export function draw(p, t, o) {- const C = steps(o.palette, 7), S = o.seed, RAD = o.radius, beat = Math.floor(t * 20);+const CLAP = 0.12, CY = -22, BK = [1, 0.7, 0.95, 0.5, 0.8, 0.3];+const DUST = hex("#6e6382"), STONE = ["#655b7a", "#4a4263", "#342d45"].map(hex), ASH = hex("#5b5566");- // 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));+export function create(o) {+ const C = fit(o.palette, 8), R = new Rng(o.seed), REACH = o.reach, floor = () => 0;+ const ps = new Particles({ rng: R, ground: floor, sparks: o.sparks }), hot = new Particles({ rng: R, ground: floor }), lights = new Lights();+ // eight bolts: the lower ones stab the floor, the upper ones tear into the air+ const bolts = Array.from({ length: 8 }, (_, i) => {+ const down = i % 2 === 0, side = i % 4 < 2 ? -1 : 1, a = down ? (side > 0 ? R.range(0.35, 0.75) : Math.PI - R.range(0.35, 0.75)) : side > 0 ? -R.range(0.15, 1.2) : Math.PI + R.range(0.15, 1.2);+ const L = down ? -CY / Math.sin(a) : R.range(40, 62), x1 = Math.cos(a) * L, y1 = down ? 0 : CY + Math.sin(a) * L;+ return { down, x1, y1, t0: CLAP + R.range(0, 0.06) };});-- // 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);+ const front = (t) => (t < CLAP ? 0 : 8 + (REACH - 8) * ease.outCubic(clamp((t - CLAP) / 0.5)));+ let t = 0, clapped = false;+ const landed = bolts.map(() => false);+ return {+ update(dt) {+ t += dt;+ // the breath before: sparks rush in to the caster's chest+ if (t < CLAP && R.chance(60 * dt)) {+ const a = R.range(0, TAU), d = R.range(16, 30), T = R.range(0.07, 0.1), v = (d * 3) / (Math.exp(3 * T) - 1);+ ps.spawn(P.STREAK, Math.cos(a) * d, CY + Math.sin(a) * d * 0.8, -Math.cos(a) * v, -Math.sin(a) * v * 0.8, T, R.chance(0.5) ? C[6] : C[5]);+ }+ if (t >= CLAP && !clapped) {+ clapped = true;+ lights.add(0, CY - 10, 100, C[4], 0.65, 0.45);+ lights.add(0, CY, 26, WHITE, 0.5, 0.07);+ for (let i = 0; i < 64; i++) {+ const a = R.range(0, TAU), sp = R.range(170, 380) * (Math.sin(a) > 0.4 ? 0.5 : 1);+ ps.spawn(P.SPARK, Math.cos(a) * 6, CY + Math.sin(a) * 6, Math.cos(a) * sp, Math.sin(a) * sp - 40, R.range(0.2, 0.55));+ }+ for (let i = 0; i < 8; i++) ps.spawn(P.SMOKE, R.range(-8, 8), CY + R.range(-6, 6), R.range(-25, 25), -R.range(10, 30), R.range(0.8, 1.3), mix(ASH, C[4], 0.3), R.range(4, 7), R.range(0.05, 0.2));+ }+ for (const [i, b] of bolts.entries())+ if (b.down && !landed[i] && t >= b.t0) {+ landed[i] = true;+ lights.add(b.x1, -4, 46, C[4], 0.7, 0.25);+ for (let j = 0; j < 12; j++) {+ const a = -Math.PI / 2 + R.range(-1.2, 1.2), sp = R.range(70, 240);+ ps.spawn(P.SPARK, b.x1, -1, Math.cos(a) * sp, Math.sin(a) * sp, R.range(0.2, 0.5));+ }+ for (let j = 0; j < 5; j++) hot.spawn(P.SPARK, b.x1 + R.range(-2, 2), -1, R.range(-80, 80), -R.range(60, 180), R.range(0.4, 0.8));+ }+ // the ring tears the floor up as it passes: dust rolling out, grit tossed+ const fr = front(t);+ if (t > CLAP && t < CLAP + 0.5)+ for (const s of [-1, 1]) {+ if (R.chance(70 * dt)) ps.spawn(P.SMOKE, s * fr + R.range(-3, 3), -R.range(1, 4), s * R.range(10, 40), -R.range(5, 20), R.range(0.6, 1.1), DUST, R.range(3, 6) * (1 - 0.4 * (fr / REACH)), 0, PF.BIG);+ if (R.chance(50 * dt)) ps.spawn(P.GRIT, s * fr, -1, s * R.range(10, 60), -R.range(60, 180), R.range(0.8, 1.3), R.pick(STONE), R.chance(0.3) ? 2 : 1);+ }+ ps.update(dt);+ hot.update(dt);+ lights.update(dt);+ },+ drawBack(p) {+ // scorch where the bolts struck, and the far half of the shock ring+ for (const b of bolts) if (b.down && t >= b.t0) scorch(p, b.x1, 0, 9, Math.pow(clamp(1 - (t - b.t0) / 1.1), 1.3), 1 - smooth(1.4, 1.85, t));+ const u = (t - CLAP) / 0.5;+ if (u > 0 && u < 1) band(p, 0, 0.5, front(t), 0.18, Math.max(2, 16 * (1 - u)), 1.25 - u, [C[1], C[2], C[4], C[6]], (g) => Math.sin(g) < 0, u < 0.15);+ ps.draw(p, "back");+ hot.draw(p, "back");+ },+ draw(p) {+ const f = Math.floor(t * 30 + 1e-4), u = (t - CLAP) / 0.5, A = o.actor;+ // the flash: the caster lit white for a frame, a flare, a core+ const a = t - CLAP;+ if (a >= 0 && a < 0.07) p.mask(A.mask, A.x, A.y, a < 0.035 ? WHITE : C[6]);+ if (a >= 0 && a < 0.2) {+ const q = a / 0.2;+ flare(p, 0, CY, 44 * Math.pow(1 - q, 1.4), 1 - q, C);+ if (q < 0.35) p.circle(0, CY, 10 * (1 - q * 2) + 2, WHITE);+ p.glow(0, CY, 44, C[5], 0.32 * (1 - q));+ }+ // the bolts: struck, flickering, re-struck every other frame+ for (const [i, b] of bolts.entries()) {+ const ba = Math.floor((t - b.t0) * 30 + 1e-4);+ if (t < b.t0 || ba >= BK.length) continue;+ const r = rng(o.seed, 3, i, ba >> 1);+ stroke(p, zigzag(r, 0, CY, b.x1, b.y1, 0.25, b.down ? 0.5 : 0.8), BK[ba], C, ba === 0 ? 1 : 0.8, { hero: ba === 0 });+ if (b.down) {+ p.circle(b.x1, -1, 3 * BK[ba] + 1, C[5]);+ p.px(b.x1, -1, WHITE);+ p.glow(b.x1, -3, 20, C[5], 0.5 * BK[ba]);+ } else if (ba < 2) sparkle(p, b.x1, b.y1, 4, C[6], C[4], 0.4);+ }+ // the shock: the near half of the floor ring, and a ring in the air that bursts out from the clap+ if (u > 0 && u < 1) {+ band(p, 0, 0.5, front(t), 0.18, Math.max(2, 16 * (1 - u)), 1.25 - u, [C[1], C[2], C[4], C[6]], (g) => Math.sin(g) >= 0, u < 0.15);+ for (const s of [-1, 1]) p.glow(s * front(t), -3, 28, C[4], 0.45 * (1 - u));+ const ua = (t - CLAP) / 0.26;+ const ra = 8 + 60 * ease.outCubic(ua);+ if (ua < 1) p.ring(0, CY, ra, Math.max(1, 2 * (1 - ua)), ua < 0.25 ? C[5] : ua < 0.6 ? C[4] : C[3], (v, g) => (CY + Math.sin(g) * ra > -1 ? 0 : 0.85 - 0.85 * ua));+ }+ // the hum after: small arcs crackle round the caster as the charge bleeds away+ if (a > 0.2 && a < 0.9) {+ const r = rng(o.seed, 9, f), k = 1 - (a - 0.2) / 0.7;+ if (r.next() < 0.8) {+ const x0 = r.range(-14, 14), y0 = r.range(-34, -4), b = r.range(0, TAU), l = r.range(6, 13);+ crackle(p, zigzag(r, x0, y0, x0 + Math.cos(b) * l, y0 + Math.sin(b) * l, 0.4, 0.3), 0.85 * k + 0.1, C, 0.35);+ }+ }+ ps.draw(p, "front");+ hot.draw(p, "front");+ lights.draw(p);+ },+ };}diff --git a/src/fx/lightning/zap-hit.js b/src/fx/lightning/zap-hit.jsindex 2205fb5..cf5a8d0 100644--- a/src/fx/lightning/zap-hit.js+++ b/src/fx/lightning/zap-hit.js@@ -1,64 +1,135 @@-import { PAL, burst, fly, flyV, seg, ease, rng, TAU, WHITE } from "../../core/index.js";-import { steps, zap, glowPath, jagged } from "./_lib.js";+// The arc's halo-body-core inking, its flicker and the light that strobes as it dies follow Sprite Fusion's+// open-source lightning (https://www.spritefusion.com/pixel-art-vfx/lightning), MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Lights, P, Rng, fit, clamp, smooth, rng, TAU, WHITE, hex, mix } from "../../core/index.js";+import { VOLT, zigzag, stroke, crackle } 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,+ desc: "A contact zap: an arc snaps in from the left, the hit point overloads into a knot of tiny crackling zigzags, a fern of burn marks glows outward, sparks jink away, ozone puffs.",+ tags: ["lightning", "electric", "hit", "impact", "combat", "directional", "one-shot"],+ size: [144, 112],+ origin: [76, 56],+ duration: 0.9,loop: false,fps: 30,bg: "dark",- options: { palette: PAL.electric, spikes: 6, seed: 14 },+ options: { palette: VOLT, seed: 3 },};-export function draw(p, t, o) {- const C = steps(o.palette, 7), S = o.seed, beat = Math.floor(t * 20);+const SNAP = 0.05, ASH = hex("#6a6680");- // 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]);+// the burn the current leaves on what it hit: a Lichtenberg fern, main fronds radiating, side fronds alternating+function fern(R) {+ const out = [];+ const grow = (x, y, a, len, w, d, depth) => {+ const pts = [[x, y, d]];+ let side = R.sign();+ for (let s = 0; s < len; s += 1.4) {+ a += R.range(-0.3, 0.3);+ x += Math.cos(a) * 1.4;+ y += Math.sin(a) * 1.4;+ d += 1.4;+ pts.push([x, y, d]);+ if (depth < 2 && s > 2 && R.chance(0.24)) {+ side = -side;+ grow(x, y, a + side * R.range(0.55, 1.05), (len - s) * R.range(0.3, 0.55), w * 0.6, d, depth + 1);+ }}- }+ out.push({ pts, w });+ };+ for (let i = 0; i < 6; i++) grow(0, 0, (i / 6) * TAU + R.range(-0.35, 0.35), R.range(18, 32), 1, 0, 0);+ return out;+}- // 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));+export function create(o) {+ const C = fit(o.palette, 8), R = new Rng(o.seed), ps = new Particles({ rng: R }), lights = new Lights();+ const tree = fern(R), Y0 = R.range(-14, 6);+ // sparks that jink: they fly out and jerk to a new heading every few hundredths of a second+ const kinked = Array.from({ length: 16 }, () => {+ const a = R.range(-1.2, 1.2) + (R.chance(0.7) ? 0 : Math.PI), sp = R.range(130, 250);+ return { x: 0, y: 0, vx: Math.cos(a) * sp, vy: Math.sin(a) * sp - 40, life: R.range(0.2, 0.36), age: -SNAP, next: R.range(0.02, 0.05), trail: [] };});-- // 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);+ let t = 0, hit = false;+ return {+ update(dt) {+ t += dt;+ if (!hit && t >= SNAP) {+ hit = true;+ lights.add(0, 0, 60, C[4], 0.7, 0.3);+ lights.add(0, 0, 14, WHITE, 0.5, 0.07);+ for (let i = 0; i < 3; i++) ps.spawn(P.SMOKE, R.range(-3, 5), R.range(-4, 2), R.range(-5, 8), -R.range(8, 16), R.range(0.55, 0.75), mix(ASH, C[4], 0.3), R.range(2.5, 3.8), R.range(0.08, 0.16));+ }+ for (const s of kinked) {+ if ((s.age += dt) < 0 || s.age >= s.life) continue;+ if ((s.next -= dt) <= 0) {+ s.next = R.range(0.025, 0.055);+ const sp = Math.hypot(s.vx, s.vy), a = Math.atan2(s.vy, s.vx) + R.sign() * R.range(0.6, 1.3);+ s.vx = Math.cos(a) * sp;+ s.vy = Math.sin(a) * sp;+ s.trail.push([s.x, s.y]);+ if (s.trail.length > 4) s.trail.shift();+ }+ s.vx -= s.vx * 3 * dt;+ s.vy -= s.vy * 3 * dt - 140 * dt;+ s.x += s.vx * dt;+ s.y += s.vy * dt;+ }+ ps.update(dt);+ lights.update(dt);+ },+ drawBack(p) {+ // the fern burns outward from the hit, glowing white, cooling through the palette, then fading+ if (t < SNAP) return;+ // it cools by stepping down the palette, and only the last embers dither away+ const cool = smooth(0.45, 0.85, t), fade = 1 - smooth(0.78, 0.88, t);+ for (const br of tree)+ for (let i = 1; i < br.pts.length; i++) {+ const [x0, y0] = br.pts[i - 1], [x, y, d] = br.pts[i], age = t - SNAP - d / 260;+ if (age < 0) break;+ const k = Math.exp(-age / 0.22) - cool * 0.3, c = k > 0.75 ? WHITE : k > 0.45 ? C[6] : k > 0.25 ? C[5] : k > 0.1 ? C[4] : k > -0.05 ? C[2] : C[1];+ p.line(x0, y0, x, y, c, fade);+ if (br.w >= 1 && d < 9) p.line(x0 + 1, y0, x + 1, y, k > 0.45 ? C[5] : C[2], fade);+ if ((i & 3) === 0 && k > 0) p.glow(x, y, 5, C[5], 0.35 * k * fade);+ }+ ps.draw(p, "back");+ },+ draw(p) {+ const f = Math.floor(t * 30 + 1e-4);+ // the arc snaps in from the left in two frames, holds and flickers, then lets go+ if (t < 0.32) {+ const r = rng(o.seed, 2, f), b = zigzag(r, -66, Y0, 0, 0, 0.22, 0.35), u = clamp(t / SNAP);+ const k = t < SNAP ? 1 : t < 0.2 ? (f % 2 ? 0.7 : 1) : 0.55 * (1 - (t - 0.2) / 0.12);+ stroke(p, u < 1 ? { paths: [b.paths[0]] } : b, k, C, t < SNAP + 0.034 ? 0.95 : 0.7, { upTo: u, hero: t >= SNAP && t < SNAP + 0.034 });+ if (u < 1) {+ const tp = b.paths[0].pts, [hx, hy] = tp[Math.floor(u * (tp.length - 1))];+ p.circle(hx, hy, 2, WHITE);+ p.glow(hx, hy, 14, C[5], 0.6);+ }+ }+ // the hit point overloads: a tight knot of tiny zigzags re-struck every frame round a white heart+ if (t >= SNAP && t < 0.45) {+ const a = (t - SNAP) / 0.4, r = rng(o.seed, 5, f), R0 = 8 * (1 - a * 0.6), m = Math.round(11 * (1 - a * 0.5));+ for (let i = 0; i < m; i++) {+ const ang = r.range(0, TAU), d0 = r.range(0.5, R0 * 0.5), ang2 = ang + r.range(-1.2, 1.2), d1 = r.range(R0 * 0.55, R0);+ crackle(p, zigzag(r, Math.cos(ang) * d0, Math.sin(ang) * d0, Math.cos(ang2) * d1, Math.sin(ang2) * d1, 0.5, 0), 0.75 * (1 - a) + 0.25, C, 0.25);+ }+ p.circle(0, 0, 3 * (1 - a) + 1, C[5]);+ p.circle(0, 0, 2 * (1 - a) + 0.5, WHITE);+ p.glow(0, 0, 20, C[4], 0.55 * (1 - a));+ if (t < SNAP + 0.07) p.glow(0, 0, 9, WHITE, 0.4);+ }+ // the sparks: a bright head, the zigzag behind it cooling+ for (const s of kinked) {+ if (s.age < 0 || s.age >= s.life) continue;+ const k = 1 - s.age / s.life, path = [...s.trail, [s.x, s.y]];+ for (let i = 0; i < path.length - 1; i++) p.line(path[i][0], path[i][1], path[i + 1][0], path[i + 1][1], i === path.length - 2 ? (k > 0.5 ? WHITE : C[6]) : k > 0.5 ? C[5] : C[4], 0.6 + 0.4 * (i / path.length));+ p.px(s.x, s.y, k > 0.4 ? WHITE : C[5]);+ p.glow(s.x, s.y, 4, C[5], 0.4 * k);+ }+ // the light strobes as it dies+ if (t >= SNAP) p.glow(0, 0, 40 * Math.max(0, 1 - t / 0.85), C[3], 0.45 * Math.exp(-(t - SNAP) * 5) * (f % 2 ? 0.7 : 1));+ ps.draw(p, "front");+ lights.draw(p);+ },+ };}diff --git a/src/fx/melee/_lib.js b/src/fx/melee/_lib.jsindex 39d6e24..29f9178 100644--- a/src/fx/melee/_lib.js+++ b/src/fx/melee/_lib.js@@ -1,94 +1,210 @@-// Shared bits for the melee category: the crescent smear of a swing, the lens of a straight cut, glints.+// Shared by the melee effects: swings on a tilted circle (the smear, its dotted trace), floor cracks, rocks.+// The crescent and trace recipe is adapted from Sprite Fusion's open-source slash+// (https://www.spritefusion.com/pixel-art-vfx/slash), MIT License, Copyright (c) 2026 Hugo Duprez.// Files starting with _ are helpers, not effects.-import { at, clamp, smooth, noise2, WHITE } from "../../core/index.js";+import { P, clamp, smooth, ease, hex, mix, scale, rgb, WHITE, TAU } 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.+ * A swing: a circle of radius R around (cx, cy), squashed to sy across its plane (1 stands up facing us, 0.16+ * lies on the floor) and turned by rot, swept from angle a0 in direction dir (+1 turns clockwise on screen).+ * k lifts the band into a shallow cone: a point dr inside the rim sits k * dr higher, so a level ring shows its+ * near half broad and its far half thin, like a blade angled down from the hilt (keep k below sy).+ * Positions along it are u, radians from a0 in the swing's direction.*/-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)));+export const swing = (o) => ({ cx: 0, cy: 0, R: 30, sy: 1, rot: 0, a0: 0, dir: 1, k: 0, ...o });++/** A swing on radius R whose arc passes through (x, y) heading along angle th, that point `at` of the way along span. */+export function through(x, y, th, dir, R, span, at = 0.55, extra = {}) {+ const a = th - (dir * Math.PI) / 2;+ return swing({ cx: x - Math.cos(a) * R, cy: y - Math.sin(a) * R, R, sy: 1, rot: 0, a0: a - dir * span * at, dir, span, ...extra });+}++/** The screen point at plane radius r, u radians along the swing. */+export function onSwing(s, r, u) {+ const a = s.a0 + s.dir * u, lx = Math.cos(a) * r, ly = Math.sin(a) * r * s.sy - s.k * (s.R - r), c = Math.cos(s.rot), n = Math.sin(s.rot);+ return [s.cx + lx * c - ly * n, s.cy + lx * n + ly * c];+}++/** The on-screen unit direction the swing travels at u, and the in-plane angle there (sin < 0 is the far half). */+export function travel(s, u) {+ const [x0, y0] = onSwing(s, s.R, u), [x1, y1] = onSwing(s, s.R, u + 0.01), l = Math.hypot(x1 - x0, y1 - y0) || 1;+ return { x: x0, y: y0, dx: (x1 - x0) / l, dy: (y1 - y0) / l, a: s.a0 + s.dir * u };+}++/** The plane radius and angle under a screen point (inverts onSwing, cone included). */+export function plane(s, x, y) {+ const c = Math.cos(s.rot), n = Math.sin(s.rot), dx = x - s.cx, dy = y - s.cy, lx = dx * c + dy * n, ly = -dx * n + dy * c;+ if (!s.k) return [Math.hypot(lx, ly / s.sy), Math.atan2(ly / s.sy, lx)];+ // r sin(a) sy = m - k r, r cos(a) = lx => r^2 (sy^2 - k^2) + 2 m k r - (lx^2 sy^2 + m^2) = 0+ const m = ly + s.k * s.R, A = s.sy * s.sy - s.k * s.k, B = 2 * m * s.k, Cc = lx * lx * s.sy * s.sy + m * m;+ const r = (-B + Math.sqrt(B * B + 4 * A * Cc)) / (2 * A);+ return [r, Math.atan2((m - s.k * r) / s.sy, lx)];}/**- * 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.+ * Shade a swing's band from u0 to u1 (u1 - u0 at most a full turn), plane radius R + pad down to R - wMax - 1.+ * fn(u, r, out, a) shades each pixel: u along the swing, r its plane radius, a the in-plane angle. half: 0 the+ * whole band, -1 only the far half (behind a character), 1 only the near half.*/-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));+export function smear(p, s, u0, u1, wMax, fn, half = 0, pad = 1) {+ if (u1 - u0 < 0.005) return;+ const c = Math.cos(s.rot), n = Math.sin(s.rot), A = s.R + pad + 1, Bn = A * s.sy + s.k * (wMax + 2);+ const hx = Math.hypot(A * c, Bn * n) + 1, hy = Math.hypot(A * n, Bn * c) + 1, rIn = s.R - wMax - 1;+ // each half only needs its side of the centre (plus what the tilt and the cone lift can reach across)+ const over = Math.abs(n) * A + s.k * (wMax + 2) + 2, y0 = half > 0 ? s.cy - over : s.cy - hy, y1 = half < 0 ? s.cy + over : s.cy + hy;+ p.shade(s.cx - hx, y0, s.cx + hx, y1, (x, y, out) => {+ const [r, a] = plane(s, x, y);+ if (r > s.R + pad || r < rIn) return;+ if (half && (Math.sin(a) < 0 ? -1 : 1) !== half) return;+ let u = (s.dir * (a - s.a0)) % TAU;+ if (u < 0) u += TAU;+ while (u < u0) u += TAU;+ if (u > u1) return;+ return fn(u, r, out, a);});}-/** 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);+/** Dots along a swing at plane radius r from u0 to u1, every `step` px, alpha a(u) (dithered into a dotted trace). */+export function trace(p, s, r, u0, u1, c, a, half = 0, step = 0.6) {+ const du = step / Math.max(4, r);+ for (let u = u0; u <= u1; u += du) {+ const g = s.a0 + s.dir * u;+ if (half && (Math.sin(g) < 0 ? -1 : 1) !== half) continue;+ const [x, y] = onSwing(s, r, u), k = typeof a === "function" ? a(u) : a;+ if (k > 0) p.dot(x, y, typeof c === "function" ? c(u) : c, k);+ }+}++/** Glow riding a swing from u0 to u1 (light along the arc). */+export function glowAlong(p, s, r, u0, u1, rad, c, k, half = 0, step = 0.35) {+ for (let u = u0; u <= u1; u += step) {+ const g = s.a0 + s.dir * u;+ if (half && (Math.sin(g) < 0 ? -1 : 1) !== half) continue;+ const [x, y] = onSwing(s, r, u), kk = typeof k === "function" ? k(u) : k;+ if (kk > 0.004) p.glow(x, y, rad, c, kk);}- 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.+ * A slash crescent along swing s (Sprite Fusion's recipe): the edge whips out over s.span radians in s.sweep s,+ * holds, then the tail follows over s.trail, thinning and cooling down s.ramp (dark to bright); a dotted trace+ * lingers where it passed. s: a swing plus { span, W, t0, sweep, hold, trail, ramp, hot (0..1 flashes it white),+ * lens (thickest in the middle, not just behind the edge) }.*/-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);+export function slash(p, s, t, half = 0) {+ const u = t - s.t0;+ if (u < 0) return;+ const R = s.ramp, n = R.length, life = s.sweep + s.hold + s.trail, hot = s.hot ?? 0;+ const head = ease.outExpo(clamp(u / s.sweep)), tail = smooth(s.sweep + s.hold, life, u), age = clamp(u / life);+ const U = s.span * head, T = s.span * tail, W = s.W * (1 - tail * 0.55);+ if (tail < 1 && U - T > 0.01) {+ smear(p, s, T, U, W, (uu, r, out) => {+ const v = (uu - T) / (U - T), w = W * Math.pow(Math.sin(Math.PI * Math.pow(v, s.lens ? 1 : 2.2)), s.lens ? 0.75 : 0.6);+ if (w < 0.35) return;+ const q = (s.R - r) / w;+ if (q < 0 || q > 1) return;+ const ci = (q < 0.22 && age < 0.5) || q < hot * 0.7 ? 0 : Math.round(q * (n - 1) * 0.75 + age * 2.4 - v * 0.8 + 0.4 - hot * 3);+ out.c = R[n - 1 - clamp(ci, 0, n - 1)];+ out.a = Math.min(1, v / (s.lens ? 0.1 : 0.4));+ }, half);+ glowAlong(p, s, s.R - W * 0.4, T, U, 5 + W, R[n - 3], (uu) => (0.22 + hot * 0.3) * (1 - age) * ((uu - T) / (U - T)), half, 0.3);+ }+ const th = 0.7 * (1 - clamp((u - s.sweep - s.hold) / (s.trail + 0.2)));+ if (tail > 0.02 && th > 0) trace(p, s, s.R - 0.5, 0, T, R[2], (uu) => th * (0.4 + 0.6 * uu / s.span), half);+}++/** Where a slash's edge ends up, and which way it's travelling there. */+export const slashEnd = (s) => travel({ ...s, R: s.R - s.W * 0.3 }, s.span);++/** Shavings flung off a slash's edge, outward from its circle (Sprite Fusion's slash). */+export function shavings(ps, R, s, n, colors, from = 0.3) {+ for (let i = 0; i < n; i++) {+ const [x, y] = onSwing(s, s.R, s.span * R.range(from, 1)), ox = x - s.cx, oy = y - s.cy, l = Math.hypot(ox, oy) || 1, sp = R.range(30, 100);+ ps.spawn(P.MOTE, x, y, (ox / l) * sp, Math.min(25, (oy / l) * sp) - 10, R.range(0.25, 0.55), R.pick(colors), 0.6);+ }+}++/** Stone shades for rocks, grit and dust from one body color (as Sprite Fusion's explosion does). */+export function stone(c) {+ c = hex(c);+ return { light: mix(scale(c, 1.35), WHITE, 0.08), body: c, shade: scale(c, 0.64), dust: mix(scale(c, 1.2), rgb(150, 140, 150), 0.3), dark: scale(c, 0.42) };+}++const OUTLINE = hex("#1a1422");+/** A tumbling rock (a Bits CHUNK): a lit side, a shaded side, an outline, fading at the end of its life. */+export function rock(p, b, st) {+ const r = 0.6 + b.s * 0.75, fade = Math.min(1, b.life / 0.5), lx = Math.cos(b.a) * r * 0.4, ly = Math.sin(b.a) * r * 0.4;+ p.shade(b.x - r - 1, b.y - r - 1, b.x + r + 1, b.y + r + 1, (x, y, out) => {+ const dx = x - b.x, dy = y - b.y, d = Math.hypot(dx * 1.15, dy);+ if (d > r + 0.9) return;+ const lit = dx * lx + dy * ly;+ out.c = d > r ? OUTLINE : lit < -0.4 ? st.light : lit > 0.6 ? st.shade : st.body;+ out.a = fade;+ });}/**- * 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).+ * Jagged cracks splitting the floor from x0: each runs out along the floor's edge and zig-zags down into its+ * face (y from 0 to about depth), with short forks. n cracks alternate sides (bias > 0 sends more forward).+ * Returns [{ pts, at (0..1 how far out it starts), fork }]. Built once from an Rng.*/-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);+export function cracks(R, x0, n, reach, depth = 7, bias = 0.3) {+ const out = [];+ for (let i = 0; i < n; i++) {+ const side = R.chance(0.5 + bias * 0.5) ? 1 : -1, L = reach * R.range(0.45, 1) * (i < 2 ? 1 : 0.7), pts = [[x0 + side * R.range(0, 1.5), 0]];+ let x = pts[0][0], y = 0;+ while (Math.abs(x - x0) < L && y < depth) {+ x += side * R.range(1.5, 3.5);+ y = Math.min(depth, Math.max(0, y + R.range(-0.6, 1.6) * (Math.abs(x - x0) > 3 ? 1 : 0.3)));+ pts.push([Math.round(x), Math.round(y)]);+ if (R.chance(0.18) && pts.length > 3 && y < depth - 2) {+ const f = [[Math.round(x), Math.round(y)]];+ let fx = x, fy = y;+ for (let j = R.int(1, 3); j > 0; j--) (fx += side * R.range(1, 3)), (fy += R.range(0.8, 2)), f.push([Math.round(fx), Math.round(Math.min(depth + 1, fy))]);+ out.push({ pts: f, at: Math.abs(x - x0) / reach, fork: true });+ }+ }+ out.push({ pts, at: 0, fork: false });}- 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);+ return out;+}++/**+ * An impact star (after Sprite Fusion's impact): tapered spikes [{ a, len, w }] around (x, y), drawn in three+ * passes (rim, body, core) with a hot disc in the middle. sc stretches, th thins.+ */+export function star(p, x, y, spikes, sc, th, core, body, inner, rim) {+ for (const pass of [0, 1, 2])+ for (const s of spikes) {+ const c = Math.cos(s.a), sn = Math.sin(s.a), L = s.len * sc;+ for (let d = 0; d <= L; d += 0.5) {+ const hw0 = s.w * th * (1 - d / L) * Math.min(1, 0.5 + d / 3), hw = pass === 0 ? hw0 + 0.8 : pass === 1 ? hw0 : hw0 * 0.45;+ if (pass === 2 && d > L * 0.55) break;+ for (let o = -hw; o <= hw; o += 0.5) p.px(x + c * d - sn * o, y + sn * d + c * o, pass === 0 ? rim : pass === 1 ? (d < L * 0.35 ? inner : body) : core);+ }}- 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);- });+ const r = 2.4 * sc * Math.sqrt(th);+ p.circle(x, y, r + 0.8, inner);+ p.circle(x, y, r, core);+}++/** A thin arc flying out from (x, y): a sliver at radius r around angle a, arc radians long, dithered by k. */+export function sliver(p, x, y, a, r, arc, c, k) {+ const n = Math.ceil(r * arc * 2.2);+ for (let j = 0; j <= n; j++) {+ const u = j / n - 0.5, th = a + u * arc, w = 1.4 * (1 - Math.abs(u) * 2);+ for (let o = -w * 0.5; o <= w * 0.5 + 0.01; o += 0.5) p.dot(x + Math.cos(th) * (r + o), y + Math.sin(th) * (r + o), c, k);+ }}++/** Part of a polyline: the first `len` px of it. Calls fn(x0, y0, x1, y1, d) for each piece (d: distance along). */+export function along(pts, len, fn) {+ let d = 0;+ for (let i = 1; i < pts.length && d < len; i++) {+ const [x0, y0] = pts[i - 1], [x1, y1] = pts[i], l = Math.hypot(x1 - x0, y1 - y0), f = Math.min(1, (len - d) / l);+ fn(x0, y0, x0 + (x1 - x0) * f, y0 + (y1 - y0) * f, d);+ d += l;+ }+}+diff --git a/src/fx/melee/axe-chop.js b/src/fx/melee/axe-chop.jsdeleted file mode 100644index 32dd17d..0000000--- a/src/fx/melee/axe-chop.js+++ /dev/null@@ -1,66 +0,0 @@-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.jsindex cde212a..587052c 100644--- a/src/fx/melee/claw-swipe.js+++ b/src/fx/melee/claw-swipe.js@@ -1,55 +1,95 @@-import { PAL, ramp, burst, fly, seg, ease, clamp, WHITE } from "../../core/index.js";-import { cut } from "./_lib.js";+// The shaded smear, its light and the dotted trace follow Sprite Fusion's open-source slash+// (https://www.spritefusion.com/pixel-art-vfx/slash), MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Bits, Lights, P, B, Rng, fit, sparkle, clamp, smooth, ease } from "../../core/index.js";+import { through, onSwing, travel, smear, trace, glowAlong } 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,+ desc: "Three claw marks rake down one after another, white-hot, cooling through orange to red, then close up from both ends and leave a dotted scar, with hot flecks and drips.",+ tags: ["melee", "claw", "swipe", "beast", "scratch", "combat", "directional", "one-shot"],+ size: [128, 96],+ origin: [36, 84],+ duration: 0.9,loop: false,fps: 30,bg: "ground",- actor: true,- options: { palette: PAL.blood, count: 3, seed: 7 },+ actor: 2,+ options: {+ palette: ["#2a0808", "#5c0f12", "#a51d1d", "#e2401f", "#ff8a2a", "#ffd166", "#fff3c4", "#ffffff"],+ sparks: ["#fff3c4", "#ffd166", "#ff8a2a", "#c42a1a"],+ seed: 8,+ },};-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]);+const RAKE = 0.05; // each mark tears open+const STAGGER = 0.04;+const CLOSE0 = 0.16, CLOSE = 0.3; // then closes up from both ends++export function create(o) {+ const C = fit(o.palette, 8), n = C.length, Rg = new Rng(o.seed), floor = () => 0;+ const ps = new Particles({ rng: Rg, ground: floor, sparks: o.sparks }), drips = new Bits({ ground: floor }), lights = new Lights();+ // three marks raking down and back, each a little lower and further out than the last+ const marks = [0, 1, 2].map((i) => {+ const s = through(31 + i * 8, -23 + i * 2, 1.84, 1, 40, 0.84 - i * 0.05, 0.5);+ return { s, t0: i * STAGGER, W: 4.2 - i * 0.4, open: false, end: travel(s, s.span) };});- p.glow(20, -13, 22, C[top - 2], 0.35 * (1 - seg(t, 0.05, 0.3)) * seg(t, -0.02, 0.03));+ let t = 0;+ const heatAt = (m) => clamp(1 - (t - m.t0) / 0.42);+ return {+ update(dt) {+ t += dt;+ for (const m of marks) {+ if (!m.open && t >= m.t0 + RAKE * 0.7) {+ m.open = true;+ lights.add(m.end.x, m.end.y - 6, 34, C[4], 0.45, 0.3);+ // hot flecks thrown on along the rake, and drips running off the wound+ for (let i = 0; i < 7; i++) {+ const a = Math.atan2(m.end.dy, m.end.dx) + Rg.range(-0.5, 0.5), sp = Rg.range(110, 260);+ ps.spawn(P.SPARK, m.end.x, m.end.y, Math.cos(a) * sp, Math.sin(a) * sp, Rg.range(0.12, 0.32));+ }+ for (let i = 0; i < 5; i++) {+ const [x, y] = onSwing(m.s, m.s.R, m.s.span * Rg.range(0.15, 0.9));+ ps.spawn(P.MOTE, x, y, Rg.range(-60, -10), Rg.range(-30, 30), Rg.range(0.2, 0.4), Rg.chance(0.5) ? C[5] : C[4], 0.5);+ }+ for (let i = 0; i < 2; i++) {+ const [x, y] = onSwing(m.s, m.s.R - 1, m.s.span * Rg.range(0.35, 0.75));+ drips.add({ kind: B.DRIP, x, y, vx: Rg.range(-8, 8), vy: Rg.range(10, 40), g: 0.55, life: 1.2, c: C[3] });+ }+ }+ }+ drips.update(dt);+ ps.update(dt);+ lights.update(dt);+ },+ draw(p) {+ for (const m of marks) {+ const u = t - m.t0;+ if (u < 0) continue;+ const S = m.s.span, head = S * ease.outExpo(clamp(u / RAKE)), c = smooth(CLOSE0, CLOSE0 + CLOSE, u), lo = (S / 2) * c, hi = Math.min(head, S - (S / 2) * c);+ const heat = heatAt(m);+ if (hi - lo > 0.02) {+ // a lens: sharp at both ends, thickest in the middle; white-hot at the core, cooling outward and with time+ smear(p, m.s, lo, hi, m.W, (uu, r, out) => {+ const v = uu / S, w = m.W * Math.pow(Math.sin(Math.PI * v), 1.15) * (1 - 0.55 * c), off = Math.abs(r - (m.s.R - m.W / 2)) / (w / 2 + 0.01);+ if (w < 0.5 || off > 1) return;+ const ci = Math.round((1 - heat) * 5.2 + off * 1.6 + (head < S ? (S - uu) / S : 0) * 0.5);+ out.c = C[n - 1 - clamp(ci, 0, n - 2)];+ }, 0, 2);+ glowAlong(p, m.s, m.s.R - m.W / 2, lo, hi, 11, C[4], 0.42 * heat * heat, 0, 0.2);+ }+ // where it has closed, a dotted red scar lingers and fades+ const k = 0.8 * (1 - clamp((u - CLOSE0 - CLOSE * 0.5) / 0.4));+ if (c > 0.05 && k > 0) {+ trace(p, m.s, m.s.R - m.W / 2, 0.04 * S, lo, C[2], k);+ trace(p, m.s, m.s.R - m.W / 2, S - lo, 0.96 * S, C[2], k);+ }+ // the claw tip glints as it tears in+ const g = u - RAKE * 0.4;+ if (g > 0 && g < 0.16) sparkle(p, m.end.x, m.end.y, 5 * ease.outBack(Math.min(1, g / 0.04)) * (1 - g / 0.16), C[6], C[4], 0.4);+ }+ drips.draw(p);+ ps.draw(p);+ lights.draw(p);+ },+ };}diff --git a/src/fx/melee/counter-flash.js b/src/fx/melee/counter-flash.jsdeleted file mode 100644index e7fad15..0000000--- a/src/fx/melee/counter-flash.js+++ /dev/null@@ -1,68 +0,0 @@-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.jsindex b2289b6..3710ffe 100644--- a/src/fx/melee/dagger-flurry.js+++ b/src/fx/melee/dagger-flurry.js@@ -1,50 +1,79 @@-import { ramp, burst, rng, fly, seg, ease, clamp, WHITE } from "../../core/index.js";-import { swing } from "./_lib.js";+// The crescent, trace, glint and spark recipe is adapted from Sprite Fusion's open-source slash+// (https://www.spritefusion.com/pixel-art-vfx/slash), MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Lights, P, Rng, fit, sparkle, clamp, ease, WHITE } from "../../core/index.js";+import { swing, slash, slashEnd, shavings, sliver } 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,+ desc: "A flurry of small quick crescents at every angle in front of the fighter, each with a flick of sparks, finished by one big cut that glints and bursts.",+ tags: ["melee", "slash", "dagger", "combo", "flurry", "fast", "combat", "directional", "one-shot"],+ size: [148, 104],+ origin: [36, 86],+ duration: 0.95,loop: false,fps: 30,bg: "ground",- actor: true,- options: { palette: ["#140a26", "#2b1252", "#4a2390", "#7440cc", "#a070f0", "#cfa8ff", "#f0e0ff", "#ffffff"], count: 10, seed: 8 },+ actor: 2,+ options: {+ palette: ["#1b1630", "#3a2f63", "#6150a3", "#9480d8", "#c7b8f5", "#efe9ff", "#ffffff"],+ sparks: ["#ffffff", "#efe9ff", "#c7b8f5", "#9480d8"],+ seed: 12,+ },};-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));- });+const EVERY = 0.055;+// small cuts: where, how they're turned, which way they go+const CUTS = [+ [21, -27, -0.5, 1], [33, -16, 0.9, -1], [26, -38, 2.4, 1], [37, -30, -1.8, -1], [19, -17, 0.2, 1], [30, -24, 1.4, -1],+];++export function create(o) {+ const C = fit(o.palette, 7), Rg = new Rng(o.seed), ps = new Particles({ rng: Rg, ground: () => 0, sparks: o.sparks }), lights = new Lights();+ const small = CUTS.map(([x, y, rot, dir], i) => swing({ cx: x, cy: y, R: Rg.range(12, 15), sy: Rg.range(0.55, 0.75), rot, a0: Rg.range(-2.8, -2.2), dir, span: Rg.range(2.3, 2.8), W: Rg.range(5.2, 6.4), t0: i * EVERY, sweep: 0.035, hold: 0.03, trail: 0.13, ramp: C }));+ // the finisher: one wide flat cut right across the front, left to right+ const big = swing({ cx: 24, cy: -26, R: 30, sy: 0.36, k: 0.24, rot: 0.12, a0: 3.0, dir: -1, span: 2.85, W: 11, t0: small.length * EVERY + 0.04, sweep: 0.055, hold: 0.06, trail: 0.24, ramp: C });+ const all = [...small, big], ends = all.map(slashEnd), done = all.map(() => false);+ const slivers = [-2.6, -1.5, -0.4, 0.7].map((a) => ({ a: a + Rg.range(-0.2, 0.2), r: Rg.range(4, 7), v: Rg.range(70, 110), arc: Rg.range(0.4, 0.7) }));+ let t = 0;+ return {+ update(dt) {+ t += dt;+ all.forEach((s, i) => {+ if (done[i] || t < s.t0 + s.sweep) return;+ done[i] = true;+ const e = ends[i], last = s === big;+ lights.add(e.x, e.y, last ? 56 : 26, C[3], last ? 0.6 : 0.4, last ? 0.4 : 0.14);+ if (last) lights.add(e.x, e.y, 16, WHITE, 0.7, 0.08);+ for (let k = 0; k < (last ? 12 : 3); k++) {+ const a = Math.atan2(e.dy, e.dx) + Rg.range(-0.5, 0.5), sp = Rg.range(100, last ? 340 : 220);+ ps.spawn(P.SPARK, e.x, e.y, Math.cos(a) * sp, Math.sin(a) * sp, Rg.range(0.1, last ? 0.35 : 0.22));+ }+ shavings(ps, Rg, s, last ? 14 : 4, [C[4], C[5]]);+ if (last) for (let k = 0; k < 5; k++) ps.spawn(P.STAR, s.cx + Rg.range(-22, 22), s.cy + Rg.range(-14, 14), 0, -4, Rg.range(0.2, 0.45), Rg.chance(0.5) ? C[5] : WHITE, Rg.range(1, 2.2), Rg.range(0.05, 0.25));+ });+ ps.update(dt);+ lights.update(dt);+ },+ draw(p) {+ for (const s of all) slash(p, s, t);+ all.forEach((s, i) => {+ const e = ends[i], g = t - s.t0 - s.sweep * 0.6, last = s === big, life = last ? 0.24 : 0.12;+ if (g > 0 && g < life) sparkle(p, e.x, e.y, (last ? 10 : 4) * ease.outBack(Math.min(1, g / 0.04)) * (1 - g / life), C[5], C[3], last ? 0.6 : 0.35);+ // light rides each edge while it's moving+ const u = t - s.t0;+ if (u > 0 && u < s.sweep + 0.1) {+ const h = slashEnd({ ...s, span: s.span * ease.outExpo(clamp(u / s.sweep)) });+ p.glow(h.x, h.y, last ? 40 : 22, C[3], (last ? 0.5 : 0.35) * (1 - u / (s.sweep + 0.1)));+ }+ });+ // the finisher throws slivers off its end+ const q = t - big.t0 - big.sweep;+ if (q > 0.02 && q < 0.14) {+ const k = (q - 0.02) / 0.12, e = ends[ends.length - 1];+ for (const s of slivers) sliver(p, e.x, e.y, s.a + Math.atan2(e.dy, e.dx), s.r + s.v * (q - 0.02), s.arc * (1 - 0.4 * k), k < 0.4 ? C[6] : k < 0.7 ? C[5] : C[4], 1 - k);+ }+ ps.draw(p);+ lights.draw(p);+ },+ };}diff --git a/src/fx/melee/double-slash.js b/src/fx/melee/double-slash.jsindex 79d88c3..5a1b239 100644--- a/src/fx/melee/double-slash.js+++ b/src/fx/melee/double-slash.js@@ -1,82 +1,98 @@-import { PAL, ramp, burst, fly, seg, ease, clamp, WHITE } from "../../core/index.js";-import { cut, glint } from "./_lib.js";+// The crescent, trace, glint and spark recipe is adapted from Sprite Fusion's open-source slash+// (https://www.spritefusion.com/pixel-art-vfx/slash), MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Lights, P, Rng, fit, sparkle, flare, clamp, ease, WHITE } from "../../core/index.js";+import { through, slash, slashEnd, shavings, sliver } 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,+ desc: "A down cut, then an up cut that crosses it: the moment the X closes both strokes flash white, the crossing bursts with light and sparks, and a dotted X lingers.",+ tags: ["melee", "slash", "combo", "sword", "cross", "combat", "directional", "one-shot"],+ size: [164, 108],+ origin: [44, 92],+ duration: 0.8,loop: false,fps: 30,bg: "ground",- actor: true,- options: { palette: PAL.neon, size: 1, seed: 3 },+ actor: 2,+ options: {+ palette: ["#2a0a22", "#5e1238", "#a01f4e", "#e0386a", "#ff86a6", "#ffd2dd", "#ffffff"],+ sparks: ["#fff3a6", "#ffe26b", "#ff8a2a", "#f2561d"],+ seed: 6,+ },};-// 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];-};+const UP = 0.14; // the second cut starts+const R0 = 62;++const cut = (x, y, th, dir, span, extra) => through(x, y, th, dir, R0, span, 0.55, extra);-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;+export function create(o) {+ const C = fit(o.palette, 7), Rg = new Rng(o.seed), ps = new Particles({ rng: Rg, ground: () => 0, sparks: o.sparks }), lights = new Lights();+ const X = 34, Y = -23;+ const down = cut(X, Y, 0.72, 1, 0.84, { W: 10, t0: 0, sweep: 0.06, hold: 0.07, trail: 0.24, ramp: C, lens: true });+ const up = cut(X, Y, -0.66, -1, 0.84, { W: 11, t0: UP, sweep: 0.06, hold: 0.06, trail: 0.26, ramp: C, lens: true });+ const ends = [slashEnd(down), slashEnd(up)], slivers = [-2.4, -1.1, 0.2, 1.6].map((a) => ({ a: a + Rg.range(-0.2, 0.2), r: Rg.range(5, 8), v: Rg.range(70, 120), arc: Rg.range(0.4, 0.7) }));+ const CLOSE = UP + 0.012;+ let t = 0, cut1 = false, cut2 = false, closed = false;+ return {+ update(dt) {+ t += dt;+ if (!cut1 && t >= down.sweep) {+ cut1 = true;+ shavings(ps, Rg, down, 10, [C[4], C[5]]);+ for (let i = 0; i < 6; i++) {+ const a = Math.atan2(ends[0].dy, ends[0].dx) + Rg.range(-0.5, 0.5), sp = Rg.range(120, 300);+ ps.spawn(P.SPARK, ends[0].x, ends[0].y, Math.cos(a) * sp, Math.sin(a) * sp, Rg.range(0.12, 0.3));+ }+ }+ if (!closed && t >= CLOSE) {+ closed = true;+ lights.add(X, Y, 56, C[3], 0.45, 0.4);+ lights.add(X, Y, 18, WHITE, 0.6, 0.08);+ for (let i = 0; i < 18; i++) {+ const a = Rg.range(-Math.PI, Math.PI) * 0.8, sp = Rg.range(140, 360);+ ps.spawn(P.SPARK, X, Y, Math.cos(a) * sp, Math.sin(a) * sp - 40, Rg.range(0.14, 0.4));+ }+ for (let i = 0; i < 5; i++) ps.spawn(P.STAR, X + Rg.range(-14, 14), Y + Rg.range(-12, 12), 0, -4, Rg.range(0.2, 0.4), Rg.chance(0.5) ? C[5] : WHITE, Rg.range(1, 2.2), Rg.range(0.05, 0.2));+ }+ if (!cut2 && t >= UP + up.sweep) {+ cut2 = true;+ shavings(ps, Rg, up, 12, [C[4], C[5]]);+ }+ ps.update(dt);+ lights.update(dt);+ },+ draw(p) {+ // both strokes flash white for two frames when the X closes+ const flash = t >= CLOSE && t < CLOSE + 0.07 ? 1 : 0;+ down.hot = up.hot = flash;+ slash(p, down, t);+ slash(p, up, t);+ // glints at the ends of the strokes+ for (const [s, e] of [[down, ends[0]], [up, ends[1]]]) {+ const g = t - s.t0 - s.sweep * 0.6;+ if (g > 0 && g < 0.2) sparkle(p, e.x, e.y, 7 * ease.outBack(Math.min(1, g / 0.05)) * (1 - g / 0.2), C[5], C[3], 0.5);+ }+ // the crossing: a flare, slivers flying off it, light+ const q = t - CLOSE;+ if (q >= 0 && q < 0.26) {+ const k = q / 0.26;+ flare(p, X, Y, 22 * Math.pow(1 - k, 1.4), 1 - k, C);+ p.glow(X, Y, 34, C[4], 0.35 * (1 - k));+ }+ if (q >= 0.03 && q < 0.15) {+ const k = (q - 0.03) / 0.12;+ for (const s of slivers) sliver(p, X, Y, s.a, s.r + s.v * (q - 0.03), s.arc * (1 - 0.4 * k), k < 0.4 ? C[6] : k < 0.7 ? C[5] : C[4], 1 - k);+ }+ // light rides each edge as it goes+ for (const s of [down, up]) {+ const u = t - s.t0;+ if (u <= 0 || u >= 0.25) continue;+ const e = slashEnd({ ...s, span: s.span * ease.outExpo(clamp(u / s.sweep)) });+ p.glow(e.x, e.y, 40, C[3], 0.5 * (1 - u / 0.25));}- 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)));- }+ ps.draw(p);+ lights.draw(p);+ },+ };}diff --git a/src/fx/melee/hammer-smash.js b/src/fx/melee/hammer-smash.jsindex 9169d6b..355e33f 100644--- a/src/fx/melee/hammer-smash.js+++ b/src/fx/melee/hammer-smash.js@@ -1,90 +1,210 @@-import { PAL, ramp, fit, at, burst, fly, seg, ease, clamp, WHITE } from "../../core/index.js";-import { dustCloud } from "./_lib.js";+// The rocks, grit, rolling dust and floor ring are adapted from Sprite Fusion's open-source explosion, and the+// dome from his ice nova (https://www.spritefusion.com/pixel-art-vfx), MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Bits, Lights, P, PF, B, Rng, fit, band, clamp, smooth, ease, rand, hex, TAU, WHITE } from "../../core/index.js";+import { swing, onSwing, smear, stone, rock, cracks, along } 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,+ desc: "A hammer drops in front in a wedge of motion: a white slam with rays, a dome of force, a dent with cracks, rocks thrown up that bounce and settle, and dust.",+ tags: ["melee", "smash", "hammer", "heavy", "ground", "shockwave", "debris", "combat", "directional", "one-shot"],+ size: [208, 112],+ origin: [80, 92],+ duration: 2.0,loop: false,fps: 30,bg: "ground",- actor: true,- options: { palette: PAL.volt, debris: PAL.stone, reach: 17, seed: 15 },+ actor: 2,+ options: {+ palette: ["#141834", "#242c5c", "#38479a", "#5a72d0", "#8fa8f0", "#c4d4ff", "#eef3ff", "#ffffff"],+ stone: "#4a3f69",+ seed: 9,+ },};-const DUST = ramp(["#2e2830", "#463e48", "#655b63", "#8a7f84", "#b0a5a6", "#d6cdc8"]);+const SOOT = hex("#0d0a12"), HOT = ["#fff3a6", "#ffc23d", "#ff8a2a", "#c9281f"].map(hex);+const DROP = 0.15; // the hammer comes over and down, gathering speed+const head = (t) => {+ const x = clamp((t + 0.03) / (DROP + 0.03));+ return 0.28 * x + 0.72 * x * x;+};-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,+export function create(o) {+ const C = fit(o.palette, 8), n = C.length, R = new Rng(o.seed), st = stone(o.stone), floor = () => 0;+ const ps = new Particles({ rng: R, ground: floor }), bits = new Bits({ ground: floor }), chips = new Bits({ ground: floor }), lights = new Lights();+ // the hammer head's path: round the shoulders, from overhead down to the floor in front+ const A = swing({ cx: 5, cy: -25, R: 32, sy: 1, rot: 0, a0: -2.25, dir: 1 });+ let U1 = 0;+ while (onSwing(A, A.R, U1)[1] < -0.5 && U1 < 4) U1 += 0.005;+ const HW = 13, [X] = onSwing(A, A.R - HW / 2, U1);+ const lines = cracks(R, X, 5, 24, 6, 0);+ const rays = [-0.95, -0.6, -0.3, -0.05, 0.22, 0.5, 0.85].map((d, i) => ({ a: -Math.PI / 2 + d + R.range(-0.06, 0.06), L: (i === 3 ? 34 : i === 2 || i === 4 ? 26 : i === 1 || i === 5 ? 18 : 12) * R.range(0.9, 1.1) }));+ let t = 0, hit = false;++ // the smear: the hammer head's path as a comet, a hard white leading face, tapering to a hair behind it,+ // cooling along the taper (edges first), with speed lines trailing along the arc+ const Rm = A.R - HW / 2;+ const wedge = (p) => {+ const h = head(t), U = U1 * h, after = smooth(DROP, DROP + 0.07, t), lagU = Math.max(0, U - (0.3 + 1.05 * h)), T = lagU + (U - lagU) * after * 0.8;+ if (U - T < 0.03 || after >= 1) return;+ const len = (U - T) * Rm;+ smear(p, A, T, U, HW + 1, (u, r, out) => {+ const lead = (U - u) * Rm, f = lead / len, w = HW * (lead < 3 ? 1 : Math.pow(1 - (lead - 3) / Math.max(1, len - 3), 0.85)) * (1 - after * 0.5);+ const off = (r - Rm) / (w / 2 + 0.01);+ if (w < 0.6 || Math.abs(off) > 1) return;+ let ci = lead < 2 ? 0 : Math.round(1 + f * 3.4 + Math.abs(off) * 1.4 - (off > 0.55 ? 1 : 0) + after * 3);+ if (ci > n - 3) return;+ out.c = C[n - 1 - Math.max(0, ci)];});- });- 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]);- });+ // speed lines trail the head along the arc, dotted out at their ends+ if (after < 0.6)+ for (const [dr, l0, L] of [[-HW / 2 - 2, 3, 26], [-HW / 2 - 5, 9, 16], [HW / 2 + 2, 2, 30], [HW / 2 + 5, 8, 18], [-1, len + 2, 14], [3, len + 4, 9]]) {+ const r = Rm + dr;+ for (let d = l0; d < l0 + L * (1 - after); d += 0.5) {+ const u = U - d / r, k = (d - l0) / L;+ if (u < 0) break;+ p.dot(...onSwing(A, r, u), k < 0.25 ? C[6] : k < 0.6 ? C[5] : C[4], (1 - k) * (1 - after));+ }+ }+ const [hx, hy] = onSwing(A, Rm, U);+ p.glow(hx, hy, 34, C[4], 0.5 * (1 - smooth(DROP - 0.03, DROP, t)));+ };++ return {+ update(dt) {+ t += dt;+ if (!hit && t >= DROP) {+ hit = true;+ lights.add(X, -5, 16, WHITE, 0.35, 0.08);+ lights.add(X, -10, 64, C[4], 0.42, 0.6);+ // rocks thrown up out of the dent: they tumble, land, bounce and settle+ for (let i = 0; i < 15; i++) {+ const s = R.sign();+ bits.add({ kind: B.CHUNK, x: X + s * R.range(0, 5), y: -2, vx: s * R.range(20, 105), vy: -R.range(110, 300), g: 1, drag: 0.35, bounce: 0.38, life: R.range(1.25, 1.65), a: R.range(0, TAU), va: R.range(-16, 16), s: R.pick([1, 1, 2, 2, 3]) });+ }+ // hot chips struck off the stone: they bounce, settle and cool through the ramp+ for (let i = 0; i < 11; i++) {+ const a = -Math.PI / 2 + R.range(-1.2, 1.2), sp = R.range(90, 230);+ chips.add({ kind: B.SHARD, x: X + R.range(-4, 4), y: -2, vx: Math.cos(a) * sp, vy: Math.sin(a) * sp, g: 0.9, drag: 0.5, bounce: 0.35, life: R.range(0.9, 1.5), s: 1 });+ }+ for (let i = 0; i < 40; i++) {+ const a = -Math.PI / 2 + R.range(-1.1, 1.1), sp = R.range(50, 210);+ ps.spawn(P.GRIT, X + R.range(-4, 4), -1, Math.cos(a) * sp, Math.sin(a) * sp, R.range(0.9, 1.5), R.pick([st.light, st.body, st.body, st.shade]), R.chance(0.4) ? 2 : 1);+ }+ // force motes skid out along the floor, sparks off the stone+ for (let i = 0; i < 14; i++) {+ const s = i % 2 ? -1 : 1, sp = R.range(120, 260);+ ps.spawn(P.MOTE, X + s * 6, -R.range(1, 4), s * sp, -R.range(0, 30), R.range(0.18, 0.34), R.chance(0.5) ? C[6] : C[5], 0.8, R.range(0.02, 0.05));+ }+ for (let i = 0; i < 24; i++) {+ const a = -Math.PI / 2 + R.range(-1.4, 1.4), sp = R.range(150, 380);+ ps.spawn(P.SPARK, X + Math.cos(a) * 6, -2 + Math.sin(a) * 4, Math.cos(a) * sp, Math.sin(a) * sp - 30, R.range(0.12, 0.42), 0, 1, R.range(0.035, 0.08));+ }+ // dust rolls out both ways along the floor, and a puff lifts off the dent+ for (let i = 0; i < 20; i++) {+ const s = i % 2 ? -1 : 1;+ ps.spawn(P.SMOKE, X + s * R.range(2, 10), -R.range(2, 7), s * R.range(40, 125), -R.range(2, 14), R.range(0.95, 1.5), st.dust, R.range(6, 9), R.range(0.02, 0.08), PF.BIG);+ }+ for (let i = 0; i < 7; i++) ps.spawn(P.SMOKE, X + R.range(-6, 6), -R.range(3, 9), R.range(-20, 20), -R.range(30, 80), R.range(1.0, 1.4), st.dust, R.range(5, 7.5), R.range(0.04, 0.14), PF.BIG);+ for (let i = 0; i < 8; i++) ps.spawn(P.DUST, X + R.range(-6, 6), -R.range(1, 4), R.range(-70, 70), -R.range(8, 30), R.range(0.35, 0.7), st.dust, R.range(2, 3.5));+ }+ bits.update(dt);+ chips.update(dt);+ // settled rocks catch the light now and then+ if (hit && t > DROP + 0.4 && t < DROP + 1.2 && R.chance(0.08)) {+ const b = R.pick(bits.list);+ if (b && b.rest) ps.spawn(P.STAR, b.x + R.range(-1, 1), b.y - 1.5 - b.s, 0, -2, R.range(0.25, 0.45), R.chance(0.5) ? HOT[0] : WHITE, R.range(0.6, 1.6));+ }+ // rocks that land kick up a little dust+ for (const b of bits.list)+ if (b.rest && !b.dusted) {+ b.dusted = true;+ for (let i = 0; i < 3; i++) ps.spawn(P.DUST, b.x + R.range(-1.5, 1.5), -0.5, R.sign() * R.range(8, 35), -R.range(2, 14), R.range(0.3, 0.6), st.dust, R.range(1.3, 2.6));+ }+ ps.update(dt);+ lights.update(dt);+ },+ drawBack(p) {+ const q = t - DROP;+ if (q >= 0) {+ // the dent: the floor's top knocked down into a shallow pit, its surface lit at the bottom, chipped lips+ const fade = 1 - smooth(1.3, 1.7, q);+ for (let x = -11; x <= 11; x++) {+ const u = x / 10, d = Math.abs(x) > 10 ? 0 : Math.round(3.2 * (1 - u * u) + (rand(x, 4) - 0.5) * 0.8);+ for (let y = 0; y < d; y++) p.dot(X + x, y, y === 0 ? SOOT : st.dark, fade);+ if (d > 0) p.dot(X + x, d, Math.abs(x) < 7 ? st.light : st.body, fade);+ if (Math.abs(x) >= 8) p.dot(X + x, -1, Math.abs(x) >= 10 ? st.body : st.light, fade);+ if (Math.abs(x) === 9 && rand(x, 7) < 0.7) p.dot(X + x, -2, st.body, fade);+ }+ // the floor ring's far half+ const k = q / 0.5;+ if (k < 1) band(p, X, 0.5, 6 + 50 * ease.outCubic(k), 0.16, Math.max(1, 2 * (1 - k)), 1.15 - k, [st.body, C[3], C[5], C[7]], (g) => Math.sin(g) < 0);+ }+ ps.draw(p, "back");+ },+ draw(p) {+ const q = t - DROP;+ wedge(p);+ if (q >= 0) {+ // cracks split out of the dent: a white flash, then dark lines that fade with the dent+ const fade = 1 - smooth(1.3, 1.7, q);+ for (const c of lines) {+ const reach = 30 * ease.outCubic(clamp((q - c.at * 0.06) / 0.08)) * (c.fork ? 0.3 : 1);+ if (reach > 0)+ along(c.pts, reach, (x0, y0, x1, y1) => {+ if (q >= 0.12) p.line(x0, y0 + 3, x1, y1 + 3, st.shade, fade);+ p.line(x0, y0 + 2, x1, y1 + 2, q < 0.05 ? WHITE : q < 0.12 ? C[5] : SOOT, fade);+ });+ }+ // the near half of the floor ring+ const k = q / 0.5;+ if (k < 1) band(p, X, 0.5, 6 + 50 * ease.outCubic(k), 0.16, Math.max(1, 2 * (1 - k)), 1.15 - k, [st.body, C[3], C[5], C[7]], (g) => Math.sin(g) >= 0);+ // the dome of force swells off the floor, thins to dots and fades+ const d = (q - 0.045) / 0.4;+ if (d >= 0 && d < 1) {+ // solid steps through the shell (white rim, two blues inside); it dissolves as a whole at the end+ const r = 12 + 30 * ease.outCubic(d), th = Math.max(1, 3.6 * Math.pow(1 - d, 0.8)), a = d < 0.6 ? 1 : (1 - d) / 0.4;+ p.shade(X - r - 1, -r - 1, X + r + 1, 0, (x, y, out) => {+ const e = r - Math.hypot(x - X, y);+ if (e < 0 || e > th || y > -0.5) return;+ const v = e / th;+ out.c = d < 0.1 ? (v < 0.6 ? WHITE : C[6]) : v < 0.34 ? (d < 0.45 ? WHITE : C[6]) : v < 0.67 ? C[5] : C[4];+ out.a = a;+ });+ for (let i = 0; i < 7; i++) {+ const g = -Math.PI * (0.08 + (i / 6) * 0.84);+ p.glow(X + Math.cos(g) * r, Math.sin(g) * r, 14, C[4], 0.36 * (1 - d));+ }+ }+ // rays of light shoot up out of the slam+ if (q < 0.2)+ for (const ry of rays) {+ const d1 = ry.L * ease.outCubic(Math.min(1, q / 0.05)), d0 = ry.L * smooth(0.04, 0.2, q), ca = Math.cos(ry.a), sa = Math.sin(ry.a);+ if (d1 - d0 < 1) continue;+ p.line(X + ca * (2 + d0), -1 + sa * (2 + d0), X + ca * d1, -1 + sa * d1, (u) => (u < 0.5 ? WHITE : u < 0.8 ? C[6] : C[5]));+ p.glowLine(X + ca * d0, -1 + sa * d0, X + ca * d1, -1 + sa * d1, 4, C[5], 0.18 * (1 - q / 0.2));+ }+ // the white slam: a flat flash on the floor for two frames+ if (q < 0.07) {+ const hot = q < 0.035, rx = hot ? 16 : 12, ry = hot ? 3 : 2;+ p.ellipse(X, 0, rx + 2, ry + 1, hot ? C[6] : C[5]);+ p.ellipse(X, 0, rx, ry, hot ? WHITE : C[7]);+ }+ if (q < 0.2) {+ const pop = Math.exp(-q / 0.05);+ p.glow(X, -5, 26, C[5], 0.3 * pop);+ }+ // the struck stone stays warm for a moment+ p.glow(X, -1, 16, HOT[2], 0.28 * Math.exp(-q / 0.35));+ }+ for (const b of bits.list) rock(p, b, st);+ for (const b of chips.list) {+ const k = b.life / b.max, c = k > 0.7 ? HOT[0] : k > 0.45 ? HOT[1] : k > 0.25 ? HOT[2] : HOT[3];+ p.dot(b.x, b.y, c, Math.min(1, k * 4));+ if (!b.rest) p.dot(b.x - b.vx * 0.012, b.y - b.vy * 0.012, HOT[3], Math.min(1, k * 4));+ p.glow(b.x, b.y, 4, c, 0.35 * k);+ }+ ps.draw(p, "front");+ lights.draw(p);+ },+ };}diff --git a/src/fx/melee/heavy-cleave.js b/src/fx/melee/heavy-cleave.jsindex e83cedc..9ecd07b 100644--- a/src/fx/melee/heavy-cleave.js+++ b/src/fx/melee/heavy-cleave.js@@ -1,94 +1,188 @@-import { PAL, ramp, at, rand, burst, fly, seg, ease, clamp, WHITE } from "../../core/index.js";-import { swing, glint, dustCloud } from "./_lib.js";+// The crescent and its cooling ramp are adapted from Sprite Fusion's open-source slash+// (https://www.spritefusion.com/pixel-art-vfx/slash), and the impact star, dust, grit and embers from his+// impact and explosion (https://www.spritefusion.com/pixel-art-vfx), MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Bits, Lights, P, PF, B, Rng, fit, sparkle, band, clamp, smooth, ease, rand, TAU, WHITE } from "../../core/index.js";+import { swing, onSwing, smear, trace, glowAlong, stone, rock, cracks, star, sliver, along } 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,+ desc: "A glint over the head, then a thick ember arc accelerates over the top into the floor: a white slam, glowing cracks, dust rolling both ways, grit and rising embers.",+ tags: ["melee", "slash", "cleave", "axe", "heavy", "ground", "fire", "combat", "directional", "one-shot"],+ size: [208, 116],+ origin: [68, 96],+ duration: 1.9,loop: false,fps: 30,bg: "ground",- actor: true,- options: { palette: PAL.ember, radius: 27, seed: 6 },+ actor: 2,+ options: {+ palette: ["#2a0c10", "#5c1414", "#a3241a", "#e0481c", "#ff8a2a", "#ffc23d", "#fff0a0", "#ffffff"],+ stone: "#4a3f69",+ seed: 5,+ },};-const DUST = ramp(["#2e2830", "#463e48", "#655b63", "#8a7f84", "#b0a5a6", "#d6cdc8"]);-const CRACK = ramp(["#0c0a10", "#5a5262"]);+const RAISE = 0.2; // the glint over the head+const SWING = 0.135; // the arc accelerates over the top+const HIT = RAISE + SWING;+const HOLD = 0.05, TRAIL = 0.22;+const head = (t) => ease.inQuad(clamp((t - RAISE) / SWING)); // fraction of the arc the edge has made+const passedAt = (f) => RAISE + SWING * Math.sqrt(clamp(f)); // when the edge passed fraction f-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),+export function create(o) {+ const C = fit(o.palette, 8), n = C.length, R = new Rng(o.seed), st = stone(o.stone), floor = () => 0;+ const ps = new Particles({ rng: R, ground: floor, sparks: [C[6], C[5], C[4], C[3]] }), bits = new Bits({ ground: floor }), lights = new Lights();+ // the arc: from behind the head, over the top, down into the floor in front+ const A = swing({ cx: 3, cy: -22, R: 37, sy: 0.88, rot: 0.32, a0: -2.45, dir: 1 });+ let U1 = 0;+ while (onSwing(A, A.R, U1)[1] < -0.5 && U1 < 4) U1 += 0.005;+ const E = { ...A, R: A.R * 0.76 }, W = 16, WE = 5;+ const [X] = onSwing(A, A.R - 2, U1), GLINT = onSwing(A, A.R - 3, 0);+ const lines = cracks(R, X, 4, 40, 7, 0.4);+ // the impact star: long spikes along the floor, shorter ones up+ const spikes = [-Math.PI, -2.7, -2.15, -1.62, -1.05, -0.45, 0].map((a, i) => ({ a: a + R.range(-0.08, 0.08), len: (i === 0 || i === 6 ? 20 : i === 3 ? 15 : 9) + R.range(0, 4), w: 1.6 + R.range(0, 0.6) }));+ const shards = [-2.5, -1.9, -1.2, -0.6].map((a) => ({ a: a + R.range(-0.15, 0.15), r: 8 + R.range(0, 3), v: R.range(80, 130), arc: R.range(0.35, 0.6) }));+ let t = 0, hit = false;++ const arc = (p, s, w0, lag, rim) => {+ const tt = t - lag, U = U1 * head(tt), T = U1 * smooth(HIT + HOLD, HIT + HOLD + TRAIL, tt);+ if (U < 0.02 || T >= U - 0.02) return;+ const gone = smooth(HIT + HOLD, HIT + HOLD + TRAIL, tt), shrink = 1 - 0.75 * gone;+ smear(p, s, T, U, w0, (u, r, out) => {+ const age = Math.max(0, tt - passedAt(u / U1)), v = (u - T) / (U - T);+ const w = w0 * shrink * Math.pow(Math.sin(Math.PI * Math.pow(v, 2.2)), 0.6);+ if (w < 0.4) return;+ const q = (s.R - r) / w;+ if (q < 0 || q > 1) return;+ const ci = rim && q < 0.22 && age < 0.12 ? 0 : Math.round(q * (n - 1) * 0.62 + age * 7 + Math.max(0, tt - HIT) * 10 - v * 0.8 + (rim ? 0.7 : 1.7));+ out.c = C[n - 1 - clamp(ci, 0, n - 1)];+ out.a = Math.min(1, v / 0.35) * (1.2 - gone);});- });- 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));- });+ if (rim) glowAlong(p, s, s.R - w0 * 0.4, T, U, 7 + w0 * 0.5, C[4], (u) => 0.26 * Math.exp(-Math.max(0, tt - passedAt(u / U1)) / 0.2) * ((u - T) / (U - T)));+ };++ return {+ update(dt) {+ t += dt;+ // heat gathers to the raised blade+ if (t < RAISE - 0.04 && R.chance(0.35)) {+ const a = R.range(0, TAU), D = R.range(14, 26), T = R.range(0.14, 0.2), v = (D * 3) / (Math.exp(3 * T) - 1);+ ps.spawn(P.STREAK, GLINT[0] + Math.cos(a) * D, GLINT[1] + Math.sin(a) * D, -Math.cos(a) * v, -Math.sin(a) * v, T, R.chance(0.5) ? C[5] : C[4]);+ }+ // embers shed off the edge as it comes over+ if (t > RAISE && t < HIT && R.chance(0.7)) {+ const u = U1 * head(t) * R.range(0.6, 1), [x, y] = onSwing(A, A.R - R.range(0, 6), u);+ ps.spawn(P.EMBER, x, y, R.range(-20, 20), R.range(-40, -10), R.range(0.5, 1.1), C[4], R.range(1, 2));+ }+ if (!hit && t >= HIT) {+ hit = true;+ lights.add(X, -6, 26, WHITE, 0.9, 0.1);+ lights.add(X, -12, 64, C[4], 0.5, 0.8);+ // sparks fan up off the floor, most of them forward+ for (let i = 0; i < 26; i++) {+ const a = -Math.PI / 2 + R.range(-1.2, 1.35), sp = R.range(140, 360);+ ps.spawn(P.SPARK, X, -1, Math.cos(a) * sp, Math.sin(a) * sp - 40, R.range(0.15, 0.5));+ }+ // dust rolls out both ways along the floor+ for (let i = 0; i < 20; i++) {+ const s = i % 2 ? -1 : 1;+ ps.spawn(P.SMOKE, X + s * R.range(0, 8), -R.range(2, 6), s * R.range(45, 135), -R.range(2, 12), R.range(1.0, 1.45), st.dust, R.range(5, 8.5), R.range(0, 0.07), PF.BIG);+ }+ for (let i = 0; i < 4; i++) ps.spawn(P.SMOKE, X + R.range(-4, 4), -R.range(3, 8), R.range(-15, 15), -R.range(40, 90), R.range(1.0, 1.45), st.dust, R.range(4, 6.5), R.range(0.02, 0.1), PF.BIG);+ for (let i = 0; i < 8; i++) ps.spawn(P.DUST, X + R.range(-4, 4), -R.range(1, 4), R.range(-60, 60), -R.range(8, 30), R.range(0.35, 0.7), st.dust, R.range(2, 3.5));+ // grit and a few stones thrown up, forward+ for (let i = 0; i < 44; i++) {+ const a = -Math.PI / 2 + R.range(-0.7, 1.0), sp = R.range(60, 230);+ ps.spawn(P.GRIT, X + R.range(-3, 3), -1, Math.cos(a) * sp, Math.sin(a) * sp, R.range(1.0, 1.5), R.pick([st.light, st.body, st.body, st.shade]), R.chance(0.35) ? 2 : 1);+ }+ for (let i = 0; i < 6; i++)+ bits.add({ kind: B.CHUNK, x: X + R.range(-3, 3), y: -2, vx: R.range(-50, 110), vy: -R.range(120, 260), g: 1, drag: 0.4, bounce: 0.3, life: R.range(1.15, 1.5), a: R.range(0, TAU), va: R.range(-14, 14), s: R.int(1, 2) });+ // embers lift off the cut+ for (let i = 0; i < 16; i++) ps.spawn(P.EMBER, X + R.range(-8, 8), -R.range(1, 6), R.range(-50, 60), -R.range(30, 110), R.range(0.7, 1.5), C[4], R.range(1, 2));+ }+ // the cracks breathe embers while they're hot+ if (hit && t < HIT + 0.6 && R.chance(0.12)) {+ const c = R.pick(lines), pt = R.pick(c.pts);+ ps.spawn(P.EMBER, pt[0], pt[1] - 1, R.range(-12, 12), -R.range(20, 50), R.range(0.5, 0.9), C[4], 1);+ }+ bits.update(dt);+ for (const b of bits.list)+ if (b.rest && !b.dusted) {+ b.dusted = true;+ for (let i = 0; i < 2; i++) ps.spawn(P.DUST, b.x + R.range(-1.5, 1.5), -0.5, R.sign() * R.range(8, 30), -R.range(2, 12), R.range(0.3, 0.6), st.dust, R.range(1.3, 2.4));+ }+ ps.update(dt);+ lights.update(dt);+ },+ drawBack(p) {+ const q = t - HIT;+ if (q >= 0) {+ // the floor under the blade: white hot, cooling through the ramp to soot+ const fade = 1 - smooth(1.0, 1.5, q);+ for (let y = 0; y <= 2; y++)+ for (let x = -9; x <= 9; x++) {+ const d = Math.hypot((x + 0.5) / 9, (y + 0.5) / 3.5);+ if (d > 1) continue;+ const T = Math.pow(clamp(1 - q / 0.8), 1.4) * (1.2 - d) - rand(x, y, 3) * 0.3;+ if (T > 0.08) p.dot(X + x, y, C[clamp(Math.round(T * 9), 1, 7)], fade);+ else p.dot(X + x, y, d < 0.5 ? st.dark : st.shade, (d < 0.9 - rand(x, y, 9) * 0.3 ? 1 : 1 - d) * fade);+ }+ // the shock runs out along the floor: the far half behind the fighter+ const k = q / 0.45;+ if (k < 1) band(p, X, 0.5, 6 + 46 * ease.outCubic(k), 0.16, Math.max(1, 3 * (1 - k)), 1.15 - k, [st.body, st.light, C[4], C[6]], (g) => Math.sin(g) < 0);+ }+ ps.draw(p, "back");+ },+ draw(p) {+ const q = t - HIT;+ // the glint over the head: the raised blade catching the light+ if (t < RAISE + 0.03) {+ const g = ease.outBack(clamp(t / 0.1)) * (1 + 0.15 * Math.sin(t * 60)) * (t > RAISE ? 1 - (t - RAISE) / 0.03 : 1);+ sparkle(p, GLINT[0], GLINT[1], 1 + 7 * g, C[6], C[4], 0.5);+ p.glow(GLINT[0], GLINT[1], 22, C[4], 0.3 * g);+ }+ if (q >= 0) {+ // cracks race out from the cut and split down into the floor: white hot, cooling down the ramp to dark+ const heat = Math.pow(clamp(1 - q / 1.2), 1.2), fade = 1 - smooth(1.15, 1.5, q);+ for (const c of lines) {+ const reach = 40 * ease.outCubic(clamp((q - c.at * 0.1) / 0.13)) * (c.fork ? 0.3 : 1);+ if (reach <= 0) continue;+ along(c.pts, reach, (x0, y0, x1, y1, d) => {+ const h = heat * (1 - d / 46) - (c.fork ? 0.12 : 0), col = h > 0.72 ? WHITE : h > 0.08 ? C[clamp(Math.round(h * 8), 1, 6)] : st.dark;+ if (y1 > 0.5) p.line(x0 + 1, y0, x1 + 1, y1, st.dark, fade);+ p.line(x0, y0, x1, y1, col, fade);+ if (h > 0.25 && (d | 0) % 6 < 2) p.glow(x1, y1, 6, C[4], 0.2 * h * fade);+ });+ }+ if (heat > 0) p.glow(X, -2, 34, C[4], 0.32 * heat * fade);+ // the near half of the shock ring+ const k = q / 0.45;+ if (k < 1) band(p, X, 0.5, 6 + 46 * ease.outCubic(k), 0.16, Math.max(1, 3 * (1 - k)), 1.15 - k, [st.body, st.light, C[4], C[6]], (g) => Math.sin(g) >= 0);+ }+ // the arc and its echo, then a dotted trace of embers where it has been+ arc(p, E, WE, 0.02, false);+ arc(p, A, W, 0, true);+ const tail = U1 * smooth(HIT + HOLD, HIT + HOLD + TRAIL, t), th = 0.8 * (1 - clamp((t - HIT - HOLD) / (TRAIL + 0.25)));+ if (tail > 0.02 && th > 0) trace(p, A, A.R - 0.5, 0, tail, C[3], (u) => th * (0.4 + 0.6 * u / U1));+ if (t > RAISE && t < HIT + 0.05) {+ const [x, y] = onSwing(A, A.R - 5, U1 * head(t));+ p.glow(x, y, 40, C[4], 0.5);+ }+ // the white slam: an impact star flat on the floor, then slivers flying off and a hot pool+ if (q >= 0 && q < 0.035) star(p, X, -1, spikes, 1, 1, WHITE, C[6], C[7], C[5]);+ else if (q >= 0.035 && q < 0.07) star(p, X, -1, spikes, 1.25, 0.55, C[7], C[6], C[6], C[4]);+ if (q >= 0.05 && q < 0.16) {+ const k = (q - 0.05) / 0.11;+ for (const s of shards) sliver(p, X, -1, s.a, s.r + s.v * (q - 0.05), s.arc * (1 - 0.4 * k), k < 0.4 ? C[6] : k < 0.7 ? C[5] : C[4], 1 - k);+ }+ if (q >= 0 && q < 0.2) {+ const pop = Math.exp(-q / 0.05);+ p.glow(X, -6, 30, C[5], 0.8 * pop);+ p.glow(X, -2, 10, WHITE, 0.7 * pop);+ }+ for (const b of bits.list) rock(p, b, st);+ ps.draw(p, "front");+ lights.draw(p);+ },+ };}diff --git a/src/fx/melee/iaido-cut.js b/src/fx/melee/iaido-cut.jsdeleted file mode 100644index 945e02b..0000000--- a/src/fx/melee/iaido-cut.js+++ /dev/null@@ -1,80 +0,0 @@-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.jsdeleted file mode 100644index 94a619d..0000000--- a/src/fx/melee/punch-combo.js+++ /dev/null@@ -1,70 +0,0 @@-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.jsindex 2287146..4c88095 100644--- a/src/fx/melee/scythe-reap.js+++ b/src/fx/melee/scythe-reap.js@@ -1,62 +1,131 @@-import { ramp, at, burst, seg, ease, clamp, smooth, WHITE } from "../../core/index.js";+// The crescent and trace recipe is adapted from Sprite Fusion's open-source slash, and the vapour from his+// ice and poison (https://www.spritefusion.com/pixel-art-vfx), MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Lights, P, PF, Rng, fit, sparkle, clamp, smooth, ease, rand, WHITE } from "../../core/index.js";+import { swing, onSwing, travel, smear, glowAlong } from "./_lib.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,+ desc: "A slow, huge dark crescent reaps round the front with a pale ghostly edge; it hangs, then tears away from the tail into curling wisps and cold vapour.",+ tags: ["melee", "scythe", "reap", "dark", "ghost", "death", "slash", "combat", "one-shot"],+ size: [184, 116],+ origin: [84, 98],+ duration: 2.1,loop: false,fps: 30,bg: "ground",- actor: true,- options: { palette: ["#05030a", "#120a1e", "#24123a", "#3a1e5a", "#5a3a80", "#8a7ab0", "#bfe8d8", "#effff8"], radius: 30, seed: 13 },+ actor: 2,+ options: {+ palette: ["#07040c", "#140a22", "#24113a", "#3b1d58", "#5a3a82", "#7fd6c0", "#d8fff2", "#ffffff"],+ 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));- });+const WIND = 0.08, SWEEP = 0.34, HANG = 0.14, TEAR = 0.55;+const T0 = WIND, T1 = WIND + SWEEP, T2 = T1 + HANG, T3 = T2 + TEAR;+const head = (t) => ease.inOutSine(clamp((t - T0) / SWEEP));++export function create(o) {+ const C = fit(o.palette, 8), Rg = new Rng(o.seed), ps = new Particles({ rng: Rg, ground: () => 0, haze: C[5] }), lights = new Lights();+ // a wide reap from out on the right, round the front of the fighter, to the left+ const A = swing({ cx: 8, cy: -33, R: 52, sy: 0.6, k: 0.1, rot: 0.08, a0: -0.5, dir: 1, span: 3.5 });+ const W = 21;+ const wisps = [];+ let t = 0, lastTear = 0;+ // how far the tear has eaten in from the tail (0..1 of the span), ragged by a per-pixel threshold+ const tear = () => smooth(T2, T3, t);+ const addWisp = (x, y, far) => wisps.push({ x, y, vx: Rg.range(-12, 12), vy: -Rg.range(8, 26), life: Rg.range(0.5, 0.9), max: 0, seed: Rg.range(0, 100), pts: [], far });+ return {+ update(dt) {+ t += dt;+ // the cold gathers on the blade before it moves+ if (t < WIND && Rg.chance(0.5)) {+ const [x, y] = onSwing(A, A.R - 4, 0);+ ps.spawn(P.VAPOUR, x + Rg.range(-14, 14), y + Rg.range(-8, 8), Rg.range(-10, 10), Rg.range(-6, 6), Rg.range(0.3, 0.5), C[5], Rg.range(1.5, 2.5));+ }+ // the edge sheds a little vapour as it goes+ if (t > T0 && t < T1 && Rg.chance(0.5)) {+ const tr = travel(A, A.span * head(t) * Rg.range(0.75, 1));+ ps.spawn(P.VAPOUR, tr.x, tr.y, tr.dx * 20, -Rg.range(4, 14), Rg.range(0.5, 0.9), C[6], Rg.range(2, 3.5), 0, Math.sin(tr.a) < 0 ? PF.BACK : 0);+ }+ // tearing away: wisps peel off where the crescent is coming apart+ const k = tear();+ for (let u = lastTear; u < k * 1.15; u += 0.022) {+ const uu = Math.min(1, u) * A.span, tr = travel({ ...A, R: A.R - Rg.range(0, 8) }, uu), far = Math.sin(tr.a) < 0;+ addWisp(tr.x, tr.y, far);+ if (Rg.chance(0.5)) ps.spawn(P.VAPOUR, tr.x, tr.y, Rg.range(-10, 10), -Rg.range(6, 18), Rg.range(0.55, 0.85), Rg.chance(0.5) ? C[5] : C[4], Rg.range(2.5, 4.5), 0, far ? PF.BACK : 0);+ if (Rg.chance(0.2)) ps.spawn(P.STAR, tr.x + Rg.range(-3, 3), tr.y + Rg.range(-3, 3), 0, -6, Rg.range(0.25, 0.5), Rg.chance(0.5) ? C[6] : WHITE, Rg.range(0.6, 1.6), 0, far ? PF.BACK : 0);+ }+ lastTear = Math.max(lastTear, k * 1.15);+ // wisps rise, sway and curl, leaving a fading thread behind them+ for (let i = wisps.length - 1; i >= 0; i--) {+ const w = wisps[i];+ w.max += dt;+ if (w.max > w.life) {+ wisps.splice(i, 1);+ continue;+ }+ w.vy -= 30 * dt;+ w.vx += Math.sin(w.max * 9 + w.seed) * 120 * dt;+ w.vx -= w.vx * 2 * dt;+ w.vy -= w.vy * 1.2 * dt;+ w.x += w.vx * dt;+ w.y += w.vy * dt;+ w.pts.push([w.x, w.y]);+ if (w.pts.length > 14) w.pts.shift();+ }+ ps.update(dt);+ lights.update(dt);+ },+ drawBack(p) {+ this.blade(p, -1);+ ps.draw(p, "back");+ this.threads(p, true);+ },+ draw(p) {+ this.blade(p, 1);+ // the blade's point glints cold as it sets off and where it stops+ if (t < WIND + 0.05) {+ const [x, y] = onSwing(A, A.R - 3, 0);+ sparkle(p, x, y, 6 * Math.min(1, t / 0.04) * (1 - smooth(WIND - 0.02, WIND + 0.05, t)), C[6], C[5], 0.45);+ }+ const g = t - T1 + 0.06;+ if (g > 0 && g < 0.3) {+ const [x, y] = onSwing(A, A.R - 3, A.span);+ sparkle(p, x, y, 9 * ease.outBack(Math.min(1, g / 0.06)) * (1 - g / 0.3), C[6], C[5], 0.55);+ }+ ps.draw(p, "front");+ this.threads(p, false);+ lights.draw(p);+ },+ blade(p, half) {+ const U = A.span * head(t), k = tear();+ if (U < 0.02 || k >= 1) return;+ const ramp = half < 0 ? [C[0], C[0], C[1], C[2], C[3], C[4], C[5], C[6]] : C;+ smear(p, A, 0, U, W, (u, r, out, a) => {+ const v = u / U, w = W * Math.pow(Math.sin(Math.PI * Math.pow(v, 1.7)), 0.55);+ if (w < 0.5) return;+ const q = (A.R - r) / w;+ if (q < 0 || q > 1) return;+ // torn away from the tail: a ragged front of per-pixel thresholds+ const n = rand(Math.floor(u * 40), Math.floor(r), 7);+ if (k > 0 && (u / A.span) < k * 1.2 - n * 0.2) return;+ // a pale ghostly rim, a dark body that deepens inward, a faint lit seam+ const ci = q < 0.08 ? 7 : q < 0.16 ? 6 : q < 0.25 ? 5 : q < 0.4 ? 4 : q < 0.62 ? 3 : 2;+ out.c = ramp[t > T1 && q < 0.2 ? ci - 1 : ci];+ out.a = Math.min(1, v / 0.25);+ }, half);+ glowAlong(p, A, A.R - 2, Math.max(0, k * 1.2 * A.span - 0.3), U, 14, C[5], (u) => 0.3 * (u / U), half, 0.25);+ },+ threads(p, back) {+ for (const w of wisps) {+ if (w.far !== back) continue;+ const life = 1 - w.max / w.life;+ for (let i = 1; i < w.pts.length; i++) {+ const f = i / w.pts.length;+ p.line(w.pts[i - 1][0], w.pts[i - 1][1], w.pts[i][0], w.pts[i][1], f > 0.75 ? C[6] : f > 0.4 ? C[5] : C[3], life * (0.3 + 0.7 * f));+ }+ if (life > 0.5) p.glow(w.x, w.y, 5, C[5], 0.25 * life);+ }+ },+ };}diff --git a/src/fx/melee/spear-sweep.js b/src/fx/melee/spear-sweep.jsindex 46b2991..b31f17b 100644--- a/src/fx/melee/spear-sweep.js+++ b/src/fx/melee/spear-sweep.js@@ -1,99 +1,73 @@-import { PAL, ramp, at, burst, fly, seg, ease, clamp, smooth, wrap, TAU, WHITE } from "../../core/index.js";-import { dustCloud } from "./_lib.js";+// The crescent, trace and glint recipe is adapted from Sprite Fusion's open-source slash, and the rolling dust and+// grit from his explosion (https://www.spritefusion.com/pixel-art-vfx), MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Lights, P, PF, Rng, fit, sparkle, clamp, ease } from "../../core/index.js";+import { swing, onSwing, travel, slash, slashEnd, stone } 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,+ desc: "A wide low sweep at shin height: a long flat crescent swings from behind the legs round the front, and the wind of it kicks a wake of dust and grit along the floor.",+ tags: ["melee", "sweep", "spear", "polearm", "low", "aoe", "ground", "dust", "combat", "one-shot"],+ size: [216, 84],+ origin: [104, 70],+ duration: 1.5,loop: false,fps: 30,bg: "ground",- actor: true,- options: { palette: PAL.cyber, radius: 34, seed: 10 },+ actor: 2,+ options: {+ palette: ["#0f2a2a", "#18504a", "#22806e", "#3fb894", "#8fe6c0", "#dcfff0", "#ffffff"],+ sparks: ["#fff3a6", "#ffe26b", "#ff8a2a", "#f2561d"],+ stone: "#4a3f69",+ 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;+export function create(o) {+ const C = fit(o.palette, 7), Rg = new Rng(o.seed), st = stone(o.stone), ps = new Particles({ rng: Rg, ground: () => 0, sparks: o.sparks }), lights = new Lights();+ // from behind the left leg, round the front, out to the right; the far part is behind the fighter+ const A = swing({ cx: 2, cy: -12, R: 50, sy: 0.2, k: 0.19, rot: -0.04, a0: Math.PI + 0.55, dir: -1, span: Math.PI + 0.35, W: 19, t0: 0, sweep: 0.13, hold: 0.05, trail: 0.3, ramp: C });+ const end = slashEnd(A);+ let t = 0, lastU = 0, done = false;+ return {+ update(dt) {+ t += dt;+ // the wind under the blade kicks dust up off the floor as it passes, rolling on the way it goes+ const U = A.span * ease.outExpo(clamp(t / A.sweep));+ for (let u = lastU; u < U; u += 0.09) {+ const tr = travel(A, u), near = Math.sin(tr.a) >= 0, fy = near ? -1 : -3, sp = Rg.range(30, 90);+ ps.spawn(P.SMOKE, tr.x, fy - Rg.range(0, 2), tr.dx * sp, -Rg.range(4, 16), Rg.range(0.7, 1.15), st.dust, Rg.range(3, 5.5), Rg.range(0, 0.05));+ if (Rg.chance(0.6)) ps.spawn(P.GRIT, tr.x, fy, tr.dx * Rg.range(40, 120) + Rg.range(-20, 20), -Rg.range(40, 130), Rg.range(0.6, 1.0), Rg.pick([st.light, st.body, st.shade]), Rg.chance(0.3) ? 2 : 1);+ if (Rg.chance(0.35)) ps.spawn(P.MOTE, tr.x, tr.y, tr.dx * Rg.range(40, 100), tr.dy * 40 - Rg.range(5, 20), Rg.range(0.2, 0.4), Rg.chance(0.5) ? C[4] : C[5], 0.6, 0, near ? 0 : PF.BACK);+ }+ lastU = U;+ if (!done && t >= A.sweep) {+ done = true;+ lights.add(end.x, end.y - 4, 50, C[3], 0.5, 0.35);+ for (let i = 0; i < 8; i++) {+ const a = Math.atan2(end.dy, end.dx) + Rg.range(-0.5, 0.3), sp = Rg.range(120, 260);+ ps.spawn(P.SPARK, end.x, end.y, Math.cos(a) * sp, Math.sin(a) * sp - 40, Rg.range(0.12, 0.3));+ }+ // the wake piles up and rolls on past the tip+ for (let i = 0; i < 6; i++) ps.spawn(P.SMOKE, end.x + Rg.range(-6, 4), -Rg.range(1, 4), Rg.range(30, 90), -Rg.range(4, 14), Rg.range(0.9, 1.25), st.dust, Rg.range(4.5, 7), Rg.range(0, 0.08), PF.BIG);+ }+ ps.update(dt);+ lights.update(dt);+ },+ drawBack(p) {+ slash(p, A, t, -1);+ ps.draw(p, "back");+ },+ draw(p) {+ slash(p, A, t, 1);+ const g = t - A.sweep * 0.6;+ if (g > 0 && g < 0.24) sparkle(p, end.x, end.y, 9 * ease.outBack(Math.min(1, g / 0.05)) * (1 - g / 0.24), C[5], C[3], 0.55);+ // light rides the edge+ if (t < A.sweep + 0.12) {+ const [x, y] = onSwing(A, A.R - 5, A.span * ease.outExpo(clamp(t / A.sweep)));+ p.glow(x, y, 36, C[3], 0.45 * (1 - t / (A.sweep + 0.12)));+ }+ ps.draw(p, "front");+ lights.draw(p);+ },+ };}diff --git a/src/fx/melee/spin-slash.js b/src/fx/melee/spin-slash.jsindex 6b87d8a..3a87daf 100644--- a/src/fx/melee/spin-slash.js+++ b/src/fx/melee/spin-slash.js@@ -1,75 +1,139 @@-import { ramp, at, burst, fly, seg, ease, clamp, smooth, wrap, TAU, WHITE } from "../../core/index.js";+// The crescent shading, cooling ramp, dotted trace, glint and spark recipe is adapted from Sprite Fusion's+// open-source slash (https://www.spritefusion.com/pixel-art-vfx/slash), MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Lights, P, PF, Rng, fit, sparkle, clamp, smooth, ease, rand, TAU, WHITE } from "../../core/index.js";+import { swing, onSwing, travel, smear, trace, glowAlong } from "./_lib.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.",+ desc: "The blade whirls once round the waist on a tilted plane, behind the body and back in front; the closed ring flares white, dissolves into a dotted trace and throws sparks.",tags: ["melee", "slash", "spin", "sword", "aoe", "combat", "one-shot"],- size: [76, 48],- origin: [38, 38],- duration: 0.45,+ size: [208, 104],+ origin: [104, 84],+ duration: 0.8,loop: false,fps: 30,bg: "ground",- actor: true,- options: { palette: ["#04201c", "#0a3a30", "#12604a", "#1f8a62", "#3cb87a", "#7ee0a0", "#c8ffd8", "#ffffff"], radius: 26, seed: 4 },+ actor: 2,+ options: {+ palette: ["#16224a", "#1f4a86", "#2a7fc0", "#48b8ec", "#9fe2ff", "#e2f7ff", "#ffffff"],+ sparks: ["#fff3a6", "#ffe26b", "#ff8a2a", "#f2561d"],+ radius: 46,+ seed: 3,+ },};-// 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;- });- }-}+const SW = 0.17; // the edge goes once round+const FLARE = 0.3; // the closed ring flares and dissolves+const turn = (t) => 1 - Math.pow(1 - clamp(t / SW), 1.6); // fraction of the turn the edge has made+const passedAt = (f) => SW * (1 - Math.pow(1 - clamp(f), 1 / 1.6)); // when the edge passed fraction f-export function drawBack(p, t, o) {- band(p, t, o, false);-}+export function create(o) {+ const C = fit(o.palette, 7), n = C.length, Rg = new Rng(o.seed), R0 = o.radius;+ const ps = new Particles({ rng: Rg, ground: () => 0, sparks: o.sparks }), lights = new Lights();+ // the spin starts front-right, goes up the right side, behind the body, down the left and back across the front+ const A = swing({ cx: 0, cy: -17, R: R0, sy: 0.27, rot: -0.1, a0: 0.5, dir: -1, k: 0.15 });+ // a thinner echo just inside, a beat behind+ const E = { ...A, R: R0 * 0.8, k: 0.1 };+ const W = 16, WE = 5;+ // the far half sits deeper in the ramp+ const DIM = [C[0], C[0], C[1], C[2], C[3], C[4], C[5]];+ let t = 0, closed = false, lastU = 0;++ // the smear: thickest just behind the edge, thinning and cooling where the edge passed longer ago+ const body = (p, s, w0, lag, half, rim) => {+ const U = TAU * turn(t - lag), ramp = half < 0 ? DIM : C;+ if (U < 0.02 || t - lag > SW + 0.02) return;+ smear(p, s, 0, U, w0, (u, r, out) => {+ const age = t - lag - passedAt(u / TAU), lead = U - u;+ const w = w0 * Math.pow(clamp(lead / 0.85), 0.5) * (0.3 + 0.7 * Math.exp(-age / 0.075)) * Math.pow(clamp(u / 1.3), 0.7);+ if (w < 0.45) return;+ const q = (s.R - r) / w;+ if (q < 0 || q > 1) return;+ // white rim while fresh, then darker steps inward, with age and towards the tail+ const ci = rim && q < 0.26 && age < 0.06 ? 0 : Math.round(q * (n - 1) * 0.7 + age * 13 + (rim ? 0.4 : 1.4));+ out.c = ramp[n - 1 - clamp(ci, 0, n - 1)];+ out.a = Math.min(1, u / 1.1 + 0.2);+ }, half);+ };++ const ring = (p, half) => {+ // the swept smear and its echo+ body(p, E, WE, 0.025, half, false);+ body(p, A, W, 0, half, true);+ if (t < SW + 0.04) glowAlong(p, A, A.R - 5, 0, TAU * turn(t), 14, C[3], (u) => (half < 0 ? 0.2 : 0.3) * Math.exp(-(t - passedAt(u / TAU)) / 0.08), half);+ if (t < SW) return;+ // closed: the ring flares white, swells a little, thins, cools and breaks into dots+ const f = (t - SW) / FLARE, ramp = half < 0 ? DIM : C;+ if (f < 1) {+ const R = A.R + 6 * ease.outCubic(f), th = f < 0.13 ? 9 : Math.max(1, 6 * Math.pow(1 - f, 1.5) + 0.5), S = { ...A, R };+ const step = f < 0.13 ? 6 : f < 0.3 ? 5 : f < 0.55 ? 4 : 3;+ smear(p, S, 0, TAU, th, (u, r, out) => {+ const q = (R - r) / th;+ if (q < 0 || q > 1) return;+ out.c = f < 0.13 ? (q < 0.6 ? WHITE : ramp[5]) : q < 0.45 ? ramp[step] : ramp[step - 1];+ out.a = f < 0.4 ? 1 : 1.3 - f;+ }, half);+ glowAlong(p, S, R - 2, 0, TAU, 14, C[4], 0.32 * (1 - f) * (1 - f), half);+ }+ // a dotted trace of the blade's path lingers where the ring was, fading+ const k = 1 - clamp((t - SW - 0.06) / 0.4);+ if (k > 0) trace(p, A, A.R - 0.5, 0, TAU, ramp[4], (u) => clamp(k * 1.5 - rand(Math.floor(u * 30), 5) * 0.8) * 0.95, half);+ };-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));- });+ return {+ update(dt) {+ t += dt;+ const U = TAU * turn(t);+ // shavings peel off the edge as it goes round, flung along its path+ if (t < SW) {+ for (let u = lastU; u < U; u += 0.3) {+ const tr = travel(A, u), ox = tr.x - A.cx, oy = tr.y - A.cy, l = Math.hypot(ox, oy) || 1, sp = Rg.range(40, 120);+ ps.spawn(P.MOTE, tr.x, tr.y, tr.dx * sp + (ox / l) * sp * 0.35, tr.dy * sp * 0.6 - Rg.range(5, 30), Rg.range(0.22, 0.45), C[4 + Rg.int(0, 1)], 0.55, 0, Math.sin(tr.a) < 0 ? PF.BACK : 0);+ }+ lastU = U;+ }+ if (!closed && t >= SW) {+ closed = true;+ lights.add(A.cx, A.cy + 4, 90, C[3], 0.4, 0.4);+ // sparks off the edge where it closes, and all round the ring along its turn+ const end = travel(A, TAU);+ for (let i = 0; i < 9; i++) {+ const a = Math.atan2(end.dy, end.dx) + Rg.range(-0.45, 0.35), sp = Rg.range(160, 360);+ ps.spawn(P.SPARK, end.x, end.y, Math.cos(a) * sp, Math.sin(a) * sp - Rg.range(20, 70), Rg.range(0.14, 0.36));+ }+ for (let i = 0; i < 16; i++) {+ const u = Rg.range(0, TAU), tr = travel(A, u), sp = Rg.range(110, 260);+ ps.spawn(P.SPARK, tr.x, tr.y, tr.dx * sp, tr.dy * sp - Rg.range(20, 80), Rg.range(0.12, 0.32), 0, 1, 0, Math.sin(tr.a) < 0 ? PF.BACK : 0);+ }+ // and twinkles left hanging on the ring+ for (let i = 0; i < 6; i++) {+ const u = Rg.range(0, TAU), [x, y] = onSwing(A, A.R + Rg.range(-1, 3), u);+ ps.spawn(P.STAR, x, y, 0, -Rg.range(2, 8), Rg.range(0.25, 0.5), Rg.chance(0.5) ? C[5] : WHITE, Rg.range(1.2, 2.6), Rg.range(0.04, 0.16), Math.sin(A.a0 + A.dir * u) < 0 ? PF.BACK : 0);+ }+ }+ ps.update(dt);+ lights.update(dt);+ },+ drawBack(p) {+ ring(p, -1);+ ps.draw(p, "back");+ },+ draw(p) {+ ring(p, 1);+ // the blade catches the light as it sets off, and glints again where the ring closes+ if (t < 0.06) {+ const [x, y] = onSwing(A, A.R - 3, 0);+ sparkle(p, x, y, 7 * (1 - t / 0.06), C[5], C[3], 0.5);+ }+ const g = t - SW * 0.85, tip = onSwing(A, A.R - 3, TAU);+ if (g > 0 && g < 0.24) sparkle(p, tip[0], tip[1], 10 * ease.outBack(Math.min(1, g / 0.05)) * (1 - g / 0.24), C[5], C[3], 0.6);+ // light rides the edge+ if (t < SW + 0.05) {+ const U = TAU * turn(t), [x, y] = onSwing(A, A.R - 5, U), far = Math.sin(A.a0 + A.dir * U) < 0;+ p.glow(x, y, far ? 26 : 38, C[3], (far ? 0.3 : 0.5) * (1 - smooth(SW - 0.04, SW + 0.05, t)));+ }+ ps.draw(p, "front");+ lights.draw(p);+ },+ };}diff --git a/src/fx/melee/thrust.js b/src/fx/melee/thrust.jsindex 94329ee..5604b1c 100644--- a/src/fx/melee/thrust.js+++ b/src/fx/melee/thrust.js@@ -1,66 +1,114 @@-import { PAL, ramp, burst, fly, seg, ease, WHITE } from "../../core/index.js";+// The speed lines are adapted from Sprite Fusion's open-source dash and the ray star from his sparkle+// (https://www.spritefusion.com/pixel-art-vfx), MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Lights, P, Rng, fit, sparkle, clamp, smooth, ease, TAU, 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,+ desc: "A piercing stab: a bundle of streaks shoots out from the hand to a point, a long four-point star flares at the tip with a pierce ring, sparks and speed lines.",+ tags: ["melee", "thrust", "stab", "spear", "rapier", "pierce", "combat", "directional", "one-shot"],+ size: [196, 76],+ origin: [34, 62],+ duration: 0.75,loop: false,fps: 30,bg: "ground",- actor: true,- options: { palette: PAL.gold, reach: 44, seed: 5 },+ actor: 2,+ options: {+ palette: ["#2a1608", "#6b3c10", "#b8701a", "#f0b42e", "#ffe27a", "#fff6cf", "#ffffff"],+ sparks: ["#fff3a6", "#ffe26b", "#ff8a2a", "#f2561d"],+ reach: 66,+ seed: 4,+ },};-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]);+const OUT = 0.07; // the point arrives+const HOLD = 0.06, PULL = 0.2;++// a long four-point star: the forward and back arms long, up and down shorter, thick at the heart+function longStar(p, x, y, L, k, C) {+ if (L < 1) return;+ const arms = [[1, 0, L], [-1, 0, L * 0.7], [0, -1, L * 0.42], [0, 1, L * 0.42]];+ for (const [dx, dy, len] of arms)+ for (let d = 1; d <= len; d += 0.5) {+ const u = d / len, c = u < 0.3 ? WHITE : u < 0.65 ? C[5] : C[4];+ p.dot(x + dx * d, y + dy * d, c, u < 0.7 ? 1 : 1 - (u - 0.7) / 0.35);+ if (u < 0.25 && len > 6) (p.dot(x + dx * d - dy, y + dy * d + dx, C[5]), p.dot(x + dx * d + dy, y + dy * d - dx, C[5]));}- 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));- });+ for (const [dx, dy] of [[1, 1], [1, -1], [-1, 1], [-1, -1]]) for (let d = 1; d <= Math.min(3, L * 0.14); d++) p.px(x + dx * d, y + dy * d, d < 2 ? C[5] : C[4]);+ p.px(x, y, WHITE);+ p.glow(x, y, 6 + L * 1.3, C[4], 0.35 * k);+ p.glow(x, y, 3 + L * 0.4, WHITE, 0.3 * k);+}++export function create(o) {+ const C = fit(o.palette, 7), Rg = new Rng(o.seed), ps = new Particles({ rng: Rg, ground: () => 0, sparks: o.sparks }), lights = new Lights();+ const HX = 9, HY = -20, TX = HX + o.reach, TY = HY;+ // the bundle: streaks fanned at the hand, meeting at the point; the middle one hottest+ const streaks = [-7, -4, -2, 0, 2, 4, 7].map((off) => ({ off, x0: HX + 1 + Rg.range(0, 5) + Math.abs(off) * 0.6, t0: Rg.range(0, 0.02) + Math.abs(off) * 0.003, w: off === 0 ? 2 : 1, hot: off === 0, len: Rg.range(0.75, 1) }));+ const lines = [];+ let t = 0, struck = false;+ return {+ update(dt) {+ t += dt;+ // speed lines race forward beside the bundle while it shoots out and just after+ if (t < OUT + 0.08 && Rg.chance(0.5)) {+ const s = Rg.sign();+ lines.push({ x: HX + Rg.range(0, o.reach * 0.6), y: HY + s * Rg.range(7, 17), l: Rg.range(18, 42), v: Rg.range(200, 340), t });+ }+ for (let i = lines.length - 1; i >= 0; i--) if (t - lines[i].t > 0.24) lines.splice(i, 1);+ for (const l of lines) l.x += l.v * dt;+ if (!struck && t >= OUT) {+ struck = true;+ lights.add(TX, TY, 44, C[4], 0.45, 0.3);+ lights.add(TX, TY, 14, WHITE, 0.6, 0.06);+ for (let i = 0; i < 12; i++) {+ const a = Rg.range(-0.55, 0.45), sp = Rg.range(150, 330);+ ps.spawn(P.SPARK, TX, TY, Math.cos(a) * sp, Math.sin(a) * sp - 30, Rg.range(0.12, 0.35));+ }+ for (let i = 0; i < 10; i++) {+ const a = Rg.range(-0.9, 0.9) + (Rg.chance(0.3) ? Math.PI : 0), sp = Rg.range(40, 120);+ ps.spawn(P.MOTE, TX + Rg.range(-6, 2), TY + Rg.range(-2, 2), Math.cos(a) * sp, Math.sin(a) * sp, Rg.range(0.25, 0.5), Rg.chance(0.5) ? C[5] : C[4], 0.6);+ }+ for (let i = 0; i < 4; i++) ps.spawn(P.STAR, TX + Rg.range(-10, 8), TY + Rg.range(-9, 9), 0, -3, Rg.range(0.2, 0.4), Rg.chance(0.5) ? C[5] : WHITE, Rg.range(1, 2), Rg.range(0.06, 0.2));+ }+ ps.update(dt);+ lights.update(dt);+ },+ draw(p) {+ // the point catches the light before it goes+ if (t < 0.05) sparkle(p, HX + 2, HY, 5 * (1 - t / 0.05) + 1, C[5], C[3], 0.4);+ // speed lines: dotted, white at the head, dimming back along their length+ for (const l of lines) {+ const k = (t - l.t) / 0.24;+ for (let d = 0; d < l.l * (1 - k * 0.6); d++) p.dot(l.x - d, l.y, d < 3 ? WHITE : d < l.l * 0.4 ? C[5] : C[3], (1 - d / l.l) * (1 - k));+ }+ // the bundle: each streak shoots from the hand to the point, holds, then is drawn in to the point+ const pull = smooth(OUT + HOLD, OUT + HOLD + PULL, t);+ for (const s of streaks) {+ const u = clamp((t - s.t0) / OUT), head = ease.outExpo(u);+ if (u <= 0 || pull >= 1) continue;+ // the outer streaks stop short of the point and trail a little behind, so each reads on its own+ const y0 = HY + s.off, end = s.x0 + (TX - s.x0) * s.len, x1 = s.x0 + (end - s.x0) * head, xa = s.x0 + (end - s.x0) * Math.max(pull, head * 0.35 * (1 - s.len) * 3);+ const yAt = (x) => y0 + (TY - y0) * clamp((x - s.x0) / (TX - s.x0)) * 0.85;+ for (let x = xa; x <= x1; x += 0.5) {+ const v = (x - xa) / Math.max(1, x1 - xa), c = v > 0.88 ? WHITE : s.hot ? (v > 0.35 ? C[6] : C[5]) : v > 0.55 ? C[5] : v > 0.25 ? C[4] : C[3];+ p.dot(x, yAt(x), c, v < 0.12 ? v / 0.12 : 1);+ if (s.w > 1 && v > 0.1) p.dot(x, yAt(x) + 1, v > 0.6 ? C[5] : C[3], v < 0.2 ? v / 0.2 : 1);+ }+ }+ if (t < OUT + HOLD + PULL) p.glowLine(HX + (TX - HX) * pull, HY, HX + (TX - HX) * ease.outExpo(clamp(t / OUT)), TY, 6, C[4], 0.22 * (1 - pull));+ // the long star at the point, and a pierce ring shed from it+ const q = t - OUT;+ if (q >= 0 && q < 0.4) {+ const g = ease.outBack(clamp(q / 0.04), 2.4) * (1 - smooth(0.08, 0.4, q)) * (1 + 0.12 * Math.sin(q * 70));+ longStar(p, TX, TY, 24 * g, 1 - q / 0.4, C);+ }+ if (q >= 0 && q < 0.2) {+ const k = q / 0.2, rx = 2 + 7 * ease.outCubic(k), ry = 4 + 12 * ease.outCubic(k);+ for (let a = 0; a < TAU; a += 0.05) p.dot(TX + 4 + 10 * k + Math.cos(a) * rx, TY + Math.sin(a) * ry, k < 0.3 ? WHITE : C[5], 1.15 - k);+ }+ ps.draw(p);+ lights.draw(p);+ },+ };}diff --git a/src/fx/melee/uppercut.js b/src/fx/melee/uppercut.jsindex 05b31bc..18119db 100644--- a/src/fx/melee/uppercut.js+++ b/src/fx/melee/uppercut.js@@ -1,62 +1,97 @@-import { PAL, ramp, burst, fly, seg, ease, star, clamp, WHITE } from "../../core/index.js";-import { swing } from "./_lib.js";+// The crescent recipe is adapted from Sprite Fusion's open-source slash, and the star from his impact+// (https://www.spritefusion.com/pixel-art-vfx), MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Lights, P, Rng, fit, hex, clamp, smooth, ease, TAU, WHITE } from "../../core/index.js";+import { swing, onSwing, slash, slashEnd, star } 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,+ desc: "A crescent rises from the floor past the face, and at the top a comic impact star bursts: bold outline, hot core, burst lines, twinkles and sparks.",+ tags: ["melee", "uppercut", "punch", "rising", "launcher", "comic", "combat", "directional", "one-shot"],+ size: [132, 128],+ origin: [48, 110],+ duration: 0.85,loop: false,fps: 30,bg: "ground",- actor: true,- options: { palette: PAL.volt, size: 1, seed: 12 },+ actor: 2,+ options: {+ palette: ["#3a1408", "#7a2a10", "#c4501a", "#f08a2a", "#ffc94a", "#fff2a8", "#ffffff"],+ outline: "#2a0a08",+ sparks: ["#fff3a6", "#ffe26b", "#ff8a2a", "#f2561d"],+ seed: 11,+ },};-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));- });+export function create(o) {+ const C = fit(o.palette, 7), INK = hex(o.outline), Rg = new Rng(o.seed), ps = new Particles({ rng: Rg, ground: () => 0, sparks: o.sparks }), lights = new Lights();+ // up from the floor in front, bowing forward past the face, to the top+ const A = swing({ cx: 8, cy: -25, R: 27, sy: 1, rot: 0, a0: 1.08, dir: -1, span: 2.5, W: 13, t0: 0.02, sweep: 0.07, hold: 0.05, trail: 0.22, ramp: C });+ const top = slashEnd(A), SX = top.x + 3, SY = top.y - 5, HIT = A.t0 + A.sweep * 0.8;+ const spikes = Array.from({ length: 10 }, (_, i) => ({ a: (i / 10) * TAU + Rg.range(-0.12, 0.12) - Math.PI / 2, len: (i % 2 ? 7 : 13) + Rg.range(0, 4), w: i % 2 ? 2.2 : 3 }));+ const bursts = Array.from({ length: 8 }, (_, i) => ({ a: (i / 8) * TAU + 0.2 + Rg.range(-0.15, 0.15), r0: Rg.range(15, 18), L: Rg.range(5, 9) }));+ let t = 0, hit = false, kicked = false;+ return {+ update(dt) {+ t += dt;+ if (!kicked) {+ kicked = true;+ // the fist comes up off the floor+ for (let i = 0; i < 4; i++) ps.spawn(P.DUST, 18 + Rg.range(-4, 4), -1, Rg.range(-30, 30), -Rg.range(5, 20), Rg.range(0.3, 0.55), "#6a6080", Rg.range(1.5, 2.6));+ }+ if (!hit && t >= HIT) {+ hit = true;+ lights.add(SX, SY, 56, C[4], 0.6, 0.4);+ lights.add(SX, SY, 18, WHITE, 0.7, 0.08);+ for (let i = 0; i < 16; i++) {+ const a = -Math.PI / 2 + Rg.range(-1.6, 1.6), sp = Rg.range(120, 320);+ ps.spawn(P.SPARK, SX, SY, Math.cos(a) * sp, Math.sin(a) * sp, Rg.range(0.15, 0.45));+ }+ for (let i = 0; i < 6; i++) {+ const a = Rg.range(0, TAU), d = Rg.range(14, 24);+ ps.spawn(P.STAR, SX + Math.cos(a) * d, SY + Math.sin(a) * d, Math.cos(a) * 20, Math.sin(a) * 20 - 10, Rg.range(0.25, 0.5), Rg.chance(0.5) ? C[5] : WHITE, Rg.range(1.4, 2.6), Rg.range(0.04, 0.18));+ }+ }+ ps.update(dt);+ lights.update(dt);+ },+ draw(p) {+ slash(p, A, t);+ // speed lines rising beside the crescent while it goes up+ const u = t - A.t0;+ if (u > 0 && u < 0.16)+ for (const [dx, y0, L] of [[A.cx + A.R + 7, -16, 18], [A.cx + A.R + 11, -30, 12], [A.cx - 4, -40, 10]]) {+ const k = u / 0.16, y = y0 - 30 * k;+ for (let d = 0; d < L; d += 1) p.dot(dx, y + d, d < 3 ? WHITE : d < L * 0.5 ? C[5] : C[3], (1 - d / L) * (1 - k));+ }+ if (u > 0 && u < A.sweep + 0.06) {+ const [x, y] = onSwing(A, A.R - 5, A.span * ease.outExpo(clamp(u / A.sweep)));+ p.glow(x, y, 34, C[3], 0.45 * (1 - u / (A.sweep + 0.06)));+ }+ // the comic star: pops past full size, holds, then shrinks away turning, with burst lines round it+ const q = t - HIT;+ if (q >= 0 && q < 0.36) {+ const pop = ease.outBack(clamp(q / 0.05), 2.6), out = 1 - smooth(0.16, 0.36, q), sc = pop * (0.35 + 0.65 * out), turn = q * 1.2;+ const sp = spikes.map((s) => ({ ...s, a: s.a + turn }));+ if (sc > 0.08) {+ star(p, SX, SY, sp, sc * 1.12, 1, INK, INK, INK, INK);+ star(p, SX, SY, sp, sc, 1, q < 0.05 ? WHITE : C[6], C[4], C[3], C[2]);+ }+ p.glow(SX, SY, 30, C[4], 0.45 * out);+ }+ if (q >= 0.02 && q < 0.24) {+ // a ring bursts out round the star, white to orange, breaking into dots+ const k = (q - 0.02) / 0.22, r = 7 + 17 * ease.outCubic(k), th = Math.max(1, 2.2 * (1 - k)), col = k < 0.25 ? WHITE : k < 0.5 ? C[5] : k < 0.75 ? C[4] : C[3];+ for (let a = 0; a < TAU; a += 0.6 / r) for (let o = 0; o < th; o += 0.5) p.dot(SX + Math.cos(a) * (r - o), SY + Math.sin(a) * (r - o), col, 1.15 - k);+ }+ if (q >= 0.02 && q < 0.2) {+ const k = (q - 0.02) / 0.18;+ for (const b of bursts) {+ const r0 = b.r0 + 10 * ease.outCubic(k), ca = Math.cos(b.a), sa = Math.sin(b.a);+ p.line(SX + ca * r0, SY + sa * r0, SX + ca * (r0 + b.L * (1 - k)), SY + sa * (r0 + b.L * (1 - k)), k < 0.4 ? WHITE : C[5], 1.1 - k);+ }+ }+ ps.draw(p);+ lights.draw(p);+ },+ };}diff --git a/src/fx/melee/whip-crack.js b/src/fx/melee/whip-crack.jsindex 28fdcf1..2284fb8 100644--- a/src/fx/melee/whip-crack.js+++ b/src/fx/melee/whip-crack.js@@ -1,85 +1,125 @@-import { PAL, ramp, fit, burst, fly, seg, ease, lerp, WHITE } from "../../core/index.js";+// The pop's star and slivers follow Sprite Fusion's open-source impact, and the sparks his slash+// (https://www.spritefusion.com/pixel-art-vfx), MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Lights, P, Rng, fit, clamp, smooth, ease, TAU, WHITE } from "../../core/index.js";+import { star, sliver } from "./_lib.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,+ desc: "A whip rolls out to the right as a loop running down its length, faster and faster, until the tip flips over and cracks: a white pop, a ring of air, sparks and a puff of smoke.",+ tags: ["melee", "whip", "crack", "lash", "combat", "directional", "one-shot"],+ size: [192, 80],+ origin: [30, 68],+ duration: 0.85,loop: false,fps: 30,bg: "ground",- actor: true,- options: { palette: PAL.volt, leather: ["#2a160c", "#4a2a16", "#6e4222", "#8e5a30", "#b07a48"], length: 46, seed: 11 },+ actor: 2,+ options: {+ palette: ["#2a1a10", "#5c3a1e", "#9c6a34", "#d8a45a", "#ffd890", "#fff4d6", "#ffffff"],+ sparks: ["#fff3a6", "#ffe26b", "#ff8a2a", "#f2561d"],+ length: 76,+ seed: 3,+ },};-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+const ROLL0 = 0.02, ROLL = 0.19, CRACK = ROLL0 + ROLL; // the loop runs out; the tip cracks when it gets there+const RECOIL = 0.16;-// 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]);+export function create(o) {+ const C = fit(o.palette, 7), Rg = new Rng(o.seed), ps = new Particles({ rng: Rg, ground: () => 0, sparks: o.sparks }), lights = new Lights();+ const L = o.length, HX = 11, HY = -21, TIP = [HX + L, HY - 1];+ // how far down the whip the loop has run: it starts a third of the way out, cocked, and accelerates+ const lam = (t) => L * (0.34 + 0.66 * ease.inQuad(clamp((t - ROLL0) / ROLL)));+ // the whip as points, handle to tip: straight out to the loop, round the loop, folded back under it+ const shape = (t) => {+ const l = lam(t), r = 6.5 - 3.5 * (l / L), pts = [];+ const recoil = smooth(CRACK + 0.04, CRACK + 0.04 + RECOIL, t), len = L * (1 - recoil * 0.85);+ for (let s = 0; s <= len; s += 1) {+ let x, y;+ if (s <= l) (x = HX + s), (y = HY - Math.sin((Math.PI * s) / Math.max(l, 1)) * 2.5 * (1 - l / L));+ else if (s <= l + Math.PI * r) {+ const th = (s - l) / r;+ (x = HX + l + Math.sin(th) * r), (y = HY + r - Math.cos(th) * r);+ } else (x = HX + l - (s - l - Math.PI * r)), (y = HY + 2 * r);+ // after the crack it sags as it's pulled back in+ if (recoil > 0) y += Math.sin((Math.PI * s) / L) * 6 * recoil;+ pts.push([x, y]);}- }- // 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]);+ return pts;+ };+ const spikes = [0, 0.8, 1.6, 2.4, 3.14, 3.9, 4.7, 5.5].map((a, i) => ({ a: a + Rg.range(-0.15, 0.15), len: (i === 0 ? 13 : i % 2 ? 6 : 9) + Rg.range(0, 3), w: 1.4 + Rg.range(0, 0.5) }));+ const slivers = [-1.2, -0.3, 0.5, 1.3].map((a) => ({ a: a + Rg.range(-0.2, 0.2), r: Rg.range(4, 6), v: Rg.range(80, 120), arc: Rg.range(0.4, 0.7) }));+ let t = 0, cracked = false;+ const tipTrail = [];+ return {+ update(dt) {+ t += dt;+ if (t > CRACK - 0.05 && t < CRACK + 0.01) {+ const pts = shape(t);+ tipTrail.push({ p: pts[pts.length - 1], t });}- }- 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]));+ for (let i = tipTrail.length - 1; i >= 0; i--) if (t - tipTrail[i].t > 0.06) tipTrail.splice(i, 1);+ if (!cracked && t >= CRACK) {+ cracked = true;+ lights.add(TIP[0], TIP[1], 46, C[4], 0.6, 0.3);+ lights.add(TIP[0], TIP[1], 14, WHITE, 0.8, 0.07);+ for (let i = 0; i < 16; i++) {+ const a = Rg.range(-1.3, 1.2), sp = Rg.range(130, 300);+ ps.spawn(P.SPARK, TIP[0], TIP[1], Math.cos(a) * sp, Math.sin(a) * sp - 40, Rg.range(0.12, 0.36));+ }+ for (let i = 0; i < 3; i++) ps.spawn(P.SMOKE, TIP[0] + Rg.range(-2, 3), TIP[1] + Rg.range(-2, 2), Rg.range(10, 40), -Rg.range(6, 18), Rg.range(0.5, 0.8), C[2], Rg.range(2.5, 4), Rg.range(0.02, 0.06));+ for (let i = 0; i < 4; i++) ps.spawn(P.STAR, TIP[0] + Rg.range(-8, 10), TIP[1] + Rg.range(-8, 8), 0, -3, Rg.range(0.2, 0.4), Rg.chance(0.5) ? C[5] : WHITE, Rg.range(0.8, 1.8), Rg.range(0.05, 0.2));}- }- 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));- });- }+ ps.update(dt);+ lights.update(dt);+ },+ draw(p) {+ const end = CRACK + 0.04 + RECOIL;+ if (t < end) {+ const fade = 1 - smooth(end - 0.06, end, t);+ // afterimages of the whip a beat and two beats back: the loop's motion+ if (t < CRACK)+ for (const [lag, c, a] of [[0.03, C[1], 0.5], [0.015, C[2], 0.7]]) {+ const old = shape(Math.max(0, t - lag));+ for (let i = 1; i < old.length; i += 2) p.dot(old[i][0], old[i][1], c, a);+ }+ // the whip: thicker and lit near the handle, a single line to the tip+ const pts = shape(t), n = pts.length, l = lam(t), r = 6.5 - 3.5 * (l / L);+ for (let i = 1; i < n; i++) {+ const [x0, y0] = pts[i - 1], [x1, y1] = pts[i], u = i / n, s = i;+ // the loop's leading half is moving fastest: it runs hot+ const inLoop = t < CRACK && s > l && s < l + Math.PI * r, lead = inLoop && Math.abs(s - l - (Math.PI * r) / 2) < r * 0.9;+ p.line(x0, y0, x1, y1, lead ? WHITE : inLoop ? C[5] : u < 0.5 ? C[4] : C[3], fade);+ if (u < 0.4) p.line(x0, y0 + 1, x1, y1 + 1, C[2], fade);+ }+ // the running loop is the fastest part: it shines+ if (t < CRACK) {+ const l = lam(t), r = 6.5 - 3.5 * (l / L);+ p.glow(HX + l + r, HY + r, 12, C[4], 0.4);+ }+ }+ // the tip's path just before the crack: a white-hot streak+ for (let i = 1; i < tipTrail.length; i++) {+ const k = 1 - (t - tipTrail[i].t) / 0.06;+ p.line(tipTrail[i - 1].p[0], tipTrail[i - 1].p[1], tipTrail[i].p[0], tipTrail[i].p[1], k > 0.6 ? WHITE : C[5], k);+ }+ // the crack: a white pop, a ring of air, slivers+ const q = t - CRACK;+ if (q >= 0 && q < 0.035) star(p, TIP[0], TIP[1], spikes, 1, 1, WHITE, C[5], C[6], C[4]);+ else if (q >= 0.035 && q < 0.07) star(p, TIP[0], TIP[1], spikes, 1.3, 0.5, C[6], C[5], C[5], C[3]);+ if (q >= 0.02 && q < 0.2) {+ const k = (q - 0.02) / 0.18, r = 4 + 16 * ease.outCubic(k), th = Math.max(1, 2.2 * (1 - k)), col = k < 0.25 ? WHITE : k < 0.5 ? C[5] : k < 0.75 ? C[4] : C[3];+ for (let a = 0; a < TAU; a += 0.6 / r)+ for (let o = 0; o < th; o += 0.5) p.dot(TIP[0] + Math.cos(a) * (r - o), TIP[1] + Math.sin(a) * (r - o) * 0.8, col, 1.15 - k);+ p.glow(TIP[0], TIP[1], r + 6, C[4], 0.25 * (1 - k));+ }+ if (q >= 0.04 && q < 0.16) {+ const k = (q - 0.04) / 0.12;+ for (const s of slivers) sliver(p, TIP[0], TIP[1], s.a, s.r + s.v * (q - 0.04), s.arc * (1 - 0.4 * k), k < 0.4 ? C[6] : C[5], 1 - k);+ }+ if (q >= 0 && q < 0.15) p.glow(TIP[0], TIP[1], 26, C[5], 0.7 * Math.exp(-q / 0.04));+ ps.draw(p);+ lights.draw(p);+ },+ };}diff --git a/src/fx/nature/_lib.js b/src/fx/nature/_lib.jsnew file mode 100644index 0000000..e773ce9--- /dev/null+++ b/src/fx/nature/_lib.js@@ -0,0 +1,342 @@+// Shared by the nature effects: faceted stones that tumble and break, the stone spike they break from, leaves,+// droplets, bubbles and gas. The gas (puffs that drift off their push, rise, swell and thin, a lit cap) is adapted+// from Sprite Fusion's open-source poison (https://www.spritefusion.com/pixel-art-vfx/poison), MIT License, Copyright (c) 2026 Hugo Duprez.+import { TAU, WHITE, GRAVITY, rand, clamp } from "../../core/index.js";++/** Corners of an irregular stone, unit size, in angular order. */+export function stoneShape(R, n = R.int(5, 7)) {+ const pts = [], a0 = R.range(0, TAU), squash = R.range(0.7, 1);+ for (let i = 0; i < n; i++) {+ const a = a0 + ((i + R.range(-0.28, 0.28)) * TAU) / n, r = R.range(0.72, 1.12);+ pts.push([Math.cos(a) * r, Math.sin(a) * r * squash]);+ }+ return pts;+}++const LX = -0.6, LY = -0.8;+const inPoly = (V, x, y) => {+ let inside = false;+ for (let i = 0, j = V.length - 1; i < V.length; j = i++) {+ const [xi, yi] = V[i], [xj, yj] = V[j];+ if (yi > y !== yj > y && x < ((xj - xi) * (y - yi)) / (yj - yi) + xi) inside = !inside;+ }+ return inside;+};+const MASK = new Uint8Array(64 * 64), FACE = new Int8Array(64 * 64), ROWS = 400, RL = new Float32Array(ROWS), RR = new Float32Array(ROWS), RU = new Float32Array(ROWS);++/**+ * A faceted stone at (x, y): corners pts (from stoneShape) scaled by s and turned by a. Each wedge between+ * neighbouring corners is a facet, lit by how squarely it faces the top left; edges facing the light catch a+ * bright rim, a dark rim goes round the rest. S: stone ramp, dark to bright (7+ steps). alpha dithers it out.+ */+export function drawRock(p, x, y, s, a, pts, S, alpha = 1, white = false) {+ const n = S.length, top = n - 2, ca = Math.cos(a), sa = Math.sin(a);+ if (s < 1.4) {+ p.dot(x, y, S[top - 1], alpha);+ p.dot(x + 1, y, S[top - 3], alpha);+ return;+ }+ const V = pts.map(([u, v]) => [(u * ca - v * sa) * s, (u * sa + v * ca) * s]);+ const ang = V.map(([vx, vy]) => Math.atan2(vy, vx));+ // each facet's light: its edge's outward normal against the light+ const lit = V.map(([ax, ay], i) => {+ const [bx, by] = V[(i + 1) % V.length], ex = bx - ax, ey = by - ay, l = Math.hypot(ex, ey) || 1;+ let nx = ey / l, ny = -ex / l;+ if (nx * (ax + bx) + ny * (ay + by) < 0) (nx = -nx), (ny = -ny);+ return nx * LX + ny * LY;+ });+ const X0 = Math.floor(x) - Math.ceil(s * 1.25) - 1, Y0 = Math.floor(y) - Math.ceil(s * 1.25) - 1, N = Math.min(62, 2 * Math.ceil(s * 1.25) + 3);+ for (let j = 0; j < N; j++)+ for (let i = 0; i < N; i++) {+ const dx = X0 + i + 0.5 - x, dy = Y0 + j + 0.5 - y, k = j * 64 + i;+ MASK[k] = inPoly(V, dx, dy) ? 1 : 0;+ if (!MASK[k]) continue;+ const g = Math.atan2(dy, dx);+ let f = 0;+ for (let q = 0; q < ang.length; q++) {+ const a0 = ang[q], a1 = ang[(q + 1) % ang.length];+ let d = (g - a0) % TAU, span = (a1 - a0) % TAU;+ if (d < 0) d += TAU;+ if (span < 0) span += TAU;+ if (d <= span) {+ f = q;+ break;+ }+ }+ FACE[k] = f;+ }+ const at = (i, j) => i >= 0 && j >= 0 && i < N && j < N && MASK[j * 64 + i] === 1;+ for (let j = -1; j <= N; j++)+ for (let i = -1; i <= N; i++) {+ const X = X0 + i, Y = Y0 + j;+ if (!at(i, j)) {+ if (at(i - 1, j) || at(i + 1, j) || at(i, j - 1) || at(i, j + 1)) p.dot(X, Y, S[0], alpha);+ continue;+ }+ if (white) {+ p.dot(X, Y, WHITE, alpha);+ continue;+ }+ const L = lit[FACE[j * 64 + i]], edge = !at(i - 1, j) || !at(i + 1, j) || !at(i, j - 1) || !at(i, j + 1);+ let c = L > 0.55 ? S[top] : L > 0.15 ? S[top - 1] : L > -0.3 ? S[top - 2] : S[top - 3];+ if (edge) c = L > 0.3 ? S[top + 1] : L < -0.2 ? S[Math.max(1, top - 4)] : c;+ p.dot(X, Y, c, alpha);+ }+}++/**+ * A faceted stone spike standing on (x, base): h tall, w wide at the base, its tip `lean` px over. A ridge+ * splits a lit left face from a shaded right face; strata step across both; notches chip the edges; a dark+ * rim goes round it. sp: { notches: [{ u, side, d }], strata: [u], slope } from spikeLook(). S: stone ramp+ * (8 steps). opts: { a, white, glint (0..1 height of a sweeping highlight, or -1), clip (draw only u < clip, with a+ * ragged edge), half (-1 or 1: only the part left or right of the ridge), floor (draw nothing below this y),+ * cracks: [[[u, v], ...], ...] with crack (0..1 of each drawn), heat (0..1: cracks glow) and glowRamp }.+ */+export function drawSpike(p, x, base, h, w, lean, sp, S, opts = {}) {+ if (h < 1.5) return;+ const a = opts.a ?? 1, white = opts.white, glint = opts.glint ?? -1, clip = opts.clip ?? 1, floorY = opts.floor ?? Infinity;+ const hw = (u, side) => {+ let v = (w / 2) * Math.pow(Math.max(0, 1 - u), 0.85) + 0.3;+ for (const n of sp.notches) if (n.side === side && u > n.u && u < n.u + 0.07) v -= n.d * (1 - u * 0.5);+ return Math.max(0, v);+ };+ const half = opts.half ?? 0, Y0 = Math.floor(base - h) - 2, NR = Math.min(ROWS, Math.ceil(base) - Y0 + 2);+ // each row's edges, once+ for (let k = 0; k < NR; k++) {+ const u = (base - (Y0 + k + 0.5)) / h;+ RU[k] = u;+ if (u < 0 || u > 1 || Y0 + k + 0.5 > floorY) (RL[k] = Infinity), (RR[k] = -Infinity);+ else (RL[k] = x + lean * u - hw(u, -1)), (RR[k] = x + lean * u + hw(u, 1));+ }+ const inside = (px, py) => {+ const k = py - Y0, fx = px + 0.5;+ if (k < 0 || k >= NR || fx < RL[k] || fx > RR[k]) return false;+ if (clip < 1 && RU[k] > clip + (rand(px, 77) - 0.5) * 0.07) return false;+ if (!half) return true;+ const q = ((fx - RL[k]) / Math.max(0.5, RR[k] - RL[k])) * 2 - 1;+ return half < 0 ? q < -0.18 : q >= -0.18;+ };+ const X0 = Math.floor(x - w / 2 - Math.abs(lean) - 2), X1 = Math.ceil(x + w / 2 + Math.abs(lean) + 2);+ for (let py = Math.floor(base - h) - 1; py < Math.ceil(base); py++)+ for (let px = X0; px <= X1; px++) {+ if (!inside(px, py)) {+ if (py + 0.5 <= floorY && (inside(px - 1, py) || inside(px + 1, py) || inside(px, py + 1) || (inside(px, py - 1) && py < base - 1))) p.dot(px, py, S[0], a);+ continue;+ }+ if (white) {+ p.dot(px, py, WHITE, a);+ continue;+ }+ const k0 = py - Y0, u = RU[k0], c = x + lean * u, l = RL[k0], r = RR[k0], fx = px + 0.5;+ // which stratum this row sits in: facets jog sideways at each bedding plane, like stacked rock+ let band = 0, st = false;+ for (const s of sp.strata) {+ const d = u * h - s * h - sp.slope * (fx - c);+ if (d > 0) band++;+ if (Math.abs(d) < 0.5) st = true;+ }+ const jog = (rand(band, sp.seed) - 0.5) * 0.3, q = ((fx - l) / Math.max(0.5, r - l)) * 2 - 1, qr = -0.18 + jog;+ let i;+ if (u > 0.93) i = q < qr + 0.3 ? 7 : 5;+ else if (Math.abs(q - qr) < Math.max(0.09, 0.55 / Math.max(1, r - l))) i = 7;+ else if (q < qr) i = fx - l < 1 ? 7 : q < -0.5 + jog ? 6 : 5;+ else i = r - fx < 1 ? 3 : q < 0.38 + jog ? 4 : 2;+ if (st && i < 7) i -= 1;+ const fleck = rand(px * 7 + 3, py * 13 + 5);+ if (fleck < 0.035) i = q < qr ? 7 : i - 1;+ else if (fleck > 0.965) i -= 1;+ if (glint >= 0 && q < qr + 0.1) {+ const g = Math.abs(u - glint);+ if (g < 0.035) i = 8;+ else if (g < 0.07) i = Math.max(i, 7);+ }+ p.dot(px, py, i >= 8 ? WHITE : S[clamp(i, 0, S.length - 1)], a);+ }+ // cracks spreading over it, a lit lip on one side of each+ if (opts.cracks && opts.crack > 0)+ for (const path of opts.cracks) {+ const m = Math.max(1, Math.floor(path.length * opts.crack));+ for (let k = 1; k < m; k++) {+ const [u0, v0] = path[k - 1], [u1, v1] = path[k];+ const P = ([u, v]) => [x + lean * u + v * hw(u, v < 0 ? -1 : 1), base - u * h];+ const [ax, ay] = P([u0, v0]), [bx, by] = P([u1, v1]);+ if (u1 > clip) break;+ if (!inside(Math.floor(ax), Math.floor(ay)) || !inside(Math.floor(bx), Math.floor(by))) continue;+ const hot = opts.heat ?? 0, Gl = opts.glowRamp;+ if (hot > 0.05 && Gl) {+ // a seam of light inside the crack, a dark lip below it+ p.line(ax + 1, ay, bx + 1, by, S[0], a);+ p.line(ax, ay, bx, by, hot > 0.7 ? Gl[4] : hot > 0.4 ? Gl[3] : hot > 0.2 ? Gl[2] : Gl[1], a);+ if (k % 2 === 0) p.glow(bx, by, 7, Gl[2], 0.35 * hot);+ } else {+ p.line(ax, ay, bx, by, S[0], a);+ p.dot(bx + 1, by - 1, S[6], a * 0.7);+ }+ }+ }+}++/** The random look of one spike: notches on its edges, strata across it. */+export function spikeLook(R) {+ const notches = [], strata = [];+ for (let i = 0, n = R.int(3, 5); i < n; i++) notches.push({ u: R.range(0.1, 0.8), side: R.sign(), d: R.range(0.8, 1.8) });+ for (let i = 0, n = R.int(2, 4); i < n; i++) strata.push(R.range(0.12, 0.8));+ return { notches, strata, slope: R.range(-0.25, 0.25), seed: R.int(1, 9999) };+}++/** A crack that branches up a spike: points [u (height 0..1), v (-1 left edge..1 right edge)]. */+export function spikeCrack(R, u0, v0, dir) {+ const pts = [[u0, v0]];+ let u = u0, v = v0;+ for (let i = 0; i < 9; i++) {+ u += R.range(0.03, 0.08);+ v += dir * R.range(0.05, 0.28) + R.range(-0.12, 0.12);+ if (u > 0.95 || Math.abs(v) > 1) break;+ pts.push([u, v]);+ }+ return pts;+}++/** A jagged floor crack from x = 0 out to side * len: points [x, y], y 0..3 into the floor. */+export function floorCrack(R, side, len) {+ const pts = [[0, 0]];+ for (let x = 0; Math.abs(x) < len; ) {+ x += side * R.range(2, 5);+ pts.push([x, R.int(0, 2)]);+ }+ return pts;+}++/**+ * A leaf len px long and wid px across at its widest, centered on (x, y), turned by ang and flipping about its+ * midrib by fl (radians: edge on at pi/2, its paler underside showing past it). A pointed blade, lit along its+ * upper half and shaded along the lower, a darker midrib, a stem, a dark rim. pal: [dark, shade, body, light]+ * (dark to bright). alpha dithers it out.+ */+export function drawLeaf(p, x, y, len, wid, ang, fl, pal, alpha = 1) {+ const ca = Math.cos(ang), sa = Math.sin(ang), sq = Math.cos(fl), w = Math.max(0.55, Math.abs(sq) * wid), under = sq < 0;+ const R = Math.ceil(len / 2 + 2), X = Math.round(x), Y = Math.round(y);+ const inside = (i, j) => {+ const u = (i + 0.5) * ca + (j + 0.5) * sa + len / 2, v = -(i + 0.5) * sa + (j + 0.5) * ca;+ if (u < 0 || u > len) return 0;+ const half = w * Math.pow(Math.sin((Math.PI * u) / len), 0.75);+ return Math.abs(v) <= half ? (v < 0 ? 1 : 2) : 0;+ };+ for (let j = -R; j <= R; j++)+ for (let i = -R; i <= R; i++) {+ const s = inside(i, j);+ if (!s) {+ if (inside(i - 1, j) || inside(i + 1, j) || inside(i, j - 1) || inside(i, j + 1)) p.dot(X + i, Y + j, pal[0], alpha);+ continue;+ }+ const u = (i + 0.5) * ca + (j + 0.5) * sa + len / 2, v = -(i + 0.5) * sa + (j + 0.5) * ca;+ const rib = Math.abs(v) < 0.5 && u > len * 0.12 && u < len * 0.88 && w > 1.2;+ p.dot(X + i, Y + j, rib ? pal[1] : (s === 1) !== under ? pal[3] : pal[2], alpha);+ }+ // the stem trails off the base+ p.dot(X - ca * (len / 2 + 1), Y - sa * (len / 2 + 1), pal[1], alpha);+}++/**+ * Droplets of liquid: arc under gravity with a little drag, drawn as a bright bead with a short tail along+ * their motion, and land on the floor (onLand(d, y) in update, then they're gone). add(x, y, vx, vy, s, delay).+ */+export class Drops {+ constructor(ground = () => 0) {+ this.list = [];+ this.ground = ground;+ }+ add(x, y, vx, vy, s = 1, delay = 0) {+ this.list.push({ x, y, vx, vy, s, delay });+ }+ update(dt, onLand) {+ for (let i = this.list.length - 1; i >= 0; i--) {+ const d = this.list[i];+ if (d.delay > 0) {+ d.delay -= dt;+ continue;+ }+ const drag = 0.6 / d.s, py = d.y;+ d.vy += GRAVITY * dt;+ d.vx -= d.vx * drag * dt;+ d.vy -= d.vy * drag * 0.5 * dt;+ d.x += d.vx * dt;+ d.y += d.vy * dt;+ const g = this.ground(d.x);+ if (d.vy > 0 && py <= g && d.y >= g) {+ onLand?.(d, g);+ this.list.splice(i, 1);+ }+ }+ }+ /** C: the liquid's ramp, dark to bright (5+ steps). */+ draw(p, C) {+ const n = C.length;+ for (const d of this.list) {+ if (d.delay > 0) continue;+ const sp = Math.hypot(d.vx, d.vy) || 1, ux = d.vx / sp, uy = d.vy / sp, len = Math.min(5, 0.5 + sp * 0.012);+ p.line(d.x - ux * len, d.y - uy * len, d.x - ux, d.y - uy, C[n - 4]);+ p.px(d.x, d.y, C[n - 1]);+ if (d.s > 1) p.px(d.x - ux, d.y - uy, C[n - 2]), p.px(d.x + 1, d.y, C[n - 3]);+ p.glow(d.x, d.y, 3 + d.s * 1.5, C[n - 2], 0.3);+ }+ }+}++/** A puff of gas: a darker belly hanging low, a body, a denser core, a lit cap up and to the left (hi: a rim). */+export function gasPuff(p, x, y, r, a, belly, body, cap, hi = 0) {+ if (a < 0.02 || r < 0.6) return;+ p.disc(x + r * 0.06, y + r * 0.28, r * 0.9, belly, a * 0.55);+ p.disc(x, y, r, body, a * 0.45);+ p.disc(x + r * 0.03, y - r * 0.02, r * 0.76, body, a * 0.5);+ p.disc(x - r * 0.2, y - r * 0.34, r * 0.52, cap, a * 0.45);+ if (hi) p.disc(x - r * 0.3, y - r * 0.55, r * 0.26, hi, a * 0.32);+}++/**+ * A bubble of radius r centered at (x, y): a 1 px skin (lit c1 on its upper left, c2 elsewhere), a+ * translucent belly, a white glint. dome: only the part above y (a bubble swelling on a surface).+ */+export function bubble(p, x, y, r, c1, c2, fill, a = 1, dome = false) {+ const R = Math.ceil(r) + 1, X = Math.round(x), Y = Math.round(y);+ for (let j = -R; j <= (dome ? 0 : R); j++)+ for (let i = -R; i <= R; i++) {+ const d = Math.hypot(i, j);+ if (d > r + 0.45) continue;+ if (d > r - 0.6) p.dot(X + i, Y + j, i < 0 && j < -r * 0.2 ? c1 : c2, a);+ else p.blend(X + i, Y + j, fill, 0.3 * a);+ }+ if (r >= 1.5) p.dot(X - Math.round(r * 0.45), Y - Math.round(r * 0.5), WHITE, a);+}++/**+ * Puffs of gas with their own clock: add(t, x, y, vx, vy, r0, r1, end, rise) launches one at time t that drifts+ * off its push (fading drag), rises at `rise` px/s, sways, swells from r0 to r1 and thins out by `end`. Draw+ * them with draw(p, t, belly, body, cap, hi, k): layered translucent puffs, a little light on the big ones.+ */+export class Gas {+ constructor() {+ this.list = [];+ this.n = 0;+ }+ add(t, x, y, vx, vy, r0, r1, end, rise = 0) {+ this.list.push({ x, y, vx, vy, r0, r1, t0: t, end, rise, seed: (this.n++ * 37.7) % 100 });+ }+ prune(t) {+ for (let i = this.list.length - 1; i >= 0; i--) if (t > this.list[i].end) this.list.splice(i, 1);+ }+ at(q, t) {+ const age = t - q.t0, e = 1 - Math.exp(-age * 2.2), sw = Math.min(1, age);+ const x = q.x + (q.vx / 2.2) * e + Math.sin(t * 1.7 + q.seed) * 2.5 * sw, y = q.y + (q.vy / 2.2) * e - q.rise * age + Math.sin(t * 1.3 + q.seed * 2) * 1.5 * sw;+ const u = clamp(age / Math.max(0.01, q.end - q.t0)), r = q.r0 + (q.r1 - q.r0) * (1 - Math.pow(1 - Math.min(1, age / 1.2), 3));+ return { x, y, r, a: clamp(age / 0.15) * (1 - clamp((u - 0.4) / 0.6)), u };+ }+ draw(p, t, belly, body, cap, hi = 0, k = 1, glow = 0) {+ for (const q of this.list) {+ const g = this.at(q, t);+ if (g.a <= 0.02) continue;+ gasPuff(p, g.x, g.y, g.r, g.a * k, belly, body, cap, g.u < 0.5 ? hi : 0);+ if (glow && g.r > 4) p.glow(g.x, g.y, g.r * 1.6, glow, 0.07 * g.a * k);+ }+ }+}diff --git a/src/fx/nature/acid-splash.js b/src/fx/nature/acid-splash.jsindex 3b400e8..7ba1254 100644--- a/src/fx/nature/acid-splash.js+++ b/src/fx/nature/acid-splash.js@@ -1,112 +1,207 @@-import { ramp, at, burst, stream, fly, flyV, seg, ease, clamp, noise, TAU, hex } from "../../core/index.js";+// The drops that splat where they land are adapted from Sprite Fusion's open-source blood+// (https://www.spritefusion.com/pixel-art-vfx/blood), MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Lights, P, Rng, fit, sparkle, clamp, smooth, ease, noise, rand, TAU, WHITE, mix, hex } from "../../core/index.js";+import { Drops } from "./_lib.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,+ desc: "A gob of acid bursts into a crown and spatters; it eats a glowing, smoking pit into the floor and boils down into it, spitting bright beads, pale steam curling off.",+ tags: ["nature", "acid", "poison", "splash", "liquid", "ground", "one-shot"],+ size: [184, 116],+ origin: [92, 100],+ duration: 2.8,loop: false,fps: 30,bg: "ground",- options: {- palette: ["#1d2208", "#35420c", "#55700f", "#7fa214", "#acd21c", "#d8f040", "#f6ffa6"],- size: 1,- seed: 11,- },+ options: { palette: ["#0e140a", "#1c3010", "#2c5214", "#457e18", "#6aae1c", "#a0dc2a", "#dcff6a", "#f8ffd0"], seed: 6 },};-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+const HIT = 0.3, Y0 = -62, V0 = 60, SPREAD = 0.4, DRY = 0.7, GONE = 2.2, W = 30, PIT = 5;-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;+// a curl of steam: thin, pale, quick, fading as it goes+function wisp(p, q, t, col) {+ const age = t - q.t0, u = age / q.life;+ if (u < 0 || u >= 1) return;+ const head = q.rise * age, tail = Math.max(0, head - q.len), fade = smooth(0, 0.15, u) * (1 - smooth(0.4, 1, u));+ for (let h = tail; h <= head; h += 0.5) {+ const s = (h - tail) / Math.max(1, head - tail), x = q.x + q.amp * Math.sin(h * q.k + q.ph) * (0.2 + s) + q.drift * age;+ p.blend(x, q.y - h, col, fade * Math.sin(Math.PI * s) * 0.42);}- 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]);+}++export function create(o) {+ const C = fit(o.palette, 8), R = new Rng(o.seed), floor = () => 0;+ const SCORCH = mix(C[0], hex("#140f0c"), 0.6), BURNT = mix(C[1], hex("#2a1a10"), 0.6), STEAM = mix(C[7], hex("#e8ece6"), 0.75);+ const ps = new Particles({ rng: R, ground: floor, sparks: [C[7], C[6], C[5], C[4]] });+ const drops = new Drops(floor), lights = new Lights(), stains = [], wisps = [], pops = [];+ const spikes = Array.from({ length: 13 }, (_, i) => ({ a: (i / 13) * TAU + R.range(-0.18, 0.18), h: R.range(4, 10), r: R.range(0.85, 1.12), shed: false }));+ const rag = Array.from({ length: 80 }, (_, i) => rand(i, o.seed, 5) - 0.5);+ let t = 0, hit = false;+ // the pit it etches: wider as it spreads, deeper as it eats; the acid's level sinks into it as it boils away+ const pw = () => W * ease.outCubic(clamp((t - HIT) / SPREAD)) * 1.02;+ const pitD = () => PIT * ease.outCubic(clamp((t - HIT) / 1.1));+ const depth = (x) => {+ const w = pw(), d = Math.abs(x) / Math.max(1, w);+ return d >= 1 ? -1 : pitD() * Math.sqrt(1 - d * d) + rag[(Math.round(x) + 200) % 80] * 0.9;+ };+ const level = () => (t < HIT ? 0 : -1.6 + (PIT + 1.6) * ease.inQuad(smooth(DRY, GONE, t)));+ const width = () => {+ const L = level(), w = pw();+ return L <= 0 ? w : w * Math.sqrt(Math.max(0, 1 - (L / Math.max(0.1, pitD())) ** 2));+ };+ const heat = () => smooth(HIT, HIT + 0.3, t) * (1 - smooth(GONE - 0.3, GONE + 0.25, t));+ const gobY = () => Y0 + V0 * t + 0.5 * 950 * t * t;+ const crownR = () => 4 + 11 * ease.outCubic(clamp((t - HIT) / 0.16));+ const crownH = () => 5 * Math.sin(Math.PI * clamp((t - HIT) / 0.26));+ const spikeK = () => {+ const u = clamp((t - HIT - 0.015) / 0.26);+ return Math.sin(Math.PI * Math.pow(u, 0.6));+ };+ const tipOf = (s) => {+ const r = crownR() * s.r, h = crownH(), sn = Math.sin(s.a), sh = s.h * spikeK();+ const bx = Math.cos(s.a) * r, by = sn * r * 0.3 - h * (0.75 + 0.25 * Math.abs(sn));+ return [bx, by, bx + Math.cos(s.a) * sh * 0.55, by - sh];+ };+ const steam = (x, y, big) => wisps.push({ x, y, t0: t, life: Math.min(R.range(0.5, 0.9) * (big ? 1.3 : 1), meta.duration - 0.05 - t), rise: R.range(22, 32), len: R.range(5, 10) * (big ? 1.4 : 1), amp: R.range(1, 2.5), k: R.range(0.35, 0.6), ph: R.range(0, TAU), drift: R.range(-4, 4) });+ // the crown: a thin cup wall rising round the impact, a bright rim, spikes off the rim with beads on their tips+ const crown = (p, back) => {+ if (t < HIT || t > HIT + 0.27) return;+ const r = crownR(), h = crownH(), ry = r * 0.3;+ for (let x = Math.floor(-r); x <= Math.ceil(r); x++) {+ const c = (x + 0.5) / r;+ if (Math.abs(c) > 1) continue;+ const e = Math.sqrt(1 - c * c), yb = (back ? -ry : ry) * e, hh = h * (0.75 + 0.25 * e);+ for (let y = Math.floor(yb - hh); y <= Math.round(yb); y++) {+ const rim = y === Math.floor(yb - hh);+ if (rim) p.px(x, y, back ? C[5] : c < 0.1 ? C[7] : C[6]);+ else p.blend(x, y, C[(c < -0.25 ? 5 : c > 0.45 ? 3 : 4) - (back ? 1 : 0)], back ? 0.55 : 0.7);+ }}- });- // 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);+ for (const s of spikes) {+ if (Math.sin(s.a) < 0 !== back) continue;+ const [bx, by, tx, ty] = tipOf(s);+ p.line(bx, by, tx, ty, back ? C[4] : C[6]);+ p.line(bx + 1, by, (bx + tx) / 2 + 0.5, (by + ty) / 2, back ? C[3] : C[5]);+ if (!s.shed) p.px(tx, ty - 1, back ? C[5] : C[7]), p.px(tx + 1, ty - 1, C[5]);}- });- 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);+ };++ return {+ update(dt) {+ t += dt;+ const f = Math.min(1, dt * 120), w = width();+ if (!hit && t >= HIT) {+ hit = true;+ lights.add(0, -4, 28, WHITE, 0.6, 0.08);+ lights.add(0, -10, 56, C[5], 0.5, 0.6);+ for (let i = 0; i < 26; i++) {+ const a = -Math.PI / 2 + R.range(-1.35, 1.35), sp = R.range(60, 250);+ drops.add(R.range(-3, 3), -2, Math.cos(a) * sp, Math.sin(a) * sp, R.chance(0.3) ? 2 : 1);+ }+ for (let i = 0; i < 10; i++) {+ const a = -Math.PI / 2 + R.range(-1.2, 1.2), sp = R.range(120, 260);+ ps.spawn(P.SPARK, 0, -2, Math.cos(a) * sp, Math.sin(a) * sp, R.range(0.12, 0.3));+ }+ for (let i = 0; i < 5; i++) steam(R.range(-10, 10), -R.range(2, 6), true);+ }+ // beads break off the crown's spikes as they peak+ if (hit)+ for (const s of spikes)+ if (!s.shed && t > HIT + 0.09) {+ s.shed = true;+ const [, , tx, ty] = tipOf(s);+ drops.add(tx, ty - 1, Math.cos(s.a) * R.range(30, 80), -R.range(50, 130), R.chance(0.4) ? 2 : 1);+ }+ drops.update(dt, (d) => {+ // a drop that lands eats a little spot into the floor and hisses+ if (Math.abs(d.x) > pw()) stains.push({ x: d.x, t0: t, w: d.s * 0.8 + R.range(0.3, 1.2) });+ if (t < GONE) steam(d.x, -1, false);+ });+ // the acid sizzles: tiny bright beads spit off it, pops flash on its surface, steam curls off it and the pit+ const lv = level(), w2 = width();+ if (t > HIT + 0.15 && t < GONE && w2 > 2) {+ if (R.chance(0.3 * f)) {+ const x = R.range(-0.85, 0.85) * w2, y = Math.min(lv, depth(x)) - 1;+ pops.push({ x, y, t0: t });+ for (let j = 0; j < R.int(1, 3); j++) drops.add(x, Math.min(y - 1, -1), R.range(-40, 40), -R.range(50, 110), 1);+ }+ if (R.chance(0.14 * f)) steam(R.range(-0.9, 0.9) * w2, Math.min(lv, 0) - 1, R.chance(0.25));+ }+ // the pit keeps smoking a while after the acid is gone+ if (t > GONE - 0.2 && t < meta.duration - 0.5 && R.chance(0.08 * f)) steam(R.range(-0.7, 0.7) * pw(), 0, false);+ for (let i = pops.length - 1; i >= 0; i--) if (t - pops[i].t0 > 0.1) pops.splice(i, 1);+ for (let i = wisps.length - 1; i >= 0; i--) if (t - wisps[i].t0 > wisps[i].life) wisps.splice(i, 1);+ ps.update(dt);+ lights.update(dt);+ },+ drawBack(p) {+ const fade = 1 - smooth(meta.duration - 0.6, meta.duration - 0.08, t), hk = heat(), w = pw(), lv = level();+ // spatter spots etched round it+ for (const s of stains) {+ const age = t - s.t0, k = 1 - smooth(1, 1.8, age), c = age < 0.15 ? C[7] : age < 0.5 ? C[6] : age < 0.9 ? C[4] : BURNT;+ for (let x = Math.floor(s.x - s.w); x <= Math.ceil(s.x + s.w); x++) p.dot(x, 0, Math.abs(x - s.x) < s.w * 0.5 ? SCORCH : c, k * fade);+ if (age < 0.5) p.glow(s.x, -1, 5, C[5], 0.3 * (1 - age / 0.5));+ }+ crown(p, true);+ if (t > HIT && w > 1) {+ // the pit: an etched bowl in the floor, its edge glowing where the acid is still eating, cooling to a burnt lip+ for (let x = Math.floor(-w) - 1; x <= Math.ceil(w) + 1; x++) {+ const dp = depth(x + 0.5);+ if (dp < 0) continue;+ const bottom = Math.max(0, Math.round(dp)), edge = Math.abs(x + 0.5) / w > 0.88;+ for (let y = 0; y <= bottom; y++) p.dot(x, y, y === bottom ? (hk > 0.5 ? C[6] : hk > 0.15 ? C[4] : BURNT) : SCORCH, fade);+ p.dot(x, bottom + 1, hk > 0.5 ? C[5] : hk > 0.15 ? C[3] : SCORCH, fade * 0.8);+ if (edge) p.dot(x, -1, hk > 0.4 ? C[7] : hk > 0.1 ? C[5] : BURNT, fade);+ }+ for (const sd of [-1, 1]) p.glow(sd * w, -1, 8, C[6], 0.45 * hk);+ // the acid in it: a bright skin shimmering on top, darker as it deepens, sinking as it boils off+ if (t < GONE)+ for (let x = Math.floor(-w); x <= Math.ceil(w); x++) {+ const dp = depth(x + 0.5);+ if (dp < 0) continue;+ const d = Math.abs(x + 0.5) / w, dome = lv < 0 ? Math.round(lv * Math.sqrt(Math.max(0, 1 - d * d))) : Math.round(lv), bottom = Math.round(dp);+ if (dome > bottom) continue;+ const n = noise(x * 0.25 - t * 2.4, 3) + noise(x * 0.1 + t * 1.4, 5) * 0.6;+ for (let y = dome; y <= bottom; y++) p.px(x, y, y === dome ? (n > 0.7 ? C[7] : C[6]) : y === dome + 1 ? (n > 0.2 ? C[5] : C[4]) : y >= bottom ? C[3] : C[4]);+ }+ p.glow(0, -6, w * 1.4 + 10, C[4], 0.3 * hk * (0.85 + 0.15 * Math.sin(t * 9)));+ p.glow(0, 1, w * 0.9, C[6], 0.2 * hk);+ }+ ps.draw(p, "back");+ },+ draw(p) {+ // the gob: a teardrop stretched by its fall, lit on its upper left, a trail of droplets above it+ if (t < HIT) {+ const y = gobY(), v = V0 + 950 * t, st = 1 + v * 0.0022, rx = 2.6 / Math.sqrt(st), ry = 2.8 * st;+ p.shade(-rx - 1, y - ry - 4, rx + 1, y + ry + 1, (x, yy, out) => {+ const dx = x / rx, dy = (yy - y) / ry, tail = dy < 0 && Math.abs(x) < rx * (1 + dy * 0.9) + 0.4 && dy > -1.7;+ const d = dx * dx + dy * dy;+ if (d > 1.25 && !tail) return;+ out.c = d > 1 && !tail ? C[2] : dx < -0.2 && dy < -0.1 ? C[7] : dy > 0.45 ? C[4] : C[5];+ });+ p.px(-1, y - ry * 0.3, WHITE);+ for (let i = 1; i <= 3; i++) p.dot(0, y - ry - 2 - i * 4, C[5], 1 - i * 0.25);+ p.glow(0, y, 10, C[5], 0.45);+ }+ crown(p, false);+ // the hero frame: a white burst where it lands+ const e = t - HIT;+ if (e >= 0 && e < 0.07) {+ const k = 1 - e / 0.07;+ p.ellipse(0, -2, 6 + 6 * (1 - k), 2.5, k > 0.5 ? WHITE : C[7]);+ sparkle(p, 0, -4, 8 * k, C[7], C[6], 0.6);+ }+ // sizzle: tiny star flashes where beads spit off the surface+ for (const q of pops) {+ const k = (t - q.t0) / 0.1;+ p.px(q.x, q.y, WHITE);+ for (const [dx, dy] of [[1, 0], [-1, 0], [0, -1]]) p.dot(q.x + dx * (1 + k * 2), q.y + dy * (1 + k * 2), C[7], 1 - k);+ p.glow(q.x, q.y, 4, C[6], 0.4 * (1 - k));+ }+ for (const q of wisps) wisp(p, q, t, STEAM);+ drops.draw(p, C);+ ps.draw(p, "front");+ lights.draw(p);+ },+ };}diff --git a/src/fx/nature/boulder.js b/src/fx/nature/boulder.jsindex 007f867..3152de6 100644--- a/src/fx/nature/boulder.js+++ b/src/fx/nature/boulder.js@@ -1,97 +1,152 @@-import { PAL, ramp, burst, fly, seg, ease, clamp, lerp, TAU, hex } from "../../core/index.js";+// The impact (rocks thrown up that tumble and bounce and kick up dust where they land, gravel, dust rolling out+// along the floor and climbing, a ring on the floor, a white flash) is adapted from Sprite Fusion's open-source+// explosion (https://www.spritefusion.com/pixel-art-vfx/explosion), MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Bits, Lights, P, PF, B, Rng, fit, band, sparkle, clamp, smooth, ease, TAU, WHITE, hex, mix } from "../../core/index.js";+import { stoneShape, drawRock } from "./_lib.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,+ desc: "A spinning boulder arcs right shedding dust and pebbles, smashes into the floor in a white flash and bursts into tumbling chunks, gravel and rolling dust.",+ tags: ["nature", "earth", "rock", "projectile", "impact", "directional", "one-shot"],+ size: [264, 120],+ origin: [40, 104],+ duration: 2.3,loop: false,fps: 30,bg: "ground",- options: { palette: PAL.stone, distance: 60, size: 7, seed: 43 },+ options: {+ palette: ["#100e12", "#1e1a22", "#302a36", "#463e4c", "#5e5464", "#7c7080", "#a0949e", "#cec4c8"],+ sparks: ["#fff3a6", "#ffe26b", "#ff8a2a", "#f2561d"],+ size: 11,+ seed: 11,+ },};-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 X0 = 6, Y0 = -26, VX = 220, VY = -170, G = 860;+// the boulder's own surface, turning with it: a few shallow pits, a mossy rim along one side+function surface(p, x, y, r, a, S, M) {+ const c = Math.cos(a), s = Math.sin(a), at = (u, v) => [x + (u * c - v * s) * r, y + (u * s + v * c) * r];+ for (const [u, v] of [[0.42, 0.12], [-0.3, 0.38]]) {+ const [px, py] = at(u, v);+ p.px(px, py, S[3]);}- 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);+ for (let k = 0; k < 9; k++) {+ const g = 3.6 + (k / 8) * 1.3, rr = k % 3 === 1 ? 0.78 : 0.92, [px, py] = at(Math.cos(g) * rr, Math.sin(g) * rr);+ p.px(px, py, M[k % 3 === 1 ? 0 : py < y ? 2 : 1]);}- // 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)]);- });+}++export function create(o) {+ const S = fit(o.palette, 8), R = new Rng(o.seed), floor = () => 0, RAD = o.size;+ const DUST = mix(S[6], hex("#9a8f86"), 0.4), DUST2 = mix(S[5], hex("#7a7068"), 0.35);+ const ps = new Particles({ rng: R, ground: floor, sparks: o.sparks }), MOSSC = [hex("#1f3a1e"), hex("#3f7a2c"), hex("#7cb83a")];+ const bits = new Bits({ ground: floor }), lights = new Lights(), shape = stoneShape(R, 8);+ const tHit = (-VY + Math.sqrt(VY * VY - 2 * G * (Y0 + RAD * 0.8))) / G, xHit = X0 + VX * tHit;+ let t = 0, hit = false, thrown = false;+ const at = (tt) => [X0 + VX * tt, Y0 + VY * tt + 0.5 * G * tt * tt];+ const rock = (b) => bits.add({ ...b, pts: stoneShape(R) });+ return {+ update(dt) {+ t += dt;+ const f = Math.min(1, dt * 120);+ if (!thrown) {+ thrown = true;+ for (let i = 0; i < 6; i++) ps.spawn(P.DUST, X0 - R.range(0, 6), Y0 + R.range(-4, 4), -R.range(20, 70), R.range(-20, 20), R.range(0.4, 0.7), DUST, R.range(2.5, 4.5));+ lights.add(X0, Y0, 30, WHITE, 0.3, 0.1);+ }+ if (t < tHit) {+ // it sheds dust and the odd pebble as it flies+ const [x, y] = at(t);+ if (R.chance(0.5 * f)) ps.spawn(P.DUST, x - R.range(2, 6), y + R.range(-4, 4), -R.range(10, 40), R.range(-10, 10), R.range(0.3, 0.6), DUST, R.range(2, 3.5));+ if (R.chance(0.12 * f)) ps.spawn(P.GRIT, x + R.range(-4, 4), y + R.range(-2, 4), VX * 0.3, R.range(-40, 20), R.range(0.6, 0.9), R.pick([S[5], S[4]]), R.chance(0.3) ? 2 : 1);+ }+ if (!hit && t >= tHit) {+ hit = true;+ const x = xHit, y = -RAD * 0.6;+ lights.add(x, y, 36, WHITE, 0.75, 0.1);+ lights.add(x, y, 60, hex("#ffb060"), 0.45, 0.5);+ // big chunks of the boulder, thrown up and on, spinning+ for (let i = 0; i < 9; i++) {+ const a = -Math.PI / 2 + R.range(-1.2, 1.1), sp = R.range(100, 240);+ rock({ kind: B.CHUNK, x: x + R.range(-5, 5), y: y + R.range(-5, 5), vx: Math.cos(a) * sp + 30, vy: Math.sin(a) * sp, g: 1, drag: 0.7, bounce: 0.35, life: R.range(1.3, 1.7), a: R.range(0, TAU), va: R.range(-14, 14), s: R.range(2.8, 5.2) });+ }+ for (let i = 0; i < 14; i++) {+ const a = -Math.PI / 2 + R.range(-1.4, 1.4), sp = R.range(120, 280);+ rock({ kind: B.CHUNK, x: x + R.range(-4, 4), y, vx: Math.cos(a) * sp + 25, vy: Math.sin(a) * sp, g: 1, drag: 0.8, bounce: 0.3, life: R.range(1.1, 1.5), a: R.range(0, TAU), va: R.range(-18, 18), s: R.range(1.4, 2.6) });+ }+ for (let i = 0; i < 60; i++) {+ const u = R.range(-1, 1), a = -Math.PI / 2 + u * 1.1, sp = R.range(80, 300) * (1 - 0.3 * Math.abs(u));+ ps.spawn(P.GRIT, x + u * 6, -1, Math.cos(a) * sp + 30, Math.sin(a) * sp, R.range(1, 1.8), R.pick([S[6], S[5], S[4], S[4], S[3]]), R.chance(0.4) ? 2 : 1);+ }+ for (let i = 0; i < 12; i++) {+ const a = -Math.PI / 2 + R.range(-1.3, 1.3), sp = R.range(150, 380);+ ps.spawn(P.SPARK, x, y, Math.cos(a) * sp + 40, Math.sin(a) * sp, R.range(0.15, 0.4));+ }+ // dust rolling out both ways along the floor, and a cloud climbing off the hit+ for (let i = 0; i < 14; i++) {+ const sd = R.sign();+ ps.spawn(P.SMOKE, x + sd * R.range(2, 10), -R.range(1, 5), sd * R.range(40, 140) + 10, -R.range(4, 20), R.range(1.1, 1.8), R.chance(0.5) ? DUST : DUST2, R.range(4.5, 8), R.range(0, 0.05), PF.BIG);+ }+ for (let i = 0; i < 6; i++) ps.spawn(P.SMOKE, x + R.range(-6, 6), -R.range(4, 14), R.range(-15, 25), -R.range(30, 80), R.range(1.2, 1.8), DUST, R.range(6, 9), R.range(0, 0.1), PF.BIG);+ for (let i = 0; i < 3; i++) ps.spawn(P.STAR, x + R.range(-8, 8), y + R.range(-10, 4), 0, -4, R.range(0.2, 0.4), S[7], R.range(1, 2));+ }+ bits.update(dt);+ for (const b of bits.list)+ if (b.rest && !b.dusted) {+ b.dusted = true;+ for (let i = 0; i < 2; i++) ps.spawn(P.DUST, b.x + R.range(-1.5, 1.5), -0.5, R.sign() * R.range(8, 35), -R.range(2, 12), Math.min(R.range(0.3, 0.6), meta.duration - 0.05 - t), DUST2, R.range(1.3, 2.6));+ }+ ps.update(dt);+ lights.update(dt);+ },+ drawBack(p) {+ const e = t - tHit;+ // the scar it leaves: a dark dent with cracks running from it, fading at the end+ if (e > 0) {+ const fade = 1 - smooth(meta.duration - 0.6, meta.duration - 0.15, t), w = 10 * Math.min(1, e / 0.05);+ for (let x = Math.floor(-w); x <= w; x++) {+ const d = Math.abs(x) / w;+ p.dot(xHit + x, 0, d < 0.6 ? S[0] : S[1], fade);+ if (d < 0.5) p.dot(xHit + x, 1, S[1], fade * 0.8);+ }+ for (const sd of [-1, 1]) for (let k = 0; k < 4; k++) p.dot(xHit + sd * (w + 2 + k * 3), (k & 1) ? 1 : 0, S[1], fade * (1 - k / 4));+ const k = e / 0.45;+ if (k < 1) band(p, xHit, 0.5, 46 * ease.outCubic(k), 0.18, Math.max(1, 3 * (1 - k)), 1.15 - k, [S[4], S[6], hex("#ffd27a"), WHITE], (g) => Math.sin(g) < 0);+ }+ ps.draw(p, "back");+ },+ draw(p) {+ if (t < tHit) {+ const [x, y] = at(t), sp = Math.hypot(VX, VY + G * t), ux = VX / sp, uy = (VY + G * t) / sp;+ // speed lines trailing it+ for (let i = 0; i < 4; i++) {+ const off = (i - 1.5) * RAD * 0.55, nx = -uy * off, ny = ux * off, L = 10 + (i % 2) * 6;+ p.line(x - ux * (RAD + 2) + nx, y - uy * (RAD + 2) + ny, x - ux * (RAD + 2 + L) + nx, y - uy * (RAD + 2 + L) + ny, i % 2 ? S[5] : S[6], 0.8);+ }+ drawRock(p, x, y, RAD, t * 13, shape, S);+ surface(p, x, y, RAD * 0.8, t * 13, S, MOSSC);+ p.glow(x, y, RAD * 2, S[6], 0.12);+ }+ const e = t - tHit;+ if (e >= 0 && e < 0.07) {+ // the hero frame: the boulder flashes white as it breaks, lines of force burst out+ drawRock(p, xHit, -RAD * 0.8, RAD, tHit * 13, shape, S, 1, true);+ sparkle(p, xHit, -RAD * 0.6, 12 * (1 - e / 0.07), WHITE, hex("#ffd27a"), 0.6);+ }+ if (e >= 0 && e < 0.14) {+ const k = e / 0.14;+ for (let i = 0; i < 9; i++) {+ const a = -Math.PI + (i / 8) * Math.PI, r0 = RAD + 4 + 16 * k, r1 = r0 + 8 * (1 - k);+ p.line(xHit + Math.cos(a) * r0, -RAD * 0.6 + Math.sin(a) * r0, xHit + Math.cos(a) * r1, -RAD * 0.6 + Math.sin(a) * r1, k < 0.5 ? WHITE : S[6]);+ }+ }+ if (e > 0) {+ const k = e / 0.45;+ if (k < 1) band(p, xHit, 0.5, 46 * ease.outCubic(k), 0.18, Math.max(1, 3 * (1 - k)), 1.15 - k, [S[4], S[6], hex("#ffd27a"), WHITE], (g) => Math.sin(g) >= 0);+ }+ for (const b of bits.list) drawRock(p, b.x, b.y, b.s, b.a, b.pts, S, Math.min(1, b.life / 0.4));+ ps.draw(p, "front");+ lights.draw(p);+ },+ };}diff --git a/src/fx/nature/earth-spike.js b/src/fx/nature/earth-spike.jsindex cb783b5..a7db300 100644--- a/src/fx/nature/earth-spike.js+++ b/src/fx/nature/earth-spike.js@@ -1,128 +1,227 @@-import { ramp, burst, fly, seg, ease, clamp, lerp, rand, hex } from "../../core/index.js";+// The eruption (a spike punching up with overshoot and a white frame, a burst of debris, mist and glints, then+// breaking into tumbling pieces) is adapted from Sprite Fusion's open-source ice spikes, and the grit and+// rolling dust from his explosion (https://www.spritefusion.com/pixel-art-vfx/ice), MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Bits, Lights, P, PF, B, Rng, fit, sparkle, clamp, smooth, ease, lerp, TAU, WHITE, hex, mix } from "../../core/index.js";+import { stoneShape, drawRock, drawSpike, spikeLook, spikeCrack, floorCrack } from "./_lib.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,+ desc: "The floor cracks with light and heaves, a faceted stone spike rams up with two side shards in a burst of chips, grit and dust; rubble rains, then it splits and crumbles.",+ tags: ["nature", "earth", "stone", "spike", "ground", "attack", "one-shot"],+ size: [272, 150],+ origin: [136, 132],+ duration: 3.4,loop: false,fps: 30,bg: "ground",- options: { palette: ["#17121a", "#2b2430", "#443a46", "#5f5359", "#806f6e", "#a39087", "#c9b6a5", "#eee2d2"], height: 34, seed: 41 },+ options: {+ palette: ["#120c0c", "#251917", "#3b2a24", "#553d31", "#715440", "#8f6e52", "#b8966e", "#e6d0a8"],+ glow: ["#4a1a0c", "#a8401a", "#ff8a2a", "#ffd27a", "#fff4d0"],+ height: 62,+ seed: 5,+ },};-const DUST = ["#3a3230", "#5a4e48", "#7e7068", "#a4968a"].map(hex);-const T_UP = 0.1, T_BREAK = 0.86;+const UP = 0.34, RISE = 0.09, CRACK = 1.18, SPLIT = 1.5, PART = 0.1, FALL = 0.42, SINK = 0.55;-// 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]);+export function create(o) {+ const S = fit(o.palette, 8), G = fit(o.glow, 5), R = new Rng(o.seed), floor = () => 0, H = o.height;+ const DUST = mix(S[6], hex("#8c8494"), 0.45), DUST2 = mix(S[5], hex("#6c6474"), 0.4);+ const ps = new Particles({ rng: R, ground: floor, sparks: [G[4], G[3], G[2], G[1]] });+ const bits = new Bits({ ground: floor }), lights = new Lights();+ // the spike and two side shards leaning away from it, each with its own chips, strata and cracks+ const spikes = [+ { x: -H * 0.17, H: H * 0.52, w: H * 0.22, lean: -H * R.range(0.13, 0.18), at: UP + 0.045, split: SPLIT - 0.1, back: true },+ { x: H * 0.18, H: H * 0.4, w: H * 0.2, lean: H * R.range(0.11, 0.15), at: UP + 0.085, split: SPLIT + 0.08, back: false },+ { x: 0, H, w: H * 0.36, lean: R.range(-2, 2), at: UP, split: SPLIT, back: false, main: true },+ ];+ for (const s of spikes) {+ s.look = spikeLook(R);+ s.cracks = [spikeCrack(R, R.range(0.04, 0.16), R.range(-0.6, -0.1), 1), spikeCrack(R, R.range(0.22, 0.4), R.range(0.1, 0.6), -1), spikeCrack(R, R.range(0.42, 0.58), R.range(-0.4, 0.4), R.sign())];+ s.up = s.split0 = false;+ s.cut = R.range(0.24, 0.32);+ s.top = 1;}- 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));-}+ const cracks = [floorCrack(R, -1, R.range(34, 44)), floorCrack(R, 1, R.range(34, 44)), floorCrack(R, -1, R.range(14, 20)), floorCrack(R, 1, R.range(14, 20))];+ const slabs = [-1, 1].map((sd) => ({ sd, x: sd * R.range(13, 16), pts: [[-1.2, -0.32], [1.1, -0.42], [1.2, 0.36], [-1.1, 0.4]], s: R.range(5.5, 7), a: sd * R.range(0.45, 0.65) }));+ const rock = (b) => bits.add({ ...b, pts: stoneShape(R) });+ let t = 0;+ const grown = (s) => (t < s.at ? 0 : ease.outBack(clamp((t - s.at) / RISE), 2.2));+ const open = () => ease.outCubic(clamp((t - 0.02) / 0.24));+ const heat = () => (t < UP ? smooth(0, UP, t) : 1 - smooth(UP, UP + 0.9, t));+ // after the split the halves part, tip outwards and come down from the top as rubble+ const gap = (s) => smooth(s.split, s.split + PART, t) * (s.main ? 3 : 2);+ const tip = (s) => smooth(s.split, s.split + PART + FALL, t) * 0.12 * s.H;+ const topAt = (s) => lerp(1, s.cut, ease.inQuad(clamp((t - s.split - 0.04) / FALL)));-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);- }+ const erupt = (s) => {+ const k = s.H / H;+ lights.add(s.x, -s.H * 0.4, 30 * k + 14, WHITE, 0.5 * k + 0.1, 0.1);+ lights.add(s.x, -10, 60 * k + 20, G[2], 0.34 * k, 0.5);+ for (let i = 0; i < Math.round(16 * k) + 3; i++) {+ const a = -Math.PI / 2 + R.range(-1.1, 1.1), sp = R.range(140, 360) * (0.6 + 0.4 * k);+ rock({ kind: B.CHUNK, x: s.x + R.range(-s.w / 3, s.w / 3), y: -R.range(1, 6), vx: Math.cos(a) * sp, vy: Math.sin(a) * sp, g: 1, drag: 0.35, bounce: 0.32, life: R.range(1.4, 2.4), a: R.range(0, TAU), va: R.range(-14, 14), s: R.range(1.6, 3.8) * (0.6 + 0.4 * k) });}- }- 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);+ for (let i = 0; i < Math.round(55 * k) + 10; i++) {+ const u = R.range(-1, 1), a = -Math.PI / 2 + u * 0.9, sp = R.range(90, 330) * (1 - 0.35 * Math.abs(u));+ ps.spawn(P.GRIT, s.x + u * s.w * 0.4, -1, Math.cos(a) * sp, Math.sin(a) * sp, R.range(1, 2), R.pick([S[6], S[5], S[4], S[4], S[3]]), R.chance(0.4) ? 2 : 1);}- // 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]);+ for (let i = 0; i < Math.round(9 * k) + 2; i++) {+ const a = -Math.PI / 2 + R.range(-1.2, 1.2), sp = R.range(160, 380);+ ps.spawn(P.SPARK, s.x, -R.range(2, 10), Math.cos(a) * sp, Math.sin(a) * sp, R.range(0.15, 0.4));}- }- // 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]);+ // dust: a low skirt rolling out both ways, a few puffs hanging round the base+ for (let i = 0; i < Math.round(10 * k) + 3; i++) {+ const sd = R.sign();+ ps.spawn(P.SMOKE, s.x + sd * R.range(2, 10), -R.range(1, 4), sd * R.range(50, 170) * (0.5 + 0.5 * k), -R.range(3, 16), R.range(0.9, 1.6), R.chance(0.5) ? DUST : DUST2, R.range(3, 5.5) * (0.6 + 0.4 * k), R.range(0, 0.05), PF.BIG);}- }- // 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]));- });- }+ for (let i = 0; i < Math.round(14 * k) + 4; i++) {+ const sd = R.sign();+ ps.spawn(P.DUST, s.x + sd * R.range(0, 8), -R.range(0, 3), sd * R.range(40, 160), -R.range(2, 20), R.range(0.5, 1), R.chance(0.5) ? DUST : DUST2, R.range(1.5, 3.2));+ }+ for (let i = 0; i < Math.round(3 * k) + 1; i++)+ ps.spawn(P.SMOKE, s.x + R.range(-6, 6), -R.range(2, 12), R.range(-20, 20), -R.range(15, 45), R.range(1, 1.6), DUST, R.range(4, 6) * k + 2, R.range(0.02, 0.12), PF.BIG);+ if (s.main) {+ for (let i = 0; i < 3; i++) ps.spawn(P.STAR, s.x + R.range(-5, 5), -R.range(10, s.H * 0.9), 0, -3, R.range(0.25, 0.5), S[7], R.range(1, 2.2), R.range(0.1, 0.4));+ // rubble that went up high comes raining back down+ for (let i = 0; i < 14; i++) ps.spawn(P.GRIT, R.range(-60, 60), -R.range(110, 125), R.range(-15, 15), R.range(10, 60), R.range(1.2, 1.8), R.pick([S[5], S[4], S[3]]), R.chance(0.35) ? 2 : 1, R.range(0.25, 0.9));+ }+ };++ // one band of a spike, u0..u1, breaks off both halves into rubble that drops and tumbles+ const crumble = (s, u0, u1) => {+ const g = gap(s), lean = s.lean, tp = tip(s);+ for (const half of [-1, 1]) {+ const u = (u0 + u1) / 2, hw = (s.w / 2) * Math.pow(1 - u, 0.85), x = s.x + lean * u + half * (g / 2 + hw * 0.45 + tp * u), y = -u * s.H;+ if (hw < 0.8 && half > 0) continue;+ rock({ kind: B.CHUNK, x, y, vx: half * R.range(8, 40) + lean * 0.6, vy: -R.range(0, 50), g: 1, drag: 0.3, bounce: 0.3, life: Math.min(R.range(1.1, 1.6), meta.duration - 0.15 - t), a: R.range(0, TAU), va: R.range(-8, 8), s: clamp(hw * 0.62, 1.6, 4.8) });+ for (let i = 0; i < 3; i++) ps.spawn(P.GRIT, x + R.range(-2, 2), y + R.range(-2, 2), half * R.range(5, 45), -R.range(10, 70), R.range(0.9, 1.6), R.pick([S[6], S[5], S[4], S[3]]), R.chance(0.35) ? 2 : 1);+ }+ if (R.chance(0.5)) ps.spawn(P.DUST, s.x + lean * u1 + R.range(-4, 4), -u1 * s.H, R.sign() * R.range(15, 45), R.range(20, 60), R.range(0.35, 0.6), DUST, R.range(2, 3.5));+ };++ const drawShard = (p, s) => {+ const g = grown(s);+ if (g <= 0) return;+ if (t < s.split) {+ const white = t - s.at < 0.04 || t > s.split - 0.045, crack = smooth(CRACK + (s.main ? 0 : 0.05), s.split - 0.03, t);+ const sw = (t - s.at) * 0.9 - 0.15, glint = sw > 0 && sw % 1.2 < 0.55 ? (sw % 1.2) / 0.55 : -1;+ drawSpike(p, s.x, 0, s.H * g, s.w, s.lean * Math.min(1, g), s.look, S, { white, glint, cracks: s.cracks, crack, heat: smooth(CRACK, s.split, t), glowRamp: G });+ return;+ }+ // split: two halves part along the ridge and tip away, crumbling from the top; the stump sinks+ const top = topAt(s), gp = gap(s), tp = tip(s), sink = smooth(s.split + FALL, s.split + FALL + SINK, t) * s.H * (s.cut + 0.06);+ if (sink >= s.H * (s.cut + 0.05)) return;+ for (const half of [-1, 1]) drawSpike(p, s.x + (half * gp) / 2, sink, s.H, s.w, s.lean + half * tp, s.look, S, { half, clip: top, floor: 0, cracks: s.cracks, crack: 1, heat: 1 - smooth(s.split, s.split + 0.45, t), glowRamp: G });+ };++ return {+ update(dt) {+ t += dt;+ const f = Math.min(1, dt * 120);+ // the floor splits open: grit hops out of the cracks as they run, dust puffs from them+ if (t < UP) {+ const L = open();+ for (const c of cracks)+ if (R.chance(0.35 * f)) {+ const q = c[Math.min(c.length - 1, Math.floor(R.range(0, L) * c.length))];+ ps.spawn(P.GRIT, q[0], -1, R.range(-20, 20), -R.range(30, 110), R.range(0.5, 1), R.pick([S[5], S[4]]), 1);+ if (R.chance(0.25)) ps.spawn(P.DUST, q[0], -1, R.range(-15, 15), -R.range(4, 14), R.range(0.3, 0.6), DUST2, R.range(1.5, 3));+ }+ if (t > 0.12 && R.chance(0.2 * f)) ps.spawn(P.DUST, R.sign() * R.range(10, 16), -R.range(1, 4), R.sign() * R.range(10, 30), -R.range(4, 12), R.range(0.4, 0.7), DUST2, R.range(2, 3.5));+ }+ for (const s of spikes) {+ if (!s.up && t >= s.at) (s.up = true), erupt(s);+ if (!s.split0 && t >= s.split) {+ s.split0 = true;+ lights.add(s.x, -s.H * 0.5, 30, WHITE, 0.3, 0.08);+ ps.spawn(P.STAR, s.x + s.lean * 0.5, -s.H * 0.55, 0, -2, 0.3, S[7], 2.5);+ }+ // crumbling from the top: each band that goes turns to rubble+ if (t >= s.split) {+ const top = topAt(s);+ while (s.top - top > 0.045 || (top <= s.cut + 1e-6 && s.top > s.cut + 1e-6)) {+ const u1 = s.top, u0 = Math.max(top, s.top - 0.11);+ crumble(s, u0, u1);+ s.top = u0;+ if (u0 <= s.cut + 1e-6) break;+ }+ }+ // cracking: grit and dust dribble out of the cracks+ if (t < s.split && t > CRACK && R.chance(0.12 * f)) {+ const u = R.range(0.1, 0.7);+ ps.spawn(P.GRIT, s.x + s.lean * u + R.range(-2, 2), -u * s.H, R.range(-15, 15), -R.range(0, 20), R.range(0.6, 1.1), R.pick([S[5], S[4]]), 1);+ if (R.chance(0.3)) ps.spawn(P.DUST, s.x + s.lean * u, -u * s.H, R.range(-10, 10), -R.range(2, 8), R.range(0.4, 0.7), DUST, R.range(1.5, 2.5));+ }+ // while it stands, pebbles trickle off its flanks and light glints off its edges+ if (s.up && t < s.split && t > s.at + 0.2 && R.chance(0.05 * f)) {+ const u = R.range(0.2, 0.8), sd = R.sign();+ ps.spawn(P.GRIT, s.x + s.lean * u + sd * (s.w / 2) * (1 - u), -u * s.H, sd * R.range(10, 30), -R.range(0, 15), R.range(0.7, 1.2), R.pick([S[6], S[5]]), 1);+ }+ if (s.main && s.up && t < s.split && t > s.at + 0.25 && R.chance(0.03 * f))+ ps.spawn(P.STAR, s.x + R.range(-4, 2), -R.range(8, s.H * 0.85), 0, -2, R.range(0.25, 0.45), R.chance(0.5) ? S[7] : G[3], R.range(0.8, 2));+ // the stump sinking pushes up a last puff of dust+ if (t > s.split + FALL && t < s.split + FALL + SINK * 0.8 && R.chance(0.15 * f))+ ps.spawn(P.DUST, s.x + R.range(-s.w / 2, s.w / 2), -R.range(0, 2), R.sign() * R.range(20, 60), -R.range(0, 5), R.range(0.4, 0.7), DUST2, R.range(1.5, 3));+ }+ bits.update(dt);+ // stones that land hard kick up a little dust+ for (const b of bits.list)+ if (b.rest && !b.dusted) {+ b.dusted = true;+ for (let i = 0; i < 2; i++) ps.spawn(P.DUST, b.x + R.range(-1.5, 1.5), -0.5, R.sign() * R.range(8, 35), -R.range(2, 14), R.range(0.3, 0.6), DUST2, R.range(1.3, 2.6));+ }+ ps.update(dt);+ lights.update(dt);+ },+ drawBack(p) {+ // the cracks in the floor: a glowing seam that cools to a dark scar, then fades+ const L = open(), hk = heat(), fade = 1 - smooth(meta.duration - 1.1, meta.duration - 0.3, t);+ for (const c of cracks) {+ const m = Math.max(2, Math.ceil(c.length * L));+ for (let k = 1; k < m; k++) {+ const [x0, y0] = c[k - 1], [x1, y1] = c[k];+ p.line(x0, y0 + 1, x1, y1 + 1, S[0], fade);+ p.line(x0, y0, x1, y1, hk > 0.65 ? G[4] : hk > 0.35 ? G[3] : hk > 0.12 ? G[2] : hk > 0.03 ? G[1] : S[1], fade);+ if (k % 2 === 0) p.glow(x1, y1, 6, G[2], 0.3 * hk);+ }+ }+ if (hk > 0) p.glow(0, -3, 26, G[2], 0.35 * hk);+ ps.draw(p, "back");+ for (const s of spikes) if (s.back) drawShard(p, s);+ },+ draw(p) {+ // before it breaks through, the floor heaves into a trembling mound+ if (t < UP + 0.02) {+ const k = smooth(0.06, UP, t), hm = 8 * k, jx = Math.sin(t * 95) * 0.8 * k;+ if (hm > 0.6)+ p.shade(-16, -hm - 1, 16, 1, (x, y, out) => {+ const dx = (x - jx) / 15, dy = y / hm, d = dx * dx + dy * dy;+ if (y > 0.5 || d > 1.18) return;+ out.c = d > 1 ? S[0] : dy < -0.72 ? S[6] : dx < -0.3 ? S[5] : dx > 0.35 ? S[3] : S[4];+ });+ }+ // slabs of floor shoved up around the base, sinking back as the spike crumbles+ if (t >= UP) {+ const sink = smooth(SPLIT + FALL, SPLIT + FALL + SINK, t) * 7, a = 1 - smooth(SPLIT + FALL, SPLIT + FALL + SINK, t);+ for (const sl of slabs) {+ const g = ease.outBack(clamp((t - UP) / 0.1), 2);+ if (a > 0) drawRock(p, sl.x, -1.5 + sink, sl.s * Math.min(1, g), sl.a * g, sl.pts, S, a, t - UP < 0.04);+ }+ }+ for (const s of spikes) if (!s.back) drawShard(p, s);+ const m0 = spikes[2], leak = smooth(CRACK, SPLIT, t) * (1 - smooth(SPLIT, SPLIT + 0.5, t));+ if (leak > 0) p.glowLine(m0.x, -4, m0.x + m0.lean * 0.6, -m0.H * 0.6, 20, G[2], 0.22 * leak);+ for (const b of bits.list) drawRock(p, b.x, b.y, b.s, b.a, b.pts, S, Math.min(1, b.life / 0.4));+ ps.draw(p, "front");+ // the hero frame: a flare where the tip breaks through, light running up the spike+ const m = spikes[2], e = t - m.at;+ if (e > 0 && e < 0.2) {+ const g = ease.outBack(clamp(e / RISE), 2.2);+ sparkle(p, m.x + m.lean, -m.H * g, 10 * (1 - e / 0.2), S[7], G[3], 0.5);+ p.glowLine(m.x, 0, m.x + m.lean, -m.H * g, 10, G[3], 0.3 * (1 - e / 0.2));+ }+ lights.draw(p);+ },+ };}diff --git a/src/fx/nature/healing-bloom.js b/src/fx/nature/healing-bloom.jsindex 9bcc5c3..10f753d 100644--- a/src/fx/nature/healing-bloom.js+++ b/src/fx/nature/healing-bloom.js@@ -1,99 +1,177 @@-import { PAL, ramp, burst, fly, seg, ease, clamp, lerp, TAU, hex } from "../../core/index.js";+// The healing light (a soft column of glow, a lit ring on the floor, motes and bevelled crosses drifting up and+// glinting) is adapted from Sprite Fusion's open-source heal (https://www.spritefusion.com/pixel-art-vfx/heal),+// MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Lights, P, Rng, fit, sparkle, band, clamp, smooth, ease, lerp, TAU, WHITE } from "../../core/index.js";+import { drawLeaf } from "./_lib.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.",+ desc: "A sprout pushes up and unfurls, a bud swells and opens round a glowing golden heart in a flare of healing light; its petals lift away one by one as motes.",tags: ["nature", "heal", "flower", "plant", "buff", "ground", "one-shot"],- size: [64, 64],- origin: [32, 56],- duration: 2,+ size: [124, 120],+ origin: [62, 108],+ duration: 3.3,loop: false,fps: 30,bg: "ground",- options: { palette: PAL.heal, seed: 37 },+ options: {+ palette: ["#0c1a10", "#173a1a", "#24582a", "#357a34", "#52a03e", "#86c84e", "#c4ec7a", "#f4ffd0"],+ petal: ["#4a1a3a", "#a8406e", "#ec8ab0", "#ffd8e8"],+ heart: ["#a8641a", "#f0b42e", "#ffe680", "#fffbe0"],+ seed: 4,+ },};-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;+const STEM = 0.42, BUD = 0.75, OPEN = 1.05, LIFT = 1.7, WILT = 2.4, H = 36, NPET = 6;-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]);+// a bevelled cross of light+function cross(p, x, y, L, C, a, glint) {+ const X = Math.round(x), Y = Math.round(y), ins = (dx, dy) => (dx === 0 && Math.abs(dy) <= L) || (dy === 0 && Math.abs(dx) <= L);+ for (let dy = -L - 1; dy <= L + 1; dy++)+ for (let dx = -L - 1; dx <= L + 1; dx++) {+ if (ins(dx, dy)) p.dot(X + dx, Y + dy, glint && !dx && !dy ? WHITE : dy < 0 || dx < 0 ? C[6] : C[5], a);+ else if (L > 1 && (ins(dx - 1, dy) || ins(dx + 1, dy) || ins(dx, dy - 1) || ins(dx, dy + 1))) p.dot(X + dx, Y + dy, C[2], a * 0.8);}- 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]);+ p.glow(x, y, 5 + L * 2, C[6], 0.35 * a);+}++export function create(o) {+ const C = fit(o.palette, 8), Pt = fit(o.petal, 4), Ht = fit(o.heart, 4), R = new Rng(o.seed), floor = () => 0;+ const ps = new Particles({ rng: R, ground: floor, sparks: [Ht[3], Ht[2], Ht[1], Ht[0]] });+ const lights = new Lights(), flying = [], glyphs = [];+ const petals = Array.from({ length: NPET }, (_, i) => ({ az: (i / NPET) * TAU + 0.3, off: (i * 0.7) % 1, gone: false, at: LIFT + ((i * 0.37) % 1) * 0.55 }));+ let t = 0, popped = false, sprouted = false;+ const grow = () => ease.outCubic(clamp(t / STEM)) * (1 - ease.inCubic(clamp((t - WILT) / 0.6)));+ const sway = () => Math.sin(t * 2.6) * 1.4 * smooth(0.2, 0.6, t);+ // the stem's points, base to tip: a gentle S that sways+ const stem = () => {+ const g = grow(), pts = [];+ for (let i = 0; i <= 12; i++) {+ const s = i / 12;+ pts.push([Math.sin(s * 3.2) * 2.2 * s + sway() * s * s, (1 - g) * H * 1.1 - s * H]);}+ return pts;+ };+ const open = () => ease.outBack(clamp((t - BUD) / (OPEN - BUD)), 1.4);+ return {+ update(dt) {+ t += dt;+ const f = Math.min(1, dt * 120), top = stem()[12];+ if (!sprouted) {+ sprouted = true;+ for (let i = 0; i < 8; i++) ps.spawn(P.GRIT, R.range(-3, 3), -1, R.range(-40, 40), -R.range(40, 100), R.range(0.5, 0.8), R.pick([C[2], C[3]]), 1);+ for (let i = 0; i < 3; i++) ps.spawn(P.DUST, R.range(-3, 3), -1, R.sign() * R.range(10, 30), -R.range(4, 10), R.range(0.4, 0.6), C[3], R.range(1.5, 2.5));+ }+ // the bud draws light in as it swells+ if (t > STEM && t < BUD && R.chance(0.3 * f)) {+ const a = R.range(0, TAU), d = R.range(14, 26), x = top[0] + Math.cos(a) * d, y = top[1] - 3 + Math.sin(a) * d * 0.8;+ ps.spawn(P.STREAK, x, y, (top[0] - x) * 3.4, (top[1] - 3 - y) * 3.4, R.range(0.18, 0.26), R.chance(0.5) ? Ht[2] : C[6]);+ }+ if (!popped && t >= OPEN - 0.12) {+ popped = true;+ lights.add(top[0], top[1] - 3, 22, WHITE, 0.45, 0.08);+ lights.add(top[0], top[1] - 3, 70, Ht[2], 0.5, 0.8);+ for (let i = 0; i < 16; i++) {+ const a = R.range(0, TAU), sp = R.range(40, 120);+ ps.spawn(P.MOTE, top[0], top[1] - 3, Math.cos(a) * sp, Math.sin(a) * sp - 20, R.range(0.4, 0.8), R.chance(0.5) ? Ht[3] : C[7], 0.7);+ }+ for (let i = 0; i < 5; i++) ps.spawn(P.STAR, top[0] + R.range(-10, 10), top[1] - R.range(0, 14), 0, -6, R.range(0.3, 0.6), Ht[3], R.range(1, 2.4), R.range(0, 0.3));+ }+ // while it blooms: crosses and motes of light drift up round it+ if (t > OPEN && t < WILT && R.chance(0.13 * f)) glyphs.push({ x: R.range(-22, 22), y: -R.range(2, 36), t0: t, life: Math.min(R.range(0.7, 1.1), meta.duration - 0.05 - t), L: R.chance(0.35) ? 3 : 2, seed: R.next() * 9 });+ if (t > OPEN - 0.1 && t < WILT && R.chance(0.35 * f)) ps.spawn(P.EMBER, R.range(-20, 20), -R.range(0, 8), R.range(-6, 6), -R.range(25, 55), Math.min(R.range(0.6, 1.1), meta.duration - 0.05 - t), R.chance(0.6) ? C[6] : Ht[2], R.chance(0.3) ? 2 : 1);+ for (let i = glyphs.length - 1; i >= 0; i--) if (t - glyphs[i].t0 > glyphs[i].life) glyphs.splice(i, 1);+ // petals let go one by one and lift away, turning, until they twinkle out+ for (const q of petals)+ if (!q.gone && t >= q.at) {+ q.gone = true;+ const e = Math.PI / 2 - 0.15, dx = Math.sin(e) * Math.cos(q.az), L = 10;+ flying.push({ x: top[0] + dx * L * 0.6, y: top[1] - 3 - Math.cos(e) * L * 0.6, vx: dx * 30 + R.range(-10, 10), vy: -R.range(25, 45), a: Math.atan2(-Math.cos(e), dx), va: R.range(-5, 5), fl: 0, vf: R.range(5, 9), life: Math.min(R.range(0.75, 1.0), meta.duration - 0.45 - t), max: 0 });+ flying[flying.length - 1].max = flying[flying.length - 1].life;+ }+ for (let i = flying.length - 1; i >= 0; i--) {+ const q = flying[i];+ if ((q.life -= dt) <= 0) {+ ps.spawn(P.STAR, q.x, q.y, 0, -8, Math.min(0.35, meta.duration - 0.05 - t), Pt[3], 1.8);+ flying.splice(i, 1);+ continue;+ }+ q.vx -= q.vx * 1.5 * dt;+ q.vy -= q.vy * 0.8 * dt + 10 * dt;+ q.x += q.vx * dt + Math.sin(q.fl) * 12 * dt;+ q.y += q.vy * dt;+ q.a += q.va * dt;+ q.fl += q.vf * dt;+ }+ ps.update(dt);+ lights.update(dt);+ },+ drawBack(p) {+ const bloom = smooth(OPEN - 0.15, OPEN + 0.2, t) * (1 - smooth(WILT - 0.2, WILT + 0.5, t)), top = stem()[12];+ // a column of soft healing light, and a lit ring on the floor that blooms out as it opens+ for (let h = 0; h < 70; h += 7) p.glow(0, -h, 22, C[5], 0.12 * bloom * (1 - h / 80));+ const k = clamp((t - OPEN + 0.12) / 0.6);+ if (k > 0 && k < 1) band(p, 0, 0.5, 6 + 30 * ease.outCubic(k), 0.18, Math.max(1, 3 * (1 - k)), 1.1 - k, [C[3], C[5], Ht[2], Ht[3]], (g) => Math.sin(g) < 0);+ const fw = 6 + 16 * smooth(0, 0.8, t);+ for (let x = Math.floor(-fw); x <= fw; x++) {+ const u = Math.abs(x) / fw, a = Math.sqrt(1 - u) * smooth(0, 0.4, t) * (1 - smooth(WILT, WILT + 0.6, t));+ p.dot(x, 0, u < 0.3 ? C[6] : u < 0.65 ? C[5] : C[4], a);+ if ((x % 5) === 0) p.glow(x, 0, 8, C[5], 0.2 * a * (1 - u));+ }+ // the far petals sit behind the heart+ if (t > BUD - 0.05) for (const q of petals) if (Math.sin(q.az) < 0 && !q.gone) petal(p, q, top);+ ps.draw(p, "back");+ },+ draw(p) {+ const pts = stem(), top = pts[12], g = grow();+ if (g > 0.02) {+ // the stem: a 2 px shoot, lit down its left side+ for (let i = 1; i < pts.length; i++) {+ const [x0, y0] = pts[i - 1], [x1, y1] = pts[i];+ if (y1 > 0) continue;+ p.line(x0, y0, x1, y1, C[5]);+ p.line(x0 + 1, y0, x1 + 1, y1, C[3]);+ }+ // leaves unfurl off it+ for (const [i, sd, d] of [[4, -1, 0.1], [7, 1, 0.22]]) {+ const lk = ease.outBack(clamp((t - d - 0.12) / 0.3), 1.6) * (1 - smooth(WILT, WILT + 0.5, t) * 0.4), [x, y] = pts[i];+ if (lk <= 0 || y > -1) continue;+ const la = sd < 0 ? -2.6 + 0.4 * (1 - lk) : -0.55 - 0.4 * (1 - lk);+ drawLeaf(p, x + Math.cos(la) * 6 * lk, y + Math.sin(la) * 6 * lk, 12 * lk, 3.4, la, 0.25, [C[1], C[3], C[5], C[6]]);+ }+ // the bud, then the heart once it opens+ if (t > STEM - 0.1 && t < OPEN - 0.1) {+ const b = clamp((t - STEM + 0.1) / (BUD - STEM)), w = 2 + 2.5 * b, h = 3.5 + 5 * b;+ p.ellipse(top[0], top[1] - h * 0.6, w, h, (d, a) => (Math.cos(a) < -0.2 ? Pt[2] : d > 0.7 ? Pt[0] : Pt[1]));+ p.glow(top[0], top[1] - h * 0.6, 8 + 8 * b, Ht[2], 0.25 * b);+ }+ }+ for (const q of petals) if (Math.sin(q.az) >= 0 && !q.gone && t > BUD - 0.05) petal(p, q, top);+ if (t > OPEN - 0.12 && t < WILT + 0.3) {+ const pulse = 0.85 + 0.15 * Math.sin(t * 9), k = 1 - smooth(WILT - 0.3, WILT + 0.3, t), cy = top[1] - 4;+ p.circle(top[0], cy, 3.3 * k, Ht[1]);+ p.circle(top[0] - 0.5, cy - 0.5, 2.2 * k, Ht[2]);+ p.px(top[0] - 1, cy - 1, Ht[3]);+ p.glow(top[0], cy, 16 * pulse, Ht[2], 0.5 * k);+ p.glow(top[0], cy, 34, C[5], 0.2 * k);+ }+ const e = t - OPEN + 0.12;+ if (e > 0 && e < 0.16) sparkle(p, top[0], top[1] - 3, 10 * (1 - e / 0.16), Ht[3], Ht[2], 0.6);+ for (const q of flying) drawLeaf(p, q.x, q.y, 6, 2.2, q.a, q.fl, [Pt[0], Pt[1], Pt[2], Pt[3]], Math.min(1, q.life / 0.3));+ for (const q of glyphs) {+ const k = (t - q.t0) / q.life;+ cross(p, q.x + Math.sin(k * 5 + q.seed) * 2, q.y - k * 24, q.L, C, Math.sin(Math.PI * k), Math.sin(k * 14 + q.seed) > 0.8);+ }+ ps.draw(p, "front");+ lights.draw(p);+ },+ };++ // a petal: from closed round the bud to splayed open round the heart, foreshortened by where it points+ function petal(p, q, top) {+ const op = open(), e = lerp(0.15, Math.PI / 2 - 0.2, op), dx = Math.sin(e) * Math.cos(q.az), dz = Math.sin(e) * Math.sin(q.az), dy = -Math.cos(e);+ const L = lerp(8, 12, op), len = L * Math.hypot(dx, dy), ang = Math.atan2(dy, dx), back = dz < 0, cy = top[1] - 3;+ if (len < 1.5) return;+ drawLeaf(p, top[0] + dx * L * 0.5, cy + dy * L * 0.5, len + 1, 3 + (1 - Math.abs(dz)) * 0.8, ang, back ? 0.9 : 0.2, back ? [Pt[0], Pt[0], Pt[1], Pt[2]] : [Pt[0], Pt[1], Pt[2], Pt[3]]);}- 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.jsindex 37015ea..65f4cf8 100644--- a/src/fx/nature/leaf-storm.js+++ b/src/fx/nature/leaf-storm.js@@ -1,61 +1,96 @@-import { PAL, ramp, at, cycle, TAU, hex } from "../../core/index.js";+// The leaves' tumble (turning as they go, flipping over through edge-on, palettes of autumn and green) is adapted+// from Sprite Fusion's open-source falling leaves (https://www.spritefusion.com/pixel-art-vfx/falling-leaves),+// MIT License, Copyright (c) 2026 Hugo Duprez.+import { cycle, fit, rng, smooth, clamp, lerp, TAU, WHITE } from "../../core/index.js";+import { drawLeaf } from "./_lib.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,+ desc: "Leaves tumble up a rising spiral round the character, passing behind and in front, turning and flipping, wrapped in bright bands of wind; litter swirls at their feet.",+ tags: ["nature", "wind", "leaves", "buff", "aura", "actor", "loop"],+ size: [112, 104],+ origin: [56, 92],+ duration: 2.4,loop: true,fps: 30,bg: "ground",- actor: true,- options: { palette: PAL.leaf, count: 20, radius: 15, seed: 29 },+ actor: 2,+ options: {+ palette: ["#1a2420", "#2e4038", "#4a6656", "#7a9a84", "#b4d0b8", "#eef8e8"],+ leaves: ["#123818", "#2f7a2a", "#6cb83a", "#c8f070", "#4a2a08", "#a8701c", "#e8b42e", "#fff09a", "#3a1010", "#9a2e1c", "#e0642a", "#ffb070"],+ seed: 5,+ },};-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."],-];+const SY = 0.3, TOP = 64;+const ringR = (y) => 15 + 9 * clamp(-y / TOP);-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 riding the spiral: up from the floor, round two turns or so, flung out off the top+function leaves(p, L, t, seed, back) {+ cycle(t, meta.duration, 28, seed, (g) => g.range(1.5, 2.3), (age, life, R) => {+ const k = age / life, turns = R.range(1.4, 2.2), th = R.range(0, TAU) + turns * TAU * k, sn = Math.sin(th);+ if (sn > 0 === back) return;+ const y = -lerp(1, TOP, Math.pow(k, 0.9)) - R.range(0, 6), fling = smooth(0.75, 1, k), rr = ringR(y) * R.range(0.85, 1.15) + fling * 22;+ const x = Math.cos(th) * rr, yy = y + sn * rr * SY;+ const a = Math.min(1, k * 7) * (1 - smooth(0.85, 1, k)), spin = R.range(-9, 9) * age + th, fl = age * R.range(5, 11), o = R.int(0, 2) * 4;+ const pal = back ? [L[o], L[o], L[o + 1], L[o + 2]] : [L[o], L[o + 1], L[o + 2], L[o + 3]];+ drawLeaf(p, x, yy, R.range(6.5, 9), R.range(2.4, 3.3), spin, fl, pal, a);+ // a glint as it turns face on to the light+ if (!back && Math.abs(Math.cos(fl)) > 0.97) {+ p.px(x, yy, WHITE);+ p.glow(x, yy, 5, L[o + 3], 0.35 * a);}+ });+}++// wind bands: 1 px streaks on tilted rings round the character, bright at the head, fading behind, the far+// halves dimmer and behind it+function wind(p, C, t, seed, back) {+ for (let j = 0; j < 16; j++) {+ const R = rng(seed, j), y0 = -R.range(4, TOP - 4), r = ringR(y0) * R.range(1.0, 1.25), K = R.int(2, 3), span = R.range(1.1, 2.4);+ const head = R.range(0, TAU) + (TAU * K * t) / meta.duration, rise = R.range(-0.18, 0.18);+ for (let s = 0; s <= span; s += 0.45 / r) {+ const th = head - s, sn = Math.sin(th);+ if (sn > 0 === back) continue;+ const k = s / span, x = Math.cos(th) * r, y = y0 + sn * r * SY + (th - head) * rise * 4;+ const c = back ? (k < 0.3 ? C[3] : C[2]) : k < 0.06 && R.next() < 2 ? WHITE : k < 0.15 ? C[5] : k < 0.4 ? C[4] : C[3];+ if (k < 0.45) p.dot(x, y, c);+ else p.blend(x, y, c, 1.6 * (1 - k));+ }+ if (!back && Math.sin(head) > 0) p.glow(Math.cos(head) * r, y0 + Math.sin(head) * r * SY, 5, C[4], 0.25);}- // 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,- });+}++// at the feet: litter and dust swept round on the floor+function swirl(p, C, L, t, seed, back) {+ cycle(t, meta.duration, 14, seed, (g) => g.range(0.6, 1.1), (age, life, R) => {+ const k = age / life, th = R.range(0, TAU) + R.range(6, 9) * age, sn = Math.sin(th);+ if (sn > 0 === back) return;+ const rr = R.range(10, 22) + k * 8, x = Math.cos(th) * rr, y = -1 - k * R.range(2, 8) + sn * rr * 0.25, s = R.range(2, 3.5) * (0.6 + k);+ p.disc(x, y, s, back ? C[2] : C[3], (1 - k) * Math.min(1, k * 6) * 0.3);});- if (front) p.glow(0, -14, 26, C[5], 0.08);+ for (let j = 0; j < 6; j++) {+ const R = rng(seed + 9, j), rr = R.range(12, 24), th0 = R.range(0, TAU) + (TAU * 3 * t) / meta.duration, span = R.range(0.5, 1);+ for (let s = 0; s < span; s += 0.6 / rr) {+ const th = th0 - s;+ if (Math.sin(th) > 0 === back) continue;+ p.dot(Math.cos(th) * rr, 0.5 + rr * 0.2 * Math.sin(th), s < span * 0.4 ? C[3] : C[2], 1 - s / span);+ }+ }}-export const drawBack = (p, t, o) => storm(p, t, o, false);-export const draw = (p, t, o) => storm(p, t, o, true);+export function drawBack(p, t, o) {+ const C = fit(o.palette, 6), L = fit(o.leaves, 12);+ p.glow(0, -30, 46, C[4], 0.12);+ p.glow(0, -2, 26, L[2], 0.12);+ swirl(p, C, L, t, o.seed * 3 + 1, true);+ wind(p, C, t, o.seed * 5 + 2, true);+ leaves(p, L, t, o.seed * 7 + 3, true);+}++export function draw(p, t, o) {+ const C = fit(o.palette, 6), L = fit(o.leaves, 12);+ swirl(p, C, L, t, o.seed * 3 + 1, false);+ wind(p, C, t, o.seed * 5 + 2, false);+ leaves(p, L, t, o.seed * 7 + 3, false);+}diff --git a/src/fx/nature/poison-cloud.js b/src/fx/nature/poison-cloud.jsindex 6335b80..f045358 100644--- a/src/fx/nature/poison-cloud.js+++ b/src/fx/nature/poison-cloud.js@@ -1,84 +1,124 @@-import { ramp, at, cycle, rng, noise2, clamp, ease, TAU } from "../../core/index.js";+import { cycle, fit, rng, smooth, clamp, TAU, WHITE, tileNoise } 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,+ desc: "A miasma hugging the floor: ragged sheets of gas lit yellow-green from within, fading to violet, creep out in tongues that curl over at their tips; plumes twist up as ribbons.",+ tags: ["nature", "poison", "gas", "cloud", "miasma", "toxic", "area", "ground", "loop"],+ size: [256, 100],+ origin: [128, 86],+ duration: 4,loop: true,fps: 30,bg: "ground",options: {- palette: ["#221a33", "#3a3450", "#4a5a4a", "#5f7f40", "#84a842", "#aed056", "#d6ee86", "#f4ffcc"],- size: 1,- seed: 7,+ palette: ["#0e0816", "#24123a", "#3e2056", "#5a3a62", "#6a6a3a", "#96aa30", "#cce040", "#f4ffa0"],+ spread: 1,+ seed: 3,},};-// 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],+const D = meta.duration;+// sheets of gas, back to front: how tall, how wide, how thick, how much dimmer, how fast their edges flow+const SHEETS = [+ { h: 36, e: 0.84, a: 0.46, dim: 2, flow: 4, n: 2, back: true },+ { h: 26, e: 0.96, a: 0.5, dim: 1, flow: 8, n: 2, back: true },+ { h: 16, e: 1.04, a: 0.56, dim: 0, flow: 8, n: 3, back: false },];-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 });- });+// tongues creeping out along the floor from the middle: where each one's front is, how tall, how far along+function tongues(sh, si, E, ph) {+ const out = [];+ for (const s of [-1, 1])+ for (let i = 0; i < sh.n; i++) {+ const q = (ph + i / sh.n + si * 0.17 + (s > 0 ? 0.5 / sh.n : 0)) % 1;+ out.push({ s, q, x: s * E * (0.3 + 0.82 * q), h: sh.h * (0.75 - 0.45 * q) });+ }+ return out;+}- 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);+// a sheet's height above the floor at x: flat through the middle, falling away at its ends, its top torn by+// noise that flows outward, raised behind each tongue's front+function height(sh, si, E, x, ph, T, seed) {+ const ax = Math.abs(x), env = 1 - smooth(0.5, 1, ax / (E * sh.e)), r = tileNoise(ax * 0.07 - ph * sh.flow, si * 3.7, sh.flow, 0, seed + si);+ let h = sh.h * env * (0.55 + 0.45 * r);+ for (const g of T) {+ const behind = g.s * (g.x - x);+ if (behind < -1.5 || behind > 30) continue;+ h = Math.max(h, g.h * Math.sqrt(Math.max(0, 1 - behind / 30)) * smooth(-1.5, 1.5, behind) * (1 - smooth(0.75, 1, g.q)));+ }+ return h;+}++// one sheet: brightest down at the floor where it's lit from within, darkening to violet toward its torn top,+// streaked in thin layers, a pale rim along its edge+function sheet(p, C, sh, si, E, t, seed) {+ const ph = t / D, T = tongues(sh, si, E, ph), d = sh.dim, X = Math.ceil(E * 1.25);+ for (let x = -X; x <= X; x++) {+ const H = height(sh, si, E, x + 0.5, ph, T, seed);+ if (H < 0.6) continue;+ const top = -Math.round(H);+ for (let y = top; y <= 1; y++) {+ const v = clamp(-y / H), streak = 0.7 + 0.3 * tileNoise(x * 0.05 - ph * sh.flow * Math.sign(x || 1), y * 0.55, sh.flow, 0, seed + 9 + si);+ const lv = v - (streak - 0.7) * 0.6, c = y === top ? C[Math.max(1, 4 - d)] : lv < 0.16 ? C[6 - d] : lv < 0.42 ? C[5 - d] : lv < 0.68 ? C[4 - d] : C[Math.max(1, 3 - d)];+ p.blend(x, y, c, sh.a * (y === top ? 0.65 : (0.6 + 0.4 * (1 - v)) * streak));}- 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);- });+ }+ // the tongues' leading edges roll over in curls as they creep forward+ for (const g of T) {+ const k = Math.sin(Math.PI * g.q);+ if (k < 0.15 || g.h < 4) continue;+ const r = 1.8 + g.h * 0.22, cx = g.x - g.s * r * 0.6, cy = -g.h * 0.72, spin = -g.s * g.q * TAU * 2.2;+ // a roll of gas: a thick soft band winding in on itself, lighter along its outer edge+ for (let a = 0; a < 4.6; a += 0.1) {+ const rr = r * (1 - a * 0.12), px = cx + g.s * Math.cos(spin + a) * rr, py = cy + Math.sin(spin + a) * rr, w = 1.6 * (1 - a / 6);+ for (let o = -w; o <= w; o += 0.8) {+ const qx = px + g.s * Math.cos(spin + a) * o, qy = py + Math.sin(spin + a) * o;+ p.blend(qx, qy, o > w * 0.4 ? C[5 - d] : C[4 - d], sh.a * 0.75 * k * (1 - a / 5.5));+ }+ }+ }+}- // 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]));+// plumes: columns that lift off the sheets and twist into ribbons, thinning as they climb+function plumes(p, C, E, t, seed) {+ cycle(t, D, 5, seed, (g) => g.range(2.4, 3.2), (age, L, R) => {+ const u = age / L, x0 = R.range(-0.55, 0.55) * E, rise = R.range(13, 19), len = R.range(34, 48), ph = R.range(0, TAU), amp = R.range(3, 5);+ const head = 14 + rise * age, tail = Math.max(10, head - len), fade = smooth(0, 0.15, u) * (1 - smooth(0.5, 1, u));+ for (let h = tail; h <= head; h += 0.7) {+ const s = (h - tail) / Math.max(1, head - tail), tw = Math.cos(h * 0.22 + age * 2.4 + ph), w = 0.6 + 2.2 * Math.abs(tw) * (1 - s * 0.5);+ const x = x0 + amp * Math.sin(h * 0.12 + age + ph) * (0.4 + s), a = fade * Math.sin(Math.PI * Math.min(1, s * 1.2)) * 0.32;+ for (let o = -w; o <= w; o += 1) p.blend(x + o, -h, tw > 0 ? (Math.abs(o) < w * 0.5 ? C[6] : C[5]) : Math.abs(o) < w * 0.5 ? C[3] : C[2], a);+ }});- // 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));+}++// specks drifting out through the gas with its flow, twinkling+function specks(p, C, E, t, seed) {+ cycle(t, D, 30, seed, (g) => g.range(1.5, 2.6), (age, L, R) => {+ const u = age / L, s = R.sign(), x = s * (R.range(0.05, 0.7) * E + age * R.range(6, 14)), y = -R.range(2, 20) - Math.sin(age * R.range(1.5, 3) + R.next() * TAU) * 2;+ const a = Math.min(1, u * 5) * Math.min(1, (1 - u) * 3) * (0.6 + 0.4 * Math.sin(age * R.range(6, 10) + R.next() * TAU));+ if (a < 0.1) return;+ p.dot(x, y, a > 0.7 ? C[7] : C[6], a * 1.3);+ p.glow(x, y, 4, C[6], 0.3 * a);});- 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);+}++export function drawBack(p, t, o) {+ const C = fit(o.palette, 8), E = 96 * o.spread, pulse = 0.85 + 0.15 * Math.sin((TAU * t * 2) / D);+ // lit from within, low down: a soft line of light along the floor under it all+ for (let x = -E; x <= E; x += 22) p.glow(x, -3, 30, C[5], 0.14 * pulse * (1 - Math.abs(x) / (E * 1.3)));+ // pockets of light wandering inside it, low down+ for (let i = 0; i < 6; i++) {+ const R = rng(o.seed, i, 7), x = Math.sin((TAU * t) / D + R.range(0, TAU)) * E * R.range(0.2, 0.7) + R.range(-0.3, 0.3) * E, k = 0.6 + 0.4 * Math.sin((TAU * t * 3) / D + i);+ p.glow(x, -R.range(4, 10), R.range(14, 22), C[6], 0.2 * k);+ }+ SHEETS.forEach((sh, i) => sh.back && sheet(p, C, sh, i, E, t, o.seed));+}++export function draw(p, t, o) {+ const C = fit(o.palette, 8), E = 96 * o.spread;+ plumes(p, C, E, t, o.seed * 7 + 2);+ SHEETS.forEach((sh, i) => !sh.back && sheet(p, C, sh, i, E, t, o.seed));+ specks(p, C, E, t, o.seed * 11 + 5);+ p.glow(0, -6, E * 0.9, C[5], 0.1);}diff --git a/src/fx/nature/quake.js b/src/fx/nature/quake.jsindex 77c63a8..6fc162d 100644--- a/src/fx/nature/quake.js+++ b/src/fx/nature/quake.js@@ -1,84 +1,136 @@-import { PAL, ramp, burst, fly, seg, ease, clamp, rand, hex } from "../../core/index.js";+// The ground's part (grit thrown up that bounces and settles, stones that tumble and kick up dust where they land,+// dust rolling out along the floor and climbing) is adapted from Sprite Fusion's open-source explosion+// (https://www.spritefusion.com/pixel-art-vfx/explosion), MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Bits, Lights, P, PF, B, Rng, fit, clamp, smooth, ease, rand, TAU, WHITE, hex, mix } from "../../core/index.js";+import { stoneShape, drawRock } from "./_lib.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,+ desc: "The ground jolts three times: a rift tears out along the floor glowing deep inside, slabs of floor heave up and drop back askew, pebbles hop and dust bursts out of the split.",+ tags: ["nature", "earth", "quake", "rift", "aoe", "ground", "one-shot"],+ size: [288, 104],+ origin: [144, 88],+ duration: 3.1,loop: false,fps: 30,bg: "ground",- options: { palette: PAL.earth, width: 48, seed: 47 },+ options: {+ palette: ["#0e0c14", "#1a1724", "#211d2d", "#2b2639", "#3a3450", "#4a4263", "#6a6088", "#8e86a8"],+ glow: ["#4a1a0c", "#a8401a", "#ff8a2a", "#ffd27a", "#fff4d0"],+ reach: 118,+ seed: 12,+ },};-const DUST = ["#2e2620", "#4e4236", "#76664f", "#a08c6c"].map(hex);-const JOLTS = [0.0, 0.32, 0.62];+const JOLTS = [0.06, 0.5, 0.92], CLOSE = 2.2;-// 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]));- });- }+export function create(o) {+ const S = fit(o.palette, 8), G = fit(o.glow, 5), R = new Rng(o.seed), floor = () => 0, REACH = o.reach;+ const DUST = mix(S[6], hex("#8c8494"), 0.4), DUST2 = mix(S[5], hex("#6c6474"), 0.35);+ const ps = new Particles({ rng: R, ground: floor, sparks: [G[4], G[3], G[2], G[1]] });+ const bits = new Bits({ ground: floor }), lights = new Lights();+ // the rift: a jagged line out both ways, its depth into the floor at each step+ const rift = [];+ for (let x = -REACH; x <= REACH; x += R.range(2.5, 5)) rift.push([x, R.int(0, 2)]);+ const slabs = [];+ for (let x = -REACH + 8; x < REACH - 6; x += R.range(12, 17)) slabs.push({ x: x + R.range(-2, 2), y: 0, vy: 0, a: 0, va: 0, rest: true, s: R.range(4.5, 6), side: R.sign(), pts: [[-1, -0.38], [1, -0.42], [1.02, 0.4], [-0.98, 0.38]] });+ let t = 0, j = 0;+ const open = () => ease.outCubic(clamp((t - JOLTS[0]) / 0.45)) * REACH * (0.55 + 0.45 * smooth(JOLTS[1], JOLTS[1] + 0.3, t));+ const gap = (x) => (1 - smooth(CLOSE, CLOSE + 0.5, t)) * (1 + 2.6 * (1 - Math.abs(x) / REACH)) * (0.6 + 0.4 * smooth(JOLTS[1], JOLTS[2] + 0.2, t));+ const heat = () => smooth(0, 0.3, t) * (1 - smooth(1.4, CLOSE + 0.3, t)) * (0.8 + 0.2 * Math.sin(t * 17));+ const shake = () => JOLTS.reduce((s, tj, i) => (t > tj ? s + Math.exp(-(t - tj) * 9) * Math.sin((t - tj) * 80) * (1.6 - i * 0.3) : s), 0);+ return {+ update(dt) {+ t += dt;+ const f = Math.min(1, dt * 120);+ while (j < JOLTS.length && t >= JOLTS[j]) {+ const k = 1 - j * 0.2, L = open() + 10;+ j++;+ lights.add(0, -2, 60, G[2], 0.5 * k, 0.5);+ lights.add(0, -2, 26, WHITE, 0.4 * k, 0.07);+ // the floor heaves: slabs along the split jump and twist, pebbles and stones hop, dust bursts out+ for (const s of slabs) {+ const d = Math.abs(s.x) / REACH;+ if (Math.abs(s.x) > L || R.chance(0.25 + d * 0.3)) continue;+ (s.rest = false), (s.vy = -R.range(70, 170) * k * (1 - d * 0.5)), (s.va = s.side * R.range(3, 8));+ }+ for (let i = 0; i < 70 * k; i++) {+ const x = R.range(-L, L), a = -Math.PI / 2 + R.range(-0.6, 0.6), sp = R.range(40, 200) * k;+ ps.spawn(P.GRIT, x, -1, Math.cos(a) * sp, Math.sin(a) * sp, R.range(0.6, 1.2), R.pick([S[7], S[6], S[5], S[4]]), R.chance(0.35) ? 2 : 1);+ }+ for (let i = 0; i < 8 * k; i++) {+ const x = R.range(-L, L) * 0.8, a = -Math.PI / 2 + R.range(-0.9, 0.9), sp = R.range(100, 230) * k;+ bits.add({ kind: B.CHUNK, x, y: -2, vx: Math.cos(a) * sp, vy: Math.sin(a) * sp, g: 1, drag: 0.5, bounce: 0.3, life: Math.min(R.range(1.1, 1.6), meta.duration - 0.1 - t), a: R.range(0, TAU), va: R.range(-14, 14), s: R.range(1.6, 3.2), pts: stoneShape(R) });+ }+ for (let i = 0; i < 14 * k; i++) {+ const x = R.range(-L, L) * 0.9;+ ps.spawn(P.SMOKE, x, -R.range(1, 4), R.range(-40, 40), -R.range(15, 55) * k, R.range(1, 1.7), R.chance(0.5) ? DUST : DUST2, R.range(4, 7) * k, R.range(0, 0.15), PF.BIG);+ }+ for (let i = 0; i < 10 * k; i++) {+ const x = R.range(-L, L) * 0.7, a = -Math.PI / 2 + R.range(-1, 1), sp = R.range(120, 300);+ ps.spawn(P.SPARK, x, -1, Math.cos(a) * sp, Math.sin(a) * sp, R.range(0.12, 0.3));+ }+ }+ // between jolts the split keeps breathing grit and wisps of dust, embers float up out of it+ if (t > JOLTS[0] && t < CLOSE && R.chance(0.3 * f)) {+ const x = R.range(-1, 1) * open();+ ps.spawn(P.GRIT, x, -1, R.range(-20, 20), -R.range(20, 70), R.range(0.5, 0.8), R.pick([S[6], S[5]]), 1);+ if (R.chance(0.3)) ps.spawn(P.EMBER, x, -1, R.range(-10, 10), -R.range(20, 45), Math.min(R.range(0.6, 1.2), meta.duration - 0.1 - t), G[3], 1);+ if (R.chance(0.25)) ps.spawn(P.DUST, x, -1, R.range(-15, 15), -R.range(4, 14), R.range(0.5, 0.8), DUST2, R.range(2, 3.5));+ }+ for (const s of slabs) {+ if (s.rest) continue;+ s.vy += 950 * dt;+ s.y += s.vy * dt;+ s.a += s.va * dt;+ if (s.y >= 0 && s.vy > 0) {+ s.y = 0;+ s.a = clamp(s.a, -0.45, 0.45);+ if (s.vy > 160) (s.vy *= -0.25), (s.va *= -0.4);+ else {+ s.rest = true;+ for (let i = 0; i < 3; i++) ps.spawn(P.DUST, s.x + R.range(-5, 5), -0.5, R.sign() * R.range(10, 40), -R.range(2, 12), R.range(0.4, 0.7), DUST2, R.range(1.5, 3));+ }+ }+ }+ bits.update(dt);+ for (const b of bits.list)+ if (b.rest && !b.dusted) {+ b.dusted = true;+ ps.spawn(P.DUST, b.x, -0.5, R.sign() * R.range(8, 30), -R.range(2, 10), Math.min(R.range(0.3, 0.6), meta.duration - 0.1 - t), DUST2, R.range(1.3, 2.4));+ }+ ps.update(dt);+ lights.update(dt);+ },+ drawBack(p) {+ // the rift: lit along its upper lip, dark inside with a deep glow, opening out from the middle+ const L = open(), hk = heat(), jx = shake(), fade = 1 - smooth(CLOSE + 0.3, CLOSE + 0.7, t);+ if (t > JOLTS[0])+ for (let i = 1; i < rift.length; i++) {+ const [x0, d0] = rift[i - 1], [x1, d1] = rift[i];+ if (Math.abs(x0) > L) continue;+ for (let x = Math.ceil(x0); x < x1; x++) {+ const u = (x - x0) / (x1 - x0), d = Math.round(d0 + (d1 - d0) * u), w = gap(x), X = x + jx;+ if (w < 0.4) {+ p.dot(X, d, S[1], fade);+ continue;+ }+ p.dot(X, d - 1, S[6], fade);+ const deep = rand(Math.floor(x / 3), 41) + (w - 1.5) * 0.35, hot = hk * clamp(deep - 0.35, 0, 1) * 1.6;+ for (let y = 0; y < w; y++) p.dot(X, d + y, y > w / 2 - 1 && hot > 0.25 ? (hot > 0.9 && rand(x, Math.floor(t * 12)) < 0.6 ? G[3] : G[2]) : y > w / 2 - 1 && hot > 0.08 ? G[1] : S[0], fade);+ p.dot(X, d + Math.ceil(w), S[2], fade);+ }+ if (i % 3 === 0 && hk > 0) p.glow(x1 + jx, d1 + 1, 9, G[2], 0.35 * hk * (1 - Math.abs(x1) / (REACH * 1.2)));+ }+ ps.draw(p, "back");+ },+ draw(p) {+ // slabs of floor heaved up out of it, tilted, sinking back as it closes+ const jx = shake(), sink = smooth(CLOSE, CLOSE + 0.6, t);+ for (const s of slabs) if (!(s.rest && s.a === 0 && s.y === 0) && sink < 1) drawRock(p, s.x + jx, s.y - 1.5 + sink * 4, s.s, s.a, s.pts, S, 1 - sink);+ for (const b of bits.list) drawRock(p, b.x, b.y, b.s, b.a, b.pts, S, Math.min(1, b.life / 0.4));+ ps.draw(p, "front");+ lights.draw(p);+ },+ };}diff --git a/src/fx/nature/root-snare.js b/src/fx/nature/root-snare.jsindex 547c00b..be3ef65 100644--- a/src/fx/nature/root-snare.js+++ b/src/fx/nature/root-snare.js@@ -1,95 +1,168 @@-import { PAL, ramp, burst, fly, seg, ease, clamp, lerp, TAU, hex } from "../../core/index.js";+// The hold-then-break (it closes round the character, holds with glints, cracks, then bursts into tumbling+// pieces, mist and light) is adapted from Sprite Fusion's open-source ice freeze (https://www.spritefusion.com/pixel-art-vfx/ice),+// MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Lights, P, Rng, fit, sparkle, clamp, smooth, ease, lerp, rand, TAU, WHITE } from "../../core/index.js";+import { drawRock, stoneShape, drawLeaf, floorCrack } from "./_lib.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,+ desc: "The floor cracks and roots burst up round the character, spiralling round its legs; they cinch tight with a snap, hold, then crack and crumble into bark and dust.",+ tags: ["nature", "roots", "plant", "snare", "root", "status", "actor", "one-shot"],+ size: [128, 96],+ origin: [64, 78],+ duration: 2.7,loop: false,fps: 30,bg: "ground",- actor: true,- options: { palette: PAL.wood, seed: 23 },+ actor: 2,+ options: {+ palette: ["#140c08", "#2a1a10", "#46301e", "#64462a", "#86623a", "#a8824e", "#ccaa70", "#ecd6a0"],+ glow: ["#123818", "#2f7a2a", "#6cb83a", "#c8f070"],+ seed: 7,+ },};-const DIRT = ["#2e2418", "#4c3a26", "#6e5638"].map(hex);-const LEAF = ["#2c5a22", "#4f9a3a", "#8ccc52"].map(hex);-const STEPS = 64;+const SY = 0.34, CINCH = 0.62, BREAK = 1.75, NP = 48;-// 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];+// one root: from the floor outside the feet it spirals in round the legs and climbs, thinning to its tip+function path(r, cinch) {+ const pts = [];+ for (let i = 0; i <= NP; i++) {+ const s = i / NP, th = r.th0 + r.dir * TAU * r.turns * s, rad = lerp(r.r0, r.leg - cinch * 1.6, ease.outCubic(Math.min(1, s * 3.5)));+ pts.push({ x: Math.cos(th) * rad, y: -r.h * Math.pow(s, 1.05) + Math.sin(th) * rad * SY, z: Math.sin(th), s });+ }+ return pts;}-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;+// a stroke of bark along the path: lit on its upper side, dark beneath, a ridge of grain, rootlet hairs+function root(p, pts, g, C, back, a) {+ const n = Math.floor(NP * g);+ for (let i = 0; i < n; i++) {+ const A = pts[i], Bp = pts[i + 1], front = (A.z + Bp.z) / 2 >= 0;+ if (front === back) continue;+ const dx = Bp.x - A.x, dy = Bp.y - A.y, L = Math.hypot(dx, dy) || 1, nx = -dy / L, ny = dx / L, up = nx * -0.6 + ny * -0.8 > 0 ? 1 : -1;+ const w = (1.4 + 3.6 * Math.pow(1 - A.s, 0.8)) / 2 + 0.35, dim = back ? 1 : 0;+ for (let y = Math.floor(Math.min(A.y, Bp.y) - w - 1); y <= Math.ceil(Math.max(A.y, Bp.y) + w + 1); y++)+ for (let x = Math.floor(Math.min(A.x, Bp.x) - w - 1); x <= Math.ceil(Math.max(A.x, Bp.x) + w + 1); x++) {+ if (y > 0) continue;+ const px = x + 0.5 - A.x, py = y + 0.5 - A.y, u = (px * dx + py * dy) / (L * L);+ if (u < -0.2 || u > 1.2) continue;+ const d = px * nx + py * ny;+ if (Math.abs(d) > w) continue;+ const side = Math.sign(d) * up, q = Math.abs(d) / w;+ let i2 = q > 0.72 ? (side > 0 ? 7 : 1) : side > 0 ? (q > 0.3 ? 6 : 5) : q > 0.35 ? 2 : 3;+ if (q < 0.25 && rand(Math.round(A.s * 40), 3) < 0.4) i2 = 4;+ p.dot(x, y, C[Math.max(1, i2 - dim)], a);}- 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]);- }+ // rootlet hairs off its underside now and then+ if (i % 7 === 3 && w > 1.2) p.dot(A.x - nx * up * (w + 1), A.y - ny * up * (w + 1), C[2 - dim], a);}}-export const drawBack = (p, t, o) => roots(p, t, o, false);-export const draw = (p, t, o) => roots(p, t, o, true);+export function create(o) {+ const C = fit(o.palette, 8), G = fit(o.glow, 4), R = new Rng(o.seed), floor = () => 0;+ const ps = new Particles({ rng: R, ground: floor, sparks: [G[3], G[2], G[1], G[0]] });+ const lights = new Lights(), chips = [];+ const roots = Array.from({ length: 5 }, (_, i) => ({+ th0: (i / 5) * TAU + R.range(-0.3, 0.3), dir: i % 2 ? 1 : -1, turns: R.range(1.1, 1.6), r0: R.range(14, 19), leg: R.range(8, 10),+ h: R.range(13, 21), at: 0.16 + i * 0.07 + R.range(0, 0.04), buds: [R.range(0.35, 0.55), R.range(0.6, 0.85)],+ }));+ const cracks = [floorCrack(R, -1, R.range(18, 26)), floorCrack(R, 1, R.range(18, 26))];+ let t = 0, cinched = false, broken = false;+ const grow = (r) => ease.outCubic(clamp((t - r.at) / 0.32));+ const squeeze = () => smooth(CINCH - 0.03, CINCH + 0.05, t) * (1 - 0.4 * smooth(CINCH + 0.05, CINCH + 0.25, t));+ return {+ update(dt) {+ t += dt;+ const f = Math.min(1, dt * 120);+ if (t < 0.4 && R.chance(0.3 * f)) {+ const sd = R.sign();+ ps.spawn(P.GRIT, sd * R.range(4, 22), -1, R.range(-20, 20), -R.range(30, 90), R.range(0.5, 0.9), R.pick([C[5], C[4]]), 1);+ }+ for (const r of roots)+ if (!r.burst && t >= r.at) {+ r.burst = true;+ const x = Math.cos(r.th0) * r.r0;+ for (let i = 0; i < 4; i++) chips.push({ x, y: -1, vx: R.range(-60, 60), vy: -R.range(60, 160), a: R.range(0, TAU), va: R.range(-15, 15), s: R.range(1.2, 2), pts: stoneShape(R), life: R.range(0.6, 0.9) });+ for (let i = 0; i < 3; i++) ps.spawn(P.DUST, x, -1, R.range(-25, 25), -R.range(4, 18), R.range(0.4, 0.8), C[5], R.range(2, 3.5));+ lights.add(x, -4, 20, G[2], 0.35, 0.3);+ }+ if (!cinched && t >= CINCH) {+ cinched = true;+ lights.add(0, -10, 40, G[3], 0.5, 0.3);+ lights.add(0, -10, 16, WHITE, 0.4, 0.06);+ for (let i = 0; i < 8; i++) ps.spawn(P.DUST, R.range(-12, 12), -R.range(0, 4), R.sign() * R.range(20, 60), -R.range(4, 14), R.range(0.5, 0.9), C[5], R.range(2, 3.5));+ for (let i = 0; i < 6; i++) ps.spawn(P.STAR, R.range(-9, 9), -R.range(4, 20), 0, -4, R.range(0.25, 0.5), G[3], R.range(0.8, 1.8), R.range(0, 0.1));+ }+ // while it holds, motes of green rise off the roots+ if (t > CINCH && t < BREAK && R.chance(0.06 * f)) ps.spawn(P.MOTE, R.range(-9, 9), -R.range(3, 18), R.range(-6, 6), -R.range(14, 30), R.range(0.5, 0.9), G[3], 0.6);+ if (!broken && t >= BREAK) {+ broken = true;+ lights.add(0, -10, 36, G[2], 0.4, 0.25);+ // every root crumbles into bark chunks and splinters along its length+ for (const r of roots) {+ const pts = path(r, 1);+ for (let i = 2; i < NP; i += 4) {+ const q = pts[i], w = 1.4 + 3.6 * Math.pow(1 - q.s, 0.8);+ chips.push({ x: q.x, y: Math.min(q.y, -1), vx: (Math.sign(q.x) || 1) * R.range(25, 85) + q.x * 3, vy: -R.range(50, 150), a: R.range(0, TAU), va: R.range(-10, 10), s: clamp(w * 0.75, 1.5, 3), pts: stoneShape(R), life: Math.min(R.range(0.7, 0.95), meta.duration - 0.05 - t) });+ if (i % 10 === 2) ps.spawn(P.GRIT, q.x, Math.min(q.y, -1), R.range(-40, 40), -R.range(20, 80), Math.min(R.range(0.6, 0.9), meta.duration - 0.05 - t), R.pick([C[4], C[3], C[2]]), R.chance(0.3) ? 2 : 1);+ }+ }+ for (let i = 0; i < 10; i++) ps.spawn(P.SMOKE, R.range(-12, 12), -R.range(2, 16), R.range(-25, 25), -R.range(5, 20), Math.min(R.range(0.6, 0.9), meta.duration - 0.05 - t), C[5], R.range(3, 5), 0, 0);+ }+ for (let i = chips.length - 1; i >= 0; i--) {+ const c = chips[i];+ if ((c.life -= dt) <= 0) chips.splice(i, 1);+ c.vy += 950 * dt;+ c.x += c.vx * dt;+ c.y += c.vy * dt;+ c.a += c.va * dt;+ if (c.y > 0 && c.vy > 0) c.vy > 110 ? ((c.y = 0), (c.vy *= -0.3), (c.vx *= 0.5)) : ((c.y = 0), (c.vy = c.vx = c.va = 0));+ }+ ps.update(dt);+ lights.update(dt);+ },+ drawBack(p) {+ // cracks run out from the feet, a mossy light seeping up from them+ const open = ease.outCubic(clamp(t / 0.25)), hot = smooth(0, 0.3, t) * (1 - smooth(0.5, 1.4, t)), fade = 1 - smooth(meta.duration - 0.6, meta.duration - 0.15, t);+ for (const c of cracks) {+ const m = Math.max(2, Math.ceil(c.length * open));+ for (let k = 1; k < m; k++) {+ const [x0, y0] = c[k - 1], [x1, y1] = c[k];+ p.line(x0, y0 + 1, x1, y1 + 1, C[0], fade);+ p.line(x0, y0, x1, y1, hot > 0.5 ? G[3] : hot > 0.2 ? G[2] : C[1], fade);+ if (k % 2 === 0) p.glow(x1, y1, 6, G[2], 0.3 * hot);+ }+ }+ const hold = smooth(0.3, CINCH, t) * (1 - smooth(BREAK, BREAK + 0.3, t)) * (0.8 + 0.2 * Math.sin(t * 8));+ if (hold > 0) p.glow(0, -12, 30, G[2], 0.3 * hold), p.glow(0, -1, 22, G[3], 0.16 * hold);+ if (t < BREAK) for (const r of roots) if (t > r.at) root(p, path(r, squeeze()), grow(r), C, true, 1);+ ps.draw(p, "back");+ },+ draw(p) {+ if (t < BREAK) {+ for (const r of roots) {+ if (t <= r.at) continue;+ const pts = path(r, squeeze()), g = grow(r);+ root(p, pts, g, C, false, 1);+ // buds open into small leaves once it has hold of them+ for (const b of r.buds) {+ const q = pts[Math.floor(b * NP)], lk = clamp((t - CINCH - 0.1 - b * 0.2) / 0.25);+ if (b > g || lk <= 0 || q.z < 0) continue;+ drawLeaf(p, q.x + 2, q.y - 2, 5 * lk, 1.6, -0.6 + Math.sin(t * 5 + b * 9) * 0.2, 0.3, [G[0], G[1], G[2], G[3]]);+ }+ }+ // the snap as they cinch+ const e = t - CINCH;+ if (e > 0 && e < 0.12) for (const [x, y] of [[-8, -6], [8, -10], [-7, -15]]) sparkle(p, x, y, 5 * (1 - e / 0.12), C[7], G[3], 0.4);+ // the white flash just before they go+ const w = BREAK - t;+ if (w > 0 && w < 0.05) for (const r of roots) for (const q of path(r, 1)) if (q.z >= 0) p.px(q.x, q.y, WHITE);+ }+ const BARK = [C[0], C[1], C[2], C[2], C[3], C[4], C[5]];+ for (const c of chips) drawRock(p, c.x, c.y, c.s, c.a, c.pts, BARK, Math.min(1, c.life / 0.25));+ ps.draw(p, "front");+ lights.draw(p);+ },+ };+}diff --git a/src/fx/nature/sand-burst.js b/src/fx/nature/sand-burst.jsdeleted file mode 100644index 9435cdc..0000000--- a/src/fx/nature/sand-burst.js+++ /dev/null@@ -1,76 +0,0 @@-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.jsindex b07c79d..38e27a8 100644--- a/src/fx/nature/spore-burst.js+++ b/src/fx/nature/spore-burst.js@@ -1,88 +1,152 @@-import { ramp, at, burst, fly, seg, ease, clamp, lerp, TAU, hex } from "../../core/index.js";+// The lumpy cloud (puffs that drift off their push, rise, swell from small to large and thin out, lit caps,+// motes with light) is adapted from Sprite Fusion's open-source poison cloud (https://www.spritefusion.com/pixel-art-vfx/poison),+// MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Lights, P, Rng, fit, sparkle, clamp, smooth, ease, lerp, TAU, WHITE } from "../../core/index.js";+import { Gas } from "./_lib.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,+ desc: "A toadstool pushes up, swells and trembles as its gills glow, then squashes and puffs a lumpy cloud of glowing spores that billows up and drifts down twinkling.",+ tags: ["nature", "mushroom", "spores", "poison", "cloud", "ground", "one-shot"],+ size: [212, 132],+ origin: [106, 118],+ duration: 3.2,loop: false,fps: 30,bg: "ground",- options: { palette: ["#1e0c26", "#3a1450", "#5e1f74", "#8c2f92", "#bc4aa6", "#e47cc0", "#ffbade", "#fff2f8"], seed: 31 },+ options: {+ palette: ["#06141c", "#0c2a34", "#11484e", "#17706a", "#22a08a", "#4cd0a8", "#a8f4d0", "#f0fff6"],+ cap: ["#1a0c1e", "#3a1438", "#62204e", "#8e3462", "#bc5276", "#e88a96"],+ stem: ["#2a2230", "#5a4e5e", "#9a8e98", "#d8ccd0", "#f6eeee"],+ seed: 9,+ },};-const STEM = ["#4a3c3a", "#8a7a6c", "#cbbca4", "#f0e6d0"].map(hex);-const T_PUFF = 0.42;+const GROW = 0.32, PUFF = 0.8, SINK = 2.15, SPOTS = [[-0.45, 0.45, 1.4], [0.1, 0.72, 1.8], [0.55, 0.38, 1.2], [-0.12, 0.25, 1], [0.3, 0.12, 0.9], [-0.7, 0.16, 0.8]];-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]);+// the toadstool at its current squash: a stem with a frilled ring, a domed cap lit from the upper left with+// pale spots, glowing gills beneath it+function toadstool(p, K, Sm, Cs, g, sx, sy, glow, sink) {+ const H = 17 * g, cw = 17 * sx * g, ch = 13 * sy * g, base = sink, top = base - H;+ if (g < 0.05) return;+ // stem+ for (let y = Math.floor(top); y <= Math.min(0, base); y++)+ for (let x = -4; x <= 4; x++) {+ const w = 3 + ((y - top) / H) * 1;+ if (Math.abs(x + 0.5) > w) continue;+ const q = (x + 0.5 + w) / (2 * w);+ p.px(x, y, Math.abs(x + 0.5) > w - 0.8 ? Sm[1] : q < 0.4 ? Sm[4] : q < 0.7 ? Sm[3] : Sm[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 });+ const ring = top + H * 0.3;+ if (ring <= 0) for (let x = -5; x <= 5; x++) p.px(x, ring + (Math.abs(x) > 3 ? 1 : 0), Math.abs(x) > 4 ? Sm[1] : Sm[3]);+ // gills: a glowing underside+ const gy = top + 1;+ if (gy <= 0)+ for (let x = Math.floor(-cw); x <= Math.ceil(cw); x++) {+ const d = Math.abs(x + 0.5) / cw;+ if (d > 0.95) continue;+ p.px(x, gy, d < 0.3 ? Cs[0] : (x & 1) ? Sm[2] : Sm[3]);+ if (glow > 0.05) p.px(x, gy, glow > 0.6 && (x & 1) ? K[7] : K[5]);+ }+ if (glow > 0.05) p.glow(0, gy + 2, cw * 1.5 + 6, K[5], 0.5 * glow);+ // the cap: a dome with a curled lip+ p.shade(-cw - 1, top - ch - 1, cw + 1, top + 1, (x, y, out) => {+ const dx = x / cw, dy = (top - y) / ch, d = dx * dx + dy * dy;+ if (dy < -0.12 || d > 1.12 || y > 0) return;+ if (d > 1) return (out.c = Cs[0]);+ let i = dx < -0.35 && dy > 0.45 ? 5 : dx < 0.05 && dy > 0.3 ? 4 : dy < 0.18 ? 2 : dx > 0.55 ? 2 : 3;+ for (const [sx0, sy0, r] of SPOTS) {+ const ex = (dx - sx0) * cw, ey = (dy - sy0) * ch;+ if (ex * ex + ey * ey * 1.6 < r * r * g * g) i = ex < 0 && ey > 0 ? 9 : 8;+ }+ out.c = i === 9 ? Sm[4] : i === 8 ? Sm[3] : Cs[i];});- 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);+ p.px(-cw * 0.45, top - ch * 0.8, Cs[5]);+}++export function create(o) {+ const K = fit(o.palette, 8), Cs = fit(o.cap, 6), Sm = fit(o.stem, 5), R = new Rng(o.seed), floor = () => 0;+ const ps = new Particles({ rng: R, ground: floor, sparks: [K[7], K[6], K[5], K[4]], haze: K[5] });+ const gas = new Gas(), lights = new Lights();+ let t = 0, puffed = false, grown = false;+ const g = () => ease.outBack(clamp(t / GROW), 1.6) * (1 - ease.inCubic(clamp((t - SINK) / 0.45)));+ const charge = () => smooth(GROW, PUFF, t);+ // squash and stretch: it swells as it charges, squashes flat as it puffs, springs back+ const shape = () => {+ if (t < PUFF) {+ const k = charge(), j = Math.sin(t * 70) * 0.04 * k;+ return [1 + 0.28 * k + j, 1 + 0.22 * k - j];+ }+ const e = t - PUFF, sp = Math.exp(-e * 7) * Math.cos(e * 26);+ return [1 + 0.25 * sp, 1 - 0.35 * sp];+ };+ return {+ update(dt) {+ t += dt;+ const f = Math.min(1, dt * 120);+ if (!grown) {+ grown = true;+ for (let i = 0; i < 10; i++) ps.spawn(P.GRIT, R.range(-4, 4), -1, R.range(-50, 50), -R.range(40, 120), R.range(0.5, 0.8), R.pick([Sm[1], Sm[2]]), 1);+ for (let i = 0; i < 4; i++) ps.spawn(P.DUST, R.range(-4, 4), -1, R.sign() * R.range(10, 40), -R.range(4, 12), R.range(0.4, 0.7), Sm[1], R.range(2, 3));}- 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);+ // charging: spores gather toward the gills+ if (t > GROW && t < PUFF - 0.05 && R.chance(0.25 * f)) {+ const a = R.range(Math.PI * 1.05, Math.PI * 1.95), d = R.range(20, 38), x = Math.cos(a) * d, y = -18 + Math.sin(a) * d * 0.7;+ ps.spawn(P.STREAK, x, y, -x * 3, (-18 - y) * 3, R.range(0.2, 0.3), K[6]);+ }+ if (!puffed && t >= PUFF) {+ puffed = true;+ lights.add(0, -22, 30, WHITE, 0.6, 0.1);+ lights.add(0, -28, 70, K[5], 0.55, 0.9);+ // the cloud: lumps shoved up and out from under the cap, swelling as they go+ for (let i = 0; i < 30; i++) {+ const a = -Math.PI / 2 + R.range(-1.1, 1.1), sp = R.range(15, 95);+ gas.add(t, R.range(-8, 8), -20 + R.range(-3, 3), Math.cos(a) * sp * 1.3, Math.sin(a) * sp - 10, R.range(3, 5), R.range(8, 14), t + R.range(1.6, 2.2), R.range(5, 10));+ }+ for (let i = 0; i < 6; i++) {+ const sd = R.sign();+ gas.add(t, sd * R.range(6, 12), -5, sd * R.range(30, 70), -R.range(2, 14), R.range(2, 3), R.range(4, 6), t + R.range(0.8, 1.1), R.range(4, 8));+ }+ for (let i = 0; i < 40; i++) {+ const a = -Math.PI / 2 + R.range(-1.4, 1.4), sp = R.range(40, 160);+ const mote = R.chance(0.5), k = mote ? 0.35 : 0.7;+ ps.spawn(mote ? P.MOTE : P.FLAKE, R.range(-5, 5), -20, Math.cos(a) * sp * k, Math.sin(a) * sp * k, R.range(1, 2), R.pick([K[7], K[6], K[6], K[5]]), R.range(0.6, 1.6));+ }+ for (let i = 0; i < 6; i++) ps.spawn(P.STAR, R.range(-20, 20), -R.range(12, 40), 0, -6, R.range(0.3, 0.6), K[7], R.range(1, 2.4), R.range(0.05, 0.4));+ for (let i = 0; i < 8; i++) ps.spawn(P.DUST, R.sign() * R.range(4, 10), -1, R.sign() * R.range(30, 90), -R.range(2, 10), R.range(0.5, 0.9), K[3], R.range(2, 3.5));+ }+ // after it: spores keep drifting down out of the cloud, twinkling+ if (puffed && t < 2.6 && R.chance(0.12 * f)) ps.spawn(P.FLAKE, R.range(-40, 40), -R.range(30, 70), R.range(-8, 8), R.range(4, 14), Math.min(R.range(0.9, 1.5), meta.duration - 0.05 - t), R.chance(0.5) ? K[7] : K[6], R.range(0.6, 1.5));+ if (t > SINK && t < SINK + 0.4 && R.chance(0.15 * f)) ps.spawn(P.DUST, R.range(-5, 5), -1, R.sign() * R.range(10, 30), -R.range(2, 8), R.range(0.3, 0.5), Sm[1], R.range(1.5, 2.5));+ gas.prune(t);+ ps.update(dt);+ lights.update(dt);+ },+ drawBack(p) {+ // a ring of glow on the floor round it while it charges and puffs+ const k = charge() * (1 - smooth(PUFF + 0.2, PUFF + 1.2, t));+ if (k > 0) for (let x = -20; x <= 20; x++) p.dot(x, 0, Math.abs(x) < 10 ? K[5] : K[4], k * (1 - Math.abs(x) / 21));+ p.glow(0, -2, 30, K[4], 0.25 * k);+ ps.draw(p, "back");+ },+ draw(p) {+ const [sx, sy] = shape(), gl = t < PUFF ? charge() * (0.75 + 0.25 * Math.sin(t * (20 + 30 * charge()))) : Math.max(0, 1 - (t - PUFF) * 1.5);+ toadstool(p, K, Sm, Cs, g(), sx, sy, gl, ease.inCubic(clamp((t - SINK) / 0.45)) * 20);+ // the cloud: teal lumps lit along their tops, a cool light through them+ gas.draw(p, t, K[2], K[4], K[6], K[7], 0.62, K[6]);+ // the cloud glows from within: a soft light riding its middle+ if (gas.list.length) {+ let cx = 0, cy = 0, n = 0;+ for (const q of gas.list) {+ const g2 = gas.at(q, t);+ (cx += g2.x * g2.a), (cy += g2.y * g2.a), (n += g2.a);+ }+ if (n > 0.2) p.glow(cx / n, cy / n, 46, K[5], Math.min(0.32, 0.03 * n));+ }+ const e = t - PUFF;+ if (e > 0 && e < 0.1) sparkle(p, 0, -20, 10 * (1 - e / 0.1), K[7], K[6], 0.6);+ ps.draw(p, "front");+ lights.draw(p);+ },+ };}diff --git a/src/fx/nature/thorns.js b/src/fx/nature/thorns.jsindex 5c44427..2966fdd 100644--- a/src/fx/nature/thorns.js+++ b/src/fx/nature/thorns.js@@ -1,74 +1,158 @@-import { ramp, burst, fly, seg, ease, clamp, TAU, hex } from "../../core/index.js";+// The wave (spikes punching up one after another, each bigger, with overshoot, a white frame, a burst of debris+// and glints, a line running along the floor ahead of them) is adapted from Sprite Fusion's open-source ice+// spikes (https://www.spritefusion.com/pixel-art-vfx/ice), MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Lights, P, Rng, fit, clamp, smooth, ease, rand, TAU, WHITE } from "../../core/index.js";+import { drawRock, stoneShape, drawLeaf } from "./_lib.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,+ desc: "A seam races along the floor and hooked thorns punch up out of it one after another, each bigger than the last, in bursts of dirt and green light; they hold, then sink.",+ tags: ["nature", "thorns", "plant", "spikes", "ground", "attack", "one-shot"],+ size: [232, 92],+ origin: [48, 78],+ duration: 2.4,loop: false,fps: 30,bg: "ground",- options: { palette: ["#1a0c10", "#341420", "#56202a", "#7a3030", "#a04c38", "#c87a52", "#f0bc8c"], count: 7, spacing: 12, seed: 19 },+ options: {+ palette: ["#160c0e", "#2e1418", "#4e2224", "#743a30", "#9a5a3e", "#c08458", "#e2b484", "#fbe8c8"],+ glow: ["#123818", "#2f7a2a", "#6cb83a", "#c8f070"],+ soil: ["#120c0c", "#251917", "#3b2a24", "#553d31", "#715440", "#8f6e52", "#b8966e", "#e6d0a8"],+ count: 6,+ seed: 8,+ },};-const DIRT = ["#2e2418", "#4c3a26", "#6e5638"].map(hex);-const MOSS = ["#22401c", "#3a6a26", "#6a9a36"].map(hex);+const RISE = 0.11, SINK = 0.36;-// 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]);+// a hooked thorn: a hardwood horn tapering from its foot, its point hooked forward; lit down its left edge with a+// bright ridge, shaded on the right, grain running up it, a pale point, a barb off its back, a dark rim+function thorn(p, s, h, C, opts) {+ if (h < 1.5) return;+ const { x, w, hook, lean } = s, base = opts.base ?? 0, white = opts.white;+ const cx = (u) => x + lean * u + hook * Math.pow(u, 2.4), hw = (u) => (w / 2) * Math.pow(1 - u, 0.9) + 0.25;+ const inside = (px, py) => {+ const u = (base - (py + 0.5)) / h;+ if (u < 0 || u > 1 || py + 0.5 > 0) return false;+ const c = cx(u), fx = px + 0.5;+ return Math.abs(fx - c) <= hw(u);+ };+ const X0 = Math.floor(x - w - 6), X1 = Math.ceil(x + w / 2 + Math.abs(lean) + Math.abs(hook) + 2);+ for (let py = Math.floor(base - h) - 1; py <= Math.min(0, Math.ceil(base)); py++)+ for (let px = X0; px <= X1; px++) {+ if (!inside(px, py)) {+ if (py <= 0 && (inside(px - 1, py) || inside(px + 1, py) || inside(px, py + 1) || inside(px, py - 1))) p.dot(px, py, C[0], opts.a ?? 1);+ continue;+ }+ if (white) {+ p.px(px, py, WHITE);+ continue;+ }+ const u = (base - (py + 0.5)) / h, c = cx(u), r = hw(u), q = (px + 0.5 - (c - r)) / (2 * r);+ let i = q < 0 ? 4 : q < 0.16 ? 6 : q < 0.36 ? 5 : q < 0.46 ? 7 : q < 0.7 ? 4 : q < 0.86 ? 3 : 2;+ if (u > 0.86) i = q < 0.6 ? 7 : 5;+ if (i < 7 && i > 2 && rand(px, Math.floor((py + 0.5 - base) / 3), s.seed) < 0.12) i -= 1;+ p.px(px, py, C[i]);+ }+ // a barb off its back, raking up and away+ if (!white && h > 14) {+ const u0 = 0.34, u1 = 0.46, y0 = base - u0 * h, y1 = base - u1 * h, e0 = cx(u0) - hw(u0), e1 = cx(u1) - hw(u1), L = w * 0.45;+ if (y0 <= 0) {+ p.tri(e0 + 0.5, y0, e1 + 0.5, y1, e1 - L, y1 - L * 0.7, C[3]);+ p.line(e1, y1, e1 - L, y1 - L * 0.7, C[6]);+ p.px(e1 - L, y1 - L * 0.7, C[7]);+ p.line(e0, y0 + 1, e1 - L + 1, y1 - L * 0.7 + 1, C[0]);+ }}}-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);- }+export function create(o) {+ const C = fit(o.palette, 8), G = fit(o.glow, 4), S = fit(o.soil, 8), R = new Rng(o.seed), floor = () => 0, n = Math.max(2, o.count);+ const ps = new Particles({ rng: R, ground: floor, sparks: [G[3], G[2], G[1], G[0]] });+ const lights = new Lights(), chips = [];+ const list = Array.from({ length: n }, (_, i) => {+ const k = i / (n - 1), h = 12 + 36 * k + R.range(-1.5, 1.5);+ return { x: 10 + i * (104 / (n - 1)) + R.range(-3, 3), h, w: 6 + 9 * k, lean: R.range(-1, 1.5) + k * 2, hook: h * R.range(0.14, 0.22), at: 0.12 + i * 0.075, sink: 1.45 + i * 0.06, seed: R.int(1, 999), up: false, down: false };});+ const reach = list[n - 1].x + 8;+ let t = 0;+ const chip = (x, sp, nn) => {+ for (let i = 0; i < nn; i++) {+ const a = -Math.PI / 2 + R.range(-1.1, 1.1), v = R.range(60, 210) * sp;+ chips.push({ x: x + R.range(-3, 3), y: -1, vx: Math.cos(a) * v, vy: Math.sin(a) * v, a: R.range(0, TAU), va: R.range(-15, 15), s: R.range(1.3, 2.6) * Math.sqrt(sp), pts: stoneShape(R), life: Math.min(R.range(0.7, 1.1), meta.duration - 0.05 - t) });+ }+ };+ const grown = (s) => (t < s.at ? 0 : ease.outBack(clamp((t - s.at) / RISE), 2.4));+ const sunk = (s) => smooth(s.sink, s.sink + SINK, t);+ return {+ update(dt) {+ t += dt;+ const f = Math.min(1, dt * 120);+ for (const s of list) {+ const k = s.h / 48;+ if (!s.up && t >= s.at) {+ s.up = true;+ lights.add(s.x, -s.h * 0.5, 18 + 18 * k, WHITE, 0.45, 0.08);+ lights.add(s.x, -s.h * 0.4, 26 + 26 * k, G[2], 0.45, 0.4);+ chip(s.x, 0.6 + 0.6 * k, 3 + Math.round(5 * k));+ for (let i = 0; i < 10 + 18 * k; i++) {+ const a = -Math.PI / 2 + R.range(-1, 1), v = R.range(60, 230) * (0.6 + 0.6 * k);+ ps.spawn(P.GRIT, s.x + R.range(-s.w / 3, s.w / 3), -1, Math.cos(a) * v, Math.sin(a) * v, R.range(0.6, 1.1), R.pick([S[5], S[4], S[3]]), R.chance(0.3) ? 2 : 1);+ }+ for (let i = 0; i < 3 + 5 * k; i++) ps.spawn(P.SMOKE, s.x + R.range(-4, 4), -R.range(1, 4), R.sign() * R.range(20, 80), -R.range(5, 25), R.range(0.7, 1.2), S[5], R.range(3, 5.5) * (0.6 + 0.5 * k), 0, 0);+ for (let i = 0; i < 2 + 3 * k; i++) ps.spawn(P.STAR, s.x + s.hook * 0.8 + R.range(-3, 3), -s.h * R.range(0.5, 1), R.range(-10, 10), -R.range(5, 20), R.range(0.3, 0.6), G[3], R.range(0.8, 2), R.range(0, 0.12));+ for (let i = 0; i < 4; i++) ps.spawn(P.MOTE, s.x + R.range(-3, 3), -R.range(2, s.h * 0.6), R.range(-20, 20), -R.range(30, 70), R.range(0.4, 0.8), G[3], 0.7);+ }+ if (!s.down && t >= s.sink) {+ s.down = true;+ chip(s.x, 0.35, 2 + Math.round(2 * k));+ for (let i = 0; i < 3 + 3 * k; i++) ps.spawn(P.DUST, s.x + R.range(-s.w / 2, s.w / 2), -R.range(0, 3), R.sign() * R.range(15, 50), -R.range(2, 10), Math.min(R.range(0.4, 0.7), meta.duration - 0.05 - t), S[5], R.range(2, 4));+ }+ // while they stand, glints run up their lit edges+ if (s.up && !s.down && t > s.at + 0.2 && R.chance(0.05 * f)) ps.spawn(P.STAR, s.x + s.lean * 0.5 - s.w * 0.15, -s.h * R.range(0.3, 0.8), 0, -3, R.range(0.25, 0.45), C[7], R.range(0.8, 1.8));+ }+ for (let i = chips.length - 1; i >= 0; i--) {+ const c = chips[i];+ if ((c.life -= dt) <= 0) chips.splice(i, 1);+ c.vy += 950 * dt;+ c.x += c.vx * dt;+ c.y += c.vy * dt;+ c.a += c.va * dt;+ if (c.y > 0 && c.vy > 0) c.vy > 120 ? ((c.y = 0), (c.vy *= -0.3), (c.vx *= 0.6), (c.va *= 0.5)) : ((c.y = 0), (c.vy = c.vx = c.va = 0));+ }+ ps.update(dt);+ lights.update(dt);+ },+ drawBack(p) {+ // the seam racing ahead along the floor: a dark split with a green glow in it, closing up again at the end+ const run = ease.outCubic(clamp((t - 0.04) / 0.5)) * reach, fade = 1 - smooth(1.9, 2.3, t);+ for (let x = -2; x <= run; x++) {+ const hot = clamp(1 - (run - x) / 18) * (1 - smooth(0.6, 1.2, t)), h = rand(x, 31);+ p.dot(x, 0, hot > 0.4 ? G[3] : hot > 0.1 ? G[2] : S[0], fade);+ if (h < 0.5) p.dot(x, 1, S[1], fade * 0.8);+ if (h < 0.15) p.dot(x, -1, S[4], fade);+ if (hot > 0.3 && (x & 3) === 0) p.glow(x, 0, 6, G[2], 0.3 * hot);+ }+ ps.draw(p, "back");+ },+ draw(p) {+ for (const s of list) {+ const g = grown(s), k = sunk(s);+ if (g <= 0 || k >= 1) continue;+ thorn(p, s, s.h * g, C, { white: t - s.at < 0.035, base: k * s.h * 1.05 });+ if (t - s.at < 0.3) p.glow(s.x, -s.h * 0.5 * g, s.h * 0.6 + 6, G[2], 0.35 * (1 - (t - s.at) / 0.3));+ // a collar of leaves round its foot, unfurling as it comes up and folding away as it sinks+ const lk = clamp((t - s.at - 0.04) / 0.18) * (1 - k), lw = s.w * 0.5;+ if (lk > 0.05)+ for (const [sd, a0, sz] of [[-1, -2.5, 1], [1, -0.55, 0.9], [-1, -1.9, 0.7]]) {+ const la = a0 + sd * 0.25 * (1 - lk) + Math.sin(t * 4 + s.x) * 0.06, L = (5 + s.w * 0.45) * sz * lk;+ drawLeaf(p, s.x + sd * lw + Math.cos(la) * L * 0.5, -1 + Math.sin(la) * L * 0.5, L, 1.4 + s.w * 0.1 * sz, la, 0.35, [G[0], G[1], G[2], G[3]]);+ }+ p.glow(s.x, -2, s.w + 6, G[2], 0.18 * lk);+ }+ for (const c of chips) drawRock(p, c.x, c.y, c.s, c.a, c.pts, S, Math.min(1, c.life / 0.25));+ ps.draw(p, "front");+ lights.draw(p);+ },+ };}diff --git a/src/fx/nature/tornado.js b/src/fx/nature/tornado.jsindex e29eb80..a2efc88 100644--- a/src/fx/nature/tornado.js+++ b/src/fx/nature/tornado.js@@ -1,62 +1,188 @@-import { ramp, at, cycle, tileNoise, clamp, lerp, TAU, hex } from "../../core/index.js";+import { cycle, fit, rand, rng, smooth, clamp, lerp, TAU, WHITE, mix, tileNoise, bolt } from "../../core/index.js";+import { drawRock, stoneShape, drawLeaf } from "./_lib.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.",+ desc: "A snaking funnel of spinning wind bands under a flared, churning top that flickers with lightning; leaves and debris whirl round it front and back, dust boils at its foot.",tags: ["nature", "wind", "tornado", "storm", "hazard", "ground", "loop"],- size: [76, 80],- origin: [38, 72],- duration: 1.2,+ size: [196, 168],+ origin: [98, 152],+ duration: 2,loop: true,fps: 30,bg: "ground",- options: { palette: ["#1a1b24", "#2c2e3a", "#43465a", "#5e6378", "#7e8498", "#a2a8ba", "#c8ccd8", "#eef0f4"], height: 62, seed: 59 },+ options: {+ palette: ["#141221", "#231f33", "#36314a", "#4d4762", "#68617d", "#8a839e", "#b3adc4", "#e2def0"],+ dust: ["#2a2018", "#4e3e2e", "#76624a", "#a08a6a", "#cbb894"],+ leaves: ["#4a200c", "#a8541c", "#e8962e", "#ffd27a", "#123818", "#2f7a2a", "#6cb83a", "#c8f070"],+ height: 112,+ seed: 4,+ },};-const DEBRIS = ["#3a2a1c", "#6a4a2c", "#8e6a3e"].map(hex);-const LEAF = ["#2c5a22", "#4f9a3a", "#8ccc52"].map(hex);+const SY = 0.28;-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;+// the funnel at time t: its axis snakes (a wave running up it), its radius flares at the top+function geo(o, t) {+ const ph = (TAU * t) / meta.duration, FH = o.height;+ return {+ FH,+ ph,+ ax: (u) => 8.5 * Math.sin(ph - 2.6 * u) * (0.2 + 0.8 * u) + 3 * Math.sin(2 * ph + 1.3 - 4.5 * u) * u,+ rad: (u) => 3 + 20 * Math.pow(u, 1.5) + 17 * Math.pow(smooth(0.78, 1, u), 2),};- // 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]);+}++// the body: a translucent column, thicker through its middle, lit from the left, with streaks of dust that+// shear past each other as rows spin at different speeds+function body(p, C, Dst, g, t, seed) {+ const { FH, ax, rad } = g;+ for (let y = -Math.ceil(FH) + 2; y <= 0; y++) {+ const u = -y / FH, cx = ax(u), r = rad(u), K = 2 + (rand(y, seed) < 0.35 ? 1 : 0), rot = (TAU * K * t) / meta.duration;+ const fade = Math.min(1, u * 8 + 0.25) * (1 - smooth(0.9, 1.02, u));+ for (let x = Math.floor(cx - r); x <= Math.ceil(cx + r); x++) {+ const c = (x + 0.5 - cx) / r;+ if (Math.abs(c) > 1) continue;+ const n = tileNoise(((Math.acos(c) + rot) * 6) / TAU, y * 0.34, 6, 0, seed), v = -c * 0.55 + 0.15 + n * 0.55;+ let col = v > 0.6 ? C[6] : v > 0.28 ? C[5] : v > -0.05 ? C[4] : v > -0.4 ? C[3] : C[2];+ if (u < 0.3) col = mix(col, Dst[v > 0.3 ? 3 : v > -0.2 ? 2 : 1], 0.7 * (1 - u / 0.3));+ p.blend(x, y, col, (0.14 + 0.36 * Math.sqrt(1 - c * c)) * fade);+ }+ }+}++// wind bands: 1 px streaks wrapped round the funnel, bright at the head, fading along the tail; the far half+// goes behind, dimmer+function bands(p, C, g, t, seed, back) {+ const { FH, ax, rad } = g;+ for (let j = 0; j < 58; j++) {+ const R = rng(seed, j), u = (j + R.range(0.1, 0.9)) / 58, K = R.int(2, 4), span = R.range(0.7, 2.1), lvl = R.next();+ const cx = ax(u), r = rad(u) * R.range(1.0, 1.1), y0 = -u * FH, head = R.range(0, TAU) + (TAU * K * t) / meta.duration;+ if (u > 0.97) continue;+ for (let s = 0; s <= span; s += 0.5 / Math.max(2, r)) {+ const th = head - s, sn = Math.sin(th);+ if (sn > 0 === back) continue;+ const k = s / span, x = cx + r * Math.cos(th), y = y0 + r * SY * sn, lit = Math.cos(th) < 0.2;+ let i = lvl < 0.18 ? 2 : k < 0.15 && lvl > 0.55 ? 7 : k < 0.45 ? (lit ? 6 : 5) : lit ? 5 : 4;+ if (back) i = Math.max(1, i - 2);+ if (k < 0.5) p.dot(x, y, C[i]);+ else p.blend(x, y, C[i], 2 * (1 - k));+ }+ if (!back && lvl > 0.6 && Math.sin(head) > 0) {+ const hx = cx + r * Math.cos(head), hy = y0 + r * SY * Math.sin(head);+ p.dot(hx, hy, WHITE);+ p.glow(hx, hy, 5, C[6], 0.3);+ }+ }+}++// a soft flattened puff: rx wide, ry tall, blended+function blob(p, cx, cy, rx, ry, c, a) {+ for (let y = Math.floor(cy - ry); y <= Math.ceil(cy + ry); y++)+ for (let x = Math.floor(cx - rx); x <= Math.ceil(cx + rx); x++) {+ const dx = (x + 0.5 - cx) / rx, dy = (y + 0.5 - cy) / ry;+ if (dx * dx + dy * dy <= 1) p.blend(x, y, c, a);+ }+}++// the flared top: a lid of cloud sheared into flat bands that ride round with the funnel, each thick in the+// middle and drawn out to a thin tail behind, lit along its upper rim, dark beneath; a dark mass at its core+function crown(p, C, g, t, seed, back, flash) {+ const { FH, ax, rad } = g, cx = ax(1), r = rad(1), L = (c) => mix(c, C[7], flash * 0.6), y0 = -FH - 3;+ if (back) {+ blob(p, cx, y0 + 1, r * 0.85, 6, C[1], 0.6);+ blob(p, cx - 4, y0 - 3, r * 0.6, 3.5, L(C[3]), 0.45);+ }+ for (let j = 0; j < 16; j++) {+ const R = rng(seed, j), rr = r * R.range(0.4, 1.15), K = R.int(1, 2), span = R.range(1.4, 2.8), head = R.range(0, TAU) + (TAU * K * t) / meta.duration;+ const th0 = R.range(3.2, 6), lift = R.range(-4, 3) - (1 - rr / (r * 1.15)) * 5;+ for (let s2 = 0; s2 <= span; s2 += 0.6 / rr) {+ const th = head - s2, sn = Math.sin(th);+ if (sn > 0 === back) continue;+ const k = s2 / span, th2 = th0 * Math.sin(Math.PI * Math.pow(1 - k, 0.7)), x = cx + rr * Math.cos(th), y = y0 + lift + rr * SY * sn;+ const T = Math.max(1, Math.round(th2)), d = back ? 1 : 0, lit = Math.cos(th) < 0.3;+ for (let i = 0; i < T; i++) {+ const c = i === 0 ? L(C[(lit ? 6 : 5) - d]) : i === T - 1 && T > 2 ? C[1] : L(C[(i === 1 ? 4 : 3) - d]);+ p.blend(x, y - T / 2 + i, c, (0.55 + 0.35 * (1 - k)) * (back ? 0.75 : 1));+ }+ }+ }+}++// leaves, twigs and pebbles spiralling up round it and flung off the top+function debris(p, C, L, g, t, seed, back, S) {+ const { FH, ax, rad } = g;+ cycle(t, meta.duration, 24, seed, (q) => q.range(1.3, 1.95), (age, life, R, i) => {+ // the first stretch skids in across the floor, then it spirals up and is flung off the top+ const k = age / life, sk = R.range(0.15, 0.3), q = clamp((k - sk) / (1 - sk)), u = lerp(0.03, 0.98, Math.pow(q, 0.85));+ const th = R.range(0, TAU) + R.range(2, 3.2) * TAU * k, sn = Math.sin(th);+ if (sn > 0 === back) return;+ const fling = smooth(0.78, 1, q), inward = 1 - smooth(0, sk, k), far = R.range(26, 44);+ const rr = lerp(Math.min(68, rad(u) * (1.12 + fling * 1.1) + R.range(2, 7)), far, inward), x = ax(u) + rr * Math.cos(th), y = Math.min(-1, -u * FH + rr * SY * sn - fling * 8);+ const a = Math.min(1, k * 8) * (1 - smooth(0.85, 1, k)), kind = R.next(), spin = R.range(-14, 14) * age, dk = back ? 1 : 0;+ if (kind < 0.62) {+ const o = R.next() < 0.5 ? 0 : 4, pal = [L[o], L[o + 1], L[o + 2 - dk], L[o + 3 - dk]];+ drawLeaf(p, x, y, R.range(6, 9), R.range(1.8, 2.6), spin, age * R.range(5, 10), pal, a);+ } else if (kind < 0.8) {+ const ca = Math.cos(spin) * 2.5, sa = Math.sin(spin) * 2.5;+ p.line(x - ca, y - sa, x + ca, y + sa, back ? L[0] : L[1], a);+ p.dot(x + ca, y + sa, L[2], a);+ } else drawRock(p, x, y, R.range(1.6, 2.6), spin, stoneShape(R, 5), S, a);});- 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);+}++// at its foot: dust boiling round and out, grit hopping, scuffs swept round the floor+function skirt(p, D, g, t, seed, back) {+ const cx0 = g.ax(0);+ cycle(t, meta.duration, 40, seed, (q) => q.range(0.7, 1.3), (age, life, R) => {+ const k = age / life, th = R.range(0, TAU) + R.range(5, 9) * age, sn = Math.sin(th);+ if (sn > 0 === back) return;+ const rr = 4 + k * R.range(14, 28), x = cx0 + rr * Math.cos(th), y = -1.5 - k * R.range(4, 16) + rr * 0.3 * sn, s = R.range(3, 6) * (0.6 + 0.8 * k);+ const a = Math.min(1, k * 6) * (1 - k) * 0.6;+ p.disc(x, y + s * 0.2, s, D[back ? 1 : 2], a);+ p.disc(x - s * 0.2, y - s * 0.3, s * 0.55, D[back ? 2 : 3], a * 0.8);});- 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]));+ if (back) return;+ cycle(t, meta.duration, 16, seed + 7, (q) => q.range(0.35, 0.6), (age, life, R) => {+ const th = R.range(0, TAU), v = R.range(25, 55), x = cx0 + Math.cos(th) * (4 + v * age), y = Math.sin(th) * 2 - R.range(40, 80) * age + 260 * age * age;+ if (y < 0.5) p.dot(x, Math.min(0, y), R.next() < 0.5 ? D[3] : D[4], 1 - age / life);});- p.glow(axis(-H * 0.5), -H * 0.5, 30, C[6], 0.06);+ for (let j = 0; j < 7; j++) {+ const R = rng(seed + 3, j), rr = R.range(12, 28), th0 = R.range(0, TAU) + (TAU * 3 * t) / meta.duration, span = R.range(0.5, 1.1);+ for (let s = 0; s < span; s += 0.6 / rr) {+ const th = th0 - s;+ p.dot(cx0 + rr * Math.cos(th), 0.5 + rr * 0.18 * Math.sin(th), D[s < span * 0.4 ? 3 : 2], 1 - s / span);+ }+ }+}++// once a loop the crown lights up from inside+function flashAt(t) {+ const q = t / meta.duration;+ return Math.max(0, 1 - Math.abs(q - 0.62) / 0.025) + 0.6 * Math.max(0, 1 - Math.abs(q - 0.69) / 0.015);+}++export function drawBack(p, t, o) {+ const C = fit(o.palette, 8), D = fit(o.dust, 5), g = geo(o, t), f = flashAt(t);+ skirt(p, D, g, t, o.seed * 5 + 1, true);+ crown(p, C, g, t, o.seed * 7 + 2, true, f);+ bands(p, C, g, t, o.seed * 3 + 5, true);+ debris(p, C, fit(o.leaves, 8), g, t, o.seed * 11 + 3, true, C);+ body(p, C, D, g, t, o.seed);+}++export function draw(p, t, o) {+ const C = fit(o.palette, 8), D = fit(o.dust, 5), g = geo(o, t), f = flashAt(t), cx = g.ax(1);+ bands(p, C, g, t, o.seed * 3 + 5, false);+ crown(p, C, g, t, o.seed * 7 + 2, false, f);+ skirt(p, D, g, t, o.seed * 5 + 1, false);+ debris(p, C, fit(o.leaves, 8), g, t, o.seed * 11 + 3, false, C);+ // light: a soft pale column, a cold pool at its foot, the crown's lightning+ p.glowLine(g.ax(0.1), -g.FH * 0.1, cx, -g.FH * 0.9, 26, C[5], 0.08);+ p.glow(g.ax(0), -2, 30, D[3], 0.12);+ if (f > 0.05) {+ const R = rng(o.seed, 99, Math.floor(t / meta.duration * 7)), path = bolt(R, cx - 18, -g.FH - 6, cx + 16, -g.FH + 2, { jag: 0.3, depth: 3 });+ p.polyline(path, f > 0.6 ? WHITE : C[7], Math.min(1, f * 1.5));+ p.glow(cx, -g.FH - 2, 70, C[7], 0.45 * f);+ }}diff --git a/src/fx/nature/toxic-puddle.js b/src/fx/nature/toxic-puddle.jsindex b3280b4..0b2c481 100644--- a/src/fx/nature/toxic-puddle.js+++ b/src/fx/nature/toxic-puddle.js@@ -1,72 +1,148 @@-import { ramp, cycle, noise, ease, clamp, TAU } from "../../core/index.js";+import { cycle, fit, fly, rand, smooth, ease, clamp, mix, hex, tileNoise, TAU, WHITE } 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,+ desc: "Black tar lit from inside by chartreuse veins and a glowing rim, an oily sheen drifting on it; glossy bubbles dome, stretch and pop, vapour curls up in fraying ribbons.",+ tags: ["nature", "poison", "toxic", "sludge", "tar", "puddle", "hazard", "ground", "loop"],+ size: [176, 100],+ origin: [88, 86],+ duration: 4,loop: true,fps: 30,bg: "ground",- options: { palette: ["#0d1a0c", "#173a14", "#265e18", "#3f8a1e", "#6cb82a", "#a8e04a", "#e0ff8a"], width: 20, seed: 13 },+ options: {+ palette: ["#06070a", "#0c100c", "#141a10", "#1e2814", "#2e3c18", "#5a7a1c", "#a6d42a", "#ecff86"],+ sheen: ["#2a1648", "#5a2e8e", "#1e7a86", "#6adccc"],+ width: 42,+ seed: 2,+ },};-const BIG = [".##.", "#o.#", "#..#", ".##."];-const SMALL = [".#.", "#.#", ".#."];+const D = meta.duration;-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]);+// the surface height above the floor at x: a heavy lens of tar, slow swells rolling through it+function surf(x, W, t) {+ const d = Math.min(1, Math.abs(x) / W), ph = (TAU * t) / D;+ const lens = Math.sqrt(1 - d * d) * 6.6 + (d > 0.8 ? 1.6 * smooth(0.8, 0.9, d) : 0), swell = Math.max(0, Math.sin(x * 0.09 - ph)) ** 6 * 1.2 + Math.max(0, Math.sin(x * 0.06 + ph * 2 + 1)) ** 8 * 0.9;+ return -Math.round(lens + swell * (1 - d));+}++// the pool: an oily skin with a violet and teal sheen sliding over it, black depths threaded with veins of light,+// a chartreuse rim glowing where the tar meets the floor+function pool(p, C, Sh, W, t, seed) {+ const ph = t / D;+ for (let x = Math.floor(-W - 1); x <= Math.ceil(W + 1); x++) {+ const d = Math.abs(x + 0.5) / W;+ if (d > 1.03) continue;+ const top = surf(x + 0.5, W, t), oil = 0.6 * tileNoise(x * 0.08, ph * 4, 0, 4, seed) + 0.6 * tileNoise(x * 0.11 - ph * 4, 1, 4, 0, seed + 1), hue = tileNoise(x * 0.05, ph * 2 + 7, 0, 2, seed + 3);+ for (let y = top; y <= 2; y++) {+ if ((y === 2 && d > 0.75) || (y === 1 && d > 0.9)) continue;+ let c;+ if (d > 0.93 && y <= 0) c = y === top ? C[7] : C[6];+ else if (y === top) {+ // the skin catches light along its top: a lit edge, the sheen sliding over it, specular glints running along+ const glint = Math.abs(((x * 0.07 - ph * 3) % 1 + 1) % 1 - 0.5) < 0.012 || rand(x, Math.floor(t * 10)) < 0.015;+ c = glint ? WHITE : oil > 0.55 ? (hue > 0 ? Sh[3] : Sh[2]) : oil > 0.15 ? (hue > 0 ? Sh[1] : C[5]) : C[5];+ if (glint) p.light(x, y, C[7], 0.5);+ } else if (y === top + 1) c = oil > 0.4 ? Sh[0] : C[3];+ else if (y >= 1) c = C[0];+ else {+ // cracks of light under the crust, writhing slowly and swelling brighter and dimmer in a slow pulse+ const pulse = 0.5 + 0.5 * Math.sin((TAU * t) / D + x * 0.03), v = Math.abs(tileNoise(x * 0.09, y * 0.75 + ph * 4, 0, 4, seed + 7) + 0.2 * Math.sin((TAU * t * 2) / D + x * 0.15)), w = 0.6 + 0.6 * pulse;+ c = v < 0.035 * w ? C[7] : v < 0.08 * w ? C[6] : v < 0.14 * w ? C[4] : C[1];+ if (v < 0.08 * w) p.light(x, y, C[6], 0.25 + 0.3 * pulse);+ }+ p.px(x, y, c);+ }+ if (d > 0.9 && d <= 1.03) p.px(x, top - 1, C[1]);+ }+ // the glow bleeding out onto the floor at both lips+ for (const s of [-1, 1])+ for (let k = 1; k <= 6; k++) p.dot(s * (W + k), 0, k < 3 ? C[6] : C[5], 1 - k / 7);+}- // 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]);+// fat bubbles: dome up dark and glossy, stretch thin as light shows through their tops, pop in a ripple ring+// and a spatter of tar, and loose a ribbon of vapour+function bubbles(p, C, Sh, W, t, seed) {+ cycle(t, D, 8, seed, (g) => g.range(2.4, 3.2), (age, L, R) => {+ const swell = R.range(1, 1.6), x = R.range(-0.7, 0.7) * W, rmax = R.range(4.5, 8), sy = surf(x, W, t) + 0.5;+ if (age < swell) {+ const k = age / swell, st = smooth(0.65, 1, k), gr = ease.outCubic(Math.min(1, k * 1.3)), rx = rmax * gr * (1 - 0.18 * st), ry = rmax * gr * (1 + 0.5 * st);+ const X = Math.round(x), Y = Math.round(sy), inner = 0.35 + 0.65 * k;+ for (let j = -Math.ceil(ry) - 1; j <= 0; j++)+ for (let i = -Math.ceil(rx) - 1; i <= Math.ceil(rx) + 1; i++) {+ const dd = Math.hypot(i / Math.max(0.6, rx), j / Math.max(0.6, ry));+ if (dd > 1.1) continue;+ // a dark glossy skin with chartreuse light glowing up through it, strongest low in the middle+ let c;+ if (dd > 0.9) c = C[0];+ else if (dd < 0.55 * inner && j > -ry * 0.75) c = dd < 0.3 * inner ? C[6] : C[5];+ else if (dd < 0.8 * inner) c = C[4];+ else c = j < -ry * 0.5 ? C[2] : C[3];+ p.px(X + i, Y + j, c);+ }+ // the gloss: a curved band of sheen on its upper left, a bright highlight+ if (rx > 1.8)+ for (let a = 3.5; a < 4.7; a += 0.16) p.px(X + Math.cos(a) * rx * 0.68, Y + Math.sin(a) * ry * 0.68, a < 3.9 ? Sh[3] : a < 4.3 ? C[7] : Sh[1]);+ if (rx > 1.2) p.px(X - Math.round(rx * 0.35), Y - Math.round(ry * 0.62), WHITE), p.px(X - Math.round(rx * 0.35) + 1, Y - Math.round(ry * 0.62), C[7]);+ p.glow(x, sy - ry * 0.5, 7 + rx * 1.4, C[6], (0.2 + 0.35 * st) * gr);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]);+ const e = age - swell;+ // the pop: a ring rippling out flat across the tar, a flash of the light inside, spatter+ if (e < 0.3) {+ const k = e / 0.3, rr = 2 + 14 * ease.outCubic(k);+ for (let a = 0; a < TAU; a += 0.5 / rr) {+ const rx2 = x + Math.cos(a) * rr, ry2 = sy + Math.sin(a) * rr * 0.22;+ if (Math.abs(rx2) < W * 0.95) p.dot(rx2, ry2, k < 0.4 ? WHITE : k < 0.7 ? C[7] : C[6], (1 - k) * 1.4);+ }+ p.glowRing(x, sy, rr, 3, C[6], 0.35 * (1 - k));+ if (e < 0.1) p.glow(x, sy - 2, 18, C[6], 0.7 * (1 - e / 0.1));}+ for (let j = 0; j < 7; j++) {+ const vx = (rand(j, seed, Math.round(x * 10)) - 0.5) * 80, vy = -45 - rand(j, seed + 3, Math.round(x * 10)) * 70, [dx, dy] = fly(x, sy - 2, vx, vy, e, 420);+ if (dy < sy && e < 0.6) {+ p.px(dx, dy, C[1]);+ p.px(dx, dy - 1, j & 1 ? Sh[3] : C[6]);+ }+ }+ ribbon(p, C, x, sy - 2, e, L - swell, R, 0.9);});- // 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;+}++// vapour: a thin ribbon that curls up off the tar, then frays into wisps that wander apart and fade+function ribbon(p, C, x0, y0, age, life, R, k) {+ const u = age / life, len = R.range(16, 26), rise = R.range(9, 14), amp = R.range(2, 4.5), w = R.range(0.18, 0.3), ph = R.range(0, TAU);+ const head = rise * age, tail = Math.max(0, head - len), fray = smooth(0.35, 0.85, u), fade = smooth(0, 0.12, u) * (1 - smooth(0.5, 1, u)) * k;+ if (fade < 0.02) return;+ const GREY = hex("#b4b8ae"), n = fray > 0.05 ? 3 : 1;+ for (let h = tail; h <= head; h += 0.5) {+ const s = (h - tail) / Math.max(1, head - tail), cx = x0 + amp * Math.sin(h * w + ph + age * 1.6) * (0.3 + s), y = y0 - h, a = fade * Math.sin(Math.PI * s) * 0.45;+ // lit from below by the pool: green and bright low down, greying as it climbs and frays+ const lit = Math.max(0, 1 - h / 22) * (1 - 0.6 * fray), VAP = mix(GREY, C[6], 0.75 * lit);+ for (let q = 0; q < n; q++) {+ // each wisp wanders off on its own slow curl as the ribbon frays+ const off = n === 1 ? 0 : fray * s * (q - 1) * 3 + fray * 2.5 * Math.sin(h * (0.35 + q * 0.17) + ph * (q + 1) + age * 2);+ p.blend(cx + off, y, VAP, a * (n === 1 ? 1 : 0.65 - 0.25 * fray) * (0.8 + 0.4 * lit));}- 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);+ }+}++export function drawBack(p, t, o) {+ const C = fit(o.palette, 8), Sh = fit(o.sheen, 4), W = o.width, pulse = 0.85 + 0.15 * Math.sin((TAU * t * 2) / D);+ // the light comes from inside the pool and its rim+ p.glow(0, -3, W * 1.25, C[5], 0.22 * pulse);+ p.glow(0, -10, W * 1.1, C[6], 0.1 * pulse);+ for (const s of [-1, 1]) p.glow(s * W, -1, 12, C[6], 0.35 * pulse);+ pool(p, C, Sh, W, t, o.seed);+}++export function draw(p, t, o) {+ const C = fit(o.palette, 8), Sh = fit(o.sheen, 4), W = o.width;+ bubbles(p, C, Sh, W, t, o.seed * 7 + 1);+ // a steady breath of vapour ribbons off the whole pool+ cycle(t, D, 9, o.seed * 13 + 4, (g) => g.range(2.4, 3.4), (age, L, R) => {+ const x = R.range(-0.85, 0.85) * W;+ ribbon(p, C, x, surf(x, W, t) - 1, age, L, R, 0.75);});- 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.jsindex a04ae50..b82ba7f 100644--- a/src/fx/nature/vine-whip.js+++ b/src/fx/nature/vine-whip.js@@ -1,116 +1,210 @@-import { PAL, ramp, burst, fly, seg, ease, clamp, lerp, smooth, TAU, hex } from "../../core/index.js";+// The smear that trails the lash (white at its leading edge, cooling down the ramp as it thins), the glint and+// crack burst at the tip, are adapted from Sprite Fusion's open-source slash (https://www.spritefusion.com/pixel-art-vfx/slash),+// MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Lights, P, Rng, fit, sparkle, clamp, smooth, ease, lerp, TAU, WHITE, rand } from "../../core/index.js";+import { Drops, drawLeaf, drawRock, stoneShape } from "./_lib.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,+ desc: "A thorny vine bursts from the floor, rears back coiled, then lashes out right in a whip crack that sprays sap and tears off leaves, before sliding back into the ground.",+ tags: ["nature", "vine", "plant", "whip", "melee", "directional", "one-shot"],+ size: [216, 128],+ origin: [60, 114],+ duration: 1.4,loop: false,fps: 30,bg: "ground",- options: { palette: PAL.leaf, length: 56, seed: 17 },+ options: {+ palette: ["#0c1a10", "#173a1a", "#24582a", "#357a34", "#52a03e", "#86c84e", "#c4ec7a", "#f4ffd0"],+ thorn: ["#2a1410", "#5e2a1a", "#a04c2e", "#e89a6a"],+ soil: ["#120c0c", "#251917", "#3b2a24", "#553d31", "#715440", "#8f6e52", "#b8966e", "#e6d0a8"],+ seed: 3,+ },};-const THORN = ["#5a4a24", "#a8925a", "#e6d8a0"].map(hex);-const DIRT = ["#2e2418", "#4c3a26", "#6e5638"].map(hex);-const N = 30;+const N = 24, LS = 3.3, LASH = 0.36, LAG = 0.0052, TAU_S = 0.055, OMEGA = TAU / 0.21;+const CRACK = LASH + LAG * N + (Math.PI - Math.atan(OMEGA * TAU_S)) / OMEGA;-// 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;+// a damped spring's step: 0 before u = 0, swings past 1, settles+const spring = (u) => (u <= 0 ? 0 : 1 - Math.exp(-u / TAU_S) * (Math.cos(OMEGA * u) + Math.sin(OMEGA * u) / (OMEGA * TAU_S)));++// the vine's points at time t: each segment's angle blends from standing, to reared back with the tip coiled+// over, to lashed out right; the lash runs up the vine as a wave, so the tip whips through last+function pose(t) {+ const grow = ease.outCubic(clamp(t / 0.14)) * (1 - ease.inCubic(clamp((t - 1.0) / 0.3))), rear = smooth(0.1, LASH, t), relax = smooth(0.82, 1.0, t);+ const pts = [[0, (1 - grow) * (N * LS + 6)]];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]);+ const s = i / N, stand = -Math.PI / 2 + 0.25 * Math.sin(s * 3 + t * 7) * s;+ const back = -Math.PI / 2 - 0.3 - 1.65 * Math.pow(s, 1.3), out = -1.0 + 0.9 * Math.pow(s, 0.6);+ let a = lerp(stand, back, rear);+ a = lerp(a, out, spring(t - LASH - LAG * i));+ a = lerp(a, stand, relax);+ const [x, y] = pts[i];+ pts.push([x + Math.cos(a) * LS, y + Math.sin(a) * LS]);}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]);+// a translucent polygon: the soft body of the smear under its streaks+function haze(p, pts, c, a) {+ 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));+ for (let y = Math.floor(y0); y <= Math.ceil(y1); y++)+ for (let x = Math.floor(x0); x <= Math.ceil(x1); x++) {+ let inside = false;+ for (let i = 0, j = pts.length - 1; i < pts.length; j = i++) {+ const [xi, yi] = pts[i], [xj, yj] = pts[j];+ if (yi > y + 0.5 !== yj > y + 0.5 && x + 0.5 < ((xj - xi) * (y + 0.5 - yi)) / (yj - yi) + xi) inside = !inside;+ }+ if (inside) p.blend(x, y, c, a);+ }+}++const width = (s) => 1.2 + 4.8 * Math.pow(1 - s, 0.7);++// the vine itself: a thick stroke lit on its upper side with a bright edge, dark beneath, bark notches+function vine(p, pts, C) {+ for (let i = 0; i < N; i++) {+ const [ax, ay] = pts[i], [bx, by] = pts[i + 1], dx = bx - ax, dy = by - ay, L = Math.hypot(dx, dy) || 1, nx = -dy / L, ny = dx / L;+ const w0 = width(i / N) / 2, w1 = width((i + 1) / N) / 2, up = nx * -0.6 + ny * -0.8 > 0 ? 1 : -1;+ const X0 = Math.floor(Math.min(ax, bx) - 4), X1 = Math.ceil(Math.max(ax, bx) + 4), Y0 = Math.floor(Math.min(ay, by) - 4), Y1 = Math.ceil(Math.max(ay, by) + 4);+ for (let y = Y0; y <= Y1; y++)+ for (let x = X0; x <= X1; x++) {+ if (y > 0) continue;+ const px = x + 0.5 - ax, py = y + 0.5 - ay, u = (px * dx + py * dy) / (L * L);+ if (u < -0.15 || u > 1.15) continue;+ const d = px * nx + py * ny, w = lerp(w0, w1, clamp(u)) + 0.35;+ if (Math.abs(d) > w) continue;+ const side = Math.sign(d) * up, q = Math.abs(d) / w, arc = (i + u) * LS;+ let c = q > 0.8 ? (side > 0 ? C[5] : C[1]) : side > 0 ? (q > 0.35 ? C[4] : C[3]) : q > 0.4 ? C[2] : C[3];+ if (w > 1.6 && Math.abs(((arc + d * 0.8) % 5) - 2.5) < 0.45 && q < 0.8) c = C[2];+ p.px(x, y, c);+ }}- // 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]);+}++// thorns along it, alternating sides, hooked back toward the root; leaves on short stalks+function thorns(p, pts, T, C, t, R) {+ for (let i = 2; i < N - 1; i += 2) {+ const [ax, ay] = pts[i], [bx, by] = pts[i + 1], dx = bx - ax, dy = by - ay, L = Math.hypot(dx, dy) || 1, side = (i / 2) % 2 ? 1 : -1;+ const nx = (-dy / L) * side, ny = (dx / L) * side, w = width(i / N) / 2, len = 1.8 + 2.4 * (1 - i / N), tx0 = dx / L, ty0 = dy / L;+ const x0 = ax + nx * (w - 0.5), y0 = ay + ny * (w - 0.5), tx = x0 + nx * len - tx0 * len * 0.7, ty = y0 + ny * len - ty0 * len * 0.7;+ if (y0 > 0) continue;+ // a hooked thorn: a broad foot on the stem, a sharp lit point raking back toward the root+ p.tri(x0 - tx0 * 1.6, y0 - ty0 * 1.6, x0 + tx0 * 1.4, y0 + ty0 * 1.4, tx, ty, T[1]);+ p.line(x0 + tx0 * 0.8, y0 + ty0 * 0.8, tx, ty, T[2]);+ p.px(tx, ty, T[3]);}- 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));+ for (const k of [7, 13, 18]) {+ const [ax, ay] = pts[k], [bx, by] = pts[k + 1], a = Math.atan2(by - ay, bx - ax), side = k % 2 ? 1 : -1;+ if (ay > -2) continue;+ const la = a + side * 1.1 + Math.sin(t * 9 + k) * 0.2, lx = ax + Math.cos(la) * 4, ly = ay + Math.sin(la) * 4;+ drawLeaf(p, lx, ly, 7, 2.2, la, 0.3 + Math.sin(t * 5 + k) * 0.4, [C[1], C[3], C[5], C[6]]);}- // 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;+}++export function create(o) {+ const C = fit(o.palette, 8), T = fit(o.thorn, 4), S = fit(o.soil, 8), R = new Rng(o.seed), floor = () => 0;+ const ps = new Particles({ rng: R, ground: floor, sparks: [C[7], C[6], C[5], C[4]] });+ const drops = new Drops(floor), lights = new Lights(), chips = [], torn = [], spots = [];+ let t = 0, burst = false, cracked = false, sunk = false;+ const dirt = (n, sp) => {+ for (let i = 0; i < n; i++) {+ const a = -Math.PI / 2 + R.range(-1.2, 1.2), v = R.range(60, 200) * sp;+ chips.push({ x: R.range(-3, 3), y: -1, vx: Math.cos(a) * v, vy: Math.sin(a) * v, a: R.range(0, TAU), va: R.range(-15, 15), s: R.range(1.4, 2.6), pts: stoneShape(R), life: Math.min(R.range(0.6, 0.9), meta.duration - 0.05 - t) });}- }- // 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));+ for (let i = 0; i < n * 3; i++) {+ const a = -Math.PI / 2 + R.range(-1, 1), v = R.range(50, 200) * sp;+ ps.spawn(P.GRIT, R.range(-3, 3), -1, Math.cos(a) * v, Math.sin(a) * v, Math.min(R.range(0.5, 0.9), meta.duration - 0.05 - t), R.pick([S[5], S[4], S[3]]), R.chance(0.3) ? 2 : 1);+ }+ for (let i = 0; i < n; i++) ps.spawn(P.DUST, R.range(-4, 4), -R.range(0, 3), R.sign() * R.range(15, 60), -R.range(4, 20), Math.min(R.range(0.4, 0.8), meta.duration - 0.05 - t), S[5], R.range(2, 4));+ };+ return {+ update(dt) {+ t += dt;+ if (!burst) (burst = true), dirt(6, 1);+ if (!cracked && t >= CRACK) {+ cracked = true;+ const a = pose(t), b = pose(t - 0.01), [x, y] = a[N], vx = (x - b[N][0]) / 0.01, vy = (y - b[N][1]) / 0.01, sp = Math.hypot(vx, vy) || 1;+ lights.add(x, y, 22, WHITE, 0.5, 0.08);+ lights.add(x, y, 50, C[5], 0.35, 0.4);+ for (let i = 0; i < 18; i++) {+ const ang = Math.atan2(vy, vx) + R.range(-0.7, 0.7), v = R.range(80, 260);+ drops.add(x, y, Math.cos(ang) * v, Math.sin(ang) * v - R.range(0, 60), R.chance(0.3) ? 2 : 1);+ }+ for (let i = 0; i < 4; i++) torn.push({ x, y, vx: (vx / sp) * R.range(40, 120) + R.range(-30, 30), vy: R.range(-90, -20), a: R.range(0, TAU), va: R.range(-12, 12), fl: R.range(0, TAU), vf: R.range(8, 16), life: R.range(0.65, 0.8), max: 0 });+ for (const l of torn) l.max = l.life;+ for (let i = 0; i < 8; i++) ps.spawn(P.STAR, x + R.range(-6, 6), y + R.range(-6, 6), R.range(-20, 20), R.range(-20, 20), R.range(0.15, 0.35), C[7], R.range(0.6, 1.6));+ }+ if (!sunk && t >= 1.08) (sunk = true), dirt(3, 0.5);+ drops.update(dt, (d) => spots.push({ x: d.x, t0: t, w: d.s * 0.7 + R.range(0.2, 1) }));+ for (let i = chips.length - 1; i >= 0; i--) {+ const c = chips[i];+ if ((c.life -= dt) <= 0) chips.splice(i, 1);+ c.vy += 950 * dt;+ c.x += c.vx * dt;+ c.y += c.vy * dt;+ c.a += c.va * dt;+ if (c.y > 0) (c.y = 0), (c.vy *= -0.3), (c.vx *= 0.6);+ }+ for (let i = torn.length - 1; i >= 0; i--) {+ const l = torn[i];+ if ((l.life -= dt) <= 0) torn.splice(i, 1);+ l.vy += 160 * dt;+ l.vx -= l.vx * 2.5 * dt;+ l.vy -= l.vy * 2 * dt;+ l.x += l.vx * dt + Math.sin(l.fl) * 20 * dt;+ l.y += l.vy * dt;+ l.a += l.va * dt;+ l.fl += l.vf * dt;+ }+ ps.update(dt);+ lights.update(dt);+ },+ drawBack(p) {+ // a hole torn in the floor where it comes up, sap spots where it sprays+ const k = 1 - smooth(1.15, 1.35, t);+ for (let x = -5; x <= 5; x++) p.dot(x, 0, Math.abs(x) < 3 ? S[0] : S[1], k * (1 - Math.abs(x) / 7));+ for (const s of spots) {+ const a = (1 - smooth(0.25, 0.6, t - s.t0)) * (1 - smooth(1.2, 1.35, t));+ for (let x = Math.floor(s.x - s.w); x <= Math.ceil(s.x + s.w); x++) p.dot(x, 0, t - s.t0 < 0.1 ? C[6] : C[4], a);+ }+ ps.draw(p, "back");+ },+ draw(p) {+ const pts = pose(t);+ // the smear: a fan of streaks, each the path one point of the outer vine just swept, the tip's white,+ // the ones further in cooling down the ramp, all fading back along their length+ if (t > LASH + 0.04 && t < CRACK + 0.1) {+ const age = clamp((t - CRACK + 0.02) / 0.12), hist = [];+ for (let k = 0; k < 12; k++) hist.push(pose(t - k * 0.0045));+ for (let k = 0; k < 6; k++) haze(p, [hist[k][N], hist[k + 1][N], hist[k + 1][N - 12], hist[k][N - 12]], k < 2 ? C[6] : C[5], 0.4 * (1 - k / 6) * (1 - age));+ for (let i = N - 12; i <= N; i += 2) {+ const q = (N - i) / 12, col = q < 0.1 ? WHITE : q < 0.3 ? C[7] : q < 0.55 ? C[6] : q < 0.8 ? C[5] : C[4], len = Math.round(11 * (1 - q * 0.6));+ for (let k = 0; k < len; k++) p.line(hist[k][i][0], hist[k][i][1], hist[k + 1][i][0], hist[k + 1][i][1], k < 2 && q < 0.1 ? WHITE : col, (1 - age) * (k < len * 0.5 ? 1 : 2 * (1 - k / len)));+ }+ p.glowLine(hist[0][N][0], hist[0][N][1], hist[6][N][0], hist[6][N][1], 14, C[5], 0.35 * (1 - age));+ }+ vine(p, pts, C);+ thorns(p, pts, T, C, t, null);+ const lk = smooth(LASH, CRACK, t) * (1 - smooth(CRACK, CRACK + 0.35, t));+ if (lk > 0) for (let i = 6; i <= N; i += 6) p.glow(pts[i][0], pts[i][1], 12, C[5], 0.18 * lk);+ // the crack: a white burst of air lines and a glint at the tip+ const e = t - CRACK;+ if (e >= 0 && e < 0.12) {+ const [x, y] = pts[N], k = 1 - e / 0.12;+ for (let j = 0; j < 7; j++) {+ const a = (j / 7) * TAU + 0.3, r0 = 4 + 10 * (1 - k), r1 = r0 + 5 * k;+ p.line(x + Math.cos(a) * r0, y + Math.sin(a) * r0, x + Math.cos(a) * r1, y + Math.sin(a) * r1, k > 0.5 ? WHITE : C[6]);+ }+ p.ring(x, y, 3 + 8 * (1 - k), 1, C[7], k);+ sparkle(p, x, y, 7 * k, C[7], C[5], 0.4);+ }+ for (const c of chips) drawRock(p, c.x, c.y, c.s, c.a, c.pts, S, Math.min(1, c.life / 0.25));+ for (const l of torn) drawLeaf(p, l.x, l.y, 6, 2, l.a, l.fl, [C[1], C[3], C[5], C[6]], Math.min(1, l.life / 0.3));+ drops.draw(p, C);+ ps.draw(p, "front");+ lights.draw(p);+ },+ };}diff --git a/src/fx/nature/wind-gust.js b/src/fx/nature/wind-gust.jsdeleted file mode 100644index eeef6b1..0000000--- a/src/fx/nature/wind-gust.js+++ /dev/null@@ -1,55 +0,0 @@-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.jsindex 485802b..15cb347 100644--- a/src/fx/pickups/_lib.js+++ b/src/fx/pickups/_lib.js@@ -1,7 +1,7 @@// 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";+import { createFrame, Painter, TAU, WHITE, hex, ramp, scale, rand } 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@@ -149,3 +149,261 @@ export function heartSdf(x, y, cx, cy, w, h = w) {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;}++// ---- the rebuilt pickups (techniques from Sprite Fusion's open-source pickup and sparkle, MIT, Hugo Duprez)++const INK = hex("#0b0814");++/**+ * A soft floor shadow at x, half-width rx: dithered darkness on the floor line, fuller in the middle, with a+ * shorter second row under it. k (0..1) is its strength: lift the thing above and the shadow shrinks and thins.+ */+export function blobShadow(p, x, rx, k = 1, y = 0) {+ if (rx < 0.8 || k <= 0) return;+ for (let i = Math.floor(x - rx); i <= Math.ceil(x + rx); i++) {+ const u = Math.abs(i + 0.5 - x) / rx;+ if (u > 1) continue;+ const a = k * (1 - u * u);+ p.dot(i, y, INK, a * 1.1);+ if (u < 0.6) p.dot(i, y + 1, INK, a * 0.6);+ }+}++/** A four-point star glint: arms of arm px in c, dimmer tips, a white heart, its own light. */+export function glint(p, x, y, arm, c, k = 0.4, tip = scale(c, 0.8)) {+ const n = Math.round(arm), X = Math.floor(x), Y = Math.floor(y);+ if (n < 0) return;+ for (let d = 1; d <= n; d++) {+ const cc = d === n && n > 1 ? tip : c;+ p.px(X + d, Y, cc), p.px(X - d, Y, cc), p.px(X, Y + d, cc), p.px(X, Y - d, cc);+ }+ p.px(X, Y, n > 0 ? WHITE : c);+ p.glow(X + 0.5, Y + 0.5, 3 + n * 2.5, c, k);+}++/** Additive light in an ellipse (a pool of light on the floor): k at the center falling off to the rim. */+export function pool(p, x, y, rx, ry, c, k) {+ if (k <= 0.004 || rx < 1) 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;+ });+}++/**+ * A coin of radius r tumbling: its face turns by `spin` about an axis at screen angle `ax`, showing its rim+ * as it goes edge-on. A lit rim round a face with a shine, built in layer L with a dark outline, lit from the+ * top left. C: an 8-step gold ramp. snap puts its center on a pixel corner (even sizes) so it holds its shape+ * while it moves; pass snap false and a pixel-center y for odd heights.+ */+export function coin(L, p, x, y, r, ax, spin, C, white = false, a = 1, snap = true) {+ const X = snap ? Math.round(x) : x, Y = snap ? Math.round(y) : y, cs = Math.cos(spin), sn = Math.sin(spin);+ const b = Math.max(0.5, r * Math.abs(cs)), th = 1.2 * sn * Math.sign(cs || 1), ca = Math.cos(ax), sa = Math.sin(ax);+ const face = Math.abs(cs), R = Math.ceil(r) + 2;+ L.begin(Math.floor(X) - R, Math.floor(Y) - R);+ L.fill(Math.floor(X) - R, Math.floor(Y) - R, Math.floor(X) + R, Math.floor(Y) + R, (px, py) => {+ const dx = px - X, dy = py - Y, u = dx * ca + dy * sa, w = -dx * sa + dy * ca;+ const ef = Math.hypot(u / r, w / b), er = Math.hypot(u / r, (w - th) / b);+ if (white && (ef <= 1 || er <= 1)) return WHITE;+ if (ef <= 1) {+ // in the face's own frame: the raised rim, a recessed ring inside it, a raised middle with a shine+ const lit = -(dx * 0.62 + dy * 0.78) / Math.max(1, Math.hypot(dx, dy)), dim = face < 0.45 ? 1 : 0;+ if (b < 1.1) return lit > 0 ? C[6] : C[4];+ if (ef > 0.72) return C[(lit > 0.3 ? 6 : lit > -0.35 ? 5 : 3) - dim];+ if (b > 2.2 && ef > 0.42) return C[(lit > 0.2 ? 4 : 5) - dim];+ if (face > 0.6 && lit > 0.5) return C[7];+ return C[5 - dim];+ }+ if (er <= 1) return Math.abs(w - th) < Math.abs(w) ? C[2] : C[3];+ return 0;+ });+ L.outline(C[1]).draw(p, 0, 0, a);+}++/**+ * A small cut gem of radius r turned to angle `ang` (radians, on screen): a crown with a table over a pointed+ * pavilion, its facets lit from the top left, a white glint on the table; G is a ramp dark to bright (6++ * steps). Built in L with a dark outline.+ */+export function gemlet(L, p, x, y, r, ang, G, white = false, a = 1) {+ const X = Math.round(x), Y = Math.round(y), ca = Math.cos(ang), sa = Math.sin(ang), n = G.length, R = Math.ceil(r * 1.4) + 2;+ const ct = r * 0.75, tw = r * 0.5, pv = r * 1.3;+ L.begin(X - R, Y - R);+ L.fill(X - R, Y - R, X + R - 1, Y + R - 1, (px, py) => {+ const dx = px - X, dy = py - Y, u = dx * ca + dy * sa, w = -dx * sa + dy * ca;+ let facet;+ if (w < 0) {+ if (w < -ct || Math.abs(u) > r - ((-w) / ct) * (r - tw)) return 0;+ facet = w < -ct * 0.45 && Math.abs(u) < tw * 0.95 ? 0 : u < 0 ? 1 : 2;+ } else {+ if (w > pv || Math.abs(u) > r * (1 - w / pv)) return 0;+ facet = Math.abs(u) < 0.5 ? 4 : u < 0 ? 3 : 5;+ }+ if (white) return WHITE;+ // each facet's normal, turned with the gem; the light comes from the top left of the screen+ const N = [[0, -1], [-0.7, -0.7], [0.7, -0.7], [-0.6, 0.8], [0, 1], [0.6, 0.8]][facet];+ const nx = N[0] * ca - N[1] * sa, ny = N[0] * sa + N[1] * ca, l = -(nx * 0.62 + ny * 0.78);+ if (facet === 0 && l > 0.3 && u < 0) return WHITE;+ return l > 0.6 ? G[n - 1] : l > 0.2 ? G[n - 2] : l > -0.2 ? G[n - 3] : l > -0.6 ? G[n - 4] : G[n - 5];+ });+ L.outline(G[0]).draw(p, 0, 0, a);+}++/**+ * A cut gem as a convex solid: facet planes { n: [x, y, z] outward unit normal, d, kind }, y up, z towards+ * the viewer, the girdle on y = 0. brilliant() builds a round brilliant: a table, crown facets, a thin+ * girdle, pavilion facets down to a point; n facets round (8 by default).+ */+export function brilliant({ r = 7.5, crown = 3.6, table = 0.52, pavilion = 8, girdle = 0.8, n = 8 } = {}) {+ const planes = [{ n: [0, 1, 0], d: crown + girdle / 2, kind: 0 }];+ const cs = Math.atan2(crown, r * (1 - table)), ps = Math.atan2(pavilion, r);+ for (let i = 0; i < n * 2; i++) {+ const a = (i * Math.PI) / n, half = i % 2;+ const c = half ? Math.min(1.45, cs + 0.22) : cs, pv = half ? ps - 0.1 : ps;+ // crown: main facets, and steeper ones between them by the girdle+ planes.push({ n: [Math.sin(c) * Math.cos(a), Math.cos(c), Math.sin(c) * Math.sin(a)], d: r * Math.sin(c) * (half ? 1.012 : 1) + (girdle / 2) * Math.cos(c), kind: half ? 2 : 1 });+ // the girdle: a ring of thin upright faces+ planes.push({ n: [Math.cos(a), 0, Math.sin(a)], d: r * (half ? 1.0 : 1.0), kind: 3 });+ // pavilion: main facets to the point, shallower ones between them by the girdle+ planes.push({ n: [Math.sin(pv) * Math.cos(a), -Math.cos(pv), Math.sin(pv) * Math.sin(a)], d: r * Math.sin(pv) * (half ? 1.03 : 1) + (girdle / 2) * Math.cos(pv), kind: half ? 5 : 4 });+ }+ return { planes, r, top: crown + girdle / 2, bottom: pavilion + girdle / 2 };+}++/**+ * A crystal: an n-sided prism (apothem r, half-height half) with a pointed cap of height top and a shorter+ * point of height bottom, as facet planes for drawGem (kinds 6 prism, 7 cap, 8 point).+ */+export function prism({ r = 4.6, half = 5.5, top = 7.5, bottom = 6, n = 6 } = {}) {+ const planes = [], ct = Math.atan2(top, r), cb = Math.atan2(bottom, r);+ for (let i = 0; i < n; i++) {+ const a = (i * TAU) / n;+ planes.push({ n: [Math.cos(a), 0, Math.sin(a)], d: r, kind: 6 });+ planes.push({ n: [Math.sin(ct) * Math.cos(a), Math.cos(ct), Math.sin(ct) * Math.sin(a)], d: Math.sin(ct) * r + Math.cos(ct) * half, kind: 7 });+ planes.push({ n: [Math.sin(cb) * Math.cos(a), -Math.cos(cb), Math.sin(cb) * Math.sin(a)], d: Math.sin(cb) * r + Math.cos(cb) * half, kind: 8 });+ }+ return { planes, r: r / Math.cos(Math.PI / n), top: half + top, bottom: half + bottom };+}++/**+ * Draw gem g turned by spin (radians about its upright axis), its center (the girdle) at (x, y), seen from a+ * little above (tilt), into layer L with a dark outline. Each pixel finds the facet it looks at; crown facets+ * catch the light from the top left, pavilion facets glow with the light bouncing up through the stone.+ * C: ramp dark to bright (8). Returns the brightest spot { x, y } for a glint.+ */+export function drawGem(L, p, g, x, y, spin, C, { tilt = 0.32, white = false, a = 1, edges = true, gain = 1 } = {}) {+ const cs = Math.cos(spin), sn = Math.sin(spin), ct = Math.cos(tilt), st = Math.sin(tilt);+ const P = g.planes.map((q) => ({ n: [q.n[0] * cs - q.n[2] * sn, q.n[1], q.n[0] * sn + q.n[2] * cs], d: q.d, kind: q.kind }));+ // light from the top left, a little in front; the eye looks down the tilted z axis+ const Lx = -0.55, Ly = 0.72, Lz = 0.42, D = [0, -st, -ct], V = [0, st, ct];+ const Hl = Math.hypot(Lx + V[0], Ly + V[1], Lz + V[2]), H = [(Lx + V[0]) / Hl, (Ly + V[1]) / Hl, (Lz + V[2]) / Hl];+ const X = Math.round(x), Y = Math.round(y), R = Math.ceil(g.r) + 2, top = Math.ceil(g.top + 2), bot = Math.ceil(g.bottom + 2);+ let best = -1, bx = X, by = Y;+ const ids = new Map();+ L.begin(X - R, Y - top);+ L.fill(X - R, Y - top, X + R, Y + bot, (px, py) => {+ const sx = px - X, sy = -(py - Y);+ // the ray through this pixel: origin on the screen plane, straight down the view axis+ const o = [sx, sy * ct, -sy * st];+ let t0 = -1e9, t1 = 1e9, hit = null;+ for (const q of P) {+ const nd = q.n[0] * D[0] + q.n[1] * D[1] + q.n[2] * D[2], no = q.n[0] * o[0] + q.n[1] * o[1] + q.n[2] * o[2];+ if (Math.abs(nd) < 1e-6) {+ if (no > q.d) return 0;+ continue;+ }+ const tt = (q.d - no) / nd;+ if (nd < 0) {+ if (tt > t0) (t0 = tt), (hit = q);+ } else if (tt < t1) t1 = tt;+ }+ if (!hit || t0 > t1) return 0;+ if (white) return WHITE;+ ids.set((Math.floor(px) + 500) * 1000 + Math.floor(py) + 500, P.indexOf(hit));+ const n = hit.n, pav = hit.kind === 4 || hit.kind === 5 || hit.kind === 8;+ // the pavilion shows light that came in through the crown and bounced back: mirror its normal+ const m = pav ? [n[0], -n[1] * 0.6, n[2]] : n, ml = Math.hypot(m[0], m[1], m[2]);+ const lam = Math.max(0, (m[0] * Lx + m[1] * Ly + m[2] * Lz) / ml), spec = Math.pow(Math.max(0, (m[0] * H[0] + m[1] * H[1] + m[2] * H[2]) / ml), 18);+ let b = pav ? 0.02 + 0.72 * Math.pow(lam, 2.4) : hit.kind === 3 ? 0.12 + 0.4 * lam : 0.04 + 0.66 * Math.pow(lam, 1.8);+ // a crystal's upright faces are lit by the light's level direction; its cap catches it from above+ if (hit.kind === 6) b = 0.16 + 0.66 * Math.pow(Math.max(0, (n[0] * Lx + n[2] * Lz) / Math.hypot(Lx, Lz)), 1.3);+ else if (hit.kind === 7) b = 0.22 + 0.62 * Math.pow(lam, 1.2);+ // a fracture shows the lit inside of the stone, rough and grainy; chips are small rough facets+ else if (hit.kind === 9) b = 0.62 + 0.25 * lam;+ else if (hit.kind === 10) b = 0.3 + 0.5 * lam + (rand(Math.floor(px - X), Math.floor(py - Y), 43) - 0.5) * 0.08;+ if (hit.kind !== 9) b *= gain;+ if (hit.kind === 0) b -= 0.04;+ const s = b + spec * 0.6;+ if (s > best) (best = s), (bx = px), (by = py);+ if (spec > 0.8) return pav ? C[6] : WHITE;+ return C[Math.max(1, Math.min(6, Math.round(1 + s * 5.6)))];+ });+ // the cut: where two facets meet, a pavilion edge sinks a shade and a crown ridge catches a shade more light+ if (!white && edges) {+ const out = [];+ for (const [key, id] of ids) {+ const kx = Math.floor(key / 1000), ky = key - kx * 1000, x = kx - 500, y = ky - 500, r = ids.get(key + 1000), d = ids.get(key + 1);+ if ((r !== undefined && r !== id) || (d !== undefined && d !== id)) {+ const c = L.get(x, y) >>> 0, i = C.findIndex((k) => k >>> 0 === c), pav = [4, 5, 8].includes(P[id].kind);+ if (i > 0) out.push([x, y, pav ? C[Math.max(1, i - 1)] : C[Math.min(7, i + 1)]]);+ }+ }+ for (const [x, y, c] of out) L.set(x, y, c);+ }+ L.outline(C[0]).draw(p, 0, 0, a);+ return { x: bx, y: by, k: best };+}++/**+ * A thick coin turning on its upright axis: radius r, thickness th, turned by theta (0 faces you). Each row+ * shows the face (squashed by cos theta, a raised rim, a recessed field, an embossed star) and, beside it,+ * the reeded edge band (th |sin theta| wide). Lit from the top left; the face flashes white as it squares+ * to the light. Built in L with a dark outline. C: 8-step ramp. Returns the flash strength 0..1.+ */+export function coin3d(L, p, x, y, r, th, theta, C, { a = 1, white = false } = {}) {+ const ct = Math.cos(theta), st = Math.sin(theta), sg = ct < 0 ? -1 : 1, act = Math.abs(ct), ast = Math.abs(st);+ const xc = (th / 2) * st * sg, nfx = st * sg, Lx = -0.55, Ly = 0.45, Lz = 0.7, Ln = Math.hypot(Lx, Ly, Lz);+ // the face's normal stays level, so its flash comes when it squares to the light's level direction+ const lam = (nfx * Lx + act * Lz) / Ln, Hx = Lx / Ln, Hz = Lz / Ln + 1, Hn = Math.hypot(Hx, Hz);+ const base = Math.max(2, Math.min(5, Math.round(2 + lam * 3.2)));+ const X = Math.round(x), Y = Math.round(y), B = Math.ceil(r + th) + 2;+ let flash = 0;+ L.begin(X - B, Y - B);+ L.fill(X - B, Y - B, X + B, Y + B, (px, py) => {+ const sx = px - X, sy = -(py - Y);+ if (Math.abs(sy) > r) return 0;+ const s = Math.sqrt(1 - (sy / r) ** 2), hw = r * s * act, xr = -(st < 0 ? -1 : 1) * s * r * ct, rw = (th / 2) * ast;+ if (white && (Math.abs(sx - xc) <= hw || Math.abs(sx - xr) <= rw + 0.05)) return WHITE;+ if (Math.abs(sx - xc) <= hw && act > 0.08) {+ // on the face: un-squash to the face's own coordinates+ const fx = (sx - xc) / act, fy = sy, d = Math.hypot(fx, fy) / r;+ // a faint curve across the face makes the flash sweep over it as it turns+ const tx = nfx + (fx / r) * 0.3 * act, sp = Math.pow(Math.max(0, (tx * Hx + act * Hz) / Hn / Math.hypot(tx, act)), 130);+ flash = Math.max(flash, sp);+ // relief in whole ramp steps so it shows at every angle: a raised rim lit on its upper left, a recessed+ // field, a raised diamond with lit and shaded faces+ const lit = (-fx * 0.6 + fy * 0.8) / Math.max(0.5, Math.hypot(fx, fy));+ let k;+ if (d > 0.76) k = base + (lit > 0.75 ? 2 : lit > 0.3 ? 1 : lit < -0.35 ? -1 : 0);+ else {+ const q = (Math.abs(fx) + Math.abs(fy)) / (r * 0.52);+ k = q >= 1 ? base - 1 : q < 0.45 ? base + 1 : fx <= 0 && fy >= 0 ? base + 1 : fx > 0 && fy < 0 ? base - 2 : base;+ }+ if (sp > 0.5) return sp > 0.8 ? WHITE : C[Math.min(7, k + 2)];+ return C[Math.max(2, Math.min(6, k))];+ }+ if (Math.abs(sx - xr) <= rw + 0.05) {+ // the reeded edge: grooves across the band, lit by the edge's own normal+ const cphi = xr < 0 ? -s : s, n = [cphi * ct, sy / r, -cphi * st], l = (n[0] * Lx + n[1] * Ly + n[2] * Lz) / Ln;+ const groove = Math.floor((Math.asin(sy / r) + Math.PI) * 9) % 2;+ const edge = Math.abs(sx - xr) > rw - 0.6 && Math.sign(sx - xr) === Math.sign(xc - xr);+ return C[Math.max(1, Math.min(6, Math.round(2.6 + l * 2.6) - groove + (edge ? 1 : 0)))];+ }+ return 0;+ });+ L.outline(C[1]).draw(p, 0, 0, a);+ return flash;+}diff --git a/src/fx/pickups/ammo-crate.js b/src/fx/pickups/ammo-crate.jsdeleted file mode 100644index d9fc71d..0000000--- a/src/fx/pickups/ammo-crate.js+++ /dev/null@@ -1,62 +0,0 @@-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.jsindex 05e4066..ee0938c 100644--- a/src/fx/pickups/chest-open.js+++ b/src/fx/pickups/chest-open.js@@ -1,137 +1,408 @@-import { PAL, RAMP, hex, burst, seg, ease, bump, WHITE } from "../../core/index.js";-import { Layer, twinkle, fit } from "./_lib.js";+// The collection pop (white squash, a ring snapping out, star sparks) and the glints follow Sprite Fusion's+// open-source pickup (https://www.spritefusion.com/pixel-art-vfx/pickup), MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Lights, P, Rng, fit, flare, clamp, smooth, ease, rand, TAU, WHITE, hex, mix, scale } from "../../core/index.js";+import { Layer, coin, gemlet, glint, pool, blobShadow } 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,+ desc: "A banded chest rattles with gold light leaking from its seam, the lid kicks open, rays fan up, and coins and gems arc out, bounce, glint and get collected.",+ tags: ["pickup", "chest", "treasure", "loot", "reward", "gold", "one-shot"],+ size: [176, 112],+ origin: [88, 96],+ duration: 4.6,loop: false,fps: 30,bg: "ground",- options: { palette: PAL.gold, loot: 7, seed: 15 },+ options: {+ palette: ["#1e1206", "#4a2c08", "#86520c", "#c48412", "#f0b424", "#ffe066", "#fff6c4", "#ffffff"],+ wood: ["#110a10", "#24131a", "#3a1f1f", "#552d24", "#73402c", "#925737", "#b07246"],+ coins: 12,+ seed: 3,+ },};-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;+// gems that come out with the gold: ruby, emerald, sapphire, amethyst (dark to bright)+const GEMS = [+ ["#2a0612", "#6e0f2a", "#b81c3c", "#f0405a", "#ff8a96", "#ffd2d6"],+ ["#06200f", "#0f4a26", "#1a8040", "#34c060", "#8af0a0", "#d8ffe0"],+ ["#0a1030", "#142a70", "#2050c0", "#3a8cf0", "#8ccaff", "#dcf0ff"],+ ["#1a0a2a", "#3e1466", "#6a28a8", "#a050e0", "#d09cff", "#f0e0ff"],+].map((g) => g.map(hex));-// 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);+const T_OPEN = 0.8, T_COLLECT = 2.55, T_POOF = 3.3;+const RATTLES = [[0.1, 0.4], [0.32, 0.62], [0.5, 0.8], [0.64, 1]];+// the chest: 24 px wide, a 9 px front face, seen from a little above (tilt sin 0.34) so the open top shows+const HW = 12, FH = 9, CS = 0.94, SN = 0.34, HB = FH / CS, LA = 6, LB = 5.5, STRAPS = [-9, 7];+const L = new Layer(40, 44), IL = new Layer(16, 16);-// 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);+// the lid as rows of screen pixels: which point of its curved profile each row shows, which side, how lit.+// Points that swing below the rim (behind the back wall) are hidden.+function lidRows(th) {+ const best = new Map(), ct = Math.cos(th), st = Math.sin(th);+ for (let i = 0; i <= 260; i++) {+ const al = (i / 260) * Math.PI, dz = LA + LA * Math.cos(al), dy = LB * Math.sin(al);+ const z = -LA + dz * ct - dy * st, y = HB + dz * st + dy * ct;+ if (y < HB - 0.05) continue;+ let nz = Math.cos(al) / LA, ny = Math.sin(al) / LB;+ const nl = Math.hypot(nz, ny);+ (nz /= nl), (ny /= nl);+ const Nz = nz * ct - ny * st, Ny = nz * st + ny * ct;+ const v = y * CS + (LA - z) * SN, dep = z * CS + y * SN, row = Math.floor(-v);+ const cur = best.get(row);+ if (!cur || dep > cur.dep) best.set(row, { row, al, dep, out: Nz * CS + Ny * SN > 0, lit: Ny * 0.95 + Nz * 0.3 - 0.2 });+ }+ const rows = [...best.values()].sort((a, b) => a.row - b.row);+ // the lit crest: the outside row facing the light most squarely+ let hi = null;+ for (const r of rows) if (r.out && (!hi || r.lit > hi.lit)) hi = r;+ if (hi && hi.lit > 0.5) hi.crest = true;+ // stave seams: the row nearest each seam angle+ for (const s of [Math.PI / 3, (2 * Math.PI) / 3]) {+ let k = null;+ for (const r of rows) if (!k || Math.abs(r.al - s) < Math.abs(k.al - s)) k = r;+ if (k && Math.abs(k.al - s) < 0.4) k.seam = true;+ }+ return rows;+}++const tone = (R, l, steps) => R[steps[l > 0.6 ? 0 : l > 0.25 ? 1 : l > -0.1 ? 2 : l > -0.45 ? 3 : 4]];+const IRON = ["#0e0d16", "#1d1c28", "#2f2e3e", "#474658", "#6a6a7e", "#9898ac"].map(hex);++// the glowing hoard inside the open top: a mound of gold, lit from within+function paintHoard(C, W, g) {+ const heat = (k) => C[clamp(Math.round(k + g * 2.2), 0, 7)];+ for (let y = -13; y <= -10; y++)+ for (let x = -HW; x < HW; x++) {+ const h = rand(x, y, 7), k = h < 0.18 ? 5 : h < 0.55 ? 4 : 3;+ L.set(x, y, y === -13 && Math.abs(x + 0.5) > 9 ? W[2] : heat(k - (y === -13 ? 1 : 0)));}- 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);+ for (let x = -9; x < 9; x++) {+ const top = -13 - Math.round(2.2 * Math.pow(Math.cos(((x + 0.5) / 10) * (Math.PI / 2)), 1.4));+ for (let y = top; y < -13; y++) L.set(x, y, heat(y === top ? 5 : 4 + (rand(x, y, 3) < 0.3 ? 1 : 0)));+ }+}++// the lid at angle th: wood staves, iron straps, a gold lip and hasp outside; dark wood lit by the hoard inside+function paintLid(C, W, th, g) {+ const rows = lidRows(th), heat = (k) => C[clamp(Math.round(k + g * 2.2), 0, 7)], top = rows.length ? rows[0].row : 0;+ for (const r of rows) {+ const u = r.al;+ for (let x = -HW; x < HW; x++) {+ const strap = STRAPS.some((s) => x === s || x === s + 1), left = STRAPS.some((s) => x === s), side = (x + HW + 0.5) / (2 * HW);+ const corner = x === -HW || x === HW - 1;+ let c;+ if (r.out) {+ if (r.row === top && corner && th < 0.6) continue;+ const l = r.lit + 0.2 - side * 0.35 - (r.row === top ? 0.45 : 0);+ if (u < 0.3 || (u < 0.55 && x >= -2 && x <= 1)) c = tone(C, l + (x >= -2 && x <= 1 ? 0.15 : 0.1), [6, 5, 5, 4, 3]);+ else if (corner) c = x < 0 ? IRON[4] : IRON[2];+ else if (strap) c = tone(IRON, l + (left ? 0.3 : -0.3), [5, 4, 3, 2, 1]);+ else if (r.seam) c = W[0];+ else {+ c = r.crest && side < 0.62 ? W[6] : tone(W, l, [5, 4, 3, 2, 1]);+ if (rand(x >> 1, Math.round(u * 6), 11) < 0.2) c = W[Math.max(0, W.indexOf(c) - 1)];+ }+ } else {+ // the inside of the lid, lit by the hoard from below+ const k = g * Math.pow(u / Math.PI, 1.3);+ if (u < 0.3) c = heat(1);+ else if (r.seam) c = W[0];+ else c = k > 0.6 ? mix(W[4], C[5], 0.3) : k > 0.35 ? W[3] : k > 0.15 ? W[2] : W[1];+ if (corner) c = W[0];}+ L.set(x, r.row, 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];+// the front face: a gold rim, two planks, iron straps and corners with rivets, a gold lock plate and keyhole+function paintFront(C, W, g) {+ for (let y = -FH; y <= -1; y++)+ for (let x = -HW; x < HW; x++) {+ const side = (x + HW + 0.5) / (2 * HW);+ let c;+ if (y === -FH) c = side < 0.3 ? C[6] : side < 0.7 ? C[5] : C[4];+ else if (y === -1) c = W[1];+ else if (y === -5) c = W[0];+ else {+ const top = y === -8 || y === -4, bot = y === -6 || y === -2;+ c = W[top ? (side < 0.45 ? 4 : 3) : bot ? 2 : 3];+ if (!top && rand(x >> 1, y, 5) < 0.2) c = W[bot ? 1 : 2];+ }+ if (x === -HW) c = y === -FH ? C[5] : IRON[4];+ if (x === HW - 1) c = y === -FH ? C[3] : IRON[2];+ for (const s of STRAPS) {+ if (x === s && y > -FH) c = y === -7 || y === -3 ? IRON[5] : IRON[4];+ if (x === s + 1 && y > -FH) c = IRON[2];+ }+ L.set(x, y, c);+ }+ for (let y = -FH; y <= -4; y++)+ for (let x = -2; x <= 1; x++) L.set(x, y, x === 1 || y === -4 ? C[3] : x === -2 && y === -FH ? C[7] : C[5]);+ const kh = g < 0.15 ? W[0] : g < 0.4 ? C[4] : g < 0.7 ? C[6] : WHITE;+ L.set(-1, -7, kh), L.set(0, -7, kh), L.set(-1, -6, kh), L.set(0, -6, scale(kh, 0.85));}-const COIN = [[".aa.", "abba", "abba", ".bb."], [".a.", "aba", "aba", ".b."], [".a", "ab", "ab", ".b"]];+// the whole chest: past upright the lid stands behind the hoard, before that it covers it+function paintChest(C, W, th, g) {+ if (th > 1.2) paintLid(C, W, th, g), paintHoard(C, W, g);+ else paintHoard(C, W, g), paintLid(C, W, th, g);+ paintFront(C, W, g);+}-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);+export function create(o) {+ const C = fit(o.palette, 8), W = fit(o.wood, 7), R = new Rng(o.seed), floor = () => 0;+ const ps = new Particles({ rng: R, ground: floor, sparks: [C[7], C[6], C[5], C[4]], haze: C[4] });+ const lights = new Lights(), loot = [], rings = [], bits = [];+ const dust = new Particles({ rng: R, sparks: [C[5], C[5], C[4], C[3]] });+ const DUST = hex("#5e5068");+ // the rays that fan out of the open chest+ const rays = Array.from({ length: 9 }, (_, i) => {+ const u = (i / 8) * 2 - 1;+ return { a: u * 1.05 + R.range(-0.06, 0.06), len: R.range(46, 64) * (1.2 - 0.4 * Math.abs(u)), w: R.range(0.035, 0.08), d: R.range(0, 0.06), f: R.range(5, 10), ph: R.range(0, TAU) };+ });+ // the loot: coins and gems, launched in a fan out of the mouth+ const n = o.coins;+ for (let i = 0; i < n + 4; i++) {+ const gem = i >= n, s = i % 2 ? 1 : -1, a = s * R.range(0.1, 0.5), sp = R.range(190, 270);+ loot.push({+ gem, G: gem ? GEMS[(i - n) % GEMS.length] : null, x: R.range(-7, 7), y: -12, vx: Math.sin(a) * sp, vy: -Math.cos(a) * sp,+ t0: T_OPEN + 0.03 + R.range(0, 0.2), up: false, rest: false, r: gem ? 2.6 : 3, ax: R.range(-0.6, 0.6), spin: R.range(0, TAU), vs: R.sign() * R.range(14, 24),+ settle: 0, ph: R.next(), pop: 0, gone: false,});}- // 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 });+ // they get picked up from the outside in+ [...loot].sort((a, b) => Math.abs(b.vx) - Math.abs(a.vx)).forEach((it, k) => (it.pop = T_COLLECT + k * 0.04 + R.range(0, 0.02)));++ let t = 0, opened = false, poofed = false;+ const shake = () => {+ let dx = 0, hop = 0, lid = 0;+ for (const [t0, s] of RATTLES) {+ const u = t - t0;+ if (u < 0 || u > 0.18) continue;+ const e = 1 - u / 0.18;+ dx += Math.sin(u * 90) * 1.6 * s * e;+ if (u < 0.06 && s > 0.5) hop = 1;+ lid = Math.max(lid, Math.max(0, Math.sin(u * 38)) * 0.13 * s * e);}- 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));+ if (t >= T_OPEN && t < T_OPEN + 0.08) hop = 1;+ // the last strain: the lid creeps up off the seam just before it bursts open+ const strain = smooth(T_OPEN - 0.14, T_OPEN, t);+ if (t < T_OPEN) lid = Math.max(lid, 0.07 * strain), (dx += strain > 0.2 ? (Math.floor(t * 60) % 2 ? 1 : -1) * 0.6 : 0);+ return { dx: Math.round(dx), hop, lid };+ };+ const lidAngle = (lid) => {+ if (t < T_OPEN) return lid;+ const u = t - T_OPEN, w = 30, z = 0.55, wd = w * Math.sqrt(1 - z * z);+ return 1.98 * (1 - Math.exp(-z * w * u) * (Math.cos(wd * u) + ((z * w) / wd) * Math.sin(wd * u)));+ };+ // the light inside: it builds through the rattles, flares as the lid goes, then settles and fades+ const inner = () => {+ if (t < T_OPEN) {+ let k = 0.1 + 0.45 * smooth(0, T_OPEN, t) + 0.5 * smooth(T_OPEN - 0.14, T_OPEN, t);+ for (const [t0, s] of RATTLES) if (t > t0) k += 0.45 * s * Math.exp(-(t - t0) * 9);+ return k;+ }+ return (0.62 + 0.3 * Math.exp(-(t - T_OPEN) * 5)) * (1 - smooth(T_COLLECT - 0.3, T_POOF, t)) + 0.05 * Math.sin(t * 9);+ };+ const rayK = (r) => {+ const u = t - T_OPEN - r.d;+ if (u < 0) return 0;+ return ease.outCubic(clamp(u / 0.1)) * (1 - smooth(1.0, 2.1, u)) * (0.72 + 0.28 * Math.sin(t * r.f + r.ph));+ };++ return {+ update(dt) {+ t += dt;+ const g = inner();+ for (const [t0, s] of RATTLES)+ if (s > 0.5 && t - dt < t0 + 0.05 && t >= t0 + 0.05)+ for (let i = 0; i < 4; i++) {+ const sd = i % 2 ? 1 : -1;+ ps.spawn(P.DUST, sd * R.range(9, 13), -1, sd * R.range(20, 50), -R.range(2, 8), R.range(0.3, 0.5), DUST, R.range(1.2, 2.2) * s);+ }+ // anticipation: motes of light squeeze out of the seam and the keyhole+ if (t < T_OPEN && R.chance(g * 0.08)) {+ const x = R.range(-11, 11);+ ps.spawn(P.STAR, x, -10, x * 1.5, -R.range(8, 30), R.range(0.3, 0.6), R.chance(0.5) ? C[6] : C[5], R.range(0.4, 1.2));+ }+ if (!opened && t >= T_OPEN) {+ opened = true;+ lights.add(0, -18, 64, C[5], 0.45, 0.7);+ lights.add(0, -16, 22, WHITE, 0.35, 0.1);+ for (let i = 0; i < 7; i++) {+ const a = -Math.PI / 2 + R.range(-1.1, 1.1), sp = R.range(120, 260);+ ps.spawn(P.SPARK, R.range(-8, 8), -13, Math.cos(a) * sp, Math.sin(a) * sp, R.range(0.12, 0.26));+ }+ for (let i = 0; i < 8; i++) {+ const s = R.sign();+ ps.spawn(P.DUST, s * R.range(10, 14), -1, s * R.range(30, 80), -R.range(2, 10), R.range(0.4, 0.7), DUST, R.range(1.6, 3));+ }+ }+ // the hold: gold dust rising out of the hoard, twinkles in the light+ if (t > T_OPEN && t < T_COLLECT) {+ if (R.chance(0.22)) ps.spawn(P.EMBER, R.range(-9, 9), -13, R.range(-12, 12), -R.range(25, 60), R.range(0.8, 1.5), C[5], R.range(0.8, 1.6));+ if (R.chance(0.12)) {+ const a = R.range(-1, 1), d = R.range(10, 40);+ ps.spawn(P.STAR, Math.sin(a) * d, -12 - Math.cos(a) * d, 0, -R.range(4, 12), R.range(0.3, 0.7), R.chance(0.5) ? WHITE : C[6], R.range(0.5, 2));+ }+ }+ // the loot flies, bounces and settles+ for (const it of loot) {+ if (it.gone || t < it.t0) continue;+ it.up = true;+ if (t >= it.pop + 0.13) {+ it.gone = true;+ const y = it.y - 6;+ if (it.gem) rings.push({ x: it.x, y, t0: t });+ lights.add(it.x, y, 18, it.gem ? it.G[4] : C[5], 0.65, 0.25);+ for (let i = 0; i < 4; i++) {+ const a = R.range(0, TAU), sp = R.range(25, 55);+ ps.spawn(P.STAR, it.x, y, Math.cos(a) * sp - it.x * 0.25, Math.sin(a) * sp - 20, R.range(0.3, 0.55), i ? (it.gem ? it.G[5] : C[6]) : WHITE, R.range(0.6, 1.5));+ }+ continue;+ }+ if (it.rest) {+ it.settle += dt;+ it.vx -= it.vx * 9 * dt;+ it.x = clamp(it.x + it.vx * dt, -74, 74);+ continue;+ }+ it.vy += 950 * dt;+ it.x += it.vx * dt;+ // keep the loot on the canvas: the far ones skid back off its edge+ if (Math.abs(it.x) > 74) (it.x = Math.sign(it.x) * 74), (it.vx *= -0.3);+ it.y += it.vy * dt;+ it.spin += it.vs * dt;+ const bottom = it.y + it.r;+ if (bottom >= -0.5 && it.vy > 0) {+ it.y = -0.5 - it.r;+ if (it.vy > 110) {+ ps.spawn(P.DUST, it.x, -1, R.range(-20, 20), -R.range(4, 12), R.range(0.25, 0.45), DUST, R.range(1, 1.8));+ if (it.vy > 220) {+ for (let i = 0; i < 2; i++) ps.spawn(P.SPARK, it.x, -1, R.range(-90, 90), -R.range(60, 140), R.range(0.1, 0.22));+ lights.add(it.x, -2, 9, C[5], 0.5, 0.12);+ }+ it.vy = -it.vy * 0.42;+ it.vx *= 0.5;+ it.vs *= 0.55;+ } else {+ it.rest = true;+ it.vy = 0;+ }+ }+ }+ for (let i = rings.length - 1; i >= 0; i--) if (t - rings[i].t0 > 0.3) rings.splice(i, 1);+ if (!poofed && t >= T_POOF) {+ // the empty chest dissolves from the lid down into rising gold dust+ poofed = true;+ lights.add(0, -12, 40, C[5], 0.5, 0.6);+ L.begin(-20, -32);+ paintChest(C, W, lidAngle(0), 0.3);+ L.outline(W[0]);+ const f = L.f;+ let top = 0;+ f.color.forEach((c, i) => c && (top = Math.min(top, Math.floor(i / f.w) + f.oy)));+ f.color.forEach((c, i) => {+ if (!c) return;+ const x = (i % f.w) + f.ox, y = Math.floor(i / f.w) + f.oy;+ bits.push({ x, y, c, td: T_POOF + ((y - top) / -top) * 0.32 + rand(x, y, 21) * 0.05, mote: c !== W[0] && rand(x, y, 23) < 0.14 });+ });+ }+ for (const b of bits)+ if (!b.done && t >= b.td) {+ b.done = true;+ if (b.mote) dust.spawn(P.EMBER, b.x + 0.5, b.y + 0.5, R.range(-28, 28), -R.range(14, 50), R.range(0.4, 0.8), C[5], R.range(0.5, 1.1));+ }+ ps.update(dt);+ dust.update(dt);+ lights.update(dt);+ },+ drawBack(p) {+ if (t < T_POOF + 0.2) blobShadow(p, 0, 15, 1 - smooth(T_POOF, T_POOF + 0.2, t));+ ps.draw(p, "back");+ },+ draw(p) {+ const g = inner(), sh = shake(), th = lidAngle(sh.lid);+ // light on the floor and round the chest+ const open = t >= T_OPEN ? 1 : 0;+ pool(p, 0, 0, 30 + 10 * g, 4, C[4], (0.1 + 0.18 * open) * g);+ p.glow(0, -16, 24 + 8 * g, C[4], (0.1 + 0.2 * open) * g);+ if (t < T_POOF) {+ L.begin(-20, -32);+ paintChest(C, W, th, Math.min(1.2, g));+ L.outline(W[0]);+ L.draw(p, sh.dx, -sh.hop);+ } else for (const b of bits) if (!b.done) p.px(b.x, b.y, b.td - t < 0.04 ? (b.c === W[0] ? C[3] : C[6]) : b.c);+ // light leaking from the seam before it opens+ if (t < T_OPEN) {+ p.glowLine(-11, -9.5 - sh.hop, 11, -9.5 - sh.hop, 5, C[5], 0.22 * g);+ // light through the crack under the lid, growing as the hoard brightens+ if (g > 0.35 && sh.lid < 0.015) p.line(-10 + sh.dx, -10 - sh.hop, 9 + sh.dx, -10 - sh.hop, (u) => (Math.abs(u - 0.5) < 0.2 ? WHITE : C[6]), (u) => (g - 0.35) * 2.2 * (1 - Math.abs(u - 0.5) * 0.9));+ p.glow(sh.dx, -7 - sh.hop, 6, C[6], 0.35 * g);+ // each bump lifts the lid off the seam and light shoots out of the crack in thin rays+ if (sh.lid > 0.015)+ for (let i = 0; i < 8; i++) {+ const x = -10.5 + i * 3 + sh.dx + (rand(i, 3) - 0.5) * 1.5, a = -Math.PI / 2 + (x / 11) * 1.25, l = (7 + rand(i, Math.floor(t * 30), 1) * 12) * Math.min(1, sh.lid / 0.05);+ const y0 = -10 - sh.hop;+ p.line(x, y0, x + Math.cos(a) * l, y0 + Math.sin(a) * l, (u) => (u < 0.25 ? WHITE : u < 0.6 ? C[6] : C[5]), (u) => 1.15 - u);+ p.glowLine(x, y0, x + Math.cos(a) * l * 0.7, y0 + Math.sin(a) * l * 0.7, 3, C[5], 0.25);+ }+ }+ // the rays: wedges of light fanning out of the open chest+ for (const r of rays) {+ const k = rayK(r);+ if (k <= 0.01) continue;+ const ox = Math.sin(r.a) * 7, oy = -12, dx = Math.sin(r.a), dy = -Math.cos(r.a), len = r.len * (0.88 + 0.12 * Math.sin(t * r.f * 0.7 + r.ph)), tw = Math.tan(r.w);+ const x1 = ox + dx * len, y1 = oy + dy * len;+ p.shade(Math.min(ox, x1) - 8, Math.min(oy, y1) - 8, Math.max(ox, x1) + 8, Math.max(oy, y1) + 8, (x, y, out) => {+ const rx = x - ox, ry = y - oy, d = rx * dx + ry * dy;+ if (d < 0 || d > len) return;+ const q = Math.abs(rx * dy - ry * dx), hw = 0.6 + d * tw, f = q < hw ? 1 - 0.35 * (q / hw) : 0.65 * (1 - (q - hw) / 1.6);+ if (f <= 0) return;+ out.l = q < hw * 0.45 ? C[6] : C[5];+ out.k = k * 0.55 * f * Math.pow(1 - d / len, 1.4) * smooth(5, 14, d);+ });+ }+ // the release: a flare out of the mouth+ if (t >= T_OPEN && t < T_OPEN + 0.2) {+ const a = (t - T_OPEN) / 0.2;+ flare(p, 0, -14, 22 * Math.pow(1 - a, 1.4), 1 - a, C);+ }+ // the loot+ for (const it of loot) {+ if (!it.up || it.gone) continue;+ const pu = t - it.pop, lift = pu > 0 ? 6 * ease.outCubic(clamp(pu / 0.1)) : 0, wh = pu > 0.095;+ let y = it.y - lift, ax = it.ax, spin = it.spin;+ let flat = false;+ if (it.rest && !it.gem) {+ // a coin falls flat with a wobble, then lies there as a lens of gold+ const w = Math.exp(-it.settle * 8) * Math.abs(Math.cos(it.settle * 22));+ ax = 0;+ spin = Math.acos(clamp(0.5 + 0.5 * w, 0, 1));+ flat = w < 0.12;+ y = flat ? -1.5 - lift : -it.r * Math.cos(spin) - lift;+ }+ if (it.y > -10) blobShadow(p, it.x, 3, 0.7 * (1 - clamp(-it.y / 30)));+ if (it.gem) gemlet(IL, p, it.x, y, it.r, it.rest ? 0.4 * Math.sign(it.vs) : it.spin, it.G, wh);+ else coin(IL, p, flat ? Math.round(it.x) + 0.5 : it.x, y, it.r, ax, flat ? Math.acos(0.5) : spin, C, wh, 1, !flat);+ p.glow(it.x, y, 9, it.gem ? it.G[4] : C[5], it.rest ? 0.26 : 0.18);+ p.glow(it.x, y, 3, WHITE, 0.12);+ // resting loot glints in turn+ if (it.rest && t < it.pop) {+ const u = (t * 0.9 + it.ph) % 1;+ if (u < 0.16) glint(p, it.x - 1, y - 1.5, 2.6 * Math.sin((u / 0.16) * Math.PI), it.gem ? it.G[5] : C[6], 0.5);+ }+ }+ for (const r of rings) {+ const k = (t - r.t0) / 0.3, e = ease.outCubic(k);+ p.ring(r.x, r.y, 2 + 5 * e, 1, k < 0.3 ? WHITE : C[6], 1.15 - k);+ p.glow(r.x, r.y, 12, C[5], 0.45 * (1 - k));+ if (k < 0.5) glint(p, r.x, r.y, 3.4 * (1 - k / 0.5), C[6], 0.55);+ }+ ps.draw(p, "front");+ dust.draw(p);+ lights.draw(p);+ },+ };}diff --git a/src/fx/pickups/coin-spin.js b/src/fx/pickups/coin-spin.jsindex f1a1b07..81cb463 100644--- a/src/fx/pickups/coin-spin.js+++ b/src/fx/pickups/coin-spin.js@@ -1,59 +1,43 @@-import { PAL, TAU, bump } from "../../core/index.js";-import { Layer, shadow, twinkle, bob, fit } from "./_lib.js";+// The hover, floor shadow and glints follow Sprite Fusion's open-source pickup+// (https://www.spritefusion.com/pixel-art-vfx/pickup), MIT License, Copyright (c) 2026 Hugo Duprez.+import { fit, rand, TAU, WHITE, scale } from "../../core/index.js";+import { Layer, coin3d, glint, blobShadow } 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.",+ desc: "A thick gold coin turning on its edge: an embossed star face, a reeded rim showing as it goes edge-on, a flash sweeping the face, bobbing over its shadow.",tags: ["pickup", "coin", "gold", "money", "loop"],- size: [32, 36],- origin: [16, 32],- duration: 1,+ size: [56, 56],+ origin: [28, 48],+ duration: 1.6,loop: true,fps: 30,bg: "ground",- options: { palette: PAL.gold, radius: 7, poses: 10, shadow: true, seed: 1 },+ options: { palette: ["#1e1206", "#4a2c08", "#86520c", "#c48412", "#f0b424", "#ffe066", "#fff6c4", "#ffffff"], seed: 3 },};-const L = new Layer(40, 40);+const L = new Layer(32, 32), R = 7, TH = 3, HOVER = 17;++export function drawBack(p, t, o) {+ const T = meta.duration, ph = t / T, th = ph * TAU, y = -HOVER - 2 * Math.sin(ph * TAU);+ // the shadow narrows as the coin turns edge-on and thins as it rises+ blobShadow(p, 0, 2.5 + 4.5 * Math.abs(Math.cos(th)) + 1.5 * Math.abs(Math.sin(th)), 0.85 - (-y - HOVER + 2) * 0.06);+}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);+ const C = fit(o.palette, 8), T = meta.duration, ph = t / T, th = ph * TAU, y = -HOVER - 2 * Math.sin(ph * TAU);+ // warm light round it, swelling when the face catches the light+ const facing = Math.abs(Math.cos(th));+ p.glow(0, y, 20, C[4], 0.3 + 0.12 * facing);+ const flash = coin3d(L, p, 0, y, R, TH, th, C);+ p.glow(-1, y - 1, 12, C[6], 0.35 * flash);+ // a star glint where the flash leaves the rim+ if (flash > 0.3) glint(p, -4, y - 4, 1 + 3.2 * flash, C[6], 0.5 * flash);+ // little twinkles round it, one after another+ for (let i = 0; i < 5; i++) {+ const life = 0.35, age = (((t - (i / 5) * T - rand(i, o.seed, 3) * 0.08) % T) + T) % T;+ if (age > life) continue;+ const a = rand(i, o.seed, 1) * TAU + i * 2.1, d = 10 + rand(i, o.seed, 2) * 5, k = Math.sin((age / life) * Math.PI);+ glint(p, Math.cos(a) * d, y + Math.sin(a) * d * 0.85 - age * 8, Math.round(2 * k), i % 2 ? C[6] : WHITE, 0.35 * k);}- 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.jsindex f66b446..8c5771f 100644--- a/src/fx/pickups/collect-burst.js+++ b/src/fx/pickups/collect-burst.js@@ -1,48 +1,89 @@-import { PAL, burst, seg, ease, bump, TAU, WHITE } from "../../core/index.js";-import { twinkle, fit } from "./_lib.js";+// The pop (a white flash, a ring snapping out, star sparks with short trails) follows Sprite Fusion's+// open-source pickup (https://www.spritefusion.com/pixel-art-vfx/pickup), MIT License, Copyright (c) 2026 Hugo Duprez.+import { Lights, Rng, fit, clamp, ease, TAU, WHITE } from "../../core/index.js";+import { glint } 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,+ desc: "The moment of pickup: a white flash and a cross of light, a thin ring snapping out ahead of a softer one, twinkles thrown wide on curving paths that brake, hang and wink out.",+ tags: ["pickup", "collect", "burst", "sparkle", "reward", "one-shot"],+ size: [112, 108],+ origin: [56, 94],+ duration: 1.35,loop: false,fps: 30,- bg: "dark",- options: { palette: PAL.holy, count: 8, seed: 14 },+ bg: "ground",+ options: { palette: ["#1a0516", "#3d0a33", "#701560", "#b0228f", "#f53cd1", "#ff86e6", "#ffd2f6", "#ffffff"], seed: 3 },};-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]);+const CY = -30;++export function create(o) {+ const C = fit(o.palette, 8), R = new Rng(o.seed), lights = new Lights();+ lights.add(0, CY, 36, C[5], 0.85, 0.32);+ lights.add(0, CY, 14, WHITE, 0.75, 0.08);+ // twinkles thrown out on curving paths: each one's heading turns as it flies, and drag brakes it+ const stars = Array.from({ length: 14 }, (_, i) => {+ const a = (i / 14) * TAU + R.range(-0.2, 0.2), sp = R.range(145, 225) * (i % 3 === 0 ? 1.12 : 0.85);+ return { x: 0, y: CY, a, sp, turn: (i % 2 ? 1 : -1) * R.range(2.5, 5), life: R.range(0.75, 1.15), age: 0, size: i % 3 === 0 ? 2.6 : R.range(1.2, 2), tr: [], c: i % 4 === 0 ? WHITE : i % 2 ? C[6] : C[5], ph: R.range(0, TAU) };});- 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));+ const motes = Array.from({ length: 7 }, () => ({ x: R.range(-8, 8), y: CY + R.range(-4, 6), vy: -R.range(12, 30), life: R.range(0.5, 0.9), d: R.range(0.05, 0.25), w: R.range(0, TAU) }));+ let t = 0;+ return {+ update(dt) {+ t += dt;+ for (const s of stars) {+ if (s.age > s.life) continue;+ s.age += dt;+ s.tr.unshift([s.x, s.y]);+ if (s.tr.length > 4) s.tr.pop();+ s.a += s.turn * dt * Math.max(0, 1 - s.age * 1.5);+ s.sp -= s.sp * 4.3 * dt;+ s.x += Math.cos(s.a) * s.sp * dt;+ s.y += Math.sin(s.a) * s.sp * dt + 6 * s.age * dt;+ // the floor turns them back up+ if (s.y > -2) (s.y = -2), (s.a = -Math.abs(s.a)), (s.sp *= 0.5);+ }+ lights.update(dt);+ },+ draw(p) {+ // the flash: a white disc and a cross of light, gone in a few frames+ if (t < 0.07) p.circle(0, CY, 5.5 * (1 - t / 0.07) + 1, WHITE);+ if (t < 0.16) {+ const k = 1 - t / 0.16, L = 26 * ease.outCubic(Math.min(1, t / 0.03 + 0.4)) * k;+ for (const [dx, dy, l] of [[1, 0, 1], [-1, 0, 1], [0, 1, 0.6], [0, -1, 0.6]])+ p.line(0, CY, dx * L * l, CY + dy * L * l, (u) => (u < 0.3 ? WHITE : u < 0.65 ? C[6] : C[5]), (u) => (u < 0.5 ? 1 : (1 - u) * 2) * (0.5 + k));+ p.glow(0, CY, 20 * k + 4, C[5], 0.6 * k);+ }+ // a thin ring snapping out fast, a softer ring following+ const u1 = t / 0.32;+ if (u1 < 1) {+ const r = 3 + 23 * ease.outExpo(u1);+ p.ring(0, CY, r, 1, u1 < 0.3 ? WHITE : C[6], 1.3 - u1 * 1.2);+ p.glowRing(0, CY, r, 4, C[5], 0.4 * (1 - u1));+ }+ const u2 = (t - 0.04) / 0.5;+ if (u2 > 0 && u2 < 1) {+ const r = 2 + 16 * ease.outCubic(u2);+ p.ring(0, CY, r, Math.max(1, 2.6 * (1 - u2)), C[5], 1 - u2);+ }+ // the twinkles, with short trails, flickering as they hang and wink out+ for (const s of stars) {+ if (s.age > s.life) continue;+ const k = 1 - s.age / s.life, tw = 0.65 + 0.35 * Math.sin(s.age * 26 + s.ph);+ s.tr.forEach(([x, y], i) => i > 0 && p.dot(x, y, i < 2 ? C[5] : C[4], (1 - i / 4) * k * 1.4));+ if (k < 0.3 && Math.sin(s.age * 40 + s.ph) < 0) continue;+ glint(p, s.x, s.y, Math.round(s.size * tw * Math.min(1, k * 2.5)), s.c, 0.45 * k);+ }+ // motes drifting up after+ for (const m of motes) {+ const a = t - m.d;+ if (a < 0 || a > m.life) continue;+ const k = 1 - a / m.life, x = m.x + Math.sin(a * 6 + m.w) * 1.5, y = m.y + m.vy * a;+ p.dot(x, y, k > 0.5 ? C[6] : C[5], k * 1.5);+ p.glow(x + 0.5, y + 0.5, 3, C[5], 0.3 * k);+ }+ lights.draw(p);+ },+ };}diff --git a/src/fx/pickups/crystal-shard.js b/src/fx/pickups/crystal-shard.jsindex b4af7f8..71f91a9 100644--- a/src/fx/pickups/crystal-shard.js+++ b/src/fx/pickups/crystal-shard.js@@ -1,79 +1,128 @@-import { PAL, bump, TAU } from "../../core/index.js";-import { Layer, shadow, twinkle, bob, fit } from "./_lib.js";+// The crystal shading (a lit ridge, bright faces turned to the light, a dark rim) and the orbiting motes+// follow Sprite Fusion's open-source ice crystals and pickup (https://www.spritefusion.com/pixel-art-vfx/ice),+// MIT License, Copyright (c) 2026 Hugo Duprez.+import { fit, clamp, rand, TAU, WHITE } from "../../core/index.js";+import { Layer, drawGem, glint, blobShadow, pool } 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,+ desc: "A broken amber shard hovers and sways: chipped uneven faces, its top sheared off, light pulsing up through glowing cracks and flaring out of the break; splinters orbit it.",+ tags: ["pickup", "crystal", "shard", "relic", "broken", "loop"],+ size: [64, 76],+ origin: [32, 68],+ duration: 3.2,loop: true,fps: 30,bg: "ground",- options: { palette: PAL.cyber, shards: 3, shadow: true, seed: 3 },+ options: { palette: ["#1a0a04", "#3e1606", "#702a08", "#a8480c", "#e07818", "#ffa838", "#ffd890", "#ffffff"], seed: 8 },};-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."];+const HALF = 6, TILT = 0.18, LEAN = 0.2;+const roll = ([x, y, z]) => [x * Math.cos(LEAN) - y * Math.sin(LEAN), x * Math.sin(LEAN) + y * Math.cos(LEAN), z];+const unit = (x, y, z) => { const l = Math.hypot(x, y, z); return [x / l, y / l, z / l]; };+// the broken shard as a convex solid: an uneven six-sided body, a point on top sheared off on one side by a+// fracture, a lopsided point below, two corners chipped away+const SOLID = (() => {+ const planes = [], deg = Math.PI / 180, jit = [0, 8, -6, 4, -9, 5], rr = [1, 0.86, 1.08, 0.94, 0.82, 1.04], low = [6.5, 5.5, 7, 6, 5, 6.8];+ for (let k = 0; k < 6; k++) {+ const a = (k * 60 + jit[k]) * deg, r = 4.8 * rr[k], ct = Math.atan2(13, r), cb = Math.atan2(low[k], r);+ planes.push({ n: [Math.cos(a), 0, Math.sin(a)], d: r, kind: 6 });+ planes.push({ n: [Math.sin(ct) * Math.cos(a), Math.cos(ct), Math.sin(ct) * Math.sin(a)], d: Math.sin(ct) * r + Math.cos(ct) * HALF, kind: 7 });+ planes.push({ n: [Math.sin(cb) * Math.cos(a), -Math.cos(cb), Math.sin(cb) * Math.sin(a)], d: Math.sin(cb) * r + Math.cos(cb) * HALF, kind: 8 });+ }+ const shear = unit(0.7, 0.62, 0.34);+ planes.push({ n: shear, d: shear[1] * 7.2 + shear[0] * -0.6, kind: 9 });+ for (const [n, d] of [[unit(-0.7, -0.25, 0.65), 4.0], [unit(0.75, 0.15, 0.6), 3.9], [unit(-0.55, 0.5, 0.3), 6.8]]) planes.push({ n, d, kind: 10 });+ // the whole shard leans off upright+ for (const q of planes) q.n = roll(q.n);+ return { planes, r: 8, top: HALF + 13, bottom: HALF + 8 };+})();+// cracks running through it, in its own frame (y up): they turn with it+const CRACKS = [+ [[0.5, -9, 0.3], [-0.8, -5, 0.5], [0.6, -1, 0.2], [-0.4, 3, 0.6], [1.4, 6.5, 0.4], [2.2, 8.5, 0.6]],+ [[0.6, -1, 0.2], [2.4, 1.5, 1], [3.4, 4.2, 1.2]],+ [[-0.4, 3, 0.6], [-2, 6.5, 0.4], [-2.6, 10.5, 0.2], [-2.4, 14.5, 0.1]],+ [[-0.8, -5, 0.5], [-2.8, -3, 0.8]],+];+const L = new Layer(32, 52), SL = new Layer(16, 16), HOVER = 27, RX = 15, RY = 3.8;++const pose = (ph) => ({ y: -HOVER - 1.8 * Math.sin(ph * TAU), spin: 0.3 + 0.62 * Math.sin(ph * TAU) });+// a pulse of light climbing the cracks, twice a loop: where it is, from below the shard (-0.3) to past its top+const climb = (ph) => ((ph * 2) % 1) * 1.7 - 0.3;++// where a point of the shard lands on screen, turned by spin and seen from a little above+const project = (pt, spin, cy) => {+ const [x, y, z] = roll(pt), xr = x * Math.cos(spin) - z * Math.sin(spin), zr = x * Math.sin(spin) + z * Math.cos(spin);+ return [xr, cy - (y * Math.cos(TILT) - zr * Math.sin(TILT))];+};-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)];+function cracks(p, C, spin, cy, ph) {+ const s0 = climb(ph), rim = C[0] >>> 0;+ for (const crack of CRACKS)+ for (let i = 1; i < crack.length; i++) {+ const [x0, y0] = project(crack[i - 1], spin, cy), [x1, y1] = project(crack[i], spin, cy), n = Math.ceil(Math.hypot(x1 - x0, y1 - y0) * 2);+ for (let j = 0; j <= n; j++) {+ const u = j / n, x = x0 + (x1 - x0) * u, y = y0 + (y1 - y0) * u, h = crack[i - 1][1] + (crack[i][1] - crack[i - 1][1]) * u;+ const c = L.get(x, y) >>> 0;+ if (!c || c === rim) continue;+ // light runs up the crack: brightest where the pulse is+ const b = 0.3 + Math.exp(-((((h + 9) / 22 - s0) / 0.14) ** 2));+ p.px(x, y, b > 0.9 ? WHITE : b > 0.55 ? C[6] : C[5]);+ if (j % 4 === 0 && b > 0.5) p.glow(x + 0.5, y + 0.5, 2 + 3 * b, C[5], 0.16 * b);+ }}- return 0;+}++// a splinter: a little two-tone sliver with a dark rim, turned to angle a+function splinter(p, C, x, y, len, a, far) {+ const ca = Math.cos(a), sa = Math.sin(a), X = Math.round(x), Y = Math.round(y);+ SL.begin(X - 7, Y - 7);+ SL.fill(X - 7, Y - 7, X + 6, Y + 6, (px, py) => {+ const dx = px - X, dy = py - Y, u = dx * ca + dy * sa, v = -dx * sa + dy * ca;+ if (Math.abs(u) / len + Math.abs(v) / (u > 0 ? 1.7 : 1.1) > 1) return 0;+ const lit = -(ca * 0.6 + sa * 0.8) * Math.sign(v || 1);+ return far ? (v < 0 ? C[4] : C[3]) : Math.abs(v) < 0.5 && u < 0 ? WHITE : v < 0 === lit > 0 ? C[6] : C[4];});- L.outline(C[1]);- L.draw(p);- return { C, cy, ph, TIP, SH };+ SL.outline(C[far ? 1 : 0]).draw(p);}-// 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);+// the splinters on their tilted ring; back draws the far half, front the near half+function splinters(p, C, ph, cy, back) {+ for (let i = 0; i < 3; i++) {+ const a = ph * TAU + (i * TAU) / 3, s = Math.sin(a);+ if (s < 0 !== back) continue;+ const x = Math.cos(a) * RX, y = cy + 1 + s * RY - Math.cos(a) * 1.5, near = (s + 1) / 2;+ splinter(p, C, x, y, 3 + 1.6 * near, a * 2 + i * 1.7, back);+ p.glow(x, y, 6 + 3 * near, C[5], (back ? 0.18 : 0.32) * (0.6 + 0.4 * near));+ if (!back && s > 0.92) glint(p, x - 1, y - 1, (2.5 * (s - 0.92)) / 0.08, WHITE, 0.4);}}export function drawBack(p, t, o) {- splinters(p, t, o, false);+ const C = fit(o.palette, 8), ph = t / meta.duration, { y } = pose(ph);+ blobShadow(p, 0, 6, 0.75);+ pool(p, 0, 0.5, 20, 3.5, C[4], 0.3);+ p.glowRing(0, y, 7, 20, C[4], 0.22);+ splinters(p, C, ph, y, true);}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 C = fit(o.palette, 8), ph = t / meta.duration, { y, spin } = pose(ph), s0 = climb(ph);+ drawGem(L, p, SOLID, 0, y, spin, C, { tilt: TILT, gain: 0.6 });+ cracks(p, C, spin, y, ph);+ // lit from within, brighter while the pulse is inside it+ const inside = Math.exp(-(((s0 - 0.45) / 0.45) ** 2));+ p.glow(0, y, 10, C[5], 0.2 * inside);+ splinters(p, C, ph, y, false);+ // when the pulse reaches the break it flares out of the sheared face and throws up embers+ const [fx, fy] = project([1.8, 8.4, 0.9], spin, y), out = clamp(1 - Math.abs(s0 - 1.05) / 0.18);+ if (out > 0) glint(p, fx, fy, 3.5 * out, WHITE, 0.55 * out), p.glow(fx, fy, 12, C[5], 0.4 * out);+ const P2 = meta.duration / 2, burst = ((1.05 + 0.3) / 1.7) * P2;+ for (let i = 0; i < 7; i++) {+ const born = burst + rand(i, o.seed, 1) * 0.12, at = (((t - born) % P2) + P2) % P2, life = 0.6 + rand(i, o.seed, 2) * 0.45;+ if (at > life) continue;+ const k = 1 - at / life, x = fx + (rand(i, o.seed, 3) - 0.5) * 4 + Math.sin(at * 5 + i) * 2 * (at / life), yy = fy - at * (14 + rand(i, o.seed, 4) * 14);+ p.px(x, yy, k > 0.6 ? WHITE : k > 0.3 ? C[6] : C[5]);+ p.glow(x + 0.5, yy + 0.5, 3, C[5], 0.35 * k);}- 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.jsindex 235b5b9..b273032 100644--- a/src/fx/pickups/gem-spin.js+++ b/src/fx/pickups/gem-spin.js@@ -1,69 +1,55 @@-import { at, bump, cycle, TAU } from "../../core/index.js";-import { Layer, shadow, twinkle, bob, fit } from "./_lib.js";+// The hover, floor shadow and twinkle glints follow Sprite Fusion's open-source pickup and sparkle+// (https://www.spritefusion.com/pixel-art-vfx/pickup), MIT License, Copyright (c) 2026 Hugo Duprez.+import { fit, clamp, smooth, ease, cycle, rand, TAU, WHITE, hex, mix, scale } from "../../core/index.js";+import { Layer, brilliant, drawGem, glint, blobShadow } 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,+ desc: "A brilliant-cut ruby turning on its axis: real facets catch the light in turn, flashes roll over the crown, refracted light slides across the floor, sparkles wink round it.",+ tags: ["pickup", "gem", "jewel", "treasure", "ruby", "loop"],+ size: [64, 64],+ origin: [32, 56],+ duration: 2.4,loop: true,fps: 30,bg: "ground",- options: { palette: ["#1a0410", "#40081e", "#78102c", "#b8163a", "#ec2a48", "#ff6670", "#ffc2c2", "#ffffff"], shadow: true, seed: 2 },+ options: { palette: ["#16040e", "#3e0a1e", "#760e2e", "#b8163c", "#ec3250", "#ff7482", "#ffc4c8", "#ffffff"], seed: 6 },};-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;+const GEM = brilliant({ r: 7.5, crown: 3.2, table: 0.5, pavilion: 9.5, girdle: 0.9 });+const L = new Layer(32, 32), HOVER = 19;++// where the gem is: hovering, one slow bob a loop, turning four facets a loop+const pose = (t, T) => ({ y: -HOVER - 1.8 * Math.sin((t / T) * TAU), spin: (t / T) * Math.PI });++export function drawBack(p, t, o) {+ const C = fit(o.palette, 8), T = meta.duration, { y, spin } = pose(t, T), lift = (-y - HOVER + 2) / 4;+ blobShadow(p, 0, 8 - lift * 1.5, 0.75 - lift * 0.2);+ // light refracted through the stone, sliding over the floor as it turns+ for (let k = 0; k < 3; k++) {+ const a = spin * 4 + (k * TAU) / 3, x = Math.sin(a) * 9, k2 = 0.5 + 0.5 * Math.cos(a);+ if (k2 < 0.15) continue;+ p.dot(x, 0, k2 > 0.7 ? C[6] : C[5], k2 * 1.2);+ p.dot(x + 1, 0, C[4], k2 * 0.8);+ p.dot(x - 1, 0, C[4], k2 * 0.6);+ p.glow(x + 0.5, 0, 6, C[5], 0.3 * k2);+ }+}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 C = fit(o.palette, 8), T = meta.duration, ph = t / T, { y, spin } = pose(t, T);+ // its light: a wide soft halo and a hot heart+ p.glowRing(0, y - 1, 5, 15, C[4], 0.34);+ p.glow(0, y, 26, C[3], 0.14);+ const hi = drawGem(L, p, GEM, 0, y, spin, C, { tilt: 0.22 });+ // a star flares where a facet swings square to the light, twice a loop+ const f = ((spin * 4) / TAU) % 1, fk = Math.max(0, 1 - Math.abs(f - 0.5) / 0.08);+ if (fk > 0) glint(p, -3, y - 3, 3.4 * ease.outQuad(fk), C[6], 0.45 * fk);+ // sparkles wink on and off round it, one after another+ for (let i = 0; i < 8; i++) {+ const life = 0.4, age = (((t - (i / 8) * T - rand(i, o.seed, 3) * 0.1) % T) + T) % T;+ if (age > life) continue;+ const a = rand(i, o.seed, 1) * TAU + i * 2.4, d = 10 + rand(i, o.seed, 2) * 7, k = Math.sin((age / life) * Math.PI);+ glint(p, Math.cos(a) * d, y + Math.sin(a) * d * 0.8 - age * 6, Math.round(2.4 * k * (0.6 + 0.4 * rand(i, 9))), i % 3 ? C[6] : WHITE, 0.4 * k);}- 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.jsindex 5b27936..ef21985 100644--- a/src/fx/pickups/heart-pickup.js+++ b/src/fx/pickups/heart-pickup.js@@ -1,48 +1,66 @@-import { PAL, cycle, ease, bump, WHITE } from "../../core/index.js";-import { Layer, shadow, twinkle, bob, pillow, heartSdf, fit } from "./_lib.js";+// The hover, floor shadow and glints follow Sprite Fusion's open-source pickup+// (https://www.spritefusion.com/pixel-art-vfx/pickup), MIT License, Copyright (c) 2026 Hugo Duprez.+import { fit, clamp, rand, cycle, TAU, WHITE, hex } from "../../core/index.js";+import { Layer, pillow, heartSdf, glint, blobShadow } 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.",+ desc: "A plump glossy heart hovering over its shadow beats lub-dub: a big squash and stretch, a smaller echo, light and a thin ring pulsing out, tiny hearts drifting off.",tags: ["pickup", "heart", "health", "life", "loop"],- size: [36, 42],- origin: [18, 38],- duration: 1,+ size: [56, 60],+ origin: [28, 52],+ duration: 1.2,loop: true,fps: 30,bg: "ground",- options: { palette: PAL.blood, shadow: true, seed: 4 },+ options: { palette: ["#1a0408", "#4a0a14", "#8a1222", "#d02436", "#ff4a56", "#ff8a8e", "#ffd0cc", "#ffffff"], seed: 4 },};-const L = new Layer(40, 40);+const L = new Layer(40, 40), HOVER = 18, W = 7.2, INK = hex("#12060c");const MINI = [".a.a.", "abbba", ".aba.", "..a.."];+const LUB = 0.04, DUB = 0.24; // the two beats, as loop phase++// a beat: a sharp squash that springs back through a stretch+const beat = (ph, at, s) => {+ const u = ph - at;+ if (u < 0 || u > 0.3) return 0;+ return s * Math.exp(-u * 16) * Math.cos(u * 34);+};+const pulse = (ph) => beat(ph, LUB, 1) + beat(ph, DUB, 0.55) + beat(ph + 1, LUB, 1);-// tiny hearts float off from behind it and fadeexport 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 C = fit(o.palette, 8), ph = t / meta.duration, y = -HOVER - 1.2 * Math.sin(ph * TAU);+ blobShadow(p, 0, 8 + 1.5 * pulse(ph), 0.8);+ // tiny hearts float off from behind it, wobbling, and fade+ cycle(t, meta.duration, 4, o.seed, 0.95, (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);+ const x = side * (r.range(2, 5) + age * r.range(9, 15)) + Math.sin(age * 7 + r.range(0, TAU)) * 1.5, yy = y - 5 - age * r.range(14, 19);+ const a = Math.min(1, age / 0.12) * (1 - k * k);+ p.sprite(MINI, { a: k < 0.5 ? C[5] : C[4], b: k < 0.3 ? WHITE : C[6] }, Math.round(x - 2.5), Math.round(yy - 2), { a: a * 1.3 });+ p.glow(x, yy, 5, C[4], 0.3 * a);});}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);+ const C = fit(o.palette, 8), ph = t / meta.duration, y = -HOVER - 1.2 * Math.sin(ph * TAU), b = pulse(ph);+ // squash wide on the beat, then spring back through a stretch+ const sx = 1 + 0.16 * b, sy = 1 - 0.13 * b, cy = Math.round(y);+ // light swells on each beat+ p.glow(0, cy, 22 + 6 * Math.max(0, b), C[4], 0.26 + 0.3 * Math.max(0, b));+ L.begin(-20, cy - 20);+ pillow(L, -12, cy - 11, 12, cy + 11, (x, yy) => heartSdf(x, yy, 0, cy, W * sx, W * sy), (lt, e) => {+ if (lt > 0.92 && e > 1.2) return WHITE;+ return lt > 0.8 ? C[6] : lt > 0.6 ? C[5] : lt > 0.38 ? C[4] : lt > 0.12 ? C[3] : C[2];+ }, { bevel: 3.6 });+ L.outline(INK).draw(p);+ // a thin ring of light snaps out on the big beat+ const u = (((ph - LUB) % 1) + 1) % 1;+ if (u < 0.28) {+ const k = u / 0.28, r = 9 + 8 * (1 - (1 - k) ** 3);+ p.ring(0, cy, r, 1, k < 0.2 ? C[6] : C[5], 0.85 * (1 - k));+ p.glowRing(0, cy, r, 4, C[4], 0.25 * (1 - k));+ }+ // a glint on its shoulder after each beat+ const g = (((ph - LUB - 0.08) % 0.5) + 0.5) % 0.5;+ if (g < 0.12) glint(p, -3.5, cy - 4, 2.6 * Math.sin((g / 0.12) * Math.PI), WHITE, 0.45);}diff --git a/src/fx/pickups/key-glint.js b/src/fx/pickups/key-glint.jsindex dd0799c..54c0c59 100644--- a/src/fx/pickups/key-glint.js+++ b/src/fx/pickups/key-glint.js@@ -1,55 +1,97 @@-import { PAL, bump, TAU, WHITE } from "../../core/index.js";-import { Layer, shadow, twinkle, bob, fit } from "./_lib.js";+// The hover, floor shadow and star glints follow Sprite Fusion's open-source pickup and sparkle+// (https://www.spritefusion.com/pixel-art-vfx/pickup), MIT License, Copyright (c) 2026 Hugo Duprez.+import { fit, clamp, ease, rand, fly, flyV, TAU, WHITE } from "../../core/index.js";+import { Layer, glint, blobShadow } 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.",+ desc: "An ornate silver key hovering and rocking; a glint runs from its bow down the shaft to the teeth and bursts off the tip as falling sparks.",tags: ["pickup", "key", "unlock", "item", "loop"],- size: [40, 40],- origin: [20, 36],- duration: 1.6,+ size: [72, 60],+ origin: [36, 54],+ duration: 2,loop: true,fps: 30,bg: "ground",- options: { palette: PAL.metal, shadow: true, seed: 7 },+ options: { palette: ["#0e1018", "#222838", "#3c4660", "#5e6d8e", "#8c9cbc", "#bccae2", "#e6eeff", "#ffffff"], seed: 7 },};-const L = new Layer(40, 40);-const UPLEFT = (-3 * Math.PI) / 4;+const L = new Layer(48, 40), HOVER = 19, MID = 8, TIP = 17.5;+const G0 = 0.18, G1 = 0.5; // the glint's run, as loop phase-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];+// where the key hangs: bobbing and rocking, bow up to the left, teeth down to the right+const pose = (ph) => ({ y: -HOVER - 1.6 * Math.sin(ph * TAU), a: 0.42 + 0.11 * Math.sin(ph * TAU + 0.9) });+const toWorld = (u, v, cx, cy, a) => [cx + (u - MID) * Math.cos(a) - v * Math.sin(a), cy + (u - MID) * Math.sin(a) + v * Math.cos(a)];++// the key in its own frame: u along the shaft (bow at 0, tip at 17.5), v across it+function part(u, v) {+ const rb = Math.hypot(u, v);+ if (rb <= 4.6 && rb >= 2.1) return 1; // the bow's ring+ if (u >= 4.3 && u <= 6 && Math.abs(v) <= 1.9) return 2; // the collar+ if (u >= 6 && u <= TIP && Math.abs(v) <= 1) return 3; // the shaft+ if (u >= 12.6 && u <= TIP - 0.3 && v > 1 && v <= 4.6 && !(u > 14.3 && u < 15.4 && v > 2.7)) return 4; // the bit+ return 0;+}++function key(p, C, cx, cy, a, gu) {+ const ca = Math.cos(a), sa = Math.sin(a);+ L.begin(Math.floor(cx) - 24, Math.floor(cy) - 20);+ L.fill(Math.floor(cx) - 24, Math.floor(cy) - 20, Math.floor(cx) + 23, Math.floor(cy) + 19, (px, py) => {+ const dx = px - cx, dy = py - cy, u = dx * ca + dy * sa + MID, v = -dx * sa + dy * ca, k = part(u, v);+ if (!k) return 0;+ // light from the top left of the screen: work out which way this bit of metal faces+ let ny;+ if (k === 1) {+ const rb = Math.hypot(u, v), out = rb > 3.4 ? 1 : -1, wx = (u / rb) * out, wy = (v / rb) * out;+ ny = -(((wx * ca - wy * sa) * -0.6) + (wx * sa + wy * ca) * -0.8);+ } else ny = v < -0.35 ? 0.8 : v > 0.35 && k !== 4 ? -0.6 : k === 4 ? (v > 3.6 ? -0.5 : 0.1) : 0.2;+ let c = ny > 0.55 ? 6 : ny > 0.15 ? 4 : ny > -0.3 ? 3 : 2;+ if (k === 2) c = Math.min(7, c + 1);+ // the glint: a slanted band of white running down the key+ const g = Math.abs(u + v * 0.45 - gu);+ if (g < 0.8) return WHITE;+ if (g < 2) c = Math.min(7, c + 2);+ return C[c];});- 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);+ L.outline(C[0]).draw(p);+}++export function drawBack(p, t, o) {+ const { y } = pose(t / meta.duration);+ blobShadow(p, 0, 10, 0.8 - (-y - HOVER + 1.6) * 0.06);+}++export function draw(p, t, o) {+ const C = fit(o.palette, 8), T = meta.duration, ph = t / T, { y, a } = pose(ph);+ const q = (ph - G0) / (G1 - G0), gu = q > 0 && q < 1 ? -5 + (TIP + 7) * ease.inOutSine(q) : -100;+ // cool light round it and all along it+ const [bx, by] = toWorld(0, 0, 0, y, a), [ex, ey] = toWorld(TIP, 0, 0, y, a);+ p.glow(0, y, 24, C[4], 0.3);+ p.glowLine(bx, by, ex, ey, 7, C[5], 0.16);+ key(p, C, 0, y, a, gu);+ // a few idle twinkles round it, one after another+ for (let i = 0; i < 4; i++) {+ const life = 0.4, age = (((t - ((i + 0.6) / 4) * T) % T) + T) % T;+ if (age > life) continue;+ const an = rand(i, o.seed, 8) * TAU, d = 9 + rand(i, o.seed, 9) * 6, k = Math.sin((age / life) * Math.PI);+ glint(p, Math.cos(an) * d, y + Math.sin(an) * d * 0.8 - age * 6, Math.round(1.8 * k), i % 2 ? C[6] : WHITE, 0.35 * k);+ }+ // light rides with the glint+ if (gu > -6) {+ const [gx, gy] = toWorld(clamp(gu, 0, TIP), 0, 0, y, a);+ p.glow(gx, gy, 10, C[6], 0.45 * Math.sin(q * Math.PI));+ }+ // as it leaves the tip: a star, and sparks that arc away and fall+ const [tx, ty] = toWorld(TIP, 0, 0, y, a), at = (ph - G1 + 0.02) * T;+ if (at > 0 && at < 0.3) glint(p, tx, ty, 4.5 * (1 - at / 0.3), C[6], 0.6 * (1 - at / 0.3));+ for (let i = 0; i < 9; i++) {+ const life = 0.32 + rand(i, o.seed, 4) * 0.3, age = at - rand(i, o.seed, 5) * 0.05;+ if (age < 0 || age > life) continue;+ const sp = 25 + rand(i, o.seed, 1) * 45, an = a + (rand(i, o.seed, 2) - 0.5) * 2.2;+ const [x, yy] = fly(tx, ty, Math.cos(an) * sp, Math.sin(an) * sp - 25, age, 380, 2.5), [vx, vy] = flyV(Math.cos(an) * sp, Math.sin(an) * sp - 25, age, 380, 2.5);+ if (yy > -0.5) continue; // it has reached the floor+ const s = Math.hypot(vx, vy) || 1, L2 = Math.min(4, 1 + s * 0.03), k = 1 - age / life;+ p.line(x - (vx / s) * L2, yy - (vy / s) * L2, x, yy, (u) => (u > 0.6 ? WHITE : C[5]), k * 1.6);+ p.glow(x, yy, 3, C[5], 0.4 * k);}- 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.jsindex a239f99..0963f9f 100644--- a/src/fx/pickups/loot-beam.js+++ b/src/fx/pickups/loot-beam.js@@ -1,58 +1,185 @@-import { RAMP, cycle, fract, seg, ease, TAU, WHITE } from "../../core/index.js";-import { Layer, fit } from "./_lib.js";+// The column recipe (ramp bands out from a white core, drifting strands, dithered edges, light every few rows)+// is adapted from Sprite Fusion's open-source holy light (https://www.spritefusion.com/pixel-art-vfx/holy-light),+// MIT License, Copyright (c) 2026 Hugo Duprez.+import { fit, clamp, smooth, ease, rand, cycle, band, flare, TAU, WHITE, hex, mix, scale } from "../../core/index.js";+import { Layer, glint, pool, blobShadow } 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,+ desc: "A dropped sword in a tall pillar of rarity light: a white core thinning to the sky, rings pulsing across the floor, motes streaming up, a glint racing up the shaft.",+ tags: ["pickup", "loot", "beam", "rarity", "drop", "item", "loop"],+ size: [96, 176],+ origin: [48, 162],+ duration: 2.4,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 },+ options: {+ palette: ["#140a24", "#2c1250", "#4b1d86", "#7330c0", "#a050f0", "#c890ff", "#ecd4ff", "#ffffff"],+ seed: 4,+ },};-const L = new Layer(32, 16);-const STEEL = RAMP.metal, GRIP = RAMP.wood;+const H = 150, RINGS = [0.08, 0.58];+const STEEL = ["#151726", "#2c3149", "#4f5775", "#8a93b3", "#d6dcef", "#ffffff"].map(hex);+const GOLD = ["#3a2008", "#7a4a10", "#b8801c", "#e8b432", "#ffe27a", "#fff6cc"].map(hex);+const LEATHER = ["#1e0f0e", "#3e2016", "#633620"].map(hex);+const INK = hex("#0d0b14");+const L = new Layer(40, 24);++// the time since the last ring left the foot, in loop phase, for ring k+const since = (ph, k) => (((ph - RINGS[k]) % 1) + 1) % 1;++// the sword lying where it fell, 22 px from pommel to point: it rests on its guard and its tip, so the hilt+// lifts off the floor. Built column by column on a stepped axis so its lines stay crisp at 1x.+// The beam rises from the guard; the blade reaches out of the light to the right.+const OX = 4, axis = (x) => Math.floor(-4 + (x + 4) / 7 + 0.5);+function sword(p, C, ph) {+ const edgeLit = (x) => (Math.abs(x + OX - 0.5) < 6 ? C[6] : mix(STEEL[4], C[6], 0.45));+ L.begin(-16, -12);+ L.set = ((set) => (x, y, c) => set.call(L, x + OX, y, c))(Object.getPrototypeOf(L).set);+ for (let x = -11; x <= 10; x++) {+ const a = axis(x);+ if (x <= -9) {+ // the pommel: a stone that holds the beam's colour+ const m = x + 10;+ if (m === 0) L.set(x, a - 1, C[6]), L.set(x, a, WHITE), L.set(x, a + 1, C[4]);+ else L.set(x, a, m < 0 ? C[5] : C[3]);+ } else if (x <= -5) {+ // the grip, wrapped in leather+ L.set(x, a, LEATHER[x % 2 ? 2 : 1]);+ L.set(x, a + 1, LEATHER[x % 2 ? 1 : 0]);+ } else if (x <= -3) {+ // the guard, gold catching the beam on its lit face, a small stone at its heart+ for (let y = a - 3; y <= a + 3; y++) {+ const end = y === a - 3 || y === a + 3;+ L.set(x, y, y === a ? (x === -4 ? C[6] : C[4]) : x === -4 ? (end ? GOLD[3] : mix(GOLD[4], C[6], 0.3)) : end ? GOLD[0] : GOLD[1]);+ }+ } else {+ // the blade: a lit edge on top, steel, a dark spine below, tapering to the point+ // backlit by the beam: a dark body with the beam's colour running along its upper edge+ const tip = x - 8;+ if (tip < 1) L.set(x, a - 1, edgeLit(x));+ if (tip < 2) L.set(x, a, tip === 1 ? edgeLit(x) : mix(STEEL[3], C[4], 0.2));+ L.set(x, a + 1, tip === 2 ? STEEL[2] : STEEL[0]);+ }+ }+ delete L.set;+ L.outline(INK).draw(p);+ // a glint slides down the blade's edge once a loop+ const g = (ph - 0.72) / 0.16;+ if (g > 0 && g < 1) {+ const x = -1 + 9 * ease.inOutSine(g);+ glint(p, x + OX, axis(Math.round(x)) - 1, 2.6 * Math.sin(g * Math.PI), WHITE, 0.5);+ }+}++export function drawBack(p, t, o) {+ const C = fit(o.palette, 8), T = meta.duration, ph = t / T;+ // the floor: a pool of rarity light, a bright spot right under the item+ pool(p, 0.5, 0, 34, 5, C[4], 0.14);+ // light thrown on the floor in front, kept off the item itself+ p.shade(-30, -0.5, 31, 6, (x, y, out) => {+ const dx = (x - 0.5) / 30, dy = y / 6, d = dx * dx + dy * dy;+ if (d >= 1) return;+ out.l = C[5];+ out.k = 0.4 * (1 - Math.sqrt(d)) ** 2;+ });+ for (let x = -16; x <= 16; x++) {+ const q = Math.abs(x) / 16.5, a = 1.35 - q * 1.25;+ p.dot(x, 0, q < 0.3 ? WHITE : q < 0.6 ? C[6] : C[5], a);+ if (q < 0.75) p.dot(x, 1, q < 0.3 ? C[6] : q < 0.55 ? C[5] : C[4], a * 0.8);+ if (q < 0.4) p.dot(x, 2, C[4], a * 0.5);+ }+ // the far half of each ring, behind the item and the beam+ for (let k = 0; k < RINGS.length; k++) ring(p, C, since(ph, k) * T, true);+ column(p, C, t, T);+}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;- });+ const C = fit(o.palette, 8), T = meta.duration, ph = t / T;+ // a soft shadow where it lies, dark in the middle of the lit floor+ blobShadow(p, OX - 0.5, 12.5, 0.95);+ sword(p, C, ph);+ for (let k = 0; k < RINGS.length; k++) ring(p, C, since(ph, k) * T, false);+ motes(p, C, t, T, o.seed);+}++// a ring of light that pulses out across the floor from the item's foot+function ring(p, C, a, back) {+ const L1 = 1.1, k = a / L1;+ if (k >= 1) return;+ const r = 3 + 24 * ease.outCubic(k), th = Math.max(1, 3.2 * (1 - k));+ band(p, 0.5, 0, r, 0.2, th, Math.min(1, 1.25 * (1 - k)), [C[2], C[4], C[5], C[6]], (g) => Math.sin(g) < 0 === back, k < 0.12);+ if (!back) for (const s of [-1, 1]) p.glow(0.5 + s * r, -1, 8, C[5], 0.35 * (1 - k));+}++// the column: bands of the ramp out from a white core, strands drifting through it, pulses climbing it, the+// whole thing thinning and dithering away towards the sky; it swells as each ring leaves its foot+function column(p, C, t, T) {+ const ph = t / T;+ let beat = 0;+ for (let k = 0; k < RINGS.length; k++) {+ const s = since(ph, k) * T;+ beat = Math.max(beat, Math.exp(-s * 7) * (s < 0.5 ? 1 : 0), Math.exp(-((T - s) * 30)));}- // 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 glint racing up the shaft once a loop+ const gq = (ph - 0.22) / 0.42, gh = gq > 0 && gq < 1 ? 4 + (H - 4) * ease.inQuad(gq) : -100;+ const shimmer = Math.floor(ph * 24);+ for (let y = -1; y >= -H; y--) {+ const h = -y - 0.5, u = h / H, fade = 1 - smooth(0.25, 1, u);+ // it narrows with height until only the core is left, and the core breaks into dashes near the top+ const w = (4.2 * (1 - 0.45 * u) + 3.2 * Math.exp(-h / 7)) * (1 + 0.2 * beat);+ // dashes of uneven length, flickering, as the column gives out+ const seg = Math.floor(h / 3 + rand(Math.floor(h / 9), 5) * 2), flick = Math.floor(ph * 12);+ if (u > 0.66 && rand(seg, flick, 7) > 1.75 - u * 1.65) continue;+ const thread = u > 0.58 && rand(seg, flick, 9) < (u - 0.58) * 3;+ const climb = ((h / 30 - ph * 3) % 1 + 1) % 1 < 0.1 ? 1 : 0, trail = gh - h > 0 && gh - h < 18 ? 1 - (gh - h) / 18 : 0;+ const X = thread ? 0 : Math.ceil(w * 1.6);+ for (let x = -X; x <= X; x++) {+ const q = Math.abs(x) / w;+ const cw = 0.2 + 0.18 * (1 - smooth(0, 0.5, u));+ let lvl = q < cw ? 0 : q < 0.47 ? 1 : q < 0.72 ? 2 : q < 1 ? 3 : 4;+ for (let s = 0; s < 3; s++) {+ const sx = (s - 1) * w * 0.55 + Math.sin(h * 0.09 + ph * TAU * (s + 1) + s * 2) * 0.9;+ if (Math.abs(x - sx) < 0.5) lvl = Math.max(0, lvl - 1);+ }+ if (rand(y, shimmer, 3) < 0.05 && lvl > 0) lvl--;+ if (q < 0.72) lvl = Math.max(0, lvl - climb - (trail > 0.3 ? 1 : 0));+ // the core and inner bands are solid light; only the fringe is dithered, and it goes first+ const a = lvl <= 2 ? 1 : ((1.55 - q) / 0.75) * fade * 1.2;+ if (a <= 0) continue;+ p.dot(x, y, thread ? (u > 0.85 ? C[6] : WHITE) : lvl === 0 ? (u > 0.8 ? C[6] : WHITE) : C[7 - lvl], a);+ }+ // light all along it: a close glow, and a wide haze that fades with the column+ const near = smooth(8, 20, h);+ if ((y & 3) === 0) p.glow(0.5, y, w * 2.6 + 6, C[5], 0.36 * near * (0.3 + 0.7 * fade) * (1 + 0.4 * beat));+ if ((y & 15) === 0) p.glow(0.5, y, 34, C[4], 0.2 * near * (0.25 + 0.75 * fade));+ }+ if (gh > 0) {+ glint(p, 0, -gh, 3.5 * (1 - gq * 0.5), C[6], 0.6);+ p.glow(0.5, -gh, 14, C[5], 0.45);+ }+ // the foot of the beam burns brightest: a small flare where it rises out of the item+ flare(p, 0.5, -5, 8 + 3 * beat + Math.sin(ph * TAU * 4) * 0.8, 0.6 + 0.4 * beat, C);+ p.glow(0.5, -16, 16, C[4], 0.12 + 0.25 * beat);+}++// motes streaming up round the beam, a few twinkling+function motes(p, C, t, T, seed) {+ cycle(t, T, 30, seed, (g) => g.range(1.0, 2.2), (age, life, r) => {+ const inner = r.chance(0.3), side = r.sign(), x0 = inner ? r.range(-3, 3) : side * r.range(4, 15), vy = r.range(22, 52) * (inner ? 1.5 : 1);+ const x = x0 + Math.sin(age * r.range(1.5, 3.5) + r.range(0, TAU)) * 1.6, y = -r.range(1, 10) - vy * age;+ const k = Math.min(1, age / 0.25, (life - age) / 0.5);+ if (k <= 0 || y < -H) return;+ if (r.chance(0.22)) {+ const tw = 0.5 + 0.5 * Math.sin(age * r.range(9, 14) + r.range(0, TAU));+ if (tw * k > 0.3) glint(p, x, y, tw > 0.75 ? 2 : 1, C[6], 0.4 * k);+ return;+ }+ p.dot(x, y, inner ? WHITE : C[6], k * 1.5);+ p.dot(x, y + 1, inner ? C[6] : C[4], k);+ p.dot(x, y + 2, C[3], k * 0.6);+ p.glow(x + 0.5, y + 0.5, 3.5, C[5], 0.35 * 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.jsdeleted file mode 100644index aecd21a..0000000--- a/src/fx/pickups/magnet-pull.js+++ /dev/null@@ -1,70 +0,0 @@-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.jsindex 10108e8..bfefca9 100644--- a/src/fx/pickups/potion.js+++ b/src/fx/pickups/potion.js@@ -1,71 +1,120 @@-import { PAL, hex, cycle, TAU, WHITE } from "../../core/index.js";-import { Layer, shadow, bob, fit } from "./_lib.js";+// The bubbles (lit and shaded rims, a highlight, a dotted pop) follow Sprite Fusion's open-source bubbles+// (https://www.spritefusion.com/pixel-art-vfx/bubbles), MIT License, Copyright (c) 2026 Hugo Duprez.+import { fit, clamp, rand, cycle, TAU, WHITE, hex, mix, scale } from "../../core/index.js";+import { Layer, blobShadow, glint, pool } 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,+ desc: "A round glass flask of glowing brew rocks in the air: the brew sloshes behind the rock, bubbles rise and pop, light glows through the glass, wisps curl off the cork.",+ tags: ["pickup", "potion", "flask", "brew", "magic", "loop"],+ size: [56, 72],+ origin: [28, 64],+ duration: 2.4,loop: true,fps: 30,bg: "ground",- options: { palette: PAL.arcane, fill: 0.6, shadow: true, seed: 8 },+ options: { palette: ["#1a0516", "#3d0a33", "#701560", "#b0228f", "#f53cd1", "#ff86e6", "#ffd2f6", "#ffffff"], seed: 5 },};-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")];+const RB = 7, HOVER = 17, NECK = 2, LIP = -12, CORK_TOP = -16;+const INK = hex("#120d1a"), GLASS = hex("#2a2236");+const CORK = ["#2a160c", "#4e2c16", "#7a4a26", "#a8703a", "#d09a5a"].map(hex);+const L = new Layer(40, 44);-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];+// the flask hovers and rocks; the brew's surface stays level in the world and lags behind the rock+const pose = (ph) => ({ y: -HOVER - 1.4 * Math.sin(ph * TAU), tilt: 0.13 * Math.sin(ph * TAU + 0.4) });+const surface = (x, ph) => -0.5 + 0.17 * Math.sin(ph * TAU - 0.9) * x + 0.45 * Math.sin(x * 0.85 + ph * TAU * 3);++function flask(p, C, t, ph, cy, tilt, seed) {+ const ct = Math.cos(tilt), st = Math.sin(tilt);+ L.begin(-20, Math.floor(cy) - 22);+ L.fill(-20, Math.floor(cy) - 22, 19, Math.floor(cy) + 12, (px, py) => {+ const wx = px, wy = py - cy, fx = wx * ct + wy * st, fy = -wx * st + wy * ct, d = Math.hypot(fx, fy);+ // the cork, the lip, the neck and the bulb, in the flask's own frame+ if (fy < LIP - 0.5 && fy >= CORK_TOP && Math.abs(fx) <= NECK + 0.2) return CORK[fy < CORK_TOP + 1 ? 4 : fx < -0.6 ? 3 : fx > 1 ? 1 : 2];+ if (fy >= LIP - 0.5 && fy < LIP + 1 && Math.abs(fx) <= NECK + 1.4) return fx < 0 ? mix(WHITE, C[6], 0.4) : mix(GLASS, C[5], 0.45);+ const inNeck = fy >= LIP + 1 && fy < -RB + 2 && Math.abs(fx) <= NECK + 0.6;+ if (d > RB && !inNeck) return 0;+ const wall = inNeck ? Math.abs(fx) > NECK - 0.5 : d > RB - 1;+ // the brew: below its sloshing surface, glowing from within, a bright skin on top+ const s = surface(wx, ph), depth = wy - s;+ if (!wall && !inNeck && depth > 0) {+ // dark at the bottom and the edges, a lit heart, a bright skin with a sheen on its left+ const core = 1 - Math.hypot(wx * 0.85, wy - 1.8) / RB;+ if (depth < 0.9) return wx < -1.5 && wx > -4.5 ? WHITE : C[6];+ let k = core > 0.62 ? 5 : core > 0.38 ? 4 : core > 0.18 ? 3 : 2;+ if (depth < 1.9 && k < 5) k++;+ if (wx > 1.5 && wy > 2) k--;+ return C[Math.max(2, Math.min(6, k))];+ }+ if (wall) {+ // the glass: catching light on its left, showing the brew through its lower half+ const lit = (-fx * 0.75 - fy * 0.66) / Math.max(1, d);+ if (inNeck) return fx < 0 ? mix(GLASS, C[6], 0.55) : mix(GLASS, C[5], 0.3);+ if (lit > 0.82) return mix(WHITE, C[6], 0.3);+ if (lit > 0.3) return mix(GLASS, C[6], 0.5);+ return depth > 0 ? C[3] : mix(GLASS, C[5], 0.28);+ }+ // empty glass above the brew+ return GLASS;});- // 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]);+ L.outline(INK).draw(p);+ // a curved streak of light on the glass, and a pin-point+ for (let a = 3.45; a < 4.35; a += 0.04) {+ const lx = Math.cos(a + tilt) * (RB - 2.2), ly = Math.sin(a + tilt) * (RB - 2.2);+ p.px(lx, cy + ly, a > 3.7 && a < 4.1 ? WHITE : mix(WHITE, C[6], 0.5));+ }+ p.px(Math.round(2 * Math.cos(tilt) + 3 * Math.sin(tilt)), Math.round(cy - 3), WHITE);+ // bubbles rising through the brew and popping at its surface+ cycle(t, meta.duration, 10, seed, (g) => g.range(0.7, 1.3), (age, life, r) => {+ const x0 = r.range(-4, 4), r0 = r.range(0.6, 1.7), vy = r.range(7, 13);+ const x = x0 + Math.sin(age * r.range(5, 9) + r.range(0, TAU)) * 0.7, y = cy + 5.5 - vy * age, ph2 = (t + age) / meta.duration;+ const top = cy + surface(x, ph2);+ if (y > top + 0.8) {+ const rr = r0 * (0.7 + 0.5 * (age / life));+ if (Math.hypot(x, y - cy) > RB - 1.5) return;+ if (rr < 0.95) p.px(x, y, C[6]);+ else {+ p.px(x, y, C[3]), p.px(x + 1, y, C[6]), p.px(x, y - 1, WHITE), p.px(x + 1, y - 1, C[6]);+ if (rr > 1.4) p.px(x - 1, y, C[5]), p.px(x, y + 1, C[4]);+ }+ p.glow(x + 0.5, y, 3, C[6], 0.15);+ } else {+ // the pop: a little arc of light and two flecks thrown up+ const k = clamp((top + 0.8 - y) / 3);+ if (k >= 1) return;+ for (let a = Math.PI; a < TAU; a += 0.6) p.dot(x + Math.cos(a) * (1 + k * 2), top - 0.5 + Math.sin(a) * (1 + k * 2) * 0.5, k < 0.5 ? WHITE : C[6], 1.2 - k);+ p.dot(x - 1, top - 1.5 - k * 3, C[6], 1 - k), p.dot(x + 1.5, top - 2 - k * 4, WHITE, 1 - k);+ }});- // 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));+}++export function drawBack(p, t, o) {+ const C = fit(o.palette, 8), ph = t / meta.duration, { y } = pose(ph);+ blobShadow(p, 0, 7.5, 0.8 - (-y - HOVER + 1.4) * 0.06);+ // light thrown on the floor through the brew+ pool(p, 0, 0.5, 18, 3, C[5], 0.3);+ // wisps curling up off the cork: thin trails of light that sway wider as they rise and fade+ cycle(t, meta.duration, 7, o.seed + 1, (g) => g.range(1.2, 1.8), (age, life, r) => {+ const side = r.sign(), f = r.range(3, 4.5), ph0 = r.range(0, TAU), vy = r.range(11, 16), x0 = r.range(-1, 1);+ const at = (a) => [x0 + Math.sin(a * f + ph0) * (0.8 + a * 3.2) * side, y + CORK_TOP - 1 - a * vy];+ for (let i = 0; i < 9; i++) {+ const a = age - i * 0.04;+ if (a < 0) break;+ const [x, yy] = at(a), k = (1 - a / life) * Math.min(1, a / 0.15) * (1 - i / 9);+ p.dot(x, yy, i === 0 ? WHITE : i < 3 ? C[6] : C[5], k * 1.4);+ if (i === 0) p.glow(x, yy, 4, C[5], 0.3 * 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));+}++export function draw(p, t, o) {+ const C = fit(o.palette, 8), ph = t / meta.duration, { y, tilt } = pose(ph);+ // the brew glows through the glass+ p.glow(0, y + 1.5, 26, C[4], 0.22);+ flask(p, C, t, ph, y, tilt, o.seed);+ p.glow(0, y + 2, 10, C[5], 0.38 + 0.08 * Math.sin(ph * TAU * 2));+ // a glint on the glass now and then+ const g = ((ph + 0.2) % 0.5) / 0.5;+ if (g < 0.16) glint(p, -4, y - 4, 2.6 * Math.sin((g / 0.16) * Math.PI), WHITE, 0.4);}diff --git a/src/fx/pickups/power-star.js b/src/fx/pickups/power-star.jsindex 75508c9..03a5ab9 100644--- a/src/fx/pickups/power-star.js+++ b/src/fx/pickups/power-star.js@@ -1,75 +1,113 @@-import { PAL, cycle, bump, TAU } from "../../core/index.js";-import { Layer, shadow, twinkle, bob, fit } from "./_lib.js";+// The rays and the white-hearted glints follow Sprite Fusion's open-source sparkle+// (https://www.spritefusion.com/pixel-art-vfx/sparkle), MIT License, Copyright (c) 2026 Hugo Duprez.+import { fit, clamp, rand, fly, TAU, WHITE, hex } from "../../core/index.js";+import { Layer, glint, blobShadow } 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,+ desc: "A fat bevelled star rocks side to side and swells on each beat, rays of light turning slowly behind it, sparks spinning off its points.",+ tags: ["pickup", "star", "power-up", "invincible", "bonus", "loop"],+ size: [88, 84],+ origin: [44, 76],+ duration: 1.6,loop: true,fps: 30,bg: "ground",- options: { palette: PAL.volt, shadow: true, seed: 5 },+ options: { palette: ["#2a1604", "#5e3208", "#a05c0c", "#e09414", "#ffc626", "#ffe866", "#fff8c4", "#ffffff"], seed: 9 },};-const L = new Layer(40, 40);-const LIGHT = [-0.45, -0.65, 0.62];+const L = new Layer(44, 44), HOVER = 25, RO = 11.5, RI = 5.2, INK = hex("#1a0e04");+const BEATS = [0.25, 0.75], RAYS = 10, LA = Math.atan2(-0.8, -0.6);-// 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;-}+// a beat: it swells fast and settles slowly+const swell = (ph) => {+ let s = 0;+ for (const b of BEATS) {+ const u = (((ph - b) % 1) + 1) % 1;+ s += Math.exp(-u * 14) * (1 - u * 2.5 > 0 ? 1 : 0);+ }+ return s;+};-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]);+// the star: five arms, each with a ridge down its middle, the two halves catching the light differently+function star(p, C, cx, cy, rot, sc) {+ L.begin(Math.floor(cx) - 21, Math.floor(cy) - 21);+ L.fill(Math.floor(cx) - 21, Math.floor(cy) - 21, Math.floor(cx) + 20, Math.floor(cy) + 20, (px, py) => {+ const dx = (px - cx) / sc, dy = (py - cy) / sc, r = Math.hypot(dx, dy);+ if (r > RO + 0.5) return 0;+ let a = Math.atan2(dy, dx) - rot + Math.PI / 2;+ a = ((a % TAU) + TAU) % TAU;+ const k = Math.floor(a / (Math.PI / 5)), half = k % 2, tip = (Math.floor(k / 2) + half) * ((2 * Math.PI) / 5);+ // inside the edge from this arm's tip to the inner corner beside it+ const tA = tip - Math.PI / 2 + rot, iA = tA + (half ? -1 : 1) * (Math.PI / 5);+ const tx = Math.cos(tA) * RO, ty = Math.sin(tA) * RO, ix = Math.cos(iA) * RI, iy = Math.sin(iA) * RI;+ const ex = ix - tx, ey = iy - ty, side = (dx - tx) * ey - (dy - ty) * ex, cside = -tx * ey + ty * ex;+ if (side * cside < 0) return 0;+ // the facet slopes down from the ridge towards the inner corner: light it by that direction+ const n = tA + (half ? -1 : 1) * (Math.PI / 2), l = Math.cos(n - LA), ridge = Math.abs(Math.sin(Math.atan2(dy, dx) - tA)) * r < 0.6;+ if (r < 1.2) return WHITE;+ const toLight = Math.cos(tA - LA);+ if (ridge) return toLight > 0.3 ? WHITE : toLight > -0.4 ? C[6] : C[5];+ return C[l > 0.6 ? 6 : l > 0.15 ? 5 : l > -0.35 ? 4 : l > -0.75 ? 3 : 2];});- 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));+ L.outline(INK).draw(p);}-// rays wheel slowly behind the star: eight of them, turning one gap a loop so the loop is seamlessexport 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);+ const C = fit(o.palette, 8), ph = t / meta.duration, y = -HOVER - 1.5 * Math.sin(ph * TAU * 2), sw = swell(ph);+ blobShadow(p, 0, 9 + 2 * sw, 0.7);+ // rays turning behind it: long and short by turns, one ray's width a loop, swelling with the beat+ const spin = ph * ((TAU / RAYS) * 2);+ for (let i = 0; i < RAYS; i++) {+ const a = spin + (i * TAU) / RAYS, len = (i % 2 ? 22 : 34) * (1 + 0.18 * sw), ca = Math.cos(a), sa = Math.sin(a), w = i % 2 ? 0.06 : 0.09;+ p.shade(-len - 2, y - len - 2, len + 2, y + len + 2, (x, yy, out) => {+ const rx = x, ry = yy - y, d = rx * ca + ry * sa;+ if (d < 8 || d > len) return;+ const q = Math.abs(rx * sa - ry * ca), hw = 0.5 + d * w;+ if (q > hw + 1.5) return;+ out.l = q < hw * 0.5 ? C[6] : C[5];+ out.k = (0.32 + 0.22 * sw) * (q < hw ? 1 : 1 - (q - hw) / 1.5) * Math.pow(1 - d / len, 1.2) * Math.min(1, (d - 8) / 4);+ });+ // a fine bright line down each long ray+ if (i % 2 === 0) {+ // (clipped at the floor)+ const d0 = RO + 3, d1 = Math.min(len * 0.88, sa > 0.05 ? (-2 - y) / sa : Infinity);+ if (d1 > d0) p.line(ca * d0, y + sa * d0, ca * d1, y + sa * d1, (u) => (u < 0.35 ? C[6] : C[5]), (u) => (u < 0.5 ? 1 : 1.6 - u * 1.4) * (0.75 + 0.35 * sw));+ }+ }+}++export function draw(p, t, o) {+ const C = fit(o.palette, 8), ph = t / meta.duration, y = -HOVER - 1.5 * Math.sin(ph * TAU * 2), sw = swell(ph);+ const rot = 0.22 * Math.sin(ph * TAU), sc = 1 + 0.13 * sw;+ p.glowRing(0, y, RO * sc + 3, 13, C[4], 0.32 + 0.25 * sw);+ p.glow(0, y, 6, C[6], 0.12 + 0.2 * sw);+ star(p, C, 0, y, rot, sc);+ // on each beat a spark spins off every point+ for (const b of BEATS) {+ const age = ((((ph - b) % 1) + 1) % 1) * meta.duration;+ if (age > 0.45) continue;+ for (let i = 0; i < 5; i++) {+ const a = rot + (i * TAU) / 5 - Math.PI / 2, sp = 70 + rand(i, b * 10, 3) * 30, tan = 35;+ const vx = Math.cos(a) * sp - Math.sin(a) * tan, vy = Math.sin(a) * sp + Math.cos(a) * tan;+ const [x, yy] = fly(Math.cos(a) * RO * sc, y + Math.sin(a) * RO * sc, vx, vy, age, 60, 4), k = 1 - age / 0.45;+ glint(p, x, yy, Math.round(2 * k), k > 0.5 ? WHITE : C[6], 0.45 * k);+ }+ }+ // specks of light winking round it, and small stars popping one after another+ const f = Math.floor(ph * 24);+ for (let i = 0; i < 18; i++) {+ if (rand(f + i * 3, i, o.seed) > 0.32) continue;+ const a = rand(i, 1, o.seed) * TAU, d = 13 + rand(i, 2, o.seed) * 20, sy = y + Math.sin(a) * d * 0.85;+ if (sy < -2) p.px(Math.cos(a) * d, sy, rand(f, i, 5) < 0.5 ? WHITE : C[6]);+ }+ for (let i = 0; i < 4; i++) {+ const life = 0.3, age = (((t - ((i + 0.3) / 4) * meta.duration) % meta.duration) + meta.duration) % meta.duration;+ if (age > life) continue;+ const a = rand(i, 7, o.seed) * TAU, d = 15 + rand(i, 8, o.seed) * 12, k = Math.sin((age / life) * Math.PI);+ glint(p, Math.cos(a) * d, y + Math.sin(a) * d * 0.85, Math.round(2.5 * k), i % 2 ? C[6] : WHITE, 0.4 * k);}+ // a glint on the top arm now and then+ const g = ((ph + 0.1) % 0.5) / 0.5;+ if (g < 0.14) glint(p, -2 + rot * 4, y - 6, 3 * Math.sin((g / 0.14) * Math.PI), WHITE, 0.5);}diff --git a/src/fx/pickups/scroll.js b/src/fx/pickups/scroll.jsdeleted file mode 100644index 98ddd02..0000000--- a/src/fx/pickups/scroll.js+++ /dev/null@@ -1,76 +0,0 @@-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.jsdeleted file mode 100644index b991620..0000000--- a/src/fx/pickups/trophy.js+++ /dev/null@@ -1,74 +0,0 @@-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.jsindex 456863c..f7bfafc 100644--- a/src/fx/pickups/xp-orb.js+++ b/src/fx/pickups/xp-orb.js@@ -1,50 +1,66 @@-import { PAL, cycle, TAU, WHITE } from "../../core/index.js";-import { Layer, shadow, pillow, fit } from "./_lib.js";+// The orb's shading and its glow follow Sprite Fusion's open-source pickup orb+// (https://www.spritefusion.com/pixel-art-vfx/pickup), MIT License, Copyright (c) 2026 Hugo Duprez.+import { fit, clamp, rand, cycle, TAU, WHITE, hex } from "../../core/index.js";+import { glint, blobShadow, pool } 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,+ desc: "A small glowing orb races a figure-eight, a comet tail tapering behind it along its path, flecks shed from the tail winking out, its light following it over the floor.",+ tags: ["pickup", "xp", "orb", "experience", "energy", "loop"],+ size: [72, 56],+ origin: [36, 48],+ duration: 1.8,loop: true,fps: 30,bg: "ground",- options: { palette: PAL.matrix, radius: 4.5, shadow: true, seed: 6 },+ options: { palette: ["#0c1806", "#1e3a0a", "#36620e", "#5c9614", "#8cd024", "#c4f060", "#effcc0", "#ffffff"], seed: 2 },};-const L = new Layer(48, 40);-const pos = (ph) => [9 * Math.sin(ph * TAU), -17 + 4 * Math.sin(ph * TAU * 2)];+const A = 16, B = 9, HOVER = 20, TAIL = 0.48, INK = hex("#0a1406");++// the figure-eight, as a function of time (one lap a loop), with a little lift and fall+const at = (t) => {+ const a = (t / meta.duration) * TAU;+ return [A * Math.sin(a), -HOVER + B * Math.sin(a) * Math.cos(a) - 1.2 * Math.cos(a * 2)];+};++export function drawBack(p, t, o) {+ const C = fit(o.palette, 8), [x, y] = at(t);+ // its shadow and its light slide over the floor beneath it+ blobShadow(p, x, 3.5, 0.55);+ pool(p, x, 0.5, 14, 3, C[5], 0.3);+ // flecks shed from the tail drift down and wink out+ cycle(t, meta.duration, 16, o.seed, (g) => g.range(0.35, 0.7), (age, life, r) => {+ const [fx, fy] = at(t - age), k = 1 - age / life, tw = Math.sin(age * r.range(20, 30) + r.range(0, TAU));+ const x2 = fx + r.range(-2, 2) + age * r.range(-6, 6), y2 = fy + r.range(-2, 2) + age * r.range(4, 10);+ if (tw * k > -0.2) p.px(x2, y2, tw > 0.6 && k > 0.5 ? WHITE : k > 0.5 ? C[6] : C[5]);+ p.glow(x2 + 0.5, y2 + 0.5, 3, C[5], 0.3 * k);+ });+}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 C = fit(o.palette, 8), [x, y] = at(t), beat = 0.5 + 0.5 * Math.sin((t / meta.duration) * TAU * 3);+ // the tail: the orb's own path just behind it, tapering and cooling down the ramp+ const n = 60;+ // an outer ribbon cooling down the ramp, then a bright core line down its middle+ for (let i = n; i >= 1; i--) {+ const u = i / n, [tx, ty] = at(t - u * TAIL), r = 3.1 * Math.pow(1 - u, 1.1);+ const c = u < 0.25 ? C[5] : u < 0.55 ? C[4] : C[3];+ if (r > 0.6) p.circle(tx, ty, r, c, u < 0.7 ? 1 : (1 - u) * 3.3);+ else p.dot(tx, ty, c, (1 - u) * 3);+ if (i % 6 === 0) p.glow(tx, ty, 7 * (1 - u) + 2, C[5], 0.24 * (1 - u));}- 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);+ for (let i = Math.floor(n * 0.6); i >= 1; i--) {+ const u = i / n, [tx, ty] = at(t - u * TAIL);+ p.dot(tx, ty, u < 0.2 ? WHITE : C[6], (0.6 - u) * 4);+ }+ // the orb: a dark rim, a bright body, a white heart and a highlight, pulsing with light+ const X = Math.round(x), Y = Math.round(y);+ p.circle(X, Y, 4.4, INK);+ p.circle(X, Y, 3.6, (d, a) => (d > 0.72 ? (Math.cos(a + 2.4) > 0.3 ? C[5] : C[3]) : d > 0.4 ? (Math.cos(a + 2.4) > -0.2 ? C[6] : C[5]) : WHITE));+ p.px(X - 2, Y - 2, WHITE), p.px(X - 1, Y - 2, C[7]);+ p.glow(x, y, 16 + 3 * beat, C[5], 0.36 + 0.14 * beat);+ // a glint now and then+ const g = ((t / meta.duration) * 3) % 1;+ if (g < 0.12) glint(p, X - 2, Y - 2, 2.4 * Math.sin((g / 0.12) * Math.PI), WHITE, 0.4);}diff --git a/src/fx/projectiles/_lib.js b/src/fx/projectiles/_lib.jsindex 3959f91..eaef815 100644--- a/src/fx/projectiles/_lib.js+++ b/src/fx/projectiles/_lib.js@@ -1,146 +1,304 @@-// 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.+// Shared by the projectile effects: a steady emitter for loops, motion in a projectile's own frame, soft smoke+// puffs, speed-stretched sparks, muzzle-flash lobes, brass casings that bounce, and outlined pixel shapes.+// The smoke puff, spark streak, flash lobe and casing recipes are adapted from Sprite Fusion's open-source+// muzzle-flash and explosion (https://www.spritefusion.com/pixel-art-vfx/muzzle-flash),+// MIT License, Copyright (c) 2026 Hugo Duprez. Files starting with _ are helpers, not effects.-import { at, clamp, hex, noise2, rng, wrap, TAU, WHITE } from "../../core/index.js";+import { clamp, mix, rand, rng, wrap, 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;+/**+ * 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), r the same rng every period.+ */+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 + 1e-7, period); age < L; age += period) fn(age, L, rng(seed, i), i);+ }}/**- * 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.+ * Where something is after `age` seconds in the frame of a projectile that flies right at V px/s: launched+ * from (x, y) at (vx, vy) relative to the still air, slowed toward the air by drag k (1/s), pulled by g.+ * The air streams left at V, so whatever it carries streams left too. Returns [x, y, vx, vy] (screen motion).*/-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);+export function wake(x, y, vx, vy, age, V, k, g = 0) {+ const e = Math.exp(-k * age), f = (1 - e) / k, vt = g / k;+ return [x + vx * f - V * age, y + vt * age + (vy - vt) * f, vx * e - V, vt + (vy - vt) * e];+}++/**+ * A soft smoke puff: a body, a denser core sitting low, a lit cap on top while it's young (cap 0..1), and+ * light from a fire on one side (warm 0..1 of color wc, coming from angle wa).+ */+export function puff(p, x, y, r, a, c, cap = 1, warm = 0, wc = 0, wa = 0) {+ if (a <= 0.01 || r < 0.5) return;+ p.disc(x, y, r, c, a * 0.45);+ p.disc(x + r * 0.05, y + r * 0.06, r * 0.74, c, a * 0.62);+ if (cap > 0.02) p.disc(x - r * 0.22, y - r * 0.3, r * 0.5, mix(c, WHITE, 0.14), a * 0.42 * cap);+ if (warm > 0.02) p.disc(x + Math.cos(wa) * r * 0.32, y + Math.sin(wa) * r * 0.32, r * 0.55, wc, a * 0.7 * warm);+}++/**+ * Puffs [{ x, y, r, a, b (brightness 0..1), w (fire light 0..1) }] merged into one translucent volume: each+ * puff is lit on top and shaded underneath, densities add up, and tone and density come out in clean steps, so+ * a trail reads as one billowing cloud with lit crowns instead of a string of beads. R: smoke ramp, dark to+ * bright; WR: the same smoke lit by fire (a ramp as long as R), which young puffs (w) lean to. clip(x, y) can+ * keep it off part of the canvas.+ */+export function cloud(p, list, R, WR, { dens = 1.5, max = 0.86, clip, lit = 1 } = {}) {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);+ let X0 = Infinity, Y0 = Infinity, X1 = -Infinity, Y1 = -Infinity;+ for (const q of list) {+ X0 = Math.min(X0, Math.floor(q.x - q.r)); X1 = Math.max(X1, Math.ceil(q.x + q.r));+ Y0 = Math.min(Y0, Math.floor(q.y - q.r)); Y1 = Math.max(Y1, Math.ceil(q.y + q.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);+ const W = X1 - X0 + 3, H = Y1 - Y0 + 3, D = new Float32Array(W * H), L = new Float32Array(W * H), F = new Float32Array(W * H);+ X0--, Y0--;+ for (const q of list) {+ const r = q.r, r2 = r * r;+ for (let y = Math.floor(q.y - r); y <= Math.ceil(q.y + r); y++) {+ const dy = y + 0.5 - q.y;+ for (let x = Math.floor(q.x - r); x <= Math.ceil(q.x + r); x++) {+ const dx = x + 0.5 - q.x, d2 = (dx * dx + dy * dy) / r2;+ if (d2 >= 1) continue;+ // a ball's thickness: flat in the middle, steep at the rim, so every lump keeps its own crown+ const k = Math.sqrt(1 - d2) * q.a, i = (y - Y0) * W + (x - X0);+ D[i] += k;+ L[i] += k * q.b;+ F[i] += k * q.w * (0.5 + 0.5 * clamp(0.5 + dx / 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);+ }+ // light the merged surface: where density climbs downward the cloud faces up and catches the light. The+ // gradient comes off a blurred copy, so only lump-sized features catch it, never the crossing rims+ const B = blur(blur(D, W, H, 1, 2), W, H, W, 2), n = R.length;+ p.each(X0 + 1, Y0 + 1, X1 + 1, Y1 + 1, (lx, ly, sx, sy) => {+ const cx = Math.floor(lx) - X0, cy = Math.floor(ly) - Y0;+ if (cx < 1 || cy < 1 || cx >= W - 1 || cy >= H - 1) return;+ const i = cy * W + cx, d = D[i];+ if (d < 0.05 || (clip && !clip(lx, ly))) return;+ const a = Math.min(max, Math.ceil((1 - Math.exp(-d * dens)) * 6) / 6);+ if (a < 0.15) return;+ const gy = B[i + W] - B[i - W], gx = B[i + 1] - B[i - 1], up = clamp(0.5 + Math.atan((gy * 0.9 + gx * 0.35) / (B[i] * 0.16 + 0.03)) * 0.42 * lit);+ const w = F[i] / d, j = clamp(Math.round((L[i] / d) * (0.3 + 0.7 * up) * (n - 1) + 0.25 + w * 1.5), 0, n - 1);+ p.blendPx(sx, sy, w > 0.03 ? mix(R[j], WR[j], Math.min(0.9, Math.ceil(w * 10) / 10)) : R[j], a);});}/**- * 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.+ * Simulated smoke for one-shots, drawn with cloud(): add({ x, y, vx, vy, r0, r1, life, a, b, warm, drag, rise,+ * grow, curl, delay }). Puffs push out, slow (drag, 1/s), lift (rise, px/s²), sway, swell from r0 to r1, thin away+ * and darken as they age; warm (fire light) fades fast; curl (rad/s) keeps turning a puff's heading, so a chain of+ * them hooks round into a curl. puffs() gives the live list for cloud().*/-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)));+export class Smoke {+ constructor(rng) {+ this.R = rng;+ this.list = [];+ this.t = 0;+ }+ add(q) {+ this.list.push({ vx: 0, vy: 0, drag: 2.5, rise: 12, grow: 2, curl: 0, a: 0.6, b: 0.85, warm: 0, delay: 0, age: 0, seed: this.R.next() * 100, ...q });+ }+ get count() {+ return this.list.length;+ }+ update(dt) {+ this.t += dt;+ for (let i = this.list.length - 1; i >= 0; i--) {+ const q = this.list[i];+ if (q.delay > 0) {+ q.delay -= dt;+ continue;+ }+ if ((q.age += dt) >= q.life) {+ this.list.splice(i, 1);+ continue;+ }+ if (q.curl) {+ const c = Math.cos(q.curl * dt), s = Math.sin(q.curl * dt), vx = q.vx;+ q.vx = vx * c - q.vy * s;+ q.vy = vx * s + q.vy * c;+ }+ q.vy -= q.rise * dt;+ q.vx += Math.sin(this.t * 1.3 + q.seed) * 8 * dt;+ q.vx -= q.vx * q.drag * dt;+ q.vy -= q.vy * q.drag * dt;+ q.x += q.vx * dt;+ q.y += q.vy * dt;+ }+ }+ puffs() {+ const out = [];+ for (const q of this.list) {+ if (q.delay > 0) continue;+ const k = q.age / q.life;+ out.push({ x: q.x, y: q.y, r: q.r0 + (q.r1 - q.r0) * (1 - Math.exp(-q.grow * q.age)), a: q.a * Math.min(1, q.age * 30) * Math.pow(1 - k, 1.3), b: q.b * (1 - k * 0.5), w: q.warm * Math.exp(-q.age * 5) });+ }+ return out;+ }+}++// a box blur of radius r along one axis of a w x h field (step 1 for rows, w for columns)+function blur(src, w, h, step, r) {+ const out = new Float32Array(src.length), n = step === 1 ? w : h, lines = step === 1 ? h : w, k = 1 / (2 * r + 1);+ for (let l = 0; l < lines; l++) {+ const base = step === 1 ? l * w : l;+ let acc = 0;+ for (let j = -r; j <= r; j++) acc += j >= 0 && j < n ? src[base + j * step] : 0;+ for (let j = 0; j < n; j++) {+ out[base + j * step] = acc * k;+ const a = j - r, b = j + r + 1;+ if (a >= 0) acc -= src[base + a * step];+ if (b < n) acc += src[base + b * step];+ }}+ return out;}/**- * 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.+ * A spark: a two-tone streak stretched along its screen velocity, its head cooling down S (hot, warm, cool,+ * tail colors) as k (life left, 1..0) falls, with a point of light.*/-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]);+export function spark(p, x, y, vx, vy, k, S, glow = 0.45, stretch = 0.022, max = 9) {+ const sp = Math.hypot(vx, vy) || 1, ux = vx / sp, uy = vy / sp, len = Math.min(max, 1 + sp * stretch);+ const head = k > 0.6 ? S[0] : k > 0.3 ? S[1] : S[2];+ p.line(x - ux * len, y - uy * len, x - ux * len * 0.4, y - uy * len * 0.4, k > 0.5 ? head : S[3]);+ p.line(x - ux * len * 0.45, y - uy * len * 0.45, x, y, head);+ p.glow(x, y, 3, head, glow * k);+}++/**+ * The lobes of one muzzle flash, drawn from rng r: a fat fireball at the muzzle, a spike forward, and a burst of+ * rays round it, longest forward, shortest blown back, each side on its own (diagonals, crossways, back),+ * so every shot is a different spiky star. Frame f 2 is the same shape cooled, shorter and thinner; the same r+ * sequence gives the same shape, so a shot keeps its shape across its frames.+ */+export function flashShape(r, f, { size = 1, spike = [12, 20], diag = [5, 10], cross = [3, 6], back = [2, 4.5], core = 0.7 } = {}) {+ const k = f === 1 ? 1 : 0.6, w = f === 1 ? 1 : 0.72, S = size;+ const L = [+ { off: 0.5, a: r.range(-0.08, 0.08), len: r.range(5.5, 8) * S * k, wid: r.range(2.1, 2.6) * S * w, core: 0.5 * core },+ { off: 2, a: r.range(-0.07, 0.07), len: r.range(spike[0], spike[1]) * S * k, wid: r.range(1, 1.3) * S * w, core: 0.35 * core },+ ];+ const ray = (a, len, wid, on) => on && L.push({ off: r.range(0.5, 2), a, len: len * S * k, wid: wid * S * w, core: 0.25 * core });+ for (const s of [-1, 1]) {+ ray(s * r.range(0.3, 0.8), r.range(diag[0], diag[1]), r.range(1.1, 1.5), r.chance(0.85));+ ray(s * r.range(1.15, 1.7), r.range(cross[0], cross[1]), r.range(1, 1.3), r.chance(0.6));+ ray(s * r.range(2, 2.7), r.range(back[0], back[1]), 1, r.chance(0.7) && f === 1);}- return pts;+ return L;}+const profile = (l, u) => {+ const k = u / l.len;+ return l.wid * Math.pow(Math.max(0, 1 - k), 0.8) * Math.min(1, 0.45 + k * 3);+};/**- * 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.+ * Draw flash lobes L at (x, y) pointing along angle a: a white (or hot) core, a hot inner flame, a body and+ * a ragged rim, chosen by how deep a pixel sits inside its lobe. C: [core, inner, body, rim]. seed varies the+ * ragged edge. Returns the flash's reach.*/-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));+export function flash(p, x, y, a, L, C, seed) {+ const c = Math.cos(a), s = Math.sin(a);+ let ext = 2;+ for (const l of L) ext = Math.max(ext, l.off + l.len + 2);+ p.shade(x - ext, y - ext, x + ext, y + ext, (px, py) => {+ const dx = px - x, dy = py - y, along = dx * c + dy * s, across = -dx * s + dy * c;+ let m = -9, hot = false, warm = false;+ for (const l of L) {+ const ca = Math.cos(l.a), sa = Math.sin(l.a), lu = (along - l.off) * ca + across * sa, lv = -(along - l.off) * sa + across * ca;+ if (lu < -1.5 || lu > l.len + 1) continue;+ const r = profile(l, Math.max(0, lu)), mm = r - Math.abs(lv);+ if (mm > m) m = mm;+ if (lu < l.len * l.core && Math.abs(lv) <= r * 0.5) hot = true;+ if (mm > r * 0.4) warm = true;+ }+ const dm = 1.6 - Math.hypot(along - 0.5, across);+ if (dm > m) m = dm;+ if (dm > 0.6) hot = true;+ m += (rand(Math.floor(px) * 73 + Math.floor(py) * 151, seed) - 0.5) * 0.5 * Math.min(1, ext / 14);+ if (m < -0.85) return;+ return m < 0 ? C[3] : hot ? C[0] : warm ? C[1] : C[2];+ });+ return ext;}-/** 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]];+/**+ * A brass casing thrown from (x, y) at (vx, vy) with spin va, falling under g onto a floor at y = floor:+ * it bounces (keeping `bounce` of its speed) until it's too slow, then slides to a stop. Closed form, so a+ * loop can draw it at any age. Returns { x, y, a (angle), rest, hit (seconds since the last bounce, or -1) }.+ */+export function casing(x, y, vx, vy, va, age, g, floor, bounce = 0.42, a0 = 0) {+ let t0 = 0, a = a0, hit = -1;+ for (let n = 0; n < 6; n++) {+ // time to reach the floor from (x, y) moving (vx, vy)+ const d = floor - y, T = (-vy + Math.sqrt(Math.max(0, vy * vy + 2 * g * d))) / g;+ if (age - t0 < T) {+ const u = age - t0;+ return { x: x + vx * u, y: y + vy * u + 0.5 * g * u * u, a: a + va * u, rest: false, hit };+ }+ x += vx * T;+ a += va * T;+ t0 += T;+ hit = age - t0;+ const vin = vy + g * T;+ y = floor;+ if (vin * bounce < 45) {+ // too slow to hop again: slide to a stop, settling flat+ const u = age - t0, k = 7, s = (1 - Math.exp(-k * u)) / k;+ return { x: x + vx * 0.6 * s, y: floor, a: Math.round(a / Math.PI) * Math.PI, rest: true, hit };+ }+ vy = -vin * bounce;+ vx *= 0.55;+ va *= 0.6;+ }+ return { x, y: floor, a: Math.round(a / Math.PI) * Math.PI, rest: true, hit };}-/** 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));++/** Draw a casing: a 3 px brass slug turned by its angle, lit on one end; a glint when it has just hit. */+export function drawCasing(p, k, B, fade = 1) {+ const ca = Math.cos(k.a), sa = Math.sin(k.a), x = k.x, y = k.y - 0.5;+ p.dot(x - ca, y - sa, B[1], fade);+ p.dot(x, y, B[2], fade);+ p.dot(x + ca, y + sa, B[3], fade);+ if (k.hit >= 0 && k.hit < 0.07) {+ p.px(x + ca * 0.5, y - 1, WHITE);+ p.glow(x, y, 5, B[3], 0.55 * (1 - k.hit / 0.07));+ }}/**- * 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 }.+ * A little sprite (rows of characters, pal mapping them to colors, "." empty) turned by ang about its pivot+ * (px, py in sprite pixels) placed at (x, y), sampled nearest-pixel so it stays hard-edged at any angle.*/-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;+export function turnSprite(p, rows, pal, x, y, ang, px, py, a = 1) {+ const H = rows.length, W = rows[0].length, cs = Math.cos(ang), sn = Math.sin(ang), 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]));+ const c = pal[rows[j][i]];+ if (!c) return;+ out.c = c;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).+ * A pixel shape from a builder: build(set) calls set(px, py, ch) for every interior pixel; an outline ('o')+ * is added round it. Returns { rows, x0, y0 } ready for p.sprite at (x0, y0).*/-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);- }+export function pixelShape(x0, y0, w, h, build) {+ const g = Array.from({ length: h }, () => Array(w).fill("."));+ const set = (px, py, ch) => {+ const i = px - x0, j = py - y0;+ if (i >= 0 && j >= 0 && i < w && j < h) g[j][i] = ch;+ };+ build(set);+ const solid = (i, j) => i >= 0 && j >= 0 && i < w && j < h && g[j][i] !== "." && g[j][i] !== "o";+ for (let j = 0; j < h; j++)+ for (let i = 0; i < w; i++)+ if (g[j][i] === "." && (solid(i - 1, j) || solid(i + 1, j) || solid(i, j - 1) || solid(i, j + 1))) g[j][i] = "o";+ return { rows: g.map((r) => r.join("")), x0, y0 };}-/** 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.jsdeleted file mode 100644index 4832f15..0000000--- a/src/fx/projectiles/arrow-hit.js+++ /dev/null@@ -1,60 +0,0 @@-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.jsindex 996827f..943676e 100644--- a/src/fx/projectiles/arrow.js+++ b/src/fx/projectiles/arrow.js@@ -1,35 +1,61 @@-import { ramp, at, cycle, fract, WHITE } from "../../core/index.js";-import { ARROW, ARROW_FLAT, arrowPal, steps } from "./_lib.js";+import { fit, rand, sparkle, mix, hex, TAU, WHITE } from "../../core/index.js";+import { beat } 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,+ desc: "An arrow in flight: a steel broadhead catching the light, a wooden shaft, fletching fluttering in the wind, streaks of air peeling off its head and swirling off its feathers.",+ tags: ["projectile", "arrow", "bow", "medieval", "directional", "loop"],+ size: [112, 32],+ origin: [92, 16],+ duration: 0.6,loop: true,fps: 30,- bg: "dark",- options: { palette: ["#1c2a3a", "#2e4660", "#4a6e8e", "#7aa0bc", "#b4d0e2", "#e8f4fc"], seed: 12 },+ bg: "sky",+ options: {+ palette: ["#7a1f2c", "#b8323c", "#e8e2d6", "#ffffff"],+ wood: ["#3a2414", "#6e4422", "#a8723c", "#d8a868"],+ steel: ["#2e3648", "#5a6680", "#9aa6ba", "#dfe7f2"],+ wind: "#b8c8e8",+ seed: 3,+ },};+// the arrow, nose right, tip at (0, 0): fletching (three poses for the flutter), shaft, binding, broadhead+const HEAD = ["..LL....", "..sLLL..", "bbsSSSSW", "..dDDD..", "..DD...."];+const FLETCH = [+ ["AAa.........", ".aAAa.......", "..aaAAa.....", "nkkkkkkkkkkk", "..cCCc......", ".cCCc.......", "CCc........."],+ [".AAa........", "..aAAa......", "..aaAAAa....", "nkkkkkkkkkkk", "..cCCCc.....", "..cCCc......", ".CCc........"],+ ["AAAa........", "aAAa........", ".aaAAa......", "nkkkkkkkkkkk", "..ccCc......", "cCCc........", "CCc........."],+];+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)));+ const PL = fit(o.palette, 4), W = fit(o.wood, 4), ST = fit(o.steel, 4), wind = hex(o.wind), S = o.seed, D = meta.duration;+ const fr = Math.floor(t * 30 + 1e-6), ph = t / D, left = -meta.origin[0] + 2, LEN = 36;++ // streaks of air peeling off the head and the fletching, stretching back and thinning+ beat(t, D, 9, S, (r) => r.range(0.14, 0.26), (age, life, r) => {+ const k = age / life, top = r.chance(0.5) ? -1 : 1, from = r.chance(0.6) ? -3 : -LEN + 6;+ const x0 = from - age * r.range(160, 240), len = r.range(8, 16) * (0.5 + k), y = 0.5 + top * (r.range(3, 5) + k * r.range(1, 2.5));+ if (x0 - len < left) return;+ const c = k < 0.4 ? wind : mix(wind, hex("#2a2540"), (k - 0.4) * 1.2);+ p.line(x0, y, x0 - len, y, (u) => (u < 0.25 && k < 0.4 ? mix(wind, WHITE, 0.5) : c), (u) => (u < 0.65 ? 1 : (1 - u) / 0.35));});- // 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);+ // little eddies spinning off the feathers+ beat(t, D, 6, S + 3, (r) => r.range(0.15, 0.25), (age, life, r) => {+ const k = age / life, cx = -LEN - 2 - age * r.range(100, 150), cy = 0.5 + r.sign() * r.range(2, 4), a = age * 30 + r.range(0, TAU), rr = 1.2 + k * 1.5;+ if (cx < left + 4) return;+ for (let i = 0; i < 4; i++) p.dot(cx + Math.cos(a + i * 0.5) * rr, cy + Math.sin(a + i * 0.5) * rr, wind, (1 - k) * (1 - i * 0.2));+ });++ // the shaft with a lit top line+ p.line(-LEN + 11, 0, -7, 0, W[2]);+ for (let x = -LEN + 14; x < -8; x += 6) p.px(x, 0, W[3]);+ // the fletching flutters through its poses, faster than the frame rate can quite catch+ const pose = FLETCH[Math.floor(rand(fr, S) * 3)];+ p.sprite(pose, { a: PL[2], A: PL[3], c: PL[0], C: PL[1], k: W[1], n: W[0] }, -LEN, -3);+ // the binding and the broadhead: a lit upper bevel, a shaded lower one, a white point+ p.sprite(HEAD, { L: ST[3], s: ST[2], S: ST[2], d: ST[0], D: ST[1], b: W[0], W: WHITE }, -7, -2);+ // a glint runs down the blade now and then+ const g = (ph * 2) % 1;+ if (g < 0.25) sparkle(p, -5 + g * 16, -1, 1 + Math.round(2 * Math.sin((g / 0.25) * Math.PI)), WHITE, ST[3], 0.25);}diff --git a/src/fx/projectiles/boomerang.js b/src/fx/projectiles/boomerang.jsdeleted file mode 100644index 29bbbd6..0000000--- a/src/fx/projectiles/boomerang.js+++ /dev/null@@ -1,57 +0,0 @@-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.jsindex 97cd21a..75f195d 100644--- a/src/fx/projectiles/bullet-tracer.js+++ b/src/fx/projectiles/bullet-tracer.js@@ -1,42 +1,73 @@-import { PAL, ramp, at, cycle, fly, loopNoise, fract, TAU, WHITE } from "../../core/index.js";+// The spark and streak recipes are adapted from Sprite Fusion's open-source impact ricochet+// (https://www.spritefusion.com/pixel-art-vfx/impact), MIT License, Copyright (c) 2026 Hugo Duprez.+import { fit, rand, noise, smooth, TAU, WHITE } from "../../core/index.js";+import { beat, wake, spark, cloud } from "./_lib.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.",+ desc: "A white-hot slug tearing along, its tracer burning behind it in a long streak that sputters and cools from white through gold to red, shedding sparks and a thread of smoke.",tags: ["projectile", "bullet", "tracer", "gun", "directional", "loop"],- size: [58, 15],- origin: [52, 7],- duration: 0.4,+ size: [200, 40],+ origin: [184, 18],+ duration: 0.6,loop: true,fps: 30,- bg: "dark",- options: { palette: PAL.fire, length: 46, seed: 1 },+ bg: "sky",+ options: {+ palette: ["#4a1712", "#8a1f17", "#c9281f", "#f2561d", "#ff8a2a", "#ffc23d", "#ffe26b", "#fff3a6", "#ffffff"],+ smoke: ["#2e2a36", "#46404f", "#625b6b", "#817a8a", "#a39caa"],+ length: 120,+ speed: 520,+ seed: 4,+ },};-const SLUG = [".##..", "####o", ".##.."];+const SLUG = ["..oyyp..", ".ypwwwwp", "ywwwwwww", ".ypwwwwp", "..oyyp.."];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));+ const F = fit(o.palette, 9), SM = fit(o.smoke, 5), S = o.seed, D = meta.duration, L = o.length, V = o.speed;+ const fr = Math.floor(t * 30 + 1e-6), ph = (TAU * t) / D, left = -meta.origin[0] + 2;++ // a thread of smoke off the cool end of the trace, wavering as it thins+ const puffs = [];+ beat(t, D, 18, S + 7, (r) => r.range(0.5, 0.7), (age, life, r) => {+ const k = age / life, x = -L * r.range(0.45, 0.8) - age * 90, y = 0.5 + Math.sin(age * 6 + r.range(0, TAU)) * age * 3 - age * age * 8;+ if (x < left + 6) return;+ puffs.push({ x, y, r: 1.2 + age * 4, a: 0.55 * (1 - k) * Math.min(1, age * 8) * smooth(left, left + 30, x), b: 0.95 - k * 0.4, w: 0 });+ });+ cloud(p, puffs, SM, SM, { dens: 1.2, max: 0.6 });++ // the trace: a tapering body of burning gas near the slug, banded white core, gold, an orange rim; past it a+ // one-pixel line cooling to red. The compound sputters, so brightness ripples back along it, and the cold end+ // breaks into dashes+ const heat = (d) => 1 - Math.pow(d / L, 0.8) + noise(d * 0.12 - t * 40, S) * 0.12 + 0.08 * Math.sin(d * 0.35 - ph * 9);+ const yAt = (d) => 0.5 + Math.sin(d * 0.09 + ph * 2) * (d / L) * 0.8, HOT = L * 0.32;+ p.shade(-HOT - 1, -4, 1, 5, (x, y) => {+ const d = -x, u = d / HOT;+ if (u < 0 || u > 1) return;+ const w = 0.7 + 2.3 * Math.pow(1 - u, 1.4) * (0.9 + 0.1 * Math.sin(d * 0.8 - ph * 12)), v = Math.abs(y - yAt(d)) / w;+ if (v > 1) return;+ const h = heat(d);+ return v < 0.38 ? (h > 0.8 ? WHITE : F[7]) : v < 0.7 ? (h > 0.75 ? F[7] : h > 0.6 ? F[6] : F[5]) : u < 0.5 ? F[5] : F[4];+ });+ for (let d = HOT; d <= L; d += 0.5) {+ const u = d / L, h = heat(d);+ if (u > 0.55 && rand(Math.floor(d / 3), fr, S) < (u - 0.55) * 1.6) continue;+ const c = h > 0.55 ? F[6] : h > 0.42 ? F[5] : h > 0.3 ? F[4] : h > 0.18 ? F[3] : h > 0.08 ? F[2] : F[1];+ p.dot(-d, yAt(d), c, u < 0.85 ? 1 : (1 - u) / 0.15);}- // 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));+ p.glowLine(-2, 1, -L * 0.45, 1, 6, F[4], 0.35);+ p.glowLine(-2, 1, -L * 0.2, 1, 3, F[7], 0.3);++ // sparks of burning compound shed off the trace, dropping and cooling as they fall behind+ const SP = [F[7], F[6], F[4], F[3]];+ beat(t, D, 16, S + 2, (r) => r.range(0.1, 0.28), (age, life, r) => {+ const [x, y, vx, vy] = wake(-r.range(4, L * 0.5), 0.5 + r.range(-0.5, 1), -r.range(10, 80), r.range(-60, 50), age, V * 0.35, 3, 260);+ if (x > left + 8) spark(p, x, y, vx, vy, 1 - age / life, SP, 0.45, 0.012, 6);});- // 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);++ // the slug: a white-hot pointed round, pale-rimmed, its nose a point of light+ p.sprite(SLUG, { w: WHITE, p: F[7], y: F[6], o: F[5] }, -1, -1);+ p.glow(2, 1, 24, F[4], 0.5);+ p.glow(3, 1, 8, WHITE, 0.55);}diff --git a/src/fx/projectiles/cannonball.js b/src/fx/projectiles/cannonball.jsindex c33529f..d68a7c9 100644--- a/src/fx/projectiles/cannonball.js+++ b/src/fx/projectiles/cannonball.js@@ -1,76 +1,105 @@-import { PAL, RAMP, ramp, at, burst, stream, fly, seg, ease, clamp, WHITE } from "../../core/index.js";-import { smoke, puffs, onCanvas, steps } from "./_lib.js";+// The flash, spark and smoke recipes are adapted from Sprite Fusion's open-source muzzle-flash and explosion+// (https://www.spritefusion.com/pixel-art-vfx/muzzle-flash), MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Lights, P, Rng, fit, mix, clamp, hex, WHITE } from "../../core/index.js";+import { flash, cloud, Smoke } 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,+ name: "Cannon shot",+ desc: "A cannon fires from a muzzle `height` px above the floor (the origin): a white flash, a tongue of flame, the ball arcing off trailing smoke, a big gunsmoke cloud rolling out.",+ tags: ["projectile", "cannon", "cannonball", "smoke", "flash", "directional", "one-shot"],+ size: [208, 116],+ origin: [48, 102],+ duration: 3.8,loop: false,fps: 30,- bg: "dark",- options: { palette: PAL.fire, speed: 270, seed: 10 },+ bg: "ground",+ options: {+ palette: ["#4a1712", "#8a1f17", "#c9281f", "#f2561d", "#ff8a2a", "#ffc23d", "#ffe26b", "#fff3a6", "#ffffff"],+ smoke: ["#3a3542", "#55505e", "#736d7c", "#938d9b", "#b3adba", "#d2cdd6", "#ece8ee"],+ iron: ["#141218", "#2c2a34", "#4c4a58", "#8a8898"],+ height: 12,+ seed: 4,+ },};-const IRON = ["#141820", "#262c3a", "#3a4254", "#5a6478", "#9aa6ba"];+const ANG = -0.32, F1 = 1 / 30;-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 });+export function create(o) {+ const F = fit(o.palette, 9), SM = fit(o.smoke, 7), IR = fit(o.iron, 4), H = o.height, MY = -H, R = new Rng(o.seed);+ const ps = new Particles({ rng: R, ground: () => 0, sparks: [F[7], F[6], F[4], F[3]] }), smoke = new Smoke(R), lights = new Lights();+ const ca = Math.cos(ANG), sa = Math.sin(ANG), right = meta.size[0] - meta.origin[0] - 3, top = -meta.origin[1] + 3;+ const ball = { x: 4, y: MY, vx: ca * 330, vy: sa * 330, out: false };+ const jit = Array.from({ length: 16 }, () => R.next());+ lights.add(12, MY - 2, 44, hex("#ffb060"), 1, 0.35);+ lights.add(6, MY, 18, WHITE, 0.9, 0.08);+ // burning wadding and sparks thrown out with the shot+ for (let i = 0; i < 22; i++) {+ const a = ANG + R.range(-0.45, 0.45), sp = R.range(140, 380);+ ps.spawn(P.SPARK, 6, MY, Math.cos(a) * sp, Math.sin(a) * sp, R.range(0.1, 0.4));}- // 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));+ for (let i = 0; i < 10; i++) {+ const a = ANG + R.range(-0.3, 0.3), sp = R.range(70, 170);+ ps.spawn(P.SPARK, 6, MY, Math.cos(a) * sp, Math.sin(a) * sp, R.range(0.5, 0.9));}- // 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);+ for (let i = 0; i < 8; i++) {+ const a = ANG + R.range(-0.5, 0.3), sp = R.range(40, 110);+ ps.spawn(P.EMBER, 8, MY, Math.cos(a) * sp, Math.sin(a) * sp, R.range(0.7, 1.4), F[5], 2);+ }+ // the gunsmoke: a great white shove of it out of the bore that slows, rolls over itself, swells and lifts+ for (let i = 0; i < 34; i++) {+ const a = ANG + R.range(-0.4, 0.35), sp = R.range(40, 260) * (i < 12 ? 1.1 : 0.75);+ smoke.add({ x: 6 + R.range(0, 6), y: MY + R.range(-2, 2), vx: Math.cos(a) * sp, vy: Math.sin(a) * sp, r0: R.range(3, 4.5), r1: R.range(9, 16), life: R.range(2.7, 3.5), a: R.range(0.6, 0.75), b: R.range(0.9, 1), drag: R.range(2.2, 3.2), rise: R.range(7, 13), grow: R.range(1.5, 2.4), curl: R.range(-1.2, 0.4), warm: 1, delay: R.range(0, 0.05) });+ }+ let t = 0, wisp = 0;+ return {+ update(dt) {+ t += dt;+ if (!ball.out) {+ const x0 = ball.x, y0 = ball.y;+ ball.vy += 260 * dt;+ ball.x += ball.vx * dt;+ ball.y += ball.vy * dt;+ // the ball leaves a thin wisp of smoke off its hot skin, one puff every two pixels of flight+ for (wisp += Math.hypot(ball.x - x0, ball.y - y0) / 2; wisp > 1; wisp--) {+ const f = R.next(), x = x0 + (ball.x - x0) * f, y = y0 + (ball.y - y0) * f;+ if (x < right - 8 && x > 24 && t < 0.6) smoke.add({ x: x - 3, y, vx: -ball.vx * 0.04, vy: -ball.vy * 0.04, r0: 1, r1: R.range(2.5, 3.6) * (1 - t), life: R.range(0.7, 1.1), a: 0.5 * (1 - t), b: 0.95, drag: 2, rise: 5, grow: 2 });+ }+ if (ball.x > right || ball.y < top) ball.out = true;+ }+ ps.update(dt);+ smoke.update(dt);+ lights.update(dt);+ },+ draw(p) {+ const pop = Math.exp(-(t + 0.008) / 0.06), list = smoke.puffs();+ for (const q of list) q.w *= 0.2 + pop * 1.3;+ cloud(p, list, SM, [SM[0], mix(F[1], SM[1], 0.5), mix(F[2], SM[2], 0.45), F[3], F[4], F[6], F[7]], { dens: 1.35, max: 0.86, lit: 1.3 });+ ps.draw(p);+ // the ball: dark iron, a lit crescent, a hot glint where the flash still burns on it+ if (!ball.out) {+ const x = ball.x, y = ball.y;+ p.circle(x, y, 3.2, IR[0]);+ p.circle(x, y, 2.6, IR[1]);+ p.circle(x - 0.7, y - 0.7, 1.8, IR[2]);+ p.px(x - 1, y - 1.5, IR[3]), p.px(x - 2, y - 1, IR[3]);+ p.px(x + 1.5, y + 1, t < 0.3 ? F[5] : IR[2]);+ p.glow(x, y, 6, F[4], 0.45 * clamp(1 - t / 0.5));+ }+ // the flash: a white ball with a tongue of flame for a frame, then a cooler, bigger burst as the gas spills+ if (t < 3 * F1) {+ const f = t < F1 ? 1 : t < 2 * F1 ? 2 : 3, k = (f === 1 ? 1 : f === 2 ? 1.15 : 0.8) * 1.3;+ const L = [{ off: 0, a: 0, len: 12 * k, wid: 5 * k, core: 0.55 }, { off: 2, a: 0, len: (24 + jit[0] * 8) * k, wid: 2.2 * k, core: 0.4 }];+ for (let i = 0; i < 6; i++) {+ const a = (i < 3 ? -1 : 1) * (0.4 + (i % 3) * 0.45 + jit[i + 1] * 0.2), down = Math.sin(ANG + a);+ let len = (8 + jit[i + 7] * 7) * k * (f === 3 ? 0.7 : 1);+ if (down > 0.1) len = Math.min(len, (H - 3) / down);+ L.push({ off: 2, a, len, wid: 1.6 * k, core: 0.25 });+ }+ flash(p, 4, MY, ANG, L, f === 1 ? [WHITE, F[7], F[6], F[3]] : f === 2 ? [F[7], F[6], F[4], F[2]] : [F[5], F[4], F[3], F[1]], f);+ if (f === 1) p.circle(7, MY - 1, 6.5, WHITE), p.ring(7, MY - 1, 7.5, 1, F[7]);+ }+ lights.draw(p);+ p.glow(14, 0, 22, F[4], 0.25 * pop);+ },+ };}diff --git a/src/fx/projectiles/energy-disc.js b/src/fx/projectiles/energy-disc.jsindex 055a2fc..e46a475 100644--- a/src/fx/projectiles/energy-disc.js+++ b/src/fx/projectiles/energy-disc.js@@ -1,44 +1,70 @@-import { PAL, ramp, at, cycle, fly, fract, TAU, WHITE } from "../../core/index.js";-import { onCanvas } from "./_lib.js";+// The tangent spark streaks are adapted from Sprite Fusion's open-source energy and impact effects+// (https://www.spritefusion.com/pixel-art-vfx/energy), MIT License, Copyright (c) 2026 Hugo Duprez.+import { fit, rng, TAU, WHITE } from "../../core/index.js";+import { beat, wake, spark } 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,+ desc: "A sawblade of crackling energy spinning flat out as it flies: hooked teeth bright on their leading edges, a white hub, spiral arms churning, sparks flung off the teeth.",+ tags: ["projectile", "disc", "saw", "energy", "sci-fi", "directional", "loop"],+ size: [120, 52],+ origin: [92, 26],+ duration: 0.5,loop: true,fps: 30,- bg: "dark",- options: { palette: PAL.electric, teeth: 5, radius: 9, seed: 14 },+ bg: "sky",+ options: { palette: ["#0a0f2e", "#172a78", "#2550d0", "#3f8cff", "#7cc8ff", "#c8f0ff", "#ffffff"], size: 9, teeth: 8, speed: 220, seed: 5 },};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);+ const C = fit(o.palette, 7), R = o.size, N = o.teeth, V = o.speed, S = o.seed, D = meta.duration, left = -meta.origin[0] + 2;+ const rot = (TAU * 3 * t) / D, seg = TAU / N, frac = (x) => x - Math.floor(x);++ // speed lines peeling off the rim, top and bottom, stretching back and cooling+ beat(t, D, 8, S + 4, (r) => r.range(0.12, 0.22), (age, life, r) => {+ const k = age / life, side = r.chance(0.5) ? -1 : 1, x0 = -2 - age * r.range(180, 260), len = r.range(8, 16) * (0.5 + k), y = side * (R + r.range(0.5, 3));+ if (x0 - len < left) return;+ p.line(x0, y, x0 - len, y, k < 0.35 ? C[5] : k < 0.7 ? C[4] : C[3], (u) => (u < 0.65 ? 1 : (1 - u) / 0.35));+ });+ p.glowLine(-2, 0, -26, 0, 8, C[3], 0.35);++ // sparks flung off the tooth tips along the spin, then left behind in the air+ const SP = [WHITE, C[5], C[4], C[3]];+ beat(t, D, 20, S, (r) => r.range(0.12, 0.3), (age, life, r) => {+ const a = rot - r.range(0, TAU) * 0 + r.range(0, TAU), tip = R + 3.5, x0 = Math.cos(a) * tip, y0 = Math.sin(a) * tip, v = r.range(120, 230);+ const [x, y, vx, vy] = wake(x0, y0, -Math.sin(a) * v, Math.cos(a) * v, age, V * 0.6, 2.4, 60);+ if (x > left + 8 && Math.abs(y) < 23) spark(p, x, y, vx, vy, 1 - age / life, SP, 0.45, 0.014, 7);});- // 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));++ // the disc: a white hub in a dark collar, spiral arms of energy churning, a bright rim; past the rim, hooked+ // teeth that run white on their leading faces, and a dim blur ring where the teeth have just been+ p.shade(-R - 5, -R - 5, R + 5, R + 5, (x, y) => {+ const r = Math.hypot(x, y), th = Math.atan2(y, x);+ if (r > R + 4.6) return;+ if (r <= R) {+ if (r < 1.8) return WHITE;+ if (r < 2.9) return C[1];+ if (r > R - 1.1) return C[5];+ const arm = Math.sin(3 * (th - rot * 0.5) - r * 0.85);+ return arm > 0.65 ? C[5] : arm > 0.2 ? C[4] : arm > -0.3 ? C[3] : C[2];+ }+ const ph = frac((th - rot) / seg), h = 4.2 * Math.pow(ph, 1.4);+ if (r - R < h) return ph > 0.86 ? WHITE : ph > 0.6 ? C[6] : ph > 0.35 ? C[5] : C[4];+ if (r - R < 1.6) return C[2];});- 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);+ // filaments of energy crackling from the hub to the rim, new every frame+ const fr = Math.floor(t * 30 + 1e-6);+ for (let j = 0; j < 3; j++) {+ const g = rng(fr, j, S), a0 = g.range(0, TAU), pts = [];+ for (let i = 0; i <= 4; i++) {+ const rr = 2.5 + ((R - 3) * i) / 4, a = a0 + i * 0.25 + (i ? g.range(-0.35, 0.35) : 0);+ pts.push([Math.cos(a) * rr, Math.sin(a) * rr]);+ }+ p.polyline(pts, j ? C[6] : WHITE);+ }+ p.ring(0, 0, R + 0.5, 1, C[6]);+ // light: a soft pool, a hot hub, a glint riding the top of the rim+ p.glow(0, 0, 30, C[3], 0.4);+ p.glow(0, 0, 6, C[5], 0.35);+ p.glow(Math.cos(rot) * R, Math.sin(rot) * R, 5, C[6], 0.4);}diff --git a/src/fx/projectiles/flare.js b/src/fx/projectiles/flare.jsindex f680ddb..12e0694 100644--- a/src/fx/projectiles/flare.js+++ b/src/fx/projectiles/flare.js@@ -1,77 +1,105 @@-import { RAMP, ramp, at, stream, fly, rand, seg, ease, WHITE } from "../../core/index.js";-import { puffs, onCanvas } from "./_lib.js";+// The spark, star and light recipes are adapted from Sprite Fusion's open-source explosion and sparkle+// (https://www.spritefusion.com/pixel-art-vfx/explosion), MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Lights, P, Rng, fit, mix, clamp, smooth, ease, rand, sparkle, flare as rays, TAU, WHITE } from "../../core/index.js";+import { cloud, Smoke } 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,+ desc: "A signal flare streaks up off the ground trailing sparks and smoke, bursts, and hangs as a pulsing red star that drips sparks under its own red-lit smoke, then gutters out.",+ tags: ["projectile", "flare", "signal", "fire", "smoke", "light", "one-shot"],+ size: [152, 232],+ origin: [76, 226],+ duration: 5,loop: false,fps: 30,bg: "sky",- options: { palette: ["#2a0610", "#5c0c1a", "#9c1424", "#e0242c", "#ff5a4a", "#ffa08a", "#ffe0d4", "#ffffff"], seed: 11 },+ options: {+ palette: ["#2a0610", "#5c0d1c", "#9a1428", "#d8243a", "#ff4d5e", "#ff8a94", "#ffd0d4", "#ffffff"],+ smoke: ["#1e1a26", "#2e2938", "#433d4d", "#5b5466", "#77707f", "#958e9c", "#b3acb9"],+ height: 150,+ seed: 2,+ },};-const T1 = 0.7, T2 = 2.3, T3 = 2.55; // ignite at the top, start to gutter, out+const RISE = 0.85, BURN = 3.1;-/** 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);+export function create(o) {+ const C = fit(o.palette, 8), SM = fit(o.smoke, 7), H = o.height, R = new Rng(o.seed);+ const ps = new Particles({ rng: R, ground: () => 0, sparks: [WHITE, C[6], C[4], C[2]] }), smoke = new Smoke(R), lights = new Lights();+ const WR = [C[0], C[1], mix(C[2], SM[2], 0.45), mix(C[3], SM[3], 0.35), C[4], C[5], C[6]];+ // the rise: fast off the ground, slowing to the top; then the star hangs, sways and sinks slowly+ const rise = (t) => [Math.sin(t * 3) * 2 * (t / RISE), -H * ease.outCubic(clamp(t / RISE))];+ const star = (t) => {+ const u = t - RISE;+ return [Math.sin(u * 1.6) * 3 + rise(RISE)[0], -H + u * 9 + Math.sin(u * 2.3) * 1.5];+ };+ let t = 0, burst = false, emit = 0, drip = 0;+ lights.add(0, -3, 26, C[4], 0.8, 0.25);+ for (let i = 0; i < 5; i++) smoke.add({ x: R.range(-3, 3), y: -2, vx: R.range(-25, 25), vy: -R.range(5, 20), r0: 2, r1: R.range(4, 6), life: R.range(1, 1.6), a: 0.5, warm: 0.8, rise: 6 });+ return {+ update(dt) {+ t += dt;+ if (t < RISE) {+ const [x, y] = rise(t), [px, py] = rise(Math.max(0, t - dt));+ for (emit += Math.hypot(x - px, y - py) / 1.5; emit > 1; emit--)+ smoke.add({ x: x + R.range(-0.6, 0.6), y: y + 4, vx: R.range(-6, 6), vy: R.range(0, 8), r0: 1.3, r1: R.range(3, 4.8), life: R.range(1.4, 2.1), a: 0.5, b: 0.95, warm: 0.9, rise: 3, drag: 2, grow: 1.4 });+ if (R.chance(0.5)) ps.spawn(P.SPARK, x, y + 3, R.range(-40, 40), R.range(20, 90), R.range(0.2, 0.45));+ } else if (!burst) {+ burst = true;+ const [x, y] = star(t);+ lights.add(x, y, 64, C[4], 0.9, 0.5);+ lights.add(x, y, 24, WHITE, 0.8, 0.12);+ for (let i = 0; i < 30; i++) {+ const a = R.range(0, TAU), sp = R.range(70, 190);+ ps.spawn(P.SPARK, x, y, Math.cos(a) * sp, Math.sin(a) * sp - 30, R.range(0.25, 0.7));+ }+ for (let i = 0; i < 10; i++) smoke.add({ x: x + R.range(-3, 3), y: y + R.range(-3, 3), vx: R.range(-40, 40), vy: R.range(-40, 10), r0: 2.5, r1: R.range(6, 9), life: R.range(1.6, 2.4), a: 0.55, warm: 1, rise: 10, drag: 2.5 });+ } else if (t < RISE + BURN) {+ // the star burns: sparks drip off it, smoke boils up off it into a plume it lights from below+ const [x, y] = star(t), k = (t - RISE) / BURN, power = 1 - smooth(0.75, 1, k);+ for (drip += dt * 26 * power; drip > 1; drip--) ps.spawn(P.SPARK, x + R.range(-1.5, 1.5), y + 2, R.range(-30, 30), R.range(10, 60), R.range(0.35, 0.8));+ if (R.chance(dt * 18 * power)) smoke.add({ x: x + R.range(-1.5, 1.5), y: y - 2, vx: R.range(-8, 8), vy: -R.range(15, 30), r0: 2, r1: R.range(6, 10), life: R.range(1.6, 2.4) * (1 - 0.4 * k), a: 0.5, b: 0.85, warm: 1, rise: 14, drag: 1.6, grow: 1.2 });+ }+ ps.update(dt);+ smoke.update(dt);+ lights.update(dt);+ },+ draw(p) {+ // the smoke lit red by the star, more the closer and the brighter it burns+ const list = smoke.puffs(), lit = t > RISE && t < RISE + BURN ? 1 - smooth(0.75, 1, (t - RISE) / BURN) : 0;+ if (lit > 0) {+ const [sx, sy] = star(t);+ for (const q of list) q.w = Math.max(q.w, lit * Math.exp(-Math.hypot(q.x - sx, q.y - sy) / 26));+ }+ cloud(p, list, SM, WR, { dens: 1.4, max: 0.8, lit: 1.3 });+ ps.draw(p);+ if (t < RISE) {+ // the rising flare: a white-hot head, a short red flame under it+ const [x, y] = rise(t);+ p.line(x, y + 1, x, y + 5, (u) => (u < 0.3 ? C[6] : u < 0.7 ? C[4] : C[3]));+ p.px(x, y, WHITE), p.px(x, y - 1, C[6]);+ p.glow(x, y, 14, C[4], 0.6);+ p.glow(x, y, 4, WHITE, 0.4);+ } else if (t < RISE + BURN) {+ const [x, y] = star(t), u = t - RISE, k = u / BURN, fr = Math.floor(t * 30);+ const fl = 0.8 + 0.2 * rand(fr, 3) + 0.08 * Math.sin(u * 19), die = 1 - smooth(0.78, 1, k);+ // the burst: a flash of white and rays for a moment+ if (u < 0.25) {+ const e = u / 0.25;+ rays(p, x, y, 22 * (1 - e) + 3, 1 - e, C);+ if (e < 0.25) p.circle(x, y, 5 * (1 - e * 3) + 1, WHITE);+ }+ // the star: a hot ball with a long cross of light that pulses, guttering at the end+ const r = (2 + 0.6 * fl) * (0.4 + 0.6 * die);+ p.circle(x, y, r + 1.2, C[3]);+ p.circle(x, y, r, die > 0.4 ? C[5] : C[4]);+ if (die > 0.25) p.circle(x - 0.3, y - 0.3, r * 0.55, die > 0.6 ? WHITE : C[6]);+ if (die > 0.15 && rand(fr, 9) > 0.15) sparkle(p, x, y, Math.round((5 + 3 * fl) * die), C[6], C[4], 0.5 * die);+ p.glow(x, y, 70 * (0.6 + 0.4 * die), C[3], 0.55 * fl * die);+ p.glow(x, y, 22, C[4], 0.5 * fl * die);+ p.glow(x, y, 6, WHITE, 0.35 * die);+ }+ lights.draw(p);+ },+ };}diff --git a/src/fx/projectiles/homing-missile.js b/src/fx/projectiles/homing-missile.jsindex 5ee5e4e..97b9950 100644--- a/src/fx/projectiles/homing-missile.js+++ b/src/fx/projectiles/homing-missile.js@@ -1,85 +1,174 @@-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";+// The blast's particle recipe (fire that cools, sparks, embers, grit, rocks, scorch, floor ring, lights) is adapted+// from Sprite Fusion's open-source explosion (https://www.spritefusion.com/pixel-art-vfx/explosion),+// MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Bits, Lights, P, B, Rng, fit, band, clamp, smooth, rand, mix, scale, hex, TAU, WHITE } from "../../core/index.js";+import { cloud, Smoke, turnSprite } 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,+ desc: "A missile kicks off, arcs up, rolls over and dives onto its target (the origin), its smoke trail left hanging in the air, and hits in a fiery blast of flame, sparks and rocks.",+ tags: ["projectile", "missile", "rocket", "homing", "smoke", "explosion", "one-shot"],+ size: [248, 140],+ origin: [160, 120],+ duration: 3.8,loop: false,fps: 30,- bg: "dark",- options: { palette: PAL.fire, seed: 8 },+ bg: "ground",+ options: {+ palette: ["#4a1712", "#8a1f17", "#c9281f", "#f2561d", "#ff8a2a", "#ffc23d", "#ffe26b", "#fff3a6", "#ffffff"],+ metal: ["#25243a", "#3e4058", "#61667f", "#8e97b0", "#c4cce0"],+ smoke: ["#26222e", "#3b3644", "#544e5e", "#6f6979", "#8c8596", "#aca5b5", "#cbc4d2"],+ stone: "#4a3f69",+ 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;+const FLY = 1.15;+// the path: up out of the launcher, over the top, and down onto the target, faster all the way+const PATH = [[-130, -22], [-114, -110], [-30, -120], [0, 0]];+const at = (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 * PATH[0][0] + b * PATH[1][0] + c * PATH[2][0] + d * PATH[3][0], a * PATH[0][1] + b * PATH[1][1] + c * PATH[2][1] + d * PATH[3][1]];+};+const heading = (u) => {+ const v = 1 - u, d = (i) => 3 * v * v * (PATH[1][i] - PATH[0][i]) + 6 * v * u * (PATH[2][i] - PATH[1][i]) + 3 * u * u * (PATH[3][i] - PATH[2][i]);+ return Math.atan2(d(1), d(0));};+const progress = (t) => Math.pow(clamp(t / FLY), 1.45);+// the missile, nose right: fins, a body lit on top, a red warhead with a white tip+const MISSILE = ["ff..........", ".fhhhhhhhre.", "nmmmmmmmmrrw", ".fsssssssrd.", "ff.........."];-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);+export function create(o) {+ const F = fit(o.palette, 9), M = fit(o.metal, 5), SM = fit(o.smoke, 7), R = new Rng(o.seed), floor = () => 0;+ const st = hex(o.stone), stone = { light: mix(scale(st, 1.35), WHITE, 0.08), body: st, shade: scale(st, 0.64), dust: mix(scale(st, 1.2), hex("#968c96"), 0.3) };+ const ps = new Particles({ rng: R, ground: floor, sparks: [F[7], F[6], F[4], F[3]] }), smoke = new Smoke(R), rocks = new Bits({ ground: floor }), lights = new Lights();+ const pal = { f: M[1], h: M[4], m: M[3], s: M[1], n: M[0], r: F[2], e: F[3], d: F[1], w: WHITE };+ let t = 0, emit = 0, hit = false;+ lights.add(PATH[0][0], PATH[0][1], 30, F[4], 0.7, 0.25);+ for (let i = 0; i < 6; i++) smoke.add({ x: PATH[0][0] + 2, y: PATH[0][1] + 2, vx: R.range(-30, 20), vy: R.range(-10, 15), r0: 2, r1: R.range(5, 7.5), life: R.range(1.2, 1.8), a: 0.6, warm: 1, rise: 8 });++ const blast = () => {+ const Y = -6;+ lights.add(0, Y - 2, 52, hex("#ffb060"), 0.8, 0.8);+ lights.add(0, Y - 2, 30, WHITE, 0.75, 0.1);+ for (let i = 0; i < 26; i++) {+ const a = R.range(0, TAU), d = R.range(0, 6), sp = R.range(30, 170);+ ps.spawn(P.FIRE, Math.cos(a) * d, Y + Math.sin(a) * d, Math.cos(a) * sp, Math.sin(a) * sp * 0.75 - 40, R.range(0.45, 0.95), 0, R.range(3.2, 6.5));+ }+ for (let i = 0; i < 5; i++) ps.spawn(P.FIRE, R.range(-3, 3), Y, R.range(-10, 10), -R.range(90, 150), R.range(0.7, 1.1), 0, R.range(4, 5.5), R.range(0, 0.08));+ for (let i = 0; i < 70; i++) {+ const a = R.range(Math.PI + 0.12, TAU - 0.12), sp = R.range(110, 280);+ ps.spawn(P.SPARK, 0, Y, Math.cos(a) * sp, Math.sin(a) * sp - 40, R.range(0.2, 0.65));+ }+ for (let i = 0; i < 22; i++) {+ const a = R.range(Math.PI, TAU), sp = R.range(30, 110);+ ps.spawn(P.EMBER, Math.cos(a) * 4, Y + Math.sin(a) * 4, Math.cos(a) * sp, Math.sin(a) * sp - 50, R.range(0.9, 1.6), F[4]);+ }+ for (let i = 0; i < 16; i++)+ rocks.add({ kind: B.CHUNK, x: R.range(-5, 5), y: -2, vx: R.range(-110, 110), vy: -R.range(140, 290), g: 1, drag: 0.4, bounce: 0.3, life: R.range(1.5, 2.2), a: R.range(0, TAU), va: R.range(-16, 16), s: R.int(1, 2) });+ for (let i = 0; i < 60; i++) {+ const u = R.range(-1, 1), a = -Math.PI / 2 + u * 0.55, sp = R.range(80, 220) * (1 - 0.4 * Math.abs(u));+ ps.spawn(P.GRIT, u * 4, -1, Math.cos(a) * sp, Math.sin(a) * sp, R.range(1, 1.8), R.pick([stone.light, stone.body, stone.body, stone.shade]), R.chance(0.4) ? 2 : 1);+ }+ // the smoke: a column off the fire and dust rolling out along the floor, lit by the blast at first+ for (let i = 0; i < 18; i++) {+ const a = R.range(Math.PI * 1.15, Math.PI * 1.85), sp = R.range(20, 90);+ smoke.add({ x: Math.cos(a) * 4, y: Y + Math.sin(a) * 4, vx: Math.cos(a) * sp * 0.7, vy: Math.sin(a) * sp - 45 * (i / 18), r0: 3, r1: R.range(8, 14), life: R.range(1.7, 2.2), a: 0.62, b: 0.88, warm: 1, rise: 30 + i * 2, drag: 1.8, delay: R.range(0.05, 0.35) });+ }+ for (let i = 0; i < 12; i++) {+ const s = R.sign();+ smoke.add({ x: s * R.range(0, 6), y: -3, vx: s * R.range(60, 150), vy: -R.range(3, 12), r0: 2.5, r1: R.range(6, 9), life: R.range(1.1, 1.7), a: 0.5, b: 0.75, warm: 0.3, rise: 6, drag: 3 });}- }- // 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);+ };++ return {+ update(dt) {+ t += dt;+ if (t < FLY) {+ // the trail: puffs left behind along the path, hanging where they're dropped, swelling and thinning+ const u = progress(t), [x, y] = at(u), h = heading(u), cx = Math.cos(h), cy = Math.sin(h), [px, py] = at(progress(Math.max(0, t - dt)));+ // one puff every pixel and a half of flight, wherever along this step it fell, so the trail has no beads+ for (emit += Math.hypot(x - px, y - py) / 1.5; emit > 1; emit--) {+ const f = (emit - 1) / Math.max(1e-6, Math.hypot(x - px, y - py) / 1.5), ex = x + (px - x) * f, ey = y + (py - y) * f;+ smoke.add({ x: ex - cx * 7 + R.range(-0.6, 0.6), y: ey - cy * 7 + R.range(-0.6, 0.6), vx: -cx * R.range(10, 30) + R.range(-6, 6), vy: -cy * R.range(10, 30) + R.range(-6, 6), r0: 1.4, r1: R.range(3.5, 6), life: R.range(1.5, 2.3), a: 0.5, b: 0.9, warm: 0.8, rise: 4, drag: 3, grow: 1.2 });+ }+ if (R.chance(0.35)) {+ const a = h + Math.PI + R.range(-0.5, 0.5), sp = R.range(40, 140);+ ps.spawn(P.SPARK, x - cx * 7, y - cy * 7, Math.cos(a) * sp, Math.sin(a) * sp, R.range(0.15, 0.35));+ }+ } else if (!hit) {+ hit = true;+ blast();+ }+ for (const b of rocks.list)+ if (b.rest && !b.dusted) {+ b.dusted = true;+ for (let i = 0; i < 2; i++) ps.spawn(P.DUST, b.x + R.range(-1, 1), -0.5, R.sign() * R.range(8, 30), -R.range(2, 14), R.range(0.3, 0.6), stone.dust, R.range(1.2, 2.2));+ }+ ps.update(dt);+ smoke.update(dt);+ rocks.update(dt);+ lights.update(dt);+ },+ drawBack(p) {+ // the scorch: white-hot where it hit, cooling through the fire to soot, fading late+ if (hit) {+ const k = t - FLY, fade = 1 - smooth(meta.duration - 1, meta.duration - 0.2, t), rx = 16 * Math.min(1, k / 0.06);+ for (let y = 0; y <= 2; y++)+ for (let x = Math.floor(-rx); x <= Math.ceil(rx); x++) {+ const d = Math.hypot((x + 0.5) / rx, (y + 0.5) / 4);+ if (d > 1) continue;+ const T = Math.pow(clamp(1 - k / 1.4), 1.4) * (1.25 - d) - rand(x * 31 + y, 3) * 0.35;+ p.dot(x, y, T > 0.06 ? F[Math.max(1, Math.min(8, Math.round(T * 8)))] : d < 0.5 ? hex("#0d0a12") : hex("#17121d"), fade);+ }+ const q = k / 0.45;+ if (q < 1) band(p, 0, 0.5, 60 * (1 - Math.pow(1 - q, 3)), 0.16, Math.max(1, 4 * (1 - q)), 1.15 - q, [stone.body, stone.light, F[4], F[7]], (g) => Math.sin(g) < 0);+ }+ },+ draw(p) {+ const list = smoke.puffs();+ cloud(p, list, SM, [SM[0], mix(F[1], SM[1], 0.5), mix(F[2], SM[2], 0.4), F[3], F[4], F[6], F[7]], { dens: 1.4, max: 0.82, lit: 1.4 });+ if (hit) {+ const q = (t - FLY) / 0.45;+ if (q < 1) band(p, 0, 0.5, 60 * (1 - Math.pow(1 - q, 3)), 0.16, Math.max(1, 4 * (1 - q)), 1.15 - q, [stone.body, stone.light, F[4], F[7]], (g) => Math.sin(g) >= 0);+ }+ for (const b of rocks.list) {+ const r = 0.6 + b.s * 0.75, fade = Math.min(1, b.life / 0.5), lx = Math.cos(b.a) * r * 0.4, ly = Math.sin(b.a) * r * 0.4;+ p.shade(b.x - r - 1, b.y - r - 1, b.x + r + 1, b.y + r + 1, (x, y, out) => {+ const dx = x - b.x, dy = y - b.y, d = Math.hypot(dx * 1.15, dy);+ if (d > r + 0.9) return;+ const lit = dx * lx + dy * ly;+ out.c = d > r ? hex("#1a1422") : lit < -0.4 ? stone.light : lit > 0.6 ? stone.shade : stone.body;+ out.a = fade;+ });+ }+ ps.draw(p);+ if (t < FLY) {+ const u = progress(t), [x, y] = at(u), h = heading(u), cx = Math.cos(h), cy = Math.sin(h), fr = Math.floor(t * 30);+ // the motor: a short white-hot jet that flickers, the missile riding its heading+ const J = 5 + 3 * rand(fr, 7);+ for (let d = 0; d <= J; d += 0.5) {+ const v = d / J, c = v < 0.3 ? WHITE : v < 0.6 ? F[6] : F[4];+ p.dot(x - cx * (6.5 + d), y - cy * (6.5 + d), c);+ if (v < 0.5) p.dot(x - cx * (6.5 + d) - cy * 0.8, y - cy * (6.5 + d) + cx * 0.8, F[5]);+ }+ turnSprite(p, MISSILE, pal, x, y, h, 6, 2.5);+ p.glow(x - cx * 8, y - cy * 8, 18, F[4], 0.5);+ p.glow(x - cx * 7, y - cy * 7, 6, F[7], 0.5);+ }+ // the hit's flash: a white ball for two frames and a ring of flame+ const k = t - FLY;+ if (k >= 0 && k < 0.07) {+ const r = 14 * (0.8 + 0.2 * (1 - k / 0.07));+ p.circle(0, -6, r + 1.2, F[3]);+ p.circle(0, -6, r, k < 0.035 ? F[7] : F[6]);+ p.circle(0, -6, r * 0.6, k < 0.035 ? WHITE : F[7]);+ }+ if (k >= 0 && k < 0.3) {+ const rr = 8 + 30 * (1 - Math.pow(1 - k / 0.3, 3));+ p.ring(0, -6, rr, Math.max(1, 2.5 * (1 - k / 0.3) + 0.4), F[5], (v, ang) => (-6 + Math.sin(ang) * rr > 0 ? 0 : Math.min(1, (1 - k / 0.3) * 1.6)));+ }+ lights.draw(p);+ },+ };}diff --git a/src/fx/projectiles/laser-bolt.js b/src/fx/projectiles/laser-bolt.jsindex c6c0cfa..a503d9e 100644--- a/src/fx/projectiles/laser-bolt.js+++ b/src/fx/projectiles/laser-bolt.js@@ -1,37 +1,57 @@-import { ramp, at, fract, cycle, TAU, WHITE } from "../../core/index.js";+// The banded body, travelling pulses and spiralling sparks follow Sprite Fusion's open-source energy beam+// (https://www.spritefusion.com/pixel-art-vfx/energy), MIT License, Copyright (c) 2026 Hugo Duprez.+import { fit, rand, sparkle, TAU, WHITE } from "../../core/index.js";+import { beat } from "./_lib.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,+ desc: "A red laser bolt: a white-hot core in a rounded head, red bands tapering back, pulses racing down it, a tail that shimmers apart into wavering dashes.",+ tags: ["projectile", "laser", "energy", "sci-fi", "directional", "loop"],+ size: [128, 32],+ origin: [108, 16],+ duration: 0.5,loop: true,fps: 30,- bg: "dark",- options: { palette: ["#1e0408", "#4a0a12", "#8e1020", "#d81e2c", "#ff4a48", "#ff9e8c", "#ffe4dc", "#ffffff"], length: 16, seed: 2 },+ bg: "sky",+ options: { palette: ["#2a0610", "#5c0d1c", "#9a1428", "#d8243a", "#ff4d5e", "#ff8a94", "#ffd0d4", "#ffffff"], length: 40, 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));+ const C = fit(o.palette, 8), L = o.length, S = o.seed, D = meta.duration, ph = t / D, fr = Math.floor(t * 30 + 1e-6);+ const left = -meta.origin[0] + 2;++ // the shimmering tail: dashes shed off the bolt's end, wavering, flickering and cooling as they fall behind+ beat(t, D, 14, S, (r) => r.range(0.18, 0.3), (age, life, r) => {+ const k = age / life, x0 = -L * 0.8 - age * r.range(150, 230), len = r.range(3, 7) * (1 - k * 0.5), y = 0.5 + Math.sin(x0 * 0.25 + ph * TAU * 2) * (0.5 + k * 1.5) + r.range(-0.6, 0.6) * k;+ if (x0 - len < left || rand(fr, r.int(0, 999)) < k * 0.5) return;+ p.line(x0, y, x0 - len, y, k < 0.3 ? C[5] : k < 0.6 ? C[4] : C[3]);+ if (k < 0.4) p.glow(x0 - len / 2, y, 4, C[4], 0.3 * (1 - k));});- // 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));++ // the body: bands round a white core, thickest just behind the rounded head and tapering to a thread, a+ // pulse running back down it every so often; the edge breaks up a little as the light shimmers+ p.shade(-L - 1, -5, 4, 6, (x, y) => {+ const d = -x + 3, u = d / (L + 3);+ if (u < 0 || u > 1) return;+ const head = d < 3 ? Math.sqrt(Math.max(0, 1 - ((3 - d) / 3) ** 2)) : 1;+ const w = (3.4 * Math.pow(1 - u, 0.9) + 0.5) * head * (1 + 0.08 * Math.sin(d * 0.9 - ph * TAU * 4)), v = Math.abs(y - 0.5) / w;+ if (v > 1.2) return;+ if (v > 1 && (u > 0.5 || rand(Math.floor(x), fr) > 0.6)) return;+ const pulse = ((d * 0.05 - ph * 3) % 1 + 1) % 1 < 0.12 ? 1 : 0;+ const lvl = v < 0.22 ? (u < 0.6 ? 7 : 6) : v < 0.45 ? 6 - (u > 0.5 ? 1 : 0) : v < 0.72 ? 4 : v <= 1 ? 3 : 2;+ return C[Math.min(7, lvl + (v < 0.72 ? pulse : 0))];});- 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);+ // sparks spiralling round the core, a bright one on the near side and a dim one behind+ for (const s of [0, Math.PI]) {+ for (let d = 2; d < L * 0.7; d += 1) {+ const a = d * 0.45 - ph * TAU * 3 + s, y = 0.5 + Math.sin(a) * (2.2 * (1 - d / L) + 0.6);+ if (Math.cos(a) > 0.3) p.dot(-d, y, Math.cos(a) > 0.8 ? WHITE : C[6]);+ }+ }+ // the head's glint, flickering, and the light+ const g = 0.75 + 0.25 * Math.sin(ph * TAU * 2);+ sparkle(p, 1, 0.5, 3 + Math.round(g * 2), C[6], C[4], 0.5);+ p.glowLine(1, 0.5, -L, 0.5, 9, C[3], 0.4);+ p.glow(-2, 0.5, 20, C[3], 0.5 * g);+ p.glow(1, 0.5, 6, WHITE, 0.25);}diff --git a/src/fx/projectiles/magic-missile.js b/src/fx/projectiles/magic-missile.jsindex 90127f6..f82a9e8 100644--- a/src/fx/projectiles/magic-missile.js+++ b/src/fx/projectiles/magic-missile.js@@ -1,76 +1,105 @@-import { PAL, ramp, at, burst, stream, fly, seg, ease, clamp, TAU, WHITE } from "../../core/index.js";-import { onCanvas } from "./_lib.js";+// The gathering motes, star particles and burst flare follow Sprite Fusion's open-source energy bolt+// (https://www.spritefusion.com/pixel-art-vfx/energy), MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Lights, P, Rng, fit, flare, sparkle, clamp, smooth, ease, TAU, WHITE } from "../../core/index.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,+ desc: "Motes gather into an arcane orb at a hand `height` px above the floor (the origin); it weaves to its target trailing a twisting ribbon and bursts into a star of light.",+ tags: ["projectile", "magic", "arcane", "missile", "spell", "directional", "one-shot"],+ size: [208, 112],+ origin: [24, 104],+ duration: 1.9,loop: false,fps: 30,- bg: "dark",- options: { palette: PAL.arcane, distance: 88, seed: 9 },+ bg: "ground",+ options: { palette: ["#140a26", "#2b1252", "#481c88", "#6b2cc0", "#9a48ec", "#c684ff", "#ecc8ff", "#ffffff"], height: 26, reach: 112, seed: 6 },};-const HIT = 0.55;+const CHARGE = 0.2, FLY = 0.62;-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);+export function create(o) {+ const C = fit(o.palette, 8), H = o.height, X1 = o.reach, R = new Rng(o.seed);+ const ps = new Particles({ rng: R, ground: () => 0, sparks: [WHITE, C[6], C[5], C[4]] }), lights = new Lights();+ // the path: out of the hand, weaving up and down twice, homing in on the target at the same height+ const pos = (u) => [X1 * ease.inOutSine(u) + Math.sin(u * Math.PI) * 6, -H + Math.sin(u * TAU * 1.5) * 9 * Math.sin(u * Math.PI)];+ let t = 0, burst = false;+ const trail = [];+ return {+ update(dt) {+ t += dt;+ if (t < CHARGE) {+ // motes spiral in to the hand+ if (R.chance(0.8)) {+ const a = R.range(0, TAU), d = R.range(12, 26), sp = d / 0.14;+ ps.spawn(P.MOTE, Math.cos(a) * d, -H + Math.sin(a) * d, -Math.cos(a) * sp - Math.sin(a) * sp * 0.5, -Math.sin(a) * sp + Math.cos(a) * sp * 0.5, 0.14, R.pick([C[5], C[6], WHITE]), 0.8);+ }+ } else if (t < CHARGE + FLY) {+ const u = (t - CHARGE) / FLY, [x, y] = pos(u);+ trail.push({ x, y, t });+ if (R.chance(0.6)) ps.spawn(P.MOTE, x, y, R.range(-50, 50), R.range(-50, 50), R.range(0.2, 0.4), R.pick([C[4], C[5], C[6]]), 0.7);+ if (R.chance(0.25)) ps.spawn(P.STAR, x + R.range(-3, 3), y + R.range(-3, 3), R.range(-10, 10), R.range(-10, 10), R.range(0.25, 0.5), C[6], R.range(0.6, 1.6));+ } else if (!burst) {+ burst = true;+ const y = -H;+ lights.add(X1, y, 52, C[4], 0.95, 0.55);+ lights.add(X1, y, 22, WHITE, 0.8, 0.12);+ for (let i = 0; i < 26; i++) {+ const a = R.range(0, TAU), sp = R.range(60, 150) * (1 - 0.65 * Math.max(0, Math.sin(a)));+ ps.spawn(i % 3 ? P.MOTE : P.STAR, X1, y, Math.cos(a) * sp, Math.sin(a) * sp, R.range(0.25, 0.45), R.pick([C[5], C[6], WHITE]), R.range(0.8, 1.8));+ }+ for (let i = 0; i < 18; i++) {+ const a = R.range(0, TAU), sp = R.range(110, 240) * (1 - 0.5 * Math.max(0, Math.sin(a)));+ ps.spawn(P.SPARK, X1, y, Math.cos(a) * sp, Math.sin(a) * sp - 30, R.range(0.12, 0.3));+ }+ for (let i = 0; i < 14; i++) {+ const a = R.range(0, TAU), d = R.range(4, 22);+ ps.spawn(P.STAR, X1 + Math.cos(a) * d, y + Math.sin(a) * d * 0.8, 0, -R.range(2, 8), R.range(0.5, 1.1), R.pick([C[6], WHITE, C[5]]), R.range(0.8, 2.6), R.range(0.05, 0.45));+ }+ }+ ps.update(dt);+ lights.update(dt);+ },+ draw(p) {+ // the ribbon: a strip that twists as it trails the orb, its bright face and its dark back taking turns,+ // fading from the tail+ const now = t, keep = trail.filter((q) => now - q.t < 0.32);+ for (let i = 1; i < keep.length; i++) {+ const a = keep[i - 1], b = keep[i], dx = b.x - a.x, dy = b.y - a.y, l = Math.hypot(dx, dy) || 1, nx = -dy / l, ny = dx / l;+ for (let f = 0; f < 1; f += 0.5 / l) {+ const tt = a.t + (b.t - a.t) * f, k = 1 - (now - tt) / 0.32, tw = Math.sin(tt * 26), w = 3.2 * k * Math.abs(tw) + 0.4, face = tw > 0;+ const x = a.x + dx * f, y = a.y + dy * f;+ for (let s = -w; s <= w; s += 0.5) {+ const edge = Math.abs(s) > w - 0.8, c = face ? (edge ? C[6] : k > 0.6 ? C[5] : C[4]) : edge ? C[4] : C[2];+ p.dot(x + nx * s, y + ny * s, c, k > 0.35 ? 1 : k / 0.35);+ }+ }+ if (i % 3 === 0) p.glow(b.x, b.y, 6, C[4], 0.25 * (1 - (now - b.t) / 0.32));+ }+ ps.draw(p);+ // the orb: gathering at the hand, then flying, its heart white, a ring of light turning round it+ if (t < CHARGE + FLY) {+ const k = t < CHARGE ? t / CHARGE : 1, [x, y] = t < CHARGE ? [0, -H] : pos((t - CHARGE) / FLY), r = 1 + 3 * ease.outBack(k);+ p.circle(x, y, r + 1.4, C[3]);+ p.circle(x, y, r + 0.4, C[5]);+ p.circle(x - 0.4, y - 0.4, r * 0.55, WHITE);+ for (let i = 0; i < 3; i++) {+ const a = t * 14 + (i * TAU) / 3;+ p.px(x + Math.cos(a) * (r + 3), y + Math.sin(a) * (r + 3) * 0.6, i ? C[6] : WHITE);+ }+ p.glow(x, y, 20, C[4], 0.65 * k);+ p.glow(x, y, 7, C[6], 0.5 * k);+ }+ // the burst: a star flare and a ring that open out and fade+ const q = t - CHARGE - FLY;+ if (q >= 0 && q < 0.5) {+ const e = q / 0.5;+ if (e < 0.5) flare(p, X1, -H, 26 * Math.pow(1 - e * 2, 1.2) + 2, 1 - e * 2, C);+ if (e < 0.12) p.circle(X1, -H, 6 * (1 - e / 0.12) + 1, WHITE);+ p.ring(X1, -H, 4 + 20 * ease.outCubic(e), Math.max(1, 2.5 * (1 - e)), e < 0.3 ? C[6] : C[5], Math.min(1, (1 - e) * 1.5));+ if (e < 0.4) sparkle(p, X1, -H, 7 * (1 - e / 0.4), C[6], C[4], 0.6 * (1 - e / 0.4));+ }+ lights.draw(p);+ void clamp, smooth;+ },+ };}diff --git a/src/fx/projectiles/muzzle-pistol.js b/src/fx/projectiles/muzzle-pistol.jsindex 9d015a2..44e57bc 100644--- a/src/fx/projectiles/muzzle-pistol.js+++ b/src/fx/projectiles/muzzle-pistol.js@@ -1,53 +1,75 @@-import { PAL, RAMP, ramp, at, rng, burst, fly, seg, ease, WHITE } from "../../core/index.js";-import { smoke, muzzleFlash } from "./_lib.js";+// The flash lobes, spark, smoke and casing recipes are adapted from Sprite Fusion's open-source+// muzzle-flash (https://www.spritefusion.com/pixel-art-vfx/muzzle-flash), MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, P, Rng, rng, fit, mix, WHITE } from "../../core/index.js";+import { flashShape, flash, cloud, Smoke, casing, drawCasing } 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,+ name: "Pistol shot",+ desc: "One pistol shot from a muzzle `height` px above the floor (the origin): a spiky white-cored flash, sparks, a curl of smoke hooking up and back, a casing that bounces and settles.",+ tags: ["projectile", "muzzle", "gun", "pistol", "flash", "smoke", "casing", "directional", "one-shot"],+ size: [96, 72],+ origin: [44, 66],+ duration: 1.8,loop: false,fps: 30,- bg: "dark",- options: { palette: PAL.fire, size: 1, seed: 4 },+ bg: "ground",+ options: {+ palette: ["#4a1712", "#8a1f17", "#c9281f", "#f2561d", "#ff8a2a", "#ffc23d", "#ffe26b", "#fff3a6", "#ffffff"],+ brass: ["#4a2e10", "#8c5c1c", "#d9a441", "#ffe39a"],+ smoke: ["#26222e", "#3b3644", "#544e5e", "#6f6979", "#8c8596", "#aca5b5", "#cbc4d2"],+ height: 26,+ seed: 3,+ },};-const F = 1 / 30;+const F1 = 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));+export function create(o) {+ const F = fit(o.palette, 9), B = fit(o.brass, 4), SM = fit(o.smoke, 7), H = o.height, MY = -H, R = new Rng(o.seed);+ const ps = new Particles({ rng: R, ground: () => 0, sparks: [F[7], F[6], F[4], F[3]] }), smoke = new Smoke(R);+ // the flash's shape, fixed for this shot+ const shapeSeed = R.int(0, 1e6), tilt = R.range(-0.05, 0.05);+ // sparks spat forward, a few grains of unburnt powder that drop+ for (let i = 0; i < 6; i++) {+ const a = R.range(-0.3, 0.3), sp = R.range(180, 400);+ ps.spawn(P.SPARK, 3, MY, Math.cos(a) * sp, Math.sin(a) * sp, R.range(0.06, 0.16));}- // 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);+ for (let i = 0; i < 5; i++) {+ const a = R.range(-0.35, 0.25), sp = R.range(60, 160);+ ps.spawn(P.EMBER, 3, MY, Math.cos(a) * sp, Math.sin(a) * sp, R.range(0.25, 0.5), F[5]);+ }+ // a puff of gas forward, then a chain of wisps that push out, slow and curl up and back over the muzzle+ for (let i = 0; i < 3; i++) smoke.add({ x: 3, y: MY, vx: R.range(70, 120), vy: R.range(-12, 6), r0: 1.6, r1: R.range(4.5, 6), life: R.range(0.8, 1.05), a: 0.55, drag: 3.5, rise: 10, warm: 0.9, delay: i * 0.012 });+ for (let i = 0; i < 14; i++) {+ const k = i / 13;+ smoke.add({ x: 2, y: MY, vx: 115 - 75 * k + R.range(-12, 12), vy: -6 - 10 * k + R.range(-5, 5), r0: 1.4, r1: (3.6 + k * 2.6) * R.range(0.75, 1.25), life: 1.15 + k * 0.3, a: 0.62, b: R.range(0.85, 1), drag: 2.2, rise: 6, curl: -4.4 + k * 1.8 + R.range(-0.5, 0.5), grow: 1.6, warm: 0.7, delay: 0.02 + i * 0.022 });+ }+ smoke.add({ x: -7, y: MY - 2, vx: -6, vy: -18, r0: 1.2, r1: 4, life: 1.05, a: 0.4, rise: 8, delay: 0.03 });+ const shell = { vx: -R.range(25, 45), vy: -R.range(95, 130), va: R.sign() * R.range(22, 32), a0: R.range(0, 6.28) };+ let t = 0;+ return {+ update(dt) {+ t += dt;+ ps.update(dt);+ smoke.update(dt);+ },+ draw(p) {+ const pop = Math.exp(-(t + 0.008) / 0.035);+ const list = smoke.puffs();+ for (const q of list) q.w *= 0.4 + pop;+ cloud(p, list, SM, [SM[0], mix(F[1], SM[1], 0.5), mix(F[2], SM[2], 0.4), F[3], F[4], F[5], F[7]], { dens: 1.5, max: 0.8, lit: 1.4 });+ // the casing: out of the port, up and back, tumbling, a bounce or two, then it lies there and fades+ if (t < meta.duration) drawCasing(p, casing(-7, MY - 1, shell.vx, shell.vy, shell.va, t, 850, -0.5, 0.42, shell.a0), B, Math.min(1, (meta.duration - 0.05 - t) / 0.3));+ // the flash: the hero frame with a white core, then one cooler, smaller frame+ if (t < 2 * F1) {+ const f = t < F1 ? 1 : 2, L = flashShape(rng(shapeSeed), f, { size: 1.15, spike: [15, 22], diag: [7, 12], cross: [4.5, 8], back: [3, 5.5] });+ flash(p, 0, MY, tilt, L, f === 1 ? [WHITE, F[7], F[6], F[3]] : [F[7], F[6], F[4], F[2]], f + o.seed);+ }+ ps.draw(p);+ // light: the pop, its warm pool, a touch on the floor below+ p.glow(4, MY, 30, F[4], 0.85 * pop);+ p.glow(2, MY, 8, WHITE, 0.5 * pop);+ p.glow(4, 0, 16, F[4], 0.2 * pop);+ },+ };}diff --git a/src/fx/projectiles/muzzle-shotgun.js b/src/fx/projectiles/muzzle-shotgun.jsindex d8e5036..248ae51 100644--- a/src/fx/projectiles/muzzle-shotgun.js+++ b/src/fx/projectiles/muzzle-shotgun.js@@ -1,84 +1,106 @@-import { PAL, RAMP, ramp, at, rng, burst, fly, seg, ease, lerp, TAU, WHITE } from "../../core/index.js";-import { smoke, onCanvas } from "./_lib.js";+// The flash lobes, spark, smoke and casing recipes are adapted from Sprite Fusion's open-source+// muzzle-flash (https://www.spritefusion.com/pixel-art-vfx/muzzle-flash), MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, P, Rng, fit, mix, clamp, WHITE } from "../../core/index.js";+import { flash, cloud, Smoke, casing } 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,+ desc: "A shotgun blast from a muzzle `height` px above the floor (the origin): a wide ragged fan of flame, pellet streaks, a heavy rolling smoke cloud, a red shell kicked out on the pump.",+ tags: ["projectile", "muzzle", "gun", "shotgun", "flash", "smoke", "casing", "directional", "one-shot"],+ size: [160, 88],+ origin: [44, 82],+ duration: 3.2,loop: false,fps: 30,- bg: "dark",- options: { palette: PAL.fire, spread: 0.36, pellets: 9, seed: 5 },+ bg: "ground",+ options: {+ palette: ["#4a1712", "#8a1f17", "#c9281f", "#f2561d", "#ff8a2a", "#ffc23d", "#ffe26b", "#fff3a6", "#ffffff"],+ smoke: ["#221e2a", "#36313f", "#4e4858", "#6a6474", "#888192", "#a8a1b1", "#c8c1cf"],+ shell: ["#4a0f14", "#9a1e22", "#d8423a", "#8c5c1c", "#e9b54a"],+ height: 26,+ seed: 5,+ },};-const F = 1 / 30;+const F1 = 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]);+// the fan: a fat fireball at the muzzle and a spray of ragged tongues across the cone, each its own length+function fan(R, f) {+ const k = f === 1 ? 1 : f === 2 ? 0.82 : 0.55, w = f === 1 ? 1 : 1.25;+ const L = [{ off: 0.5, a: 0, len: 11 * k, wid: 3.6 * w, core: 0.5 }];+ for (let i = 0; i < 9; i++) {+ const u = i / 8 - 0.5, a = u * 1.15 + R[i * 3] * 0.12, len = (17 + 11 * (1 - Math.abs(u) * 1.4) + R[i * 3 + 1] * 7) * k;+ L.push({ off: 2, a, len, wid: (1.7 + R[i * 3 + 2]) * w, core: f === 1 ? 0.32 : 0 });}- return pts;+ if (f === 1) for (const s of [-1, 1]) L.push({ off: 1, a: s * (1.6 + R[27 + (s > 0)] * 0.4), len: 5 + R[29] * 3, wid: 1.2, core: 0 });+ return L;}-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));+export function create(o) {+ const F = fit(o.palette, 9), SM = fit(o.smoke, 7), SH = fit(o.shell, 5), H = o.height, MY = -H, R = new Rng(o.seed);+ const ps = new Particles({ rng: R, ground: () => 0, sparks: [F[7], F[6], F[4], F[3]] }), smoke = new Smoke(R);+ const right = meta.size[0] - meta.origin[0] - 2, jit = Array.from({ length: 32 }, () => R.next());+ // pellets: a tight spray, gone off the canvas in a few frames, each dragging a hot streak+ const pellets = Array.from({ length: 10 }, () => ({ a: R.range(-0.13, 0.13), v: R.range(900, 1150), d0: R.range(0, 4) }));+ // sparks and burning wad, flung wide+ for (let i = 0; i < 16; i++) {+ const a = R.range(-0.55, 0.55), sp = R.range(180, 460);+ ps.spawn(P.SPARK, 4, MY, Math.cos(a) * sp, Math.sin(a) * sp - 20, R.range(0.08, 0.3));}- // 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);+ for (let i = 0; i < 7; i++) {+ const a = R.range(-0.5, 0.3), sp = R.range(70, 200);+ ps.spawn(P.EMBER, 4, MY, Math.cos(a) * sp, Math.sin(a) * sp, R.range(0.4, 0.9), F[5]);+ }+ // the smoke: a heavy shove of gas forward that slows, rolls, swells and lifts; the first of it lit by the blast+ for (let i = 0; i < 26; i++) {+ const a = R.range(-0.45, 0.35), sp = R.range(60, 230) * (i < 8 ? 1.15 : 0.8);+ smoke.add({ x: 4 + R.range(0, 4), y: MY + R.range(-1.5, 1.5), vx: Math.cos(a) * sp, vy: Math.sin(a) * sp, r0: R.range(2.5, 3.5), r1: R.range(7, 12.5), life: R.range(2.1, 2.9), a: R.range(0.55, 0.72), b: R.range(0.9, 1), drag: R.range(2.6, 3.6), rise: R.range(9, 15), grow: R.range(1.8, 2.8), warm: 1, delay: R.range(0, 0.04) });+ }+ for (let i = 0; i < 6; i++) smoke.add({ x: 2, y: MY, vx: R.range(15, 50), vy: -R.range(10, 25), r0: 1.5, r1: R.range(4, 6), life: R.range(1.8, 2.4), a: 0.5, b: 1, drag: 2, rise: 10, curl: -R.range(1.5, 3), warm: 0.6, delay: 0.08 + i * 0.05 });+ // the pump throws the spent shell a beat later+ const shell = { t0: 0.42, vx: -R.range(30, 55), vy: -R.range(110, 150), va: R.sign() * R.range(16, 24), a0: R.range(0, 6.28) };+ let t = 0;+ return {+ update(dt) {+ t += dt;+ ps.update(dt);+ smoke.update(dt);+ },+ draw(p) {+ const pop = Math.exp(-(t + 0.008) / 0.05), list = smoke.puffs();+ for (const q of list) q.w *= 0.25 + pop * 1.2;+ cloud(p, list, SM, [SM[0], mix(F[1], SM[1], 0.5), mix(F[2], SM[2], 0.4), F[3], F[4], F[5], F[7]], { dens: 1.4, max: 0.86, lit: 1.4 });++ // the shell: red hull, brass head, tumbling up and back, bouncing, lying a moment+ if (t > shell.t0 && t < meta.duration - 0.05) {+ const k = casing(-9, MY, shell.vx, shell.vy, shell.va, t - shell.t0, 850, -1, 0.35, shell.a0), ca = Math.cos(k.a), sa = Math.sin(k.a), fade = clamp((meta.duration - 0.05 - t) / 0.3);+ for (let d = -1.5; d <= 1.5; d += 0.5) p.dot(k.x + ca * d, k.y + sa * d - 0.5, d > 0.8 ? (d > 1.2 ? SH[4] : SH[3]) : d > -0.6 ? SH[2] : SH[1], fade);+ for (let d = -1; d <= 1; d += 0.5) p.dot(k.x + ca * d - sa, k.y + sa * d + ca - 0.5, d > 0.6 ? SH[3] : SH[0], fade);+ if (k.hit >= 0 && k.hit < 0.07) p.glow(k.x, k.y, 5, SH[4], 0.5 * (1 - k.hit / 0.07));+ }++ // the flash: a white-hot hero frame, then the fan cooling and spreading as the gas balloons+ if (t < 3 * F1) {+ const f = t < F1 ? 1 : t < 2 * F1 ? 2 : 3;+ flash(p, 0, MY, 0, fan(jit, f), f === 1 ? [WHITE, F[7], F[6], F[3]] : f === 2 ? [F[7], F[6], F[4], F[2]] : [F[5], F[4], F[3], F[1]], f + 9);+ }+ // the pellets: hot heads with tails that cool to orange, clipped at the canvas edge+ if (t < 0.2)+ for (const q of pellets) {+ const head = 6 + q.d0 + q.v * t, tail = Math.max(4, head - 26), ca = Math.cos(q.a), sa = Math.sin(q.a);+ for (let d = tail; d <= head; d += 0.5) {+ const x = ca * d;+ if (x > right) break;+ const u = (d - tail) / Math.max(1, head - tail);+ p.dot(x, MY + sa * d, u > 0.85 ? WHITE : u > 0.5 ? F[6] : F[4], u > 0.3 ? 1 : u / 0.3);+ }+ if (ca * head < right) p.glow(ca * head, MY + sa * head, 4, F[6], 0.5);+ }+ ps.draw(p);+ // light: a big pop that floods the floor, a white heart+ p.glow(8, MY, 46, F[4], 0.95 * pop);+ p.glow(4, MY, 12, WHITE, 0.6 * pop);+ p.glow(10, 0, 30, F[4], 0.28 * pop);+ },+ };}diff --git a/src/fx/projectiles/muzzle-smg.js b/src/fx/projectiles/muzzle-smg.jsindex 12953b1..f0c6a56 100644--- a/src/fx/projectiles/muzzle-smg.js+++ b/src/fx/projectiles/muzzle-smg.js@@ -1,48 +1,91 @@-import { PAL, RAMP, ramp, at, rng, burst, cycle, fly, WHITE } from "../../core/index.js";-import { smoke, muzzleFlash } from "./_lib.js";+// The flash lobes, spark, smoke wisp and casing recipes are adapted from Sprite Fusion's open-source+// muzzle-flash (https://www.spritefusion.com/pixel-art-vfx/muzzle-flash), MIT License, Copyright (c) 2026 Hugo Duprez.+import { clamp, rand, rng, wrap, fit, fly, flyV, hex, mix, TAU, WHITE } from "../../core/index.js";+import { flashShape, flash, spark, cloud, casing, drawCasing } 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,+ desc: "Sustained fire at twelve rounds a second: each shot a different spiky flash with a white core, sparks, smoke wisps piling up and drifting, brass casings bouncing on the floor.",+ tags: ["projectile", "muzzle", "gun", "automatic", "flash", "smoke", "casing", "directional", "loop"],+ size: [112, 72],+ origin: [56, 66],+ duration: 1,loop: true,fps: 30,- bg: "dark",- options: { palette: PAL.volt, shots: 4, seed: 6 },+ bg: "ground",+ options: {+ palette: ["#4a1712", "#8a1f17", "#c9281f", "#f2561d", "#ff8a2a", "#ffc23d", "#ffe26b", "#fff3a6", "#ffffff"],+ brass: ["#4a2e10", "#8c5c1c", "#d9a441", "#ffe39a"],+ smoke: ["#26222e", "#3b3644", "#544e5e", "#6f6979", "#8c8596", "#aca5b5", "#cbc4d2"],+ height: 26,+ seed: 6,+ },};+const SHOTS = 12, F1 = 1 / 30;++// every live copy of every shot: fn(s, age) for shot s fired at s * D / SHOTS, while age < life+function shots(t, D, life, fn) {+ for (let s = 0; s < SHOTS; s++) for (let age = wrap(t - (s * D) / SHOTS + 1e-7, D); age < life; age += D) fn(s, age);+}+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 F = fit(o.palette, 9), B = fit(o.brass, 4), SM = fit(o.smoke, 7), S = o.seed, D = meta.duration, H = o.height;+ const MX = 0, MY = -H, SP = [F[7], F[6], F[4], F[3]], top = -meta.origin[1] + 1;+ // the latest shot's pop of light, for the smoke it lights up+ let pop = 0;+ shots(t, D, 0.2, (s, age) => (pop = Math.max(pop, Math.exp(-(age + 0.008) / 0.035))));++ // smoke: every shot leaves a few wisps that push forward, slow, swell and rise, piling up into a drifting hazeconst 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 });+ shots(t, D, 2.2, (s, age) => {+ for (let j = 0; j < 3; j++) {+ const r = rng(S, s, j, 3), life = r.range(1.5, 2.2), dl = j * 0.03;+ if (age < dl || age - dl >= life) continue;+ const a = age - dl, k = a / life, port = j === 2;+ // a push forward that dies fast, then the warm gas lifts it and the air drifts it back over the gun+ const vx = port ? r.range(-12, 6) : r.range(45, 100) * (1 - j * 0.4), vy = port ? -r.range(14, 26) : -r.range(4, 16);+ const x = (port ? -7 : MX + 3) + (vx * (1 - Math.exp(-3.2 * a))) / 3.2 - r.range(3, 7) * a * a + Math.sin(a * 2.1 + r.range(0, TAU)) * a * 2.5;+ const y = (port ? MY - 2 : MY) + (vy * (1 - Math.exp(-2.4 * a))) / 2.4 - 0.5 * r.range(9, 16) * a * a;+ const rad = (port ? 1 : 1.2) + r.range(2, 4.5) * (1 - Math.exp(-1.4 * a));+ if (y - rad < top + 1) continue;+ const edge = Math.min(1, (y - rad - top) / 12);+ puffs.push({ x, y, r: rad, a: Math.min(1, a * 10) * Math.pow(1 - k, 1.6) * (port ? 0.24 : 0.34) * edge, b: clamp(0.92 - k * 0.6), w: pop * Math.exp(-Math.hypot(x - MX, y - MY) / 9) });+ }+ });+ cloud(p, puffs, SM, [SM[0], mix(F[1], SM[1], 0.5), mix(F[2], SM[2], 0.4), F[3], F[4], F[5], F[7]], { dens: 1.4, max: 0.7, lit: 1.3 });++ // casings: thrown up and back out of the ejection port, tumbling, bouncing on the floor, then lying a moment+ shots(t, D, D, (s, age) => {+ const r = rng(S, s, 7), k = casing(-7, MY - 1, -r.range(18, 48), -r.range(85, 135), r.sign() * r.range(20, 32), age, 850, -0.5, 0.42, r.range(0, TAU));+ drawCasing(p, k, B, clamp((D - age) / 0.25));+ });++ // the flash: a hero frame with a white core, then a cooler, smaller one; every shot its own shape+ shots(t, D, 2 * F1, (s, age) => {+ const r = rng(S, s), f = age < F1 ? 1 : 2, tilt = r.range(-0.06, 0.06);+ const L = flashShape(r, f, { size: r.range(0.95, 1.2), spike: [12, 21], diag: [6, 11], cross: [4, 7.5], back: [2.5, 5] });+ const C = f === 1 ? [WHITE, F[7], F[6], F[3]] : [F[7], F[6], F[4], F[2]];+ flash(p, MX, MY, tilt, L, C, s * 7 + f);+ });++ // sparks and unburnt grains spat forward with each shot, dropping as they slow+ shots(t, D, 0.3, (s, age) => {+ for (let j = 0; j < 5; j++) {+ const r = rng(S, s, j, 11), life = r.range(0.05, 0.16) * (j > 2 ? 1.8 : 1);+ if (age >= life) continue;+ const a = r.range(-0.3, 0.3), sp = r.range(170, 380) * (j > 2 ? 0.5 : 1), [x, y] = fly(MX + 2, MY, Math.cos(a) * sp, Math.sin(a) * sp, age, 420, 2.2);+ const [vx, vy] = flyV(Math.cos(a) * sp, Math.sin(a) * sp, age, 420, 2.2);+ if (j > 2) p.px(x, y, age / life < 0.5 ? F[6] : F[4]);+ else spark(p, x, y, vx, vy, 1 - age / life, SP, 0.45, 0.011);+ }+ });++ // light: a hot pop at the muzzle on every shot, the floor and smoke catching it+ shots(t, D, 0.15, (s, age) => {+ const k = Math.exp(-(age + 0.008) / 0.03);+ p.glow(MX + 4, MY, 26, F[4], 0.8 * k);+ p.glow(MX + 2, MY, 7, WHITE, 0.45 * k);+ p.glow(MX + 2, 0, 12, F[4], 0.16 * k);});- 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.jsindex bde385b..2e1a0f5 100644--- a/src/fx/projectiles/plasma-shot.js+++ b/src/fx/projectiles/plasma-shot.js@@ -1,53 +1,110 @@-import { ramp, at, cycle, TAU, WHITE } from "../../core/index.js";+// The layered head, rim rays and trail light follow Sprite Fusion's open-source energy bolt and orb+// (https://www.spritefusion.com/pixel-art-vfx/energy), MIT License, Copyright (c) 2026 Hugo Duprez.+import { rng, fit, cycle, TAU, WHITE } from "../../core/index.js";+import { beat, wake, spark } from "./_lib.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.",+ desc: "A glowing plasma blob: hot knots churning in its core, a corona crackling over its skin, its tail necking into droplets that tear off, cool and wink out behind.",tags: ["projectile", "plasma", "energy", "sci-fi", "directional", "loop"],- size: [52, 23],- origin: [42, 11],- duration: 0.6,+ size: [144, 60],+ origin: [108, 30],+ duration: 0.8,loop: true,fps: 30,- bg: "dark",- options: { palette: ["#04161a", "#073536", "#0b5e4e", "#119060", "#2ac46e", "#7cf07c", "#d4ffc0", "#ffffff"], size: 5, seed: 3 },+ bg: "sky",+ options: {+ palette: ["#061a1c", "#0b3b34", "#0f6a4a", "#18a05a", "#3fd46a", "#8cf57e", "#d6ffc4", "#ffffff"],+ size: 6,+ speed: 200,+ 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+ const C = fit(o.palette, 8), R = o.size, V = o.speed, S = o.seed, D = meta.duration, w = (TAU * t) / D;+ const fr = Math.floor(t * 30 + 1e-6), left = -meta.origin[0] + 2;++ // an ion streak left in the air behind it, rippling and cooling in steps+ const T0 = -R * 3.2, tail = (x) => Math.sin(x * 0.2 + w * 2) * (0.3 + ((T0 - x) / 44) * 1.8);+ for (let x = T0; x > T0 - 44; x -= 1) {+ const u = (T0 - x) / 44, y = tail(x);+ p.dot(x, y, u < 0.2 ? C[6] : u < 0.45 ? C[5] : C[4], u < 0.55 ? 1 : (1 - u) / 0.45);+ if (u < 0.3) p.px(x, y + 1, u < 0.15 ? C[5] : C[4]);+ }++ // the blob as a field of balls: a body, three hot knots churning round inside it at their own speeds, a wagging+ // tail, and droplets that cling to the tail's end until the air tears them off (the skin necks as they part)+ const balls = [{ x: 0, y: 0, r: R, h: 1, core: 0.8 }];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]);+ const a = w * [2, -3, 5][i] + (i * TAU) / 3, d = R * (0.5 + 0.1 * Math.sin(w * 3 + i * 2));+ balls.push({ x: Math.cos(a) * d - 0.4, y: Math.sin(a) * d * 0.8, r: R * 0.32, h: 1, core: 1 });}- // 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]);+ // the tail: thick and hot where it leaves the body, tapering and cooling to a point, its axis still glowing+ for (let i = 1; i <= 6; i++) {+ const x = -R * (0.5 + i * 0.42), wag = Math.sin(w * 2 - i * 0.9) * (0.3 + i * 0.28), r = R * (0.62 - i * 0.08);+ balls.push({ x, y: wag, r, h: 0.96 - i * 0.05, core: Math.sqrt((5.2 - i * 0.65) * 0.3) / r });+ }+ const drops = [];+ cycle(t, D, 11, S, (r) => r.range(0.34, 0.5), (age, life, r) => {+ const k = age / life, pull = r.range(450, 800), x = -R * 2.9 - 0.5 * pull * age * age - r.range(0, 16) * age;+ const y = Math.sin(w * 2 - 5.4 + age * 12) * 2 + r.range(-30, 30) * age * (0.4 + age);+ const rad = R * r.range(0.3, 0.48) * (1 - k * 0.6);+ drops.push({ x, y, r: rad, h: 0.97 * (1 - k * 0.75), core: Math.sqrt(Math.max(0, 1 - k * 1.3) * 7 * 0.3) / rad, k });});- 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);+ const all = balls.concat(drops);+ // the skin comes from a compact field (so the tail tapers and droplets neck cleanly as they part); the hot+ // bands inside come only from the body and its churning knots: a deep rim, the body, a bright inner, a pale+ // core, white where the knots run hottest+ p.shade(-R * 2.6 - 60, -R * 2 - 8, R * 1.6, R * 2 + 8, (x, y) => {+ let f = 0, heat = 0, hh = 0;+ for (const b of all) {+ const dx = x - b.x, dy = y - b.y, d2 = dx * dx + dy * dy, q = d2 / (4 * b.r * b.r);+ if (q < 1) {+ const c = ((1 - q) * (1 - q)) / 0.5625;+ f += c;+ heat += c * b.h;+ }+ if (b.core) hh += (b.core * b.core * b.r * b.r) / (d2 + 0.3);}- 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);+ const lvl = hh > 10 ? 7 : hh > 4.6 ? 6 : hh > 2.2 ? 5 : f > 1.4 ? 4 : 3, cap = Math.round(2 + (heat / f) * 5.4);+ return C[Math.max(2, Math.min(x > R * 0.3 && lvl < 5 ? lvl + 1 : lvl, cap))];});- // 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));++ // the corona: jagged arcs leaping off the skin and back, and rays flickering round the rim, new every frame+ for (let j = 0; j < 3; j++) {+ const g = rng(fr, j, S), a0 = g.range(-2.3, 2.3), span = g.range(0.45, 0.9) * g.sign(), n = 6, hgt = g.range(1.5, 3.5);+ const pts = [];+ for (let i = 0; i <= n; i++) {+ const a = a0 + (span * i) / n, rr = R + 0.6 + hgt * Math.sin((Math.PI * i) / n) + (i % n ? g.range(-0.5, 0.5) : 0);+ pts.push([Math.cos(a) * rr - 0.4, Math.sin(a) * rr * 0.92]);+ }+ p.polyline(pts, j ? C[5] : C[6]);+ p.px(pts[3][0], pts[3][1], WHITE);+ p.glow(pts[3][0], pts[3][1], 6, C[5], 0.4);+ }+ for (let j = 0; j < 4; j++) {+ const g = rng(fr, j + 9, S), a = g.range(-2.2, 2.2), l = g.range(1.5, 4), r0 = R + 1;+ const x0 = Math.cos(a) * r0 - 0.4, y0 = Math.sin(a) * r0 * 0.92;+ p.line(x0, y0, x0 + Math.cos(a) * l, y0 + Math.sin(a) * l, j % 2 ? C[4] : C[5]);+ }+ // motes flung off the corona, streaking back+ const SP = [WHITE, C[6], C[5], C[3]];+ beat(t, D, 14, S + 5, (r) => r.range(0.12, 0.3), (age, life, r) => {+ const a = r.range(-2.4, 2.4), sp = r.range(60, 130), [x, y, vx, vy] = wake(Math.cos(a) * (R + 1), Math.sin(a) * (R + 1), Math.cos(a) * sp, Math.sin(a) * sp, age, V * 0.7, 4, 0);+ if (x > left + 4 && Math.abs(y) < 26) spark(p, x, y, vx, vy, 1 - age / life, SP, 0.4, 0.015, 6);});- 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);++ // light: a big soft pool, a hot heart that pulses with the churn, a point on every droplet+ const pulse = 0.85 + 0.15 * Math.sin(w * 4);+ p.glow(-2, 0, 34, C[3], 0.8 * pulse);+ p.glow(0, 0, 16, C[4], 0.35 * pulse);+ p.glow(1, 0, 7, C[6], 0.3 * pulse);+ p.glowLine(-R, 0, -R * 4.6, 0, 7, C[3], 0.3);+ for (const d of drops) {+ if (d.x < left + 4) continue;+ if (d.k < 0.6 && d.x < -R * 3.5) p.px(d.x, d.y, d.k < 0.3 ? C[7] : C[6]);+ p.glow(d.x, d.y, 3 + d.r * 2, C[2], 0.6 * (1 - d.k));+ }}diff --git a/src/fx/projectiles/rocket.js b/src/fx/projectiles/rocket.jsindex 05a3ddd..f932d47 100644--- a/src/fx/projectiles/rocket.js+++ b/src/fx/projectiles/rocket.js@@ -1,61 +1,134 @@-import { PAL, RAMP, ramp, at, cycle, rand, loopNoise, WHITE } from "../../core/index.js";-import { smoke, beat, onCanvas, steps } from "./_lib.js";+// The spark and fire-ball recipes are adapted from Sprite Fusion's open-source explosion+// (https://www.spritefusion.com/pixel-art-vfx/explosion), MIT License, Copyright (c) 2026 Hugo Duprez.+import { clamp, smooth, rand, mix, fit, TAU, WHITE, hex } from "../../core/index.js";+import { beat, wake, cloud, spark, pixelShape } 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,+ desc: "A steel rocket roars along: a flickering jet with shock diamonds and a white-hot nozzle, a thick billowing smoke trail lit by the flame, sparks shed behind.",+ tags: ["projectile", "rocket", "missile", "smoke", "fire", "directional", "loop"],+ size: [288, 76],+ origin: [252, 42],+ duration: 1.2,loop: true,fps: 30,- bg: "dark",- options: { palette: PAL.fire, seed: 7 },+ bg: "sky",+ options: {+ palette: ["#4a1712", "#8a1f17", "#c9281f", "#f2561d", "#ff8a2a", "#ffc23d", "#ffe26b", "#fff3a6", "#ffffff"],+ metal: ["#0f0d16", "#25243a", "#3e4058", "#61667f", "#8e97b0", "#c4cce0", "#f2f6ff"],+ paint: ["#3a0d14", "#7c1a22", "#bd2f2c", "#ec5a45", "#ff9b7e"],+ smoke: ["#26222e", "#3d3846", "#5a5463", "#7e7887", "#a7a1ad", "#d0cad2", "#f1ecee"],+ speed: 120,+ seed: 5,+ },};-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" };+const OUTLINE = hex("#100d17");+const NOZZLE = -14; // the bell's exit: the jet starts here+const J0 = 22; // the jet's mean length++// the rocket: a steel body lit from above with a specular line, a painted ogive nose and band, swept fins with+// lit leading edges, a dark bell with a glowing lip+const SHIP = pixelShape(-15, -9, 30, 19, (set) => {+ const body = { "-3": "4", "-2": "6", "-1": "5", 0: "4", 1: "3", 2: "2", 3: "1" };+ const seam = { "-3": "3", "-2": "4", "-1": "4", 0: "3", 1: "2", 2: "1", 3: "1" };+ const paint = { "-3": "d", "-2": "e", "-1": "e", 0: "d", 1: "c", 2: "b", 3: "a" };+ for (let y = -3; y <= 3; y++) for (let x = -11; x <= 5; x++) set(x, y, body[y]);+ for (let y = -3; y <= 3; y++) set(-3, y, seam[y]), set(-9, y, paint[y]), set(-8, y, paint[y]);+ const nose = { 6: 3, 7: 3, 8: 2, 9: 2, 10: 1, 11: 1, 12: 0, 13: 0 };+ for (const [xs, h] of Object.entries(nose)) for (let y = -h; y <= h; y++) set(+xs, y, paint[y]);+ set(7, -2, "w"), set(8, -2, "w"), set(9, -1, "e"), set(13, 0, "e");+ // fins, the top one in the light, the bottom one in shadow; each leading edge catches a highlight+ [[-13, -8], [-13, -9], [-13, -10], [-13, -11]].forEach(([a, b], i) => {+ for (let x = a; x <= b; x++) set(x, -4 - i, x === b ? "5" : i > 1 ? "4" : "3"), set(x, 4 + i, x === b ? "3" : i > 1 ? "1" : "2");+ });+ // the bell: a throat and a flared exit, its lip glowing+ for (let y = -2; y <= 2; y++) set(-12, y, y < 0 ? "3" : "2");+ for (let y = -3; y <= 3; y++) set(-13, y, y < -1 ? "2" : "1");+ set(-14, -3, "h"), set(-14, 3, "h");+ for (let y = -2; y <= 2; y++) set(-14, y, Math.abs(y) < 2 ? "x" : "h");+});++// the jet: a cone of flame out of the bell in clean bands (a red rim, orange, a gold core), white-hot at the+// nozzle, with a chain of shock diamonds down its middle; fr changes every frame so it flickers+function jet(p, F, x0, y0, J, wob, fr) {+ const dia = [0, 1, 2, 3].map((i) => 3.6 + i * 4.3 + (rand(fr, i, 41) - 0.5) * 0.7);+ p.shade(x0 - J - 2, y0 - 6, x0, y0 + 6, (x, y) => {+ const u = x0 - x;+ if (u < 0) return;+ const q = u / J;+ if (q > 1.05) return;+ const ady = Math.abs(y - y0), qq = Math.min(q, 1), w = (2.6 + 2.4 * Math.pow(qq, 0.7)) * (1 - qq * qq) * wob;+ const m = w - ady + (rand(Math.floor(x) * 7 + Math.floor(y) * 131, fr) - 0.5) * 0.9 * Math.min(1, 0.25 + q * 2);+ if (m < -0.5) return;+ if (m < 0.5) return F[q < 0.45 ? 3 : 2];+ for (let i = 0; i < dia.length; i++) {+ if (dia[i] > J * 0.72) break;+ const d = Math.abs(u - dia[i]) / (1.9 - i * 0.15) + ady / (1.7 - i * 0.25);+ if (d < 1) return d < 0.55 && i < 3 ? F[8] : F[7];+ }+ if (u < 1.6 && ady < 1.6) return F[8];+ const lvl = (1 - ady / Math.max(0.6, w)) * (1 - Math.pow(qq, 1.5));+ return lvl > 0.62 ? (u < 3 ? F[7] : F[5]) : lvl > 0.38 ? F[5] : lvl > 0.16 ? F[4] : F[3];+ });+}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 F = fit(o.palette, 9), M = fit(o.metal, 7), A = fit(o.paint, 5), SM = fit(o.smoke, 7), S = o.seed, D = meta.duration;+ const V = o.speed, fr = Math.floor(t * 30 + 1e-6);+ const bob = (tt) => Math.round(Math.sin((tt / D) * TAU) * 0.62), by = bob(t);+ const J = J0 * (0.84 + 0.32 * rand(fr, S, 1)), wob = 0.92 + 0.16 * rand(fr, S, 2), fl = J / J0;+ const left = -meta.origin[0] + 2, SP = [F[7], F[6], F[4], F[3]];++ // smoke: puffs leave the tail of the flame, stream back, swell and rise, lit by the fire while youngconst 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,- });+ beat(t, D, 66, S + 1, (r) => r.range(1.1, 1.45), (age, life, r) => {+ const [x, y] = wake(NOZZLE - J0 * r.range(0.62, 0.8), bob(t - age) + r.range(-1, 1), -r.range(75, 105), r.range(-20, 20), age, V, 3, 0);+ const k = age / life, rise = 0.5 * r.range(6, 16) * age * age, sway = Math.sin(age * 2.3 + r.range(0, TAU)) * age * 2;+ const rad = r.range(2.2, 3) + ((r.chance(0.25) ? r.range(14, 19) : r.range(8, 13)) - 2.6) * (1 - Math.exp(-2.2 * age));+ if (x - rad < left + 1) return;+ const a = Math.min(1, age * 16) * Math.pow(1 - k, 1.25) * 0.68 * smooth(left, left + 40, x - rad);+ list.push({ x, y: y - rise + sway, r: rad, a, b: clamp(0.95 - k * 0.75 + r.range(-0.08, 0.08)), w: Math.exp(-age * r.range(3.5, 6)) });});- 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);+ cloud(p, list, SM, [mix(F[0], SM[0], 0.5), mix(F[1], SM[1], 0.45), mix(F[2], SM[2], 0.35), F[3], F[4], F[6], F[7]], { dens: 1.3, lit: 1.5 });+ // the smoke right behind the flame glows from inside+ p.glow(NOZZLE - J0 - 6, by, 26, F[4], 0.24 * fl);++ // embers carried off in the smoke, cooling and winking out+ beat(t, D, 9, S + 4, (r) => r.range(0.6, 1.1), (age, life, r) => {+ const k = 1 - age / life;+ const [x, y] = wake(NOZZLE - J0 * 0.6, bob(t - age), -r.range(40, 120), r.range(-40, 30), age, V, 2.5, -8);+ if (x < left + 2 || (k < 0.3 && rand(fr, r.int(0, 999)) < 0.5)) return;+ const c = k > 0.6 ? F[6] : k > 0.3 ? F[4] : F[2];+ p.px(x, y, c);+ p.glow(x, y, 3, c, 0.35 * k);});- // 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));++ // tongues of flame torn off the tip of the jet, cooling and shrinking as they fall behind+ beat(t, D, 30, S + 3, (r) => r.range(0.08, 0.16), (age, life, r) => {+ const k = age / life, [x, y] = wake(NOZZLE - J0 * r.range(0.6, 0.9), bob(t - age) + r.range(-1.5, 1.5), -r.range(10, 50), r.range(-12, 12), age, V, 4, -30);+ const idx = 7 - Math.floor(Math.pow(k, 0.7) * 4), rad = r.range(1.2, 2.2) * (1 - k * 0.6);+ p.circle(x, y, rad, F[idx - 2]);+ p.circle(x + rad * 0.25, y - rad * 0.1, rad * 0.65, F[idx]);+ p.glow(x, y, rad * 2.4 + 2, F[idx], 0.2 * (1 - k));+ });++ // sparks shed behind, streaking back and dropping+ beat(t, D, 30, S + 2, (r) => r.range(0.18, 0.45), (age, life, r) => {+ const [x, y, vx, vy] = wake(NOZZLE - r.range(2, J0 * 0.7), bob(t - age) + r.range(-1.5, 1.5), -r.range(20, 190), r.range(-80, 50), age, V, 2.6, 160);+ if (x > left + 10) spark(p, x, y, vx, vy, 1 - age / life, SP);});- 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);+ beat(t, D, 8, S + 6, (r) => r.range(0.5, 0.8), (age, life, r) => {+ const [x, y, vx, vy] = wake(NOZZLE - r.range(4, J0 * 0.8), bob(t - age) + r.range(-1, 1), -r.range(10, 80), r.range(-60, 10), age, V, 1.8, 170);+ if (x > left + 10) spark(p, x, y, vx, vy, 1 - age / life, SP, 0.5);+ });++ jet(p, F, NOZZLE, by + 0.5, J, wob, fr + S * 31);+ p.sprite(SHIP.rows, { o: OUTLINE, 1: M[1], 2: M[2], 3: M[3], 4: M[4], 5: M[5], 6: M[6], a: A[0], b: A[1], c: A[2], d: A[3], e: A[4], w: WHITE, h: F[5], x: F[8] }, SHIP.x0, SHIP.y0 + by);++ // light: a warm pool round the tail that breathes with the jet, the flame's own glow, a white-hot nozzle+ p.glow(NOZZLE - 10, by, 60, F[4], 0.28 * fl);+ p.glowLine(NOZZLE - 3, by + 0.5, NOZZLE - J * 0.9, by + 0.5, 11, F[4], 0.2);+ p.glow(NOZZLE - 1, by + 0.5, 8, F[7], 0.45);+ p.glow(NOZZLE + 3, by + 5, 12, F[4], 0.22 * fl); // the flame lights the tail from below}diff --git a/src/fx/projectiles/shuriken.js b/src/fx/projectiles/shuriken.jsdeleted file mode 100644index 810e9c0..0000000--- a/src/fx/projectiles/shuriken.js+++ /dev/null@@ -1,39 +0,0 @@-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.jsdeleted file mode 100644index 63a3851..0000000--- a/src/fx/projectiles/sniper-trail.js+++ /dev/null@@ -1,53 +0,0 @@-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.jsindex d77a846..1c8b8fe 100644--- a/src/fx/scifi/_lib.js+++ b/src/fx/scifi/_lib.js@@ -1,41 +1,167 @@-// 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.+// Shared by the scifi effects. Ghosts: the toolkit's simulated particles for loops (sparks that fall and bounce,+// smoke that rises and thins) worked out from their birth each frame, so a loop is a function of t alone and has+// no seam. Also lights that flare in loops, and electric arcs stroked the way Hugo strokes his bolts. Their motion is the toolkit's (src/core/sim.js), which is adapted from Sprite Fusion's open-source+// pixel art VFX (https://www.spritefusion.com/pixel-art-vfx), MIT License, Copyright (c) 2026 Hugo Duprez.-import { ramp } from "../../core/index.js";+import { Particles, P, PF, GRAVITY, hex, rand, WHITE, TAU } from "../../core/index.js";-export { zap, jagged, glowPath, brokenRing } from "../lightning/_lib.js";+const SOFT = new Set([P.VAPOUR, P.DUST, P.SMOKE]);+const STEP = 1 / 240;-/** 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))]);+// one toolkit step for one particle, with its own age standing in for the system clock (so it repeats)+function move(q, dt, age, ground) {+ switch (q.k) {+ case P.FIRE:+ q.vy -= 95 * dt;+ q.vx += Math.sin(age * 17 + q.seed) * 30 * dt;+ q.vx -= q.vx * 5 * dt;+ q.vy -= q.vy * 3.2 * dt;+ break;+ case P.GRIT: {+ q.vy += GRAVITY * dt;+ q.vx -= q.vx * 0.8 * dt;+ const g = ground(q.x), ny = q.y + q.vy * dt;+ q.x += q.vx * dt;+ if (q.vy > 0 && q.y <= g && ny >= g) {+ q.y = g - 0.25;+ if (q.vy > 130 && rand(q.seed * 1000, q.hops++) < 0.4) (q.vy = -q.vy * 0.25), (q.vx = q.vx * 0.5);+ else (q.vx = q.vy = 0), (q.life = Math.min(q.life, 0.5));+ } else q.y = ny;+ return;+ }+ case P.SPARK: {+ q.vy += GRAVITY * 0.45 * dt;+ q.vx -= q.vx * 2.2 * dt;+ q.vy -= q.vy * 2.2 * dt;+ const g = ground(q.x), ny = q.y + q.vy * dt;+ q.x += q.vx * dt;+ if (q.vy > 0 && q.y <= g && ny >= g) (q.vy = -q.vy * 0.45), (q.vx *= 0.7), (q.y = g - 0.25);+ else q.y = ny;+ return;+ }+ case P.STREAK: (q.vx += q.vx * 3 * dt), (q.vy += q.vy * 3 * dt); break;+ case P.FLAKE:+ q.vx -= q.vx * 2.2 * dt;+ q.vy -= q.vy * 2.2 * dt - 35 * dt;+ q.x += Math.sin(age * 2.5 + q.seed) * 7 * dt;+ break;+ case P.EMBER:+ q.vy += (-30 + Math.sin(age * 3 + q.seed) * 20) * dt;+ q.vx += Math.cos(age * 2.3 + q.seed) * 45 * dt;+ q.vx -= q.vx * 1.6 * dt;+ q.vy -= q.vy * 1.6 * dt;+ break;+ case P.SMOKE: {+ const big = q.flag & PF.BIG;+ q.vy -= (big ? 23 : 16) * dt;+ q.vx += Math.sin(age * 1.3 + q.seed) * 8 * dt;+ q.vx -= q.vx * 1.6 * dt;+ q.vy -= q.vy * 1.2 * dt;+ break;+ }+ case P.MOTE: q.vx -= q.vx * 0.6 * dt; q.vy -= q.vy * 0.6 * dt; break;+ default: {+ const drag = SOFT.has(q.k) ? 4 : 1.6;+ q.vx -= q.vx * drag * dt;+ q.vy -= q.vy * drag * dt + 5 * dt;+ }+ }+ q.x += q.vx * dt;+ q.y += q.vy * dt;}-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).+ * Simulated particles for loops. add(born, ...Particles.spawn arguments) once, at build time, for each particle+ * born `born` seconds into the period; at(t) returns a Particles holding every particle alive at t, each moved+ * there from its birth by the toolkit's physics, ready for draw(p, layer). A particle born late in the period+ * carries on into the next one, so the loop has no seam. opts: the Particles options (ground, sparks, haze) and+ * box: [x0, y0, x1, y1], outside which particles are dropped (keeps sparks on the canvas).*/-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)];+export class Ghosts {+ constructor(period, opts = {}) {+ this.D = period;+ this.ground = opts.ground ?? (() => Infinity);+ this.box = opts.box ?? null;+ this.ps = new Particles({ ground: this.ground, sparks: opts.sparks, haze: opts.haze });+ this.specs = [];+ }+ add(born, k, x, y, vx, vy, life, col = WHITE, size = 1, flag = 0) {+ const n = this.specs.length, D = this.D;+ // a star's twinkle runs on the clock: pick its seed so the twinkle repeats with the period too+ let seed = rand(n, 41) * 100;+ if (k === P.STAR) {+ const m = Math.ceil((8 * D) / TAU), f = (TAU * m) / D - 8;+ if (f < 5) seed = f + 5 * Math.floor(rand(n, 43) * 19);+ }+ this.specs.push({ born: ((born % D) + D) % D, k, x, y, vx, vy, life, col: col ? hex(col) : 0, size, flag, seed });+ }+ get count() {+ return this.specs.length;+ }+ /** The state of one particle `age` seconds after its birth, or null if it's gone. */+ state(s, age) {+ const q = { k: s.k, x: s.x, y: s.y, vx: s.vx, vy: s.vy, life: s.life, max: s.life, col: s.col, size: s.size, seed: s.seed, delay: 0, flag: s.flag, hops: 0 };+ let a = 0;+ while (a < age - 1e-9) {+ const dt = Math.min(STEP, age - a);+ move(q, dt, a, this.ground);+ a += dt;+ q.life -= dt;+ if (q.life <= 0) {+ // a fire puff with SMOKES turns into smoke when it dies, as in the toolkit+ if (q.k !== P.FIRE || !(q.flag & PF.SMOKES)) return null;+ const big = q.flag & PF.BIG, L = big ? 1.3 + rand(s.seed * 7, 1) : 0.8 + rand(s.seed * 7, 1) * 0.6;+ Object.assign(q, { k: P.SMOKE, vx: q.vx * 0.6, vy: q.vy * 0.6 - 6, life: L, max: L, col: 0, size: q.size * (big ? 0.85 : 0.7), flag: big ? PF.BIG : 0 });+ }+ }+ if (this.box) {+ const [x0, y0, x1, y1] = this.box;+ if (q.x < x0 || q.x > x1 || q.y < y0 || q.y > y1) return null;+ }+ return q;+ }+ at(t) {+ const D = this.D, list = [];+ for (const s of this.specs) {+ // its age now, and in each earlier period it may still be alive from (smoke from fire lives longer)+ const span = s.k === P.FIRE && s.flag & PF.SMOKES ? s.life + 2.4 : s.life;+ for (let age = (((t - s.born) % D) + D) % D; age < span; age += D) {+ const q = this.state(s, age);+ if (q) list.push(q);+ }+ }+ this.ps.list = list;+ this.ps.t = t;+ return this.ps;+ }+}++/** A light that flares at t0 and dies over life, as the toolkit's Lights do, for loops: k falls with life². */+export function flash(p, t, t0, x, y, r, c, k, life) {+ const a = t - t0;+ if (a < 0 || a >= life) return;+ const q = 1 - a / life;+ p.glow(x, y, r * (0.55 + 0.45 * q), c, k * q * q);}-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;+/** Smallest positive age of an event at t0 in a loop of period D, seen at t. */+export const since = (t, t0, D) => (((t - t0) % D) + D) % D;++/**+ * An electric arc along a path [[x, y], ...], drawn the way Hugo strokes his bolts: a dark halo, a bright body,+ * a white-hot core while it's fresh, light along it. C: [halo, body, glow]; k: 1 fresh, falling to 0; w: weight.+ */+export function strokeArc(p, pts, C, k = 1, w = 1) {+ const [halo, body, glow] = C;+ for (const pass of [0, 1, 2])+ for (let i = 1; i < pts.length; i++) {+ const [ax, ay] = pts[i - 1], [bx, by] = pts[i], L = Math.max(1, Math.hypot(bx - ax, by - ay));+ for (let d = 0; d <= L; d += 0.5) {+ const x = ax + ((bx - ax) * d) / L, y = ay + ((by - ay) * d) / L;+ if (pass === 0) p.circle(x, y, (k > 0.6 ? 1.6 : 1.1) * w, halo);+ else if (pass === 1) p.circle(x, y, (k > 0.6 ? 0.9 : 0.6) * w, body);+ else if (k > 0.3) p.px(x, y, WHITE);+ }+ if (pass === 0 && i % 3 === 0) p.glow(ax, ay, 9 * w, glow, 0.45 * k);+ }}diff --git a/src/fx/scifi/cloak.js b/src/fx/scifi/cloak.jsdeleted file mode 100644index c03fd9a..0000000--- a/src/fx/scifi/cloak.js+++ /dev/null@@ -1,62 +0,0 @@-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.jsdeleted file mode 100644index 0374919..0000000--- a/src/fx/scifi/data-stream.js+++ /dev/null@@ -1,39 +0,0 @@-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.jsindex 87fc816..77abd6a 100644--- a/src/fx/scifi/emp-blast.js+++ b/src/fx/scifi/emp-blast.js@@ -1,77 +1,194 @@-import { PAL, burst, fly, flyV, seg, ease, rng, rand, TAU, WHITE } from "../../core/index.js";-import { steps, jagged } from "./_lib.js";+// The pop (a white disc, a fast ring, sparks bursting, short arcs crawling the area as it dies away) follows+// Sprite Fusion's open-source lightning impact (https://www.spritefusion.com/pixel-art-vfx/lightning),+// MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Lights, P, Rng, fit, bolt, sparkle, band, clamp, smooth, lerp, ease, rand, hex, mix, TAU, WHITE } from "../../core/index.js";+import { strokeArc } 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,+ desc: "A disc charge ticks, pops white, and a bubble of rolling scanlines swells out with arcs crawling its skin; it strobes, tears and shorts out into falling dead pixels.",+ tags: ["scifi", "emp", "pulse", "shockwave", "electric", "grenade", "glitch", "one-shot"],+ size: [152, 116],+ origin: [76, 84],+ duration: 3.2,loop: false,fps: 30,- bg: "dark",- options: { palette: PAL.electric, radius: 42, seed: 33 },+ bg: "ground",+ options: {+ palette: ["#0d0820", "#1c1658", "#2d2aa0", "#3f55e8", "#5a8eff", "#9cc4ff", "#dceaff", "#ffffff"],+ fringe: "#ff5ad8",+ radius: 56,+ seed: 33,+ },};-const OFF = [[0.13, 0.166], [0.3, 0.333], [0.5, 0.533]]; // strobe: frames where the bubble cuts out+// the beats: it ticks, pops, the bubble swells and holds, strobes, breaks+const POP = 0.42, GROW = 0.32, STROBE = 1.25, BREAK = 1.58;-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);+export function create(o) {+ const C = fit(o.palette, 8), F = hex(o.fringe), RM = o.radius, R = new Rng(o.seed);+ const ps = new Particles({ rng: R, ground: () => 0, sparks: [WHITE, C[6], C[5], C[4]], haze: C[5] }), lights = new Lights();+ const arcs = [], dead = [];+ let t = 0, popped = false, broke = false, nextArc = 0, star = [], starAt = -1;+ const radius = () => (t < POP ? 0 : RM * (0.12 + 0.88 * ease.outExpo(clamp((t - POP) / GROW))) * (1 + 0.04 * clamp((t - POP - GROW) / 0.8)));+ // which frames the bubble cuts out in while it fails+ const off = () => t > STROBE && t < BREAK && rand(o.seed, Math.floor(t * 30)) < 0.2 + 0.5 * ((t - STROBE) / (BREAK - STROBE));- // 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 charge: a mote of light just off the floor, swelling, blinking faster, crackling+ const charge = (p) => {+ if (t >= POP) return;+ const k = t / POP, r = 1 + 3.2 * k * k, tick = Math.sin(TAU * (2 * t + 10 * t * t)) > 0;+ p.circle(0, -7, r + 1, C[4]);+ p.circle(0, -7, r, tick ? WHITE : C[6]);+ const f = Math.floor(t * 30), rr = new Rng(o.seed * 97 + f);+ for (let i = 0; i < 1 + Math.floor(k * 3); i++) {+ const a = rr.range(0, TAU), l = r + 2 + rr.range(2, 6) * k;+ strokeArc(p, bolt(rr, Math.cos(a) * r, -7 + Math.sin(a) * r, Math.cos(a) * l, -7 + Math.sin(a) * l, { jag: 0.4, depth: 2 }), [C[2], C[5], C[4]], 0.7, 0.5);}- }+ p.glow(0, -7, 8 + 16 * k, C[4], 0.4 + 0.5 * k * (tick ? 1 : 0.6));+ };- // 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);+ // the bubble: thin glass, brighter toward its rim, interference lines rolling down it, tears across it+ const bubble = (p, near) => {+ const r = radius();+ if (r <= 1 || t >= BREAK || off()) return;+ const age = t - POP, slot = Math.floor(t * 30), roll = age * 40, ry = r * 0.16;+ // the tears: a few rows this frame shifted sideways and burning bright+ const tears = new Map();+ for (let i = 0; i < 2 + (t > STROBE ? 4 : 0); i++) tears.set(Math.floor(-rand(o.seed, slot, i) * r), (rand(o.seed, slot, i, 1) < 0.5 ? -1 : 1) * (2 + Math.floor(rand(o.seed, slot, i, 2) * 4)));+ for (let y = Math.floor(-r); y <= Math.ceil(ry); y++) {+ const shift = tears.get(y) ?? 0;+ for (let x = Math.floor(-r); x <= Math.ceil(r); x++) {+ const sx = x - shift, d = Math.hypot(sx + 0.5, y < 0 ? y + 0.5 : 0) / r;+ // a split edge just outside the rim, as if the signal's colors had slipped+ if (d > 1) {+ if (near && y < 0 && d < 1 + 1.4 / r && (x + y) % 2 === 0) p.px(x, y, F);+ continue;+ }+ // the dome above the floor, the floor disc below it only as its rim+ if (y >= 0) {+ const e = Math.hypot((sx + 0.5) / r, (y + 0.5) / ry);+ if (e > 1 || e < 0.92 || (y > 0) !== near) continue;+ p.px(x, y, e > 0.97 ? C[6] : C[4]);+ continue;+ }+ if (!near) continue;+ const rim = d ** 6, line = ((((y - roll) % 4) + 4) % 4) < 1, band = ((((y - roll * 0.5) % 22) + 22) % 22) < 4;+ if (d > 0.965) p.px(x, y, shift ? WHITE : -y > r * 0.55 && sx < 0 ? WHITE : C[6]);+ else if (d > 0.93) p.px(x, y, C[4]);+ else if (shift) p.px(x, y, Math.abs(sx) > r * 0.8 ? F : (x & 1) ? C[6] : C[5]);+ else p.blend(x + 0.5, y + 0.5, line && band ? C[6] : line ? C[5] : band ? C[4] : C[3], 0.06 + 0.42 * rim + (line ? 0.14 + 0.24 * rim : 0) + (band ? 0.16 : 0));+ }+ if (shift && near) p.glowLine(-r, y, r, y, 4, C[5], 0.3);}- }-- // 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]);- });+ if (near) {+ for (let a = 0.15; a < Math.PI - 0.1; a += 0.35) p.glow(Math.cos(a) * r, -Math.sin(a) * r, 8, C[4], 0.12);+ // junk blocks flicker on inside it+ for (let i = 0; i < 3; i++) {+ const k = rand(o.seed, slot, i, 7);+ if (k > 0.5) continue;+ const a = rand(o.seed, slot, i, 8) * Math.PI, d = rand(o.seed, slot, i, 9) * r * 0.85, bx = Math.round(Math.cos(a) * d), by = Math.round(-Math.sin(a) * d);+ p.rect(bx, by, 2 + Math.floor(k * 8), 1 + Math.floor(k * 4), k < 0.2 ? WHITE : C[5]);+ }+ }+ };- 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);+ return {+ update(dt) {+ t += dt;+ // charging: energy streaks in to the puck+ if (t < POP - 0.05 && R.chance(0.6)) {+ const a = R.range(-Math.PI, 0), D = R.range(16, 40), T = R.range(0.14, 0.22), v = (D * 3) / (Math.exp(3 * T) - 1);+ ps.spawn(P.STREAK, Math.cos(a) * D, -5 + Math.sin(a) * D * 0.7, -Math.cos(a) * v, -Math.sin(a) * v * 0.7, T, R.chance(0.5) ? C[6] : C[5]);+ }+ // the discharge: a star of thick arcs out of the pop, jittering each frame as it shrinks+ const sa = t - POP, sf = Math.floor(t * 30);+ if (sa >= 0 && sa < 0.26 && sf !== starAt) {+ starAt = sf;+ const len = sa < 0.05 ? ease.outBack(sa / 0.05, 2) : 1 - (sa - 0.05) / 0.26;+ star = [];+ for (let i = 0; i < 7; i++) {+ const a = -Math.PI + (i / 6) * Math.PI + rand(o.seed, i, 3) * 0.3 - 0.15 + R.range(-0.1, 0.1), L = (20 + 16 * rand(o.seed, i, 5)) * Math.max(0.15, len);+ star.push(bolt(R, 0, -7, Math.cos(a) * L, Math.min(-1, -7 + Math.sin(a) * L), { jag: 0.28, depth: 4 }));+ }+ }+ if (sa >= 0.26) star = [];+ if (t >= POP && !popped) {+ popped = true;+ for (let i = 0; i < 16; i++) {+ const a = R.range(-Math.PI, 0), sp = R.range(50, 150);+ ps.spawn(P.MOTE, 0, -7, Math.cos(a) * sp, Math.sin(a) * sp, R.range(0.3, 0.6), R.pick([WHITE, C[6], C[5]]), 0.8);+ }+ lights.add(0, -20, 72, C[4], 0.9, 0.5);+ lights.add(0, -7, 30, WHITE, 0.9, 0.12);+ for (let i = 0; i < 60; i++) {+ const a = R.range(-Math.PI, 0), sp = R.range(90, 220);+ ps.spawn(P.SPARK, 0, -7, Math.cos(a) * sp, Math.sin(a) * sp, R.range(0.2, 0.6));+ }+ for (let i = 0; i < 6; i++) ps.spawn(P.SMOKE, R.range(-3, 3), -4, R.range(-12, 12), -R.range(10, 24), R.range(1, 1.6), hex("#3c3a52"), R.range(2.5, 4), R.range(0.05, 0.3));+ }+ // arcs crawl over the bubble's skin, faster as it fails+ if (popped && !broke && t >= nextArc) {+ nextArc = t + (t > STROBE ? R.range(0.02, 0.05) : R.range(0.05, 0.11));+ const r = radius(), a0 = R.range(0.1, Math.PI - 0.1), a1 = a0 + R.sign() * R.range(0.25, 0.6), rr = r * R.range(0.92, 1);+ arcs.push({ t, pts: bolt(R, Math.cos(a0) * rr, -Math.sin(a0) * rr, Math.cos(a1) * rr, -Math.max(0.05, Math.sin(a1)) * rr, { jag: 0.3, depth: 4 }), life: R.range(0.05, 0.1) });+ if (R.chance(0.35)) ps.spawn(P.SPARK, Math.cos(a1) * rr, -Math.max(0.05, Math.sin(a1)) * rr, R.range(-80, 80), R.range(-90, 10), R.range(0.15, 0.3));+ }+ if (t >= BREAK && !broke) {+ broke = true;+ // it shorts out: the skin bursts into dead pixels, a last crackle, the charge smokes+ const r = radius();+ lights.add(0, -r * 0.4, r * 1.3, C[5], 0.8, 0.3);+ for (let i = 0; i < 70; i++) {+ const a = R.range(0.05, Math.PI - 0.05), d = r * R.range(0.6, 1);+ dead.push({ x: Math.cos(a) * d, y: -Math.sin(a) * d, vx: Math.cos(a) * R.range(5, 25), vy: -R.range(0, 20), life: R.range(0.4, 1), max: 1, s: R.chance(0.3) ? 2 : 1, c: R.pick([WHITE, C[6], C[5], C[4]]), ph: R.range(0, 9) });+ }+ for (let i = 0; i < 6; i++) {+ const a0 = R.range(0.1, Math.PI - 0.1), a1 = a0 + R.range(-0.5, 0.5);+ arcs.push({ t, pts: bolt(R, Math.cos(a0) * r, -Math.sin(a0) * r, Math.cos(a1) * r * 0.6, -Math.max(0.05, Math.sin(a1)) * r * 0.6, { jag: 0.35, depth: 4 }), life: 0.1 });+ }+ for (let i = 0; i < 8; i++) ps.spawn(P.SMOKE, R.range(-3, 3), -4, R.range(-6, 6), -R.range(8, 18), R.range(0.8, 1.2), hex("#2f2c3c"), R.range(2, 3.4), R.range(0, 0.35));+ }+ // the dead charge fizzes now and then+ if (broke && t < meta.duration - 0.8 && R.chance(0.05)) ps.spawn(P.SPARK, R.range(-3, 3), -3, R.range(-60, 60), -R.range(40, 120), R.range(0.15, 0.3));+ for (let i = arcs.length - 1; i >= 0; i--) if (t - arcs[i].t > arcs[i].life) arcs.splice(i, 1);+ for (let i = dead.length - 1; i >= 0; i--) {+ const d = dead[i];+ if ((d.life -= dt) <= 0) dead.splice(i, 1);+ d.vy += 60 * dt;+ d.x += d.vx * dt;+ d.y = Math.min(-1, d.y + d.vy * dt);+ }+ ps.update(dt);+ lights.update(dt);+ },+ drawBack(p) {+ bubble(p, false);+ ps.draw(p, "back");+ },+ draw(p) {+ charge(p);+ bubble(p, true);+ // the pop: a white disc, a ring racing out ahead of the bubble, a flare+ const a = t - POP;+ if (a >= 0 && a < 0.06) {+ p.circle(0, -7, 12 * (1 - a / 0.06) + 3, C[6]);+ p.circle(0, -7, 9 * (1 - a / 0.06) + 1, WHITE);+ }+ if (a >= 0 && a < 0.4) {+ const k = a / 0.4, rr = 6 + (RM + 14) * ease.outCubic(k);+ band(p, 0, 0, rr, 0.16, Math.max(1, 3 * (1 - k)), 1.2 - k, [C[3], C[5], C[6], WHITE], () => true, k < 0.3);+ }+ if (a >= 0 && a < 0.16) sparkle(p, 0, -7, 10 * (1 - a / 0.16), C[6], C[5], 0.6);+ for (const b of star) strokeArc(p, b, [C[3], C[6], C[5]], 1 - (t - POP) / 0.3, 1.3);+ for (const c of arcs) strokeArc(p, c.pts, [C[2], C[5], C[4]], 1 - (t - c.t) / (c.life + 0.03), 0.8);+ // dead pixels: drifting down, blinking, going out+ for (const d of dead) {+ if (Math.sin(t * 40 + d.ph) < -0.3 && d.life < 0.6) continue;+ p.rect(d.x, d.y, d.s, d.s, d.life > 0.5 ? d.c : C[3]);+ }+ ps.draw(p, "front");+ lights.draw(p);+ },+ };}diff --git a/src/fx/scifi/energy-core.js b/src/fx/scifi/energy-core.jsindex 11b9d26..e0b4c8f 100644--- a/src/fx/scifi/energy-core.js+++ b/src/fx/scifi/energy-core.js@@ -1,81 +1,206 @@-import { PAL, ramp, at, seg, ease, rng, rand, wrap, TAU, WHITE } from "../../core/index.js";-import { steps, jagged, brokenRing } from "./_lib.js";+// The plasma ball (a lit rim, filaments from a white-hot heart, motes riding round it, zaps that spark where+// they land) follows Sprite Fusion's open-source energy orb (https://www.spritefusion.com/pixel-art-vfx/energy),+// MIT License, Copyright (c) 2026 Hugo Duprez.+import { P, Rng, fit, bolt, forks, tileFbm, clamp, smooth, lerp, ease, rand, rng, mix, TAU, WHITE } from "../../core/index.js";+import { Ghosts, since, strokeArc } 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,+ desc: "A plasma core beating in a steel cage: it swells and throws a shock ring on each beat, two tilted rings orbit it, and arcs jump to the bars and spark.",+ tags: ["scifi", "reactor", "core", "power", "plasma", "machine", "prop", "ground", "loop"],+ size: [112, 100],+ origin: [56, 88],+ duration: 2.4,loop: true,fps: 30,- bg: "dark",- options: { palette: PAL.gold, radius: 8, seed: 35 },+ bg: "ground",+ options: {+ palette: ["#1a0516", "#3d0a33", "#701560", "#b0228f", "#f53cd1", "#ff86e6", "#ffd2f6", "#ffffff"],+ metal: ["#0e0d14", "#1e1c27", "#312e3e", "#4b4759", "#6f6a82", "#9d98b0"],+ seed: 35,+ },};-const METAL = ramp(["#121119", "#24222f", "#3a3748", "#575369", "#7d7891", "#a7a2b8"]);-const BEAT = 0.8, RAIL = 16;+const D = meta.duration, CY = -36, R0 = 11, RC = 24, TOPY = -64, BOTY = -9, SLOT = 0.1, NS = Math.round(D / SLOT);+// two heartbeats a loop, each a strong thump and a softer echo+const BEATS = [[0.05, 1, true], [0.25, 0.5, false], [1.25, 1, true], [1.45, 0.5, false]];+const env = (a) => (a < 0.03 ? a / 0.03 : Math.exp(-(a - 0.03) / 0.12));+const pulseAt = (t) => BEATS.reduce((m, [b, k]) => Math.max(m, k * env(since(t, b, D))), 0);+// the cage's bars round the core: angle, x, depth (> 0 in front)+const BARS = Array.from({ length: 6 }, (_, i) => {+ const a = (i / 6) * TAU + Math.PI / 6;+ return { x: RC * Math.sin(a), z: Math.cos(a) };+});+// a point on an orbiting ring, tilted and turning: [x, y, depth]+function ringPt(r, tilt, spin, a) {+ const x = r * Math.cos(a), z0 = r * Math.sin(a), y = -z0 * Math.sin(tilt), z = z0 * Math.cos(tilt);+ return [x * Math.cos(spin) + z * Math.sin(spin), CY - y, -x * Math.sin(spin) + z * Math.cos(spin)];+}+const RINGS = [+ { r: 17, tilt: 1.15, spin: (t) => TAU * (t / D) },+ { r: 19, tilt: -0.9, spin: (t) => -TAU * 2 * (t / D) + 1 },+];-// 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]);+const cache = new Map();+function setup(o) {+ const key = `${o.seed}:${o.palette.join()}`;+ if (cache.has(key)) return cache.get(key);+ const C = fit(o.palette, 8), rn = new Rng(o.seed);+ const g = new Ghosts(D, { ground: () => 0, sparks: [WHITE, C[6], C[5], C[4]], haze: C[5], box: [-54, -98, 54, 11] });+ // arcs: each slot of the loop may fire one or two, more just after a thump+ const arcs = [];+ for (let s = 0; s < NS; s++) {+ const ts = s * SLOT, hot = BEATS.some(([b, , strong]) => strong && since(ts, b, D) < 0.16);+ for (let n = 0; n < (hot ? 2 : 1); n++) {+ if (!hot && !rn.chance(0.4)) continue;+ const bar = rn.pick(BARS.filter((b) => b.z > -0.2)), ty = rn.range(TOPY + 8, BOTY - 6), ang = Math.atan2(ty - CY, bar.x);+ const sx = Math.cos(ang) * R0, sy = CY + Math.sin(ang) * R0, path = bolt(rn, sx, sy, bar.x - Math.sign(bar.x) * 1.5, ty, { jag: 0.3, depth: 4 });+ arcs.push({ s, path, fk: forks(rn, path, { count: rn.int(0, 1), len: 7, jag: 0.35 }) });+ for (let i = 0; i < 5; i++) {+ const a = Math.atan2(ty - sy, bar.x - sx) + Math.PI + rn.range(-1.2, 1.2), sp = rn.range(60, 170);+ g.add(ts, P.SPARK, bar.x, ty, Math.cos(a) * sp, Math.sin(a) * sp - 40, rn.range(0.2, 0.5));+ }+ }+ }+ // each thump throws motes off the core+ for (const [b, , strong] of BEATS) {+ if (!strong) continue;+ for (let i = 0; i < 12; i++) {+ const a = rn.range(0, TAU), sp = rn.range(40, 110);+ g.add(b + 0.02, P.MOTE, Math.cos(a) * R0, CY + Math.sin(a) * R0, Math.cos(a) * sp, Math.sin(a) * sp, rn.range(0.25, 0.5), rn.pick([WHITE, C[6], C[5]]), 0.7);+ }}- return out;+ const v = { C, arcs, g };+ cache.set(key, v);+ return v;}-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]);+// the plinth on the floor: a steel drum with a lit top and a row of status lights+function plinth(p, C, H, t, pulse) {+ p.shade(-30, -10, 30, 2, (x, y, out) => {+ const top = ((x / 29) ** 2 + ((y + 7) / 4) ** 2) <= 1, side = Math.abs(x) <= 29 && y > -7 && y <= 0;+ if (!top && !side) return;+ if (top) out.c = ((x / 29) ** 2 + ((y + 7) / 4) ** 2) > 0.82 ? H[0] : y < -8 ? H[5] : x < 0 ? H[4] : H[3];+ else out.c = Math.abs(x) > 28 || y === 0 ? H[0] : y === -6 ? H[4] : x < -14 ? H[3] : x > 14 ? H[1] : H[2];+ });+ for (let i = 0; i < 7; i++) {+ const x = -18 + i * 6, k = 0.5 + 0.5 * Math.cos(TAU * (2 * (t / D) - i / 7));+ p.px(x, -3, k > 0.75 ? WHITE : k > 0.4 ? C[5] : C[2]);+ if (k > 0.6) p.glow(x, -3, 4, C[4], 0.3 * k);}+ p.glow(0, -8, 26, C[4], 0.25 + 0.3 * pulse);+}- // 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]);+// a cage bar: steel, lit on the face toward the core+function barDraw(p, b, C, H, pulse, back) {+ const lit = back ? C[3] : pulse > 0.5 ? C[6] : C[5], inward = -Math.sign(b.x);+ for (let y = TOPY + 2; y < BOTY; y++)+ for (let i = -1; i <= 1; i++) {+ const face = i === inward;+ p.px(b.x + i, y, back ? (face ? lit : H[1]) : face ? lit : i === 0 ? H[3] : H[1]);}- });- 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);+// the cage's rings top and bottom: the far half or the near half of a steel hoop+function hoop(p, y, rx, H, C, near, pulse) {+ for (let i = 0, n = Math.ceil(rx * 8); i < n; i++) {+ const g = (i / n) * TAU, s = Math.sin(g);+ if (s >= 0 !== near) continue;+ const x = Math.cos(g) * rx, yy = y + s * 4;+ p.px(x, yy, near ? (s > 0.6 ? H[4] : H[3]) : H[1]);+ p.px(x, yy + 1, near ? H[1] : H[0]);+ if (near && s < 0.3) p.px(x, yy - 1, pulse > 0.5 ? C[5] : C[3]);+ }+}++// the core: dark plasma held in a hard rim, thin bright bands churning round a white-hot heart, filaments+// flickering out from it; a thump floods it with light+function core(p, t, C, R, pulse, seed) {+ const ph = t / D;+ p.shade(-R - 2, CY - R - 2, R + 2, CY + R + 2, (x, y, out) => {+ const dx = x, dy = y - CY, d = Math.sqrt(dx * dx + dy * dy) / R;+ if (d > 1.1) return;+ if (d > 1) return (out.c = C[2]);+ if (d > 0.9) return (out.c = dy < -R * 0.3 && dx < R * 0.3 ? C[6] : C[4]);+ const a = Math.atan2(dy, dx), n = 0.5 + 0.5 * tileFbm((a / TAU) * 6 + ph * 6 + d * 1.5, d * 2.2 - ph * 4, 6, 4, seed, 2);+ const band = Math.abs(n - 0.5) < 0.05 + 0.05 * pulse, heat = (1 - d) ** 2 + pulse * 0.45;+ if (band) out.c = heat > 0.5 ? WHITE : heat > 0.2 ? C[6] : C[5];+ else out.c = heat > 0.7 ? C[6] : heat > 0.42 ? C[5] : heat > 0.2 ? C[3] : n > 0.5 ? C[2] : C[1];});+ // filaments, redrawn every other frame+ const f = Math.floor(t * 15), r = rng(seed, f, 5);+ for (let i = 0; i < 3; i++) {+ const a = (i / 3) * TAU + f * 0.7 + r.range(-0.4, 0.4), pts = bolt(r, 0, CY, Math.cos(a) * R * 0.88, CY + Math.sin(a) * R * 0.88, { jag: 0.32, depth: 3 });+ p.polyline(pts, (u) => (u < 0.4 ? WHITE : C[6]));+ const [ex, ey] = pts[pts.length - 1];+ p.px(ex, ey, WHITE);+ p.glow(ex, ey, 4, C[5], 0.4);+ }+ p.circle(0, CY, 1.8 + pulse * 2, WHITE);+ p.circle(0, CY, 3 + pulse * 2, (d) => (d > 0.6 ? C[6] : WHITE), 0.0001);+ // a glassy highlight top left+ p.px(-R * 0.45, CY - R * 0.55, WHITE);+ p.px(-R * 0.45 + 1, CY - R * 0.55, C[6]);+}- orbit(true);+function ring(p, t, rg, C, front, pulse) {+ const spin = rg.spin(t), bead = (t / D) * TAU * 3;+ for (let i = 0, n = Math.ceil(rg.r * 9); i < n; i++) {+ const a = (i / n) * TAU, [x, y, z] = ringPt(rg.r, rg.tilt, spin, a);+ if (z >= 0 !== front) continue;+ const u = ((((a - bead) / TAU) % 1) + 1) % 1, head = u > 0.9;+ p.px(x, y, head ? WHITE : !front ? C[3] : z > 0.5 * rg.r || pulse > 0.6 ? C[6] : C[5]);+ }+ if (front) {+ const [x, y] = ringPt(rg.r, rg.tilt, spin, bead);+ p.glow(x, y, 6, C[5], 0.5);+ }+}- // 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] });+export function drawBack(p, t, o) {+ const C = fit(o.palette, 8), H = fit(o.metal, 6), pulse = pulseAt(t);+ hoop(p, BOTY, RC, H, C, false, pulse);+ hoop(p, TOPY, RC, H, C, false, pulse);+ for (const b of BARS) if (b.z < 0) barDraw(p, b, C, H, pulse, true);+ for (const rg of RINGS) ring(p, t, rg, C, false, pulse);+}- // 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);+export function draw(p, t, o) {+ const { C, arcs, g } = setup(o), H = fit(o.metal, 6), pulse = pulseAt(t), R = R0 * (1 + 0.14 * pulse);+ plinth(p, C, H, t, pulse);+ core(p, t, C, R, pulse, o.seed);+ for (const rg of RINGS) ring(p, t, rg, C, true, pulse);+ for (const b of BARS) if (b.z >= 0) barDraw(p, b, C, H, pulse, false);+ hoop(p, BOTY, RC, H, C, true, pulse);+ hoop(p, TOPY, RC, H, C, true, pulse);+ // the cap: a steel dome with an emitter on top+ p.shade(-15, TOPY - 7, 15, TOPY, (x, y, out) => {+ const d = (x / 14.5) ** 2 + ((y - TOPY) / 6.5) ** 2;+ if (d > 1) return;+ const l = -x * 0.05 - (y - TOPY) * 0.12;+ out.c = d > 0.8 ? H[0] : l > 0.55 ? H[5] : l > 0.3 ? H[4] : H[3];+ });+ p.px(0, TOPY - 7, pulse > 0.4 ? WHITE : C[5]);+ p.glow(0, TOPY - 7, 5, C[4], 0.4 + 0.4 * pulse);+ // the arcs firing now+ const s = Math.floor(t / SLOT) % NS, k = 1 - (t - Math.floor(t / SLOT) * SLOT) / SLOT;+ for (const a of arcs) {+ if (a.s !== s) continue;+ strokeArc(p, a.path, [C[2], C[5], C[4]], k);+ for (const f of a.fk) strokeArc(p, f, [C[2], C[5], C[4]], k, 0.6);+ const [ex, ey] = a.path[a.path.length - 1];+ p.glow(ex, ey, 8, C[5], 0.6 * k);}-- // 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]);+ // each thump: a shock ring rolls out from the core+ for (const [b, , strong] of BEATS) {+ const a = since(t, b, D);+ if (!strong || a > 0.45) continue;+ const q = a / 0.45, r = R0 + 34 * ease.outCubic(q);+ p.ring(0, CY, r, Math.max(1, 3 * (1 - q)), q < 0.25 ? WHITE : q < 0.5 ? C[6] : C[5], 1.1 - q);+ p.glowRing(0, CY, r, 6, C[4], 0.35 * (1 - q));}-- p.glow(0, 0, 30, C[4], 0.3 + 0.25 * swell);- p.glow(0, 0, 11, C[6], 0.35 + 0.2 * swell);+ g.at(t).draw(p);+ // light: the core's heat, its white heart, the steel lit round it+ p.glow(0, CY, 46, C[4], 0.2 + 0.3 * pulse);+ p.glow(0, CY, 9, WHITE, 0.35 + 0.4 * pulse);}diff --git a/src/fx/scifi/force-field.js b/src/fx/scifi/force-field.jsindex 85e46b7..f09eb8a 100644--- a/src/fx/scifi/force-field.js+++ b/src/fx/scifi/force-field.js@@ -1,96 +1,278 @@-import { PAL, ramp, at, burst, fly, flyV, seg, clamp, rand, wrap, TAU, WHITE } from "../../core/index.js";-import { steps, hexCell } from "./_lib.js";+// The hit recipe (a tracer from the right, a flash and a ripple over a hex shell mapped by longitude and+// latitude, sparks glancing off) is adapted from Sprite Fusion's open-source shield+// (https://www.spritefusion.com/pixel-art-vfx/shield), MIT License, Copyright (c) 2026 Hugo Duprez.+import { P, Rng, fit, sparkle, band, bolt, forks, clamp, smooth, rand, hex, TAU, WHITE } from "../../core/index.js";+import { Ghosts, flash, since } 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,+ desc: "A glassy dome of hex plates over the hero: plates glint, tracers from the right slam into it, a ripple and cracks of light race across, sparks glance off.",+ tags: ["scifi", "shield", "barrier", "dome", "hex", "hit", "defense", "loop"],+ size: [184, 104],+ origin: [76, 84],+ duration: 2.4,loop: true,fps: 30,bg: "ground",- options: { palette: PAL.electric, width: 36, height: 34, cell: 5, seed: 25 },+ actor: 2,+ options: {+ palette: ["#0b1030", "#152a63", "#1d4f9e", "#2582d2", "#36b9ee", "#8ae8ff", "#d4fbff", "#ffffff"],+ sparks: ["#fff3a6", "#ffe26b", "#ff8a2a", "#f2561d"],+ radius: 44,+ seed: 5,+ },};-const SHOT = ramp(["#a8301a", "#ff8a2a", "#ffd27a", "#ffffff"]);-const HIT = 0.55; // when the shot lands, each loop+const S3 = Math.sqrt(3), SA = 0.13, CA = Math.sqrt(1 - SA * SA); // we look down on the dome a little+const G = 6.3, KY = 1.12; // hex plates per radian of longitude, and their stretch in latitude+// the shots, once a loop: a heavy one that cracks the shell, a lighter one lower down that it shrugs off+const SHOTS = [+ { t: 0.42, lon: 0.66, lat: 0.62, big: true },+ { t: 1.5, lon: 0.95, lat: 0.26, big: false },+].map((s) => ({ ...s, N: [Math.cos(s.lat) * Math.sin(s.lon), Math.sin(s.lat), Math.cos(s.lat) * Math.cos(s.lon)] }));-// 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];+// the pointy-top hex (corner radius 1) under grid point (gx, gy): its axial coords and center, how near its+// edge (1 on it) and how near one of its corners (0 on it)+function cell(gx, gy) {+ const fq = (S3 / 3) * gx - gy / 3, fr = (2 / 3) * gy, 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 hx = S3 * (q + r / 2), hy = 1.5 * r, dx = gx - hx, dy = gy - hy, ax = Math.abs(dx);+ const e = Math.max(ax, Math.abs(ax / 2 + (dy * S3) / 2), Math.abs(ax / 2 - (dy * S3) / 2)) / (S3 / 2);+ const k = Math.round((Math.atan2(dy, dx) - Math.PI / 6) / (Math.PI / 3)), ca = Math.PI / 6 + (k * Math.PI) / 3;+ return { q, r, hx, hy, e, corner: Math.hypot(dx - Math.cos(ca), dy - Math.sin(ca)) };}-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;+// a point on the dome (longitude, latitude) to the screen: [x, y, facing (> 0 on the near side)]+function project(R, lon, lat) {+ const X = Math.cos(lat) * Math.sin(lon), Y = Math.sin(lat), Z = Math.cos(lat) * Math.cos(lon);+ return [R * X, -R * (Y * CA - Z * SA), Y * SA + Z * CA];+}- 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;+// every pixel of the near and far shell, worked out once: where it sits on the sphere and on the plates, and+// whether it's a seam (the last pixel of a plate before the next) or a plate's lit top-left edge+const shells = new Map();+function shell(R) {+ let g = shells.get(R);+ if (g) return g;+ const near = [], far = [], N = Math.ceil(R) + 1, W = 2 * N + 1, ids = [new Map(), new Map()];+ for (let y = -N; y <= Math.ceil(R * SA) + 1; y++)+ for (let x = -N; x <= N; x++) {+ const u = (x + 0.5) / R, vy = -(y + 0.5) / R, q = u * u + vy * vy;+ if (q > 1) continue;+ const vz = Math.sqrt(1 - q);+ for (const s of [1, -1]) {+ const Y = vy * CA + s * vz * SA, Z = -vy * SA + s * vz * CA;+ if (Y < 0) continue;+ const lon = Math.atan2(u, Z), lat = Math.asin(Math.min(1, Y)), c = cell(lon * G, lat * G * KY), id = c.q * 1000 + c.r;+ (s > 0 ? near : far).push({ x, y, X: u, Y, Z, lon, lat, q: c.q, r: c.r, id, e: c.e, corner: c.corner, rim: 1 - vz, sil: (1 - Math.sqrt(q)) * R });+ ids[s > 0 ? 0 : 1].set((y + N) * W + x + N, id);+ }}- 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);+ [near, far].forEach((list, i) => {+ const at = (x, y) => ids[i].get((y + N) * W + x + N);+ for (const q of list) {+ const r = at(q.x + 1, q.y), d = at(q.x, q.y + 1), l = at(q.x - 1, q.y), u = at(q.x, q.y - 1);+ q.seam = (r !== undefined && r !== q.id) || (d !== undefined && d !== q.id);+ q.bevel = !q.seam && ((l !== undefined && l !== q.id) || (u !== undefined && u !== q.id));}- 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;});+ shells.set(R, (g = { near, far }));+ return g;+}- // 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]);+// fractures: jagged forked paths from the hit across the plates, laid out by longitude and latitude so they+// bend with the dome; each point carries how far along it is, so they can race out from the hit+const crackCache = new Map();+function cracks(R, seed, s) {+ const key = `${R}:${seed}`;+ if (crackCache.has(key)) return crackCache.get(key);+ const rn = new Rng(seed * 13 + 5), out = [];+ const toScreen = (path, u0, u1) => {+ const pts = [];+ for (let i = 0; i < path.length; i++) {+ const [lon, lat] = path[i];+ if (lat < 0.03 || lat > 1.52 || Math.abs(lon) > 1.5) break;+ pts.push([...project(R, lon, lat), u0 + ((u1 - u0) * i) / (path.length - 1)]);+ }+ return pts;+ };+ for (let i = 0; i < 5; i++) {+ const a = (i / 5) * TAU + rn.range(-0.35, 0.35), L = rn.range(0.42, 0.8);+ const path = bolt(rn, s.lon, s.lat, s.lon + (Math.cos(a) * L) / Math.cos(s.lat), s.lat + Math.sin(a) * L, { jag: 0.2, depth: 4 });+ out.push(toScreen(path, 0, 1));+ for (const f of forks(rn, path, { count: rn.int(0, 2), len: L * 0.5, jag: 0.25, spread: 0.9 })) {+ const j = path.findIndex((q) => q[0] === f[0][0] && q[1] === f[0][1]), u0 = Math.max(0, j) / (path.length - 1);+ out.push(toScreen(f, u0, u0 + 0.5));+ }}- p.glow(0, 0, RX, C[3], 0.2);+ crackCache.set(key, out);+ return out;+}- // 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);+// what the shots throw off and the glints on the plates, born once a loop+const ghostCache = new Map();+function ghosts(o, C, R) {+ const key = `${R}:${o.seed}:${o.sparks.join()}:${o.palette.join()}`;+ if (ghostCache.has(key)) return ghostCache.get(key);+ const W = meta.size[0] - meta.origin[0], rn = new Rng(o.seed), D = meta.duration;+ const g = new Ghosts(D, { ground: () => 0, sparks: o.sparks, box: [-70, -80, W - 6, 14] });+ for (const s of SHOTS) {+ const [hx, hy] = project(R, s.lon, s.lat), n = s.big ? 1 : 0.55;+ // glancing off the curve: up and away to the right, the way the shot was going when it was turned+ for (let i = 0; i < 24 * n; i++) {+ const a = (s.big ? -0.9 : -0.55) + rn.range(-0.7, 0.65), sp = rn.range(100, 280) * (0.7 + 0.3 * n);+ g.add(s.t + rn.range(0, 0.02), P.SPARK, hx, hy, Math.cos(a) * sp, Math.sin(a) * sp - 30, rn.range(0.25, 0.75));+ }+ for (let i = 0; i < 7 * n; i++) {+ const a = -0.9 + rn.range(-1.2, 1.2), sp = rn.range(30, 90);+ g.add(s.t + rn.range(0, 0.05), P.MOTE, hx, hy, Math.cos(a) * sp, Math.sin(a) * sp - 15, rn.range(0.3, 0.6), rn.pick([C[5], C[6], C[4]]), 0.7);+ }+ for (let i = 0; i < 3 * n; i++) g.add(s.t + 0.04 + i * 0.07, P.STAR, hx + rn.range(-6, 6), hy + rn.range(-5, 5), 0, -4, rn.range(0.3, 0.5), C[6], rn.range(1, 2));+ for (let i = 0; i < 3 * n; i++) g.add(s.t + 0.03 + i * 0.04, P.SMOKE, hx + 2 + rn.range(-2, 2), hy - 1, rn.range(8, 22), rn.range(-14, -4), rn.range(0.9, 1.3), hex("#5b5f78"), rn.range(2.2, 3.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));+ // a star on each plate as it glints+ for (let r = 0; r < 12; r++)+ for (let q = -14; q <= 14; q++) {+ if (!glints(o.seed, q, r)) continue;+ const lon = (S3 * (q + r / 2)) / G, lat = (1.5 * r) / (G * KY), [x, y, f] = project(R, lon, lat);+ if (f < 0.25 || lat < 0.15 || lat > 1.45 || Math.abs(lon) > 1.3) continue;+ g.add(glintAt(o.seed, q, r) + 0.03, P.STAR, x, y, 0, -3, 0.4, C[6], 1.4 + rand(q, r, 9));+ }+ ghostCache.set(key, g);+ return g;+}+const glints = (S, q, r) => rand(S, q, r, 3) < 0.2;+// when a plate glints: only in the quiet part of the loop, so nothing competes with the big hit+const glintAt = (S, q, r) => {+ const g = rand(S, q, r) * 1.7;+ return g < 1.4 ? 1 + g : g - 1.4;+};++function drawShell(p, t, o, C, near) {+ const R = o.radius, D = meta.duration, S = o.seed, ph = t / D, { near: N, far: F } = shell(R);+ const ages = SHOTS.map((s) => since(t, s.t, D));+ // the scan: a band of light climbing the dome once a loop+ const sk = clamp((ph - 0.72) / 0.26), scanLat = -0.2 + sk * 2, scanK = Math.sin(Math.PI * sk);+ for (const q of near ? N : F) {+ const ff = q.rim * q.rim;+ // the ripples: a front racing out over the sphere from each hit, the plates behind it still humming+ let rp = 0, hot = 0;+ for (let i = 0; i < SHOTS.length; i++) {+ const s = SHOTS[i], age = ages[i];+ if (age >= 1) continue;+ const d = Math.acos(clamp(q.X * s.N[0] + q.Y * s.N[1] + q.Z * s.N[2], -1, 1)), f = 0.06 + 3.1 * age, k = (1 - age) * (s.big ? 1 : 0.7);+ rp = Math.max(rp, Math.exp(-(((d - f) / 0.15) ** 2)) * k, d < f ? 0.22 * k * k * (1 - d / f) : 0);+ const hr = s.big ? 0.3 : 0.17;+ if (age < 0.55 && d < hr) hot = Math.max(hot, age < 0.07 && d < hr * 0.75 ? 2 : (1 - age / 0.55) ** 1.5 * (1.1 - (0.6 * d) / hr));+ }+ // plates glint now and then+ let gl = 0;+ if (glints(S, q.q, q.r)) {+ const a = since(t, glintAt(S, q.q, q.r), D);+ if (a < 0.45) gl = 1 - a / 0.45;+ }+ const sc = scanK * Math.exp(-(((q.lat - scanLat) / 0.09) ** 2));+ if (!near) {+ // the far side, seen through the glass: dim seams, a breath of tint+ if (q.seam) p.blend(q.x + 0.5, q.y + 0.5, rp > 0.3 ? C[5] : C[3], clamp(0.18 + 0.25 * ff + 0.6 * rp + 0.3 * sc));+ else p.blend(q.x + 0.5, q.y + 0.5, C[2], 0.04 + 0.06 * ff + 0.15 * rp);+ continue;+ }+ if (q.sil < 1.15) {+ // the rim: a hard bright edge, whiter where the light catches it+ const lit = -q.X * 0.55 + q.Y * 0.85;+ p.px(q.x, q.y, rp > 0.4 || lit > 0.8 ? WHITE : lit > 0.3 ? C[6] : C[5]);+ p.light(q.x, q.y, C[4], 0.3);+ continue;+ }+ if (hot >= 2) {+ // the hero frame: the struck plates go white+ p.px(q.x, q.y, q.seam ? C[6] : WHITE);+ continue;+ }+ if (q.seam) {+ const I = 0.12 + 0.5 * ff + 0.08 * Math.sin(q.lon * 2.3 + q.lat * 3 - ph * TAU) + (q.corner < 0.32 ? 0.18 : 0) + 0.9 * gl + 0.7 * sc + 1.3 * rp + hot;+ const c = gl > 0.6 || rp > 0.55 || hot > 0.5 ? WHITE : I > 0.8 ? C[6] : I > 0.55 ? C[5] : C[4];+ if (I > 0.36) p.px(q.x, q.y, c);+ else p.blend(q.x + 0.5, q.y + 0.5, c, 0.3 + I);+ p.light(q.x, q.y, C[4], 0.04 + 0.08 * I);+ } else {+ // the glass: thin face-on, thicker toward the rim, a lit top-left edge on every plate+ const a = 0.05 + 0.34 * ff * q.rim + 0.1 * q.e ** 4 + (q.bevel ? 0.12 + 0.2 * ff : 0) + 0.35 * gl + 0.1 * sc + 0.3 * rp + 0.6 * hot;+ const c = hot > 0.6 ? WHITE : hot > 0.3 || gl > 0.5 ? C[6] : rp > 0.4 || q.bevel ? C[5] : ff > 0.5 ? C[4] : C[3];+ p.blend(q.x + 0.5, q.y + 0.5, c, clamp(a));+ if (rp > 0.1 || hot > 0 || gl > 0) p.light(q.x, q.y, C[4], 0.06 * (rp + hot + gl));+ }}- 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));+}++// the dome's foot: a ring on the floor with emitters round it, chasing+function drawFoot(p, t, C, R, near) {+ const D = meta.duration, keep = (g) => (Math.sin(g) >= 0) === near;+ band(p, 0, 0, R + 1, SA, 2, 1, [C[1], C[3], C[5], C[6]], keep);+ for (let i = 0; i < 10; i++) {+ const g = (i / 10) * TAU + 0.31;+ if (!keep(g)) continue;+ const x = Math.cos(g) * (R - 0.5), y = Math.sin(g) * R * SA, k = 0.5 + 0.5 * Math.cos(TAU * (2 * (t / D) - i / 10));+ p.px(x - 1, y, C[2]);+ p.px(x + 1, y, C[2]);+ p.px(x, y, k > 0.6 ? WHITE : C[5]);+ p.glow(x, y, 6 + 4 * k, C[4], (near ? 0.25 : 0.15) * (0.4 + k));+ }+}++export function drawBack(p, t, o) {+ const C = fit(o.palette, 8), R = o.radius;+ for (let x = -R; x <= R; x += R / 3) p.glow(x, -1, 22, C[3], 0.1);+ drawFoot(p, t, C, R, false);+ drawShell(p, t, o, C, false);+}++export function draw(p, t, o) {+ const C = fit(o.palette, 8), SP = fit(o.sparks, 4), R = o.radius, D = meta.duration, W = meta.size[0] - meta.origin[0];+ drawShell(p, t, o, C, true);+ drawFoot(p, t, C, R, true);+ for (const s of SHOTS) {+ const age = since(t, s.t, D), [hx, hy] = project(R, s.lon, s.lat), n = s.big ? 1 : 0.6;+ // the fractures: race out from the hit white-hot, then cool down the ramp and fade+ if (s.big && age < 0.9) {+ const fade = 1 - smooth(0.35, 0.9, age), reach = clamp(age / 0.09);+ for (const pass of [0, 1])+ for (const c of cracks(R, o.seed, s))+ for (let i = 1; i < c.length; i++) {+ const [x0, y0, f0] = c[i - 1], [x1, y1, f1, u] = c[i];+ if (u > reach || f0 < 0.05 || f1 < 0.05) continue;+ const k = fade * (1.2 - u * 0.4);+ if (pass === 0) {+ if (age < 0.32) for (const [ox, oy] of [[1, 0], [-1, 0], [0, 1], [0, -1]]) p.line(x0 + ox, y0 + oy, x1 + ox, y1 + oy, age < 0.12 ? C[6] : C[5], k * (1 - age / 0.32));+ continue;+ }+ p.line(x0, y0, x1, y1, age < 0.12 + u * 0.08 ? WHITE : age < 0.3 + u * 0.1 ? C[6] : C[5], k);+ if (i % 3 === 0) p.glow(x1, y1, 6, C[4], 0.35 * fade * (1 - u * 0.5));+ }+ }+ // the tracer, in from the right: a streak that comes out of the edge, its tail never past where it entered+ const tk = (t - (s.t - 0.1)) / 0.1;+ if (tk >= 0 && tk < 1) {+ const sx = W - 3, sy = hy - 12, L = Math.hypot(sx - hx, sy - hy), at = (d) => [sx + ((hx - sx) * Math.max(0, d)) / L, sy + ((hy - sy) * Math.max(0, d)) / L];+ const h = L * tk, [x, y] = at(h), [x2, y2] = at(h - 2), [x7, y7] = at(h - 7), [x16, y16] = at(h - 16);+ p.line(x16, y16, x7, y7, SP[3]);+ p.line(x7, y7, x2, y2, SP[1]);+ p.line(x2, y2, x, y, SP[0]);+ p.px(x, y, WHITE);+ p.glow(x, y, 9, SP[1], 0.55);+ }+ // the impact: a white star, light that flares and dies+ if (age < 0.14) sparkle(p, hx, hy, (7 * (1 - age / 0.14) + 1) * n, C[6], C[5], 0.4);+ flash(p, t, s.t, hx, hy, 56 * n, C[4], 0.45, 0.45);+ flash(p, t, s.t, hx, hy, 12, WHITE, 0.5 * n, 0.08);+ flash(p, t, s.t, hx + 3, hy, 22, SP[1], 0.4 * n, 0.15);+ }+ // the dome's own light, and what glances off+ const a0 = since(t, SHOTS[0].t, D);+ p.glow(0, -R * 0.45, R * 1.3, C[3], 0.11 + 0.1 * Math.max(0, 1 - a0 * 2));+ ghosts(o, C, R).at(t).draw(p);}diff --git a/src/fx/scifi/glitch.js b/src/fx/scifi/glitch.jsindex bb5dc0a..8453a00 100644--- a/src/fx/scifi/glitch.js+++ b/src/fx/scifi/glitch.js@@ -1,75 +1,107 @@-import { PAL, ramp, rand, rng, WHITE } from "../../core/index.js";-import { steps } from "./_lib.js";+import { fit, clamp, rand, hex, mix, luma, WHITE } from "../../core/index.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,+ desc: "The hero's signal breaks up in bursts: an RGB split, slices torn sideways, rows smeared out, junk blocks and dead pixels, then snaps back clean.",+ tags: ["scifi", "glitch", "digital", "corrupt", "hologram", "status", "loop"],+ size: [88, 64],+ origin: [44, 54],+ duration: 2.4,loop: true,fps: 30,bg: "ground",- actor: true,- options: { palette: PAL.cyber, seed: 28 },+ actor: 2,+ options: { palette: ["#14101f", "#3b1f5c", "#ff2e63", "#ff7aa8", "#2ef2ff", "#b4fbff", "#ffffff"], seed: 7 },};-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;+const FPS = 30, NF = Math.round(meta.duration * FPS);+// the bursts: [first frame, last frame, how hard]+const BURSTS = [[9, 16, 0.8], [33, 37, 0.5], [51, 62, 1]];-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]);-}+// the effect draws the hero itself, clean or broken+export const actorAlpha = () => 0;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]);+ const C = fit(o.palette, 7), A = o.actor, S = o.seed, RED = C[2], CYAN = C[4], f = Math.floor(t * FPS + 1e-6) % NF;+ const burst = BURSTS.find(([a, b]) => f >= a && f <= b), k = burst ? burst[2] : 0, r = (...n) => rand(S, f, ...n);+ // what this frame's corruption is+ const split = burst ? Math.round(1 + r(1) * 3 * k) * (r(2) < 0.5 ? -1 : 1) : 0;+ const tears = [];+ if (burst) for (let i = 0; i < 1 + Math.floor(r(3) * 4 * k); i++) tears.push([A.y + Math.floor(r(4, i) * A.h), 1 + Math.floor(r(5, i) * 5), Math.round((r(6, i) - 0.5) * 16 * k), r(7, i)]);+ // a lone row slips now and then even when it's calm+ if (!burst && r(8) < 0.07) tears.push([A.y + Math.floor(r(9) * A.h), 1, r(10) < 0.5 ? -2 : 2, 1]);+ const interlace = burst && r(11) < 0.3, roll = burst && r(12) < 0.15 ? -2 - Math.floor(r(13) * 2) : 0, poster = burst && r(14) < 0.15 * k;+ const tearAt = (y) => {+ for (const [y0, h, dx, tint] of tears) if (y >= y0 && y < y0 + h) return [dx, tint];+ return null;+ };+ // the calm signal: a faint bar rolling down the body+ const bar = A.y + ((t / meta.duration) * 2 * (A.h + 12)) % (A.h + 12) - 6;++ const px = (x, y, c) => p.px(x, y, c);+ // the split: the red and cyan ghosts first, offset either side+ if (split)+ for (let my = 0; my < A.h; my++)+ for (let mx = 0; mx < A.w; mx++) {+ if (!A.mask.data[my * A.w + mx]) continue;+ const y = A.y + my + roll, tr = tearAt(A.y + my), dx = tr ? tr[0] : 0;+ px(A.x + mx + dx - split, y, RED);+ px(A.x + mx + dx + split, y, CYAN);+ }+ // the body itself, row by row: torn, interlaced, rolled, posterised, tinted where the bar passes+ for (let my = 0; my < A.h; my++) {+ const ry = A.y + my, y = ry + roll;+ if (interlace && (my & 1)) continue;+ const tr = tearAt(ry), dx = tr ? tr[0] : 0, tint = tr && tr[1] < 0.35 ? (tr[1] < 0.18 ? RED : CYAN) : 0, near = Math.abs(ry - bar);+ for (let mx = 0; mx < A.w; mx++) {+ const c = A.pixels[my * A.w + mx];+ if (!c) continue;+ let col = c;+ if (poster) col = luma(c) > 0.32 ? C[5] : C[1];+ else if (tint) col = mix(c, tint, 0.6);+ else if (near < 1) col = mix(c, C[5], 0.35);+ px(A.x + mx + dx, y, col);+ }+ // a torn row smears its edge pixel out sideways, fading+ if (tr && Math.abs(dx) > 2 && rand(S, f, ry) < 0.6) {+ const right = dx > 0, mx = right ? A.w - 1 - [...Array(A.w)].findIndex((_, i) => A.mask.data[my * A.w + A.w - 1 - i]) : [...Array(A.w)].findIndex((_, i) => A.mask.data[my * A.w + i]);+ if (mx >= 0 && mx < A.w) {+ const c = A.pixels[my * A.w + mx], L = 4 + Math.floor(rand(S, f, ry, 1) * 10);+ for (let i = 1; i <= L; i++) p.dot(A.x + mx + dx + (right ? i : -i), y, c, 1 - i / (L + 1));+ }}- 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]);+ // a roll leaves the top slice repeated at the bottom+ if (roll)+ for (let my = 0; my < -roll; my++)+ for (let mx = 0; mx < A.w; mx++) {+ const c = A.pixels[my * A.w + mx];+ if (c && ((mx + my) & 1)) px(A.x + mx, A.y + A.h + roll + my, mix(c, C[1], 0.5));}+ // junk blocks round the body+ if (burst)+ for (let i = 0; i < 2 + Math.floor(r(20) * 5 * k); i++) {+ const w = 2 + Math.floor(r(21, i) * 9), h = 1 + Math.floor(r(22, i) * 3), x = A.x - 6 + Math.floor(r(23, i) * (A.w + 12)), y = A.y + Math.floor(r(24, i) * A.h);+ const c = [WHITE, RED, CYAN, C[5], C[3]][Math.floor(r(25, i) * 5)];+ if (r(26, i) < 0.4) for (let yy = 0; yy < h; yy++) for (let xx = 0; xx < w; xx++) p.px(x + xx, y + yy, (xx + yy) & 1 ? c : C[0]);+ else p.rect(x, y, w, h, c);+ }+ // dead pixels thrown off by a burst, drifting and blinking out+ for (const [a, b, kk] of BURSTS) {+ const age = (f - a + NF) % NF;+ if (age > b - a + 8) continue;+ for (let i = 0; i < 10 * kk; i++) {+ const life = 4 + Math.floor(rand(S, a, i) * 6), at = Math.floor(rand(S, a, i, 1) * (b - a + 1)), q = age - at;+ if (q < 0 || q > life || (q > life / 2 && (q & 1))) continue;+ const x0 = A.x + rand(S, a, i, 2) * A.w, y0 = A.y + rand(S, a, i, 3) * A.h, side = rand(S, a, i, 4) < 0.5 ? -1 : 1;+ p.px(x0 + side * q * (1 + rand(S, a, i, 5) * 2), y0 - q * 0.5, [WHITE, RED, CYAN][i % 3]);}}- // 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);+ // light: a cold flicker in the bursts, the split's colors glowing at its edges+ if (burst) {+ if (f === burst[0]) p.glow(A.x + A.w / 2, A.y + A.h / 2, 26, C[5], 0.4);+ p.glow(A.x + A.w / 2 - split * 4, A.y + A.h / 2, 18, RED, 0.18 * k);+ p.glow(A.x + A.w / 2 + split * 4, A.y + A.h / 2, 18, CYAN, 0.18 * k);}- // 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);+ if (Math.abs(bar - (A.y + A.h / 2)) < A.h / 2 + 3) p.glowLine(A.x - 2, bar, A.x + A.w + 2, bar, 4, C[4], 0.12);}diff --git a/src/fx/scifi/hologram.js b/src/fx/scifi/hologram.jsindex 7258d8b..e7d1ccd 100644--- a/src/fx/scifi/hologram.js+++ b/src/fx/scifi/hologram.js@@ -1,88 +1,139 @@-import { ramp, cycle, rand, TAU, WHITE } from "../../core/index.js";-import { steps } from "./_lib.js";+import { fit, cycle, clamp, smooth, lerp, rand, hex, TAU, WHITE } from "../../core/index.js";+import { since } 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,+ desc: "A floor projector throws a cone of light holding a turning wireframe model: scanlines roll through it, a data ring circles it, and it flickers, tears and jitters.",+ tags: ["scifi", "hologram", "projector", "wireframe", "display", "glitch", "ground", "loop"],+ size: [112, 104],+ origin: [56, 92],+ duration: 4,loop: true,fps: 30,bg: "ground",- options: { palette: ["#061224", "#0c2a4e", "#154e86", "#2484c0", "#4cbce8", "#9ae6ff", "#e6fbff"], size: 7, seed: 21 },+ options: {+ palette: ["#050c1e", "#0a1f48", "#123b80", "#1d64b8", "#2e98e8", "#6cd0ff", "#c8f0ff", "#ffffff"],+ metal: ["#0e0d14", "#1e1c27", "#312e3e", "#4b4759", "#6f6a82", "#9d98b0"],+ split: "#ff4fd8",+ 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;-}+const D = meta.duration, OY = -50, RAD = 16, LENS = -6;+// the model: a tall six-sided crystal, a point at each end and a ring of six round its waist+const VERTS = [[0, 1.45, 0], [0, -1.45, 0], ...Array.from({ length: 6 }, (_, i) => [Math.cos((i / 6) * TAU) * 0.9, 0.12, Math.sin((i / 6) * TAU) * 0.9])];+const FACES = [];+for (let i = 0; i < 6; i++) FACES.push([0, 2 + i, 2 + ((i + 1) % 6)], [1, 2 + ((i + 1) % 6), 2 + i]);+const EDGES = [];+for (let i = 0; i < 6; i++) EDGES.push([0, 2 + i], [1, 2 + i], [2 + i, 2 + ((i + 1) % 6)]);+// when it glitches: [start, length, how hard]+const GLITCHES = [[0.92, 0.12, 1], [2.55, 0.2, 1.4], [3.42, 0.06, 0.7]];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);+ const C = fit(o.palette, 8), H = fit(o.metal, 6), SPLIT = hex(o.split), S = o.seed, ph = t / D, frame = Math.floor(t * 30);+ const gl = GLITCHES.reduce((m, [g0, len, k]) => (t >= g0 && t < g0 + len ? Math.max(m, k) : m), 0);+ const flick = gl > 0 && rand(S, frame) < 0.5 ? 1 : 0;+ // where it sits: a slow bob, a jolt when it glitches+ const cx = gl ? (rand(S, frame, 2) < 0.5 ? -2 : 2) * gl : 0, cy = OY + 1.5 * Math.sin(TAU * ph * 2);+ // the tears this frame: bands of rows knocked sideways+ const tears = [];+ if (gl) for (let i = 0; i < 2; i++) tears.push([Math.floor(cy - RAD + rand(S, frame, i) * RAD * 2), 2 + Math.floor(rand(S, frame, i, 1) * 4), Math.round((rand(S, frame, i, 2) - 0.5) * 10 * gl)]);+ const tearAt = (y) => {+ for (const [y0, h, dx] of tears) if (y >= y0 && y < y0 + h) return dx;+ return 0;+ };+ // every pixel of the hologram goes through here: interlaced, torn, split+ const put = (x, y, c, a = 1) => {+ const yy = Math.floor(y);+ if (flick && (yy & 1)) return;+ const dx = tearAt(yy);+ if (dx) {+ p.dot(x + dx, y, SPLIT, a * 0.8);+ p.dot(x + dx + Math.sign(dx), y, c, a);+ return;+ }+ p.dot(x, y, c, a);+ };- // 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);+ // the projector: a steel drum on the floor with a lens on top and lights round it+ p.shade(-16, -8, 16, 2, (x, y, out) => {+ const top = (x / 15) ** 2 + ((y + 5) / 3) ** 2 <= 1, side = Math.abs(x) <= 15 && y > -5 && y <= 0;+ if (!top && !side) return;+ if (top) out.c = (x / 15) ** 2 + ((y + 5) / 3) ** 2 > 0.8 ? H[0] : y < -6 ? H[5] : H[3];+ else out.c = Math.abs(x) > 14 || y === 0 ? H[0] : y === -4 ? H[4] : x < -6 ? H[3] : x > 6 ? H[1] : H[2];});- 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]);+ p.ellipse(0, LENS + 0.5, 5.5, 1.6, (d) => (d < 0.4 ? WHITE : d < 0.8 ? C[6] : C[4]));+ for (let i = 0; i < 4; i++) {+ const k = 0.5 + 0.5 * Math.cos(TAU * (2 * ph - i / 4));+ p.px(-9 + i * 6, -2, k > 0.7 ? C[6] : 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];- });+ // the cone of light up to the model: thin, fading as it rises, scanlines climbing it+ const top = cy + RAD * 1.3;+ for (let y = Math.ceil(top); y < LENS; y++) {+ const v = (y - LENS) / (top - LENS), w = lerp(4, RAD + 4, v), lineOn = ((((y + t * 24) % 5) + 5) % 5) < 1;+ for (let x = Math.floor(-w); x <= Math.ceil(w); x++) {+ const q = Math.abs(x + 0.5) / w;+ if (q > 1) continue;+ if (q > 1 - 1 / w) put(x, y, v < 0.5 ? C[5] : C[4]);+ else p.blend(x + 0.5, y + 0.5, lineOn ? C[5] : C[4], (0.05 + 0.12 * (1 - v)) * (1 - 0.6 * q * q) + (lineOn ? 0.06 : 0));+ }}- 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]);+ p.glow(0, LENS, 12, C[5], 0.6);+ // the stage the model stands on: a thin ring where the cone ends+ for (let i = 0; i < 56; i++) {+ const a = (i / 56) * TAU - ph * TAU, x = Math.cos(a) * (RAD + 4), y = top + Math.sin(a) * 3;+ if (i % 7 < 5) put(x, y, Math.sin(a) > 0 ? C[6] : C[4], Math.sin(a) > 0 ? 1 : 0.7);+ }+ p.glowLine(-RAD - 4, top, RAD + 4, top, 4, C[4], 0.2);+ // data bits rising through the cone+ cycle(t, D, 18, S + 1, (r) => r.range(0.8, 1.4), (age, life, r) => {+ const k = age / life, y = lerp(LENS - 2, top, k), w = lerp(4, RAD + 2, k);+ put(r.range(-0.8, 0.8) * w, y, r.chance(0.3) ? WHITE : C[5], Math.min(1, (1 - k) * 2));});- // 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);+ // the model: turning once a loop, tilted toward us+ const spin = TAU * ph, tilt = 0.32, P3 = VERTS.map(([x, y, z]) => {+ const x1 = x * Math.cos(spin) + z * Math.sin(spin), z1 = -x * Math.sin(spin) + z * Math.cos(spin);+ const y2 = y * Math.cos(tilt) - z1 * Math.sin(tilt), z2 = y * Math.sin(tilt) + z1 * Math.cos(tilt);+ return [cx + x1 * RAD, cy - y2 * RAD, z2];+ });+ // a scan bar climbing through it, twice a loop+ const scanY = lerp(cy + RAD * 1.5, cy - RAD * 1.5, ((ph * 2) % 1) / 0.8);+ // the faces that face us, filled with scanlines+ for (const f of FACES) {+ const [a, b, c] = f.map((i) => P3[i]), nz = (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]);+ if (nz >= 0) continue;+ const shade = clamp(0.3 + 0.7 * ((a[2] + b[2] + c[2]) / 3 + 0.5));+ p.poly([a, b, c], (x, y) => (Math.abs(y - scanY) < 2 ? C[6] : shade > 0.6 ? C[4] : C[3]), (x, y) => {+ const yy = Math.floor(y);+ return (yy % 3 === 0 && !(flick && yy & 1)) || Math.abs(y - scanY) < 1.5 ? 1 : 0;+ });+ }+ // the edges: the far ones dim, the near ones bright, hot where the scan bar crosses them+ const edges = EDGES.map(([i, j]) => [P3[i], P3[j], (P3[i][2] + P3[j][2]) / 2]).sort((a, b) => a[2] - b[2]);+ for (const [a, b, z] of edges) {+ const L = Math.hypot(b[0] - a[0], b[1] - a[1]);+ for (let d = 0; d <= L; d += 0.5) {+ const x = lerp(a[0], b[0], d / L), y = lerp(a[1], b[1], d / L), hot = Math.abs(y - scanY) < 1.5;+ if (z < -0.15) put(x, y, hot ? C[5] : C[3], 0.7);+ else put(x, y, hot ? WHITE : z > 0.4 ? C[6] : C[5]);+ }+ }+ for (const [x, y, z] of P3) {+ if (z < -0.15) continue;+ put(x, y, WHITE);+ p.glow(x, y, 4, C[5], 0.3);+ }+ // a dashed data ring round its waist, its far half behind+ for (let i = 0; i < 64; i++) {+ const a = (i / 64) * TAU + ph * TAU * 2, x = cx + Math.cos(a) * (RAD + 9), y = cy + 3 + Math.sin(a) * 4;+ if (Math.floor(i / 3) % 3 === 2) continue;+ put(x, y, Math.sin(a) > 0 ? (i % 9 === 0 ? WHITE : C[5]) : C[3], Math.sin(a) > 0 ? 1 : 0.6);+ }+ // light: the model glows, the scan bar glows, a flicker drops the light too+ const lk = flick ? 0.5 : 1;+ p.glow(cx, cy, RAD * 2.2, C[4], 0.36 * lk);+ p.glow(cx, cy - RAD * 0.6, RAD, C[5], 0.15 * lk);+ if (Math.abs(scanY - cy) < RAD * 1.4) p.glowLine(cx - RAD, scanY, cx + RAD, scanY, 5, C[5], 0.3 * lk);+ p.glow(0, -2, 22, C[4], 0.2);}diff --git a/src/fx/scifi/jetpack.js b/src/fx/scifi/jetpack.jsindex b2487f8..922e0d1 100644--- a/src/fx/scifi/jetpack.js+++ b/src/fx/scifi/jetpack.js@@ -1,65 +1,111 @@-import { PAL, RAMP, ramp, at, cycle, rand, clamp, loopNoise, tileFbm, WHITE } from "../../core/index.js";-import { steps } from "./_lib.js";+// The exhaust (flame puffs cooling down the fire ramp into smoke, a warm light over the smoke) follows Sprite+// Fusion's open-source fire (https://www.spritefusion.com/pixel-art-vfx/fire), MIT License,+// Copyright (c) 2026 Hugo Duprez.+import { P, PF, Rng, fit, tileFbm, clamp, lerp, rand, mix, TAU, WHITE } from "../../core/index.js";+import { Ghosts } 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.",+ desc: "Twin thrusters fire straight down: white-hot cores with shock diamonds inside ragged flames, puffs that cool into smoke billowing below, lit by the fire.",tags: ["scifi", "jetpack", "thrust", "rocket", "fire", "smoke", "flight", "loop"],- size: [48, 76],- origin: [24, 10],- duration: 1,+ size: [96, 116],+ origin: [48, 30],+ duration: 2,loop: true,fps: 30,bg: "dark",- options: { palette: PAL.fire, length: 22, gap: 5, seed: 30 },+ options: {+ palette: ["#2a0e12", "#5c1818", "#a02818", "#e0501a", "#ff8a2a", "#ffc23d", "#fff3a6", "#ffffff"],+ metal: ["#0e0d14", "#1e1c27", "#312e3e", "#4b4759", "#6f6a82", "#9d98b0"],+ length: 26,+ seed: 30,+ },};-const METAL = ramp(["#15141c", "#2b2936", "#47445a", "#6c6884", "#9a96b0"]);+const D = meta.duration, GAP = 8, FR = 30;-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;+const cache = new Map();+function ghosts(o, F) {+ const key = `${o.seed}:${o.palette.join()}:${o.length}`;+ if (cache.has(key)) return cache.get(key);+ const rn = new Rng(o.seed), L = o.length;+ const g = new Ghosts(D, { sparks: [WHITE, F[6], F[5], F[4]], box: [-46, -28, 46, 84] });+ for (const s of [-1, 1]) {+ // flame shed off the tip, cooling down the ramp into smoke that's driven down, slows and billows+ for (let i = 0; i < 26; i++) g.add(rn.range(0, D), P.FIRE, s * GAP + rn.range(-1.5, 1.5), L * rn.range(0.55, 0.85), rn.range(-10, 10), rn.range(70, 130), rn.range(0.22, 0.4), 0, rn.range(2.2, 3.4), PF.SMOKES | (rn.chance(0.5) ? PF.BIG : 0));+ for (let i = 0; i < 10; i++) g.add(rn.range(0, D), P.SMOKE, s * GAP + rn.range(-3, 3), L + rn.range(2, 8), s * rn.range(0, 14), rn.range(40, 80), rn.range(1.1, 1.6), 0, rn.range(3, 5), PF.BIG);+ // sparks spat out of the exhaust, embers drifting off it+ for (let i = 0; i < 10; i++) g.add(rn.range(0, D), P.SPARK, s * GAP + rn.range(-1, 1), L * rn.range(0.3, 0.7), s * rn.range(-40, 60), rn.range(80, 200), rn.range(0.2, 0.45));+ for (let i = 0; i < 5; i++) g.add(rn.range(0, D), P.EMBER, s * GAP + rn.range(-2, 2), L * rn.range(0.6, 1), s * rn.range(10, 40), rn.range(20, 60), rn.range(0.6, 1.1), F[4], rn.range(0.8, 1.6));+ }+ cache.set(key, g);+ return g;+}- // 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);+// the pack: twin tanks with rounded caps, a spine between them, belled nozzles glowing hot inside+function pack(p, H, F, dy) {+ for (const s of [-1, 1]) {+ const cx = s * GAP;+ p.shade(cx - 5, -24 + dy, cx + 5, -3 + dy, (x, y, out) => {+ const u = (x - cx) / 4.5, top = -19 + dy, v = y < top ? (y - top) / 4.5 : 0;+ if (u * u + v * v > 1) return;+ const l = -u * 0.8 - v * 0.6;+ out.c = u * u + v * v > 0.78 ? H[0] : Math.abs(y - (-12 + dy)) < 0.6 ? H[1] : l > 0.55 ? H[5] : l > 0.15 ? H[4] : l > -0.35 ? H[3] : H[2];});- });+ // the nozzle bell, wider at its mouth, its inside lit by the flame+ for (let y = -3; y <= 0; y++) {+ const w = 2 + (y + 3) * 0.7;+ for (let x = Math.floor(cx - w); x <= Math.ceil(cx + w); x++) {+ const inner = Math.abs(x + 0.5 - cx) < w - 1.2 && y >= -1;+ p.px(x, y + dy, inner ? (y === 0 ? F[6] : F[4]) : Math.abs(x + 0.5 - cx) > w - 0.6 ? H[0] : x < cx ? H[3] : H[1]);+ }+ }+ }+ for (let y = -20; y <= -6; y++) p.px(-1, y + dy, H[1]), p.px(0, y + dy, H[2]), p.px(1, y + dy, H[0]);+ // a status light on the spine+ p.px(0, -16 + dy, F[5]);+}+export function draw(p, t, o) {+ const F = fit(o.palette, 8), H = fit(o.metal, 6), ph = t / D, f = Math.floor(t * FR) % Math.round(D * FR), S = o.seed;+ const dy = Math.round(Math.sin(TAU * 12 * ph) * 0.6);+ const g = ghosts(o, F).at(t);+ // smoke and spent flame behind, then the plumes+ g.draw(p, "back");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));+ const cx = s * GAP + (rand(S, f, s) < 0.15 ? s * 0.5 : 0), L = o.length * (0.92 + 0.08 * Math.sin(TAU * 7 * ph + s) + 0.06 * (rand(S, f, s, 1) - 0.5));+ // the flame: a cone of heat torn ragged by noise streaming down it, white at its heart, red at its edges+ p.shade(cx - 7, dy, cx + 7, dy + L + 4, (x, y, out) => {+ const v = (y - dy) / L, w = lerp(3.4, 0.6, v) + 1.4 * Math.sin(v * Math.PI) * (v < 1 ? 1 : 0);+ const n = tileFbm((x - cx) / 3 + s * 5, (y - dy) / 4 - ph * 20, 0, 10, S + (s > 0 ? 9 : 0), 2), q = Math.abs(x - cx) / w + n * 0.45;+ if (v > 1.15 || q > 1.2) return;+ const heat = (1 - v) * 1.15 - q * 0.9 + n * 0.25;+ // a dark red rim round the flame, so it reads as a shape and not a smear+ if (q > 0.95) {+ out.c = heat > 0.2 ? F[3] : F[2];+ if (heat < -0.3) out.a = 0.5;+ return;+ }+ out.c = heat > 0.82 ? WHITE : heat > 0.62 ? F[6] : heat > 0.42 ? F[5] : heat > 0.22 ? F[4] : heat > 0.02 ? F[3] : F[2];});- 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]);+ // shock diamonds: bright knots strung down the core, breathing+ for (let i = 0; i < 3; i++) {+ const y = Math.round(dy + 5 + i * 6.5 + Math.sin(TAU * 4 * ph + i) * 0.5), r = Math.round(2.2 - i * 0.45 + 0.4 * Math.sin(TAU * 8 * ph + i * 2));+ if (y > dy + L * 0.75 || r < 1) break;+ for (let yy = -r; yy <= r; yy++)+ for (let xx = -r; xx <= r; xx++) {+ const d = Math.abs(xx) + Math.abs(yy);+ if (d <= r) p.px(cx + xx, y + yy, d < r ? WHITE : i === 0 ? F[6] : F[5]);+ }+ p.glow(cx, y, 6, F[6], 0.35);+ }+ // light: hot at the nozzle, warm down the plume+ p.glow(cx, dy + 2, 9, WHITE, 0.45);+ p.glow(cx, dy + L * 0.45, L * 0.8, F[4], 0.35);}- 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)));+ pack(p, H, F, dy);+ g.draw(p, "front");+ // the fire lights the smoke below it, and its own surroundings+ p.glow(0, o.length + 14, 34, F[4], 0.16);+ p.glow(0, o.length * 0.4, 30, F[5], 0.18);}diff --git a/src/fx/scifi/laser-grid.js b/src/fx/scifi/laser-grid.jsindex fc9fa93..88ba1f3 100644--- a/src/fx/scifi/laser-grid.js+++ b/src/fx/scifi/laser-grid.js@@ -1,74 +1,160 @@-import { ramp, cycle, TAU, WHITE } from "../../core/index.js";-import { steps, zap } from "./_lib.js";+// The beam's build (the ramp across it, a hot core, light along it) is adapted from Sprite Fusion's open-source+// energy beam (https://www.spritefusion.com/pixel-art-vfx/energy), MIT License, Copyright (c) 2026 Hugo Duprez.+import { P, Rng, fit, sparkle, tileFbm, clamp, lerp, rand, hex, mix, TAU, WHITE } from "../../core/index.js";+import { Ghosts } 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,+ desc: "Security lasers between two steel posts: red beams slide and scissor across, dust and haze light up only where they cut through, and the floor sweepers scorch and spark.",+ tags: ["scifi", "laser", "security", "trap", "hazard", "beam", "ground", "loop"],+ size: [128, 84],+ origin: [64, 76],+ duration: 3,loop: true,fps: 30,bg: "ground",- options: { palette: ["#1a0408", "#4a0a12", "#8a1020", "#d01c2a", "#ff4a4a", "#ff9a90", "#ffe4e0", "#ffffff"], seed: 31 },+ options: {+ palette: ["#1a0408", "#4a0a12", "#8a1020", "#d01c2a", "#ff4a4a", "#ff9a90", "#ffe4e0", "#ffffff"],+ metal: ["#0e0d14", "#1e1c27", "#312e3e", "#4b4759", "#6f6a82", "#9d98b0"],+ 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]];+const D = meta.duration, PX = 48, TOP = -64, IN = PX - 4; // posts at ±PX, TOP high; beams leave their inner faces+// the sliding beams: [middle height, swing, sweeps a loop, phase]+const SLIDE = [[-14, 8, 1, 0], [-31, 12, 2, 1.3], [-48, 9, 1, 3.6]];+// the sweepers: from each post's head down to a spot on the floor that runs to and fro+const sweepX = (t, s) => s * (34 - 68 * (0.5 - 0.5 * Math.cos(TAU * (t / D) + (s > 0 ? 0 : 1.9))));+const slideY = (t, [y, a, n, f]) => y + a * Math.sin(TAU * n * (t / D) + f);-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]);+function beams(t) {+ const out = SLIDE.map((b) => [-IN, slideY(t, b), IN, slideY(t, b)]);+ for (const s of [-1, 1]) out.push([s * IN, TOP + 6, sweepX(t, s), 0]);+ return out;+}++// a laser: a white-hot core, a red body either side, a dithered fringe, haze lighting up along it+function laser(p, b, C, t, seed) {+ const [x0, y0, x1, y1] = b, steep = Math.abs(y1 - y0) > Math.abs(x1 - x0), ox = steep ? 1 : 0, oy = steep ? 0 : 1;+ for (const s of [-1, 1]) p.line(x0 + s * ox, y0 + s * oy, x1 + s * ox, y1 + s * oy, s < 0 ? C[4] : C[3]);+ p.line(x0, y0, x1, y1, (u) => ((((u * 5 - t * 3) % 1) + 1) % 1 < 0.12 ? C[6] : WHITE));+ // the haze it passes through scatters its light, so its glow is uneven and drifts+ const L = Math.hypot(x1 - x0, y1 - y0);+ for (let d = 0; d <= L; d += 5) {+ const x = lerp(x0, x1, d / L), y = lerp(y0, y1, d / L), h = 0.5 + 0.5 * tileFbm(x / 14 + (t / D) * 4, y / 10, 4, 0, seed);+ p.glow(x, y, 6 + 4 * h, C[3], 0.14 + 0.3 * h * h);}- 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]);+}++// where two beams cross, if they do+function cross(a, b) {+ const [x1, y1, x2, y2] = a, [x3, y3, x4, y4] = b, d = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4);+ if (Math.abs(d) < 1e-6) return null;+ const u = ((x1 - x3) * (y3 - y4) - (y1 - y3) * (x3 - x4)) / d, v = -((x1 - x2) * (y1 - y3) - (y1 - y2) * (x1 - x3)) / d;+ return u >= 0 && u <= 1 && v >= 0 && v <= 1 ? [x1 + u * (x2 - x1), y1 + u * (y2 - y1)] : null;+}+function near(b, x, y) {+ const [x0, y0, x1, y1] = b, dx = x1 - x0, dy = y1 - y0, u = clamp(((x - x0) * dx + (y - y0) * dy) / (dx * dx + dy * dy)), ex = x0 + dx * u - x, ey = y0 + dy * u - y;+ return Math.sqrt(ex * ex + ey * ey);+}++// a steel post: a lit edge, a shaded side, a groove the emitters ride in, red light where the beams meet it+function post(p, s, H, C, t) {+ const x0 = s * PX - 4, B = SLIDE.map((b) => slideY(t, b));+ for (let y = TOP + 4; y < 0; y++) {+ const glint = Math.max(...B.map((by) => Math.exp(-(((y - by) / 2.5) ** 2))));+ for (let i = 0; i < 8; i++) {+ const x = x0 + i, inner = s < 0 ? i >= 6 : i <= 1;+ let c = i === 0 || i === 7 ? H[0] : i === 1 ? H[4] : i === 2 ? H[3] : i === 4 ? H[1] : i === 6 ? H[2] : H[3];+ if (inner && i !== 0 && i !== 7 && glint > 0.35) c = glint > 0.75 ? C[5] : C[3];+ p.px(x, y, c);+ }}+ // bolts down the post, the head with its lens, the foot plate+ for (let y = TOP + 12; y < -4; y += 9) p.px(x0 + 3, y, H[5]);+ for (let y = TOP; y < TOP + 10; y++)+ for (let i = -1; i < 9; i++) p.px(x0 + i, y, i === -1 || i === 8 || y === TOP || y === TOP + 9 ? H[0] : y === TOP + 1 ? H[5] : i < 3 ? H[4] : H[2]);+ p.px(s * IN, TOP + 6, WHITE);+ p.px(s * IN, TOP + 5, C[5]);+ p.px(s * IN, TOP + 7, C[4]);+ for (let i = -3; i < 11; i++) p.px(x0 + i, -2, i === -3 || i === 10 ? H[0] : H[4]), p.px(x0 + i, -1, i === -3 || i === 10 ? H[0] : H[2]), p.px(x0 + i, 0, H[1]);+ // a carriage for each sliding beam, riding the groove+ for (const by of B) {+ const y = Math.round(by);+ for (let j = -2; j <= 2; j++)+ for (let i = 0; i < 4; i++) p.px(s < 0 ? x0 + 5 + i : x0 - 1 + i, y + j, Math.abs(j) === 2 || i === (s < 0 ? 3 : 0) ? H[0] : j < 0 ? H[5] : H[3]);+ p.px(s * IN, y, WHITE);+ p.glow(s * IN, y, 7, C[4], 0.55);+ }+ p.glow(s * IN, TOP + 6, 8, C[4], 0.55);+}- // 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);+const cache = new Map();+function ghosts(o, C) {+ const key = `${o.seed}:${o.palette.join()}`;+ if (cache.has(key)) return cache.get(key);+ const rn = new Rng(o.seed), g = new Ghosts(D, { ground: () => 0, sparks: [WHITE, C[6], C[4], C[3]], box: [-62, -80, 62, 7] });+ // the sweepers kick up sparks and wisps of smoke where they burn the floor+ for (let i = 0; i < 36; i++) {+ const tb = (i / 36) * D + rn.range(0, 0.05), s = i % 2 ? 1 : -1, x = sweepX(tb, s), dir = Math.sign(sweepX(tb + 0.02, s) - x) || 1, a = -Math.PI / 2 - dir * rn.range(0.2, 1.1);+ g.add(tb, P.SPARK, x, -1, Math.cos(a) * rn.range(50, 140), Math.sin(a) * rn.range(50, 140), rn.range(0.2, 0.45));+ if (i % 4 === 0) g.add(tb, P.SMOKE, x, -2, rn.range(-4, 4), -rn.range(6, 14), rn.range(0.8, 1.2), hex("#3a2a30"), rn.range(1.6, 2.4));}- 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);+ cache.set(key, g);+ return g;+}++export function draw(p, t, o) {+ const C = fit(o.palette, 8), H = fit(o.metal, 6), B = beams(t), S = o.seed;+ // the floor where the sweepers have just been: a scorch that cools from white to deep red+ for (const s of [-1, 1])+ for (let k = 0; k < 14; k++) {+ const ago = k * 0.025, x = sweepX(t - ago, s), c = k < 2 ? WHITE : k < 5 ? C[6] : k < 9 ? C[4] : C[3];+ p.dot(x, 0, c, 1 - k / 14);+ p.dot(x, 1, C[3], 0.6 - k / 24);+ }+ // a low red pool on the floor under it all+ for (let x = -40; x <= 40; x += 20) p.glow(x, -2, 20, C[3], 0.12);+ // haze hanging in the air, thickest low down, seen only where a beam passes through it and lights it red+ const ph = t / D;+ for (let y = -60; y < 0; y++)+ for (let x = -IN + 1; x < IN; x++) {+ let d = 99;+ for (const b of B) d = Math.min(d, near(b, x + 0.5, y + 0.5));+ if (d > 11) continue;+ const low = 0.35 + 0.65 * clamp((y + 60) / 50), n = 0.5 + 0.5 * tileFbm((x + 0.5) / 18 + ph * 3, (y + 0.5) / 7 + 0.4 * Math.sin(TAU * ph), 3, 0, S + 7, 2), dens = clamp((n - 0.42) * 2.2) * low;+ if (dens <= 0.02) continue;+ const lit = Math.exp(-d / 4.5);+ p.blend(x + 0.5, y + 0.5, lit > 0.5 ? C[4] : lit > 0.15 ? C[3] : C[1], dens * 0.8 * lit);+ }+ for (const s of [-1, 1]) post(p, s, H, C, t);+ for (const b of B) laser(p, b, C, t, S);+ // dust and haze motes, invisible until a beam catches them+ for (let i = 0; i < 90; i++) {+ const x = (rand(S, i) * 2 - 1) * (IN - 3) + 4 * Math.sin(TAU * (t / D) + i), y = -2 - rand(S, i, 1) * 62 + 3 * Math.sin(TAU * 2 * (t / D) + i * 1.7);+ let d = 9;+ for (const b of B) d = Math.min(d, near(b, x, y));+ if (d < 1.6) {+ p.px(x, y, d < 0.9 ? WHITE : C[6]);+ p.glow(x, y, 3, C[5], 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;- }+ // where beams cross, the haze between them flares+ for (let i = 0; i < B.length; i++)+ for (let j = i + 1; j < B.length; j++) {+ const c = cross(B[i], B[j]);+ if (!c) continue;+ p.glow(c[0], c[1], 9, C[5], 0.4);+ sparkle(p, c[0], c[1], 2, C[6], C[5], 0.3);}- });-- // the posts, with a lit rail on their inner faces+ // the sweepers' hot spots on the floorfor (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]);+ const x = sweepX(t, s);+ p.px(x, -1, WHITE);+ p.px(x - 1, 0, C[6]);+ p.px(x + 1, 0, C[6]);+ p.glow(x, -1, 10, C[4], 0.55);+ p.glow(x, -1, 4, WHITE, 0.35);}+ ghosts(o, C).at(t).draw(p);}diff --git a/src/fx/scifi/radar-ping.js b/src/fx/scifi/radar-ping.jsdeleted file mode 100644index d3677d5..0000000--- a/src/fx/scifi/radar-ping.js+++ /dev/null@@ -1,59 +0,0 @@-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.jsindex c562092..3c9f98d 100644--- a/src/fx/scifi/scanner.js+++ b/src/fx/scifi/scanner.js@@ -1,58 +1,131 @@-import { PAL, ease, rand, WHITE } from "../../core/index.js";-import { steps } from "./_lib.js";+import { P, fit, sparkle, clamp, smooth, lerp, ease, rand, TAU, WHITE } from "../../core/index.js";+import { Ghosts, since } 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,+ desc: "Brackets snap onto the hero, a scan line sweeps head to toe leaving a cooling outline, and a readout counts up to OK before it all lets go.",+ tags: ["scifi", "scan", "target", "hud", "tech", "status", "ui", "loop"],+ size: [112, 78],+ origin: [42, 58],+ duration: 3.2,loop: true,fps: 30,bg: "ground",- actor: true,- options: { palette: PAL.cyber, seed: 22 },+ actor: 2,+ options: { palette: ["#03140a", "#06301a", "#0c5a2c", "#16893e", "#2cc256", "#7cf08c", "#d0ffd4", "#ffffff"], 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];+const D = meta.duration, LOCK = 0.3, SCAN0 = 0.42, SCAN1 = 1.6, DONE = 1.75, LET = 2.5;++// the body: its outline pixels by row, and each row's extent, worked out once per actor+const bodies = new WeakMap();+function body(A) {+ let b = bodies.get(A);+ if (b) return b;+ const m = A.mask, on = (x, y) => x >= 0 && y >= 0 && x < m.w && y < m.h && m.data[y * m.w + x];+ const edge = [], rows = new Map();+ for (let y = -1; y <= m.h; y++)+ for (let x = -1; x <= m.w; x++) {+ if (on(x, y)) {+ const r = rows.get(A.y + y) ?? [A.x + x, A.x + x];+ rows.set(A.y + y, [Math.min(r[0], A.x + x), Math.max(r[1], A.x + x)]);+ } else if (on(x - 1, y) || on(x + 1, y) || on(x, y - 1) || on(x, y + 1)) edge.push([A.x + x, A.y + y]);+ }+ bodies.set(A, (b = { edge, rows }));+ return b;+}- // 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);+const scanY = (t, A) => lerp(A.y - 3, 1, ease.inOutSine(clamp((t - SCAN0) / (SCAN1 - SCAN0))));+const scanT = (y, A) => SCAN0 + ((SCAN1 - SCAN0) * Math.acos(1 - 2 * clamp((y + 0.5 - (A.y - 3)) / (4 - A.y)))) / Math.PI;- // 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;- });+// an L-shaped bracket: two arms from a corner, a hot pixel at the corner+function bracket(p, x, y, sx, sy, L, c, hot, a) {+ p.line(x, y, x + sx * L, y, c, a);+ p.line(x, y, x, y + sy * L, c, a);+ p.line(x + sx, y + sy, x + sx * 3, y + sy, c, a * 0.6);+ p.dot(x, y, hot, a);+}- // 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]);+const ghostCache = new WeakMap();+function ghosts(o, A, C) {+ const key = `${o.seed}:${o.palette.join()}`, byActor = ghostCache.get(A) ?? new Map();+ ghostCache.set(A, byActor);+ if (byActor.has(key)) return byActor.get(key);+ const { rows } = body(A), g = new Ghosts(D, { ground: () => 0, box: [-40, -58, 68, 9] });+ // data bits flicked off the body's edges as the line crosses them+ for (let y = A.y; y < 0; y += 3) {+ const r = rows.get(y);+ if (!r) continue;+ for (const [x, s] of [[r[0] - 1, -1], [r[1] + 1, 1]])+ if (rand(o.seed, y, s) < 0.6) g.add(scanT(y, A), P.MOTE, x, y, s * (30 + 50 * rand(y, s, 3)), -10 + 20 * rand(y, s, 4), 0.2 + 0.15 * rand(y, s, 5), rand(y, s, 6) < 0.4 ? WHITE : C[5], 0.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);+ byActor.set(key, g);+ return g;+}- // 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]);+export function draw(p, t, o) {+ const C = fit(o.palette, 8), A = o.actor, { edge, rows } = body(A);+ // the box the brackets lock to, and how far out they are: closing in with a snap, letting go at the end+ const bx0 = A.x - 4, bx1 = A.x + A.w + 3, by0 = A.y - 4, by1 = 3;+ const lock = ease.outBack(clamp(t / LOCK), 2.2), out = ease.inCubic(clamp((t - LET) / 0.45)), spread = (1 - lock) * 14 + out * 12;+ const gone = t > LET + 0.45 || (t > LET + 0.25 && Math.floor((t - LET) * 20) % 2 === 1), vis = gone ? 0 : 1, flash = (t > LOCK && t < LOCK + 0.07) || (t > DONE && t < DONE + 0.05) || (t > DONE + 0.12 && t < DONE + 0.17);+ const bc = flash ? WHITE : C[5], L = 7;+ if (vis > 0)+ for (const [x, y, sx, sy] of [[bx0 - spread, by0 - spread, 1, 1], [bx1 + spread, by0 - spread, -1, 1], [bx0 - spread, by1 + spread, 1, -1], [bx1 + spread, by1 + spread, -1, -1]]) {+ bracket(p, x, y, sx, sy, L, bc, WHITE, vis);+ p.glow(x, y, 6, C[4], 0.35 * vis);+ }+ // on lock: a box flashes out from the brackets+ const lk = (t - LOCK) / 0.3;+ if (lk >= 0 && lk < 1) {+ const e = 3 + 10 * ease.outCubic(lk), c = lk < 0.25 ? WHITE : lk < 0.5 ? C[6] : lk < 0.75 ? C[5] : C[3];+ p.line(bx0 - e, by0 - e, bx1 + e, by0 - e, c);+ p.line(bx0 - e, by1 + e, bx1 + e, by1 + e, c);+ p.line(bx0 - e, by0 - e, bx0 - e, by1 + e, c);+ p.line(bx1 + e, by0 - e, bx1 + e, by1 + e, c);+ }+ // the outline, lit row by row as the line passes and cooling behind it+ const pulse = since(t, DONE, D) < 0.3 ? 1 - since(t, DONE, D) / 0.3 : 0, offY = lerp(A.y - 2, 2, clamp((t - LET) / 0.4));+ if (t > SCAN0)+ for (const [x, y] of edge) {+ const a = t - scanT(y, A);+ if (a < 0 || (t > LET && y < offY)) continue;+ const c = pulse > 0.4 ? WHITE : a < 0.07 ? WHITE : a < 0.25 ? C[6] : a < 0.6 ? C[5] : t > LET - 0.3 ? C[3] : C[4];+ p.px(x, y, c);+ }+ // the scan line and the slice of light just above it+ if (t > SCAN0 && t < SCAN1) {+ const y = Math.floor(scanY(t, A));+ for (let k = 1; k <= 5; k++) {+ const r = rows.get(y - k);+ if (r) for (let x = r[0]; x <= r[1]; x++) if (A.mask.data[(y - k - A.y) * A.w + x - A.x]) p.blend(x + 0.5, y - k + 0.5, k < 2 ? C[6] : C[5], 0.55 - k * 0.09);+ }+ for (let x = bx0 - 2; x <= bx1 + 2; x++) {+ const r = rows.get(y), inside = r && x >= r[0] && x <= r[1];+ p.px(x, y, inside ? WHITE : C[6]);+ p.blend(x + 0.5, y - 0.5, C[5], 0.35);+ }+ p.glowLine(bx0, y, bx1, y, 6, C[5], 0.45);+ const r = rows.get(y);+ if (r) for (const x of [r[0] - 0.5, r[1] + 1.5]) sparkle(p, x, y + 0.5, 2, C[6], C[5], 0.3);}- // 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]);+ // the readout: a leader from the top-right bracket to a panel, a count, a bar filling, then OK+ const lead = clamp((t - LOCK) / 0.1);+ if (vis > 0 && lead > 0) {+ const px = bx1 + spread + 6, py = by0 - spread + 2, k = clamp((t - SCAN0) / (SCAN1 - SCAN0)), ok = t > DONE;+ p.line(bx1 + spread, by0 - spread, lerp(bx1 + spread, px - 1, lead), lerp(by0 - spread, py + 4, lead), C[3]);+ if (lead < 1) return void ghosts(o, A, C).at(t).draw(p);+ p.line(px - 1, py + 4, px + 1, py + 4, C[3]);+ const del = clamp((t - LET) / 0.25), full = ok ? "OK" : `${Math.floor(k * 100)}%`, label = full.slice(0, Math.ceil(full.length * (1 - del)));+ const blinkOk = ok && Math.floor((t - DONE) * 8) % 2 === 0 && t < DONE + 0.5;+ if (label) p.text(label, px + 2, py, blinkOk ? WHITE : C[6], { font: "mini", scale: 2, shadow: C[1] });+ // the bar: ten cells filling as it goes, emptying from the right as it lets go+ for (let i = 0; i < 10; i++) {+ if (i >= 10 * (1 - del)) break;+ const on = (i + 1) / 10 <= k + 1e-6 || ok;+ p.rect(px + 2 + i * 3, py + 13, 2, 3, on ? (ok ? C[6] : C[5]) : C[2]);+ }+ p.glow(px + 16, py + 6, 18, C[4], 0.2 * vis);}+ ghosts(o, A, C).at(t).draw(p);}diff --git a/src/fx/scifi/teleporter-pad.js b/src/fx/scifi/teleporter-pad.jsindex d4b0f20..17aa24b 100644--- a/src/fx/scifi/teleporter-pad.js+++ b/src/fx/scifi/teleporter-pad.js@@ -1,68 +1,116 @@-import { PAL, ramp, cycle, wrap, TAU, WHITE } from "../../core/index.js";-import { steps } from "./_lib.js";+// The rising band and the column of light it rides in follow Sprite Fusion's open-source heal+// (https://www.spritefusion.com/pixel-art-vfx/heal), MIT License, Copyright (c) 2026 Hugo Duprez.+import { P, Rng, fit, band, sparkle, cycle, clamp, lerp, ease, rand, mix, TAU, WHITE } from "../../core/index.js";+import { Ghosts, since } 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,+ desc: "A steel pad glows on the floor, its rings rippling outward; a soft column of light rises off it and rings of light lift away, sparkles drifting up through them.",+ tags: ["scifi", "teleporter", "pad", "portal", "beam", "spawn", "ground", "loop"],+ size: [96, 104],+ origin: [48, 92],+ duration: 2.4,loop: true,fps: 30,bg: "ground",- options: { palette: PAL.neon, radius: 16, seed: 26 },+ options: {+ palette: ["#120a26", "#26145a", "#3c2296", "#5a3ad2", "#7f66f0", "#b4a2ff", "#e6deff", "#ffffff"],+ metal: ["#0e0d14", "#1e1c27", "#312e3e", "#4b4759", "#6f6a82", "#9d98b0"],+ seed: 26,+ },};-const METAL = ramp(["#121119", "#24222f", "#3a3748", "#575369", "#7d7891", "#a7a2b8"]);-const RINGS = 4, RISE = 1.2, TOP = -54;+const D = meta.duration, RX = 31, RY = 7, PY = -3, IN = 0.78, HIGH = -84;-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));- });+const cache = new Map();+function ghosts(o, C) {+ const key = `${o.seed}:${o.palette.join()}`;+ if (cache.has(key)) return cache.get(key);+ const rn = new Rng(o.seed), g = new Ghosts(D, { box: [-46, -90, 46, 10] });+ // motes and sparkles drifting up through the column+ for (let i = 0; i < 40; i++) {+ const a = rn.range(0, TAU), r = Math.sqrt(rn.next()) * RX * IN * 0.9, star = i % 3 === 0;+ g.add(rn.range(0, D), star ? P.STAR : P.MOTE, Math.cos(a) * r, PY + Math.sin(a) * r * (RY / RX), rn.range(-4, 4), -rn.range(30, 75), rn.range(0.7, 1.3), rn.pick([WHITE, C[6], C[5]]), star ? rn.range(1.8, 3.4) : rn.range(0.6, 1.2));+ }+ cache.set(key, g);+ return g;+}- // 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));+// the pad: a steel rim with a lit far edge, a recessed disc of light whose rings ripple outward, a hot middle+function pad(p, t, C, H) {+ const ph = t / D;+ p.shade(-RX - 1, PY - RY - 1, RX + 1, 2, (x, y, out) => {+ const u = x / RX, v = (y - PY) / RY, d = Math.sqrt(u * u + v * v);+ // the drum's side, below the top face+ if (d > 1) {+ if (Math.abs(x) <= RX && y > PY && y <= 1 && Math.sqrt(u * u + ((y - 3 - PY) / RY) ** 2) <= 1) out.c = y === 1 || Math.abs(x) > RX - 1 ? H[0] : x < -RX * 0.4 ? H[3] : x > RX * 0.4 ? H[1] : H[2];+ return;}- };- 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];+ if (d > 0.97) return (out.c = H[0]);+ if (d > IN) {+ // the rim: lit along its far edge, shadowed on the near one, a seam round it+ out.c = Math.abs(d - (IN + 0.1)) < 0.03 ? H[1] : d < IN + 0.03 ? C[3] : v < -0.3 ? H[5] : v < 0.2 ? H[4] : H[3];+ return;+ }+ // the light well: rings rolling outward, brighter toward the middle+ const r = d / IN, ring = ((((r * 3 - ph * 3) % 1) + 1) % 1) < 0.16, heat = (1 - r) ** 1.5;+ out.c = r > 0.94 ? C[3] : ring ? (heat > 0.3 ? WHITE : C[6]) : heat > 0.55 ? C[6] : heat > 0.25 ? C[5] : r > 0.8 ? C[3] : 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]);+ // emitters round the rim, chasing+ for (let i = 0; i < 10; i++) {+ const a = (i / 10) * TAU + 0.15, x = Math.cos(a) * RX * 0.885, y = PY + Math.sin(a) * RY * 0.885, k = 0.5 + 0.5 * Math.cos(TAU * (2 * ph - i / 10));+ p.px(x, y, k > 0.7 ? WHITE : k > 0.4 ? C[5] : C[2]);+ if (k > 0.5) p.glow(x, y, 4, C[4], 0.35 * k);+ }+}- ring(true);+// a ring of light lifting off the pad: crisp lines stepping down the ramp as it climbs, a glint running round it;+// its far half or its near half+function lift(p, t, C, near) {+ for (let i = 0; i < 4; i++) {+ const k = since(t, (i / 4) * D, D) / 1.25;+ if (k >= 1) continue;+ const y = lerp(PY, HIGH + 12, Math.pow(k, 0.85)), rx = RX * IN * (1 + 0.08 * k), ry = rx * (RY / RX), c = k < 0.12 ? WHITE : k < 0.4 ? C[6] : k < 0.65 ? C[5] : k < 0.85 ? C[4] : C[3];+ const glint = ((i * 0.37 + k * 1.5) % 1) * TAU;+ for (let j = 0, n = Math.ceil(rx * 7); j < n; j++) {+ const g = (j / n) * TAU, sg = Math.sin(g);+ if (sg >= 0 !== near) continue;+ const x = Math.cos(g) * rx, yy = y + sg * ry, hot = Math.abs(((g - glint + Math.PI * 3) % TAU) - Math.PI) < 0.25;+ if (k > 0.85 && (j & 1)) continue;+ p.px(x, yy, hot && k < 0.8 ? WHITE : near ? c : k < 0.4 ? C[5] : C[3]);+ if (k < 0.3) p.px(x, yy + 1, near ? C[5] : C[3]);+ }+ if (near) p.glow(0, y + ry * 0.5, rx + 8, C[4], 0.22 * (1 - k));+ }+}- // 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]);+export function drawBack(p, t, o) {+ const C = fit(o.palette, 8), H = fit(o.metal, 6), ph = t / D;+ pad(p, t, C, H);+ // the column: a soft tube of light standing on the well, fading as it rises, light drawn up it+ const W = RX * IN;+ for (let y = HIGH; y < PY; y++) {+ const v = (y - PY) / (HIGH - PY), fade = (1 - v) ** 1.6;+ for (let x = Math.floor(-W); x <= Math.ceil(W); x++) {+ const q = Math.abs(x + 0.5) / W;+ if (q > 1) continue;+ p.blend(x + 0.5, y + 0.5, q > 0.9 ? C[6] : C[5], fade * (0.07 + 0.26 * q ** 4 + 0.12 * (1 - v) ** 4));+ }+ }+ cycle(t, D, 30, o.seed + 3, (r) => r.range(0.6, 1.1), (age, life, r) => {+ const k = age / life, x = r.range(-0.9, 0.9) * W, y = lerp(PY - 2, HIGH + 10, k), L = 3 + 7 * k;+ p.line(x, y, x, y + L, (u) => (u < 0.3 ? C[6] : C[4]), (1 - k) * 1.2);});+ lift(p, t, C, false);+ for (let y = PY - 6; y > HIGH + 20; y -= 12) p.glow(0, y, W + 8, C[4], 0.16 * (1 - (y - PY) / (HIGH - PY)));+}- p.glow(0, -3, R + 8, C[4], 0.35);- p.glow(0, -3, 6, C[6], 0.3);+export function draw(p, t, o) {+ const C = fit(o.palette, 8), ph = t / D;+ lift(p, t, C, true);+ ghosts(o, C).at(t).draw(p);+ // the light: a pool on the floor, a hot heart to the well, pulsing+ const k = 0.85 + 0.15 * Math.sin(TAU * 2 * ph);+ for (const x of [-RX * 0.6, 0, RX * 0.6]) p.glow(x, PY, 20, C[4], 0.25 * k);+ p.glow(0, PY, 10, WHITE, 0.3 * k);}diff --git a/src/fx/scifi/tractor-beam.js b/src/fx/scifi/tractor-beam.jsindex bbed12f..120b64d 100644--- a/src/fx/scifi/tractor-beam.js+++ b/src/fx/scifi/tractor-beam.js@@ -1,70 +1,231 @@-import { ramp, at, cycle, ease, TAU, WHITE } from "../../core/index.js";-import { steps } from "./_lib.js";+// Rocks torn out of the floor with a puff of dust, then hauled up spinning, and matter drawn in as streaks,+// follow Sprite Fusion's open-source black hole (https://www.spritefusion.com/pixel-art-vfx/black-hole),+// MIT License, Copyright (c) 2026 Hugo Duprez.+import { P, Rng, fit, sparkle, cycle, clamp, smooth, lerp, ease, rand, mix, scale, TAU, WHITE } from "../../core/index.js";+import { Ghosts, flash, since } 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,+ desc: "A hovering pod projects a cone of light to the floor; rocks tear loose in puffs of dust and spiral up spinning into the lens while rings of light climb the beam.",+ tags: ["scifi", "beam", "tractor", "lift", "abduct", "debris", "ground", "loop"],+ size: [120, 132],+ origin: [60, 114],+ duration: 3,loop: true,fps: 30,bg: "ground",- options: { palette: ["#04160e", "#0a2e1c", "#125232", "#1e8048", "#3cb862", "#86eaa0", "#dcffe4"], height: 70, seed: 27 },+ options: {+ palette: ["#06161a", "#0b2e33", "#11505a", "#1a7f84", "#2bb5a8", "#7ef0c8", "#d6fff0", "#ffffff"],+ hull: ["#0d0f17", "#1c2030", "#2e3448", "#4a5470", "#7a86a8", "#b8c4e0"],+ stone: ["#1a1622", "#2e2838", "#4a4258", "#6d6480", "#9a90aa"],+ seed: 9,+ },};-const HULL = ramp(["#101018", "#1f1e2b", "#33313f", "#4c4a5c", "#706d84", "#9c99b0"]);-const ROCK = ramp(["#34352c", "#575645", "#7f7b62"]);-const ROCKS = [[".##", "###", "##."], ["##.", "###", ".#."], [".#.", "###", ".##"]];+const D = meta.duration, LENS = -84, TOPW = 5.5, BOTW = 32;+// the cone's half width at height y+const half = (y) => lerp(BOTW, TOPW, clamp(y / LENS));-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+// where something hauled up the beam is at progress k (0 on the floor, 1 in the lens): quickening as it+// rises, winding round the axis and in toward it. [x, y, depth (> 0 on the near side)]+function haul(r0, th0, dir, turns, k) {+ const s = Math.pow(clamp(k), 1.8), y = lerp(-2, LENS + 5, s), th = th0 + dir * TAU * turns * s, rr = r0 * (half(y) / BOTW) * (1 - 0.5 * s);+ return [Math.cos(th) * rr, y, Math.sin(th)];+}- // 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]);+// a rock's life: it pops out of the floor, wobbles a beat, then spirals up into the lens+const POP = 0.1, HOVER = 0.32, RISE = 1.4, LIFE = POP + HOVER + RISE;+function rockAt(r, age) {+ const lift = clamp((age - POP - HOVER) / RISE);+ if (lift > 0) {+ const [x, y, z] = haul(r.r0, r.th0, r.dir, 1.3, lift), [x1, y1] = haul(r.r0, r.th0, r.dir, 1.3, lift - 0.07);+ return { x, y, z, px: x1, py: y1, size: r.s * (1 - 0.6 * lift ** 2.5), a: r.a0 + r.va * age * (0.3 + lift * 2), lift };+ }+ const y = age < POP ? lerp(3, -2, age / POP) : -2 - 2 * smooth(0, HOVER, age - POP), wob = age > POP ? Math.sin(age * 55 + r.th0 * 9) * 0.7 : 0;+ return { x: Math.cos(r.th0) * r.r0 + wob, y, z: 1, size: r.s, a: r.a0 + r.va * age * 0.3, lift: 0 };+}++// a tumbling chunk of stone: an uneven outline, lit from above by the lens, shaded underneath+function rock(p, q, r, S, C, back) {+ const n = 6, R = Math.max(0.9, q.size), ca = Math.cos(q.a), sa = Math.sin(q.a), lit = mix(S[4], C[6], 0.3 + 0.6 * q.lift);+ const rad = (ang) => {+ const f = ((((ang / TAU) * n) % n) + n) % n, i = Math.floor(f), k = f - i;+ return R * (0.75 + 0.35 * lerp(rand(r.id, i), rand(r.id, (i + 1) % n), k));+ };+ // a faint trail of its rush up the beam+ if (q.lift > 0.15 && !back) {+ p.line(q.px, q.py, q.x, q.y, (u) => (u > 0.6 ? C[5] : C[3]), (u) => 0.7 * u);+ for (let i = 1; i <= 3; i++) p.disc(lerp(q.x, q.px, i / 3), lerp(q.y, q.py, i / 3) + 1, R * (0.5 + 0.25 * i), mix(S[3], C[5], 0.4), 0.22 * (1 - i / 4) * q.lift);+ }+ p.shade(q.x - R - 2, q.y - R - 2, q.x + R + 2, q.y + R + 2, (x, y, out) => {+ const dx = x - q.x, dy = y - q.y, u = dx * ca + dy * sa, v = -dx * sa + dy * ca, d = Math.hypot(u, v), e = rad(Math.atan2(v, u));+ if (d > e + 0.8) return;+ out.c = d > e ? S[0] : back ? (dy < -0.3 * R ? S[3] : S[1]) : dy < -0.45 * R ? (q.lift > 0.35 && d > e - 1 ? C[6] : lit) : dy < -0.1 * R ? (dx < 0 ? S[4] : S[3]) : dy > 0.35 * R ? S[1] : S[2];});+ if (!back && q.lift > 0) p.glow(q.x, q.y - R, 5 + R, C[5], 0.25 * q.lift);+}- // 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);+// the hovering pod: a cockpit dome on a wide hull, a rim of running lights, the lens underneath+function pod(p, t, C, H, y0) {+ const y = Math.round(y0);+ p.shade(-21, y - 12, 21, y + 6, (x, yy, out) => {+ const dy = yy - y;+ // the cockpit: a small glassy dome, a hot glint top left+ const cx = x / 8.5, cy = (dy + 5) / 6;+ if (cy < 0 && cx * cx + cy * cy <= 1) {+ const d = cx * cx + cy * cy, l = -cx * 0.6 - cy * 0.8;+ out.c = d > 0.8 ? H[0] : l > 0.85 ? WHITE : l > 0.6 ? C[6] : l > 0.2 ? C[4] : C[3];+ return;+ }+ // the hull: a flat lens shape, lit on its upper face, a dark seam, the rim+ const hx = x / 20, hy = (dy + 0.5) / 4.5;+ if (dy <= 0 && hx * hx + hy * hy <= 1) {+ const d = hx * hx + hy * hy, l = -hx * 0.55 - hy * 0.7;+ out.c = d > 0.88 ? H[0] : dy === -2 ? H[1] : l > 0.55 ? H[5] : l > 0.25 ? H[4] : l > -0.1 ? H[3] : H[2];+ return;+ }+ // the underside, tapering in toward the lens housing, lit from below by its own beam+ const w = 19.5 - dy * 2.4;+ if (dy > 0 && dy <= 5 && Math.abs(x) <= w) out.c = Math.abs(x) > w - 1 ? H[0] : dy === 1 ? H[2] : dy >= 4 && Math.abs(x) < 9 ? C[3] : H[1];});+ // running lights chase round the rim+ for (let i = 0; i < 6; i++) {+ const lx = -15 + i * 6, k = 0.5 + 0.5 * Math.cos(TAU * (4 * (t / D) - i / 6));+ p.px(lx, y + 1, k > 0.7 ? WHITE : k > 0.35 ? C[5] : C[2]);+ if (k > 0.5) p.glow(lx, y + 1, 5, C[5], 0.35 * k);+ }+ // the lens: a white-hot eye in a ring of light+ p.ellipse(0, y + 5.5, 7.5, 2.2, (d) => (d < 0.45 ? WHITE : d < 0.75 ? C[6] : d < 0.9 ? C[5] : C[3]));+}- // 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]);+// a ring of light round the beam at height y: a hard line in front, a fainter one for the far side+function hoop(p, y, rx, c, back) {+ const ry = rx * 0.17;+ for (let i = 0, n = Math.ceil(rx * 7); i < n; i++) {+ const g = (i / n) * TAU, s = Math.sin(g);+ if (s >= 0 === back) continue;+ p.px(Math.cos(g) * rx, y + s * ry, c);}- 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);+const cache = new Map();+function setup(o) {+ const key = `${o.seed}:${o.palette.join()}:${o.stone.join()}`;+ if (cache.has(key)) return cache.get(key);+ const C = fit(o.palette, 8), S = fit(o.stone, 5), rn = new Rng(o.seed);+ // rocks torn up one after another, from spots left and right of the middle+ const rocks = Array.from({ length: 7 }, (_, i) => ({+ id: i + o.seed * 31, born: (i / 7) * D + rn.range(-0.06, 0.06), r0: rn.range(8, 25), th0: (i % 2 ? 0 : Math.PI) + rn.range(-0.45, 0.45),+ dir: rn.sign(), s: rn.range(2.4, 4.4), a0: rn.range(0, TAU), va: rn.range(-7, 7),+ }));+ const g = new Ghosts(D, { ground: () => 0, box: [-58, -112, 58, 14] });+ // each rock leaves the floor in a puff of dust and a spray of grit+ for (const r of rocks) {+ const x = Math.cos(r.th0) * r.r0;+ for (let i = 0; i < 5; i++) g.add(r.born + 0.02, P.DUST, x + rn.range(-3, 3), -1, rn.range(-34, 34), -rn.range(8, 26), rn.range(0.5, 0.9), mix(S[3], C[4], 0.3), rn.range(2.2, 3.6));+ for (let i = 0; i < 6; i++) g.add(r.born + 0.02, P.GRIT, x + rn.range(-2, 2), -2, rn.range(-45, 45), -rn.range(60, 150), rn.range(0.5, 0.9), rn.pick([S[2], S[3], S[4]]), rn.chance(0.3) ? 2 : 1);+ }+ // dust always swirling round the foot of the beam+ for (let i = 0; i < 16; i++) {+ const s = rn.sign();+ g.add(rn.range(0, D), P.DUST, s * rn.range(14, 34), -rn.range(0, 3), -s * rn.range(6, 22), -rn.range(4, 14), rn.range(0.9, 1.5), mix(S[3], C[5], 0.3), rn.range(2.6, 4.4));+ }+ const v = { C, S, rocks, g };+ cache.set(key, v);+ return v;+}++export function drawBack(p, t, o) {+ const { C, S, rocks, g } = setup(o);+ // the pool of light where the beam meets the floor, and the far half of its rim+ for (let y = -6; y <= 6; y++)+ for (let x = -BOTW; x <= BOTW; x++) {+ const d = Math.hypot((x + 0.5) / BOTW, (y + 0.5) / 5.5);+ if (d <= 1) p.blend(x + 0.5, y + 0.5, d < 0.35 ? C[6] : C[5], 0.2 + 0.55 * (1 - d) ** 1.5);+ }+ hoop(p, 0, BOTW + 1, C[5], true);+ g.at(t).draw(p, "back");+ // rocks on the far side of the beam, seen through it+ for (const r of rocks) {+ const age = since(t, r.born, D);+ if (age >= LIFE) continue;+ const q = rockAt(r, age);+ if (q.z < 0 && q.lift > 0) rock(p, q, r, S, C, true);+ }+}++export function draw(p, t, o) {+ const { C, S, rocks, g } = setup(o), H = fit(o.hull, 6), ph = t / D, podY = LENS - 5 + 1.5 * Math.sin(TAU * 2 * ph);+ // the beam: a glassy cone, white-hot at the lens, hard bright edges with a soft fringe, light drifting in it+ for (let y = Math.ceil(LENS + 3); y < 0; y++) {+ const w = half(y), v = (y - LENS) / -LENS, pulse = ((((v * 3.2 + ph * 6) % 1) + 1) % 1) < 0.08 ? 1 : 0;+ for (let x = Math.floor(-w) - 1; x <= Math.ceil(w); x++) {+ const q = Math.abs(x + 0.5) / w;+ if (q > 1 + 1.2 / w) continue;+ if (q > 1) p.dot(x, y, C[4], 0.6 - 0.3 * v);+ else if (q > 1 - 1 / w) p.px(x, y, v < 0.2 ? WHITE : v < 0.45 ? C[6] : C[5]);+ else {+ let curtain = 0;+ for (let s = 0; s < 4; s++) if (Math.abs((x + 0.5) / w - (rand(o.seed, s, 7) - 0.5) * 1.4 - 0.12 * Math.sin(TAU * ph + s * 1.7)) < 0.045) curtain = 1;+ const core = (1 - q) ** 2 * (1 - v) ** 1.6, a = 0.08 + 0.22 * q ** 4 + 0.6 * core + 0.12 * pulse + 0.18 * curtain;+ p.blend(x + 0.5, y + 0.5, core > 0.45 ? WHITE : curtain || pulse || v < 0.35 ? C[5] : C[4], clamp(a));+ }+ }+ if ((y & 3) === 0) for (const s of [-1, 1]) p.glow(s * w, y, 8, C[4], 0.18);+ }+ // rings climbing the beam, quickening and narrowing with it+ for (let i = 0; i < 5; i++) {+ const k = since(t, (i / 5) * D, D) / 1.1;+ if (k >= 1) continue;+ const y = lerp(0, LENS + 5, ease.inQuad(k)), w = half(y) + 1;+ hoop(p, y, w, C[3], true);+ hoop(p, y, w, k < 0.12 ? WHITE : C[6], false);+ p.glow(0, y + w * 0.17, w + 4, C[5], 0.12);+ }+ // light streaks drawn up the beam+ cycle(t, D, 22, o.seed + 1, (r) => r.range(0.6, 1), (age, life, r) => {+ const k = age / life, y = lerp(-2, LENS + 5, k * k), w = half(y), x = r.range(-0.85, 0.85) * w, L = 2 + 6 * k;+ p.line(x, y, x, y + L, (u) => (u < 0.3 ? WHITE : C[5]), Math.min(1, (1 - k) * 3));+ });+ // dust drawn up in soft puffs, thinning as it goes+ cycle(t, D, 9, o.seed + 3, (r) => r.range(1.4, 2), (age, life, r) => {+ const k = age / life, [x, y] = haul(r.range(8, 26), r.range(0, TAU), r.sign(), 0.8, k);+ p.disc(x, y, lerp(4, 1.5, k), mix(S[3], C[5], 0.25 + 0.5 * k), 0.4 * Math.min(1, k * 6) * (1 - k));+ });+ // grit and motes of light hauled up in a quick spiral, streaking as they go+ cycle(t, D, 46, o.seed + 2, (r) => r.range(0.8, 1.3), (age, life, r) => {+ const k = age / life, r0 = r.range(6, 30), th0 = r.range(0, TAU), dir = r.sign(), turns = r.range(1, 1.8), mote = r.chance(0.45);+ const [x, y, z] = haul(r0, th0, dir, turns, k), [x1, y1] = haul(r0, th0, dir, turns, k - (mote ? 0.13 : 0.06));+ const c = mote ? (r.chance(0.5) ? WHITE : C[6]) : r.pick([S[3], S[4], S[4]]);+ p.line(x1, y1, x, y, (u) => (u > 0.5 ? (z > 0 ? c : scale(c, 0.7)) : mote ? C[4] : S[2]));+ if (mote) {+ p.px(x, y, WHITE);+ p.glow(x, y, 4, C[5], 0.45);+ }+ });+ // twinkles caught in the light+ cycle(t, D, 8, o.seed + 4, 0.5, (age, life, r) => {+ const k = age / life, [x, y] = haul(r.range(4, 24), r.range(0, TAU), r.sign(), 0.6, r.range(0.1, 0.7) + k * 0.15), arm = Math.round(2 * Math.sin(Math.PI * k));+ if (arm > 0) sparkle(p, x, y, arm, C[6], C[5], 0.4);+ });+ // the rocks on the near side and those still on the floor+ for (const r of rocks) {+ const age = since(t, r.born, D);+ if (age >= LIFE) continue;+ const q = rockAt(r, age);+ if (q.z >= 0 || q.lift <= 0) rock(p, q, r, S, C, false);+ // swallowed: a glint at the lens+ if (age > LIFE - 0.1) sparkle(p, q.x, LENS + 3, 5, C[6], 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);+ for (const r of rocks) flash(p, t, r.born + LIFE - 0.08, 0, LENS + 3, 30, C[5], 0.7, 0.28);+ g.at(t).draw(p, "front");+ hoop(p, 0, BOTW + 1, WHITE, false);+ hoop(p, 1, BOTW, C[5], false);+ // light: the lens, the beam's body, the pool on the floor+ pod(p, t, C, H, podY);+ const fl = 0.85 + 0.15 * Math.sin(TAU * 6 * ph);+ p.glow(0, LENS + 6, 36, C[5], 0.7 * fl);+ p.glow(0, LENS + 6, 12, WHITE, 0.7 * fl);+ for (let y = LENS + 16; y < -8; y += 14) p.glow(0, y, half(y) + 10, C[4], 0.16);+ for (const x of [-20, 0, 20]) p.glow(x, -2, 22, C[4], 0.26);}diff --git a/src/fx/scifi/warp-in.js b/src/fx/scifi/warp-in.jsindex 49536ef..46b6b48 100644--- a/src/fx/scifi/warp-in.js+++ b/src/fx/scifi/warp-in.js@@ -1,88 +1,265 @@-import { burst, seg, ease, rand, TAU, WHITE } from "../../core/index.js";-import { steps, maskCells } from "./_lib.js";+// The column (bands of the ramp across it, strands, pulses scrolling along it, a guide thread before it lands,+// rings riding it) is adapted from Sprite Fusion's open-source holy light+// (https://www.spritefusion.com/pixel-art-vfx/holy-light), MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Lights, P, Rng, fit, band, sparkle, clamp, smooth, lerp, ease, rand, mix, TAU, WHITE } from "../../core/index.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,+ desc: "A beam slams down, rings run down it and a scanline paints the hero in from head to toe, white-hot pixels cooling to their own colors; the beam pinches shut in sparks.",+ tags: ["scifi", "teleport", "warp", "beam", "spawn", "arrive", "one-shot"],+ size: [192, 168],+ origin: [96, 128],+ duration: 3,loop: false,fps: 30,bg: "ground",- actor: true,- options: { palette: ["#0a1430", "#14306a", "#2060b0", "#3aa0e0", "#80dcff", "#d0f6ff", "#ffffff"], height: 76, seed: 23 },+ actor: 2,+ options: { palette: ["#0b1030", "#152a63", "#1d4f9e", "#2582d2", "#36b9ee", "#8ae8ff", "#d4fbff", "#ffffff"], width: 15, seed: 3 },};-const OPEN = 0.36, SHUT = 0.52; // the column holds full width until OPEN, gone by SHUT+// the beats: the guide thread, the slam, the tube opens, the scan, the cooling, the beam narrows, it snaps shut+const SLAM = 0.34, OPEN = 0.52, SCAN0 = 0.62, SCAN1 = 1.4, COOL = 0.42, DONE = SCAN1 + COOL, CLOSE = 1.9, SNAP = 2.16;+const TOP = -meta.origin[1];-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);+export const actorAlpha = (t) => (t >= DONE ? 1 : 0);- // 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));- }+// when the scanline crosses row y (top to bottom, easing in and out), for a body from y0 to the floor+const scanY = (t, y0) => lerp(y0 - 2, 1, ease.inOutSine(clamp((t - SCAN0) / (SCAN1 - SCAN0))));+const scanT = (y, y0) => SCAN0 + ((SCAN1 - SCAN0) * Math.acos(1 - 2 * clamp((y + 0.5 - (y0 - 2)) / (3 - y0)))) / Math.PI;++// the beam's half width over time: overshoots as it lands, hums, narrows to a thread+function widthAt(t, W) {+ if (t < SLAM) return 0;+ if (t < CLOSE) return W * (1 + 0.45 * Math.exp(-(t - SLAM) * 14) + 0.03 * Math.sin(t * 31));+ return lerp(W, 0.7, ease.outCubic(clamp((t - CLOSE) / (SNAP - CLOSE))));+}- // 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)));+export function create(o) {+ const C = fit(o.palette, 8), W = o.width, R = new Rng(o.seed), A = o.actor;+ const ps = new Particles({ rng: R, ground: () => 0, sparks: [WHITE, C[6], C[5], C[3]], haze: C[5] }), lights = new Lights();+ // the body: each filled pixel, its own color, whether it's on the outline, and each row's extent+ const body = [], rows = new Map();+ for (let my = 0; my < A.h; my++)+ for (let mx = 0; mx < A.w; mx++) {+ const i = my * A.w + mx;+ if (!A.mask.data[i]) continue;+ const on = (x, y) => x >= 0 && y >= 0 && x < A.w && y < A.h && A.mask.data[y * A.w + x];+ const x = A.x + mx, y = A.y + my, edge = !on(mx - 1, my) || !on(mx + 1, my) || !on(mx, my - 1) || !on(mx, my + 1);+ body.push({ x, y, c: A.pixels[i] || C[2], edge, ts: scanT(y, A.y), j: rand(o.seed, mx, my) });+ const r = rows.get(y) ?? [x, x];+ rows.set(y, [Math.min(r[0], x), Math.max(r[1], x)]);+ }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]);+ let t = 0, slammed = false, snapped = false, nextRing = SLAM + 0.08, lastRow = A.y - 3;++ const column = (p) => {+ const w = widthAt(t, W);+ if (w <= 0.05 || t > SNAP + 0.14) return;+ // it falls from the sky as it lands, and snaps back up into it at the end+ const bottom = t - SLAM < 0.06 ? lerp(TOP, 0, ease.inCubic(clamp((t - SLAM) / 0.06) * 0.5 + 0.5)) : t > SNAP ? lerp(0, TOP, ease.outExpo((t - SNAP) / 0.14)) : 0;+ // the core hollows out from the middle into a tube of light, and the tube's walls close into a thread+ const hero = t - SLAM < 0.07, hollow = 0.78 * smooth(OPEN - 0.16, OPEN, t), thin = 1 - clamp((w - 1.5) / (W - 1.5));+ for (let y = Math.floor(TOP); y < bottom; y++) {+ const pulse = ((((y - TOP) * 0.028 - t * 2.6) % 1) + 1) % 1 < 0.09 ? 1 : 0;+ for (let x = Math.floor(-w * 1.35); x <= Math.ceil(w * 1.35); x++) {+ const q = Math.abs(x + 0.5) / w;+ if (q > 1.35) continue;+ if (hero) {+ p.dot(x, y, q < 0.55 ? WHITE : q < 0.8 ? C[6] : q < 1 ? C[5] : C[4], q < 1 ? 1 : (1.35 - q) / 0.35);+ continue;+ }+ if (w < 2.4) {+ p.dot(x, y, q < 0.7 ? WHITE : C[6], q < 1 ? 1 : (1.35 - q) / 0.35);+ continue;+ }+ // strands: thin bright threads drifting inside the beam+ let strand = 0;+ for (let s = 0; s < 5; s++) if (Math.abs((x + 0.5) / w - (rand(o.seed, s) - 0.5) * 1.3 - 0.06 * Math.sin(t * (1.5 + s) + s * 2)) < 0.05) strand = 1;+ if (q < hollow) p.blend(x + 0.5, y + 0.5, strand || pulse ? C[6] : C[5], clamp(0.12 + 0.3 * q * q + 0.3 * strand + 0.25 * pulse + 0.7 * thin));+ else if (q < 0.78) {+ const lvl = Math.max(0, (q < 0.22 ? 0 : q < 0.45 ? 1 : 2) - pulse - strand);+ p.px(x, y, lvl === 0 ? WHITE : C[7 - lvl]);+ } else if (q < 0.96) p.px(x, y, q > 0.86 && q < 0.93 ? WHITE : C[6]);+ else p.dot(x, y, q < 1.1 ? C[5] : C[4], (1.35 - q) / 0.39);+ }+ // light rides the walls, not the middle, so the body being built inside stays readable+ if ((y & 7) === 0) {+ const r = Math.min(w + 8, y - TOP + 2);+ if (hollow < 0.4) p.glow(0, y, Math.min(w * 2.6 + 6, y - TOP + 2), C[4], hero ? 0.55 : 0.32);+ else for (const s of [-1, 1]) p.glow(s * (w + 3), y, r, C[4], 0.24);+ }+ }+ };++ // a ring riding down the beam: the near half in front, the far half behind+ const ring = (p, near) => {+ const w = widthAt(t, W);+ for (const r of rings) {+ const k = (t - r.t0) / 0.5;+ if (k < 0 || k >= 1) continue;+ const y = lerp(TOP + 6, -1, ease.inQuad(k)), rx = w * 1.18 + 1, c = k < 0.25 ? WHITE : C[6];+ band(p, 0, y, rx, 2.6 / rx, 1.5, 1, [C[3], C[5], c, WHITE], (g) => Math.sin(g) >= 0 === near);+ if (near) p.glow(0, y, rx + 6, C[5], 0.25);+ }+ };++ // the floor where the beam stands: a pool of light, ripples where rings land, the slam's shockwave+ const floor = (p, near) => {+ const on = t < SLAM ? smooth(0, SLAM, t) * 0.5 : 1 - smooth(SNAP, SNAP + 0.5, t);+ if (!near && on > 0.01) {+ const rx = W * 1.9 + (t < SLAM ? 0 : 2 * Math.sin(t * 6)), ry = 4;+ for (let y = -4; y <= 4; y++)+ for (let x = Math.floor(-rx); x <= Math.ceil(rx); x++) {+ const d = Math.hypot((x + 0.5) / rx, (y + 0.5) / ry);+ if (d > 1) continue;+ p.dot(x, y, d < 0.35 ? C[7] : d < 0.6 ? C[6] : d < 0.85 ? C[5] : C[4], on * clamp((1.05 - d) * 2.4));+ }+ for (const x of [-rx * 0.6, 0, rx * 0.6]) p.glow(x, -1, rx * 1.3, C[4], 0.3 * on);+ }+ const keep = (g) => Math.sin(g) >= 0 === near;+ for (const r of rings) {+ const k = (t - r.t0 - 0.5) / 0.35;+ if (k >= 0 && k < 1) band(p, 0, 0, W * (1.2 + 1.3 * ease.outCubic(k)), 0.16, 1.5, 1 - k, [C[3], C[4], C[5], C[6]], keep);}+ for (const [d, s] of [[0, 1], [0.08, 0.65]]) {+ const k = (t - SLAM - d) / 0.55;+ if (k >= 0 && k < 1) band(p, 0, 0.5, 92 * s * ease.outCubic(k), 0.16, Math.max(1, 5 * (1 - k)), 1.15 - k, [C[3], C[5], C[6], WHITE], keep, k < 0.25);+ }+ const k = (t - SNAP) / 0.45;+ if (k >= 0 && k < 1) band(p, 0, 0, 10 + 26 * ease.outCubic(k), 0.16, 2 * (1 - k) + 0.5, 1.1 - k, [C[4], C[5], C[6], WHITE], keep, k < 0.3);};- 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]);+ // the hero, built out of light: the blueprint first, then each row as the scanline crosses it, white-hot+ // and cooling through the beam's color to its own+ const hero = (p) => {+ if (t >= DONE || t < SCAN0 - 0.2) return;+ const blink = Math.floor(t * 24);+ for (const b of body) {+ const a = t - b.ts;+ if (a < 0) {+ if (b.edge && rand(b.x, b.y, blink) < 0.6) p.dot(b.x, b.y, C[1], 0.8 * smooth(SCAN0 - 0.25, SCAN0 - 0.05, t));+ continue;+ }+ const k = a / COOL;+ // the newest rows jitter sideways a pixel, as if still arriving+ const dx = a < 0.06 && b.j < 0.3 ? (b.j < 0.15 ? -1 : 1) : 0;+ p.px(b.x + dx, b.y, k < 0.18 ? WHITE : k < 0.45 ? mix(b.c, C[6], 0.72) : k < 0.75 ? mix(b.c, C[5], 0.38) : b.c);+ if (k < 0.5) p.light(b.x + dx, b.y, C[5], 0.22 * (1 - k / 0.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);- });+ // the scanline: a white rule across the beam, hottest where it crosses the body, sparking at its edges+ const scanline = (p) => {+ if (t < SCAN0 || t > SCAN1) return;+ const y = Math.floor(scanY(t, A.y)), w = widthAt(t, W) * 1.5, r = rows.get(y);+ for (let x = Math.floor(-w); x <= Math.ceil(w); x++) {+ const inside = r && x >= r[0] && x <= r[1];+ p.dot(x, y, inside ? WHITE : C[6], inside ? 1 : 1 - Math.abs(x + 0.5) / (w + 1));+ }+ p.glowLine(-w, y, w, y, 5, C[5], 0.5);+ if (r) for (const x of r) sparkle(p, x + 0.5, y, 2, C[6], C[5], 0.3);+ };++ return {+ update(dt) {+ t += dt;+ // gathering: energy streaks in toward the spot, vapour slides along the floor+ if (t < SLAM - 0.04) {+ if (R.chance(0.8)) {+ const a = R.range(-Math.PI * 0.95, -Math.PI * 0.05), D = R.range(30, 64), T = R.range(0.18, 0.28), v = (D * 3) / (Math.exp(3 * T) - 1);+ const x = Math.cos(a) * D, y = Math.sin(a) * D * 0.8 - 2, l = Math.hypot(x, y + 2) || 1;+ ps.spawn(P.STREAK, x, y, (-x / l) * v, (-(y + 2) / l) * v, T, R.chance(0.5) ? C[6] : C[5]);+ }+ if (R.chance(0.12)) {+ const s = R.sign();+ ps.spawn(P.VAPOUR, s * R.range(30, 56), -R.range(0, 2), -s * R.range(40, 70), -R.range(0, 4), R.range(0.3, 0.45), C[5], R.range(2, 3));+ }+ }+ if (t >= SLAM && !slammed) {+ slammed = true;+ lights.add(0, -40, 120, C[4], 1, 0.55);+ lights.add(0, -10, 44, WHITE, 0.9, 0.14);+ for (let i = 0; i < 34; i++) {+ const a = -Math.PI / 2 + R.sign() * R.range(0.35, 1.45), sp = R.range(110, 270);+ ps.spawn(P.SPARK, R.range(-W, W) * 0.6, -1, Math.cos(a) * sp, Math.sin(a) * sp, R.range(0.25, 0.75));+ }+ for (let i = 0; i < 18; i++) {+ const s = R.sign();+ ps.spawn(P.VAPOUR, s * R.range(4, 18), -R.range(0, 4), s * R.range(40, 150), -R.range(2, 18), R.range(0.5, 0.95), R.chance(0.6) ? C[6] : C[5], R.range(3, 6));+ }+ for (let i = 0; i < 10; i++) ps.spawn(P.STAR, R.range(-W, W) * 1.3, -R.range(2, 40), R.range(-20, 20), -R.range(10, 40), R.range(0.4, 0.8), R.chance(0.5) ? WHITE : C[6], R.range(1, 2.2));+ }+ if (slammed && t < CLOSE) {+ // rings ride down, light falls down the beam, glints wink at its walls+ if (t >= nextRing) rings.push({ t0: nextRing }), (nextRing += 0.17);+ const w = widthAt(t, W);+ if (R.chance(0.5)) ps.spawn(P.STREAK, R.range(-0.8, 0.8) * w, TOP + R.range(9, 36), 0, R.range(60, 110), R.range(0.3, 0.45), R.chance(0.5) ? WHITE : C[6]);+ if (R.chance(0.18)) ps.spawn(P.STAR, R.sign() * w * R.range(0.8, 1.3), -R.range(4, 70), 0, -R.range(5, 20), R.range(0.3, 0.6), C[6], R.range(0.6, 1.8));+ if (R.chance(0.1)) {+ const s = R.sign();+ ps.spawn(P.VAPOUR, s * R.range(8, 16), -R.range(0, 3), s * R.range(20, 50), -R.range(2, 8), R.range(0.5, 0.8), C[5], R.range(2.5, 4));+ }+ }+ // the scanline spits light off the edges of the body as it crosses+ if (t > SCAN0 && t < SCAN1) {+ const y = Math.floor(scanY(t, A.y));+ if (y !== lastRow) {+ lastRow = y;+ const r = rows.get(y);+ if (r && R.chance(0.7)) for (const [x, s] of [[r[0], -1], [r[1] + 1, 1]]) if (R.chance(0.6)) ps.spawn(P.MOTE, x, y, s * R.range(40, 90), R.range(-20, 10), R.range(0.15, 0.3), R.chance(0.5) ? WHITE : C[6], 0.6);+ }+ }+ if (t >= DONE && t - dt < DONE) {+ // set: a glint or two on the new body+ for (let i = 0; i < 6; i++) {+ const b = body[Math.floor(R.next() * body.length)];+ ps.spawn(P.STAR, b.x + 0.5, b.y + 0.5, R.range(-6, 6), -R.range(6, 20), R.range(0.4, 0.8), R.chance(0.5) ? WHITE : C[6], R.range(1, 2));+ }+ }+ if (t >= SNAP && !snapped) {+ snapped = true;+ lights.add(0, -1, 32, C[4], 0.5, 0.25);+ lights.add(0, -1, 10, WHITE, 0.5, 0.08);+ for (let i = 0; i < 22; i++) {+ const a = -Math.PI / 2 + R.range(-1.4, 1.4), sp = R.range(90, 260);+ ps.spawn(P.SPARK, R.range(-2, 2), -1, Math.cos(a) * sp, Math.sin(a) * sp, R.range(0.2, 0.6));+ }+ for (let i = 0; i < 12; i++) ps.spawn(P.STAR, R.range(-16, 16), -R.range(0, 46), R.range(-10, 10), -R.range(8, 26), R.range(0.5, 0.9), R.chance(0.5) ? WHITE : C[6], R.range(0.6, 1.8));+ // where the beam stood, motes keep rising for a while+ for (let i = 0; i < 18; i++) ps.spawn(R.chance(0.6) ? P.STAR : P.MOTE, R.range(-6, 6), -R.range(10, 100), R.range(-6, 6), -R.range(14, 40), R.range(0.5, 0.75), R.chance(0.4) ? WHITE : R.chance(0.5) ? C[6] : C[5], R.range(0.5, 1.4), R.range(0, 0.25));+ }+ ps.update(dt);+ lights.update(dt);+ },+ drawBack(p) {+ floor(p, false);+ ring(p, false);+ column(p);+ // the guide thread: a dotted line pricking down to the spot, brightening+ if (t < SLAM) {+ const a = smooth(0, SLAM * 0.8, t) * 0.8, head = lerp(TOP, 0, ease.outCubic(clamp(t / (SLAM * 0.6))));+ for (let y = TOP; y < head; y++) p.dot(0, y, (y & 1) === 0 ? C[6] : C[5], a * (0.35 + 0.65 * ((y - TOP) / -TOP)));+ p.glow(0, head, 10, C[5], 0.5 * a);+ // a target on the floor, closing in+ const rx = lerp(34, 12, ease.outCubic(t / SLAM)), k = smooth(0, 0.15, t);+ for (let i = 0; i < 48; i++) {+ const g = (i / 48) * TAU + t * 3;+ if (Math.floor(i / 4) % 2) continue;+ p.dot(Math.cos(g) * rx, Math.sin(g) * rx * 0.16, i % 4 === 0 ? WHITE : C[5], k);+ }+ }+ ps.draw(p, "back");+ },+ draw(p) {+ hero(p);+ scanline(p);+ ring(p, true);+ floor(p, true);+ // the set body's outline flares as it lands, then fades+ if (t >= DONE && t < DONE + 0.3) p.outline(A.mask, A.x, A.y, C[6], 1 - (t - DONE) / 0.3);+ if (t > SLAM && t < SLAM + 0.16) sparkle(p, 0, -2, 12 * (1 - (t - SLAM) / 0.16), C[6], C[5], 0.6);+ ps.draw(p, "front");+ lights.draw(p);+ },+ };}diff --git a/src/fx/scifi/warp-out.js b/src/fx/scifi/warp-out.jsindex 946a143..d92043a 100644--- a/src/fx/scifi/warp-out.js+++ b/src/fx/scifi/warp-out.js@@ -1,90 +1,138 @@-import { burst, seg, ease, rand, stockActor, TAU, WHITE } from "../../core/index.js";-import { steps, maskCells } from "./_lib.js";+// The breakup (the outline flickering on, a white hero frame, the body bursting into bits of light) follows+// Sprite Fusion's open-source blink (https://www.spritefusion.com/pixel-art-vfx/movement), MIT License,+// Copyright (c) 2026 Hugo Duprez.+import { Particles, Lights, P, Rng, fit, band, sparkle, clamp, smooth, lerp, ease, rand, mix, TAU, WHITE } from "../../core/index.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,+ desc: "The hero's outline flickers on, they flash white and break into light from the head down, streaming up a beam that lifts off the floor and pinches shut.",+ tags: ["scifi", "teleport", "warp", "beam", "despawn", "leave", "one-shot"],+ size: [128, 168],+ origin: [64, 128],+ duration: 2.6,loop: false,fps: 30,bg: "ground",- options: { palette: ["#0a1430", "#14306a", "#2060b0", "#3aa0e0", "#80dcff", "#d0f6ff", "#ffffff"], height: 76, seed: 24 },+ actor: 2,+ options: { palette: ["#0b1030", "#152a63", "#1d4f9e", "#2582d2", "#36b9ee", "#8ae8ff", "#d4fbff", "#ffffff"], seed: 4 },};-// 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());+// the beats: it charges, flashes white, breaks up into the beam, the beam lifts away+const FLASH = 0.42, BREAK0 = 0.5, BREAK1 = 1.1, LIFT = 1.3, GONE = 1.62, TOP = -meta.origin[1];-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);+export const actorAlpha = (t) => (t < FLASH ? 1 : 0);- // 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;+export function create(o) {+ const C = fit(o.palette, 8), R = new Rng(o.seed), A = o.actor;+ const ps = new Particles({ rng: R, ground: () => 0, sparks: [WHITE, C[6], C[5], C[4]] }), lights = new Lights();+ // the body: every pixel, its own color, whether it's on the edge, when it lets go (head first)+ const bits = [], on = (x, y) => x >= 0 && y >= 0 && x < A.w && y < A.h && A.mask.data[y * A.w + x];+ const edge = [];+ for (let my = -1; my <= A.h; my++)+ for (let mx = -1; mx <= A.w; mx++) {+ if (on(mx, my)) {+ const x = A.x + mx, y = A.y + my, tr = BREAK0 + (my / A.h) * (BREAK1 - BREAK0 - 0.12) + R.range(0, 0.12);+ const rim = !on(mx - 1, my) || !on(mx + 1, my) || !on(mx, my - 1) || !on(mx, my + 1);+ bits.push({ x, y, x0: x, y0: y, vx: 0, vy: 0, tr, c: A.pixels[my * A.w + mx] || C[3], free: false, j: R.next(), rim });+ } else if (on(mx - 1, my) || on(mx + 1, my) || on(mx, my - 1) || on(mx, my + 1)) edge.push([A.x + mx, A.y + my]);}- 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]);+ let t = 0, flashed = false, lifted = false;+ // the beam's half width and how far its foot has lifted off the floor+ const width = () => (t < BREAK0 ? 0 : t < LIFT ? 2 + 7 * ease.outCubic(clamp((t - BREAK0) / 0.35)) : lerp(9, 0.6, ease.inCubic(clamp((t - LIFT) / (GONE - LIFT)))));+ const foot = () => (t < LIFT ? 0 : lerp(0, TOP, ease.inQuad(clamp((t - LIFT) / (GONE - LIFT)))));- // 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]);- });+ return {+ update(dt) {+ t += dt;+ // charging: motes gather to the body, the floor target closes in+ if (t < FLASH - 0.05 && R.chance(0.7)) {+ const a = R.range(0, TAU), D = R.range(26, 48), T = R.range(0.16, 0.26), v = (D * 3) / (Math.exp(3 * T) - 1), cy = -19;+ ps.spawn(P.STREAK, Math.cos(a) * D, cy + Math.sin(a) * D * 0.8, -Math.cos(a) * v, -Math.sin(a) * v * 0.8, T, R.chance(0.5) ? C[6] : C[5]);+ }+ if (t >= FLASH && !flashed) {+ flashed = true;+ lights.add(0, -20, 80, C[4], 0.9, 0.5);+ lights.add(0, -20, 30, WHITE, 0.8, 0.12);+ for (let i = 0; i < 14; i++) ps.spawn(P.STAR, R.range(-14, 14), -R.range(2, 40), R.range(-20, 20), -R.range(10, 40), R.range(0.3, 0.6), R.chance(0.5) ? WHITE : C[6], R.range(0.8, 1.8));+ }+ // the body lets go bit by bit: a little burst outward, then hauled up the beam, drawn in to its middle+ for (let i = bits.length - 1; i >= 0; i--) {+ const b = bits[i];+ if (t < b.tr) continue;+ if (!b.free) {+ b.free = true;+ const ox = b.x + 0.5, oy = b.y + 19;+ b.vx = ox * R.range(1.5, 4) + R.range(-10, 10);+ b.vy = oy * R.range(0.5, 1.5) - R.range(10, 40);+ }+ b.vy -= 560 * dt;+ b.vx += (-(b.x + 0.5) * 14 - b.vx * 3) * dt;+ b.x += b.vx * dt;+ b.y += b.vy * dt;+ if (b.y < TOP + 2) bits.splice(i, 1);+ }+ if (t >= LIFT && !lifted) {+ lifted = true;+ lights.add(0, -2, 40, C[4], 0.7, 0.3);+ for (let i = 0; i < 22; i++) {+ const a = -Math.PI / 2 + R.range(-1.4, 1.4), sp = R.range(80, 220);+ ps.spawn(P.SPARK, R.range(-3, 3), -1, Math.cos(a) * sp, Math.sin(a) * sp, R.range(0.2, 0.55));+ }+ for (let i = 0; i < 16; i++) ps.spawn(P.STAR, R.range(-10, 10), -R.range(4, 70), R.range(-6, 6), -R.range(10, 30), R.range(0.5, 0.95), R.chance(0.4) ? WHITE : C[6], R.range(0.6, 1.6), R.range(0, 0.3));+ }+ ps.update(dt);+ lights.update(dt);+ },+ drawBack(p) {+ // the floor target: a ring closing in on the feet, then the beam's foot glowing+ const k = clamp(t / FLASH), fade = 1 - smooth(LIFT, LIFT + 0.6, t);+ if (fade > 0) band(p, 0, 0, lerp(30, 14, ease.outCubic(k)), 0.16, 1.5, (0.4 + 0.6 * k) * fade, [C[3], C[4], C[5], C[6]], (g) => Math.sin(g) < 0);+ // the beam: thin bright walls, a glassy inside, from its foot to the sky+ const w = width(), f = foot();+ if (w > 0.3 && t < GONE)+ for (let y = Math.floor(TOP); y < f + (t < LIFT ? 0 : 0); y++) {+ if (y >= f && t >= LIFT) break;+ for (let x = Math.floor(-w) - 1; x <= Math.ceil(w); x++) {+ const q = Math.abs(x + 0.5) / w;+ if (q > 1 + 1 / w) continue;+ if (w < 2.2) p.px(x, y, q < 0.7 ? WHITE : C[6]);+ else if (q > 1) p.dot(x, y, C[4], 0.5);+ else if (q > 1 - 1.2 / w) p.px(x, y, C[6]);+ else p.blend(x + 0.5, y + 0.5, C[5], 0.12 + 0.25 * q * q);+ }+ if ((y & 7) === 0) p.glow(0, y, Math.min(w * 2.5 + 6, y - TOP + 2), C[4], 0.28);+ }+ ps.draw(p, "back");+ },+ draw(p) {+ const k = clamp(t / FLASH), fade = 1 - smooth(LIFT, LIFT + 0.6, t);+ if (fade > 0) band(p, 0, 0, lerp(30, 14, ease.outCubic(k)), 0.16, 1.5, (0.4 + 0.6 * k) * fade, [C[3], C[5], C[6], WHITE], (g) => Math.sin(g) >= 0);+ // charging: the outline flickers on round the hero, denser as it builds+ if (t < FLASH) {+ const fr = Math.floor(t * 24);+ for (const [x, y] of edge) if (rand(x, y, fr) < 0.25 + 0.7 * k) p.px(x, y, k > 0.7 && rand(x, y, fr, 1) < 0.5 ? WHITE : C[5]);+ p.glow(0, -20, 26, C[4], 0.4 * k);+ }+ // the body, still held together: white in the flash, then cooling to the beam's color as it waits its turn+ for (const b of bits) {+ if (b.free || t < FLASH) continue;+ // white in the flash, then light with the body's own shading under it, a bright rim, a rolling scanline+ const a = t - FLASH, scan = ((b.y + Math.floor(t * 40)) % 4 + 4) % 4 === 0;+ const c = a < 0.07 ? WHITE : a < 0.16 ? C[6] : b.rim ? C[6] : mix(b.c, scan ? C[6] : C[5], scan ? 0.6 : 0.45);+ p.px(b.x, b.y, b.tr - t < 0.06 ? WHITE : c);+ }+ // the bits on their way up: streaks, longer the faster they go, cooling as they climb+ for (const b of bits) {+ if (!b.free) continue;+ const sp = Math.abs(b.vy), L = Math.min(8, sp * 0.02), u = clamp((b.y - TOP) / (b.y0 - TOP));+ const head = u > 0.75 ? WHITE : u > 0.4 ? C[6] : C[5];+ // one in three draws a streak, the rest a single spark, so the stream reads as light, not static+ if (L >= 1 && b.j < 0.33) p.line(b.x, b.y, b.x - b.vx * 0.01, b.y + L, (s) => (s < 0.25 ? head : s < 0.6 ? C[5] : C[3]));+ else if (b.j < 0.75 || u > 0.6) p.px(b.x, b.y, b.j > 0.9 ? WHITE : head);+ }+ if (t >= FLASH && t < FLASH + 0.12) sparkle(p, 0, -20, 10 * (1 - (t - FLASH) / 0.12), C[6], C[5], 0.6);+ ps.draw(p, "front");+ lights.draw(p);+ },+ };}diff --git a/src/fx/shadow/_lib.js b/src/fx/shadow/_lib.jsindex 4268a2b..656b0e5 100644--- a/src/fx/shadow/_lib.js+++ b/src/fx/shadow/_lib.js@@ -1,57 +1,351 @@-// 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);+// The flame puff (after sim.js's FIRE) and the swirling pull (attract) are adapted from Sprite Fusion's+// open-source black-hole (https://www.spritefusion.com/pixel-art-vfx/black-hole),+// MIT License, Copyright (c) 2026 Hugo Duprez.+//+// Shared bits for the shadow effects (files starting with _ are helpers, not effects): the void palette,+// light that black shapes cut, smoke lit from one side, violet flame, obsidian slivers, ink drops.++import { hex, mix, ramp, clamp, noise, WHITE, GRAVITY } from "../../core/index.js";++/** Dark magic, dark to bright: void black, deep violet, a white-lilac edge. */+export const VOID = ["#06040b", "#150c26", "#2a1150", "#461a84", "#6f2cc0", "#9d5cec", "#cfa6ff", "#f6eaff"];++/**+ * Take the light back off every pixel in a local box where dark(x, y) is true, keeping a share keep (0..1):+ * call it last, so black shapes stay black under every glow, spark and ring drawn before.+ */+export function unlight(p, x0, y0, x1, y1, dark, keep = 0) {+ const L = p.L, w = p.w, ox = p.ox, oy = p.oy;+ p.each(x0, y0, x1, y1, (x, y, sx, sy) => {+ if (!dark(x, y)) return;+ const i = (sy - oy) * w + (sx - ox), d = L[i];+ if (!d) return;+ if (keep <= 0) L[i] = 0;+ else L[i] = (255 << 24) | ((((d >>> 16) & 255) * keep) << 16) | ((((d >>> 8) & 255) * keep) << 8) | ((d & 255) * keep);+ });+}++// the pixel cells of the annulus r0 <= d < r1 round (x, y), row by row, jumping the hole: fn(cx, cy, d)+function annulus(x, y, r0, r1, fn) {+ const r02 = r0 > 0 ? r0 * r0 : -1, r12 = r1 * r1;+ for (let py = Math.floor(y - r1); py <= Math.ceil(y + r1); py++) {+ const cy = py + 0.5, dy = cy - y, dy2 = dy * dy;+ if (dy2 >= r12) continue;+ const xo = Math.sqrt(r12 - dy2), xi = dy2 < r02 ? Math.sqrt(r02 - dy2) : 0;+ for (let px = Math.floor(x - xo), x1 = Math.ceil(x + xo); px <= x1; px++) {+ const cx = px + 0.5, dx = cx - x;+ if (xi > 0 && dx > -xi && dx < xi) {+ px = Math.max(px, Math.floor(x + xi) - 1);+ continue;+ }+ const d2 = dx * dx + dy2;+ if (d2 < r12 && d2 >= r02) fn(cx, cy, Math.sqrt(d2));+ }+ }+}++/**+ * A ring from radius r - w out to r round (x, y), like p.ring (c and a may be functions of v: 0 inner to 1+ * outer, and angle) but visiting only the band's own pixels, so a big thin shock ring stays cheap.+ */+export function ringFast(p, x, y, r, w, c, a = 1) {+ if (r <= 0) return;+ const r0 = Math.max(0, r - w), fc = typeof c === "function", fa = typeof a === "function";+ annulus(x, y, r0, r, (cx, cy, d) => {+ const v = (d - r0) / (r - r0 || 1), ang = fc || fa ? Math.atan2(cy - y, cx - x) : 0;+ p.dot(cx, cy, fc ? c(v, ang) : c, fa ? a(v, ang) : a);+ });+}++/** Light hugging a circle of radius R at (x, y), falling off over w either side, only where keep(x, y). */+export function ringLight(p, x, y, R, w, c, k, keep = null) {+ if (w < 1 || k <= 0.004) return;+ const col = hex(c);+ annulus(x, y, Math.max(0, R - w), R + w, (cx, cy, d) => {+ if (keep && !keep(cx, cy)) return;+ const f = 1 - Math.abs(d - R) / w;+ p.light(cx, cy, col, f * f * k);+ });+}++/** A ring of light hugging a black disc: k at radius r0, falling to nothing at r1, and none inside r0. */+export function halo(p, x, y, r0, r1, c, k) {+ if (r1 <= r0 || k <= 0.004) return;+ const col = hex(c), w = r1 - r0;+ annulus(x, y, Math.max(0, r0), r1, (cx, cy, d) => {+ const f = 1 - (d - r0) / w;+ p.light(cx, cy, col, f * f * k);+ });+}++/**+ * A black star rasterized once: four long arms (L) and four short ones, turned rot, at (0, cy), its cells+ * in a grid. { at(x, y) } says if a local point is black; draw(p, c, rim, skip) fills it and burns a rim on+ * the cells just outside it (except where skip(x, y)). The arms keep a 1 px black spine to their tips.+ */+export function blackStar(cy, L, rot, short = 0.46, q = 0.32) {+ const R0 = Math.ceil(L) + 2, n = R0 * 2 + 1, data = new Uint8Array(n * n);+ for (let j = 0; j < n; j++)+ for (let i = 0; i < n; i++) {+ const x = i - R0 + 0.5, y = cy + j - R0 + 0.5;+ if (inStar(x, y, 0, cy, L, rot, q) || inStar(x, y, 0, cy, L * short, rot + Math.PI / 4, q)) data[j * n + i] = 1;+ }+ for (let a = 0; a < 4; a++)+ for (let d = 0, ca = Math.cos(rot + (a * Math.PI) / 2), sa = Math.sin(rot + (a * Math.PI) / 2); d < L - 1; d += 0.5) {+ const i = Math.floor(ca * d) + R0, j = Math.floor(sa * d) + R0;+ data[j * n + i] = 1;+ }+ const at = (x, y) => {+ const i = Math.floor(x) + R0, j = Math.floor(y - cy) + R0;+ return i >= 0 && j >= 0 && i < n && j < n && data[j * n + i] === 1;+ };+ return {+ R0,+ at,+ /** take the light off its black cells (call last, like unlight) */+ unlight(p) {+ const Lb = p.L, w = p.w, h = p.h, ox = p.ox, oy = p.oy;+ for (let j = 0; j < n; j++)+ for (let i = 0; i < n; i++) {+ if (!data[j * n + i]) continue;+ const x = i - R0 + 0.5, y = cy + j - R0 + 0.5, sx = p.cellX(x, y) - ox, sy = p.cellY(x, y) - oy;+ if (sx >= 0 && sy >= 0 && sx < w && sy < h) Lb[sy * w + sx] = 0;+ }+ },+ draw(p, c, rim, skip) {+ for (let j = 0; j < n; j++)+ for (let i = 0; i < n; i++) {+ const x = i - R0 + 0.5, y = cy + j - R0 + 0.5;+ if (data[j * n + i]) p.px(x, y, c);+ else if (rim && !skip(x, y) && (at(x - 1, y) || at(x + 1, y) || at(x, y - 1) || at(x, y + 1))) p.px(x, y, rim);+ }+ },+ };+}++/** Is (x, y) inside a four-point star at (cx, cy), arms L long, turned rot? q < 1 hollows the sides into thin spikes. */+export function inStar(x, y, cx, cy, L, rot, q = 0.42) {+ if (L <= 0) return false;+ const c = Math.cos(rot), s = Math.sin(rot), dx = x - cx, dy = y - cy;+ const u = Math.abs(dx * c + dy * s) / L, v = Math.abs(-dx * s + dy * c) / L;+ // inside needs the smaller of u, v under 0.5^(1/q): most points fail that before any pow+ return u < 1 && v < 1 && Math.min(u, v) <= Math.pow(0.5, 1 / q) && Math.pow(u, q) + Math.pow(v, q) <= 1;+}++/**+ * Pull particles (anything with x, y, vx, vy) toward (x, y): gravity softened at r0, a swirl round it, drag+ * that grows inside reach. Those that reach r0 are eaten (removed); returns how many. w(q) weighs each one+ * (0 leaves it alone).+ */+export function attract(list, x, y, G, reach, swirl, r0, dt, w = () => 1, vmax = Infinity) {+ let eaten = 0;+ for (let i = list.length - 1; i >= 0; i--) {+ const q = list[i], wt = w(q);+ if (!wt || q.delay > 0) continue;+ const dx = x - q.x, dy = y - q.y, d2 = dx * dx + dy * dy;+ if (d2 > reach * reach) continue;+ const d = Math.sqrt(d2) || 1;+ if (d < r0) {+ list.splice(i, 1);+ eaten++;+ continue;+ }+ const a = (G / (d2 + r0 * r0)) * Math.min(1, (reach - d) / (reach * 0.25)) * wt * dt, ux = dx / d, uy = dy / d;+ q.vx += (ux - uy * swirl) * a;+ q.vy += (uy + ux * swirl) * a;+ const drag = Math.min(0.2, (1 - d / reach) * 1.6 * dt);+ q.vx -= q.vx * drag;+ q.vy -= q.vy * drag;+ const v = Math.hypot(q.vx, q.vy);+ if (v > vmax) (q.vx *= vmax / v), (q.vy *= vmax / v);+ }+ return eaten;+}++/** Puff kinds: FLAME (a ball of flame cooling down a ramp), SOOT (dark smoke lit on the side facing a light). */+export const PK = { FLAME: 0, SOOT: 1 };++/**+ * Violet flame and dark smoke. opts: { rng, flame: ramp white-hot to burnt out, soot: [fresh, old] smoke+ * colours, cap: the soot's dim lit top, rim: [hot, warm, dim] colours of its lit side, floor: (x) => y }.+ * spawn(kind, x, y, vx, vy, life, size, delay, smokes): smokes turns a dying flame into soot.+ * draw(p, kind, light): light = { x, y, k, reach } is what the soot's rims face (k 0 leaves them dark).+ */+export class Puffs {+ constructor(o) {+ this.R = o.rng;+ this.list = [];+ this.t = 0;+ this.F = ramp(o.flame);+ this.soot = ramp(o.soot);+ this.cap = hex(o.cap);+ this.rim = ramp(o.rim);+ this.floor = o.floor ?? null;+ }+ spawn(k, x, y, vx, vy, life, size, delay = 0, smokes = false) {+ this.list.push({ k, x, y, vx, vy, life, max: life, size, delay, smokes, seed: this.R.next() * 100 });+ }+ get count() {+ return this.list.length;+ }+ update(dt) {+ this.t += dt;+ const t = this.t;+ for (let i = this.list.length - 1; i >= 0; i--) {+ const q = this.list[i];+ if (q.delay > 0) {+ q.delay -= dt;+ continue;+ }+ if ((q.life -= dt) <= 0) {+ if (q.k === PK.FLAME && q.smokes) this.spawn(PK.SOOT, q.x, q.y - 1, q.vx * 0.5, q.vy * 0.5 - 6, this.R.range(0.9, 1.6), q.size * 1.25);+ this.list.splice(i, 1);+ continue;+ }+ if (q.k === PK.FLAME) {+ q.vy -= 95 * dt;+ q.vx += Math.sin(t * 17 + q.seed) * 30 * dt;+ q.vx -= q.vx * 5 * dt;+ q.vy -= q.vy * 3.2 * dt;+ } else {+ q.vy -= 18 * dt;+ q.vx += Math.sin(t * 1.3 + q.seed) * 8 * dt;+ q.vx -= q.vx * 1.6 * dt;+ q.vy -= q.vy * 1.3 * dt;+ }+ q.x += q.vx * dt;+ q.y += q.vy * dt;+ // smoke rolls along the floor rather than through it+ if (this.floor && q.k === PK.SOOT) {+ const f = this.floor(q.x) - q.size * 0.6;+ if (q.y > f) (q.y = f), (q.vy = Math.min(0, q.vy)), (q.vx *= 1 - 2 * dt);+ }+ }+ }+ draw(p, kind, light = null) {+ const F = this.F, n = F.length;+ for (const q of this.list) {+ if (q.delay > 0 || q.k !== kind) continue;+ const k = q.life / q.max, age = 1 - k, x = q.x, y = q.y;+ if (q.k === PK.FLAME) {+ // a ball of flame: a darker rim, a lit core up and left, a tongue on top, a hot heart while young+ const heat = Math.min(0.999, Math.pow(age, 0.62) + (q.seed % 1) * 0.1), idx = Math.min(n - 2, Math.floor(heat * (n - 1)));+ const r = q.size * (0.55 + 0.45 * Math.min(1, age * 7)) * (1 - age * 0.55), c = F[idx];+ if (idx >= n - 3) p.disc(x, y, r, c, Math.min(1, k * 3) * 0.8);+ else {+ p.circle(x, y, r, F[Math.min(n - 1, idx + 2)]);+ p.circle(x - r * 0.16, y - r * 0.22, r * 0.78, c);+ if (r > 1.6) p.circle(x, y - r * 0.9, r * 0.42, c);+ if (idx <= 3 && r > 1.8) p.circle(x - r * 0.28, y - r * 0.34, r * 0.36, F[Math.max(0, idx - 1)]);+ if (idx < 6) p.glow(x, y, r * 2.4 + 2, c, 0.2 * k);+ }+ continue;+ }+ // soot: a soft body and a denser core, a dim cap on top, and lit from the side facing the light by two+ // discs pushed toward it (a soft wash over the near half, a brighter lip at its edge)+ const r = q.size * (0.65 + Math.min(1, age * 2.5) * 0.45 + age * 0.45);+ const a = Math.min(1, age * 10) * Math.min(1, k * 2.2) * 0.72, body = mix(this.soot[0], this.soot[1], age);+ // one pass for the body: thinner at the edge, denser in the core (two layers' worth)+ const edge = a * 0.5, core = 1 - (1 - a * 0.5) * (1 - a * 0.62);+ p.disc(x, y + r * 0.06, r, body, (d) => (d < 0.72 ? core : edge));+ const lk = light ? light.k : 0;+ if (lk < 0.5) p.disc(x - r * 0.2, y - r * 0.32, r * 0.48, this.cap, a * 0.32 * (1 - age * 0.7) * (1 - lk * 2));+ if (lk <= 0.02) continue;+ const lx = light.x - x, ly = light.y - y, dl = Math.sqrt(lx * lx + ly * ly) || 1, ux = lx / dl, uy = ly / dl;+ const lit = Math.min(1, light.k * clamp(1.3 - dl / light.reach)) * a;+ if (lit <= 0.02) continue;+ const [hot, warm, dim] = this.rim;+ p.disc(x + ux * r * 0.26, y + uy * r * 0.26, r * 0.72, dim, lit * 0.55);+ p.disc(x + ux * r * 0.5, y + uy * r * 0.5, r * 0.46, warm, lit * 0.5);+ if (r > 3) p.disc(x + ux * r * 0.68, y + uy * r * 0.68, r * 0.24, hot, lit * 0.4);+ }+ }+}++/**+ * An obsidian shard from core Bits ({ x, y, a, s, life }): a thin triangle pointing along its spin angle, a+ * dark violet body, the long edge facing the light at (lx, ly) lit (brighter with lk), the other in shadow,+ * a white glint at the tip while the light is strong. C is an 8-step palette.+ */+export function shard(p, b, C, lx, ly, lk) {+ const fa = Math.min(1, b.life / 0.4), ca = Math.cos(b.a), sa = Math.sin(b.a), L = Math.max(2, b.s), W = Math.max(2, L * 0.55);+ const side = -sa * (lx - b.x) + ca * (ly - b.y) > 0 ? 1 : -1;+ const rim = lk > 0.6 ? C[6] : lk > 0.3 ? C[5] : lk > 0.08 ? C[4] : C[3], E = L / 2 + 1.5;+ p.shade(b.x - E, b.y - E, b.x + E, b.y + E, (x, y, out) => {+ const dx = x - b.x, dy = y - b.y, u = dx * ca + dy * sa, v = (-dx * sa + dy * ca) * side;+ if (u < -L / 2 - 0.4 || u > L / 2 + 0.4) return;+ const half = ((W / 2) * (L / 2 - u)) / L + 0.4;+ if (Math.abs(v) > half) return;+ out.a = fa;+ if (u > L / 2 - 1.3 && lk > 0.3) return WHITE;+ if (v > half - 1) return u > -L / 4 ? rim : C[Math.max(3, C.indexOf(rim) - 1)];+ return v < -half + 1 ? C[1] : C[2];+ });+ if (lk > 0.04) p.glow(b.x, b.y, 3 + L * 0.6, C[5], 0.2 * lk * fa);+}++/**+ * Ink drops: fly under gravity, land on the floor (y = floor(x)) and call onLand(x, y, speed).+ * add(x, y, vx, vy, size); update(dt); draw(p, body, shine) draws a dark drop with a lit top.+ */+export class Drops {+ constructor(o = {}) {+ this.list = [];+ this.floor = o.floor ?? (() => 0);+ this.onLand = o.onLand ?? null;+ this.g = o.g ?? 0.8;+ }+ add(x, y, vx, vy, size = 1) {+ this.list.push({ x, y, vx, vy, size });+ }+ update(dt) {+ for (let i = this.list.length - 1; i >= 0; i--) {+ const d = this.list[i];+ d.vy += GRAVITY * this.g * dt;+ d.vx -= d.vx * 0.4 * dt;+ d.x += d.vx * dt;+ d.y += d.vy * dt;+ const f = this.floor(d.x);+ if (d.vy > 0 && d.y >= f) {+ this.onLand?.(d.x, f, d.vy, d.size);+ this.list.splice(i, 1);+ }+ }+ }+ draw(p, body, shine) {+ for (const d of this.list) {+ const up = d.vy < 0;+ p.px(d.x, d.y, body);+ if (d.size > 1.4) p.px(d.x, d.y + (up ? 1 : -1), body);+ p.px(d.x, d.y - (d.size > 1.4 && !up ? 1 : 0), shine);+ }+ }+}++/**+ * A dark pool opened in the floor, seen at a slant (radius rx, centred on the floor at x = 0): the far lip lit,+ * the near lip dark, ripples ({ x, t0, life, w }) running out across it, a sheen along the far side, a wet fringe.+ */+export function floorPool(p, C, rx, t, ripples) {+ if (rx < 1) return;+ const ry = rx * 0.17 + 0.6;+ p.shade(-rx - 3, -ry - 2, rx + 3, ry + 2, (x, y) => {+ const dx = x / rx, dy = (y - 0.5) / ry, d = Math.sqrt(dx * dx + dy * dy);+ if (d > 1.18) return;+ if (d > 1) {+ if (dy < 0 && d < 1.09) return Math.abs(dx) < 0.55 ? C[6] : Math.abs(dx) < 0.85 ? C[5] : C[4];+ if (dy >= 0 && d < 1.09) return C[2];+ return y > -0.5 && noise(x * 0.7, 9) > 0.15 ? C[1] : undefined;+ }+ // ripples: ellipses on the slanted surface, kept about a pixel thick all the way round+ for (const r of ripples) {+ const age = t - r.t0, rr = age * 46 * r.w + 1, ex = x - r.x, ey = (y - 0.5) / 0.17, e = Math.sqrt(ex * ex + ey * ey) || 1;+ const g = Math.sqrt(ex * ex + (ey / 0.17) ** 2) / e;+ if (Math.abs(e - rr) < 0.55 * g && age < r.life) return age < r.life * 0.5 ? C[4] : C[3];}+ if (dy < -0.55 && dy > -0.85 && noise(x * 0.25 + t * 1.3, 4) > 0.2) return noise(x * 0.6 - t * 2, 6) > 0.55 ? C[5] : C[2];+ // the far inner wall catches the glow from below: violet just under the lip, falling to black+ if (dy < -0.35 && d > 0.72) return d > 0.9 ? C[3] : C[2];+ return d > 0.86 ? C[1] : C[0];+ });}diff --git a/src/fx/shadow/black-hole.js b/src/fx/shadow/black-hole.jsindex 43a2cd0..d2a0e71 100644--- a/src/fx/shadow/black-hole.js+++ b/src/fx/shadow/black-hole.js@@ -1,87 +1,153 @@-import { cycle, tileNoise, ease, at, TAU } from "../../core/index.js";-import { steps } from "./_lib.js";+// The dithered tone ramp and the brighter, bluer approaching side are adapted from Sprite Fusion's open-source+// black-hole (https://www.spritefusion.com/pixel-art-vfx/black-hole), MIT License, Copyright (c) 2026 Hugo Duprez.+import { cycle, fit, clamp, smooth, TAU, WHITE, hex, mix } from "../../core/index.js";+import { VOID, halo, unlight } 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,+ desc: "A tilted disk of banded rings turns round a black hole, its far side bent up over the top and under the bottom; debris spirals in, stretches and is swallowed.",+ tags: ["shadow", "black-hole", "void", "space", "gravity", "dark", "magic", "loop"],+ size: [184, 132],+ origin: [92, 124],+ duration: 4,loop: true,fps: 30,- bg: "dark",- options: {- palette: ["#08050e", "#1a0c2c", "#34124e", "#5a1c7c", "#8a2ea6", "#c454c4", "#f496d8", "#fff2fa"],- radius: 32, count: 6, seed: 11,- },+ bg: "ground",+ options: { palette: VOID, rock: ["#120d1c", "#2e2440", "#544468", "#857399"], seed: 4 },};-const TILT = 0.22, RH = 7.5; // disk tilt (y squash) and the shadow's radius+// the hole's centre, its shadow, how hard it bends light; the disk's tilt (screen angle, and how open it is)+// light bent over the top left the far side's upper face, so the arch sees the disk more face-on (SI_ARCH)+const Y = -70, RS = 13.5, E = 17.5, SI = 0.25, SI_ARCH = 0.46, TILT = -0.14, D = 4;+const CT = Math.cos(TILT), ST = Math.sin(TILT);+// rings with gaps between them, inner ones hotter and turning faster (whole turns of pattern a loop)+const BANDS = [+ { r0: 18, r1: 24, n: 5, hot: 1.35, k: 0.3 },+ { r0: 26, r1: 34, n: 3, hot: 0.92, k: 1.9 },+ { r0: 35.5, r1: 46, n: 2, hot: 0.64, k: 3.7 },+ { r0: 47.5, r1: 60, n: 1, hot: 0.42, k: 5.2 },+];+const ROUT = 60;+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 ICE = hex("#e4f7ff");-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);- });- };+// brightness of the disk at a point of its plane (X across, Z away from us), banded, streaked, turning+function disk(X, Z, t) {+ const rho = Math.sqrt(X * X + Z * Z);+ for (const b of BANDS) {+ if (rho < b.r0 || rho > b.r1) continue;+ const w = (rho - b.r0) / (b.r1 - b.r0), ph = Math.atan2(Z, X) - (TAU * b.n * t) / D;+ const streak = 0.62 + 0.22 * Math.cos(7 * ph + rho * 0.8 + b.k) + 0.16 * Math.cos(13 * ph - rho * 1.6 + b.k * 2);+ const lane = 0.72 + 0.28 * Math.cos(rho * 2.3 + b.k);+ const edge = smooth(0, 0.18, w) * (1 - smooth(0.78, 1, w));+ return { I: b.hot * streak * lane * (0.35 + 0.65 * edge), dop: -X / rho };+ }+ return null;+}- // 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);+// the hole and its disk, ray by ray: the near half straight in front, the far half seen through the bend+// (above the hole, and as a thin second image below it), the shadow, and the photon ring at its edge+function hole(p, C, t, pulse) {+ const RAMP = [C[1], C[2], C[3], C[4], C[5], C[6], C[7], WHITE], n = RAMP.length;+ const W = ROUT + 2, H = 42;+ p.shade(-W, Y - H, W, Y + H, (x, y, out) => {+ const dx = x, dy = y - Y, u = dx * CT + dy * ST, v = -dx * ST + dy * CT, r = Math.sqrt(u * u + v * v);+ let s = null;+ if (v > 0) s = disk(u, -v / SI, t);+ if (!s && r > RS) {+ const k = 1 - (E * E) / (r * r), bu = u * k, bv = v * k, si = k > 0 ? SI_ARCH : SI;+ if (-bv / si > 0) s = disk(bu, -bv / si, t);}- };-- 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);+ if (!s || s.I < 0.06) {+ if (r < RS - 0.4) return C[0];+ if (r < RS + 0.7) {+ const a = Math.atan2(v, u), f = 0.5 + 0.5 * Math.cos(3 * a + (TAU * 2 * t) / D) + pulse * 0.4;+ out.k = 0.3;+ return f > 0.55 ? WHITE : C[7];+ }+ return;+ }+ // tone: dithered between ramp steps; the side turning toward us brighter and icier+ const I = s.I * 1.3 * (1 + 0.55 * s.dop) * (1 + 0.25 * pulse), f = clamp(I) * (n - 1);+ let i = Math.floor(f);+ if (f - i > BAYER[((Math.floor(y) & 3) << 2) | (Math.floor(x) & 3)]) i = Math.min(n - 1, i + 1);+ if (i === 0 && I < 0.12) return;+ let c = RAMP[i];+ if (s.dop > 0.35 && i >= n - 3) c = mix(c, ICE, Math.min(1, (s.dop - 0.35) * 2));+ if (s.dop < -0.4 && i >= 2 && i < n - 2) c = mix(c, C[3], 0.35);+ if (i >= n - 4 && ((Math.floor(x) + Math.floor(y)) & 1) === 0) out.k = 0.3 * Math.min(1, I - 0.35);+ return c;});- // the shadow and its photon ring- p.circle(0, 0, RH + 1, (d) => (d > 0.88 ? C[7] : C[0]));+}- bitPass(false);- diskPass(true);+export function drawBack(p, t, o) {+ const C = fit(o.palette, 8);+ p.glow(0, -1, 44, C[4], 0.12);+ p.glow(0, Y, 80, C[4], 0.32);+ p.glow(0, Y, 46, mix(C[6], C[5], 0.5), 0.45);+}- 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);+export function draw(p, t, o) {+ const C = fit(o.palette, 8), K = fit(o.rock, 4), S = o.seed;+ // a gulp as debris is swallowed, twice a loop+ const pulse = Math.max(0, Math.cos((TAU * 2 * t) / D)) ** 12;+ // pebbles torn off the floor, rising to join the disk+ cycle(t, D, 10, S + 3, (r) => r.range(1.6, 2.6), (age, L, r) => {+ const x0 = r.range(-60, 60), u = Math.pow(age / L, 1.5), tx = Math.sign(x0 || 1) * r.range(40, 56), ty = Y + r.range(4, 9);+ const x = x0 + (tx - x0) * u, y = -1 + (ty + 1) * u - Math.sin(Math.PI * u) * 10;+ p.px(x, y, u > 0.6 ? K[3] : K[2]);+ if (age < 0.25) p.disc(x0, -1.5, 2 + age * 8, K[2], 0.4 * (1 - age / 0.25));+ });+ hole(p, C, t, pulse);+ // motes streaking in from all round, turning with the disk as they fall+ cycle(t, D, 40, S + 7, (r) => r.range(0.5, 0.9), (age, L, r) => {+ const a0 = r.range(0, TAU), d0 = r.range(48, 76), q = Math.pow(age / L, 1.6), d = RS + 2 + (d0 - RS - 2) * (1 - q), a = a0 + 0.9 * q;+ const x = Math.cos(a) * d * 1.15, y = Y + Math.sin(a) * d * 0.75, q2 = Math.pow(Math.max(0, age - 0.09) / L, 1.6), d2 = RS + 2 + (d0 - RS - 2) * (1 - q2), a2 = a0 + 0.9 * q2;+ if (d < RS + 3 || y > -3 || y < -120 || Y + Math.sin(a2) * d2 * 0.75 < -120 || Math.abs(x) > 90) return;+ const col = r.pick([WHITE, C[7], C[6], C[5]]);+ p.line(Math.cos(a2) * d2 * 1.15, Y + Math.sin(a2) * d2 * 0.75, x, y, (u) => (u > 0.6 ? col : C[4]), Math.min(1, age * 6));+ p.glow(x, y, 3, col, 0.3);+ });+ // debris spiralling in: lumps of rock lit on the side toward the hole, stretched into hot streaks as they+ // fall, gone in a flash at the photon ring; behind the hole they're hidden by it+ cycle(t, D, 22, S, (r) => r.range(1.4, 2.4), (age, L, r) => {+ const ph0 = r.range(0, TAU), rho0 = r.range(58, 80), hgt = r.range(-8, 8), size = r.range(1.6, 2.8);+ const at = (aa) => {+ const q = clamp(aa / L), rho = RS + 1 + (rho0 - RS - 1) * (1 - Math.pow(q, 1.5)), ph = ph0 + 2.4 * Math.pow(q, 1.6) * (1 + 1.5 * q);+ const X = Math.cos(ph) * rho, Z = Math.sin(ph) * rho, sx = X, sy = -Z * SI + hgt * (1 - q);+ return { x: sx * CT - sy * ST, y: Y + sx * ST + sy * CT, Z, rho };+ };+ const a = at(age), b = at(age - 0.04), hidden = a.Z > 0 && Math.hypot(a.x, a.y - Y) < RS + 1;+ if (hidden) return;+ if (a.rho < RS + 3) {+ p.px(a.x, a.y, WHITE);+ p.glow(a.x, a.y, 6, C[6], 0.6);+ return;+ }+ const heat = 1 - smooth(16, 34, a.rho), len = 1 + heat * 7;+ if (heat > 0.05) {+ const dx = a.x - b.x, dy = a.y - b.y, l = Math.hypot(dx, dy) || 1;+ p.line(a.x - (dx / l) * len, a.y - (dy / l) * len, a.x, a.y, (u) => (u > 0.7 ? WHITE : u > 0.35 ? C[6] : C[4]));+ p.glow(a.x, a.y, 4, C[6], 0.4 * heat);+ } else {+ const lx = -a.x / (Math.hypot(a.x, a.y - Y) || 1), ly = -(a.y - Y) / (Math.hypot(a.x, a.y - Y) || 1);+ // a lump of rock: a fading wake along its orbit, a dark body, its face toward the hole lit violet+ const c = at(age - 0.09), d = at(age - 0.15);+ p.px(b.x, b.y, C[3]);+ p.dot(c.x, c.y, C[3], 0.7);+ p.dot(d.x, d.y, C[2], 0.5);+ const s2 = size > 2.2;+ p.px(a.x, a.y, K[2]);+ p.px(a.x + 1, a.y, K[1]);+ p.px(a.x, a.y + 1, K[1]);+ if (s2) (p.px(a.x + 1, a.y + 1, K[0]), p.px(a.x - 1, a.y, K[1]), p.px(a.x, a.y - 1, K[2]));+ p.px(a.x + Math.round(lx * 1.4), a.y + Math.round(ly * 1.4), s2 ? C[6] : C[5]);+ p.glow(a.x, a.y, 4, C[5], 0.15);+ }+ });+ halo(p, 0, Y, RS - 0.4, RS + 4, C[6], 0.35 + 0.3 * pulse);+ unlight(p, -RS, Y - RS, RS, Y + RS, (x, y) => {+ const dx = x, dy = y - Y, v = -dx * ST + dy * CT, u = dx * CT + dy * ST;+ return u * u + v * v < (RS - 0.6) ** 2 && !(v > 0 && disk(u, -v / SI, t));+ });}diff --git a/src/fx/shadow/curse.js b/src/fx/shadow/curse.jsindex dd5c97b..989f6a0 100644--- a/src/fx/shadow/curse.js+++ b/src/fx/shadow/curse.js@@ -1,81 +1,239 @@-import { burst, seg, ease, clamp, rand, bump, TAU, WHITE } from "../../core/index.js";-import { steps, UMBRA, SKULL_11, shape } from "./_lib.js";+// The tint that floods the character and the gas round it are adapted from Sprite Fusion's open-source poison+// aura (https://www.spritefusion.com/pixel-art-vfx/poison), MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Bits, P, B, Rng, fit, sparkle, smooth, ease, noise, TAU, WHITE, mix, luma } from "../../core/index.js";+import { VOID, Puffs, PK, attract, ringFast, unlight } 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,+ desc: "Wisps gather over the head, a skull stamps down with a flash, its eyes burn as the curse floods the body violet, then it cracks and crumbles.",+ tags: ["shadow", "curse", "debuff", "skull", "status", "dark", "magic", "one-shot"],+ size: [112, 124],+ origin: [56, 108],+ duration: 3.4,loop: false,fps: 30,bg: "ground",- actor: true,- options: { palette: UMBRA, seed: 10 },+ actor: 2,+ options: { palette: VOID, bone: ["#170f26", "#4a3a6e", "#7f6ea6", "#b3a4d4", "#e2d8f6"], seed: 9 },};-const STAMP = 0.28; // the skull lands+// where the skull hangs, and the beats: it stamps in, burns, cracks, breaks+const SY = -60, STAMP = 0.55, CRACK = 1.72, BREAK = 1.98;-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 skull, drawn by hand (light from the upper left): k outline, d m l h bone dark to bright, e sockets,+// n nose, t teeth, g the gaps between them+const SKULL = [+ "......kkkkk......",+ "....kkhhhhlkk....",+ "...khhhhhhlllk...",+ "..khhhhhllllllk..",+ ".khhhhlllllllmmk.",+ ".khhhllllllllmmk.",+ "khhllllllllllmmdk",+ "khlldddllldddmmdk",+ "khleeeeelleeeeedk",+ "kleeeeeelleeeeedk",+ "kleeeeeemleeeeedk",+ "kmleeeelmmleeedkk",+ ".kmmlllmnnmlmddk.",+ "..kmmlmnnnnmddk..",+ "..kdmlllmmlmddk..",+ "...kgtgtgtgtgk...",+ "...kdgtgtgtgdk...",+ "....kkkkkkkkk....",+];+const SW = 17, SH = 18, EYES = [[-3.5, 1.5], [3.5, 1.5]];+const inSkull = (u, v) => u >= 0 && v >= 0 && u < SW && v < SH && SKULL[v][u] !== ".";+// cracks: jagged paths from the crown down to the sockets and out to the temple, each pixel with its turn to split+const CRACKS = (() => {+ const out = new Map(), paths = [[[8, 1], [7, 3], [8, 5], [6, 6], [5, 7]], [[9, 1], [10, 3], [10, 4], [12, 6], [12, 7]], [[4, 3], [3, 5], [2, 6]], [[13, 4], [14, 6]]];+ for (const path of paths) {+ let n = 0;+ const len = path.length - 1;+ for (let k = 0; k < len; k++) {+ const [x0, y0] = path[k], [x1, y1] = path[k + 1], steps = Math.max(Math.abs(x1 - x0), Math.abs(y1 - y0));+ for (let s = 0; s <= steps; s++) {+ const x = Math.round(x0 + ((x1 - x0) * s) / steps), y = Math.round(y0 + ((y1 - y0) * s) / steps), key = y * SW + x;+ if (!out.has(key)) out.set(key, (k + s / Math.max(1, steps)) / len);+ n++;+ }}- });+ }+ return out;+})();- // 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 skull at scale s (squashed by sq as it lands), shaken by (ox, oy); white for the stamp's first frames;+// crack 0..1 splits it from the crown, light leaking out of the splits+function skull(p, C, K, s, sq, ox, oy, white, crack) {+ const PAL = { k: K[0], d: K[1], m: K[2], l: K[3], h: K[4], e: C[0], n: C[0], t: K[3], g: K[0] };+ const cx = ox, cy = SY + oy, hw = (SW / 2) * s + 1, hh = (SH / 2) * s * sq + 1;+ p.shade(cx - hw, cy - hh, cx + hw, cy + hh, (x, y) => {+ const u = Math.floor((x - cx) / s + SW / 2), v = Math.floor((y - cy) / (s * sq) + SH / 2);+ if (!inSkull(u, v)) return;+ const ch = SKULL[v][u];+ if (white) return ch === "e" || ch === "n" ? C[5] : WHITE;+ const ck = CRACKS.get(v * SW + u);+ if (ck !== undefined && ck < crack) return crack > 0.55 && (u + v) % 2 ? C[6] : K[0];+ return PAL[ch];});- // 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));+// a socket burning: tongues of violet flame from a white root, licking up out of the eye+function eyeFire(p, C, x, y, t, k, i) {+ if (k <= 0) return;+ // two thin tongues lick up out of the socket and past the brow, swaying, cooling to violet+ for (const j of [-0.6, 0.7]) {+ const h = (1.5 + 3 * (0.5 + 0.5 * noise(t * 8 + j * 3.1 + i * 7, 4))) * k, sw = noise(t * 4 + j * 2 + i * 3, 8) * 1.2;+ for (let d = 1; d <= h; d += 0.5) {+ const u = d / h;+ p.dot(x + j + sw * u * u, y - d, u < 0.3 ? C[7] : u < 0.6 ? C[6] : u < 0.85 ? C[5] : C[4], u < 0.75 ? 1 : (1 - u) * 4);}- 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]);- });+ // the pupil: a hard white point in the dark+ p.px(x, y, WHITE);+ p.px(x - 1, y, C[6]);+ p.glow(x, y, 8, C[5], 0.5 * k);+}++export function create(o) {+ const C = fit(o.palette, 8), K = fit(o.bone, 5), R = new Rng(o.seed), A = o.actor, floor = () => 0;+ const ps = new Particles({ rng: R, ground: floor, sparks: [WHITE, C[7], C[6], C[5]], haze: C[4] });+ const puffs = new Puffs({ rng: R, flame: [WHITE, C[7], C[6], C[5], C[4], C[3], C[2], C[1], C[0]], soot: [mix(C[3], C[2], 0.5), mix(C[1], C[0], 0.3)], cap: mix(C[4], C[2], 0.5), rim: [C[6], C[5], C[4]], floor });+ const dust = new Puffs({ rng: R, flame: [WHITE, WHITE, WHITE, WHITE, WHITE, WHITE, WHITE, WHITE, WHITE], soot: [mix(K[2], K[1], 0.4), mix(K[1], K[0], 0.5)], cap: K[3], rim: [K[4], K[3], K[2]], floor });+ const bits = new Bits({ ground: floor }), lights = [];+ let t = 0, stamped = false, broke = false, acc = 0;+ const light = (x, y, r, c, k, life) => lights.push({ x, y, r, c, k, life, max: life });+ const head = A ? A.y : -38;++ return {+ update(dt) {+ t += dt;+ // wisps and motes gather over the head, spiralling in+ if (t < STAMP - 0.05) {+ const k = t / STAMP;+ for (acc += dt * (40 + 60 * k); acc > 1; acc--) {+ const a = R.range(0, TAU), D = R.range(22, 44);+ ps.spawn(P.MOTE, Math.cos(a) * D, SY + Math.sin(a) * D * 0.8, -Math.sin(a) * 60, Math.cos(a) * 60, 0.8, R.pick([WHITE, C[7], C[6], C[5]]), R.range(0.6, 1));+ }+ if (R.chance(dt * 14)) {+ const a = R.range(0, TAU), D = R.range(20, 34);+ puffs.spawn(PK.SOOT, Math.cos(a) * D, SY + Math.sin(a) * D * 0.7, -Math.sin(a) * 40, Math.cos(a) * 30, R.range(0.5, 0.7), R.range(3, 5.5));+ }+ attract(ps.list, 0, SY, 9e5 * (0.4 + k), 70, 0.6, 2.5, dt, (q) => (q.k === P.MOTE ? 1 : 0), 300);+ attract(puffs.list, 0, SY, 5e5 * (0.4 + k), 60, 0.7, 3.5, dt, () => 1, 120);+ }+ if (t >= STAMP && !stamped) {+ stamped = true;+ ps.list.length = 0;+ puffs.list.length = 0;+ light(0, SY, 64, C[5], 1, 0.35);+ light(0, SY, 30, WHITE, 1, 0.1);+ light(0, head + 12, 40, C[4], 0.6, 0.5);+ for (let i = 0; i < 22; i++) {+ const a = R.range(0, TAU), sp = R.range(80, 160);+ ps.spawn(P.SPARK, Math.cos(a) * 6, SY + Math.sin(a) * 6, Math.cos(a) * sp, Math.sin(a) * sp - 30, R.range(0.2, 0.5));+ }+ for (let i = 0; i < 6; i++) {+ const a = R.range(0, TAU), sp = R.range(20, 45);+ puffs.spawn(PK.SOOT, Math.cos(a) * 8, SY + Math.sin(a) * 6, Math.cos(a) * sp, Math.sin(a) * sp * 0.6 - 10, R.range(0.6, 0.9), R.range(2.5, 4.5));+ }+ }+ // it burns: embers and thin smoke off the eyes, a violet haze round it, the curse dripping onto the head+ if (stamped && !broke) {+ for (const [ex, ey] of EYES) {+ if (R.chance(dt * 9)) ps.spawn(P.EMBER, ex, SY + ey - 3, R.range(-10, 10), -R.range(20, 45), R.range(0.5, 0.9), C[6]);+ if (R.chance(dt * 7)) puffs.spawn(PK.SOOT, ex + R.range(-1, 1), SY + ey - 3, R.range(-5, 5), -R.range(14, 26), R.range(0.5, 0.8), R.range(1.4, 2.4));+ }+ if (R.chance(dt * 8)) ps.spawn(P.VAPOUR, R.range(-7, 7), SY + R.range(-6, 6), R.range(-12, 12), R.range(-12, 4), R.range(0.5, 0.8), R.chance(0.5) ? C[3] : C[4], R.range(5, 8));+ // the curse runs down from the skull into the head+ if (R.chance(dt * 12)) ps.spawn(P.MOTE, R.range(-4, 4), SY + 9, R.range(-6, 6), R.range(40, 70), R.range(0.25, 0.4), R.chance(0.5) ? C[6] : C[5], 0.8);+ if (R.chance(dt * 10)) puffs.spawn(PK.SOOT, R.range(-3.5, 3.5), SY + 9, R.range(-3, 3), R.range(14, 26), R.range(0.45, 0.7), R.range(1.2, 2.2));+ if (t > STAMP + 0.3 && R.chance(dt * 5)) ps.spawn(P.STAR, R.range(-1, 1) * (A ? A.w / 2 : 10), head + R.range(4, A ? A.h - 4 : 30), 0, -6, R.range(0.3, 0.5), C[6], R.range(1, 2));+ }+ if (t >= BREAK && !broke) {+ broke = true;+ // the skull breaks: chunks of bone tumble and bounce, grit rains, dust and the last of the fire rise+ for (let i = 0; i < 24; i++) {+ let x, y;+ do (x = R.range(-8.5, 8.5)), (y = R.range(-9, 9));+ while (!inSkull(Math.floor(x + SW / 2), Math.floor(y + SH / 2)));+ bits.add({ kind: B.CHUNK, x, y: SY + y, vx: x * R.range(2.5, 6) + R.range(-12, 12), vy: R.range(-70, 10), g: 0.85, drag: 0.4, bounce: 0.35, life: R.range(0.8, 1.2), a: R.range(0, TAU), va: R.range(-14, 14), s: R.range(1, 2.4), ramp: [K[0], K[1], K[2], K[3], K[4]] });+ }+ for (let i = 0; i < 26; i++) ps.spawn(P.GRIT, R.range(-7, 7), SY + R.range(-8, 8), R.range(-32, 32), R.range(-60, 20), R.range(0.8, 1.3), R.pick([K[2], K[3], K[3], K[4]]), R.chance(0.3) ? 2 : 1);+ for (let i = 0; i < 7; i++) dust.spawn(PK.SOOT, R.range(-7, 7), SY + R.range(-8, 6), R.range(-25, 25), R.range(-20, 5), R.range(0.5, 0.8), R.range(2, 4), R.range(0, 0.1));+ for (const [ex, ey] of EYES) puffs.spawn(PK.FLAME, ex, SY + ey, Math.sign(ex) * 6, -30, 0.5, 2.6, 0, false);+ light(0, SY, 40, C[5], 0.5, 0.25);+ }+ for (let i = lights.length - 1; i >= 0; i--) if ((lights[i].life -= dt) <= 0) lights.splice(i, 1);+ // chunks that land kick up a little dust+ bits.update(dt);+ for (const b of bits.list)+ if (b.rest && !b.dusted) {+ b.dusted = true;+ dust.spawn(PK.SOOT, b.x, -1.5, R.range(-12, 12), -R.range(4, 10), R.range(0.35, 0.6), R.range(1.5, 2.5));+ }+ ps.update(dt);+ puffs.update(dt);+ dust.update(dt);+ },+ drawBack(p) {+ puffs.draw(p, PK.SOOT, { x: 0, y: SY, k: stamped && !broke ? 0.8 : 0.3, reach: 50 });+ dust.draw(p, PK.SOOT);+ ps.draw(p, "back");+ },+ draw(p) {+ // the curse floods down the body from the head, a bright front ahead of it, then ebbs+ const flood = smooth(STAMP + 0.04, STAMP + 0.42, t), ebb = 1 - smooth(BREAK + 0.15, BREAK + 0.75, t);+ if (A && flood > 0 && ebb > 0) {+ const k = ebb, pulse = 0.85 + 0.15 * Math.sin(t * 9);+ for (let my = 0; my < A.h; my++) {+ const u = my / A.h;+ if (u > flood + 0.06) break;+ const edge = flood < 1 && Math.abs(u - flood) < 0.05, band = flood >= 1 && Math.abs(u - (((t - STAMP) * 1.3) % 1.4) + 0.2) < 0.06;+ for (let mx = 0; mx < A.w; mx++) {+ const c0 = A.pixels[my * A.w + mx];+ if (!c0) continue;+ const l = luma(c0), cc = l > 0.72 ? C[6] : l > 0.5 ? C[5] : l > 0.33 ? C[4] : l > 0.18 ? C[3] : C[2];+ p.blend(A.x + mx, A.y + my, edge ? C[7] : band ? C[6] : cc, edge ? 0.85 : band ? 0.7 * k : 0.6 * k * pulse);+ }+ }+ // a crawling violet edge round the cursed body+ p.outline(A.mask, A.x, A.y, (mx, my) => (Math.sin(my * 0.7 - t * 14 + mx * 0.3) > 0.2 ? C[6] : C[4]), (mx, my) => (my / A.h <= flood ? k : 0));+ p.glow(0, A.y + A.h * 0.45, 30, C[4], 0.3 * k * pulse);+ }+ // the gathering: a dim swirl of light where the skull will be+ if (t < STAMP) {+ const q = t / STAMP;+ p.glow(0, SY, 14 + 16 * q, C[5], 0.2 + 0.5 * q);+ if (q > 0.15) ringFast(p, 0, SY, 4 + 30 * (1 - ease.inQuad(q)), 1, q > 0.7 ? C[5] : q > 0.4 ? C[4] : C[3]);+ }+ // the skull: it slams down from big and pale, squashes, bobs while it burns, shakes as it cracks+ if (t >= STAMP && t < BREAK) {+ const u = (t - STAMP) / 0.1, s = u < 1 ? 1.7 - 0.7 * ease.inQuad(u) : 1, land = t - STAMP - 0.1;+ const sq = land > 0 ? 1 - 0.16 * Math.exp(-land * 18) * Math.cos(land * 40) : 1;+ const shake = t > CRACK ? (t - CRACK) * 4 : 0, ox = Math.round(Math.sin(t * 61) * shake), oy = land > 0 ? Math.round(Math.sin(t * 3.4) * 1.2) : 0;+ skull(p, C, K, s, sq, ox, oy, t < STAMP + 0.067, smooth(CRACK, BREAK, t));+ const burn = smooth(STAMP + 0.1, STAMP + 0.25, t);+ if (u >= 1) EYES.forEach(([ex, ey], i) => eyeFire(p, C, ox + ex, SY + oy + ey, t, burn * (1 + 0.4 * smooth(CRACK, BREAK, t)), i));+ if (u < 1.2) sparkle(p, 0, SY, 14 * (1 - u / 1.2), C[7], C[5], 0.6);+ p.glow(0, SY, 26, C[4], 0.25);+ }+ // the stamp's shock ring+ const ru = (t - STAMP - 0.08) / 0.3;+ if (ru > 0 && ru < 1) ringFast(p, 0, SY + 2, 10 + 26 * ease.outCubic(ru), Math.max(1, 2.5 * (1 - ru)), (v) => (v > 0.5 ? WHITE : C[6]), 1.2 - ru);+ bits.draw(p);+ puffs.draw(p, PK.FLAME);+ ps.draw(p, "front");+ for (const l of lights) {+ const q = l.life / l.max;+ p.glow(l.x, l.y, l.r * (0.6 + 0.4 * q), l.c, l.k * q * q);+ }+ // bone keeps its own colours under the glow (all but the stamp's white frame)+ if (t >= STAMP + 0.067 && t < BREAK)+ unlight(p, -10, SY - 10, 10, SY + 10, (x, y) => {+ const u = Math.floor(x + SW / 2), v = Math.floor(y - SY + SH / 2);+ return inSkull(u, v) && SKULL[v][u] !== "e";+ }, 0.2);+ },+ };}diff --git a/src/fx/shadow/dark-explosion.js b/src/fx/shadow/dark-explosion.jsindex e6fb2ea..0a088c0 100644--- a/src/fx/shadow/dark-explosion.js+++ b/src/fx/shadow/dark-explosion.js@@ -1,110 +1,323 @@-import { burst, fly, flyV, seg, ease, clamp, star, tileNoise, TAU, WHITE } from "../../core/index.js";-import { steps, UMBRA } from "./_lib.js";+// The pull that swirls motes into the core and the collapse burst are adapted from Sprite Fusion's open-source+// black-hole (https://www.spritefusion.com/pixel-art-vfx/black-hole), the sparks, rings and smoke from his explosion,+// MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Bits, P, B, Rng, fit, sparkle, band, clamp, smooth, ease, noise, hex, TAU, WHITE, mix } from "../../core/index.js";+import { VOID, Puffs, PK, halo, ringLight, ringFast, unlight, blackStar, attract, shard } 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,+ desc: "Motes swirl into a pulsing core, a black star cuts across a violet-white flash, and a black sphere burns at the rim, throws lit shards and smoke, then collapses.",+ tags: ["shadow", "explosion", "void", "dark", "magic", "impact", "one-shot"],+ size: [280, 248],+ origin: [140, 206],+ duration: 3.8,loop: false,fps: 30,- bg: "dark",- options: { palette: UMBRA, size: 1, seed: 6 },+ bg: "ground",+ options: { palette: VOID, seed: 6 },};-const T0 = 0.16; // the moment it goes off+// the heart of the blast hangs above the floor; the sphere's radius; the beats of the choreography+const Y = -54, RS = 16, REL = 0.52, BURN = 1.62, POP = 1.84, SMOKE = hex("#5d5468");-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;- }+// a black sphere: a void body (a faint crescent of reflected light low on the right, a dull glint high on the+// left), a white rim, and pointed tongues of violet flame that lean up, flicker and crawl round it+function sphere(p, C, r, t, heat) {+ if (r < 0.6) return;+ const E = r + 12 * heat + 2;+ p.shade(-E, Y - E, E, Y + E, (x, y, out) => {+ const dx = x, dy = y - Y, d = Math.sqrt(dx * dx + dy * dy);+ if (d > E) return;+ if (d < r - 0.5) {+ const e = r - d, ang = Math.atan2(dy, dx);+ if (e < 1.4 && Math.cos(ang - 0.8) > 0.55) return C[2];+ if (r > 8 && (dx + r * 0.45) ** 2 + (dy + r * 0.45) ** 2 < 1.6) return C[3];+ return C[0];+ }+ const e = d - (r - 0.5);+ if (e < 1) {+ out.c = Math.sin(Math.atan2(dy, dx) * 7 + t * 9) > -0.6 ? WHITE : C[7];+ out.k = 0.4;+ return;+ }+ // the further out, the lower the angle it's sampled at: tongues bend upward like flame+ const ang = Math.atan2(dy + e * 0.6, dx), top = Math.max(0, -Math.sin(ang));+ const a1 = ang - t * 0.9, a2 = ang + t * 1.7;+ const i1 = Math.round((a1 * 9) / TAU), i2 = Math.round((a2 * 15) / TAU);+ const T1 = Math.pow(0.5 + 0.5 * Math.cos(a1 * 9), 3) * (0.55 + 0.45 * noise(t * 7 + i1 * 3.7, 1));+ const T2 = Math.pow(0.5 + 0.5 * Math.cos(a2 * 15), 4) * (0.5 + 0.5 * noise(t * 11 + i2 * 5.1, 2));+ const h = heat * (0.3 + 0.95 * top) * (1.5 + 12 * Math.max(0, T1) + 6 * Math.max(0, T2));+ if (e > h + 1) return;+ const u = (e - 1) / h;+ out.c = u < 0.18 ? WHITE : u < 0.4 ? C[7] : u < 0.62 ? C[6] : u < 0.84 ? C[5] : C[4];+ out.a = u < 0.8 ? 1 : (1 - u) * 5;+ if (u < 0.6 && ((Math.floor(x) + Math.floor(y)) & 1) === 0) out.k = 0.25 * (1 - u);+ });+}- // 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 });+export function create(o) {+ const C = fit(o.palette, 8), R = new Rng(o.seed), floor = () => 0;+ const ps = new Particles({ rng: R, ground: floor, sparks: [WHITE, C[7], C[6], C[5]] });+ const embers = new Particles({ rng: R, ground: floor, sparks: [C[7], C[6], C[5], C[4]] });+ const puffs = new Puffs({+ rng: R,+ flame: [WHITE, C[7], C[6], C[5], C[5], C[4], C[4], C[3], C[2]],+ soot: [mix(mix(C[3], C[1], 0.3), SMOKE, 0.45), mix(C[1], SMOKE, 0.3)],+ cap: mix(mix(C[4], C[2], 0.5), SMOKE, 0.4),+ rim: [C[6], C[5], C[4]],+ floor,});- 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];- });+ const bits = new Bits({ ground: floor }), lights = [], rings = [];+ let t = 0, released = false, collapsing = false, popped = false, acc = 0, dustAcc = 0, flick = 1;++ const coreR = (tt) => (tt < REL - 0.07 ? 1.5 + 5 * ease.inQuad(tt / REL) : 1);+ const sphereR = (tt) => {+ if (tt < REL) return 0;+ if (tt < BURN) return RS * ease.outBack(clamp((tt - REL) / 0.14), 2.4) * (1 + 0.06 * smooth(REL + 0.3, BURN, tt) + 0.02 * Math.sin(tt * 11));+ if (tt < POP) return RS * 1.08 * (1 - ease.inQuad((tt - BURN) / (POP - BURN)));+ return 0;+ };+ const starL = (tt) => (tt < REL || tt > REL + 0.26 ? 0 : 60 * (1 - ease.inQuad(clamp((tt - REL - 0.05) / 0.21))));+ const starRot = (tt) => 0.32 + (tt - REL) * 2.2;+ // how hard the sphere lights what's round it: the rims of the smoke, the edges of the shards+ const burning = (tt) => (tt < REL ? clamp(tt / REL) * 0.7 : tt < BURN ? 1 : tt < POP ? 1.2 : Math.max(0, 1 - (tt - POP) / 0.35));+ const light = (x, y, r, c, k, life) => lights.push({ x, y, r, c, k, life, max: life });+ const rim = (a, r) => [Math.cos(a) * r, Y + Math.sin(a) * r];++ function release() {+ light(0, Y, 100, C[4], 1.25, 0.85);+ light(0, Y, 86, mix(C[6], WHITE, 0.5), 1.3, 0.22);+ rings.push({ r0: RS, r1: 104, life: 0.46, max: 0.46, th: 3.6, hot: true, delay: 0 });+ rings.push({ r0: RS * 0.8, r1: 62, life: 0.3, max: 0.3, th: 1.6, hot: true, delay: 0.02 });+ rings.push({ r0: RS, r1: 124, life: 0.62, max: 0.62, th: 1.2, hot: false, delay: 0.07 });+ // shards of the void: big slivers tumbling out and raining onto the floor, fine splinters faster+ for (let i = 0; i < 34; i++) {+ const big = i < 20, a = R.range(0, TAU), [x, y] = rim(a, RS * 0.7), sp = big ? R.range(80, 170) : R.range(130, 220);+ bits.add({ kind: B.SHARD, x, y, vx: Math.cos(a) * sp, vy: Math.sin(a) * sp - R.range(40, 110), g: 0.75, drag: big ? 1.3 : 1.7, bounce: 0.35, life: R.range(1.6, 2.6), a: R.range(0, TAU), va: R.range(-16, 16), s: big ? R.range(6, 11) : R.range(3, 4.5) });+ }+ for (let i = 0; i < 84; i++) {+ const a = R.range(0, TAU), [x, y] = rim(a, RS * 0.8), sp = R.range(120, 235);+ ps.spawn(P.SPARK, x, y, Math.cos(a) * sp, Math.sin(a) * sp - 50, R.range(0.2, 0.7));+ }+ for (let i = 0; i < 28; i++) {+ const a = R.range(0, TAU), [x, y] = rim(a, RS * 0.9), sp = R.range(30, 130);+ embers.spawn(P.EMBER, x, y, Math.cos(a) * sp, Math.sin(a) * sp - 40, R.range(1.3, 2.5));+ }+ for (let i = 0; i < 24; i++) {+ const a = R.range(0, TAU), [x, y] = rim(a, RS * 0.9), sp = R.range(15, 70);+ puffs.spawn(PK.SOOT, x, y, Math.cos(a) * sp, Math.sin(a) * sp * 0.8 - 14, R.range(2, 2.8), R.range(7, 12), R.range(0.02, 0.3));+ }+ // the shock flattens on the floor and shoves smoke out along it+ for (let i = 0; i < 12; i++) {+ const s = i % 2 ? 1 : -1;+ puffs.spawn(PK.SOOT, s * R.range(10, 40), -R.range(2, 5), s * R.range(50, 120), -R.range(0, 10), R.range(1.6, 2.4), R.range(5, 9), R.range(0.08, 0.2));+ }+ for (let i = 0; i < 10; i++) {+ const a = -Math.PI / 2 + R.range(-1.6, 1.6), [x, y] = rim(a, RS), sp = R.range(30, 80);+ puffs.spawn(PK.FLAME, x, y, Math.cos(a) * sp, Math.sin(a) * sp - 30, R.range(0.3, 0.6), R.range(2, 3.6), 0, R.chance(0.5));+ }+ // what was still falling in is swallowed by the blast+ ps.list.length = 0;+ puffs.list = puffs.list.filter((q) => q.delay > 0);}- // 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]);+ function pop() {+ light(0, Y, 56, WHITE, 0.9, 0.18);+ light(0, Y, 120, C[5], 0.8, 0.5);+ rings.push({ r0: 2, r1: 40, life: 0.28, max: 0.28, th: 2, hot: true, delay: 0 });+ for (let i = 0; i < 26; i++) {+ const a = R.range(0, TAU), sp = R.range(120, 250);+ ps.spawn(P.SPARK, 0, Y, Math.cos(a) * sp, Math.sin(a) * sp - 40, R.range(0.2, 0.6));+ }+ for (let i = 0; i < 14; i++) {+ const a = R.range(0, TAU), sp = R.range(20, 90);+ embers.spawn(P.EMBER, 0, Y, Math.cos(a) * sp, Math.sin(a) * sp - 30, R.range(0.9, 1.6));+ }+ for (let i = 0; i < 10; i++) {+ const a = R.range(0, TAU), sp = R.range(20, 70);+ puffs.spawn(PK.SOOT, Math.cos(a) * 3, Y + Math.sin(a) * 3, Math.cos(a) * sp, Math.sin(a) * sp - 15, R.range(1.1, 1.7), R.range(3, 6), R.range(0, 0.08));+ }- // 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];- });+ for (const q of [...embers.list, ...puffs.list]) {+ const dx = q.x, dy = q.y - Y, d = Math.hypot(dx, dy) || 1, f = 90 * Math.max(0, 1 - d / 70);+ q.vx += (dx / d) * f;+ q.vy += (dy / d) * f - f * 0.3;+ }+ // what's left of it climbs away as a column of smoke+ for (let i = 0; i < 12; i++)+ puffs.spawn(PK.SOOT, R.range(-6, 6), Y + R.range(-4, 6), R.range(-10, 10), -R.range(20, 55), R.range(1.3, 1.8), R.range(7, 12), R.range(0.02, 0.2));}- // 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));- });+ return {+ update(dt) {+ t += dt;+ flick = 0.88 + 0.12 * Math.sin(t * 37) * Math.sin(t * 23);+ // the charge: motes swirl in from all round, streaks shoot straight at the core, darkness gathers+ if (t < REL - 0.06) {+ const k = t / REL;+ for (acc += dt * (90 + 150 * k); acc > 1; acc--) {+ const a = R.range(0, TAU), D = R.range(36, 84), x = Math.cos(a) * D, y = Math.min(-3, Y + Math.sin(a) * D), vt = R.range(50, 110), vi = R.range(10, 40);+ ps.spawn(P.MOTE, x, y, -Math.sin(a) * vt - Math.cos(a) * vi, Math.cos(a) * vt - Math.sin(a) * vi, 0.9, R.pick([WHITE, C[6], C[6], C[5]]), R.range(0.7, 1.2));+ }+ if (R.chance(0.75)) {+ const a = R.range(0, TAU), D = R.range(28, 70), T = R.range(0.18, 0.28), v = (D * 3) / (Math.exp(3 * T) - 1);+ ps.spawn(P.STREAK, Math.cos(a) * D, Y + Math.sin(a) * D, -Math.cos(a) * v, -Math.sin(a) * v, T, R.chance(0.5) ? C[7] : C[6]);+ }+ if (t < REL - 0.2 && R.chance(0.16)) {+ const a = R.range(0, TAU), D = R.range(34, 60);+ puffs.spawn(PK.SOOT, Math.cos(a) * D, Y + Math.sin(a) * D, -Math.sin(a) * 40, Math.cos(a) * 40, R.range(0.6, 0.9), R.range(3, 6));+ }+ attract(ps.list, 0, Y, 2.2e6 * (0.3 + k), 110, 0.55, 2.5, dt, (q) => (q.k === P.MOTE ? 1 : 0), 420);+ attract(puffs.list, 0, Y, 1.2e6 * (0.3 + k), 90, 0.7, 4, dt, () => 1, 160);+ }+ if (t >= REL && !released) {+ released = true;+ release();+ }+ // the sphere burns: flame licks off its rim, the odd spark and ember+ if (released && t < BURN) {+ const sr = sphereR(t);+ for (acc += dt * 34; acc > 1; acc--) {+ const a = -Math.PI / 2 + R.gauss() * 1.1, [x, y] = rim(a, sr + 1), sp = R.range(10, 35);+ puffs.spawn(PK.FLAME, x, y, Math.cos(a) * sp, Math.sin(a) * sp - R.range(10, 30), R.range(0.25, 0.45), R.range(1.2, 2.2), 0, R.chance(0.2));+ }+ if (R.chance(dt * 10)) {+ const a = -Math.PI / 2 + R.range(-1.4, 1.4), [x, y] = rim(a, sr * 0.9);+ puffs.spawn(PK.SOOT, x, y, Math.cos(a) * 20, -R.range(15, 35), R.range(1.2, 1.7), R.range(5, 9));+ }+ if (R.chance(dt * 8)) {+ const a = R.range(0, TAU), [x, y] = rim(a, sr), sp = R.range(110, 200);+ ps.spawn(P.SPARK, x, y, Math.cos(a) * sp, Math.sin(a) * sp - 40, R.range(0.2, 0.5));+ }+ if (R.chance(dt * 7)) {+ const a = -Math.PI / 2 + R.range(-1.2, 1.2), [x, y] = rim(a, sr);+ embers.spawn(P.EMBER, x, y, Math.cos(a) * 30, -R.range(20, 50), R.range(0.9, 1.6));+ }+ }+ // the collapse: the sphere draws its own flame back in, streaks race to the heart+ if (t >= BURN && !collapsing) {+ collapsing = true;+ for (let i = 0; i < 14; i++) {+ const a = R.range(0, TAU), D = R.range(26, 48), T = R.range(0.14, 0.2), v = (D * 3) / (Math.exp(3 * T) - 1);+ ps.spawn(P.STREAK, Math.cos(a) * D, Y + Math.sin(a) * D, -Math.cos(a) * v, -Math.sin(a) * v, T, R.chance(0.5) ? WHITE : C[6]);+ }+ }+ if (collapsing && !popped) {+ attract(puffs.list, 0, Y, 1.4e6, 64, 0.6, 3, dt, (q) => (q.k === PK.FLAME ? 1 : 0.35), 200);+ }+ if (t >= POP && !popped) {+ popped = true;+ pop();+ }+ // the shock reaches the floor: dust rolls out under the ring+ for (const r of rings) {+ if (r.delay > 0 || !r.hot || r.th < 3) continue;+ const rr = r.r0 + (r.r1 - r.r0) * (1 - Math.pow(r.life / r.max, 3)), rf = rr > -Y ? Math.sqrt(rr * rr - Y * Y) : 0;+ if (rf > 0)+ for (dustAcc += dt * 60; dustAcc > 1; dustAcc--) {+ const s = R.sign();+ ps.spawn(P.DUST, s * rf + R.range(-2, 2), -R.range(1, 3), s * R.range(20, 50), -R.range(4, 14), R.range(0.4, 0.8), mix(C[2], C[3], R.next()), R.range(1.5, 3));+ }+ }+ for (const a of [lights, rings])+ for (let i = a.length - 1; i >= 0; i--) {+ const q = a[i];+ if (q.delay > 0) q.delay -= dt;+ else if ((q.life -= dt) <= 0) a.splice(i, 1);+ }+ bits.update(dt);+ for (const b of bits.list) {+ // a shard that comes to rest lies flat on the floor+ if (b.rest && !b.flat) {+ b.flat = true;+ b.a = Math.round(b.a / Math.PI) * Math.PI + R.range(-0.2, 0.2);+ b.y = -1;+ }+ // and once it has lain a while, it dissolves into a wisp+ if (b.life < 0.45 && !b.wisp) {+ b.wisp = true;+ puffs.spawn(PK.SOOT, b.x, b.y - 1, R.range(-4, 4), -R.range(8, 16), R.range(0.6, 0.9), R.range(1.4, 2.4));+ }+ }+ puffs.update(dt);+ ps.update(dt);+ embers.update(dt);+ },+ drawBack(p) {+ const k = burning(t);+ for (const r of rings) floorRing(p, C, r, true);+ puffs.draw(p, PK.SOOT, { x: 0, y: Y, k: k * flick, reach: 84 });+ ps.draw(p, "back");+ if (k > 0) p.glow(0, -3, 74, C[4], 0.24 * Math.min(1, k) * flick);+ },+ draw(p) {+ const sr = sphereR(t), k = burning(t), L = starL(t);+ for (const r of rings) floorRing(p, C, r, false);+ // the charge: a contracting ring and a black core that beats+ let cr = 0;+ if (t < REL) {+ const q = t / REL, ring = 3 + 74 * (1 - ease.inQuad(q));+ const beat = 1 + 0.3 * Math.exp(-((t - REL * 0.5) ** 2) / 0.0015) + 0.4 * Math.exp(-((t - REL * 0.8) ** 2) / 0.0015);+ cr = coreR(t) * beat;+ ringFast(p, 0, Y, ring, 1, q > 0.7 ? C[6] : C[5], 0.2 + 0.7 * q);+ if (t > REL - 0.07) p.circle(0, Y, 1.6, WHITE);+ else sphere(p, C, cr, t, 0.3 + 0.3 * q);+ halo(p, 0, Y, cr, cr + 14 + 30 * q, C[5], (0.45 + 0.7 * q) * beat);+ p.glow(0, Y, 60 + 30 * q, C[4], 0.12 + 0.3 * q);+ }+ // the release: a violet-white flash with a black star cut across it+ const fu = (t - REL) / 0.12;+ if (fu >= 0 && fu < 1) {+ const r = 36 * (1 - 0.3 * fu);+ p.circle(0, Y, r + 1.5, C[5], 1.2 - fu);+ p.circle(0, Y, r, fu < 0.35 ? WHITE : C[6], 1.1 - fu);+ if (fu < 0.6) p.circle(0, Y, r * 0.62, WHITE);+ }+ // the shock rings in the air+ for (const r of rings) {+ if (r.delay > 0) continue;+ const q = r.life / r.max, rr = r.r0 + (r.r1 - r.r0) * (1 - q * q * q), th = Math.max(1, r.th * q + 0.4);+ // the floor stops it: below the floor line it's the flat ring on the floor instead+ ringFast(p, 0, Y, rr, th, (v) => (r.hot ? (v > 0.6 ? WHITE : v > 0.3 ? C[6] : C[5]) : v > 0.5 ? C[5] : C[4]), (v, g) => (Y + Math.sin(g) * rr > 0.5 ? 0 : Math.min(1, q * 1.6)));+ if (r.hot) ringLight(p, 0, Y, rr, 4, C[5], 0.4 * q, (x, y) => y < 0.5);+ }+ sphere(p, C, sr, t, t < BURN ? 1 : 1 + 0.5 * clamp((t - BURN) / (POP - BURN)));+ // the black star, burning at the edge where its arms leave the flash+ const star = L > 0 ? blackStar(Y, L, starRot(t), 0.5, 0.4) : null;+ if (star) {+ const age = t - REL, fr = age < 0.12 ? 36 * (1 - 0.3 * (age / 0.12)) + 1.5 : 0, cut = Math.max(fr, sr);+ star.draw(p, C[0], age < 0.1 ? C[5] : C[4], (x, y) => x * x + (y - Y) ** 2 < cut * cut);+ }+ puffs.draw(p, PK.FLAME);+ for (const b of bits.list) shard(p, b, C, 0, Y, Math.min(1, k) * 0.9);+ ps.draw(p, "front");+ embers.draw(p, "front");+ // the pop as it goes: a glint and a last hard light+ const pu = (t - POP) / 0.2;+ if (pu >= 0 && pu < 1) sparkle(p, 0, Y, 12 * (1 - pu), C[6], C[5], 0.7 * (1 - pu));+ // light: the blast's flare and the sphere's corona; then black takes its light back+ for (const l of lights) {+ const q = l.life / l.max;+ p.glow(l.x, l.y, l.r * (0.55 + 0.45 * q), l.c, l.k * q * q);+ }+ if (sr > 1) {+ halo(p, 0, Y, sr - 0.5, sr + 16, C[6], 0.5 * flick * Math.min(1, k));+ p.glow(0, Y, sr + 54, C[4], 0.5 * flick * Math.min(1, k));+ }+ // black takes its light back: the sphere and the core, then the star's own cells+ const B0 = Math.max(sr, cr) + 1;+ if (B0 > 2) unlight(p, -B0, Y - B0, B0, Y + B0, (x, y) => x * x + (y - Y) ** 2 < (Math.max(sr, cr) - 0.5) ** 2);+ if (star) star.unlight(p);+ },+ };+}- // 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);+// where the shock meets the floor: its cross-section with the floor plane, a flat ring racing out+function floorRing(p, C, r, back) {+ if (r.delay > 0 || !r.hot || r.th < 3) return;+ const q = r.life / r.max, rr = r.r0 + (r.r1 - r.r0) * (1 - q * q * q);+ if (rr <= -Y) return;+ const rf = Math.sqrt(rr * rr - Y * Y);+ band(p, 0, 0.5, rf, 0.16, Math.max(1, 3 * q), Math.min(1, q * 1.5), [C[3], C[4], C[5], C[6]], (g) => (Math.sin(g) < 0) === back);+ if (!back) for (const s of [-1, 1]) p.glow(s * rf, -2, 16, C[5], 0.4 * q);}diff --git a/src/fx/shadow/doom-mark.js b/src/fx/shadow/doom-mark.jsdeleted file mode 100644index d58e9cd..0000000--- a/src/fx/shadow/doom-mark.js+++ /dev/null@@ -1,80 +0,0 @@-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.jsindex 5602e9c..c2470b8 100644--- a/src/fx/shadow/eclipse.js+++ b/src/fx/shadow/eclipse.js@@ -1,69 +1,90 @@-import { cycle, tileNoise, bump, clamp, TAU, WHITE } from "../../core/index.js";-import { steps, CRIMSON } from "./_lib.js";+import { cycle, fit, clamp, smooth, rand, TAU, WHITE, mix } from "../../core/index.js";+import { VOID, halo, unlight } 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,+ desc: "A black moon over the sun: a breathing pearl corona with long streamers, a thin white rim, and one diamond bead blazing on its edge.",+ tags: ["shadow", "eclipse", "moon", "sun", "corona", "sky", "magic", "loop"],+ size: [160, 144],+ origin: [80, 72],+ duration: 4,loop: true,fps: 30,bg: "sky",- options: {- palette: ["#0a0614", "#1e1236", "#3a2066", "#5c3496", "#8a58c4", "#b88ae4", "#e2c4f8", "#ffffff"],- radius: 12, seed: 4,- },+ options: { palette: VOID, pearl: ["#5a4f8a", "#a99be0", "#e6defa", "#fffaf2"], seed: 3 },};-const BEAD = -0.75; // where the last sliver of sun shows (radians)+// the moon's radius, the loop, where the bead blazes on the rim (radians, 0 = right, up is negative)+const R = 19, D = 4, BEAD = -0.72;+const breathe = (t, k, ph) => Math.sin((TAU * k * t) / D + ph);+// streamers: crowded toward the equator (left and right), longer there, each curving off as it goes out+const STREAMS = Array.from({ length: 30 }, (_, i) => {+ const side = i % 2 ? 0 : Math.PI, spread = (rand(i, 1) - 0.5) * (rand(i, 2) < 0.7 ? 1.3 : 3.1);+ const a = side + spread, eq = Math.abs(Math.cos(a));+ return { a, len: (10 + rand(i, 3) * 28) * (0.45 + 0.75 * eq), curl: (rand(i, 4) - 0.5) * 0.00018, k: 1 + (i % 3), ph: rand(i, 5) * TAU, w: rand(i, 6) };+});-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)];+export function drawBack(p, t, o) {+ const C = fit(o.palette, 8), Q = fit(o.pearl, 4), S = o.seed;+ // stars twinkling in the dark sky round it+ cycle(t, D, 26, S, (r) => r.range(1.2, 2.6), (age, L, r) => {+ const x = r.range(-78, 78), y = r.range(-70, 70);+ if (Math.hypot(x, y) < R + 22) return;+ const k = Math.sin((Math.PI * age) / L);+ p.dot(x, y, k > 0.7 ? WHITE : Q[1], k * 1.2);+ if (k > 0.85 && r.next() < 0.4) (p.dot(x - 1, y, Q[0], 0.8), p.dot(x + 1, y, Q[0], 0.8));});-- // 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]);+ // the outer corona's light: a wide pearly bloom, breathing+ const b = 1 + 0.08 * breathe(t, 1, 0);+ p.glow(0, 0, 72 * b, C[4], 0.38);+ p.glow(0, 0, 46 * b, Q[1], 0.34);+ // streamers: fine rays of pearl, white at the root, thinning to violet, curling as they go out+ for (const s of STREAMS) {+ const L = s.len * (1 + 0.18 * breathe(t, s.k, s.ph));+ for (let d = 4; d <= L; d += 0.5) {+ const u = d / L, a = s.a + s.curl * d * d, r = R + 1 + d, x = Math.cos(a) * r, y = Math.sin(a) * r;+ p.dot(x, y, u < 0.3 ? Q[2] : u < 0.65 ? Q[1] : C[5], u < 0.75 ? 1 : (1 - u) * 4);}- 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));- });+ p.glowLine(Math.cos(s.a) * (R + 4), Math.sin(s.a) * (R + 4), Math.cos(s.a) * (R + L * 0.6), Math.sin(s.a) * (R + L * 0.6), 3, Q[1], 0.12);+ }+}- // 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];+export function draw(p, t, o) {+ const C = fit(o.palette, 8), Q = fit(o.pearl, 4), b = 1 + 0.08 * breathe(t, 1, 0);+ // the inner corona: a bright collar hugging the moon, finely streaked, fading out through pearl to violet+ const W = R + 10;+ p.shade(-W, -W, W, W, (x, y, out) => {+ const r = Math.sqrt(x * x + y * y);+ if (r < R - 0.5 || r > R + 9 * b) return;+ const a = Math.atan2(y, x), e = (r - R) / (9 * b);+ const streak = 0.55 + 0.3 * Math.cos(a * 23 + Math.sin(a * 5) * 2) + 0.15 * Math.cos(a * 41 - (TAU * t) / D);+ const I = (1 - e) ** 2.2 * streak * (0.75 + 0.4 * Math.abs(Math.cos(a)));+ if (r < R + 0.9) return Q[3];+ if (I < 0.1) return;+ if (I > 0.45 && ((Math.floor(x) + Math.floor(y)) & 1) === 0) out.k = 0.2 * I;+ return I > 0.72 ? Q[2] : I > 0.42 ? Q[1] : I > 0.22 ? C[5] : C[4];});- // 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);+ // the moon: black, a whisper of earthshine on its left limb+ p.shade(-R, -R, R, R, (x, y) => {+ const r = Math.sqrt(x * x + y * y);+ if (r >= R - 0.5) return;+ return r > R - 2.2 && x < -R * 0.45 ? C[1] : C[0];+ });+ // the diamond bead: a blazing point on the rim, rays flaring out and breathing+ const bx = Math.cos(BEAD) * (R + 0.4), by = Math.sin(BEAD) * (R + 0.4), k = 0.75 + 0.25 * breathe(t, 2, 1);+ for (let i = 0; i < 8; i++) {+ const a = (i * Math.PI) / 4 + 0.12, len = (i % 2 ? 7 : 22) * k * (i === 1 || i === 5 ? 1.6 : 1);+ for (let d = 1; d <= len; d += 0.5) {+ const u = d / len, x = bx + Math.cos(a) * d, y = by + Math.sin(a) * d;+ if (x * x + y * y < (R - 0.5) ** 2) break;+ p.dot(x, y, u < 0.35 ? WHITE : u < 0.7 ? Q[2] : Q[1], u < 0.5 ? 1 : (1 - u) * 2.2);+ }+ }+ p.circle(bx, by, 3 * k, Q[2]);+ p.circle(bx, by, 2.2 * k, Q[3]);+ p.circle(bx, by, 1.4, WHITE);+ p.glow(bx, by, 46 * k, Q[2], 0.8 * k);+ p.glow(bx, by, 14, WHITE, 0.8);+ halo(p, 0, 0, R - 0.5, R + 16, Q[2], 0.35 * b);+ unlight(p, -R, -R, R, R, (x, y) => x * x + y * y < (R - 0.6) ** 2);}diff --git a/src/fx/shadow/grasping-hands.js b/src/fx/shadow/grasping-hands.jsindex f7837fd..e47ad0b 100644--- a/src/fx/shadow/grasping-hands.js+++ b/src/fx/shadow/grasping-hands.js@@ -1,89 +1,187 @@-import { burst, cycle, seg, ease, clamp, TAU } from "../../core/index.js";-import { steps, UMBRA } from "./_lib.js";+import { Particles, P, Rng, fit, clamp, smooth, ease, TAU, WHITE, mix } from "../../core/index.js";+import { VOID, Puffs, PK, Drops, floorPool, ringFast } 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,+ desc: "Shadow arms burst up out of a dark pool with a splash, clench their hands into claws, strain, and are dragged back under, fingers clawing at the air.",+ tags: ["shadow", "hands", "arms", "grab", "ground", "dark", "magic", "one-shot"],+ size: [200, 116],+ origin: [100, 100],+ duration: 3.1,loop: false,fps: 30,bg: "ground",- options: { palette: UMBRA, height: 22, seed: 12 },+ options: { palette: VOID, seed: 5 },};-// 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]);+const RX = 42, OPEN = 0.32, SHUT = 2.35, LX = -0.6, LY = -0.8;++// an arm at t: it rises out of the pool along its own shape, bent at the elbow, swaying; returns its spine+function arm(A, t) {+ const e = clamp((t - A.t0) / 0.22), d = clamp((t - A.td) / 0.34);+ if (e <= 0 || d >= 1) return null;+ const rise = ease.outBack(e, 1.6) * (1 - ease.inQuad(d)), hidden = (1 - rise) * A.L;+ const grip = gripOf(A, t), strain = t > A.t0 + 0.5 && t < A.td ? Math.sin(t * 47 + A.ph) * 0.03 : 0;+ const elbow = A.bend * (0.3 + 0.7 * grip) * (1 - d) + strain, lean = A.lean + 0.06 * Math.sin(t * 2.2 + A.ph) + d * A.lean * 0.6;+ let th = -Math.PI / 2 + lean, x = A.x - Math.cos(th) * hidden, y = A.y - Math.sin(th) * hidden;+ const pts = [], n = Math.ceil(A.L / 0.5);+ for (let i = 0; i <= n; i++) {+ const s = i * 0.5, u = s / A.L;+ pts.push({ x, y, th, w: A.W * (1 - 0.5 * u) + 0.4, u });+ th += 0.5 * (elbow * Math.exp(-(((u - 0.52) / 0.07) ** 2)) / (0.07 * Math.sqrt(Math.PI) * A.L) + A.curve / A.L);+ x += Math.cos(th) * 0.5;+ y += Math.sin(th) * 0.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]]) };+ return pts;+}+// how closed the hand is: opens as it rises, snaps shut into a claw, splays as it's dragged down+function gripOf(A, t) {+ const shut = ease.outBack(clamp((t - A.t0 - 0.3) / 0.12), 2.2), splay = smooth(A.td, A.td + 0.12, t);+ return shut * (1 - splay) - 0.35 * splay;}-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));+// the arm in cross-sections, lit like the tendrils: a near-black body, a bright edge toward the light+function drawArm(p, A, pts, C) {+ const surf = A.y;+ for (const q of pts) {+ if (q.y > surf) continue;+ const nx = -Math.sin(q.th), ny = Math.cos(q.th), ks = nx * LX + ny * LY >= 0 ? 1 : -1;+ for (let v = -q.w; v <= q.w; v += 0.5) {+ const x = q.x + nx * v, y = q.y + ny * v, u = (v / q.w) * ks;+ if (y <= surf) p.px(x, y, u > 0.55 ? C[2] : u > -0.45 ? C[1] : C[0]);+ }}+ for (const q of pts) {+ if (q.y > surf) continue;+ const nx = -Math.sin(q.th), ny = Math.cos(q.th), f = nx * LX + ny * LY, ks = f >= 0 ? 1 : -1, l = ks * q.w;+ if (q.y - ny * l <= surf) p.px(q.x - nx * l, q.y - ny * l, C[3]);+ if (q.y + ny * l <= surf) p.px(q.x + nx * l, q.y + ny * l, Math.abs(f) > 0.8 ? C[7] : C[6]);+ }+ const base = pts.find((q) => q.y <= surf);+ if (base) p.line(base.x - base.w - 1.5, surf, base.x + base.w + 1.5, surf, C[5]);+}- // 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));+// a hand on the arm's end: a palm, four fingers and a thumb, each two bones with a lit edge and a pale claw+function drawHand(p, A, pts, C, t) {+ const tip = pts[pts.length - 1];+ if (tip.y > A.y - 2) return;+ const th = tip.th, dx = Math.cos(th), dy = Math.sin(th), nx = -dy, ny = dx, g = gripOf(A, t), side = A.curl;+ const cx = tip.x + dx * 2.6, cy = tip.y + dy * 2.6;+ p.shade(cx - 5, cy - 5, cx + 5, cy + 5, (x, y) => {+ const a = (x - cx) * dx + (y - cy) * dy, b = (x - cx) * nx + (y - cy) * ny, d = (a / 3) ** 2 + (b / 2.7) ** 2;+ if (d > 1.25) return;+ if (d > 1) return b * side < 0 ? C[6] : C[3];+ return b * side < -1 ? C[2] : C[1];});- // 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 bone = (x0, y0, ang, len, last) => {+ const x1 = x0 + Math.cos(ang) * len, y1 = y0 + Math.sin(ang) * len, ox = Math.round(-Math.sin(ang) * side * -1), oy = Math.round(Math.cos(ang) * side * -1);+ p.line(x0, y0, x1, y1, C[1]);+ p.line(x0 + ox, y0 + oy, x1 + ox, y1 + oy, C[5]);+ if (last) (p.px(x1, y1, WHITE), p.px(x1 + Math.cos(ang), y1 + Math.sin(ang), C[7]));+ return [x1, y1];};- 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]);+ const spread = 1 - 0.65 * Math.max(0, g), curl = g * 1.2;+ [-2.2, -0.75, 0.75, 2.2].forEach((o, i) => {+ const bx = cx + dx * 2.6 + nx * o * 0.9, by = cy + dy * 2.6 + ny * o * 0.9, len = i === 0 || i === 3 ? 2.6 : 3.2;+ const a0 = th + o * 0.2 * spread, [jx, jy] = bone(bx, by, a0 + curl * side * 0.6, len, false);+ bone(jx, jy, a0 + curl * side * 1.5, len * 0.85, true);});+ const [jx, jy] = bone(cx - nx * side * 2.4, cy - ny * side * 2.4, th - side * (1 - 0.6 * g), 2.4, false);+ bone(jx, jy, th - side * (0.6 - 1.4 * g), 2, true);+ p.glow(cx, cy, 8, C[5], 0.18 + 0.3 * Math.max(0, g));+}++export function create(o) {+ const C = fit(o.palette, 8), DIM = [C[0], C[0], C[1], C[1], C[3], C[4], C[5], C[6]], R = new Rng(o.seed), floor = () => 0;+ const ps = new Particles({ rng: R, ground: floor, sparks: [C[7], C[6], C[5], C[4]], haze: C[4] });+ const puffs = new Puffs({ rng: R, flame: [C[7], C[6], C[5], C[4], C[3], C[2], C[1], C[1], C[0]], soot: [mix(C[3], C[2], 0.55), mix(C[2], C[1], 0.5)], cap: mix(C[4], C[2], 0.5), rim: [C[6], C[5], C[4]], floor });+ const ripples = [], splats = [], lights = [];+ let t = 0, acc = 0;+ const rx = (tt) => RX * ease.outCubic(clamp(tt / OPEN)) * (1 - ease.inCubic(clamp((tt - SHUT) / 0.45)));+ const drops = new Drops({ onLand: (x, y, v, s) => (Math.abs(x) < rx(t) * 0.95 ? ripples.push({ x, t0: t, life: 0.5, w: 0.6 }) : splats.push({ x, t0: t, s })) });+ // four arms: two at the back, taller and dimmer, two in front; elbows bending toward the middle+ const LAY = [[-20, -2.5, 1], [17, -2.5, -1], [-30, 2.5, 1], [28, 2.5, -1]];+ const arms = LAY.map(([x, y, toward], i) => ({+ x: x + R.range(-3, 3), y, back: y < 0, L: y < 0 ? R.range(44, 52) : R.range(36, 44), W: y < 0 ? R.range(3.2, 3.8) : R.range(3.6, 4.2),+ lean: -toward * R.range(0.16, 0.3), bend: toward * R.range(0.35, 0.6), curve: toward * R.range(0.05, 0.15), curl: toward,+ t0: 0.3 + [1, 3, 0, 2][i] * 0.06 + R.range(0, 0.03), td: 1.45 + [2, 0, 3, 1][i] * 0.09 + R.range(0, 0.05), ph: R.range(0, TAU), up: false, shut: false, down: false,+ }));+ function splash(x, y, n, k) {+ for (let i = 0; i < n; i++) drops.add(x + R.range(-2, 2), y - 1, R.range(-70, 70) * k, -R.range(90, 220) * k, R.chance(0.4) ? 2 : 1);+ ripples.push({ x, t0: t, life: 0.7, w: 1 });+ lights.push({ x, y: y - 7, r: 30, k: 0.55 * k, life: 0.25, max: 0.25 });+ }+ return {+ update(dt) {+ t += dt;+ for (const A of arms) {+ if (!A.up && t >= A.t0) (A.up = true), splash(A.x, A.y, 12, 1);+ if (!A.shut && t >= A.t0 + 0.36) {+ // the clench: a snap of light at the fist, a puff of dark breath, a few sparks+ A.shut = true;+ const pts = arm(A, t);+ if (pts) {+ const q = pts[pts.length - 1];+ lights.push({ x: q.x, y: q.y, r: 22, k: 0.7, life: 0.2, max: 0.2 });+ A.snap = { x: q.x + Math.cos(q.th) * 4, y: q.y + Math.sin(q.th) * 4, t0: t };+ for (let i = 0; i < 6; i++) {+ const a = R.range(0, TAU), sp = R.range(60, 130);+ ps.spawn(P.SPARK, A.snap.x, A.snap.y, Math.cos(a) * sp, Math.sin(a) * sp - 20, R.range(0.12, 0.3));+ }+ puffs.spawn(PK.SOOT, A.snap.x, A.snap.y, 0, -12, 0.6, 3.5);+ }+ }+ if (!A.down && t >= A.td + 0.28) (A.down = true), splash(A.x, A.y, 8, 0.7);+ }+ const r = rx(t);+ if (r > 8 && t < SHUT - 0.4) {+ for (acc += dt * 8; acc > 1; acc--) puffs.spawn(PK.SOOT, R.range(-0.8, 0.8) * r, -R.range(1, 4), R.range(-8, 8), -R.range(14, 28), R.range(0.6, 0.85), R.range(3, 6));+ if (R.chance(dt * 12)) ps.spawn(P.MOTE, R.range(-0.8, 0.8) * r, -2, R.range(-8, 8), -R.range(30, 70), R.range(0.5, 0.9), R.pick([C[7], C[6], C[5]]), R.range(0.6, 1));+ if (R.chance(dt * 6)) ps.spawn(P.VAPOUR, R.range(-0.7, 0.7) * r, -R.range(2, 8), R.range(-6, 6), -R.range(10, 22), R.range(0.6, 0.9), R.chance(0.5) ? C[3] : C[4], R.range(3, 6));+ if (R.chance(dt * 3)) ripples.push({ x: R.range(-0.7, 0.7) * r, t0: t, life: 0.6, w: 0.5 });+ }+ for (const a of [ripples, splats]) for (let i = a.length - 1; i >= 0; i--) if (t - a[i].t0 > (a[i].life ?? 0.6)) a.splice(i, 1);+ for (let i = lights.length - 1; i >= 0; i--) if ((lights[i].life -= dt) <= 0) lights.splice(i, 1);+ drops.update(dt);+ puffs.update(dt);+ ps.update(dt);+ },+ drawBack(p) {+ const r = rx(t), k = r / RX;+ floorPool(p, C, r, t, ripples);+ if (k > 0) {+ p.glow(0, -16, 80, C[4], 0.2 * k);+ p.glow(0, -8, r * 1.7 + 12, C[4], 0.3 * k);+ p.glow(0, 0, r * 1.15, C[5], 0.16 * k);+ }+ puffs.draw(p, PK.SOOT, { x: 0, y: 6, k, reach: 70 });+ ps.draw(p, "back");+ for (const A of arms) if (A.back) {+ const pts = arm(A, t);+ if (pts) drawArm(p, A, pts, DIM), drawHand(p, A, pts, DIM, t);+ }+ },+ draw(p) {+ for (const A of arms) if (!A.back) {+ const pts = arm(A, t);+ if (pts) drawArm(p, A, pts, C), drawHand(p, A, pts, C, t);+ }+ for (const A of arms) if (A.snap && t - A.snap.t0 < 0.22) {+ const u = (t - A.snap.t0) / 0.22;+ ringFast(p, A.snap.x, A.snap.y, 2 + 5 * ease.outCubic(u), 1, u < 0.4 ? C[6] : u < 0.7 ? C[5] : C[3]);+ }+ drops.draw(p, C[1], C[5]);+ for (const s of splats) {+ const a = 1 - (t - s.t0) / 0.6;+ p.dot(s.x, -0.5, C[1], a * 1.5);+ p.dot(s.x + 1, -0.5, C[2], a);+ p.dot(s.x, -1.5, C[5], a);+ }+ ps.draw(p, "front");+ for (const l of lights) {+ const q = l.life / l.max;+ p.glow(l.x, l.y, l.r * (0.6 + 0.4 * q), C[5], l.k * q * q);+ }+ },+ };}diff --git a/src/fx/shadow/hex-sigil.js b/src/fx/shadow/hex-sigil.jsindex da98259..8452c54 100644--- a/src/fx/shadow/hex-sigil.js+++ b/src/fx/shadow/hex-sigil.js@@ -1,133 +1,160 @@-import { burst, seg, ease, clamp, rand, bump, TAU, WHITE } from "../../core/index.js";-import { steps, shape } from "./_lib.js";+import { Particles, Bits, P, B, Rng, rng, fit, sparkle, clamp, smooth, ease, TAU, WHITE, mix } from "../../core/index.js";+import { VOID, Puffs, PK, ringFast } 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,+ desc: "A burning pen traces a cursed sigil in the air, its glyphs pop in one by one, then it flares white and crumbles into falling embers.",+ tags: ["shadow", "hex", "sigil", "rune", "curse", "magic", "circle", "one-shot"],+ size: [168, 128],+ origin: [84, 112],+ duration: 4.2,loop: false,fps: 30,- bg: "dark",- options: {- palette: ["#0e0412", "#24082e", "#3e0c4c", "#62146e", "#8c1e8e", "#c032b0", "#ec6ad2", "#ffd0f4"],- radius: 22, seed: 13,- },+ bg: "ground",+ options: { palette: VOID, seed: 7 },};-const GLYPHS = [["#.#", "###", "..#"], [".#.", "#.#", "##."], ["##.", ".##", "#.."], ["#..", "###", ".#."], [".##", "#..", "##."], ["#.#", ".#.", "###"]];-const FLARE = 1.12; // the moment it flares+// the sigil's centre and radii; the beats: traced, glyphs pop, holds, flares, crumbles+const CY = -50, RO = 28, RI = 22, RC = 6, GLYPH = 1.62, FLARE = 2.6, BREAK = 2.74;-// 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]);+// the strokes, in the order the pen draws them, as points with the moment the pen passes each+function strokes(seed) {+ const paths = [], circle = (r, a0, n = 0) => Array.from({ length: (n || Math.ceil(r * TAU)) + 1 }, (_, i) => [Math.cos(a0 + (i / (n || Math.ceil(r * TAU))) * TAU) * r, CY + Math.sin(a0 + (i / (n || Math.ceil(r * TAU))) * TAU) * r]);+ paths.push(circle(RO, -Math.PI / 2));+ // a seven-pointed star, drawn in one stroke, three points round each time+ const star = [];+ for (let i = 0; i <= 7; i++) {+ const a = -Math.PI / 2 + ((i * 3) % 7) * (TAU / 7);+ star.push([Math.cos(a) * RI, CY + Math.sin(a) * RI]);}- 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;+ paths.push(star);+ paths.push(circle(RI, -Math.PI / 2));+ paths.push(circle(RC, Math.PI / 2));+ paths.push([[0, CY - 3.5], [2, CY], [0, CY + 3.5], [-2, CY], [0, CY - 3.5]]);+ // sample every half pixel, timing the pen along it: the outer circle fast, the star with more weight+ const pts = [], speeds = [420, 700, 550, 380, 300];+ let t = 0.12;+ paths.forEach((path, k) => {+ for (let i = 1; i < path.length; i++) {+ const [x0, y0] = path[i - 1], [x1, y1] = path[i], L = Math.hypot(x1 - x0, y1 - y0);+ for (let d = 0; d < L; d += 0.5) pts.push({ x: x0 + ((x1 - x0) * d) / L, y: y0 + ((y1 - y0) * d) / L, t: t + d / speeds[k] });+ t += L / speeds[k];}- }- return [out, out[out.length - 1]];+ t += 0.04;+ });+ return { pts, end: t };}-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];+// seven small glyphs of our own: a spine and two or three branches on a 3x3 grid of nodes+function glyphs(seed) {+ return Array.from({ length: 7 }, (_, i) => {+ const r = rng(seed, i, 31), segs = [[[1, 0], [1, 2]]];+ for (let k = 0; k < 2 + (r.next() < 0.5 ? 1 : 0); k++) {+ const a = [r.int(0, 2), r.int(0, 2)], b = [Math.max(0, Math.min(2, a[0] + r.int(-1, 1))), Math.max(0, Math.min(2, a[1] + r.int(-1, 1)))];+ if (a[0] !== b[0] || a[1] !== b[1]) segs.push([a, b]);}- 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]);+ const ang = -Math.PI / 2 + (i * TAU) / 7 + Math.PI / 7, rr = (RO + RI) / 2;+ return { x: Math.cos(ang) * rr, y: CY + Math.sin(ang) * rr, segs, t: GLYPH + i * 0.07 };});+}- // 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));+export function create(o) {+ const C = fit(o.palette, 8), R = new Rng(o.seed), floor = () => 0, S = strokes(o.seed), G = glyphs(o.seed);+ const ps = new Particles({ rng: R, ground: floor, sparks: [WHITE, C[7], C[6], C[5]] });+ const embers = new Particles({ rng: R, ground: floor, sparks: [C[7], C[6], C[5], C[4]] });+ const puffs = new Puffs({ rng: R, flame: [WHITE, C[7], C[6], C[5], C[4], C[3], C[2], C[1], C[0]], soot: [mix(C[3], C[2], 0.5), mix(C[2], C[1], 0.5)], cap: mix(C[4], C[2], 0.5), rim: [C[6], C[5], C[4]], floor });+ const bits = new Bits({ ground: floor }), lights = [];+ let t = 0, pi = 0, flared = false, broke = false;+ const pen = () => S.pts[Math.min(S.pts.length - 1, pi)];+ return {+ update(dt) {+ t += dt;+ // the pen: it spits sparks and drips burning embers as it writes+ while (pi < S.pts.length - 1 && S.pts[pi + 1].t <= t) pi++;+ if (t > 0.12 && t < S.end) {+ const q = pen();+ if (R.chance(dt * 70)) ps.spawn(P.SPARK, q.x, q.y, R.range(-70, 70), R.range(-100, 20), R.range(0.12, 0.35));+ if (R.chance(dt * 10)) embers.spawn(P.EMBER, q.x, q.y, R.range(-12, 12), R.range(5, 25), R.range(0.5, 0.9));+ }+ // power drawn into the sigil while it's written and held: streaks racing in to its heart+ if (t > 0.2 && t < FLARE - 0.05 && R.chance(dt * (8 + 14 * smooth(0.2, FLARE, t)))) {+ const a = R.range(0, TAU), D0 = R.range(40, 60), T = R.range(0.22, 0.32), v = (D0 * 3) / (Math.exp(3 * T) - 1);+ ps.spawn(P.STREAK, Math.cos(a) * D0, CY + Math.sin(a) * D0, -Math.cos(a) * v, -Math.sin(a) * v, T, R.chance(0.5) ? C[7] : C[6]);+ }+ for (const g of G)+ if (!g.popped && t >= g.t) {+ g.popped = true;+ lights.push({ x: g.x, y: g.y, r: 14, k: 0.7, life: 0.2, max: 0.2 });+ for (let i = 0; i < 4; i++) ps.spawn(P.SPARK, g.x, g.y, R.range(-60, 60), R.range(-70, 20), R.range(0.1, 0.25));+ }+ if (t >= FLARE && !flared) {+ flared = true;+ lights.push({ x: 0, y: CY, r: 96, k: 1.4, life: 0.45, max: 0.45 }, { x: 0, y: CY, r: 44, k: 1, life: 0.14, max: 0.14 });+ for (let i = 0; i < 24; i++) {+ const a = R.range(0, TAU), sp = R.range(60, 130);+ ps.spawn(P.SPARK, Math.cos(a) * 13, CY + Math.sin(a) * 13, Math.cos(a) * sp, Math.sin(a) * sp - 30, R.range(0.2, 0.45));+ }+ }+ if (t >= BREAK && !broke) {+ // it crumbles: every stroke breaks into burning fragments that tumble down and bounce+ broke = true;+ // pieces drop nearly straight at first, so the sigil's shape lingers as it falls apart+ for (let i = 0; i < S.pts.length - 1; i += 7) {+ const q = S.pts[i], n = S.pts[i + 1], a = Math.atan2(n.y - q.y, n.x - q.x);+ bits.add({ kind: B.SHARD, x: q.x, y: q.y, vx: R.range(-8, 8), vy: R.range(-12, 6), g: R.range(0.22, 0.45), drag: 0.6, bounce: 0.25, life: R.range(0.8, 1.2), a, va: R.range(-3, 3), s: R.range(2.5, 3.5), c: R.pick([C[7], C[6], C[6], C[5]]) });+ if (i % 27 === 0) embers.spawn(P.EMBER, q.x, q.y, R.range(-10, 10), -R.range(10, 40), R.range(0.6, 1.1));+ }+ for (const g of G) puffs.spawn(PK.SOOT, g.x, g.y, R.range(-6, 6), -R.range(8, 18), R.range(0.7, 1.1), R.range(3, 5));+ for (let i = 0; i < 8; i++) puffs.spawn(PK.SOOT, R.range(-20, 20), CY + R.range(-20, 20), R.range(-8, 8), -R.range(6, 16), R.range(0.8, 1.2), R.range(3, 6), R.range(0, 0.15));+ }+ for (let i = lights.length - 1; i >= 0; i--) if ((lights[i].life -= dt) <= 0) lights.splice(i, 1);+ bits.update(dt);+ ps.update(dt);+ embers.update(dt);+ puffs.update(dt);+ },+ drawBack(p) {+ puffs.draw(p, PK.SOOT, { x: 0, y: CY, k: broke ? 0.3 : 0, reach: 50 });+ const k = t < BREAK ? smooth(0.1, 0.6, t) : 1 - smooth(BREAK, BREAK + 0.6, t);+ if (k > 0) p.glow(0, CY, 52, C[4], 0.3 * k);+ },+ draw(p) {+ if (!broke) {+ // the traced lines: white where the pen just passed, cooling to violet; pulsing as it holds; white in the flare+ const hold = t > S.end ? 0.5 + 0.5 * Math.sin((t - S.end) * 9) : 0, white = t >= FLARE;+ for (const q of S.pts) {+ if (q.t > t) break;+ const age = t - q.t;+ p.px(q.x, q.y, white ? WHITE : age < 0.05 ? WHITE : age < 0.15 ? C[7] : age < 0.35 ? C[6] : hold > 0.75 ? C[6] : C[5]);+ }+ if (white) for (const q of S.pts) if (((q.x * 2) | 0) % 3 === 0) p.light(q.x, q.y, C[6], 0.5);+ // glyphs: each pops in white and settles+ for (const g of G) {+ if (t < g.t) continue;+ const age = t - g.t, col = white || age < 0.06 ? WHITE : age < 0.2 ? C[7] : hold > 0.75 ? C[7] : C[6];+ for (const [a, b] of g.segs) p.line(g.x - 2 + a[0] * 2, g.y - 2 + a[1] * 2, g.x - 2 + b[0] * 2, g.y - 2 + b[1] * 2, col);+ if (age < 0.18) ringFast(p, g.x, g.y, 2 + 4 * (age / 0.18), 1, age < 0.09 ? C[7] : C[5]);+ p.glow(g.x, g.y, 6, C[5], 0.25);+ }+ // the pen: a white-hot point with a little cross of light+ if (t > 0.12 && t < S.end + 0.05) {+ const q = pen();+ sparkle(p, q.x, q.y, 3 + Math.sin(t * 60), C[7], C[6], 0.6);+ p.glow(q.x, q.y, 16, C[6], 0.55);+ }+ }+ // the flare: a burst ring as it goes white+ const fu = (t - FLARE) / 0.35, bu = (t - FLARE) / 0.22;+ if (bu > 0 && bu < 1) sparkle(p, 0, CY, 18 * (1 - bu), C[7], C[5], 0.9 * (1 - bu));+ if (fu > 0 && fu < 1) ringFast(p, 0, CY, RO + 3 + 12 * ease.outCubic(fu), Math.max(1, 3 * (1 - fu)), fu < 0.4 ? WHITE : fu < 0.7 ? C[6] : C[4]);+ bits.draw(p);+ puffs.draw(p, PK.FLAME);+ ps.draw(p);+ embers.draw(p);+ for (const l of lights) {+ const q = l.life / l.max;+ p.glow(l.x, l.y, l.r * (0.6 + 0.4 * q), l.k > 1 ? C[5] : C[6], l.k * q * q);+ }+ },+ };}diff --git a/src/fx/shadow/life-steal.js b/src/fx/shadow/life-steal.jsindex f3ee26a..e8ca1a0 100644--- a/src/fx/shadow/life-steal.js+++ b/src/fx/shadow/life-steal.js@@ -1,96 +1,135 @@-import { burst, seg, ease, clamp, lerp, TAU, WHITE } from "../../core/index.js";-import { steps, CRIMSON } from "./_lib.js";+import { Particles, P, Rng, fit, sparkle, clamp, smooth, ease, TAU, WHITE, mix, luma } from "../../core/index.js";+import { ringFast, Drops } 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,+ desc: "A target on the right is struck and bleeds red orbs; they hang a moment, then whip home as comet streaks and flood the caster crimson.",+ tags: ["shadow", "life-steal", "drain", "blood", "heal", "directional", "magic", "one-shot"],+ size: [184, 100],+ origin: [36, 92],+ duration: 2.2,loop: false,fps: 30,- bg: "dark",- options: { palette: CRIMSON, count: 6, distance: 58, seed: 8 },+ bg: "ground",+ actor: 2,+ options: { palette: ["#14040a", "#3a0a14", "#6a101c", "#a01824", "#d42a30", "#ff5a50", "#ff9a8a", "#ffe6de"], dark: "#2a1040", seed: 11 },};-// 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 target point on the right, the caster's heart; when the orbs turn for home+const TX = 104, TY = -24, HX = 1, HY = -20, N = 7;- // 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));+export function create(o) {+ const C = fit(o.palette, 8), R = new Rng(o.seed), A = o.actor, floor = () => 0;+ const ps = new Particles({ rng: R, ground: floor, sparks: [WHITE, C[7], C[6], C[5]] });+ const drops = new Drops({ onLand: (x) => stains.push({ x, t0: t }) }), stains = [], lights = [];+ const orbs = [];+ for (let i = 0; i < N; i++) {+ const a = -Math.PI / 2 + (i - (N - 1) / 2) * 0.4 + R.range(-0.12, 0.12), sp = R.range(100, 170);+ orbs.push({ x: TX, y: TY, vx: Math.cos(a) * sp + 10, vy: Math.sin(a) * sp, home: 0.36 + i * 0.05 + R.range(0, 0.04), trail: [], done: false, at: 0, size: R.range(1.6, 2.4) });}+ let t = 0, hit = false, flush = 0;+ const light = (x, y, r, c, k, life) => lights.push({ x, y, r, c, k, life, max: life });- // 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)];+ return {+ update(dt) {+ t += dt;+ if (!hit) {+ hit = true;+ light(TX, TY, 54, C[5], 1, 0.35);+ light(TX, TY, 18, WHITE, 1, 0.08);+ for (let i = 0; i < 14; i++) drops.add(TX + R.range(-3, 3), TY + R.range(-3, 3), R.range(-40, 90), R.range(-140, -20), R.chance(0.4) ? 2 : 1);+ for (let i = 0; i < 12; i++) {+ const a = R.range(0, TAU), sp = R.range(80, 170);+ ps.spawn(P.SPARK, TX, TY, Math.cos(a) * sp, Math.sin(a) * sp, R.range(0.15, 0.35));+ }}- 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];+ for (const b of orbs) {+ if (b.done) continue;+ if (t < b.home) {+ // burst out, slowing to a hover+ b.vx -= b.vx * 5 * dt;+ b.vy -= b.vy * 5 * dt;+ } else {+ // whip home: steer hard at the caster's heart, faster and faster+ const dx = HX - b.x, dy = HY - b.y, d = Math.hypot(dx, dy) || 1, pull = 2600 * Math.min(1, (t - b.home) * 3);+ b.vx += (dx / d) * pull * dt;+ b.vy += (dy / d) * pull * dt;+ b.vx -= b.vx * 2.2 * dt;+ b.vy -= b.vy * 2.2 * dt;+ if (d < 6) {+ b.done = true;+ b.at = t;+ flush = Math.min(1.5, flush + 0.45);+ light(HX, HY, 30, C[5], 0.8, 0.25);+ for (let i = 0; i < 6; i++) {+ const a = R.range(0, TAU), sp = R.range(40, 100);+ ps.spawn(P.SPARK, HX, HY, Math.cos(a) * sp, Math.sin(a) * sp - 20, R.range(0.12, 0.3));+ }+ for (let i = 0; i < 3; i++) ps.spawn(P.EMBER, HX + R.range(-8, 8), HY + R.range(-6, 14), R.range(-10, 10), -R.range(15, 35), R.range(0.6, 1.1), C[6]);+ }+ }+ b.x += b.vx * dt;+ b.y += b.vy * dt;+ b.trail.unshift([b.x, b.y]);+ if (b.trail.length > 26) b.trail.pop();}- }- 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));- }+ flush -= flush * 2.6 * dt;+ for (let i = lights.length - 1; i >= 0; i--) if ((lights[i].life -= dt) <= 0) lights.splice(i, 1);+ for (let i = stains.length - 1; i >= 0; i--) if (t - stains[i].t0 > 0.8) stains.splice(i, 1);+ drops.update(dt);+ ps.update(dt);+ },+ drawBack(p) {+ // the wound: a dark red bloom where the target was struck, thinning away+ const k = 1 - smooth(0.1, 0.9, t);+ if (k > 0) {+ p.disc(TX, TY, 6 + t * 10, C[2], 0.5 * k);+ p.glow(TX, TY, 30, C[4], 0.35 * k);+ }+ for (const s of stains) p.dot(s.x, -0.5, C[3], 1 - (t - s.t0) / 0.8);+ },+ draw(p) {+ // the caster flushes crimson as the orbs land: its own colours pushed toward blood-red, a hot outline+ const fk = Math.min(1, flush) * (1 - smooth(1.5, 2.05, t));+ if (A && fk > 0.03) {+ for (let my = 0; my < A.h; my++)+ for (let mx = 0; mx < A.w; mx++) {+ const c0 = A.pixels[my * A.w + mx];+ if (!c0) continue;+ const l = luma(c0);+ p.blend(A.x + mx, A.y + my, l > 0.6 ? C[6] : l > 0.4 ? C[5] : l > 0.2 ? C[4] : C[3], 0.45 * fk);+ }+ if (fk > 0.12) p.outline(A.mask, A.x, A.y, fk > 0.6 ? C[6] : fk > 0.3 ? C[5] : C[3]);+ p.glow(HX, HY, 28, C[5], 0.45 * fk);+ }+ // the hit on the target+ if (t < 0.12) sparkle(p, TX, TY, 10 * (1 - t / 0.12), C[7], C[5], 0.6);+ const ru = t / 0.28;+ if (ru < 1) ringFast(p, TX, TY, 4 + 16 * ease.outCubic(ru), Math.max(1, 2 * (1 - ru)), ru < 0.4 ? C[7] : C[5]);+ drops.draw(p, C[3], C[6]);+ // the orbs: comet tails tapering from a hot head through blood-red to a dark wine thread+ for (const b of orbs) {+ if (b.done && t - b.at > 0.2) continue;+ // the tail is swallowed after the head: it shortens rather than fades+ const n = b.done ? Math.floor(b.trail.length * (1 - (t - b.at) / 0.2)) : b.trail.length;+ for (let i = n - 1; i >= 1; i--) {+ const u = i / 25, [x0, y0] = b.trail[i - 1], [x1, y1] = b.trail[i];+ p.line(x1, y1, x0, y0, u < 0.15 ? C[7] : u < 0.35 ? C[6] : u < 0.6 ? C[5] : u < 0.8 ? C[4] : C[2]);+ if (i < 7) p.disc(x1, y1, (b.size + 0.4) * (1 - i / 7), u < 0.12 ? C[6] : C[5], 0.8);+ if (i % 6 === 3) p.glow(x1, y1, 6, C[5], 0.2 * (1 - u));+ }+ if (b.done) continue;+ const pulse = t < b.home ? 0.8 + 0.2 * Math.sin(t * 30 + b.size * 9) : 1;+ p.circle(b.x, b.y, b.size + 0.9, C[4]);+ p.circle(b.x, b.y, b.size * pulse, C[6]);+ p.px(b.x - 0.5, b.y - 0.5, WHITE);+ p.glow(b.x, b.y, 9, C[5], 0.5);+ }+ ps.draw(p);+ for (const l of lights) {+ const q = l.life / l.max;+ p.glow(l.x, l.y, l.r * (0.6 + 0.4 * q), l.c, l.k * q * q);+ }+ },+ };}diff --git a/src/fx/shadow/necro-skulls.js b/src/fx/shadow/necro-skulls.jsindex 83e3f8d..fbc8262 100644--- a/src/fx/shadow/necro-skulls.js+++ b/src/fx/shadow/necro-skulls.js@@ -1,76 +1,113 @@-import { cycle, rng, TAU } from "../../core/index.js";-import { steps, SPECTRAL, SKULL_7, shape } from "./_lib.js";+import { cycle, fit, clamp, smooth, tileNoise, TAU, WHITE, mix } from "../../core/index.js";+import { halo } 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,+ desc: "Spectral skulls circle a cold green flame on a tilted orbit, passing behind and before it, eyes lit, trailing curls of ghost smoke.",+ tags: ["shadow", "necromancy", "skull", "orbit", "ghost", "spectral", "magic", "loop"],+ size: [136, 116],+ origin: [68, 108],+ duration: 3,loop: true,fps: 30,- bg: "dark",- options: { palette: SPECTRAL, count: 5, radius: 18, seed: 7 },+ bg: "ground",+ options: {+ palette: ["#040e10", "#0a2228", "#0f3d44", "#16615f", "#23907f", "#45c4a0", "#9af0c8", "#e8fff4"],+ bone: ["#0c1a1c", "#2c4a4a", "#5c847c", "#a6cdb8", "#e4fff0"],+ seed: 6,+ },};-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)];- };+// the flame's base and height; the orbit (centre, radii, tilt); six skulls, one turn a loop+const CY = -52, FB = -32, FH = 34, RX = 42, RY = 11, TILT = -0.12, D = 3, N = 5;+const SKULL = [+ "...kkkkk...",+ ".kkhhhllkk.",+ "khhhhlllmmk",+ "khhllllllmk",+ "kleeeleeemk",+ "kleeeleeedk",+ "kmleelleedk",+ ".kmllnllmk.",+ ".kmmlnlmdk.",+ "..kmmmmmk..",+ "..ktgtgtk..",+ "...kkkkk...",+];- 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+// a skull's place at t: round the tilted orbit, bobbing; z > 0 is in front of the flame+function skullAt(i, t) {+ const a = (TAU * t) / D + (i * TAU) / N, ex = Math.cos(a) * RX, ey = Math.sin(a) * RY;+ const bob = Math.sin((TAU * 2 * t) / D + i * 1.7) * 2;+ return { x: ex * Math.cos(TILT) - ey * Math.sin(TILT), y: CY + ex * Math.sin(TILT) + ey * Math.cos(TILT) + bob, z: Math.sin(a), a };+}- 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);- };+// ghost smoke curling off behind each skull along its orbit: puffs that swell, rise and thin with age+function tail(p, C, i, t) {+ for (let k = 8; k >= 1; k--) {+ const tt = t - k * 0.05, s = skullAt(i, tt), age = k / 8;+ const r = 2 + age * 3.6, a = (1 - age) * 0.5 * (0.6 + 0.4 * (s.z + 1) / 2);+ p.disc(s.x, s.y - age * 7 + 2, r, age < 0.4 ? C[5] : age < 0.7 ? C[4] : C[3], a);+ }+}- 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);- }+function drawSkull(p, C, K, s, t, i) {+ const front = s.z >= 0, depth = 0.55 + 0.45 * (s.z + 1) / 2;+ const PAL = front+ ? { k: K[0], d: K[1], m: K[2], l: K[3], h: K[4], e: C[0], n: C[0], t: K[3], g: K[0] }+ : { k: K[0], d: K[0], m: K[1], l: K[2], h: K[3], e: C[0], n: C[0], t: K[2], g: K[0] };+ const x0 = Math.round(s.x) - 5, y0 = Math.round(s.y) - 6;+ p.sprite(SKULL, PAL, x0, y0);+ // eyes: cold points of light in the dark, flaring as the skull swings toward us+ const k = (0.5 + 0.5 * Math.sin((TAU * 3 * t) / D + i * 2.1)) * 0.5 + 0.5;+ for (const ex of [3, 7]) {+ p.px(x0 + ex + 0.5, y0 + 5.5, front ? (k > 0.75 ? WHITE : C[7]) : C[6]);+ if (front) p.px(x0 + ex + 0.5, y0 + 4.5, C[5]);+ p.glow(x0 + ex + 1, y0 + 6, 6, C[5], 0.45 * depth * k);}- if (!coreDone) core();+ p.glow(s.x, s.y, 11, C[4], 0.18 * depth);+}- // 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]);+// the cold flame: a body that swells off its base and tapers into licking tongues, white only low in its heart,+// cooling outward and upward through the ghost greens, scrolling up (the noise wraps once a loop)+function flame(p, C, t) {+ const W = 10, scroll = t / D;+ p.shade(-W - 4, FB - FH - 4, W + 4, FB + 2, (x, y, out) => {+ const u = (FB - y) / FH;+ if (u < -0.04 || u >= 1) return;+ const n1 = tileNoise(x * 0.3, y * 0.2 + scroll * 8, 0, 8, 3), n2 = tileNoise(x * 0.6, y * 0.45 + scroll * 16, 0, 16, 5);+ const prof = u < 0.22 ? 0.35 + 0.65 * Math.sqrt(Math.max(0, u) / 0.22) : Math.pow(1 - (u - 0.22) / 0.78, 0.85);+ const w = W * prof * (1 + 0.3 * n1) + n2 * 2.2 * u, sway = n1 * 3 * u * u, d = Math.abs(x - sway) / Math.max(0.6, w);+ if (d > 1) return;+ const heat = Math.pow(1 - d, 0.7) * Math.pow(Math.max(0, 1 - u), 0.55) + n2 * 0.12;+ if (((Math.floor(x) + Math.floor(y)) & 1) === 0) out.k = 0.16 * heat;+ return heat > 0.82 ? WHITE : heat > 0.66 ? C[7] : heat > 0.46 ? C[6] : heat > 0.27 ? C[5] : heat > 0.12 ? C[4] : C[3];+ });+ p.glow(0, FB - FH * 0.35, 40, C[5], 0.45);+ p.glow(0, FB - 5, 12, C[7], 0.25);+}++export function drawBack(p, t, o) {+ const C = fit(o.palette, 8), K = fit(o.bone, 5);+ p.glow(0, -1, 40, C[4], 0.2);+ // the far half of the orbit: tails and skulls behind the flame, back to front+ const order = Array.from({ length: N }, (_, i) => [i, skullAt(i, t)]).filter(([, s]) => s.z < 0).sort((a, b) => a[1].z - b[1].z);+ for (const [i] of order) tail(p, C, i, t);+ for (const [i, s] of order) drawSkull(p, C, K, s, t, i);+}++export function draw(p, t, o) {+ const C = fit(o.palette, 8), K = fit(o.bone, 5), S = o.seed;+ // motes and cold sparks rising off the flame+ cycle(t, D, 18, S, (r) => r.range(0.8, 1.4), (age, L, r) => {+ const x0 = r.range(-6, 6), u = age / L, x = x0 + Math.sin(u * 5 + r.range(0, 6)) * 3 * u, y = FB - 6 - u * r.range(36, 56);+ p.dot(x, y, u < 0.5 ? C[7] : C[6], u < 0.7 ? 1 : (1 - u) * 3.3);+ p.glow(x, y, 3, C[6], 0.3 * (1 - u));});+ flame(p, C, t);+ // the near half of the orbit, back to front+ const order = Array.from({ length: N }, (_, i) => [i, skullAt(i, t)]).filter(([, s]) => s.z >= 0).sort((a, b) => a[1].z - b[1].z);+ for (const [i] of order) tail(p, C, i, t);+ for (const [i, s] of order) drawSkull(p, C, K, s, t, i);+ halo(p, 0, CY, 0, 46, C[4], 0.12);}diff --git a/src/fx/shadow/shadow-flames.js b/src/fx/shadow/shadow-flames.jsindex cf40d35..e122825 100644--- a/src/fx/shadow/shadow-flames.js+++ b/src/fx/shadow/shadow-flames.js@@ -1,59 +1,102 @@-import { cycle, tileFbm, loopNoise, clamp, TAU } from "../../core/index.js";-import { steps, UMBRA } from "./_lib.js";+// Tongues built from nested layers, each narrower and shorter than the last, are adapted from Sprite Fusion's+// open-source fire (https://www.spritefusion.com/pixel-art-vfx/fire), MIT License, Copyright (c) 2026 Hugo Duprez.+// Here the layers run the other way: a pale skin outside, violet within, a black heart at the core.+import { cycle, fit, noise2, TAU, WHITE, mix } from "../../core/index.js";+import { VOID } 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,+ desc: "Inside-out fire on the floor: a black heart wrapped in violet flame with pale skin and tips, shedding embers and dark smoke.",+ tags: ["shadow", "fire", "flame", "ground", "dark", "magic", "loop"],+ size: [104, 112],+ origin: [52, 102],+ duration: 2.4,loop: true,fps: 30,bg: "ground",- options: { palette: UMBRA, height: 26, seed: 3 },+ options: { palette: VOID, seed: 12 },};-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)];+const D = 2.4, GX = 22, GY = 60;+// tongues: offset, base height, width, seed; the middle tallest+const TONGUES = [[-11, 20, 4.2, 1], [11, 22, 4.4, 2], [-6, 31, 5.4, 3], [6, 29, 5.2, 4], [0, 40, 6.6, 5]];+// layers from the outside in: width share, height share, which tone (3 is the black heart)+const LAYERS = [[1, 1, 0], [0.8, 0.88, 1], [0.54, 0.68, 2], [0.32, 0.48, 3]];++// noise that comes back to where it started each loop: a circle through 2D noise, offset by v+const lnoise = (t, v, seed, speed = 5) => noise2(Math.cos((TAU * t) / D) * speed + v, Math.sin((TAU * t) / D) * speed, seed);- // 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);+export function drawBack(p, t, o) {+ const C = fit(o.palette, 8), S = o.seed;+ // the scorched floor: a dark burn, violet light pooled on it+ p.ellipse(0, 0.5, 22, 3.2, (d) => (d < 0.6 ? C[0] : C[1]), (d) => (d < 0.85 ? 1 : (1 - d) * 6));+ p.glow(0, -2, 46, C[4], 0.3);+ // dark smoke climbing off the tips, a lit rim on its underside+ cycle(t, D, 14, S + 1, (r) => r.range(1.2, 1.9), (age, L, r) => {+ const u = age / L, x = r.range(-6, 6) + Math.sin(u * 4 + r.range(0, 6)) * 5 * u, y = -30 - u * r.range(36, 52), rad = 3 + u * 6;+ const a = Math.min(1, u * 6) * (1 - u) * 0.7;+ p.disc(x, y, rad, mix(mix(C[3], C[2], 0.5), C[1], u), a);+ p.disc(x - rad * 0.2, y - rad * 0.3, rad * 0.5, C[3], a * 0.4);+ p.disc(x, y + rad * 0.45, rad * 0.55, C[5], a * 0.45 * (1 - u));});- // 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]);+}++export function draw(p, t, o) {+ const C = fit(o.palette, 8), S = o.seed, TONE = [C[6], C[4], C[2], C[0]];+ // rasterize the tongues, outermost first, into a grid of tones+ const grid = new Int8Array(GX * 2 * GY).fill(-1), set = (x, y, v) => {+ const i = Math.round(x) + GX, j = Math.round(y) + GY;+ if (i >= 0 && j >= 0 && i < GX * 2 && j < GY) grid[j * GX * 2 + i] = v;+ };+ const order = TONGUES.map((_, i) => i).sort((a, b) => Math.abs(TONGUES[b][0]) - Math.abs(TONGUES[a][0]));+ for (const i of order) {+ const [dx, H0, w, n] = TONGUES[i], h = H0 * (0.78 + 0.22 * lnoise(t, n * 3, n, 4)), sway = lnoise(t, n * 7, n + 9, 3) * 3;+ for (const [lw, lh, tone] of LAYERS) {+ const Hl = h * lh;+ for (let r = 0; r <= Hl; r++) {+ const u = r / Math.max(1, Hl);+ const half = w * lw * Math.pow(1 - u, 0.85) * Math.min(1, (r + 1.5) / 3.5) + lnoise(t, r * 0.45 + n, n + 20, 6) * 1.1 + lnoise(t, r * 1.3 + n * 5, n + 50, 9) * 0.6;+ const cx = dx + sway * u * u * lh + lnoise(t, r * 0.2 + n * 2, n + 30, 5) * u * 1.4;+ if (half < 0.3) continue;+ for (let x = Math.round(cx - half); x <= Math.round(cx + half); x++) {+ // the skin breaks up near the top: pixels flicker out of it+ if (tone === 0 && u > 0.45 && lnoise(t, x * 0.9 + r * 0.7 + n, n + 60, 8) > 0.35) continue;+ set(x, -r, tone);+ }+ }+ }+ }+ // draw it: the pale skin whitening to its tips, the black heart pure black+ for (let j = 0; j < GY; j++)+ for (let i = 0; i < GX * 2; i++) {+ const v = grid[j * GX * 2 + i];+ if (v < 0) continue;+ const x = i - GX, y = j - GY;+ let c = TONE[v];+ if (v === 0 && y < -24 && (grid[(j - 1) * GX * 2 + i] ?? -1) < 0) c = y < -32 ? WHITE : C[7];+ p.px(x + 0.5, y + 0.5, c);+ }+ // licks of pale flame breaking off the tips+ cycle(t, D, 34, S, (r) => r.range(0.25, 0.5), (age, L, r) => {+ const u = age / L, k = r.int(0, 4), [dx, H0] = TONGUES[k], x = dx + r.range(-4, 4) + u * r.range(-5, 5), y = -H0 * r.range(0.45, 0.85) - u * r.range(10, 20);+ const rad = r.range(1, 2.2) * (1 - u) + 0.3;+ p.circle(x, y, rad + 0.6, u < 0.5 ? C[6] : C[4]);+ if (rad > 1) p.circle(x, y + 0.4, rad * 0.5, u < 0.3 ? C[2] : C[4]);});- // 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));+ // embers drifting up, flickering, cooling to violet+ cycle(t, D, 30, S + 2, (r) => r.range(1, 1.8), (age, L, r) => {+ const u = age / L, x = r.range(-12, 12) + Math.sin(u * 6 + r.range(0, 6)) * 5 * u, y = -10 - u * r.range(40, 70);+ if (u > 0.7 && Math.sin(age * 40 + x) < 0) return;+ p.px(x, y, u < 0.3 ? WHITE : u < 0.6 ? C[7] : C[6]);+ p.glow(x, y, 3, C[6], 0.35 * (1 - u));});-- // 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);+ // light: a violet bloom round it, but none on the black heart+ const fl = 0.85 + 0.15 * lnoise(t, 0, 77, 6);+ p.glow(0, -16, 52, C[4], 0.5 * fl);+ p.glow(0, -12, 26, C[6], 0.34 * fl);+ for (let j = 0; j < GY; j++)+ for (let i = 0; i < GX * 2; i++) if (grid[j * GX * 2 + i] === 3) {+ const sx = p.cellX(i - GX + 0.5, j - GY + 0.5) - p.ox, sy = p.cellY(i - GX + 0.5, j - GY + 0.5) - p.oy;+ if (sx >= 0 && sy >= 0 && sx < p.w && sy < p.h) p.L[sy * p.w + sx] = 0;+ }}diff --git a/src/fx/shadow/shadow-step.js b/src/fx/shadow/shadow-step.jsdeleted file mode 100644index 77fdccf..0000000--- a/src/fx/shadow/shadow-step.js+++ /dev/null@@ -1,69 +0,0 @@-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.jsindex 28400d2..52783a8 100644--- a/src/fx/shadow/shadow-tendrils.js+++ b/src/fx/shadow/shadow-tendrils.js@@ -1,73 +1,194 @@-import { burst, cycle, seg, ease, TAU } from "../../core/index.js";-import { steps, UMBRA } from "./_lib.js";+import { Particles, P, Rng, fit, clamp, smooth, ease, noise, TAU, WHITE, mix } from "../../core/index.js";+import { VOID, Puffs, PK, Drops, floorPool } 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,+ desc: "A dark pool opens on the floor; tentacles with lit rims and hooked tips lash up out of it with a splash, writhe, and sink back as it closes.",+ tags: ["shadow", "tentacle", "tendril", "ground", "dark", "magic", "one-shot"],+ size: [208, 130],+ origin: [104, 106],+ duration: 3.2,loop: false,fps: 30,bg: "ground",- options: { palette: UMBRA, count: 4, height: 34, seed: 4 },+ options: { palette: VOID, seed: 3 },};-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);+const RX = 40, OPEN = 0.34, SHUT = 2.5, SINK = 0.5, LX = -0.6, LY = -0.8;- // 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));+// a tentacle's spine at t: it rises out of the pool along its own curve, a wave writhes up it, its lean sways+// and sometimes whips, and its tip curls into a hook; points every 0.5 px with angle and half-width+function spine(T, t) {+ const e = clamp((t - T.t0) / 0.2), s1 = clamp((t - T.t1) / SINK);+ if (e <= 0 || s1 >= 1) return null;+ // it lashes up past its length and settles; going, it lifts a little, then slides back under+ const lift = 0.07 * Math.sin(Math.PI * clamp(s1 / 0.3)), down = ease.inOutCubic(clamp((s1 - 0.12) / 0.88));+ const rise = ease.outBack(e, 1.8) * (1 + lift) * (1 - down), hidden = (1 - rise) * T.L;+ const writhe = T.A * (0.25 + 0.75 * smooth(T.t0 + 0.08, T.t0 + 0.5, t));+ const hook = (0.04 + T.H * ease.outBack(clamp((t - T.t0 - 0.1) / 0.32), 2.5)) * (1 + 0.5 * s1) * (1 + 0.18 * Math.sin(t * 2.3 + T.ph));+ let lean = T.lean + 0.12 * Math.sin(t * 1.6 + T.ph);+ if (T.whip) lean += T.whip.a * Math.exp(-(((t - T.whip.t) / 0.14) ** 2));+ let th = -Math.PI / 2 + lean, x = T.x - Math.cos(th) * hidden, y = T.y - Math.sin(th) * hidden;+ const pts = [], n = Math.ceil(T.L / 0.5);+ for (let i = 0; i <= n; i++) {+ const s = i * 0.5, u = s / T.L;+ pts.push({ x, y, th, w: T.W * Math.pow(1 - u, 0.75) + 0.45, u, s });+ th += 0.5 * (writhe * Math.sin((s / T.lam) * TAU - T.om * t + T.ph) + T.curl * hook * smooth(0.58, 1, u));+ x += Math.cos(th) * 0.5;+ y += Math.sin(th) * 0.5;}+ return pts;+}- // 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;+// a tentacle in cross-sections: a dark body with a lighter half toward the light, then the rims: bright where it+// faces the light (white where it faces it squarely), violet on the side the pool lights, suckers inside the hook+function tentacle(p, T, pts, C, t) {+ const surf = T.y;+ for (const q of pts) {+ if (q.y > surf) continue;+ const nx = -Math.sin(q.th), ny = Math.cos(q.th), ks = nx * LX + ny * LY >= 0 ? 1 : -1;+ for (let v = -q.w; v <= q.w; v += 0.5) {+ const x = q.x + nx * v, y = q.y + ny * v;+ const u = (v / q.w) * ks;+ if (y <= surf) p.px(x, y, u > 0.55 ? C[2] : u > -0.45 ? C[1] : C[0]);}- 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);+ }+ // a pulse of light runs up it as it lashes, then slower ones while it writhes+ const pulse = (t - T.t0) * 150, slow = (((t - T.t0) * 55) % (T.L * 1.8)) - 4;+ for (const q of pts) {+ if (q.y > surf) continue;+ const nx = -Math.sin(q.th), ny = Math.cos(q.th), f = nx * LX + ny * LY, ks = f >= 0 ? 1 : -1;+ const lit = ks * q.w, x0 = q.x + nx * lit, y0 = q.y + ny * lit, x1 = q.x - nx * lit, y1 = q.y - ny * lit;+ if (y1 <= surf) p.px(x1, y1, C[3]);+ if (y0 <= surf) p.px(x0, y0, Math.abs(f) > 0.8 && q.u > 0.15 ? C[7] : q.u > 0.85 ? C[6] : Math.abs(f) > 0.3 ? C[6] : C[5]);+ if (q.u > 0.62 && q.u < 0.93 && q.s % 3 < 0.5) p.px(q.x + nx * T.curl * q.w * 0.45, q.y + ny * T.curl * q.w * 0.45, C[4]);+ const dp = Math.min(Math.abs(q.s - pulse), Math.abs(q.s - slow) * 1.6);+ if (dp < 2.5) p.px(q.x, q.y, dp < 1 ? C[7] : C[5]);+ }+ // the tip catches the light, and light runs along it+ const tip = pts[pts.length - 1];+ if (tip.y <= surf) {+ p.px(tip.x, tip.y, WHITE);+ p.glow(tip.x, tip.y, 6, C[6], 0.25);+ }+ for (let i = 0; i < pts.length; i += 8) if (pts[i].y < surf) p.glow(pts[i].x, pts[i].y, 9, C[4], 0.1);+ const pq = pts[Math.min(pts.length - 1, Math.max(0, Math.round(pulse * 2)))];+ if (pulse < T.L && pq.y < surf) p.glow(pq.x, pq.y, 10, C[6], 0.45);+ // where it breaks the surface: a lit collar of ink+ const base = pts.find((q) => q.y <= surf);+ if (base) {+ const w = base.w + 1.5;+ p.line(base.x - w, surf, base.x + w, surf, C[5]);+ p.px(base.x - w - 1, surf + 0.5, C[3]);+ p.px(base.x + w + 1, surf + 0.5, C[3]);+ }+}- // 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]);+export function create(o) {+ const C = fit(o.palette, 8), R = new Rng(o.seed), floor = () => 0;+ const DIM = [C[0], C[0], C[1], C[1], C[3], C[4], C[5], C[6]];+ const ps = new Particles({ rng: R, ground: floor, sparks: [C[7], C[6], C[5], C[4]], haze: C[4] });+ const puffs = new Puffs({ rng: R, flame: [C[7], C[6], C[5], C[4], C[3], C[2], C[1], C[1], C[0]], soot: [mix(C[3], C[2], 0.55), mix(C[2], C[1], 0.5)], cap: mix(C[4], C[2], 0.5), rim: [C[6], C[5], C[4]], floor });+ const ripples = [], splats = [], lights = [];+ let t = 0, acc = 0;+ const rx = (tt) => RX * ease.outCubic(clamp(tt / OPEN)) * (1 - ease.inCubic(clamp((tt - SHUT) / 0.45)));+ const inPool = (x, tt) => Math.abs(x) < rx(tt) * 0.95;+ const drops = new Drops({+ onLand: (x, y, v, s) => {+ if (inPool(x, t)) ripples.push({ x, t0: t, life: 0.5, w: 0.6 });+ else splats.push({ x, t0: t, s });+ },+ });+ // seven tentacles in two rows: the back row taller and dimmer, hooks mostly curling inward+ const rows = [[-22, -2.5], [-8, -3], [7, -3], [21, -2.5], [-28, 2.5], [-1, 3], [27, 2.5]];+ const order = [3, 0, 5, 2, 4, 1, 6], last = [1, 5, 0, 6, 3, 2, 4];+ const tents = rows.map(([x, y], i) => {+ const back = y < 0, sx = Math.sign(x) || 1;+ return {+ x: x + R.range(-3, 3), y, back,+ L: back ? R.range(46, 62) : R.range(32, 46), W: back ? R.range(3.2, 4) : R.range(3.8, 4.6),+ lean: sx * (0.06 + Math.abs(x) / 120) + R.range(-0.06, 0.06), curl: R.chance(0.75) ? -sx : sx,+ lam: R.range(36, 50), om: R.range(4.5, 7) * R.sign(), ph: R.range(0, TAU), A: R.range(0.06, 0.085), H: R.range(0.15, 0.32),+ t0: 0.3 + order[i] * 0.045 + R.range(0, 0.03), t1: 1.5 + last[i] * 0.1 + R.range(0, 0.05),+ whip: R.chance(0.45) ? { t: R.range(0.9, 1.5), a: R.range(0.28, 0.45) * R.sign() } : null,+ up: false, down: false,+ };});++ function splash(x, y, n, power) {+ for (let i = 0; i < n; i++) drops.add(x + R.range(-2, 2), y - 1, R.range(-70, 70) * power, -R.range(90, 230) * power, R.chance(0.4) ? 2 : 1);+ ripples.push({ x, t0: t, life: 0.7, w: 1 });+ lights.push({ x, y: y - 7, r: 30, k: 0.6 * power, life: 0.25, max: 0.25 });+ }++ return {+ update(dt) {+ t += dt;+ for (const T of tents) {+ if (!T.up && t >= T.t0) {+ T.up = true;+ splash(T.x, T.y, 12, 1);+ for (let i = 0; i < 4; i++) ps.spawn(P.SPARK, T.x, T.y - 2, R.range(-80, 80), -R.range(120, 260), R.range(0.2, 0.45));+ }+ if (!T.down && t >= T.t1 + SINK * 0.8) {+ T.down = true;+ splash(T.x, T.y, 6, 0.6);+ }+ // glints run over the rims while they stand+ if (t > T.t0 + 0.2 && t < T.t1 && R.chance(dt * 1.6)) {+ const pts = spine(T, t), q = pts && pts[Math.floor(R.range(0.3, 0.95) * pts.length)];+ if (q && q.y < T.y) ps.spawn(P.STAR, q.x - Math.sin(q.th) * q.w, q.y + Math.cos(q.th) * q.w, 0, -4, R.range(0.25, 0.5), C[6], R.range(1, 2.2));+ }+ }+ // the pool breathes out wisps and motes while it's open+ const r = rx(t);+ if (r > 8 && t < SHUT - 0.4) {+ for (acc += dt * 9; acc > 1; acc--) puffs.spawn(PK.SOOT, R.range(-0.8, 0.8) * r, -R.range(1, 4), R.range(-8, 8), -R.range(14, 30), R.range(0.6, 0.85), R.range(3, 6));+ if (R.chance(dt * 16)) ps.spawn(P.MOTE, R.range(-0.8, 0.8) * r, -2, R.range(-8, 8), -R.range(30, 80), R.range(0.5, 1), R.pick([C[7], C[6], C[6], C[5]]), R.range(0.6, 1.1));+ if (R.chance(dt * 5)) ps.spawn(P.EMBER, R.range(-0.8, 0.8) * r, -3, R.range(-10, 10), -R.range(20, 45), R.range(0.6, 1), C[6]);+ if (R.chance(dt * 3)) ripples.push({ x: R.range(-0.7, 0.7) * r, t0: t, life: 0.6, w: 0.5 });+ // a violet haze hangs over the pool, lit from inside+ if (R.chance(dt * 7)) ps.spawn(P.VAPOUR, R.range(-0.7, 0.7) * r, -R.range(2, 8), R.range(-6, 6), -R.range(10, 22), R.range(0.6, 0.9), R.chance(0.5) ? C[3] : C[4], R.range(3, 6));+ }+ for (const a of [ripples, splats]) for (let i = a.length - 1; i >= 0; i--) if (t - a[i].t0 > (a[i].life ?? 0.6)) a.splice(i, 1);+ for (let i = lights.length - 1; i >= 0; i--) if ((lights[i].life -= dt) <= 0) lights.splice(i, 1);+ drops.update(dt);+ puffs.update(dt);+ ps.update(dt);+ },+ drawBack(p) {+ const r = rx(t), k = r / RX;+ floorPool(p, C, r, t, ripples);+ if (k > 0) {+ p.glow(0, -16, 86, C[4], 0.22 * k);+ p.glow(0, -8, r * 1.7 + 12, C[4], 0.32 * k * (0.9 + 0.1 * Math.sin(t * 5)));+ p.glow(0, 0, r * 1.15, C[5], 0.18 * k);+ }+ puffs.draw(p, PK.SOOT, { x: 0, y: 6, k: k, reach: 70 });+ ps.draw(p, "back");+ for (const T of tents) if (T.back) {+ const pts = spine(T, t);+ if (pts) tentacle(p, T, pts, DIM, t);+ }+ },+ draw(p) {+ for (const T of tents) if (!T.back) {+ const pts = spine(T, t);+ if (pts) tentacle(p, T, pts, C, t);+ }+ drops.draw(p, C[1], C[5]);+ for (const s of splats) {+ const a = 1 - (t - s.t0) / 0.6;+ p.dot(s.x, -0.5, C[1], a * 1.5);+ p.dot(s.x + 1, -0.5, C[2], a);+ if (s.s > 1) p.dot(s.x - 1, -0.5, C[2], a);+ p.dot(s.x, -1.5, C[5], a);+ }+ ps.draw(p, "front");+ for (const l of lights) {+ const q = l.life / l.max;+ p.glow(l.x, l.y, l.r * (0.6 + 0.4 * q), C[5], l.k * q * q);+ }+ },+ };}diff --git a/src/fx/shadow/soul-drain.js b/src/fx/shadow/soul-drain.jsindex bc133bd..180649a 100644--- a/src/fx/shadow/soul-drain.js+++ b/src/fx/shadow/soul-drain.js@@ -1,74 +1,136 @@-import { cycle, ease, bump, clamp, tileNoise, at, TAU } from "../../core/index.js";-import { steps, shape } from "./_lib.js";+import { cycle, fit, smooth, ease, rand, TAU, WHITE } from "../../core/index.js";+import { VOID, ringFast, halo } 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,+ desc: "Pale souls are torn loose on the right and dragged down a funnel of streaks into a black crystal vessel, which flares violet as each one lands.",+ tags: ["shadow", "soul", "drain", "necromancy", "funnel", "directional", "magic", "loop"],+ size: [208, 120],+ origin: [40, 110],+ duration: 3.2,loop: true,fps: 30,- bg: "dark",- options: {- palette: ["#0a0614", "#1c0e36", "#341a5c", "#4a3a8a", "#5a72b4", "#7cb4dc", "#c4ecf8", "#ffffff"],- length: 70, count: 5, seed: 9,- },+ bg: "ground",+ options: { palette: VOID, soul: ["#2c3f66", "#7d9fd0", "#cfe6ff", "#ffffff"], seed: 8 },};-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 vessel's centre; the loop; the funnel's streamlines (start points out on the right); four souls a loop+const VY = -50, D = 3.2, LINES = 11, SOULS = 4, TRAVEL = 1.45;+const wrap = (x) => ((x % D) + D) % D;+const line = (i) => {+ const sx = 96 + rand(i, 1) * 64, sy = -88 + rand(i, 2) * 72, bend = (rand(i, 3) - 0.5) * 50;+ return { sx, sy, c1x: sx * 0.55, c1y: sy + bend, c2x: 22 + rand(i, 4) * 14, c2y: VY + (sy - VY) * 0.25 };+};+const LN = Array.from({ length: LINES }, (_, i) => line(i));+// a point along streamline i at u (0 at its start, 1 at the vessel), cubic bezier+function along(L, 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 * L.sx + b * L.c1x + c * L.c2x, a * L.sy + b * L.c1y + c * L.c2y + d * (VY - L.sy) + d * L.sy];+}+const soul = (j) => ({ born: (j + 0.15 + rand(j, 7) * 0.5) * (D / SOULS), line: Math.floor(rand(j, 8) * LINES) });+const landings = (t) => {+ let f = 0;+ for (let j = 0; j < SOULS; j++) {+ const since = wrap(t - soul(j).born - TRAVEL);+ f += Math.exp(-since / 0.14) * (since < 1 ? 1 : 0);+ }+ return Math.min(1.4, f);+};- // 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));+// the vessel: a black crystal, two facets lit violet from inside, a hard ridge, a heart of stolen light+function vessel(p, C, t, f) {+ const y0 = VY + Math.sin((TAU * t) / D) * 1.5, W = 9, UP = 14, DN = 12;+ p.shade(-W - 1, y0 - UP - 1, W + 1, y0 + DN + 1, (x, y) => {+ const dy = y - y0, half = dy < 0 ? W * (1 + dy / UP) : W * (1 - dy / DN);+ if (half <= 0 || Math.abs(x) > half + 0.6) return;+ if (Math.abs(x) > half - 0.4) return f > 0.5 ? C[6] : C[1];+ const ridge = Math.abs(x + dy * 0.12) < 0.6, heart = Math.abs(x) + Math.abs(dy - 1) < 2.6 + f * 1.5;+ if (heart) return f > 0.4 ? WHITE : C[6];+ if (ridge) return f > 0.3 ? C[7] : C[5];+ if (x < 0) return dy < 0 ? (f > 0.2 ? C[5] : C[4]) : C[3];+ return dy < 0 ? C[2] : C[1];});+ p.glow(0, y0, 30 + 14 * f, C[5], 0.5 + 0.5 * f);+ p.glow(0, y0 + 1, 8, WHITE, 0.25 + 0.6 * f);+ return y0;+}- // 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);+export function drawBack(p, t, o) {+ const C = fit(o.palette, 8);+ // the funnel: streamlines bunching into the vessel, dashes running down them, brighter as they close in+ for (let i = 0; i < LINES; i++) {+ const L = LN[i], ph = wrap(t + i * 0.37) / D;+ let px = null, py = null;+ for (let u = 0; u <= 1.0001; u += 0.01) {+ const [x, y] = along(L, u), dash = (((u * 5 - ph * 10 + i * 0.3) % 1) + 1) % 1;+ // a faint line the whole way, bright dashes riding it inward, all brighter as it narrows+ if (px !== null) p.line(px, py, x, y, u > 0.6 ? C[3] : C[2], 0.4 + 0.6 * u);+ if (dash < 0.18) p.px(x, y, u > 0.7 ? C[7] : u > 0.35 ? C[6] : C[5]);+ (px = x), (py = y);}- });+ }+ p.glow(10, VY, 40, C[4], 0.22);+}- // 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]);+export function draw(p, t, o) {+ const C = fit(o.palette, 8), S = fit(o.soul, 4), f = landings(t);+ // where the souls are torn from: a faint pale haze out on the right+ cycle(t, D, 10, o.seed, (r) => r.range(0.8, 1.3), (age, Lf, r) => {+ const x = r.range(100, 150), y = r.range(-80, -20) - age * 18, u = age / Lf;+ p.dot(x, y, S[2], (1 - u) * 0.8);+ p.glow(x, y, 4, S[1], 0.2 * (1 - u));+ });+ // streaks racing down the funnel, faster as they close on the vessel, white at the head+ cycle(t, D, 22, o.seed + 1, (r) => r.range(0.4, 0.7), (age, Lf, r) => {+ const L = LN[Math.floor(r.next() * LINES)], u0 = r.range(0.15, 0.5), q = u0 + (1 - u0) * Math.pow(age / Lf, 2.2), q2 = u0 + (1 - u0) * Math.pow(Math.max(0, age - 0.06) / Lf, 2.2);+ const [x, y] = along(L, q), [tx, ty] = along(L, q2);+ p.line(tx, ty, x, y, (v) => (v > 0.7 ? WHITE : v > 0.35 ? C[6] : C[4]));+ p.glow(x, y, 4, C[6], 0.35);+ });+ const y0 = vessel(p, C, t, f);+ // motes circling the vessel, in front and behind it+ for (let k = 0; k < 6; k++) {+ const a = (TAU * (2 * t)) / D + (k * TAU) / 6, ex = Math.cos(a) * 15, ey = Math.sin(a) * 5 - 2, z = Math.sin(a);+ p.px(ex, y0 + ey, z > 0 ? C[7] : C[4]);+ if (z > 0) p.glow(ex, y0 + ey, 4, C[6], 0.35);+ }+ // the souls: a pale head with hollow eyes and an open mouth, a wavering tail, dragged faster as they go+ for (let j = 0; j < SOULS; j++) {+ const s = soul(j), age = wrap(t - s.born);+ if (age > TRAVEL) continue;+ const L = LN[s.line], u = Math.pow(age / TRAVEL, 1.8), [x, y] = along(L, u);+ if (age < 0.18) {+ const k = 1 - age / 0.18;+ ringFast(p, L.sx, L.sy, 3 + 9 * (1 - k), 1, k > 0.5 ? S[2] : S[1]);+ p.glow(L.sx, L.sy, 12, S[1], 0.5 * k);+ }+ // the tail: a wavering wisp, pale near the head, thinning to violet+ for (let k = 14; k >= 1; k--) {+ const uu = Math.pow(Math.max(0, age - k * 0.03) / TRAVEL, 1.8), [tx, ty] = along(L, uu), w = Math.sin(t * 12 + k * 0.8 + j) * k * 0.16;+ const r = Math.max(0.5, 2.6 - k * 0.17);+ p.disc(tx, ty + w, r, k < 4 ? S[2] : k < 9 ? S[1] : C[5], 0.75 * (1 - k / 15));+ }+ // the head: a pale round face, hollow eyes and an open mouth, a lit rim, stretched as it nears the vessel+ const near = smooth(0.82, 1, u), hr = 3.4 - near * 1.6;+ p.circle(x, y, hr + 0.8, S[1]);+ p.circle(x, y, hr, S[2]);+ p.px(x - 1, y - 2, S[3]);+ p.px(x - 2, y - 1, S[3]);+ if (near < 0.5) {+ p.px(x - 1.5, y, S[0]);+ p.px(x + 1.5, y, S[0]);+ p.px(x, y + 1.6, S[0]);+ p.px(x, y + 2.4, S[0]);+ }+ p.glow(x, y, 10, S[1], 0.5);+ }+ // each landing: a flash in the heart, a ring off the crystal, a glint+ for (let j = 0; j < SOULS; j++) {+ const since = wrap(t - soul(j).born - TRAVEL);+ if (since < 0.3) {+ const k = since / 0.3;+ ringFast(p, 0, y0, 6 + 18 * ease.outCubic(k), Math.max(1, 2 * (1 - k)), k < 0.4 ? C[7] : k < 0.7 ? C[5] : C[3]);+ }}- 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);+ halo(p, 0, y0, 4, 22, C[6], 0.25 * f);}diff --git a/src/fx/shadow/void-orb.js b/src/fx/shadow/void-orb.jsindex 0325125..63f0c0f 100644--- a/src/fx/shadow/void-orb.js+++ b/src/fx/shadow/void-orb.js@@ -1,62 +1,183 @@-import { cycle, tileNoise, ease, fract, TAU } from "../../core/index.js";-import { steps, UMBRA } from "./_lib.js";+import { cycle, fit, clamp, smooth, ease, fbm, TAU, WHITE, mix } from "../../core/index.js";+import { VOID, halo, ringLight, ringFast, unlight } 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,+ desc: "A black orb hangs in the air, a pale rim crawling round it; a dark vortex winds into it, motes and streaks are pulled in, and light bends round its edge.",+ tags: ["shadow", "void", "orb", "vortex", "dark", "magic", "loop"],+ size: [168, 160],+ origin: [84, 150],+ duration: 3.2,loop: true,fps: 30,- bg: "dark",- options: { palette: UMBRA, radius: 8, count: 9, seed: 3 },+ bg: "ground",+ options: { palette: VOID, seed: 5 },};-const K = 2.2; // how tightly the vortex arms wind+// the orb's centre and radius, the vortex's reach, the radius light bends to (Einstein ring), the loop+// matter can't orbit inside GAP: there the dark is empty but for light bent round the orb+const Y = -62, R = 12, VR = 48, GAP = R + 9, E = R + 4.5, D = 3.2, ARMS = 3, K = 7, WIND = (TAU * 2) / D;+// two gulps a loop: the rim flares, the vortex brightens, a ring is drawn in+const GULPS = [0.2, 0.68];+const wrap = (x) => x - Math.floor(x);+const gulp = (t) => GULPS.reduce((s, g) => s + Math.exp(-((((wrap(t / D - g + 0.5) - 0.5) * D) / 0.07) ** 2)), 0);-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];- });+// specks of light behind the orb on looping paths; we see them through the lens: far off, a speck; passing+// behind, smeared into an arc hugging the rim, with a faint second image on the far side+const SOURCES = [+ { cx: 0, cy: 0, rho: 6, n: 1, ph: 0, s: 2.6, sy: 0.75 },+ { cx: 1, cy: -1, rho: 8, n: -1, ph: 2.2, s: 2, sy: 0.6 },+ { cx: 18, cy: -6, rho: 24, n: 1, ph: 0.4, s: 2.4, sy: 0.7 },+ { cx: -26, cy: 10, rho: 30, n: 1, ph: 2.6, s: 2, sy: 0.55 },+ { cx: 8, cy: 22, rho: 20, n: 2, ph: 4.1, s: 1.6, sy: 0.8 },+ { cx: -12, cy: -26, rho: 34, n: 1, ph: 5.3, s: 1.8, sy: 0.6 },+ { cx: 34, cy: 18, rho: 16, n: 2, ph: 1.2, s: 1.4, sy: 0.9 },+];- // 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);- });+// tables round the orb, built once: radius, angle, log radius, and lumpy turbulence for the vortex+let TAB = null;+function tables() {+ if (TAB) return TAB;+ const n = VR * 2, N = n * n, r = new Float32Array(N), th = new Float32Array(N), ln = new Float32Array(N), nz = new Float32Array(N);+ for (let j = 0; j < n; j++)+ for (let i = 0; i < n; i++) {+ const x = i - VR + 0.5, y = j - VR + 0.5, k = j * n + i, a = Math.atan2(y, x), d = Math.hypot(x, y), l = Math.log(Math.max(1, d));+ r[k] = d;+ th[k] = a;+ ln[k] = l;+ nz[k] = fbm(Math.cos(a) * 2.5 + l * 2.4, Math.sin(a) * 2.5 + l * 2.4, 17, 3);+ }+ return (TAB = { n, r, th, ln, nz });+}++// the vortex: three arms of dark dust winding inward, a dithered veil threaded with thin bright filaments that+// stream in along them faster than the arms turn, a lit leading edge, all heating to pale violet near the rim+function vortex(p, C, t, g) {+ const T = tables(), n = T.n, wf = (TAU * 12) / D;+ for (let j = 0; j < n; j++)+ for (let i = 0; i < n; i++) {+ const k = j * n + i, r = T.r[k];+ if (r < GAP || r > VR) continue;+ const env = smooth(VR, VR * 0.42, r) * smooth(GAP, GAP + 4, r);+ const ph = ARMS * T.th[k] + K * T.ln[k] + WIND * t + T.nz[k] * 2.6, cs = Math.cos(ph);+ const A = (0.5 + 0.5 * cs) * env * (1 + 0.4 * g);+ if (A < 0.16) continue;+ const x = i - VR + 0.5, y = Y + j - VR + 0.5, hot = 1 - smooth(GAP, GAP + 16, r);+ const fil = Math.cos(12 * T.th[k] + 28 * T.ln[k] + wf * t + T.nz[k] * 1.6);+ // streams break into dashes that run inward with them+ const dash = Math.cos(9 * T.ln[k] * 2.2 + 2.2 * T.th[k] + wf * 0.75 * t);+ if (fil > 0.86 && A > 0.3 && dash > -0.55) {+ const c = hot > 0.6 ? C[7] : (hot > 0.25 || fil > 0.97) && dash > 0 ? C[6] : C[5];+ p.px(x, y, c);+ p.light(x, y, c, 0.1 + 0.2 * hot);+ continue;+ }+ // the arm's leading edge, where it turns into the light+ if (A > 0.36 && A < 0.46 && Math.sin(ph) > 0) {+ p.px(x, y, hot > 0.4 ? C[6] : C[4]);+ continue;+ }+ // the veil: translucent dark dust, denser in the arm's heart+ p.blend(x, y, A > 0.6 ? C[3] : C[2], Math.min(0.75, (A - 0.16) * 1.4));+ }+}++// what the orb's gravity does to light from behind it+function lensing(p, C, t, g) {+ // the Einstein ring itself, faint, brightening as it gulps+ for (let a = 0, st = 0.7 / E; a < TAU; a += st) {+ const f = 0.5 + 0.5 * Math.cos(5 * a - (TAU * 2 * t) / D) + 0.5 * g;+ p.px(Math.cos(a) * E, Y + Math.sin(a) * E, f > 0.85 ? C[5] : f > 0.45 ? C[4] : C[3]);+ }+ for (const s of SOURCES) {+ const q = (TAU * s.n * t) / D + s.ph, sx = s.cx + s.rho * Math.cos(q), sy = s.cy + s.rho * Math.sin(q) * s.sy;+ const b = Math.max(0.3, Math.hypot(sx, sy)), al = Math.atan2(sy, sx), root = Math.sqrt(b * b + 4 * E * E);+ const images = [[(b + root) / 2, al, 1], [(root - b) / 2, al + Math.PI, 0.55]];+ for (const [r, a0, w] of images) {+ if (r < R + 1.5) continue;+ const mag = (r / b) * w, hw = Math.min(Math.PI, (s.s * 1.6) / (2 * b)), step = 0.6 / r;+ for (let a = a0 - hw; a <= a0 + hw + 1e-6; a += step) {+ const u = hw > 0 ? Math.abs(a - a0) / hw : 0, x = Math.cos(a) * r, y = Y + Math.sin(a) * r;+ p.dot(x, y, u < 0.3 && mag > 0.8 ? WHITE : u < 0.65 ? C[7] : C[5], Math.min(1, mag * 1.4) * (1.15 - u));+ if (mag > 1.2 && u < 0.6) p.dot(x + Math.cos(a), y + Math.sin(a), C[6], 0.8);+ }+ p.glow(Math.cos(a0) * r, Y + Math.sin(a0) * r, 4 + Math.min(10, hw * r), C[6], Math.min(0.5, 0.18 * mag));+ }+ }+}- // 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];+// the orb: void black, a dull glint and a crescent of reflected light inside, and a pale rim crawling round+function orb(p, C, t, g) {+ p.shade(-R - 1, Y - R - 1, R + 1, Y + R + 1, (x, y) => {+ const dx = x, dy = y - Y, d = Math.sqrt(dx * dx + dy * dy);+ if (d > R + 0.5) return;+ const a = Math.atan2(dy, dx);+ if (d > R - 0.6) {+ const f = 0.5 * Math.cos(3 * a - (TAU * 2 * t) / D) + 0.3 * Math.cos(7 * a + (TAU * 3 * t) / D + 1) + 0.25 * Math.cos(13 * a - (TAU * 5 * t) / D + 2) + g;+ return f > 0.5 ? WHITE : f > 0.05 ? C[6] : f > -0.4 ? C[5] : C[4];+ }+ if (R - d < 1.4 && Math.cos(a - 0.8) > 0.6) return C[2];+ if ((dx + R * 0.42) ** 2 + (dy + R * 0.45) ** 2 < 1.6) return C[3];+ return C[0];});+}++export function drawBack(p, t, o) {+ const C = fit(o.palette, 8), g = gulp(t);+ p.glow(0, -1, 52, C[4], 0.22 + 0.1 * g);+ vortex(p, C, t, g);+ lensing(p, C, t, g);+}- // 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);+export function draw(p, t, o) {+ const C = fit(o.palette, 8), g = gulp(t), S = o.seed;+ // dust drawn up off the floor, curving into the orb+ cycle(t, D, 14, S + 2, (r) => r.range(1.6, 2.4), (age, L, r) => {+ const x0 = r.range(-44, 44), u = Math.pow(age / L, 1.7), side = Math.sign(x0) || 1, ea = Math.PI / 2 + side * r.range(0.3, 1);+ const ex = Math.cos(ea) * R, ey = Y + Math.sin(ea) * R, mx = x0 * 0.2, my = -18 - r.range(0, 12);+ const x = (1 - u) * (1 - u) * x0 + 2 * (1 - u) * u * mx + u * u * ex, y = (1 - u) * (1 - u) * -1 + 2 * (1 - u) * u * my + u * u * ey;+ if (age < 0.5) p.disc(x0, -1.5, 2 + age * 6, C[3], 0.4 * (1 - age / 0.5));+ p.dot(x, y, u > 0.6 ? C[7] : u > 0.25 ? C[6] : C[5], Math.min(1, age * 4));+ if (u > 0.3) p.glow(x, y, 3, C[5], 0.25);+ });+ // motes swirl in along the arms, faster as they fall, and spark on the rim where they're swallowed+ cycle(t, D, 30, S, (r) => r.range(1.1, 1.8), (age, L, r) => {+ let th0 = r.range(0, TAU);+ if (Math.sin(th0) > 0.75) th0 = -th0;+ const r0 = r.range(30, 64), sw = r.range(1.4, 2.6), col = r.pick([WHITE, C[7], C[6], C[6], C[5]]);+ const pos = (aa) => {+ const u = clamp(aa / L), k = Math.pow(u, 1.8), rr = R + 1 + (r0 - R - 1) * (1 - k), th = th0 - sw * (k + 0.5 * u);+ return [Math.cos(th) * rr, Y + Math.sin(th) * rr, rr];+ };+ const [x, y, rr] = pos(age), [tx, ty] = pos(age - 0.05), a = Math.min(1, age * 5);+ if (rr < R + 3) {+ p.px(x, y, WHITE);+ p.glow(x, y, 5, C[6], 0.5);+ return;+ }+ p.line(tx, ty, (tx + x) / 2, (ty + y) / 2, C[4], a * 0.8);+ p.line((tx + x) / 2, (ty + y) / 2, x, y, col, a);+ p.glow(x, y, 3, col, 0.3 * a);+ });+ // streaks: long dotted lines shot in from further out, white at the head (never from under the floor)+ cycle(t, D, 9, S + 1, 0.42, (age, L, r) => {+ let th = r.range(0, TAU);+ if (Math.sin(th) > 0.45) th = -th;+ const r0 = r.range(56, 74), u = age / L, k = (Math.exp(3 * u) - 1) / (Math.exp(3) - 1), rr = r0 - (r0 - R - 1) * k;+ const len = 2 + 10 * k, ca = Math.cos(th), sa = Math.sin(th);+ for (let d = 0; d <= len; d += 0.5) p.dot(ca * (rr + d), Y + sa * (rr + d), d < 1 ? WHITE : d < len * 0.5 ? C[6] : C[4], d < len * 0.5 ? 1 : 1.2 - d / len);+ p.glow(ca * rr, Y + sa * rr, 4, C[6], 0.4);+ });+ // a gulp draws a faint ring in after it+ for (const gp of GULPS) {+ const u = wrap(t / D - gp) / (0.4 / D);+ if (u >= 1) continue;+ const rr = R + 2 + (VR - R) * (1 - ease.inQuad(u));+ ringFast(p, 0, Y, rr, 1, C[4], 0.35 * (1 - u));+ ringLight(p, 0, Y, rr, 4, C[5], 0.3 * (1 - u));+ }+ orb(p, C, t, g);+ halo(p, 0, Y, R - 0.5, R + 7, C[6], 0.6 + 0.3 * g);+ halo(p, 0, Y, R - 0.5, R + 46, C[4], 0.38 + 0.15 * g);+ unlight(p, -R, Y - R, R, Y + R, (x, y) => x * x + (y - Y) ** 2 < (R - 0.6) ** 2);}diff --git a/src/fx/spawn/_lib.js b/src/fx/spawn/_lib.jsindex 88a6158..2c26ec1 100644--- a/src/fx/spawn/_lib.js+++ b/src/fx/spawn/_lib.js@@ -1,96 +1,34 @@-// 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.+// Shared by the spawn and death effects: the actor's own body as a list of pixels to break up, burn, freeze or+// copy, and the cells just outside it for outlines. 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;+import { hex } from "../../core/index.js";/**- * 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).+ * The actor's body: { list: [{ x, y, mx, my, c, edge }], w, h, x, y, on(mx, my), cell(mx, my) }, local space+ * with the feet at (0, 0). c is the character's own color (o.actor.pixels); an actor without pixels is shaded+ * from the ramp C (lit at the top, darker toward the feet). edge marks pixels on the silhouette's rim.*/-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 = [];+export function bodyOf(actor, C) {+ const m = actor.mask, px = actor.pixels, list = [], cells = new Array(m.w * m.h).fill(null);+ const on = (mx, my) => mx >= 0 && my >= 0 && mx < m.w && my < m.h && !!m.data[my * m.w + mx];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];+ for (let mx = 0; mx < m.w; mx++) {+ if (!on(mx, my)) continue;+ const own = px?.[my * m.w + mx];+ const c = own ? hex(own) : C[Math.max(1, Math.min(C.length - 2, Math.round((C.length - 2) * (0.85 - (my / m.h) * 0.5))))];+ const b = { x: actor.x + mx, y: actor.y + my, mx, my, c, edge: !on(mx - 1, my) || !on(mx + 1, my) || !on(mx, my - 1) || !on(mx, my + 1) };+ list.push(b);+ cells[my * m.w + mx] = b;}- out.a = a;- return ink[b];- });+ return { list, w: m.w, h: m.h, x: actor.x, y: actor.y, on, cell: (mx, my) => (on(mx, my) ? cells[my * m.w + mx] : null) };}-/** 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;- });+/** Cells just outside the body (4-neighbours of its rim), local space: [{ x, y, mx, my }]. */+export function rimOf(body) {+ const out = [];+ for (let my = -1; my <= body.h; my++)+ for (let mx = -1; mx <= body.w; mx++)+ if (!body.on(mx, my) && (body.on(mx - 1, my) || body.on(mx + 1, my) || body.on(mx, my - 1) || body.on(mx, my + 1)))+ out.push({ x: body.x + mx, y: body.y + my, mx, my });+ return out;}diff --git a/src/fx/spawn/coin-drop.js b/src/fx/spawn/coin-drop.jsindex 1258955..82bdaf0 100644--- a/src/fx/spawn/coin-drop.js+++ b/src/fx/spawn/coin-drop.js@@ -1,67 +1,167 @@-import { PAL, ramp, at, burst, seg, ease, TAU, WHITE } from "../../core/index.js";-import { cloud } from "./_lib.js";+// The coin's spin (squashed toward its edge), glints and burst of light, and the soft smoke of the poof, follow+// Sprite Fusion's open-source pickup (https://www.spritefusion.com/pixel-art-vfx/pickup), MIT License,+// Copyright (c) 2026 Hugo Duprez.+import { Particles, Lights, P, Rng, fit, flare, sparkle, clamp, smooth, ease, TAU, WHITE, hex } from "../../core/index.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,+ desc: "An enemy goes up in a soft poof and gold coins spin out of it, bounce with a glint on each hit, settle on the floor, twinkle, and wink out one by one.",+ tags: ["spawn", "death", "loot", "coins", "gold", "drop", "pickup", "ground", "one-shot"],+ size: [160, 88],+ origin: [80, 78],+ duration: 3,loop: false,fps: 30,bg: "ground",- options: { palette: PAL.gold, count: 7, seed: 24 },+ options: {+ palette: ["#2a1606", "#5c3208", "#9a5a0c", "#d48c14", "#f5b82a", "#ffe066", "#fff6c4", "#ffffff"],+ smoke: ["#3a3450", "#6c6688", "#a8a2c0", "#dcd8ea"],+ coins: 7,+ seed: 23,+ },};-// 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;+const CY = -16;+// an original coin: a rim, a lit face, a raised mark in the middle+const COIN = ["..oooo..", ".ohhlmo.", "ohlmmmdo", "ohmdhmdo", "olmdhmdo", "olmmmmdo", ".oddddo.", "..oooo.."];+// lying flat on the floor, seen from the side+const FLAT = [".lhhhl.", "olmmmdo", ".odddo."];-/** 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;+export function create(o) {+ const C = fit(o.palette, 8), SM = fit(o.smoke, 4), R = new Rng(o.seed), floor = () => 0;+ const PAL = { o: C[1], h: C[6], l: C[5], m: C[4], d: C[3] };+ const ps = new Particles({ rng: R, ground: floor, sparks: [WHITE, C[6], C[5], C[3]] }), lights = new Lights();+ const coins = [], balls = [];+ // the poof the enemy goes up in+ for (let i = 0; i < 10; i++) {+ const a = (i / 10) * TAU + R.range(-0.25, 0.25), sp = R.range(60, 100);+ const life = R.range(0.55, 0.85);+ balls.push({ x: Math.cos(a) * 2, y: CY + Math.sin(a) * 2, vx: Math.cos(a) * sp, vy: Math.sin(a) * sp * 0.7 - 10, r: R.range(4, 6), life, max: life });}- return [x + bx * Math.min(tt, 0.08), FLOOR, 4];-}+ // the coins: thrown up and out, each spinning at its own rate+ const n = o.coins;+ for (let i = 0; i < n; i++) {+ const u = n > 1 ? i / (n - 1) - 0.5 : 0, a = -Math.PI / 2 + u * 1.6 + R.range(-0.1, 0.1), sp = R.range(230, 300);+ coins.push({ x: R.range(-3, 3), y: CY, vx: Math.cos(a) * sp * 0.4, vy: Math.sin(a) * sp, ph: R.range(0, TAU), w: R.range(9, 15) * R.sign(), rest: false, hits: 0, out: 2.15 + i * 0.07 + R.range(0, 0.1), glint: R.range(1.2, 1.9), born: R.range(0.04, 0.12) });+ }+ for (let i = 0; i < 8; i++) {+ const a = R.range(0, TAU), sp = R.range(50, 120);+ ps.spawn(P.STAR, 0, CY, Math.cos(a) * sp, Math.sin(a) * sp - 20, R.range(0.3, 0.6), R.pick([WHITE, C[6], C[5]]), R.range(0.8, 1.8));+ }+ lights.add(0, CY, 44, C[4], 0.7, 0.4);+ lights.add(0, CY, 20, WHITE, 0.7, 0.1);+ let t = 0;-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);+ // a coin turning in the air: its face squashed toward the edge, the rim showing when it's side-on+ function drawCoin(p, x, y, ph) {+ const c = Math.cos(ph), sx = Math.abs(c);+ if (sx < 0.28) {+ for (let dy = -3; dy <= 3; dy++) p.px(x, y + dy, Math.abs(dy) === 3 ? C[1] : dy < 0 ? C[6] : C[5]);+ if (sx > 0.12) for (let dy = -2; dy <= 2; dy++) p.px(x + (c > 0 ? 1 : -1), y + dy, C[3]);+ return;}- 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 });-}+ const half = 4 * sx;+ for (let px = Math.floor(x - half); px < Math.ceil(x + half); px++) {+ let col = Math.floor((px + 0.5 - x) / sx + 4);+ if (col < 0 || col > 7) continue;+ if (c < 0) col = 7 - col;+ for (let row = 0; row < 8; row++) {+ const ch = COIN[row][col];+ if (ch !== ".") p.px(px, Math.round(y - 4 + row), PAL[ch]);+ }+ }+ }+ return {+ update(dt) {+ t += dt;+ for (let i = balls.length - 1; i >= 0; i--) {+ const b = balls[i];+ if ((b.life -= dt) <= 0) {+ balls.splice(i, 1);+ continue;+ }+ b.vx -= b.vx * 7 * dt;+ b.vy -= b.vy * 7 * dt + 26 * dt;+ b.x += b.vx * dt;+ b.y += b.vy * dt;+ }+ for (const c of coins) {+ // a coin winks out with a little burst of gold+ if (!c.gone && t >= c.out) {+ c.gone = true;+ for (let j = 0; j < 5; j++) {+ const a = R.range(-Math.PI, 0), sp = R.range(25, 60);+ ps.spawn(P.STAR, c.x, -3, Math.cos(a) * sp, Math.sin(a) * sp, R.range(0.3, 0.55), R.pick([WHITE, C[6], C[5]]), R.range(0.7, 1.4));+ }+ lights.add(c.x, -3, 14, C[5], 0.6, 0.2);+ }+ if (t < c.born || t > c.out || c.rest) continue;+ c.vy += 820 * dt;+ c.vx -= c.vx * 0.4 * dt;+ c.x += c.vx * dt;+ c.y += c.vy * dt;+ c.ph += c.w * dt;+ if (c.y >= -1.5 && c.vy > 0) {+ c.y = -1.5;+ c.hits++;+ // a tink of light and a puff of dust at each hit+ ps.spawn(P.STAR, c.x, -3, 0, -8, 0.25, WHITE, c.hits === 1 ? 2.2 : 1.4);+ for (let j = 0; j < 2; j++) ps.spawn(P.DUST, c.x + R.range(-1, 1), -0.5, R.sign() * R.range(8, 24), -R.range(2, 8), R.range(0.25, 0.45), SM[1], R.range(1, 1.8));+ lights.add(c.x, -3, 12, C[5], 0.5, 0.15);+ if (c.vy > 110) (c.vy *= -0.45), (c.vx *= 0.7), (c.w = c.w * 0.8 + R.range(-2, 2));+ else (c.rest = true), (c.vx = c.vy = 0), (c.restAt = t);+ }+ }+ ps.update(dt);+ lights.update(dt);+ },+ drawBack(p) {+ // a warm gleam on the floor where the coins lie+ for (const c of coins)+ if (c.rest && t < c.out) p.glow(c.x, -1, 7, C[4], 0.18);+ ps.draw(p, "back");+ },+ draw(p) {+ // the poof: soft, top-lit balls, a pop of light in the middle+ for (const layer of [0, 1, 2])+ for (const b of balls) {+ const age = b.max - b.life, k = b.life / b.max, r = b.r * (0.6 + 0.6 * ease.outCubic(clamp(age / 0.2))) * (k < 0.35 ? k / 0.35 : 1);+ if (r < 0.6) continue;+ if (layer === 0) p.disc(b.x + r * 0.15, b.y + r * 0.2, r, SM[1], 0.8);+ else if (layer === 1) p.disc(b.x - r * 0.06, b.y - r * 0.08, r * 0.86, b.y > CY + 2 ? SM[1] : SM[2], 0.85);+ else if (b.y < CY + 2) p.disc(b.x - r * 0.28, b.y - r * 0.34, r * 0.4, SM[3], 0.85);+ }+ if (t < 0.07) {+ const k = t / 0.07;+ p.circle(0, CY, 8 + 2 * k, C[6]);+ p.circle(0, CY, 6 + 2 * k, WHITE);+ flare(p, 0, CY, 16 * (1 - k * 0.5), 1 - k, C);+ }+ for (const c of coins) {+ if (t < c.born || t > c.out + 0.12) continue;+ if (t > c.out) {+ // a coin winks out with a last flash and a ring+ const k = (t - c.out) / 0.12;+ sparkle(p, c.x, -2, Math.round(5 * (1 - k)), WHITE, C[5], 0.5);+ p.ring(c.x, -3, 2 + 5 * ease.outCubic(k), 1, C[6], 1.1 - k);+ continue;+ }+ if (c.rest) {+ // flat on the floor; now and then a glint runs over it+ p.sprite(FLAT, PAL, Math.round(c.x) - 3, -3);+ p.glow(c.x, -2, 6, C[5], 0.25);+ const g = ((t - c.restAt + c.glint) % 0.95) / 0.95;+ if (g < 0.2) sparkle(p, c.x - 1, -3, Math.round(3 * Math.sin((g / 0.2) * Math.PI)), WHITE, C[5], 0.4);+ } else {+ drawCoin(p, c.x, c.y, c.ph);+ p.glow(c.x, c.y, 8, C[4], 0.3);+ // a glint catches the face as it turns toward us+ if (Math.abs(Math.cos(c.ph)) > 0.96) p.px(c.x - 1, c.y - 2, WHITE);+ }+ }+ ps.draw(p, "front");+ lights.draw(p);+ },+ };+}diff --git a/src/fx/spawn/disintegrate.js b/src/fx/spawn/disintegrate.jsindex 861ce3c..15b7216 100644--- a/src/fx/spawn/disintegrate.js+++ b/src/fx/spawn/disintegrate.js@@ -1,48 +1,194 @@-import { PAL, ramp, at, rng, noise, TAU, WHITE } from "../../core/index.js";-import { actorOf, actorPixels } from "./_lib.js";+// The flickering outline, the white silhouette flash and the body's own pixels flying off as bits of light are+// adapted from Sprite Fusion's open-source movement (https://www.spritefusion.com/pixel-art-vfx/movement),+// MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Lights, P, Rng, fit, band, sparkle, clamp, smooth, ease, rand, noise, noise2, TAU, WHITE, mix, scale } from "../../core/index.js";+import { bodyOf, rimOf } 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,+ desc: "The character crackles with light, flashes white, then peels away from the head down: each pixel flares white-hot and streams off on the wind as a cooling mote of light.",+ tags: ["spawn", "death", "disintegrate", "dissolve", "pixels", "energy", "light", "one-shot"],+ size: [176, 100],+ origin: [48, 86],+ duration: 3.4,loop: false,fps: 30,bg: "ground",- actor: false,- options: { palette: PAL.cyber, seed: 26 },+ actor: 2,+ options: {+ palette: ["#120a26", "#2a1658", "#3d2f9c", "#3f68d4", "#3fa8ec", "#86e0ff", "#d6f8ff", "#ffffff"],+ accent: ["#7a3ae4", "#b682ff", "#ecd2ff"],+ wind: 1,+ seed: 5,+ },};-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 FLASH = 0.42, WHITE_T = 0.07, P0 = FLASH + WHITE_T, PEEL = 1.2, CORE_Y = -20;+export const actorAlpha = (t) => (t < FLASH - 0.1 ? 1 : 0);++export function create(o) {+ const C = fit(o.palette, 8), A = fit(o.accent, 3), R = new Rng(o.seed), W = o.wind, floor = () => 0;+ // what a mote cools through after its white flare: the main ramp, or the accent for variety+ const COOL = [[C[6], C[5], C[5], C[4]], [A[2], A[1], A[1], A[0]], [WHITE, C[6], C[5], C[5]]];+ const body = bodyOf(o.actor, C), rim = rimOf(body), top = body.y, H = body.h;+ const ps = new Particles({ rng: R, ground: floor, sparks: [C[7], C[6], C[5], C[3]] }), lights = new Lights();+ // when each pixel lets go: row by row from the crown, a ragged front, the rim a beat before the middle+ for (const b of body.list) {+ const u = (b.y - top) / H;+ b.key = u + 0.14 * (rand(b.mx, b.my, 3) - 0.5) + 0.05 * noise(b.mx * 0.45, 7) - (b.edge ? 0.03 : 0);+ b.gone = false;+ }+ const front = (t) => -0.06 + 1.14 * ease.inOutSine(clamp((t - P0) / PEEL));+ const motes = [];+ // the wind: a steady push with gusts, and a slow swirl so neighbouring motes travel in sheets+ const gust = (t) => 0.7 + 0.5 * (noise(t * 1.6, 11) * 0.5 + 0.5);+ let t = 0, flashed = false;++ function letGo(b) {+ b.gone = true;+ const lo = b.y > -9 && R.chance(0.22), kind = lo ? 2 : R.chance(0.42) ? 1 : R.chance(0.07) ? 3 : 0;+ if (kind === 3) {+ ps.spawn(P.STAR, b.x, b.y, R.range(-6, 14) * W, R.range(-26, -8), R.range(0.6, 1.1), R.chance(0.5) ? C[6] : WHITE, R.range(1, 2.2));+ return;}- 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));+ const life = kind === 2 ? R.range(0.7, 1.2) : kind === 1 ? R.range(0.25, 0.5) : R.range(0.9, 1.7);+ // a pop off the body, outward from its middle and up, before the wind takes it+ const out = (b.x + 0.5) * R.range(2, 6);+ motes.push({+ x: b.x + 0.5, y: b.y + 0.5, vx: (out + R.range(-6, 16)) * (kind === 2 ? 0.4 : 1), vy: kind === 2 ? R.range(-30, -8) : R.range(-46, -8),+ life, max: life, c: b.c, kind, lift: R.range(0.4, 1.4), cool: COOL[R.chance(0.3) ? 1 : R.chance(0.3) ? 2 : 0], own: R.chance(0.2), rest: false, seed: R.range(0, 100),+ });}- 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);++ return {+ update(dt) {+ t += dt;+ // the charge: light gathers into the body in streaks+ if (t < FLASH - 0.05 && R.chance(0.55)) {+ const a = R.range(0, TAU), D = R.range(22, 44), T = R.range(0.16, 0.26), v = (D * 3) / (Math.exp(3 * T) - 1);+ const x = Math.cos(a) * D, y = Math.min(CORE_Y + Math.sin(a) * D * 0.9, -3), l = Math.hypot(x, y - CORE_Y) || 1;+ ps.spawn(P.STREAK, x, y, (-x / l) * v, ((CORE_Y - y) / l) * v, T, R.chance(0.5) ? C[6] : C[5]);+ }+ if (!flashed && t >= FLASH) {+ flashed = true;+ lights.add(0, CORE_Y, 64, C[4], 0.85, 0.6);+ lights.add(0, CORE_Y, 30, WHITE, 0.8, 0.14);+ for (let i = 0; i < 14; i++) {+ const a = R.range(0, TAU), sp = R.range(50, 150);+ ps.spawn(P.STAR, R.range(-6, 6), CORE_Y + R.range(-10, 10), Math.cos(a) * sp, Math.sin(a) * sp * 0.7 - 25, R.range(0.35, 0.8), R.pick([WHITE, C[6], C[5]]), R.range(0.6, 1.8));+ }+ }+ // the peel front eats the body+ if (t >= P0) {+ const f = front(t);+ for (const b of body.list) if (!b.gone && b.key < f) letGo(b);+ }+ // the wind drops once the body is gone, and the last motes hang in the air+ const g = gust(t) * (1 - 0.55 * smooth(P0 + PEEL, P0 + PEEL + 1.2, t));+ for (let i = motes.length - 1; i >= 0; i--) {+ const m = motes[i];+ if ((m.life -= dt) <= 0) {+ motes.splice(i, 1);+ continue;+ }+ if (m.kind === 2) {+ // heavier ash: drifts a little, falls, settles on the floor and glows out+ if (m.rest) continue;+ m.vx += (W * 30 * g - m.vx * 1.2) * dt;+ m.vy += 260 * dt - m.vy * 1.2 * dt;+ m.x += m.vx * dt;+ const ny = m.y + m.vy * dt;+ if (m.vy > 0 && ny >= -0.5) {+ if (m.vy > 50) (m.vy *= -0.35), (m.vx *= 0.6), (m.y = -0.6);+ else (m.rest = true), (m.y = -0.5);+ } else m.y = ny;+ continue;+ }+ const age = m.max - m.life, k = Math.min(1, age / 0.15);+ const fx = W * (100 * g + 30 * noise2(m.x * 0.07, m.y * 0.07 - t * 0.8, 3)) * k;+ const fy = (-30 * m.lift + 42 * noise2(m.x * 0.06 + 40, m.y * 0.06 - t * 1.1, 5)) * k;+ const drag = m.kind === 1 ? 3 : 1.5;+ m.vx += (fx - m.vx * drag) * dt;+ m.vy += (fy - m.vy * drag) * dt;+ m.x += m.vx * dt;+ m.y += m.vy * dt;+ }+ ps.update(dt);+ lights.update(dt);+ },+ drawBack(p) {+ // the floor ring from the flash, far half+ const k = (t - FLASH) / 0.5;+ if (k > 0 && k < 1) band(p, 0, 0, 6 + 30 * ease.outCubic(k), 0.18, Math.max(1, 3.5 * (1 - k)), 1.15 - k, C, (g) => Math.sin(g) < 0, k < 0.12);+ // a cold pool on the floor while the body burns away+ const pool = smooth(0.1, FLASH, t) * (1 - smooth(P0 + PEEL * 0.8, P0 + PEEL + 0.6, t));+ if (pool > 0) p.glow(0, -1, 30, C[4], 0.22 * pool);+ },+ draw(p) {+ const f = front(t);+ // charge: a crackling outline that thickens, the rim of the body catching light+ if (t < FLASH) {+ const k = t / FLASH, fr = Math.floor(t * 30);+ for (const c of rim) {+ const h = rand(c.mx * 61 + c.my, fr, 7);+ if (h < 0.12 + 0.62 * k * k) p.px(c.x, c.y, k > 0.72 && rand(c.mx, c.my, fr) < 0.5 ? WHITE : h < 0.2 ? C[6] : C[5]);+ }+ p.glow(0, CORE_Y, 26, C[4], 0.42 * k);+ p.glow(0, CORE_Y, 12, C[6], 0.25 * k * k);+ }+ // the body: drawn by us from the shudder on, flashing white, then charged, glowing hot at the front+ if (t >= FLASH - 0.1) {+ const shake = t < FLASH ? (Math.floor(t * 60) % 2 ? 1 : -1) * 0.6 : 0, white = t >= FLASH && t < P0;+ for (const b of body.list) {+ if (b.gone) continue;+ let c;+ if (white) c = b.edge ? C[6] : WHITE;+ else if (t < FLASH) c = b.edge ? mix(b.c, C[6], 0.7) : mix(b.c, C[5], 0.25);+ else {+ const d = b.key - f, above = !body.on(b.mx, b.my - 1) || body.cell(b.mx, b.my - 1).gone;+ c = above && d < 0.06 ? WHITE : d < 0.03 ? mix(b.c, C[6], 0.7) : d < 0.1 ? mix(b.c, C[5], 0.4) : b.edge ? mix(b.c, C[5], 0.5) : mix(b.c, C[4], 0.16);+ }+ p.px(b.x + shake, b.y, c);+ }+ if (white) {+ p.glow(0, CORE_Y, 34, C[5], 0.7);+ sparkle(p, 0, CORE_Y - 3, 9, C[6], C[4], 0.5);+ }+ }+ // light rides the peel front down the body+ if (t >= P0 && f < 1.05) {+ const fy = top + clamp(f) * H, k = 1 - smooth(0.85, 1.05, f);+ p.glowLine(-10, fy, 10, fy, 8, C[5], 0.32 * k);+ p.glow(0, fy, 22, C[4], 0.2 * k);+ }+ // the floor ring, near half+ const k = (t - FLASH) / 0.5;+ if (k > 0 && k < 1) band(p, 0, 0, 6 + 30 * ease.outCubic(k), 0.18, Math.max(1, 3.5 * (1 - k)), 1.15 - k, C, (g) => Math.sin(g) >= 0, k < 0.12);+ // the motes: flare white, cool down the ramp, leave a short tail, dither out+ for (const m of motes) {+ const age = m.max - m.life, k2 = m.life / m.max, a = k2 < 0.35 ? k2 / 0.35 : 1;+ let c;+ if (age < 0.034) c = mix(m.c, WHITE, 0.55);+ else if (age < 0.06) c = WHITE;+ else if (age < 0.15) c = m.cool[0];+ else {+ const u = (age - 0.15) / Math.max(0.05, m.max - 0.15), cc = m.cool[1 + Math.min(2, Math.floor(u * 3))];+ c = m.own && u < 0.5 ? mix(m.c, cc, 0.55) : cc;+ if (m.kind === 0 && Math.sin(t * 21 + m.seed) > 0.8) c = m.cool[0];+ }+ if (m.kind === 2) {+ p.dot(m.x, m.y, c, a);+ p.glow(m.x, m.y, 3, C[5], 0.3 * k2);+ continue;+ }+ const sp = Math.hypot(m.vx, m.vy), ux = m.vx / (sp || 1), uy = m.vy / (sp || 1);+ if (sp > 30 && m.kind === 0) p.dot(m.x - ux * 1.2, m.y - uy * 1.2, scale(c, 0.6), a * 0.85);+ if (sp > 85 && m.kind === 0) p.dot(m.x - ux * 2.4, m.y - uy * 2.4, scale(c, 0.4), a * 0.6);+ p.dot(m.x, m.y, c, a);+ if (k2 > 0.15) p.glow(m.x, m.y, 2.5, c, (m.kind === 1 ? 0.16 : 0.11) * k2);+ }+ ps.draw(p);+ lights.draw(p);+ },+ };}diff --git a/src/fx/spawn/dissolve-burn.js b/src/fx/spawn/dissolve-burn.jsindex 72cafef..c65882b 100644--- a/src/fx/spawn/dissolve-burn.js+++ b/src/fx/spawn/dissolve-burn.js@@ -1,58 +1,127 @@-import { PAL, ramp, at, rand, stream, seg, noise, scale, TAU, WHITE } from "../../core/index.js";-import { actorOf, actorPixels, steps } from "./_lib.js";+// The flames that cool into smoke, the embers and the smouldering glow are adapted from Sprite Fusion's+// open-source fire (https://www.spritefusion.com/pixel-art-vfx/fire), MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Lights, P, PF, Rng, fit, clamp, smooth, ease, rand, noise, WHITE, hex, mix } from "../../core/index.js";+import { bodyOf } 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,+ desc: "An ember seam lights at the feet and climbs the body: above it the body scorches and smoulders, at it flames lick up, below it there's only falling ash, embers and smoke.",+ tags: ["spawn", "death", "burn", "fire", "ash", "dissolve", "embers", "one-shot"],+ size: [96, 112],+ origin: [48, 100],+ duration: 3.6,loop: false,fps: 30,bg: "ground",- actor: false,- options: { palette: PAL.fire, seed: 28 },+ actor: 2,+ options: {+ palette: ["#2a0e08", "#5a1a0c", "#a8320f", "#e8601a", "#ff9a2e", "#ffd25a", "#fff3c0", "#ffffff"],+ ash: ["#2a2428", "#4a4248", "#6e6670"],+ seed: 16,+ },};-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);+const IGNITE = 0.15, BURN = 1.9, CHAR = [hex("#100908"), hex("#22130e"), hex("#3a2016")];+export const actorAlpha = () => 0;++export function create(o) {+ const C = fit(o.palette, 8), A = fit(o.ash, 3), R = new Rng(o.seed), floor = () => 0;+ const body = bodyOf(o.actor, C), H = body.h, cx = 0;+ // when each pixel catches: row by row from the feet, a ragged, licking front; the rim a beat early+ for (const b of body.list) {+ b.key = (body.h - 1 - b.my) / H + 0.08 * (rand(b.mx, b.my, 3) - 0.5) + 0.06 * noise(b.mx * 0.35, 4) - (b.edge ? 0.02 : 0);+ b.gone = false;}- // 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));+ const front = (t) => -0.04 + 1.1 * ease.inOutSine(clamp((t - IGNITE) / BURN));+ const ps = new Particles({ rng: R, ground: floor, sparks: [C[6], C[5], C[4], C[3]] }), lights = new Lights();+ let t = 0;+ // a life that ends before the effect does+ const left = (a, b) => Math.max(0.05, Math.min(R.range(a, b), meta.duration - 0.1 - t));+ // tongues of flame along the seam, licking up the body still standing: layered, flickering, swaying+ const tongues = Array.from({ length: 6 }, (_, i) => ({ x: -9 + i * 3.6 + rand(i, 1) * 1.5, h: 6 + rand(i, 2) * 6, s: i * 13 }));+ function tongue(p, x, y, h, n) {+ for (const [lw, lh, c] of [[1, 1, C[3]], [0.7, 0.8, C[4]], [0.45, 0.6, C[5]], [0.25, 0.35, C[6]]]) {+ const Hh = h * lh;+ for (let r = 0; r <= Hh; r++) {+ const u = r / Math.max(1, Hh), half = 1.8 * lw * Math.pow(1 - u, 0.9) + noise(t * 9 + r * 0.5, n) * 0.4;+ const cxr = x + noise(t * 4 + r * 0.25, n + 7) * u * 1.6;+ if (half < 0.3) continue;+ for (let px = Math.round(cxr - half); px <= Math.round(cxr + half); px++) p.px(px, Math.round(y - r), c);+ }}- // 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);}++ return {+ update(dt) {+ t += dt;+ const f = front(t);+ for (const b of body.list) {+ if (b.gone || b.key >= f) continue;+ b.gone = true;+ // a burnt pixel goes to ash that sifts down, an ember that rises, or a lick of flame+ const r = R.next();+ if (r < 0.2) {+ // ash: low down it drops and settles, higher up it sifts down slowly (and is gone before the floor)+ if (b.y > -7) ps.spawn(P.GRIT, b.x, b.y, R.range(-12, 12), R.range(-20, 0), left(0.6, 1.2), R.pick(A), 1);+ else ps.spawn(P.FLAKE, b.x, b.y, R.range(-10, 10), R.range(-8, 4), left(0.5, Math.min(1.5, -b.y / 18)), R.pick(A), R.chance(0.2) ? 1.4 : 1);+ } else if (r < 0.32) ps.spawn(P.EMBER, b.x, b.y, R.range(-12, 12), -R.range(15, 45), left(0.6, 1.4), C[5], R.range(1, 1.6));+ else if (r < 0.46) ps.spawn(P.FIRE, b.x, b.y, R.range(-6, 6), -R.range(14, 30), R.range(0.2, 0.42), 0, R.range(1.2, 2.2), 0, R.chance(0.5) ? PF.SMOKES : 0);+ else if (r < 0.5) ps.spawn(P.SMOKE, b.x, b.y - 2, R.range(-5, 5), -R.range(14, 26), left(1.2, 2), mix(A[1], C[1], 0.3), R.range(2, 3.4));+ }+ // the feet catch with a spit of sparks and a puff of light+ if (t >= IGNITE && t - dt < IGNITE) {+ lights.add(0, -4, 34, C[4], 0.8, 0.4);+ for (let i = 0; i < 10; i++) ps.spawn(P.SPARK, R.range(-8, 8), -1, R.range(-80, 80), -R.range(40, 150), R.range(0.2, 0.5));+ }+ // while it burns: steady embers and smoke off the front+ if (f > 0 && f < 1.02) {+ const fy = body.y + (1 - clamp(f)) * H;+ if (R.chance(0.34)) ps.spawn(P.SMOKE, R.range(-7, 7), fy - 5, R.range(-6, 6), -R.range(16, 30), left(1.4, 2.4), mix(A[1], C[3], 0.35), R.range(2.6, 4.2));+ if (R.chance(0.5)) ps.spawn(P.FIRE, R.range(-9, 9), fy, R.range(-6, 6), -R.range(18, 34), R.range(0.18, 0.36), 0, R.range(1.2, 2.4), 0, R.chance(0.35) ? PF.SMOKES : 0);+ if (R.chance(0.15)) ps.spawn(P.EMBER, R.range(-9, 9), fy, R.range(-15, 15), -R.range(30, 70), left(0.8, 1.6), C[5], 1.4);+ }+ ps.update(dt);+ lights.update(dt);+ },+ drawBack(p) {+ // warm light on the floor while the body burns down to it+ const k = smooth(0, IGNITE + 0.2, t) * (1 - smooth(IGNITE + BURN * 0.6, IGNITE + BURN + 0.4, t));+ if (k > 0) p.glow(0, -1, 30, C[4], 0.3 * k);+ ps.draw(p, "back");+ },+ draw(p) {+ const f = front(t), fr = Math.floor(t * 30);+ for (const b of body.list) {+ if (b.gone) continue;+ const d = b.key - f;+ let c;+ // the seam: white-hot at the very edge, flickering through yellow and orange+ if (d < 0.025) c = rand(b.mx, b.my, fr) < 0.35 ? WHITE : C[6];+ else if (d < 0.05) c = rand(b.mx, b.my, fr + 7) < 0.5 ? C[5] : C[4];+ // just above it the body is charred, with live sparks in the char+ else if (d < 0.11) c = rand(b.mx, b.my, 13) < 0.15 && rand(b.mx, fr, 2) < 0.6 ? C[3] : CHAR[d < 0.075 ? 0 : 1];+ else if (d < 0.16) c = mix(b.c, CHAR[2], 0.6);+ // above that the heat browns it+ else if (d < 0.26) c = mix(b.c, C[2], 0.18);+ else c = b.c;+ p.px(b.x, b.y, c);+ }+ // light along the seam, and flames licking up from it while there's body left to burn+ if (f > -0.02 && f < 1.05) {+ const fy = body.y + (1 - clamp(f)) * H, k = 1 - smooth(0.95, 1.05, f);+ for (const g of tongues) {+ const row = Math.round(fy - body.y), mx = Math.round(g.x - body.x);+ if (!body.on(mx, Math.min(H - 1, Math.max(0, row)))) continue;+ const h = g.h * k * (0.6 + 0.6 * (noise(t * 2.6 + g.s, g.s) * 0.5 + 0.5)) * smooth(-0.02, 0.06, f);+ if (h >= 1) tongue(p, g.x, fy + 1, h, g.s);+ }+ const fl = 0.85 + 0.15 * noise(t * 11, 9);+ p.glowLine(-11, fy, 11, fy, 9, C[4], 0.45 * k);+ p.glow(0, fy - 6, 56, C[4], 0.38 * k * fl);+ p.glow(0, fy - 2, 18, C[5], 0.28 * k * fl);+ }+ ps.draw(p, "front");+ lights.draw(p);+ },+ };}diff --git a/src/fx/spawn/egg-hatch.js b/src/fx/spawn/egg-hatch.jsindex 168b254..960bba8 100644--- a/src/fx/spawn/egg-hatch.js+++ b/src/fx/spawn/egg-hatch.js@@ -1,93 +1,302 @@-import { ramp, burst, fly, seg, ease, TAU, WHITE } from "../../core/index.js";-import { rotSprite, cloud, steps } from "./_lib.js";+// The cracks that open in stages and the burst into tumbling pieces follow Sprite Fusion's open-source ice+// shatter (https://www.spritefusion.com/pixel-art-vfx/ice), MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Bits, Lights, P, B, Rng, fit, sparkle, clamp, smooth, ease, rand, TAU, WHITE, hex, mix } from "../../core/index.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,+ desc: "A speckled egg rocks three times, each rock cracking it further with warm light leaking out, then pops: light pours out of the opening and lit shell halves tumble away.",+ tags: ["spawn", "egg", "hatch", "birth", "crack", "shell", "light", "ground", "one-shot"],+ size: [120, 96],+ origin: [60, 84],+ duration: 3.1,loop: false,fps: 30,bg: "ground",- options: { palette: ["#3a2a1c", "#6e5438", "#a88a62", "#dcc8a0", "#f6ecd2", "#fffaf0"], spots: "#7a9a4a", seed: 25 },+ options: {+ palette: ["#1e1826", "#4a3e52", "#857684", "#c4b4ac", "#ece0d2", "#fffaf0"],+ glow: ["#ff8a2a", "#ffd25a", "#fff3c0"],+ speckle: "#9a6a52",+ seed: 31,+ },};-// 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 WOBBLES = [[0.3, 0.11], [0.85, 0.19], [1.4, 0.28]], POP = 1.98, EW = 16, EH = 20, ZY = 11;+const LIGHT = [-0.72, 0.5, 0.48]; // from the upper left, a little toward us-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);+// the egg in its own pixels: x across from its middle, y up from its base; wider low than high+const EGG = [];+for (let y = 0; y < EH; y++)+ for (let x = -EW / 2; x < EW / 2; x++) {+ const v = (y + 0.5) / EH, u = (x + 0.5) / (EW / 2), half = Math.sqrt(Math.max(0, 1 - (2 * v - 1) ** 2)) * (1.08 - 0.22 * v);+ if (Math.abs(u) <= half) EGG.push({ x, y, u, v, half });+ }-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++;+export function create(o) {+ const C = fit(o.palette, 6), G = fit(o.glow, 3), SPK = hex(o.speckle), R = new Rng(o.seed), floor = () => 0;+ const at = new Map();+ for (const e of EGG) at.set(`${e.x},${e.y}`, e);+ const has = (x, y) => at.has(`${x},${y}`);+ // shading: a round shell lit from the upper left, a core shadow, a rim of bounce light on the dark side+ for (const e of EGG) {+ const nx = clamp(e.u / Math.max(0.05, e.half), -1, 1), ny = (2 * e.v - 1) * 0.9, nz = Math.sqrt(Math.max(0, 1 - nx * nx - ny * ny));+ const d = nx * LIGHT[0] + ny * LIGHT[1] + nz * LIGHT[2], edge = !has(e.x - 1, e.y) || !has(e.x + 1, e.y) || !has(e.x, e.y - 1) || !has(e.x, e.y + 1);+ let c = d > 0.9 ? WHITE : d > 0.62 ? C[5] : d > 0.32 ? C[4] : d > 0.02 ? C[3] : d > -0.3 ? C[2] : C[1];+ if (edge && nx > 0.25 && ny < 0.55) c = C[3]; // rim light on the shadow side+ else if (rand(e.x, e.y, 3) < 0.08 && e.v > 0.12 && !edge) c = d > 0.2 ? SPK : mix(SPK, C[1], 0.5);+ e.c = c;+ e.lit = d;+ }+ // cracks: three stages, the last a zigzag right round the egg where the top breaks off+ const crack = new Map();+ // a crack: a jagged line, zigging either side of its heading, every step joined pixel to pixel+ const walk = (x, y, a, len, s) => {+ let px = Math.round(x), py = Math.round(y);+ for (let i = 0; i < len; i++) {+ const side = (i % 2 ? 1 : -1) * R.range(0.6, 1.3);+ a += R.range(-0.25, 0.25);+ x += Math.cos(a) * 1.8 - Math.sin(a) * side * 0.6;+ y += Math.sin(a) * 1.8 + Math.cos(a) * side * 0.6;+ const nx = Math.round(x), ny = Math.round(y);+ for (let j = 1, n = Math.max(Math.abs(nx - px), Math.abs(ny - py)); j <= n; j++) {+ const k = `${Math.round(px + ((nx - px) * j) / n)},${Math.round(py + ((ny - py) * j) / n)}`;+ if (!at.has(k)) return;+ if (!crack.has(k)) crack.set(k, s);+ }+ (px = nx), (py = ny);}- rotSprite(p, STAGES[Math.min(3, cracked)], pal, 0, 0, ang, 7, 18);- return;+ };+ walk(2, 15, -2.2, 3, 0);+ walk(2, 15, 0.3, 2, 0);+ walk(-2, 13, -0.6, 3, 1);+ walk(-2, 13, 2.7, 3, 1);+ walk(3, 11, 1.9, 2, 1);+ walk(2, 15, 1.5, 2, 1);+ const zig = [];+ for (let x = -EW / 2; x < EW / 2; x++) {+ const y = ZY + ((x + 8) % 3 === 0 ? 1 : (x + 8) % 3 === 1 ? 0 : -1);+ zig.push(y);+ if (has(x, y)) crack.set(`${x},${y}`, 2);}- 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) });+ const zigAt = (x) => zig[clamp(x + EW / 2, 0, zig.length - 1)];+ // how close each pixel of shell is to an open crack, per stage: light shows through the shell round them+ const near = [0, 1, 2].map((s) => {+ const pts = [...crack].filter(([, cs]) => cs <= s).map(([k]) => k.split(",").map(Number)), m = new Map();+ for (const e of EGG) m.set(`${e.x},${e.y}`, Math.min(9, ...pts.map(([cx, cy]) => Math.hypot(cx - e.x, cy - e.y))));+ return m;});- 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 });++ const ps = new Particles({ rng: R, ground: floor, sparks: [WHITE, G[2], G[1], G[0]] }), lights = new Lights(), bits = new Bits({ ground: floor }), pieces = [];+ let t = 0, popped = false, crumbled = false, cupA = 0, cupV = 0;+ const done = [false, false, false], CRUMBLE = meta.duration - 0.55;+ const stage = (t) => (t > WOBBLES[2][0] + 0.05 ? 3 : t > WOBBLES[1][0] + 0.05 ? 2 : t > WOBBLES[0][0] + 0.05 ? 1 : 0);+ // the rock: a damped swing about the base, each one harder; a shiver just before it pops+ const angle = (t) => {+ let a = 0;+ for (const [t0, amp] of WOBBLES) {+ const u = t - t0;+ if (u > 0 && u < 0.55) a += amp * Math.sin(u * 22) * Math.exp(-u * 5);+ }+ if (t > POP - 0.14 && t < POP) a += 0.05 * Math.sin(t * 120);+ return a;+ };+ // the light inside: grows with each crack, flashes at the pop, then dies down in the empty cup+ const inner = (t) => (t < POP ? stage(t) / 3 + 0.25 * Math.max(0, Math.sin(t * 9)) * (stage(t) / 3) : 1.6 * Math.exp(-(t - POP) * 2.6));++ // break part of the shell into pieces round a few seeds; each keeps its lit outside and a hot broken edge+ function breakUp(keep, n, v, life) {+ const seeds = Array.from({ length: n }, () => [R.range(-EW / 2 + 1, EW / 2 - 1), R.range(0, EH)]), cells = new Map();+ for (const e of EGG) {+ if (!keep(e.x, e.y)) continue;+ let best = 0, bd = 1e9;+ seeds.forEach(([sx, sy], i) => {+ const d = Math.hypot(e.x - sx, e.y - sy);+ if (d < bd) (bd = d), (best = i);+ });+ if (!cells.has(best)) cells.set(best, []);+ cells.get(best).push(e);+ }+ for (const px of cells.values()) {+ let cx = 0, cy = 0;+ for (const e of px) (cx += e.x + 0.5), (cy += e.y + 0.5);+ (cx /= px.length), (cy /= px.length);+ const map = new Map(), mine = new Set(px.map((e) => `${e.x},${e.y}`));+ for (const e of px) {+ const edge = [[1, 0], [-1, 0], [0, 1], [0, -1]].some(([dx, dy]) => !mine.has(`${e.x + dx},${e.y + dy}`) && has(e.x + dx, e.y + dy));+ // lit by the flash: no piece flies off in shadow+ const c = e.c === C[1] || e.c === C[2] ? C[3] : e.c;+ map.set(`${Math.round(e.x + 0.5 - cx)},${Math.round(-(e.y + 0.5 - cy))}`, [c, edge]);+ }+ const r = Math.max(...px.map((e) => Math.hypot(e.x + 0.5 - cx, e.y + 0.5 - cy))) + 1, [vx, vy] = v(cx, cy), l = life();+ pieces.push({ id: pieces.length + 1, x: cx, y: -cy, vx, vy, a: 0, va: R.range(-10, 10), r, map, life: l, max: l, rest: false, born: t });+ }}- // 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);++ function pop() {+ popped = true;+ breakUp((x, y) => y >= zigAt(x), 6, (cx) => [cx * R.range(8, 13) + R.range(-14, 14), -R.range(140, 210)], () => R.range(0.95, 1.15));+ for (let i = 0; i < 14; i++) {+ const a = -Math.PI / 2 + R.range(-1.2, 1.2), sp = R.range(70, 170);+ bits.add({ kind: B.SHARD, x: R.range(-5, 5), y: -ZY - R.range(0, 4), vx: Math.cos(a) * sp, vy: Math.sin(a) * sp, g: 0.9, drag: 0.6, bounce: 0.3, life: R.range(0.55, 0.85), a: R.range(0, TAU), va: R.range(-20, 20), s: R.range(1.2, 2.4), c: R.pick([C[5], C[5], C[4], G[2]]) });+ }+ for (let i = 0; i < 12; i++) {+ const a = -Math.PI / 2 + R.range(-1.1, 1.1), sp = R.range(50, 110);+ ps.spawn(P.STAR, R.range(-3, 3), -ZY - 2, Math.cos(a) * sp, Math.sin(a) * sp, R.range(0.4, 0.9), R.pick([WHITE, G[2], G[1]]), R.range(1, 2.2));+ }+ for (let i = 0; i < 10; i++) {+ const a = -Math.PI / 2 + R.range(-1, 1), sp = R.range(100, 200);+ ps.spawn(P.SPARK, R.range(-3, 3), -ZY - 1, Math.cos(a) * sp, Math.sin(a) * sp, R.range(0.2, 0.45));+ }+ // a puff of pale dust at the base, gone in a few frames+ for (let i = 0; i < 4; i++) {+ const s = R.sign();+ ps.spawn(P.DUST, s * R.range(5, 8), -1, s * R.range(25, 50), -R.range(2, 6), R.range(0.15, 0.25), C[5], R.range(1, 1.8));+ }+ lights.add(0, -ZY - 10, 40, G[1], 0.9, 0.55);+ lights.add(0, -ZY - 2, 18, WHITE, 0.9, 0.12);+ cupV = R.sign() * 3;}++ return {+ update(dt) {+ t += dt;+ // each rock opens more crack: a tick of light, a chip or two of shell, a puff at the base+ WOBBLES.forEach(([t0], i) => {+ if (!done[i] && t >= t0 + 0.05) {+ done[i] = true;+ lights.add(i === 1 ? -3 : 2, -14 + i, 8 + i * 2, G[1], 0.25 + i * 0.08, 0.18);+ for (let j = 0; j < 2 + i * 2; j++) ps.spawn(P.STAR, R.range(-5, 5), -R.range(8, 17), R.range(-20, 20), -R.range(10, 30), R.range(0.25, 0.5), R.pick([WHITE, G[2]]), R.range(0.6, 1.4));+ for (let j = 0; j < i + 1; j++) bits.add({ kind: B.SHARD, x: R.range(-4, 4), y: -R.range(10, 16), vx: R.range(-50, 50), vy: -R.range(40, 90), g: 0.9, drag: 0.5, bounce: 0.3, life: R.range(0.5, 0.8), a: R.range(0, TAU), va: R.range(-20, 20), s: R.range(1, 1.6), c: C[4] });+ ps.spawn(P.DUST, R.sign() * R.range(5, 7), -0.5, R.sign() * R.range(8, 18), -R.range(1, 3), R.range(0.15, 0.25), C[5], R.range(0.8, 1.4));+ }+ });+ if (!popped && t >= POP) pop();+ // light keeps welling up out of the empty cup for a moment: something came out of there+ if (popped && t < POP + 0.6 && R.chance(0.35)) ps.spawn(P.MOTE, R.range(-4, 4), -ZY - 1, R.range(-8, 8), -R.range(40, 80), Math.min(R.range(0.4, 0.8), meta.duration - 0.1 - t), R.pick([G[2], G[1], WHITE]), 0.7);+ if (popped && !crumbled && t >= CRUMBLE) {+ crumbled = true;+ breakUp((x, y) => y < zigAt(x), 4, (cx) => [cx * R.range(4, 8), -R.range(40, 80)], () => R.range(0.38, 0.48));+ for (let i = 0; i < 3; i++) ps.spawn(P.DUST, R.range(-6, 6), -1, R.sign() * R.range(10, 25), -R.range(2, 6), R.range(0.15, 0.25), C[5], R.range(1, 1.6));+ }+ if (popped) {+ cupV += (-cupA * 90 - cupV * 4) * dt;+ cupA += cupV * dt;+ }+ for (let i = pieces.length - 1; i >= 0; i--) {+ const q = pieces[i];+ if ((q.life -= dt) <= 0) {+ pieces.splice(i, 1);+ continue;+ }+ if (q.rest) continue;+ q.vy += 900 * dt;+ q.vx -= q.vx * 0.6 * dt;+ q.x += q.vx * dt;+ q.y += q.vy * dt;+ q.a += q.va * dt;+ const g = -q.r * 0.45;+ if (q.y > g && q.vy > 0) {+ q.y = g;+ if (q.vy > 80) (q.vy *= -0.35), (q.vx *= 0.6), (q.va *= 0.5);+ else (q.rest = true), (q.vx = q.vy = 0);+ }+ }+ bits.update(dt);+ ps.update(dt);+ lights.update(dt);+ },+ drawBack(p) {+ // a soft contact shadow under the egg, shifting as it rocks+ if (!crumbled) {+ const sx = popped ? 0 : -angle(t) * 8, k = popped ? 1 - smooth(POP, CRUMBLE, t) * 0.4 : 1;+ for (let y = -1; y <= 1; y++)+ for (let x = -10; x <= 10; x++) {+ const d = ((x + 0.5 - sx) / 9.5) ** 2 + ((y + 0.5) / 1.8) ** 2;+ if (d < 1) p.blend(x, y, C[0], 0.5 * k * (1 - d));+ }+ }+ // warm light on the floor as it leaks out+ const g = inner(t);+ if (g > 0.05) p.glow(0, -3, 22, G[0], 0.18 * Math.min(1.2, g));+ ps.draw(p, "back");+ },+ draw(p) {+ const st = stage(t), a = popped ? cupA * 0.03 : angle(t), ca = Math.cos(a), sa = Math.sin(a), g = inner(t);+ if (!crumbled)+ p.shade(-12, -EH - 4, 12, 1, (x, y, out) => {+ const ux = Math.floor(x * ca + y * sa), uy = Math.floor(-(-x * sa + y * ca)), e = at.get(`${ux},${uy}`);+ const inside = e && !(popped && uy >= zigAt(ux));+ if (!inside) {+ // a dark outline holds the egg's shape+ const n = [[1, 0], [-1, 0], [0, 1], [0, -1]].some(([dx, dy]) => { const f = at.get(`${ux + dx},${uy + dy}`); return f && !(popped && uy + dy >= zigAt(ux + dx)); });+ if (n && !(popped && uy >= zigAt(ux) && uy <= zigAt(ux) + 1)) out.c = C[0];+ return;+ }+ const cs = crack.get(`${ux},${uy}`);+ if (popped) {+ // the cup: its broken rim burns with the light inside, cooling as it fades+ out.c = uy >= zigAt(ux) - 1 ? (g > 0.9 ? WHITE : g > 0.4 ? G[2] : g > 0.12 ? G[1] : C[4]) : e.c;+ if (uy >= zigAt(ux) - 1) (out.k = 0.25 * g), (out.l = G[1]);+ return;+ }+ if (cs !== undefined && cs < st) {+ // an open crack: deep orange light in the gap, flashing white the moment it opens+ const fresh = t - WOBBLES[cs][0] < 0.17;+ out.c = fresh ? WHITE : rand(ux, uy, (t * 20) | 0) < 0.25 + 0.1 * st ? G[1] : G[0];+ out.k = 0.14 + 0.06 * st;+ out.l = G[1];+ return;+ }+ // the lip of each crack falls into shadow below it, so the gap reads as a gap+ if (crack.get(`${ux},${uy + 1}`) < st || crack.get(`${ux + 1},${uy}`) < st) {+ out.c = e.lit > 0.3 ? C[2] : C[1];+ return;+ }+ // light shows through the shell in a halo round the cracks, and the whole egg warms a little+ const dn = st > 0 ? near[st - 1].get(`${ux},${uy}`) : 9, k = Math.min(1, g * 1.5);+ const base = st > 0 && e.c !== SPK ? mix(e.c, G[0], 0.05 * st * k) : e.c;+ out.c = dn < 1.6 ? mix(base, G[1], (st >= 2 ? 0.32 : 0.2) * k) : dn < 2.7 && st >= 2 ? mix(base, G[1], 0.14 * k) : base;+ });+ // the pop: the opening floods white, and light rays fan up out of it+ const q = t - POP;+ if (popped && q < 1.2 && !crumbled && g > 0.22) {+ const k = clamp(q / 1.2), oy = -ZY + 0.5, rx = 7;+ for (let y = -2; y <= 2; y++)+ for (let x = -rx; x <= rx; x++) {+ const d = Math.hypot((x + 0.5) / rx, (y + 0.5) / 2.2);+ if (d > 1) continue;+ if (g < 0.6 && d > 0.75) continue;+ p.px(x, oy + y, g > 1 ? (d < 0.7 ? WHITE : G[2]) : g > 0.6 ? (d < 0.5 ? G[2] : G[1]) : d < 0.45 ? G[1] : G[0]);+ }+ p.glow(0, oy, 16, G[1], 0.6 * g);+ if (q < 0.65) {+ const rk = q / 0.65, L = 36 * ease.outCubic(clamp(q / 0.1)) * (1 - rk * 0.6);+ for (let i = 0; i < 7; i++) {+ const an = -Math.PI / 2 + (i - 3) * 0.24 + 0.05 * Math.sin(t * 6 + i), len = L * (i % 2 ? 0.65 : 1), w = i % 2 ? 1 : 2;+ const x1 = Math.cos(an) * len, y1 = oy + Math.sin(an) * len;+ for (let j = 0; j < w; j++) p.line(j * 0.8 - 0.4, oy - 1, x1 + j * 0.8 - 0.4, y1, (u) => (u < 0.3 ? WHITE : u < 0.65 ? G[2] : G[1]), (u) => (1 - u * u) * (1.1 - rk));+ p.glowLine(0, oy, x1, y1, 5, G[1], 0.35 * (1 - rk));+ }+ }+ if (q < 0.1) p.glow(0, oy - 4, 30, WHITE, 0.6 * (1 - q / 0.1));+ // the light that lingers over the cup+ p.glowLine(0, oy, 0, oy - 26, 8, G[1], 0.25 * g);+ }+ // the inside glow through the shell before it pops+ if (!popped && g > 0) p.glow(0, -EH * 0.55, 7 + 2 * st, G[1], 0.05 * g);+ // pieces of shell: their lit outsides, their broken edges hot at first+ for (const s of pieces) {+ const c2 = Math.cos(s.a), s2 = Math.sin(s.a), f = Math.min(1, s.life / 0.4), r = Math.ceil(s.r), hot = t - s.born < 0.35;+ for (let py = -r; py <= r; py++)+ for (let px = -r; px <= r; px++) {+ const ux = Math.round(px * c2 + py * s2), uy = Math.round(-px * s2 + py * c2), m = s.map.get(`${ux},${uy}`);+ if (m && rand(ux, uy, s.id) < f) p.px(Math.floor(s.x) + px, Math.floor(s.y) + py, m[1] ? (hot ? G[2] : C[4]) : m[0]);+ }+ if (hot) p.glow(s.x, s.y, 6, G[1], 0.3);+ }+ bits.draw(p);+ if (popped && q < 0.9) sparkle(p, -3, -ZY - 6, Math.round(4 * (1 - q / 0.9)), WHITE, G[1], 0.4);+ ps.draw(p, "front");+ lights.draw(p);+ },+ };}diff --git a/src/fx/spawn/ghost-out.js b/src/fx/spawn/ghost-out.jsdeleted file mode 100644index 8d3d04a..0000000--- a/src/fx/spawn/ghost-out.js+++ /dev/null@@ -1,61 +0,0 @@-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.jsindex 2fb9cd6..21beaee 100644--- a/src/fx/spawn/poof.js+++ b/src/fx/spawn/poof.js@@ -1,52 +1,141 @@-import { ramp, at, burst, seg, ease, TAU, WHITE } from "../../core/index.js";-import { cloud } from "./_lib.js";+// The soft, top-lit smoke puffs (a body, a denser core, a lit cap) follow Sprite Fusion's open-source explosion+// (https://www.spritefusion.com/pixel-art-vfx/explosion), MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Lights, P, Rng, fit, flare, clamp, smooth, ease, TAU, WHITE, hex } from "../../core/index.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,+ desc: "A cartoon death poof: a white pop, a ring of soft round smoke balls bursting out between speed lines, little stars spinning off, and the cloud lifting and thinning away.",+ tags: ["spawn", "death", "despawn", "smoke", "poof", "cartoon", "one-shot"],+ size: [112, 92],+ origin: [56, 80],+ duration: 1.6,loop: false,fps: 30,bg: "ground",- options: { palette: ["#2c2840", "#5a5478", "#8e88aa", "#c4bed8", "#ecebf6", "#ffffff"], size: 1, seed: 21 },+ options: {+ palette: ["#2a2440", "#5e5878", "#9a94b4", "#cdc8e0", "#f2f0fa", "#ffffff"],+ stars: ["#ffd84a", "#fff3a6", "#ffffff"],+ 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);+const CY = -17;++export function create(o) {+ const C = fit(o.palette, 6), S = fit(o.stars, 3), R = new Rng(o.seed), floor = () => 0;+ const ps = new Particles({ rng: R, ground: floor, sparks: [WHITE, S[1], S[0], C[2]] }), lights = new Lights();+ const balls = [], lines = [];+ // a ring of fat balls round a fat core, thrown out fast and stopped by drag, each swelling as it slows+ const ring = 9;+ for (let i = 0; i < ring; i++) {+ const a = (i / ring) * TAU + R.range(-0.2, 0.2), sp = R.range(95, 140), r = R.range(5, 7);+ balls.push({ x: Math.cos(a) * 3, y: CY + Math.sin(a) * 3, vx: Math.cos(a) * sp, vy: Math.sin(a) * sp * 0.8 - 12, r0: r * 0.5, r1: r, life: R.range(0.7, 1.05), delay: R.range(0, 0.03) });+ }+ for (let i = 0; i < 5; i++) {+ const a = R.range(0, TAU), sp = R.range(20, 60);+ balls.push({ x: Math.cos(a) * 2, y: CY + Math.sin(a) * 2, vx: Math.cos(a) * sp, vy: Math.sin(a) * sp - 16, r0: 4, r1: R.range(6.5, 8.5), life: R.range(0.85, 1.2), delay: R.range(0.02, 0.06) });+ }+ // a few small puffs flung further out, gone quickly, so the cloud's edge is ragged+ for (let i = 0; i < 7; i++) {+ const a = R.range(0, TAU), sp = R.range(170, 240), r = R.range(2.2, 3.6);+ balls.push({ x: Math.cos(a) * 4, y: CY + Math.sin(a) * 4, vx: Math.cos(a) * sp, vy: Math.sin(a) * sp * 0.75 - 10, r0: r * 0.6, r1: r, life: R.range(0.32, 0.5), delay: R.range(0.01, 0.04) });+ }+ for (const b of balls) b.max = b.life;+ // speed lines between the balls, flicked out and gone in a few frames+ for (let i = 0; i < 12; i++) {+ const a = (i / 12) * TAU + R.range(-0.12, 0.12) + 0.13, sa = Math.sin(a);+ // the ones that point down stop at the floor+ lines.push({ a, r1: Math.min(R.range(24, 34), sa > 0.1 ? (-2 - CY) / sa : 99), d: R.range(0, 0.04) });}- // 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));- });+ // little stars spun off the pop+ for (let i = 0; i < 7; i++) {+ const a = R.range(-Math.PI, 0.3), sp = R.range(70, 125);+ ps.spawn(P.STAR, Math.cos(a) * 6, CY + Math.sin(a) * 6, Math.cos(a) * sp, Math.sin(a) * sp - 30, R.range(0.55, 0.95), R.pick([S[2], S[1], S[1], S[0]]), R.range(1.3, 2.4), R.range(0.02, 0.1));}- // 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);- });+ for (let i = 0; i < 10; i++) {+ const a = R.range(0, TAU), sp = R.range(40, 110);+ ps.spawn(P.STAR, Math.cos(a) * 5, CY + Math.sin(a) * 5, Math.cos(a) * sp, Math.sin(a) * sp - 20, R.range(0.3, 0.6), R.pick([WHITE, S[1]]), 0.6, R.range(0, 0.08));+ }+ // the feet go too: a skid of dust along the floor+ for (let i = 0; i < 6; i++) {+ const s = R.sign();+ ps.spawn(P.DUST, s * R.range(1, 6), -1, s * R.range(25, 70), -R.range(2, 10), R.range(0.4, 0.7), C[2], R.range(1.6, 3), R.range(0.02, 0.08));+ }+ lights.add(0, CY, 46, C[4], 0.8, 0.4);+ lights.add(0, CY, 22, WHITE, 0.8, 0.1);+ let t = 0;++ // a ball swells out, breathes, then shrinks to nothing (a cartoon puff goes out ball by ball, it doesn't fade)+ const radius = (b) => {+ const age = b.max - b.life, u = age / b.max;+ const grow = b.r0 + (b.r1 - b.r0) * ease.outBack(clamp(age / 0.22), 2), breathe = 1 + 0.06 * Math.sin(age * 14 + b.r1);+ return grow * breathe * (u < 0.62 ? 1 : 1 - ease.inBack(clamp((u - 0.62) / 0.38), 1.4));+ };+ const drawBall = (p, b, layer) => {+ const age = b.max - b.life, r = radius(b), a = Math.min(1, age * 20), lit = age < 0.12;+ if (r < 0.6) return;+ // the whole cloud is lit from above: the balls underneath are a step darker+ const hy = (b.y - CY + 6) / 14, lo = hy > 0.4, hi = hy < -0.3;+ if (layer === "shade") p.disc(b.x + r * 0.16, b.y + r * 0.2, r, lit ? C[3] : lo ? C[1] : C[2], 0.8 * a);+ else if (layer === "body") p.disc(b.x - r * 0.06, b.y - r * 0.08, r * 0.86, lit ? C[4] : lo ? C[2] : C[3], 0.88 * a);+ else if (!lo || lit) {+ p.disc(b.x - r * 0.28, b.y - r * 0.34, r * 0.42, lit || hi ? WHITE : C[4], 0.85 * a);+ if (age < 0.25) p.disc(b.x - r * 0.3, b.y - r * 0.38, r * 0.2, WHITE, 0.9 * a * (1 - age / 0.25));+ }+ };++ return {+ update(dt) {+ t += dt;+ for (let i = balls.length - 1; i >= 0; i--) {+ const b = balls[i];+ if (b.delay > 0) {+ b.delay -= dt;+ continue;+ }+ if ((b.life -= dt) <= 0) {+ // each ball goes with a pip of light+ if (b.r1 > 4) ps.spawn(P.STAR, b.x, b.y, 0, -8, 0.22, WHITE, 0.6);+ balls.splice(i, 1);+ continue;+ }+ // fast burst, hard drag, then a slow lift+ b.vx -= b.vx * 7 * dt;+ b.vy -= b.vy * 7 * dt + 30 * dt;+ b.x += b.vx * dt;+ b.y = Math.min(b.y + b.vy * dt, -radius(b) * 0.7);+ }+ ps.update(dt);+ lights.update(dt);+ },+ drawBack(p) {+ // a soft shadow where the body stood, and the light of the pop on the floor+ const s = 1 - smooth(0.1, 0.9, t);+ if (s > 0) p.glow(0, -1, 26, C[4], 0.25 * s);+ ps.draw(p, "back");+ },+ draw(p) {+ // the cloud: shade, body, then caps, so neighbouring balls merge into one lumpy cloud+ const live = balls.filter((b) => b.delay <= 0);+ for (const layer of ["shade", "body", "cap"]) for (const b of live) drawBall(p, b, layer);+ // the pop: a white ball and an 8-ray flare for a couple of frames, then a ring+ if (t < 0.07) {+ const k = t / 0.07;+ p.circle(0, CY, 9 + 3 * k, C[4]);+ p.circle(0, CY, 7 + 3 * k, WHITE);+ flare(p, 0, CY, 20 * (1 - k * 0.5), 1 - k, C);+ }+ const rk = (t - 0.03) / 0.2;+ if (rk > 0 && rk < 1) p.ring(0, CY, 8 + 18 * ease.outCubic(rk), Math.max(1, 2.5 * (1 - rk)), rk < 0.3 ? WHITE : C[4], 1.1 - rk);+ for (const l of lines) {+ const u = (t - l.d) / 0.2;+ if (u <= 0 || u >= 1) continue;+ const head = 8 + (l.r1 - 8) * ease.outExpo(clamp(u / 0.6)), tail = 8 + (l.r1 - 8) * ease.inCubic(u), ca = Math.cos(l.a), sa = Math.sin(l.a);+ p.line(ca * tail, CY + sa * tail, ca * head, CY + sa * head, (v) => (v > 0.6 ? WHITE : C[4]));+ p.glowLine(ca * tail, CY + sa * tail, ca * head, CY + sa * head, 3, C[4], 0.25);+ }+ ps.draw(p, "front");+ lights.draw(p);+ },+ };}diff --git a/src/fx/spawn/respawn-beam.js b/src/fx/spawn/respawn-beam.jsindex 70180bf..102e4d2 100644--- a/src/fx/spawn/respawn-beam.js+++ b/src/fx/spawn/respawn-beam.js@@ -1,78 +1,168 @@-import { PAL, ramp, at, burst, cycle, fly, seg, ease, WHITE } from "../../core/index.js";-import { actorOf } from "./_lib.js";+// The beam's slam, strands, rings and the sparks thrown along the floor are adapted from Sprite Fusion's+// open-source holy-light (https://www.spritefusion.com/pixel-art-vfx/holy-light), MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Lights, P, Rng, fit, band, sparkle, clamp, smooth, ease, rand, TAU, WHITE, mix } from "../../core/index.js";+import { bodyOf, rimOf } 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,+ desc: "A guide line drops, a pillar of light slams onto the spot, and a scan bar climbs from the feet writing the character back in row by row, white-hot lines cooling to its colors.",+ tags: ["spawn", "respawn", "beam", "teleport", "scanline", "light", "one-shot"],+ size: [128, 150],+ origin: [64, 136],+ duration: 2.5,loop: false,fps: 30,bg: "ground",- actor: true,- options: { palette: PAL.cyber, seed: 29 },+ actor: 2,+ options: {+ palette: ["#061e1b", "#0c3e36", "#136a5a", "#1f9c80", "#45d1a8", "#a8f5d8", "#ffffff"],+ width: 15,+ seed: 12,+ },};-const FLASH = 0.72; // the written-in silhouette flashes white; the character is there from here on+const SLAM = 0.32, WRITE0 = SLAM + 0.08, WRITE = 0.95, DONE = WRITE0 + WRITE, LIFT = DONE + 0.12;+export const actorAlpha = (t) => (t < DONE + 0.04 ? 0 : 1);-/** 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 create(o) {+ const C = fit(o.palette, 7), R = new Rng(o.seed), floor = () => 0, BW = o.width;+ const body = bodyOf(o.actor, C), rim = rimOf(body), top = body.y, H = body.h, TOPY = -136;+ const ps = new Particles({ rng: R, ground: floor, sparks: [WHITE, C[5], C[4], C[3]] }), lights = new Lights();+ // strands of brighter light running down the beam, each at its own offset and shimmer+ const strands = Array.from({ length: 6 }, (_, i) => ({ o: rand(i, 1) * 1.6 - 0.8, f: 1 + rand(i, 2) * 3, w: rand(i, 3) }));+ // the scan bar: where it is (local y), climbing from the feet to the crown+ const scanY = (t) => -ease.inOutSine(clamp((t - WRITE0) / WRITE)) * (H + 2);+ // when each row is written, and its glitch: some rows jump sideways for a frame or two as they land+ const rowT = (my) => WRITE0 + (WRITE * Math.acos(1 - 2 * clamp((H - my) / (H + 2)))) / Math.PI;+ let t = 0, slammed = false, finished = false;+ const DROP = 0.07;+ const width = (t) => (t < SLAM - DROP ? 0 : t < SLAM ? BW * 0.6 : t < LIFT ? BW * (1 + 0.4 * Math.exp(-(t - SLAM) * 10)) * (0.92 + 0.08 * Math.sin(t * 40)) : BW * (1 - ease.outCubic(clamp((t - LIFT) / 0.3))));+ // the beam lifts away bottom first once the character is written+ const bottom = (t) => (t < LIFT ? 0 : -150 * ease.inCubic(clamp((t - LIFT) / 0.4)));-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);+ return {+ update(dt) {+ t += dt;+ // the guide: motes drawn in to the spot along the floor+ if (t < SLAM && R.chance(0.5)) {+ const s = R.sign(), D = R.range(18, 40), T = R.range(0.15, 0.25), v = (D * 3) / (Math.exp(3 * T) - 1);+ ps.spawn(P.STREAK, s * D, -R.range(0, 3), -s * v, 0, T, R.chance(0.5) ? C[5] : C[4]);}- // 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);+ if (!slammed && t >= SLAM) {+ slammed = true;+ lights.add(0, -28, 64, C[4], 1, 0.5);+ lights.add(0, -52, 80, C[5], 1.1, 0.4);+ lights.add(0, -9, 24, WHITE, 0.9, 0.12);+ for (let i = 0; i < 40; i++) {+ const s = R.sign(), sp = R.range(60, 135);+ ps.spawn(P.SPARK, s * R.range(0, 6), -1, s * sp, -R.range(20, 140), R.range(0.25, 0.7));+ }+ for (let i = 0; i < 12; i++) ps.spawn(P.STAR, R.range(-BW, BW), -R.range(2, 40), R.range(-20, 20), -R.range(20, 70), R.range(0.5, 1), R.pick([WHITE, C[5]]), R.range(0.8, 1.8));+ for (let i = 0; i < 8; i++) {+ const s = R.sign();+ ps.spawn(P.DUST, s * R.range(4, 10), -1, s * R.range(30, 80), -R.range(3, 10), R.range(0.4, 0.7), C[2], R.range(1.5, 3));+ }+ }+ // the scan bar spits sparks sideways as it climbs+ if (t > WRITE0 && t < DONE && R.chance(0.45)) {+ const y = scanY(t), s = R.sign();+ ps.spawn(P.SPARK, s * R.range(6, 11), y, s * R.range(40, 140), R.range(-60, 10), R.range(0.15, 0.35));+ }+ // motes rise inside the beam while it stands+ if (t > SLAM && t < LIFT + 0.2 && R.chance(0.6)) ps.spawn(P.STAR, R.range(-1.3, 1.3) * BW, -R.range(0, 90), R.range(-6, 6), -R.range(30, 90), R.range(0.4, 0.9), R.pick([WHITE, C[5], C[5], C[4]]), R.chance(0.3) ? R.range(1, 1.8) : 0.6);+ if (!finished && t >= DONE) {+ finished = true;+ lights.add(0, top + H / 2, 40, C[5], 0.7, 0.3);+ for (let i = 0; i < 14; i++) {+ const c = R.pick(rim);+ ps.spawn(P.STAR, c.x, c.y, R.range(-25, 25), -R.range(10, 50), R.range(0.4, 0.9), R.pick([WHITE, C[5]]), R.range(0.8, 1.8));+ }+ }+ ps.update(dt);+ lights.update(dt);+ },+ drawBack(p) {+ const w = width(t), b = bottom(t);+ // the guide line before the slam, a marker on the floor+ if (t < SLAM) {+ const k = smooth(0, SLAM * 0.7, t) * (1 - smooth(SLAM - DROP, SLAM, t) * 0.5);+ for (let y = TOPY; y < -1; y += 2) p.dot(0, y + ((t * 60) | 0) % 2, C[5], k * (0.35 + 0.65 * ((y - TOPY) / -TOPY)));+ band(p, 0, 0, 10 - 4 * k, 0.2, 1, k, C, (g) => Math.sin(g) < 0);+ p.glow(0, -2, 16, C[4], 0.4 * k);+ }+ if (w <= 0.2) return;+ // the beam: a see-through column, hard bright edges, shimmering strands; its light hugs the edges so+ // whatever it writes inside stays readable+ const yEnd = t < SLAM ? TOPY + (-1 - TOPY) * ease.inCubic(clamp((t - SLAM + DROP) / DROP)) : -1 + b;+ const writing = smooth(WRITE0 - 0.05, WRITE0 + 0.1, t) * (1 - smooth(DONE, LIFT, t)), fill = 0.2 - 0.1 * writing;+ for (let y = TOPY; y <= yEnd; y++) {+ for (let x = Math.floor(-w); x <= Math.ceil(w); x++) {+ const q = Math.abs((x + 0.5) / w);+ if (q > 1) continue;+ if (q > 0.86) {+ p.dot(x, y, q > 0.94 && rand(x, y, (t * 30) | 0) < 0.7 ? WHITE : C[5], 1);+ continue;+ }+ const core = 1 - smooth(SLAM + 0.06, WRITE0 + 0.08, t);+ if (q < 0.7 * core) {+ // the white-hot core, with strands of colour running down it+ let hot = q < 0.35 * core;+ for (const s of strands) if (Math.abs((x + 0.5) / w - s.o * 0.6 - 0.05 * Math.sin(t * s.f * 3 + y * 0.05)) < 0.04) hot = false;+ p.px(x, y, hot ? WHITE : q < 0.5 * core ? C[6] : C[5]);+ continue;+ }+ let a = fill * (1.2 - q), c = C[4];+ for (const s of strands) if (Math.abs((x + 0.5) / w - s.o - 0.06 * Math.sin(t * s.f + s.o * 7)) < 0.045 + 0.03 * s.w) (a = 0.55 - 0.25 * writing), (c = C[5]);+ p.blend(x, y, c, a);+ }+ }+ if (yEnd > TOPY + 24)+ for (const s of [-1, 1]) p.glowLine(s * w, TOPY + 24, s * w, yEnd, 6, C[4], 0.3);+ p.glow(0, -5, w * 1.5 + 6, C[5], 0.45);+ },+ draw(p) {+ const w = width(t);+ const sk = (t - SLAM) / 0.45;+ if (sk > 0 && sk < 1) {+ const rx = 14 + 18 * ease.outCubic(sk), ry = 3 + 1.5 * sk;+ p.ellipse(0, 0.5, rx, ry, (d) => (d < 0.4 ? WHITE : d < 0.7 ? C[6] : C[5]), (d) => (1 - sk) * 1.4 * (1 - d * d));+ p.glow(0, -2, rx * 1.3, C[5], 0.5 * (1 - sk));+ }+ // the floor: a hot spot and rings at the slam+ for (let i = 0; i < 2; i++) {+ const k = (t - SLAM - 0.08 * i) / 0.5;+ if (k > 0 && k < 1) band(p, 0, 0, 8 + (i ? 22 : 34) * ease.outCubic(k), 0.2, Math.max(1, 3 * (1 - k)), 1.15 - k, C, () => true, k < 0.15);+ }+ // the character, written in from the feet: each row lands white, then cools to its own colors+ if (t >= WRITE0 && t < DONE + 0.05) {+ const sy = scanY(t), fr = Math.floor(t * 30);+ for (const b of body.list) {+ const t0 = rowT(b.my), age = t - t0;+ if (age < 0) continue;+ const glitch = age < 0.12 && rand(b.my, fr, 9) < 0.3 ? (rand(b.my, fr, 4) < 0.5 ? -2 : 2) : 0;+ const c = age < 0.05 ? WHITE : age < 0.14 ? C[5] : age < 0.3 ? mix(b.c, C[5], 0.5 * (1 - (age - 0.14) / 0.16)) : b.c;+ p.px(b.x + glitch, b.y, b.edge && age < 0.3 ? C[6] : c);+ }+ // the scan bar itself: a bright line across the beam and a light riding it+ if (t < DONE) {+ p.line(-w - 2, sy, w + 2, sy, (u) => (Math.abs(u - 0.5) < 0.35 ? WHITE : C[5]));+ p.line(-w, sy + 1, w, sy + 1, C[4], 0.6);+ p.glowLine(-w, sy, w, sy, 6, C[5], 0.6);+ }+ }+ // done: a flash round the finished character+ const fk = (t - DONE) / 0.25;+ if (fk > 0 && fk < 1) {+ for (const c of rim) p.dot(c.x, c.y, fk < 0.4 ? WHITE : C[5], 1.2 - fk);+ sparkle(p, 6, top + 6, Math.round(6 * (1 - fk)), WHITE, C[5], 0.5);+ }+ // the beam's front edges over the character while it stands+ if (w > 0.2) {+ const yEnd = t < SLAM ? TOPY + (-1 - TOPY) * ease.inCubic(clamp((t - SLAM + DROP) / DROP)) : -1 + bottom(t);+ if (t >= SLAM && t - SLAM < 0.1) p.glow(0, -30, 56, WHITE, 0.6 * (1 - (t - SLAM) / 0.1));+ }+ ps.draw(p);+ lights.draw(p);+ },+ };}diff --git a/src/fx/spawn/shatter-death.js b/src/fx/spawn/shatter-death.jsindex 0c6e3d7..9c72ee0 100644--- a/src/fx/spawn/shatter-death.js+++ b/src/fx/spawn/shatter-death.js@@ -1,113 +1,276 @@-import { PAL, ramp, at, rng, burst, fly, seg, luma, TAU, WHITE } from "../../core/index.js";-import { actorOf, actorPixels, steps } from "./_lib.js";+// The faceted ice shell, the cracks, and the shards, mist and glints of the burst are adapted from Sprite+// Fusion's open-source ice (https://www.spritefusion.com/pixel-art-vfx/ice), MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Bits, Lights, P, B, Rng, fit, crystal, sparkle, clamp, smooth, ease, rand, TAU, WHITE, mix } from "../../core/index.js";+import { bodyOf } 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,+ desc: "Frost races up the body and seals it in faceted ice, a glint sweeps it, cracks spread from the chest, then it bursts into its own facets that tumble, bounce and melt.",+ tags: ["spawn", "death", "ice", "freeze", "shatter", "shards", "one-shot"],+ size: [168, 96],+ origin: [84, 84],+ duration: 3.3,loop: false,fps: 30,bg: "ground",- actor: false,- options: { palette: PAL.ice, shards: 11, seed: 27 },+ actor: 2,+ options: {+ palette: ["#0e1636", "#1a2f66", "#2557a3", "#3488d6", "#5fc0f0", "#a2e6ff", "#dcf8ff", "#ffffff"],+ seed: 14,+ },};-const FREEZE = [0.06, 0.3], CRACK = 0.32, BREAK = 0.52, G = 340, E = 0.3;-const memo = new WeakMap();+const LOCK = 0.5, CRACK = 1.05, BURST = 1.4;+export const actorAlpha = (t) => (t < BURST ? 1 : 0);-/** 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);+export function create(o) {+ const C = fit(o.palette, 8), R = new Rng(o.seed), floor = () => 0;+ const body = bodyOf(o.actor, C), W = body.w + 2, H = body.h + 1, X0 = body.x - 1, Y0 = body.y - 1;+ // the ice: the body grown by a pixel (not below its feet), cut into facets round a few seeds+ const ice = new Int16Array(W * H).fill(-1), col = new Uint32Array(W * H), glass = new Uint32Array(W * H), solid = new Uint8Array(W * H);+ const inBody = (mx, my) => body.on(mx, my);+ for (let y = 0; y < H; y++)+ for (let x = 0; x < W; x++) {+ const mx = x - 1, my = y - 1;+ if (inBody(mx, my) || (my < body.h - 1 && (inBody(mx - 1, my) || inBody(mx + 1, my) || inBody(mx, my - 1) || inBody(mx, my + 1)))) ice[y * W + x] = 0;+ }+ const seeds = [];+ for (let i = 0; i < 22; i++) {+ let x, y, tries = 0;+ do (x = R.range(0, W)), (y = R.range(0, H));+ while (ice[Math.floor(y) * W + Math.floor(x)] < 0 && ++tries < 40);+ seeds.push([x, y]);}- 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 at = (x, y) => x >= 0 && y >= 0 && x < W && y < H && ice[y * W + x] >= 0;+ for (let y = 0; y < H; y++)+ for (let x = 0; x < W; x++) {+ const i = y * W + x;+ if (ice[i] < 0) continue;+ let d1 = 1e9, d2 = 1e9, k = 0;+ seeds.forEach(([sx, sy], j) => {+ const d = Math.hypot(x + 0.5 - sx, (y + 0.5 - sy) * 0.85);+ if (d < d1) (d2 = d1), (d1 = d), (k = j);+ else if (d < d2) d2 = d;});- });- 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);+ ice[i] = k;+ // each facet catches the light by where it faces: up and left bright, down and right deep+ const [sx, sy] = seeds[k], lit = clamp(0.55 + 0.35 * (rand(k, 41) - 0.5) - 0.5 * ((sx - W / 2) / W) - 0.55 * ((sy - H / 2) / H));+ const own = body.cell(x - 1, y - 1)?.c;+ // under the ice: the body's own colours, gone cold; over it: a see-through facet catching the light+ col[i] = own ? mix(own, C[4], 0.36) : C[3];+ glass[i] = C[3 + Math.min(2, Math.floor(lit * 3))];+ let sc = 0;+ if (d2 - d1 < 0.42 && !own) sc = lit > 0.5 ? C[6] : C[5]; // the seams between facets, out in the shell+ else if (d2 - d1 < 0.42) col[i] = mix(col[i], C[6], 0.45); // and faint where they cross the body+ if (!at(x - 1, y) || !at(x, y - 1)) sc = C[6]; // lit outer rim, top and left+ if (!at(x + 1, y) || (!at(x, y + 1) && y < H - 1)) sc = C[3]; // shaded rim, bottom and right+ if (sc) (col[i] = sc), (solid[i] = 1);+ }+ // rime spikes where the ice pushes out: on the shoulders, the head and the feet+ const spikes = [];+ for (let i = 0; i < 7; i++) {+ const x = R.int(1, W - 2), y0 = R.int(2, H - 3);+ let y = y0;+ while (y > 0 && at(x, y - 1)) y--;+ if (at(x, y)) spikes.push({ x: X0 + x + 0.5, base: Y0 + y + 1, h: R.range(3, 6), w: R.range(2.5, 3.5), lean: R.range(-2.5, 2.5), at: LOCK + R.range(-0.02, 0.08) });}- const slide = 1 - Math.exp(-tt * 6);- return [x + (bx / 6) * slide, floor, ang + (w / 6) * slide];-}+ for (const sd of [-1, 1])+ for (let i = 0; i < 2; i++) {+ const h = i ? R.range(5, 7) : R.range(8, 11);+ spikes.push({ x: sd * (i ? R.range(11, 13) : R.range(7, 9)), base: 0, h, w: i ? 3.5 : 4.5, lean: sd * h * R.range(0.25, 0.45), at: R.range(0.08, 0.2) });+ }+ // cracks from the chest+ const IX = Math.round(W * 0.48), IY = Math.round(H * 0.42), cracks = [];+ const walk = (x, y, a, len) => {+ const pts = [[x, y]];+ for (let s = 0; s < len; s++) {+ a += R.range(-0.5, 0.5);+ x += Math.cos(a) * R.range(1.4, 2.4);+ y += Math.sin(a) * R.range(1.4, 2.4);+ if (!at(Math.floor(x), Math.floor(y))) break;+ pts.push([x, y]);+ if (pts.length > 3 && cracks.length < 18 && R.chance(0.15)) walk(x, y, a + R.sign() * R.range(0.6, 1.1), len / 2);+ }+ cracks.push(pts);+ };+ for (let i = 0; i < 7; i++) walk(IX, IY, (i / 7) * TAU + R.range(-0.3, 0.3), 20);-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);+ const ps = new Particles({ rng: R, ground: floor, sparks: [WHITE, C[6], C[5], C[4]], haze: C[5] });+ const bits = new Bits({ ground: floor }), lights = new Lights(), pieces = [], rime = [];+ let t = 0, locked = false, cracked = false, burst = false;+ const level = (t) => H * (1 - ease.outCubic(clamp(t / LOCK))); // the frost line, mask row++ // the burst: every facet flies as one piece of ice, carrying its own pixels+ function shatter() {+ const cells = new Map();+ for (let y = 0; y < H; y++)+ for (let x = 0; x < W; x++) {+ const k = ice[y * W + x];+ if (k < 0) continue;+ if (!cells.has(k)) cells.set(k, []);+ const i = y * W + x;+ cells.get(k).push([x, y, solid[i] ? col[i] : mix(col[i], glass[i], 0.3)]);}- if (fr > 0) p.glow(0, -10, 18, C[5], 0.2 * fr);- return;+ for (const px of cells.values()) {+ let cx = 0, cy = 0;+ for (const [x, y] of px) (cx += x + 0.5), (cy += y + 0.5);+ (cx /= px.length), (cy /= px.length);+ const map = new Map(), r = Math.max(...px.map(([x, y]) => Math.hypot(x + 0.5 - cx, y + 0.5 - cy))) + 1;+ for (const [x, y, c] of px) map.set(`${Math.round(x + 0.5 - cx)},${Math.round(y + 0.5 - cy)}`, c);+ const dx = cx - IX, dy = cy - IY, d = Math.hypot(dx, dy) || 1, sp = R.range(55, 115);+ const life = R.range(1.3, 1.85);+ pieces.push({ id: pieces.length + 1, x: X0 + cx, y: Y0 + cy, vx: (dx / d) * sp + R.range(-18, 18), vy: (dy / d) * sp * 0.6 - R.range(110, 220), a: 0, va: R.range(-9, 9), r, map, life, max: life, rest: false, n: px.length });+ }+ for (let i = 0; i < 64; i++) {+ const a = -Math.PI / 2 + R.range(-1.45, 1.45), sp = R.range(60, 180);+ bits.add({ kind: B.SHARD, x: X0 + IX + R.range(-6, 6), y: Y0 + IY + R.range(-8, 8), vx: Math.cos(a) * sp, vy: Math.sin(a) * sp, g: 0.85, drag: 0.6, bounce: 0.3, life: R.range(0.9, 1.6), a: R.range(0, TAU), va: R.range(-20, 20), s: R.range(1.5, 3.2), c: R.pick([C[7], C[6], C[5]]) });+ }+ for (let i = 0; i < 14; i++) ps.spawn(P.VAPOUR, R.range(-10, 10), -R.range(1, 20), R.sign() * R.range(20, 80), -R.range(4, 20), R.range(0.6, 1.1), R.chance(0.5) ? C[6] : C[5], R.range(2.5, 4.5));+ for (let i = 0; i < 16; i++) ps.spawn(P.STAR, R.range(-16, 16), -R.range(4, 38), R.range(-40, 40), -R.range(10, 60), R.range(0.4, 1), R.pick([WHITE, C[6]]), R.range(1, 2.4));+ lights.add(0, Y0 + IY, 46, WHITE, 0.75, 0.14);+ lights.add(0, Y0 + IY, 70, C[4], 0.6, 0.5);}- 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));- });++ return {+ update(dt) {+ t += dt;+ // the cold climbs: rime sparkles at the frost line, vapour rolls off the feet+ if (t < LOCK) {+ const y = Y0 + level(t);+ if (R.chance(0.7)) ps.spawn(P.STAR, R.range(-10, 10), y, R.range(-12, 12), -R.range(0, 18), R.range(0.25, 0.5), R.chance(0.5) ? WHITE : C[6], R.range(0.8, 1.8));+ if (R.chance(0.25)) ps.spawn(P.VAPOUR, R.range(-8, 8), -1, R.sign() * R.range(15, 50), -R.range(2, 10), R.range(0.6, 1), C[6], R.range(2, 3.5));+ }+ if (!locked && t >= LOCK) {+ locked = true;+ lights.add(0, -20, 54, C[4], 0.6, 0.3);+ for (let i = 0; i < 6; i++) ps.spawn(P.STAR, R.range(-12, 12), -R.range(4, 36), 0, -4, R.range(0.35, 0.7), R.pick([WHITE, C[6]]), R.range(1.2, 2.4));+ }+ if (locked && t < CRACK && R.chance(0.08)) ps.spawn(P.STAR, R.range(-11, 11), -R.range(2, 36), 0, -3, R.range(0.3, 0.6), R.pick([WHITE, C[6]]), R.range(0.8, 2));+ if (!cracked && t >= CRACK) {+ cracked = true;+ for (let i = 0; i < 5; i++) {+ const a = R.range(0, TAU), sp = R.range(60, 150);+ bits.add({ kind: B.SHARD, x: X0 + IX, y: Y0 + IY, vx: Math.cos(a) * sp, vy: Math.sin(a) * sp - 60, g: 0.8, drag: 0.6, bounce: 0.3, life: R.range(0.5, 0.9), a: R.range(0, TAU), va: R.range(-20, 20), s: R.range(1, 2), c: C[6] });+ }+ lights.add(0, Y0 + IY, 24, WHITE, 0.7, 0.1);+ }+ if (!burst && t >= BURST) {+ burst = true;+ shatter();+ }+ // the pieces: tumble, bounce, skid to a stop, melt+ for (let i = pieces.length - 1; i >= 0; i--) {+ const q = pieces[i];+ if ((q.life -= dt) <= 0) {+ pieces.splice(i, 1);+ continue;+ }+ if (q.rest) {+ if (t < meta.duration - 0.9 && R.chance(0.02)) ps.spawn(P.VAPOUR, q.x, q.y - 1, R.range(-4, 4), -R.range(4, 10), R.range(0.5, 0.8), C[5], R.range(1.5, 2.5));+ continue;+ }+ q.vy += 900 * dt;+ q.vx -= q.vx * 0.5 * dt;+ q.x += q.vx * dt;+ q.y += q.vy * dt;+ q.a += q.va * dt;+ const g = -q.r * 0.55;+ if (q.y > g && q.vy > 0) {+ q.y = g;+ if (q.vy > 90) {+ rime.push({ x: q.x, w: 2 + q.r * 0.6, t0: t });+ q.vy *= -0.32;+ q.vx *= 0.65;+ q.va = q.va * 0.5 + R.range(-4, 4);+ if (q.n > 8) ps.spawn(P.STAR, q.x, q.y, 0, -6, 0.3, WHITE, 1.2);+ for (let j = 0; j < 2; j++) ps.spawn(P.DUST, q.x + R.range(-2, 2), -0.5, R.sign() * R.range(10, 30), -R.range(2, 8), R.range(0.3, 0.5), C[5], R.range(1.2, 2));+ } else if (Math.abs(q.vx) > 12) (q.vy = 0), (q.vx *= 0.9), (q.va *= 0.85);+ else (q.rest = true), (q.vx = q.vy = 0);+ }+ }+ bits.update(dt);+ ps.update(dt);+ lights.update(dt);+ },+ drawBack(p) {+ // frost on the floor under the feet, spreading as the ice locks, gone as the pieces melt+ const k = smooth(0.1, LOCK, t) * (1 - smooth(BURST + 0.6, BURST + 1.6, t)), reach = 6 + 12 * smooth(0, LOCK + 0.3, t);+ if (k > 0)+ for (let x = Math.floor(-reach); x <= Math.ceil(reach); x++) {+ const h = rand(x, 17), e = 1 - Math.abs(x) / (reach + 1);+ p.dot(x, 0, h < 0.3 ? WHITE : C[6], k * Math.min(1, e * 2));+ if (h < 0.5) p.dot(x, 1, C[5], k * e);+ if (h < 0.35 && e > 0.3) p.dot(x, -1, C[6], k * e);+ }+ if (k > 0) p.glow(0, -2, 26, C[4], 0.25 * k);+ // rime left where the pieces hit the floor+ for (const r of rime) {+ const a = clamp((t - r.t0) / 0.08) * (1 - smooth(meta.duration - 1, meta.duration - 0.15, t));+ for (let x = Math.floor(r.x - r.w); x <= r.x + r.w; x++) {+ const h = rand(x, 23);+ if (h < 0.7) p.dot(x, 0, h < 0.25 ? WHITE : C[6], a);+ if (h < 0.3) p.dot(x, 1, C[5], a * 0.7);+ }+ }+ ps.draw(p, "back");+ },+ draw(p) {+ if (!burst) {+ // the ice body: everything below the frost line, a white rime edge at the line itself+ const lv = level(t), shake = t > CRACK && t < BURST ? (Math.floor(t * 50) % 2 ? 1 : -1) * (t > BURST - 0.15 ? 1 : 0.5) : 0;+ const glint = t > LOCK ? ((t - LOCK) * 0.9) % 1.6 : -1;+ for (let y = 0; y < H; y++) {+ if (y < Math.floor(lv)) continue;+ for (let x = 0; x < W; x++) {+ const i = y * W + x;+ if (ice[i] < 0) continue;+ let c = y === Math.floor(lv) && t < LOCK ? (rand(x, 5) < 0.6 ? WHITE : C[6]) : t >= LOCK && t < LOCK + 0.05 ? WHITE : col[i];+ // a glint runs diagonally across the ice+ const g = Math.abs((x + (H - y) * 0.6) / (W + H * 0.6) - glint), on = glint >= 0 && glint <= 1;+ if (on && g < 0.035) c = WHITE;+ else if (on && g < 0.07 && c !== C[3]) c = C[6];+ p.px(X0 + x + shake, Y0 + y, c);+ if (!solid[i] && c === col[i]) p.blend(X0 + x + shake, Y0 + y, glass[i], 0.3);+ }+ }+ // the dark outline that holds the ice together against the floor and the dark+ for (let y = Math.max(0, Math.floor(lv) - 1); y <= H; y++)+ for (let x = -1; x <= W; x++) if (!at(x, y) && (at(x - 1, y) || at(x + 1, y) || (at(x, y + 1) && y + 1 >= lv) || at(x, y - 1)) && y < H) p.px(X0 + x + shake, Y0 + y, C[0]);+ for (const s of spikes) {+ const g = ease.outBack(clamp((t - s.at) / 0.12), 2.4);+ if (g > 0) crystal(p, s.x + shake, s.base, s.h * g, s.w, s.lean * g, C, { white: t < s.at + 0.04 });+ }+ if (cracked) {+ const k = clamp((t - CRACK) / 0.25);+ for (const pts of cracks)+ for (let i = 0, n = Math.floor(pts.length * k); i < n; i++) {+ const [x, y] = pts[i], fresh = i > n - 3 && t - CRACK < 0.3;+ p.px(X0 + x + shake, Y0 + y, fresh ? WHITE : C[7]);+ if (!fresh) p.px(X0 + x + shake, Y0 + y + 1, C[1]);+ }+ }+ // cold light from the ice, a flash as it locks+ p.glow(0, -18, 30, C[4], 0.18 * smooth(0, LOCK, t));+ if (t > LOCK && t < LOCK + 0.18) sparkle(p, -4, Y0 + 8, Math.round(8 * (1 - (t - LOCK) / 0.18)), WHITE, C[5], 0.6);+ } else if (t < BURST + 0.08) {+ // the burst frame+ const k = (t - BURST) / 0.08;+ p.circle(X0 + IX, Y0 + IY, 10 * (1 - k) + 3, WHITE);+ }+ // the pieces: each drawn back from its own little map, so they turn without holes+ for (const q of pieces) {+ const ca = Math.cos(q.a), sa = Math.sin(q.a), fade = Math.min(1, q.life / 0.5), r = Math.ceil(q.r);+ for (let py = -r; py <= r; py++)+ for (let px = -r; px <= r; px++) {+ const ux = Math.round(px * ca + py * sa), uy = Math.round(-px * sa + py * ca), c = q.map.get(`${ux},${uy}`);+ // a melting piece loses pixels at random rather than dithering away+ if (c && rand(ux, uy, q.id) < fade) p.px(Math.floor(q.x) + px, Math.floor(q.y) + py, q.max - q.life < 0.05 ? WHITE : c);+ }+ if (q.n > 6) p.glow(q.x, q.y, 6, C[5], 0.2 * fade);+ }+ bits.draw(p);+ ps.draw(p, "front");+ lights.draw(p);+ },+ };}diff --git a/src/fx/spawn/skull-pop.js b/src/fx/spawn/skull-pop.jsdeleted file mode 100644index 87b8e9b..0000000--- a/src/fx/spawn/skull-pop.js+++ /dev/null@@ -1,60 +0,0 @@-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.jsindex 3883692..71e4e5e 100644--- a/src/fx/spawn/soul-rise.js+++ b/src/fx/spawn/soul-rise.js@@ -1,59 +1,140 @@-import { ramp, at, cycle, stream, seg, ease, bump, stockActor, TAU, WHITE } from "../../core/index.js";-import { actorOf, stretchMask } from "./_lib.js";+// The pale ghost of the body and the motes it sheds follow Sprite Fusion's open-source movement and heal+// (https://www.spritefusion.com/pixel-art-vfx/movement), MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Lights, P, Rng, fit, band, clamp, smooth, ease, rand, WHITE, hex, luma } from "../../core/index.js";+import { bodyOf, rimOf } 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,+ desc: "The body's outline flares and dims, then a pale glowing copy of it lifts out, stretching as its legs melt into a rippling wisp, shedding motes until it thins into light.",+ tags: ["spawn", "death", "soul", "ghost", "spirit", "rise", "light", "one-shot"],+ size: [96, 140],+ origin: [48, 126],+ duration: 3.2,loop: false,fps: 30,bg: "ground",- actor: true,- options: { palette: ["#14203a", "#24406a", "#3c6aa4", "#64a0d8", "#9cd0f4", "#d8f4ff", "#ffffff"], height: 40, seed: 27 },+ actor: 2,+ options: {+ palette: ["#101a33", "#1f3563", "#35609e", "#5c96d4", "#94c8f0", "#d2f0ff", "#ffffff"],+ height: 50,+ 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"]);+const LEAVE = 0.35, TOP = 2.05, GONE = 2.55, SHADOW = hex("#0c0f1e");-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;+export function create(o) {+ const C = fit(o.palette, 7), R = new Rng(o.seed), floor = () => 0;+ const body = bodyOf(o.actor, C), rim = rimOf(body), W = body.w, Hh = body.h, waist = Math.round(Hh * 0.6);+ // the soul is the body's own picture in pale light: each pixel's brightness picks a step of the ramp+ const tone = body.list.map((b) => (b.edge ? 6 : 3 + Math.min(2, Math.floor(luma(b.c) * 3.6))));+ const toneAt = new Int8Array(W * Hh).fill(-1);+ body.list.forEach((b, i) => (toneAt[b.my * W + b.mx] = tone[i]));+ const ps = new Particles({ rng: R, ground: floor, sparks: [WHITE, C[5], C[4], C[3]] }), lights = new Lights();+ let t = 0, left = false;++ // where the soul is: lifted, stretched taller and thinner, swaying; legs melt into a wisp below the waist+ const lift = () => o.height * ease.inOutSine(clamp((t - LEAVE) / (TOP - LEAVE)));+ const stretch = () => 1 + 0.22 * ease.inOutSine(clamp((t - LEAVE) / (TOP - LEAVE)));+ const sway = (row) => Math.sin(t * 3 - row * 0.12) * 2.2 * smooth(LEAVE, LEAVE + 0.5, t);+ const melt = () => smooth(LEAVE + 0.1, LEAVE + 0.9, t);+ // it thins from the bottom up once it's high+ const thin = () => smooth(TOP - 0.25, GONE, t);++ // a ring of light across the floor as it tears loose: far half behind the body, near half in front+ const ring = (p, near) => {+ const k = (t - LEAVE) / 0.5;+ if (k > 0 && k < 1) band(p, 0, 0, 6 + 26 * ease.outCubic(k), 0.18, Math.max(1, 3 * (1 - k)), 1.15 - k, C, (g) => (Math.sin(g) >= 0) === near, k < 0.12);+ };++ return {+ update(dt) {+ t += dt;+ if (!left && t >= LEAVE) {+ left = true;+ lights.add(0, -20, 50, C[4], 0.85, 0.55);+ lights.add(0, -20, 24, WHITE, 0.8, 0.12);+ for (let i = 0; i < 10; i++) {+ const c = R.pick(rim);+ ps.spawn(P.STAR, c.x, c.y, R.range(-20, 20), -R.range(20, 60), R.range(0.4, 0.8), R.pick([WHITE, C[5]]), R.range(0.8, 1.8));+ }+ }+ // motes come off its edges as it rises, and pour off it as it thins+ if (t > LEAVE && t < GONE) {+ const s = stretch(), y0 = body.y * s - lift(), th = thin();+ for (let n = 0; n < (th > 0 ? 3 : 1); n++) {+ if (!R.chance(th > 0 ? 0.9 : 0.5)) continue;+ const c = R.pick(rim), row = c.my;+ if (row / Hh < 1 - th * 1.1 - 0.05 && th > 0) continue;+ const x = c.x * (1 - 0.12 * (s - 1) * 4) + sway(row), y = y0 + c.my * s;+ // nothing outlives the effect, and nothing climbs off the top+ const life = Math.min(R.range(0.5, 1.1), meta.duration - 0.1 - t, (y + 120) / 60);+ if (life > 0.1) ps.spawn(R.chance(0.7) ? P.MOTE : P.STAR, x, y, R.range(-12, 12), -R.range(25, 60), life, R.pick([WHITE, C[5], C[5], C[4]]), R.range(0.5, 1));+ }}- 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));+ ps.update(dt);+ lights.update(dt);+ },+ drawBack(p) {+ // a pale pool on the floor while it leaves, and a ring from the moment it tears loose+ const k = smooth(0, LEAVE, t) * (1 - smooth(LEAVE + 0.4, TOP, t));+ if (k > 0) p.glow(0, -1, 26, C[4], 0.3 * k);+ ring(p, false);+ },+ draw(p) {+ // the body: its outline flares as the soul tears loose, then the body is left dimmed+ if (t < LEAVE + 0.3) {+ const k = t < LEAVE ? t / LEAVE : 1 - (t - LEAVE) / 0.3;+ for (const c of rim) if (rand(c.mx, c.my, Math.floor(t * 30)) < 0.25 + 0.7 * k) p.px(c.x, c.y, k > 0.7 ? WHITE : C[5]);+ p.glow(0, -19, 26, C[4], 0.45 * k);+ }+ const dim = smooth(LEAVE, LEAVE + 0.6, t) * (1 - smooth(GONE, meta.duration - 0.1, t));+ if (dim > 0) for (const b of body.list) p.blend(b.x, b.y, SHADOW, 0.45 * dim);+ ring(p, true);+ if (t < LEAVE || t > GONE + 0.1) {+ ps.draw(p);+ lights.draw(p);+ return;+ }+ // the soul, drawn backward from the screen so stretching leaves no holes; see-through, its rim solid+ const s = stretch(), L = lift(), m = melt(), th = thin(), top = body.y * s - L, sx = 1 - 0.12 * (s - 1) * 4;+ const tail = Math.round(10 * m), y1 = top + (Hh + tail) * s, fadeIn = clamp((t - LEAVE) / 0.15);+ for (let y = Math.floor(top); y <= Math.ceil(y1); y++) {+ const my = Math.floor((y + 0.5 - top) / s);+ if (my < 0) continue;+ // rows below the waist pull in toward a wavy spine: legs melting into a wisp+ const k = my >= waist ? (my - waist + 1) / (Hh - waist + tail) : 0, narrow = 1 - k * m * 0.95;+ if (narrow <= 0.05) continue;+ const cx = sway(my) + Math.sin(my * 0.7 - t * 8) * 2 * k * m, a = (my >= waist ? 1 - k * 0.45 : 1) * fadeIn;+ for (let x = Math.floor(cx - W / 2 - 4); x <= Math.ceil(cx + W / 2 + 4); x++) {+ const mx = Math.floor((x + 0.5 - cx) / (sx * narrow) - body.x);+ // as it thins the lower rows go first, with a ragged edge+ if (th > 0 && my / (Hh + tail) > 1 - th * 1.25 + 0.25 * rand(mx, my, 5) - 0.1) continue;+ let ti;+ if (my < Hh) {+ if (mx < 0 || mx >= W) continue;+ ti = toneAt[my * W + mx];+ if (ti < 0) continue;+ } else {+ // the wisp below the feet: a thin trail that tapers to nothing+ const w = (1 - (my - Hh) / Math.max(1, tail)) * 3.2 * m, d = Math.abs(x + 0.5 - cx);+ if (d > w) continue;+ ti = d > w - 1 ? 5 : 4;+ }+ // the first frames it tears loose it is all white+ if (t < LEAVE + 0.07) p.px(x, y, ti >= 6 ? C[5] : WHITE);+ else if (ti >= 5) p.dot(x, y, ti >= 6 ? WHITE : C[5], Math.min(1, a * 1.3));+ else p.blend(x, y, C[ti], a * 0.7);+ }+ }+ // its light+ const cy = top + Hh * s * 0.45;+ p.glow(sway(10), cy, 30, C[4], 0.42 * fadeIn * (1 - th));+ p.glow(sway(10), cy - 6, 14, C[5], 0.3 * fadeIn * (1 - th));+ ps.draw(p);+ lights.draw(p);+ },+ };}++export const actorAlpha = () => 1;diff --git a/src/fx/spawn/spawn-portal.js b/src/fx/spawn/spawn-portal.jsindex 1b9f322..c713099 100644--- a/src/fx/spawn/spawn-portal.js+++ b/src/fx/spawn/spawn-portal.js@@ -1,64 +1,285 @@-import { PAL, ramp, at, burst, fly, seg, ease, fract, clamp, TAU, WHITE } from "../../core/index.js";-import { smoke, steps } from "./_lib.js";+// The streaks pulled in, the rings and lights at the burst and the collapse pop are adapted from Sprite+// Fusion's open-source black-hole (https://www.spritefusion.com/pixel-art-vfx/black-hole),+// MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Bits, Lights, P, PF, B, Rng, fit, band, sparkle, flare, clamp, smooth, ease, noise, TAU, WHITE, hex, mix } from "../../core/index.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,+ desc: "A rift tears open on the floor and swirls, belches violet smoke and sparks, spits a fountain of wisps up out of itself, then twists shut with a pop.",+ tags: ["spawn", "portal", "summon", "rift", "arcane", "smoke", "ground", "one-shot"],+ size: [208, 150],+ origin: [104, 122],+ duration: 3.8,loop: false,fps: 30,bg: "ground",- options: { palette: PAL.arcane, width: 17, seed: 31 },+ options: {+ palette: ["#12081f", "#2a0f4d", "#481b8c", "#7330d0", "#a35cff", "#cf9bff", "#f1dcff", "#ffffff"],+ width: 28,+ seed: 6,+ },};-const OPEN = [0, 0.3], PUFF = 0.3, SHUT = [1.05, 1.3];+const OPEN = 0.3, BELCH = [0.52, 0.76], BURST = 1.0, SHUT = 1.9, POP = 2.22, SY = 0.34;+const VOID = hex("#06030b"), FUME = hex("#3a3046"), STONE = ["#1a1424", "#2b2639", "#4a4263", "#6c6488", "#9a91b4"].map(hex), DUST = hex("#5a5070");-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 rift's size over its life: a tear that snaps open past round, breathes, swells as it shuts, then collapses+function radius(t, RX) {+ if (t < OPEN) return RX * ease.outBack(clamp(t / OPEN), 2.2);+ if (t < SHUT) return RX * (1 + 0.035 * Math.sin(t * 9) + 0.1 * Math.exp(-((t - BURST - 0.05) ** 2) / 0.006));+ const k = clamp((t - SHUT) / (POP - SHUT));+ return RX * (k < 0.35 ? 1 + 0.1 * Math.sin((k / 0.35) * Math.PI * 0.5) : 1.1 * (1 - Math.pow((k - 0.35) / 0.65, 1.6)));+}+// how far the swirl has turned: lazy, then whipping round as it shuts+const spinAt = (t) => t * 2.4 + 1.5 * smooth(BURST - 0.1, BURST + 0.3, t) + 10 * Math.pow(clamp((t - SHUT) / (POP - SHUT)), 2.2);+const lipAt = (th, spin) => 1 + 0.05 * noise(th * 3 + spin * 0.6, 5) + 0.035 * noise(th * 8 - spin * 1.3, 9);++// the hole: a void, a lit far wall, three arms of light spiralling down into it+function hole(p, C, rx, spin, heat, wind = 2.3) {+ if (rx < 1) return;+ const ry = rx * SY;+ p.shade(-rx - 2, -ry - 2, rx + 2, ry + 2, (x, y, out) => {+ const u = x / rx, v = y / ry, q = Math.hypot(u, v), th = Math.atan2(v, u), lip = lipAt(th, spin);+ if (q > lip) return;+ const w = q / lip;+ // the far inner wall catches the glow from below; the near one is hidden+ out.c = v < 0 && w > 0.72 ? (w > 0.86 ? C[2] : C[1]) : w > 0.55 ? C[0] : VOID;});- // 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);+ const n = Math.max(40, Math.round(rx * 5));+ for (let i = 0; i < 3; i++)+ for (let j = 0; j <= n; j++) {+ const q = 0.14 + 0.82 * (j / n), th = spin + (i * TAU) / 3 - wind * Math.log(q), lip = lipAt(th, spin);+ const x = Math.cos(th) * q * lip * rx, y = Math.sin(th) * q * lip * ry;+ const c = q > 0.8 ? (heat > 1.1 ? WHITE : C[6]) : q > 0.55 ? C[5] : q > 0.32 ? C[4] : C[3];+ p.dot(x, y, c, q > 0.3 ? 1 : q / 0.3);+ // a fainter strand riding just inside each arm+ if (q > 0.4 && j % 2 === 0) {+ const t2 = th - 0.32, x2 = Math.cos(t2) * q * 0.94 * lip * rx, y2 = Math.sin(t2) * q * 0.94 * lip * ry;+ p.dot(x2, y2, q > 0.7 ? C[4] : C[3], 0.85);+ }+ }+ p.glow(0, 0, rx * 0.45, C[3], 0.35 * heat);+}++// the lip: a ragged ring of white-hot light, a dark cut outside it; far half behind, near half in front+function lip(p, C, rx, spin, heat, near) {+ if (rx < 1) return;+ const ry = rx * SY, n = Math.ceil(rx * 7);+ for (let j = 0; j < n; j++) {+ const th = (j / n) * TAU, s = Math.sin(th);+ if ((s >= 0) !== near) continue;+ const l = lipAt(th, spin), x = Math.cos(th) * rx * l, y = s * ry * l, f = noise(th * 9 + spin * 3, 13);+ p.dot(Math.cos(th) * (rx * l + 1.2), s * (ry * l + 1), C[1]);+ p.dot(x, y, near ? (f > -0.3 || heat > 1.1 ? WHITE : C[6]) : f > 0.2 ? C[6] : C[5]);+ if (j % 6 === 0) p.glow(x, y, 7, C[5], (near ? 0.3 : 0.2) * Math.min(1.4, heat));+ }+}++export function create(o) {+ const C = fit(o.palette, 8), RX = o.width, R = new Rng(o.seed), floor = () => 0;+ // violet smoke, dulled toward a smoky grey so it reads as smoke and not as glass+ const SM = [mix(C[4], FUME, 0.4), mix(C[3], FUME, 0.3), mix(C[5], FUME, 0.55)];+ const ps = new Particles({ rng: R, ground: floor, sparks: [C[7], C[6], C[5], C[3]] });+ const rocks = new Bits({ ground: floor }), lights = new Lights();+ const swirl = [], wisps = [], rings = [];+ const done = {};+ let t = 0;++ // a mote riding the swirl on the floor plane, spiralling in+ const addSwirl = (r0) => swirl.push({ a: R.range(0, TAU), r: r0, w: R.range(2.2, 4), in: R.range(0.3, 0.7), c: R.pick([WHITE, C[6], C[6], C[5]]) });+ // a streak of light sucked in from the air round the rift+ const pull = () => {+ const a = R.range(Math.PI * 1.03, Math.PI * 1.97), D = R.range(40, 86), T = R.range(0.24, 0.42);+ const x = Math.cos(a) * D * 1.08, y = Math.sin(a) * D * 0.85, l = Math.hypot(x, y), v = (0.6 * l) / (1 - Math.exp(-0.6 * T));+ ps.spawn(P.MOTE, x, y, (-x / l) * v, (-y / l) * v, T, R.pick([WHITE, C[6], C[5], C[5], C[4]]), R.range(1, 1.7));+ };+ const puff = (n, big, sp) => {+ for (let i = 0; i < n; i++) {+ const a = R.range(0, TAU), d = R.range(0, 0.55) * RX;+ ps.spawn(P.SMOKE, Math.cos(a) * d, Math.sin(a) * d * SY - 2, R.range(-1, 1) * sp * 0.6, -R.range(0.4, 1) * sp, R.range(1.2, 2.2) * (big ? 1.15 : 0.8), R.pick(SM), R.range(2.8, 4.6) * (big ? 1.15 : 0.9), big ? R.range(0, 0.3) : R.range(0, 0.1), big ? PF.BIG : 0);+ }+ };+ const sparks = (n, up, spread) => {+ for (let i = 0; i < n; i++) {+ const a = -Math.PI / 2 + R.range(-spread, spread), sp = R.range(0.5, 1) * up;+ ps.spawn(P.SPARK, R.range(-0.5, 0.5) * RX, -1, Math.cos(a) * sp, Math.sin(a) * sp, R.range(0.35, 0.8));+ }+ };+ const once = (k, at) => !done[k] && t >= at && (done[k] = true);++ return {+ update(dt) {+ t += dt;+ // the tear pulls dust and light in while it opens, while it's open, and hard while it shuts+ const shutting = t > SHUT && t < POP;+ if ((t < OPEN + 0.15 || shutting) && R.chance(0.55)) {+ const s = R.sign(), D = R.range(RX * 1.3, RX * 2.4), T = R.range(0.18, 0.3), v = (D * 3) / (Math.exp(3 * T) - 1);+ ps.spawn(P.STREAK, s * D, -R.range(0, 3), -s * v, R.range(-2, 2), T, R.chance(0.5) ? C[6] : C[5]);+ }+ if (t > 0.1 && t < POP - 0.1 && R.chance(shutting ? 0.85 : t < BURST ? 0.55 : 0.1)) pull();+ if (t < POP && t > 0.12 && R.chance(shutting ? 0.5 : 0.25)) addSwirl(R.range(1.1, 1.5));+ if (once("open", OPEN * 0.7)) {+ lights.add(0, -8, 50, C[4], 0.75, 0.45);+ rings.push({ t0: t, life: 0.42, r0: RX * 0.8, r1: RX * 1.9, th: 2.5, hot: true });+ for (let i = 0; i < 8; i++) ps.spawn(P.DUST, R.sign() * R.range(0.7, 1.1) * RX, -1, R.sign() * R.range(10, 45), -R.range(4, 14), R.range(0.4, 0.7), DUST, R.range(1.5, 3));+ }+ // two small belches before the big one: a burp of smoke and a few sparks+ if (once("b0", BELCH[0])) puff(6, false, 34), sparks(8, 210, 0.55), lights.add(0, -6, 44, C[4], 0.6, 0.3);+ if (once("b1", BELCH[1])) puff(8, false, 40), sparks(12, 240, 0.6), lights.add(0, -6, 48, C[4], 0.65, 0.3);+ // the burst: something comes up through it+ if (once("burst", BURST)) {+ lights.add(0, -26, 74, C[4], 1, 0.75);+ lights.add(0, -10, 40, WHITE, 0.85, 0.14);+ rings.push({ t0: t, life: 0.55, r0: RX * 1.0, r1: RX * 2.5, th: 3.5, hot: true }, { t0: t + 0.06, life: 0.45, r0: RX * 0.8, r1: RX * 1.8, th: 2, hot: false });+ puff(18, true, 70);+ sparks(34, 400, 0.8);+ for (let i = 0; i < 5; i++) {+ const a = -Math.PI / 2 + (i - 2) * 0.27 + R.range(-0.08, 0.08), sp = R.range(185, 235);+ wisps.push({ x: R.range(-4, 4), y: -2, vx: Math.cos(a) * sp, vy: Math.sin(a) * sp, life: R.range(0.75, 1.0), max: 1, tr: [], acc: 0, ph: R.range(0, TAU) });+ }+ for (let i = 0; i < 12; i++)+ rocks.add({ kind: B.CHUNK, x: R.sign() * R.range(0.75, 1.05) * RX, y: -1, vx: R.range(-100, 100), vy: -R.range(150, 280), g: 1, drag: 0.4, bounce: 0.3, life: R.range(1.3, 1.9), a: R.range(0, TAU), va: R.range(-14, 14), s: R.range(1, 2.4), ramp: STONE });+ for (let i = 0; i < 14; i++) ps.spawn(P.STAR, R.range(-0.8, 0.8) * RX, -R.range(4, 34), R.range(-30, 30), -R.range(10, 60), R.range(0.5, 1.1), R.pick([WHITE, C[6], C[5]]), R.range(0.8, 2));+ }+ // while it's open it keeps venting thin smoke and the odd spark+ if (t > OPEN && t < SHUT && R.chance(0.16)) puff(1, false, 22);+ if (t > OPEN && t < SHUT + 0.1 && R.chance(0.06)) sparks(1, 160, 0.4);+ // the pop when it closes+ if (once("pop", POP)) {+ lights.add(0, -4, 50, C[4], 0.95, 0.5);+ lights.add(0, -2, 28, WHITE, 0.9, 0.12);+ rings.push({ t0: t, life: 0.35, r0: 2, r1: RX * 1.9, th: 2.5, hot: true });+ for (let i = 0; i < 18; i++) {+ const a = R.range(-Math.PI, 0), sp = R.range(90, 270);+ ps.spawn(P.SPARK, 0, -1, Math.cos(a) * sp, Math.sin(a) * sp * 0.8, R.range(0.25, 0.6));+ }+ for (let i = 0; i < 9; i++) {+ const a = R.range(0, TAU), sp = R.range(30, 95);+ ps.spawn(P.STAR, 0, -2, Math.cos(a) * sp, Math.sin(a) * sp * 0.5 - 20, R.range(0.4, 0.9), R.pick([WHITE, C[6]]), R.range(0.8, 1.8));+ }+ for (let i = 0; i < 6; i++) ps.spawn(P.SMOKE, R.range(-6, 6), -R.range(1, 4), R.range(-34, 34), -R.range(10, 30), R.range(0.8, 1.3), SM[2], R.range(2.5, 4.5));+ // what's left on the floor: specks of light that twinkle out where the rift was+ for (let i = 0; i < 14; i++) ps.spawn(P.STAR, R.range(-1, 1) * RX * 0.9, -R.range(0.5, 2), R.range(-4, 4), -R.range(0, 4), R.range(0.6, 1.4), R.pick([C[6], C[5], C[5]]), R.range(0.4, 0.9), R.range(0, 0.25));+ }+ for (let i = swirl.length - 1; i >= 0; i--) {+ const s = swirl[i], k = shutting ? 2.4 : 1;+ s.a += s.w * k * dt * (1.4 / Math.max(0.3, s.r));+ s.r -= s.in * k * dt;+ if (s.r < 0.25 || t > POP) swirl.splice(i, 1);+ }+ // the wisps: comets with smoky tails that arc up and out, then burst+ for (let i = wisps.length - 1; i >= 0; i--) {+ const w = wisps[i];+ w.tr.unshift([w.x, w.y]);+ if (w.tr.length > 12) w.tr.pop();+ // a wisp bursts when it runs out or comes down on the floor+ if ((w.life -= dt) <= 0 || (w.vy > 0 && w.y > -2)) {+ for (let j = 0; j < 8; j++) {+ const a = R.range(0, TAU), sp = R.range(30, 120);+ ps.spawn(P.SPARK, w.x, w.y, Math.cos(a) * sp + w.vx * 0.2, Math.sin(a) * sp + w.vy * 0.2, R.range(0.2, 0.5));+ }+ ps.spawn(P.STAR, w.x, w.y, 0, -6, 0.45, WHITE, 2.4);+ lights.add(w.x, w.y, 24, C[5], 0.65, 0.25);+ wisps.splice(i, 1);+ continue;+ }+ w.vy += 360 * dt;+ w.vx += Math.sin((w.max - w.life) * 16 + w.ph) * 160 * dt;+ w.vx -= w.vx * 1.1 * dt;+ w.vy -= w.vy * 1.1 * dt;+ w.x += w.vx * dt;+ w.y += w.vy * dt;+ for (w.acc += dt; w.acc > 0.03; w.acc -= 0.03) ps.spawn(P.SMOKE, w.x, w.y, w.vx * 0.05, w.vy * 0.05 - 4, R.range(0.6, 1), SM[0], R.range(1.5, 2.4));+ if (R.chance(0.3)) ps.spawn(P.MOTE, w.x, w.y, -w.vx * 0.2 + R.range(-15, 15), -w.vy * 0.2 + R.range(-15, 15), R.range(0.2, 0.4), C[6], 0.6);+ }+ for (let i = rings.length - 1; i >= 0; i--) if (t - rings[i].t0 > rings[i].life) rings.splice(i, 1);+ rocks.update(dt);+ for (const b of rocks.list)+ if (b.rest && !b.dusted) {+ b.dusted = true;+ for (let i = 0; i < 2; i++) ps.spawn(P.DUST, b.x + R.range(-1.5, 1.5), -0.5, R.sign() * R.range(6, 30), -R.range(2, 12), R.range(0.3, 0.6), DUST, R.range(1.2, 2.4));+ }+ ps.update(dt);+ lights.update(dt);+ },+ drawBack(p) {+ const rx = radius(t, RX), spin = spinAt(t), heat = 0.85 + 0.15 * Math.sin(t * 7) + 0.6 * Math.exp(-((t - BURST) ** 2) / 0.01);+ // the floor glows violet round the hole+ if (t < POP) {+ p.glow(0, -4, rx * 1.8 + 10, C[4], 0.32 * clamp(rx / RX));+ // and light wells up out of it into the air+ p.glowLine(0, -2, 0, -44, rx * 0.7 + 6, C[4], 0.16 * clamp(rx / RX));+ }+ // the slit it tears open from+ if (t < OPEN * 0.6) {+ const k = t / (OPEN * 0.6), L = RX * 1.1 * ease.outCubic(k);+ p.line(-L, 0, L, 0, (u) => (Math.abs(u - 0.5) < 0.3 ? WHITE : C[6]));+ p.glowLine(-L, 0, L, 0, 7, C[5], 0.6);+ }+ if (t > OPEN * 0.35 && t < POP) {+ // the arms wind tighter as it twists shut+ hole(p, C, rx, spin, heat + 0.4 * smooth(SHUT, POP, t), 2.3 + 2.6 * smooth(SHUT, POP - 0.05, t));+ lip(p, C, rx, spin, heat, false);+ }+ for (const r of rings) ring(p, C, r, t, false);+ drawSwirl(p, false);+ ps.draw(p, "back");+ },+ draw(p) {+ const rx = radius(t, RX), spin = spinAt(t), heat = 0.85 + 0.15 * Math.sin(t * 7) + 0.6 * Math.exp(-((t - BURST) ** 2) / 0.01);+ if (t > OPEN * 0.35 && t < POP) lip(p, C, rx, spin, heat, true);+ for (const r of rings) ring(p, C, r, t, true);+ drawSwirl(p, true);+ // the burst: a column of light shoots up out of the hole, thins and lifts away+ const b = t - BURST;+ if (b > 0 && b < 0.45) {+ const k = b / 0.45, top = -84 * ease.outExpo(clamp(b / 0.14)), bot = -1 - 60 * ease.inQuad(k), w0 = RX * 0.55 * (1 - k * 0.8);+ p.shade(-w0 - 1, top, w0 + 1, bot, (x, y, out) => {+ const u = (y - bot) / (top - bot), half = w0 * Math.pow(1 - u, 0.8) * (0.85 + 0.15 * Math.sin(y * 0.7 + t * 40));+ const d = Math.abs(x) / Math.max(0.5, half);+ if (d > 1) return;+ out.c = d < 0.35 ? WHITE : d < 0.7 ? C[6] : C[5];+ });+ p.glowLine(0, bot, 0, top, w0 + 12, C[5], 0.55 * (1 - k));+ if (b < 0.14) flare(p, 0, -4, 36 * (1 - b / 0.14), 1 - b / 0.14, C);+ }+ // the collapse: a white point that pops+ const q = t - POP;+ if (q > -0.08 && q < 0.25) sparkle(p, 0, -1, Math.round((q < 0 ? 4 : 12) * (1 - clamp(q / 0.25))), WHITE, C[5], 0.7 * (1 - clamp(q / 0.25)));+ rocks.draw(p);+ for (const w of wisps) {+ const k = w.life / w.max;+ for (let i = 1; i < w.tr.length; i++) {+ const [x0, y0] = w.tr[i - 1], [x1, y1] = w.tr[i], u = i / w.tr.length;+ p.line(x0, y0, x1, y1, u < 0.25 ? WHITE : u < 0.55 ? C[6] : C[4], 1.15 - u);+ if (u < 0.35) p.line(x0 + 1, y0, x1 + 1, y1, C[5], 1);+ }+ p.circle(w.x, w.y, 2, C[5]);+ p.circle(w.x, w.y, 1.2, C[6]);+ p.px(w.x, w.y, WHITE);+ p.glow(w.x, w.y, 12, C[5], 0.5 * k + 0.2);+ }+ ps.draw(p, "front");+ lights.draw(p);+ },+ };++ function drawSwirl(p, near) {+ const rx = radius(t, RX);+ for (const s of swirl) {+ for (let j = 0; j < 3; j++) {+ const a = s.a - j * 0.08 * (1.4 / Math.max(0.3, s.r)), x = Math.cos(a) * s.r * rx, y = Math.sin(a) * s.r * rx * SY;+ if ((Math.sin(a) >= 0) !== near) continue;+ p.dot(x, y - 0.5, j ? C[5] : s.c, j ? 0.9 - j * 0.3 : 1);+ if (!j) p.glow(x, y, 3, C[5], 0.35);+ }+ }}- // 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));+}++// a shock ring on the floor plane: far half behind, near half in front+function ring(p, C, r, t, near) {+ const k = (t - r.t0) / r.life;+ if (k < 0 || k >= 1) return;+ band(p, 0, 0, r.r0 + (r.r1 - r.r0) * ease.outCubic(k), SY * 0.62, Math.max(1, r.th * (1 - k)), 1.15 - k, C, (g) => (Math.sin(g) >= 0) === near, r.hot && k < 0.15);}diff --git a/src/fx/spawn/summon-rise.js b/src/fx/spawn/summon-rise.jsindex cfd76b0..aede4ab 100644--- a/src/fx/spawn/summon-rise.js+++ b/src/fx/spawn/summon-rise.js@@ -1,97 +1,412 @@-import { PAL, RAMP, ramp, at, burst, fly, seg, ease, bump, rand, TAU, WHITE, hex } from "../../core/index.js";-import { smoke, onCanvas } from "./_lib.js";+// The rubble, dust, grit, embers and smoke recipe is adapted from Sprite Fusion's open-source explosion+// (https://www.spritefusion.com/pixel-art-vfx/explosion), MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Bits, Lights, P, PF, B, Rng, fit, clamp, smooth, ease, noise, rand, TAU, WHITE, hex, mix } from "../../core/index.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,+ desc: "A rune circle burns into the floor, the ground bursts, and a horned brute heaves up out of it through dust and rubble, lit from below, until its eyes flare.",+ tags: ["spawn", "summon", "demon", "rise", "runes", "dust", "rubble", "ground", "one-shot"],+ size: [176, 116],+ origin: [88, 94],+ duration: 4.6,loop: false,fps: 30,bg: "ground",- options: { palette: PAL.lava, seed: 32 },+ options: {+ palette: ["#1a0608", "#3d0c0c", "#7a1a10", "#c0381a", "#f06a1e", "#ffae3a", "#ffe08a", "#ffffff"],+ body: ["#060409", "#0e0913", "#170f1e", "#211628", "#2d2036"],+ horn: ["#0c080c", "#201820", "#352a32", "#4e3f48", "#6e5c64"],+ stone: ["#1a1424", "#2b2639", "#4a4263", "#6c6488", "#9a91b4"],+ seed: 9,+ },};-// 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];+const SOOT = hex("#2a1e2a"), IGN = 0.5, RUNES = 0.78, BREAK = 1.05, EYES = 2.3, FADE = 3.4, SY = 0.3, R0 = 36, R1 = 27;-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));+// the brute, built part by part so overlapping forms keep their own edges. Parts front to back: 1 head,+// 2 horns, 3 arms, 4 shoulders, 5 chest, 6 waist, 7 legs, 8 tail. Each pixel keeps the frontmost part over it, that+// part's surface direction (from its own blurred shape), and whether it sits on a crease over a part behind.+const PARTS = ["head", "horns", "arms", "shoulders", "chest", "waist", "legs", "tail"];+function beast() {+ const W = 46, H = 46, N = W * H, C = 22.5, parts = PARTS.map(() => new Uint8Array(N));+ let cur;+ const put = (x, y) => {+ x = Math.round(x), y = Math.round(y);+ if (x >= 0 && y >= 0 && x < W && y < H) cur[y * W + x] = 1;+ };+ const ell = (cx, cy, rx, ry) => {+ for (let y = Math.floor(cy - ry); y <= Math.ceil(cy + ry); y++)+ for (let x = Math.floor(cx - rx); x <= Math.ceil(cx + rx); x++) {+ const dx = (x + 0.5 - cx) / rx, dy = (y + 0.5 - cy) / ry;+ if (dx * dx + dy * dy <= 1) put(x, y);+ }+ };+ const stroke = (pts, r0, r1) => {+ const L = [];+ let total = 0;+ for (let i = 1; i < pts.length; i++) total += L[i - 1] = Math.hypot(pts[i][0] - pts[i - 1][0], pts[i][1] - pts[i - 1][1]);+ for (let i = 1, acc = 0; i < pts.length; acc += L[i - 1], i++) {+ const n = Math.ceil(L[i - 1] * 3) + 1;+ for (let j = 0; j <= n; j++) {+ const u = j / n, r = r0 + (r1 - r0) * ((acc + L[i - 1] * u) / total);+ ell(pts[i - 1][0] + (pts[i][0] - pts[i - 1][0]) * u, pts[i - 1][1] + (pts[i][1] - pts[i - 1][1]) * u, r, r);+ }}- p.glow(0, 0, 26, at(C, 0.55), 0.35 * rune * hot);+ };+ const [HEAD, HORNS, ARMS, SHOULDERS, CHEST, WAIST, LEGS, TAIL] = parts;+ for (const s of [-1, 1]) {+ const X = (d) => C + s * d;+ cur = HORNS;+ stroke([[X(4), 11], [X(8), 8], [X(12), 6.5], [X(15), 4], [X(16), 1.5], [X(15.2), 0]], 2.3, 0.45);+ cur = SHOULDERS;+ ell(X(10), 16, 7, 5);+ ell(X(8.5), 19.5, 5.5, 4.2);+ cur = ARMS;+ stroke([[X(14.5), 16.5], [X(17.5), 22], [X(18.5), 28]], 4, 3.2);+ stroke([[X(18.5), 28], [X(19), 33], [X(19.2), 36.5]], 3.4, 2.8);+ ell(X(19.2), 37.8, 3, 2.3);+ stroke([[X(17.2), 39], [X(16.6), 41.8]], 0.9, 0.4);+ stroke([[X(19.2), 39.5], [X(19.3), 42.6]], 0.9, 0.4);+ stroke([[X(21.2), 38.8], [X(22), 41.4]], 0.9, 0.4);+ cur = LEGS;+ stroke([[X(5.5), 31], [X(8), 37], [X(7.5), 42]], 4, 3);+ ell(X(8.5), 44.3, 4.2, 1.7);}- // 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);+ cur = TAIL;+ stroke([[C, 30], [C + 0.5, 36], [C + 2.5, 41.5], [C + 7, 44.6], [C + 12.5, 44.2], [C + 14.5, 42.5]], 2.3, 0.6);+ cur = CHEST;+ ell(C, 22.5, 8.2, 7.5);+ cur = WAIST;+ ell(C, 29.5, 6.2, 4.5);+ cur = HEAD;+ ell(C, 12.5, 5.2, 4.6);+ ell(C, 16, 4.2, 2.8);+ const part = new Uint8Array(N);+ for (let i = 0; i < N; i++) for (let k = 0; k < parts.length; k++) if (parts[k][i]) { part[i] = k + 1; break; }+ const on = (x, y) => x >= 0 && y >= 0 && x < W && y < H && part[y * W + x] > 0;+ // surface direction per part: the gradient of the part blurred on its own+ const blur = (src) => {+ let a = Float32Array.from(src), b = new Float32Array(N);+ for (let pass = 0; pass < 2; pass++) {+ for (let y = 0; y < H; y++)+ for (let x = 0; x < W; x++) {+ let s = 0;+ for (let d = -2; d <= 2; d++) s += x + d >= 0 && x + d < W ? a[y * W + x + d] : 0;+ b[y * W + x] = s / 5;+ }+ for (let y = 0; y < H; y++)+ for (let x = 0; x < W; x++) {+ let s = 0;+ for (let d = -2; d <= 2; d++) s += y + d >= 0 && y + d < H ? b[(y + d) * W + x] : 0;+ a[y * W + x] = s / 5;+ }+ }+ return a;+ };+ const amb = new Float32Array(N), down = new Float32Array(N), rim = new Float32Array(N), crease = new Uint8Array(N);+ parts.forEach((pm, k) => {+ const B = blur(pm), at = (x, y) => (x >= 0 && y >= 0 && x < W && y < H ? B[y * W + x] : 0);+ for (let y = 0; y < H; y++)+ for (let x = 0; x < W; x++) {+ const i = y * W + x;+ if (part[i] !== k + 1) continue;+ const gx = at(x + 1, y) - at(x - 1, y), gy = at(x, y + 1) - at(x, y - 1), g = Math.hypot(gx, gy) || 1e-6;+ const ox = -gx / g, oy = -gy / g, e = clamp(g / 0.28);+ // a dim cool light from above and the left rounds each form; undersides fall into shadow+ amb[i] = 0.42 + e * (0.4 * Math.max(0, -oy) + 0.14 * Math.max(0, -ox) - 0.3 * Math.max(0, oy) - 0.08 * Math.max(0, ox));+ // less light reaches up into the gap between the legs, so it doesn't read as a lit doorway+ down[i] = e * Math.max(0, oy) * (Math.abs(x + 0.5 - C) < 7 && y > 27 ? 0.3 : 1);+ // a crease where this part's edge lies over a part behind it+ for (const [dx, dy] of [[1, 0], [-1, 0], [0, 1], [0, -1]]) {+ const j = (y + dy) * W + x + dx;+ if (on(x + dx, y + dy) && part[j] > k + 1) crease[i] = 1;+ }}+ });+ // the underlight's rim: the bottom of the whole silhouette, two pixels deep; less in the gap between the legs+ for (let y = 0; y < H; y++)+ for (let x = 0; x < W; x++) {+ if (!on(x, y)) continue;+ const k = !on(x, y + 1) ? 1 : !on(x, y + 2) ? 0.5 : 0;+ rim[y * W + x] = Math.abs(x + 0.5 - C) < 7 && y > 27 ? k * 0.3 : k;}- // 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);+ const outline = [];+ for (let y = -1; y <= H; y++)+ for (let x = -1; x <= W; x++) if (!on(x, y) && (on(x - 1, y) || on(x + 1, y) || on(x, y - 1) || on(x, y + 1))) outline.push([x, y]);+ const eyes = [], tusks = [];+ for (const s of [-1, 1]) {+ eyes.push([Math.round(C + s * 2.2 - 0.5), 12], [Math.round(C + s * 3.2 - 0.5), 12]);+ tusks.push([Math.round(C + s * 3.4 - 0.5), 16], [Math.round(C + s * 3.6 - 0.5), 15]);}- // 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]);- });+ return { w: W, h: H, part, amb, down, rim, crease, outline, eyes, tusks, glints: [[Math.round(C - 2.7 - 0.5) - W / 2, 12 - H], [Math.round(C + 2.7 - 0.5) - W / 2, 12 - H]] };+}+const BEAST = beast();++// rune glyphs: little strokes in (along, across) units, set round the circle between its two rings+const GLYPHS = [+ [[[0, -2], [0, 2]], [[-1.5, -1], [1.5, 1]]],+ [[[-1.5, 2], [0, -2], [1.5, 2]], [[-0.8, 0.4], [0.8, 0.4]]],+ [[[-1.5, -2], [-1.5, 2], [1.5, 2]], [[0, -2], [1.5, -0.5]]],+ [[[0, -2], [0, 2]], [[0, -2], [1.6, -0.6], [0, 0.6]]],+ [[[-1.5, -2], [1.5, 2]], [[1.5, -2], [-1.5, 2]], [[-1.5, 0], [1.5, 0]]],+ [[[-1.4, -2], [1.4, -2], [-1.4, 2], [1.4, 2]]],+];++export function create(o) {+ const C = fit(o.palette, 8), SH = fit(o.body, 5), HR = fit(o.horn, 5), ST = fit(o.stone, 5), DUST = mix(ST[2], hex("#7a6c78"), 0.45), R = new Rng(o.seed), floor = () => 0;+ const ps = new Particles({ rng: R, ground: floor, sparks: [C[6], C[5], C[4], C[3]] });+ // rubble: the floor's own stone, its faces lit warm by the fire underneath+ const RUB = [ST[0], ST[1], mix(ST[2], C[2], 0.3), mix(ST[3], C[4], 0.3), mix(ST[4], C[5], 0.35)];+ const rocks = new Bits({ ground: floor }), lights = new Lights();+ const runes = Array.from({ length: 12 }, (_, i) => ({ a: (i / 12) * TAU + 0.13, g: GLYPHS[(i * 5 + 2) % GLYPHS.length] }));+ // cracks radiating from the middle of the circle, on the floor plane+ const cracks = [];+ for (let i = 0; i < 7; i++) {+ let a = (i / 7) * TAU + R.range(-0.25, 0.25), r = 3;+ const pts = [[0, 0]];+ const len = R.range(R1 * 0.6, R1 * 1.05);+ while (r < len) {+ r += R.range(2, 4);+ a += R.range(-0.3, 0.3);+ pts.push([Math.cos(a) * r, Math.sin(a) * r * SY]);+ }+ cracks.push(pts);+ }+ // the rise: two heaves with a sag between, a little overshoot at the top+ const rise = (t) => {+ if (t < BREAK) return 0;+ const a = ease.outCubic(clamp((t - BREAK) / 0.4)) * 0.56, sag = 0.04 * Math.sin(Math.PI * clamp((t - BREAK - 0.42) / 0.3));+ const b = ease.outBack(clamp((t - BREAK - 0.62) / 0.45), 1.4) * 0.44;+ return a - sag + b;+ };+ // the circle's fire: lights up, flares at the break and when the eyes open, dies in the fade+ const heat = (t) => smooth(0, IGN, t) * (1 - smooth(FADE, FADE + 0.8, t)) * (1 - 0.25 * smooth(EYES + 0.2, EYES + 0.9, t)) * (0.85 + 0.15 * noise(t * 9, 3) + 0.5 * Math.exp(-((t - BREAK) ** 2) / 0.02) + 0.3 * Math.exp(-((t - EYES) ** 2) / 0.01));+ let t = 0;+ const done = {};+ // a life that ends before the effect does+ const left = (a, b) => Math.max(0.05, Math.min(R.range(a, b), meta.duration - 0.1 - t));+ const once = (k, at) => !done[k] && t >= at && (done[k] = true);+ const topEdge = () => {+ const off = BEAST.h * (1 - rise(t)), pts = [];+ for (let x = 0; x < BEAST.w; x++)+ for (let y = 0; y < BEAST.h; y++)+ if (BEAST.part[y * BEAST.w + x]) {+ const ly = y - BEAST.h + off;+ if (ly < 0) pts.push([x - BEAST.w / 2, ly]);+ break;+ }+ return pts;+ };++ return {+ update(dt) {+ t += dt;+ const h = heat(t);+ // the rings smoulder: embers and thin smoke off the lines, sparks at the burning front+ if (t < IGN) {+ const ph = (t / IGN) * Math.PI;+ for (const s of [-1, 1]) {+ const a = Math.PI / 2 + s * ph;+ const y = Math.sin(a) * R0 * SY;+ if (R.chance(0.5)) y < -0.5 ? ps.spawn(P.SPARK, Math.cos(a) * R0, y, R.range(-40, 40), -R.range(40, 130), R.range(0.2, 0.45)) : ps.spawn(P.EMBER, Math.cos(a) * R0, y, R.range(-20, 20), -R.range(30, 70), R.range(0.3, 0.6), C[6], 1.4);+ }+ }+ if (t > 0.2 && t < FADE + 0.6 && R.chance(0.2 * h)) {+ const a = R.range(0, TAU), r = R.pick([R0, R1, R0]);+ ps.spawn(P.EMBER, Math.cos(a) * r, Math.sin(a) * r * SY, R.range(-10, 10), -R.range(20, 50), left(0.8, 1.6), C[5], R.range(1, 1.8));+ }+ if (t > 0.15 && R.chance(0.4 * Math.min(1, h))) {+ const a = R.range(0, TAU), r = R.chance(0.7) ? R0 : R1;+ if (t < IGN ? Math.abs(((a - Math.PI / 2 + Math.PI * 3) % TAU) - Math.PI) < (t / IGN) * Math.PI : true)+ ps.spawn(P.FIRE, Math.cos(a) * r, Math.sin(a) * r * SY - 0.5, R.range(-4, 4), -R.range(6, 16), R.range(0.18, 0.4), 0, R.range(0.8, 1.6) * Math.min(1, h), 0, R.chance(0.25) ? PF.SMOKES : 0);+ }+ if (t > 0.3 && t < FADE + 0.4 && R.chance(0.05 * h)) {+ const a = R.range(0, TAU);+ ps.spawn(P.SMOKE, Math.cos(a) * R0 * 0.9, Math.sin(a) * R0 * SY - 1, R.range(-4, 4), -R.range(12, 24), left(1.4, 2.2), 0, R.range(2.2, 3.4));+ }+ if (once("ign", IGN)) lights.add(0, -4, 60, C[4], 0.55, 0.5);+ if (once("runes", RUNES)) lights.add(0, -4, 50, C[5], 0.5, 0.35);+ // the rumble: grit jumps on the floor, dust stirs+ if (t > RUNES && t < BREAK && R.chance(0.35)) ps.spawn(P.GRIT, R.range(-R1, R1), -0.5, R.range(-20, 20), -R.range(40, 120), R.range(0.5, 0.9), R.pick([ST[2], ST[3], ST[4]]), 1);+ if (t > RUNES && t < BREAK && R.chance(0.1)) ps.spawn(P.DUST, R.range(-R1, R1), -1, R.range(-12, 12), -R.range(4, 12), R.range(0.4, 0.7), DUST, R.range(1.5, 2.5));+ // the break: the floor bursts open+ if (once("break", BREAK)) {+ lights.add(0, -18, 64, C[4], 0.9, 0.6);+ lights.add(0, -8, 26, C[6], 0.8, 0.14);+ for (let i = 0; i < 18; i++)+ rocks.add({ kind: B.CHUNK, x: R.range(-14, 14), y: -2, vx: R.range(-75, 75), vy: -R.range(170, 320), g: 1, drag: 0.7, bounce: 0.32, life: R.range(1.6, 2.4), a: R.range(0, TAU), va: R.range(-14, 14), s: R.range(1.3, 3), ramp: RUB });+ for (let i = 0; i < 60; i++) {+ const u = R.range(-1, 1), a = -Math.PI / 2 + u * 0.7, sp = R.range(80, 230) * (1 - 0.4 * Math.abs(u));+ ps.spawn(P.GRIT, u * 10, -1, Math.cos(a) * sp, Math.sin(a) * sp, R.range(1, 1.8), R.pick([ST[2], ST[3], ST[3], ST[4]]), R.chance(0.4) ? 2 : 1);+ }+ for (let i = 0; i < 12; i++) {+ const s = R.sign();+ ps.spawn(P.SMOKE, s * R.range(2, 14), -R.range(1, 5), s * R.range(35, 100), -R.range(4, 24), R.range(1.2, 2), DUST, R.range(3.5, 6), R.range(0, 0.1), PF.BIG);+ }+ for (let i = 0; i < 4; i++) {+ const s = R.sign();+ ps.spawn(P.SMOKE, s * R.range(10, 18), -R.range(2, 8), s * R.range(10, 30), -R.range(40, 90), R.range(1.4, 2.2), DUST, R.range(4, 6.5), R.range(0, 0.12), PF.BIG);+ }+ for (let i = 0; i < 24; i++) {+ const a = -Math.PI / 2 + R.range(-1.1, 1.1), sp = R.range(150, 360);+ ps.spawn(P.SPARK, R.range(-6, 6), -2, Math.cos(a) * sp, Math.sin(a) * sp, R.range(0.25, 0.65));+ }+ }+ // the heave: earth slides off its shoulders, dust rolls out round its feet+ const rv = rise(t) - rise(t - dt);+ if (t > BREAK && t < BREAK + 1.2 && rv > 0) {+ if (R.chance(Math.min(0.9, rv * 140))) {+ const e = topEdge();+ if (e.length) {+ const [x, y] = R.pick(e);+ ps.spawn(P.GRIT, x, y, R.range(-25, 25), -R.range(10, 60), R.range(0.8, 1.4), R.pick([ST[2], ST[3], ST[4]]), R.chance(0.3) ? 2 : 1);+ }+ }+ if (R.chance(Math.min(0.8, rv * 70))) {+ const s = R.sign();+ ps.spawn(P.SMOKE, s * R.range(10, 22), -R.range(1, 4), s * R.range(30, 80), -R.range(2, 12), R.range(1, 1.8), DUST, R.range(3, 5.5), 0, PF.BIG);+ }+ }+ if (once("heave2", BREAK + 0.64)) {+ lights.add(0, -10, 56, C[4], 0.6, 0.4);+ for (let i = 0; i < 8; i++)+ rocks.add({ kind: B.CHUNK, x: R.sign() * R.range(10, 22), y: -2, vx: R.sign() * R.range(25, 70), vy: -R.range(90, 180), g: 1, drag: 0.7, bounce: 0.3, life: R.range(1.2, 1.8), a: R.range(0, TAU), va: R.range(-12, 12), s: R.range(1.2, 2.4), ramp: RUB });+ }+ // the eyes flare+ if (once("eyes", EYES)) {+ for (const [ex, ey] of BEAST.glints) {+ lights.add(ex, ey, 14, C[6], 0.7, 0.3);+ for (let i = 0; i < 5; i++) ps.spawn(P.SPARK, ex, ey, R.range(-90, 90), R.range(-90, 20), R.range(0.15, 0.35));+ }+ for (let i = 0; i < 10; i++) {+ const s = R.sign();+ ps.spawn(P.DUST, s * R.range(8, 20), -1, s * R.range(30, 80), -R.range(3, 10), R.range(0.4, 0.8), DUST, R.range(1.5, 3));+ }+ }+ if (t > FADE + 0.05 && t < FADE + 0.75 && R.chance(0.45)) {+ const x = R.int(4, BEAST.w - 5), y = R.int(2, BEAST.h - 4);+ if (BEAST.part[y * BEAST.w + x]) {+ const lx = x - BEAST.w / 2, ly = y - BEAST.h;+ ps.spawn(P.SMOKE, lx, ly, R.range(-6, 6), -R.range(10, 26), left(0.9, 1.5), SOOT, R.range(2, 3.4));+ if (R.chance(0.3)) ps.spawn(P.EMBER, lx, ly, R.range(-10, 10), -R.range(15, 40), left(0.6, 1.2), C[4], 1);+ }+ }+ rocks.update(dt);+ for (const b of rocks.list)+ if (b.rest && !b.dusted) {+ b.dusted = true;+ for (let i = 0; i < 2; i++) ps.spawn(P.DUST, b.x + R.range(-1.5, 1.5), -0.5, R.sign() * R.range(6, 30), -R.range(2, 12), R.range(0.3, 0.6), DUST, R.range(1.2, 2.4));+ }+ ps.update(dt);+ lights.update(dt);+ },+ drawBack(p) {+ const h = heat(t);+ if (h <= 0.01) return;+ // the warm pool on the floor+ p.glow(0, -2, 52, C[4], 0.28 * h);+ p.glow(0, -22, 72, C[4], 0.1 * h);+ p.glow(0, -1, 22, C[5], 0.2 * h);+ // the cracks open under it and glow+ const ck = smooth(RUNES, BREAK, t) * (1 - smooth(FADE, FADE + 0.7, t));+ if (ck > 0)+ for (const pts of cracks)+ for (let i = 1; i < pts.length; i++) {+ const u = i / pts.length;+ if (u > ck * 1.1) break;+ const cool = smooth(BREAK + 0.1, BREAK + 1.1, t), ci = Math.round(6 - u * 2 - cool * 2.6);+ p.line(pts[i - 1][0], pts[i - 1][1], pts[i][0], pts[i][1], C[clamp(ci, 2, 6)], 1);+ }+ // the rings: burnt in from the front round to the back, flickering+ const n = 220, prog = clamp(t / IGN) * Math.PI;+ for (let j = 0; j < n; j++) {+ const a = (j / n) * TAU, d = Math.abs(((a - Math.PI / 2 + Math.PI * 3) % TAU) - Math.PI);+ if (d > prog) continue;+ const fresh = prog - d < 0.25 && t < IGN + 0.1, f = noise(a * 6 + t * 5, 4) * 0.5 + 0.5, k = h * (0.7 + 0.5 * f);+ const ca = Math.cos(a), sa = Math.sin(a);+ p.dot(ca * R0, sa * R0 * SY, fresh ? WHITE : k > 0.95 ? C[6] : k > 0.6 ? C[5] : k > 0.35 ? C[4] : C[3]);+ p.dot(ca * (R0 + 2.2), sa * (R0 + 2.2) * SY, k > 0.8 ? C[4] : C[3], 0.9);+ if (t > RUNES - 0.15) p.dot(ca * R1, sa * R1 * SY, k > 0.9 ? C[5] : k > 0.5 ? C[4] : C[3], smooth(RUNES - 0.15, RUNES + 0.05, t));+ if (j % 11 === 0) p.glow(ca * R0, sa * R0 * SY, 9, C[4], 0.22 * k);+ }+ // the runes between the rings+ const rk = smooth(RUNES - 0.1, RUNES + 0.15, t);+ if (rk > 0)+ for (const r of runes) {+ const k = h * rk * (0.75 + 0.35 * noise(t * 4 + r.a * 5, 8)), mid = (R0 + R1) / 2 + 0.5, ta = [-Math.sin(r.a), Math.cos(r.a)], na = [Math.cos(r.a), Math.sin(r.a)];+ const proj = ([u, v]) => [(na[0] * mid + ta[0] * u * 1.1 + na[0] * v) , (na[1] * mid + ta[1] * u * 1.1 + na[1] * v) * SY];+ for (const stroke of r.g)+ for (let i = 1; i < stroke.length; i++) {+ const [x0, y0] = proj(stroke[i - 1]), [x1, y1] = proj(stroke[i]);+ p.line(x0, y0, x1, y1, k > 0.9 ? C[6] : k > 0.55 ? C[5] : C[4], Math.min(1, k * 1.5));+ }+ }+ // the hole the brute climbs out of: a glowing gash+ const hole = smooth(BREAK - 0.05, BREAK + 0.15, t) * (1 - smooth(BREAK + 0.95, BREAK + 1.5, t));+ if (hole > 0) {+ const hw = 15 * hole;+ p.shade(-hw - 1, -1, hw + 1, 4, (x, y, out) => {+ const d = Math.hypot(x / hw, (y - 0.5) / 3.2);+ if (d > 1) return;+ out.c = d > 0.86 ? C[4] : d > 0.62 ? C[1] : C[0];+ });+ p.glow(0, 0, 24, C[5], 0.3 * hole * h);+ }+ ps.draw(p, "back");+ },+ draw(p) {+ const r = rise(t), off = BEAST.h * (1 - r), h = heat(t), fade = smooth(FADE + 0.1, FADE + 0.8, t);+ if (r > 0) {+ const W = BEAST.w, H = BEAST.h, x0 = -W / 2, oy = off - H, k = Math.min(1, h);+ const gone = (x, y) => fade > 0 && fade > 0.06 + 0.86 * (0.55 * (1 - y / H) + 0.45 * rand(x, y, 3));+ // a dark edge all round, so the bulk reads against the night+ for (const [x, y] of BEAST.outline) if (y + oy < 0 && !gone(x, Math.min(H - 1, Math.max(0, y)))) p.px(x0 + x, y + oy, SH[0]);+ for (let y = 0; y < H; y++) {+ const ly = y + oy;+ if (ly >= 0) break;+ // the fire below lights the undersides: rims strongest by the floor, broad planes higher up+ const upRim = Math.exp(ly / 17) * k, upPlane = Math.exp(ly / 19) * k;+ for (let x = 0; x < W; x++) {+ const i = y * W + x, pt = BEAST.part[i];+ if (!pt || gone(x, y)) continue;+ const ramp = pt === 2 ? HR : SH, a = BEAST.amb[i];+ let si = BEAST.crease[i] ? 0 : a > 0.74 ? 4 : a > 0.56 ? 3 : a > 0.36 ? 2 : 1;+ if (pt === 2 && si > 0) si = Math.min(4, si + (y < 3 ? 2 : 1)); // horns are paler, tips palest+ // rims can run hot; the broad planes only ever warm up to deep red+ const Lr = BEAST.rim[i] * upRim, Lp = BEAST.down[i] * upPlane * 0.6;+ let c = ramp[si];+ if (Lr > 0.7) c = C[5];+ else if (Lr > 0.48) c = C[4];+ else if (Lr > 0.3 || Lp > 0.42) c = C[3];+ else if (Lr > 0.17 || Lp > 0.26) c = mix(C[2], ramp[si], 0.3);+ else if (Lr > 0.08 || Lp > 0.12) c = mix(ramp[si], C[1], 0.6);+ p.px(x0 + x, ly, c);+ }+ }+ // tusks catch the light; the eye sockets smoulder until the eyes open+ for (const [x, y] of BEAST.tusks) if (y + oy < 0 && !gone(x, y)) p.px(x0 + x, y + oy, mix(HR[4], C[4], 0.35 * k));+ for (const [x, y] of BEAST.eyes) if (y + oy < 0 && !gone(x, y)) p.px(x0 + x, y + oy, t > EYES - 0.05 ? (t < EYES + 0.1 ? WHITE : C[6]) : t > BREAK + 0.5 ? C[2] : SH[0]);+ // the eyes: a flare as they open, then a steady burn that outlasts the body+ if (t > EYES - 0.05) {+ const k = (1 - smooth(FADE + 0.6, FADE + 1.0, t)) * (0.85 + 0.15 * Math.sin(t * 13));+ for (const [ex, ey0] of BEAST.glints) {+ const ey = ey0 + off;+ if (ey >= 0) continue;+ p.glow(ex + 0.5, ey, 6, C[5], 0.5 * k);+ const g = (t - EYES) / 0.3;+ if (g > 0 && g < 1) {+ const L = 9 * Math.pow(1 - g, 1.5);+ p.line(ex - L, ey, ex + L, ey, (u) => (Math.abs(u - 0.5) < 0.18 ? WHITE : Math.abs(u - 0.5) < 0.35 ? C[6] : C[5]));+ if (g < 0.4) p.line(ex, ey - 2 * (1 - g), ex, ey + 2 * (1 - g), C[6]);+ } else if (fade > 0.6 && k > 0.05) p.px(ex, ey, C[6]);+ }+ }+ // the light that rakes up its front+ p.glow(0, -6, 30, C[4], 0.25 * h * r);+ }+ rocks.draw(p);+ ps.draw(p, "front");+ lights.draw(p);+ },+ };}diff --git a/src/fx/spawn/teleport-sparkle.js b/src/fx/spawn/teleport-sparkle.jsdeleted file mode 100644index 5a0e364..0000000--- a/src/fx/spawn/teleport-sparkle.js+++ /dev/null@@ -1,69 +0,0 @@-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.jsindex b6b1903..bc624f2 100644--- a/src/fx/status/_lib.js+++ b/src/fx/status/_lib.js@@ -1,81 +1,255 @@-// Shared bits for the status effects (files starting with _ are helpers, not effects).+// Shared by the status effects (files starting with _ are helpers, not effects): the character's shape, noise+// that loops, and the toolkit's flame, smoke and ember particles drawn from their age alone, so loops stay seamless.+// The flame tongue, flame puff, smoke and ember recipes are+// adapted from Sprite Fusion's open-source fire (https://www.spritefusion.com/pixel-art-vfx/fire),+// MIT License, Copyright (c) 2026 Hugo Duprez.+// The shaded, outlined icons are+// adapted from Sprite Fusion's open-source heal (https://www.spritefusion.com/pixel-art-vfx/heal),+// MIT License, Copyright (c) 2026 Hugo Duprez.-import { ramp, luma, clamp } from "../../core/index.js";+import { rand, wrap, mix, luma, WHITE, SMOKE_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))]);-}--const GEOM = new WeakMap();-const M = 14; // how far around the mask the geometry reaches+const SHAPES = new WeakMap();/**- * 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).+ * The character's shape, worked out once per mask, in mask space (0, 0 = its top-left): `on(x, y)`, `body`+ * ([x, y] of every pixel), `up` (pixels with nothing above them: where flames stand), `side` ([x, y, dir] of+ * pixels open to the left (-1) or right (1)), `outline` ([x, y, nx, ny]: empty cells touching it, with the+ * outward normal), `top` (each column's first row, -1 if empty) and `rows` ([left, right] of each row).*/-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;+export function shape(a) {+ const m = a.mask;+ let s = SHAPES.get(m);+ if (s) return s;+ const { w, h, data } = m, on = (x, y) => x >= 0 && y >= 0 && x < w && y < h && data[y * w + x] > 0;+ const body = [], up = [], side = [], outline = [], top = [], rows = [];+ for (let x = 0; x < w; x++) {+ let y = 0;+ while (y < h && !on(x, y)) y++;+ top.push(y < h ? y : -1);+ }+ for (let y = 0; y < h; y++) {+ let l = -1, r = -1;+ for (let x = 0; x < w; x++) {+ if (!on(x, y)) continue;+ if (l < 0) l = x;+ r = x;+ body.push([x, y]);+ if (!on(x, y - 1)) up.push([x, y]);+ if (!on(x - 1, y)) side.push([x, y, -1]);+ if (!on(x + 1, y)) side.push([x, y, 1]);}- const outline = [], rim = [], top = [];+ rows.push([l, r]);+ }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]);+ if (on(x, y)) continue;+ let nx = 0, ny = 0;+ for (let dy = -1; dy <= 1; dy++) for (let dx = -1; dx <= 1; dx++) if (on(x + dx, y + dy)) (nx -= dx), (ny -= dy);+ if (on(x - 1, y) || on(x + 1, y) || on(x, y - 1) || on(x, y + 1)) {+ const l = Math.hypot(nx, ny) || 1;+ outline.push([x, y, nx / l, ny / l]);+ }+ }+ s = { w, h, on, body, up, side, outline, top, rows };+ SHAPES.set(m, s);+ return s;+}++/** The character's own color at mask pixel (x, y), or a mid grey for a mask without pixels. */+export const colorAt = (a, x, y) => (a.pixels ? a.pixels[y * a.mask.w + x] : a.mask.data[y * a.mask.w + x] ? 0xff6b6b6b : 0);++/** 1D value noise in [-1, 1] whose lattice wraps every P cells. */+export function wnoise(x, P, seed = 0) {+ const i = Math.floor(x), f = x - i, u = f * f * (3 - 2 * f);+ const a = rand(wrap(i, P), seed), b = rand(wrap(i + 1, P), seed);+ return (a + (b - a) * u) * 2 - 1;+}++/** Noise of time t that repeats every D seconds, about f wiggles a second; off slides along it (ripples). */+export function tnoise(t, D, f, seed = 0, off = 0) {+ const P = Math.max(2, Math.round(f * D));+ return wnoise((t / D) * P + off, P, seed);+}++/** How far something has moved after age a, launched at speed v under acceleration g with linear drag d. */+export const travel = (v, g, d, a) => (d > 0 ? (g / d) * a + ((v - g / d) * (1 - Math.exp(-d * a))) / d : v * a + 0.5 * g * a * a);++// A tongue's nested layers: [width, height, ramp step (0 brightest)]: a deep rim, orange, yellow, a white heart.+export const LAYERS = [[1, 1, 6], [0.76, 0.86, 4], [0.54, 0.68, 2], [0.3, 0.42, 0]];++/**+ * A flame tongue standing on (x, y): h tall, w half-wide at its root, its tip swept sx px sideways, filled in+ * nested layers from F (bright to dark, 9 steps). Rows ripple with noise that loops every D seconds (seed n).+ */+export function tongue(p, x, y, h, w, sx, F, t, D, n, layers = LAYERS) {+ if (h < 1) return;+ for (const [lw, lh, ri] of layers) {+ if (ri === 0 && h < 4) continue;+ const H = h * lh, col = F[ri];+ for (let r = 0; r <= H; r++) {+ const u = r / Math.max(1, H);+ const half = w * lw * Math.pow(1 - u, 0.85) * Math.min(1, (r + 1.5) / 3.5) + tnoise(t, D, 9, n, r * 0.45) * 0.5;+ if (half < 0.3) continue;+ const cx = x + sx * u * u * lh + tnoise(t, D, 4, n + 7, r * 0.2) * u * 1.1;+ for (let px = Math.round(cx - half); px <= Math.round(cx + half); px++) p.px(px, Math.round(y - r), col);}- 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]];- },+}++/** A ball of flame at age u (0..1) of its life, radius size, cooling down F (bright to dark) as it rises. */+export function flame(p, x, y, size, u, F, heatSeed = 0) {+ const n = F.length, k = 1 - u;+ const heat = Math.min(0.999, Math.pow(u, 0.62) + heatSeed * 0.1), idx = Math.min(n - 2, Math.floor(heat * (n - 1)));+ const r = size * (0.55 + 0.45 * Math.min(1, u * 7)) * (1 - u * 0.55), c = F[idx];+ if (idx >= n - 2) return p.disc(x, y, r, c, Math.min(1, k * 3) * 0.85);+ p.circle(x, y, r, F[Math.min(n - 1, idx + 2)]);+ p.circle(x - r * 0.16, y - r * 0.22, r * 0.78, c);+ if (r > 1.6) p.circle(x, y - r * 0.9, r * 0.42, c);+ if (idx <= 3 && r > 1.8) p.circle(x - r * 0.28, y - r * 0.34, r * 0.36, F[Math.max(0, idx - 1)]);+ if (idx < 6) p.glow(x, y, r * 2.4 + 2, c, 0.18 * k);+}++const rampAt = (r, t) => r[Math.min(r.length - 1, Math.max(0, Math.floor(t * r.length)))];++/**+ * A puff of smoke at age u (0..1): three soft discs (a body, a denser core sitting low, a lit cap while young),+ * swelling and thinning, tinted col and walking down the smoke ramp. warm (a color) lights its underside.+ */+export function smoke(p, x, y, size, u, col, k = 1, warm = 0) {+ const r = size * (0.65 + Math.min(1, u * 2.5) * 0.45 + u * 0.4);+ const a = Math.min(1, u * 12) * Math.min(1, (1 - u) * 2.4) * 0.58 * k;+ if (a <= 0.01) return;+ const c = col ? mix(col, rampAt(SMOKE_RAMP, u), u) : rampAt(SMOKE_RAMP, u * 1.05);+ p.disc(x, y, r, c, a * 0.45);+ p.disc(x + r * 0.05, y + r * 0.06, r * 0.74, c, a * 0.62);+ if (warm && u < 0.6) p.disc(x + r * 0.1, y + r * 0.3, r * 0.56, mix(c, warm, 0.5), a * 0.7 * (1 - u / 0.6));+ if (u < 0.5) p.disc(x - r * 0.22, y - r * 0.3, r * 0.5, mix(c, WHITE, 0.12), a * 0.4 * (1 - u * 2));+}++/** An ember at age u: hot and flickering, cooling to a dim red that blinks out. E is [hot, warm, cool]. */+export function ember(p, x, y, u, E, ph, k = 1) {+ const left = 1 - u;+ if (left < 0.22 && Math.sin(ph * 40) < 0) return;+ const c = left > 0.5 ? (Math.sin(ph * 22) > -0.2 ? E[0] : E[1]) : left > 0.22 ? E[1] : E[2];+ p.px(x, y, c);+ p.glow(x, y, 3, c, 0.32 * left * k);+}+++++/** A flat, translucent bank of haze centred on (x, y), rx by ry, thinning to nothing at its edge. */+export function haze(p, x, y, rx, ry, col, a) {+ if (a <= 0.01 || rx < 0.5 || ry < 0.5) return;+ for (let py = Math.floor(y - ry); py <= Math.ceil(y + ry); py++)+ for (let px = Math.floor(x - rx); px <= Math.ceil(x + rx); px++) {+ const dx = (px + 0.5 - x) / rx, dy = (py + 0.5 - y) / ry, d = dx * dx + dy * dy;+ if (d < 1) p.blend(px, py, col, a * (1 - d));+ }+}++/**+ * A shape from a bitmap (rows of strings, "." empty), centred on (0, 0), scaled up by whole k, mirrored if flip:+ * returns inside(dx, dy) giving the bitmap's character there (or "").+ */+export function bitmap(rows, k = 1, flip = false) {+ const h = rows.length, w = rows[0].length, ox = Math.floor((w * k) / 2), oy = Math.floor((h * k) / 2);+ return (dx, dy) => {+ let bx = Math.floor((dx + ox) / k);+ const by = Math.floor((dy + oy) / k);+ if (bx < 0 || by < 0 || bx >= w || by >= h) return "";+ if (flip) bx = w - 1 - bx;+ const c = rows[by][bx];+ return c === "." ? "" : c;};- 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.+ * A little shaded pixel icon at (x, y): every cell where inside(dx, dy) is truthy, within ext of the centre, filled+ * from R = [outline, shadow, body, light] (lit on its top and left edges, shaded on the bottom and right, ringed by+ * the outline) and recoloured where inside returns a character listed in paint ({ e: eyeColor, ... }). a fades it.*/-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);+export function icon(p, x, y, ext, inside, R, a = 1, paint = null) {+ const X = Math.round(x), Y = Math.round(y), at = (dx, dy) => !!inside(dx, dy);+ for (let dy = -ext - 1; dy <= ext + 1; dy++)+ for (let dx = -ext - 1; dx <= ext + 1; dx++) {+ const ch = inside(dx, dy);+ let c;+ if (ch) {+ if (paint && paint[ch] !== undefined) c = paint[ch];+ else {+ const top = !at(dx, dy - 1), left = !at(dx - 1, dy), bottom = !at(dx, dy + 1), right = !at(dx + 1, dy);+ c = top || left ? R[3] : bottom || right ? R[1] : R[2];+ }+ } else if (R[0] && (at(dx - 1, dy) || at(dx + 1, dy) || at(dx, dy - 1) || at(dx, dy + 1))) c = R[0];+ else continue;+ p.dot(X + dx, Y + dy, c, a);}}-/** 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);+/** inside(dx, dy) for a shape given in its own unit space by f(u, v), rotated by ang and scaled by s px. */+export const shaped = (f, s, ang = 0) => {+ const c = Math.cos(ang), n = Math.sin(ang);+ return (dx, dy) => {+ const x = dx + 0.5, y = dy + 0.5;+ return f((x * c + y * n) / s, (-x * n + y * c) / s) ? "#" : "";+ };+};++/** A five-pointed star in unit space (points at radius 1, inner corners at r0). */+export function starShape(r0 = 0.45) {+ return (u, v) => {+ const a = Math.atan2(v, u) + Math.PI / 2, d = Math.hypot(u, v), seg = (2 * Math.PI) / 5;+ const k = 1 - Math.abs((((a % seg) + seg) % seg) - seg / 2) / (seg / 2); // 0 at a point, 1 between two+ return d <= 1 - (1 - r0) * Math.pow(k, 0.8);+ };+}++/** A heart in unit space (two lobes and a point, about 2 wide and 2 tall, centred). */+export const heartShape = (u, v) =>+ (u + 0.5) ** 2 + (v + 0.32) ** 2 <= 0.55 ** 2 || (u - 0.5) ** 2 + (v + 0.32) ** 2 <= 0.55 ** 2 || (v >= -0.32 && v <= 1 && Math.abs(u) <= 1.04 * Math.pow(1 - (v + 0.32) / 1.32, 0.75));++const EYES = new WeakMap();+/**+ * The character's eyes, if it has any we can find: small blobs of very dark pixels (with any white beside them)+ * inside the upper part of the body, surrounded by it. [{ x0, x1, y0, y1, px: [[x, y]...], skin }] in mask+ * space, left to right; skin is the colour round them, to paint them shut with. [] when nothing looks like eyes.+ */+export function eyes(a) {+ let list = EYES.get(a.mask);+ if (list) return list;+ const S = shape(a), W = S.w, col = (x, y) => (S.on(x, y) ? colorAt(a, x, y) : 0);+ const dark = (x, y) => S.on(x, y) && y < S.h * 0.4 && luma(col(x, y)) < 0.15 && S.on(x - 1, y) && S.on(x + 1, y) && S.on(x, y - 1) && S.on(x, y + 1);+ const seen = new Set();+ list = [];+ for (const [x0, y0] of S.body) {+ if (seen.has(y0 * W + x0) || !dark(x0, y0)) continue;+ const px = [], q = [[x0, y0]];+ seen.add(y0 * W + x0);+ while (q.length) {+ const [x, y] = q.pop();+ px.push([x, y]);+ for (const [dx, dy] of [[1, 0], [-1, 0], [0, 1], [0, -1]]) {+ const nx = x + dx, ny = y + dy, k = ny * W + nx;+ if (seen.has(k) || !(dark(nx, ny) || (S.on(nx, ny) && luma(col(nx, ny)) > 0.95))) continue;+ seen.add(k);+ q.push([nx, ny]);+ }+ }+ if (px.length < 2 || px.length > 14) continue;+ const xs = px.map((p) => p[0]), ys = px.map((p) => p[1]), counts = new Map();+ const e = { x0: Math.min(...xs), x1: Math.max(...xs), y0: Math.min(...ys), y1: Math.max(...ys), px };+ for (const [x, y] of px)+ for (const [dx, dy] of [[1, 0], [-1, 0], [0, 1], [0, -1], [2, 0], [-2, 0]]) {+ const c = col(x + dx, y + dy), l = luma(c);+ if (c && l > 0.5 && l < 0.95 && !px.some((p) => p[0] === x + dx && p[1] === y + dy)) counts.set(c, (counts.get(c) ?? 0) + 1);+ }+ e.skin = [...counts].sort((p, q) => q[1] - p[1])[0]?.[0];+ if (e.skin && e.x1 - e.x0 <= 4 && e.y1 - e.y0 <= 5) list.push(e);+ }+ list.sort((p, q) => p.x0 - q.x0);+ if (list.length > 2) list = [];+ EYES.set(a.mask, list);+ return list;+}diff --git a/src/fx/status/bleeding.js b/src/fx/status/bleeding.jsindex 1eb9754..18cbe68 100644--- a/src/fx/status/bleeding.js+++ b/src/fx/status/bleeding.js@@ -1,87 +1,132 @@-import { PAL, cycle, bump, clamp, TAU } from "../../core/index.js";-import { steps, geom, recolor, tone } from "./_lib.js";+// The beads, drops, drying splats and crowns are+// adapted from Sprite Fusion's open-source blood (https://www.spritefusion.com/pixel-art-vfx/blood),+// MIT License, Copyright (c) 2026 Hugo Duprez.+import { fit, rand, smooth } from "../../core/index.js";+import { shape, travel } 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,+ desc: "Bleeding out: beads swell at three wounds, run, let go and fall to spatter into a glossy pool that ripples; each heartbeat spurts a little and flashes the body red.",+ tags: ["status", "bleed", "blood", "dot", "debuff", "wound", "loop"],+ size: [60, 56],+ origin: [30, 46],+ duration: 2.4,loop: true,fps: 30,bg: "ground",- actor: true,- options: { palette: PAL.blood, count: 5, seed: 8 },+ actor: 2,+ options: { palette: ["#350711", "#5e0c1b", "#931327", "#c71e33", "#f2384a", "#ff8a7a"], seed: 5 },};-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+const D = meta.duration, BEAT = D / 2, G = 900;++// the wounds: two on the edges of the arms and one on the front of the body. Blood runs down the body from each+// and beads at the end of the run; drops fall in front of the body to the floor+const WOUNDS = new WeakMap();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;+ let w = WOUNDS.get(a.mask);+ if (w) return w;+ const S = shape(a), H = S.h, W = S.w;+ const make = (mx, my, drops, phase) => {+ let run = 1;+ while (run < 3 && S.on(mx, my + run + 1)) run++;+ return { x: a.x + mx + 0.5, mx, y0: a.y + my, yb: a.y + my + run + 1, drops, phase, side: mx < W / 2 ? -1 : 1 };+ };+ const edge = (q, side) => {+ const my = Math.round(H * q), [l, r] = S.rows[my];+ return [side < 0 ? l + 1 : r - 1, my];+ };+ const front = S.body.filter(([x, y]) => y > H * 0.5 && y < H * 0.62 && x > W * 0.55 && x < W * 0.75 && S.on(x, y + 3))[0] ?? edge(0.55, 1);+ w = [make(...edge(0.57, -1), 3, 0), make(...front, 2, 0.35), make(...edge(0.6, 1), 2, 0.7)];+ WOUNDS.set(a.mask, w);+ return w;}-export function draw(p, t, o) {- const B = steps(o.palette), a = o.actor, S = o.seed, D = meta.duration, ph = t / D;+// a drop in flight: a bead with a tail when it is fast (Hugo's drop)+function drop(p, C, x, y, v, s) {+ const tail = Math.min(5, v * 0.012);+ if (tail >= 1) p.line(x, y - tail, x, y - 1, s >= 2 ? C[3] : C[2]);+ if (s >= 2) {+ p.px(x, y, C[5]);+ p.px(x + 1, y, C[4]);+ p.px(x, y + 1, C[3]);+ p.px(x + 1, y + 1, C[2]);+ } else p.px(x, y, C[4]);+}- // 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));+// a splat where a drop lands: it spreads, throws a crown of droplets, then dries darker and fades+function splat(p, C, x, ground, age, big, seed) {+ const life = D * 0.85;+ if (age < 0 || age > life) return;+ const spread = smooth(0, 0.1, age), hw = (big ? 2.2 : 1.4) * (0.5 + 0.5 * spread), fade = 1 - smooth(life - 0.5, life, age);+ const dry = age < 0.35 ? 4 : age < 1 ? 3 : 2;+ for (let xx = Math.floor(x - hw); xx <= Math.ceil(x + hw); xx++) p.dot(xx, ground - 1, Math.abs(xx + 0.5 - x) > hw * 0.75 ? C[dry - 1] : C[dry], fade);+ if (age < 0.3) p.px(x - 0.5, ground - 1, C[5]);+ // the crown+ if (age < 0.4)+ for (let j = 0; j < (big ? 3 : 2); j++) {+ const vx = (j % 2 ? 1 : -1) * (18 + 24 * rand(seed, j, 1)), vy = -(40 + 40 * rand(seed, j, 2)), tt = age;+ const dx = vx * tt, dy = vy * tt + 0.5 * G * tt * tt;+ if (dy <= 0) p.px(x + dx, ground - 1 + dy, j ? C[3] : C[4]);+ }+}- // 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]);+export function drawBack(p, t, o) {+ const C = fit(o.palette, 6), a = o.actor, W = wounds(a);+ // the pool under the lowest wounds: dark and glossy, a ripple where each drop lands in it+ const px = (W[0].x + W[2].x) / 2 - 1, rx = 6.5, beat = Math.exp(-((((t % BEAT) + BEAT) % BEAT) / 0.25));+ for (let x = Math.floor(px - rx - 1); x <= px + rx + 1; x++) {+ const q = Math.abs(x + 0.5 - px) / rx;+ if (q > 1.1) continue;+ p.px(x, -1, q > 0.85 ? C[2] : C[1]);+ if (q < 0.8) p.px(x, 0, q < 0.5 ? C[1] : C[0]);+ if (q < 0.45) p.px(x, 1, C[0]);}- // 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;+ p.px(px - 2, -1, C[4]);+ p.px(px - 1, -1, C[3]);+ p.px(px + 3, -1, C[3]);+ p.glow(px, -1, 8, C[3], 0.06 + 0.04 * beat);+}++export function draw(p, t, o) {+ const C = fit(o.palette, 6), a = o.actor, W = wounds(a), S = shape(a);+ // each heartbeat flashes the body red for a moment+ const ph = ((t % BEAT) + BEAT) % BEAT, hurt = Math.max(0, 1 - ph / 0.12);+ if (hurt > 0) for (const [mx, my] of S.body) p.blend(a.x + mx, a.y + my, C[4], 0.26 * hurt);+ for (const w of W) {+ // the wound, a dark gash with a wet lip, and the blood running down from it+ p.px(w.x, w.y0 - 1, C[1]);+ p.px(w.x - w.side, w.y0 - 1, C[0]);+ p.px(w.x - w.side, w.y0, C[2]);+ for (let y = w.y0; y < w.yb; y++) p.px(w.x, y, y === w.y0 ? C[4] : y >= w.yb - 1 ? C[3] : C[2]);+ // drops: a bead swells, sags, lets go, falls, splats+ const period = D / w.drops;+ for (let k = 0; k < w.drops; k++) {+ const born = w.phase * period + k * period, age = (((t - born) % D) + D) % D, swell = period * 0.62, big = (k + w.mx) % 2 === 0;+ const fallH = Math.max(1, -1 - w.yb), fall = Math.sqrt((2 * fallH) / G), ground = 0;+ if (age < swell) {+ // a bead gathers at the end of the run, sags and stretches+ const u = age / swell, len = u < 0.35 ? 1 : u < 0.75 ? 2 : 3;+ for (let j = 0; j < len; j++) p.px(w.x, w.yb + j, j === len - 1 ? C[2] : C[3]);+ if (len === 3) p.px(w.x - 1, w.yb + 2, C[1]);+ p.px(w.x, w.yb + len - 2, u > 0.5 ? C[5] : C[4]);+ } else if (age < swell + fall) {+ const f = age - swell, y = w.yb + 2 + 0.5 * G * f * f;+ drop(p, C, w.x, y, G * f, big ? 2 : 1);+ } else splat(p, C, w.x, ground, age - swell - fall, big, w.mx * 31 + k);}- 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;+ }+ // the heartbeat squeezes a little spurt from the first wound: droplets streak out and fall+ const w = W[0];+ if (ph < 0.5)+ for (let j = 0; j < 7; j++) {+ const vx = w.side * (18 + 42 * rand(j, 7)), vy = -(15 + 50 * rand(j, 8)), tt = ph - j * 0.012;+ if (tt <= 0) continue;+ const x = w.x + travel(vx, 0, 1.2, tt), y = w.y0 + travel(vy, G * 0.8, 0.6, tt);+ const x2 = w.x + travel(vx, 0, 1.2, tt - 0.02), y2 = w.y0 + travel(vy, G * 0.8, 0.6, tt - 0.02);+ if (y >= -1) continue;+ p.line(x2, y2, x, y, j % 3 ? C[3] : C[2]);+ p.px(x, y, j % 2 ? C[5] : C[4]);}- // 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);+ p.glow(w.x, w.y0, 6, C[4], 0.25 * hurt);}diff --git a/src/fx/status/burning.js b/src/fx/status/burning.jsindex b3d09c2..d2e526f 100644--- a/src/fx/status/burning.js+++ b/src/fx/status/burning.js@@ -1,66 +1,126 @@-import { PAL, cycle, tileFbm, loopNoise, clamp, at, TAU } from "../../core/index.js";-import { steps, geom } from "./_lib.js";+// The flame tongues, embers and thin smoke are+// adapted from Sprite Fusion's open-source fire (https://www.spritefusion.com/pixel-art-vfx/fire),+// MIT License, Copyright (c) 2026 Hugo Duprez.+import { cycle, fit, hex, mix, rand, Rng, clamp, WHITE } from "../../core/index.js";+import { shape, colorAt, tnoise, travel, tongue, smoke, ember } from "./_lib.js";+import { luma } from "../../core/index.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.",+ desc: "Burning over time: small flames lick from four hot spots, trailing sparks and thin smoke; every 0.6 s they flare, the body flashes white then orange, scorch marks spread.",tags: ["status", "fire", "burn", "dot", "debuff", "loop"],- size: [40, 50],- origin: [20, 45],- duration: 1,+ size: [72, 80],+ origin: [36, 70],+ duration: 1.2,loop: true,fps: 30,bg: "ground",- actor: true,- options: { palette: PAL.fire, seed: 4 },+ actor: 2,+ options: {+ palette: ["#4a1712", "#8a1f17", "#c9281f", "#f2561d", "#ff8a2a", "#ffc23d", "#ffe26b", "#fff3a6", "#ffffff"],+ char: ["#120c0a", "#2a1a14", "#4a2c1c"],+ smoke: "#5b5566",+ seed: 3,+ },};-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];-};+const D = meta.duration, TICK = 0.6, WIND = -14;+const since = (t) => (((t % TICK) + TICK) % TICK);+const flare = (t) => Math.exp(-since(t) / 0.12);+/** The stand-in is hidden for the one white frame of each tick (the effect draws the body then). */+export const actorAlpha = (t) => (since(t) < 0.034 ? 0 : 1);++// the hot spots on the outline: the hair tips, a shoulder, the back, a sleeve; scorch spots near them per tick+const SPOTS = new WeakMap();+function spots(a, seed) {+ let s = SPOTS.get(a.mask);+ if (!s) SPOTS.set(a.mask, (s = new Map()));+ if (s.has(seed)) return s.get(seed);+ const S = shape(a), H = S.h, W = S.w, R = new Rng(seed * 13 + 5);+ const at = (q, side) => {+ const my = Math.round(H * q), [l, r] = S.rows[my];+ return [side < 0 ? l : r, my];+ };+ const hair = S.up.filter(([x]) => x < W * 0.42).sort((p, q) => p[1] - q[1] || p[0] - q[0])[0];+ const shoulder = S.up.filter(([x, y]) => x > W / 2 && y > H * 0.4 && y < H * 0.62).sort((p, q) => p[1] - q[1])[0] ?? at(0.5, 1);+ const list = [+ { at: hair, side: -1, n: 3, h: 4.5 },+ { at: shoulder, side: 1, n: 2, h: 4 },+ { at: at(0.62, -1), side: -1, n: 2, h: 3.5 },+ { at: at(0.6, 1), side: 1, n: 2, h: 3.5 },+ ].map((sp, i) => ({ ...sp, x: a.x + sp.at[0] + 0.5, y: a.y + sp.at[1] + 1.5, tongues: Array.from({ length: sp.n }, (_, j) => ({ dx: (j - (sp.n - 1) / 2) * 1.6 + R.range(-0.4, 0.4), h: sp.h * R.range(0.8, 1.2), n: i * 17 + j * 5 + seed })) }));+ // scorch marks: each tick chars two patches on the clothes near the spots+ const scorch = [0, 1].map((tick) =>+ [0, 1].map((k) => {+ // on the clothes (mid-tones, where char shows), near a hot spot+ const sp = list[(tick * 2 + k + 1) % list.length], lum = (x, y) => luma(colorAt(a, x, y));+ let cand = S.body.filter(([x, y]) => Math.hypot(a.x + x + 0.5 - sp.x, a.y + y + 0.5 - sp.y) < 9 && y > H * 0.42 && lum(x, y) > 0.3 && lum(x, y) < 0.6);+ if (!cand.length) cand = S.body.filter(([, y]) => y > H * 0.45);+ const [x, y] = cand[Math.floor(R.next() * cand.length)];+ return { x: a.x + x + 0.5, y: a.y + y + 0.5, r: R.range(3.2, 4.4) };+ }));+ const out = { list, scorch };+ s.set(seed, out);+ return out;+}-// behind the body: the flame field around the silhouette, licking highest off upward-facing edgesexport 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 F = fit(o.palette, 9).reverse(), a = o.actor, fl = flare(t), flick = 0.8 + 0.2 * tnoise(t, D, 7.5, 3);+ // warm flicker on the floor+ p.shade(-30, -3, 30, 7, (x, y, out) => {+ const d = Math.hypot(x / 26, (y - 0.5) / 4.5);+ if (d < 1) (out.l = mix(F[3], F[4], 0.5)), (out.k = (0.16 + 0.22 * fl) * flick * (1 - d) * (1 - d));+ });+ // thin smoke drifting up and away from each spot+ const smokeC = mix(hex(o.smoke), F[6], 0.2), { list } = spots(a, o.seed);+ cycle(t, D, 16, o.seed + 4, (r) => r.range(0.8, 1.2), (age, life, r, i) => {+ const sp = list[i % list.length], x = sp.x + travel(WIND * 0.6, WIND * 0.5, 0.8, age) + Math.sin(age * 4 + i) * 1.2, y = sp.y - 3 - travel(18, 6, 1, age);+ smoke(p, x, y, r.range(1.1, 1.9), age / life, smokeC, 0.9);});- 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, embersexport 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);+ const F = fit(o.palette, 9).reverse(), CH = fit(o.char, 3), a = o.actor, S = shape(a), { list, scorch } = spots(a, o.seed);+ const ph = since(t), tick = Math.floor(t / TICK) % 2, fl = flare(t);+ // the tick: the body's own pixels flash white for a frame, then orange, fading+ if (ph < 0.034) for (const [mx, my] of S.body) p.px(a.x + mx, a.y + my, WHITE);+ else if (ph < 0.22) {+ const k = 1 - (ph - 0.034) / 0.186;+ for (const [mx, my] of S.body) p.blend(a.x + mx, a.y + my, F[4], 0.55 * k);}- // 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));+ // scorch marks spreading over the clothes from this tick, ember-edged, cooling and fading by the next+ for (const sc of scorch[tick]) {+ const grow = clamp(ph / 0.14), fade = 1 - clamp((ph - 0.25) / 0.33), r = sc.r * (0.4 + 0.6 * grow);+ if (fade <= 0) continue;+ for (const [mx, my] of S.body) {+ const x = a.x + mx + 0.5, y = a.y + my + 0.5, d = Math.hypot(x - sc.x, (y - sc.y) * 1.2) + rand(mx, my, 7) * 0.9;+ if (d > r) continue;+ const edge = d > r - 1;+ if (edge) p.dot(x - 0.5, y - 0.5, rand(mx, my, Math.floor(t * 20)) < 0.5 ? F[3] : F[4], fade * 1.2);+ else p.dot(x - 0.5, y - 0.5, d < r * 0.5 ? CH[0] : CH[1], fade * 1.1);+ }+ p.glow(sc.x, sc.y, 6, F[4], 0.3 * fade);+ }+ // the hot spots: little tongues licking up, flaring on the tick+ for (const sp of list) {+ for (const tg of sp.tongues) {+ const h = tg.h * (0.85 + 0.25 * tnoise(t, D, 5, tg.n)) * (1 + 1.6 * fl);+ tongue(p, sp.x + tg.dx, sp.y, h, 1.1 + 0.3 * fl, WIND * 0.08 * h / 4 + tnoise(t, D, 3, tg.n + 9) * 0.8, F, t, D, tg.n);+ }+ p.glow(sp.x, sp.y - 2, 9 + 6 * fl, F[4], 0.22 + 0.35 * fl);+ }+ // sparks streaming up and away+ cycle(t, D, 20, o.seed + 6, (r) => r.range(0.5, 0.9), (age, life, r, i) => {+ const sp = list[i % list.length], x = sp.x + r.range(-1.5, 1.5) + travel(WIND + r.range(-10, 6), WIND * 0.6, 1.2, age) + Math.sin(age * 9 + i) * 1.2 * age;+ const y = sp.y - 2 + travel(-r.range(25, 55), -18, 1.4, age);+ ember(p, x, y, age / life, [F[1], F[3], F[5]], age + i);});- p.glow(0, a.y + 4, 9, F[6], 0.2);+ // the tick throws a burst of sparks off every spot+ if (ph < 0.3)+ for (const [k, sp] of list.entries())+ for (let j = 0; j < 4; j++) {+ const an = -Math.PI / 2 + (rand(k, j, tick) - 0.5) * 2.2, v = 50 + 50 * rand(k, j, 2), x = sp.x + Math.cos(an) * travel(v, 0, 3, ph), y = sp.y - 2 + Math.sin(an) * travel(v, 0, 3, ph) + 60 * ph * ph;+ p.px(x, y, ph < 0.12 ? F[1] : F[3]);+ p.light(x, y, F[3], 0.4 * (1 - ph / 0.3));+ }}diff --git a/src/fx/status/charmed.js b/src/fx/status/charmed.jsindex 81850f8..ddafc78 100644--- a/src/fx/status/charmed.js+++ b/src/fx/status/charmed.js@@ -1,63 +1,86 @@-import { bump, rng, TAU } from "../../core/index.js";-import { steps } from "./_lib.js";+// The shaded, outlined hearts are+// adapted from Sprite Fusion's open-source heal (https://www.spritefusion.com/pixel-art-vfx/heal),+// MIT License, Copyright (c) 2026 Hugo Duprez.+import { cycle, fit, mix, sparkle, TAU } from "../../core/index.js";+import { icon, bitmap, shaped, heartShape, eyes } 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,+ desc: "Smitten: a big heart beats over the head, throwing a ring and a flush of light with every beat, little hearts float up, the eyes go pink and the cheeks blush.",+ tags: ["status", "charm", "love", "hearts", "debuff", "loop"],+ size: [60, 76],+ origin: [30, 68],+ duration: 2.4,loop: true,fps: 30,bg: "ground",- actor: true,- options: {- palette: ["#2a0614", "#5a0c2c", "#9a1648", "#d62a6a", "#ff5a92", "#ff9ac0", "#ffd6e8", "#ffffff"],- count: 4, seed: 9,- },+ actor: 2,+ options: { palette: ["#3a0a1e", "#7a1238", "#c4245a", "#f04e86", "#ff8ab0", "#ffc8da", "#ffffff"], seed: 8 },};-const HEARTS = [- ["##.##", "#####", ".###.", "..#.."],- [".##.##.", "#######", "#######", ".#####.", "..###..", "...#..."],- [".##...##.", "####.####", "#########", "#########", ".#######.", "..#####..", "...###...", "....#...."],- [".###...###.", "#####.#####", "###########", "###########", "###########", ".#########.", "..#######..", "...#####...", "....###....", ".....#....."],-];+const D = meta.duration, BEAT = D / 2;+const HEART5 = bitmap([".#.#.", "#####", "#####", ".###.", "..#.."]);+const HEART7 = bitmap([".##.##.", "#######", "#######", ".#####.", "..###..", "...#..."]);+// a heartbeat: a strong lub and a softer dub+const thump = (ph) => Math.exp(-(((ph - 0.04) / 0.07) ** 2)) + 0.6 * Math.exp(-(((ph - 0.26) / 0.07) ** 2));-// 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]);+// little hearts drifting up (half of them behind the character)+function hearts(p, C, a, t, seed, back) {+ cycle(t, D, 12, seed + 4, (r) => r.range(1.3, 1.9), (age, life, r, i) => {+ if ((i % 3 === 0) !== back) return;+ const u = age / life, side = r.next() < 0.5 ? -1 : 1, ph = r.range(0, TAU), big = r.next() < 0.3;+ const x = side * r.range(4, 15) + Math.sin(age * 4 + ph) * 2.2, y = a.y + r.range(8, 30) - age * r.range(14, 22);+ const k = Math.min(1, u * 6);+ if (u > 0.88) {+ // it pops into a twinkle+ const q = (u - 0.88) / 0.12;+ sparkle(p, x, y, Math.round(2 * (1 - q)), C[5], C[4], 0.4 * (1 - q));+ return;}+ const R = back ? [C[0], C[1], C[2], C[3]] : [C[0], C[2], C[3], C[4]];+ icon(p, x, y, 4, big ? HEART7 : HEART5, R, k);+ if (!back) p.px(x - (big ? 2 : 1), y - 1, C[6]);+ p.glow(x, y, 6, C[3], (back ? 0.12 : 0.22) * k);+ });}-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;+export function drawBack(p, t, o) {+ const C = fit(o.palette, 7), a = o.actor, ph = ((t % BEAT) + BEAT) % BEAT, th = thump(ph);+ p.glow(0, a.y - 8, 26 + 8 * th, C[3], 0.16 + 0.22 * th);+ hearts(p, C, a, t, o.seed, true);+}- // 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);+export function draw(p, t, o) {+ const C = fit(o.palette, 7), a = o.actor, ph = ((t % BEAT) + BEAT) % BEAT, th = thump(ph);+ // lovestruck: pink eyes with a bright catchlight, flushed cheeks+ for (const e of eyes(a)) {+ for (const [x, y] of e.px) p.px(a.x + x, a.y + y, y === e.y0 ? C[3] : C[2]);+ p.px(a.x + e.x0, a.y + e.y0 + 1, C[6]);+ const blush = mix(e.skin, C[3], 0.55), out = e.x0 < a.w / 2 ? -1 : 1, bx = out < 0 ? e.x0 - 1 : e.x1;+ p.px(a.x + bx, a.y + e.y1 + 1, blush);+ p.px(a.x + bx + 1, a.y + e.y1 + 1, blush);}-- // 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);+ hearts(p, C, a, t, o.seed, false);+ // the big heart, beating+ const hx = 0, hy = a.y - 10, s = 5.6 * (1 + 0.24 * th);+ // a heart-shaped ring thrown off with each beat+ for (const [t0, kk] of [[0.04, 1], [0.26, 0.6]]) {+ const u = (ph - t0) / 0.5;+ if (u < 0 || u > 1) continue;+ const S1 = 5.6 * (1.25 + 1.3 * u), outer = shaped(heartShape, S1), inner = shaped(heartShape, S1 - 1.3), E = Math.ceil(S1 * 1.2) + 1;+ for (let dy = -E; dy <= E; dy++)+ for (let dx = -E; dx <= E; dx++) if (outer(dx, dy) && !inner(dx, dy)) p.dot(hx + dx, hy + dy, u < 0.3 ? C[5] : C[4], (1 - u) * kk * 1.3);+ }+ icon(p, hx, hy, 9, shaped(heartShape, s), [C[0], C[2], C[3], C[4]]);+ // a glint on the left lobe+ p.px(hx - Math.round(s * 0.55), hy - Math.round(s * 0.45), C[6]);+ p.px(hx - Math.round(s * 0.55) + 1, hy - Math.round(s * 0.45), C[5]);+ p.px(hx - Math.round(s * 0.55), hy - Math.round(s * 0.45) + 1, C[5]);+ p.glow(hx, hy, 12 + 6 * th, C[4], 0.3 + 0.4 * th);+ if (th > 0.5) sparkle(p, hx + s * 0.9, hy - s * 0.8, Math.round(3 * th), C[5], C[4], 0.4 * th);+ // twinkles round the heart+ cycle(t, D, 8, o.seed + 2, (r) => r.range(0.3, 0.5), (age, life, r) => {+ const an = r.range(0, TAU), d = r.range(8, 15), u = age / life;+ sparkle(p, hx + Math.cos(an) * d, hy + Math.sin(an) * d * 0.8, Math.round(1.6 * Math.sin(Math.PI * u)), C[5], C[4], 0.3 * Math.sin(Math.PI * u));+ });}diff --git a/src/fx/status/confused.js b/src/fx/status/confused.jsindex 2fbe909..b8d414e 100644--- a/src/fx/status/confused.js+++ b/src/fx/status/confused.js@@ -1,56 +1,102 @@-import { PAL, seg, ease, rng, TAU } from "../../core/index.js";-import { steps } from "./_lib.js";+// The shaded, outlined question marks are+// adapted from Sprite Fusion's open-source heal (https://www.spritefusion.com/pixel-art-vfx/heal),+// MIT License, Copyright (c) 2026 Hugo Duprez.+import { cycle, fit, sparkle, ease, clamp, TAU } from "../../core/index.js";+import { icon, bitmap, eyes } 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,+ desc: "Head in a spin: a glowing spiral whirls over the head, question marks pop up round it and bob, the eyes dart left and right.",+ tags: ["status", "confused", "confusion", "dizzy", "debuff", "loop"],+ size: [60, 78],+ origin: [30, 70],+ duration: 2.4,loop: true,fps: 30,bg: "ground",- actor: true,- options: { palette: PAL.cyber, count: 3, seed: 7 },+ actor: 2,+ options: {+ palette: ["#1e0f2e", "#4b2070", "#8a3ab0", "#c66ae0", "#f0a8ff", "#ffffff"],+ marks: ["#2a1608", "#b0701a", "#ffd84a", "#fff4b8"],+ seed: 6,+ },};-// a question mark, 5 x 7-const Q = [".###.", "#...#", "....#", "...#.", "..#..", ".....", "..#.."];-const SPOTS = [[-11, 1], [7, -1], [-3, -9]]; // where each mark pops up, around the swirl+const D = meta.duration;+const QS = [+ [".###.", "#...#", "....#", "...#.", "..#..", ".....", "..#.."],+ [".####.", "##..##", "....##", "...##.", "..##..", "..##..", "......", "..##..", "..##.."],+ [".#####.", "##...##", "##...##", ".....##", "....##.", "...##..", "...##..", ".......", "...##..", "...##.."],+].map((rows) => bitmap(rows));+// three marks round the spiral: where they sit, when they pop, how big they get+const MARKS = [+ { x: -12, y: -5, t0: 0, big: 2 },+ { x: 12, y: -8, t0: 0.8, big: 1 },+ { x: 1, y: -17, t0: 1.6, big: 2 },+];-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]);+// the spiral, seen from the front: an arm winding out from its heart, spinning+function spiral(p, C, cx, cy, t) {+ const rot = (t / D) * TAU * 2, turns = 1.8, n = 72, breathe = 1 + 0.08 * Math.sin((t / D) * TAU * 4);+ const at = (u) => {+ const th = u * turns * TAU - rot, r = (0.8 + 6.6 * u) * breathe;+ return [cx + Math.cos(th) * r, cy + Math.sin(th) * r * 0.9];+ };+ // a dark underlay on the outer arm so it reads against anything, then the arm brightening as it winds out+ for (let i = 1; i <= n; i++) {+ const u = i / n, [x0, y0] = at((i - 1) / n), [x1, y1] = at(u);+ if (u > 0.45) p.line(x0 + 0.5, y0 + 0.7, x1 + 0.5, y1 + 0.7, C[1]);+ }+ for (let i = 1; i <= n; i++) {+ const u = i / n, [x0, y0] = at((i - 1) / n), [x1, y1] = at(u);+ p.line(x0, y0, x1, y1, u > 0.88 ? C[5] : u > 0.62 ? C[4] : u > 0.3 ? C[3] : C[2]);+ if (i % 6 === 0) p.light(x1, y1, C[3], 0.4 * u);+ }+ const [hx, hy] = at(1);+ sparkle(p, hx, hy, 2, C[4], C[3], 0.5);+ p.glow(cx, cy, 13, C[3], 0.28);}-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;+export function drawBack(p, t, o) {+ const C = fit(o.palette, 6), a = o.actor;+ p.glow(0, a.y - 7, 16, C[3], 0.22);+}- // 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]);+export function draw(p, t, o) {+ const C = fit(o.palette, 6), M = fit(o.marks, 4), a = o.actor;+ // the eyes dart from side to side+ const look = Math.floor((t / D) * 6) % 2 ? 1 : -1;+ for (const e of eyes(a)) {+ for (const [x, y] of e.px) p.px(a.x + x, a.y + y, 0xff17121f);+ p.px(a.x + (look < 0 ? e.x0 : e.x1), a.y + e.y0, 0xffffffff);}- 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));+ spiral(p, C, 0, a.y - 7, t);+ // the question marks pop up, bob, and shrink away+ for (const m of MARKS) {+ const age = (((t - m.t0) % D) + D) % D, life = 1.9;+ if (age > life) continue;+ const u = age / life, pop = ease.outBack(clamp(age / 0.16), 3), out = clamp((u - 0.82) / 0.18);+ const size = Math.max(0, Math.round(m.big * pop * (1 - out) + (pop > 1.1 ? 1 : 0)));+ const bob = Math.sin(age * 5 + m.t0 * 3) * 1.6, tilt = Math.sin(age * 3.3 + m.t0) * 0.8;+ if (pop < 0.3 || (out > 0 && size === 0 && out > 0.6)) continue;+ const x = m.x + tilt, y = a.y + m.y + bob - age * 2;+ // it pops in with a burst of short rays and a flash+ if (age < 0.2) {+ const k = age / 0.2;+ for (let j = 0; j < 8; j++) {+ const an = (j / 8) * TAU + 0.2, d0 = 4 + 7 * k, d1 = d0 + 3 * (1 - k);+ p.line(x + Math.cos(an) * d0, y + Math.sin(an) * d0, x + Math.cos(an) * d1, y + Math.sin(an) * d1, j % 2 ? M[2] : M[3], 1 - k);+ }+ p.glow(x, y, 16, M[2], 0.45 * (1 - k));+ }+ icon(p, x, y, 7, QS[Math.min(2, size)], [M[0], M[1], M[2], M[3]]);+ p.glow(x, y, 10 + size * 2, M[2], 0.28 * (1 - out));}+ // glitter flicking off the spiral+ cycle(t, D, 10, o.seed + 2, (r) => r.range(0.35, 0.6), (age, life, r) => {+ const th = r.range(0, TAU), u = age / life, d = 6 + age * r.range(12, 22);+ const x = Math.cos(th) * d, y = a.y - 7 + Math.sin(th) * d * 0.8;+ if (Math.sin(Math.PI * u) > 0.6 && r.next() < 0.5) sparkle(p, x, y, 1, C[4], C[3], 0.3);+ else p.dot(x, y, u < 0.5 ? C[5] : C[4], 1.2 - u);+ });}diff --git a/src/fx/status/cursed.js b/src/fx/status/cursed.jsindex 483cddf..8d9bfdb 100644--- a/src/fx/status/cursed.js+++ b/src/fx/status/cursed.js@@ -1,74 +1,132 @@-import { cycle, bump, rand, clamp, TAU } from "../../core/index.js";-import { steps, geom, recolor, tone } from "./_lib.js";+// The soft lit smoke puffs and the shaded, outlined skull are+// adapted from Sprite Fusion's open-source poison (https://www.spritefusion.com/pixel-art-vfx/poison),+// MIT License, Copyright (c) 2026 Hugo Duprez.+import { fit, rand, clamp, luma, mix, smooth, tileFbm, TAU } from "../../core/index.js";+import { shape, colorAt, eyes, icon, bitmap } 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,+ desc: "Hexed: violet smoke rises off the body in winding trails, a dark stain creeps up from the feet with a glowing edge, the eyes burn, a skull glitches in overhead.",+ tags: ["status", "curse", "hex", "dark", "debuff", "shadow", "loop"],+ size: [64, 84],+ origin: [32, 76],+ duration: 2.4,loop: true,fps: 30,bg: "ground",- actor: true,- options: { palette: ["#07040c", "#170b28", "#2c1049", "#481872", "#6e22a0", "#9a3acb", "#cc70ec", "#f6d2ff"], seed: 6 },+ actor: 2,+ options: { palette: ["#0c0612", "#1f0f2e", "#3a1a55", "#5e2a85", "#8a3fc0", "#b86ef0", "#e0b0ff", "#ffffff"], seed: 9 },};-const SKULL = [".#####.", "#######", "#ee#ee#", "#ee#ee#", "###n###", ".#####.", ".#t#t#."];+const D = meta.duration;+const SKULL = bitmap([+ "...#####...",+ ".#########.",+ "###########",+ "##eee#eee##",+ "##eEe#eEe##",+ "##eee#eee##",+ "#####.#####",+ ".####.####.",+ "..#######..",+ "..#.#.#.#..",+ "...#####...",+]);+// the skull's life in the loop: hidden, glitching in, hanging there, glitching out+const IN = 0.5, HOLD = 0.75, OUT = 1.85, GONE = 2.1;-// 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);+// how high the stain has crept at column x (0 at the feet, 1 at the head), a slow tide with crawling tendrils+const tide = (t) => 0.3 + 0.12 * Math.sin((t / D) * TAU);+const reach = (x, t, seed) => tide(t) + 0.13 * tileFbm(x * 0.35, (t / D) * 4, 0, 4, seed, 2);++// smoke trails: each rises from a spot on the body as a ribbon of soft puffs that wind as they climb, swell, cool+// and thin+function trails(p, C, a, S, t, seed, front) {+ const spots = [[0.12, -1], [0.1, 1], [0.5, -1], [0.48, 1]];+ spots.forEach(([q, side], j) => {+ if ((j % 2 === 0) !== front) return;+ const my = Math.round(S.h * q), [l, r] = S.rows[my] ?? [0, 0];+ const x0 = a.x + (side < 0 ? l : r + 1), y0 = a.y + my, life = 1.6, n = 18;+ for (let i = n - 1; i >= 0; i--) {+ const age = (((t - (i / n) * D - j * 0.37) % D) + D) % D, tb = t - age, u = age / life;+ if (u >= 1) continue;+ const sway = Math.sin((tb / D) * TAU * 2 + j * 1.7) * 4 * Math.min(1, u * 1.6);+ const x = x0 + side * u * 7 + sway + (rand(i, j, 71) - 0.5) * 2.5 * u, y = y0 - age * 19 - 5 * u * u;+ const rad = (1.3 + 3.6 * (1 - Math.pow(1 - u, 3))) * (0.7 + 0.6 * rand(i, j, 72)), k = smooth(0, 0.12, u) * (1 - smooth(0.45, 1, u)) * (front ? 0.5 : 0.62);+ const c = mix(rand(i, j, 70) < 0.5 ? C[4] : mix(C[4], C[3], 0.4), C[1], u * 0.85);+ p.disc(x, y, rad * 1.08, c, k * 0.4);+ p.disc(x + rad * 0.05, y + rad * 0.08, rad * 0.76, c, k * 0.55);+ p.disc(x - rad * 0.22, y - rad * 0.3, rad * 0.48, mix(c, C[6], 0.25), k * 0.38 * (1 - u * 0.6));+ if (i % 3 === 0) p.glow(x, y, rad * 1.6, C[4], 0.08 * k);}- 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);+ const C = fit(o.palette, 8), a = o.actor, S = shape(a);+ // the stain pooling round the feet, its rim glowing+ const [fl, fr] = S.rows[S.h - 1], cx = a.x + (fl + fr + 1) / 2, rx = (fr - fl) / 2 + 7 + 2 * Math.sin((t / D) * TAU);+ for (let x = Math.floor(cx - rx - 1); x <= cx + rx + 1; x++) {+ const q = Math.abs(x + 0.5 - cx) / rx, n = rand(x, 31);+ if (q > 1 + n * 0.12) continue;+ p.px(x, 0, q > 0.8 ? C[4] : n < 0.2 ? C[3] : C[2]);+ if (q < 0.85) p.px(x, 1, C[1]);+ if (q < 0.55 && n < 0.7) p.px(x, 2, C[1]);+ }+ p.shade(cx - rx - 6, -4, cx + rx + 6, 5, (x, y, out) => {+ const d = Math.hypot((x - cx) / (rx + 6), y / 4);+ if (d < 1) (out.l = C[4]), (out.k = 0.2 * (1 - d) * (1 - d));+ });+ trails(p, C, a, S, t, o.seed, false);}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);+ const C = fit(o.palette, 8), a = o.actor, S = shape(a), H = S.h;+ // the stain on the body: everything below the creeping line drowned in violet, the line itself burning+ for (const [mx, my] of S.body) {+ const c = colorAt(a, mx, my), up = 1 - (my + 0.5) / H, lv = reach(mx, t, o.seed);+ if (up > lv + 0.035) continue;+ const x = a.x + mx, y = a.y + my;+ if (up > lv - 0.02) p.px(x, y, C[6]);+ else if (up > lv - 0.06) p.px(x, y, C[4]);+ else p.px(x, y, mix(C[1], C[3], clamp(luma(c) * 1.6)));+ }+ for (let mx = 0; mx < S.w; mx++) {+ const lv = reach(mx, t, o.seed), my = Math.floor((1 - lv) * H);+ if (S.on(mx, my)) p.glow(a.x + mx, a.y + my, 4, C[5], 0.14);+ }+ // the eyes burn+ for (const e of eyes(a)) {+ for (const [x, y] of e.px) p.px(a.x + x, a.y + y, y === e.y0 ? C[7] : C[5]);+ p.glow(a.x + (e.x0 + e.x1 + 1) / 2, a.y + (e.y0 + e.y1 + 1) / 2, 5, C[5], 0.4);+ }+ trails(p, C, a, S, t, o.seed, true);+ // the skull glitches in, hangs there bobbing, and glitches out+ if (t >= IN && t < GONE) {+ const glitch = t < HOLD ? 1 - (t - IN) / (HOLD - IN) : t > OUT ? (t - OUT) / (GONE - OUT) : 0;+ const f = Math.floor(t * 30), on = glitch < 0.15 || rand(f, 3) > glitch * 0.6;+ const x = 0, y = a.y - 12 + Math.sin((t / D) * TAU * 2) * 1.2;+ if (on) {+ const tear = (dx, dy) => {+ const row = dy + 6, shift = glitch > 0 && rand(f, row >> 1, 7) < glitch * 0.8 ? Math.round((rand(f, row, 9) - 0.5) * 6 * glitch) : 0;+ return SKULL(dx - shift, dy);+ };+ if (glitch > 0) {+ icon(p, x - 2, y, 7, tear, [0, C[2], C[2], C[3]], 0.7 * glitch);+ icon(p, x + 2, y, 7, tear, [0, C[6], C[6], C[6]], 0.5 * glitch);+ }+ icon(p, x, y, 8, tear, [C[0], C[4], C[6], C[7]], 1, { e: C[0], E: C[7] });+ p.glow(x - 3, y - 1, 5, C[5], 0.6);+ p.glow(x + 3, y - 1, 5, C[5], 0.6);+ p.glow(x, y, 16, C[4], 0.24 + 0.3 * glitch);}+ // scanlines fizzing as it comes and goes+ if (glitch > 0.1)+ for (let k = 0; k < 3; k++) {+ const ly = y - 5 + Math.floor(rand(f, k, 11) * 11), lx = Math.round((rand(f, k, 12) - 0.5) * 10), len = 3 + Math.floor(rand(f, k, 13) * 8);+ p.line(lx - len / 2, ly, lx + len / 2, ly, k % 2 ? C[6] : C[4], glitch);+ }}+ p.glow(0, a.y + H * (1 - tide(t)), 24, C[4], 0.2);+ p.glow(0, a.y + H * 0.45, 30, C[3], 0.12);}diff --git a/src/fx/status/fortified.js b/src/fx/status/fortified.jsdeleted file mode 100644index 3faac08..0000000--- a/src/fx/status/fortified.js+++ /dev/null@@ -1,63 +0,0 @@-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.jsindex b68d680..c5e2c83 100644--- a/src/fx/status/frozen.js+++ b/src/fx/status/frozen.js@@ -1,83 +1,158 @@-import { PAL, cycle, rand, clamp, TAU, WHITE } from "../../core/index.js";-import { steps, geom, recolor, tone } from "./_lib.js";+import { cycle, fit, mix, luma, rand, Rng, clamp, smooth, sparkle, TAU, WHITE } from "../../core/index.js";+import { shape, colorAt, eyes, travel } 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],+ desc: "Chilled to the bone: frost ferns creep over the body, icicles hang from chin, hands and hair and drip, breath steams, snow settles, a shiver every second, frost spreads underfoot.",+ tags: ["status", "ice", "freeze", "frozen", "cold", "chill", "debuff", "loop"],+ size: [72, 64],+ origin: [36, 54],duration: 2,loop: true,fps: 30,bg: "ground",- actor: true,- options: { palette: PAL.ice, count: 7, seed: 3 },+ actor: 2,+ options: { palette: ["#151a3d", "#212f6b", "#2c58aa", "#3a8bd8", "#62c8f4", "#a6ecff", "#dcfbff", "#ffffff"], seed: 4 },};-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;+const D = meta.duration, SHIVER = 1;+const since = (t) => (((t % SHIVER) + SHIVER) % SHIVER);+/** The effect draws the whole (chilled, shivering) body, so the stand-in is hidden throughout. */+export const actorAlpha = () => 0;+const shake = (t) => (since(t) < 0.22 ? (Math.floor(t * 50) % 2 ? 1 : -1) : 0);++// worked out once per character: fern paths creeping in from the outline, icicle roots, snow ledges, the mouth+const PLANS = new WeakMap();+function plan(a, seed) {+ let m = PLANS.get(a.mask);+ if (!m) PLANS.set(a.mask, (m = new Map()));+ if (m.has(seed)) return m.get(seed);+ const S = shape(a), H = S.h, W = S.w, R = new Rng(seed * 11 + 1);+ // ferns: a stem walking in from an edge with fronds branching off it at alternate sides, each pixel ordered by when it grows+ const ferns = [];+ const roots = S.side.filter(([, y]) => y > H * 0.2 && y < H * 0.85).sort(() => R.next() - 0.5).slice(0, 6);+ roots.forEach(([x0, y0, dir], i) => {+ let x = x0, y = y0, ang = dir < 0 ? -0.5 : Math.PI + 0.5;+ ang += R.range(-0.4, 0.4);+ for (let s = 0; s < 9; s++) {+ x += Math.cos(ang) * 1.1;+ y += Math.sin(ang) * 1.1;+ const px = Math.round(x), py = Math.round(y);+ if (!S.on(px, py)) break;+ ferns.push([px, py, s / 9, i]);+ if (s % 2 === 1)+ for (const side of [-1, 1]) {+ const ba = ang + side * 1.05, L = 1 + Math.round(R.range(0, 2) * (1 - s / 9));+ for (let k = 1; k <= L; k++) {+ const bx = Math.round(x + Math.cos(ba) * k), by = Math.round(y + Math.sin(ba) * k);+ if (S.on(bx, by)) ferns.push([bx, by, (s + k * 0.6) / 9, i]);+ }+ }+ ang += R.range(-0.25, 0.25);+ }+ });+ // icicles under the hair tips, the jaw and the hands: bottom edges with clear space under them+ const clear = (x, y) => {+ let n = 0;+ while (n < 7 && y + 1 + n < H && !S.on(x, y + 1 + n)) n++;+ return n;+ };+ const hangs = S.body.filter(([x, y]) => !S.on(x, y + 1) && S.on(x, y - 1) && y < H * 0.72 && y > 4).map(([x, y]) => [x, y, clear(x, y)]).filter(([, , c]) => c >= 4);+ const best = (f, key) => hangs.filter(f).sort(key)[0];+ const icicles = [+ best(([, y]) => y < H * 0.36, (p, q) => p[0] - q[0]),+ best(([, y]) => y < H * 0.36, (p, q) => q[0] - p[0]),+ best(([x, y]) => y >= H * 0.36 && y < H * 0.5 && x < W / 2, (p, q) => q[0] - p[0]),+ best(([x, y]) => y >= H * 0.36 && y < H * 0.5 && x >= W / 2, (p, q) => p[0] - q[0]),+ best(([x, y]) => y >= H * 0.5 && x < W / 2, (p, q) => p[0] - q[0]),+ best(([x, y]) => y >= H * 0.5 && x >= W / 2, (p, q) => q[0] - p[0]),+ ]+ .filter(Boolean)+ .map(([x, y, c], i) => ({ x, y: y + 1, len: Math.min(c - 1, R.range(3, 5.5)), phase: R.next(), period: i % 2 ? 1 : 2 }));+ // snow ledges: the upward edges of the head and the shoulders+ const snow = S.up.filter(([, y]) => y < H * 0.6).map(([x, y]) => [x, y, 1 + (rand(x, seed, 3) < 0.45 ? 1 : 0)]);+ const E = eyes(a), mouth = E.length === 2 ? [(E[0].x1 + E[1].x0 + 1) / 2, Math.max(E[0].y1, E[1].y1) + 2] : [W / 2, H * 0.38];+ const out = { ferns, icicles, snow, mouth };+ m.set(seed, out);+ return out;}-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));+// frost on the floor round the feet: a white crust, a pale bloom under it, its edge creeping out and back+function frost(p, C, t, reach) {+ for (let x = -Math.ceil(reach) - 1; x <= reach + 1; x++) {+ const q = Math.abs(x + 0.5) / reach, h = rand(x, 17), k = 1 - q * q;+ if (q > 1 + h * 0.15) continue;+ const tw = Math.sin((t / D) * TAU * 2 + rand(x, 3) * TAU) > 0.94;+ p.px(x, 0, tw || h < 0.3 ? C[7] : q > 0.85 ? C[5] : C[6]);+ if (h < 0.3 * k) p.px(x, -1, C[6]);+ for (let j = 1; j <= 1 + Math.round(2 * k); j++) p.dot(x, j, j === 1 ? C[5] : C[4], (1.05 - j / 4) * 0.85);+ }+}- // 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];+export function drawBack(p, t, o) {+ const C = fit(o.palette, 8), reach = 13 + 3.5 * Math.sin((t / D) * TAU);+ p.shade(-28, -3, 28, 6, (x, y, out) => {+ const d = Math.hypot(x / 24, (y - 0.5) / 4);+ if (d < 1) (out.l = C[4]), (out.k = 0.24 * (1 - d) * (1 - d));});+ frost(p, C, t, reach);+}- // 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);+export function draw(p, t, o) {+ const C = fit(o.palette, 8), a = o.actor, S = shape(a), H = S.h, P = plan(a, o.seed), dx = shake(t), ph = since(t);+ const X = (mx) => a.x + mx + dx, Y = (my) => a.y + my;+ // the body, chilled: its colours pulled toward ice; the rim frosted and lit+ for (const [mx, my] of S.body) {+ const c = colorAt(a, mx, my), ice = C[clamp(1 + Math.round(luma(c) * 5.6), 1, 7)];+ const rim = !S.on(mx - 1, my) || !S.on(mx, my - 1) || !S.on(mx + 1, my);+ p.px(X(mx), Y(my), rim && luma(c) < 0.3 ? (my < H * 0.5 || !S.on(mx - 1, my) ? C[5] : C[3]) : mix(c, ice, 0.38));+ }+ // frost ferns creeping in from the outline; each shiver cracks most of it off and it creeps back+ const grow = 0.2 + 0.65 * smooth(0.05, 0.95, ph);+ for (const [x, y, u] of P.ferns) if (u < grow) p.px(X(x), Y(y), u > grow - 0.1 ? WHITE : rand(x, y, 5) < 0.5 ? C[6] : C[5]);+ // snow settled on the head and shoulders+ for (const [x, y, d] of P.snow) {+ p.px(X(x), Y(y) - 1, C[7]);+ if (d > 1) p.px(X(x), Y(y) - 2, rand(x, y, 9) < 0.5 ? C[7] : C[6]);+ }+ // icicles hanging under the chin, hands and hair: they grow, a drop gathers and falls, they shrink back+ for (const ic of P.icicles) {+ const per = ic.period, u = ((t / per + ic.phase) % 1 + 1) % 1, L = ic.len * (0.55 + 0.45 * smooth(0, 0.7, u)), x = X(ic.x), y0 = Y(ic.y);+ for (let j = 0; j < L; j++) {+ const v = j / L;+ p.px(x, y0 + j, v > 0.75 ? WHITE : v < 0.3 ? C[7] : C[6]);+ if (v < 0.5) p.px(x + 1, y0 + j, C[4]);}+ // the drop: it swells at the tip, lets go and falls to the floor+ if (u > 0.7 && u < 0.86) p.px(x, y0 + L, C[6]);+ else if (u >= 0.86) {+ const f = (u - 0.86) * per, y = y0 + L + 0.5 * 760 * f * f;+ if (y < -1) (p.px(x, y, C[6]), p.px(x, y - 1, C[5]));+ }+ p.glow(x, y0 + L * 0.6, 4, C[5], 0.18);+ }+ // breath steaming from the mouth between shivers+ const [mx0, my0] = P.mouth;+ for (let i = 0; i < 4; i++) {+ const age = ph - 0.35 - i * 0.05;+ if (age < 0 || age > 0.65) continue;+ const u = age / 0.65, x = X(mx0) + 1 + travel(16, 0, 2.2, age) + i, y = Y(my0) - travel(6, 3, 1, age) - i * 0.5, rad = 0.8 + 2.4 * Math.sqrt(u);+ p.disc(x, y, rad, C[7], 0.5 * (1 - u) * Math.min(1, u * 8));+ p.disc(x - rad * 0.2, y - rad * 0.3, rad * 0.5, WHITE, 0.4 * (1 - u));+ }+ // snow falling and settling; flakes flung off by the shiver+ cycle(t, D, 9, o.seed + 2, (r) => r.range(1.2, 1.8), (age, life, r) => {+ const x = r.range(-14, 14) + Math.sin(age * 3 + r.next() * TAU) * 1.5, y = a.y - 16 + age * 14;+ if (y > a.y + 2) return;+ p.dot(x, y, r.next() < 0.5 ? WHITE : C[6], Math.min(1, age * 4));});-- // 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);+ if (ph < 0.5)+ for (let i = 0; i < 8; i++) {+ const side = i % 2 ? 1 : -1, vx = side * (20 + 30 * rand(i, 4)), vy = -(20 + 30 * rand(i, 5)), x = side * (6 + 6 * rand(i, 6)) + vx * ph, y = a.y + 3 * rand(i, 7) + vy * ph + 0.5 * 300 * ph * ph;+ p.dot(x, y, i % 3 ? C[6] : WHITE, 1.2 - ph * 2);+ }+ if (ph < 0.25) sparkle(p, X(Math.round(S.w * 0.3)), Y(4), Math.round(3 * (1 - ph / 0.25)), C[6], C[5], 0.4);+ // cold light: off the body, lifting with each shiver+ p.glow(0, a.y + H * 0.45, 30, C[4], 0.2 + 0.12 * Math.exp(-ph / 0.2));+ p.glow(0, a.y + 2, 16, C[5], 0.1);}diff --git a/src/fx/status/haste.js b/src/fx/status/haste.jsindex 1198ef5..b819f07 100644--- a/src/fx/status/haste.js+++ b/src/fx/status/haste.js@@ -1,48 +1,93 @@-import { PAL, cycle } from "../../core/index.js";-import { steps } from "./_lib.js";+// The banded after-images, the dotted speed lines with bright heads and the kicked-up dust are+// adapted from Sprite Fusion's open-source movement dash (https://www.spritefusion.com/pixel-art-vfx/movement),+// MIT License, Copyright (c) 2026 Hugo Duprez.+import { cycle, fit, hex, luma, rand, TAU } from "../../core/index.js";+import { shape, colorAt, travel } 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,+ desc: "Sped up: striped after-images stream out behind, speed lines whip past, dust kicks off the heels and the leading edge catches the wind. Faces right.",+ tags: ["status", "haste", "speed", "fast", "buff", "directional", "loop"],+ size: [100, 56],+ origin: [64, 48],+ duration: 1.2,loop: true,fps: 30,bg: "ground",- actor: true,- options: { palette: PAL.volt, seed: 3 },+ actor: 2,+ options: { palette: ["#4c25ab", "#773ae4", "#5b6cff", "#5eb0ff", "#a3dcff", "#ccf6ff", "#ffffff"], dust: "#8a8090", seed: 4 },};-// behind the body: afterimages, each a striped copy of the silhouette, trailing and shivering+const D = meta.duration;++// the character's shading in three levels (dark outline, mid, light), for the after-images+const LEVELS = new WeakMap();+function levels(a) {+ let l = LEVELS.get(a.mask);+ if (l) return l;+ const S = shape(a);+ l = S.body.map(([x, y]) => {+ const v = luma(colorAt(a, x, y));+ return [x, y, v < 0.24 ? 1 : v < 0.66 ? 2 : 3];+ });+ LEVELS.set(a.mask, l);+ return l;+}+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);+ const C = fit(o.palette, 7), a = o.actor, L = levels(a), S = shape(a), f = Math.floor(t * 30);+ // three after-images trailing back, each a step colder and cut into thinner stripes that scroll, jittering+ for (let g = 3; g >= 1; g--) {+ const dx = -g * 14 - Math.round(rand(f >> 1, g, 3) * 1.6), every = [0, 3, 4, 0][g];+ // its outline, solid near, broken further back, and a few scrolling stripes across it+ p.outline(a.mask, a.x + dx, a.y, (mx, my) => (g === 3 && (mx + my) % 2 ? 0 : C[5 - g]));+ if (every)+ for (const [x, y, v] of L) {+ if ((((y + f) % every) + every) % every) continue;+ p.px(a.x + x + dx, a.y + y, C[Math.max(0, Math.min(6, 5 - g + v - 2))]);}- }+ p.glow(a.x + a.w / 2 + dx, a.y + a.h * 0.45, 16, C[3], 0.12 * (1 - g * 0.25));+ }+ // a smear streaming off the trailing edge+ for (const [x, y, dir] of S.side) {+ if (dir > 0 || (y + (f >> 1)) % 3) continue;+ const len = 3 + Math.floor(rand(y, f >> 1, 5) * 6);+ for (let d = 1; d <= len; d++) p.dot(a.x + x - d, a.y + y, d < 3 ? C[5] : C[4], 1 - d / (len + 1));}- // 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]));+ // speed lines whipping past behind+ lines(p, C, a, t, o.seed, false);+ // dust kicked off the heels, rolling away behind+ const dust = hex(o.dust);+ cycle(t, D, 12, o.seed + 5, (r) => r.range(0.45, 0.7), (age, life, r, i) => {+ const u = age / life, foot = i % 2 ? -7 : 3, x = foot + travel(-r.range(50, 100), 0, 3.5, age), y = -1.5 - travel(r.range(6, 18), 0, 3.5, age);+ const rad = r.range(2.6, 4.6) * (0.6 + 1 * u), k = Math.pow(1 - u, 1.2) * Math.min(1, u * 10);+ p.disc(x, y, rad, dust, k * 0.5);+ p.disc(x + rad * 0.05, y + rad * 0.08, rad * 0.74, dust, k * 0.62);+ p.disc(x - rad * 0.22, y - rad * 0.3, rad * 0.5, C[5], k * 0.25);});- 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]);+// streaks: a bright head, a coloured body, a dotted tail thinning out behind (some cut across the body in front)+function lines(p, C, a, t, seed, front) {+ cycle(t, D, front ? 5 : 11, seed + (front ? 9 : 7), (r) => r.range(0.12, 0.26), (age, life, r) => {+ const u = age / life, y = a.y + r.range(2, a.h - 3), len = r.range(10, 26) * (front ? 0.7 : 1);+ const x = r.range(-14, 4) - age * r.range(160, 240);+ for (let d = 0; d < len; d++) {+ if (d > len * 0.45 && d % 2) continue;+ p.dot(x + d, y, d < 2 ? C[6] : d < len * 0.4 ? C[5] : C[3], (1 - d / len) * (1 - u) * (front ? 0.7 : 1.1));+ }+ p.light(x, y, C[4], 0.4 * (1 - u));});}++export function draw(p, t, o) {+ const C = fit(o.palette, 7), a = o.actor, S = shape(a);+ // the leading edge catches the wind: a bright rim, flickering+ for (const [x, y, dir] of S.side) if (dir > 0 && rand(x, y, Math.floor(t * 15)) < 0.85) p.px(a.x + x, a.y + y, rand(y, Math.floor(t * 15), 2) < 0.3 ? C[6] : C[5]);+ lines(p, C, a, t, seed(o), true);+ // a cool glow streaming off the back+ p.glow(-6, a.y + a.h * 0.5, 22, C[3], 0.16);+ p.glow(0, a.y + a.h * 0.45, 30, C[3], 0.16);+ p.glow(a.x + a.w, a.y + a.h * 0.5, 10, C[5], 0.12 + 0.06 * Math.sin((t / D) * TAU * 3));+}+const seed = (o) => o.seed;diff --git a/src/fx/status/invisible.js b/src/fx/status/invisible.jsdeleted file mode 100644index 10ec5d4..0000000--- a/src/fx/status/invisible.js+++ /dev/null@@ -1,51 +0,0 @@-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.jsdeleted file mode 100644index 0b5d831..0000000--- a/src/fx/status/marked.js+++ /dev/null@@ -1,49 +0,0 @@-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.jsindex d93e0a2..fb44f87 100644--- a/src/fx/status/petrified.js+++ b/src/fx/status/petrified.js@@ -1,99 +1,165 @@-import { PAL, burst, rng, rand, seg, ease, clamp, noise } from "../../core/index.js";-import { steps, geom, recolor, tone } from "./_lib.js";+// The creeping front, the branching cracks and the burst of the body into chunks, grit and dust are+// adapted from Sprite Fusion's open-source ice freeze and shatter (https://www.spritefusion.com/pixel-art-vfx/ice),+// MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Bits, Lights, P, B, Rng, fit, rand, clamp, luma, smooth, tileFbm, TAU, WHITE } from "../../core/index.js";+import { shape, colorAt } 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,+ desc: "Turned to stone: grey creeps up from the feet behind a crackling edge that spits grit, the statue holds, cracks run through it, and it bursts into tumbling chunks and dust.",+ tags: ["status", "stone", "petrify", "petrified", "debuff", "death", "one-shot"],+ size: [120, 74],+ origin: [60, 64],+ duration: 3.8,loop: false,fps: 30,bg: "ground",- actor: true,- options: { palette: PAL.stone, seed: 7 },+ actor: 2,+ options: { palette: ["#16141c", "#2a2733", "#433f4d", "#5f5a6a", "#7d7889", "#a29dab", "#cdc8d2", "#f0edf3"], seed: 3 },};-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);+const CREEP = 0.95, CRACK = 1.75, SHATTER = 2.2;-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));+/** The stand-in character is gone once the stone covers it (the statue is drawn in its place). */+export const actorAlpha = (t) => (t < CREEP ? 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]);- }+// how far up the stone has crept (0 at the feet, past 1 over the head), stuttering as it climbs+const level = (t) => (t >= CREEP ? 1.2 : 1.2 * smooth(0, CREEP, t) + 0.025 * Math.sin((t / CREEP) * TAU * 3));++export function create(o) {+ const C = fit(o.palette, 8), a = o.actor, S = shape(a), H = S.h, R = new Rng(o.seed), floor = () => 0;+ const ps = new Particles({ rng: R, ground: floor, sparks: [C[7], C[6], C[5], C[4]] });+ const bits = new Bits({ ground: floor }), lights = new Lights();+ const front = (mx) => level(t) + 0.06 * tileFbm(mx * 0.4, 0.5, 0, 0, o.seed, 2);+ // each pixel's stone: its own shading walked down a grey ramp, grained, lit on the top left+ const stone = S.body.map(([x, y]) => {+ const tone = clamp((luma(colorAt(a, x, y)) - 0.06) / 0.78), mottle = tileFbm(x * 0.32, y * 0.32, 0, 0, o.seed + 5, 2);+ let i = 1 + Math.round(tone * 4.6 + mottle * 1.1);+ if (!S.on(x - 1, y) || !S.on(x, y - 1)) i += 1;+ else if (!S.on(x + 1, y) || !S.on(x, y + 1)) i -= 1;+ return { x, y, up: 1 - (y + 0.5) / H, c: C[clamp(i, 1, 6)] };+ });+ // cracks: random walks through the statue from a point on its chest+ const cracks = [], ox = Math.round(S.w * 0.55), oy = Math.round(H * 0.42);+ const walk = (x, y, ang, len) => {+ const pts = [[x, y]];+ for (let s = 0; s < len; s++) {+ ang += R.range(-0.55, 0.55);+ x += Math.cos(ang) * R.range(1.4, 2.4);+ y += Math.sin(ang) * R.range(1.4, 2.4);+ if (!S.on(Math.floor(x), Math.floor(y))) break;+ pts.push([x, y]);+ if (pts.length > 3 && cracks.length < 16 && R.chance(0.14)) walk(x, y, ang + R.sign() * R.range(0.6, 1.2), len / 2);}- p.glow(0, a.y + a.h * (1 - creep), 10, C[6], 0.2 * (1 - seg(t, 0.95, 1.1)));- return;- }+ cracks.push(pts);+ };+ for (let i = 0; i < 7; i++) walk(ox, oy, (i / 7) * TAU + R.range(-0.3, 0.3), 14);+ let t = 0, broke = false, settled = false;- // 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);+ return {+ update(dt) {+ t += dt;+ // the creeping edge spits grit and dust and the odd spark+ if (t < CREEP) {+ const rate = 60 * dt;+ for (let n = 0; n < rate; n++) {+ if (!R.chance(0.5)) continue;+ const [mx, my] = S.body[R.int(0, S.body.length - 1)];+ if (Math.abs(1 - (my + 0.5) / H - front(mx)) > 0.04) continue;+ const x = a.x + mx + 0.5, y = a.y + my, side = mx < S.w / 2 ? -1 : 1;+ ps.spawn(P.GRIT, x, y, side * R.range(15, 60), -R.range(30, 90), R.range(0.6, 1.1), R.pick([C[4], C[5], C[6]]), R.chance(0.3) ? 2 : 1);+ if (R.chance(0.3)) ps.spawn(P.DUST, x + side * 2, y, side * R.range(10, 30), -R.range(4, 14), R.range(0.4, 0.7), C[4], R.range(1.5, 2.6));+ if (R.chance(0.25)) ps.spawn(P.MOTE, x, y, side * R.range(40, 90), -R.range(20, 70), R.range(0.15, 0.3), C[7], 0.5);+ }}- 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);+ if (!settled && t >= CREEP) {+ settled = true;+ lights.add(0, a.y + H * 0.5, 34, C[6], 0.35, 0.3);+ for (let i = 0; i < 8; i++) ps.spawn(P.DUST, R.range(-8, 8), -R.range(0, 2), R.sign() * R.range(20, 50), -R.range(2, 10), R.range(0.6, 1), C[3], R.range(2, 3.5));+ }+ // while it holds a pebble or two drops off+ if (t > CREEP + 0.2 && t < SHATTER && R.chance(1.6 * dt)) {+ const [mx, my] = S.body[R.int(0, S.body.length - 1)];+ if (!S.on(mx, my + 1)) ps.spawn(P.GRIT, a.x + mx + 0.5, a.y + my + 1, R.range(-8, 8), 0, R.range(0.8, 1.2), C[3], 1);+ }+ // the cracks pop chips off as they run+ if (t >= CRACK && t < SHATTER && R.chance(12 * dt)) {+ const pts = R.pick(cracks), [x, y] = pts[Math.floor(R.next() * pts.length)];+ ps.spawn(P.GRIT, a.x + x, a.y + y, R.range(-40, 40), -R.range(30, 80), R.range(0.5, 0.9), R.pick([C[5], C[6]]), 1);+ }+ if (!broke && t >= SHATTER) {+ broke = true;+ lights.add(0, a.y + H * 0.45, 46, C[6], 0.7, 0.5);+ lights.add(0, a.y + H * 0.45, 30, WHITE, 0.7, 0.12);+ // the statue bursts: chunks tumble out, grit sprays, dust rolls along the floor+ const cx = a.x + ox, cy = a.y + oy;+ for (let i = 0; i < 18; i++) {+ const q = stone[R.int(0, stone.length - 1)], x = a.x + q.x + 0.5, y = a.y + q.y + 0.5, dx = x - cx, dy = y - cy, d = Math.hypot(dx, dy) || 1, sp = R.range(35, 110);+ bits.add({ kind: B.CHUNK, x, y, vx: (dx / d) * sp, vy: (dy / d) * sp * 0.6 - R.range(60, 160), g: 1, drag: 0.4, bounce: 0.3, life: R.range(1.1, 1.5), a: R.range(0, TAU), va: R.range(-14, 14), s: R.range(1.3, 2.8), ramp: [C[0], C[2], C[3], C[5], C[6]] });+ }+ for (const q of stone) {+ if (rand(q.x, q.y, 9) > 0.22) continue;+ const x = a.x + q.x + 0.5, y = a.y + q.y + 0.5, dx = x - cx, dy = y - cy, d = Math.hypot(dx, dy) || 1, sp = R.range(40, 130);+ ps.spawn(P.GRIT, x, y, (dx / d) * sp, (dy / d) * sp * 0.6 - R.range(40, 140), R.range(0.9, 1.4), q.c, R.chance(0.35) ? 2 : 1);+ }+ // pale flakes of the skin of it, tumbling, and glints in the dust+ for (let i = 0; i < 16; i++) {+ const an = -Math.PI / 2 + R.range(-1.4, 1.4), sp = R.range(50, 120);+ bits.add({ kind: B.SHARD, x: cx + R.range(-5, 5), y: cy + R.range(-8, 8), vx: Math.cos(an) * sp, vy: Math.sin(an) * sp, g: 0.8, drag: 0.6, bounce: 0.3, life: R.range(0.9, 1.4), a: R.range(0, TAU), va: R.range(-18, 18), s: R.range(1.5, 3), c: R.pick([C[5], C[6], C[7]]) });+ }+ for (let i = 0; i < 6; i++) ps.spawn(P.STAR, cx + R.range(-12, 12), cy + R.range(-10, 14), R.range(-10, 10), -R.range(5, 20), R.range(0.4, 0.9), C[6], R.range(1, 2.2), R.range(0.05, 0.4));+ for (let i = 0; i < 12; i++) {+ const side = R.sign();+ ps.spawn(P.SMOKE, side * R.range(0, 8), -R.range(1, 6), side * R.range(20, 60), -R.range(4, 16), R.range(0.9, 1.4), C[4], R.range(2.4, 4), R.range(0, 0.08), 0);+ }+ for (let i = 0; i < 6; i++) ps.spawn(P.SMOKE, R.range(-6, 6), a.y + H * R.range(0.3, 0.8), R.range(-20, 20), -R.range(10, 30), R.range(1, 1.5), C[3], R.range(3, 4.5), R.range(0, 0.1), 0);+ }+ bits.update(dt);+ // chunks that hit hard kick up a little dust+ for (const b of bits.list)+ if (b.rest && !b.dusted) {+ b.dusted = true;+ ps.spawn(P.DUST, b.x, -0.5, R.range(-20, 20), -R.range(2, 10), R.range(0.3, 0.6), C[3], R.range(1.2, 2.2));+ }+ ps.update(dt);+ lights.update(dt);+ },+ drawBack(p) {+ ps.draw(p, "back");+ },+ draw(p) {+ if (t < SHATTER) {+ // the shudder before it breaks+ const sh = t >= CRACK ? Math.round(Math.sin(t * 90) * Math.min(1, (t - CRACK) / (SHATTER - CRACK)) * 1.2) : 0;+ const white = t > SHATTER - 0.035;+ for (const q of stone) {+ const f = front(q.x), d = f - q.up;+ if (d < 0) continue;+ const x = a.x + q.x + sh, y = a.y + q.y;+ // the crackling edge: bright, flickering+ if (d < 0.035 && t < CREEP) p.px(x, y, rand(q.x, q.y, Math.floor(t * 24)) < 0.5 ? C[7] : C[6]);+ else if (d < 0.07 && t < CREEP) p.px(x, y, C[5]);+ else p.px(x, y, white ? WHITE : q.c);+ }+ if (t < CREEP) for (let mx = 0; mx < S.w; mx += 2) {+ const my = Math.floor((1 - front(mx)) * H);+ if (S.on(mx, my)) p.glow(a.x + mx, a.y + my, 5, C[6], 0.18);+ }+ // the cracks running through it, fresh tips white+ if (t >= CRACK) {+ const k = clamp((t - CRACK) / 0.3);+ for (const pts of cracks)+ for (let i = 0, n = Math.floor(pts.length * k); i < n; i++) {+ const [x, y] = pts[i], px = Math.floor(a.x + x) + sh, py = Math.floor(a.y + y), fresh = i > n - 3;+ p.px(px, py, fresh ? WHITE : C[0]);+ if (!fresh) p.px(px, py - 1, C[6]);+ }+ p.glow(a.x + ox, a.y + oy, 12, C[6], 0.25 * k);+ }+ }+ bits.draw(p);+ ps.draw(p, "front");+ lights.draw(p);+ },+ };}diff --git a/src/fx/status/poisoned.js b/src/fx/status/poisoned.jsindex 7ab31f7..1356304 100644--- a/src/fx/status/poisoned.js+++ b/src/fx/status/poisoned.js@@ -1,81 +1,148 @@-import { PAL, cycle, clamp, bump, ease, TAU } from "../../core/index.js";-import { steps, geom, recolor, tone } from "./_lib.js";+import { fit, hex, mix, luma, rand, Rng, clamp, smooth, band, TAU, WHITE } from "../../core/index.js";+import { shape, colorAt, eyes } 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,+ desc: "Sick to the bone: green rolls up the body in waves, dark veins creep from a wound, toxic sweat drips and hisses; every 0.8 s it wobbles, blisters pop and a ring pulses out.",+ tags: ["status", "poison", "toxic", "dot", "debuff", "sick", "loop"],+ size: [72, 64],+ origin: [36, 54],+ duration: 1.6,loop: true,fps: 30,bg: "ground",- actor: true,- options: { palette: PAL.poison, seed: 5 },+ actor: 2,+ options: { palette: ["#0e1d14", "#173320", "#23552e", "#318232", "#55b92f", "#8eea3f", "#cfff63", "#f6ffc2"], veins: "#2c1a3a", seed: 5 },};-const BUBBLE_S = [".#.", "#.#", ".#."];-const BUBBLE_L = [".##.", "#..#", "#..#", ".##."];+const D = meta.duration, TICK = 0.8, G = 760;+const since = (t) => (((t % TICK) + TICK) % TICK);+/** The effect draws the whole (sick, swaying) body, so the stand-in is hidden throughout. */+export const actorAlpha = () => 0;-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;+// worked out once per character: the veins (walks out from a wound on the forearm), blister spots, sweat spots+const BODIES = new WeakMap();+function body(a, seed) {+ let m = BODIES.get(a.mask);+ if (!m) BODIES.set(a.mask, (m = new Map()));+ if (m.has(seed)) return m.get(seed);+ const S = shape(a), H = S.h, W = S.w, R = new Rng(seed * 7 + 3);+ const [l, r] = S.rows[Math.round(H * 0.6)], wx = r - 1, wy = Math.round(H * 0.6);+ const veins = [];+ const walk = (x, y, ang, len, depth) => {+ const pts = [];+ for (let s = 0; s < len; s++) {+ ang += R.range(-0.5, 0.5);+ x += Math.cos(ang);+ y += Math.sin(ang);+ if (!S.on(Math.round(x), Math.round(y))) break;+ pts.push([Math.round(x), Math.round(y), s / len]);+ if (depth < 2 && s > 2 && R.chance(0.16)) walk(x, y, ang + R.sign() * R.range(0.6, 1.1), len * 0.55, depth + 1);+ }+ veins.push(pts);+ };+ for (let i = 0; i < 4; i++) walk(wx, wy, Math.PI + (i / 4 - 0.45) * 2.2, 11, 0);+ const lum = (x, y) => luma(colorAt(a, x, y));+ const skin = S.body.filter(([x, y]) => lum(x, y) > 0.55 && S.on(x - 1, y) && S.on(x + 1, y));+ const pick = (list) => list[Math.floor(R.next() * list.length)];+ const blisters = [0, 1].map(() => [0, 1, 2].map(() => {+ const [x, y] = pick(S.body.filter(([x, y]) => y > 4 && S.on(x - 1, y) && S.on(x + 1, y) && S.on(x, y - 1)));+ return { x, y, r: R.range(1.1, 1.8) };+ }));+ const E = eyes(a), sweat = [];+ for (const e of E) sweat.push([e.x0 < W / 2 ? e.x0 - 1 : e.x1 + 1, e.y0 - 1]);+ for (const side of [-1, 1]) {+ const hand = S.body.filter(([x, y]) => y > H * 0.5 && y < H * 0.7 && (side < 0 ? x <= l + 1 : x >= r - 1) && !S.on(x, y + 1));+ if (hand.length) sweat.push(hand[0]);+ }+ if (!sweat.length) sweat.push(pick(skin.length ? skin : S.body));+ const out = { veins, wound: [wx, wy], blisters, sweat };+ m.set(seed, out);+ return out;}-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));+// the sway: the body leans from the feet, the head moving most; on the tick, every row wobbles a pixel+function offsets(t, H) {+ const lean = 1.3 * Math.sin((t / D) * TAU), ph = since(t), wob = ph < 0.12;+ const w = wob ? Math.sin((ph / 0.12) * Math.PI) : 0;+ return (my) => Math.round(lean * (1 - my / H) + w * Math.sin(my * 0.42 + ph * 40));+}- // 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]);- }+export function drawBack(p, t, o) {+ const P = fit(o.palette, 8), ph = since(t);+ // a green ring pulses out across the floor on the tick (far half), the floor glows sick+ const k = ph / 0.55;+ if (k < 1) band(p, 0, 0, 5 + 22 * Math.sqrt(k), 0.18, Math.max(1, 2.5 * (1 - k)), 1 - k, [P[3], P[4], P[5], P[6]], (g) => Math.sin(g) < 0);+ p.shade(-28, -3, 28, 6, (x, y, out) => {+ const d = Math.hypot(x / 24, (y - 0.5) / 4);+ if (d < 1) (out.l = P[4]), (out.k = (0.14 + 0.2 * Math.exp(-ph / 0.2)) * (1 - d) * (1 - d));});+}- // 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;+export function draw(p, t, o) {+ const P = fit(o.palette, 8), a = o.actor, S = shape(a), H = S.h, B = body(a, o.seed), off = offsets(t, H), ph = since(t), tick = Math.floor(t / TICK) % 2;+ const vein = hex(o.veins);+ // the body, swaying, its own colours sickened by green that rolls up it in waves+ for (const [mx, my] of S.body) {+ const c = colorAt(a, mx, my), l = luma(c), wave = 0.5 + 0.5 * Math.sin(TAU * ((my / H) * 1.6 + (t / D) * 2));+ const sick = P[clamp(1 + Math.round(l * 6.2), 1, 7)], k = 0.22 + 0.4 * wave * wave;+ p.px(a.x + mx + off(my), a.y + my, mix(c, wave > 0.85 && l > 0.4 ? mix(sick, P[6], 0.3) : sick, k));+ }+ // veins creeping out from the wound and drawing back+ const grow = smooth(0, D * 0.55, t) * (1 - smooth(D * 0.62, D, t)) * 1.15;+ for (const pts of B.veins)+ for (const [x, y, u] of pts) if (u < grow) p.px(a.x + x + off(y), a.y + y, u > grow - 0.12 ? P[2] : vein);+ const [wx, wy] = B.wound;+ p.px(a.x + wx + off(wy), a.y + wy, P[6]);+ p.px(a.x + wx + off(wy) - 1, a.y + wy, P[3]);+ p.glow(a.x + wx, a.y + wy, 6, P[5], 0.3);+ // blisters: on the tick they swell up out of the skin, shine, and pop+ for (const bl of B.blisters[tick]) {+ const x = a.x + bl.x + off(bl.y), y = a.y + bl.y, grow2 = clamp(ph / 0.16), pop = ph > 0.38;+ if (!pop) {+ const r = bl.r * grow2;+ p.circle(x, y, r + 0.6, P[3]);+ p.circle(x - 0.2, y - 0.2, r, P[5]);+ if (r > 0.8) p.px(x - 0.5, y - 0.8, WHITE);+ p.glow(x, y, 4, P[5], 0.3 * grow2);+ } else if (ph < 0.56) {+ const k = (ph - 0.38) / 0.18;+ for (let j = 0; j < 6; j++) {+ const an = (j / 6) * TAU + bl.x, d = bl.r + 0.5 + k * 3.5;+ p.dot(x + Math.cos(an) * d, y + Math.sin(an) * d - k * 2, j % 2 ? P[6] : P[5], 1.2 - k);+ }+ p.glow(x, y, 6, P[6], 0.4 * (1 - k));}- const y = y0 + 1 + 140 * fall * fall;- if (y < -0.5) {- p.px(x, y, P[6]), p.px(x, y - 1, P[4]);+ }+ // toxic sweat: beads gather, run, fall and hiss on the floor+ B.sweat.forEach(([sx, sy], i) => {+ const per = D / 2, age = (((t - i * 0.37) % per) + per) % per, gather = 0.35;+ const x = a.x + sx + 0.5 + off(sy), y0 = a.y + sy;+ if (age < gather) {+ const k = age / gather, run = Math.round(k * 2);+ p.px(x, y0 + run, k > 0.5 ? P[6] : P[5]);+ if (k > 0.5) p.px(x, y0 + run - 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]);+ const f = age - gather, fallH = -1 - (y0 + 2), tf = Math.sqrt((2 * Math.max(1, fallH)) / G);+ if (f < tf) {+ const y = y0 + 2 + 0.5 * G * f * f;+ p.line(x, y - Math.min(3, G * f * 0.012), x, y, P[4]);+ p.px(x, y, P[6]);+ return;}+ const h = f - tf;+ if (h > 0.4) return;+ // the hiss: a green fleck spreads, a wisp of vapour curls up, sizzle sparks+ const k = h / 0.4;+ p.line(x - 1 - k * 2, -1, x + 1 + k * 2, -1, P[k < 0.4 ? 6 : 4], 1.2 - k);+ for (let j = 0; j < 3; j++) p.dot(x + (j - 1) * (2 + 3 * k), -2 - j % 2 - 5 * k * (1 - k), P[6], 1 - k);+ p.disc(x + Math.sin(k * 6) * 1.5, -3 - k * 6, 1 + 1.5 * k, P[5], 0.35 * (1 - k));+ p.glow(x, -1.5, 5, P[5], 0.35 * (1 - k));});-- p.glow(0, a.y + 9, 20, P[4], 0.12 + 0.2 * pulse);+ // the near half of the floor ring+ const k = ph / 0.55;+ if (k < 1) band(p, 0, 0, 5 + 22 * Math.sqrt(k), 0.18, Math.max(1, 2.5 * (1 - k)), 1 - k, [P[3], P[4], P[5], P[6]], (g) => Math.sin(g) >= 0);+ // a sick light on the body, surging with the tick+ p.glow(0, a.y + H * 0.45, 26, P[4], 0.14 + 0.2 * Math.exp(-ph / 0.18));}diff --git a/src/fx/status/rage.js b/src/fx/status/rage.jsindex b786d66..3eb934a 100644--- a/src/fx/status/rage.js+++ b/src/fx/status/rage.js@@ -1,54 +1,156 @@-import { cycle, tileFbm, bump, clamp, at } from "../../core/index.js";-import { steps, geom, recolor, tone } from "./_lib.js";+// The shaded, outlined anger mark and the embers are+// adapted from Sprite Fusion's open-source heal and fire (https://www.spritefusion.com/pixel-art-vfx/heal),+// MIT License, Copyright (c) 2026 Hugo Duprez.+import { cycle, fit, hex, mix, luma, rand, Rng, clamp, TAU } from "../../core/index.js";+import { shape, colorAt, eyes, icon, bitmap, travel, ember } 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,+ desc: "Seething: the body judders on every heartbeat, an anger mark throbs at the temple, eyes burn, steam jets off the head, stress lines flash out and the floor cracks hot underfoot.",+ tags: ["status", "rage", "berserk", "anger", "buff", "loop"],+ size: [80, 80],+ origin: [40, 70],+ duration: 1.2,loop: true,fps: 30,bg: "ground",- actor: true,+ actor: 2,options: {- palette: ["#1a0306", "#3c060c", "#6e0a12", "#a8121a", "#e0261e", "#ff5a2a", "#ffa060", "#fff0c8"],- seed: 2,+ palette: ["#1a0208", "#4a0612", "#8a0c1c", "#c81828", "#ff3040", "#ff7a7a", "#ffc8c8", "#ffffff"],+ heat: ["#5a0a0a", "#c8281a", "#ff7a2a", "#ffd27a"],+ steam: "#f2e8ee",+ seed: 6,},};-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));+const D = meta.duration, LUB = 0.05, DUB = 0.29, G = 760;+const pulse = (t, at, w = 0.06) => Math.exp(-((((((t - at) % D) + D + D / 2) % D - D / 2) / w) ** 2));+const beat = (t) => pulse(t, LUB) + 0.65 * pulse(t, DUB);+// how long after the last lub or dub it is+const since = (t, at) => (((t - at) % D) + D) % D;+// the body judders for a moment on each beat+const shaking = (t) => since(t, LUB - 0.02) < 0.13 || since(t, DUB - 0.02) < 0.09;++/** The stand-in is hidden while the body judders: the effect draws it, shaken. */+export const actorAlpha = (t) => (shaking(t) ? 0 : 1);++// the anger mark: four curves round a cross-shaped gap, at two sizes for the throb+const MARK = [+ bitmap(["..#.#..", "..#.#..", "##...##", ".......", "##...##", "..#.#..", "..#.#.."]),+ bitmap(["...#.#...", "...#.#...", "..##.##..", "###...###", ".........", "###...###", "..##.##..", "...#.#...", "...#.#..."]),+];++// cracks in the floor round the feet, worked out once per seed: jagged runs out from under each foot+const CRACKS = new Map();+function cracks(a, seed) {+ if (CRACKS.has(seed)) return CRACKS.get(seed);+ const S = shape(a), [fl, fr] = S.rows[S.h - 1], R = new Rng(seed * 31 + 7), out = [];+ for (const [x0, dir] of [[a.x + fl + 2, -1], [a.x + fr - 1, 1], [a.x + (fl + fr) / 2, -1], [a.x + (fl + fr) / 2 + 1, 1]]) {+ let x = x0, y = 0.5;+ const pts = [[x, y]], n = R.int(5, 9);+ for (let i = 0; i < n; i++) {+ x += dir * R.range(1.2, 2.4);+ y = clamp(y + R.range(-0.9, 0.9), 0, 2.5);+ pts.push([x, y]);+ if (i > 1 && R.chance(0.3)) out.push([[x, y], [x + dir * R.range(1, 2), clamp(y + R.sign() * R.range(0.6, 1.4), 0, 3)]]);+ }+ out.push(pts);+ }+ CRACKS.set(seed, out);+ return out;+}-// behind: the aura, a flame field around the silhouette that roars upward and swells on the beatexport 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);+ const C = fit(o.palette, 8), Hh = fit(o.heat, 4), a = o.actor, b = beat(t), stamp = Math.exp(-since(t, LUB) / 0.18);+ // dark-red heat shimmering up round the body+ cycle(t, D, 9, o.seed + 2, (r) => r.range(0.7, 1.1), (age, life, r) => {+ const u = age / life, x0 = r.range(-16, 16), y = a.y + r.range(10, 40) - age * r.range(14, 22), len = r.range(6, 11), ph = r.range(0, TAU);+ const k = Math.sin(Math.PI * u) * 0.55;+ for (let d = 0; d < len; d++) p.dot(x0 - len / 2 + d, y + Math.round(Math.sin(d * 0.9 + ph + age * 12) * 0.8), d % 3 ? C[2] : C[1], k * (1 - Math.abs(d / len - 0.5) * 1.4));+ });+ // the floor: red light pooling, cracks under the feet glowing hot on each stamp and cooling between+ p.shade(-30, -4, 30, 8, (x, y, out) => {+ const d = Math.hypot(x / 28, (y - 0.5) / 4.5);+ if (d < 1) (out.l = C[3]), (out.k = (0.2 + 0.3 * b) * (1 - d) * (1 - d));});- p.glow(0, a.y + 8, 30, R[4], 0.18 + 0.22 * beat);+ const heat = 0.25 + 0.75 * stamp;+ for (const pts of cracks(a, o.seed))+ for (let i = 1; i < pts.length; i++) {+ const [x0, y0] = pts[i - 1], [x1, y1] = pts[i], far = i / pts.length;+ p.line(x0, y0, x1, y1, heat * (1 - far * 0.6) > 0.6 ? Hh[3] : heat * (1 - far * 0.5) > 0.35 ? Hh[2] : Hh[1]);+ if (i % 2) p.glow(x1, y1, 4, Hh[2], 0.25 * heat * (1 - far * 0.5));+ }}-// in front: the body flushes and its outline flares on the beat, streaks shoot up, the anger mark popsexport 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]);+ const C = fit(o.palette, 8), Hh = fit(o.heat, 4), a = o.actor, S = shape(a), b = beat(t), steam = hex(o.steam);+ const shake = shaking(t), dx = shake ? (Math.floor(t * 60) % 2 ? 1 : -1) : 0, dy = shake && since(t, LUB - 0.02) < 0.06 ? -1 : 0;+ // the body: shaken while the beat lands, the face flushing red with it+ for (const [mx, my] of S.body) {+ const c = colorAt(a, mx, my), l = luma(c), skin = l > 0.55 && (c & 255) > ((c >>> 16) & 255) + 30;+ if (skin) p.px(a.x + mx + dx, a.y + my + dy, mix(c, C[4], 0.22 + 0.3 * b));+ else if (shake) p.px(a.x + mx + dx, a.y + my + dy, c);+ }+ // burning eyes under angry brows+ for (const e of eyes(a)) {+ const ex = a.x + dx, ey = a.y + dy, inner = (e.x0 + e.x1) / 2 < a.w / 2 ? 1 : -1;+ for (const [x, y] of e.px) p.px(ex + x, ey + y, y === e.y0 ? C[7] : y === e.y0 + 1 ? C[6] : C[4]);+ const xi = inner > 0 ? e.x1 : e.x0, xo = inner > 0 ? e.x0 : e.x1;+ p.px(ex + xo - inner, ey + e.y0 - 2, 0xff1f1726);+ p.px(ex + xo, ey + e.y0 - 2, 0xff1f1726);+ p.px(ex + xi, ey + e.y0 - 1, 0xff1f1726);+ p.glow(ex + (e.x0 + e.x1 + 1) / 2, ey + e.y0 + 1, 5, C[5], 0.35 + 0.35 * b);+ }+ // the anger mark throbbing at the temple: big on the lub, smaller on the dub+ const big = pulse(t, LUB + 0.02, 0.05) > 0.35 || pulse(t, DUB + 0.02, 0.04) > 0.6;+ const mx = a.x + a.w * 0.86 + dx, my = a.y + 3 + dy;+ icon(p, mx, my, 5, MARK[big ? 1 : 0], [C[0], C[3], C[4], C[5]]);+ p.px(mx - (big ? 3 : 2), my - (big ? 3 : 2), C[6]);+ p.glow(mx, my, 8, C[4], 0.25 + 0.4 * b);+ // steam jetting off the head in short bursts after each beat+ for (const [at, n, power] of [[LUB + 0.04, 7, 1], [DUB + 0.04, 4, 0.75]])+ for (const side of [-1, 1])+ for (let i = 0; i < n; i++) {+ const age = since(t, at + i * 0.016), life = 0.22 + 0.12 * rand(i, side, 3);+ if (age >= life) continue;+ const u = age / life, ang = -Math.PI / 2 + side * (0.5 + 0.2 * rand(i, side, 5)), sp = (90 + 40 * rand(i, side, 7)) * power;+ const x = side * a.w * 0.36 + Math.cos(ang) * travel(sp, 0, 7, age), y = a.y + 3 + Math.sin(ang) * travel(sp, 0, 7, age) - 8 * age;+ const rad = (1 + 3.2 * Math.sqrt(u)) * (0.8 + 0.4 * rand(i, side, 9)), k = Math.min(1, u * 12) * Math.pow(1 - u, 2);+ p.disc(x, y, rad, steam, 0.7 * k);+ p.disc(x - rad * 0.2, y - rad * 0.25, rad * 0.6, 0xffffffff, 0.6 * k);+ if (u < 0.3) p.dot(x, y, 0xffffffff, 1 - u / 0.3);+ }+ // jagged stress lines flashing out round the head on the beat+ for (const [at, n, len] of [[LUB, 8, 7], [DUB, 6, 5]]) {+ const age = since(t, at);+ if (age > 0.2) continue;+ const k = age / 0.2;+ for (let i = 0; i < n; i++) {+ const ang = -Math.PI / 2 + ((i + 0.5) / n - 0.5) * 4.4, r0 = 15 + 6 * k, ca = Math.cos(ang), sa = Math.sin(ang), cx = 0, cy = a.y + 12;+ const pts = [];+ for (let j = 0; j <= 3; j++) {+ const r = r0 + (j / 3) * len, off = j % 2 ? 1.3 : -0.4;+ pts.push([cx + ca * r - sa * off, cy + sa * r + ca * off]);+ }+ p.polyline(pts, (u) => (u > 0.66 ? C[7] : u > 0.33 ? C[5] : C[4]), 1.2 - k);+ p.glowLine(pts[0][0], pts[0][1], pts[3][0], pts[3][1], 3, C[4], 0.3 * (1 - k));+ }+ }+ // the stamp: embers spat up out of the cracks, grit hopping+ const st = since(t, LUB);+ for (let i = 0; i < 10; i++) {+ const life = 0.5 + 0.5 * rand(i, 11), age = st - 0.02 * rand(i, 12);+ if (age < 0 || age > life) continue;+ const x = (rand(i, 13) - 0.5) * 30 + Math.sin(age * 9 + i) * 1.5 * age, y = -1 + travel(-(40 + 50 * rand(i, 14)), -20, 1.6, age);+ ember(p, x, y, age / life, [Hh[3], Hh[2], Hh[1]], age + i);+ }+ for (let i = 0; i < 12; i++) {+ const vx = (rand(i, 21) - 0.5) * 90, vy = -(40 + 70 * rand(i, 22)), tt = st;+ const x = (rand(i, 23) - 0.5) * 18 + vx * tt, y = -1 + vy * tt + 0.5 * G * tt * tt;+ if (tt > 0.6 || y > 0) continue;+ p.px(x, y, i % 3 ? C[2] : 0xff6a5e72);+ }+ // the beat flares red light round the head and down onto the floor+ p.glow(0, a.y + 10, 26, C[4], 0.12 + 0.4 * b);+ p.glow(0, a.y + 22, 34, C[3], 0.08 + 0.18 * b);}diff --git a/src/fx/status/sleep.js b/src/fx/status/sleep.jsindex 192e373..e439757 100644--- a/src/fx/status/sleep.js+++ b/src/fx/status/sleep.js@@ -1,52 +1,97 @@-import { seg, ease, rng, TAU } from "../../core/index.js";-import { steps } from "./_lib.js";+// The shaded, outlined letters are+// adapted from Sprite Fusion's open-source heal (https://www.spritefusion.com/pixel-art-vfx/heal),+// MIT License, Copyright (c) 2026 Hugo Duprez.+import { cycle, fit, sparkle, TAU } from "../../core/index.js";+import { icon, bitmap, eyes, colorAt } 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.",+ desc: "Fast asleep: eyes shut, soft outlined Zs float up off the head one after another, swaying and growing as they rise, dream motes drift, a slow breathing glow.",tags: ["status", "sleep", "zzz", "rest", "debuff", "loop"],- size: [44, 52],- origin: [16, 48],+ size: [60, 82],+ origin: [26, 74],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,- },+ actor: 2,+ options: { palette: ["#1a1636", "#3c3a7a", "#6f78c8", "#a9b8f0", "#dfe6ff", "#ffffff"], seed: 3 },};-const Z = [- ["####", "..#.", ".#..", "####"],+const D = meta.duration, NZ = 3;+// the letter at four sizes: it grows a step at a time as it rises+const ZS = [["#####", "...#.", "..#..", ".#...", "#####"],- ["######", "....#.", "...#..", "..#...", ".#....", "######"],-];+ ["#######", ".....#.", "....#..", "...#...", "..#....", ".#.....", "#######"],+ [".#######.", "#########", "......##.", ".....##..", "....##...", "...##....", "..##.....", "#########", ".#######."],+ [".#########.", "###########", ".......###.", "......###..", ".....###...", "....###....", "...###.....", "..###......", ".###.......", "###########", ".#########."],+].map((rows) => bitmap(rows));-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);+// a Z at age u (0..1): where it is, how big, how solid+function zAt(a, i, u) {+ const side = i % 2 ? 1 : 0.6, x0 = a.x + a.w * 0.78, y0 = a.y + 7;+ const x = x0 + 13 * side * u + 2.5 * Math.sin(TAU * 1.1 * u + i * 2.1), y = y0 - 32 * (1 - Math.pow(1 - u, 1.35));+ const size = u < 0.18 ? 0 : u < 0.42 ? 1 : u < 0.68 ? 2 : 3, k = Math.min(1, u / 0.06);+ return { x, y, size, k };+}++// shut the eyes: paint them over with skin and draw a soft lid line+function shut(p, a) {+ for (const e of eyes(a)) {+ for (const [x, y] of e.px) p.px(a.x + x, a.y + y, e.skin);+ const lid = colorAt(a, e.x0 - 1, e.y0 - 4) || colorAt(a, e.px[0][0], e.px[0][1]);+ const y = a.y + e.y1 - 1;+ for (let x = e.x0; x <= e.x1; x++) p.px(a.x + x, y, 0xff1f1726);+ p.px(a.x + e.x0 - 1, y - 1, 0xff1f1726);+ p.px(a.x + e.x1 + 1, y - 1, 0xff1f1726);+ void lid;+ }}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]);+ const C = fit(o.palette, 6), a = o.actor, breath = 0.5 + 0.5 * Math.sin((t / D) * TAU * 2);+ shut(p, a);+ // a slow breathing glow round the head, and soft dream light drifting about it+ p.glow(0, a.y + 10, 24, C[3], 0.1 + 0.1 * breath);+ cycle(t, D, 5, o.seed + 6, D, (age, life, r) => {+ const u = age / life, x = a.x + a.w * r.range(0.3, 1.1) + Math.sin(u * TAU + r.next() * TAU) * 3, y = a.y + r.range(-6, 8) - u * 10;+ const rad = r.range(3, 5) * (0.8 + 0.4 * u), k = Math.sin(Math.PI * u);+ p.glow(x, y, rad * 2.4, C[3], 0.1 * k);+ });+ // dream motes drifting up+ cycle(t, D, 14, o.seed + 4, (r) => r.range(1.2, 2), (age, life, r) => {+ const u = age / life, x = a.x + a.w * r.range(0.4, 1.1) + Math.sin(age * 2 + r.next() * TAU) * 2, y = a.y + r.range(0, 10) - age * r.range(10, 18);+ const tw = Math.sin(Math.PI * u) * (0.6 + 0.4 * Math.sin(age * 9 + r.next() * TAU));+ if (tw < 0.15) return;+ sparkle(p, x, y, tw > 0.7 && r.next() < 0.4 ? 1 : 0, C[4], C[3], 0.3 * tw);+ p.dot(x, y, tw > 0.6 ? C[5] : C[4], tw * 1.3);+ });+ // the Zs, oldest (biggest) first so the young ones sit on top+ const zs = [];+ for (let i = 0; i < NZ; i++) zs.push({ i, u: (((t - (i * D) / NZ) % D) + D) % D / D });+ zs.sort((p1, p2) => p2.u - p1.u);+ for (const { i, u } of zs) {+ const z = zAt(a, i, u);+ if (u > 0.9) {+ // it pops into motes+ const k = (u - 0.9) / 0.1;+ for (let j = 0; j < 7; j++) {+ const an = (j / 7) * TAU + i, d = 3 + 6 * Math.sqrt(k);+ p.dot(z.x + Math.cos(an) * d, z.y + Math.sin(an) * d * 0.8, j % 2 ? C[4] : C[5], 1.2 - k);+ }+ p.glow(z.x, z.y, 10, C[3], 0.25 * (1 - k));+ continue;+ }+ // a dotted trail where it has been+ for (let j = 1; j <= 6; j++) {+ const q = zAt(a, i, Math.max(0, u - j * 0.025));+ if (j % 2 === 0 || u - j * 0.025 < 0.05) continue;+ p.dot(q.x - 1, q.y + 4 + q.size, C[3], (1 - j / 7) * 0.9);+ }+ // it dims down the ramp as it gets old+ const old = u > 0.78 ? 1 : 0, R = old ? [C[0], C[1], C[2], C[3]] : [C[1], C[2], C[3], C[4]];+ icon(p, z.x, z.y, 7, ZS[z.size], R, z.k);+ if (!old) p.px(z.x - 2 - z.size, z.y - 2 - z.size * 0.8, C[5]);+ p.glow(z.x, z.y, 7 + z.size * 3, C[3], (old ? 0.12 : 0.26) * z.k);}- p.glow(hx + 6, hy - 12, 16, C[5], 0.1);}diff --git a/src/fx/status/slowed.js b/src/fx/status/slowed.jsindex f848bd3..2fadb2c 100644--- a/src/fx/status/slowed.js+++ b/src/fx/status/slowed.js@@ -1,63 +1,110 @@-import { cycle, ease, fract, clamp, TAU } from "../../core/index.js";-import { steps } from "./_lib.js";+import { cycle, fit, clamp, ease, TAU } from "../../core/index.js";+import { shape } 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.",+ desc: "Dragged through time: a glassy clock dial behind the head ticks round in heavy steps, flashing with each, while drops sink in slow motion and spread slow rings.",tags: ["status", "slow", "time", "clock", "debuff", "loop"],- size: [44, 46],- origin: [22, 42],+ size: [64, 76],+ origin: [32, 68],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,- },+ actor: 2,+ options: { palette: ["#081a24", "#0e3446", "#165a6e", "#2a8a9a", "#52bcc4", "#9ee6e0", "#e2fff8", "#ffffff"], seed: 7 },};-const center = (a) => [0, a.y + 5];+const D = meta.duration, TICKS = 4, STEP = D / TICKS, R = 18;-// 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]));+// the hand's angle: it waits, pulls back a little, snaps a quarter turn, overshoots and settles+function hand(t) {+ const k = Math.floor(t / STEP), ph = (t - k * STEP) / STEP, base = -Math.PI / 2 + (k * TAU) / TICKS, q = TAU / TICKS;+ if (ph < 0.62) return { ang: base, flash: 0, ph };+ if (ph < 0.72) return { ang: base - 0.1 * Math.sin(((ph - 0.62) / 0.1) * Math.PI * 0.5), flash: 0, ph };+ const s = (ph - 0.72) / 0.28, snap = ease.outBack(clamp(s / 0.35), 2.2), wob = Math.exp(-s * 6) * Math.sin(s * 22) * 0.05;+ return { ang: base - 0.1 * (1 - clamp(s / 0.2)) + q * snap + wob, flash: Math.exp(-s * 5), ph };+}+// the flash of the last tick, still fading after the hand has settled+const afterglow = (t) => {+ const s = (((t - STEP * 0.72) % STEP) + STEP) % STEP;+ return Math.exp(-s * 4);+};++function dial(p, C, cx, cy, t) {+ const h = hand(t), fl = Math.max(h.flash, afterglow(t));+ // a glassy face, lit from the top left+ p.disc(cx, cy, R - 1, C[2], 0.2);+ p.disc(cx - R * 0.25, cy - R * 0.3, R * 0.5, C[4], 0.08);+ // the rim: a dark edge, a bright band, a thin inner line+ p.ring(cx, cy, R + 1, 1, C[0]);+ p.ring(cx, cy, R, 2, (v, ang) => (Math.sin(ang + 0.8) < -0.3 ? (fl > 0.4 ? C[7] : C[6]) : v > 0.5 ? C[5] : C[4]));+ p.ring(cx, cy, R - 3.5, 1, C[3], 0.6);+ // the minute dots, then the hour marks, the quarters longer and brighter+ for (let i = 0; i < 60; i++) {+ if (i % 5 === 0) continue;+ const a = (i / 60) * TAU;+ p.dot(cx + Math.cos(a) * (R - 2.6), cy + Math.sin(a) * (R - 2.6), C[4], 0.8);}- // ticksfor (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]);+ const a = (i / 12) * TAU, big = i % 3 === 0, r0 = R - 2.5, r1 = R - (big ? 6 : 4.5), c = Math.cos(a), s = Math.sin(a);+ p.line(cx + c * r0, cy + s * r0, cx + c * r1, cy + s * r1, big ? C[6] : C[5]);}- // 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);+ // the hands: a short one that only shudders, a long heavy one that ticks+ const shud = h.flash * Math.sin(t * 60) * 0.06, ha = -Math.PI / 2 + 2.2 + shud;+ p.beam(cx, cy, cx + Math.cos(ha) * R * 0.5, cy + Math.sin(ha) * R * 0.5, 2.2, C[5]);+ const tx = cx + Math.cos(h.ang) * (R - 4), ty = cy + Math.sin(h.ang) * (R - 4);+ p.beam(cx, cy, tx, ty, 2.4, (u) => (u > 0.8 ? C[7] : C[6]));+ p.circle(cx, cy, 2, C[6]);+ p.px(cx, cy, C[1]);+ // light: the face glows, the rim flares as each tick lands, a ripple runs out from it+ p.glow(cx, cy, R + 8, C[4], 0.14 + 0.2 * fl);+ p.glowRing(cx, cy, R, 3, C[5], 0.12 + 0.35 * fl);+ p.glow(tx, ty, 5, C[6], 0.3 + 0.3 * h.flash);+ if (h.flash > 0.02) {+ const s = 1 - h.flash;+ p.ring(cx, cy, R + 2 + 10 * s, 1, C[5], h.flash);+ p.glowRing(cx, cy, R + 2 + 10 * s, 3, C[4], 0.3 * h.flash);+ }+}++export function drawBack(p, t, o) {+ const C = fit(o.palette, 8), a = o.actor;+ dial(p, C, 0, a.y + 3, t);+ // the body lags behind itself: an after-image of its outline, dragged a step back after every tick+ const lag = afterglow(t);+ if (lag > 0.05) p.outline(a.mask, a.x - 1 - Math.round(2 * lag), a.y, C[5], 0.55 * lag);}-// in front: drops of time leaving the bottom of the dial, sinking slowly then faster, splattingexport 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]);+ const C = fit(o.palette, 8), a = o.actor, S = shape(a), fl = Math.max(hand(t).flash, afterglow(t));+ // a cold film of time over the body, thickening with each tick+ for (const [mx, my] of S.body) p.blend(a.x + mx, a.y + my, C[5], 0.08 + 0.12 * fl);+ // drops sinking in slow motion, ghosts trailing them, slow rings where they reach the floor+ cycle(t, D, 6, o.seed + 3, (r) => r.range(1.6, 2.2), (age, life, r) => {+ const side = r.next() < 0.5 ? -1 : 1, x = side * r.range(10, 17), y0 = a.y + r.range(6, 22), v0 = r.range(18, 30), k = 1.1;+ const yAt = (g) => y0 + (v0 * (1 - Math.exp(-k * g))) / k + 4 * g;+ const y = yAt(age), u = age / life;+ if (y < -1) {+ for (const [lag, al] of [[0.22, 0.35], [0.11, 0.6]]) if (age > lag) p.dot(x, yAt(age - lag), C[4], al);+ p.px(x, y - 1, C[5]);+ p.px(x, y, C[6]);+ p.px(x, y + 1, C[5]);+ p.px(x - 1, y + 1, C[4]);+ p.px(x - 1, y, C[7]);+ p.glow(x, y, 4, C[5], 0.3 * (1 - u));} 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]);+ // it reached the floor: a slow ring spreads and fades+ let g = age;+ while (g > 0 && yAt(g) >= -1) g -= 0.02;+ const s = clamp((age - g) / 0.9);+ if (s < 1) {+ // two crests running apart along the floor, a faint far edge behind them+ const rx = 1 + 7 * Math.sqrt(s), c = s < 0.3 ? C[6] : C[5];+ for (const sd of [-1, 1]) p.line(x + sd * rx, -0.5, x + sd * (rx - 1.5), -0.5, c, (1 - s) * 1.2);+ for (let dx = -rx + 2; dx <= rx - 2; dx += 1) p.dot(x + dx, -1.5, C[4], (1 - s) * 0.5 * (1 - Math.abs(dx) / rx));+ p.glow(x, -1, 4 + rx, C[4], 0.12 * (1 - s));+ }}});}diff --git a/src/fx/status/stunned.js b/src/fx/status/stunned.jsindex 8217469..bfb71aa 100644--- a/src/fx/status/stunned.js+++ b/src/fx/status/stunned.js@@ -1,33 +1,96 @@-import { PAL, fit, TAU, WHITE } from "../../core/index.js";+// The shaded, outlined icons and the twinkles are+// adapted from Sprite Fusion's open-source heal (https://www.spritefusion.com/pixel-art-vfx/heal),+// MIT License, Copyright (c) 2026 Hugo Duprez.+import { cycle, fit, hex, mix, sparkle, flare, rand, TAU } from "../../core/index.js";+import { icon, bitmap, shaped, starShape } from "./_lib.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,+ desc: "Seeing stars: three spinning stars and two little birds circle the head on a tilted ring, ducking behind it and sweeping round in front, trailing glitter.",+ tags: ["status", "stun", "dizzy", "daze", "stars", "birds", "debuff", "loop"],+ size: [60, 64],+ origin: [30, 56],+ duration: 2,loop: true,fps: 30,bg: "ground",- actor: true,- options: { palette: PAL.gold, count: 3, seed: 6 },+ actor: 2,+ options: {+ palette: ["#3a1e0c", "#8a4a12", "#d88a1c", "#f5c030", "#ffe36e", "#fff6c8", "#ffffff"],+ birds: ["#1a1422", "#6a7fae", "#b8c8e8", "#f4f8ff"],+ beak: "#ffae35",+ seed: 2,+ },};-const STAR = ["..a..", ".aba.", "abbba", ".aba.", ".a.a."];+const D = meta.duration, TURNS = 2, N = 5;+const STAR7 = ["...#...", "..###..", "#######", ".#####.", "..###..", ".##.##.", ".#...#."];+// a little bird facing right: body, head, eye, beak, tail, a wing that beats+const BIRD = [true, false].map((up) => (dx, dy) => {+ const x = dx + 0.5, y = dy + 0.5;+ if (dx === 3 && dy === -2) return "e";+ if ((dx === 5 || dx === 4) && dy === -1) return dx === 5 ? "b" : "#";+ const wing = up ? [[-1, -1], [-1, -2], [-2, -2], [-2, -3], [-3, -3], [-3, -4]] : [[-1, 1], [-1, 2], [-2, 2], [-2, 3], [0, 1]];+ if (wing.some(([a, b]) => a === dx && b === dy)) return "w";+ if ((x / 3.3) ** 2 + ((y - 0.6) / 1.9) ** 2 <= 1 || (x - 2.8) ** 2 + (y + 1.2) ** 2 <= 1.7 ** 2) return "#";+ if ((dx === -4 && (dy === -1 || dy === 0)) || (dx === -5 && dy === -1)) return "#";+ return "";+});+const STAR = shaped.bind(null, starShape(0.44));-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);+// the ring round the head: stars at 0, 2, 4, birds between+function ring(t, a) {+ const cy = a.y + 2, rx = a.w * 0.62, ry = 4.5;+ return Array.from({ length: N }, (_, i) => {+ const th = TAU * ((TURNS * t) / D + i / N), s = Math.sin(th);+ return { i, th, x: Math.cos(th) * rx, y: cy + s * ry, near: s >= 0, depth: 0.5 + 0.5 * s, bird: i % 2 === 1, rx, ry, cy };+ });+}++function draw1(p, t, o, layer) {+ const C = fit(o.palette, 7), Bd = fit(o.birds, 4), a = o.actor, far = layer === "back";+ const dim = (c) => (far ? mix(c, Bd[0], 0.3) : c);+ for (const it of ring(t, a)) {+ if (it.near === far) continue;+ // glitter left along the ring behind each star+ if (!it.bird)+ for (let k = 1; k <= 12; k++) {+ const th = it.th - k * 0.085, x = Math.cos(th) * it.rx, y = it.cy - 1 + Math.sin(th) * it.ry;+ if (Math.sin(th) >= 0 === far || rand(it.i, k, Math.floor(((t / D) * TURNS + k * 0.37) * 9)) < 0.25) continue;+ p.dot(x, y, dim(k < 4 ? C[6] : k < 8 ? C[5] : C[4]), 1.1 - k / 13);+ if (k < 6) p.light(x, y, C[4], 0.3 * (1 - k / 6));+ }+ if (it.bird) {+ const up = Math.floor(t * 8 + it.i * 0.5) % 2 === 0, bob = Math.sin((t / D) * TAU * 4 + it.i) * 0.7, flip = it.near;+ const f = BIRD[up ? 0 : 1], ins = flip ? (dx, dy) => f(-dx, dy) : f;+ icon(p, it.x, it.y - 3 + bob, 7, ins, [Bd[0], dim(Bd[1]), dim(Bd[2]), dim(Bd[3])], 1, { e: Bd[0], b: dim(hex(o.beak)), w: dim(Bd[1]) });+ } else {+ const spin = (t / D) * TAU * 3 + it.i, R = [C[0], dim(C[3]), dim(C[4]), dim(C[5])];+ if (it.depth > 0.55) icon(p, it.x, it.y - 1, 7, STAR(4 + 0.8 * it.depth, spin), R);+ else icon(p, it.x, it.y - 1, 5, bitmap(STAR7), R);+ p.px(it.x, it.y - 1, far ? C[5] : C[6]);+ p.glow(it.x, it.y - 1, 11, C[4], 0.24 + 0.3 * it.depth);+ p.glow(it.x, it.y - 1, 4, C[6], 0.3 * it.depth);+ // a flare as it sweeps past the front, nearest the eye+ const fr = Math.exp(-((Math.atan2(Math.sin(it.th - Math.PI / 2), Math.cos(it.th - Math.PI / 2)) / 0.32) ** 2));+ if (!far && fr > 0.08) flare(p, it.x, it.y - 1, 9 * fr, fr, [C[3], C[4], C[5], C[6]]);+ }}}-export const drawBack = (p, t, o) => stars(p, t, o, false);-export const draw = (p, t, o) => stars(p, t, o, true);+export function drawBack(p, t, o) {+ draw1(p, t, o, "back");+}++export function draw(p, t, o) {+ const C = fit(o.palette, 7), a = o.actor;+ draw1(p, t, o, "front");+ // little twinkles popping round the ring+ cycle(t, D, 14, o.seed + 3, (r) => r.range(0.25, 0.5), (age, life, r) => {+ const th = r.range(0, TAU), u = age / life, x = Math.cos(th) * a.w * r.range(0.45, 0.95), y = a.y + 1 + Math.sin(th) * 7 - r.range(0, 9);+ const arm = Math.round(r.range(1, 2.6) * Math.sin(Math.PI * u));+ if (arm < 1) p.dot(x, y, C[6], Math.sin(Math.PI * u) * 1.4);+ sparkle(p, x, y, arm, C[5], C[4], 0.35 * Math.sin(Math.PI * u));+ });+ p.glow(0, a.y + 1, 26, C[4], 0.13);+}diff --git a/src/fx/transitions/_lib.js b/src/fx/transitions/_lib.jsindex 3c3ae4b..fe5cf27 100644--- a/src/fx/transitions/_lib.js+++ b/src/fx/transitions/_lib.js@@ -1,16 +1,11 @@-// 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.+// Shared by the screen transitions: a 320 x 180 screen with its origin at the top-left. Each one covers the+// screen in o.color by about 45% of its duration, holds, then uncovers so the last frame is empty.+// glint() is adapted from Sprite Fusion's open-source sparkle (https://www.spritefusion.com/pixel-art-vfx/sparkle),+// MIT License, Copyright (c) 2026 Hugo Duprez.-import { seg, ramp } from "../../core/index.js";+import { Painter, clamp, TAU, WHITE } 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;-}+export const W = 320, H = 180;/** The meta every transition shares; pass what differs. */export function screenMeta({ name, desc, tags, duration, options }) {@@ -21,41 +16,188 @@ export function screenMeta({ name, desc, tags, duration, options }) {};}+// a painter that drops every pixel outside the screen+class Clipped extends Painter {+ inside(sx, sy) {+ const lx = this.fromX(sx + 0.5, sy + 0.5), ly = this.fromY(sx + 0.5, sy + 0.5);+ return lx >= 0 && ly >= 0 && lx < W && ly < H;+ }+ put(sx, sy, c, a) {+ if (this.inside(sx, sy)) super.put(sx, sy, c, a);+ }+ add(sx, sy, c, k) {+ if (this.inside(sx, sy)) super.add(sx, sy, c, k);+ }+ blendPx(sx, sy, c, a) {+ if (this.inside(sx, sy)) super.blendPx(sx, sy, c, a);+ }+}+const clips = new WeakMap();+/**- * 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.+ * The painter, clipped to the screen: sparks, smoke and light that fly past an edge are cut there instead of+ * spilling outside the canvas. Every drawing call goes through it unchanged. (One per painter, kept in step+ * with it, so it stays the same shape of object every frame.)*/-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 };+export function clipTo(p) {+ let q = clips.get(p);+ if (!q) clips.set(p, (q = new Clipped(p.frame)));+ q.reset();+ q.tx = p.tx; q.ty = p.ty; q.fx = p.fx; q.cs = p.cs; q.sn = p.sn;+ q.fade = p.fade; q.lightK = p.lightK; q.layer = p.layer;+ return q;}-/** 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);+// screen column of local pixel column x, for an unrotated painter: x maps to b + fx * x+const unrotated = (p) => p.sn === 0 && p.cs === 1;+const col0 = (p) => (p.fx > 0 ? Math.floor(p.tx + 0.5) : Math.floor(p.tx - 0.5));++/**+ * p.rect(x, y, w, h, c) for opaque fills, mapping each row to the screen once instead of every pixel (the+ * transitions fill a lot of screen); through p.rect itself when the painter is rotated.+ */+export function rect(p, x, y, w, h, c) {+ if (!unrotated(p)) return p.rect(x, y, w, h, c);+ const X0 = Math.round(x), X1 = Math.round(x + w), Y0 = Math.round(y), Y1 = Math.round(y + h), fx = p.fx, b = col0(p);+ for (let yy = Y0; yy < Y1; yy++) {+ const sy = Math.floor(p.ty + yy + 0.5);+ for (let xx = X0; xx < X1; xx++) p.put(b + fx * xx, sy, c, 1);+ }+}++/**+ * Fill a convex polygon [[x, y], ...] row by row, clipped to the screen. c is a color or fn(x, y) -> color+ * (0 skips the pixel); a is the alpha (dithered).+ */+export function fillConvex(p, pts, c, a = 1) {+ let y0 = Infinity, y1 = -Infinity;+ for (const [, y] of pts) (y0 = Math.min(y0, y)), (y1 = Math.max(y1, y));+ const r0 = Math.max(0, Math.ceil(y0 - 0.5)), r1 = Math.min(H - 1, Math.floor(y1 - 0.5)), n = pts.length, fc = typeof c === "function";+ for (let y = r0; y <= r1; y++) {+ const yc = y + 0.5;+ let xl = Infinity, xr = -Infinity;+ for (let i = 0, j = n - 1; i < n; j = i++) {+ const [xi, yi] = pts[i], [xj, yj] = pts[j];+ if (yi > yc === yj > yc) continue;+ const x = xi + ((yc - yi) * (xj - xi)) / (yj - yi);+ if (x < xl) xl = x;+ if (x > xr) xr = x;+ }+ const c0 = Math.max(0, Math.ceil(xl - 0.5)), c1 = Math.min(W - 1, Math.floor(xr - 0.5));+ if (unrotated(p)) {+ const fx = p.fx, b = col0(p), sy = Math.floor(p.ty + yc);+ for (let x = c0; x <= c1; x++) {+ const col = fc ? c(x + 0.5, yc) : c;+ if (col) p.put(b + fx * x, sy, col, a);+ }+ } else+ for (let x = c0; x <= c1; x++) {+ const col = fc ? c(x + 0.5, yc) : c;+ if (col) p.dot(x, y, col, a);+ }+ }+}-/** The whole screen in one color. */-export const fill = (p, c) => p.rect(0, 0, W, H, c);+/** The part of polygon pts on the side of the line through (cx, cy) that normal (nx, ny) points to. */+export function halfPlane(pts, cx, cy, nx, ny) {+ const out = [], side = ([x, y]) => (x - cx) * nx + (y - cy) * ny;+ for (let i = 0; i < pts.length; i++) {+ const a = pts[i], b = pts[(i + 1) % pts.length], sa = side(a), sb = side(b);+ if (sa >= 0) out.push(a);+ if (sa >= 0 !== sb >= 0) {+ const k = sa / (sa - sb);+ out.push([a[0] + (b[0] - a[0]) * k, a[1] + (b[1] - a[1]) * k]);+ }+ }+ return out;+}-/** Is a point on the screen? */-export const onScreen = (x, y) => x >= 0 && y >= 0 && x < W && y < H;+/**+ * A scalar field over the screen from fn(x, y) (pixel centers), plus g: one over its gradient's length, so+ * (k - f[i]) * g[i] is roughly the distance in pixels from pixel i to the level set f = k. Returns+ * { f, g, ny, lo, hi, order }: ny is the gradient's vertical share (-1 rising upward .. 1 downward), order+ * lists the pixels from the lowest value to the highest.+ */+export function field(fn, gmin = 0.45, gmax = 3) {+ const f = new Float32Array(W * H), g = new Float32Array(W * H), ny = new Float32Array(W * H);+ let lo = Infinity, hi = -Infinity;+ for (let y = 0; y < H; y++)+ for (let x = 0; x < W; x++) {+ const v = fn(x + 0.5, y + 0.5);+ f[y * W + x] = v;+ if (v < lo) lo = v;+ if (v > hi) hi = v;+ }+ for (let y = 0; y < H; y++)+ for (let x = 0; x < W; x++) {+ const xa = Math.max(0, x - 1), xb = Math.min(W - 1, x + 1), ya = Math.max(0, y - 1), yb = Math.min(H - 1, y + 1);+ const gx = (f[y * W + xb] - f[y * W + xa]) / (xb - xa), gy = (f[yb * W + x] - f[ya * W + x]) / (yb - ya);+ const L = Math.hypot(gx, gy);+ g[y * W + x] = 1 / clamp(L, gmin, gmax);+ ny[y * W + x] = L > 1e-6 ? gy / L : 0;+ }+ const order = Uint32Array.from({ length: W * H }, (_, i) => i).sort((a, b) => f[a] - f[b]);+ const sorted = Float32Array.from(order, (i) => f[i]);+ // the slice of `order` whose values are below v: pixels f < v are order[0 .. below(v))+ const below = (v) => {+ let a = 0, b = sorted.length;+ while (a < b) {+ const m = (a + b) >> 1;+ if (sorted[m] < v) a = m + 1;+ else b = m;+ }+ return a;+ };+ return { f, g, ny, lo, hi, order, below };+}-/** 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;+/**+ * Write whole screen pixels by index fast: at(i) picks pixel i = y * W + x, then put(c, a), add(c, k) and+ * blend(c, a) write it. Straight to the frame when the painter is unrotated (the usual case), else through it.+ */+export function pixels(p) {+ let sx = 0, sy = 0, i0 = 0;+ if (p.sn === 0 && p.cs === 1) {+ const tx = p.tx, ty = p.ty, fx = p.fx;+ return {+ at(i) {+ sx = Math.floor(tx + ((i % W) + 0.5) * fx);+ sy = Math.floor(ty + ((i / W) | 0) + 0.5);+ },+ put: (c, a = 1) => p.put(sx, sy, c, a),+ add: (c, k) => p.add(sx, sy, c, k),+ blend: (c, a) => p.blendPx(sx, sy, c, a),+ };+ }+ const x = () => (i0 % W) + 0.5, y = () => ((i0 / W) | 0) + 0.5;+ return {+ at(i) {+ i0 = i;+ },+ put: (c, a = 1) => p.dot(x(), y(), c, a),+ add: (c, k) => p.light(x(), y(), c, k),+ blend: (c, a) => p.blend(x(), y(), c, a),+ };+}-/** 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;+/**+ * A spinning 8-ray glint at (x, y): long rays white at the heart, c1 in the middle and c2 at the tips, short+ * diagonals, the long rays thickened near the heart, and two lights. ang spins it; a fades it (dithered).+ */+export function glint(p, x, y, L, ang, c1, c2, a = 1) {+ if (L < 0.8 || a <= 0) return;+ for (let i = 0; i < 8; i++) {+ const diag = i % 2 === 1, an = ang + (i * TAU) / 8, len = diag ? L * 0.42 : L, ca = Math.cos(an), sa = Math.sin(an);+ for (let d = 0; d <= len; d += 0.5) {+ const u = d / len, c = diag ? (u < 0.5 ? c1 : c2) : u < 0.3 ? WHITE : u < 0.65 ? c1 : c2;+ p.dot(x + ca * d, y + sa * d, c, a * (u < 0.7 ? 1 : 1 - (u - 0.7) / 0.35));+ if (!diag && u < 0.22 && L > 4) p.dot(x + ca * d - sa, y + sa * d + ca, c1, a), p.dot(x + ca * d + sa, y + sa * d - ca, c1, a);}- 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);+ p.dot(x, y, WHITE, a);+ p.glow(x, y, 4 + L * 1.4, c1, 0.5 * a);+ p.glow(x, y, 2 + L * 0.5, WHITE, 0.4 * a);}++/** Particle lives cut so nothing outlives the effect: the smaller of life and what's left before `end`. */+export const lifeLeft = (life, t, end) => Math.min(life, end - t);diff --git a/src/fx/transitions/blinds.js b/src/fx/transitions/blinds.jsindex cf327b0..44a8b6d 100644--- a/src/fx/transitions/blinds.js+++ b/src/fx/transitions/blinds.js@@ -1,45 +1,95 @@-import { PAL, hex, ease, seg } from "../../core/index.js";-import { screenMeta, timeline, screen, fill, W, H, accents } from "./_lib.js";+// The dust drifting in the light and the light squeezing through follow Sprite Fusion's open-source holy light+// (https://www.spritefusion.com/pixel-art-vfx/holy-light), MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, P, Rng, fit, hex, clamp, ease, WHITE } from "../../core/index.js";+import { W, H, screenMeta, clipTo, glint, rect } 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 },+ desc: "Slats catch the light edge-on, then tilt shut top to bottom, lit rims glinting as warm light squeezes through the closing gaps with dust in it; then they tilt open and fade.",+ tags: ["blinds", "slats", "light", "wipe"],+ duration: 2.0,+ options: { palette: ["#1a120c", "#33241a", "#5a4030", "#8a6848", "#c09a6a", "#e8cc98", "#fff0cc", "#ffffff"], seed: 1 },});-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;- });+const N = 12, SH = H / N, SHUT0 = 0.08, OPEN0 = 1.02, STEP = 0.038, TURN = 0.42, OSTEP = 0.03, OTURN = 0.4, FADE0 = 1.72, FADE1 = 1.94;++// how far slat i has turned: 0 edge-on, π/2 flat and shut (a little past while it settles)+function angle(i, t) {+ if (t < OPEN0) return (Math.PI / 2) * ease.outBack(clamp((t - SHUT0 - i * STEP) / TURN), 1.6);+ return (Math.PI / 2) * (1 - ease.inOutCubic(clamp((t - OPEN0 - i * OSTEP) / OTURN)));+}++export function create(o) {+ const C = fit(o.palette, 8), ink = hex(o.color), R = new Rng(o.seed);+ const ps = new Particles({ rng: R, sparks: [WHITE, C[6], C[5], C[4]] });+ let t = 0;+ const end = meta.duration - 0.05;+ return {+ update(dt) {+ t += dt;+ // dust drifts in the light coming through+ if (t < FADE0 && R.chance(0.8)) {+ const i = R.int(0, N - 1), th = angle(i, t);+ if (th > 0.2 && th < 1.45) ps.spawn(P.EMBER, R.range(0, W), (i + 1) * SH + R.range(-2, 2), R.range(-8, 8), -R.range(2, 8), Math.min(R.range(0.5, 1), end - t), 0, 1);+ }+ ps.update(dt);+ },+ draw(p0) {+ const p = clipTo(p0), open = new Uint8Array(H).fill(1);+ for (let i = 0; i < N; i++) {+ const h = Math.max(1, (SH + 1) * Math.abs(Math.sin(angle(i, t)))), yc = (i + 0.5) * SH;+ for (let y = Math.max(0, Math.ceil(yc - h / 2 - 0.5)); y <= Math.min(H - 1, Math.floor(yc + h / 2 - 0.5)); y++) open[y] = 0;+ }+ // the dust is behind the slats: it only shows (and only shines) in the gaps+ for (const q of ps.list) {+ const y = Math.floor(q.y), k = q.life / q.max;+ if (q.delay > 0 || y < 0 || y >= H || !open[y] || q.x < 0 || q.x >= W) continue;+ // some catch the light as little twinkling crosses+ const tw = (q.seed % 1) < 0.3 && Math.sin(t * 14 + q.seed) > 0;+ p0.px(q.x, y, tw || k > 0.5 ? WHITE : C[5]);+ if (tw) for (const [dx, dy] of [[1, 0], [-1, 0], [0, 1], [0, -1]]) if (open[y + dy]) p.px(q.x + dx, y + dy, C[6]);+ p0.light(q.x, y, C[6], (tw ? 0.7 : 0.4) * k);+ }+ const fade = 1 - clamp((t - FADE0) / (FADE1 - FADE0)), appear = clamp(t / SHUT0);+ for (let i = 0; i < N; i++) {+ const th = angle(i, t), s = Math.sin(th), c = Math.cos(th), yc = (i + 0.5) * SH;+ const h = Math.max(1, (SH + 1) * Math.abs(s)), y0 = Math.max(0, Math.ceil(yc - h / 2 - 0.5)), y1 = Math.min(H - 1, Math.floor(yc + h / 2 - 0.5));+ const under = th > Math.PI / 2; // turned past flat: the shadowed underside shows+ // edge-on, the slat is just its lit edge: it brightens in at the start and fades out at the end+ if (h < 2.5) {+ const k = Math.min(appear, fade);+ if (k <= 0) continue;+ const yy = Math.round(yc - 0.5);+ rect(p0, 0, yy, W, 1, k > 0.66 ? C[6] : k > 0.33 ? C[4] : C[2]);+ if (h >= 1.5 && yy + 1 < H) rect(p0, 0, yy + 1, W, 1, k > 0.5 ? C[3] : C[1]);+ for (let x = 0; x < W; x += 2) p0.light(x, yy, C[5], 0.18 * k);+ continue;+ }+ // tilted: a lit top rim, a sheen, a face that darkens as it turns flat to us, a shadowed underside+ const lit = under ? 0 : c;+ for (let y = y0; y <= y1; y++) {+ // the face is lit from above: brightest just under the rim, falling away down it+ const r = y - y0, last = y === y1, v = r / Math.max(1, y1 - y0), f = lit * (1 - v * 0.8);+ const col = r === 0 ? (lit > 0.55 ? WHITE : lit > 0.3 ? C[6] : lit > 0.12 ? C[4] : ink)+ : r === 1 ? (lit > 0.45 ? C[5] : lit > 0.2 ? C[3] : ink)+ : last ? ink+ : f > 0.55 ? C[3] : f > 0.35 ? C[2] : f > 0.15 ? C[1] : ink;+ rect(p0, 0, y, W, 1, col);+ if (r === 0 && lit > 0.12) for (let x = 0; x < W; x += 2) p0.light(x, y, C[5], 0.35 * lit);+ }+ // light squeezes through the gap under the slat, brighter as the gap narrows+ const gap = SH - h;+ if (gap > 0.5 && th > 0.12 && !under) {+ const k = (0.2 + 0.45 * (1 - gap / SH) ** 1.5) * Math.min(1, th / 0.4), gy = y1 + 1;+ for (let y = gy; y < Math.min(H, gy + Math.ceil(gap)); y++) {+ const v = (y - gy + 0.5) / gap, kk = k * (1 - Math.abs(v - 0.5) * 1.2);+ if (kk > 0.01) for (let x = 0; x < W; x += 1) p0.light(x, y, C[6], kk), p0.light(x, y, C[4], kk * 0.5);+ }+ }+ // a glint runs along the lit rim as the slat turns+ const u = t < OPEN0 ? clamp((t - SHUT0 - i * STEP) / TURN) : clamp((t - OPEN0 - i * OSTEP) / OTURN);+ if (lit > 0.3 && u > 0.05 && u < 0.95) glint(p, W * (t < OPEN0 ? u : 1 - u), y0, 6 * Math.sin(Math.PI * u), u * 3, C[6], C[5]);+ }+ },+ };}diff --git a/src/fx/transitions/burn-away.js b/src/fx/transitions/burn-away.jsindex d486156..3b2f702 100644--- a/src/fx/transitions/burn-away.js+++ b/src/fx/transitions/burn-away.js@@ -1,79 +1,262 @@-import { PAL, hex, ease, clamp, fbm, rng, fly } from "../../core/index.js";-import { screenMeta, timeline, screen, fill, onScreen, W, H, accents } from "./_lib.js";+// The layered flame tongues and the licks, embers and smoke shed off a burning edge follow Sprite Fusion's+// open-source fire (https://www.spritefusion.com/pixel-art-vfx/fire), MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Lights, P, Rng, fit, hex, mix, clamp, smooth, ease, fbm, noise, noise2, rand, TAU, WHITE, SMOKE_RAMP } from "../../core/index.js";+import { W, H, screenMeta, clipTo, field, pixels, lifeLeft, rect } 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 },+ desc: "The screen burns in from its edges behind a ragged ember line of licking flames, embers and smoke; then the black smoulders and burns open from the middle.",+ tags: ["burn", "fire", "embers", "smoke", "wipe"],+ duration: 3,+ options: { palette: ["#4a1712", "#8a1f17", "#c9281f", "#f2561d", "#ff8a2a", "#ffc23d", "#ffe26b", "#fff3a6", "#ffffff"], seed: 3 },});-// the inverse of ease.inOutSine: when the front reaches a spot-const unSine = (y) => Math.acos(1 - 2 * clamp(y)) / Math.PI;+const D = meta.duration, CLOSE = 1.18, COVER = 1.35, SMOULDER = 1.5, POP = 1.8, OPEN = 2.62, SC = 90, HALO = 24, POOL = 48;+const ASH = ["#a39cab", "#7b7484", "#5c5664", "#433e4b"];+// a tongue's layers: [width, height, palette step], outermost (red) to the white core+const LAYERS = [[1, 1, 2], [0.76, 0.86, 4], [0.54, 0.68, 6], [0.3, 0.42, 8]];-// 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);+// where the fire reaches when: rising from the edges' midpoints (the corners go first), ragged at two scales,+// and the bottom burns a little faster because fire climbs+function inField(seed) {+ return field((x, y) => {+ const ux = (x - W / 2) / (W / 2), uy = (y - H / 2) / (H / 2), m = Math.pow(ux ** 4 + uy ** 4, 0.25);+ return (1 - m) * SC + 14 * fbm(x / 44, y / 44, seed, 3) + 2.4 * fbm(x / 7, y / 7, seed + 9, 2) + 7 * (0.5 - y / H);+ });+}+// the hole: from a spot near the middle (and two smaller ones that catch a beat later) out to the corners+function outField(seed) {+ const R = new Rng(seed * 31 + 5), ox = W / 2 + R.range(-26, 26), oy = H / 2 + R.range(-14, 6);+ const sats = [-1, 1].map((s) => ({ x: ox + s * R.range(70, 110), y: oy + R.range(-40, 40), d: R.range(30, 44) }));+ const f = field((x, y) => {+ let v = Math.hypot((x - ox) / (W / 2), (y - oy) / (H / 2)) * SC;+ for (const s of sats) v = Math.min(v, s.d + Math.hypot((x - s.x) / (W / 2), (y - s.y) / (H / 2)) * SC * 1.15);+ return v + 13 * fbm(x / 40, y / 40, seed + 21, 3) + 2.4 * fbm(x / 7, y / 7, seed + 33, 2);+ });+ f.ox = ox;+ f.oy = oy;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)];+// a flame standing on (x, y): four layers of the ramp, each narrower, shorter and hotter, swaying at the tip+function tongue(p, F, x, y, h, w, sway, t, n) {+ for (const [lw, lh, ri] of LAYERS) {+ const Ht = h * lh, col = F[ri];+ for (let r = 0; r <= Ht; r++) {+ const u = r / Math.max(1, Ht), half = w * lw * Math.pow(1 - u, 0.85) * Math.min(1, (r + 1.5) / 3.5) + noise(t * 9 + r * 0.45, n) * 0.5;+ if (half < 0.3) continue;+ const cx = x + sway * u * u * lh + noise(t * 4 + r * 0.2, n + 7) * u * 1.1;+ for (let px = Math.round(cx - half); px <= Math.round(cx + half); px++) p.px(px, Math.round(y - r), col);}- 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));}}++export function create(o) {+ const F = fit(o.palette, 9), ink = hex(o.color), R = new Rng(o.seed), seed = o.seed * 13;+ const CHAR = mix(ink, F[0], 0.45), SCORCH = mix(ink, hex("#3a2216"), 0.6), WARM = mix(F[4], F[5], 0.4);+ const SMOKE = mix(hex("#8a7276"), F[2], 0.2);+ const A = inField(seed), B = outField(seed + 1);+ // per pixel: how hot the ember line burns there (two smooth fields), and the odd fleck that glows on+ // (ph: a smooth phase 0..63 that the flicker tables are read with; jit: a ragged char rim)+ // (vein: near 0 along a web of thin curving cracks, where the char smoulders before it burns open)+ const heat = new Float32Array(W * H), ph = new Uint8Array(W * H), fleck = new Float32Array(W * H), jit = new Float32Array(W * H), vein = new Float32Array(W * H);+ for (let i = 0; i < W * H; i++) {+ const x = i % W, y = (i / W) | 0;+ heat[i] = 0.5 + 0.5 * noise2(x / 13, y / 13, seed + 41);+ ph[i] = Math.min(63, Math.floor((0.5 + 0.5 * noise2(x / 23, y / 23, seed + 43)) * 64));+ fleck[i] = rand(x, y, seed + 45) < 0.04 ? 9 + 22 * rand(x, y, seed + 47) : 0;+ jit[i] = (rand(x, y, seed + 49) - 0.5) * 1.5;+ const rx = x * 0.8 + y * 0.6, ry = y * 0.8 - x * 0.6; // off the pixel grid, so cracks don't run square+ vein[i] = Math.min(Math.abs(noise2(rx / 11, ry / 9, seed + 61)), Math.abs(noise2(ry / 5.5, rx / 5, seed + 63)) * 1.5);+ }+ const FL = new Float32Array(64), HV = new Float32Array(64), TW = new Uint8Array(64);+ const kIn = (t) => A.lo - 8 + (A.hi - A.lo + 8) * Math.pow(Math.max(0, t) / CLOSE, 1.25);+ const kOut = (t) =>+ t < POP ? B.lo - 24 + 24 * ease.inQuad(clamp((t - SMOULDER) / (POP - SMOULDER))) : B.lo + (B.hi - B.lo + 16) * ease.outQuad(clamp((t - POP) / (OPEN - POP)));++ const ps = new Particles({ rng: R, sparks: [F[7], F[6], F[4], F[2]] });+ const ash = new Particles({ rng: R, sparks: ASH });+ const lights = new Lights();+ const line = []; // the white-hot line's pixels this frame: where flames stand+ let t = 0, pin = 0, pout = 0, closed = false, popped = false;++ // what a patch of edge gives off as the front crosses it: licks of flame, embers, ash, now and then a cloud+ // of smoke (a run of puffs from one spot, so it rolls up as a wisp, not a dot) and a flicker of light. Per+ // pixel crossed: [flame, ember, smoke, smoke on the hottest stretches, ash, light]. The black burning open+ // sheds fewer embers and less ash, so the picture it uncovers stays clear.+ const RATE = { in: [0.006, 0.0014, 0.0006, 0.0024, 0.0012, 0.0004], out: [0.006, 0.0005, 0.0004, 0.0012, 0.0004, 0.0004] };+ const shed = (i, inA) => {+ // what burns in is gone before the black burns open, so the uncovered picture starts clean+ const [fl, em, sm, sh, as, li] = inA ? RATE.in : RATE.out, x = (i % W) + 0.5, y = ((i / W) | 0) + 0.5, end = inA ? POP + 0.1 : D - 0.05;+ let r = R.next();+ if ((r -= fl) < 0) {+ const life = lifeLeft(R.range(0.18, 0.4), t, end);+ if (life > 0.08) ps.spawn(P.FIRE, x, y - 3, R.range(-8, 8), -R.range(25, 50), life, 0, R.range(0.8, 1.7));+ } else if ((r -= em) < 0) {+ const life = lifeLeft(inA ? R.range(0.6, 1.3) : R.range(0.5, 1), t, end);+ if (life > 0.2) ps.spawn(P.EMBER, x, y - 2, R.range(-30, 30), -R.range(40, 100), life, 0, R.chance(0.25) ? 2 : 1);+ } else if ((r -= sm + sh * heat[i] ** 2) < 0) {+ // smoke lives long only where the front chases it upward; elsewhere the front leaves it, so it's a wisp+ const n = R.int(4, 6), vx = R.range(-6, 6), up = (inA ? A : B).ny[i] < -0.25;+ for (let j = 0; j < n; j++) {+ const life = lifeLeft(up ? R.range(0.8, 1.3) : R.range(0.35, 0.65), t + j * 0.05, end);+ if (life > 0.4) ps.spawn(P.SMOKE, x + R.range(-3.5, 3.5), y - 4 - j * 1.2, vx + R.range(-3, 3), -R.range(18, 34), life, SMOKE, R.range(2.8, 4.8), j * 0.05);+ }+ } else if ((r -= as) < 0) {+ const life = lifeLeft(R.range(0.9, 1.6), t, end);+ if (life > 0.3) ash.spawn(P.EMBER, x, y - 2, R.range(-18, 18), -R.range(25, 60), life);+ } else if ((r -= li) < 0) lights.add(x, y - 4, R.range(20, 32), WARM, R.range(0.14, 0.26), R.range(0.18, 0.4));+ };++ // smoke shows where firelight catches it: lit warm near the burning line, dark over the picture, all but lost+ // in the black away from the fire (the sim's smoke puff, three soft discs, shaded by that light)+ const LIT = mix(hex("#8a7276"), F[3], 0.25), DIM = hex(SMOKE_RAMP[3]);+ const drawSmoke = (p, p0) => {+ const inPhase = t < COVER, open = t >= SMOULDER && t < OPEN + 0.25, k = inPhase ? kIn(t) : kOut(t), f = inPhase ? A.f : B.f;+ for (const q of ps.list) {+ if (q.k !== P.SMOKE || q.delay > 0) continue;+ const kk = q.life / q.max, age = 1 - kk, r = q.size * (0.65 + Math.min(1, age * 2.5) * 0.45 + age * 0.4);+ const i = clamp(Math.floor(q.y), 0, H - 1) * W + clamp(Math.floor(q.x), 0, W - 1);+ const e = inPhase || open ? (inPhase ? k - f[i] : f[i] - k) : 99, lit = clamp(1 - Math.abs(e) / 30);+ const a = Math.min(1, age * 12) * Math.min(1, kk * 2.4) * 0.58 * (e > 0 ? 0.05 + 0.95 * lit : inPhase ? 1 : 0.2 + 0.8 * lit);+ if (a < 0.04) continue;+ // a puff wholly on screen needs no clipping+ const c = mix(mix(DIM, LIT, lit), SMOKE_RAMP[2], age * 0.5), d = q.x - r > 0 && q.y - r > 0 && q.x + r < W - 1 && q.y + r < H - 1 ? p0 : p;+ d.disc(q.x, q.y, r, c, a * 0.45);+ d.disc(q.x + r * 0.05, q.y + r * 0.06, r * 0.74, c, a * 0.62);+ if (age < 0.5) d.disc(q.x - r * 0.22, q.y - r * 0.3, r * 0.5, mix(c, WHITE, 0.15), a * 0.4 * (1 - age * 2));+ }+ };++ return {+ update(dt) {+ t += dt;+ // the front eats inward: everything it passes this step gives off flame, embers, ash and smoke+ if (t < COVER) {+ const k = kIn(t);+ while (pin < A.order.length && A.f[A.order[pin]] <= k) shed(A.order[pin++], true);+ if (!closed && t >= CLOSE) {+ // the last of the picture goes up in a puff+ closed = true;+ const i = A.order[A.order.length - 1], x = i % W, y = (i / W) | 0;+ lights.add(x, y, 64, WARM, 0.5, 0.4);+ for (let j = 0; j < 12; j++) ps.spawn(P.EMBER, x + R.range(-6, 6), y + R.range(-3, 3), R.range(-50, 50), -R.range(40, 120), R.range(0.5, 0.75), 0, R.chance(0.3) ? 2 : 1);+ for (let j = 0; j < 5; j++) ps.spawn(P.SMOKE, x + R.range(-8, 8), y + R.range(-4, 2), R.range(-10, 10), -R.range(12, 28), R.range(1.1, 1.6), SMOKE, R.range(3.5, 5.5), R.range(0, 0.15));+ }+ }+ // the black smoulders in the middle, then burns open+ if (t >= SMOULDER && t < POP && R.chance(0.1)) {+ const i = B.order[R.int(0, 400)], x = (i % W) + 0.5, y = ((i / W) | 0) + 0.5;+ if (R.chance(0.6)) ps.spawn(P.SMOKE, x, y, R.range(-4, 4), -R.range(8, 16), lifeLeft(R.range(0.9, 1.4), t, D - 0.05), SMOKE, R.range(2, 3.5));+ else ps.spawn(P.EMBER, x, y, R.range(-12, 12), -R.range(15, 40), R.range(0.4, 0.8));+ }+ if (!popped && t >= POP) {+ popped = true;+ lights.add(B.ox, B.oy, 90, WARM, 0.6, 0.45);+ lights.add(B.ox, B.oy, 34, F[7], 0.7, 0.12);+ for (let j = 0; j < 12; j++) {+ const a = R.range(0, TAU), sp = R.range(50, 150);+ ps.spawn(P.EMBER, B.ox + Math.cos(a) * 3, B.oy + Math.sin(a) * 2, Math.cos(a) * sp, Math.sin(a) * sp * 0.7 - 40, R.range(0.4, 0.9), 0, R.chance(0.3) ? 2 : 1);+ }+ for (let j = 0; j < 10; j++) {+ const a = R.range(0, TAU), sp = R.range(120, 260);+ ps.spawn(P.SPARK, B.ox, B.oy, Math.cos(a) * sp, Math.sin(a) * sp - 50, R.range(0.15, 0.35));+ }+ }+ if (t >= POP && t < OPEN + 0.2) {+ const k = kOut(t);+ while (pout < B.order.length && B.f[B.order[pout]] <= k) shed(B.order[pout++], false);+ }+ ps.update(dt);+ ash.update(dt);+ lights.update(dt);+ },+ draw(p0) {+ const p = clipTo(p0);+ line.length = 0;+ if (t >= COVER && t < SMOULDER) rect(p0, 0, 0, W, H, ink);+ else if (t < OPEN + 0.25) {+ const inPhase = t < COVER, k = inPhase ? kIn(t) : kOut(t), Fd = inPhase ? A : B, f = Fd.f, g = Fd.g;+ const fade = inPhase ? 1 - smooth(COVER - 0.15, COVER, t) : 1;+ for (let j = 0; j < 64; j++) {+ const q = j / 63;+ FL[j] = 0.75 + 0.25 * Math.sin(t * 7 + q * 9);+ HV[j] = 0.3 * Math.sin(t * 5.5 + q * 11);+ TW[j] = Math.sin(t * 13 + q * 40) > -0.5 ? 1 : 0;+ }+ // only the pixels near the burning line need working out (a slice of the field's order): the cover+ // behind it is plain ink, the picture far ahead of it untouched. Straight to the frame: all on screen.+ const px = pixels(p0), ord = Fd.order, N = ord.length;+ // before the black burns open it smoulders: a web of cracks in the hole's own shape glows, spreads and+ // heats from dark red, then the hole bursts through it and it cools+ const su = clamp((t - SMOULDER) / (POP - SMOULDER)), SR = 5 + 17 * su;+ const sk = inPhase || t < SMOULDER ? 0 : t < POP ? 0.3 + 0.7 * su : 1 - (t - POP) / 0.3;+ const shadeAt = (i) => {+ // e: how far into the cover this pixel is in field units (smooth, for light); s: in px from the+ // burning line (sharp near it, for the line itself)+ const e = inPhase ? k - f[i] : f[i] - k, s = e * g[i];+ px.at(i);+ if (e < 0) {+ // the picture just ahead of the fire: scorched, and lit by it+ if (inPhase && s > -2.5) px.blend(SCORCH, 0.5 * (1 + s / 2.5));+ const u = Math.max(0, 1 + e / HALO), v = 1 + e / POOL;+ px.add(WARM, (0.3 * u * u + 0.12 * v * v) * FL[ph[i]]);+ return;+ }+ const hv = clamp(heat[i] + HV[ph[i]]), th = 0.6 + 0.6 * hv, u = s / th;+ if (u < 6.4) {+ // the ember line: white-hot at the edge, cooling down the ramp into char+ if (u < 0.9) line.push(i);+ px.put(u < 0.9 ? (hv > 0.6 ? F[8] : F[7]) : u < 1.7 ? F[6] : u < 2.4 ? F[5] : u < 3.1 ? F[4] : u < 3.8 ? F[3] : u < 4.6 ? F[2] : u < 5.5 ? F[1] : F[0]);+ if (u < 4.6) px.add(WARM, 0.45 * (1 - u / 4.6) * (0.7 + 0.3 * hv));+ return;+ }+ if (sk > 0 && f[i] < B.lo + SR) {+ const hm = (1 - (f[i] - B.lo) / SR) * sk * (0.7 + 0.6 * hv);+ if (vein[i] < 0.04 + 0.08 * hm) {+ px.put(hm > 0.95 ? F[6] : hm > 0.75 ? F[5] : hm > 0.55 ? F[4] : hm > 0.38 ? F[3] : hm > 0.22 ? F[2] : F[1]);+ px.add(WARM, 0.4 * hm);+ return;+ }+ px.add(WARM, 0.2 * hm * hm);+ }+ // char, with the odd fleck still glowing in it+ const L = fleck[i] * (0.8 + 0.4 * hv);+ if (L > 0 && s < L) {+ const v = (s - 6.4 * th) / Math.max(1, L - 6.4 * th);+ if (v < 1 && TW[(ph[i] * 5) & 63] && !(fade < 1 && fade <= jit[i] / 1.5 + 0.5)) {+ px.put(v < 0.3 ? F[4] : v < 0.55 ? F[3] : v < 0.8 ? F[2] : F[1]);+ px.add(WARM, 0.3 * (1 - v));+ return;+ }+ }+ if (e < 22) px.add(WARM, 0.2 * (1 - e / 22) ** 2);+ px.put(u - 6.4 < 1.6 * th + jit[i] ? CHAR : ink);+ };+ // [c0, c1): deep in the cover; [a0, a1): near the line+ const lo = Fd.below(k - (inPhase ? 33 : POOL)), hi = Fd.below(Math.max(k + (inPhase ? POOL : 33), sk > 0 ? B.lo + SR : -1e9));+ const [c0, c1, a0, a1] = inPhase ? [0, lo, lo, hi] : [hi, N, lo, hi];+ for (let j = c0; j < c1; j++) {+ const i = ord[j];+ if (fleck[i]) shadeAt(i);+ else px.at(i), px.put(ink);+ }+ for (let j = a0; j < a1; j++) shadeAt(ord[j]);+ // flames stand on the white-hot line: tall and many where the char lies below it and they rise clear,+ // short and few where they'd only lick up over the char+ for (const i of line) {+ const x = i % W, y = (i / W) | 0, dn = inPhase ? -Fd.ny[i] : Fd.ny[i], h0 = rand(x, y >> 3, seed + 51);+ if (h0 > 0.12 + 0.6 * Math.max(0, dn)) continue;+ const n = (x * 7 + (y >> 4) * 131) % 977, hv = heat[i];+ const leap = 1 + Math.max(0, noise(t * 2.6 + n * 3.1, n + 70) - 0.5) * 1.8;+ const h = (5 + 7 * rand(x, 1, seed + 53)) * (0.6 + 0.4 * noise(t * 3.3 + n * 1.7, n)) * (0.6 + 0.6 * hv) * leap * fade * (dn > 0 ? 0.65 + 0.5 * dn : 0.5);+ if (h >= 1.5) tongue(p, F, x + 0.5, y + 1, h, (1.1 + 0.7 * hv) * (0.8 + h / 16), noise(t * 2.2 + n, n + 40) * 1.5, t, n);+ }+ }+ drawSmoke(p, p0);+ ash.draw(p, "front");+ ps.draw(p, "front");+ lights.draw(p);+ },+ };+}diff --git a/src/fx/transitions/crt-off.js b/src/fx/transitions/crt-off.jsindex 5c56431..7320aea 100644--- a/src/fx/transitions/crt-off.js+++ b/src/fx/transitions/crt-off.js@@ -1,60 +1,87 @@-import { hex, ease, seg, WHITE } from "../../core/index.js";-import { screenMeta, timeline, screen, fill, W, H, accents } from "./_lib.js";+// The glowing line (a white core, a pale fringe, an outer fringe while it's fresh, light along it) follows+// Sprite Fusion's open-source lightning strike (https://www.spritefusion.com/pixel-art-vfx/lightning),+// MIT License, Copyright (c) 2026 Hugo Duprez.+import { fit, hex, clamp, ease, noise, rand, WHITE } from "../../core/index.js";+import { W, H, screenMeta, clipTo, glint, rect } 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"] },+ desc: "The picture squeezes into a white-hot glowing line, the line into a dot that lingers as a fading afterglow; then it switches back on, dot to line to picture, with a warm-up glow.",+ tags: ["crt", "tv", "retro", "switch", "wipe"],+ duration: 2.0,+ options: { palette: ["#060a14", "#0e1a33", "#1a3360", "#2a5a9a", "#4a8fd0", "#8cc4f0", "#d4ecff", "#ffffff"], seed: 1 },});-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;+const YC = H / 2, XC = W / 2;+// off: squeeze to a line, the line to a dot, the dot fades; on: a dot, a line, the picture+const SQ0 = 0.06, SQ1 = 0.34, LN1 = 0.56, DOT1 = 0.86, ON0 = 1.06, ON1 = 1.16, OPEN1 = 1.42;++// the visible strip's height and the line's half-length at time t+function shape(t) {+ if (t < SQ0) return { h: H, w: XC };+ if (t < SQ1) return { h: Math.max(1, H * (1 - ease.inCubic((t - SQ0) / (SQ1 - SQ0)))), w: XC };+ if (t < LN1) return { h: 1, w: XC * (1 - ease.inQuad((t - SQ1) / (LN1 - SQ1))) };+ if (t < ON0) return { h: 0, w: 0 };+ if (t < ON1) return { h: 1, w: XC * ease.outExpo((t - ON0) / (ON1 - ON0)) };+ return { h: Math.max(1, H * ease.outCubic(clamp((t - ON1) / (OPEN1 - ON1)))), w: XC };+}++export function draw(p0, t, o) {+ const C = fit(o.palette, 8), ink = hex(o.color), p = clipTo(p0), { h, w } = shape(t), fl = 0.85 + 0.15 * rand(Math.floor(t * 30), 7, o.seed);+ if (t >= OPEN1 + 0.02 && t < OPEN1 + 0.6) {+ // switched on: a warm-up glow over the picture, a bright refresh band rolling down it once, scanlines+ const u = (t - OPEN1) / 0.6, band = -20 + u * (H + 40);+ for (let y = 0; y < H; y++) {+ const k = 0.22 * (1 - u) ** 2 + 0.3 * Math.max(0, 1 - Math.abs(y - band) / 10) ** 2 * (1 - u) + (y & 1 ? 0.05 * (1 - u) : 0);+ if (k > 0.01) for (let x = 0; x < W; x += 1) p0.light(x, y, C[5], k);+ }+ return;}- 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;- });+ if (h >= H) return;+ const top = Math.round(YC - h / 2), bot = Math.round(YC + h / 2);+ // the dark closing in from above and below+ if (top > 0) rect(p0, 0, 0, W, top, ink);+ if (bot < H) rect(p0, 0, bot, W, H - bot, ink);+ if (h > 2) {+ // the squeezed picture: brighter as it narrows, with scanlines, its edges glowing where the dark meets it+ const sq = 1 - h / H;+ for (let y = top; y < bot; y++) {+ const e = Math.min(y - top, bot - 1 - y), k = 0.55 * sq * sq + (y & 1 ? 0.08 * sq : 0) + 0.35 * Math.max(0, 1 - e / 6) ** 2;+ for (let x = 0; x < W; x++) p0.light(x, y, C[5], k * fl);+ }+ for (const y of [top - 1, bot]) if (y >= 0 && y < H) rect(p0, 0, y, W, 1, sq > 0.6 ? C[6] : C[5]);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);+ // the line (and the dot it shrinks to): white-hot core, a pale fringe, an outer fringe while it's fresh, light+ const dotPhase = t >= LN1 && t < ON0, x0 = Math.floor(XC - w), x1 = Math.ceil(XC + w), fresh = t < SQ1 + 0.08 || (t > ON0 && t < ON1 + 0.04);+ if (h > 0 && w >= 1) {+ const fr = Math.floor(t * 30);+ for (let x = Math.max(0, x0); x < Math.min(W, x1); x++) {+ // it hums: the line wavers a pixel here and there, and crackles with flecks of static+ const u = Math.abs(x + 0.5 - XC) / w, y = YC + Math.round(noise(x / 23 + t * 9, o.seed) * (0.7 + 0.5 * u)); // 0 middle .. 1 ends+ p0.px(x, y, u < 0.85 ? WHITE : C[6]);+ if (u < 0.92) p0.px(x, y - 1, C[6]), p0.px(x, y + 1, u < 0.6 ? C[6] : C[5]);+ if (fresh && u < 0.8) p0.dot(x, y - 2, C[4], 0.5), p0.dot(x, y + 2, C[4], 0.5);+ if (rand(x, fr, o.seed + 3) < 0.06) p.px(x, y + (rand(x, fr, o.seed + 4) < 0.5 ? -1 : 1) * (2 + Math.floor(rand(x, fr, o.seed + 5) * 4)), rand(x, fr, 6) < 0.5 ? WHITE : C[5]);+ p0.light(x, y, C[6], 0.5 * fl * (1 - u * 0.6));+ }+ for (let x = x0; x <= x1; x += 9) p.glow(x, YC, 10, C[5], 0.35 * fl);+ p.glow(XC, YC, Math.min(70, 16 + w * 0.4), C[5], 0.4 * fl);+ }+ // the dot: a glint that holds a moment, then an afterglow cooling to nothing+ if (dotPhase) {+ const u = (t - LN1) / (DOT1 - LN1);+ if (u < 0.35) glint(p, XC, YC, 10 * (1 - u / 0.35) + 3, 0.2 + u * 2, C[6], C[5]);+ if (u < 1) {+ p.px(XC, YC, u < 0.5 ? WHITE : u < 0.75 ? C[6] : C[4]);+ p.px(XC - 1, YC, u < 0.4 ? C[6] : C[4]);+ // the phosphor smears the dot sideways as it cools+ const sm = Math.round(9 * (1 - u));+ for (let k = 2; k <= sm; k++) p.dot(XC - k, YC, C[4], 1 - k / (sm + 1)), p.dot(XC + k - 1, YC, C[4], 1 - k / (sm + 1));+ p.glow(XC, YC, 22 * (1 - u * 0.5), C[5], 0.55 * (1 - u) ** 1.5);+ }}+ // switching on: a pop of light at the heart before the line runs out+ const s = t - ON0;+ if (s >= 0 && s < 0.14) glint(p, XC, YC, 12 * (1 - s / 0.14) + 2, 0.4 + s * 6, C[6], C[5]), p.glow(XC, YC, 40, WHITE, 0.5 * (1 - s / 0.14));}diff --git a/src/fx/transitions/diamond-wipe.js b/src/fx/transitions/diamond-wipe.jsindex 59bd0cc..518680e 100644--- a/src/fx/transitions/diamond-wipe.js+++ b/src/fx/transitions/diamond-wipe.js@@ -1,45 +1,89 @@-import { PAL, hex, ease, seg } from "../../core/index.js";-import { screenMeta, timeline, screen, fill, W, H, accents } from "./_lib.js";+// The faceted shading (a lit ridge, a bright face toward the light, a dark one away, a bright rim) follows+// Sprite Fusion's open-source ice crystals (https://www.spritefusion.com/pixel-art-vfx/ice), MIT License,+// Copyright (c) 2026 Hugo Duprez.+import { PAL, fit, hex, clamp, smooth, ease, rand, WHITE } from "../../core/index.js";+import { W, H, screenMeta, clipTo, glint, rect } 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 },+ desc: "A wave of faceted diamonds swells across the screen, rims bright and ridges lit, cooling to black as they lock; then they rise as gems again and shrink away with glints.",+ tags: ["diamond", "lattice", "geometric", "wipe"],+ duration: 2.0,+ options: { palette: PAL.arcane, seed: 1 },});-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);+const S = 32, HD = S / 2 + 1, GROW = 0.24, IN0 = 0.04, IN1 = 0.66, OUT0 = 1.05, OUT1 = 1.56;++// the lattice: rows of diamonds S apart, every other row shifted half a step, so they tile when full+const cache = new Map();+function lattice(seed) {+ if (cache.has(seed)) return cache.get(seed);+ const out = [];+ for (let j = -1; j <= Math.ceil(H / (S / 2)) + 1; j++)+ for (let i = -1; i <= Math.ceil(W / S) + 1; i++) {+ const cx = i * S + (j & 1 ? S / 2 : 0), cy = (j * S) / 2;+ if (cx + HD < 0 || cy + HD < 0 || cx - HD > W || cy - HD > H) continue;+ // the wave runs left to right on a slant, each diamond a little early or late+ const u = clamp((cx + 0.45 * cy) / (W + 0.45 * H)), jr = rand(i, j, seed);+ out.push({ cx, cy, tin: IN0 + (IN1 - IN0) * clamp(u + (jr - 0.5) * 0.08), tout: OUT0 + (OUT1 - OUT0) * clamp(u + (rand(i, j, seed + 1) - 0.5) * 0.08), glint: jr < 0.3, spin: rand(i, j, seed + 2) * 3 });}- 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);+ cache.set(seed, out);+ return out;+}++export function draw(p0, t, o) {+ const C = fit(o.palette, 8), ink = hex(o.color), p = clipTo(p0), L = lattice(o.seed), glints = [];+ // facets, toward the light first: top left, top right, bottom left, bottom right; and how each cools+ // (faces stay in the shadow end of the ramp: the rims and ridges carry the light)+ const FACE = [[C[2], C[1], C[0]], [C[1], C[0], C[0]], [C[1], C[0], C[0]], [C[0], C[0], ink]];+ for (const d of L) {+ const ki = (t - d.tin) / GROW, ko = (t - d.tout) / GROW;+ // the last glint as it winks out+ if (d.glint && ko > 0.7 && ko < 1.5) glints.push([d, (ko - 0.7) / 0.8, 0]);+ if (ki <= 0 || ko >= 1) continue;+ // its size: swelling in with an overshoot; out, a breath bigger and then shrinking to nothing+ const hd = HD * (ko > 0 ? 1 - ease.inBack(ko, 2) : ease.outBack(Math.min(1, ki), 2.2));+ // its heat: bright while it swells, cooling once it's locked in; lighting up again as it goes+ const heat = ko > 0 ? smooth(0, 0.35, ko) : 1 - smooth(0.45, 1.25, ki);+ if (hd < 0.5) continue;+ const settled = heat <= 0;+ const y0 = Math.max(0, Math.floor(d.cy - hd)), y1 = Math.min(H - 1, Math.ceil(d.cy + hd));+ for (let y = y0; y <= y1; y++) {+ const dy = y + 0.5 - d.cy, w = hd - Math.abs(dy);+ if (w <= 0) continue;+ const x0 = Math.max(0, Math.ceil(d.cx - w - 0.5)), x1 = Math.min(W - 1, Math.floor(d.cx + w - 0.5));+ if (x1 < x0) continue;+ if (settled) {+ rect(p0, x0, y, x1 - x0 + 1, 1, ink);+ continue;}- 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;- });+ const st = heat > 0.66 ? 0 : heat > 0.33 ? 1 : 2;+ for (let x = x0; x <= x1; x++) {+ const dx = x + 0.5 - d.cx, e = hd - Math.abs(dx) - Math.abs(dy); // e: px in from the rim+ const q = (dy < 0 ? 0 : 2) + (dx < 0 ? 0 : 1), vr = dx > -1 && dx <= 0, hr = dy > -1 && dy <= 0; // the centre column and row+ let c;+ if (e < 1) {+ // the rim, lit from the top left: white there, cooling round to the far side+ const r = [heat > 0.5 ? WHITE : C[6], heat > 0.5 ? C[6] : C[5], heat > 0.5 ? C[5] : C[4], heat > 0.5 ? C[4] : C[3]][q];+ c = heat > 0.15 ? r : ink;+ if (heat > 0.15) p0.light(x, y, C[5], 0.4 * heat * (q === 0 ? 1 : 0.6));+ } else if (e < 2 && q === 0 && heat > 0.4) c = C[5];+ else if ((vr || hr) && heat > 0.3) {+ // ridges, with a white tip at the top point and a sheen running down them+ const tip = vr && dy < -hd + 4, sheen = Math.abs(((x + y - t * 260) % 90 + 90) % 90 - 45) < 3;+ c = tip || (sheen && heat > 0.5) ? WHITE : vr && dy < 0 ? (heat > 0.6 ? C[6] : C[5]) : heat > 0.6 ? C[3] : C[2];+ }+ else c = heat > 0.15 ? FACE[q][st] : ink;+ p0.px(x, y, c);+ }+ }+ if (!settled) p.glow(d.cx, d.cy, hd + 6, C[4], 0.22 * heat);+ // a glint on its top point as it locks in+ if (ki > 0.6 && ki < 1.8 && d.glint) glints.push([d, (ki - 0.6) / 1.2, hd]);+ }+ for (const [d, u, hd] of glints) {+ if (u <= 0 || u >= 1) continue;+ const y = hd ? d.cy - hd : d.cy;+ glint(p, d.cx, y, 9 * Math.pow(Math.sin(Math.PI * u), 0.7), d.spin + u * 1.5, C[6], C[5]);+ }}diff --git a/src/fx/transitions/dither-fade.js b/src/fx/transitions/dither-fade.jsdeleted file mode 100644index 2a401e8..0000000--- a/src/fx/transitions/dither-fade.js+++ /dev/null@@ -1,30 +0,0 @@-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.jsindex ac4c00d..f6cfb7d 100644--- a/src/fx/transitions/glitch-wipe.js+++ b/src/fx/transitions/glitch-wipe.js@@ -1,69 +1,102 @@-import { PAL, hex, seg, ease, rand, clamp, WHITE } from "../../core/index.js";-import { screenMeta, timeline, screen, fill, W, H, accents } from "./_lib.js";+// The specks of white, cyan and magenta a body breaks into follow Sprite Fusion's open-source blink+// (https://www.spritefusion.com/pixel-art-vfx/movement), MIT License, Copyright (c) 2026 Hugo Duprez.+import { PAL, fit, hex, clamp, ease, noise, rand, WHITE } from "../../core/index.js";+import { W, H, screenMeta, clipTo, rect } 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 },+ desc: "Torn bands of black stutter across the screen, freezing and jerking back, their ragged edges split into magenta and cyan ghosts spitting data slivers; then they tear on through.",+ tags: ["glitch", "digital", "rgb", "bands", "wipe"],+ duration: 1.8,+ options: { palette: PAL.cyber, split: "#ff2d6f", seed: 1 },});-// the bands: chunky random heights down the screen, each with a side, a start and a speed (cached per seed)+const TICK = 1 / 18, IN0 = 0.03, IN1 = 0.78, OUT0 = 0.98, OUT1 = 1.66;++// the bands: torn strips of different thickness. Neighbours move together in chunks (their timing follows a+// smooth noise down the screen), mostly left to right, now and then one from the other sideconst cache = new Map();function bands(seed) {if (cache.has(seed)) return cache.get(seed);- const list = [];+ const out = [];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,- });+ const r = rand(i, seed), h = Math.min(H - y, r < 0.4 ? 5 + Math.floor(rand(i, seed + 1) * 6) : r < 0.85 ? 10 + Math.floor(rand(i, seed + 1) * 10) : 20 + Math.floor(rand(i, seed + 1) * 12));+ const a = clamp(0.5 + 0.55 * noise(y / 40, seed + 9) + (rand(i, seed + 2) - 0.5) * 0.25), b = clamp(0.5 + 0.55 * noise(y / 40, seed + 19) + (rand(i, seed + 3) - 0.5) * 0.25);+ const span = 0.32 + rand(i, seed + 6) * 0.12;+ out.push({ i, y, h, dir: rand(i, seed + 4) < 0.82 ? 1 : -1, off: rand(i, seed + 5), t0: IN0 + a * (IN1 - IN0 - span), t1: IN0 + a * (IN1 - IN0 - span) + span, o0: OUT0 + b * (OUT1 - OUT0 - span), o1: OUT0 + b * (OUT1 - OUT0 - span) + span });y += h;}- cache.set(seed, list);- return list;+ cache.set(seed, out);+ return out;+}++// how far a band has torn at t: it moves only on ticks, by uneven jumps, sometimes freezing, sometimes+// jerking back a little, but it always starts at 0 and ends at 1+function tear(b, t, t0, t1, salt) {+ if (t <= t0) return 0;+ if (t >= t1) return 1;+ let n = Math.floor((t + b.off * TICK) / TICK);+ while (n > 0 && rand(n, b.i, salt) < 0.22) n--; // frozen ticks hold the last position+ const tq = n * TICK - b.off * TICK, u = clamp((tq - t0) / (t1 - t0));+ return clamp(ease.inOutQuad(u) + (rand(n, b.i, salt + 1) - 0.6) * 0.12 * Math.sin(Math.PI * u));}-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;+export function draw(p0, t, o) {+ const C = fit(o.palette, 8), ink = hex(o.color), RED = hex(o.split), p = clipTo(p0), B = bands(o.seed), fr = Math.floor(t / TICK);+ const out = t >= OUT0;+ for (const b of B) {+ const k = out ? tear(b, t, b.o0, b.o1, 7) : tear(b, t, b.t0, b.t1, 3);+ if ((!out && k <= 0) || (out && k >= 1)) continue;+ const moving = k > 0 && k < 1, slip = moving && rand(fr, b.i, 11) < 0.12 ? Math.round((rand(fr, b.i, 12) - 0.5) * 18) : 0;+ // the edge advances along +fwd; in, the black is behind it; out, the black is ahead of it+ const fwd = b.dir, e = (b.dir > 0 ? k * W : W - k * W) + slip;+ for (let y = b.y; y < b.y + b.h; y++) {+ // a ragged edge: each row torn a little ahead or behind, re-torn every tick+ const jag = moving ? Math.round((rand(fr, y, 14) - 0.5) * 6 + (rand(fr >> 1, b.i, 15) - 0.5) * 6) : 0, ex = clamp(Math.round(e + jag), 0, W);+ const behind = (fwd > 0) !== out; // is the black on the low-x side of the edge?+ if (behind) ex > 0 && rect(p0, 0, y, ex, 1, ink);+ else ex < W && rect(p0, ex, y, W - ex, 1, ink);+ if (!moving) continue;+ // the torn edge: a white line, a magenta ghost on the open side and a cyan ghost in the black+ const e1 = behind ? ex - 1 : ex, side = behind ? 1 : -1, sp = 2 + ((b.i + fr) % 3);+ p.px(e1, y, WHITE);+ p.px(e1 + side * sp, y, RED), p.px(e1 + side * (sp + 1), y, RED);+ p.px(e1 - side * (sp + 1), y, C[5]), p.px(e1 - side * (sp + 2), y, C[4]);+ p.light(e1, y, WHITE, 0.45);+ p.light(e1 + side * (sp + 1), y, RED, 0.5), p.light(e1 + side * (sp + 3), y, RED, 0.22);+ p.light(e1 - side * (sp + 1), y, C[5], 0.45), p.light(e1 - side * (sp + 3), y, C[5], 0.22);+ }+ if (!moving) continue;+ const ex = clamp(Math.round(e), 0, W), open = ((fwd > 0) !== out) ? 1 : -1;+ // the edge glows, and a cloud of specks crackles round it, thickest close in+ p.glow(ex, b.y + b.h / 2, b.h * 0.7 + 7, (b.i & 1) ? RED : C[5], 0.28);+ for (let s = 0; s < b.h; s++) {+ if (rand(fr, b.i, 100 + s) > 0.55) continue;+ const x = ex + open * Math.round(rand(fr, b.i, 200 + s) ** 2 * 22 - 4), y = b.y + Math.floor(rand(fr, b.i, 300 + s) * b.h);+ p.px(x, y, [WHITE, C[6], C[5], RED][Math.floor(rand(fr, b.i, 400 + s) * 4)]);+ }+ // data slivers spit off the edge: dashes of light out over the picture and glitches back in the black+ for (let s = 0; s < 4; s++) {+ if (rand(fr, b.i, 20 + s) > 0.5) continue;+ const len = 2 + Math.floor(rand(fr, b.i, 30 + s) ** 2 * 60), ahead = rand(fr, b.i, 40 + s) < 0.6;+ const d = Math.floor(rand(fr, b.i, 50 + s) ** 1.5 * 70) + 4, y = b.y + Math.floor(rand(fr, b.i, 60 + s) * b.h);+ const x = ahead ? (open > 0 ? ex + d : ex - d - len) : open > 0 ? ex - d - len : ex + d, c = [WHITE, C[6], C[5], RED][Math.floor(rand(fr, b.i, 70 + s) * 4)];+ p.rect(x, y, len, 1, c);+ for (let q = 0; q < len; q += 3) p.light(x + q, y, c, 0.35);+ }+ // a corrupted block or two: the outline of a broken tile near the edge+ if (b.h >= 8 && rand(fr, b.i, 80) < 0.35) {+ const bw = 6 + Math.floor(rand(fr, b.i, 81) * 10), bh = 3 + Math.floor(rand(fr, b.i, 82) * Math.min(6, b.h - 3)), x = ex + open * Math.floor(rand(fr, b.i, 83) * 24 - 4) - (open < 0 ? bw : 0);+ const y = b.y + Math.floor(rand(fr, b.i, 84) * (b.h - bh)), c = rand(fr, b.i, 85) < 0.5 ? C[5] : RED;+ p.rect(x, y, bw, 1, c), p.rect(x, y + bh - 1, bw, 1, c), p.rect(x, y, 1, bh, c), p.rect(x + bw - 1, y, 1, bh, c);+ for (let q = 0; q < bw; q += 2) p.light(x + q, y, c, 0.25);}- // 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);}+ // while it's all black, the signal still spits now and then+ if (t > IN1 && t < OUT0 + 0.05)+ for (let s = 0; s < 3; s++) {+ if (rand(fr, s, 90) > 0.4) continue;+ const y = Math.floor(rand(fr, s, 91) * H), x = Math.floor(rand(fr, s, 92) * W), len = 3 + Math.floor(rand(fr, s, 93) ** 2 * 40);+ p.rect(x, y, len, 1, s === 0 ? C[4] : s === 1 ? C[3] : RED);+ }}diff --git a/src/fx/transitions/iris.js b/src/fx/transitions/iris.jsindex 3c968d4..022b4ba 100644--- a/src/fx/transitions/iris.js+++ b/src/fx/transitions/iris.js@@ -1,41 +1,121 @@-import { PAL, hex, ease, seg, lerp } from "../../core/index.js";-import { screenMeta, timeline, screen, fill, W, H, accents } from "./_lib.js";+// The motes drifting in the light and the glints follow Sprite Fusion's open-source holy-light and sparkle+// (https://www.spritefusion.com/pixel-art-vfx/sparkle), MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Lights, P, Rng, fit, hex, clamp, smooth, ease, TAU, WHITE } from "../../core/index.js";+import { W, H, screenMeta, clipTo, glint, rect } 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 },+ desc: "A lit iris closes onto a warm spotlight where dust drifts, holds as its rim twinkles, snaps shut into a glint, then pops open from a flash with a white-hot rim throwing sparks.",+ tags: ["iris", "circle", "spotlight", "wipe"],+ duration: 2.2,+ options: { palette: ["#1c140c", "#3b2a18", "#6e5233", "#a8875a", "#d9bd8a", "#f3e2bd", "#fff7e8", "#ffffff"], focus: [160, 100], seed: 1 },});-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);- }+const D = meta.duration, CLOSE = 0.62, SNAP = 0.9, SHUT = 0.99, POP = 1.2, OPEN = 1.75, RS = 24, RW = 5, GLO = 16;++export function create(o) {+ const C = fit(o.palette, 8), ink = hex(o.color), R = new Rng(o.seed), [fx, fy] = o.focus;+ const R0 = Math.max(...[[0, 0], [W, 0], [0, H], [W, H]].map(([x, y]) => Math.hypot(x - fx, y - fy))) + RW + 2;+ const ps = new Particles({ rng: R, sparks: [WHITE, C[6], C[5], C[4]] }), lights = new Lights();+ // the hole's radius: closing, breathing on the spotlight, snapping shut; then popping open+ const radius = (t) =>+ t < CLOSE ? RS + (R0 - RS) * (1 - ease.inOutCubic(t / CLOSE))+ : t < SNAP ? RS + Math.sin((t - CLOSE) * 22) * 0.8 * (1 - (t - CLOSE) / (SNAP - CLOSE))+ : t < SHUT ? RS * (1 - ease.inCubic((t - SNAP) / (SHUT - SNAP)))+ : t < POP ? 0 : R0 * ease.outQuart(clamp((t - POP) / (OPEN - POP)));+ let t = 0, shut = false, popped = false, prevR = R0;+ const end = D - 0.05;+ return {+ update(dt) {+ t += dt;+ const r = radius(t);+ // dust drifts up through the spotlight while it holds+ if (t > CLOSE - 0.25 && t < SNAP && R.chance(0.25)) {+ const a = R.range(0, TAU), d = Math.sqrt(R.next()) * r * 0.9;+ ps.spawn(P.EMBER, fx + Math.cos(a) * d, fy + Math.sin(a) * d, R.range(-6, 6), -R.range(4, 14), R.range(0.4, 0.8), 0, 1);+ }+ // the rim twinkles as it holds+ if (t > CLOSE - 0.1 && t < SNAP && R.chance(0.3)) {+ const a = R.range(0, TAU);+ ps.spawn(P.STAR, fx + Math.cos(a) * (r + 1), fy + Math.sin(a) * (r + 1), 0, 0, R.range(0.2, 0.4), R.chance(0.5) ? WHITE : C[6], R.range(1, 2.4));+ }+ if (!shut && t >= SHUT) {+ shut = true;+ lights.add(fx, fy, 50, C[5], 0.7, 0.3);+ }+ if (!popped && t >= POP) {+ // pop: a white flash, sparks thrown out of the opening+ popped = true;+ lights.add(fx, fy, 140, C[5], 0.7, 0.45);+ lights.add(fx, fy, 50, WHITE, 0.9, 0.12);+ for (let i = 0; i < 40; i++) {+ const a = R.range(0, TAU), v = R.range(150, 420);+ ps.spawn(P.SPARK, fx + Math.cos(a) * 3, fy + Math.sin(a) * 3, Math.cos(a) * v, Math.sin(a) * v, R.range(0.2, 0.5));+ }+ }+ // as the rim races out it sheds glinting motes that fly on and fade+ if (t > POP && t < OPEN - 0.1) {+ const vr = (r - prevR) / dt;+ for (let k = 0; k < 2; k++) {+ if (!R.chance(0.6)) continue;+ const a = R.range(0, TAU), x = fx + Math.cos(a) * r, y = fy + Math.sin(a) * r;+ if (x < 0 || y < 0 || x >= W || y >= H) continue;+ ps.spawn(P.MOTE, x, y, Math.cos(a) * vr * 0.35, Math.sin(a) * vr * 0.35, Math.min(R.range(0.2, 0.45), end - t), R.chance(0.5) ? C[6] : C[5], 0.7);+ }+ }+ prevR = r;+ ps.update(dt);+ lights.update(dt);+ },+ draw(p0) {+ const p = clipTo(p0), r = radius(t);+ // the rim's heat: warm while it closes, white-hot as it pops, cooling as it opens+ const hot = t >= POP ? 1 - smooth(POP, OPEN, t) : t < SNAP ? 0.45 + 0.25 * smooth(CLOSE - 0.2, CLOSE, t) : 0.7;+ const rw = RW + (t >= POP ? 3 * hot : 0);+ if (t < OPEN + 0.05 && !(t >= SHUT && t < POP && r <= 0)) {+ for (let y = 0; y < H; y++) {+ const dy = y + 0.5 - fy, xo = Math.sqrt(Math.max(0, (r + rw) ** 2 - dy * dy)), xi = Math.abs(dy) < r ? Math.sqrt(r * r - dy * dy) : 0;+ if (xo <= 0) {+ rect(p0, 0, y, W, 1, ink);+ continue;+ }+ const a0 = clamp(Math.floor(fx - xo), 0, W), b1 = clamp(Math.ceil(fx + xo), 0, W);+ if (a0 > 0) rect(p0, 0, y, a0, 1, ink);+ if (b1 < W) rect(p0, b1, y, W - b1, 1, ink);+ // the rim band and the light just inside it+ const g = r > GLO ? Math.sqrt(Math.max(0, (r - GLO) ** 2 - dy * dy)) : 0;+ for (let x = a0; x < b1; x++) {+ const dx = x + 0.5 - fx;+ if (Math.abs(dx) < g) continue;+ const d = Math.hypot(dx, dy) - r;+ if (d >= 0) {+ // a bevel lit from the top left: bright there, a step darker round the far side+ const q = d / rw, lit = 0.5 - 0.5 * (dx * 0.7 + dy * 0.7) / (r + d + 0.01), h = hot * (0.55 + 0.6 * lit);+ p0.px(x, y, q >= 1 ? ink : q < 0.2 ? (h > 0.5 ? WHITE : h > 0.3 ? C[6] : C[5]) : q < 0.4 ? (h > 0.38 ? C[6] : C[5]) : q < 0.65 ? (h > 0.3 ? C[5] : C[4]) : q < 0.85 ? C[3] : C[2]);+ if (q < 0.5) p0.light(x, y, C[5], 0.45 * h * (1 - q * 2));+ } else if (d > -GLO) p0.light(x, y, C[5], (0.18 + 0.3 * hot) * (1 + d / GLO) ** 2);+ }+ }+ } else if (t >= SHUT && t < POP) rect(p0, 0, 0, W, H, ink);+ // the spotlight's pool of light, gathering as the iris closes, hottest at its heart+ if (r > 0 && r < 80 && t < SHUT) {+ const k = 1 - r / 80;+ p.glow(fx, fy, r * 1.15 + 6, C[5], 0.18 + 0.32 * k);+ p.glow(fx, fy, r * 0.6 + 3, C[6], 0.25 * k);+ }+ // light catches the iris as it turns: a glint runs once round the rim while it closes+ if (t > 0.08 && t < SNAP) {+ const a = -2.4 + ((t - 0.08) / (SNAP - 0.08)) * TAU, gx = fx + Math.cos(a) * (r + 1), gy = fy + Math.sin(a) * (r + 1);+ if (gx > 2 && gy > 2 && gx < W - 2 && gy < H - 2) glint(p, gx, gy, 7 + 3 * Math.sin(t * 9), t * 3, C[6], C[5], 0.9);+ }+ // snapping shut: the light collapses into a glint that lingers in the dark+ const s = t - SHUT;+ if (s > -0.06 && s < 0.22) glint(p, fx, fy, 14 * (1 - Math.abs(s + 0.01) / 0.23), s * 4, C[6], C[5]);+ // popping open: a flash at the heart+ const u = t - POP;+ if (u >= 0 && u < 0.18) glint(p, fx, fy, 20 * (1 - u / 0.18), 0.4 - u * 3, C[6], C[5]), p.glow(fx, fy, 60, WHITE, 0.6 * (1 - u / 0.18));+ ps.draw(p);+ lights.draw(p);+ },+ };}diff --git a/src/fx/transitions/pixel-dissolve.js b/src/fx/transitions/pixel-dissolve.jsindex 4fd28ac..63ce054 100644--- a/src/fx/transitions/pixel-dissolve.js+++ b/src/fx/transitions/pixel-dissolve.js@@ -1,58 +1,107 @@-import { PAL, hex, ease, seg, clamp, rand, noise2 } from "../../core/index.js";-import { screenMeta, timeline, screen, fill, W, H, accents } from "./_lib.js";+// The glints and the twinkling pixel dust follow Sprite Fusion's open-source sparkle+// (https://www.spritefusion.com/pixel-art-vfx/sparkle), MIT License, Copyright (c) 2026 Hugo Duprez.+import { PAL, fit, hex, clamp, ease, fbm, rand, WHITE } from "../../core/index.js";+import { W, H, screenMeta, clipTo, glint, rect } 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 },+ desc: "Clumps of blocks wink in, each drawn in a white outline that fills black and cools, with glints; then they wink out, outlines collapsing, the last small ones sparkling away.",+ tags: ["dissolve", "pixel", "blocks", "glint"],+ duration: 2.2,+ options: { palette: PAL.neon, seed: 1 },});-// when each block arrives (in) and leaves (out), as shares of each half: random, nudged by low noise into clumps+const P = 0.17, IN0 = 0.04, IN1 = 0.8, OUT0 = 1.12, OUT1 = 1.85, CELL = 20;++// the blocks: 20 px cells, some whole, some in quarters, some in sixteenths. Each winks in and out at its own+// time read off a clumpy field, so they gather in growing patches: small ones scatter first, big ones fill inconst 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;+function layout(seed) {+ if (cache.has(seed)) return cache.get(seed);+ const blocks = [];+ for (let cy = 0; cy < H / CELL; cy++)+ for (let cx = 0; cx < W / CELL; cx++) {+ const h = rand(cx, cy, seed), n = h < 0.32 ? 1 : h < 0.74 ? 2 : 4, s = CELL / n;+ for (let j = 0; j < n; j++) for (let i = 0; i < n; i++) blocks.push({ x: cx * CELL + i * s, y: cy * CELL + j * s, s });}- const v = { tin, tout, glint };- cache.set(key, v);- return v;+ const rank = (key) => {+ const v = blocks.map(key), out = new Float32Array(v.length);+ v.map((_, i) => i).sort((a, b) => v[a] - v[b]).forEach((i, k) => (out[i] = k / (v.length - 1)));+ return out;+ };+ const at = (b, sd) => fbm((b.x + b.s / 2) / 64, (b.y + b.s / 2) / 64, sd, 3);+ const uin = rank((b) => at(b, seed) + 0.22 * rand(b.x, b.y, seed + 1) + (b.s === 20 ? 0.12 : b.s === 5 ? -0.08 : 0));+ const uout = rank((b) => at(b, seed + 7) + 0.22 * rand(b.x, b.y, seed + 2) + (b.s === 20 ? -0.14 : b.s === 5 ? 0.1 : 0));+ blocks.forEach((b, i) => {+ b.tin = IN0 + uin[i] * (IN1 - IN0);+ b.tout = OUT0 + uout[i] * (OUT1 - OUT0);+ b.glint = rand(b.x, b.y, seed + 3) < (b.s >= 10 ? 0.32 : 0.1);+ b.gx = b.x + (rand(b.x, b.y, seed + 4) < 0.5 ? 0 : b.s);+ b.gy = b.y + (rand(b.x, b.y, seed + 5) < 0.5 ? 0 : b.s);+ b.spin = (rand(b.x, b.y, seed + 6) - 0.5) * 3;+ // now and then a big block throws a hero glint+ b.L = b.s === 20 && rand(b.x, b.y, seed + 8) < 0.45 ? 9 + 6 * rand(b.x, b.y, seed + 9) : 2.5 + b.s * 0.32;+ });+ cache.set(seed, blocks);+ return blocks;}-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;+// a square block, filled, with a 1 px rim+// a mote of pixel dust: a lone pixel, or now and then a little cross+function mote(p, x, y, c, cross) {+ p.px(x, y, c);+ if (cross) for (const [dx, dy] of [[1, 0], [-1, 0], [0, 1], [0, -1]]) p.px(x + dx, y + dy, c);+}++function square(p, x, y, s, fill, rim) {+ const X = Math.round(x), Y = Math.round(y), S = Math.max(1, Math.round(s));+ if (fill) rect(p, X, Y, S, S, fill);+ if (rim && S > 2) rect(p, X, Y, S, 1, rim), rect(p, X, Y + S - 1, S, 1, rim), rect(p, X, Y, 1, S, rim), rect(p, X + S - 1, Y, 1, S, rim);+}++export function draw(p0, t, o) {+ const C = fit(o.palette, 8), ink = hex(o.color), p = clipTo(p0), blocks = layout(o.seed), glints = [], frame = Math.floor(t * 15);+ for (let n = 0; n < blocks.length; n++) {+ const b = blocks[n], ki = (t - b.tin) / P, ko = (t - b.tout) / P, { x, y, s } = b, cx = x + s / 2, cy = y + s / 2;+ if (ki < 0 || ko >= 1.6) continue;+ if (ko < 0) {+ if (ki >= 1) square(p0, x, y, s, ink);+ else {+ // winking in: a white outline swells to the block, it fills with black, its rim cools down the ramp+ const g = ki < 0.35 ? 0.35 + 0.65 * ease.outBack(ki / 0.35) : 1, h = s * g;+ const rim = ki < 0.45 ? WHITE : ki < 0.6 ? C[6] : ki < 0.75 ? C[5] : ki < 0.9 ? C[4] : C[3];+ square(p, cx - h / 2, cy - h / 2, h, ki > 0.2 ? ink : 0, rim);+ if (ki < 0.3 && s >= 10) for (const [dx, dy] of [[0, 0], [1, 0], [-1, 0], [0, 1], [0, -1]]) p.px(cx - 0.5 + dx, cy - 0.5 + dy, dx || dy ? C[6] : WHITE);+ p.glow(cx, cy, s * 0.8 + 4, C[5], 0.45 * (1 - ki));+ }+ if (b.glint && ki > 0.15 && ki < 1.6) glints.push([b, (ki - 0.15) / 1.45, 1]);+ // pixel dust flickers round the fresh block+ if (ki < 1.4 && rand(frame, n, 9) < 0.35) mote(p, x + rand(frame, n, 10) * (s + 6) - 3, y + rand(frame, n, 11) * (s + 6) - 3, rand(frame, n, 12) < 0.5 ? WHITE : C[6], rand(frame, n, 17) < 0.25);+ } else {+ if (ko < 0.35) {+ // winking out: its rim lights up...+ const q = ko / 0.35;+ square(p0, x, y, s, ink, q < 0.4 ? C[4] : q < 0.75 ? C[5] : C[6]);+ p.glow(cx, cy, s * 0.8 + 3, C[4], 0.35 * q);+ } else if (ko < 0.75) {+ // ...the black drops away and the white outline collapses into its heart+ const q = (ko - 0.35) / 0.4, h = s * (1 - ease.inQuad(q) * 0.85);+ square(p, cx - h / 2, cy - h / 2, h, 0, q < 0.5 ? WHITE : C[6]);+ p.glow(cx, cy, s * 0.8 + 4, C[5], 0.45 * (1 - q * 0.5));+ } else if (ko < 1) {+ const q = (ko - 0.75) / 0.25;+ for (const [dx, dy] of [[0, 0], [1, 0], [-1, 0], [0, 1], [0, -1]]) if (!(dx || dy) || q < 0.5) p.px(cx - 0.5 + dx, cy - 0.5 + dy, dx || dy ? C[6] : WHITE);+ p.glow(cx, cy, s * 0.5 + 3, C[5], 0.35 * (1 - q));+ }+ if (b.glint && ko > 0.3) glints.push([b, (ko - 0.3) / 1.3, -1]);+ if (ko > 0.3 && ko < 1.5 && rand(frame, n, 13) < 0.3) mote(p, x + rand(frame, n, 14) * (s + 6) - 3, y + rand(frame, n, 15) * (s + 6) - 3, rand(frame, n, 16) < 0.5 ? WHITE : C[6], rand(frame, n, 18) < 0.25);}- });+ }+ // glints on top: a spinning star on a corner of the block, swelling and fading+ for (const [b, u, dir] of glints) {+ if (u <= 0 || u >= 1) continue;+ const L = b.L * Math.pow(Math.sin(Math.PI * u), 0.7);+ glint(p, b.gx, b.gy, L, b.spin * u * dir + 0.4, C[5], C[4]);+ if (b.L > 8) p.glow(b.gx, b.gy, 18 + L, C[5], 0.25 * Math.sin(Math.PI * u));+ }}diff --git a/src/fx/transitions/shatter-wipe.js b/src/fx/transitions/shatter-wipe.jsindex 3c7b0eb..ab23b72 100644--- a/src/fx/transitions/shatter-wipe.js+++ b/src/fx/transitions/shatter-wipe.js@@ -1,207 +1,280 @@-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";+// The impact flash, cracks racing out from the impact, the white flash before the burst, and the glass+// splinters, glints and cold light of the burst are adapted from Sprite Fusion's open-source ice shatter+// (https://www.spritefusion.com/pixel-art-vfx/ice), MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Bits, Lights, P, B, Rng, fit, hex, mix, clamp, smooth, sparkle, flare, TAU, WHITE } from "../../core/index.js";+import { W, H, screenMeta, clipTo, fillConvex, rect } 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 },+ desc: "A dark glass pane drops over the screen and bounces; cracks race out from an impact with a flash, then it bursts into tumbling glass shards with lit edges that fall away.",+ tags: ["shatter", "glass", "break", "shards", "wipe"],+ duration: 2.8,+ options: { palette: ["#0c1430", "#162c5c", "#1f4f94", "#2f7fcc", "#58b4ec", "#9bdcff", "#d8f4ff", "#ffffff"], seed: 2 },});-// 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+const D = meta.duration, LAND = 0.55, GP = (2 * H) / (LAND * LAND), REST = 0.3, CRACK = 1.32, BREAK = 1.62, WAVE = 520;+const LX = -0.6, LY = -0.8; // light comes from the top left+const L3 = [-0.42, -0.56, 0.71]; // and a little from the front, for the faces-// 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);+// the pane's top edge over time: it falls from above the screen, lands, bounces twice and settles+const BOUNCES = (() => {+ const out = [];+ let t0 = LAND, v = GP * LAND * REST;+ for (let k = 0; k < 3; k++) out.push({ t0, v, T: (2 * v) / GP }), (t0 += (2 * v) / GP), (v *= REST);return out;+})();+function paneY(t) {+ if (t < LAND) return -H + 0.5 * GP * t * t;+ for (const b of BOUNCES) if (t < b.t0 + b.T) return -(b.v * (t - b.t0) - 0.5 * GP * (t - b.t0) ** 2);+ return 0;}-// 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,- });+// the break: jagged rays out of the impact crossed by rings, every crack shared by the two cells it splits+function pattern(R) {+ const Ix = W * R.range(0.4, 0.6), Iy = H * R.range(0.36, 0.54), NR = 13, RING = [0, 9, 21, 37, 58, 86, 122, 168, 232];+ const ang = Array.from({ length: NR }, (_, i) => ((i + R.range(-0.3, 0.3)) / NR) * TAU), speed = ang.map(() => R.range(800, 1300));+ const V = ang.map((a) => RING.map((r, j) => {+ if (!j) return [Ix, Iy];+ const rr = r * R.range(0.84, 1.16), aa = a + R.range(-0.07, 0.07);+ return [Ix + Math.cos(aa) * rr, Iy + Math.sin(aa) * rr];+ }));+ const jag = (A, Bp) => {+ const dx = Bp[0] - A[0], dy = Bp[1] - A[1], L = Math.hypot(dx, dy) || 1, n = L > 18 ? 2 : 1, out = [A];+ for (let k = 1; k <= n; k++) {+ const f = k / (n + 1) + R.range(-0.08, 0.08), off = R.range(-1, 1) * Math.min(3, L * 0.07);+ out.push([A[0] + dx * f - (dy / L) * off, A[1] + dy * f + (dx / L) * off]);}- }- // 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);+ out.push(Bp);+ return out;+ };+ const rad = V.map((v) => v.slice(0, -1).map((A, j) => jag(A, v[j + 1])));+ const ring = V.map((v, i) => v.map((A, j) => (j ? jag(A, V[(i + 1) % NR][j]) : null)));+ // real glass breaks into long wedges: rings near the impact are whole, further out they're broken arcs+ const keep = V.map(() => RING.map((_, j) => j <= 2 || j === RING.length - 1 || R.chance(0.78 - 0.07 * j)));+ // when a crack gets to each pixel: rays race out at their own speed, rings snap across once both rays pass+ const cracks = [], reach = (i, x, y) => CRACK + Math.hypot(x - Ix, y - Iy) / speed[i];+ const trace = (pts, when) => {+ for (let k = 1; k < pts.length; k++) {+ const [ax, ay] = pts[k - 1], [bx, by] = pts[k], n = Math.ceil(Math.hypot(bx - ax, by - ay) * 2);+ for (let s = 0; s < n; s++) {+ const x = ax + ((bx - ax) * s) / n, y = ay + ((by - ay) * s) / n;+ if (x >= 0 && y >= 0 && x < W && y < H) cracks.push({ x: Math.floor(x), y: Math.floor(y), t0: when(x, y) });}- 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;+ }+ };+ for (let i = 0; i < NR; i++) for (const e of rad[i]) trace(e, (x, y) => reach(i, x, y));+ for (let i = 0; i < NR; i++)+ for (let j = 1; j < RING.length - 1; j++) {+ if (!keep[i][j]) continue;+ const i2 = (i + 1) % NR, e = ring[i][j], start = Math.max(reach(i, ...V[i][j]), reach(i2, ...V[i2][j])) + R.range(0.02, 0.07);+ const [ax, ay] = e[0];+ trace(e, (x, y) => start + Math.hypot(x - ax, y - ay) / 420);+ }+ cracks.sort((a, b) => a.t0 - b.t0);+ const cells = [];+ for (let i = 0; i < NR; i++)+ for (let j = 0, jb; j < RING.length - 1; j = jb + 1) {+ // a wedge from ring j out to the next ring crack that's there+ for (jb = j; !keep[i][jb + 1]; jb++);+ const i2 = (i + 1) % NR, side = (r) => rad[r].slice(j, jb + 1).flatMap((e, k) => (k ? e.slice(1) : e));+ const pts = [...side(i), ...ring[i][jb + 1].slice(1), ...side(i2).reverse().slice(1)];+ if (j) pts.push(...ring[i][j].slice().reverse().slice(1, -1));+ else pts.pop();+ let x0 = Infinity, y0 = Infinity, x1 = -Infinity, y1 = -Infinity, cx = 0, cy = 0;+ 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)), (cx += x), (cy += y);+ if (x1 < 0 || y1 < 0 || x0 >= W || y0 >= H) continue;+ // a shard of what's on screen: centered on the visible part, so it spins about what you see+ cx = (clamp(x0, 0, W) + clamp(x1, 0, W)) / 2;+ cy = (clamp(y0, 0, H) + clamp(y1, 0, H)) / 2;+ const d = Math.hypot(cx - Ix, cy - Iy);+ cells.push({ pts, lp: pts.map(([x, y]) => [x - cx, y - cy]), cx, cy, d, r: Math.hypot(x1 - x0, y1 - y0) / 2, tb: BREAK + d / WAVE + R.range(0, 0.04) });+ }+ return { Ix, Iy, cracks, cells };}-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;+export function create(o) {+ const C = fit(o.palette, 8), ink = hex(o.color), R = new Rng(o.seed), pat = pattern(R), { Ix, Iy } = pat;+ const ps = new Particles({ rng: R, sparks: [C[7], C[6], C[5], C[4]], haze: C[5] });+ const bits = new Bits(), lights = new Lights();+ let t = 0, bounce = -1, struck = false, burst = false;+ const end = D - 0.05;++ // glass splinters thrown from (x, y): little white-tipped streaks that tumble and fall+ const splinters = (x, y, n, vx, vy, spread, sp0, sp1) => {+ for (let i = 0; i < n; i++) {+ const a = Math.atan2(vy, vx) + R.range(-spread, spread), sp = R.range(sp0, sp1), life = Math.min(R.range(0.6, 1.2), end - t);+ if (life > 0.2) bits.add({ kind: B.SHARD, x, y, vx: Math.cos(a) * sp, vy: Math.sin(a) * sp, g: 0.8, drag: 0.6, life, a: R.range(0, TAU), va: R.range(-20, 20), s: R.range(1.5, 3.5), c: R.pick([C[7], C[6], C[5]]) });+ }+ };+ const glint = (x, y, s = R.range(1, 2.4)) => ps.spawn(P.STAR, x, y, R.range(-8, 8), R.range(-10, 4), Math.min(R.range(0.3, 0.6), end - t), R.chance(0.5) ? WHITE : C[6], s);++ return {+ update(dt) {+ t += dt;+ // each landing: chips spring off the bottom edge, glints, a cold flash along it+ while (bounce + 1 < BOUNCES.length && t >= BOUNCES[bounce + 1].t0) {+ const k = BOUNCES[++bounce].v / BOUNCES[0].v;+ if (k < 0.05) continue;+ for (let i = 0; i < 5; i++) lights.add(W * (i + 0.5) / 5, H - 2, 70, C[5], 0.5 * k, 0.35);+ for (let i = 0; i < Math.round(26 * k); i++) splinters(R.range(4, W - 4), H - 1, 1, R.range(-0.4, 0.4), -1, 0.5, 120 * k, 330 * k);+ for (let i = 0; i < Math.round(9 * k); i++) glint(R.range(8, W - 8), H - R.range(2, 10));}- 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);+ if (!struck && t >= CRACK) {+ // the blow: a white flash at the point of impact, a puff of splinters back off the glass+ struck = true;+ lights.add(Ix, Iy, 90, C[5], 0.8, 0.35);+ lights.add(Ix, Iy, 34, WHITE, 0.9, 0.1);+ splinters(Ix, Iy, 16, 0, -1, Math.PI, 60, 240);+ for (let i = 0; i < 5; i++) ps.spawn(P.VAPOUR, Ix, Iy, R.range(-40, 40), R.range(-40, 30), R.range(0.35, 0.6), C[6], R.range(2, 3.5));+ }+ // while the cracks run, glints chase their tips+ if (t > CRACK && t < BREAK && R.chance(0.12)) {+ const c = pat.cracks[R.int(0, pat.cracks.length - 1)];+ if (c.t0 < t) glint(c.x, c.y, R.range(0.6, 1.6));+ }+ if (!burst && t >= BREAK) {+ // the burst: a cold flash, a spray of splinters and a breath of glass dust out of the impact+ burst = true;+ lights.add(Ix, Iy, 170, C[4], 0.55, 0.5);+ lights.add(Ix, Iy, 60, WHITE, 0.8, 0.14);+ splinters(Ix, Iy, 46, 0, -1, Math.PI, 90, 340);+ for (let i = 0; i < 14; i++) {+ const a = R.range(0, TAU), sp = R.range(30, 110);+ ps.spawn(P.VAPOUR, Ix + Math.cos(a) * 4, Iy + Math.sin(a) * 4, Math.cos(a) * sp, Math.sin(a) * sp, R.range(0.45, 0.8), R.chance(0.6) ? C[6] : C[5], R.range(3, 6));}}- // 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);+ // the pane bursts outward from the impact: each shard flies off, tumbling, and falls away from the screen+ for (const s of pat.cells) {+ if (!s.broke && t >= s.tb) {+ s.broke = true;+ const dx = s.cx - Ix, dy = s.cy - Iy, d = Math.hypot(dx, dy) || 1, sp = R.range(40, 130) * (1.15 - Math.min(1, s.d / 260));+ s.vx = (dx / d) * sp + R.range(-15, 15);+ s.vy = (dy / d) * sp * 0.6 - R.range(20, 90);+ s.a = 0;+ s.va = R.range(-2.5, 2.5) * (1 + 20 / (s.r + 10));+ s.phi = 0;+ s.vphi = R.sign() * R.range(3, 9);+ s.psi = R.range(0, TAU);+ s.z = 0;+ s.vz = R.range(0.25, 0.7);+ s.g = R.range(0.85, 1.1);+ s.edgeOn = false;+ splinters(s.cx, s.cy, s.r > 24 ? 4 : 2, s.vx, s.vy, 1.2, 60, 220);+ if (R.chance(0.15)) glint(s.cx + R.range(-4, 4), s.cy + R.range(-4, 4));+ }+ if (!s.broke || s.gone) continue;+ s.vy += 950 * s.g * dt;+ s.vx -= s.vx * 0.3 * dt;+ s.cx += s.vx * dt;+ s.cy += s.vy * dt;+ s.a += s.va * dt;+ s.phi += s.vphi * dt;+ s.z += s.vz * dt;+ // turning edge-on to us it flashes: a glint where the light catches the glass+ const on = Math.abs(Math.cos(s.phi)) < 0.2;+ if (on && !s.edgeOn && t < end - 0.3) glint(s.cx, s.cy, R.range(1.4, 2.6));+ s.edgeOn = on;+ if (s.cy - s.r / (1 + s.z) > H + 2) s.gone = true;}- 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);+ ps.update(dt);+ bits.update(dt);+ lights.update(dt);+ },+ draw(p0) {+ const p = clipTo(p0);+ if (t < BREAK) {+ // the pane: dark glass, a lit bevel along its falling edge, faint reflections that fade once it settles+ const yb = paneY(t) + H, r1 = Math.min(H, Math.floor(yb));+ if (r1 > 0) {+ rect(p0, 0, 0, W, r1, ink);+ const shine = 1 - smooth(0.98, 1.22, t), y0 = yb - H;+ if (shine > 0) {+ for (const [off, w, a] of [[0, 16, 0.05], [22, 3, 0.1], [30, 1, 0.12]])+ for (let y = 0; y < r1; y++) {+ const xc = W * 0.18 + off + (H - (y - y0)) * 0.7;+ for (let x = Math.max(0, Math.floor(xc - w / 2)); x < Math.min(W, Math.ceil(xc + w / 2)); x++) p0.blend(x + 0.5, y + 0.5, C[6], a * shine);+ }+ const st = shine > 0.66 ? 0 : shine > 0.33 ? 1 : 2;+ for (const [dy, c] of [[1, C[6 - st * 2]], [2, C[4 - st]], [3, C[Math.max(1, 2 - st)]]]) if (r1 - dy >= 0 && r1 - dy < H) rect(p0, 0, r1 - dy, W, 1, c);+ // light runs along the edge as it falls, and spills onto the picture below it+ const gx = W * clamp(t / (LAND + 0.25)) * 1.2 - 20;+ for (let x = 0; x < W; x++) {+ const k = Math.max(0, 1 - Math.abs(x - gx) / 28);+ if (k > 0 && r1 - 1 < H) p0.px(x, r1 - 1, k > 0.5 ? WHITE : C[6]), p0.light(x, r1 - 1, C[6], 0.5 * k);+ for (let d = 0; d < 14 && r1 + d < H; d++) p0.light(x, r1 + d, C[5], 0.3 * shine * (1 - d / 14) ** 2 * (0.6 + 0.8 * k));+ }+ if (t < LAND + 0.25 && gx > 0 && gx < W && r1 - 1 < H) sparkle(p, gx, r1 - 1, 6, C[6], C[4], 0.5);+ }+ }+ // the cracks race out from the impact: white at the tip, cooling to ice, each with its shadow+ if (t >= CRACK) {+ for (const c of pat.cracks) {+ if (c.t0 > t) break;+ const age = t - c.t0;+ if (c.x + 1 < W && c.y + 1 < H) p0.px(c.x + 1, c.y + 1, C[1]);+ p0.px(c.x, c.y, age < 0.04 ? WHITE : age < 0.18 ? C[6] : C[5]);+ if (age < 0.3) p0.light(c.x, c.y, C[5], 0.55 * (1 - age / 0.3));+ }+ const u = (t - CRACK) / 0.22;+ if (u < 1) {+ flare(p, Ix, Iy, 30 * Math.pow(1 - u, 1.5), 1 - u, C);+ p.glow(Ix, Iy, 50, WHITE, 0.7 * (1 - u));+ }+ // a beat before the burst, the cracks flare white+ const w = (t - (BREAK - 0.07)) / 0.07;+ if (w > 0) for (const c of pat.cracks) p0.px(c.x, c.y, WHITE), p0.light(c.x, c.y, C[6], 0.4 * w);+ }+ } else {+ // shards still in place first (the pane breaking up outward), then the falling ones, nearest last+ const fall = pat.cells.filter((s) => s.broke && !s.gone).sort((a, b) => b.z - a.z);+ for (const s of pat.cells) if (!s.broke) drawShard(p, p0, s, C, ink, true);+ for (const s of fall) drawShard(p, p0, s, C, ink, false);+ }+ bits.draw(p);+ ps.draw(p);+ lights.draw(p);+ },+ };+}++// a shard: dark glass that tumbles about an axis in its plane (squashing as it turns, a bright sliver+// edge-on), its edges lit where they face the light, its face catching a cool sheen as it turns to it+function drawShard(p, p0, s, C, ink, still) {+ let pts, face = ink, sliver = false, gl = 0;+ if (still) pts = s.pts;+ else {+ const cp = Math.cos(s.phi), sp = Math.sin(s.phi), ci = Math.cos(s.psi), si = Math.sin(s.psi), ca = Math.cos(s.a), sa = Math.sin(s.a), k = 1 / (1 + s.z);+ pts = s.lp.map(([x, y]) => {+ const u = x * ci + y * si, v = (-x * si + y * ci) * cp, qx = u * ci - v * si, qy = u * si + v * ci;+ return [s.cx + (qx * ca - qy * sa) * k, s.cy + (qx * sa + qy * ca) * k];});- return;+ // the face's normal, turned by the tumble and the spin, against the light+ const nx0 = si * sp, ny0 = -ci * sp, nz = cp, nx = nx0 * ca - ny0 * sa, ny = nx0 * sa + ny0 * ca;+ const d = Math.abs(nx * L3[0] + ny * L3[1] + nz * L3[2]);+ gl = Math.pow(d, 6);+ // turning toward edge-on the glass reflects more (a grazing sheen), and a hairline sliver goes bright+ const graze = clamp(1 - Math.abs(cp) / 0.3) ** 2;+ face = mix(mix(ink, C[2], 0.12 + 0.4 * gl), C[3], 0.55 * graze);+ sliver = Math.abs(cp) < 0.2;+ if (Math.abs(cp) * s.r < 1.5) face = C[5];}- // 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]);+ fillConvex(p0, pts, face);+ let a2 = 0;+ for (let i = 0, j = pts.length - 1; i < pts.length; j = i++) a2 += pts[j][0] * pts[i][1] - pts[i][0] * pts[j][1];+ const sg = a2 > 0 ? 1 : -1;+ for (let i = 0, j = pts.length - 1; i < pts.length; j = i++) {+ const [ax, ay] = pts[j], [bx, by] = pts[i], dx = bx - ax, dy = by - ay, L = Math.hypot(dx, dy);+ if (L < 0.5) continue;+ const mx = (dy / L) * sg, my = (-dx / L) * sg, el = mx * LX + my * LY;+ if (still) {+ // a crack in the pane: lit fracture line, its shadow below+ p.line(ax, ay, bx, by, el > 0 ? C[5] : C[4]);+ continue;}- 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);- }+ if (el > 0.2 || sliver) {+ p.line(ax - mx, ay - my, bx - mx, by - my, C[4]);+ p.line(ax, ay, bx, by, gl > 0.5 || sliver ? WHITE : C[6]);+ p.glow((ax + bx) / 2, (ay + by) / 2, Math.min(12, 4 + L * 0.3), C[5], 0.12 + 0.3 * gl);+ } else p.line(ax, ay, bx, by, el > -0.3 ? C[4] : C[2]);}}diff --git a/src/fx/transitions/slash-wipe.js b/src/fx/transitions/slash-wipe.jsindex 3da82d0..f8d8118 100644--- a/src/fx/transitions/slash-wipe.js+++ b/src/fx/transitions/slash-wipe.js@@ -1,50 +1,201 @@-import { PAL, hex, ease, burst, fly, WHITE } from "../../core/index.js";-import { screenMeta, timeline, screen, fill, onScreen, W, H, accents } from "./_lib.js";+// The cut's tapered smear (white at the rim, cooling down the ramp with age), the dotted trace it leaves, the+// tip glint, the sparks off the end and the shavings flung off the line are adapted from Sprite Fusion's+// open-source slash (https://www.spritefusion.com/pixel-art-vfx/slash), MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Lights, P, Rng, fit, hex, clamp, smooth, ease, sparkle, WHITE } from "../../core/index.js";+import { W, H, screenMeta, clipTo, fillConvex, halfPlane, rect } 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 },+ desc: "A white-hot blade edge slices across the screen, light ahead of it and sparks spraying back over the cover; a second cut flashes through and the cover splits apart.",+ tags: ["slash", "blade", "cut", "sparks", "wipe"],+ duration: 1.7,+ options: {+ palette: ["#151a3d", "#212f6b", "#2c58aa", "#3a8bd8", "#62c8f4", "#b8c9e8", "#e8f1ff", "#ffffff"],+ sparks: ["#fff3a6", "#ffe26b", "#ff8a2a", "#f2561d"],+ seed: 2,+ },});-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;+const D = meta.duration, SL = 0.55, CS = 1 / Math.hypot(1, SL), HALO = 18;+const T0 = 0.06, SWEEP = 0.62, E0 = -(H / 2) * SL - 4, E1 = W + (H / 2) * SL + 24;+const CUT = 0.84, CSW = 0.07, CHOLD = 0.05, CTRAIL = 0.12, SLIP = CUT + 0.12, SPLIT = CUT + CSW + CHOLD + CTRAIL;++// the blade edge: x where it crosses row y, and how fast it's moving+const edgeAt = (t) => E0 + (E1 - E0) * ease.outCubic(clamp((t - T0) / SWEEP));+const speedAt = (t) => (t < T0 || t > T0 + SWEEP ? 0 : ((E1 - E0) * 3 * (1 - (t - T0) / SWEEP) ** 2) / SWEEP);+const xAt = (e, y) => e + (H / 2 - y) * SL;++export function create(o) {+ const C = fit(o.palette, 8), ink = hex(o.color), R = new Rng(o.seed), n = C.length;+ const ps = new Particles({ rng: R, sparks: o.sparks }), lights = new Lights();+ // the second cut: a "\\" through the middle, from where it enters the screen to where it leaves+ const th = R.range(0.42, 0.56), ux = Math.cos(th), uy = Math.sin(th), nx = uy, ny = -ux;+ const cx = W / 2 + R.range(-24, 24), cy = H / 2 + R.range(-10, 10);+ // the halves overhang the screen a little, so slipping along the cut never uncovers an edge+ const area = [[-24, -24], [W + 24, -24], [W + 24, H + 24], [-24, H + 24]];+ const ends = [-1, 1].map((s) => {+ // walk out along the cut until it leaves the screen+ let lo = 0, hi = 400;+ for (let k = 0; k < 30; k++) {+ const m = (lo + hi) / 2, x = cx + s * ux * m, y = cy + s * uy * m;+ if (x >= 0 && x <= W && y >= 0 && y <= H) lo = m;+ else hi = m;}- 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;+ return [cx + s * ux * lo, cy + s * uy * lo];});- // 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);+ const [A, B] = ends, LC = Math.hypot(B[0] - A[0], B[1] - A[1]);+ const halves = [1, -1].map((s) => {+ const pts = halfPlane(area, cx, cy, s * nx, s * ny);+ let mx = 0, my = 0;+ for (const [x, y] of pts) (mx += x / pts.length), (my += y / pts.length);+ return { s, pts, mx, my, spin: s * R.range(0.5, 0.9) };});+ let t = 0, acc = 0, entered = false, tipped = false, split = false;+ const end = D - 0.05;++ // where a half of the cover is: it slips along the cut, then the halves fly apart, turning a little+ const placeOf = (hf) => {+ const slip = 5 * ease.outCubic(clamp((t - SLIP) / 0.12)) * (hf.s > 0 ? 1 : -0.4), u = Math.max(0, t - SPLIT);+ const sep = 30 * u + 0.5 * 1500 * u * u, rot = hf.spin * u * u;+ return { dx: ux * slip + hf.s * nx * sep, dy: uy * slip + hf.s * ny * sep, rot, sep };+ };+ const moved = (hf, pl, [x, y]) => {+ const c = Math.cos(pl.rot), s = Math.sin(pl.rot), lx = x - hf.mx, ly = y - hf.my;+ return [hf.mx + lx * c - ly * s + pl.dx, hf.my + lx * s + ly * c + pl.dy];+ };++ return {+ update(dt) {+ t += dt;+ // the blade grinds through: sparks spray back over the cover, shavings flake off, light rides the edge+ const sp = speedAt(t), e = edgeAt(t);+ if (!entered && t >= T0) {+ entered = true;+ lights.add(4, 4, 60, C[5], 0.6, 0.25);+ }+ // in bursts: each a fountain of sparks off one spot where the edge bites+ for (acc += sp * dt * 0.035; acc > 1; acc--) {+ const y = R.range(4, H - 4), x = xAt(e, y) - 1, a0 = Math.PI + R.range(-0.1, 0.6), n = R.int(5, 10);+ if (x < 0 || x >= W) continue;+ for (let i = 0; i < n; i++) {+ const a = a0 + R.range(-0.75, 0.75), v = R.range(0.2, 1) * (140 + 0.22 * sp);+ ps.spawn(P.SPARK, x, y + R.range(-2, 2), Math.cos(a) * v, Math.sin(a) * v, R.range(0.15, 0.4));+ if (R.chance(0.4)) ps.spawn(P.MOTE, x, y, Math.cos(a) * v * 0.45, Math.sin(a) * v * 0.45 - 20, R.range(0.2, 0.5), R.chance(0.5) ? C[6] : C[5], 0.7);+ }+ lights.add(x, y, R.range(30, 46), C[5], 0.35, 0.14);+ }+ // the second cut lands: a glint at its end, sparks thrown on along it, shavings off its length+ if (!tipped && t >= CUT + CSW) {+ tipped = true;+ for (let i = 0; i < 12; i++) {+ const a = Math.atan2(uy, ux) + R.range(-0.5, 0.5), v = R.range(150, 400);+ ps.spawn(P.SPARK, B[0] - ux * 2, B[1] - uy * 2, Math.cos(a) * v, Math.sin(a) * v, R.range(0.12, 0.35));+ }+ for (let i = 0; i < 18; i++) {+ const k = R.range(0.1, 1), x = A[0] + (B[0] - A[0]) * k, y = A[1] + (B[1] - A[1]) * k, s = R.sign(), v = R.range(30, 100);+ ps.spawn(P.MOTE, x, y, s * nx * v + ux * 20, s * ny * v - 10, R.range(0.25, 0.55), R.chance(0.5) ? C[5] : C[4], 0.6);+ }+ for (let i = 0; i < 5; i++) lights.add(A[0] + (B[0] - A[0]) * (i + 0.5) / 5, A[1] + (B[1] - A[1]) * (i + 0.5) / 5, 46, C[5], 0.45, 0.3);+ }+ // and the halves break apart: sparks spray out of the opening seam both ways+ if (!split && t >= SPLIT) {+ split = true;+ for (let i = 0; i < 46; i++) {+ const k = R.range(0, 1), x = A[0] + (B[0] - A[0]) * k, y = A[1] + (B[1] - A[1]) * k, s = R.sign(), v = R.range(80, 320);+ const a = Math.atan2(s * ny, s * nx) + R.range(-0.7, 0.7);+ ps.spawn(P.SPARK, x, y, Math.cos(a) * v, Math.sin(a) * v, Math.min(R.range(0.15, 0.45), end - t));+ }+ for (let i = 0; i < 6; i++) lights.add(A[0] + (B[0] - A[0]) * (i + 0.5) / 6, A[1] + (B[1] - A[1]) * (i + 0.5) / 6, 56, C[5], 0.5, 0.35);+ }+ ps.update(dt);+ lights.update(dt);+ },+ draw(p0) {+ const p = clipTo(p0);+ if (t < CUT + CSW + CHOLD + 0.02 || t < SLIP) {+ // the cover behind the blade, row by row: ink, then the smear cooling from the white-hot edge, light ahead+ const e = edgeAt(t), sp = speedAt(t), Ls = clamp(sp * 0.0065, 1.5, 8), echo = clamp(sp / 900) * 0.6;+ for (let y = 0; y < H; y++) {+ const xe = xAt(e, y + 0.5), ia = clamp(Math.floor(xe - (Ls + 10) / CS), 0, W), ib = clamp(Math.ceil(xe + HALO / CS), 0, W);+ if (ia > 0) rect(p0, 0, y, ia, 1, ink);+ for (let x = ia; x < ib; x++) {+ const d = (xe - (x + 0.5)) * CS;+ if (d < 0) {+ const u = 1 + d / HALO;+ p0.light(x, y, C[5], 0.32 * u * u);+ if (d > -4) p0.light(x, y, WHITE, 0.3 * (1 + d / 4) ** 2);+ continue;+ }+ if (d < 1) p0.px(x, y, WHITE);+ else if (d < 2) p0.px(x, y, C[6]);+ else {+ const q = (d - 2) / Ls;+ p0.px(x, y, q < 0.3 ? C[5] : q < 0.55 ? C[4] : q < 0.8 ? C[3] : q < 1 ? C[2] : ink);+ // a dotted trace a beat behind the edge, while it's moving fast+ if (echo > 0 && Math.abs(d - Ls - 7) < 0.5 && (x + y) % 3 === 0) p0.dot(x, y, C[4], echo);+ }+ if (d < Ls + 2) p0.light(x, y, C[5], 0.3 * (1 - d / (Ls + 2)));+ }+ }+ }+ if (t >= SLIP) {+ // the two halves: dark, their cut edges white-hot and cooling to ice; light pours out of the seam+ const heat = 1 - clamp((t - CUT - 0.05) / 0.5);+ for (const hf of halves) {+ const pl = placeOf(hf), pts = hf.pts.map((q) => moved(hf, pl, q)), a = moved(hf, pl, A), b = moved(hf, pl, B);+ // the cut face of this half: white-hot at the edge, cooling and narrowing to an ice rim+ const c = Math.cos(pl.rot), sn = Math.sin(pl.rot), mx = hf.s * (nx * c - ny * sn), my = hf.s * (nx * sn + ny * c);+ const rim = [heat > 0.55 ? WHITE : heat > 0.25 ? C[6] : C[5], heat > 0.4 ? C[6] : C[4], heat > 0.3 ? C[5] : C[3], heat > 0.3 ? C[4] : ink];+ const deep = clamp(1 + pl.sep * 0.5, 1, 4); // the cut face shows more as the halves part+ fillConvex(p0, pts, (x, y) => {+ const d = (x - a[0]) * mx + (y - a[1]) * my;+ if (d < deep) {+ if (d < 2) p0.light(x, y, C[5], 0.4 * heat * (1 - d / 2));+ return rim[Math.max(0, Math.floor(d))];+ }+ return ink;+ });+ if (heat > 0)+ for (let i = 0; i < 8; i++) {+ const k = (i + 0.5) / 8;+ p.glow(a[0] + (b[0] - a[0]) * k, a[1] + (b[1] - a[1]) * k, 12 + pl.sep * 0.15, C[5], 0.3 * heat);+ }+ }+ }+ // the second cut: a smear that rips along the line, thickest just behind its head, white at its core,+ // cooling down the ramp, its tail dissolving; a dotted trace where it's gone; light riding its head+ const u = t - CUT;+ if (u >= 0 && u < CSW + CHOLD + CTRAIL + 0.25) {+ const head = LC * ease.outExpo(clamp(u / CSW)), tail = LC * smooth(CSW + CHOLD, CSW + CHOLD + CTRAIL, u), age = clamp(u / (CSW + CHOLD + CTRAIL));+ const Wc = 3.6 * (1 - (tail / LC) * 0.55), span = head - tail, sn = Math.abs(nx);+ if (span > 1 && tail < LC - 1 && t < SPLIT)+ for (let y = 0; y < H; y++) {+ // the cut crosses row y at x0; the smear spans Wc either side of it, measured square to the cut+ const x0 = A[0] + ((y + 0.5 - A[1]) * ux) / uy, hw = (Wc + 1) / sn;+ for (let x = Math.max(0, Math.floor(x0 - hw)); x < Math.min(W, Math.ceil(x0 + hw)); x++) {+ const px = x + 0.5 - A[0], py = y + 0.5 - A[1], s = px * ux + py * uy, v = (s - tail) / span;+ if (v < 0 || v > 1) continue;+ const w = Wc * Math.pow(Math.sin(Math.PI * Math.pow(v, 2.2)), 0.6);+ if (w < 0.35) continue;+ const q = Math.abs(px * nx + py * ny) / w;+ if (q > 1) continue;+ const ci = q < 0.34 && age < 0.5 ? 0 : Math.round(q * (n - 1) * 0.75 + age * 2.4 - v * 0.8 + 0.4);+ p0.dot(x, y, C[n - 1 - clamp(ci, 0, n - 1)], Math.min(1, v / 0.4));+ if (q < 0.5) p0.light(x, y, C[5], 0.4 * (1 - age));+ }+ }+ // the trace it leaves behind, until the cover parts+ if (tail > 2 && t < SPLIT)+ for (let s = 0; s < tail; s += 1.6) p.dot(A[0] + ux * s, A[1] + uy * s, C[5], 0.7 * (0.4 + (0.6 * s) / LC));+ if (u < 0.3) {+ const hx = A[0] + ux * head, hy = A[1] + uy * head;+ p.glow(hx, hy, 46, C[4], 0.55 * (1 - u / 0.3));+ }+ const g = u - CSW * 0.6;+ if (g > 0 && g < 0.24) sparkle(p, B[0] - ux * 3, B[1] - uy * 3, 11 * ease.outBack(Math.min(1, g / 0.05)) * (1 - g / 0.24), C[6], C[4], 0.7);+ }+ ps.draw(p);+ lights.draw(p);+ },+ };}diff --git a/src/fx/transitions/spiral-wipe.js b/src/fx/transitions/spiral-wipe.jsdeleted file mode 100644index 55106bc..0000000--- a/src/fx/transitions/spiral-wipe.js+++ /dev/null@@ -1,54 +0,0 @@-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.jsindex f127e9e..b46315a 100644--- a/src/fx/transitions/star-iris.js+++ b/src/fx/transitions/star-iris.js@@ -1,55 +1,116 @@-import { PAL, hex, seg, lerp, wrap, TAU, WHITE } from "../../core/index.js";-import { screenMeta, timeline, screen, fill, W, H, accents } from "./_lib.js";+// The twinkles (spinning glints at the tips, motes shed as it turns) follow Sprite Fusion's open-source sparkle+// (https://www.spritefusion.com/pixel-art-vfx/sparkle), MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Lights, P, Rng, PAL, fit, hex, clamp, ease, TAU, WHITE } from "../../core/index.js";+import { W, H, screenMeta, clipTo, glint, rect } 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 },+ desc: "A five-point star iris spins shut on the middle of the screen, its gold rim lit and its tips twinkling and shedding motes; it closes on a glint and spins open again from a flash.",+ tags: ["iris", "star", "gold", "wipe"],+ duration: 2.2,+ options: { palette: PAL.gold, focus: [160, 96], seed: 1 },});-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));+const CLOSE = 0.98, OPEN0 = 1.16, OPEN1 = 2.0, RMAX = 430, INNER = 0.46, RW = 4;++// the star at t: its outer radius and its turn+function starAt(t) {+ if (t < CLOSE) return { r: RMAX * (1 - ease.inOutQuad(t / CLOSE)) ** 1.3, a: -Math.PI / 2 + ease.inOutCubic(t / CLOSE) * 1.6 * TAU };+ if (t < OPEN0) return { r: 0, a: 0 };+ const u = clamp((t - OPEN0) / (OPEN1 - OPEN0));+ return { r: RMAX * ease.inOutCubic(u) ** 1.15, a: -Math.PI / 2 - ease.inOutCubic(u) * 1.6 * TAU };+}+const points = (fx, fy, r, a) => Array.from({ length: 10 }, (_, i) => {+ const rr = i % 2 ? r * INNER : r, an = a + (i * Math.PI) / 5;+ return [fx + Math.cos(an) * rr, fy + Math.sin(an) * rr];+});++export function create(o) {+ const C = fit(o.palette, 8), ink = hex(o.color), R = new Rng(o.seed), [fx, fy] = o.focus;+ const ps = new Particles({ rng: R, sparks: [WHITE, C[6], C[5], C[4]] }), lights = new Lights();+ let t = 0, shut = false, opened = false, prev = starAt(0);+ const end = meta.duration - 0.05;+ return {+ update(dt) {+ t += dt;+ const s = starAt(t), pts = points(fx, fy, s.r, s.a), spin = (s.a - prev.a) / dt;+ // the tips shed gold motes as the star turns, flung off along their path+ if (s.r > 2)+ for (let i = 0; i < 10; i += 2) {+ const [x, y] = pts[i];+ if (x < 0 || y < 0 || x >= W || y >= H || !R.chance(0.35)) continue;+ const an = s.a + (i * Math.PI) / 5, v = spin * s.r * 0.25;+ ps.spawn(R.chance(0.6) ? P.STAR : P.MOTE, x, y, -Math.sin(an) * v + Math.cos(an) * 20, Math.cos(an) * v + Math.sin(an) * 20, Math.min(R.range(0.25, 0.55), end - t), R.chance(0.5) ? C[6] : C[5], R.range(0.6, 1.8));+ }+ if (!shut && t >= CLOSE) {+ shut = true;+ lights.add(fx, fy, 60, C[5], 0.7, 0.3);+ }+ if (!opened && t >= OPEN0) {+ opened = true;+ lights.add(fx, fy, 120, C[5], 0.7, 0.4);+ lights.add(fx, fy, 40, WHITE, 0.8, 0.12);+ for (let i = 0; i < 24; i++) {+ const a = R.range(0, TAU), v = R.range(60, 200);+ ps.spawn(P.STAR, fx, fy, Math.cos(a) * v, Math.sin(a) * v, R.range(0.3, 0.6), R.chance(0.5) ? WHITE : C[6], R.range(0.6, 2));+ }+ }+ prev = s;+ ps.update(dt);+ lights.update(dt);+ },+ draw(p0) {+ const p = clipTo(p0), s = starAt(t);+ if (t >= CLOSE && t < OPEN0) rect(p0, 0, 0, W, H, ink);+ else if (s.r < RMAX - 2) {+ const pts = points(fx, fy, s.r, s.a);+ // the dark outside the star, row by row: the star's spans are where the outline crossings pair up+ for (let y = 0; y < H; y++) {+ const yc = y + 0.5, xs = [];+ for (let i = 0, j = 9; i < 10; j = i++) {+ const [xi, yi] = pts[i], [xj, yj] = pts[j];+ if (yi > yc !== yj > yc) xs.push(xi + ((yc - yi) * (xj - xi)) / (yj - yi));+ }+ xs.sort((a, b) => a - b);+ let x = 0;+ for (let k = 0; k + 1 < xs.length; k += 2) {+ const a = clamp(Math.round(xs[k]), 0, W);+ if (a > x) rect(p0, x, y, a - x, 1, ink);+ x = Math.max(x, clamp(Math.round(xs[k + 1]), 0, W));+ }+ if (x < W) rect(p0, x, y, W - x, 1, ink);+ }+ // the gold rim: along each edge, out into the dark, white where it faces the light+ for (let i = 0, j = 9; i < 10; j = i++) {+ const [ax, ay] = pts[j], [bx, by] = pts[i], L = Math.hypot(bx - ax, by - ay);+ if (L < 0.5) continue;+ const ux = (bx - ax) / L, uy = (by - ay) / L, nx = -uy, ny = ux; // outward for this winding+ const lit = nx * -0.6 + ny * -0.8 > 0.1;+ for (let sx = 0; sx <= L; sx += 0.5) {+ const x0 = ax + ux * sx, y0 = ay + uy * sx;+ if (x0 < -RW || y0 < -RW || x0 > W + RW || y0 > H + RW) continue;+ for (let d = 0; d < RW; d += 0.5) {+ const c = d < 1 ? (lit ? WHITE : C[6]) : d < 2 ? C[5] : d < 3 ? C[4] : C[3];+ p.px(x0 + nx * d, y0 + ny * d, c);+ }+ if (sx % 2 === 0) p.light(x0, y0, C[5], 0.5);+ }+ }+ // twinkles on the tips, and light pooling in the star as it closes+ for (let i = 0; i < 10; i += 2) {+ const [x, y] = pts[i];+ if (x < 2 || y < 2 || x > W - 2 || y > H - 2) continue;+ glint(p, x, y, 5 + 3 * Math.sin(t * 13 + i), t * 2 + i, C[6], C[5]);+ }+ if (s.r < 140) p.glow(fx, fy, s.r * 0.7 + 8, C[5], 0.35 * (1 - s.r / 140));+ }+ // shutting: a glint where it closed; opening: a flash+ const u = t - CLOSE;+ if (u > -0.05 && u < 0.2) glint(p, fx, fy, 14 * (1 - Math.abs(u) / 0.2), u * 4, C[6], C[5]);+ const v = t - OPEN0;+ if (v >= 0 && v < 0.16) glint(p, fx, fy, 18 * (1 - v / 0.16), 0.3 - v * 5, C[6], C[5]), p.glow(fx, fy, 50, WHITE, 0.5 * (1 - v / 0.16));+ ps.draw(p);+ lights.draw(p);+ },+ };}diff --git a/src/fx/ui/_lib.js b/src/fx/ui/_lib.jsindex 8feeb54..86cbc0d 100644--- a/src/fx/ui/_lib.js+++ b/src/fx/ui/_lib.js@@ -1,46 +1,195 @@-// Helpers for the ui effects: chunky outlined text, per-letter layout, shakes. Not an effect (starts with _).+// Helpers for the ui effects (not an effect: the file name starts with _). Big pixel words with a hand-made+// finish, a character lit or flashed by the effect, HUD plates and a whole-pixel shake.+// tintActor adapts the body flash of Sprite Fusion's open-source power-up+// (https://www.spritefusion.com/pixel-art-vfx/power-up), MIT License, Copyright (c) 2026 Hugo Duprez.-import { noise } from "../../core/index.js";-export { Layer, twinkle, fit } from "../pickups/_lib.js";+import { FONTS, WHITE, luma, noise, mix } from "../../core/index.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.+ * The letters of str in a pixel font, laid out left to right in font pixels:+ * { letters: [{ ch, g (glyph, null for a space), x (left edge), w, h }], w (total width), h }.*/-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);+export function spell(str, font = "big") {+ const F = FONTS[font], letters = [];+ let x = 0;+ for (const ch of String(str)) {+ const g = F.glyphs[ch] ?? F.glyphs[ch.toUpperCase()] ?? null;+ const w = g ? g.w : F.space;+ letters.push({ ch, g, x, w, h: F.h });+ x += w + F.gap;+ }+ return { letters, w: Math.max(0, x - F.gap), h: F.h };}-/** 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;+// scratch maps of which letter covers each pixel and where it sits in its font pixel, reused between frames+let ids = new Int16Array(4096), edges = new Uint8Array(4096);++/**+ * Draw letters as one word with a crafted finish at the 1 px level: a gradient down each letter, a lit top+ * edge, a shaded underside, a 1 px dark outline and a drop shadow, an optional diagonal shine and a white flash.+ * items: [{ g (glyph), x, y (top-left, local px), sx, sy (px per font pixel), a (alpha), flash (0..1 white),+ * slant (italics: px of lean per font row, stepped in whole pixels) }]. st: { fill: [bottom..top colors], edge (lit top edge), under (underside),+ * outline, ow (outline width, 1 or 2), shadow, shine (diagonal position, local x at the word's top row), shineY,+ * glint: color beside the shine's white core }.+ */+export function drawWord(p, items, st) {+ if (!items.length) return;+ let x0 = Infinity, y0 = Infinity, x1 = -Infinity, y1 = -Infinity;+ for (const it of items) {+ const h = it.g.rows.length * it.sy, w = it.g.w * it.sx, sl = Math.abs(it.slant ?? 0) * it.g.rows.length;+ x0 = Math.min(x0, it.x - sl); x1 = Math.max(x1, it.x + w + sl);+ y0 = Math.min(y0, it.y); y1 = Math.max(y1, it.y + h);}- return { list: out, w: Math.max(0, x - scale) };+ const ow = st.ow ?? 1;+ x0 = Math.floor(x0) - 1 - ow; y0 = Math.floor(y0) - 1 - ow; x1 = Math.ceil(x1) + 2 + ow; y1 = Math.ceil(y1) + 3 + ow;+ const W = x1 - x0, H = y1 - y0;+ if (W * H > ids.length) (ids = new Int16Array(W * H * 2)), (edges = new Uint8Array(W * H * 2));+ ids.fill(0, 0, W * H);+ items.forEach((it, k) => {+ const g = it.g, gh = g.rows.length, h = gh * it.sy, bot = it.y + h, sl = it.slant ?? 0;+ for (let py = Math.floor(it.y); py < Math.ceil(bot); py++) {+ const gy = Math.floor((py + 0.5 - it.y) / it.sy);+ if (gy < 0 || gy >= gh) continue;+ const shift = Math.round(((bot - py - 0.5) / it.sy) * sl);+ const ry = py + 0.5 - it.y - gy * it.sy, row = g.rows[gy];+ for (let px = Math.floor(it.x + shift) - 1; px <= Math.ceil(it.x + shift + g.w * it.sx); px++) {+ const fx = px + 0.5 - it.x - shift, gx = Math.floor(fx / it.sx);+ if (gx < 0 || gx >= g.w || !row[gx]) continue;+ const i = (py - y0) * W + (px - x0);+ if (i < 0 || i >= W * H) continue;+ ids[i] = k + 1;+ // the bevel follows the font pixels, so italic steps don't break it: lit top, shaded underside, lit left.+ // Only flat edges get it: a diagonal stroke (a font pixel touching one corner to corner) stays whole.+ const rx = fx - gx * it.sx, up = gy > 0 ? g.rows[gy - 1] : null, dn = gy < gh - 1 ? g.rows[gy + 1] : null;+ const open = (r) => !r || (!r[gx] && !r[gx - 1] && !r[gx + 1]);+ edges[i] = (ry < 1 && open(up) ? 1 : 0) | (ry >= it.sy - 1 && open(dn) ? 2 : 0) | (rx < 1 && !(gx > 0 && row[gx - 1]) ? 4 : 0);+ }+ }+ });+ const at = (x, y) => (x < x0 || y < y0 || x >= x1 || y >= y1 ? 0 : ids[(y - y0) * W + (x - x0)]);+ const F = st.fill, nF = F.length, shine = st.shine, glint = st.glint ?? WHITE, sy0 = st.shineY ?? y0;+ for (let y = y0; y < y1; y++)+ for (let x = x0; x < x1; x++) {+ const id = at(x, y);+ if (id) {+ const it = items[id - 1], v = (y + 0.5 - it.y) / (it.g.rows.length * it.sy);+ let i = Math.min(nF - 1, Math.max(0, Math.floor((1 - v) * nF)));+ let c = F[i];+ const e = edges[(y - y0) * W + (x - x0)];+ if (e & 1) c = st.edge ?? F[nF - 1];+ else if (e & 2) c = st.under ?? F[0];+ else if (e & 4 && i < nF - 1) c = F[i + 1];+ if (shine !== undefined && shine !== null) {+ const d = Math.abs(x + 0.5 - (y + 0.5 - sy0) * 0.6 - shine);+ if (d < 1.1) c = WHITE;+ else if (d < 2.4) c = glint;+ }+ // a flash is white all over, then wipes up off the letter (no dither)+ if (it.flash > 0.6 || (it.flash > 0.25 && v < 0.5)) c = WHITE;+ p.dot(x, y, c, it.a ?? 1);+ continue;+ }+ // the outline hugs every letter; the shadow drops below and right of it+ let n = 0;+ for (let dy = -ow; dy <= ow && !n; dy++) for (let dx = -ow; dx <= ow && !n; dx++) if (ow < 2 || Math.abs(dx) + Math.abs(dy) < 4) n = at(x + dx, y + dy);+ if (n) {+ p.dot(x, y, st.outline, items[n - 1].a ?? 1);+ continue;+ }+ const s = at(x - ow, y - 1 - ow) || at(x + 1 - ow, y - 1 - ow) || at(x - ow, y - ow);+ if (s && st.shadow) p.dot(x, y, st.shadow, (items[s - 1].a ?? 1) * 0.9);+ }}-/** 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)];+/**+ * Flash a character in light: its own pixels recolored by brightness into a bright ramp ([shadow, middle,+ * light] colors). k (0..1) steps down without dither: all of it, then its lighter parts, then only highlights;+ * above 0.8 the lightest go white.+ */+export function tintActor(p, A, k, ramp) {+ if (!A || k <= 0.12) return;+ const m = A.mask, pix = A.pixels, cut = k > 0.6 ? 0 : k > 0.3 ? 0.22 : 0.5;+ for (let j = 0; j < m.h; j++)+ for (let i = 0; i < m.w; i++) {+ const q = j * m.w + i;+ if (!m.data[q]) continue;+ const l = pix ? luma(pix[q]) : 0.6;+ if (l < cut) continue;+ p.px(A.x + i, A.y + j, l > 0.5 ? (k > 0.8 ? WHITE : ramp[2]) : l > 0.22 ? ramp[1] : ramp[0]);+ }}-/** 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);- }+/**+ * Light a character: warm additive light over its body (k), stronger towards the top, and light catching the+ * edge just inside its dark outline (rim 0..1), mixed into its own colors so it stays solid and readable.+ */+export function lightActor(p, A, c, k, rim = 0, t = 0) {+ if (!A || (k <= 0.01 && rim <= 0.01)) return;+ const m = A.mask, pix = A.pixels, has = (i, j) => i >= 0 && j >= 0 && i < m.w && j < m.h && m.data[j * m.w + i];+ for (let j = 0; j < m.h; j++)+ for (let i = 0; i < m.w; i++) {+ if (!m.data[j * m.w + i]) continue;+ if (k > 0.01) p.light(A.x + i, A.y + j, c, k * (1.1 - (0.5 * j) / m.h));+ if (rim <= 0.01 || !has(i - 1, j) || !has(i + 1, j) || !has(i, j - 1)) continue;+ if (has(i - 2, j) && has(i + 2, j) && has(i, j - 2)) continue;+ const f = rim * (0.75 + 0.35 * noise(j * 0.6 - t * 8, i * 3));+ if (f > 0.25) p.px(A.x + i, A.y + j, mix(pix ? pix[j * m.w + i] || c : c, c, Math.min(0.85, f)));+ }+}++/** A glowing 1 px line just outside a character, flickering: an aura's edge. */+export function haloActor(p, A, c, k, t = 0) {+ if (!A || k <= 0.02) return;+ p.outline(A.mask, A.x, A.y, c, (mx, my) => k * (0.75 + 0.45 * noise(my * 0.45 - t * 7, mx * 3)));+}++/**+ * A UI plate: a rounded rectangle with a dark outline, a lit top rim, a body that darkens towards the bottom+ * and a shaded bottom edge. col: { outline, rim, top, body, low }. opts: { r (corner), a, shine (diagonal x) }.+ */+export function panel(p, x, y, w, h, col, { r = 3, a = 1, shine = null } = {}) {+ if (w < 2 || h < 2) return;+ const X1 = x + w, Y1 = y + h;+ p.shade(x, y, X1, Y1, (px, py, o) => {+ const cx = Math.max(x + r - px, 0, px - (X1 - r)), cy = Math.max(y + r - py, 0, py - (Y1 - r));+ const e = cx > 0 && cy > 0 ? r - Math.hypot(cx, cy) : Math.min(px - x, X1 - px, py - y, Y1 - py);+ if (e < 0) return;+ o.a = a;+ if (e < 1) return col.outline;+ if (py - y < 2) return col.rim;+ if (Y1 - py < 2) return col.low;+ if (shine !== null) {+ const d = Math.abs(px - (py - y) * 0.6 - shine);+ if (d < 1.3) return WHITE;+ if (d < 3) return col.rim;+ }+ return py - y < h * 0.45 ? col.top : col.body;+ });+}++/**+ * A HUD heart, 13 x 12: k outline, w highlight, h light, o body, m shade, d deep shade. heartPal(C) maps a+ * ramp onto it (C[0] outline .. C[4] body, white highlight); drawn with p.sprite.+ */+export const HEART = [+ "..kkk...kkk..",+ ".khhok.khook.",+ "khwhookoooomk",+ "khwoooooooomk",+ "khoooooooommk",+ "kooooooooomdk",+ ".kooooooomdk.",+ "..kooooomdk..",+ "...kooomdk...",+ "....komdk....",+ ".....kdk.....",+ "......k......",+];+export const heartPal = (C) => ({ k: C[0], w: WHITE, h: C[5], o: C[4], m: C[3], d: C[2] });++/** A whole-pixel shake that dies away: [dx, dy] at time t, amp px, from t0 over len seconds. */+export function shake(t, amp, t0 = 0, len = 0.3, seed = 1, hz = 32) {+ if (t < t0 || t > t0 + len) return [0, 0];+ const k = 1 - (t - t0) / len;+ return [Math.round(noise(t * hz, seed) * amp * k * 1.7), Math.round(noise(t * hz, seed + 7) * amp * k * 1.3)];}diff --git a/src/fx/ui/achievement.js b/src/fx/ui/achievement.jsindex 3dcda89..982a080 100644--- a/src/fx/ui/achievement.js+++ b/src/fx/ui/achievement.js@@ -1,62 +1,116 @@-import { PAL, RAMP, seg, ease, bump, WHITE } from "../../core/index.js";-import { Layer, boldText, twinkle, fit } from "./_lib.js";+import { Particles, Lights, P, Rng, fit, sparkle, star, clamp, seg, ease, rand, TAU, WHITE, hex } from "../../core/index.js";+import { spell, drawWord, panel } 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,+ desc: "A toast slides in on speed lines and settles; a gold medal pops onto it in a burst of sparkles, a shine sweeps the whole toast, then it slides away.",+ tags: ["ui", "achievement", "toast", "medal", "reward", "text", "one-shot"],+ size: [220, 72],+ origin: [110, 36],+ duration: 2.4,loop: false,fps: 30,bg: "dark",- options: { palette: PAL.arcane, title: "ACHIEVEMENT", text: "UNLOCKED", seed: 7 },+ options: {+ palette: ["#2a1405", "#5c3008", "#9a5a0e", "#d48e18", "#f5b92c", "#ffde5e", "#fff4bc", "#ffffff"],+ ribbon: ["#0c1430", "#1f3a7a", "#2f66c4", "#5aa0f0", "#a6d4ff"],+ title: "ACHIEVEMENT",+ text: "UNLOCKED",+ seed: 9,+ },};-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+const PW = 130, PH = 34, PX = -PW / 2, PY = -PH / 2, IN = 0.2, MEDAL = 0.26, SHINE = 0.95, OUT = 1.92;+const MX = PX + 17, MY = 2;+const INK = { outline: hex("#0d0a14"), rim: hex("#5a4f74"), top: hex("#2a2338"), body: hex("#211b2d"), low: hex("#15111c") };-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;- });+// the medal: ribbon straps behind it, a scalloped-free gold disc with a lit rim and a raised star+function medal(p, G, B, x, y, s, white, shine) {+ const r = 10 * s;+ for (const sd of [-1, 1]) {+ // a strap from the medal up to the toast's top edge+ p.poly([[x + sd * 2 * s, y - r + 2], [x + sd * 7 * s, y - r + 2], [x + sd * 9 * s, PY + 1], [x + sd * 4 * s, PY + 1]], (px) => (Math.abs(px - x) < 4.5 * s ? B[2] : B[3]));+ p.line(x + sd * 2 * s, y - r + 2, x + sd * 4 * s, PY + 1, B[0]);+ p.line(x + sd * 7 * s, y - r + 2, x + sd * 9 * s, PY + 1, B[0]);}- 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));+ const st = star(x, y + 0.5, 2.8 * s, 6.5 * s, 5);+ const inStar = (px, py) => {+ let inside = false;+ for (let i = 0, j = st.length - 1; i < st.length; j = i++) {+ const [xi, yi] = st[i], [xj, yj] = st[j];+ if (yi > py !== yj > py && px < ((xj - xi) * (py - yi)) / (yj - yi) + xi) inside = !inside;+ }+ return inside;+ };+ p.shade(x - r - 1, y - r - 1, x + r + 1, y + r + 1, (px, py) => {+ const dx = px - x, dy = py - y, d = Math.hypot(dx, dy);+ if (d > r) return;+ if (white) return r - d < 1 ? G[6] : WHITE;+ if (r - d < 1) return G[0];+ const l = -(dx * 0.6 + dy * 0.8) / r;+ if (shine !== null && Math.abs(dx - dy * 0.6 - shine) < 1.2) return WHITE;+ if (r - d < 2.5) return l > 0.2 ? G[6] : l > -0.3 ? G[4] : G[3];+ // the raised star: a dark edge, a lit upper-left face, a shaded lower-right one+ if (inStar(px, py)) return !inStar(px + 1, py) || !inStar(px - 1, py) || !inStar(px, py + 1) || !inStar(px, py - 1) ? G[2] : dx + dy < 0 ? G[7] : G[6];+ return l > 0.4 ? G[5] : l > -0.2 ? G[4] : G[3];+ });+}++export function create(o) {+ const G = fit(o.palette, 8), B = fit(o.ribbon, 5), R = new Rng(o.seed);+ const ps = new Particles({ rng: R, sparks: [G[7], G[6], G[5], G[3]] }), lights = new Lights();+ const title = spell(o.title, "mini"), sub = spell(o.text, "mini"), TX = PX + 34;+ let t = 0, popped = false;+ const end = meta.duration - 0.05;+ // the toast slides in from the right, overshoots and settles; at the end it eases back and slides off+ const xAt = (t) => (t < IN ? 30 * Math.pow(1 - t / IN, 3) : t < OUT ? -3 * Math.exp(-(t - IN) * 12) * Math.sin((t - IN) * 30) : seg(t, OUT, OUT + 0.06) < 1 ? -3 * seg(t, OUT, OUT + 0.06) : -3 + 33 * ease.inQuad(seg(t, OUT + 0.06, OUT + 0.24)));+ return {+ update(dt) {+ t += dt;+ if (!popped && t >= MEDAL + 0.06) {+ popped = true;+ lights.add(MX, MY, 36, G[5], 0.7, 0.4);+ for (let i = 0; i < 12; i++) {+ const an = (i / 12) * TAU + R.range(-0.2, 0.2), sp = R.range(40, 90);+ ps.spawn(P.STAR, MX + Math.cos(an) * 9, MY + Math.sin(an) * 9, Math.cos(an) * sp, Math.sin(an) * sp * 0.6, R.range(0.25, 0.45), R.pick([G[7], G[6], G[5]]), i % 3 ? 0.6 : R.range(1.2, 1.8));+ }+ }+ if (t > 0.5 && t < OUT && R.chance(0.05)) ps.spawn(P.STAR, MX + R.range(-11, 11), MY + R.range(-11, 9), 0, -R.range(4, 10), Math.min(R.range(0.3, 0.5), end - t), G[6], R.chance(0.3) ? 1.4 : 0.6);+ ps.update(dt);+ lights.update(dt);+ },++ draw(p) {+ const x = xAt(t), out = t > OUT + 0.06, a = t < 0.05 ? 0.5 : out ? 1 - seg(t, OUT + 0.12, OUT + 0.24) : 1;+ if (a <= 0) return;+ // speed lines trail it while it moves+ const moving = t < IN * 0.8 || out;+ if (moving)+ for (let i = 0; i < 8; i++) {+ const y = PY + 3 + rand(Math.floor(t * 30), i, 1) * (PH - 6), L = 10 + rand(Math.floor(t * 30), i, 2) * 26, x0 = x + PW / 2 + 2 + rand(i, 3) * 6;+ p.line(x0, y, Math.min(106, x0 + L), y, (u) => (u < 0.3 ? WHITE : u < 0.6 ? G[6] : G[4]), (u) => a * (1.1 - u));+ }+ // the plate and its gold edge; a shine sweeps the whole toast+ const sh = seg(t, SHINE, SHINE + 0.36), shine = sh > 0 && sh < 1 ? PX - 12 + (PW + 30) * ease.inOutSine(sh) : null;+ panel(p, PX + x, PY, PW, PH, INK, { r: 4, a, shine: shine === null ? null : shine + x });+ p.line(PX + x + 4, PY + 1, PX + x + PW - 5, PY + 1, G[4], a);+ p.px(PX + x + 3, PY + 1, G[2]);+ // the words: a gold title, a white line under it+ const ti = title.letters.filter((L) => L.g).map((L) => ({ g: L.g, x: TX + x + L.x * 2, y: PY + 5, sx: 2, sy: 2, a }));+ drawWord(p, ti, { fill: [G[4], G[5], G[6]], edge: G[7], under: G[3], outline: INK.outline, shadow: 0, shine: shine === null ? null : shine + x, shineY: PY, glint: G[7] });+ const si = sub.letters.filter((L) => L.g).map((L) => ({ g: L.g, x: TX + x + L.x * 2, y: PY + 19, sx: 2, sy: 2, a }));+ drawWord(p, si, { fill: [hex("#9a94b0"), hex("#d8d4e6"), WHITE], edge: WHITE, under: hex("#6e6886"), outline: INK.outline, shadow: 0, shine: shine === null ? null : shine + x, shineY: PY });+ // the medal pops onto it: big and white for a frame, then springs to size+ const mk = t - MEDAL;+ if (mk > 0) {+ const s = mk < 0.035 ? 1.5 : 1 + 0.35 * Math.exp(-mk * 16) * Math.cos(mk * 28);+ medal(p, G, B, MX + x, MY, s, mk < 0.07, shine === null ? null : shine - MX + 4);+ p.glow(MX + x, MY, 20, G[5], 0.3 * a + (mk < 0.15 ? 0.5 * (1 - mk / 0.15) : 0));+ const g = ((t - 1.5) % 0.9) / 0.9;+ if (t > 1.5 && g < 0.25) sparkle(p, MX + x - 4, MY - 4, 4 * Math.sin((g / 0.25) * Math.PI), G[7], G[6], 0.5);+ }+ ps.draw(p);+ lights.draw(p);+ },+ };}diff --git a/src/fx/ui/button-press.js b/src/fx/ui/button-press.jsdeleted file mode 100644index 9534390..0000000--- a/src/fx/ui/button-press.js+++ /dev/null@@ -1,73 +0,0 @@-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.jsdeleted file mode 100644index 23fe3c1..0000000--- a/src/fx/ui/checkmark.js+++ /dev/null@@ -1,53 +0,0 @@-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.jsindex 0cc68b5..7bed56e 100644--- a/src/fx/ui/coin-collect.js+++ b/src/fx/ui/coin-collect.js@@ -1,69 +1,176 @@-import { PAL, hex, burst, fly, seg, ease, WHITE } from "../../core/index.js";-import { boldText, twinkle, fit } from "./_lib.js";+// The coin's pop (a white disc, then a ring and stars) and the trails of flying coins adapt Sprite Fusion's+// open-source pickup (https://www.spritefusion.com/pixel-art-vfx/pickup), MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Lights, P, Rng, fit, band, flare, sparkle, clamp, seg, ease, TAU, WHITE, hex } from "../../core/index.js";+import { spell, drawWord, panel } 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,+ desc: "A coin bursts into a fountain of spinning coins that hang, then zip one by one into a HUD counter that pops and ticks up, glints and folds away.",+ tags: ["ui", "coins", "pickup", "reward", "hud", "counter", "one-shot"],+ size: [176, 116],+ origin: [60, 102],+ duration: 2.45,loop: false,fps: 30,bg: "ground",- options: { palette: PAL.gold, count: 5, from: 12, seed: 18 },+ options: { palette: ["#2a1405", "#5c3008", "#9a5a0e", "#d48e18", "#f5b92c", "#ffde5e", "#fff4bc", "#ffffff"], count: 10, from: 12, seed: 4 },};-// 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")];+const POP = 0.3, FLY0 = 0.58, GAP = 0.075, FLY = 0.28, FOLD = 2.0, CY = -16;+// the HUD: a plate at the top right with a coin icon and the count+const HX = 50, HY = -88, HW = 60, HH = 22, IX = HX + 12, IY = HY + 11;+const INK = { outline: hex("#0d0a14"), rim: hex("#4a4060"), top: hex("#2a2338"), body: hex("#1e1929"), low: hex("#141019") };-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);+// a coin r px across, turned so its face is w wide (0..1): a dark edge, a rim lit on its upper left, a face lit+// from the top left with an embossed bar, white when it flashes+function coin(p, C, x, y, r, w, white = false) {+ const rx = Math.max(0.7, r * w), ry = r;+ p.shade(x - rx - 1, y - ry - 1, x + rx + 1, y + ry + 1, (px, py) => {+ const u = (px - x) / rx, v = (py - y) / ry, d = Math.hypot(u, v);+ if (d > 1) return;+ const e = (1 - d) * Math.min(rx * 1.6, ry);+ if (white) return e < 1 ? C[6] : WHITE;+ if (e < 1) return C[1];+ if (rx < 2) return v < -0.2 ? C[6] : v < 0.4 ? C[4] : C[3];+ if (e < 2) return u + v < -0.2 ? C[6] : C[3];+ if (Math.abs(px - x) < 0.55 && Math.abs(v) < 0.5) return C[3];+ if (px - x >= 0.55 && px - x < 1.55 && Math.abs(v) < 0.5) return C[7];+ const l = -(u * 0.6 + v * 0.8);+ return l > 0.4 ? C[7] : l > 0.05 ? C[6] : l > -0.35 ? C[5] : C[4];});- // 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]);+}++export function create(o) {+ const C = fit(o.palette, 8), R = new Rng(o.seed), N = clamp(Math.round(o.count), 1, 12);+ const ps = new Particles({ rng: R, ground: () => 0, sparks: [C[7], C[6], C[5], C[3]] }), lights = new Lights();+ const end = meta.duration - 0.05;+ const coins = Array.from({ length: N }, (_, i) => {+ const s = (i / Math.max(1, N - 1)) * 2 - 1;+ return { x: 0, y: CY, vx: s * R.range(55, 90) + R.range(-12, 12), vy: -R.range(170, 285), ph: R.range(0, TAU), spin: R.range(9, 14) * R.sign(), state: 0, t0: FLY0 + i * GAP, fx: 0, fy: 0, trail: [], bob: R.range(0, TAU) };+ });+ let t = 0, popped = false, count = Math.round(o.from), bump = 0, flash = 0;++ return {+ update(dt) {+ t += dt;+ if (!popped && t >= POP) {+ popped = true;+ lights.add(0, CY, 46, WHITE, 0.8, 0.14);+ lights.add(0, CY, 48, C[5], 0.6, 0.5);+ for (let i = 0; i < 14; i++) {+ const an = (i / 14) * TAU + R.range(-0.2, 0.2), sp = R.range(80, 170);+ ps.spawn(P.SPARK, Math.cos(an) * 3, CY + Math.sin(an) * 3, Math.cos(an) * sp, Math.sin(an) * sp - 30, R.range(0.15, 0.35));+ }+ for (let i = 0; i < 4; i++) ps.spawn(P.DUST, R.range(-6, 6), -1, R.sign() * R.range(15, 40), -R.range(2, 8), R.range(0.3, 0.5), hex("#5a4f6e"), R.range(1.5, 2.5));+ // a ring of stars flung out of the burst+ for (let i = 0; i < 10; i++) {+ const an = (i / 10) * TAU + R.range(-0.2, 0.2), sp = R.range(70, 130), down = Math.sin(an) > 0 ? 0.25 : 1;+ ps.spawn(P.STAR, Math.cos(an) * 6, CY + Math.sin(an) * 6, Math.cos(an) * sp, Math.sin(an) * sp * down, R.range(0.35, 0.6), R.pick([C[7], C[6], C[5]]), i % 3 ? 0.6 : R.range(1.2, 2));+ }+ }+ for (const c of coins) {+ if (!popped || c.state === 3) continue;+ c.ph += c.spin * dt;+ if (c.state < 2) {+ // the fountain: thrown up, slowed by the air, then they hang and bob+ if (c.state === 0) {+ c.vy += 640 * dt;+ c.vx -= c.vx * 2.2 * dt;+ if (c.vy > 0) c.state = 1;+ } else (c.vy -= c.vy * 7 * dt), (c.vx -= c.vx * 4 * dt);+ c.x += c.vx * dt;+ c.y += c.vy * dt;+ if (t >= c.t0) (c.state = 2), (c.fx = c.x), (c.fy = c.y + Math.sin(t * 6 + c.bob) * 1.5);+ }+ if (c.state === 2) {+ // the flight: an arc up and over into the HUD's coin, quickening as it goes+ const u = clamp((t - c.t0) / FLY), e = u * u, mx = c.fx + (IX - c.fx) * 0.35, my = Math.min(c.fy, IY) - 26;+ c.x = (1 - e) * (1 - e) * c.fx + 2 * (1 - e) * e * mx + e * e * IX;+ c.y = (1 - e) * (1 - e) * c.fy + 2 * (1 - e) * e * my + e * e * IY;+ c.trail.unshift([c.x, c.y]);+ if (c.trail.length > 7) c.trail.pop();+ // it sheds sparkles as it goes+ if (R.chance(0.25)) ps.spawn(P.STAR, c.x + R.range(-2, 2), c.y + R.range(-2, 2), R.range(-8, 8), R.range(-4, 10), R.range(0.2, 0.4), R.pick([C[7], C[6]]), 0.6);+ if (u >= 1) {+ c.state = 3;+ count++;+ bump = 1;+ flash = 1;+ lights.add(IX, IY, 26, C[5], 0.6, 0.25);+ for (let i = 0; i < 3; i++) {+ const an = R.range(0, TAU), sp = R.range(18, 40);+ ps.spawn(P.STAR, IX + Math.cos(an) * 5, IY + Math.sin(an) * 5, Math.cos(an) * sp, Math.sin(an) * sp, Math.min(R.range(0.25, 0.45), end - t), R.pick([C[7], C[6]]), i ? 0.6 : R.range(1.2, 1.8));+ }+ }+ }+ }+ bump = Math.max(0, bump - dt / 0.14);+ flash = Math.max(0, flash - dt / 0.07);+ ps.update(dt);+ lights.update(dt);+ },++ drawBack(p) {+ // a ring on the floor where the coin bursts+ const k = (t - POP) / 0.45;+ if (k > 0 && k < 1) band(p, 0, 0, 4 + 34 * ease.outCubic(k), 0.22, Math.max(1, 3 * (1 - k)), 1.15 - k, C, (g) => Math.sin(g) < 0);+ ps.draw(p, "back");+ },++ draw(p) {+ const k = (t - POP) / 0.45;+ if (k > 0 && k < 1) band(p, 0, 0, 4 + 34 * ease.outCubic(k), 0.22, Math.max(1, 3 * (1 - k)), 1.15 - k, C, (g) => Math.sin(g) >= 0);+ // the big coin: bobbing and turning above its shadow, then it bursts in a white disc+ if (t < POP + 0.02) {+ const y = CY + Math.sin(t * 9) * 1.5, w = Math.abs(Math.cos(t * 7));+ p.ellipse(0, 0.5, 6 - 0.5 * Math.sin(t * 9), 1.3, hex("#0d0a14"), 0.6);+ // two motes circle it, passing behind and in front+ for (let i = 0; i < 2; i++) {+ const an = t * 7 + i * Math.PI, ox = Math.cos(an) * 11, oy = Math.sin(an) * 3;+ if (Math.sin(an) < 0) p.px(ox, y + oy, C[4]);+ }+ coin(p, C, 0, y, 7, Math.max(0.12, w), t > POP - 0.04);+ for (let i = 0; i < 2; i++) {+ const an = t * 7 + i * Math.PI, ox = Math.cos(an) * 11, oy = Math.sin(an) * 3;+ if (Math.sin(an) >= 0) p.px(ox, y + oy, C[7]), p.glow(ox, y + oy, 4, C[5], 0.4);+ }+ p.glow(0, y, 20, C[5], 0.45 + 0.4 * seg(t, POP - 0.15, POP));+ if (t > 0.06 && t < 0.2) sparkle(p, -3, y - 3, 3.5 * Math.sin(((t - 0.06) / 0.14) * Math.PI), C[7], C[6], 0.4);+ }+ const pk = (t - POP) / 0.1;+ if (pk > 0 && pk < 1) p.circle(0, CY, 13 * (1 - pk) + 1, pk < 0.5 ? WHITE : C[6]);+ const fk = (t - POP) / 0.2;+ if (fk > 0 && fk < 1) flare(p, 0, CY, 26 * Math.pow(1 - fk, 1.5), 1 - fk, C);+ const rk = (t - POP - 0.03) / 0.35;+ if (rk > 0 && rk < 1) p.ring(0, CY, 6 + 22 * ease.outCubic(rk), Math.max(1, 2 * (1 - rk)), rk < 0.3 ? WHITE : C[6], 1.2 - rk);+ // the coins and their trails+ for (const c of coins) {+ if (!popped || c.state === 3) continue;+ c.trail.forEach(([x, y], i) => i > 0 && p.line(c.trail[i - 1][0], c.trail[i - 1][1], x, y, i < 3 ? C[6] : C[4], 1.2 - i / 7));+ const hover = c.state === 1 ? Math.sin(t * 6 + c.bob) * 1.5 : 0, w = Math.abs(Math.cos(c.ph));+ coin(p, C, c.x, c.y + hover, 5, Math.max(0.15, w));+ p.glow(c.x, c.y + hover, 10, C[5], c.state === 2 ? 0.5 : 0.32);+ // light catches each hanging coin now and then+ const gl = (t * 1.7 + c.bob) % 1;+ if (c.state === 1 && gl < 0.12 && w > 0.5) sparkle(p, c.x - 1, c.y + hover - 2, 3 * Math.sin((gl / 0.12) * Math.PI), C[7], C[6], 0.4);+ }+ // the HUD: unfolds, counts up with a pop on every coin, glints, folds away+ const open = ease.outBack(seg(t, 0.06, 0.26), 2.2) * (1 - ease.inBack(seg(t, FOLD, FOLD + 0.2), 2));+ if (open > 0.04) {+ const h = HH * open, y0 = HY + (HH - h) / 2, sh = seg(t, 1.5, 1.76);+ panel(p, HX, y0, HW, h, INK, { r: Math.min(4, h / 2), shine: sh > 0 && sh < 1 ? HX - 6 + (HW + 16) * sh : null });+ if (open > 0.7) {+ coin(p, C, IX, IY, 5.5 * (1 + 0.3 * bump), 1, flash > 0.5);+ p.glow(IX, IY, 14, C[5], 0.25 + 0.4 * bump);+ if (bump > 0) p.ring(IX, IY, 7 + 8 * (1 - bump), 1, bump > 0.6 ? WHITE : C[6], bump * 1.3);+ const s = 2 * (1 + 0.22 * bump), str = "x" + count, word = spell(str), W = word.w * s, H = 7 * s, x0 = IX + 9, ty = IY - H / 2;+ const items = word.letters.filter((L) => L.g).map((L) => ({ g: L.g, x: x0 + L.x * s, y: ty, sx: s, sy: s, flash: flash > 0.5 ? 1 : 0 }));+ drawWord(p, items, { fill: [C[4], C[5], C[6], C[7]], edge: WHITE, under: C[3], outline: INK.outline, shadow: 0 });+ if (bump > 0) p.glow(x0 + W / 2, IY, 16, C[5], 0.3 * bump);+ }+ }+ ps.draw(p, "front");+ lights.draw(p);+ },+ };}diff --git a/src/fx/ui/combo-counter.js b/src/fx/ui/combo-counter.jsindex d28f4d9..2aaf9f4 100644--- a/src/fx/ui/combo-counter.js+++ b/src/fx/ui/combo-counter.js@@ -1,54 +1,129 @@-import { PAL, burst, seg, ease, TAU, WHITE } from "../../core/index.js";-import { Layer, boldText, blitSlant, shake, fit } from "./_lib.js";+import { Particles, Lights, P, Rng, fit, sparkle, clamp, seg, ease, rand, TAU, WHITE, scale } from "../../core/index.js";+import { spell, drawWord, shake } 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,+ desc: "x5 COMBO rockets in on streaming speed lines, smearing, and slams to a stop: a white flash, a ring, sparks; it pulses while a timer bar drains, then whooshes out.",+ tags: ["ui", "combo", "counter", "combat", "text", "one-shot"],+ size: [208, 100],+ origin: [104, 50],+ duration: 1.45,loop: false,fps: 30,bg: "dark",- options: { palette: PAL.neon, count: 5, label: "COMBO", seed: 4 },+ options: { palette: ["#1a0516", "#3d0a33", "#701560", "#b0228f", "#f53cd1", "#ff86e6", "#ffd2f6", "#ffffff"], count: 5, label: "COMBO", seed: 6 },};-const L = new Layer(96, 48);-const LAND = 0.12;+const HIT = 0.1, BEAT = 0.5, OUT = 1.1;-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]);- });+// a burst of speed lines across the frame, re-thrown every frame like a comic panel; k fades them+function speedLines(p, C, t, k, dir) {+ if (k <= 0.02) return;+ const f = Math.floor(t * 30);+ for (let i = 0; i < 18; i++) {+ if (rand(f, i, 3) > k) continue;+ const y = Math.round((rand(f, i, 1) - 0.5) * 60), L = 16 + rand(f, i, 2) * 50, x = (rand(f, i, 4) - 0.5) * 190;+ const x0 = Math.max(-100, x - L / 2), x1 = Math.min(100, x + L / 2);+ p.line(x0, y, x1, y, (u) => ((dir > 0 ? u : 1 - u) > 0.75 ? WHITE : (dir > 0 ? u : 1 - u) > 0.35 ? C[6] : C[4]), (u) => ((dir > 0 ? u : 1 - u) < 0.25 ? 0.6 : 1));}- // 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));+}++export function create(o) {+ const C = fit(o.palette, 8), R = new Rng(o.seed), SHADOW = scale(C[0], 0.5);+ const ps = new Particles({ rng: R, sparks: [C[7], C[6], C[5], C[3]] }), lights = new Lights();+ const big = spell("x" + Math.round(o.count)), lab = spell(o.label);+ const BS = 4, LS = 2, W = big.w * BS + 4 + lab.w * LS, X0 = -W / 2, BASE = 12;+ const spikes = Array.from({ length: 10 }, (_, i) => [(i / 10) * TAU + R.range(-0.15, 0.15), R.range(14, 24)]);+ let t = 0, hit = false, out = false;+ // where the words sit: rocketing in from the left, overshooting, settling; whooshing out to the right+ const xAt = (t) => {+ t = Math.max(0, t);+ if (t < HIT) return -32 * Math.pow(1 - t / HIT, 2);+ if (t < OUT) return 7 * Math.exp(-(t - HIT) * 18) * Math.sin((t - HIT) * 34);+ const u = seg(t, OUT, OUT + 0.2);+ return u < 0.3 ? -4 * ease.outQuad(u / 0.3) : -4 + 24 * ease.inQuad((u - 0.3) / 0.7);+ };++ return {+ update(dt) {+ t += dt;+ if (!hit && t >= HIT) {+ hit = true;+ lights.add(0, 0, 70, C[5], 0.7, 0.4);+ lights.add(-20, 0, 34, WHITE, 0.8, 0.1);+ for (let i = 0; i < 26; i++) {+ const an = R.range(-1.2, 1.2) + (R.chance(0.3) ? Math.PI : 0), sp = R.range(120, 300);+ ps.spawn(P.SPARK, R.range(-20, 20), R.range(-8, 8), Math.cos(an) * sp, Math.sin(an) * sp * 0.6 - 20, R.range(0.12, 0.3));+ }+ }+ // sparkles pop off the count on its beat+ if (t > BEAT && t < OUT && R.chance(0.1)) {+ const x = X0 + R.range(0, big.w * BS), y = BASE - R.range(0, 30);+ ps.spawn(P.STAR, x, y, R.range(-10, 10), -R.range(5, 20), R.range(0.25, 0.45), R.pick([C[7], C[6]]), R.chance(0.3) ? 1.6 : 0.6);+ }+ if (!out && t >= OUT + 0.06) {+ out = true;+ for (let i = 0; i < 10; i++) ps.spawn(P.MOTE, R.range(-50, 30), R.range(-14, 10), R.range(220, 320), R.range(-10, 10), R.range(0.06, 0.14), R.pick([C[7], C[6]]), 1);+ }+ ps.update(dt);+ lights.update(dt);+ },++ draw(p) {+ const [sx, sy] = shake(t, 3, HIT, 0.25, o.seed);+ // speed lines stream behind it as it rockets in, and again as it leaves+ speedLines(p, C, t, t < HIT ? 1 : t < OUT ? Math.max(0, 1 - (t - HIT) / 0.35) * 0.9 : seg(t, OUT + 0.04, OUT + 0.12) * (1 - seg(t, OUT + 0.18, OUT + 0.3)), t >= OUT ? -1 : 1);+ // the slam: a spiky white star behind the count for two frames, then a ring rolling out+ const hk = t - HIT;+ if (hk >= 0 && hk < 0.07) {+ const cx = X0 + (big.w * BS) / 2, k = hk < 0.035 ? 1 : 1.3;+ for (const [an, L] of spikes) {+ const ca = Math.cos(an) * 1.4, sa = Math.sin(an);+ if (k === 1) p.beam(cx, 0, cx + ca * L, sa * L, 3, (u) => (u < 0.5 ? WHITE : C[6]));+ else p.line(cx + ca * L * 0.5, sa * L * 0.5, cx + ca * L * k, sa * L * k, C[5]);+ }+ }+ const rk = (t - HIT) / 0.32;+ if (rk > 0 && rk < 1) {+ const r = 20 + 34 * ease.outCubic(rk);+ p.ellipse(sx, sy, r * 1.5, r * 0.75, rk < 0.3 ? WHITE : C[5], (d) => (d > 1 - 1.5 / (r * 0.75) ? 1.25 - rk : 0));+ }+ ps.draw(p);+ // the words: smeared while they fly, white on the slam, a pulse on the beat, a drained timer underneath+ const x = xAt(t), moving = t < HIT || t > OUT + 0.06, stretch = moving ? (t < HIT ? 1.22 : 1.12) : 1;+ const pulse = Math.exp(-(((t - BEAT) / 0.05) ** 2)), flash = (t >= HIT && t < HIT + 0.07) || pulse > 0.6 ? 1 : 0;+ const a = t > OUT ? 1 - seg(t, OUT + 0.08, OUT + 0.2) : t < 0.035 ? 0.5 : 1;+ const layout = (dx) => {+ const bs = BS * (1 + 0.12 * pulse), items = [];+ const bx = X0 + dx - (big.w * BS * (stretch - 1)) / 2, by = BASE - 7 * bs;+ big.letters.forEach((L) => L.g && items.push({ g: L.g, x: bx + L.x * BS * stretch, y: by, sx: BS * stretch, sy: bs, slant: 1, flash, a }));+ const lx = X0 + dx + big.w * BS * stretch + 4;+ lab.letters.forEach((L) => L.g && items.push({ g: L.g, x: lx + L.x * LS * stretch, y: BASE - 7 * LS, sx: LS * stretch, sy: LS, slant: 0.5, flash, a }));+ return items;+ };+ if (moving && a > 0) {+ // two dimmer afterimages trailing the words+ for (const [lag, c] of [[0.03, C[2]], [0.015, C[3]]]) {+ const items = layout(xAt(t - (t < HIT ? lag : -lag)) + sx);+ drawWord(p, items.map((it) => ({ ...it, flash: 0 })), { fill: [c], edge: c, under: c, outline: 0, shadow: 0 });+ }+ }+ if (a > 0) {+ const sh = seg(t, 0.62, 0.86), items = layout(x + sx);+ drawWord(p, items.map((it) => ({ ...it, y: it.y + sy })), { fill: [C[4], C[5], C[6], C[7]], edge: WHITE, under: C[3], outline: C[0], ow: 2, shadow: SHADOW, shine: sh > 0 && sh < 1 ? X0 - 10 + (W + 24) * sh : null, shineY: BASE - 28, glint: C[6] });+ // the combo timer: a thin bar under the words, draining until it goes+ const bk = seg(t, HIT + 0.1, HIT + 0.2) * (t > OUT ? 0 : 1);+ if (bk > 0) {+ const bw = W * bk, left = 1 - seg(t, HIT + 0.2, OUT), bx = X0 + x + sx, by = BASE + 5 + sy;+ p.rect(bx - 1, by - 1, bw + 2, 4, C[0]);+ p.rect(bx, by, bw, 2, C[1]);+ if (left > 0) p.rect(bx, by, bw * left, 2, C[5]), p.rect(bx, by, bw * left, 1, C[6]), p.px(bx + bw * left - 1, by, WHITE);+ }+ }+ p.glow(sx - 20, 0, 60, C[4], 0.2 * a + (t >= HIT && t < HIT + 0.15 ? 0.5 * (1 - (t - HIT) / 0.15) : 0) + 0.25 * pulse);+ const g = (t - 0.86) / 0.22;+ if (g > 0 && g < 1) sparkle(p, X0 + W - 2, BASE - 14, 6 * Math.sin(g * Math.PI), C[7], C[5], 0.5);+ lights.draw(p);+ },+ };}diff --git a/src/fx/ui/confetti.js b/src/fx/ui/confetti.jsindex 90290c0..735fd4e 100644--- a/src/fx/ui/confetti.js+++ b/src/fx/ui/confetti.js@@ -1,49 +1,168 @@-import { PAL, ramp, burst, fly, seg, scale, TAU, WHITE } from "../../core/index.js";+// The flutter (a swing that slows at its ends, a tilt that follows it, a paper flip that shows the back) adapts+// Sprite Fusion's open-source falling leaves (https://www.spritefusion.com/pixel-art-vfx/falling-leaves),+// MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Lights, P, Rng, fit, sparkle, clamp, seg, ease, TAU, WHITE, hex, scale, mix } 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,+ desc: "Two party poppers bang one after the other: paper bits and curly streamers burst out, stall, then tumble and flutter down, flipping, and settle on the floor.",+ tags: ["ui", "celebration", "confetti", "party", "reward", "one-shot"],+ size: [200, 140],+ origin: [100, 126],+ duration: 3.4,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 },+ bg: "ground",+ options: { palette: ["#ff4a5a", "#ff9a2a", "#ffe03c", "#5ad84a", "#3cc8ff", "#7a6cff", "#f53cd1"], seed: 11 },};-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));+const POPPERS = [+ { x: -74, y: -1, a: -Math.PI / 2 + 0.62, t: 0.1 },+ { x: 74, y: -1, a: -Math.PI / 2 - 0.62, t: 0.26 },+];+const INK = hex("#141019");++// a party popper: a striped cone pointing along a, kicked back k px when it fires+function popper(p, x, y, a, k, C, alpha) {+ const ca = Math.cos(a), sa = Math.sin(a), bx = x - ca * k, by = y - sa * k;+ p.shade(bx - 12, by - 12, bx + 12, by + 12, (px, py, o) => {+ const dx = px - bx, dy = py - by, u = dx * ca + dy * sa, v = -dx * sa + dy * ca;+ // u along the cone (0 at its tip on the floor, 11 at its mouth), v across+ if (u < 0 || u > 11) return;+ const hw = 0.8 + u * 0.32;+ if (Math.abs(v) > hw + 0.6) return;+ o.a = alpha;+ if (Math.abs(v) > hw - 0.4 || u > 10.2 || u < 0.8) return INK;+ const stripe = Math.floor((u + v * 0.6) / 2.2) % 2 === 0;+ return stripe ? (v < 0 ? C[2] : scale(C[2], 0.75)) : v < 0 ? WHITE : hex("#c8c0d8");+ });+}++export function create(o) {+ const C = fit(o.palette, 7), R = new Rng(o.seed);+ const ps = new Particles({ rng: R, ground: () => 0, sparks: ["#ffffff", "#fff3a6", "#ffc23d", "#ff8a2a"] }), lights = new Lights();+ const bits = [], ribbons = [], fired = [false, false], end = meta.duration - 0.05;+ const kick = (t, pp) => (t < pp.t ? 0 : 3 * Math.exp(-(t - pp.t) * 14));++ function fire(pp) {+ const mx = pp.x + Math.cos(pp.a) * 11, my = pp.y + Math.sin(pp.a) * 11;+ lights.add(mx, my, 34, WHITE, 0.6, 0.12);+ lights.add(mx, my, 50, C[2], 0.4, 0.4);+ for (let i = 0; i < 6; i++) ps.spawn(P.SMOKE, mx, my, Math.cos(pp.a) * R.range(20, 60) + R.range(-10, 10), Math.sin(pp.a) * R.range(20, 60), R.range(0.6, 1), hex("#5d5660"), R.range(2.5, 4));+ for (let i = 0; i < 12; i++) {+ const an = pp.a + R.range(-0.5, 0.5), sp = R.range(120, 260);+ ps.spawn(P.SPARK, mx, my, Math.cos(an) * sp, Math.sin(an) * sp, R.range(0.1, 0.25));+ }+ // paper: thrown hard up the cone, the air soon stalls it+ for (let i = 0; i < 46; i++) {+ const an = pp.a + R.range(-0.38, 0.38), sp = R.range(200, 380);+ bits.push({ x: mx, y: my, vx: Math.cos(an) * sp, vy: Math.sin(an) * sp, c: R.pick(C), w: R.range(2, 3), h: R.range(3, 4.6), ang: R.range(0, TAU), spin: R.range(-14, 14), flip: R.range(0, TAU), fs: R.range(5, 13), ph: R.range(0, TAU), amp: R.range(5, 12), fw: R.range(2, 3.4), x0: 0, mode: 0, rest: 0, fall: R.range(26, 40) });+ }+ // streamers: a head that flies like the paper, a tail that follows it and curls+ for (let i = 0; i < 4; i++) {+ const an = pp.a + R.range(-0.25, 0.25), sp = R.range(220, 330), n = 11;+ ribbons.push({ pts: Array.from({ length: n }, () => [mx, my]), vx: Math.cos(an) * sp, vy: Math.sin(an) * sp, c: R.pick(C), ph: R.range(0, TAU), amp: R.range(6, 12), fw: R.range(1.5, 2.4), mode: 0, x0: 0, curl: R.range(0.7, 1.1), fall: R.range(22, 32) });}- 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);- });}++ let t = 0;+ return {+ update(dt) {+ t += dt;+ POPPERS.forEach((pp, i) => !fired[i] && t >= pp.t && ((fired[i] = true), fire(pp)));+ for (const b of bits) {+ if (b.mode === 2) {+ b.rest += dt;+ continue;+ }+ b.flip += b.fs * dt;+ if (b.mode === 0) {+ // the burst: heavy drag, a little gravity, tumbling fast; once slow it starts to flutter+ b.vx -= b.vx * 3.4 * dt;+ b.vy -= b.vy * 3.4 * dt - 140 * dt;+ b.x += b.vx * dt;+ b.y += b.vy * dt;+ b.ang += b.spin * dt;+ if (Math.hypot(b.vx, b.vy) < 40) (b.mode = 1), (b.x0 = b.x - Math.sin(b.ph) * b.amp);+ } else {+ b.ph += b.fw * dt;+ b.x0 += b.vx * dt;+ b.vx -= b.vx * 2 * dt;+ b.x = b.x0 + Math.sin(b.ph) * b.amp;+ b.y += b.fall * (0.4 + 0.9 * Math.abs(Math.cos(b.ph))) * dt;+ b.ang = Math.cos(b.ph) * 0.9;+ if (b.y >= -1) (b.y = -0.5), (b.mode = 2), (b.ang = R.range(-0.3, 0.3)), (b.flip = 0);+ }+ }+ for (const r of ribbons) {+ const h = r.pts[0];+ if (r.mode === 0) {+ r.vx -= r.vx * 3 * dt;+ r.vy -= r.vy * 3 * dt - 120 * dt;+ h[0] += r.vx * dt;+ h[1] += r.vy * dt;+ if (Math.hypot(r.vx, r.vy) < 35) (r.mode = 1), (r.x0 = h[0] - Math.sin(r.ph) * r.amp);+ } else if (h[1] < -1) {+ r.ph += r.fw * dt;+ r.x0 += r.vx * dt;+ r.vx -= r.vx * 2 * dt;+ h[0] = r.x0 + Math.sin(r.ph) * r.amp;+ h[1] += r.fall * (0.5 + 0.7 * Math.abs(Math.cos(r.ph))) * dt;+ }+ // the tail follows the head link by link and hangs a little+ for (let i = 1; i < r.pts.length; i++) {+ const a = r.pts[i - 1], b = r.pts[i];+ b[1] = Math.min(-0.5, b[1] + 20 * dt);+ const dx = b[0] - a[0], dy = b[1] - a[1], d = Math.hypot(dx, dy) || 1;+ if (d > 2.6) (b[0] = a[0] + (dx / d) * 2.6), (b[1] = a[1] + (dy / d) * 2.6);+ }+ }+ ps.update(dt);+ lights.update(dt);+ },++ drawBack(p) {+ ps.draw(p, "back");+ },++ draw(p) {+ const fade = 1 - seg(t, end - 0.45, end - 0.05);+ for (const pp of POPPERS) {+ const k = kick(t, pp);+ popper(p, pp.x, pp.y, pp.a, k, C, 1 - seg(t, 2.5, 2.9));+ const ft = t - pp.t;+ if (ft > 0 && ft < 0.12) sparkle(p, pp.x + Math.cos(pp.a) * 13, pp.y + Math.sin(pp.a) * 13, 7 * (1 - ft / 0.12), WHITE, C[2], 0.7);+ }+ // streamers: a two-tone ribbon that curls along its length+ for (const r of ribbons) {+ const pts = r.pts.map(([x, y], i) => [x + Math.sin(i * r.curl + t * 9 + r.ph) * (i ? 1.6 : 0), y]);+ for (let i = 1; i < pts.length; i++) {+ const [x0, y0] = pts[i - 1], [x1, y1] = pts[i], front = Math.sin(i * r.curl + t * 9 + r.ph) > 0;+ p.line(x0, y0, x1, y1, front ? r.c : scale(r.c, 0.6), fade);+ p.line(x0 + 1, y0, x1 + 1, y1, front ? mix(r.c, WHITE, 0.35) : scale(r.c, 0.45), fade);+ }+ }+ // paper bits: a little card turned by its tilt, its width by its flip; the back side shows darker+ for (const b of bits) {+ if (b.y > 1) continue;+ const fw = b.mode === 2 ? 1 : Math.cos(b.flip), w = Math.max(0.5, Math.abs(fw) * b.w), ca = Math.cos(b.ang), sa = Math.sin(b.ang);+ const c = fw >= 0 ? b.c : scale(b.c, 0.62), a = fade;+ if (b.mode === 2) {+ p.dot(b.x, b.y, scale(b.c, 0.8), a);+ p.dot(b.x + 1, b.y, scale(b.c, 0.6), a);+ continue;+ }+ p.shade(b.x - 4, b.y - 4, b.x + 4, b.y + 4, (x, y, out) => {+ const dx = x - b.x, dy = y - b.y, u = dx * ca + dy * sa, v = -dx * sa + dy * ca;+ if (Math.abs(u) > w / 2 + 0.2 || Math.abs(v) > b.h / 2) return;+ out.a = a;+ return Math.abs(fw) > 0.92 && v < -b.h / 2 + 1 ? WHITE : c;+ });+ // it catches the light as it turns face-on+ if (Math.abs(fw) > 0.97) p.glow(b.x, b.y, 5, mix(b.c, WHITE, 0.5), 0.35 * fade);+ }+ ps.draw(p, "front");+ lights.draw(p);+ },+ };}diff --git a/src/fx/ui/countdown.js b/src/fx/ui/countdown.jsindex ed4f0bf..6cb827c 100644--- a/src/fx/ui/countdown.js+++ b/src/fx/ui/countdown.js@@ -1,58 +1,176 @@-import { PAL, burst, seg, ease, TAU, WHITE } from "../../core/index.js";-import { boldText, shake, fit } from "./_lib.js";+import { Particles, Lights, P, Rng, fit, sparkle, clamp, seg, smooth, ease, TAU, WHITE, scale } from "../../core/index.js";+import { spell, drawWord, shake } 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.",+ desc: "3, 2, 1 slam into a timer ring that drains like a burning fuse, throwing sparks; then GO! bursts out as the ring blows into a shockwave with rays.",tags: ["ui", "countdown", "start", "timer", "text", "one-shot"],- size: [76, 60],- origin: [38, 30],- duration: 2.5,+ size: [152, 136],+ origin: [76, 68],+ duration: 3.1,loop: false,fps: 30,bg: "dark",- options: { palette: PAL.volt, from: 3, go: "GO!", seed: 5 },+ options: {+ palette: ["#0a1030", "#142a66", "#1f4fae", "#2f86e6", "#5cc4ff", "#a8e8ff", "#e6fbff", "#ffffff"],+ go: ["#0b2410", "#16501c", "#22882a", "#3cc23a", "#7ee84c", "#c4ff8a", "#f0ffd6", "#ffffff"],+ from: 3,+ word: "GO!",+ seed: 5,+ },};-const STEP = 0.55;+const STEP = 0.62, R = 30, TOP = -Math.PI / 2;-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;+// the timer: a dark socket, ticks round it, and the lit arc from the burning head round to the top+function timer(p, C, x, y, f, flash, t) {+ p.ring(x, y, R + 4, 8, (v) => (v < 0.13 || v > 0.87 ? C[0] : C[1]));+ // a fine dotted dial inside the track, turning+ for (let j = 0; j < 40; j++) {+ const an = (j / 40) * TAU + t * 0.6;+ p.dot(x + Math.cos(an) * (R - 6), y + Math.sin(an) * (R - 6), j % 5 ? C[2] : C[4], 1);}- // 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 head = TOP + TAU * (1 - f);+ for (let i = 0; i < 12; i++) {+ const an = TOP + (i * TAU) / 12, lit = an >= head - 1e-6 || f >= 0.999, near = Math.abs(an - head) < 0.2 && f < 0.999;+ const ca = Math.cos(an), sa = Math.sin(an);+ p.line(x + ca * (R + 6), y + sa * (R + 6), x + ca * (R + 8), y + sa * (R + 8), flash || near ? WHITE : lit ? C[5] : C[2]);+ }+ if (f <= 0.002) return head;+ p.arc(x, y, R + 2, 5, head, TOP + TAU, (u, v) => {+ const d = u * TAU * f;+ if (flash || d < 0.1) return WHITE;+ if (d < 0.32) return v > 0.5 ? WHITE : C[6];+ return v > 0.75 ? C[6] : v > 0.4 ? C[5] : v > 0.15 ? C[4] : C[3];});- 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);+ // light runs round the lit arc, hottest at the head+ for (let an = head + 0.25; an < TOP + TAU; an += 0.55) p.glow(x + Math.cos(an) * (R - 0.5), y + Math.sin(an) * (R - 0.5), 9, C[4], 0.12);+ const hx = x + Math.cos(head) * (R - 0.5), hy = y + Math.sin(head) * (R - 0.5);+ p.glow(hx, hy, 14, C[5], 0.5);+ if (!flash) sparkle(p, hx, hy, 2 + 1.5 * (0.5 + 0.5 * Math.sin(t * 40)), C[6], C[5], 0.4);+ return head;+}++export function create(o) {+ const C = fit(o.palette, 8), G = fit(o.go, 8), Rg = new Rng(o.seed), n = clamp(Math.round(o.from), 1, 3);+ const ps = new Particles({ rng: Rg, sparks: [C[7], C[6], C[5], C[3]] }), gs = new Particles({ rng: Rg, sparks: [G[7], G[6], G[5], G[3]] });+ const lights = new Lights(), GO = n * STEP, OUT = GO + 0.78, end = meta.duration - 0.05;+ const digits = Array.from({ length: n }, (_, i) => spell(String(n - i))), word = spell(o.word);+ const rays = Array.from({ length: 18 }, (_, i) => ({ a: (i / 18) * TAU + Rg.range(-0.06, 0.06), L: i % 2 ? Rg.range(10, 16) : Rg.range(22, 30) }));+ const sizeAt = (u, base, big) => base + big * Math.exp(-u * 26) * Math.cos(u * 38);+ const reach = (v, d) => (v <= d * 2.2 ? 9 : -Math.log(1 - (d * 2.2) / v) / 2.2);+ let t = 0, beat = -1, went = false, popped = false;++ return {+ update(dt) {+ t += dt;+ const i = Math.floor(t / STEP);+ // each number slams in: the ring refills white and throws a ring of sparks+ if (t < GO && i !== beat) {+ beat = i;+ lights.add(0, 0, 54, C[5], 0.6, 0.35);+ for (let j = 0; j < 14; j++) {+ const an = (j / 14) * TAU + Rg.range(-0.1, 0.1), sp = Rg.range(90, 200);+ ps.spawn(P.SPARK, Math.cos(an) * (R + 2), Math.sin(an) * (R + 2), Math.cos(an) * sp, Math.sin(an) * sp, Math.min(Rg.range(0.12, 0.3), reach(sp, 26)));+ }+ }+ // the burning head of the arc spits sparks as it runs+ if (t < GO) {+ const k = (t % STEP) / STEP, f = 1 - seg(k, 0.06, 0.97), head = TOP + TAU * (1 - f);+ if (f > 0.01 && f < 0.99 && Rg.chance(0.7)) {+ const hx = Math.cos(head) * R, hy = Math.sin(head) * R, tx = -Math.sin(head), ty = Math.cos(head), out = Rg.range(-0.4, 1), sp = Rg.range(60, 150);+ ps.spawn(P.SPARK, hx, hy, (-tx * 0.8 + Math.cos(head) * out) * sp, (-ty * 0.8 + Math.sin(head) * out) * sp - 20, Rg.range(0.12, 0.28));+ // and leaves cinders drifting off the burnt-out track behind it+ if (Rg.chance(0.15)) ps.spawn(P.EMBER, hx, hy, Math.cos(head) * Rg.range(5, 20), Math.sin(head) * Rg.range(5, 20), Rg.range(0.4, 0.8), C[5], 1);+ }+ }+ // GO!: the ring blows out, sparks and stars everywhere+ if (!went && t >= GO) {+ went = true;+ lights.add(0, 0, 70, WHITE, 0.9, 0.18);+ lights.add(0, 0, 64, G[5], 0.7, 0.8);+ for (let j = 0; j < 36; j++) {+ const an = Rg.range(0, TAU), sp = Rg.range(120, 300);+ gs.spawn(P.SPARK, Math.cos(an) * R, Math.sin(an) * R, Math.cos(an) * sp, Math.sin(an) * sp - 40, Math.min(Rg.range(0.18, 0.36), reach(sp, 24)));+ }+ for (let j = 0; j < 18; j++) {+ const an = Rg.range(0, TAU), sp = Rg.range(30, 80), r = Rg.range(10, 28);+ gs.spawn(P.STAR, Math.cos(an) * r, Math.sin(an) * r, Math.cos(an) * sp, Math.sin(an) * sp - 10, Rg.range(0.5, 1), Rg.pick([G[7], G[6], G[5]]), Rg.chance(0.4) ? Rg.range(1.5, 2.5) : 0.6);+ }+ }+ // it twinkles while it holds+ if (t > GO + 0.2 && t < OUT - 0.1 && Rg.chance(0.12)) {+ const an = Rg.range(0, TAU), r = Rg.range(30, 46);+ gs.spawn(P.STAR, Math.cos(an) * r, Math.sin(an) * r * 0.8, 0, -Rg.range(4, 12), Rg.range(0.3, 0.6), Rg.pick([G[7], G[6]]), Rg.chance(0.3) ? 1.6 : 0.6);+ }+ if (!popped && t >= OUT + 0.05) {+ popped = true;+ lights.add(0, 0, 40, G[6], 0.6, 0.25);+ for (let j = 0; j < 14; j++) {+ const an = (j / 14) * TAU + Rg.range(-0.15, 0.15), sp = Rg.range(60, 130);+ gs.spawn(P.STAR, Math.cos(an) * 12, Math.sin(an) * 8, Math.cos(an) * sp, Math.sin(an) * sp * 0.8 - 10, Math.min(Rg.range(0.3, 0.45), end - t), Rg.pick([G[7], G[6], G[5]]), j % 3 ? 0.6 : Rg.range(1.3, 2));+ }+ }+ ps.update(dt);+ gs.update(dt);+ lights.update(dt);+ },++ draw(p) {+ if (t < GO) {+ const i = Math.floor(t / STEP), u = t - i * STEP, k = u / STEP;+ const [sx, sy] = shake(t, 3, i * STEP, 0.22, o.seed + i);+ const f = 1 - seg(k, 0.06, 0.97), flash = u < 0.07;+ // a shock ring off each slam+ const rk = u / 0.3;+ if (rk < 1) p.ring(sx, sy, R + 6 + 22 * ease.outCubic(rk), 1.5 * (1 - rk) + 1, rk < 0.3 ? WHITE : C[5], 1.3 * (1 - rk));+ timer(p, C, sx, sy, f, flash, t);+ // the slam's white-hot frame fills the ring+ if (u < 0.035) p.circle(sx, sy, R - 3, WHITE);+ else if (u < 0.07) p.ring(sx, sy, R - 3, 3, C[6]);+ // the number: huge and white for a frame, then a stiff spring down to size+ const s = sizeAt(u, 5, 2), d = digits[i], W = d.w * s, H = 7 * s, x0 = sx - W / 2, y0 = sy - H / 2;+ const items = d.letters.filter((L) => L.g).map((L) => ({ g: L.g, x: x0 + L.x * s, y: y0, sx: s, sy: s, flash: u < 0.035 ? 1 : u < 0.07 ? 0.4 : 0 }));+ drawWord(p, items, { fill: [C[4], C[5], C[6], C[7]], edge: WHITE, under: C[3], outline: C[0], ow: 2, shadow: scale(C[0], 0.5) });+ p.glow(sx, sy, 30, C[4], 0.22 + (u < 0.12 ? 0.6 * (1 - u / 0.12) : 0));+ p.glow(sx, sy, R + 8, C[3], 0.2 * (1 - k) + 0.08);+ } else {+ const u = t - GO, [sx, sy] = shake(t, 4, GO, 0.3, o.seed + 9);+ // the ring blows out into a shockwave+ const bk = u / 0.4;+ if (bk < 1) {+ const r = R + 4 + 30 * ease.outCubic(bk), w = Math.max(1, 7 * (1 - bk));+ p.ring(0, 0, r, w, (v) => (bk < 0.2 || v > 0.6 ? WHITE : G[6]), 1.4 * (1 - bk));+ p.glowRing(0, 0, r - w / 2, 8, G[5], 0.5 * (1 - bk));+ }+ const ik = (u - 0.05) / 0.3;+ if (ik > 0 && ik < 1) p.ring(0, 0, R + 22 * ease.outCubic(ik), 1, G[5], 1.2 * (1 - ik));+ // rays: shoot out from just outside the word, turn slowly, draw back in+ const rk = ease.outExpo(clamp(u / 0.18)) * (1 - ease.inQuad(seg(t, OUT - 0.25, OUT + 0.05)));+ for (const ry of rays) {+ if (rk <= 0.02) break;+ const an = ry.a + u * 0.35, ca = Math.cos(an), sa = Math.sin(an), r0 = 1 / Math.sqrt((ca / 40) ** 2 + (sa / 23) ** 2) + 3 * rk, r1 = r0 + ry.L * 0.7 * rk;+ p.line(ca * r0, sa * r0, ca * r1, sa * r1, (q) => (q < 0.3 ? WHITE : q < 0.65 ? G[6] : G[5]), (q) => (q < 0.6 ? 1.3 : (1.3 * (1 - q)) / 0.4));+ }+ // GO!: slams in bigger than the numbers, throbs while it holds, then pops+ const pu = (t - OUT) / 0.06;+ if (pu < 1) {+ let s = sizeAt(u, 5, 3.5), flash = u < 0.035 ? 1 : u < 0.07 ? 0.4 : 0;+ const throb = Math.max(0, Math.sin((u - 0.25) * 9)) * smooth(0.25, 0.35, u);+ if (pu > 0) (s = 5 * (1 + 0.25 * pu)), (flash = 1);+ const W = word.w * s, H = 7 * s, x0 = sx - W / 2, y0 = sy - H / 2;+ const items = word.letters.filter((L) => L.g).map((L) => ({ g: L.g, x: x0 + L.x * s, y: y0, sx: s, sy: s, slant: 1, flash }));+ const sh = seg(u, 0.32, 0.56), shine = sh > 0 && sh < 1 ? x0 - 8 + (W + 22) * ease.inOutSine(sh) : null;+ drawWord(p, items, { fill: [G[4], G[5], G[6], G[7]], edge: WHITE, under: G[3], outline: G[0], ow: 2, shadow: scale(G[0], 0.5), shine, shineY: y0, glint: G[6] });+ p.glow(sx, sy, 46, G[5], 0.25 + 0.15 * throb + (u < 0.12 ? 0.7 * (1 - u / 0.12) : 0));+ } else {+ const k = (t - OUT - 0.06) / 0.22;+ if (k > 0 && k < 1) p.ring(0, 0, 8 + 26 * ease.outCubic(k), 1, k < 0.4 ? WHITE : G[6], 1.3 * (1 - k));+ }+ }+ ps.draw(p);+ gs.draw(p);+ lights.draw(p);+ },+ };}diff --git a/src/fx/ui/crit-number.js b/src/fx/ui/crit-number.jsindex 589e0b5..4c6978b 100644--- a/src/fx/ui/crit-number.js+++ b/src/fx/ui/crit-number.js@@ -1,52 +1,197 @@-import { PAL, burst, seg, ease, rng, star, TAU, WHITE } from "../../core/index.js";-import { boldText, shake, fit } from "./_lib.js";+import { Particles, Bits, Lights, P, B, Rng, fit, sparkle, clamp, seg, smooth, ease, rand, TAU, WHITE, scale } from "../../core/index.js";+import { spell, drawWord, shake } 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.",+ desc: "CRIT 128! slams in huge and white over a jagged starburst with a hard shake and speed lines, cools to fire, holds with a shine, then pops into sparks.",tags: ["ui", "critical", "damage", "number", "combat", "text", "one-shot"],- size: [88, 70],- origin: [44, 38],- duration: 1.2,+ size: [152, 120],+ origin: [76, 60],+ duration: 1.5,loop: false,fps: 30,bg: "dark",- options: { palette: PAL.fire, text: "128!", label: "CRIT", seed: 3 },+ options: { palette: ["#2a0710", "#5e0f16", "#a3191c", "#e0401c", "#ff7b22", "#ffb93b", "#ffe68a", "#ffffff"], 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]);+const FOLD = 0.92, TAGOUT = 0.98, POP = 1.06, SX = 1.3, NS = 4, NY = 5;++// the jagged starburst: a spiky polygon with a dark rim, a bright inner contour, bands that cool from the+// white-hot middle out, and spokes of light running to every tip. heat 1 is white all through.+function starburst(p, C, cx, cy, R, rot, tips, heat, boil, a = 1) {+ if (R < 2 || a <= 0) return;+ const n = tips.length, V = [];+ for (let i = 0; i < n * 2; i++) {+ const an = rot + (i * Math.PI) / n, r = R * (i % 2 ? 0.6 + tips[i >> 1].dip : tips[i >> 1].len * (1 + 0.14 * (rand(boil, i) - 0.5)));+ V.push([Math.cos(an) * r, Math.sin(an) * r, an]);}- // 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]);+ const step = Math.PI / n;+ const edge = (dx, dy) => {+ // where the ray from the middle through (dx, dy) leaves the polygon: the vertices sit at even angles, so+ // the ray's angle names the one edge it can cross+ let a = Math.atan2(dy, dx) - rot;+ a -= Math.floor(a / TAU) * TAU;+ const i = Math.min(V.length - 1, Math.floor(a / step)), [x0, y0] = V[i], [x1, y1] = V[(i + 1) % V.length];+ const ex = x1 - x0, ey = y1 - y0, den = dx * ey - dy * ex;+ return Math.abs(den) < 1e-9 ? Math.hypot(x0, y0) : (x0 * ey - y0 * ex) / den;+ };+ const M = R * 1.15 + 2;+ p.shade(cx - M * SX, cy - M, cx + M * SX, cy + M, (x, y, o) => {+ const dx = (x - cx) / SX, dy = y - cy, d = Math.hypot(dx, dy);+ if (d < 0.01) return WHITE;+ const L = edge(dx / d, dy / d), gap = (L - d) * (1 + 0.3 * Math.abs(dx / d)), q = d / L;+ if (gap < 0) return;+ o.a = a;+ if (heat > 0.85) return gap < 1 ? C[6] : WHITE;+ // a dark edge, a glowing rim inside it, then a middle that deepens to dark red for the number to stand on+ if (gap < 1) return C[1];+ if (gap < 2.2) return heat > 0.3 ? WHITE : C[6];+ if (gap < 3.4) return heat > 0.3 ? C[6] : C[5];+ if (gap >= 6 && gap < 7) return heat > 0.5 ? WHITE : C[4];+ // spokes: a line of light from the middle out to each tip+ const an = Math.atan2(dy, dx) - rot, sp = Math.abs(((an / TAU) * n + 0.5) % 1 - 0.5) * (TAU / n) * d;+ if (sp < 0.6 && q > 0.25) return heat > 0.5 ? WHITE : q > 0.6 ? C[5] : C[4];+ const i = Math.round((q > 0.72 ? 3 : q > 0.45 ? 4 : 5) - heat * 5);+ return i <= 0 ? WHITE : [WHITE, C[6], C[5], C[4], C[3], C[2]][i];});- 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] });+}++// the CRIT tag: a leaning dark plate with a lit top edge+function tag(p, C, x, y, w, h, lean) {+ p.shade(x - 1, y - 1, x + w + lean + 1, y + h + 1, (px, py) => {+ const lx = px - x - lean * ((y + h - py) / h);+ if (py < y || py > y + h || lx < 0 || lx > w) return;+ if (lx < 1 || lx > w - 1 || py < y + 1 || py > y + h - 1) return C[0];+ return py < y + 2 ? C[4] : py < y + h * 0.55 ? C[3] : C[2];+ });+}++// speed lines thrown out round the burst+function speedLines(p, C, t, lines) {+ const k = t / 0.24;+ if (k <= 0 || k >= 1) return;+ for (const l of lines) {+ const r0 = l.r * (1 + 0.5 * ease.outExpo(k)), r1 = r0 + l.len * (1 - k) + 2, ca = Math.cos(l.a) * 1.2, sa = Math.sin(l.a) * 0.92;+ p.line(ca * r0, sa * r0, ca * r1, sa * r1, (u) => (u > 0.5 || k < 0.3 ? WHITE : C[6]));}- p.glow(sx, sy, 36, C[5], 0.5 * (1 - seg(t, 0, 0.5)) + 0.12);+}++export function create(o) {+ const C = fit(o.palette, 8), R = new Rng(o.seed), SHADOW = scale(C[0], 0.5);+ const ps = new Particles({ rng: R, sparks: [C[7], C[6], C[5], C[3]] }), bits = new Bits(), lights = new Lights();+ const num = spell(o.text), lab = spell(o.label, "mini");+ const tips = Array.from({ length: 13 }, () => ({ len: R.range(0.86, 1.12), dip: R.range(-0.06, 0.06) }));+ const lines = Array.from({ length: 18 }, (_, i) => ({ a: (i / 18) * TAU + R.range(-0.1, 0.1), r: R.range(31, 34), len: R.range(8, 15) }));+ // how long a spark launched at v px/s may live before its drag carries it d px (so none leaves the canvas)+ const reach = (v, d) => (v <= d * 2.2 ? 9 : -Math.log(1 - (d * 2.2) / v) / 2.2);+ const end = meta.duration - 0.05;+ let t = 0, slammed = false, stamped = false, popped = false, tagGone = false;+ const spawnStar = (x, y, vx, vy, life, c, size) => ps.spawn(P.STAR, x, y, vx, vy, Math.min(life, end - t), c, size);++ // the number's size: huge for the first frame, then a stiff spring down to 3 px a pixel+ const sizeAt = (t) => NS + 3 * Math.exp(-t * 26) * Math.cos(t * 38);+ return {+ update(dt) {+ t += dt;+ if (!slammed) {+ slammed = true;+ lights.add(0, 0, 70, WHITE, 0.9, 0.16);+ lights.add(0, 0, 60, C[4], 0.45, 0.5);+ for (let i = 0; i < 30; i++) {+ const an = R.range(0, TAU), sp = R.range(140, 300);+ ps.spawn(P.SPARK, Math.cos(an) * 8, Math.sin(an) * 6, Math.cos(an) * sp * 1.15, Math.sin(an) * sp - 40, Math.min(R.range(0.12, 0.32), reach(sp * 1.15, 40)));+ }+ for (let i = 0; i < 10; i++) {+ const an = R.range(0, TAU), sp = R.range(90, 170);+ bits.add({ kind: B.SHARD, x: Math.cos(an) * 10, y: Math.sin(an) * 7, vx: Math.cos(an) * sp * 1.15, vy: Math.sin(an) * sp - 60, g: 0.35, drag: 1.6, life: Math.min(R.range(0.3, 0.5), end - t), a: R.range(0, TAU), va: R.range(-24, 24), s: R.range(2, 3.5), c: R.pick([C[7], C[6], C[5]]) });+ }+ }+ // the label stamps down a beat later+ if (!stamped && t >= 0.09) {+ stamped = true;+ lights.add(-4, -20, 30, C[6], 0.5, 0.2);+ for (let i = 0; i < 6; i++) ps.spawn(P.STAR, -4 + R.range(-16, 16), -20 + R.range(-4, 4), R.range(-40, 40), R.range(-30, 10), R.range(0.2, 0.4), C[6], R.range(0.5, 1.4));+ }+ // the tag bursts into sparkles as it goes+ if (!tagGone && t >= TAGOUT) {+ tagGone = true;+ for (let i = 0; i < 6; i++) spawnStar(-10 + R.range(-16, 16), -14 + R.range(-5, 5), R.range(-50, 50), -R.range(10, 60), R.range(0.25, 0.4), R.pick([C[7], C[6]]), i ? 0.6 : 1.6);+ }+ // the burst crackles: sparks spit from its tips+ if (t > 0.3 && t < FOLD - 0.1 && R.chance(0.07)) {+ const an = R.range(0, TAU), sp = R.range(70, 150);+ ps.spawn(P.SPARK, Math.cos(an) * 30 * SX, Math.sin(an) * 30, Math.cos(an) * sp, Math.sin(an) * sp - 30, Math.min(R.range(0.12, 0.26), reach(sp, 14)));+ }+ // embers lift off the burst while it holds+ if (t > 0.12 && t < FOLD && R.chance(0.16)) {+ const an = R.range(0, TAU), r = R.range(14, 28);+ ps.spawn(P.EMBER, Math.cos(an) * r * SX, Math.sin(an) * r, R.range(-10, 10), -R.range(15, 40), Math.min(R.range(0.5, 0.9), end - t), C[5], R.range(1, 2));+ }+ if (!popped && t >= POP + 0.05) {+ popped = true;+ lights.add(0, 0, 44, C[6], 0.7, 0.25);+ for (let i = 0; i < 14; i++) {+ const an = (i / 14) * TAU + R.range(-0.15, 0.15), sp = R.range(60, 130);+ ps.spawn(P.STAR, Math.cos(an) * 10 * SX, Math.sin(an) * 7, Math.cos(an) * sp * SX, Math.sin(an) * sp - 10, Math.min(R.range(0.3, 0.42), end - t), R.pick([C[7], C[6], C[5]]), i % 3 ? 0.6 : R.range(1.3, 2.2));+ }+ for (let i = 0; i < 8; i++) {+ const an = R.range(0, TAU), sp = R.range(120, 240);+ ps.spawn(P.SPARK, Math.cos(an) * 6, Math.sin(an) * 4, Math.cos(an) * sp, Math.sin(an) * sp - 30, Math.min(R.range(0.15, 0.3), end - t, reach(sp, 40)));+ }+ }+ ps.update(dt);+ bits.update(dt);+ lights.update(dt);+ },++ draw(p) {+ const [sx, sy] = shake(t, 4, 0, 0.32, o.seed), [lx, ly] = shake(t, 2, 0.09, 0.15, o.seed + 3);+ // the burst: white on the slam, cooling; it breathes while it holds, then folds away+ const grow = t < 0.04 ? 1.25 : 1 + 0.1 * Math.exp(-(t - 0.04) * 14), fold = 1 - ease.inBack(seg(t, FOLD - 0.12, FOLD), 2.4);+ const heat = t < 0.035 ? 1 : clamp(1 - (t - 0.035) / 0.12), breathe = 1 + 0.04 * Math.sin(t * 16);+ // it boils: the spikes re-roll a little every few frames+ if (fold > 0.02) starburst(p, C, sx, sy, 31 * grow * fold * breathe, -Math.PI / 2 + 0.25 * t, tips, heat, t < 0.2 ? 0 : Math.floor(t * 10));+ speedLines(p, C, t, lines);+ // the ring the slam throws out+ const rk = t / 0.26;+ const rr = 30 + 22 * ease.outCubic(rk);+ if (rk > 0 && rk < 1) p.ellipse(0, 0, rr * SX, rr, rk < 0.35 ? WHITE : C[6], (d) => (d > 1 - 1.6 / rr ? 1.2 - rk : 0));+ bits.draw(p);+ ps.draw(p);+ // the number: slams in huge and white, settles with a spring; a shine runs over it; it pops at the end+ let s = sizeAt(t), sxN = s, syN = s, flash = t < 0.035 ? 1 : t < 0.07 ? 0.5 : 0;+ const pu = (t - POP) / 0.05;+ if (pu >= 1) {+ // gone: a ring where it was+ const k = (t - POP - 0.05) / 0.22;+ if (k > 0 && k < 1) p.ellipse(0, 0, (6 + 22 * ease.outCubic(k)) * SX, 6 + 22 * ease.outCubic(k), k < 0.4 ? WHITE : C[6], (d) => (d > 1 - 1.5 / (6 + 22 * ease.outCubic(k)) ? 1.3 - k : 0));+ } else {+ const sq = seg(t, POP - 0.07, POP);+ if (sq > 0 && pu <= 0) (sxN = NS * (1 + 0.14 * sq)), (syN = NS * (1 - 0.12 * sq));+ if (pu > 0) (sxN = syN = NS * (1 + 0.25 * pu)), (flash = 1);+ const W = num.w * sxN, H = 7 * syN, x0 = sx - W / 2 - 3, y0 = sy + NY - H / 2 - 3 * smooth(0.15, FOLD, t);+ const items = num.letters.filter((L) => L.g).map((L) => ({ g: L.g, x: x0 + L.x * sxN, y: y0, sx: sxN, sy: syN, slant: 1, flash }));+ const sh = seg(t, 0.36, 0.6), shine = sh > 0 && sh < 1 ? x0 - 10 + (W + 26) * ease.inOutSine(sh) : null;+ drawWord(p, items, { fill: [C[5], C[6], C[6], C[7]], edge: WHITE, under: C[4], outline: C[0], ow: 2, shadow: SHADOW, shine, shineY: y0, glint: C[5] });+ if (shine !== null && shine > x0 && shine < x0 + W) p.glowLine(shine, y0, shine + 0.6 * H, y0 + H, 8, C[6], 0.3);+ // the label stamps down on top, a size too big for a frame+ const lk = t - 0.06, lo = seg(t, TAGOUT - 0.05, TAGOUT);+ if (lk > 0 && t < TAGOUT) {+ const ls = lk < 0.035 ? 3 : lk < 0.07 ? 1.8 : 2 * (1 + 0.15 * lo), LW = lab.w * ls, lh = 5 * ls, lxo = sx + lx - 8 - LW / 2, lyo = y0 - 3 - lh + ly - 2 * lo;+ if (lo > 0.5) tag(p, { 0: WHITE, 2: WHITE, 3: WHITE, 4: WHITE }, lxo - 4, lyo - 3, LW + 8, lh + 5, 3);+ else tag(p, C, lxo - 4, lyo - 3, LW + 8, lh + 5, 3);+ const lit = lab.letters.filter((L) => L.g).map((L) => ({ g: L.g, x: lxo + 1 + L.x * ls, y: lyo, sx: ls, sy: ls, slant: 0.5, flash: lk < 0.035 ? 1 : 0 }));+ drawWord(p, lit, { fill: [C[6], C[7], C[7]], edge: WHITE, under: C[5], outline: 0, shadow: C[1] });+ }+ // a glint on the number's corner after the shine+ const g = (t - 0.6) / 0.24;+ if (g > 0 && g < 1) sparkle(p, x0 + W - 2, y0 + 1, 6 * Math.sin(g * Math.PI), C[6], C[5], 0.6);+ }+ // light: the white flash of the slam, then a hot glow that pulses while it holds+ const hold = smooth(0, 0.1, t) * (1 - smooth(FOLD - 0.1, POP + 0.1, t));+ p.glow(sx, sy, 56, C[4], 0.14 * hold * (1 + 0.2 * Math.sin(t * 16)));+ if (t < 0.12) p.glow(0, 0, 64, WHITE, 0.8 * (1 - t / 0.12));+ lights.draw(p);+ },+ };}diff --git a/src/fx/ui/damage-number.js b/src/fx/ui/damage-number.jsindex c5f370b..3f02684 100644--- a/src/fx/ui/damage-number.js+++ b/src/fx/ui/damage-number.js@@ -1,28 +1,89 @@-import { PAL, seg, ease, WHITE } from "../../core/index.js";-import { boldText, fit } from "./_lib.js";+import { Particles, Lights, P, Rng, fit, sparkle, clamp, seg, ease, TAU, WHITE, scale } from "../../core/index.js";+import { spell, drawWord } 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,+ desc: "A red -27 punches out of a hit spark, white for a frame, arcs up, lands with a squash and a little hop, then fades as it lifts away.",+ tags: ["ui", "damage", "number", "combat", "text", "hit", "one-shot"],+ size: [76, 68],+ origin: [30, 52],+ duration: 1.05,loop: false,fps: 30,bg: "dark",- options: { palette: PAL.blood, text: "-27", scale: 1, pop: true, seed: 1 },+ options: { palette: ["#1a0508", "#4a0b12", "#8c1420", "#d42a2e", "#ff5a4a", "#ff9a86", "#ffd8cc", "#ffffff"], text: "-27", seed: 2 },};-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);+const LAND = -8, FADE = 0.84;++export function create(o) {+ const C = fit(o.palette, 8), R = new Rng(o.seed), word = spell(o.text);+ const ps = new Particles({ rng: R, sparks: [C[7], C[6], C[4], C[2]] }), lights = new Lights();+ // the number is a little body: thrown up and out, it lands, hops once and settles+ const n = { x: 0, y: LAND, vx: 34, vy: -175, sq: 0, hops: 0 };+ const spikes = Array.from({ length: 9 }, (_, i) => [(i / 9) * TAU + R.range(-0.2, 0.2), R.range(8, 14)]);+ let t = 0, hit = false;+ return {+ update(dt) {+ t += dt;+ if (!hit) {+ hit = true;+ lights.add(0, -4, 30, C[5], 0.7, 0.25);+ lights.add(0, -4, 14, WHITE, 0.6, 0.08);+ for (let i = 0; i < 9; i++) {+ const an = R.range(-Math.PI * 0.95, -0.05) + (i % 2 ? Math.PI * 0.08 : 0), sp = R.range(90, 200);+ ps.spawn(P.SPARK, 0, -4, Math.cos(an) * sp, Math.sin(an) * sp, R.range(0.1, 0.25));+ }+ }+ if (n.hops < 2) {+ n.vy += 900 * dt;+ n.vx -= n.vx * 2 * dt;+ n.x += n.vx * dt;+ n.y += n.vy * dt;+ if (n.y >= LAND && n.vy > 0) {+ n.y = LAND;+ n.sq = 1;+ n.hops++;+ n.vy = n.hops < 2 ? -n.vy * 0.36 : 0;+ if (n.hops === 1) for (const s of [-1, 1]) ps.spawn(P.STAR, n.x + s * 14, LAND + R.range(-2, 1), s * R.range(15, 35), -R.range(5, 20), R.range(0.2, 0.35), C[6], R.range(0.5, 1.2));+ }+ }+ n.sq = Math.max(0, n.sq - dt / 0.09);+ ps.update(dt);+ lights.update(dt);+ },++ draw(p) {+ // the hit: two frames of a spiky white-hot star, then a glint and a ring where the blow landed+ if (t < 0.07) {+ const big = t < 0.035;+ spikes.forEach(([an, L], i) => {+ const l = L * (big ? 1 : 1.3), ca = Math.cos(an), sa = Math.sin(an);+ if (big) {+ // a fat spike: a red rim either side of a white-hot core that narrows to the tip+ p.line(-sa, -4 + ca, ca * l * 0.7 - sa, -4 + sa * l * 0.7 + ca, C[4]);+ p.line(sa, -4 - ca, ca * l * 0.7 + sa, -4 + sa * l * 0.7 - ca, C[4]);+ }+ p.line(ca * (big ? 0 : l * 0.45), -4 + sa * (big ? 0 : l * 0.45), ca * l, -4 + sa * l, big ? WHITE : i % 2 ? C[6] : C[5]);+ });+ if (big) p.circle(0, -4, 3.2, WHITE);+ } else if (t < 0.16) sparkle(p, 0, -4, 5 * (1 - (t - 0.07) / 0.09), WHITE, C[5], 0.6);+ const rk = t / 0.22;+ if (rk < 1) p.ring(0, -4, 3 + 10 * ease.outCubic(rk), Math.max(1, 2 * (1 - rk)), rk < 0.4 ? WHITE : C[5], 1.2 - rk);+ ps.draw(p);+ // the number: punches out big and white, springs to size, squashes as it lands, then lifts and fades+ const out = seg(t, FADE, meta.duration - 0.04);+ if (out < 1) {+ let s = 2 + 1.4 * Math.exp(-t * 22) * Math.cos(t * 30), sx = s, sy = s;+ if (n.sq > 0) (sx = s * (1 + 0.18 * n.sq)), (sy = s * (1 - 0.2 * n.sq));+ else if (n.hops < 2 && Math.abs(n.vy) > 120) (sx = s * 0.92), (sy = s * 1.1);+ const W = word.w * sx, H = 7 * sy, x0 = n.x - W / 2, y0 = n.y - H - 6 * ease.inQuad(out);+ const flash = t < 0.035 ? 1 : t < 0.07 ? 0.4 : 0;+ const items = word.letters.filter((L) => L.g).map((L) => ({ g: L.g, x: x0 + L.x * sx, y: y0, sx, sy, flash, a: 1 - out }));+ drawWord(p, items, { fill: [C[3], C[3], C[4], C[5]], edge: C[6], under: C[2], outline: C[0], shadow: scale(C[0], 0.5) });+ p.glow(n.x, y0 + H / 2, 18, C[4], 0.3 * (1 - out) + (t < 0.1 ? 0.4 * (1 - t / 0.1) : 0));+ }+ lights.draw(p);+ },+ };}diff --git a/src/fx/ui/error-x.js b/src/fx/ui/error-x.jsdeleted file mode 100644index 451cfb4..0000000--- a/src/fx/ui/error-x.js+++ /dev/null@@ -1,50 +0,0 @@-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.jsindex ce61820..fcf5fee 100644--- a/src/fx/ui/exclamation.js+++ b/src/fx/ui/exclamation.js@@ -1,58 +1,107 @@-import { seg, ease, WHITE } from "../../core/index.js";-import { Layer, fit } from "./_lib.js";+import { Particles, Lights, P, Rng, fit, sparkle, clamp, seg, ease, TAU, WHITE } from "../../core/index.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,+ desc: "A bold ! springs up off the hero's head, stretching as it shoots up and squashing as it lands; surprise ticks flick out, it wobbles, then pops away.",+ tags: ["ui", "alert", "surprise", "emote", "character", "one-shot"],+ size: [84, 104],+ origin: [42, 92],+ duration: 1.4,loop: false,fps: 30,bg: "ground",- actor: true,- options: { palette: ["#2a1206", "#6a2a0a", "#c0480e", "#f07818", "#ffb02e", "#ffe070", "#fff8d0", "#ffffff"], seed: 16 },+ actor: 2,+ options: { palette: ["#2a1405", "#6a2e06", "#b85a0a", "#f08c14", "#ffc23a", "#ffe580", "#fff6c8", "#ffffff"], seed: 3 },};-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 },-};+const HEAD = -40, REST = -45, POP = 1.1;-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;+// the mark: a bar that tapers to its foot and a round dot, with a dark outline, lit down its left side,+// turned by a about its foot+function bang(p, C, x, y, sx, sy, a, white) {+ const ca = Math.cos(a), sa = Math.sin(a);+ const hw = (V) => 2.3 + (-V - 10) * 0.09;+ const inBar = (U, V) => V > -24 && V < -9.5 && Math.abs(U) < hw(V);+ const inDot = (U, V) => Math.hypot(U, V + 3.6) < 3.3;+ const inside = (U, V) => inBar(U, V) || inDot(U, V);+ p.shade(x - 16, y - 34, x + 16, y + 6, (px, py) => {+ const dx = px - x, dy = py - y, u = (dx * ca + dy * sa) / sx, v = (-dx * sa + dy * ca) / sy, ex = 1 / sx, ey = 1 / sy;+ if (!inside(u, v)) return inside(u - ex, v) || inside(u + ex, v) || inside(u, v - ey) || inside(u, v + ey) ? C[0] : undefined;+ if (white) return WHITE;+ if (inDot(u, v)) return Math.hypot(u + 1.2, v + 4.8) < 1.2 ? WHITE : u + v + 3.6 < -0.5 ? C[6] : u + v + 3.6 < 1.5 ? C[5] : C[4];+ const w = hw(v), q = (u + w) / (2 * w);+ if (q < 0.28) return v < -20 ? WHITE : C[7];+ if (q > 0.74) return C[4];+ return v < -18 ? C[6] : v < -13 ? C[5] : C[5];+ });}-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);+export function create(o) {+ const C = fit(o.palette, 8), R = new Rng(o.seed);+ const ps = new Particles({ rng: R, sparks: [C[7], C[6], C[5], C[3]] }), lights = new Lights();+ // the mark's foot: shot up off the head with a spring, so it overshoots and settles+ const m = { y: HEAD, vy: -420, sq: 0, landed: false };+ let t = 0, popped = false, sprung = false;+ const end = meta.duration - 0.05;+ return {+ update(dt) {+ t += dt;+ if (t < POP) {+ // a stiff spring pulls it to its rest above the head+ m.vy += (-(m.y - REST) * 900 - m.vy * 14) * dt;+ m.y += m.vy * dt;+ if (!m.landed && m.vy > 0) (m.landed = true), (m.sq = 1);+ }+ m.sq = Math.max(0, m.sq - dt / 0.12);+ // it leaves the head with a little burst of light+ if (!sprung && t >= 0.04) {+ sprung = true;+ lights.add(0, HEAD - 4, 26, C[5], 0.6, 0.25);+ for (let i = 0; i < 8; i++) {+ const an = -Math.PI / 2 + R.range(-1.3, 1.3), sp = R.range(40, 90);+ ps.spawn(P.STAR, R.range(-4, 4), HEAD - 2, Math.cos(an) * sp, Math.sin(an) * sp, R.range(0.2, 0.4), R.pick([C[7], C[6], C[5]]), i % 3 ? 0.6 : 1.3);+ }+ }+ if (!popped && t >= POP + 0.05) {+ popped = true;+ lights.add(0, REST - 13, 28, C[5], 0.5, 0.2);+ for (let i = 0; i < 7; i++) {+ const an = (i / 7) * TAU + R.range(-0.2, 0.2), sp = R.range(30, 60);+ ps.spawn(P.STAR, Math.cos(an) * 5, REST - 13 + Math.sin(an) * 9, Math.cos(an) * sp, Math.sin(an) * sp, Math.min(R.range(0.2, 0.35), end - t), R.pick([C[7], C[6], C[5]]), i % 3 ? 0.6 : 1.4);+ }+ }+ ps.update(dt);+ lights.update(dt);+ },++ draw(p) {+ const k = t;+ // surprise ticks: three flick out each side on the spring, and again on a second beat+ for (const [t0, len] of [[0.04, 6], [0.48, 4.5]]) {+ const u = (k - t0) / 0.24;+ if (u <= 0 || u >= 1) continue;+ for (const s of [-1, 1])+ for (let i = 0; i < 3; i++) {+ const an = -Math.PI / 2 + s * (0.55 + i * 0.42), r0 = 14 + 7 * ease.outCubic(u), L = len * Math.sin(u * Math.PI) * (i === 1 ? 1 : 0.75);+ const cx = 0, cy = REST - 13, ca = Math.cos(an), sa = Math.sin(an);+ if (L < 0.8) continue;+ p.line(cx + ca * r0, cy + sa * r0, cx + ca * (r0 + L), cy + sa * (r0 + L), (q) => (q < 0.5 ? WHITE : C[5]));+ }+ }+ // the mark: stretched while it shoots up, squashed as it lands, wobbling, white on the pop+ const pu = (k - POP) / 0.06;+ if (pu < 1) {+ const speed = Math.min(1, Math.abs(m.vy) / 420), up = m.vy < 0 ? speed : 0;+ let sx = 1 - 0.3 * up + 0.3 * m.sq, sy = 1 + 0.45 * up - 0.28 * m.sq;+ if (k < 0.05) (sx *= k / 0.05), (sy *= k / 0.05);+ if (pu > 0) (sx = sy = 1 + 0.3 * pu);+ const wob = 0.28 * Math.exp(-k * 4) * Math.sin(k * 26), white = k < 0.06 || pu > 0;+ if (sx > 0.1) bang(p, C, 0, m.y, sx, sy, wob, white);+ p.glow(0, m.y - 13, 20, C[5], 0.35 + (white ? 0.3 : 0));+ if (k > 0.6 && k < 0.85) sparkle(p, -3, m.y - 22, 3.5 * Math.sin(((k - 0.6) / 0.25) * Math.PI), C[7], C[6], 0.4);+ }+ ps.draw(p);+ lights.draw(p);+ },+ };}diff --git a/src/fx/ui/heal-number.js b/src/fx/ui/heal-number.jsdeleted file mode 100644index 3c0c910..0000000--- a/src/fx/ui/heal-number.js+++ /dev/null@@ -1,45 +0,0 @@-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.jsindex 3561ad9..14c43a3 100644--- a/src/fx/ui/health-bar-hit.js+++ b/src/fx/ui/health-bar-hit.js@@ -1,55 +1,96 @@-import { PAL, RAMP, hex, burst, seg, ease, WHITE } from "../../core/index.js";-import { shake, fit } from "./_lib.js";+import { Particles, Bits, Lights, P, B, Rng, fit, sparkle, clamp, seg, ease, TAU, WHITE, hex, mix } from "../../core/index.js";+import { panel, shake, HEART, heartPal } 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,+ desc: "A segmented health bar takes a hit: it jolts and dips, the lost chunk flashes white and sheds chips, holds, then drains away behind a sparking edge.",+ tags: ["ui", "health", "hud", "damage", "bar", "one-shot"],+ size: [160, 64],+ origin: [80, 30],+ duration: 2.0,loop: false,fps: 30,bg: "dark",- options: { palette: PAL.leaf, from: 0.8, to: 0.45, seed: 14 },+ options: { palette: ["#1a0508", "#4a0b12", "#8c1420", "#d42a2e", "#ff5a4a", "#ff9a86", "#ffd8cc", "#ffffff"], from: 0.8, to: 0.45, seed: 3 },};-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;+const HIT = 0.2, DRAIN = 0.62, DRAINED = 1.05, FOLD = 1.62;+const BX = -48, BW = 104, BY = -4, BH = 8, CELLS = 10;+const INK = { outline: hex("#0d0a14"), rim: hex("#4a4060"), top: hex("#2a2338"), body: hex("#1e1929"), low: hex("#141019") };-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);+export function create(o) {+ const C = fit(o.palette, 8), R = new Rng(o.seed), from = clamp(o.from), to = clamp(Math.min(o.to, from));+ const ps = new Particles({ rng: R, sparks: [C[7], C[6], C[5], C[3]] }), bits = new Bits(), lights = new Lights();+ const PALE = mix(C[6], hex("#ffe9a8"), 0.5), pal = heartPal(C);+ let t = 0, hit = false;+ const end = meta.duration - 0.05;+ // the white chunk's right end: holds, then drains down to the new value+ const ghostAt = (t) => (t < DRAIN ? from : from - (from - to) * ease.inOutQuad(seg(t, DRAIN, DRAINED)));+ return {+ update(dt) {+ t += dt;+ if (!hit && t >= HIT) {+ hit = true;+ lights.add(BX + BW * (to + from) / 2, BY + 4, 50, C[5], 0.7, 0.3);+ lights.add(BX + BW * (to + from) / 2, BY + 4, 24, WHITE, 0.6, 0.08);+ // chips break off the lost chunk+ for (let i = 0; i < 12; i++) {+ const x = BX + BW * R.range(to, from), an = -Math.PI / 2 + R.range(-1.2, 1.2), sp = R.range(50, 130);+ bits.add({ kind: B.SHARD, x, y: BY + R.range(1, 7), vx: Math.cos(an) * sp, vy: Math.sin(an) * sp, g: 0.45, drag: 1.2, life: R.range(0.35, 0.6), a: R.range(0, TAU), va: R.range(-20, 20), s: R.range(1.5, 3), c: R.pick([C[7], C[6], C[5], C[4]]) });+ }+ for (let i = 0; i < 10; i++) {+ const an = R.range(0, TAU), sp = R.range(60, 160);+ ps.spawn(P.SPARK, BX + BW * R.range(to, from), BY + 4, Math.cos(an) * sp, Math.sin(an) * sp * 0.6 - 30, R.range(0.12, 0.26));+ }+ }+ // the draining edge sparks as it runs back+ if (t > DRAIN && t < DRAINED && R.chance(0.5)) {+ const x = BX + BW * ghostAt(t);+ ps.spawn(P.SPARK, x, BY + R.range(1, 7), R.range(-20, 60), -R.range(20, 70), R.range(0.1, 0.22));+ }+ bits.update(dt);+ ps.update(dt);+ lights.update(dt);+ },++ draw(p) {+ const [jx, jy] = shake(t, 3, HIT, 0.28, o.seed), dip = t > HIT ? Math.round(3 * Math.exp(-(t - HIT) * 10) * Math.cos((t - HIT) * 24)) : 0;+ const open = ease.outBack(seg(t, 0, 0.14), 2) * (1 - ease.inBack(seg(t, FOLD, FOLD + 0.18), 2));+ if (open > 0.04) {+ const ox = jx, oy = jy + dip, h = 18 * open, y0 = -9 + (18 - h) / 2;+ // the frame flashes red on the hit+ const red = t >= HIT && t < HIT + 0.07;+ panel(p, BX - 22 + ox, y0 + oy, BW + 26, h, red ? { ...INK, outline: C[4], rim: C[6] } : INK, { r: Math.min(5, h / 2) });+ if (open > 0.75) {+ // the track, then the fill (red, lit on top, dark below), the white chunk, and the cell dividers+ const val = t < HIT ? from : to, ghost = t < HIT ? from : ghostAt(t), white = t >= HIT && t < HIT + 0.07;+ p.rect(BX + ox, BY + oy, BW, BH, hex("#0d0a14"));+ p.shade(BX + ox, BY + oy, BX + BW + ox, BY + BH + oy, (x, y) => {+ const u = (x - BX - ox) / BW, v = y - BY - oy;+ if (u < val) return v < 1 ? C[6] : v < 2 ? C[5] : v < 5 ? C[4] : v < 7 ? C[3] : C[2];+ if (u < ghost) return white ? WHITE : v < 1 ? WHITE : v < 6 ? PALE : C[5];+ return v < 1 ? hex("#2a2338") : hex("#191424");+ });+ for (let i = 1; i < CELLS; i++) p.rect(BX + ox + Math.round((BW * i) / CELLS), BY + oy, 1, BH, hex("#0d0a14"));+ // the new edge of the health glints, and a hot spark rides the draining edge+ if (t > HIT) p.rect(BX + ox + Math.round(BW * val) - 1, BY + oy, 1, BH, C[7]);+ if (t > DRAIN && t < DRAINED) {+ const gx = BX + ox + BW * ghost;+ p.rect(gx - 1, BY + oy - 1, 2, BH + 2, WHITE);+ p.glow(gx, BY + oy + 4, 10, C[5], 0.6);+ }+ p.glow(BX + ox + BW * val * 0.5, BY + oy + 4, BW * 0.4, C[3], 0.12);+ // the heart: jumps and flashes white on the hit, glints before it+ const hk = t - HIT, hop = hk > 0 ? Math.round(-3 * Math.exp(-hk * 12) * Math.abs(Math.cos(hk * 22))) : 0;+ p.sprite(HEART, pal, BX - 17 + ox, oy - 6 + hop);+ if (hk > 0 && hk < 0.07) p.sprite(HEART, { ...pal, k: 0, w: WHITE, h: WHITE, o: WHITE, m: WHITE, d: C[6] }, BX - 17 + ox, oy - 6 + hop);+ p.glow(BX - 11 + ox, oy, 10, C[4], 0.25 + (hk > 0 && hk < 0.2 ? 0.4 : 0));+ if (t < HIT && (t * 2.5) % 1 < 0.3) sparkle(p, BX - 14 + ox, oy - 3, 2, C[7], C[6], 0.3);+ }+ }+ bits.draw(p);+ ps.draw(p);+ lights.draw(p);+ },+ };}diff --git a/src/fx/ui/heart-lost.js b/src/fx/ui/heart-lost.jsindex f6f568b..dc4ffa2 100644--- a/src/fx/ui/heart-lost.js+++ b/src/fx/ui/heart-lost.js@@ -1,76 +1,159 @@-import { PAL, burst, seg, ease, WHITE } from "../../core/index.js";-import { Layer, fit } from "./_lib.js";-import { pillow, heartSdf } from "../pickups/_lib.js";+import { Particles, Bits, Lights, P, B, Rng, fit, sparkle, clamp, seg, ease, TAU, WHITE, hex } from "../../core/index.js";+import { shake } from "./_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,+ desc: "A HUD heart is hit: it flashes white and jolts, a crack runs down it, it splits into two halves that tumble away, leaving an empty socket that fades.",+ tags: ["ui", "health", "heart", "hud", "damage", "one-shot"],+ size: [96, 88],+ origin: [48, 34],+ duration: 1.5,loop: false,fps: 30,bg: "dark",- options: { palette: PAL.blood, seed: 15 },+ options: { palette: ["#1a0508", "#4a0b12", "#8c1420", "#d42a2e", "#ff5a4a", "#ff9a86", "#ffd8cc", "#ffffff"], seed: 5 },};-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))];+const HIT = 0.14, CRACK = 0.24, SPLIT = 0.5;+// the heart's shape, 19 x 16, centred on (0, 0)+const MASK = [+ "....xxxx...xxxx....",+ "..xxxxxxx.xxxxxxx..",+ ".xxxxxxxxxxxxxxxxx.",+ "xxxxxxxxxxxxxxxxxxx",+ "xxxxxxxxxxxxxxxxxxx",+ "xxxxxxxxxxxxxxxxxxx",+ "xxxxxxxxxxxxxxxxxxx",+ ".xxxxxxxxxxxxxxxxx.",+ "..xxxxxxxxxxxxxxx..",+ "...xxxxxxxxxxxxx...",+ "....xxxxxxxxxxx....",+ ".....xxxxxxxxx.....",+ "......xxxxxxx......",+ ".......xxxxx.......",+ "........xxx........",+ ".........x.........",+];+const MW = 19, MH = 16, OX = -9.5, OY = -8;+const inMask = (i, j) => i >= 0 && j >= 0 && i < MW && j < MH && MASK[j][i] === "x";+// the crack: a zigzag from the notch to the tip, as a column per row+const CRACK_X = [9, 9, 10, 9, 8, 8, 9, 10, 10, 9, 8, 9, 9, 10, 9, 9];-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 });+// the heart's own color at mask pixel (i, j): a lit left lobe with a white glint, shade down the right+function shadeAt(C, i, j) {+ const u = (i - 9) / 9.5, v = (j - 7) / 8;+ if ((i === 3 || i === 4) && (j === 2 || j === 3) && !(i === 4 && j === 3)) return WHITE;+ if (i >= 2 && i <= 5 && j >= 2 && j <= 5 && u + v < -0.75) return C[5];+ const l = -(u * 0.55 + v * 0.65);+ return l > 0.25 ? C[4] : l > -0.3 ? C[3] : l > -0.6 ? C[2] : C[1];}-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]);+// draw part of the heart (side: -1 left of the crack, 1 right, 0 whole) turned by a about its pivot+function drawPart(p, C, side, x, y, a, white, crackK, alpha) {+ const ca = Math.cos(a), sa = Math.sin(a), px0 = side < 0 ? -4.5 : side > 0 ? 4.5 : 0, py0 = 0;+ const own = (i, j) => inMask(i, j) && (side === 0 || (side < 0 ? i < CRACK_X[j] : i >= CRACK_X[j]));+ p.shade(x - 13, y - 13, x + 13, y + 13, (sx, sy, o) => {+ // back into the heart's own pixels+ const dx = sx - x, dy = sy - y, lx = dx * ca + dy * sa + px0, ly = -dx * sa + dy * ca + py0;+ const i = Math.floor(lx - OX), j = Math.floor(ly - OY);+ if (!own(i, j)) return;+ o.a = alpha;+ const edge = !own(i - 1, j) || !own(i + 1, j) || !own(i, j - 1) || !own(i, j + 1);+ if (white) return edge ? C[6] : WHITE;+ if (edge) return C[0];+ // the crack opens down the middle, dark with a lit lip+ if (side === 0 && j / MH < crackK) {+ if (i === CRACK_X[j]) return C[0];+ if (i === CRACK_X[j] - 1) return C[6];+ }+ return shadeAt(C, i, j);});- if (age < 0.1) p.glow(0, 0, 16, C[5], 0.4 * (1 - age / 0.1));+}++export function create(o) {+ const C = fit(o.palette, 8), R = new Rng(o.seed);+ const ps = new Particles({ rng: R, sparks: [C[7], C[6], C[5], C[3]] }), bits = new Bits(), lights = new Lights();+ const SOCKET = [hex("#0d0a14"), hex("#2a2338"), hex("#3c3350")];+ const halves = [-1, 1].map((s) => ({ s, x: s * 4.5, y: 0, vx: s * R.range(55, 70), vy: -R.range(60, 80), a: 0, va: s * R.range(2.2, 3.2) }));+ let t = 0, hit = false, split = false, gone = false;+ const end = meta.duration - 0.05;+ return {+ update(dt) {+ t += dt;+ if (!hit && t >= HIT) {+ hit = true;+ lights.add(0, 0, 40, C[5], 0.6, 0.3);+ for (let i = 0; i < 8; i++) {+ const an = R.range(0, TAU), sp = R.range(80, 170);+ ps.spawn(P.SPARK, Math.cos(an) * 9, Math.sin(an) * 7, Math.cos(an) * sp, Math.sin(an) * sp - 30, R.range(0.1, 0.22));+ }+ }+ if (!split && t >= SPLIT) {+ split = true;+ lights.add(0, 0, 44, WHITE, 0.6, 0.12);+ lights.add(0, 0, 50, C[5], 0.5, 0.4);+ // the break throws shards from the crack and a puff of red dust+ for (let i = 0; i < 12; i++) {+ const j = R.int(1, 14), an = -Math.PI / 2 + R.range(-1.4, 1.4), sp = R.range(40, 100);+ bits.add({ kind: B.SHARD, x: CRACK_X[j] + OX, y: j + OY, vx: Math.cos(an) * sp, vy: Math.sin(an) * sp, g: 0.5, drag: 1, life: R.range(0.35, 0.55), a: R.range(0, TAU), va: R.range(-20, 20), s: R.range(1.5, 3), c: R.pick([C[6], C[5], C[4], C[3]]) });+ }+ for (let i = 0; i < 5; i++) ps.spawn(P.DUST, R.range(-2, 2), R.range(-6, 6), R.range(-25, 25), R.range(-20, 5), R.range(0.35, 0.6), C[2], R.range(2, 3.5));+ for (let i = 0; i < 6; i++) {+ const an = R.range(0, TAU), sp = R.range(30, 70);+ ps.spawn(P.STAR, Math.cos(an) * 4, Math.sin(an) * 4, Math.cos(an) * sp, Math.sin(an) * sp, R.range(0.25, 0.45), R.pick([C[7], C[6]]), i % 2 ? 0.6 : 1.4);+ }+ }+ if (split && !gone && t >= 0.95) {+ gone = true;+ for (const h of halves)+ for (let i = 0; i < 5; i++) {+ const an = R.range(0, TAU), sp = R.range(20, 50);+ ps.spawn(P.STAR, h.x + Math.cos(an) * 4, h.y + Math.sin(an) * 4, Math.cos(an) * sp, Math.sin(an) * sp - 10, Math.min(R.range(0.2, 0.35), end - t), R.pick([C[7], C[6], C[5]]), i ? 0.6 : 1.3);+ }+ }+ if (split)+ for (const h of halves) {+ h.vy += 520 * dt;+ h.vx -= h.vx * 0.6 * dt;+ h.x += h.vx * dt;+ h.y += h.vy * dt;+ h.a += h.va * dt;+ // a shard or two of red trails off each half as it tumbles+ if (t < 0.92 && R.chance(0.05)) ps.spawn(P.EMBER, h.x, h.y, R.range(-10, 10), R.range(-10, 5), Math.min(R.range(0.3, 0.5), end - t), C[4], 1);+ }+ bits.update(dt);+ ps.update(dt);+ lights.update(dt);+ },++ draw(p) {+ const [jx, jy] = shake(t, 3, HIT, 0.25, o.seed), tremble = t > CRACK && t < SPLIT ? Math.round(Math.sin(t * 90)) : 0;+ // the empty socket it leaves behind, which fades away at the end+ const sk = seg(t, SPLIT - 0.05, SPLIT + 0.1) * (1 - seg(t, 1.15, 1.4));+ if (sk > 0)+ p.shade(-12, -10, 12, 10, (sx, sy, out) => {+ const i = Math.floor(sx - OX), j = Math.floor(sy - OY);+ if (!inMask(i, j)) return;+ out.a = sk;+ const edge = !inMask(i - 1, j) || !inMask(i + 1, j) || !inMask(i, j - 1) || !inMask(i, j + 1);+ return edge ? SOCKET[2] : j < 3 ? SOCKET[1] : SOCKET[0];+ });+ if (t < SPLIT) {+ // whole: it beats before the hit, flashes white and jolts on it, then trembles as the crack runs down+ const beat = t < HIT ? 1 + 0.08 * Math.max(0, Math.sin(t * 22)) : 1, white = t >= HIT && t < HIT + 0.07;+ drawPart(p, C, 0, jx + tremble, jy, 0, white, seg(t, CRACK, SPLIT - 0.06), 1);+ p.glow(0, 0, 18 * beat, C[4], 0.3 + (white ? 0.5 : 0));+ if (t < HIT) sparkle(p, -6, -5, 2.5 * Math.max(0, Math.sin(t * 22)), C[7], C[6], 0.3);+ } else {+ // the halves tumble away, flashing white on the break, and fade+ const fade = 1 - seg(t, 0.9, 1.0), white = t < SPLIT + 0.05;+ if (fade > 0) for (const h of halves) drawPart(p, C, h.s, h.x, h.y, h.a, white, 0, fade);+ const rk = (t - SPLIT) / 0.3;+ if (rk < 1) p.ring(0, 0, 8 + 16 * ease.outCubic(rk), Math.max(1, 2 * (1 - rk)), rk < 0.3 ? WHITE : C[5], 1.2 - rk);+ }+ bits.draw(p);+ ps.draw(p);+ lights.draw(p);+ },+ };}diff --git a/src/fx/ui/level-up.js b/src/fx/ui/level-up.jsindex eb157c9..4d4d23a 100644--- a/src/fx/ui/level-up.js+++ b/src/fx/ui/level-up.js@@ -1,66 +1,312 @@-import { PAL, fit, at, burst, cycle, seg, ease, bump, clamp, TAU, WHITE, hex } from "../../core/index.js";+// The pillar's strands of light and the rings climbing it adapt Sprite Fusion's open-source holy light+// (https://www.spritefusion.com/pixel-art-vfx/holy-light), and the streaks rushing in its power-up+// (https://www.spritefusion.com/pixel-art-vfx/power-up), MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Lights, P, PF, Rng, fit, band, flare, sparkle, clamp, seg, smooth, ease, noise2, fract, rand, scale, TAU, WHITE } from "../../core/index.js";+import { spell, drawWord, tintActor, lightActor, haloActor } from "./_lib.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,+ desc: "Gold gathers at the feet and bursts up as a pillar of light round the hero; rings climb it, LEVEL UP! drops in letter by letter, a shine sweeps it, sparkles twinkle.",+ tags: ["ui", "level", "reward", "text", "light", "one-shot"],+ size: [176, 138],+ origin: [88, 114],+ duration: 3.2,loop: false,fps: 30,bg: "ground",- actor: true,- options: { palette: PAL.gold, text: "LEVEL UP!", seed: 5 },+ actor: 2,+ options: { palette: ["#2a1405", "#5c3008", "#9a5a0e", "#d48e18", "#f5b92c", "#ffde5e", "#fff4bc", "#ffffff"], text: "LEVEL UP!", seed: 5 },};-const OUTLINE = hex("#2a1406");+// release, pillar lifts off, pillar gone, pillar height, text top, first letter, stagger, shine, letters pop+const REL = 0.28, RET = 1.02, GONE = 1.34, TOP = 100, TY = -68, DROP = 0.5, STAG = 0.05, LANDED = 1.06, SHINE = 1.24, EXIT = 2.3;+// strands of light streaming up the pillar in dashes: where across it, how fast, dash period and length+const STRANDS = Array.from({ length: 9 }, (_, i) => ({ x: (i / 8 - 0.5) * 1.5 + (rand(i, 1) - 0.5) * 0.16, sp: 170 + rand(i, 2) * 170, per: 10 + rand(i, 3) * 16, duty: 0.3 + rand(i, 4) * 0.35, ph: rand(i, 5), lvl: rand(i, 6) < 0.35 ? 1 : 2, end: 0.5 + rand(i, 7) * 0.42 }));-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));+// half-width of the pillar at time t+const widthAt = (t) => (t < REL ? 0 : 12 * (1 + 0.4 * Math.exp(-(t - REL) * 10)) * (1 - 0.82 * smooth(RET - 0.12, RET + 0.16, t)));++// the pillar: shoots up from the feet (one white-hot frame), then stands as light, not paint: two flowing+// walls, a white core and strands streaming up in dashes; at the end its foot lifts off and it shoots away+function column(p, C, t) {+ const a = t - REL;+ if (a < 0 || t > GONE) return;+ const top = -TOP * ease.outExpo(clamp(a / 0.12)), bot = -TOP * ease.inCubic(seg(t, RET, GONE)), W = widthAt(t), k = 1 - smooth(RET, GONE, t);+ p.glowLine(0, top, 0, Math.min(bot, -34), W * 1.6 + 6, C[5], 0.2 * k + 0.06);+ p.glowLine(0, top, 0, Math.min(bot, -40), 5, WHITE, 0.18 * k);+ if (a < 0.04) {+ for (let y = Math.floor(top); y < bot; y++) {+ const wr = W * 0.55 * (1 - 0.3 * (-y / TOP));+ for (let x = Math.floor(-wr); x <= Math.ceil(wr); x++) p.dot(x, y, Math.abs(x + 0.5) < wr - 1.5 ? WHITE : C[6], clamp((y + TOP) / 20) * 1.5);+ }+ return;}- // 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 });+ for (let y = Math.ceil(top); y < Math.ceil(bot); y++) {+ const h = -y / TOP, fade = clamp((y + TOP) / 16) * (t < RET ? 1 : clamp((bot - y) / 10)), head = y - top < 3 && a < 0.16;+ const wr = W * (1 - 0.3 * h) + 0.9 * noise2(y * 0.2, t * 12, 3);+ for (const s of [-1, 1]) {+ const run = fract(y * 0.06 + t * 3.4 + (s > 0 ? 0.5 : 0)) < 0.78, xw = s * wr;+ p.dot(xw, y, head ? WHITE : run ? C[6] : C[5], fade * 1.4);+ p.dot(xw + s, y, C[4], fade * (run ? 0.5 : 0.25));+ if (run) p.dot(xw - s, y, C[5], fade * 1.2);+ }+ p.dot(0, y, WHITE, fade * 1.6);+ p.dot(-1, y, noise2(y * 0.3, t * 14, 5) > -0.2 ? WHITE : C[6], fade * 1.3);+ if (noise2(y * 0.25, t * 9, 8) > 0.25) p.dot(1, y, C[6], fade * 1.2);+ for (const S of STRANDS) {+ if (h > S.end) continue;+ const ph = fract((y + t * S.sp) / S.per + S.ph);+ if (ph > S.duty) continue;+ const u = ph / S.duty;+ p.px(S.x * wr, y, head || u < 0.2 ? WHITE : u < 0.65 ? C[7 - S.lvl] : C[6 - S.lvl]);}- x += w + 1;+ }+}++// the plate of light the pillar stands on+function plate(p, C, t, k) {+ if (k <= 0.02) return;+ const rx = 9 + 9 * k + Math.sin(t * 9), ry = 2.2;+ p.shade(-rx, -ry, rx, ry, (x, y, o) => {+ const dx = x / rx, dy = y / ry, d = Math.sqrt(dx * dx + dy * dy);+ if (d > 1) return;+ const u = d / Math.max(0.05, k);+ o.c = u < 0.3 ? WHITE : u < 0.55 ? C[6] : u < 0.8 ? C[5] : C[4];+ o.a = d < 0.6 * k ? 1 : k * (1 - d) * 2.2;});- // 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, -1, rx * 2.2, C[4], 0.35 * k);+}++// a burst of rays above and below the title: they start on an ellipse just outside the word, so none crosses+// it, shoot out when the last letter lands, shimmer, and draw back in+function rays(p, C, t, k, cx, cy) {+ if (k <= 0.02) return;+ for (let i = 0; i < 20; i++) {+ const an = (i / 20) * TAU + 0.08, ca = Math.cos(an), sa = Math.sin(an), long = i % 2 === 0;+ if (Math.abs(sa) < 0.4) continue;+ const r0 = 1 / Math.sqrt((ca / 52) ** 2 + (sa / 12) ** 2) + 2 * k, len = (long ? 15 + 7 * rand(i, 9) : 7 + 4 * rand(i, 8)) * k;+ if (len < 1) continue;+ const sh = 0.75 + 0.25 * Math.sin(t * 7 + i * 2.1), x0 = cx + ca * r0, y0 = cy + sa * r0;+ p.line(x0, y0, x0 + ca * len, y0 + sa * len, (u) => (u < 0.3 ? C[7] : u < 0.6 ? C[6] : C[5]), (u) => sh * (u < 0.55 ? 1.3 : (1.3 * (1 - u)) / 0.45));+ }+}++export function create(o) {+ const C = fit(o.palette, 8), R = new Rng(o.seed), A = o.actor, SHADOW = scale(C[0], 0.5);+ const ps = new Particles({ rng: R, ground: () => 0, sparks: [C[7], C[6], C[5], C[3]] }), lights = new Lights();+ // every particle is gone by the end+ const spawn = (k, x, y, vx, vy, life, ...rest) => ps.spawn(k, x, y, vx, vy, Math.min(life, meta.duration - 0.05 - t), ...rest);+ const word = spell(o.text), BASE = TY + 14, X0 = -word.w;+ const lets = word.letters.filter((L) => L.g).map((L, i) => ({ g: L.g, w: L.w, cx: X0 + (L.x + L.w / 2) * 2, born: DROP + i * STAG, pop: EXIT + i * 0.04, off: -18, v: 60, sq: 0, flash: 0, on: false, landed: false, rest: false, burst: false }));+ const right = X0 + word.w * 2;+ // sparkles that pop round the title one after another+ const sats = Array.from({ length: 8 }, (_, i) => {+ const s = i % 2 ? 1 : -1, x = s * R.range(20, 60), y = TY + 7 + (Math.abs(x) < 50 ? R.sign() * R.range(11, 18) : R.range(-14, 14));+ return { x, y, t0: SHINE - 0.1 + i * 0.13 + R.range(0, 0.05), dur: R.range(0.32, 0.5), L: R.range(3, 6) };});- p.glow(0, -30, 46, G[4], 0.3 * bump(t, 0, 1.4));+ const halos = [];+ let t = 0, released = false, nextHalo = REL + 0.03, gather = 0;+ const rush = [];+ // a gathering streak: a gold tail and a white head, running straight in+ const drawRush = (p, back) => {+ for (const m of rush) {+ if (m.back !== back) continue;+ const sp = Math.hypot(m.vx, m.vy), ux = m.vx / sp, uy = m.vy / sp, L = m.len;+ p.line(m.x - ux * L, m.y - uy * L, m.x - ux * L * 0.4, m.y - uy * L * 0.4, m.c);+ p.line(m.x - ux * L * 0.35, m.y - uy * L * 0.35, m.x, m.y, WHITE);+ p.glow(m.x, m.y, 4, C[5], 0.25);+ }+ };++ return {+ update(dt) {+ t += dt;+ // the gathering: streaks pour in along the floor to the feet and in from all round to the body, and in the+ // last beat run up the hero from the feet; the late ones are swallowed by the burst+ for (gather += t < REL ? dt * 420 : 0; gather >= 1; gather--) {+ const kind = R.next(), sp = R.range(140, 250) * (1 + t * 2);+ let x, y, tx, ty;+ if (kind < 0.42) {+ const an = R.range(0, TAU), D = R.range(22, 70);+ (x = Math.cos(an) * D), (y = -1 - Math.abs(Math.sin(an)) * D * 0.1), (tx = Math.cos(an) * 3), (ty = -1);+ } else if (kind < 0.84) {+ const an = R.range(0, TAU), D = R.range(34, 64);+ (x = Math.cos(an) * D), (y = Math.min(-3, -20 + Math.sin(an) * D * 0.85)), (tx = Math.cos(an) * 11), (ty = -20 + Math.sin(an) * 14);+ } else {+ if (t < REL * 0.4) continue;+ (x = R.range(-9, 9)), (y = -1), (tx = x * 0.7), (ty = -R.range(26, 44));+ }+ const dx = tx - x, dy = ty - y, l = Math.hypot(dx, dy) || 1;+ rush.push({ x, y, vx: (dx / l) * sp, vy: (dy / l) * sp, life: Math.min(l / sp, REL + 0.06 - t), len: R.range(5, 9), c: R.chance(0.45) ? C[6] : C[5], back: kind > 0.84 && R.chance(0.5) });+ }+ for (let i = rush.length - 1; i >= 0; i--) {+ const m = rush[i];+ if ((m.life -= dt) <= 0) rush.splice(i, 1);+ else (m.x += m.vx * dt), (m.y += m.vy * dt);+ }+ if (t < REL && R.chance(0.12)) spawn(P.STAR, R.range(-30, 30), -R.range(0, 3), 0, -R.range(10, 30), R.range(0.3, 0.5), C[6], 0.6);+ if (!released && t >= REL) {+ released = true;+ lights.add(0, -24, 90, C[5], 0.6, 0.7);+ lights.add(0, -8, 40, WHITE, 0.6, 0.12);+ // speed lines flung out from the hero+ for (let i = 0; i < 22; i++) {+ const an = (i / 22) * TAU + R.range(-0.12, 0.12), sp = R.range(260, 460);+ const y0 = -18 + Math.sin(an) * 8, vy = Math.sin(an) * sp * 0.8, life = Math.min(R.range(0.1, 0.2), vy > 0 ? -y0 / vy : vy < 0 ? (y0 + 104) / -vy : 1, 78 / Math.abs(Math.cos(an) * sp));+ spawn(P.MOTE, Math.cos(an) * 6, y0, Math.cos(an) * sp, vy, life, R.chance(0.4) ? C[7] : C[6], 1, 0, an > 0.3 && an < Math.PI - 0.3 ? PF.BACK : 0);+ }+ for (let i = 0; i < 26; i++) {+ const an = -Math.PI / 2 + R.range(-1.3, 1.3), sp = R.range(120, 290);+ spawn(P.SPARK, R.range(-5, 5), -2, Math.cos(an) * sp, Math.sin(an) * sp, R.range(0.35, 0.8));+ }+ for (let i = 0; i < 16; i++)+ spawn(P.STAR, R.range(-10, 10), R.range(-36, -4), R.range(-30, 30), -R.range(15, 60), R.range(0.6, 1.3), R.pick([C[7], C[6], C[5]]), R.chance(0.35) ? R.range(1.5, 2.6) : R.range(0.4, 0.9), 0, R.chance(0.4) ? PF.BACK : 0);+ }+ const W = widthAt(t);+ if (t >= nextHalo && t < RET - 0.1) halos.push(t), (nextHalo += 0.16);+ // streaks race up beside the pillar+ if (t > REL && t < RET + 0.1 && R.chance(0.5)) {+ const s = R.sign();+ const y = R.range(-4, -60), vy = -R.range(140, 260);+ spawn(P.MOTE, s * R.range(0.75, 1.6) * W, y, 0, vy, Math.min(R.range(0.16, 0.32), (y + 96) / -vy), R.chance(0.5) ? C[7] : C[6], R.range(0.6, 1), 0, R.chance(0.5) ? PF.BACK : 0);+ }+ // motes rise from the floor while the light lasts+ if (t > REL && t < 2.4 && R.chance(0.14 * (1 - seg(t, 1.6, 2.4)))) {+ spawn(P.EMBER, R.range(-20, 20), -R.range(1, 30), R.range(-15, 15), -R.range(20, 55), R.range(0.8, 1.6), C[5], R.range(1, 2), 0, R.chance(0.4) ? PF.BACK : 0);+ }+ // gold motes lift off the hero while the light lasts+ if (A && t > REL + 0.1 && t < 2.2 && R.chance(0.09)) {+ const m = A.mask;+ for (let n = 0; n < 12; n++) {+ const i = R.int(0, m.w - 1), j = R.int(0, m.h - 1);+ if (!m.data[j * m.w + i]) continue;+ spawn(P.STAR, A.x + i + 0.5, A.y + j + 0.5, R.range(-8, 8), -R.range(14, 34), R.range(0.6, 1.1), R.pick([C[7], C[6], C[5]]), R.chance(0.2) ? 1.5 : 0.6, 0, R.chance(0.5) ? PF.BACK : 0);+ break;+ }+ }+ // twinkles round the title and the hero while it holds+ if (t > 1.0 && t < 2.5 && R.chance(0.13)) {+ const up = R.chance(0.6), x = up ? R.range(-58, 58) : R.range(-20, 20), y = up ? TY + 7 + R.range(-16, 16) : R.range(-44, -6);+ spawn(P.STAR, x, y, R.range(-6, 6), -R.range(4, 14), R.range(0.4, 0.8), R.pick([C[7], C[6], C[6], C[5]]), R.chance(0.3) ? R.range(1.5, 2.4) : 0.6, 0, R.chance(0.3) ? PF.BACK : 0);+ }+ // the letters drop in, bounce and settle; then pop away one by one+ for (const L of lets) {+ if (t < L.born) continue;+ L.on = true;+ if (!L.rest) {+ L.v += 1700 * dt;+ L.off += L.v * dt;+ if (L.off >= 0 && L.v > 0) {+ L.off = 0;+ if (L.v > 110) {+ L.sq = 1;+ if (!L.landed) {+ L.landed = true;+ L.flash = 1;+ lights.add(L.cx, BASE - 7, 18, C[5], 0.55, 0.25);+ for (const s of [-1, 1]) spawn(P.STAR, L.cx + s * L.w, BASE - R.range(0, 3), s * R.range(15, 40), -R.range(5, 25), R.range(0.25, 0.45), C[6], R.range(0.5, 1.2));+ }+ L.v = -L.v * 0.3;+ } else (L.v = 0), (L.rest = true);+ }+ }+ L.sq = Math.max(0, L.sq - dt / 0.1);+ L.flash = Math.max(0, L.flash - dt / 0.12);+ if (!L.burst && t >= L.pop + 0.06) {+ L.burst = true;+ for (let i = 0; i < 3; i++) {+ const an = R.range(0, TAU), sp = R.range(20, 55);+ spawn(P.STAR, L.cx + R.range(-3, 3), BASE - 7 + R.range(-4, 4), Math.cos(an) * sp, Math.sin(an) * sp - 15, R.range(0.3, 0.6), R.pick([C[7], C[6]]), i ? 0.6 : R.range(1.2, 2));+ }+ }+ }+ ps.update(dt);+ lights.update(dt);+ },++ drawBack(p) {+ rays(p, C, t, ease.outExpo(seg(t, LANDED, LANDED + 0.2)) * (1 - ease.inQuad(seg(t, EXIT - 0.15, EXIT + 0.1))), 0, TY + 7);+ if (t < REL) {+ const k = seg(t, 0.02, REL);+ band(p, 0, 0, 4 + 52 * (1 - ease.inQuad(k)), 0.2, 1.5, k * 1.1, C, (g) => Math.sin(g) < 0);+ }+ for (const [d, r1, th] of [[0, 72, 4], [0.08, 46, 2.5]]) {+ const k = (t - REL - d) / 0.55;+ if (k > 0 && k < 1) band(p, 0, 0, 5 + r1 * ease.outCubic(k), 0.2, Math.max(1, th * (1 - k)), 1.15 - k, C, (g) => Math.sin(g) < 0, k < 0.15);+ }+ for (const h0 of halos) {+ const k = (t - h0) / 0.6;+ if (k > 0 && k < 1) band(p, 0, -2 - 72 * ease.outQuad(k), (widthAt(t) * 1.45 + 4) * (1 - 0.4 * k), 0.3, 1.5, (1 - k) * 1.4, C, (g) => Math.sin(g) < 0, k < 0.12);+ }+ column(p, C, t);+ plate(p, C, t, t < REL ? 0.55 * seg(t, 0.05, REL) : 1 - smooth(RET - 0.1, GONE + 0.2, t));+ ps.draw(p, "back");+ drawRush(p, true);+ },++ draw(p) {+ // near halves of the rings, in front of the hero+ if (t < REL) {+ const k = seg(t, 0.02, REL);+ band(p, 0, 0, 4 + 52 * (1 - ease.inQuad(k)), 0.2, 1.5, k * 1.1, C, (g) => Math.sin(g) >= 0);+ }+ for (const [d, r1, th] of [[0, 72, 4], [0.08, 46, 2.5]]) {+ const k = (t - REL - d) / 0.55;+ if (k > 0 && k < 1) band(p, 0, 0, 5 + r1 * ease.outCubic(k), 0.2, Math.max(1, th * (1 - k)), 1.15 - k, C, (g) => Math.sin(g) >= 0, k < 0.15);+ }+ for (const h0 of halos) {+ const k = (t - h0) / 0.6;+ if (k > 0 && k < 1) band(p, 0, -2 - 72 * ease.outQuad(k), (widthAt(t) * 1.45 + 4) * (1 - 0.4 * k), 0.3, 1.5, (1 - k) * 1.4, C, (g) => Math.sin(g) >= 0, k < 0.12);+ }+ // the hero: warming as it gathers, flashed white on the release, then lit gold with a glowing edge+ const lit = smooth(REL - 0.02, REL + 0.04, t) * (1 - smooth(RET, 2.5, t));+ tintActor(p, A, t < REL ? 0 : t < REL + 0.06 ? 1 : Math.exp(-(t - REL - 0.06) / 0.07), [C[4], C[5], C[6]]);+ lightActor(p, A, C[5], 0.1 * seg(t, 0.05, REL) * (1 - lit) + 0.06 * lit, 0.6 * lit, t);+ haloActor(p, A, C[5], 0.85 * lit * (1 - smooth(RET, GONE + 0.3, t)) + 0.3 * lit, t);+ // the spark gathering at the feet, then the flare of the release+ if (t < REL) {+ const k = seg(t, 0.05, REL), beat = 1 + 0.4 * Math.exp(-((t - REL * 0.6) ** 2) / 0.001);+ sparkle(p, 0, -2, (1 + 4 * k * k) * beat, C[6], C[5], 0.3 + 0.4 * k);+ } else if (t < REL + 0.22) {+ const a = (t - REL) / 0.22;+ flare(p, 0, -4, 28 * Math.pow(1 - a, 1.5), 1 - a, C);+ p.glow(0, -16, 48, WHITE, 0.3 * (1 - a));+ }+ ps.draw(p, "front");+ drawRush(p, false);+ // the title+ const items = [], done = (t - LANDED) / 0.12;+ for (const L of lets) {+ if (!L.on) continue;+ let sx = 2, sy = 2, flash = L.flash;+ if (!L.landed && L.v > 150) (sx = 1.8), (sy = 2.3);+ if (L.sq > 0) (sx = 2 * (1 + 0.22 * L.sq)), (sy = 2 * (1 - 0.22 * L.sq));+ const pu = (t - L.pop) / 0.07, hop = seg(t, L.pop - 0.1, L.pop);+ if (pu >= 1) continue;+ if (hop > 0 && pu <= 0) (sx = 2 * (1 - 0.1 * hop)), (sy = 2 * (1 + 0.15 * hop));+ if (pu > 0) (sx = sy = 2 * (1 + 0.3 * pu)), (flash = 1);+ flash = Math.max(flash, done > 0 && done < 1 ? 1 - done : 0);+ const h = 7 * sy, w = L.w * sx;+ items.push({ g: L.g, x: L.cx - w / 2, y: BASE + L.off - h - 3 * ease.outQuad(hop), sx, sy, a: clamp((t - L.born) / 0.05), flash });+ }+ const sh = seg(t, SHINE, SHINE + 0.34), shine = sh > 0 && sh < 1 ? X0 - 14 + (right - X0 + 30) * ease.inOutSine(sh) : null;+ drawWord(p, items, { fill: [C[3], C[4], C[5], C[6]], edge: WHITE, under: C[2], outline: C[0], shadow: SHADOW, shine, shineY: TY, glint: C[6] });+ if (shine !== null && shine > X0 && shine < right) p.glowLine(shine, TY, shine + 8.4, BASE, 9, C[6], 0.3);+ const hold = smooth(0.9, 1.2, t) * (1 - smooth(EXIT, EXIT + 0.4, t));+ if (hold > 0) p.glow(0, TY + 7, 50, C[5], 0.22 * hold + (done > 0 && done < 1 ? 0.3 * (1 - done) : 0));+ // each letter twinkles out where it popped+ for (const L of lets) {+ const u = (t - L.pop - 0.07) / 0.16;+ if (u > 0 && u < 1) sparkle(p, L.cx, BASE - 7, 6 * (1 - u) * (1 - u), C[6], C[5], 0.5);+ }+ // the glint where the shine leaves the word, and sparkles popping round it+ const g = (t - SHINE - 0.3) / 0.26;+ if (g > 0 && g < 1) sparkle(p, right - 2, TY + 1, 7 * Math.sin(g * Math.PI), C[6], C[5], 0.6);+ for (const s of sats) {+ const u = (t - s.t0) / s.dur;+ if (u > 0 && u < 1) sparkle(p, s.x, s.y, s.L * Math.pow(Math.sin(u * Math.PI), 0.7), C[6], C[5], 0.5);+ }+ lights.draw(p);+ },+ };}diff --git a/src/fx/ui/loading-dots.js b/src/fx/ui/loading-dots.jsdeleted file mode 100644index 4cfa390..0000000--- a/src/fx/ui/loading-dots.js+++ /dev/null@@ -1,39 +0,0 @@-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.jsdeleted file mode 100644index 54ce61e..0000000--- a/src/fx/ui/loading-spinner.js+++ /dev/null@@ -1,33 +0,0 @@-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.jsdeleted file mode 100644index 2a07384..0000000--- a/src/fx/ui/notification.js+++ /dev/null@@ -1,66 +0,0 @@-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.jsindex b4f76f3..7d83738 100644--- a/src/fx/ui/quest-complete.js+++ b/src/fx/ui/quest-complete.js@@ -1,84 +1,165 @@-import { PAL, RAMP, seg, ease, bump, WHITE, hex } from "../../core/index.js";-import { Layer, boldText, letters, twinkle, shake, fit } from "./_lib.js";+import { Particles, Lights, P, Rng, fit, sparkle, clamp, seg, ease, TAU, WHITE, scale } from "../../core/index.js";+import { spell, drawWord, shake } 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,+ desc: "A stitched ribbon unrolls from the middle, QUEST COMPLETE types on letter by letter, a gold seal stamps down and ticks, stars pop; then it all rolls away.",+ tags: ["ui", "quest", "banner", "reward", "text", "one-shot"],+ size: [204, 92],+ origin: [102, 46],+ duration: 2.6,loop: false,fps: 30,bg: "dark",- options: { palette: PAL.water, text: "QUEST COMPLETE", seed: 6 },+ options: {+ palette: ["#2a1405", "#5c3008", "#9a5a0e", "#d48e18", "#f5b92c", "#ffde5e", "#fff4bc", "#ffffff"],+ ribbon: ["#1e0608", "#45101a", "#7a1a26", "#ad2632", "#d8433f", "#f27a5e", "#ffb79a"],+ text: "QUEST COMPLETE",+ seed: 8,+ },};-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."];+const L = 66, BH = 8, OPEN = 0.32, TYPE = 0.2, STEP = 0.036, STAMP = 0.95, SX = 64, SY = 4, POPSEAL = 2.0, ROLL = 2.08;-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);+// the ribbon: two notched tails behind, dark folds, then the band with a lit top, stitching and rolled ends+function ribbon(p, Rb, G, l, tails, t) {+ if (l < 1) return;+ if (tails > 0.02)+ for (const s of [-1, 1]) {+ const drop = 6 * tails, x0 = s * (l - 8), x1 = s * (l + 16 * tails);+ p.shade(Math.min(x0, x1) - 1, -BH + drop - 1, Math.max(x0, x1) + 1, BH + drop + 1, (x, y) => {+ const u = (x - x0) / (x1 - x0), v = y - drop;+ if (u < 0 || u > 1 || Math.abs(v) > BH) return;+ // a V notch cut into the far end+ if (u > 1 - (0.3 * (BH - Math.abs(v))) / BH) return;+ const e = Math.min(BH - Math.abs(v), (1 - u) * (x1 - x0) * s);+ if (e < 1 || u < 0.02) return Rb[0];+ return v < -BH + 2 ? Rb[3] : v < 0 ? Rb[2] : Rb[1];+ });+ // the fold where the tail tucks under the band+ p.tri(s * (l - 8), BH, s * (l - 1), BH, s * (l - 8), BH + drop, Rb[0]);+ }+ p.shade(-l - 1, -BH - 1, l + 1, BH + 1, (x, y) => {+ const ax = Math.abs(x), v = y;+ if (ax > l || Math.abs(v) > BH) return;+ const e = Math.min(l - ax, BH - Math.abs(v));+ if (e < 1) return Rb[0];+ if (v < -BH + 2) return Rb[5];+ if (v > BH - 2) return Rb[1];+ // gold stitching just inside the top and bottom edges+ if ((Math.abs(v + BH - 2.5) < 0.5 || Math.abs(v - BH + 3.5) < 0.5) && Math.floor(x + 0.5) % 3 !== 0 && ax < l - 3) return G[3];+ return v < -1 ? Rb[4] : Rb[3];+ });+ // while it unrolls, the rolled-up ends ride its edges+ if (tails < 0.02)+ for (const s of [-1, 1]) {+ const x = s * l;+ p.rect(Math.round(x) - 2, -BH - 2, 4, BH * 2 + 4, Rb[0]);+ p.rect(Math.round(x) - 1, -BH - 1, 1, BH * 2 + 2, Rb[4]);+ p.rect(Math.round(x), -BH - 1, 1, BH * 2 + 2, Rb[2]);+ p.px(Math.round(x) - 1, -BH - 1, Rb[6]);}- 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));+}++// a gold seal: a scalloped rim, a lit face with an inner ring, and a check mark drawn on in progress k+function seal(p, G, x, y, r, sx, sy, white, k) {+ const M = r * 1.25 + 2;+ p.shade(x - M * sx, y - M * sy, x + M * sx, y + M * sy, (px, py) => {+ const dx = (px - x) / sx, dy = (py - y) / sy, d = Math.hypot(dx, dy), an = Math.atan2(dy, dx), edge = r * (1 + 0.09 * Math.cos(an * 14));+ if (d > edge) return;+ if (white) return edge - d < 1 ? G[5] : WHITE;+ if (edge - d < 1) return G[0];+ const l = -(dx * 0.6 + dy * 0.8) / r;+ if (edge - d < 3) return l > 0.3 ? G[6] : l > -0.3 ? G[5] : G[3];+ if (Math.abs(d - r * 0.66) < 0.5) return l > 0 ? G[3] : G[2];+ return l > 0.45 ? G[7] : l > 0.1 ? G[6] : l > -0.35 ? G[5] : G[4];+ });+ if (white || k <= 0) return;+ // the check: a short stroke down, a long one up, white with a dark edge+ const pts = [[-5, 0], [-1.5, 3.5], [5.5, -4.5]].map(([a, b]) => [x + a * sx, y + b * sy]);+ const len1 = Math.hypot(pts[1][0] - pts[0][0], pts[1][1] - pts[0][1]), len2 = Math.hypot(pts[2][0] - pts[1][0], pts[2][1] - pts[1][1]);+ const done = k * (len1 + len2), segs = [[pts[0], pts[1], Math.min(1, done / len1)], [pts[1], pts[2], clamp((done - len1) / len2)]];+ for (const [w, c] of [[4.2, G[0]], [2.4, WHITE]])+ for (const [a, b, u] of segs) if (u > 0) p.beam(a[0], a[1], a[0] + (b[0] - a[0]) * u, a[1] + (b[1] - a[1]) * u, w, c);+}++export function create(o) {+ const G = fit(o.palette, 8), Rb = fit(o.ribbon, 7), R = new Rng(o.seed);+ const ps = new Particles({ rng: R, sparks: [G[7], G[6], G[5], G[3]] }), lights = new Lights();+ const word = spell(o.text, "mini"), TS = 2, TW = word.w * TS, TX = -TW / 2 - 4, TY = -5;+ const glyphs = word.letters.filter((Lt) => Lt.g);+ const sats = Array.from({ length: 7 }, (_, i) => ({ x: (i / 6 - 0.5) * 140 + R.range(-6, 6), y: (i % 2 ? 1 : -1) * R.range(15, 22), t0: STAMP + 0.12 + i * 0.12 + R.range(0, 0.04), dur: R.range(0.3, 0.45), L: R.range(3, 6) }));+ let t = 0, stamped = false, popped = false;+ const end = meta.duration - 0.05;+ return {+ update(dt) {+ t += dt;+ if (!stamped && t >= STAMP) {+ stamped = true;+ lights.add(SX, SY, 40, G[5], 0.7, 0.35);+ lights.add(SX, SY, 18, WHITE, 0.7, 0.1);+ for (let i = 0; i < 12; i++) {+ const an = (i / 12) * TAU + R.range(-0.2, 0.2), sp = R.range(40, 80) * (Math.cos(an) > 0 ? 0.6 : 1);+ ps.spawn(P.STAR, SX + Math.cos(an) * 11, SY + Math.sin(an) * 11, Math.cos(an) * sp, Math.sin(an) * sp * 0.7, R.range(0.25, 0.45), R.pick([G[7], G[6], G[5]]), i % 3 ? 0.6 : R.range(1.2, 1.8));+ }+ }+ // gold motes drift up off the banner while it holds+ if (t > STAMP && t < POPSEAL && R.chance(0.08)) ps.spawn(P.STAR, R.range(-L, L), R.range(-BH, BH), R.range(-5, 5), -R.range(8, 20), Math.min(R.range(0.4, 0.8), end - t), R.pick([G[6], G[5]]), 0.6);+ if (!popped && t >= POPSEAL + 0.05) {+ popped = true;+ lights.add(SX, SY, 30, G[6], 0.6, 0.2);+ for (let i = 0; i < 8; i++) {+ const an = R.range(0, TAU), sp = R.range(40, 90);+ ps.spawn(P.STAR, SX + Math.cos(an) * 6, SY + Math.sin(an) * 6, Math.cos(an) * sp, Math.sin(an) * sp, Math.min(R.range(0.25, 0.4), end - t), R.pick([G[7], G[6]]), i % 2 ? 0.6 : 1.5);+ }+ }+ ps.update(dt);+ lights.update(dt);+ },++ draw(p) {+ const [jx, jy] = shake(t, 2, STAMP, 0.18, o.seed);+ // the ribbon unrolls from the middle, and rolls back up at the end+ const l = L * (t < ROLL ? ease.outCubic(seg(t, 0, OPEN)) : 1 - ease.inCubic(seg(t, ROLL, ROLL + 0.26)));+ const tails = seg(t, OPEN - 0.02, OPEN + 0.12) * (t < ROLL ? 1 : 0);+ const sh = seg(t, 1.2, 1.5), shine = sh > 0 && sh < 1 ? -L - 10 + (2 * L + 20) * sh : null;+ ribbon(p, Rb, G, l, ease.outBack(tails, 2), t);+ if (shine !== null)+ for (let y = -BH + 1; y < BH; y++) {+ const x = shine + (y + BH) * 0.6;+ if (Math.abs(x) < l - 2) (p.px(x, y, Rb[6]), p.px(x + 1, y, Rb[5]));+ }+ // the words type on, each letter popping in white, clipped by the ribbon as it rolls away+ const items = [];+ glyphs.forEach((Lt, i) => {+ const u = t - (TYPE + i * STEP), x = TX + Lt.x * TS + jx;+ if (u < 0 || Math.abs(x + Lt.w) > l - 3) return;+ const s = u < 0.035 ? 2.6 : TS;+ items.push({ g: Lt.g, x: x - ((s - TS) * Lt.w) / 2, y: TY + jy - ((s - TS) * 5) / 2, sx: s, sy: s, flash: u < 0.07 ? 1 : 0 });+ });+ drawWord(p, items, { fill: [G[4], G[5], G[6], G[7]], edge: WHITE, under: G[3], outline: Rb[0], shadow: Rb[1] });+ // the seal: drops in big and faint, stamps with a squash and a flash, ticks, pops at the end+ const dk = seg(t, STAMP - 0.12, STAMP), pk = t - POPSEAL;+ if (dk > 0 && pk < 0.08) {+ const fall = 1 - ease.inQuad(dk), sq = Math.exp(-(t - STAMP) * 30) * (t >= STAMP ? 1 : 0);+ let s = 1 + 0.8 * fall, sx = s * (1 + 0.2 * sq), sy = s * (1 - 0.2 * sq);+ if (pk > 0) (sx = sy = 1 + 0.3 * (pk / 0.08));+ const white = (t >= STAMP && t < STAMP + 0.05) || pk > 0;+ if (dk < 1) p.ellipse(SX, SY + 12, 10 * (1 - 0.3 * fall), 2, Rb[0], 0.5 * dk);+ seal(p, G, SX + jx, SY - 14 * fall + jy, 11, sx, sy, white, seg(t, STAMP + 0.08, STAMP + 0.24));+ p.glow(SX, SY, 22, G[5], 0.3 + (white ? 0.4 : 0));+ }+ const rk = (t - STAMP) / 0.3;+ const rr = 12 + 13 * ease.outCubic(rk);+ if (rk > 0 && rk < 1) p.ellipse(SX, SY, rr * 1.15, rr, rk < 0.3 ? WHITE : G[5], (d) => (d > 1 - 1.4 / rr ? 1.2 - rk : 0));+ // stars pop round the banner one after another+ for (const s of sats) {+ const u = (t - s.t0) / s.dur;+ if (u > 0 && u < 1) sparkle(p, s.x, s.y, s.L * Math.pow(Math.sin(u * Math.PI), 0.7), G[6], G[5], 0.5);+ }+ ps.draw(p);+ p.glow(0, 0, 76, G[4], 0.2 * seg(t, 0.2, 0.5) * (1 - seg(t, ROLL, ROLL + 0.2)));+ lights.draw(p);+ },+ };}diff --git a/src/fx/water/_lib.js b/src/fx/water/_lib.jsindex f48f241..86fed17 100644--- a/src/fx/water/_lib.js+++ b/src/fx/water/_lib.js@@ -1,83 +1,231 @@-// 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.+// Shared by the water effects: the water ramp, droplets that fly over a water surface seen at a low angle and+// land with rings, ripple trains, lacy foam, foam billows, wet stone. Files starting with _ are helpers.+// The droplet sprites (a pixel, a shaded 2x2, a round bead with a highlight, each trailing a tail along its+// motion) are adapted from Sprite Fusion's open-source blood (https://www.spritefusion.com/pixel-art-vfx/blood),+// MIT License, Copyright (c) 2026 Hugo Duprez.-import { ramp, noise2 } from "../../core/index.js";+import { noise, noise2, TAU, WHITE, hex } from "../../core/index.js";-const call = (v, ...a) => (typeof v === "function" ? v(...a) : v);+/** Water, deep to white: deep color only in shadow, tinted middles, white crests. */+export const WATER = ["#0a1630", "#123063", "#1b5596", "#2a7fc4", "#45a9e3", "#86d3f5", "#cdf1ff", "#ffffff"];+/** Wet stone for props (lips, basins, vents), outline to highlight. */+export const ROCK = ["#141219", "#221f2b", "#34303f", "#4a4558", "#655f74", "#8a8498"];-/** 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 droplet at (x, y) moving at (vx, vy) px/s: s 1 is a pixel, 2 a shaded 2x2, 3 a round bead with a+ * highlight; a tail trails back along its motion, longer the faster it goes. C: an 8-step water ramp.+ */+export function bead(p, x, y, vx, vy, s, C, a = 1) {+ const sp = Math.hypot(vx, vy) || 1, ux = vx / sp, uy = vy / sp, tail = Math.min(5, sp * 0.011);+ if (tail >= 1) p.line(x - ux * (tail + 1), y - uy * (tail + 1), x - ux * 1.2, y - uy * 1.2, (u) => (u < 0.45 ? C[3] : s > 1 ? C[5] : C[4]), a);+ if (s >= 3) {+ p.circle(x, y, 1.75, C[4], a);+ p.circle(x - 0.25, y - 0.25, 1.15, C[6], a);+ p.dot(x - 0.7, y - 0.7, WHITE, a);+ } else if (s >= 2) {+ const X = Math.floor(x), Y = Math.floor(y);+ p.dot(X, Y, WHITE, a);+ p.dot(X + 1, Y, C[6], a);+ p.dot(X, Y + 1, C[5], a);+ p.dot(X + 1, Y + 1, C[4], a);+ } else p.dot(x, y, sp > 160 ? C[6] : C[5], a);}-/** 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"];+/**+ * Droplets in flight over a flat surface seen at a low angle: x across, z into the screen (negative is far),+ * h height above the surface; on screen they sit at (x, z * sy - h). Gravity pulls h down; when a drop+ * reaches the surface it calls onLand(drop) and is gone. add({ x, z, h, vx, vz, vh, s (1..3), life, delay }).+ */+export class Drops {+ constructor({ sy = 0.22, g = 820, drag = 0.35, onLand = null } = {}) {+ this.sy = sy;+ this.g = g;+ this.drag = drag;+ this.onLand = onLand;+ this.list = [];+ }+ add(d) {+ const life = d.life ?? 4;+ this.list.push({ x: 0, z: 0, h: 0, vx: 0, vz: 0, vh: 0, s: 1, delay: 0, ...d, life, max: life });+ }+ get count() {+ return this.list.length;+ }+ update(dt) {+ const k = this.drag * dt;+ for (let i = this.list.length - 1; i >= 0; i--) {+ const d = this.list[i];+ if (d.delay > 0) {+ d.delay -= dt;+ continue;+ }+ if ((d.life -= dt) <= 0) {+ this.list.splice(i, 1);+ continue;+ }+ d.vh -= this.g * dt;+ d.vx -= d.vx * k;+ d.vz -= d.vz * k;+ d.vh -= d.vh * k * 0.5;+ d.x += d.vx * dt;+ d.z += d.vz * dt;+ d.h += d.vh * dt;+ if (d.h <= 0 && d.vh < 0) {+ d.h = 0;+ this.list.splice(i, 1);+ this.onLand?.(d);+ }+ }+ }+ /** Draw the drops behind z = 0 ("back"), in front of it ("front"), or all. */+ draw(p, C, layer) {+ for (const d of this.list) {+ if (d.delay > 0 || (layer === "back" && d.z >= 0) || (layer === "front" && d.z < 0)) continue;+ const x = d.x, y = d.z * this.sy - d.h;+ bead(p, x, y, d.vx, d.vz * this.sy - d.vh, d.s, C, Math.min(1, d.life / 0.2));+ p.glow(x, y, 2.5 + d.s, C[5], 0.1 + 0.05 * d.s);+ }+ }+}/**- * 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).+ * A ripple on a surface seen at a low angle: a train of n crests gap px apart around (cx, cy), squashed by sy,+ * the outer crest brightest. k 0..1+ strength: a crisp 1 px crest that steps down the ramp as k falls and+ * only breaks into dashes at the very end. half: 0 the whole ring, -1 the far half (draw it behind things),+ * 1 the near half. hot: a white crest. glint: a white catch-light on the near side. wob: px the crest wanders+ * in and out round the ring, so it isn't a perfect ellipse.*/-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);- });+export function ring(p, cx, cy, r, sy, k, C, { n = 2, gap = 3, half = 0, hot = false, glint = 0, seed = 0, wob = 0 } = {}) {+ if (k <= 0.02 || r < 0.5) return;+ for (let j = 0; j < n; j++) {+ const rr = r - j * gap;+ if (rr < 0.6) break;+ const kj = k * (1 - j * 0.42), m = Math.max(6, Math.ceil(rr * TAU * 1.3)), need = 1.15 - 2.3 * Math.min(1, kj * 1.25);+ for (let i = 0; i < m; i++) {+ const a = (i / m) * TAU, s = Math.sin(a), near = s > 0;+ if ((half > 0 && !near) || (half < 0 && near)) continue;+ // as it weakens the crest breaks into glinting dashes (whole pixels, no dither), fixed to the ring+ if (noise(a * 4.7 + seed * 13.1 + j * 5.3, seed) * 0.65 + noise(a * 11.3 + seed * 7.7, seed + 3) * 0.35 < need) continue;+ // the near side and the side toward the light (upper left) read brighter+ const lit = kj * (near ? 1 : 0.7) * (0.88 - 0.12 * Math.cos(a));+ const c = hot && near && j === 0 ? WHITE : C[lit > 0.7 ? 6 : lit > 0.38 ? 5 : 4], ra = wob ? rr + wob * noise(a * 2.6 + seed * 1.9 + j, seed + 11) : rr;+ const x = cx + Math.cos(a) * ra, y = cy + s * ra * sy;+ p.dot(x, y, c);+ if (j === 0) p.light(x, y, C[4], 0.3 * lit);+ }+ }+ if (glint > 0 && half >= 0) {+ const x = cx + Math.cos(2.05) * r, y = cy + Math.sin(2.05) * r * sy;+ p.px(x, y, WHITE);+ p.glow(x, y, 3 + glint * 2, C[5], 0.35 * glint);+ }}/**- * 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.+ * Ripples that spread and fade: add(x, z, r0, r1, life, { n, gap, k, hot (seconds of white crest), glint, delay }).+ * update(dt); draw(p, C, half) with half as in ring().*/-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);+export class Ripples {+ constructor({ sy = 0.22 } = {}) {+ this.sy = sy;+ this.list = [];+ }+ add(x, z, r0, r1, life, o = {}) {+ this.list.push({ x, z, r0, r1, life, age: -(o.delay ?? 0), k: o.k ?? 1, n: o.n ?? 2, gap: o.gap ?? 3, hot: o.hot ?? 0.1, glint: o.glint ?? 0, seed: (this.seq = (this.seq ?? 0) + 1) });+ }+ get count() {+ return this.list.length;+ }+ update(dt) {+ for (let i = this.list.length - 1; i >= 0; i--) if ((this.list[i].age += dt) >= this.list[i].life) this.list.splice(i, 1);+ }+ draw(p, C, half = 0) {+ for (const q of this.list) {+ if (q.age < 0) continue;+ const u = q.age / q.life, r = q.r0 + (q.r1 - q.r0) * (1 - Math.pow(1 - u, 2.6)), k = q.k * Math.pow(1 - u, 1.7);+ ring(p, q.x, q.z * this.sy, r, this.sy, k, C, { n: q.n, gap: q.gap * (0.55 + 0.6 * u), half, hot: q.age < q.hot, glint: q.glint * k, seed: q.seed });+ }+ }}-/** 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);+/**+ * Lacy foam floating on the surface around (cx, cy), over an rx x ry patch: the crests of a noise field make+ * a white net with holes, thinning out as k falls (1 thick, 0 gone). t drifts it; seed picks the pattern.+ */+export function lace(p, cx, cy, rx, ry, k, C, t, seed = 0) {+ if (k <= 0.01 || rx < 1) return;+ const sy = ry / rx;+ p.shade(cx - rx, cy - ry, cx + rx, cy + ry, (x, y, o) => {+ const dx = (x - cx) / rx, dy = (y - cy) / ry, d = dx * dx + dy * dy;+ if (d > 1) return;+ const u = (x - cx) * 0.36, v = ((y - cy) / sy) * 0.36;+ const n = noise2(u + seed * 7.13, v - t * 0.35, seed), m = noise2(u * 2.2 - t * 0.3, v * 2.2 + seed * 3.1, seed + 9);+ const net = 1 - Math.abs(n) * 4.6 + m * 0.3, need = 1.02 - k * (1.15 - d * 0.9);+ if (net < need) return;+ o.c = net > need + 0.4 ? WHITE : C[6];+ });}/**- * 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.)+ * Mist: soft puffs with no hard edge (alpha falls off to the rim), lit on top, that swell, drift on a slowing+ * push and thin away. add(x, y, vx, vy, r0, r1, life, color, a, delay); update(dt); draw(p, haze).*/-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;+export class Mist {+ constructor() {+ this.list = [];+ }+ add(x, y, vx, vy, r0, r1, life, c, a = 0.25, delay = 0) {+ this.list.push({ x, y, vx, vy, r0, r1, life, max: life, c: hex(c), a, delay });+ }+ get count() {+ return this.list.length;+ }+ update(dt) {+ for (let i = this.list.length - 1; i >= 0; i--) {+ const m = this.list[i];+ if (m.delay > 0) {+ m.delay -= dt;+ continue;+ }+ if ((m.life -= dt) <= 0) {+ this.list.splice(i, 1);+ continue;+ }+ m.vx -= m.vx * 2.4 * dt;+ m.vy -= m.vy * 2.4 * dt + 7 * dt;+ m.x += m.vx * dt;+ m.y += m.vy * dt;+ }+ }+ draw(p, haze) {+ for (const m of this.list) {+ if (m.delay > 0) continue;+ const age = 1 - m.life / m.max, r = m.r0 + (m.r1 - m.r0) * (1 - Math.pow(1 - age, 2.2));+ const a = m.a * Math.min(1, age / 0.12) * Math.pow(1 - age, 1.4);+ if (a < 0.01) continue;+ p.disc(m.x, m.y, r, m.c, (d) => a * (1 - d * d) * (1 - d * 0.5));+ p.disc(m.x - r * 0.2, m.y - r * 0.32, r * 0.55, WHITE, (d) => a * 0.25 * (1 - d) * (1 - d));+ if (haze) p.glow(m.x, m.y, r * 1.5, haze, (0.16 * a) / m.a * Math.min(1, m.a * 3));+ }}}-/** 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;+/** A billow of churning foam: a shadowed underside, a white body, a lit cap. a < 1 dithers it away. */+export function billow(p, x, y, r, C, a = 1) {+ if (r < 0.9) return p.dot(x, y, C[6], a);+ p.circle(x + r * 0.12, y + r * 0.2, r, C[4], a);+ p.circle(x, y, r * 0.84, C[6], a);+ if (r > 1.6) p.circle(x - r * 0.3, y - r * 0.32, r * 0.46, WHITE, a);}++/** A pebble or rock: lit upper left, shaded lower right, a dark rim. ST: a 6-step stone ramp (ROCK). */+export function pebble(p, x, y, r, ST) {+ p.shade(x - r - 1, y - r - 1, x + r + 1, y + r + 1, (px, py, o) => {+ const dx = px - x, dy = py - y, d = Math.hypot(dx * 1.1, dy);+ if (d > r + 0.8) return;+ const lit = (dx + dy) / Math.max(0.5, r);+ o.c = d > r ? ST[0] : lit < -0.7 ? ST[5] : lit < 0.2 ? ST[4] : lit < 0.8 ? ST[3] : ST[2];+ });+}++export const rock = () => ROCK.map(hex);diff --git a/src/fx/water/bubbles.js b/src/fx/water/bubbles.jsindex 6bc9eb5..6ba609c 100644--- a/src/fx/water/bubbles.js+++ b/src/fx/water/bubbles.js@@ -1,64 +1,139 @@-import { PAL, rng, seg, wrap, TAU } from "../../core/index.js";-import { fit, oval } from "./_lib.js";+// The bubble shading (a lit rim top-left, a shaded rim bottom-right, a see-through body, a highlight and a+// refraction fleck, 2x2 and 1 px forms when small) and the surface line are adapted from Sprite Fusion's+// open-source bubbles (https://www.spritefusion.com/pixel-art-vfx/bubbles), MIT License, Copyright (c) 2026 Hugo Duprez.+import { fit, cycle, clamp, smooth, rand, TAU, WHITE } from "../../core/index.js";+import { WATER, rock } 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,+ desc: "Bubbles stream up from a vent of pebbles, wobbling and swelling as they rise, flare as they cross shafts of light from the surface, then dome up and pop there.",+ tags: ["water", "bubbles", "underwater", "vent", "ambient", "loop"],+ size: [104, 112],+ origin: [52, 104],+ duration: 4,loop: true,fps: 30,- bg: "dark",- options: { palette: PAL.water, count: 8, seed: 5 },+ bg: "ground",+ options: { palette: WATER, seed: 4 },};-const SMALL = { 1: ["b"], 2: [".b.", "w.b", ".c."], 3: [".bb.", "bw.b", "b..c", ".cc."] };+const D = meta.duration, TOP = -92, HALF = 48;-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));+// the surface: a wavy lit line, a darker band under it+const surfaceY = (x, ph) => TOP + Math.sin(x * 0.13 + ph * TAU * 2) * 1.1 + Math.sin(x * 0.051 - ph * TAU) * 1.3;+// light shafts slanting down from the surface, drifting: how much of one a point is in+const shaft = (x, y, ph) => {+ const u = x + (y - TOP) * 0.32, s = Math.sin(u * 0.16 + ph * TAU) * 0.6 + Math.sin(u * 0.07 - ph * TAU + 1) * 0.4;+ return Math.max(0, s - 0.35) / 0.65;+};++// one bubble at (x, y), radius r, squash q: tiny ones a pixel or a shaded 2x2, bigger ones a lit rim round a+// see-through body with a highlight and a fleck of light refracted through it+function bubble(p, C, x, y, r, q, lit) {+ if (r < 0.9) return p.px(x, y, lit > 0.3 ? WHITE : r < 0.7 ? C[5] : C[6]);+ if (r < 1.5) {+ const X = Math.floor(x), Y = Math.floor(y);+ p.px(X, Y, WHITE);+ p.px(X + 1, Y, C[6]);+ p.px(X, Y + 1, C[5]);+ p.px(X + 1, Y + 1, C[4]);+ p.glow(x + 0.5, y + 0.5, 3, C[5], 0.12 + 0.2 * lit);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]);+ const rx = r * (1 + q), ry = r * (1 - q);+ p.shade(x - rx - 1, y - ry - 1, x + rx + 1, y + ry + 1, (px, py, out) => {+ const dx = (px - x) / rx, dy = (py - y) / ry, d = Math.hypot(dx, dy) * r;+ if (d > r + 0.5) return;+ const l = (-dx - dy) / Math.SQRT2 / Math.max(0.01, d / r);+ if (d > r - 0.6) out.c = l > 0.45 ? C[6] : l < -0.55 ? C[3] : C[4];+ else p.blend(px, py, C[5], 0.16 + 0.2 * lit);+ });+ p.px(Math.round(x - rx * 0.45), Math.round(y - ry * 0.45), WHITE);+ if (r >= 2.5) p.px(Math.round(x - rx * 0.45) + 1, Math.round(y - ry * 0.45), C[6]);+ if (r >= 2) p.px(Math.round(x + rx * 0.5), Math.round(y + ry * 0.5), C[6]);+ p.glow(x, y, r * 2.4 + 2, C[5], 0.12 + 0.3 * lit);+}++// the bubbles, from the vent's three mouths: each rises faster the bigger it is, swells as the pressure drops,+// wobbles side to side, and pops at the surface+const MOUTHS = [-5, 1, 6];+function each(t, S, fn) {+ cycle(t, D, 46, S, (g) => g.range(2.2, 3.4), (age, life, r, i) => {+ const m = MOUTHS[i % 3], r0 = r.next() < 0.7 ? r.range(0.5, 1.4) : r.range(1.6, 2.6), vy = 30 + 9 * r0 + r.range(-4, 4);+ const wf = r.range(3, 6), wa = 0.8 + r0 * 1.2, ph0 = r.range(0, TAU), drift = r.range(-4, 4);+ const y = -2 - vy * age, k = clamp(-y / -TOP), x = m + drift * k + Math.sin(age * wf + ph0) * wa * k;+ fn({ x, y, r: r0 * (1 + 0.45 * k), q: 0.12 * Math.sin(age * wf * 2 + ph0) * Math.min(1, r0 / 2), i, age, vy });+ });+}++export function drawBack(p, t, o) {+ const C = fit(o.palette, 8), ph = t / D;+ // the water: deeper toward the floor, light falling through it in shafts+ for (let Y = TOP - 2; Y < 0; Y++)+ for (let X = -HALF; X < HALF; X++) {+ const x = X + 0.5, y = Y + 0.5, sy = surfaceY(x, ph);+ if (y < sy) continue;+ const e = 1 - smooth(HALF - 14, HALF, Math.abs(x)), depth = (y - TOP) / -TOP;+ p.blend(x, y, C[1], (0.22 + 0.22 * depth) * e);+ const s = shaft(x, y, ph) * (1 - depth * 0.7) * e;+ if (s > 0.05) p.light(x, y, C[4], 0.2 * s);+ }+ // where the shafts reach the floor, caustic light dances on it+ for (let X = -HALF; X < HALF; X++) {+ const x = X + 0.5, e = 1 - smooth(HALF - 14, HALF, Math.abs(x)), s = shaft(x, -2, ph);+ const c = Math.max(0, 1 - Math.abs(Math.sin(x * 0.42 + Math.sin(x * 0.11 + ph * TAU * 2) * 2.2)) * 2.4);+ if (s * c * e > 0.05) {+ p.light(x, -1, C[5], 0.5 * s * c * e);+ p.light(x, -2, C[4], 0.25 * s * c * e);+ p.light(x, 0, C[4], 0.3 * s * c * e);+ }+ }+ // the vent: a little heap of pebbles round a dark mouth+ const ST = rock();+ for (const [x, y, rr] of [[-9, -1.5, 2.4], [-4, -1, 1.8], [3.5, -1.2, 2.2], [9, -1.4, 2.6], [0, -0.6, 1.4], [-12.5, -0.8, 1.6]])+ p.shade(x - rr - 1, y - rr - 1, x + rr + 1, y + rr + 1, (px, py, out) => {+ const dx = px - x, dy = py - y, d = Math.hypot(dx * 1.1, dy);+ if (d > rr + 0.7 || py > 0) return;+ out.c = d > rr ? ST[0] : dx + dy < -rr * 0.6 ? ST[5] : dx + dy < rr * 0.3 ? ST[3] : ST[2];+ });+ for (const m of MOUTHS) p.px(m, -1, ST[0]);}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);+ const C = fit(o.palette, 8), ph = t / D, S = o.seed;+ // specks drifting in the water, flaring in the light+ cycle(t, D, 26, S + 7, D, (age, life, r) => {+ const x = r.range(-HALF + 6, HALF - 6) + Math.sin((age / D) * TAU + r.range(0, TAU)) * 3, y = TOP + 6 + ((r.range(0, 86) + age * 4) % 86);+ const s = shaft(x, y, ph), tw = Math.sin((age / D) * TAU * 3 + r.range(0, TAU));+ if (tw < -0.3 && s < 0.2) return;+ p.px(x, y, s > 0.4 ? WHITE : tw > 0.6 ? C[5] : C[4]);+ if (s > 0.4) p.glow(x, y, 3, C[5], 0.25 * s);+ });+ // the bubbles; when one reaches the surface it domes up, then pops with a ring and a couple of flecks+ each(t, S, (b) => {+ const sy = surfaceY(b.x, ph);+ if (b.y > sy + b.r) bubble(p, C, b.x, b.y, b.r, b.q, shaft(b.x, b.y, ph));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]);+ const since = (sy + b.r - b.y) / b.vy;+ if (since < 0.12 && b.r >= 1.4) {+ for (let a = Math.PI; a <= TAU + 0.01; a += 0.4 / b.r) p.px(b.x + Math.cos(a) * b.r, sy + Math.sin(a) * b.r * 0.9, C[6]);+ p.px(b.x - b.r * 0.4, sy - b.r * 0.6, WHITE);+ } else if (since < (b.r >= 1.4 ? 0.32 : 0.2)) {+ const k = clamp((since - (b.r >= 1.4 ? 0.12 : 0)) / 0.2), w = Math.max(1, b.r + 1 + k * 4);+ for (let a = 0; a < Math.PI; a += 0.5 / w) if (Math.sin(a) > 0.15) p.dot(b.x + Math.cos(a) * w, sy + Math.sin(a) * w * 0.3, k < 0.4 ? WHITE : C[5], 1.2 - k);+ if (b.r >= 1.4 && k < 0.6) {+ p.px(b.x - 2, sy - 2 - k * 4, C[6]);+ p.px(b.x + 2, sy - 3 - k * 5, C[6]);+ }}- 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]);+ });+ // the surface: a lit line with glints running along it, a darker band under it+ for (let X = -HALF; X < HALF; X++) {+ const x = X + 0.5, y = surfaceY(x, ph), e = 1 - smooth(HALF - 12, HALF, Math.abs(x));+ const glint = Math.sin(x * 0.37 - ph * TAU * 3) * Math.sin(x * 0.13 + ph * TAU) > 0.55;+ p.dot(X, y, glint ? WHITE : C[5], e * 1.3);+ p.dot(X, y + 1, C[3], e * 1.3);+ if ((X & 3) === 0) p.glow(x, y + 1, 7, C[5], (glint ? 0.22 : 0.1) * e);}}diff --git a/src/fx/water/drip.js b/src/fx/water/drip.jsindex d10fecb..ac2ede2 100644--- a/src/fx/water/drip.js+++ b/src/fx/water/drip.js@@ -1,82 +1,127 @@-import { PAL, seg, ease, wrap, burst } from "../../core/index.js";-import { fit, ripple, landTime, STONE } from "./_lib.js";+// The bead swelling at the tip and the falling drop's tail follow Sprite Fusion's open-source blood+// (https://www.spritefusion.com/pixel-art-vfx/blood), MIT License, Copyright (c) 2026 Hugo Duprez.+import { fit, clamp, smooth, ease, TAU, WHITE } from "../../core/index.js";+import { WATER, bead, ring, rock } 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.",+ desc: "A bead swells under a wet stone tip and catches the light, pinches off, falls stretched by its speed and plinks into a puddle with a crown, a ring and a tiny rebound.",tags: ["water", "drip", "drop", "puddle", "cave", "ambient", "loop"],- size: [32, 72],- origin: [16, 66],- duration: 1.8,+ size: [72, 88],+ origin: [36, 78],+ duration: 1.6,loop: true,fps: 30,bg: "ground",- options: { palette: PAL.water, height: 60, puddle: 11, seed: 3 },+ options: { palette: WATER, height: 62, source: true, seed: 1 },};-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."];+const D = meta.duration, SY = 0.28, G = 760, LET = 0.78, PRX = 20;++// the stone the water gathers on: a lump of ceiling rock tapering to a dripstone point, lit on its left, a dark+// rim, a wet streak running down to the point+function dripstone(p, H) {+ const ST = rock(), top = -H - 14;+ p.shade(-24, top, 22, -H + 0.5, (x, y, out) => {+ // a ragged underside of ceiling rock that hangs down into a short dripstone, its point at x = 0+ const under = top + 7 + Math.sin(x * 0.45) * 1.2 + Math.sin(x * 1.3 + 1) * 0.6 - Math.abs(x + 4) * 0.12, cone = -H - Math.abs(x) * 1.25;+ const bottom = Math.max(under, Math.min(cone, -H)), span = x < 0 ? 24 : 22;+ if (y > bottom || Math.abs(x) > span - Math.max(0, top + 3 - y) * 4) return;+ const rim = y > bottom - 1 || Math.abs(x) > span - 1, lx = (x + 24) / 46, v = (y - top) / 14;+ out.c = rim ? ST[0] : v < 0.25 ? ST[1] : y > under && Math.abs(x) < 6 ? (x < 0 ? ST[4] : ST[2]) : lx < 0.3 ? ST[4] : lx < 0.62 ? ST[3] : ST[2];+ if (!rim && Math.abs(x - 9 - (y - top) * 0.4) < 0.5 && v > 0.3 && v < 0.7) out.c = ST[0];+ });+ // a wet streak down to the point, catching the light+ for (let y = -H - 7; y < -H; y++) p.px(-1, y, y > -H - 3 ? C_WET[1] : C_WET[0]);+ p.px(-1, -H - 2, WHITE);+}+const C_WET = ["#5d6a86", "#9fb6d6"].map((h) => parseInt(h.slice(1, 3), 16) | (parseInt(h.slice(3, 5), 16) << 8) | (parseInt(h.slice(5, 7), 16) << 16) | 0xff000000);++// the puddle: dark see-through water with a lit far edge, the drop's light in it+function puddle(p, C) {+ const ry = PRX * SY;+ for (let Y = Math.floor(-ry); Y < ry; Y++)+ for (let X = -PRX; X < PRX; X++) {+ const x = X + 0.5, y = Y + 0.5, d = (x / PRX) ** 2 + (y / ry) ** 2;+ if (d > 1) continue;+ p.blend(x, y, C[1], 0.72 * Math.min(1, (1 - d) * 5));+ }+ // the far edge catches the light in one fine line+ for (let X = -PRX + 3; X < PRX - 3; X++) {+ const x = X + 0.5, y = -Math.sqrt(1 - (x / PRX) ** 2) * ry;+ p.dot(x, y + 0.5, Math.abs(x) < PRX * 0.5 ? C[4] : C[3], 0.95);+ }+}++export function drawBack(p, t, o) {+ const C = fit(o.palette, 8);+ puddle(p, C);+ const u = t - landAt(o.height);+ if (u >= 0) ring(p, 0, 0, 2 + 17 * ease.outCubic(u / 0.75), SY, 1.1 * (1 - u / 0.75), C, { n: 2, gap: 2.5, half: -1, seed: 1, wob: 0.4 });+ const v = t - landAt(o.height) - REBOUND - BACK;+ if (v >= 0) ring(p, 0, 0, 1.5 + 9 * ease.outCubic(v / 0.5), SY, 0.9 * (1 - v / 0.5), C, { n: 1, half: -1, seed: 2 });+}++const landAt = (H) => LET + Math.sqrt((2 * H) / G);+const REBOUND = 0.06, BACK = 0.2;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);+ const C = fit(o.palette, 8), H = o.height, land = landAt(H);+ if (o.source) dripstone(p, H);+ // the bead swells at the tip, wobbling, and catches the light; its neck stretches before it lets go+ if (t < LET) {+ const k = t / LET, r = 0.7 + 2.3 * ease.inQuad(k), wob = 0.15 * Math.sin(t * 26) * k, neck = smooth(0.82, 1, k) * 2.5;+ const cy = -H + r + neck;+ if (neck > 0.2) p.line(0, -H, 0, cy - r, C[5]);+ p.ellipse(0, cy, r * (1 - wob), r * (1 + wob) + 0.3 * k, (d, a) => (d > 0.72 ? (Math.cos(a) < 0 && Math.sin(a) < 0.3 ? C[5] : C[3]) : d < 0.35 && Math.cos(a) > 0 ? C[6] : C[4]));+ if (r > 1) p.px(-r * 0.4, cy - r * 0.45, WHITE);+ p.glow(0, cy, 4 + r * 2, C[5], 0.14 + 0.14 * k);} 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]);+ // a little of it springs back up the tip after it lets go+ const s = (t - LET) / 0.15;+ if (s < 1) p.ellipse(0, -H + 0.8, 1.2 * (1 - s * 0.6), 1 + Math.sin(s * Math.PI) * 0.8, C[4]);}- // 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 fall, stretched by its speed+ const f = t - LET;+ if (f > 0 && t < land) {+ const y = -H + 3 + 0.5 * G * f * f, vy = G * f;+ bead(p, 0, y, 0, vy, 3, C);+ p.glow(0, y, 6, C[5], 0.2);}- // 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]);+ // the plink: a white fleck, a little crown thrown up, the near half of the ring, light+ const u = t - land;+ if (u >= 0) {+ ring(p, 0, 0, 2 + 17 * ease.outCubic(u / 0.75), SY, 1.1 * (1 - u / 0.75), C, { n: 2, gap: 2.5, half: 1, hot: u < 0.08, seed: 1, wob: 0.4, glint: u < 0.5 ? 1 - u * 2 : 0 });+ if (u < 0.06) {+ p.px(0, 0, WHITE);+ p.px(-1, 0, C[6]);+ p.px(1, 0, C[6]);+ p.glow(0, -1, 10, C[5], 0.5 * (1 - u / 0.06));+ }+ // the crown: three flecks thrown out and back+ for (const [vx, vh] of [[-26, 70], [24, 64], [-6, 90]]) {+ const h = vh * u - 0.5 * G * u * u;+ if (h > 0 && u < 0.3) p.px(vx * u, -h, u < 0.1 ? WHITE : C[6]);+ }+ // the rebound: a bead pops up out of the middle and drops back+ const r = u - REBOUND, h = 52 * r - 0.5 * G * 0.5 * r * r * 2;+ if (r > 0 && h > 0) {+ p.line(0, -1, 0, -h + 1, C[5]);+ p.circle(0, -h, 1.1, C[6]);+ p.px(0, -h - 1, WHITE);+ }+ const v = u - REBOUND - BACK;+ if (v >= 0) ring(p, 0, 0, 1.5 + 9 * ease.outCubic(v / 0.5), SY, 0.9 * (1 - v / 0.5), C, { n: 1, half: 1, seed: 2, hot: v < 0.06 });+ p.glow(0, 0, 18, C[4], 0.22 * (1 - clamp(u / 0.6)));}- 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);+ // the tip and the drop shimmer in the puddle+ const sh = Math.sin(t * 20) > 0 ? 0 : 1;+ p.px(-1 + sh, 2, C[4]);+ if (f > 0 && t < land) {+ const ry = 2 + 0.5 * G * f * f * 0.04;+ p.px(sh, Math.min(4, ry), C[5]);}+ // the wet light under the tip and in the puddle+ p.glow(0, -H + 2, 8, C[5], 0.16);+ p.glow(0, 0, 26, C[3], 0.14);}diff --git a/src/fx/water/fountain.js b/src/fx/water/fountain.jsindex 70b7be1..a18a887 100644--- a/src/fx/water/fountain.js+++ b/src/fx/water/fountain.js@@ -1,84 +1,156 @@-import { PAL, cycle, tileNoise, fract, TAU } from "../../core/index.js";-import { fit, ripple, drop, landTime, STONE } from "./_lib.js";+// The basin's caustic light (two warped sine nets, light where they cross zero) is adapted from Sprite Fusion's+// open-source bubbles (https://www.spritefusion.com/pixel-art-vfx/bubbles), MIT License, Copyright (c) 2026 Hugo Duprez.+import { fit, cycle, tileNoise, clamp, smooth, rand, TAU, WHITE } from "../../core/index.js";+import { WATER, bead, ring, rock } 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.",+ desc: "A stone basin; a jet rises from its spout and blooms into glassy arcs that break into beads, fall back and plink into the water with rings.",tags: ["water", "fountain", "jet", "basin", "prop", "ambient", "loop"],- size: [72, 72],- origin: [36, 66],- duration: 1.2,+ size: [120, 104],+ origin: [60, 96],+ duration: 2,loop: true,fps: 30,bg: "ground",- options: { palette: PAL.water, height: 46, seed: 8 },+ options: { palette: WATER, seed: 3 },};-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]];+const D = meta.duration, SY = 0.34, G = 600, RIM = 10, RX = 36, IN = 29.5, JET = 54, ARCS = 12;+// the basin stands on the floor: its base ellipse touches y = 0 at the front; heights are measured from that plane+const BY = -RX * SY, LEVEL = RIM - 1.2;-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]);- }+// the arcs: water thrown out of the top of the jet in every direction, each a parabola back down to the basin+const arcs = (S) =>+ Array.from({ length: ARCS }, (_, i) => {+ const a = ((i + 0.5) / ARCS) * TAU + rand(i, S) * 0.25, vr = 38 + 14 * rand(i, S + 1), vh = 30 + 26 * rand(i, S + 2);+ const tl = (vh + Math.sqrt(vh * vh + 2 * G * (JET - LEVEL))) / G;+ return { a, vr, vh, tl, ca: Math.cos(a), sa: Math.sin(a) };});- // 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);+// a point along an arc tau seconds into its flight: screen x, y and the height above the floor+const along = (q, tau) => {+ const r = q.vr * tau, h = JET + q.vh * tau - 0.5 * G * tau * tau;+ return [q.ca * r, BY + q.sa * r * SY - h, h];+};++// the stone basin: a wide rim lit toward the light with a dark line round both edges, a wall of stone blocks+// below its near side (lit left, shaded right) standing on the floor+const inEll = (x, y, rx, cy) => (x / rx) ** 2 + ((y - cy) / (rx * SY)) ** 2 <= 1;+function basin(p, ST, half) {+ const cy = BY - RIM, ry = RX * SY;+ p.shade(-RX - 1, cy - ry - 1, RX + 1, 1, (x, y, out) => {+ if (inEll(x, y, RX, cy)) {+ if (inEll(x, y, IN, cy)) return;+ const near = y > cy;+ if (near !== half > 0) return;+ const outer = !inEll(x, y - 1, RX, cy) || !inEll(x, y + 1, RX, cy) || !inEll(x - 1, y, RX, cy) || !inEll(x + 1, y, RX, cy);+ const inner = inEll(x, y - 1, IN, cy) || inEll(x, y + 1, IN, cy) || inEll(x - 1, y, IN, cy) || inEll(x + 1, y, IN, cy);+ const a = Math.atan2((y - cy) / ry, x / RX), lit = -Math.cos(a) * 0.65 - Math.sin(a) * 0.45;+ out.c = outer ? ST[0] : inner ? (y < cy ? ST[2] : ST[1]) : lit > 0.4 ? ST[5] : lit > -0.05 ? ST[4] : lit > -0.45 ? ST[3] : ST[2];+ return;}+ // the wall, under the near half of the rim+ if (half < 0 || Math.abs(x) >= RX) return;+ const dx = x / RX, top = cy + Math.sqrt(1 - dx * dx) * ry, base = top + RIM;+ if (y < top || y > base) return;+ const u = Math.asin(clamp(dx)) * RX * 0.62, block = ((((u + 40) / 9) % 1) + 1) % 1, row = y - top, course = row > RIM * 0.5 ? 1 : 0;+ const joint = (((((u + 40 + course * 4.5) / 9) % 1) + 1) % 1) < 0.1;+ out.c = y > base - 1 || Math.abs(x) > RX - 1 || row < 1 ? ST[0] : joint || Math.abs(row - RIM * 0.5) < 0.5 ? ST[1] : dx < -0.4 ? ST[4] : dx < 0.3 ? ST[3] : ST[2];+ if (row >= 1 && row < 2 && !joint) out.c = dx < 0 ? ST[2] : ST[1];});- 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);+}++// the water in the basin: dark and see-through, a lit band at the far side, caustic light swimming in it+function pool(p, C, ph) {+ const rx = IN, ry = rx * SY, cy = BY - LEVEL, T = ph * TAU;+ for (let Y = Math.floor(cy - ry); Y < cy + ry; Y++)+ for (let X = -Math.ceil(rx); X < rx; X++) {+ const x = X + 0.5, y = Y + 0.5, dx = x / rx, dy = (y - cy) / ry, d = dx * dx + dy * dy;+ if (d > 1) continue;+ p.blend(x, y, dy < -0.55 ? C[3] : C[1], dy < -0.55 ? 0.8 : 0.85);+ const u = x * 0.25 + 1.6 * Math.sin(y * 0.6 + T), w = y * 0.7 + 1.6 * Math.sin(x * 0.14 - T * 2);+ const f = Math.max(0, 1 - Math.abs(Math.sin(u) + Math.sin(w)) * 2.6) * (1 - d);+ if (f > 0.35) p.light(x, y, C[5], 0.3 * f);+ }+}++export function drawBack(p, t, o) {+ const C = fit(o.palette, 8), ph = t / D, S = o.seed, ST = rock(), Q = arcs(S);+ basin(p, ST, -1);+ pool(p, C, ph);+ // the arcs on the far side, dimmer, behind the jet+ for (const q of Q) if (q.sa < 0) arc(p, C, q, ph, true);+}++// one arc: a glassy stream that thins as it falls and breaks into beads at the end; beads slide down it+function arc(p, C, q, ph, back) {+ let prev = null;+ for (let tau = 0; tau <= q.tl; tau += 0.012) {+ const [x, y] = along(q, tau), u = tau / q.tl;+ if (prev && u < 0.66) p.line(prev[0], prev[1], x, y, back ? (u < 0.25 ? C[5] : C[4]) : u < 0.2 ? WHITE : u < 0.45 ? C[6] : C[5]);+ prev = [x, y];+ }+ // the beads it breaks into, sliding down at the water's own speed+ for (let k = 0; k < 6; k++) {+ const u = ((ph * 2 + k / 6) % 1) * 0.42 + 0.58, tau = u * q.tl, [x, y] = along(q, tau), vy = (q.vh - G * tau) * -1 + q.sa * q.vr * SY;+ bead(p, x, y, q.ca * q.vr, vy, back ? 1 : k % 3 === 0 ? 2 : 1, back ? [C[0], C[1], C[2], C[2], C[3], C[4], C[5], C[5]] : C);+ }+ // and the ones sliding along the stream itself catch the light+ const g = ((ph * 4 + q.a) % 1) * 0.6, [gx, gy] = along(q, g * q.tl);+ p.px(gx, gy, WHITE);+ if (!back) p.glow(gx, gy, 3, C[5], 0.3);+}++export function draw(p, t, o) {+ const C = fit(o.palette, 8), ph = t / D, S = o.seed, ST = rock(), Q = arcs(S), T = ph * TAU;+ // the spout: a little stone stem in the middle of the basin+ p.shade(-3.5, BY - 16, 3.5, BY - LEVEL + 0.5, (x, y, out) => {+ const w = y < BY - 14 ? 3.4 : 2.2;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];+ out.c = Math.abs(x) > w - 0.8 || y < BY - 15.5 ? ST[0] : x < -0.6 ? ST[4] : x < 0.8 ? ST[3] : ST[2];});- // 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);+ // the jet: a glassy column, white down its middle, wobbling a little at the top+ p.shade(-3, BY - JET - 1, 3, BY - 16, (x, y, out) => {+ const v = (BY - 16 - y) / (JET - 16), sway = Math.sin(T * 2 + v * 5) * 0.5 * v, w = 1.3 + 0.5 * v + 0.3 * Math.sin(T * 3 + y * 0.4), q = (x - sway) / w;+ if (Math.abs(q) > 1) return;+ const n = tileNoise(x * 0.9, y * 0.15 + ph * 16, 0, 16, S);+ out.c = q < -0.4 ? C[6] : q < 0.35 ? (n > -0.3 ? WHITE : C[6]) : C[5];+ });+ // the bloom where it opens out at the top+ p.circle(0, BY - JET - 1, 2.4, C[6]);+ p.circle(-0.4, BY - JET - 1.5, 1.4, WHITE);+ p.glow(0, BY - JET, 22, C[5], 0.46 + 0.06 * Math.sin(T * 4));+ p.glow(0, BY - JET - 1, 8, WHITE, 0.3);+ // glints wink along the arcs+ cycle(t, D, 10, S + 30, (g) => g.range(0.2, 0.35), (age, life, r) => {+ const q = Q[Math.floor(r.next() * ARCS)], [x, y] = along(q, r.range(0.1, 0.7) * q.tl), k = Math.sin((Math.PI * age) / life);+ if (q.sa < -0.3) return;+ p.px(x, y, WHITE);+ if (k > 0.6) for (const [dx, dy] of [[1, 0], [-1, 0], [0, 1], [0, -1]]) p.px(x + dx, y + dy, C[6]);+ p.glow(x, y, 5, C[5], 0.4 * k);+ });+ // foam where the jet leaves the spout+ for (let i = 0; i < 4; i++) p.px(Math.sin(T * 3 + i * 1.7) * 2.5, BY - 16 - (i % 2), i % 2 ? C[6] : WHITE);+ // the arcs on the near side, in front of the jet+ for (const q of Q) if (q.sa >= 0) arc(p, C, q, ph, false);+ // where they come down: near halves of the rings, flecks and tiny crowns thrown up, light on the water+ Q.forEach((q, i) => {+ const f = (ph * 2 + rand(i, S + 9)) % 1, [x, y] = along(q, q.tl);+ ring(p, x, y, 2 + f * 8, SY, 0.8 * Math.pow(1 - f, 1.3), C, { n: 1, half: 1, seed: i });+ const g = (ph * 6 + rand(i, S + 10)) % 1;+ if (g < 0.15) p.px(x, y - 1, WHITE);+ if (g < 0.3 && q.sa > -0.2) p.line(x, y - 1, x + (rand(i, S + 11) - 0.5) * 2, y - 1 - 3 * (1 - g / 0.3), C[6]);+ p.glow(x, y, 6, C[5], 0.18 * (1 - g));+ });+ basin(p, ST, 1);+ // a fine mist hangs round the bloom+ cycle(t, D, 16, S + 20, (g) => g.range(0.8, 1.4), (age, life, r) => {+ const k = age / life, a = r.range(0, TAU), rr = r.range(4, 20) + k * 6, x = Math.cos(a) * rr, y = BY - JET + r.range(-4, 16) + k * 10;+ if (k > 0.75 && r.next() < (k - 0.75) * 4) return;+ p.px(x, y, r.next() < 0.4 ? WHITE : C[6]);+ });+ // light: the jet, and the basin water lit from above+ p.glowLine(0, BY - 16, 0, BY - JET, 10, C[5], 0.18);+ p.glow(0, BY - LEVEL - 2, 46, C[4], 0.26 + 0.03 * Math.sin(T * 2));+ p.glow(0, BY - LEVEL - 20, 30, C[5], 0.12);}diff --git a/src/fx/water/geyser.js b/src/fx/water/geyser.jsindex 1faabd5..2840d89 100644--- a/src/fx/water/geyser.js+++ b/src/fx/water/geyser.js@@ -1,96 +1,257 @@-import { PAL, stream, burst, seg, ease, clamp, tileNoise, noise2, bump, WHITE } from "../../core/index.js";-import { fit, ripple, drop, landTime } from "./_lib.js";+// The column (a banded white core, strands running through it, light down its length) and the slam with its+// floor ring follow Sprite Fusion's open-source holy-light (https://www.spritefusion.com/pixel-art-vfx/holy-light),+// MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Lights, P, Rng, fit, clamp, smooth, ease, noise, noise2, rand, TAU, WHITE } from "../../core/index.js";+import { WATER, Drops, Ripples, Mist, ring, lace, billow } 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,+ desc: "A pool heaves and burbles faster and faster, then blasts a white column of water skyward with a churning foam head; it rains back down in drops and steam, slumps and sputters out.",+ tags: ["water", "geyser", "eruption", "steam", "column", "nature", "one-shot"],+ size: [184, 168],+ origin: [92, 146],+ duration: 5,loop: false,fps: 30,bg: "ground",- options: { palette: PAL.water, height: 86, seed: 9 },+ options: { palette: WATER, height: 100, seed: 4 },};-const ERUPT = 0.5, G = 380;+const SY = 0.22, G = 820, ERUPT = 1.15, FALL = 2.6, GONE = 3.3;+// small spurts while it builds, and the sputters after: [time, height]+const SPURTS = [[0.46, 7], [0.72, 12], [0.92, 9], [1.04, 15], [GONE + 0.15, 15], [GONE + 0.55, 8]];-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]);+export function create(o) {+ const C = fit(o.palette, 8), R = new Rng(o.seed), HMAX = o.height, S = o.seed;+ const ps = new Particles({ rng: R }), mist = new Mist(), lights = new Lights(), rings = new Ripples({ sy: SY });+ const plinks = [], pops = [];+ const V0 = Math.sqrt(2 * G * HMAX);+ let t = 0;+ const poolR = (tt) => (12 + 7 * smooth(0, 1, tt) + 15 * ease.outCubic(clamp((tt - ERUPT) / 1.2))) * (1 - 0.25 * smooth(GONE, 4.6, tt));+ const poolK = (tt) => smooth(0, 0.2, tt) * (1 - smooth(4.0, 4.85, tt));+ const drops = new Drops({+ sy: SY,+ g: G,+ onLand: (d) => {+ const inPool = Math.hypot(d.x, d.z) < poolR(t);+ rings.add(d.x, d.z, 0.6, (inPool ? 2.5 : 1.5) + d.s * 1.6, 0.32 + d.s * 0.1, { n: 1, k: inPool ? 0.95 : 0.7, hot: 0.05 });+ plinks.push({ x: d.x, y: d.z * SY, s: d.s, age: 0 });+ if (d.s > 1 && !d.small)+ for (let i = 0; i < 2; i++) {+ const a = R.range(0, TAU), v = R.range(8, 28);+ drops.add({ x: d.x, z: d.z, h: 0.5, vx: Math.cos(a) * v, vz: Math.sin(a) * v, vh: R.range(45, 95), s: 1, small: true, life: 1 });+ }+ },+ });+ // how tall the column stands: a fast blast, surging while it holds, slumping when the pressure goes+ const top = (tt) => {+ if (tt < ERUPT || tt > GONE) return 0;+ return HMAX * ease.outCubic(clamp((tt - ERUPT) / 0.3)) * (0.93 + 0.07 * noise(tt * 2.2, S)) * (1 - ease.inQuad(clamp((tt - FALL) / (GONE - FALL))));+ };+ const head = (tt) => smooth(ERUPT + 0.08, ERUPT + 0.3, tt) * (1 - smooth(FALL + 0.1, FALL + 0.45, tt));+ const spurt = (tt) => {+ let h = 0;+ for (const [s0, hs] of SPURTS) h = Math.max(h, hs * Math.sin(Math.PI * clamp((tt - s0) / 0.2)));+ return h;+ };+ const done = new Set(), once = (key, at) => !done.has(key) && t >= at && done.add(key);+ const emit = (rate, dt) => R.chance(Math.min(1, rate * dt));++ // the column: a white core banded out to blue edges, shadowed on the right; 1 px strands whose streaks run up+ // in jet time (fast and long low down, bunching where the water slows near the top); it spreads as it rises,+ // its sides ragged and running, a sway through it, light all the way up+ function column(p, H, thin) {+ if (H < 1) return;+ const tau = (h) => (V0 - Math.sqrt(Math.max(0, V0 * V0 - 2 * G * Math.min(h, HMAX * 0.96)))) / G;+ p.shade(-22, -H - 2, 22, 0, (x, y, out) => {+ const h = -y, v = h / H, sway = noise(t * 1.6 + h * 0.025, S + 5) * 2.5 * v;+ const rag = noise2(h * 0.2 - t * 11, x < sway ? 3 : 7, S + 6) * (0.5 + 1.8 * v);+ const w = (3.6 + 7.5 * Math.pow(v, 1.8)) * thin + rag, q = (x - sway) / Math.max(1, w), aq = Math.abs(q);+ if (aq > 1) return;+ const X = Math.floor(x), streak = noise2(X * 1.618 + 0.3, (tau(h) - t) * 14, S), body = noise2(Math.floor((x + 40) / 2) * 2.3, (tau(h) - t) * 5, S + 1);+ let lvl = aq < 0.42 ? 0 : aq < 0.7 ? 1 : aq < 0.9 ? 2 : 3;+ if (q > 0.38) lvl++;+ if (streak > 0.28) lvl--;+ if (body < -0.4) lvl++;+ out.c = [WHITE, C[6], C[5], C[4], C[3]][clamp(lvl, 0, 4)];});+ p.glowLine(0, 0, 0, -H, 16 + 8 * thin, C[5], 0.12 * thin);}- // 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);++ // the head: water boiling over at the top and falling back round the column in an umbrella of streaks, foam+ // billows churning in it, shadowed underneath, lit on top+ function foamHead(p, H, k, back) {+ if (k <= 0.01 || H < 4) return;+ if (back) {+ // the umbrella: streaks pouring off the rim of the head, running down and thinning out+ for (let i = 0; i < 16; i++) {+ const side = i % 2 ? 1 : -1, x0 = side * (5 + 9 * rand(i, S + 20)) * k, len = (14 + 26 * rand(i, S + 21)) * k, speed = 70 + 50 * rand(i, S + 22);+ for (let j = 0; j < 3; j++) {+ const f = (t * speed / len + j / 3 + rand(i, S + 23)) % 1, y0 = -H + 2 + f * len, x = x0 + side * f * f * 6, L = 1 + 4 * f * (1 - f) * 2;+ if (f < 0.85) p.line(x, y0, x + side * 0.6, y0 + L, f < 0.4 ? C[6] : f < 0.7 ? C[5] : C[4]);+ }+ }}- });- 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];+ for (let i = 0; i < 12; i++) {+ const a = (i / 12) * TAU + t * (i % 2 ? 1.3 : -1.1), z = Math.sin(a);+ if (z < 0 !== back) continue;+ const rho = (3 + 7 * rand(i, S)) * k, x = Math.cos(a) * rho * 1.25 + noise(t * 3 + i, S + 8) * 2.5;+ const y = -H + z * rho * 0.45 + (rho / 10) * 4 - 4 * (1 - rho / (10 * k)) + noise(t * 3 + i + 50, S + 9) * 2.5, r = (2 + 2.6 * rand(i, S + 2) + 0.7 * Math.sin(t * 7 + i)) * k;+ if (back) billow(p, x, y, r, [C[0], C[1], C[2], C[3], C[3], C[4], C[5], C[5]]);+ else {+ p.circle(x + r * 0.15, y + r * 0.25, r, C[4]);+ p.circle(x, y, r * 0.82, rho > 6 * k ? C[5] : C[6]);+ p.circle(x - r * 0.25, y - r * 0.3, r * 0.5, WHITE);}- 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]);}+ if (!back) p.glow(0, -H - 2, 38, C[5], 0.34 * k);}- 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));++ return {+ update(dt) {+ t += dt;+ const H = top(t), hk = head(t), k = t / ERUPT;+ // building: bubbles burst on the heaving mound, faster and faster, steam starts to lift+ if (t < ERUPT && emit(1.5 + 9 * k * k, dt)) {+ const a = R.range(0, TAU), r = R.range(0, 7), x = Math.cos(a) * r, z = Math.sin(a) * r;+ pops.push({ x, y: z * SY - R.range(1, 3), age: 0, r: R.range(1, 2) });+ rings.add(x, z, 1, R.range(5, 9), 0.55, { n: 1, k: 0.85 });+ for (let i = 0; i < R.int(1, 3); i++) drops.add({ x, z, h: 2, vx: R.range(-25, 25), vz: R.range(-15, 15), vh: R.range(50, 120), s: 1, small: true, life: 1 });+ }+ if (t < ERUPT && emit(3 + 7 * k, dt)) mist.add(R.range(-8, 8), -R.range(1, 5), R.range(-10, 10), -R.range(6, 18), 2, R.range(5, 9), R.range(0.9, 1.5), C[6], 0.22);+ for (const [s0, hs] of SPURTS)+ if (once("spurt" + s0, s0 + 0.08))+ for (let i = 0; i < 3 + Math.round(hs / 4); i++) {+ const a = R.range(0, TAU), v = R.range(10, 40);+ drops.add({ x: 0, z: 0, h: hs * 0.8, vx: Math.cos(a) * v, vz: Math.sin(a) * v, vh: R.range(20, 90), s: R.chance(0.3) ? 2 : 1 });+ }+ if (once("erupt", ERUPT)) {+ // the blast: light, a ring thrown across the ground, water flung high, steam rolling out+ lights.add(0, -26, 64, C[5], 0.85, 0.6);+ lights.add(0, -4, 28, WHITE, 0.75, 0.1);+ rings.add(0, 0, 6, 40, 1.2, { n: 2, gap: 3, k: 1.2, hot: 0.12, glint: 1 });+ for (let i = 0; i < 44; i++) {+ const a = R.range(0, TAU), v = R.range(30, 120);+ drops.add({ x: Math.cos(a) * 3, z: Math.sin(a) * 3, h: R.range(2, 10), vx: Math.cos(a) * v, vz: Math.sin(a) * v, vh: R.range(180, 400), s: R.chance(0.15) ? 3 : R.chance(0.35) ? 2 : 1, delay: R.range(0, 0.12) });+ }+ for (let i = 0; i < 12; i++) {+ const s = i % 2 ? 1 : -1;+ mist.add(s * R.range(3, 9), -R.range(1, 6), s * R.range(30, 80), -R.range(4, 18), 3, R.range(9, 14), R.range(1.2, 1.9), R.chance(0.5) ? C[6] : WHITE, 0.3, R.range(0, 0.15));+ }+ for (let i = 0; i < 14; i++) ps.spawn(P.STAR, R.range(-16, 16), -R.range(8, 80), R.range(-10, 10), -6, R.range(0.3, 0.7), R.chance(0.5) ? WHITE : C[6], R.range(1, 2.6), R.range(0.05, 0.5));+ }+ // holding: the head sheds drops that rain back down, spray hangs off the column, steam pours off the top+ if (hk > 0) {+ if (emit(60 * hk, dt)) {+ const a = R.range(0, TAU), v = R.range(10, 60);+ drops.add({ x: R.range(-9, 9), z: R.range(-4, 4), h: H + R.range(-8, 3), vx: Math.cos(a) * v, vz: Math.sin(a) * v, vh: R.range(-40, 60), s: R.chance(0.08) ? 3 : R.chance(0.3) ? 2 : 1 });+ }+ if (emit(9 * hk, dt)) mist.add(R.range(-8, 8), -H + R.range(-6, 2), R.range(-34, 34), -R.range(14, 34), 3, R.range(8, 13), R.range(0.9, 1.4), R.chance(0.6) ? C[6] : WHITE, 0.2);+ if (emit(5 * hk, dt)) mist.add(R.sign() * R.range(3, 9), -R.range(1, 6), R.sign() * R.range(20, 50), -R.range(2, 10), 3, R.range(8, 12), R.range(1, 1.6), C[6], 0.22);+ if (emit(40 * hk, dt)) {+ const s = R.sign(), hh = R.range(8, H * 0.95);+ ps.spawn(P.FLAKE, s * (3 + 6 * Math.pow(hh / H, 1.8)), -hh, s * R.range(10, 45), R.range(-20, 10), R.range(0.6, 1.2), R.chance(0.5) ? WHITE : C[6], R.range(0.6, 1.3));+ }+ if (emit(4 * hk, dt)) rings.add(R.range(-2, 2), R.range(-2, 2), 4, poolR(t) * R.range(0.7, 1), 0.9, { n: 1, k: 0.8 });+ if (emit(7 * hk, dt)) ps.spawn(P.STAR, R.range(-14, 14), -R.range(10, H + 8), R.range(-6, 6), -4, R.range(0.25, 0.55), R.chance(0.4) ? WHITE : C[6], R.range(0.8, 2.2), 0);+ }+ if (once("collapse", FALL + 0.12)) {+ // the head falls apart: a heavy rain of drops all at once+ for (let i = 0; i < 40; i++) {+ const a = R.range(0, TAU), v = R.range(15, 80);+ drops.add({ x: R.range(-6, 6), z: R.range(-3, 3), h: top(t) + R.range(-8, 4), vx: Math.cos(a) * v, vz: Math.sin(a) * v, vh: R.range(-40, 60), s: R.chance(0.12) ? 3 : R.chance(0.35) ? 2 : 1, delay: R.range(0, 0.25) });+ }+ for (let i = 0; i < 6; i++) mist.add(R.range(-8, 8), -top(t) + R.range(-6, 6), R.range(-34, 34), -R.range(10, 26), 4, R.range(9, 13), R.range(0.8, 1.2), C[6], 0.18);+ }+ for (let i = pops.length - 1; i >= 0; i--) if ((pops[i].age += dt) > 0.12) pops.splice(i, 1);+ for (let i = plinks.length - 1; i >= 0; i--) if ((plinks[i].age += dt) > 0.14) plinks.splice(i, 1);+ drops.update(dt);+ rings.update(dt);+ mist.update(dt);+ ps.update(dt);+ lights.update(dt);+ },+ drawBack(p) {+ // the pool: dark see-through water, a lit far rim+ const pr = poolR(t), pk = poolK(t);+ if (pk > 0)+ p.each(-pr, -pr * SY, pr, pr * SY, (x, y, sx, sy) => {+ const d = (x / pr) ** 2 + (y / (pr * SY)) ** 2;+ if (d > 1) return;+ p.blendPx(sx, sy, d < 0.15 ? C[2] : C[1], 0.6 * pk * Math.min(1, (1 - d) * 4));+ if (y < 0 && d > 0.78 && d < 0.95) p.blendPx(sx, sy, C[4], 0.7 * pk);+ });+ rings.draw(p, C, -1);+ const u = (t - ERUPT) / 0.4;+ if (u > 0 && u < 1) ring(p, 0, 0.5, 6 + 42 * ease.outCubic(u), SY, 1.5 * (1 - u), C, { n: 3, gap: 1.6 + 2 * u, half: -1, hot: u < 0.3, seed: 9 });+ foamHead(p, top(t), head(t), true);+ drops.draw(p, C, "back");+ },+ draw(p) {+ const H = top(t), hk = head(t), k = clamp(t / ERUPT), thin = smooth(ERUPT, ERUPT + 0.12, t) * (1 - 0.55 * smooth(FALL, GONE, t));+ rings.draw(p, C, 1);+ const u = (t - ERUPT) / 0.4;+ if (u > 0 && u < 1) ring(p, 0, 0.5, 6 + 42 * ease.outCubic(u), SY, 1.5 * (1 - u), C, { n: 3, gap: 1.6 + 2 * u, half: 1, hot: u < 0.3, seed: 9 });+ // foam rides the pool round the foot of the column+ const fk = smooth(ERUPT, ERUPT + 0.3, t) * (1 - smooth(GONE - 0.3, 4.4, t));+ if (fk > 0) lace(p, 0, 0, 8 + 10 * fk, (8 + 10 * fk) * SY + 0.5, fk, C, t, S);+ // the heaving mound while it builds, beating faster+ if (t < ERUPT + 0.05) {+ const beat = Math.pow(Math.max(0, Math.sin(t * (8 + 18 * k * k))), 3), rd = 4 + 3.5 * k + 1.5 * beat, hd = 1.5 + 3 * k + 3 * beat;+ p.shade(-rd - 1, -hd - 1, rd + 1, 0.5, (x, y, out) => {+ const dx = x / rd, dy = y / hd, d = dx * dx + dy * dy;+ if (d > 1 || y > 0.5) return;+ // water heaving up: a white rim where it faces the light, a tinted body, shadow low on the right+ const lit = -dx * 0.7 - dy * 0.7, rim = d > 0.68;+ out.c = rim ? (lit > 0.3 ? WHITE : lit > -0.15 ? C[6] : C[4]) : lit > 0.55 ? C[6] : lit > 0.12 ? C[5] : lit > -0.3 ? C[4] : C[3];+ });+ p.px(-rd * 0.35, -hd * 0.6, WHITE);+ p.glow(0, -5, 16 + 16 * k + 8 * beat, C[5], 0.06 + 0.12 * k + 0.12 * beat);+ }+ // spurts while it builds and sputters as it dies: a short white jet with a bead on top+ const sp = spurt(t);+ if (sp > 1 && H < 1) {+ p.shade(-2, -sp - 1, 2, 0, (x, y, out) => {+ const q = x / (1 + 0.8 * (1 + y / sp));+ if (Math.abs(q) > 1) return;+ out.c = q < -0.3 ? C[6] : q < 0.35 ? WHITE : C[5];+ });+ p.circle(0, -sp, 1.3, C[6]);+ p.px(0, -sp - 1, WHITE);+ p.glowLine(0, 0, 0, -sp, 8, C[5], 0.3);+ }+ column(p, H, thin);+ // the foot: billows boil out round it+ if (hk > 0 || (H > 1 && t < GONE))+ for (let i = 0; i < 7; i++) {+ const a = (i / 7) * TAU + t * 2.1, r = 4 + 2 * Math.sin(t * 5 + i * 1.7), x = Math.cos(a) * r * 1.3, y = Math.sin(a) * r * SY - 2;+ billow(p, x, y, (1.6 + 1.2 * rand(i, S + 4)) * Math.max(hk, thin * 0.6), C);+ }+ foamHead(p, H, hk, false);+ for (const q of pops) {+ const g = q.age / 0.12;+ for (const [dx, dy] of [[1, 0], [-1, 0], [0.7, -0.7], [-0.7, -0.7], [0, -1]]) p.dot(q.x + dx * (q.r + 3 * g), q.y + dy * (q.r + 3 * g), C[6], 1 - g);+ }+ for (const q of plinks) {+ const g = q.age / 0.14;+ if (g < 0.5) p.px(q.x, q.y, WHITE);+ if (q.s > 1) p.line(q.x, q.y - 1, q.x, q.y - 1 - 3 * (1 - g), g < 0.4 ? WHITE : C[6]);+ p.glow(q.x, q.y, 4, C[5], 0.25 * (1 - g));+ }+ drops.draw(p, C, "front");+ // the blast's first two frames: a white burst at the vent+ const f = (t - ERUPT) / 0.07;+ if (f >= 0 && f < 1) {+ p.circle(0, -4, 7 * (1 - f * 0.4), WHITE);+ p.ellipse(0, 0, 12, 2.6, (d) => (d < 0.6 ? WHITE : C[6]));+ }+ ps.draw(p);+ mist.draw(p, C[5]);+ lights.draw(p);+ // light: the column and its head, the pool round its foot+ if (H > 1) p.glowLine(0, 0, 0, -H, 26, C[4], 0.2 * thin);+ p.glow(0, -2, 46, C[4], 0.24 * Math.max(hk, 0.3 * k * (t < ERUPT ? 1 : 0)));+ p.glow(0, 2, 60, C[3], 0.12 * poolK(t));+ },+ };}diff --git a/src/fx/water/puddle-step.js b/src/fx/water/puddle-step.jsdeleted file mode 100644index 5253f61..0000000--- a/src/fx/water/puddle-step.js+++ /dev/null@@ -1,64 +0,0 @@-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.jsindex 4ae501c..fc0377a 100644--- a/src/fx/water/rain-splash.js+++ b/src/fx/water/rain-splash.js@@ -1,61 +1,168 @@-import { PAL, rng, seg, clamp, wrap } from "../../core/index.js";-import { fit, ripple, landTime } from "./_lib.js";+// The streaks falling in (a dim body, a bright head) follow Sprite Fusion's open-source rain+// (https://www.spritefusion.com/pixel-art-vfx/rain), MIT License, Copyright (c) 2026 Hugo Duprez.+import { fit, cycle, clamp, smooth, rand, TAU, WHITE } from "../../core/index.js";+import { WATER, bead, ring } 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,+ desc: "A low close-up on one puddle in the rain: big drops land in crowns that throw beads and a rebound jet, rings spread and interfere, a lamp's reflection wobbles on the water.",+ tags: ["water", "rain", "splash", "puddle", "close-up", "ambient", "loop"],+ size: [176, 80],+ origin: [88, 50],+ duration: 2.4,loop: true,fps: 30,bg: "ground",- options: { palette: PAL.water, count: 20, width: 30, seed: 4 },+ options: { palette: WATER, seed: 9 },};-const G = 520;+const D = meta.duration, SY = 0.3, RX = 92, G = 640, N = 8, LAMP = 34;++// the big drops: where each lands on the puddle (x across, z into it), when, how tall its crown stands+function drops(S) {+ return Array.from({ length: N }, (_, i) => ({+ x: (rand(i, S) - 0.5) * 120, z: (rand(i, S + 1) - 0.5) * 50, t0: ((i + 0.25 * rand(i, S + 2)) / N) * D,+ H: 10 + 4 * rand(i, S + 3), J: 7 + 4 * rand(i, S + 4), spin: rand(i, S + 5) * TAU, i,+ }));+}+const ageOf = (t, t0) => (((t - t0) % D) + D) % D;+// a ring's radius and strength at age a+const ringR = (a) => 3 + 34 * Math.pow(a / 1.8, 0.7);+const ringK = (a) => (a < 1.8 ? 1.3 * Math.pow(1 - a / 1.8, 1.3) * Math.min(1, a / 0.06) : 0);+// the crown at age a: how high its walls stand and how wide its foot is+const crownH = (a, H) => H * Math.pow(Math.sin(Math.PI * clamp(a / 0.3)), 0.8) * (a < 0.3 ? 1 : 0);+const crownR = (a) => 1.5 + 4.5 * Math.sqrt(clamp(a / 0.3));+// the rebound jet: up and back down after the crown has fallen+const jetH = (a, J) => (a > 0.26 && a < 0.56 ? J * Math.sin((Math.PI * (a - 0.26)) / 0.3) : 0);++// the water's height at a point: every ring's swell summed, so where two cross they add and cancel+function field(x, z, list) {+ let h = 0;+ for (const q of list) {+ const dx = x - q.x;+ if (dx > q.R + 10 || dx < -q.R - 10) continue;+ const d = Math.hypot(dx, z - q.z) - q.R, w = 3.6 + q.a * 3;+ if (d > 2 * w || d < -3 * w) continue;+ h += q.k * Math.cos(d * 1.1) * Math.exp(-((d / w) ** 2));+ }+ return h;+}++export function drawBack(p, t, o) {+ const C = fit(o.palette, 8), S = o.seed, ry = RX * SY, ph = t / D;+ const list = drops(S).map((q) => ({ ...q, a: ageOf(t, q.t0) })).filter((q) => q.a < 1.8).map((q) => ({ ...q, R: ringR(q.a), k: ringK(q.a) }));+ for (let Y = Math.floor(-ry); Y < ry; Y++) {+ const y = Y + 0.5, z = y / SY, act = list.filter((q) => Math.abs(z - q.z) <= q.R + 12), far = (y + ry) / (2 * ry);+ // the lamp's reflection on this row: a dash of light, its width shimmering, pushed about by the swell+ const dashW = (1.5 + far * 4) * (0.35 + 0.65 * (0.5 + 0.5 * Math.sin(Y * 1.73 + ph * TAU * 3 + Math.sin(Y * 0.61) * 3)));+ let hPrev = 0;+ for (let X = -88; X < 88; X++) {+ const x = X + 0.5, d = (x / RX) ** 2 + (y / ry) ** 2;+ if (d > 1) continue;+ const edge = Math.min(1, (1 - d) * 6);+ // the puddle: dark see-through water, the far part holding a little of the sky+ p.blend(x, y, C[0], (0.62 + 0.2 * far) * edge);+ if (far < 0.45) p.blend(x, y, C[2], 0.3 * (1 - far / 0.45) * edge);+ // its swell: every ring summed, so crests catch the light, troughs go dark, and crossings beat+ const h = act.length ? field(x, z, act) : 0, hx = h - hPrev;+ hPrev = h;+ if (h > 0.24) p.blend(x, y, h > 0.75 ? C[5] : C[4], Math.min(0.95, (h - 0.24) * 2.2) * edge);+ else if (h < -0.4) p.blend(x, y, C[0], Math.min(0.85, (-h - 0.4) * 1.8) * edge);+ if (x < LAMP - 14 || x > LAMP + 14) continue;+ const lx = Math.abs(x - LAMP - hx * 9 - Math.sin(y * 0.8 + ph * TAU * 2) * 1.4);+ if (lx < dashW) {+ const k = (1 - lx / dashW) * edge;+ p.px(X, Y, k > 0.72 ? WHITE : k > 0.35 ? C[6] : C[5]);+ p.light(x, y, C[5], 0.2 * k);+ }+ }+ }+ // the far rim of the puddle catches the light+ for (let X = -82; X < 82; X++) {+ const x = X + 0.5, y = -Math.sqrt(Math.max(0, 1 - (x / RX) ** 2)) * ry;+ p.px(X, y + 0.5, Math.abs(x - LAMP) < 10 ? C[6] : C[3]);+ }+ // the back halves of the crowns, behind their own front walls+ for (const q of drops(S)) crown(p, C, q, ageOf(t, q.t0), true);+}++// a crown: a ring of fingers thrown up round the drop's hole, a bead on each tip until they tear away+function crown(p, C, q, a, back) {+ const h = crownH(a, q.H);+ if (h < 1) return;+ const r0 = crownR(a), cy = q.z * SY;+ for (let f = 0; f < 10; f++) {+ const ang = q.spin + (f / 10) * TAU, s = Math.sin(ang);+ if (s < 0 !== back) continue;+ const tip = h * (0.75 + 0.25 * rand(q.i, f, 7)), lean = 0.35 * tip, x0 = q.x + Math.cos(ang) * r0, y0 = cy + s * r0 * SY;+ const x1 = q.x + Math.cos(ang) * (r0 + lean), y1 = cy + s * (r0 + lean) * SY - tip;+ p.line(x0, y0, x1, y1, back ? (u) => (u > 0.7 ? C[5] : C[3]) : (u) => (u > 0.75 ? WHITE : u > 0.35 ? C[6] : C[5]));+ if (a > 0.08 && a < 0.17) p.px(x1, y1 - 1, back ? C[5] : WHITE);+ }+ if (!back) p.glow(q.x, cy - h * 0.6, 6 + h * 0.6, C[5], 0.3 * (h / q.H));+}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 C = fit(o.palette, 8), S = o.seed;+ for (const q of drops(S)) {+ const a = ageOf(t, q.t0), cy = q.z * SY;+ // falling in: a streak dropping into the frame just before it lands+ const pre = D - a;+ if (pre < 0.14 && cy - pre * 520 - 10 > -48) {+ const y = cy - pre * 520;+ p.line(q.x, y - 10, q.x, y - 4, C[4]);+ p.line(q.x, y - 4, q.x, y, C[6]);+ }+ // the hit: a white fleck and a flash of light, then the crown+ if (a < 0.05) {+ p.px(q.x, cy, WHITE);+ p.glow(q.x, cy - 2, 12, C[5], 0.5 * (1 - a / 0.05));}- 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]);+ crown(p, C, q, a, false);+ // beads torn off the crown's tips arc out and fall back, each with a fleck and a little ring+ if (a > 0.16 && a < 0.8)+ for (let f = 0; f < 10; f += 2) {+ const ang = q.spin + (f / 10) * TAU, tip = crownH(0.16, q.H) * (0.75 + 0.25 * rand(q.i, f, 7)), r0 = crownR(0.16) + tip * 0.35;+ const v = 22 + 18 * rand(q.i, f, 8), vh = 40 + 30 * rand(q.i, f, 9), tt = a - 0.16, hh = tip + vh * tt - 0.5 * G * tt * tt;+ const bx = q.x + Math.cos(ang) * (r0 + v * tt), bz = q.z + Math.sin(ang) * (r0 + v * tt), by = bz * SY;+ if (hh > 0) bead(p, bx, by - hh, Math.cos(ang) * v, -(vh - G * tt) + Math.sin(ang) * v * SY, rand(q.i, f, 10) < 0.4 ? 2 : 1, C);+ else {+ const land = (vh + Math.sqrt(vh * vh + 2 * G * tip)) / G, since = tt - land;+ if (since < 0.05) p.px(bx, by, WHITE);+ if (since < 0.35) ring(p, bx, by, 1 + since * 12, SY, 1 - since / 0.35, C, { n: 1, half: 1, seed: q.i * 10 + f });+ }+ }+ // the rebound jet, with a bead that pinches off its top and drops back+ const jh = jetH(a, q.J);+ if (jh > 0.8) {+ p.line(q.x, cy - 1, q.x, cy - jh, (u) => (u > 0.6 ? WHITE : C[6]));+ p.px(q.x + 1, cy - 1, C[5]);+ if (a < 0.41) p.circle(q.x, cy - jh - 0.5, 1.2, C[6]);+ p.glow(q.x, cy - jh * 0.6, 6, C[5], 0.3);}- // 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]);+ const ba = a - 0.41, bh = q.J + 1 + 24 * ba - 0.5 * G * ba * ba;+ if (ba > 0 && bh > 0) {+ p.circle(q.x, cy - bh, 1.1, C[6]);+ p.px(q.x, cy - bh - 1, WHITE);}- // 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);}+ // the near halves of the main rings, crisp, so each splash has its own edge in the swell+ for (const q of drops(S)) {+ const a = ageOf(t, q.t0);+ if (a < 1.8) ring(p, q.x, q.z * SY, ringR(a), SY, 0.75 * ringK(a), C, { n: 1, half: 1, hot: a < 0.1, seed: q.i, wob: 0.5 + a });+ }+ // finer rain dimpling the water, and a few streaks falling past+ cycle(t, D, 16, S + 20, 0.5, (age, life, r) => {+ const x = r.range(-80, 80), z = r.range(-26, 26), y = z * SY, s = age - 0.1;+ if (s < 0) {+ const yy = y - (0.1 - age) * 600;+ if (yy - 6 < -48) return;+ p.line(x, yy - 6, x, yy, (u) => (u > 0.6 ? C[5] : C[3]));+ } else if (s < 0.4 && (x / RX) ** 2 + (y / (RX * SY)) ** 2 < 0.9) {+ if (s < 0.04) p.px(x, y, C[6]);+ ring(p, x, y, 1 + s * 9, SY, 0.8 * (1 - s / 0.4), C, { n: 1, half: 1, seed: 40 });+ }+ });+ // the lamp's glow on the water+ p.glow(LAMP, -6, 30, C[4], 0.16);}diff --git a/src/fx/water/ripples.js b/src/fx/water/ripples.jsindex cbaf3cf..d3352f4 100644--- a/src/fx/water/ripples.js+++ b/src/fx/water/ripples.js@@ -1,45 +1,100 @@-import { PAL, fract, ease, seg, rng } from "../../core/index.js";-import { fit, oval, ripple } from "./_lib.js";+import { fit, cycle, clamp, smooth, ease, TAU, WHITE } from "../../core/index.js";+import { WATER, ring } 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],+ desc: "A drop plinks on still dark water and rings spread out across it at a low angle: the swell of each ring catches the light, crests glint, and they fade into the calm.",+ tags: ["water", "ripples", "rings", "surface", "pond", "ambient", "loop"],+ size: [136, 52],+ origin: [68, 30],duration: 2,loop: true,fps: 30,bg: "ground",- options: { palette: PAL.water, count: 3, radius: 36, squash: 0.28, seed: 1 },+ options: { palette: WATER, seed: 2 },};-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);+const D = meta.duration, SY = 0.26, EVERY = 0.5, LIFE = 2, RMAX = 60, PATCH = 64;++// one ring at age a: its radius (fast out, slowing) and strength+const radius = (a) => 2 + (RMAX - 2) * ease.outCubic(a / LIFE);+const power = (a) => Math.pow(1 - a / LIFE, 1.5) * Math.min(1, a / 0.08);++// the rings alive at t, newest first: [age, index]+function alive(t) {+ const out = [];+ for (let k = 0; k * EVERY < LIFE; k++) {+ const a = (((t - k * EVERY) % D) + D) % D;+ if (a < LIFE) out.push([a, Math.round((((t - a) % D) + D) % D / EVERY)]);}- // 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;+ return out;+}++// the water: dark and see-through, shading with the slope of the swell each ring carries, so the rings read as+// waves catching the light from the far left, not just lines+function surface(p, C, t) {+ const rs = alive(t).map(([a]) => [radius(a), power(a), 3 + a * 2.2]);+ for (let Y = Math.floor(-PATCH * SY); Y < PATCH * SY; Y++)+ for (let X = -PATCH; X < PATCH; X++) {+ const x = X + 0.5, y = Y + 0.5, z = y / SY, r = Math.hypot(x, z), e = r / PATCH;+ if (e > 1) continue;+ const edge = 1 - smooth(0.6, 1, e);+ p.blend(x, y, C[1], 0.55 * edge);+ let slope = 0;+ for (const [R, k, w] of rs) {+ const d = r - R;+ if (d > 2.2 * w || d < -2.2 * w) continue;+ slope += k * Math.exp(-((d / w) ** 2)) * -Math.sin(d * 1.15) * 1.15;+ }+ if (slope === 0) continue;+ // the side of a swell facing the light (back and left) catches it; the side away from it goes dark+ const face = slope * (-(x * -0.55 + z * -0.84) / Math.max(1, r));+ if (face > 0.18) p.blend(x, y, face > 0.6 ? C[5] : C[4], Math.min(0.9, (face - 0.18) * 2.2) * edge);+ else if (face < -0.25) p.blend(x, y, C[0], Math.min(0.8, (-face - 0.25) * 2) * edge);}- p.px(x, y - lift, lift ? W[7] : W[5]);- if (r.next() < 0.5) p.px(x + 1, y - lift, W[4]);+}++function rings(p, C, t, half) {+ for (const [a, i] of alive(t)) {+ const R = radius(a), k = power(a);+ ring(p, 0, 0, R, SY, 0.85 * k, C, { n: 2, gap: 3 + a * 1.4, half, hot: a < 0.14, glint: half > 0 && a > 0.1 ? k : 0, seed: i + 1, wob: 0.4 + a * 1.1 });}- // 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]);+}++export function drawBack(p, t, o) {+ const C = fit(o.palette, 8);+ surface(p, C, t);+ rings(p, C, t, -1);+}++export function draw(p, t, o) {+ const C = fit(o.palette, 8), S = o.seed;+ rings(p, C, t, 1);+ // each ring starts with a drop: a white fleck, a bead thrown up and back down, a little light+ for (const [a] of alive(t)) {+ if (a < 0.08) {+ p.px(0, 0, WHITE);+ p.px(-1, 0, C[6]);+ p.px(1, 0, C[6]);+ p.glow(0, 0, 8, C[5], 0.5 * (1 - a / 0.08));+ }+ const b = a - 0.04, h = 90 * b - 0.5 * 700 * b * b;+ if (b > 0 && h > 0) {+ p.px(0, -h, WHITE);+ p.px(0, -h + 1, C[5]);+ }}- p.glow(0, 0, 10, W[5], 0.1 + 0.1 * hop);+ // glints ride the near crests, winking+ cycle(t, D, 10, S + 5, (g) => g.range(0.25, 0.45), (age, life, r) => {+ const all = alive(t), [a] = all[Math.floor(r.next() * all.length)] ?? [0];+ const ang = r.range(0.3, Math.PI - 0.3), R = radius(a), k = Math.sin((Math.PI * age) / life) * power(a);+ if (k < 0.15 || R < 6) return;+ const x = Math.cos(ang) * R, y = Math.sin(ang) * R * SY;+ p.px(x, y, WHITE);+ if (k > 0.5) for (const [dx, dy] of [[1, 0], [-1, 0], [0, 1], [0, -1]]) p.px(x + dx, y + dy, C[6]);+ p.glow(x, y, 5, C[5], 0.4 * k);+ });+ // a cool light on the water, brightest where the rings start+ p.glow(0, 0, 40, C[4], 0.14);+ p.glow(0, 0, 14, C[5], 0.12);}diff --git a/src/fx/water/splash.js b/src/fx/water/splash.jsindex 6d68a96..abb5249 100644--- a/src/fx/water/splash.js+++ b/src/fx/water/splash.js@@ -1,99 +1,250 @@-import { PAL, burst, seg, ease, TAU, WHITE } from "../../core/index.js";-import { fit, oval, ripple, drop, landTime } from "./_lib.js";+// The droplet recipe (shaded beads with tails that fly, land and throw up a little crown of their own) is+// adapted from Sprite Fusion's open-source blood (https://www.spritefusion.com/pixel-art-vfx/blood),+// MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Lights, P, Rng, fit, sparkle, clamp, smooth, ease, rand, noise, TAU, WHITE } from "../../core/index.js";+import { WATER, Drops, Ripples, Mist, bead, lace, pebble, rock } 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.",+ desc: "A stone drops into still water: a white hit, a crown that tears into droplets arcing out to plink down with rings, a jet that bounces back, foam and drifting mist.",tags: ["water", "splash", "impact", "drop", "liquid", "one-shot"],- size: [84, 52],- origin: [42, 40],- duration: 1.2,+ size: [176, 100],+ origin: [88, 78],+ duration: 2.5,loop: false,fps: 30,bg: "ground",- options: { palette: PAL.water, size: 1, seed: 2 },+ options: { palette: WATER, stone: true, seed: 3 },};-const T0 = 0.1, Q = 0.3, G = 430; // impact time, how flat the surface looks, gravity+const SY = 0.22, HIT = 0.16, G = 820, FINGERS = 12, JET = 0.3, TEAR = 0.11;-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]);+// the crown over time u after the hit: it leaps up in a few frames, flares out, then falls back+const height = (u) => 19 * ease.outCubic(clamp(u / 0.09)) * (1 - ease.inQuad(clamp((u - 0.12) / 0.3)));+const foot = (u) => 3 + 7.5 * ease.outCubic(clamp(u / 0.45));+const lip = (u) => foot(u) + height(u) * 0.42 + 3 * ease.outCubic(clamp(u / 0.25));+// the jet that bounces back up the middle once the crown has fallen+const jetH = (u) => 26 * (ease.outCubic(clamp(u / 0.12)) - ease.inQuad(clamp((u - 0.15) / 0.28)));++export function create(o) {+ const C = fit(o.palette, 8), R = new Rng(o.seed), ST = rock(), phi = R.range(0, TAU);+ const ps = new Particles({ rng: R }), mist = new Mist(), lights = new Lights(), rings = new Ripples({ sy: SY });+ const plinks = [], bubbles = [], spikes = Array.from({ length: FINGERS }, (_, k) => ({ a: ((k * TAU) / FINGERS + phi) % TAU, L: R.range(0.2, 0.36) }));+ const drops = new Drops({+ sy: SY,+ g: G,+ onLand: (d) => {+ // every drop that comes down plinks: a white fleck, a ring, and the bigger ones throw up a tiny crown+ rings.add(d.x, d.z, 0.6, 2 + d.s * 1.8, 0.34 + d.s * 0.1, { n: 1, k: 0.95, hot: 0.06 });+ plinks.push({ x: d.x, y: d.z * SY, s: d.s, age: 0 });+ if (d.s > 1 && !d.small)+ for (let i = 0; i < d.s; i++) {+ const a = R.range(0, TAU), v = R.range(10, 34);+ drops.add({ x: d.x, z: d.z, h: 0.5, vx: Math.cos(a) * v, vz: Math.sin(a) * v, vh: R.range(55, 110), s: 1, small: true, life: 1 });+ }+ },+ });+ let t = 0;+ const done = new Set(), once = (key, at) => !done.has(key) && t >= at && done.add(key);+ // the lip isn't level: it rises and dips round the crown+ const scallop = (a, h) => h * (0.86 + 0.14 * noise(Math.cos(a) * 2.2 + Math.sin(a) * 1.3 + phi * 3, o.seed));++ // the crown: a thin sheet from its foot to a rolled lip. The far wall's shadowed inside shows over the near+ // lip; the near wall is see-through between bright streaks, white down its lit edge; fingers rise off the lip+ function crown(p, back) {+ const u = t - HIT, h = height(u);+ if (u < 0 || h < 0.7) return;+ const r0 = foot(u), rt = lip(u), white = u < 0.045;+ const cells = new Map();+ const put = (x, y, c, a, rank) => {+ const X = Math.floor(x), Y = Math.floor(y), key = (Y + 4096) * 8192 + X + 4096, cur = cells.get(key);+ if (!cur || rank > cur.r) cells.set(key, { x: X, y: Y, c, a, r: rank });+ };+ const n = Math.ceil(rt * TAU * 1.6);+ for (let i = 0; i < n; i++) {+ const a = (i / n) * TAU, s = Math.sin(a), c = Math.cos(a);+ if (s < 0 !== back) continue;+ const lane = Math.floor(((a + phi) * rt) / 2.2), streak = rand(lane, 31) < 0.3, H = scallop(a, h);+ // as it falls, each lane of the sheet gives way from the top at its own moment+ const keep = 1 - clamp((u - 0.13 - 0.14 * rand(lane, 7)) / 0.1), steps = Math.ceil(H * 1.4) + 2;+ for (let k = 0; k <= steps * keep; k++) {+ const v = k / steps, r = r0 + (rt - r0) * Math.pow(v, 2.2), x = c * r, y = s * r * SY - H * v;+ if (white) put(x, y, WHITE, 1, 3);+ else if (back) put(x, y, v > 0.72 ? (streak ? C[5] : C[4]) : streak ? C[3] : C[2], 1, 1);+ else if (Math.abs(c) > 0.9) put(x, y, c < 0 ? (Math.abs(c) > 0.97 ? WHITE : C[6]) : C[4], 1, 2);+ else if (v < 0.1) put(x, y, v < 0.05 ? WHITE : C[6], 1, 2);+ else if (streak) put(x, y, c < -0.2 ? C[6] : C[5], 1, 1);+ else put(x, y, c < 0 ? C[5] : C[4], 0.22, 0);+ }+ // the rolled lip: a hard white line on the near side, softer on the far, gone where the lane broke+ if (!white && keep >= 1) {+ const x = c * rt, y = s * rt * SY - H;+ put(x, y, back ? C[5] : c < 0.45 ? WHITE : C[6], 1, 3);+ if (!back && c < 0.2) put(x, y + 1, C[6], 1, 2);}- }- // 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]);+ for (const q of cells.values()) {+ if (q.r === 0) p.blend(q.x, q.y, q.c, q.a);+ else p.px(q.x, q.y, q.c);}- 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);- }+ // fingers: spikes running on up and out from the lip, a bead on each until it tears off+ const reach = 1 - smooth(TEAR, TEAR + 0.1, u);+ for (const f of spikes) {+ if (Math.sin(f.a) < 0 !== back || reach <= 0) continue;+ const H = scallop(f.a, h), L = h * f.L * reach, x0 = Math.cos(f.a) * rt, y0 = Math.sin(f.a) * rt * SY - H, x1 = x0 + Math.cos(f.a) * L * 0.45, y1 = y0 - L;+ if (L >= 1) p.line(x0, y0, x1, y1, white ? WHITE : back ? C[4] : C[6]);+ if (u > 0.04 && u < TEAR) bead(p, x1 - (back ? 0 : 0.5), y1 - 1, 0, -1, back ? 1 : 2, C);+ if (!back && Math.sin(f.a) > 0.3) p.glow(x0, y0, 6, C[5], 0.22 * reach);}}- // 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);++ function jet(p) {+ const u = t - HIT - JET, h = jetH(u);+ if (u < 0 || h < 0.8) return;+ const top = -h;+ // a mound of water heaves up under it+ p.ellipse(0, 0, 5, 2.4, (d, a) => (Math.sin(a) > 0 ? null : d < 0.5 ? WHITE : Math.cos(a) < 0 ? C[6] : C[5]));+ p.shade(-3, top - 2, 3, 0, (x, y, out) => {+ const v = clamp((y - top) / h), w = 1.15 + 1.5 * v * v * v, q = x / w;+ if (Math.abs(q) > 1) return;+ out.c = q < -0.5 ? C[6] : q < 0.3 ? WHITE : q < 0.72 ? C[5] : C[4];+ });+ if (u < 0.12) {+ // the bulb at its tip, about to pinch off+ p.circle(0, top - 1, 1.7, C[5]);+ p.circle(-0.3, top - 1.3, 1.1, C[6]);+ p.px(-1, top - 2, WHITE);+ }+ p.glowLine(0, -1, 0, top, 7, C[5], 0.3);}- p.glow(0, -6, 18, W[5], 0.12 * (1 - seg(tau, 0, 0.5)));++ return {+ update(dt) {+ t += dt;+ if (once("hit", HIT)) {+ lights.add(0, -6, 52, C[5], 0.6, 0.45);+ lights.add(0, -4, 16, WHITE, 0.5, 0.08);+ rings.add(0, 0, 8, 56, 2.0, { n: 2, gap: 3.4, k: 1.35, hot: 0.16, glint: 1 });+ rings.add(0, 0, 5, 38, 1.7, { n: 1, k: 0.9, delay: 0.14 });+ // the first sheet of spray, thrown up fast and fine+ for (let i = 0; i < 20; i++) {+ const a = R.range(0, TAU), v = R.range(50, 125);+ drops.add({ x: Math.cos(a) * 3, z: Math.sin(a) * 3, h: R.range(1, 6), vx: Math.cos(a) * v, vz: Math.sin(a) * v, vh: R.range(160, 270), s: R.chance(0.25) ? 2 : 1, delay: R.range(0, 0.04) });+ }+ // mist rolls out low along the water+ for (let i = 0; i < 9; i++) {+ const s = i % 2 ? 1 : -1, x = s * R.range(4, 12);+ mist.add(x, -R.range(1, 7), s * R.range(25, 70), -R.range(4, 16), R.range(2.5, 4), R.range(7, 11), R.range(0.9, 1.5), R.chance(0.5) ? C[6] : C[5], R.range(0.3, 0.42), R.range(0, 0.1));+ }+ }+ if (once("spray", HIT + 0.04)) {+ for (let i = 0; i < 20; i++) {+ const a = R.range(0, TAU);+ ps.spawn(P.FLAKE, Math.cos(a) * 9, Math.sin(a) * 9 * SY - R.range(6, 15), Math.cos(a) * R.range(25, 90), -R.range(30, 100), R.range(0.7, 1.3), R.chance(0.5) ? WHITE : C[6], R.range(0.6, 1.5));+ }+ for (let i = 0; i < 5; i++) ps.spawn(P.STAR, R.range(-13, 13), -R.range(6, 20), 0, -4, R.range(0.25, 0.55), C[6], R.range(1, 2.4), R.range(0, 0.15));+ }+ if (once("tear", HIT + TEAR)) {+ // the beads on the finger tips tear off and arc away+ const h = height(TEAR), rt = lip(TEAR);+ for (const f of spikes) {+ const a = f.a + R.range(-0.08, 0.08), v = R.range(32, 88), L = h * f.L;+ drops.add({ x: Math.cos(f.a) * (rt + L * 0.45), z: Math.sin(f.a) * rt, h: h + L + 1, vx: Math.cos(a) * v, vz: Math.sin(a) * v, vh: R.range(90, 190), s: R.chance(0.3) ? 3 : 2 });+ }+ }+ // as the crown gives way its lip comes apart into drops+ const u = t - HIT;+ if (u > 0.13 && u < 0.3 && R.chance(0.3)) {+ const a = R.range(0, TAU), rt = lip(u), v = R.range(15, 45);+ drops.add({ x: Math.cos(a) * rt, z: Math.sin(a) * rt, h: scallop(a, height(u)) * R.range(0.6, 1), vx: Math.cos(a) * v, vz: Math.sin(a) * v, vh: R.range(-10, 45), s: R.chance(0.3) ? 2 : 1 });+ }+ if (once("fall", HIT + 0.3)) {+ // the crown falls back, shedding a few heavy drops close in+ for (let i = 0; i < 8; i++) {+ const a = R.range(0, TAU), r = lip(0.3), v = R.range(15, 40);+ drops.add({ x: Math.cos(a) * r, z: Math.sin(a) * r, h: R.range(3, 7), vx: Math.cos(a) * v, vz: Math.sin(a) * v, vh: R.range(30, 80), s: R.chance(0.4) ? 2 : 1 });+ }+ }+ if (once("bead", HIT + JET + 0.12)) {+ // the jet's tip pinches off into a bead that hangs, then drops back+ drops.add({ x: 0, z: 0.2, h: jetH(0.12) + 1, vx: R.range(-6, 6), vz: 0, vh: 55, s: 3 });+ for (let i = 0; i < 3; i++) mist.add(R.range(-3, 3), -jetH(0.12) + R.range(2, 8), R.range(-14, 14), -R.range(4, 12), 2, R.range(4, 6), R.range(0.6, 1), C[6], 0.3);+ }+ if (once("slump", HIT + JET + 0.38)) {+ rings.add(0, 0, 3, 30, 1.5, { n: 2, gap: 2.6, k: 0.9 });+ for (let i = 0; i < 4; i++) mist.add(R.range(-6, 6), -R.range(1, 4), R.range(-30, 30), -R.range(3, 10), 2.5, R.range(6, 9), R.range(0.8, 1.2), C[5], 0.28);+ }+ // the stone sinks and lets go of its air: a few bubbles come up and pop+ for (const [i, at] of [[0, 0.95], [1, 1.2], [2, 1.5]])+ if (once("glug" + i, HIT + at)) bubbles.push({ x: R.range(-5, 5), z: R.range(-6, 6), t0: t, r: R.range(1.3, 2.3), popped: false });+ for (const b of bubbles)+ if (!b.popped && t - b.t0 > 0.2) {+ b.popped = true;+ rings.add(b.x, b.z, 1, 7, 0.6, { n: 1, k: 0.9 });+ plinks.push({ x: b.x, y: b.z * SY, s: 1, age: 0 });+ for (let i = 0; i < 2; i++) drops.add({ x: b.x, z: b.z, h: 1, vx: R.range(-20, 20), vz: R.range(-10, 10), vh: R.range(50, 90), s: 1, small: true, life: 1 });+ }+ for (let i = plinks.length - 1; i >= 0; i--) if ((plinks[i].age += dt) > 0.14) plinks.splice(i, 1);+ drops.update(dt);+ rings.update(dt);+ mist.update(dt);+ ps.update(dt);+ lights.update(dt);+ },+ drawBack(p) {+ const u = t - HIT;+ // the cavity the stone punches, dark inside the foot of the crown+ if (u > 0 && u < 0.26) {+ const r = foot(u) * 0.85 * (1 - smooth(0.12, 0.26, u));+ p.ellipse(0, 0, r, r * SY + 0.6, (d, a) => (Math.sin(a) < 0 ? C[1] : C[2]));+ }+ rings.draw(p, C, -1);+ crown(p, true);+ drops.draw(p, C, "back");+ },+ draw(p) {+ const u = t - HIT;+ rings.draw(p, C, 1);+ if (u > 0.2) {+ const rx = 4 + 11 * ease.outCubic(clamp((u - 0.2) / 0.7)), k = smooth(0.2, 0.32, u) * (1 - smooth(0.5, 2.0, u)) * 0.9;+ lace(p, 0, 0, rx, rx * SY + 0.5, k, C, t, o.seed);+ }+ crown(p, false);+ jet(p);+ for (const b of bubbles) {+ const g = (t - b.t0) / 0.2;+ if (g > 1) continue;+ const r = b.r * ease.outBack(g), x = b.x, y = b.z * SY;+ for (let a = Math.PI; a <= TAU + 0.01; a += 0.5 / Math.max(1, r)) p.dot(x + Math.cos(a) * r, y + Math.sin(a) * r, C[6]);+ p.px(x - r * 0.4, y - r * 0.6, WHITE);+ p.glow(x, y - 1, 4, C[5], 0.25);+ }+ for (const q of plinks) {+ const k = q.age / 0.14;+ if (k < 0.5) p.px(q.x, q.y, WHITE);+ if (q.s > 1) p.line(q.x, q.y - 1, q.x, q.y - 1 - 3 * (1 - k), k < 0.4 ? WHITE : C[6]);+ p.glow(q.x, q.y, 4, C[5], 0.3 * (1 - k));+ }+ drops.draw(p, C, "front");+ // the hit: a flat white flash on the surface for two frames+ if (u >= 0 && u < 0.07) {+ p.ellipse(0, 0, 10, 2.4, (d) => (d < 0.6 ? WHITE : C[6]));+ sparkle(p, 0, -3, 5 * (1 - u / 0.07), C[6], C[5], 0.5);+ }+ // the stone, falling fast with a streak of air off it+ if (o.stone && t < HIT) {+ const v = t / HIT, y = -70 + 70 * (0.4 * v + 0.6 * v * v);+ p.line(0, y - 12, 0, y - 3, ST[4], (w) => w * 0.8);+ pebble(p, 0, y, 2.6, ST);+ }+ mist.draw(p, C[5]);+ ps.draw(p);+ lights.draw(p);+ // the disturbed water keeps a cool light on it while it settles+ if (u > 0) {+ p.glow(0, -2, 34, C[4], 0.2 * (1 - smooth(0, 1.6, u)));+ p.glow(0, 2, 64, C[3], 0.16 * (1 - smooth(0.1, 2.1, u)));+ }+ },+ };}diff --git a/src/fx/water/steam-vent.js b/src/fx/water/steam-vent.jsdeleted file mode 100644index 6697da2..0000000--- a/src/fx/water/steam-vent.js+++ /dev/null@@ -1,66 +0,0 @@-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.jsdeleted file mode 100644index 457a563..0000000--- a/src/fx/water/tidal-wave.js+++ /dev/null@@ -1,80 +0,0 @@-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.jsindex b8cf64b..8bb38c2 100644--- a/src/fx/water/water-jet.js+++ b/src/fx/water/water-jet.js@@ -1,64 +1,79 @@-import { PAL, cycle, tileNoise, clamp, seg, wrap, rand, TAU } from "../../core/index.js";-import { fit, drop } from "./_lib.js";+// The stream's build (a white core banded out to darker edges, surges running along it, light down its length, a+// flare where it leaves the source) follows Sprite Fusion's open-source energy beam+// (https://www.spritefusion.com/pixel-art-vfx/energy), MIT License, Copyright (c) 2026 Hugo Duprez.+import { fit, cycle, tileNoise, clamp, smooth, TAU, WHITE } from "../../core/index.js";+import { WATER, bead } 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,+ desc: "A pressurised stream blasts right: a tight glassy rod with surges running down it that swells, roughens, bends under its weight and breaks into chunks, spray and mist.",+ tags: ["water", "jet", "stream", "hose", "spray", "directional", "loop"],+ size: [188, 80],+ origin: [14, 32],+ duration: 1,loop: true,fps: 30,bg: "dark",- options: { palette: PAL.water, length: 66, width: 2.4, seed: 6 },+ options: { palette: WATER, length: 118, seed: 3 },};-const SEG = 7; // length of the blobs the end breaks into, px+const D = meta.duration, G = 520, SPEED = 260;++// the stream's centre line drops as it goes, and how thick it is there+const drop = (x, L) => (x / L) ** 2 * 9;+const thick = (x, L) => 2.6 + 5.4 * Math.pow(x / L, 1.1);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 C = fit(o.palette, 8), ph = t / D, L = o.length, S = o.seed, T = ph * TAU;+ // the stream, column by column: white down its core, banded out to blue edges, shadowed underneath; streaks race+ // along it and surges bulge through; past halfway it roughens, and its far end tears into chunks with gaps+ for (let X = 0; X <= L + 3; X++) {+ const x = X + 0.5, u = x / L;+ if (u > 1) break;+ const yc = drop(x, L), rough = smooth(0.25, 1, u), sd = ((((x - ph * SPEED * 2) % 130) + 130) % 130) - 65;+ const w0 = thick(x, L) + Math.exp(-(sd * sd) / 90) * 1.4 * (1 - u * 0.5);+ const up = w0 + tileNoise(x * 0.18 - ph * 30, 9, 30, 0, S + 1) * 2.2 * rough, dn = w0 + tileNoise(x * 0.18 - ph * 30, 3, 30, 0, S + 1) * 2.2 * rough;+ for (let Y = Math.floor(yc - up); Y <= Math.ceil(yc + dn); Y++) {+ const y = Y + 0.5, q = (y - yc) / Math.max(0.8, y < yc ? up : dn), aq = Math.abs(q);+ if (aq > 1) continue;+ if (u > 0.55 && tileNoise(x * 0.12 - ph * 25, (y - yc) * 0.25, 25, 0, S + 2) < -0.9 + 1.6 * smooth(0.55, 1, u)) continue;+ const streak = tileNoise(x * 0.06 - ph * 40, Math.floor(y - yc + 20) * 1.7, 40, 0, S);+ let lvl = aq < 0.2 ? 0 : aq < 0.48 ? 1 : aq < 0.78 ? 2 : 3;+ if (streak > 0.35) lvl = Math.max(0, lvl - 1);+ if (q > 0.4) lvl = Math.min(3, lvl + 1);+ p.px(X, Y, [WHITE, C[6], C[5], C[4]][lvl]);+ if (lvl === 0) p.light(x, y, C[5], 0.12);}- 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);+ }+ // the nozzle flare: a white burst where it leaves, ringed with light+ const fl = 0.85 + 0.15 * Math.sin(T * 6);+ p.circle(0, 0, 4.4 * fl, C[5]);+ p.circle(0, 0, 3.4 * fl, C[6]);+ p.circle(0, 0, 2.2 * fl, WHITE);+ for (let a = 0; a < TAU; a += 0.35) p.dot(Math.cos(a + T * 2) * 5.2 * fl, Math.sin(a + T * 2) * 5.2 * fl, C[5], 0.6);+ p.glow(0, 0, 24, C[5], 0.6 * fl);+ p.glow(0, 0, 8, WHITE, 0.4 * fl);+ // where it pinches apart: beads strung out along the end of the stream, racing on+ for (let k = 0; k < 6; k++) {+ const x = L * 0.82 + ((k * 13 + ph * SPEED) % 78), y = drop(Math.min(x, L), L) + (x > L ? ((x - L) / 60) ** 2 * 10 : 0) + Math.sin(k * 2.1) * 1.5;+ if (x < L + 34) bead(p, x, y, SPEED, 40, k % 3 === 0 ? 3 : 2, C);+ }+ // spray: a widening cone of drops shed from the stream and torn off its end, arcing down+ cycle(t, D, 70, S + 3, (g) => g.range(0.2, 0.42), (age, life, r) => {+ const f = Math.sqrt(r.next()), x0 = L * (0.3 + 0.7 * f), y0 = drop(x0, L) + r.range(-1, 1) * thick(x0, L);+ const vx = r.range(150, 270) * (0.55 + 0.45 * f), vy = r.range(-1, 1) * 110 * f + r.range(-10, 20);+ const x = x0 + vx * age, y = y0 + vy * age + 0.5 * G * age * age, k = age / life;+ if (x > L + 50 || y > 40 || y < -28 || (k > 0.75 && r.next() < (k - 0.75) * 4)) return;+ if (r.next() < 0.45) p.px(x, y, k < 0.5 ? WHITE : C[6]);+ else bead(p, x, y, vx, vy + G * age, r.next() < 0.2 ? 2 : 1, C);});- 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]);+ // mist blooming off the end+ cycle(t, D, 12, S + 4, (g) => g.range(0.7, 1), (age, life, r) => {+ const k = age / life, x = L * r.range(0.7, 1) + age * r.range(20, 45), y = drop(Math.min(x, L), L) + r.range(-5, 5) + age * r.range(4, 14);+ const rad = r.range(3, 5) + k * r.range(5, 9), a = r.range(0.1, 0.18) * Math.min(1, k / 0.15) * Math.pow(1 - k, 1.5);+ p.disc(x, y, rad, C[6], (d) => a * (1 - d * d));});- p.glowLine(0, 0, L * 0.8, 0, 6, W[5], 0.1);- p.glow(0, 0, 8, W[6], 0.3);+ // light: down the core, brightest near the nozzle+ for (let x = 0; x < L; x += 10) p.glow(x, drop(x, L), 14 + x * 0.1, C[4], 0.26 * (1 - (x / L) * 0.5));+ p.glow(L * 0.9, drop(L * 0.9, L), 26, C[5], 0.22);}diff --git a/src/fx/water/water-orb.js b/src/fx/water/water-orb.jsindex a58df74..eca9dab 100644--- a/src/fx/water/water-orb.js+++ b/src/fx/water/water-orb.js@@ -1,68 +1,113 @@-import { PAL, fract, tileNoise, TAU, bump } from "../../core/index.js";-import { fit } from "./_lib.js";+// The orb's build (a see-through body with a lit rim, an inner current drawn as streaks on a tilted plane, motes+// on tilted orbits split behind and in front, a pulsing light) follows Sprite Fusion's open-source energy orb+// (https://www.spritefusion.com/pixel-art-vfx/energy), MIT License, Copyright (c) 2026 Hugo Duprez.+import { fit, cycle, clamp, smooth, TAU, WHITE } from "../../core/index.js";+import { WATER, bead, ring } 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,+ desc: "A sphere of water floats and wobbles: a current circles inside it, the floor shows upside down through it, it shines, light gathers on the floor under it, and drips fall and plink.",+ tags: ["water", "orb", "sphere", "magic", "float", "ambient", "loop"],+ size: [100, 108],+ origin: [50, 100],+ duration: 3,loop: true,fps: 30,- bg: "dark",- options: { palette: PAL.water, radius: 13, seed: 12 },+ bg: "ground",+ options: { palette: WATER, radius: 19, seed: 2 },};+const D = meta.duration, SY = 0.3, G = 700, DRIP = 1.5, LET = 0.5;++const center = (ph) => [0, -52 + Math.sin(ph * TAU) * 2];+// the skin wobbles: radius at angle a, and the belly sags into a drip before each one falls+const skin = (a, R, ph) => {+ const sag = Math.max(0, Math.sin(a)) ** 6 * 2.2 * smooth(0.1, LET, ((ph * D) % DRIP) / DRIP) * (((ph * D) % DRIP) / DRIP < LET ? 1 : 0);+ return R + Math.sin(a * 3 + ph * TAU * 2) * 0.6 + Math.sin(a * 5 - ph * TAU * 3) * 0.35 + sag;+};++// motes of spray on tilted orbits round it: position, and whether it's in front+function motes(ph, R) {+ return Array.from({ length: 7 }, (_, i) => {+ const a = (i / 7) * TAU + ph * TAU * (i % 2 ? 1 : -1), r = R + 5 + (i % 3) * 3, tilt = (i - 3) * 0.22, x = Math.cos(a) * r, z = Math.sin(a);+ return { x: x * Math.cos(tilt), y: x * Math.sin(tilt) + z * r * 0.28, z, i };+ });+}++export function drawBack(p, t, o) {+ const C = fit(o.palette, 8), ph = t / D, R = o.radius, [cx, cy] = center(ph);+ // light gathers on the floor under it, the orb's caustic+ p.glow(cx, 0, 22, C[5], 0.32);+ p.shade(cx - 9, -2, cx + 9, 2, (x, y, out) => {+ const d = (x - cx) ** 2 / 64 + (y * 2.5) ** 2 / 9;+ if (d > 1) return;+ out.c = d < 0.25 ? WHITE : d < 0.6 ? C[6] : C[5];+ out.a = 1.2 - d;+ });+ for (const m of motes(ph, R)) if (m.z < 0) p.px(cx + m.x, cy + m.y, C[4]);+ p.glow(cx, cy, R * 3.2, C[4], 0.3 + 0.05 * Math.sin(ph * TAU * 2));+}+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]);+ const C = fit(o.palette, 8), ph = t / D, R = o.radius, [cx, cy] = center(ph), T = ph * TAU;+ // the body: see-through water, deeper toward the bottom; the floor seen upside down through its lower half+ p.shade(cx - R - 4, cy - R - 4, cx + R + 4, cy + R + 6, (x, y, out) => {+ const dx = x - cx, dy = y - cy, d = Math.hypot(dx, dy), a = Math.atan2(dy, dx), r = skin(a, R, ph);+ if (d > r) return;+ const q = d / r, lit = (-dx - dy) / Math.SQRT2 / Math.max(0.5, d);+ if (q > 0.9) {+ out.c = lit > 0.35 ? WHITE : lit > -0.2 ? C[5] : C[3];+ return;}- };- 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];+ // a lens of water: dark on the side the light comes from, the light gathering low on the far side inside+ const gather = Math.max(0, (dx + dy) / Math.SQRT2 / r) * q;+ p.blend(x, y, gather > 0.45 ? C[4] : gather > 0.25 ? C[3] : q > 0.7 ? C[2] : C[1], gather > 0.25 ? 0.7 : 0.35 + 0.3 * q);});- // 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 current inside: streaks circling on a tilted plane, bright where they pass in front+ for (let k = 0; k < 3; k++) {+ const rr = R * (0.38 + 0.2 * k), tilt = -0.5 + k * 0.35, spin = T * (k % 2 ? -2 : 3) + k * 2;+ for (let s = 0; s < 1; s += 0.012) {+ const a = spin + s * TAU, x = Math.cos(a) * rr, z = Math.sin(a), y = x * Math.sin(tilt) * 0.6 + z * rr * 0.62, dash = (s * 3 + k * 0.3) % 1;+ if (dash > 0.62) continue;+ p.px(cx + x * Math.cos(tilt), cy + y, z > 0 ? (dash < 0.1 ? WHITE : dash < 0.4 ? C[6] : C[5]) : C[3]);+ }}- // 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]);+ // bubbles drift up inside it+ cycle(t, D, 8, o.seed, (g) => g.range(1, 1.8), (age, life, r) => {+ const k = age / life, x = r.range(-0.5, 0.5) * R + Math.sin(age * 4 + r.range(0, TAU)) * 1.5, y = R * 0.6 - k * R * 1.2;+ if (Math.hypot(x, y) > R * 0.8) return;+ p.px(cx + x, cy + y, k < 0.8 ? C[6] : WHITE);+ if (r.next() < 0.35) p.px(cx + x + 1, cy + y, C[5]);+ });+ // the shine: a bright crescent up on the left, a small refracted glint low on the right+ p.arc(cx, cy, R * 0.74, 1.8, Math.PI * 1.12, Math.PI * 1.4, (u, v) => (u > 0.25 && u < 0.75 && v > 0.4 ? WHITE : C[6]));+ p.px(cx - R * 0.45, cy - R * 0.62, WHITE);+ p.px(cx + R * 0.48, cy + R * 0.5, C[6]);+ p.px(cx + R * 0.48 + 1, cy + R * 0.5, C[5]);+ // motes in front+ for (const m of motes(ph, R))+ if (m.z >= 0) {+ p.px(cx + m.x, cy + m.y, WHITE);+ p.px(cx + m.x - (m.i % 2 ? -1 : 1), cy + m.y, C[5]);+ p.glow(cx + m.x, cy + m.y, 4, C[5], 0.35);+ }+ // drips: one swells on its belly and lets go every DRIP seconds, landing with a plink and a ring+ const dt = (t % DRIP) / DRIP, fall = (t % DRIP) - DRIP * LET, y0 = cy + R + 3, land = Math.sqrt((2 * -y0) / G);+ if (fall < 0 && dt > 0.2) {+ const s = smooth(0.2, LET, dt);+ p.circle(cx, cy + R + 1 + s * 1.5, 0.8 + s * 1.2, C[5]);+ p.px(cx - 0.5, cy + R + s * 1.5, C[6]);+ } else if (fall >= 0 && fall < land) bead(p, cx, y0 + 0.5 * G * fall * fall, 0, G * fall, 2, C);+ else if (fall >= land) {+ const since = fall - land;+ if (since < 0.08) p.px(cx, 0, WHITE);+ ring(p, cx, 0, 1.5 + since * 18, SY, 1.1 * (1 - since / 0.4), C, { n: 1, half: 1, seed: 3, hot: since < 0.05 });}- orbit(true);- p.glow(0, cy, R0 * 2.2, W[4], 0.2);- p.glow(hx, hy, 6, W[6], 0.25);+ // where the lens brings the light to a point, low on the far side: a bright fleck, pulsing+ const fx = cx + R * 0.36, fy = cy + R * 0.4, pulse = 0.8 + 0.2 * Math.sin(T * 4);+ p.circle(fx, fy, 1.6, C[6]);+ p.px(fx, fy, WHITE);+ p.glow(fx, fy, 9, C[5], 0.45 * pulse);+ p.glow(cx, cy, R * 1.4, C[5], 0.22);+ p.glow(cx - R * 0.4, cy - R * 0.5, 6, WHITE, 0.25);}diff --git a/src/fx/water/waterfall.js b/src/fx/water/waterfall.jsindex dba36b2..573def3 100644--- a/src/fx/water/waterfall.js+++ b/src/fx/water/waterfall.js@@ -1,76 +1,290 @@-import { PAL, cycle, tileNoise, clamp, ease, fract, TAU } from "../../core/index.js";-import { fit, ripple } from "./_lib.js";+// The pool's caustic light (two warped sine nets, light where they cross zero) is adapted from Sprite Fusion's+// open-source bubbles (https://www.spritefusion.com/pixel-art-vfx/bubbles), MIT License, Copyright (c) 2026 Hugo Duprez.+import { fit, cycle, tileNoise, rand, clamp, smooth, ease, TAU, WHITE } from "../../core/index.js";+import { WATER, bead, ring, billow, rock } 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.",+ desc: "A river pours from a notch in a rock outcrop: a white curl, a deep sheet that splits into strands, churning foam, spray, drifting mist and rings on a dark pool.",tags: ["water", "waterfall", "cascade", "foam", "mist", "ambient", "loop"],- size: [64, 84],- origin: [32, 78],- duration: 1,+ size: [144, 136],+ origin: [72, 118],+ duration: 2,loop: true,fps: 30,bg: "ground",- options: { palette: PAL.water, height: 70, width: 10, seed: 7 },+ options: { palette: WATER, height: 92, width: 13, ledge: true, seed: 5 },};-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]);+const D = meta.duration, SY = 0.2, G = 760, POOL = [56, 11];++// half the sheet's width at depth d below the lip: it spreads a little as it falls+const halfW = (W, d, H) => W + 3.2 * Math.pow(clamp(d / H), 1.6);++// the falling sheet, in 1 px lanes. Lanes on the far side of the fall are dark and see-through, so the night shows+// between strands; the front lanes carry white dashes sliding down them, stretching as the water speeds up (the+// texture runs in fall time, √depth). The top is glassy and dark, and the lower third splits into strands that+// fan apart with gaps between, each lit down its left edge.+function sheet(p, C, ph, H, W, S) {+ for (let y = -H + 2; y <= -1; y++) {+ const d = y + 0.5 + H, v = d / H, s = Math.sqrt(d + 3), hw0 = halfW(W, d, H), split = smooth(0.56, 0.95, v), glass = 1 - smooth(4, 24, d);+ const wl = tileNoise(2, s * 1.4 - ph * 12, 0, 12, S + 2) * (0.4 + 1.8 * v), wr = tileNoise(11, s * 1.4 - ph * 12, 0, 12, S + 2) * (0.4 + 1.8 * v);+ const fan = split > 0 ? tileNoise(3, s * 0.8 - ph * 4, 0, 4, S + 61) * 1.6 : 0, sd = s * 1.5 - ph * 20, sb = s * 0.45 - ph * 6;+ for (let X = -W - 8; X <= W + 8; X++) {+ const x = X + 0.5, hw = hw0 + (x < 0 ? wl : wr), ax = Math.abs(x);+ if (ax > hw) continue;+ const e = ax / hw;+ let edge = false;+ if (split > 0) {+ const f = ((((x / (1 + 0.22 * split) + fan + 64) / 5.4) % 1) + 1) % 1;+ if (f > 1 - 0.46 * split) continue;+ edge = f < 0.2;+ }+ const dash = tileNoise(X * 1.618 + 0.31, sd, 0, 20, S);+ if (rand(X, S + 60) < 0.48 && e < 0.86 && !edge) {+ p.blend(x, y + 0.5, dash > 0.45 ? C[4] : glass > 0.5 ? C[3] : C[2], dash > 0.45 ? 0.7 : 0.42 + 0.15 * v);+ continue;+ }+ const broad = tileNoise(Math.floor((x + 40) / 3) * 2.7, sb, 0, 6, S + 1);+ let b = -0.34 + 0.46 * v + 0.3 * broad - glass * 0.5 + 0.35 * smooth(0.7, 1, e) * (x < 0 ? 1 : 0.3) - (x > 0 ? 0.12 * e : 0) + (edge ? 0.3 : 0);+ if (dash > 0.2 - 0.22 * v) b += 0.36 + 0.7 * (dash - 0.2);+ if (b > -0.2) p.px(X, y, b > 0.62 ? WHITE : b > 0.34 ? C[6] : b > 0.08 ? C[5] : C[4]);+ else p.blend(x, y + 0.5, C[3], 0.8);+ }+ }+ // strands peel off the edges and fall free+ cycle(ph * D, D, 16, S + 30, 0.4, (age, life, r) => {+ const side = r.sign(), d0 = r.range(14, H * 0.7), d = d0 + 50 * age + 260 * age * age, k = age / life;+ if (d > H - 6) return;+ const x = side * (halfW(W, d, H) + 1.5 + age * r.range(6, 16)), y = -H + d, len = 2 + 6 * k;+ p.line(x, y - len, x, y, (u) => (u > 0.7 ? C[6] : C[4]), 1 - k * 0.5);+ });+}++// the outcrop the river pours from: boulders shaded like the explosion's rocks (a lit top edge, shaded faces, a+// dark underside, a dark rim), creased where they meet, cracked; dark and glossy where the water runs over them+// which boulder is frontmost at each pixel of the outcrop, and how much light its face catches there+const ROCKS = new Map();+function rockMap(lumps, x0, y0, w, hgt, Lx, Ly, Lz, S) {+ const id = new Int8Array(w * hgt).fill(-1), lit = new Float32Array(w * hgt);+ for (let j = 0; j < hgt; j++)+ for (let i = 0; i < w; i++) {+ const x = x0 + i + 0.5, y = y0 + j + 0.5;+ let best = -1, z = -1e9, l = 0;+ lumps.forEach(([cx, cy, rx, ry], k) => {+ const nx = (x - cx) / rx, ny = (y - cy) / ry, r2 = nx * nx + ny * ny;+ if (r2 >= 1) return;+ const nz = Math.sqrt(1 - r2), depth = nz * ry + (k === 5 ? -6 : k === 2 ? -3 : k > 2 ? -1 : 0);+ if (depth > z) (z = depth), (best = k), (l = nx * Lx + ny * Ly + nz * Lz);+ });+ id[j * w + i] = best;+ lit[j * w + i] = l + 0.2 * tileNoise(x * 0.32, y * 0.32, 0, 0, S + 70);+ }+ return { id, lit };+}++function outcrop(p, C, ph, H, W, S) {+ const ST = rock(), Lx = -0.55, Ly = -0.72, Lz = 0.42;+ // [x, y, rx, ry]: a big boulder left of the notch, a smaller one right, the sill the water runs over, two feet,+ // and a slab behind that joins them, the notch cut into it+ const lumps = [[-W - 11, -H - 4, 13, 10], [W + 8, -H - 2, 9, 7.5], [0, -H + 3.5, W + 3, 4.2], [-W - 21, -H + 4, 7, 5.5], [W + 15, -H + 4.5, 5, 4], [-2, -H - 5, W + 7, 6.5]];+ const x0 = -W - 29, x1 = W + 21, y0 = -H - 15, y1 = -H + 10, w = x1 - x0 + 1, hgt = y1 - y0 + 1, key = `${W}|${H}|${S}`;+ let map = ROCKS.get(key);+ if (!map) ROCKS.set(key, (map = rockMap(lumps, x0, y0, w, hgt, Lx, Ly, Lz, S)));+ const { id, lit } = map;+ // a soft shadow under it on whatever is behind+ p.each(-W - 26, -H, W + 18, -H + 20, (x, y, sx, sy) => {+ const k = 1 - Math.hypot((x + 4) / (W + 22), (y + H) / 20);+ if (k > 0) p.blendPx(sx, sy, ST[0], 0.4 * Math.min(1, k * 3));});- // 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);+ const at = (i, j) => (i < 0 || j < 0 || i >= w || j >= hgt ? -1 : id[j * w + i]);+ for (let j = 0; j < hgt; j++)+ for (let i = 0; i < w; i++) {+ const k = id[j * w + i], x = x0 + i, y = y0 + j;+ // the river runs over the sill: nothing of the sill shows through it+ if ((k === 2 || k === 5 || k < 0) && y >= -H - 5 && y < -H + 1 && Math.abs(x + 0.5) < W + 1.5) continue;+ if (k < 0) {+ if (at(i - 1, j) >= 0 || at(i + 1, j) >= 0 || at(i, j - 1) >= 0 || at(i, j + 1) >= 0) p.px(x, y, ST[0]);+ continue;+ }+ // a crease where one boulder sits in front of another+ const r = at(i + 1, j), b = at(i, j + 1);+ if ((r >= 0 && r !== k && r < k) || (b >= 0 && b !== k)) {+ p.px(x, y, ST[1]);+ continue;+ }+ const l = lit[j * w + i], wet = Math.abs(x + 0.5) < W + 6 && y > -H - 9;+ let c = l > 0.9 ? ST[5] : l > 0.64 ? ST[4] : l > 0.3 ? ST[3] : l > -0.05 ? ST[2] : ST[1];+ if (k === 5) c = l > 0.7 ? ST[3] : l > 0.2 ? ST[2] : ST[1];+ if (at(i, j - 1) < 0 && l > 0.25) c = ST[5];+ if (wet) {+ // wet stone: a step darker, a cool gloss running down it where the light catches+ c = l > 0.9 ? ST[4] : l > 0.64 ? ST[3] : l > 0.3 ? ST[2] : ST[1];+ if (l > 0.3 && tileNoise(x * 0.9, y * 0.6 - ph * 8, 0, 8, S + 71) > 0.42) c = l > 0.6 ? C[6] : C[4];+ }+ p.px(x, y, c);+ }+ // cracks: dark lines with a lit lip above them+ for (let q = 0; q < 3; q++) {+ const L = lumps[q % 2], cx = Math.floor(L[0] + (q === 2 ? -0.5 : 0.15) * L[2]), cy = Math.floor(L[1] + L[3] * (q === 2 ? 0.1 : -0.25));+ const len = 3 + Math.floor(rand(q, S + 74) * 4), dx = rand(q, S + 75) < 0.5 ? 1 : -1;+ for (let n = 0; n <= len; n++) {+ const x = cx + Math.round(n * 0.6) * dx, y = cy + n, i = x - x0, j = y - y0;+ if (at(i, j) < 0 || at(i, j) > 1 || at(i, j + 1) < 0) break;+ p.px(x, y, n === len ? ST[1] : ST[0]);+ if (n === 0) p.px(x - dx, y - 1, ST[4]);+ }}- // 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];+ // trickles run down the wet faces either side of the notch+ for (const sx of [-W - 3, W + 3]) {+ for (let y = -H - 2; y < -H + 7; y++) {+ const g = ((y * 0.35 - ph * 6) % 1 + 1) % 1, i = Math.floor(sx) - x0, j = Math.floor(y) - y0;+ if (at(i, j) >= 0) p.px(sx, y, g < 0.3 ? C[6] : C[3]);}- 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];+ }+}++// the river sliding out of the notch between the boulders, seen from just above: flow lines sliding to the edge+function river(p, C, ph, H, W, S) {+ const top = -H - 6;+ p.shade(-W - 3, top, W + 3, -H, (x, y, out) => {+ const back = top + 1.5 + tileNoise(x * 0.3, 4, 0, 0, S + 62) * 1.5, v = (y - back) / (-H - back), hw = W + 2 - (1 - v) * 3;+ if (y < back || Math.abs(x) > hw) return;+ const n = tileNoise(x * 0.32, (y - top) * 0.7 - ph * 8, 0, 8, S + 3);+ out.c = n > 0.66 ? C[6] : n > 0.4 ? C[5] : v < 0.5 ? C[3] : C[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];+}++// the curl over the edge: glassy blue as it rolls, a hard white line along the bend; its light on the stone+function curl(p, C, ph, H, W, S) {+ for (let x = -W; x <= W; x++) {+ const g = tileNoise(x * 0.45, ph * 4, 0, 4, S + 4);+ p.px(x, -H - 1, C[4]);+ p.px(x, -H, WHITE);+ p.px(x, -H + 1, g > 0.2 ? C[6] : C[5]);+ }+ p.glowLine(-W, -H, W, -H, 6, C[6], 0.18);+ p.glow(0, -H, 34, C[5], 0.2);+ // glints run along it+ cycle(ph * D, D, 4, S + 5, 0.36, (age, life, r) => {+ const k = Math.sin((Math.PI * age) / life), x = r.range(-W, W);+ if (k > 0.5) for (const [dx, dy] of [[1, 0], [-1, 0], [0, 1], [0, -1]]) p.px(x + dx, -H + dy, C[6]);+ p.glow(x, -H, 6, C[5], 0.4 * k);});- // 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]));+}++// the pool: dark see-through water, a lit far rim, caustic light swimming in it, the falls' reflection+function pool(p, C, ph, W, S) {+ const [RX, RY] = POOL, cy = 2;+ const T = ph * TAU, cols = [];+ for (let X = -RX; X < RX; X++) {+ const x = X + 0.5;+ cols.push([Math.sin(x * 0.11 - T * 2), Math.sin(T + x * 0.05) * 1.4 + x * 0.13]);+ }+ for (let Y = Math.floor(cy - RY); Y < cy + RY; Y++) {+ const y = Y + 0.5, dy = (y - cy) / RY, sy = Math.sin(y * 0.5 + T);+ for (let X = -RX; X < RX; X++) {+ const x = X + 0.5, dx = x / RX, d = dx * dx + dy * dy;+ if (d > 1) continue;+ p.blend(x, y, d < 0.12 ? C[2] : C[1], 0.62 * Math.min(1, (1 - d) * 4));+ // caustics: two warped sine nets, light where either crosses zero+ const [cx1, cx2] = cols[X + RX], u = x * 0.2 + 1.8 * sy, w = y * 0.55 + 1.8 * cx1;+ const f = (Math.max(0, 1 - Math.abs(Math.sin(u) + Math.sin(w)) * 2.6) + 0.6 * Math.max(0, 1 - Math.abs(Math.sin(cx2 + y * 0.3)) * 3)) * (1 - d);+ if (f > 0.5) p.light(x, y, C[5], 0.18 * f);+ }+ }+ // a few glints sit on the far shore+ for (let i = 0; i < 7; i++) {+ const a = Math.PI * (1.12 + 0.76 * ((i + 0.5) / 7)), x = Math.cos(a) * RX * 0.96, y = cy + Math.sin(a) * RY * 0.96, g = Math.sin(ph * TAU * 2 + i * 2.4);+ if (g > 0.2) p.px(x, y, g > 0.8 ? C[6] : C[4]);+ }+ // the falls mirrored in the water, broken by the chop+ p.shade(-W - 3, 3, W + 3, 10, (x, y, out) => {+ const n = tileNoise(x * 0.9, (y - 3) * 0.35 + ph * 6, 0, 6, S + 6), k = 1 - (y - 3) / 7;+ if (Math.abs(x) > W + 2 - (y - 3) * 0.4 || n < 0.25 + (1 - k) * 0.4) return;+ out.c = n > 0.6 && k > 0.6 ? C[6] : C[5];+ });+}++// the foot: a churning white band, billows rolling out of it, spray thrown clear landing with rings+function foam(p, C, t, ph, W, S) {+ const R = W + 10;+ p.shade(-R, -13, R, 3, (x, y, out) => {+ const ax = Math.abs(x), lump = tileNoise(x * 0.22, ph * 6, 0, 6, S + 7) * 3 + tileNoise(x * 0.55 + 9, ph * 12, 0, 12, S + 8) * 1.5;+ const top = -8 + lump + Math.pow(ax / R, 2) * 7;+ if (ax > R - Math.max(0, -y - 1) * 0.6 || y < top) return;+ // the churn in lumps: each boil lit on top, shadowed under, darker where it meets the pool+ const n = tileNoise(x * 0.5, (y - top) * 0.5 - ph * 10, 0, 10, S + 9), boil = tileNoise(x * 0.42 + 3, y * 0.42 - ph * 8, 0, 8, S + 12), u = y - top;+ if (y > 1) out.c = n > 0 ? C[5] : C[4];+ else if (u < 1.2) out.c = WHITE;+ else if (boil < -0.3) out.c = u > 4 ? C[4] : C[5];+ else if (boil < -0.05) out.c = C[6];+ else out.c = n > -0.2 ? WHITE : C[6];+ });+ cycle(t, D, 30, S + 10, 0.7, (age, life, r) => {+ const k = age / life, side = r.sign(), x0 = r.range(-W, W) * 0.9, sp = r.range(2, 8), up = r.range(2, 8);+ const x = x0 + side * ease.outCubic(k) * sp, y = -r.range(2, 5) - ease.outCubic(k) * up, rad = r.range(1.4, 3) * Math.pow(Math.sin(Math.PI * k), 0.7);+ if (rad > 0.6) billow(p, x, y, rad, C);+ });+ // spray: beads thrown clear of the churn, landing in the pool with a ring+ cycle(t, D, 18, S + 11, 1, (age, life, r) => {+ const side = r.sign(), x0 = side * r.range(2, W + 4), vx = side * r.range(12, 60), vy = -r.range(70, 150), z = r.range(-3, 9), s = r.next() < 0.3 ? 2 : 1;+ const land = z * SY, tl = (-vy + Math.sqrt(vy * vy + 2 * G * (land + 5))) / G;+ if (age < tl) bead(p, x0 + vx * age, -5 + vy * age + 0.5 * G * age * age, vx, vy + G * age, s, C);+ else if (age < tl + 0.35) ring(p, x0 + vx * tl, land, 1 + (age - tl) * 12, SY, 1 - (age - tl) / 0.35, C, { n: 1 });+ });+}++// mist: soft puffs rolled out of the churn that drift sideways along the pool, swell and thin, with a cool light+function mist(p, C, t, S, n, seed) {+ cycle(t, D, n, S + seed, (g) => g.range(1.8, 2.8), (age, life, r) => {+ const k = age / life, side = r.sign(), drift = ease.outCubic(k);+ const x = side * (r.range(3, 12) + drift * r.range(24, 48)), y = -r.range(2, 7) - k * r.range(3, 12);+ const rad = r.range(4, 6) + k * r.range(5, 9), a = r.range(0.2, 0.3) * Math.min(1, k / 0.12) * Math.pow(1 - k, 1.7);+ p.disc(x, y, rad, C[6], (d) => a * (1 - d * d));+ if (a > 0.05) p.glow(x, y, rad * 1.2, C[4], 0.35 * a);+ });+}++export function drawBack(p, t, o) {+ const C = fit(o.palette, 8), ph = t / D, W = o.width;+ pool(p, C, ph, W, o.seed);+ for (let i = 0; i < 3; i++) {+ const f = (ph + i / 3) % 1;+ ring(p, 0, 1, W + 6 + f * 38, SY, 0.95 * Math.pow(1 - f, 1.5), C, { n: 1, half: -1, seed: i + 1 });+ }+ mist(p, C, t, o.seed, 7, 20);+}++export function draw(p, t, o) {+ const C = fit(o.palette, 8), ph = t / D, H = o.height, W = o.width, S = o.seed, T = ph * TAU;+ for (let i = 0; i < 3; i++) {+ const f = (ph + i / 3) % 1;+ ring(p, 0, 1, W + 6 + f * 38, SY, 0.95 * Math.pow(1 - f, 1.5), C, { n: 1, half: 1, seed: i + 1, glint: f < 0.4 ? 1 - f * 2.5 : 0 });+ }+ river(p, C, ph, H, W, S);+ if (o.ledge) outcrop(p, C, ph, H, W, S);+ sheet(p, C, ph, H, W, S);+ curl(p, C, ph, H, W, S);+ foam(p, C, t, ph, W, S);+ mist(p, C, t, S, 5, 21);+ // glints wink on the falling water and in the spray+ cycle(t, D, 12, S + 50, (g) => g.range(0.2, 0.4), (age, life, r) => {+ const k = Math.sin((Math.PI * age) / life), low = r.next() < 0.45, d = low ? H - r.range(4, 16) : r.range(12, H - 16);+ const x = low ? r.range(-W - 10, W + 10) : r.range(-0.8, 0.8) * halfW(W, d, H), y = -H + d - (age / life) * (low ? 6 : -10);+ p.px(x, y, WHITE);+ if (k > 0.55) for (const [dx, dy] of [[1, 0], [-1, 0], [0, 1], [0, -1]]) p.px(x + dx, y + dy, C[6]);+ if (k > 0.85 && r.next() < 0.5) for (const [dx, dy] of [[2, 0], [-2, 0], [0, 2], [0, -2]]) p.px(x + dx, y + dy, C[5]);+ p.glow(x, y, 5, C[5], 0.35 * k);});- // 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]);+ // fine spray hangs in the air off the foot, drifting up and out+ cycle(t, D, 34, S + 51, (g) => g.range(0.9, 1.6), (age, life, r) => {+ const k = age / life, side = r.sign(), x = side * (r.range(0, W + 6) + k * r.range(6, 22)) + Math.sin(age * 5 + r.range(0, TAU)) * 1.2, y = -r.range(3, 10) - k * r.range(10, 34);+ if (k > 0.7 && r.next() < (k - 0.7) * 3.3) return;+ p.px(x, y, k < 0.4 && r.next() < 0.5 ? WHITE : C[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));+ // light: down the sheet, a pool of it where the water lands, on the water around+ p.glowLine(0, -H + 6, 0, -8, 26, C[4], 0.12);+ p.glow(0, -5, 40, C[5], 0.32 + 0.05 * Math.sin(T * 2));+ p.glow(0, 4, 50, C[3], 0.14);}diff --git a/src/fx/water/wave-crash.js b/src/fx/water/wave-crash.jsindex 621c7f0..4a22114 100644--- a/src/fx/water/wave-crash.js+++ b/src/fx/water/wave-crash.js@@ -1,101 +1,228 @@-import { PAL, burst, seg, ease, clamp, noise2, WHITE } from "../../core/index.js";-import { fit, drop, landTime, ripple } from "./_lib.js";+// The lip's crescent (a thick arc, white on its outer rim, cooling to deep blue underneath, with light along it)+// follows Sprite Fusion's open-source slash (https://www.spritefusion.com/pixel-art-vfx/slash),+// MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, Lights, P, Rng, fit, sparkle, clamp, smooth, ease, noise, noise2, TAU, WHITE } from "../../core/index.js";+import { WATER, Drops, Ripples, Mist, billow } 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,+ desc: "A swell rolls in and steepens, its lip throws forward and curls over a dark barrel, then crashes into a burst of white foam and spray that surges on and fades to lace.",+ tags: ["water", "wave", "crash", "surf", "foam", "spray", "one-shot"],+ size: [224, 104],+ origin: [112, 86],+ duration: 3.2,loop: false,fps: 30,bg: "ground",- options: { palette: PAL.water, height: 38, seed: 13 },+ options: { palette: WATER, seed: 6 },};-const HIT = 0.66, G = 300;+const SY = 0.22, G = 820, CRASH = 1.2, LIP0 = 0.62, EDGE = 110;-// 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 };-}+// the swell: where its crest is, how tall, how steep its face, as it rolls in, crashes and runs on as whitewater+const crestX = (t) => (t < CRASH ? -80 + 72 * ease.inOutSine(t / CRASH) : -8 + 30 * ease.outCubic(clamp((t - CRASH) / 1.4)));+const crestH = (t) => (t < CRASH ? 5 + 33 * ease.inOutSine(clamp(t / (CRASH * 0.92))) : 38 * (1 - ease.outCubic(clamp((t - CRASH) / 0.45))) + 5 * (1 - smooth(CRASH, CRASH + 1.6, t)));+const faceW = (t) => (t < CRASH ? 24 - 16 * smooth(0.3, CRASH, t) : 8 + 14 * smooth(CRASH, CRASH + 0.6, t));+// the lip: thrown forward off the crest and falling, until its tip hits the water at CRASH+const lipK = (t) => clamp((t - LIP0) / (CRASH - LIP0));++export function create(o) {+ const C = fit(o.palette, 8), R = new Rng(o.seed), S = o.seed;+ const ps = new Particles({ rng: R }), mist = new Mist(), lights = new Lights(), rings = new Ripples({ sy: SY }), puffs = [], plinks = [];+ const drops = new Drops({+ sy: SY,+ g: G,+ onLand: (d) => {+ rings.add(d.x, d.z, 0.6, 2 + d.s * 1.8, 0.3 + d.s * 0.1, { n: 1, k: 0.9, hot: 0.05 });+ plinks.push({ x: d.x, y: d.z * SY, age: 0 });+ },+ });+ let t = 0, crashed = false;+ const height = (x, tt) => {+ const xc = crestX(tt), A = crestH(tt), dx = x - xc;+ return A * Math.exp(-((dx / (dx < 0 ? 30 : faceW(tt))) ** 2));+ };+ // a point on the lip at s (0 at the crest, 1 at its tip), and its thickness there+ const lip = (s, tt) => {+ const k = lipK(tt), xc = crestX(tt), A = crestH(tt);+ return [xc + 1 + s * 30 * Math.pow(k, 0.8), -A - 4 * s * (1 - s) * (1 + 4 * k) + s * s * A * ease.inQuad(k) * 0.98, (11 - 8.5 * s) * (0.5 + 0.5 * k)];+ };+ const puff = (x, y, vx, vy, r0, r1, life, delay = 0) => puffs.push({ x, y, vx, vy, r0, r1, life, max: life, delay });-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]);- });+ // the swell's body, column by column: deep blue down its back and base with wind lines, a lit rim along its+ // surface, white water at the crest, a lit window high on its face where the light comes through, and streaks of+ // foam drawn up the face+ function body(p, fade) {+ const xc = crestX(t), A = crestH(t);+ for (let X = -EDGE; X < EDGE; X++) {+ const x = X + 0.5, h = height(x, t), edge = 1 - smooth(EDGE - 24, EDGE, Math.abs(x));+ if (h < 0.6 || edge <= 0) continue;+ const face = x > xc, near = Math.exp(-(((x - xc) / 9) ** 2)), a = fade * edge * 1.4;+ for (let Y = Math.floor(-h); Y < 0; Y++) {+ const y = Y + 0.5, u = (y + h) / h, depth = y + h;+ let c;+ if (depth < 1) c = near > 0.5 && A > 14 && noise(x * 0.6 + t * 9, S) > -0.35 ? WHITE : face ? C[5] : C[6];+ else if (depth < 2.4 && near > 0.35 && A > 14) c = noise2(x * 0.5, y * 0.5 + t * 6, S + 1) > -0.1 ? WHITE : C[6];+ else {+ // face and back shade differently; blend the two across the crest so there's no seam+ const win = near * (1 - u) * 1.6, up = noise2((x * 0.9 - y * 0.35) * 0.8, y * 0.12 + t * 5, S + 2), wind = noise2(x * 0.18 - t * 2, y * 0.9, S + 3);+ const fi = up > 0.55 && u < 0.85 ? 6 : win > 0.8 ? 5 : win > 0.45 || up > 0.3 ? 4 : win > 0.2 || up > 0.05 ? 3 : u < 0.6 ? 2 : 1;+ const bi = u < 0.14 ? 4 : wind > 0.55 ? 4 : wind > 0.25 || u < 0.32 ? 3 : u < 0.7 ? 2 : 1;+ c = C[Math.round(bi + (fi - bi) * smooth(xc - 5, xc + 5, x))];+ }+ p.dot(X, Y, c, a);+ }}}- 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);++ // the lip: a thick arc thrown off the crest, white along its outer edge, tinted through, dark underneath+ function curl(p) {+ const k = lipK(t);+ if (k <= 0 || t >= CRASH) return;+ const cells = new Map();+ for (let s = 0; s <= 1; s += 0.012) {+ const [x, y, w] = lip(s, t), [x2, y2] = lip(Math.min(1, s + 0.012), t), tx = x2 - x, ty = y2 - y, l = Math.hypot(tx, ty) || 1, nx = ty / l, ny = -tx / l;+ for (let q = 0; q <= 1; q += 0.5 / Math.max(1, w)) {+ const px = x + nx * (q - 0.5) * w, py = y + ny * (q - 0.5) * w, key = Math.floor(py) * 1024 + Math.floor(px);+ // q 0 is the outer (upper) rim, 1 the underside+ const c = q < 0.18 ? WHITE : q < 0.36 ? (s > 0.8 ? WHITE : C[6]) : q < 0.56 ? C[5] : q < 0.76 ? C[4] : C[3];+ const cur = cells.get(key);+ if (!cur || q < cur.q) cells.set(key, { x: px, y: py, c, q });+ }}- 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;+ for (const c of cells.values()) p.px(c.x, c.y, c.c);+ for (let s = 0; s <= 1; s += 0.125) {+ const [x, y, w] = lip(s, t);+ p.glow(x, y, 6 + w, C[5], 0.24 * k);}- 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);+ // the tip glints as it throws+ const [tx, ty] = lip(1, t), g = Math.sin(Math.PI * clamp((k - 0.55) / 0.45));+ if (g > 0.05) sparkle(p, tx, ty, 6 * g, C[6], C[5], 0.5 * g);+ // light caught under the barrel+ const [bx, by] = lip(0.6, t);+ p.glow(bx - 3, by + 8, 16, C[4], 0.25 * k);}- p.glow(hitX, -10, 26, W[5], 0.22 * (1 - seg(a, 0, 0.5)));-}-const lerpN = (a, b, k) => a + (b - a) * k;+ // the sea it rolls on: a lit line along the surface, dark water under it, glints sliding along+ function sea(p, fade) {+ for (let X = -EDGE; X < EDGE; X++) {+ const x = X + 0.5, edge = 1 - smooth(EDGE - 30, EDGE, Math.abs(x)), a = fade * edge;+ if (a <= 0.02) continue;+ const g = noise(x * 0.3 - t * 3, S + 4);+ p.dot(X, 0, g > 0.55 ? C[6] : C[4], a * 1.2);+ p.blend(x, 1.5, C[2], 0.6 * a);+ p.blend(x, 2.5, C[1], 0.45 * a);+ }+ }++ return {+ update(dt) {+ t += dt;+ const k = lipK(t);+ // wind tears spray off the crest; the lip's tip sheds drops as it throws+ if (t < CRASH && crestH(t) > 14 && R.chance(0.5)) {+ const xc = crestX(t), A = crestH(t);+ ps.spawn(P.FLAKE, xc + R.range(-4, 3), -A - R.range(0, 2), -R.range(20, 60), -R.range(10, 40), R.range(0.5, 0.9), R.chance(0.5) ? WHITE : C[6], R.range(0.6, 1.3));+ }+ if (k > 0.3 && t < CRASH && R.chance(0.35)) {+ const [x, y] = lip(1, t);+ drops.add({ x, z: R.range(-3, 3), h: -y, vx: R.range(30, 90), vz: R.range(-10, 10), vh: R.range(-20, 40), s: R.chance(0.3) ? 2 : 1 });+ }+ if (!crashed && t >= CRASH) {+ crashed = true;+ const [X0] = lip(1, CRASH - 1e-3);+ lights.add(X0, -20, 56, C[5], 0.8, 0.55);+ lights.add(X0, -4, 22, WHITE, 0.6, 0.1);+ for (let i = 0; i < 46; i++) {+ const a = R.range(-0.9, 0.6) * Math.PI, v = R.range(30, 120);+ drops.add({ x: X0 + R.range(-6, 6), z: R.range(-4, 4), h: R.range(2, 8), vx: Math.cos(a) * v * 0.85 + 18, vz: Math.sin(a) * v * 0.5, vh: R.range(120, 320), s: R.chance(0.15) ? 3 : R.chance(0.35) ? 2 : 1, delay: R.range(0, 0.1) });+ }+ // the spit: a plume shot straight up where the lip lands+ for (let i = 0; i < 14; i++) drops.add({ x: X0 + R.range(-3, 3), z: R.range(-2, 2), h: R.range(2, 6), vx: R.range(-15, 25), vz: R.range(-8, 8), vh: R.range(220, 300), s: R.chance(0.3) ? 2 : 1, delay: R.range(0.04, 0.16) });+ for (let i = 0; i < 34; i++) puff(X0 + R.range(-12, 10), -R.range(2, 12), R.range(-40, 130), -R.range(30, 150), R.range(1, 2), R.range(1.8, 4.2), R.range(0.4, 0.95), R.range(0, 0.14));+ // fine spray hangs in the air over the burst+ for (let i = 0; i < 34; i++) {+ const a = R.range(-Math.PI * 0.95, -Math.PI * 0.05), v = R.range(40, 160);+ ps.spawn(P.FLAKE, X0 + R.range(-8, 8), -R.range(4, 14), Math.cos(a) * v + 25, Math.sin(a) * v, R.range(0.6, 1.3), R.chance(0.5) ? WHITE : C[6], R.range(0.6, 1.4), R.range(0, 0.1));+ }+ for (let i = 0; i < 12; i++) mist.add(X0 + R.range(-10, 14), -R.range(3, 16), R.range(-20, 70), -R.range(6, 24), 3, R.range(9, 15), R.range(1.1, 1.7), R.chance(0.5) ? C[6] : WHITE, 0.26, R.range(0, 0.2));+ for (let i = 0; i < 10; i++) ps.spawn(P.STAR, X0 + R.range(-20, 24), -R.range(6, 40), 0, -5, R.range(0.3, 0.6), C[6], R.range(1, 2.4), R.range(0.05, 0.4));+ rings.add(X0, 0, 6, 40, 1.2, { n: 2, gap: 3, k: 1.1, hot: 0.12 });+ }+ // the whitewater surges on, boiling up foam at its front, then calms+ if (crashed && t < CRASH + 1.1 && R.chance(0.45 * (1 - (t - CRASH) / 1.1))) {+ const x = crestX(t) + R.range(-6, 14);+ puff(x, -R.range(1, 4), R.range(10, 40), -R.range(10, 40), R.range(0.9, 1.8), R.range(1.8, 3.6), R.range(0.4, 0.8));+ }+ if (crashed && t < CRASH + 0.8 && R.chance(0.12)) mist.add(crestX(t) + R.range(-8, 8), -R.range(2, 6), R.range(10, 40), -R.range(3, 10), 3, R.range(7, 11), R.range(0.8, 1.1), C[6], 0.2);+ for (let i = puffs.length - 1; i >= 0; i--) {+ const f = puffs[i];+ if (f.delay > 0) {+ f.delay -= dt;+ continue;+ }+ if ((f.life -= dt) <= 0) {+ puffs.splice(i, 1);+ continue;+ }+ f.vx -= f.vx * 2.5 * dt;+ f.vy += (160 - f.vy * 2.5) * dt;+ f.x += f.vx * dt;+ f.y = Math.min(f.y + f.vy * dt, -1);+ }+ for (let i = plinks.length - 1; i >= 0; i--) if ((plinks[i].age += dt) > 0.12) plinks.splice(i, 1);+ drops.update(dt);+ rings.update(dt);+ mist.update(dt);+ ps.update(dt);+ lights.update(dt);+ },+ drawBack(p) {+ const fade = smooth(0, 0.25, t) * (1 - smooth(meta.duration - 0.7, meta.duration - 0.1, t));+ sea(p, fade);+ rings.draw(p, C, -1);+ drops.draw(p, C, "back");+ },+ draw(p) {+ const fade = smooth(0, 0.25, t) * (1 - smooth(meta.duration - 0.7, meta.duration - 0.1, t));+ body(p, fade);+ curl(p);+ rings.draw(p, C, 1);+ // lace left on the water behind the surge, thinning out+ if (crashed) {+ const k = 1 - smooth(CRASH + 0.4, meta.duration - 0.15, t), x0 = -20, x1 = crestX(t) + 10;+ for (let X = Math.floor(x0); X < x1; X++) {+ const x = X + 0.5, n = 1 - Math.abs(noise2(x * 0.35, t * 0.8, S + 7)) * 4;+ if (n > 1.15 - k * 1.1) p.px(X, 0, n > 1.4 - k ? WHITE : C[6]);+ if (n > 1.4 - k * 0.9) p.px(X, 1, C[5]);+ }+ }+ for (const f of puffs) {+ if (f.delay > 0) continue;+ const g = 1 - f.life / f.max, r = (f.r0 + (f.r1 - f.r0) * ease.outCubic(g)) * (1 - smooth(0.7, 1, g));+ if (r > 0.6) billow(p, f.x, f.y, r, C);+ }+ for (const q of plinks) {+ if (q.age < 0.06) p.px(q.x, q.y, WHITE);+ p.glow(q.x, q.y, 4, C[5], 0.25 * (1 - q.age / 0.12));+ }+ drops.draw(p, C, "front");+ // the crash: a white burst where the lip lands+ const f = (t - CRASH) / 0.08;+ if (f >= 0 && f < 1) {+ const [X0] = lip(1, CRASH - 1e-3);+ p.circle(X0, -3, 8 * (1 - f * 0.4), WHITE);+ p.ellipse(X0, 0, 14, 2.6, (d) => (d < 0.6 ? WHITE : C[6]));+ }+ ps.draw(p);+ mist.draw(p, C[5]);+ lights.draw(p);+ // light: the crest catches it while it stands, the whitewater after+ if (t < CRASH) {+ p.glow(crestX(t) + 4, -crestH(t) + 2, 26, C[4], 0.22 * smooth(0.2, CRASH, t));+ p.glowLine(crestX(t) - 26, -crestH(t) * 0.45, crestX(t), -crestH(t), 10, C[5], 0.14 * smooth(0.2, CRASH, t));+ }+ else p.glow(crestX(t), -10, 34, C[4], 0.26 * (1 - smooth(CRASH, meta.duration - 0.3, t)));+ },+ };+}diff --git a/src/fx/water/whirlpool.js b/src/fx/water/whirlpool.jsindex f5d97e5..e1772bb 100644--- a/src/fx/water/whirlpool.js+++ b/src/fx/water/whirlpool.js@@ -1,47 +1,85 @@-import { PAL, cycle, tileNoise, fract, ease, clamp, TAU } from "../../core/index.js";-import { fit } from "./_lib.js";+// The swirl's texture (streaks laid along a differentially wound flow, light on the brightest pixels) is adapted+// from Sprite Fusion's open-source black hole (https://www.spritefusion.com/pixel-art-vfx/black-hole), MIT License, Copyright (c) 2026 Hugo Duprez.+import { fit, cycle, clamp, smooth, TAU, WHITE } from "../../core/index.js";+import { WATER } 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,+ desc: "Seen from above, dark water winds into a vortex: foam arms spiral in, darkening as they're drawn down into a deep eye with a lit far rim, flecks of foam circling in after them.",+ tags: ["water", "whirlpool", "vortex", "maelstrom", "swirl", "top-down", "loop"],+ size: [128, 84],+ origin: [64, 42],+ duration: 3,loop: true,fps: 30,bg: "dark",- options: { palette: PAL.water, radius: 27, arms: 4, seed: 11 },+ options: { palette: WATER, seed: 5 },};+const D = meta.duration, R = 60, SY = 0.6, K = 2.4, EYE = 0.16;++// the flow at radius rho (0 eye, 1 rim), angle th: thin streaks of foam laid along a log spiral that turns once a+// loop (a turning log spiral reads as water drawn inward), dashed and brightest where two sets of streaks cross+function foam(rho, th, ph) {+ const s = Math.log(Math.max(rho, 0.02)), a = th + K * s + ph * TAU, b = th + K * 1.35 * s + ph * TAU * 2;+ const one = Math.pow(0.5 + 0.5 * Math.cos(7 * a + 0.9 * Math.sin(3 * a + s * 4)), 26);+ const two = Math.pow(0.5 + 0.5 * Math.cos(11 * b + 1.3), 34) * 0.7;+ // finer streaks crowd in near the eye, where the water runs fastest+ const three = Math.pow(0.5 + 0.5 * Math.cos(17 * (th + K * 0.8 * s + ph * TAU * 3)), 30) * 0.8 * Math.max(0, 1 - (rho - EYE) * 2.2);+ const dash = 0.55 + 0.45 * Math.sin(s * 22 - ph * TAU * 4 + a * 2);+ return (one + two + three) * dash;+}+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];+ const C = fit(o.palette, 8), ph = t / D, ry = R * SY;+ p.shade(-R, -ry, R, ry, (x, y, out) => {+ const dx = x / R, dy = y / ry, rho = Math.hypot(dx, dy);+ if (rho > 1) return;+ const th = Math.atan2(dy, dx);+ // the eye: a hole down into the dark, its far wall lit, a ring of foam racing round its lip+ if (rho < EYE) {+ const far = -dy / rho;+ // the far wall of the funnel, lit, falling off into the dark below the lip on the near side+ const wall = (rho / EYE - 0.35) / 0.65;+ if (far > 0) out.c = wall > 0.8 ? (far > 0.6 ? C[5] : C[4]) : wall > 0.45 ? C[3] : wall > 0.15 ? C[2] : C[0];+ else out.c = wall > 0.85 && far > -0.5 ? C[2] : C[0];+ return;+ }+ const k = (rho - EYE) / (1 - EYE), fade = 1 - smooth(0.62, 1, k);+ // dark see-through water, darker toward the eye, a faint sheen mid-way+ p.blend(x, y, k < 0.25 ? C[0] : C[1], (0.75 - 0.25 * k) * (1 - smooth(0.8, 1, k)));+ if (k > 0.3 && k < 0.8) p.blend(x, y, C[2], 0.18 * Math.sin(Math.PI * (k - 0.3) / 0.5));+ // the foam ring round the eye+ if (k < 0.035) {+ const g = 0.5 + 0.5 * Math.cos(th * 9 - ph * TAU * 6);+ out.c = g > 0.7 ? WHITE : g > 0.3 ? C[6] : C[4];+ return;+ }+ const I = foam(rho, th, ph) * fade * Math.min(1, (k - 0.08) * 4) * (0.45 + 0.55 * Math.sin(Math.PI * Math.min(1, k * 1.25)));+ if (I > 0.12) {+ out.c = I > 0.75 ? WHITE : I > 0.45 ? C[6] : I > 0.25 ? C[5] : C[4];+ if (I > 0.25) (out.l = C[5]), (out.k = 0.08 + 0.14 * Math.min(1, I));+ }+ });+ // flecks of foam drawn round and in along the arms, each a short streak along its path+ cycle(t, D, 30, o.seed, (g) => g.range(1.2, 2.2), (age, life, r) => {+ const u = age / life, rho = 0.8 - 0.62 * u * u, a0 = r.range(0, TAU), th = a0 - K * Math.log(rho);+ const ang = th - age * (1.5 + 2.2 / rho), x = Math.cos(ang) * rho * R, y = Math.sin(ang) * rho * ry;+ const ang2 = ang + 0.12 / rho, x2 = Math.cos(ang2) * rho * R, y2 = Math.sin(ang2) * rho * ry;+ if (u > 0.85 && r.next() < (u - 0.85) * 6) return;+ p.line(x2, y2, x, y, u < 0.2 ? C[5] : u < 0.6 ? WHITE : C[6]);});- // 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]);+ // glints winking on the foam+ cycle(t, D, 8, o.seed + 3, (g) => g.range(0.25, 0.45), (age, life, r) => {+ const rho = r.range(0.35, 0.8), th = r.range(0, TAU) - age * 2.5, k = Math.sin((Math.PI * age) / life);+ const x = Math.cos(th) * rho * R, y = Math.sin(th) * rho * ry;+ if (foam(rho, th, ph) < 0.35) return;+ p.px(x, y, WHITE);+ if (k > 0.55) for (const [dx, dy] of [[1, 0], [-1, 0], [0, 1], [0, -1]]) p.px(x + dx, y + dy, C[6]);+ p.glow(x, y, 5, C[5], 0.4 * k);});- p.glow(0, 0, R * 1.2, W[4], 0.12);- p.glowRing(0, 0, R * 0.95, 5, W[6], 0.12);+ // light: a cool sheen on the swirl, a glow off the eye's lit rim+ p.glow(0, 0, R * 0.9, C[4], 0.2);+ p.glow(0, 0, R * EYE * 1.6 + 6, C[5], 0.28);+ p.glow(0, -ry * EYE * 0.8, 14, C[5], 0.32);}diff --git a/src/fx/weather/_lib.js b/src/fx/weather/_lib.jsindex fb81bc5..7172775 100644--- a/src/fx/weather/_lib.js+++ b/src/fx/weather/_lib.js@@ -1,38 +1,310 @@-// 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.+// Helpers shared by the weather loops. Weather fills its whole canvas edge to edge, so: clip() keeps every pixel+// and every bit of light inside the canvas; pass() is a fast per-pixel shader over the canvas; field() bakes a+// tiling noise that scrolls a whole tile a loop; trips() rains particles that fall a whole number of times a+// loop, somewhere new each time; tree() is a branching lightning path. All of it is a pure function of t.+// The noise bake and the branching bolt are adapted from Sprite Fusion's open-source fog and lightning+// (https://www.spritefusion.com/pixel-art-vfx/fog), MIT License, Copyright (c) 2026 Hugo Duprez.-import { rng, fract } from "../../core/index.js";+import { rand, wrap, TAU } from "../../core/index.js";-/** The canvas in local coordinates: { x0, y0, x1, y1 } (inclusive pixel bounds), w, h. */+const BAYER = [0, 8, 2, 10, 12, 4, 14, 6, 3, 11, 1, 9, 15, 7, 13, 5].map((v) => (v + 0.5) / 16);++/** The canvas in local coordinates: x0 <= x < x1, y0 <= y < y1. */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 };+ return { x0: -OX, y0: -OY, x1: W - OX, y1: H - OY, 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).+ * A painter that draws only inside the effect's canvas: the same API, with color, blends and light outside it+ * dropped. Exact under the painter's flip and rotation.*/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;- };+ let ok;+ if (p.sn === 0) {+ const a = p.toX(B.x0, 0), b = p.toX(B.x1, 0), sx0 = Math.round(Math.min(a, b)), sx1 = Math.round(Math.max(a, b));+ const sy0 = Math.round(p.toY(0, B.y0)), sy1 = Math.round(p.toY(0, B.y1));+ ok = (sx, sy) => sx >= sx0 && sx < sx1 && sy >= sy0 && sy < sy1;+ } else+ 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 && ly >= B.y0 && ly < B.y1;+ };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);+ q.blendPx = (sx, sy, c, a) => ok(sx, sy) && p.blendPx(sx, sy, c, a);+ q.glow = (x, y, r, c, k) => glow(q, B, x, y, r, c, k);return q;}+// the painter's glow, with its box cut to the canvas first (big soft lights stay cheap)+function glow(q, B, x, y, r, c, k) {+ if (r < 1 || k <= 0.004) return;+ const x0 = Math.max(B.x0, Math.floor(x - r)), x1 = Math.min(B.x1 - 1, Math.ceil(x + r));+ const y0 = Math.max(B.y0, Math.floor(y - r)), y1 = Math.min(B.y1 - 1, Math.ceil(y + r));+ for (let py = y0; py <= y1; py++) {+ const dy = (py + 0.5 - y) / r;+ for (let px = x0; px <= x1; px++) {+ const dx = (px + 0.5 - x) / r, d = dx * dx + dy * dy;+ if (d >= 1) continue;+ const f = 1 - Math.sqrt(d);+ q.light(px, py, c, f * f * k);+ }+ }+}++const OUT = { c: 0, a: 1, b: 0, l: 0, k: 0 };+/**+ * A per-pixel shader over the canvas rows y0..y1 (local, clipped to the canvas), much faster than p.shade for+ * whole-sky passes. fn(x, y, out) sets out.c (color) with out.a (alpha: dithered, or truly blended when out.b+ * is 1), and out.l / out.k (light color and amount). x, y are pixel centers. Falls back to p.shade when rotated.+ */+export function pass(p, meta, y0, y1, fn) {+ const B = box(meta), o = OUT;+ y0 = Math.max(B.y0, Math.floor(y0));+ y1 = Math.min(B.y1 - 1, Math.ceil(y1));+ if (y0 > y1) return;+ if (p.sn !== 0) {+ const q = clip(p, meta);+ for (let y = y0; y <= y1; y++)+ for (let x = B.x0; x < B.x1; x++) {+ o.c = 0; o.a = 1; o.b = 0; o.l = 0; o.k = 0;+ fn(x + 0.5, y + 0.5, o);+ if (o.c) o.b ? q.blend(x, y, o.c, o.a) : q.dot(x, y, o.c, o.a);+ if (o.k > 0) q.light(x, y, o.l || o.c, o.k);+ }+ return;+ }+ const C = p.C, L = p.L, W = p.w, fade = p.fade, lk = p.lightK * fade, fx = p.fx, tx = p.tx;+ for (let y = y0; y <= y1; y++) {+ const sy = Math.floor(p.ty + y + 0.5), ry = sy - p.oy;+ if (ry < 0 || ry >= p.h) continue;+ const row = ry * W, by = (sy & 3) << 2;+ let sxf = tx + (B.x0 + 0.5) * fx;+ for (let x = B.x0; x < B.x1; x++, sxf += fx) {+ const sx = Math.floor(sxf), rx = sx - p.ox;+ if (rx < 0 || rx >= W) continue;+ o.c = 0; o.a = 1; o.b = 0; o.l = 0; o.k = 0;+ fn(x + 0.5, y + 0.5, o);+ const i = row + rx;+ if (o.c) {+ const a = o.a * fade;+ if (o.b) {+ if (a > 0.004) {+ const d = C[i], da = (d >>> 24) / 255, oa = a + da * (1 - a), k = a / oa, j = 1 - k, c = o.c;+ const r = ((c & 255) * k + (d & 255) * j) & 255, g = (((c >>> 8) & 255) * k + ((d >>> 8) & 255) * j) & 255;+ const b = (((c >>> 16) & 255) * k + ((d >>> 16) & 255) * j) & 255;+ C[i] = (((oa * 255) & 255) << 24) | (b << 16) | (g << 8) | r;+ }+ } else if (a >= 1 || a > BAYER[by | (sx & 3)]) C[i] = o.c;+ }+ if (o.k > 0) {+ const k = o.k * lk;+ if (k > 0.004) {+ const c = o.l || o.c, d = L[i];+ const r = Math.min(255, (d & 255) + (c & 255) * k) | 0, 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;+ L[i] = (255 << 24) | (b << 16) | (g << 8) | r;+ }+ }+ }+ }+}++const ROW = { w: 0, c: null, a: null, b: null, l: null, k: null };+/**+ * The fastest whole-sky shader: fn(y, R) fills one canvas row at a time (y the row's pixel center), writing+ * R.c[i] (color, 0 for none), R.a[i] (alpha, default 1), R.b[i] (1: blend, 0: dither), R.l[i] / R.k[i] (light+ * color and amount) for column i = x - box.x0. One call a row, so the effect's inner loop stays tight.+ */+export function rows(p, meta, y0, y1, fn) {+ const B = box(meta), w = B.w, R = ROW;+ if (R.w !== w) Object.assign(R, { w, c: new Uint32Array(w), a: new Float32Array(w), b: new Uint8Array(w), l: new Uint32Array(w), k: new Float32Array(w) });+ y0 = Math.max(B.y0, Math.floor(y0));+ y1 = Math.min(B.y1 - 1, Math.ceil(y1));+ const rot = p.sn !== 0, q = rot ? clip(p, meta) : null;+ const C = p.C, L = p.L, W = p.w, fade = p.fade, lk = p.lightK * fade, fx = p.fx;+ for (let y = y0; y <= y1; y++) {+ R.c.fill(0);+ R.k.fill(0);+ R.a.fill(1);+ R.b.fill(0);+ fn(y + 0.5, R);+ if (rot) {+ for (let i = 0; i < w; i++) {+ if (R.c[i]) R.b[i] ? q.blend(B.x0 + i, y, R.c[i], R.a[i]) : q.dot(B.x0 + i, y, R.c[i], R.a[i]);+ if (R.k[i] > 0) q.light(B.x0 + i, y, R.l[i] || R.c[i], R.k[i]);+ }+ continue;+ }+ const sy = Math.floor(p.ty + y + 0.5), ry = sy - p.oy;+ if (ry < 0 || ry >= p.h) continue;+ const row = ry * W, by = (sy & 3) << 2;+ let sxf = p.tx + (B.x0 + 0.5) * fx;+ for (let i = 0; i < w; i++, sxf += fx) {+ const c = R.c[i], kk = R.k[i];+ if (!c && !(kk > 0)) continue;+ const sx = Math.floor(sxf), rx = sx - p.ox;+ if (rx < 0 || rx >= W) continue;+ const j = row + rx;+ if (c) {+ const a = R.a[i] * fade;+ if (R.b[i]) {+ if (a > 0.004) {+ const d = C[j], da = (d >>> 24) / 255, oa = a + da * (1 - a), k = a / oa, m = 1 - k;+ const r = ((c & 255) * k + (d & 255) * m) & 255, g = (((c >>> 8) & 255) * k + ((d >>> 8) & 255) * m) & 255;+ const b = (((c >>> 16) & 255) * k + ((d >>> 16) & 255) * m) & 255;+ C[j] = (((oa * 255) & 255) << 24) | (b << 16) | (g << 8) | r;+ }+ } else if (a >= 1 || a > BAYER[by | (sx & 3)]) C[j] = c;+ }+ if (kk > 0) {+ const k = kk * lk;+ if (k > 0.004) {+ const lc = R.l[i] || c, d = L[j];+ const r = Math.min(255, (d & 255) + (lc & 255) * k) | 0, g = Math.min(255, ((d >>> 8) & 255) + ((lc >>> 8) & 255) * k) | 0;+ const b = Math.min(255, ((d >>> 16) & 255) + ((lc >>> 16) & 255) * k) | 0;+ L[j] = (255 << 24) | (b << 16) | (g << 8) | r;+ }+ }+ }+ }+}++/** Ordered-dither threshold of a local pixel (0..1): `a > bayer(x, y)` draws it. */+export const bayer = (x, y) => BAYER[((Math.floor(y) & 3) << 2) | (Math.floor(x) & 3)];++const FIELDS = new Map();+/**+ * A baked fractal noise that tiles: w x h cells (powers of two), octaves of `cells` lattice squares across.+ * Values 0..1, mostly near 0.5. Scroll it a whole number of tiles a loop and the loop has no seam.+ */+export function field(seed, w = 256, h = 128, cells = [4, 8, 16, 32]) {+ const key = `${seed}|${w}|${h}|${cells}`;+ let F = FIELDS.get(key);+ if (F) return F;+ const d = new Float32Array(w * h);+ let amp = 0.5, total = 0;+ for (const n of cells) {+ const cs = w / n, rows = Math.max(1, Math.round(h / cs));+ const at = (a, b) => rand(wrap(a, n), wrap(b, rows), seed, n);+ for (let y = 0; y < h; y++)+ for (let x = 0; x < w; x++) {+ const gx = x / cs, gy = (y / h) * rows, ix = Math.floor(gx), iy = Math.floor(gy), u = gx - ix, v = gy - iy;+ const su = u * u * (3 - 2 * u), sv = v * v * (3 - 2 * v);+ const top = at(ix, iy) + (at(ix + 1, iy) - at(ix, iy)) * su, bot = at(ix, iy + 1) + (at(ix + 1, iy + 1) - at(ix, iy + 1)) * su;+ d[y * w + x] += (top + (bot - top) * sv) * amp;+ }+ total += amp;+ amp *= 0.5;+ }+ for (let i = 0; i < d.length; i++) d[i] /= total;+ FIELDS.set(key, (F = { w, h, d }));+ return F;+}+/** A field at (u, v) in its own cells, wrapping, smooth between cells. */+export function sample(F, u, v) {+ const x = Math.floor(u), y = Math.floor(v), fx = u - x, fy = v - y, m = F.w - 1, n = F.h - 1, D = F.d;+ const x0 = x & m, x1 = (x + 1) & m, y0 = (y & n) * F.w, y1 = ((y + 1) & n) * F.w;+ const a = D[y0 + x0], b = D[y0 + x1], c = D[y1 + x0], e = D[y1 + x1];+ return a + (b - a) * fx + (c - a + (a - b - c + e) * fx) * fy;+}+/**- * 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.+ * Falling particles for a loop of D seconds: n slots, each falling m times a loop (m whole, from m0 to m1), each+ * fall somewhere new. fn(u, k, m, i): u 0..1 through the current fall, k its number (wrap(k, m) names it: use+ * rand(seed, i, wrap(k, m), ...) for its own randoms, the same every loop), m, the slot i. A fall lasts D / m s.*/-export function drift(t, D, n, seed, trips, fn) {+export function trips(t, D, n, seed, m0, m1, 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);+ const m = m0 + Math.floor(rand(seed, i, 72) * (m1 - m0 + 1)), s = (t / D) * m + rand(seed, i, 71), k = Math.floor(s);+ fn(s - k, k, m, i);+ }+}++/**+ * A branching lightning path from (x0, y0) to (x1, y1): midpoint displacement down to ~3 px segments, with+ * forks (and forks of forks) peeling off. Returns [{ pts: [[x, y], ...], w }], the trunk first with w = 1,+ * forks thinner (w < 1). R is an Rng.+ */+export function tree(R, x0, y0, x1, y1, jag = 0.3, forks = 0.4, w = 1, depth = 0) {+ const out = [], L = Math.hypot(x1 - x0, y1 - y0);+ let pts = [[x0, y0], [x1, y1]], off = L * jag;+ while (pts.length < 2 + L / 3) {+ const nxt = [pts[0]];+ for (let i = 0; i < pts.length - 1; i++) {+ const [ax, ay] = pts[i], [bx, by] = pts[i + 1], l = Math.hypot(bx - ax, by - ay) || 1, o = R.range(-off, off);+ nxt.push([(ax + bx) / 2 + (-(by - ay) / l) * o, (ay + by) / 2 + ((bx - ax) / l) * o], [bx, by]);+ }+ pts = nxt;+ off *= 0.52;+ }+ out.push({ pts, w, depth });+ if (depth < 2)+ for (let i = 2; i < pts.length - 3; i++)+ if (R.chance(forks / (1 + depth) / Math.max(4, pts.length / 6))) {+ const [ax, ay] = pts[i], [bx, by] = pts[Math.min(pts.length - 1, i + 3)];+ const a = Math.atan2(by - ay, bx - ax) + R.sign() * R.range(0.35, 0.95), l = (L - (i / pts.length) * L) * R.range(0.25, 0.55);+ out.push(...tree(R, ax, ay, ax + Math.cos(a) * l, ay + Math.sin(a) * l, jag * 1.1, forks, w * 0.55, depth + 1));+ }+ return out;+}++/** Whole cycles per loop: a sine with c full turns in D seconds, phase ph (radians). Seamless by construction. */+export const wave = (t, D, c, ph = 0) => Math.sin((TAU * c * t) / D + ph);++/**+ * A raindrop's splash on the floor, age seconds after it lands at (x, z): a white crown for a frame or two, a+ * flat ring spreading (its near arc brighter), and droplets thrown up that fall back. size 0..1 (far to near),+ * c = { hot, cool } colors, h a number unique to this drop. Adapted from Sprite Fusion's rain.+ */+export function splash(q, x, z, age, size, c, h) {+ const L = 0.3 + 0.12 * size, u = age / L;+ if (u >= 1) return;+ if (age < 0.07) {+ q.px(x, z - 1, c.hot);+ if (size > 0.3) (q.px(x - 1, z - 1 - (age > 0.035 ? 1 : 0), c.hot), q.px(x + 1, z - 1 - (age > 0.035 ? 1 : 0), c.hot));+ if (size > 0.65 && age > 0.03) (q.px(x - 2, z - 2, c.cool), q.px(x + 2, z - 2, c.cool));+ }+ const rx = 1 + (1.2 + 3.6 * size) * Math.sqrt(u), ry = Math.max(0.5, rx * 0.26), n = Math.ceil(rx * 6.5);+ for (let j = 0; j < n; j++) {+ const a = (j / n) * TAU, s = Math.sin(a);+ if (s < -0.25) continue;+ q.dot(x + Math.cos(a) * rx, z + s * ry, u < 0.3 && s > 0 ? c.hot : c.cool, u < 0.45 ? (s > 0.2 ? 1 : 0.7) : (1 - u) * 1.6 * (s > 0.2 ? 1 : 0.6));+ }+ const nd = size > 0.55 ? 3 : 2, H = Math.floor(h * 1e6);+ for (let d = 0; d < nd; d++) {+ const vx = (rand(H, d, 1) - 0.5) * 2 * (25 + 35 * size), vy = -(55 + rand(H, d, 2) * 70 * (0.5 + size)), y = z - 1 + vy * age + 475 * age * age;+ if (y > z - 0.5 || age > 0.34) continue;+ const xx = x + vx * age;+ q.px(xx, y, age < 0.12 ? c.hot : c.cool);+ if (vy + 950 * age < -40) q.dot(xx - vx * 0.012, y + 1, c.cool, 0.7);+ }+}++/**+ * A crisp splash on a floor line, age seconds after a drop lands at (x, z): a crown for a few frames (a white+ * point, two arms rising), then a flat dash that spreads and breaks into two end dashes, and a droplet or two+ * arcing up and back. Solid pixels only (no dither), so a line of them stays clean. size 0..1, c = { hot, cool,+ * white }, h a number unique to the drop. Returns false once it's over.+ */+export function crown(q, x, z, age, size, c, h) {+ const L = 0.22 + 0.14 * size, u = age / L, X = Math.round(x), Z = Math.round(z);+ if (u >= 1) return false;+ if (age < 0.1) {+ const up = age < 0.033 ? 1 : age < 0.067 ? 2 : 2 + (size > 0.5 ? 1 : 0);+ q.px(X, Z - 1, age < 0.05 ? c.white : c.hot);+ for (let d = 1; d <= Math.min(up, size > 0.5 ? 3 : 1); d++) (q.px(X - d, Z - 1 - (d > 1 ? d - 1 : 0), d === 1 ? c.hot : c.cool), q.px(X + d, Z - 1 - (d > 1 ? d - 1 : 0), d === 1 ? c.hot : c.cool));+ }+ if (u > 0.15) {+ const w = Math.round(1 + (1.5 + 3.5 * size) * Math.sqrt(u)), gap = u > 0.55 ? Math.max(0, w - 2) : -1;+ for (let d = -w; d <= w; d++) if (Math.abs(d) > gap) q.px(X + d, Z, Math.abs(d) >= w - 1 && u < 0.6 ? c.hot : c.cool);+ }+ const nd = size > 0.5 ? 2 : 1, H = Math.floor(h * 1e6);+ for (let d = 0; d < nd; d++) {+ const vx = (rand(H, d, 1) - 0.5) * 2 * (20 + 30 * size), vy = -(50 + rand(H, d, 2) * 60 * (0.4 + size)), y = Z - 1 + vy * age + 475 * age * age;+ if (y < Z - 0.5 && age < 0.3) q.px(x + vx * age, y, age < 0.1 ? c.white : c.hot);}+ return true;}diff --git a/src/fx/weather/aurora.js b/src/fx/weather/aurora.jsindex aa56093..64b81a2 100644--- a/src/fx/weather/aurora.js+++ b/src/fx/weather/aurora.js@@ -1,61 +1,153 @@-import { ramp, at, clamp, tileNoise, smooth, TAU, hex } from "../../core/index.js";-import { box, clip } from "./_lib.js";+// The banded light (posterized steps from a white-hot core out to deep color, fine strands running through it,+// pulses travelling along, light laid over the top) is adapted from Sprite Fusion's open-source holy light+// (https://www.spritefusion.com/pixel-art-vfx/holy-light), MIT License, Copyright (c) 2026 Hugo Duprez.+import { fit, clamp, smooth, rand, mix, TAU, WHITE, sparkle } from "../../core/index.js";+import { clip, rows, box, field, sample, bayer } 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,+ desc: "Rippling curtains of green-to-violet light over a starfield: folding hems burn bright, rays shimmer up into violet, and the whole sky slowly breathes.",+ tags: ["weather", "aurora", "northern lights", "sky", "night", "ambient", "loop"],+ size: [320, 180],+ origin: [160, 180],+ duration: 12,loop: true,fps: 30,bg: "sky",options: {- palette: ["#0a2a2a", "#0e4a3c", "#1a7a50", "#2eb064", "#6ae08a", "#c4ffcc", "#f4fff4"],- top: ["#2a1450", "#5a2a8a", "#9a4ab8"],- seed: 109,+ palette: ["#081a1e", "#0d3a36", "#13664e", "#1fa06a", "#3fd88e", "#9af7bf", "#e6fff0"],+ upper: ["#120b2a", "#26164f", "#41208a", "#6a34c0", "#9c62e8", "#d2b4ff", "#f6eeff"],+ seed: 3,},};-// two curtains: base height, fold sizes and speeds (whole turns a loop), ray height, brightness+const D = 12, W = 320, H = 180, BAY = [0, 8, 2, 10, 12, 4, 14, 6, 3, 11, 1, 9, 15, 7, 13, 5].map((v) => (v + 0.5) / 16);+const I = new Float32Array(W * H), HV = new Float32Array(W * H), BL = new Float32Array(W * H), TMP = new Float32Array(W * H);++// a curtain's light from its hem (v = 0) up its rays (v = 1): a bright hem, a body that holds, rays fading up+// into the dark. Tabled in steps of 1/200. Below the hem there's only a skirt of glow a few pixels deep.+const PROF = Float32Array.from({ length: 201 }, (_, i) => {+ const v = i / 200;+ return v < 0.035 ? 2.6 : v < 0.22 ? 1.15 - v : (1 - v) ** 1.5 * 0.9;+});++// a soft bloom of the light: a box blur of radius r, across then down, by running sums+function blur(src, dst, r) {+ const n = 2 * r + 1;+ for (let y = 0; y < H; y++) {+ let acc = 0;+ const o = y * W;+ for (let x = -r; x < W + r; x++) {+ if (x + r < W) acc += src[o + Math.min(W - 1, x + r)];+ if (x - r - 1 >= 0) acc -= src[o + x - r - 1];+ if (x >= 0 && x < W) TMP[o + x] = acc / n;+ }+ }+ for (let x = 0; x < W; x++) {+ let acc = 0;+ for (let y = -r; y < H + r; y++) {+ if (y + r < H) acc += TMP[Math.min(H - 1, y + r) * W + x];+ if (y - r - 1 >= 0) acc -= TMP[(y - r - 1) * W + x];+ if (y >= 0 && y < H) dst[y * W + x] = acc / n;+ }+ }+}+const cyc = (t, c, ph = 0) => (TAU * c * t) / D + ph;++// the curtains, back to front: where each hangs, how it folds and ripples, how tall its rays reachconst 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 },+ { y: -132, slope: -0.08, amp: 8, lam: 210, fold: 14, flam: 150, height: 40, k: 0.6, s0: -210, s1: 210, rip: 1.6, c: [1, 1, 2], hue: 0.35 },+ { y: -88, slope: 0.22, amp: 13, lam: 250, fold: 19, flam: 165, height: 82, k: 1.5, s0: -195, s1: 180, rip: 2.4, c: [1, 2, 3], hue: 0 },+ { y: -38, slope: -0.05, amp: 5, lam: 150, fold: 10, flam: 110, height: 20, k: 0.45, s0: -210, s1: 210, rip: 1.4, c: [2, 1, 3], hue: 0 },];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 q = clip(p, meta), B = box(meta), S = o.seed, G = fit(o.palette, 7), U = fit(o.upper, 7);+ stars(q, t, S, G, U);+ I.fill(0);+ HV.fill(0);+ const F = field(S * 5 + 1, 256, 128, [8, 16, 32]), breath = 0.75 + 0.25 * Math.sin(cyc(t, 1, -1.2));+ const rays = [];+ CURTAINS.forEach((c, n) => curtain(q, c, n, t, F, breath, rays, G));+ blur(I, BL, 5);+ // shade: hue by height (green at the hem, violet up the rays), brightness by intensity in posterized steps.+ // Faint light is only light, so the stars shine through it; the bright parts get crisp color too.+ const GM = G.map((g, i) => mix(g, U[i], 0.5));+ rows(p, meta, B.y0, -12, (y, R) => {+ const base = (Math.floor(y) - B.y0) * W, by = (Math.floor(y) & 3) << 2;+ for (let xi = 0; xi < W; xi++) {+ const i = base + xi, raw = I[i], bl = BL[i];+ let k = bl > 0.015 ? Math.min(0.4, bl * 0.6) : 0;+ if (raw >= 0.03) {+ const e = (raw * 1.5) / (1 + raw * 1.5), v = HV[i] / raw, th = e > 0.45 ? BAY[by | (xi & 3)] * 0.06 : 0;+ let lv = e > 0.86 + th ? 6 : e > 0.72 + th ? 5 : e > 0.56 + th ? 4 : e > 0.4 + th ? 3 : e > 0.24 ? 2 : 1;+ if (v > 0.35) lv = Math.min(lv, 5);+ const c = v < 0.3 ? G[lv] : v < 0.5 ? GM[lv] : U[lv];+ if (lv >= 3) {+ R.c[xi] = c;+ R.a[xi] = clamp((e - 0.3) * 2.2);+ R.b[xi] = lv < 5 ? 1 : 0;+ }+ R.l[xi] = lv >= 3 ? (v < 0.4 ? G[4] : U[4]) : c === G[lv] ? G[4] : c === U[lv] ? U[4] : GM[4];+ k += e * (lv >= 3 ? 0.28 : 0.72);+ } else R.l[xi] = G[4];+ R.k[xi] = 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];- });+ });+ // the brightest rays as fine strands of light, fading up into violet+ for (const r of rays) {+ const n = Math.round(r.h);+ for (let j = 1; j < n; j++) {+ const u = j / n;+ q.blend(r.x, r.hem - j, u < 0.35 ? G[5] : u < 0.6 ? mix(G[5], U[5], 0.5) : U[5], r.k * (1 - u) ** 1.3);+ }+ q.px(r.x, r.hem, G[6]);+ }+}++// one curtain: walk along it, drop each ray's light into the columns it covers; where it folds back on itself+// along the line of sight the light piles up, so folds burn brightest+function curtain(q, c, n, t, F, breath, rays, G) {+ const X0 = -160, Y0 = -180, fast = (256 * 2 * t) / D, slow = (256 * t) / D;+ let p1 = 0, p2 = 0, lastX = -999;+ for (let s = c.s0; s < c.s1; s += 0.5) {+ const x = s + c.fold * Math.sin((TAU * s) / c.flam + cyc(t, c.c[0], n * 2)) + 5 * Math.sin((TAU * s) / 64 + cyc(t, c.c[2], n));+ if (x < X0 - 2 || x >= X0 + W + 1) continue;+ const hem = c.y + c.slope * s + c.amp * Math.sin((TAU * s) / c.lam + cyc(t, c.c[1], n * 1.7)) + c.rip * Math.sin((TAU * s) / 23 - cyc(t, 7, n));+ const env = smooth(c.s0, c.s0 + 60, s) * (1 - smooth(c.s1 - 70, c.s1, s));+ // rays: fine strands drifting along the curtain, each with its own height; bright patches running along it+ const r1 = clamp((sample(F, s * 5 - fast + n * 40, 10 + n * 30) - 0.38) * 3.2), r2 = clamp((sample(F, s * 4.3 + fast * 0.7 + n * 90, 50 + n * 13) - 0.35) * 3);+ const patch = sample(F, s * 0.7 + slow + n * 17, 80 + n * 9);+ const k = c.k * env * breath * (0.2 + 0.8 * r1) * (0.3 + 1.4 * Math.max(0, patch - 0.3));+ if (k < 0.01) continue;+ const h = c.height * (0.45 + 0.75 * r2) * (0.75 + 0.5 * patch), xi = Math.floor(x - X0), fr = x - X0 - xi;+ // a ray peaks here: keep it as a strand; and a soft bloom along the bright hem+ if (p1 > 0.75 && p1 >= p2 && p1 >= r1 && Math.abs(x - lastX) > 2 && k > 0.25) (rays.push({ x, hem: hem - 1, h: h * 0.9, k: Math.min(0.85, k * 0.9) }), (lastX = x));+ p2 = p1;+ p1 = r1;+ if (xi < -1 || xi >= W) continue;+ const top = Math.max(0, Math.floor(hem - h - Y0)), bot = Math.min(H - 1, Math.floor(hem - Y0) + 3), inv = 1 / h, k0 = k * 0.5 * (1 - fr), k1 = k * 0.5 * fr;+ let v = (hem - Y0 - 0.5 - top) * inv;+ for (let yi = top; yi <= bot; yi++, v -= inv) {+ // above the hem: the ray; below it: a skirt of glow gone within three pixels+ const pr = v >= 0 ? PROF[Math.min(200, (v * 200) | 0)] : Math.max(0, 0.45 + v * h * 0.16), o = yi * W + xi, hv = v + c.hue < 0 ? 0 : v + c.hue > 1 ? 1 : v + c.hue;+ if (pr <= 0) continue;+ if (xi >= 0) (I[o] += k0 * pr), (HV[o] += k0 * pr * hv);+ if (xi + 1 < W) (I[o + 1] += k1 * pr), (HV[o + 1] += k1 * pr * hv);+ }+ }+}++// the starfield: dim specks, steady stars, a few bright ones that twinkle with a glint+function stars(q, t, S, G, U) {+ for (let i = 0; i < 150; i++) {+ const x = -160 + rand(S, i, 1) * 320, y = -180 + rand(S, i, 2) * 175, r = rand(S, i, 3), c = 1 + Math.floor(rand(S, i, 4) * 4);+ const tw = 0.5 + 0.5 * Math.sin(cyc(t, c, rand(S, i, 5) * TAU));+ const col = r < 0.6 ? mix(U[3], WHITE, 0.2) : r < 0.9 ? mix(U[5], WHITE, 0.5) : WHITE;+ if (r < 0.6) q.dot(x, y, col, 0.35 + 0.5 * tw);+ else if (r < 0.95) {+ q.px(x, y, col);+ q.glow(x + 0.5, y + 0.5, 3, U[5], 0.25 * tw);+ } else sparkle(q, x, y, 1 + Math.round(tw * 2), mix(U[5], WHITE, 0.6), U[4], 0.35 * tw);}- // 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.jsindex d408bca..c906269 100644--- a/src/fx/weather/blizzard.js+++ b/src/fx/weather/blizzard.js@@ -1,47 +1,116 @@-import { ramp, at, lerp, clamp, fract, rng, tileFbm, TAU } from "../../core/index.js";-import { box, clip } from "./_lib.js";+// Snow driven near-flat by the wind (depth layers of streaks, a gusty wind) after Sprite Fusion's open-source snow+// (https://www.spritefusion.com/pixel-art-vfx/snow), MIT License, Copyright (c) 2026 Hugo Duprez.+import { fit, clamp, smooth, rand, wrap, mix, TAU, WHITE } from "../../core/index.js";+import { clip, rows, field, sample, trips } 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,+ desc: "Snow driven almost flat by a gale: streaks at three depths race past, gusts throw translucent sheets of snow across the sky and spindrift streams off the drifts.",+ tags: ["weather", "blizzard", "snow", "wind", "storm", "winter", "ambient", "loop"],+ size: [320, 180],+ origin: [160, 170],+ duration: 8,loop: true,fps: 30,- bg: "dark",- options: { palette: ["#2a3448", "#4a5a76", "#7e92b0", "#bccce0", "#f0f6fc"], count: 140, seed: 83 },+ bg: "sky",+ options: {+ palette: ["#0d111f", "#182035", "#27324d", "#3e4d6e", "#64779c", "#9cb0d0", "#d8e4f6", "#ffffff"],+ seed: 9,+ },};+const D = 8;+// gusts: waves of wind rolling left to right, a whole number a loop+const gustAt = (x, t) => 0.5 + 0.5 * Math.sin(TAU * ((x + 160) / 400 - (2 * t) / D) + 0.8);+const bank = (x) => -2 + 1.2 * Math.sin(x * 0.05 + 2) + 0.8 * Math.sin(x * 0.15 + 1);+// far to near: how many, crossings a loop, streak length, fall while crossing, colors (tail, body, head)+const LAYERS = [+ { n: 240, m: [3, 4], len: [2, 4], drop: [10, 40], col: [3, 4, 5] },+ { n: 130, m: [4, 5], len: [5, 8], drop: [20, 60], col: [4, 5, 6] },+ { n: 34, m: [6, 7], len: [10, 16], drop: [30, 70], col: [4, 6, 7], near: true },+];++export function drawBack(p, t, o) {+ const q = clip(p, meta), S = o.seed, C = fit(o.palette, 8);+ sheets(p, t, S, C, 0);+ streaks(q, t, S, C, 0);+ streaks(q, t, S, C, 1);+ ground(p, q, t, S, C);+}+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;+ const q = clip(p, meta), S = o.seed, C = fit(o.palette, 8);+ sheets(p, t, S, C, 1);+ streaks(q, t, S, C, 2);+}++// streaks: each slot crosses the canvas a whole number of times a loop at its own height, dipping as it goes;+// the gusts stretch and brighten it+function streaks(q, t, S, C, L) {+ const Ly = LAYERS[L], sd = S * 17 + L, [c0, c1, c2] = Ly.col.map((i) => C[i]);+ trips(t, D, Ly.n, sd, Ly.m[0], Ly.m[1], (u, k, m, i) => {+ const j = wrap(k, m), R = (n) => rand(sd, i, j, n), drop = Ly.drop[0] + R(3) * (Ly.drop[1] - Ly.drop[0]);+ const x = -190 + 380 * u, y = -178 + R(1) * 182 + drop * u + 3 * Math.sin(u * TAU * (1 + R(5)) + R(6) * 6);+ if (y > bank(x) - 1) return;+ const g = gustAt(x, t);+ // between gusts the far snow thins out; in a gust it's everywhere+ if (!Ly.near && R(7) > 0.45 + 0.75 * g) return;+ const L = (Ly.len[0] + R(2) * (Ly.len[1] - Ly.len[0])) * (0.7 + 0.6 * g), dx = 380 / (D / m), dy = drop / (D / m), l = Math.hypot(dx, dy);+ const ux = dx / l, uy = dy / l;+ q.line(x - ux * L, y - uy * L, x - ux * L * 0.45, y - uy * L * 0.45, c0, (v) => 0.3 + 0.7 * v);+ q.line(x - ux * L * 0.45, y - uy * L * 0.45, x - ux, y - uy, c1);+ q.px(x, y, g > 0.6 && Ly.near ? WHITE : c2);+ if (Ly.near) q.glow(x, y, 5, C[5], 0.12 + 0.12 * g);+ });+}++// sheets of blown snow: long thin translucent bands racing with the wind, thick in a gust and thin between+const GX = new Float32Array(320), WV = new Float32Array(320);+function sheets(p, t, S, C, near) {+ const F = field(S * 3 + 7 + near, 256, 128), shift = (256 * (near ? 3 : 2) * t) / D, c = near ? C[6] : C[5], y0 = near ? -110 : -170, haze = mix(C[2], C[3], 0.5);+ const sy = near ? 4.5 : 3.2, th = near ? 0.58 : 0.54;+ for (let i = 0; i < 320; i++) (GX[i] = gustAt(i - 160 + 0.5, t)), (WV[i] = 5 * Math.sin((i - 160) * 0.021 - (TAU * t) / D + near * 2));+ rows(p, meta, y0, 4, (y, R) => {+ const fade = near ? smooth(-110, -40, y) : 1;+ for (let i = 0; i < 320; i++) {+ const g = GX[i], n = sample(F, (i - 160) * 0.16 - shift, (y + WV[i]) * sy + 40), d = (n - th) * 2.2 * (0.35 + g) * fade;+ // the far pass is also the whiteout haze behind everything, thicker in a gust+ if (near) {+ if (d <= 0.02) continue;+ R.c[i] = c;+ R.a[i] = Math.min(0.5, d);+ } else {+ R.c[i] = d > 0.08 ? c : haze;+ R.a[i] = 0.3 + 0.12 * g + Math.min(0.42, Math.max(0, d));+ }+ R.b[i] = 1;+ if (d > 0.05) (R.l[i] = C[5]), (R.k[i] = d * 0.08);+ }});- // 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]);+}++// the ground: a low drift with a white crest, spindrift streaming low along it, plumes blown off the crest+function ground(p, q, t, S, C) {+ const F = field(S * 5 + 1, 256, 128), shift = (256 * 4 * t) / D;+ for (let i = 0; i < 320; i++) (GX[i] = gustAt(i - 160 + 0.5, t)), (WV[i] = bank(i - 160 + 0.5));+ rows(p, meta, -16, 9, (y, R) => {+ for (let i = 0; i < 320; i++) {+ const x = i - 160 + 0.5, top = WV[i], d = y - top;+ if (d >= 0) {+ R.c[i] = d < 1 ? WHITE : d < 2 ? C[6] : d < 4 ? C[5] : C[4];+ if (d < 1) (R.l[i] = C[6]), (R.k[i] = 0.1);+ continue;+ }+ // spindrift: a low, fast, streaky haze hugging the drift+ if (y < -14) continue;+ const n = sample(F, x * 0.5 - shift, y * 3 + 9), s = (n - 0.5) * 3 * smooth(-14, -1, y) * (0.4 + GX[i]);+ if (s > 0.02) (R.c[i] = C[6]), (R.a[i] = Math.min(0.55, s)), (R.b[i] = 1);}});+ // grains skipping along the crest+ trips(t, D, 40, S * 23, 8, 10, (u, k, m, i) => {+ const j = wrap(k, m), x = -175 + 350 * u, y = bank(x) - 1 - rand(S, i, j, 1) * 6 * Math.abs(Math.sin(u * 9 + i));+ q.px(x, y, rand(S, i, j, 2) < 0.5 ? WHITE : C[6]);+ q.px(x - 1, y, C[5]);+ });}diff --git a/src/fx/weather/cherry-blossoms.js b/src/fx/weather/cherry-blossoms.jsindex 9aa8ee9..7680974 100644--- a/src/fx/weather/cherry-blossoms.js+++ b/src/fx/weather/cherry-blossoms.js@@ -1,35 +1,125 @@-import { ramp, lerp, TAU } from "../../core/index.js";-import { box, clip, drift } from "./_lib.js";+// Things that flutter down (a fall timed to land as their time in the air runs out, a flip by squashing across,+// a rest on the ground and a fade) after Sprite Fusion's open-source falling leaves+// (https://www.spritefusion.com/pixel-art-vfx/falling-leaves), MIT License, Copyright (c) 2026 Hugo Duprez.+import { fit, rand, wrap, mix, TAU, WHITE, hex } from "../../core/index.js";+import { clip, rows, trips } 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,+ desc: "Pink petals flutter down on a spring breeze, tumbling in little spirals and flashing as they catch the light, with a few whole blossoms spinning among them.",+ tags: ["weather", "cherry blossom", "sakura", "petals", "spring", "wind", "ambient", "loop"],+ size: [320, 180],+ origin: [160, 170],+ duration: 10,loop: true,fps: 30,bg: "sky",- options: { palette: ["#5a2448", "#a4446e", "#dc78a2", "#f6b2cc", "#fff0f6"], count: 34, seed: 101 },+ options: {+ palette: ["#4a1832", "#8e3460", "#d26a94", "#f2a2c0", "#ffd2e2", "#fff4f8"],+ seed: 12,+ },};-// 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"]];+const D = 10, FLOOR = 1;+const gust = (t) => 22 * Math.sin((TAU * t) / D + 0.4) + 7 * Math.sin((TAU * 2 * t) / D - 1);++export function drawBack(p, t, o) {+ const q = clip(p, meta), S = o.seed, C = fit(o.palette, 6);+ // a soft plum dusk, so the sky's stars don't read as petals+ const top = hex("#0e0a14"), low = mix(hex("#1a0e1a"), C[0], 0.4);+ rows(p, meta, -170, 9, (y, R) => {+ const k = (y + 170) / 180;+ R.c.fill(mix(top, low, k * k));+ R.a.fill(0.3 + 0.12 * k);+ R.b.fill(1);+ });+ scatter(q, S, C);+ petals(q, t, S, C, 0);+}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);+ const q = clip(p, meta), S = o.seed, C = fit(o.palette, 6);+ petals(q, t, S, C, 1);+ blossoms(q, t, S, C);+}++// petals: each tumbles in a little spiral as it falls and drifts on the breeze, flipping fast; turned full face+// to the light it flashes+function petals(q, t, S, C, near) {+ const n = near ? 54 : 90, sd = S * 7 + near;+ trips(t, D, n, sd, 1, 2, (u, k, m, i) => {+ const j = wrap(k, m), R = (c) => rand(sd, i, j, c), dur = D / m, tf = dur * 0.84, a = Math.min(u * dur, tf), rest = u * dur - tf;+ const born = t - u * dur, x0 = -200 + R(1) * 330, y0 = -184, vy = (FLOOR + (near ? 2 : 0) - y0) / tf, vx = 9 + R(2) * 10;+ const rho = (near ? 3 : 2) + R(3) * 3, w = 2.2 + R(4) * 2.8, ph = R(5) * TAU, gk = near ? 1 : 0.6;+ const at = (aa) => [x0 + vx * aa + (gust(born + aa) - gust(born)) * gk + rho * Math.cos(w * aa + ph), y0 + vy * aa + rho * 0.6 * Math.sin(w * aa + ph)];+ const len = (near ? 3.6 : 2.6) + R(6) * 1.1;+ if (rest > 0) {+ const [x, y] = at(tf);+ // a landed petal settles and shrinks away (no dither, so the ground stays clean)+ const fade = 1 - rest / (dur - tf);+ return void (fade > 0.15 && petal(q, x, y, len * (0.35 + 0.65 * fade), (R(7) - 0.5) * 1.2, 0.5, C, 1));+ }+ const [x, y] = at(a), flip = Math.cos(R(8) * TAU + a * (3 + R(9) * 5)), ang = R(10) * TAU + a * (R(11) - 0.5) * 3;+ petal(q, x, y, len, ang, flip, C, 1);+ if (flip > 0.9) {+ const g = (flip - 0.9) / 0.1;+ q.px(x, y - 1, WHITE);+ q.glow(x, y, near ? 7 : 5, C[4], (near ? 0.32 : 0.22) * g);+ }});}++// a petal: a little notched teardrop, squashed across as it flips; its pale face or its deeper back+function petal(q, x, y, len, ang, flip, C, a) {+ const fs = 0.3 + 0.7 * Math.abs(flip), back = flip < -0.2, c = Math.cos(ang), s = Math.sin(ang), e = len + 1;+ // deeper at the base, palest at the tip, lit on one side; the back is a step deeper all over+ const face = back ? [C[1], C[2], C[3]] : [C[2], C[3], C[4]], tip = back ? C[3] : C[5];+ q.shade(x - e, y - e, x + e, y + e, (px, py, out) => {+ const dx = px - x, dy = py - y, u = (dx * c + dy * s) / len, v = (-dx * s + dy * c) / (len * fs);+ if (u < -1 || u > 1) return;+ const hw = 0.55 * Math.sqrt(1 - u * u) * (1 + 0.35 * u);+ if (Math.abs(v) > hw || (u > 0.7 && Math.abs(v) < 0.12)) return;+ out.c = u > 0.45 && v < 0.1 ? tip : u < -0.45 ? face[0] : v < 0 ? face[2] : face[1];+ out.a = a;+ });+}++// a whole blossom: five petals round a gold heart, spinning slowly as it sinks+function blossoms(q, t, S, C) {+ trips(t, D, 7, S * 31, 1, 1, (u, k, m, i) => {+ const R = (c) => rand(S * 31, i, c), y = -190 + (FLOOR + 2 + 190) * Math.min(1, u / 0.9), born = t - u * D;+ if (u > 0.9) return;+ const x = -190 + R(1) * 330 + 14 * u * D * 0.1 + (gust(t) - gust(born)) + 6 * Math.sin(u * TAU * 2 + R(2) * 6), rot = R(3) * TAU + u * D * (R(4) - 0.5) * 2;+ const r = 3.6 + R(5) * 1.2;+ for (let p = 0; p < 5; p++) {+ const an = rot + (p * TAU) / 5;+ petal(q, x + Math.cos(an) * r * 0.75, y + Math.sin(an) * r * 0.75, r * 0.7, an, 1, C, 1);+ }+ q.px(x, y, hex("#ffe08a"));+ q.glow(x, y, 8, C[4], 0.2);+ });+}++// petals already fallen, scattered along the floor; they never move, so they're shaded once and replayed+const SCATTER = new Map();+function scatter(q, S, C) {+ const key = S + C.join();+ let px = SCATTER.get(key);+ if (!px) {+ px = [];+ const rec = {+ shade(x0, y0, x1, y1, fn) {+ const o = { c: 0, a: 1 };+ for (let y = Math.floor(y0); y <= Math.ceil(y1); y++)+ for (let x = Math.floor(x0); x <= Math.ceil(x1); x++) {+ o.c = 0;+ const c = fn(x + 0.5, y + 0.5, o) || o.c;+ if (c) px.push(x + 0.5, y + 0.5, c, o.a);+ }+ },+ };+ for (let i = 0; i < 46; i++) petal(rec, -164 + rand(S, i, 71) * 328, FLOOR + Math.floor(rand(S, i, 72) * 3) * 2, 2.6 + rand(S, i, 73), (rand(S, i, 74) - 0.5) * 1.2, 0.5, C, 1);+ SCATTER.set(key, px);+ }+ for (let i = 0; i < px.length; i += 4) q.dot(px[i], px[i + 1], px[i + 2], px[i + 3]);+}diff --git a/src/fx/weather/clouds.js b/src/fx/weather/clouds.jsindex 556ca23..eb7454a 100644--- a/src/fx/weather/clouds.js+++ b/src/fx/weather/clouds.js@@ -1,57 +1,102 @@-import { ramp, at, rng, wrap } from "../../core/index.js";-import { box, clip } from "./_lib.js";+// Banded volumes with a lit crest (light on the top edge, tones stepping down into the body, Bayer at the steps)+// after Sprite Fusion's open-source fog (https://www.spritefusion.com/pixel-art-vfx/fog), MIT License,+// Copyright (c) 2026 Hugo Duprez.+import { fit, clamp, rand, wrap, mix, TAU, WHITE } from "../../core/index.js";+import { clip, box, bayer } 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],+ desc: "Layers of clouds drift past a bright moon at night: silver-lit tops, dark bellies, edges that flare where they cross the moon, forming and thinning as they go.",+ tags: ["weather", "clouds", "moon", "night", "sky", "ambient", "loop"],+ size: [320, 180],+ origin: [160, 180],duration: 12,loop: true,- fps: 15,+ fps: 30,bg: "sky",- options: { palette: ["#141626", "#20243a", "#2e3450", "#424a6c", "#5c668a", "#808cae", "#b2bcd6", "#e4eaf6"], seed: 149 },+ options: {+ palette: ["#0c0c18", "#16172a", "#232540", "#363a5a", "#545a80", "#8088ae", "#bcc4e2", "#f2f4ff"],+ seed: 7,+ },};-// layers back to front: how many clouds, their size, their height, how many widths they drift a loop, tone+const D = 12, MX = 92, MY = -128, MR = 12;+// far to near: how many clouds, how wide, how tall their puffs, how high, drift speed, how long they live,+// tones [belly, body, upper, top], how see-throughconst 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 },+ { n: 7, w: [40, 70], h: [6, 11], y: [-150, -110], v: 3, life: [8, 11], tone: [2, 3, 4, 5], alpha: 0.7 },+ { n: 6, w: [60, 100], h: [9, 15], y: [-120, -70], v: 6, life: [8, 11], tone: [1, 2, 4, 6], alpha: 0.88 },+ { n: 5, w: [90, 140], h: [12, 20], y: [-80, -30], v: 10, life: [9, 12], tone: [1, 2, 3, 6], alpha: 1 },];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));- });+ const q = clip(p, meta), S = o.seed, C = fit(o.palette, 8);+ moon(q, C);+ LAYERS.forEach((L, j) => {+ for (let i = 0; i < L.n; i++) cloud(q, t, S, C, L, j, i);+ });+ // the moon's light over everything: a halo, brightest close in, catching any cloud that passes+ q.glow(MX, MY, 110, C[4], 0.14);+ q.glow(MX, MY, 40, C[5], 0.25);+ q.glow(MX, MY, 18, C[6], 0.3);+}++function moon(q, C) {+ q.shade(MX - MR - 1, MY - MR - 1, MX + MR + 1, MY + MR + 1, (x, y, out) => {+ const dx = x - MX, dy = y - MY, d = Math.hypot(dx, dy) / MR;+ if (d > 1) return;+ // a pale disc with darker seas, a bright limb on the lit side+ const sea = (dx + 4) ** 2 + (dy + 2) ** 2 < 14 || (dx - 3) ** 2 + (dy - 4) ** 2 < 9 || (dx - 5) ** 2 + (dy + 5) ** 2 < 4;+ out.c = d > 0.86 ? (dx + dy < 0 ? C[6] : WHITE) : sea ? C[5] : d < 0.5 && dx + dy < 0 ? WHITE : C[7];});}++// one cloud: born once a loop, it swells into shape, drifts, and thins away. Its outline is a row of puffs on a+// flat base; shading steps down from a silver top to a dark belly, and edges near the moon flare+function cloud(q, t, S, C, L, j, i) {+ const R = (k) => rand(S, j, i, k), life = L.life[0] + R(1) * (L.life[1] - L.life[0]), age = wrap(t - R(2) * D, D);+ if (age >= life) return;+ const u = age / life, grow = Math.min(1, u * 4) * Math.min(1, (1 - u) * 4), w = (L.w[0] + R(3) * (L.w[1] - L.w[0])) * (0.6 + 0.4 * grow);+ const x0 = -200 + R(4) * 330 + L.v * age, base = L.y[0] + R(5) * (L.y[1] - L.y[0]), H = (L.h[0] + R(6) * (L.h[1] - L.h[0])) * grow;+ if (H < 1.5) return;+ // a row of puffs along the base, and a tier of bigger ones heaped in the middle+ const n = 4 + Math.floor(R(7) * 4), puffs = [];+ for (let k = 0; k < n; k++) {+ const f = (k + 0.5) / n, r = H * (0.5 + 0.35 * Math.sin(Math.PI * f)) * (0.75 + 0.5 * R(10 + k)) * (1 + 0.06 * Math.sin((TAU * t) / D + k + i));+ puffs.push([x0 + w * (f - 0.5) + (R(20 + k) - 0.5) * 6, base - r * 0.3 - R(30 + k) * H * 0.15, r]);+ }+ for (let k = 0; k < 1 + Math.floor(R(8) * 3); k++) {+ const f = 0.3 + R(40 + k) * 0.4, r = H * (0.75 + 0.35 * R(50 + k)) * (1 + 0.05 * Math.sin((TAU * t) / D + k * 2 + i));+ puffs.push([x0 + w * (f - 0.5), base - H * 0.55 - r * 0.2, r]);+ }+ const x1 = x0 - w / 2 - H, x2 = x0 + w / 2 + H, B = box(meta);+ for (let x = Math.max(B.x0, Math.floor(x1)); x <= Math.min(B.x1 - 1, Math.ceil(x2)); x++) {+ const cx = x + 0.5;+ let top = Infinity, top2 = Infinity;+ for (const [px, py, r] of puffs) {+ const dx = cx - px;+ if (dx * dx >= r * r) continue;+ const y = py - Math.sqrt(r * r - dx * dx);+ if (y < top) (top2 = top), (top = y);+ else if (y < top2) top2 = y;+ }+ if (top === Infinity) continue;+ // a belly that's nearly flat, lifting at the ends and rippling a little+ const end = Math.min(cx - x1, x2 - cx) / H, bot = base + 1.5 + Math.sin(cx * 0.21 + i) * 0.8 - (end < 1 ? (1 - end) * 4 : 0);+ if (bot <= top) continue;+ const h = bot - top, inner = top2 - top > 2.5 && top2 < bot - 2 ? Math.floor(top2) : -999;+ for (let y = Math.floor(top); y < bot; y++) {+ const d = y + 0.5 - top, v = d / h, th = bayer(x, y) * 0.12, md = Math.hypot(cx - MX, y - MY);+ let c = d < 1 ? L.tone[3] : v < 0.25 + th ? L.tone[2] : v < 0.62 + th ? L.tone[1] : L.tone[0];+ // the top of a lower puff shows inside the body as a lit line: the cloud's lobes+ if (y === inner) c = Math.max(c, L.tone[2]);+ if (bot - y - 0.5 < 1 && v > 0.5) c = Math.max(0, L.tone[0] - 1);+ // the silver lining: near the moon the edges light right up+ if (md < 46 && (d < 2 || y === inner || v < 0.3)) c = Math.min(7, c + (md < 24 ? 2 : 1));+ const a = L.alpha * Math.min(1, grow * 1.5);+ if (a >= 1) q.px(x, y, C[c]);+ else q.blend(x, y, C[c], a);+ if (d < 1 && md < 46) q.light(x, y, C[6], 0.35 * (1 - md / 46));+ }+ }+}diff --git a/src/fx/weather/falling-leaves.js b/src/fx/weather/falling-leaves.jsindex f49deb3..d758e3b 100644--- a/src/fx/weather/falling-leaves.js+++ b/src/fx/weather/falling-leaves.js@@ -1,50 +1,141 @@-import { ramp, lerp, TAU } from "../../core/index.js";-import { box, clip, drift } from "./_lib.js";+// The falling leaf (a pendulum swing that speeds through the bottom of each arc, a tilt that follows it, a flip+// by squashing across, a rest on the ground, a litter of fallen leaves) is adapted from Sprite Fusion's+// open-source falling leaves (https://www.spritefusion.com/pixel-art-vfx/falling-leaves), MIT License,+// Copyright (c) 2026 Hugo Duprez.+import { fit, clamp, rand, wrap, mix, TAU, hex } from "../../core/index.js";+import { clip, rows, trips } 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,+ desc: "Autumn leaves swing down through the air, tilting and flipping to show their pale backs, ride a gust, land flat in the litter and fade.",+ tags: ["weather", "leaves", "autumn", "fall", "wind", "nature", "ambient", "loop"],+ size: [320, 180],+ origin: [160, 170],+ duration: 10,loop: true,fps: 30,- bg: "ground",- options: { palette: ["#2a120c", "#5a1c12", "#962c16", "#cc4a1c", "#e8782a", "#f4a83c", "#fad466"], count: 18, seed: 97 },+ bg: "sky",+ options: {+ palette: ["#4a1d0c", "#8a3a14", "#c8621e", "#f0982e", "#ffcf72", "#fff0c4"],+ reds: ["#40101a", "#7c1c22", "#b8302a", "#e85a3c", "#ff9a72", "#ffd8c4"],+ golds: ["#3e300c", "#7a5c14", "#b8901e", "#e8c23a", "#fff09a", "#fffbe0"],+ seed: 8,+ },};-// 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..."],+const D = 10, FLOOR = 1;+const gust = (t) => 16 * Math.sin((TAU * t) / D - 1.2) + 5 * Math.sin((TAU * 3 * t) / D);+// ∫|cos| from the start of a swing: speeds up through the bottom of each arc, so the drop does too+const Hc = (th) => {+ const k = Math.floor((th + Math.PI / 2) / Math.PI);+ return 2 * k + 1 + Math.sin(th - k * Math.PI);+};++// a leaf's outline in its own frame: u along it (-1 stem .. 1 tip), v across; 0 inside, > 1 outside+const SHAPES = [+ (u, v) => (Math.abs(u) >= 1 ? 9 : (v * v) / (0.36 * (1 - u * u) * (1.15 - 0.3 * u))), // a beech: a long oval, pointed tip+ (u, v) => {+ const r = Math.hypot(u, v * 1.1), a = Math.atan2(v, u);+ return r / (0.62 + 0.38 * Math.abs(Math.cos(2.5 * a)) ** 1.5); // a maple: five lobes+ },+ (u, v) => (Math.abs(u) >= 1 ? 9 : (v * v) / (0.16 * (1 - u * u))), // a willow: long and thin];-// far leaves: small and dim-const SMALL = [["ab.", "bbc", ".c."], ["a.", "bc"], ["a", "b", "c"], [".a", "cb"]];-const FLAT = [".aabb.", "abbbcc"];++export function drawBack(p, t, o) {+ const q = clip(p, meta), S = o.seed, R3 = ramps(o), C = R3[0];+ // a faint dusk haze, warmer low down, that keeps the sky's stars out of the leaves' way+ const top = hex("#0e0a12"), low = mix(hex("#140c14"), C[0], 0.3);+ rows(p, meta, -170, 9, (y, R) => {+ const k = (y + 170) / 180, c = mix(top, low, k * k);+ R.c.fill(c);+ R.a.fill(0.32 + 0.1 * k);+ R.b.fill(1);+ });+ litter(q, S, R3);+ leaves(q, t, S, R3, false);+}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);+ leaves(clip(p, meta), t, o.seed, ramps(o), true);+}++const ramps = (o) => [fit(o.palette, 6), fit(o.reds, 6), fit(o.golds, 6)];++function leaves(q, t, S, R3, front) {+ trips(t, D, 62, S * 19, 2, 3, (u, k, m, i) => {+ const j = wrap(k, m), R = (n) => rand(S * 19, i, j, n), near = R(1) < 0.35;+ if (near !== front) return;+ const dur = D / m, air = 0.72, tf = dur * air, a = Math.min(u * dur, tf), rest = u * dur - tf;+ const w = 1.7 + R(2) * 1.2, ph0 = R(3) * TAU, amp = (near ? 14 : 8) + R(4) * 10, x0 = -180 + R(5) * 340, y0 = -186;+ // the drop speed that lands it on the floor just as its time in the air runs out+ const path = (aa) => 0.45 * aa + (0.9 * (Hc(w * aa + ph0) - Hc(ph0))) / w, vy = (FLOOR - y0) / path(tf);+ const born = t - u * dur, xAt = (aa) => x0 + 7 * aa + Math.sin(w * aa + ph0) * amp + (gust(born + aa) - gust(born)) * (near ? 1 : 0.7);+ const size = (near ? 5.8 : 4.2) + R(6) * 1.6, shape = Math.floor(R(7) * 3), col = R3[Math.floor(R(8) * 3)];+ if (rest > 0) {+ // lying flat in the litter, fading+ const fade = 1 - rest / (dur - tf);+ leaf(q, xAt(tf), FLOOR - 1, size, (R(9) - 0.5) * 0.5, 0.42, shape, col, fade);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 });+ const x = xAt(a), y = y0 + vy * path(a), tilt = Math.cos(w * a + ph0) * 0.75 + (near ? 0 : 0.3);+ const flip = Math.cos(R(10) * TAU + a * (R(11) < 0.3 ? 5 : 1.2));+ leaf(q, x, y, size, tilt, flip, shape, col, 1);+ // a leaf turned full face to the light catches it for a moment+ if (flip > 0.86) {+ const k = (flip - 0.86) / 0.14, hx = x - Math.cos(tilt) * size * 0.3, hy = y - Math.sin(tilt) * size * 0.3 - 1;+ q.px(hx, hy, col[5]);+ q.glow(hx, hy, 5 + size * 0.5, col[4], 0.22 * k);+ }+ });+}++// draw a leaf: squash it across by `flip` (the sign says which face shows), tilt it, outline it, a midrib down+// the middle, the face lit on one side; the back face is paler and duller+function leaf(q, x, y, size, ang, flip, shape, col, a) {+ // like a card turning: never thinner than a third, and the back shows only past edge-on+ const back = flip < -0.25, fs = 0.35 + 0.65 * Math.abs(flip), c = Math.cos(ang), s = Math.sin(ang);+ const L = size, Wd = size * 0.9, ext = L + 1.5, shapeFn = SHAPES[shape];+ const face = back ? [mix(col[1], hex("#9c8a78"), 0.2), mix(col[2], hex("#c8b49c"), 0.22), mix(col[3], hex("#e0d0b8"), 0.22)] : [col[2], col[3], col[4]];+ const rim = col[0], vein = back ? mix(col[2], hex("#e8dcc8"), 0.5) : col[1];+ q.shade(x - ext, y - ext, x + ext, y + ext, (px, py, out) => {+ const dx = px - x, dy = py - y, lu = (dx * c + dy * s) / L, lv = (-dx * s + dy * c) / (Wd * fs);+ const d = shapeFn(lu, lv);+ if (lu < -1.25 || lu > 1.1) return;+ // the stem pokes out past the base+ if (lu < -0.92 && Math.abs(lv * Wd * fs) < 0.5) return void ((out.c = rim), (out.a = a));+ if (d > 1.32) return;+ out.a = a;+ if (d > 1) out.c = rim;+ else if (Math.abs(lv * Wd * fs) < 0.45 && lu > -0.9 && lu < 0.75) out.c = vein;+ else out.c = lv < -0.15 ? face[2] : lv < 0.35 ? face[1] : face[0];});}++// fallen leaves lying in a band along the floor, overlapping. They never move, so they're shaded once per seed+// and palette and the pixels replayed+const LITTER = new Map();+function litter(q, S, R3) {+ const key = S + R3.flat().join();+ let px = LITTER.get(key);+ if (!px) {+ px = [];+ const rec = {+ shade(x0, y0, x1, y1, fn) {+ const o = { c: 0, a: 1 };+ for (let y = Math.floor(y0); y <= Math.ceil(y1); y++)+ for (let x = Math.floor(x0); x <= Math.ceil(x1); x++) {+ o.c = 0;+ o.a = 1;+ const c = fn(x + 0.5, y + 0.5, o) || o.c;+ if (c) px.push(x + 0.5, y + 0.5, c, o.a);+ }+ },+ };+ for (let i = 0; i < 64; i++) {+ const x = -164 + rand(S, i, 91) * 328, y = FLOOR - 2 + Math.floor(rand(S, i, 92) * 4) * 2, col = R3[Math.floor(rand(S, i, 93) * 3)];+ leaf(rec, x, y, 3.6 + rand(S, i, 94) * 1.8, (rand(S, i, 95) - 0.5) * 0.7, 0.45 + rand(S, i, 96) * 0.25, Math.floor(rand(S, i, 97) * 3), col.map((c) => mix(c, col[0], 0.12)), 1);+ }+ LITTER.set(key, px);+ }+ for (let i = 0; i < px.length; i += 4) q.dot(px[i], px[i + 1], px[i + 2], px[i + 3]);+}diff --git a/src/fx/weather/fireflies.js b/src/fx/weather/fireflies.jsindex 1d0b555..2551190 100644--- a/src/fx/weather/fireflies.js+++ b/src/fx/weather/fireflies.js@@ -1,41 +1,125 @@-import { ramp, rng, clamp, TAU } from "../../core/index.js";-import { box, clip } from "./_lib.js";+// The firefly (a wandering point that glows up and fades on its own rhythm, close ones drawn with a dark body,+// beating wings and a lantern that throws a big soft light, grass blades swaying underneath) is adapted from+// Sprite Fusion's open-source fireflies (https://www.spritefusion.com/pixel-art-vfx/fireflies), MIT License,+// Copyright (c) 2026 Hugo Duprez.+import { fit, clamp, rand, mix, TAU, WHITE, loopNoise } from "../../core/index.js";+import { clip, rows } 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,+ desc: "Fireflies wander over a meadow at night, each glowing up and fading on its own rhythm, trailing light and lighting the grass tips beneath them.",+ tags: ["weather", "fireflies", "night", "glow", "meadow", "nature", "ambient", "loop"],+ size: [320, 180],+ origin: [160, 170],+ duration: 12,loop: true,fps: 30,- bg: "ground",- options: { palette: ["#1e2a10", "#4a6a18", "#a0c838", "#e8f878", "#ffffe0"], count: 12, seed: 103 },+ bg: "sky",+ options: {+ palette: ["#2a3a10", "#5a7a1a", "#9ad02a", "#d6ff5a", "#f4ffb8", "#ffffff"],+ grass: ["#070f0b", "#0c1a12", "#13281a", "#1d3a24", "#2b5232", "#3f6e40"],+ seed: 2,+ },};+const D = 12, cyc = (t, n, ph = 0) => (TAU * n * t) / D + ph;++// a firefly's path and glow, both whole cycles a loop. depth 0 far .. 2 near+function fly(S, i, t) {+ const R = (n) => rand(S, i, n), depth = i < 14 ? 0 : i < 26 ? 1 : 2, k = [0.5, 0.8, 1][depth];+ const cx = -150 + R(1) * 300, cy = -16 - R(2) * (depth === 2 ? 70 : 130);+ const ax = (14 + R(3) * 26) * k, ay = (8 + R(4) * 14) * k, n1 = 1 + Math.floor(R(5) * 2), n2 = 1 + Math.floor(R(6) * 3);+ const pos = (tt) => [+ cx + ax * Math.sin(cyc(tt, n1, R(7) * TAU)) + 10 * k * loopNoise(tt / D, 1.5, i * 3),+ cy + ay * Math.sin(cyc(tt, n2, R(8) * TAU)) + 6 * k * loopNoise(tt / D, 1.5, i * 3 + 1),+ ];+ // its rhythm: a quick rise, a hold, a slow fade, dark; some flash twice+ const per = D / (3 + Math.floor(R(9) * 4)), u = (((t / per + R(10)) % 1) + 1) % 1, two = R(11) < 0.35;+ const pulse = (v) => (v < 0.06 ? v / 0.06 : v < 0.14 ? 1 : v < 0.4 ? 1 - (v - 0.14) / 0.26 : 0);+ const glow = Math.max(pulse(u), two ? pulse(u - 0.22) * 0.8 : 0);+ return { pos, depth, glow, R };+}++export function drawBack(p, t, o) {+ const q = clip(p, meta), S = o.seed, C = fit(o.palette, 6), G = fit(o.grass, 6);+ // a cool night haze, so the sky's stars don't read as fireflies+ rows(p, meta, -170, 9, (y, R) => {+ const k = (y + 170) / 180;+ R.c.fill(mix(G[0], G[1], k));+ R.a.fill(0.48 + 0.14 * k);+ R.b.fill(1);+ });+ const flies = Array.from({ length: 32 }, (_, i) => fly(S, i, t));+ grass(q, t, S, G, C, flies, false);+ for (const f of flies) if (f.depth < 2) firefly(q, t, f, C);+}+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;+ const q = clip(p, meta), S = o.seed, C = fit(o.palette, 6), G = fit(o.grass, 6);+ const flies = Array.from({ length: 32 }, (_, i) => fly(S, i, t));+ grass(q, t, S, G, C, flies, true);+ for (const f of flies) if (f.depth === 2) firefly(q, t, f, C);+}++function firefly(q, t, f, C) {+ const [x, y] = f.pos(t), g = f.glow, X = Math.round(x), Y = Math.round(y);+ if (f.depth === 0) {+ if (g < 0.08) return;+ q.dot(X, Y, g > 0.6 ? C[4] : C[3], Math.min(1, g * 1.6));+ q.glow(x, y, 6, C[2], 0.45 * g);+ return;+ }+ // a short trail of light where it has just been, while it's lit+ if (g > 0.3)+ for (let j = 1; j <= 4; j++) {+ const [tx, ty] = f.pos(t - j * 0.05);+ q.dot(tx, ty, C[2], (g - 0.3) * (1 - j / 5) * 1.3);+ }+ if (f.depth === 1) {+ q.px(X, Y, g > 0.5 ? C[5] : g > 0.15 ? C[3] : C[1]);+ if (g > 0.4) q.px(X, Y + 1, C[2]);+ q.glow(x, y, 9, C[2], 0.5 * g);+ q.glow(x, y, 3, C[4], 0.5 * g);+ return;+ }+ // a close one: a dark body, wings a blur above it, a lantern at its tail; a glint at the peak+ const [nx] = f.pos(t + 0.05), dir = nx >= x ? 1 : -1, beat = Math.floor(t * 30) % 2;+ q.px(X + dir, Y, C[0]);+ q.px(X + dir * 2, Y, C[0]);+ q.dot(X, Y - 1 - beat, mix(C[1], WHITE, 0.4), 0.7);+ q.dot(X + dir, Y - 1 - beat, mix(C[1], WHITE, 0.4), 0.7);+ q.px(X, Y, g > 0.3 ? C[5] : C[1]);+ q.px(X - dir, Y, g > 0.5 ? C[4] : g > 0.15 ? C[3] : C[1]);+ if (g > 0.6) q.px(X - dir, Y + 1, C[3]);+ if (g > 0.7) for (const [dx, dy] of [[0, -2], [0, 2], [-2, 0], [2, 0]]) q.dot(X - dir + dx, Y + dy, C[3], (g - 0.7) * 3);+ q.glow(x, y, 28, C[2], 0.45 * g);+ q.glow(x, y, 10, C[4], 0.5 * g);+ q.glow(x, y, 4, C[5], 0.5 * g);+}++// the meadow: blades in two rows (the front row drawn over the low fireflies), swaying as the breeze rolls+// across, a few seed heads; blade tips near a lit firefly catch its light+function grass(q, t, S, G, C, flies, front) {+ const lit = flies.filter((f) => f.glow > 0.25 && f.depth > 0).map((f) => [...f.pos(t), f.glow]);+ const n = front ? 150 : 230;+ for (let i = 0; i < n; i++) {+ const R = (k) => rand(S * 3 + (front ? 1 : 0), i, k), x = -162 + (i + R(1)) * (324 / n), h = (front ? 4 : 5) + R(2) * (front ? 8 : 11) + (R(3) < 0.1 ? 6 : 0);+ const base = (front ? 9 : 2) - R(4) * 3, sway = (1.2 + R(5)) * Math.sin(cyc(t, 2, -x * 0.03) + R(6)) + 0.6 * Math.sin(cyc(t, 5, x * 0.07));+ const tone = front ? 1 + Math.floor(R(7) * 3) : 1 + Math.floor(R(7) * 2);+ let tipLight = 0;+ for (const [fx, fy, g] of lit) {+ const d = Math.hypot(fx - (x + sway), fy - (base - h));+ if (d < 28) tipLight = Math.max(tipLight, g * (1 - d / 28));+ }+ for (let r = 0; r < h; r++) {+ const u = r / h, c = u > 0.8 && tipLight > 0.2 ? (tipLight > 0.55 && u > 0.9 ? C[3] : C[2]) : u > 0.7 ? G[Math.min(5, tone + 1)] : G[tone];+ q.px(x + sway * u * u, base - r, c);}- 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]);+ if (R(8) < 0.07) {+ const sx = x + sway, sy = base - h;+ q.px(sx, sy - 1, tipLight > 0.2 ? C[3] : G[5]);+ q.px(sx - 1, sy, G[4]);+ q.px(sx + 1, sy, G[4]);}- 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.jsindex 673e67b..68785cb 100644--- a/src/fx/weather/fog.js+++ b/src/fx/weather/fog.js@@ -1,52 +1,101 @@-import { ramp, clamp, tileFbm, TAU } from "../../core/index.js";-import { box, clip } from "./_lib.js";+// The banded fog (a baked tiling noise, warped, cut into a few translucent tones with Bayer edges, a lit crest+// wherever a band's top meets thinner fog) is adapted from Sprite Fusion's open-source fog+// (https://www.spritefusion.com/pixel-art-vfx/fog), MIT License, Copyright (c) 2026 Hugo Duprez.+import { fit, clamp, smooth, mix, TAU, WHITE } from "../../core/index.js";+import { rows, field, sample, bayer } 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],+ desc: "Slow banks of moonlit fog at three depths drift past each other, crests catching the light, while thin streaks of mist slide by in front.",+ tags: ["weather", "fog", "mist", "haze", "night", "ambient", "loop"],+ size: [320, 180],+ origin: [160, 170],duration: 12,loop: true,- fps: 15,- bg: "ground",- options: { palette: ["#2a3040", "#465064", "#6c7890", "#9ca8bc", "#d0d8e4"], seed: 89 },+ fps: 30,+ bg: "sky",+ options: {+ palette: ["#14121e", "#24213a", "#363250", "#4f4a6c", "#6d688b", "#918cab", "#bdb8d4", "#ece8f6"],+ seed: 5,+ },};-// 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];+const D = 12, W = 320;+const T = [0.3, 0.5, 0.7], BW = 0.06;+// far to near: where each bank's top thins out (top..base), how far down it reaches, noise scale (the tile it+// scrolls each loop is 256 / sx px wide), tiles a loop, how opaque, tones [thin, body, dense], crest tone+const BANKS = [+ { top: -84, base: -40, bot: -20, sx: 1.6, sy: 2.2, lap: 1, alpha: 0.24, tone: [2, 3, 4], crest: 5, warp: 16, crestFrom: 3 },+ { top: -62, base: -24, bot: -2, sx: 1.0667, sy: 2.5, lap: 1, alpha: 0.3, tone: [2, 3, 4], crest: 5, warp: 22, crestFrom: 2 },+ { top: -42, base: -8, bot: 10, sx: 0.8, sy: 2.8, lap: 1, alpha: 0.36, tone: [2, 3, 5], crest: 6, warp: 28, crestFrom: 1 },+];+const BR = new Float32Array(W);+const P1 = BANKS.map(() => new Float32Array(W)), P2 = BANKS.map(() => new Float32Array(W)), WARP = new Float32Array(W);++export function drawBack(p, t, o) {+ const S = o.seed, C = fit(o.palette, 8);+ bank(p, t, S, C, 0);+ bank(p, t, S, C, 1);+}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];+ const S = o.seed, C = fit(o.palette, 8);+ bank(p, t, S, C, 2);+ streaks(p, t, S, C, 1);+}++function bank(p, t, S, C, n) {+ const B = BANKS[n], F = field(S * 7 + n, 256, 128), G = field(S * 7 + 11, 256, 128, [4, 8, 16]);+ const drift = (256 * B.lap * t) / D, boil = (128 * t) / D, prev1 = P1[n], prev2 = P2[n];+ const tones = B.tone.map((i) => C[i]), crest = mix(C[B.crest], WHITE, 0.12 + 0.08 * n);+ prev1.fill(0);+ prev2.fill(0);+ // the fog breathes: its top rises and falls a little along its length+ for (let i = 0; i < W; i++) BR[i] = 2 * Math.sin((TAU * t) / D + (i - 160) * 0.006 + n * 1.7);+ rows(p, meta, B.top - 2, B.bot, (y, R) => {+ const prof = smooth(B.top, B.base, y) * (1 - smooth(B.bot - (B.bot < 10 ? 14 : 4), B.bot + 1, y));+ for (let i = 0; i < W; i += 2) WARP[i] = WARP[i + 1] = sample(G, i * 0.35 + n * 70, y * 0.5 + boil) - 0.5;+ for (let i = 0; i < W; i++) {+ const x = i - 160 + 0.5, w = WARP[i];+ // the noise is pushed hard and clamped so it, not the height, shapes the fog: blobs, not stripes+ const nn = clamp((sample(F, x * B.sx + drift + w * B.warp, (y + BR[i]) * B.sy + w * 8) - 0.5) * 2.6 + 0.5) - 0.5;+ const f = prof <= 0.01 ? 0 : (prof * 0.72 + nn * 0.95) * (0.6 + 0.5 * prof);+ const above = prev2[i];+ prev2[i] = prev1[i];+ prev1[i] = f;+ if (f <= T[0]) continue;+ const th = bayer(i, y) * BW, band = f > T[2] + th ? 2 : f > T[1] + th ? 1 : 0, solid = f > T[2] ? 2 : f > T[1] ? 1 : 0;+ // a lit crest, one pixel thick, where this band's top meets thinner fog+ if (solid >= B.crestFrom && above < T[solid]) {+ R.c[i] = crest;+ R.a[i] = B.alpha * 0.95;+ R.l[i] = C[6];+ R.k[i] = 0.07;+ } else {+ // dense fog scatters the most moonlight: it's the brightest part, with a little glow+ R.c[i] = tones[band];+ R.a[i] = B.alpha * (0.55 + 0.25 * band);+ if (band === 2) (R.l[i] = C[5]), (R.k[i] = 0.03 + 0.02 * n);}- });- }+ R.b[i] = 1;+ }+ });+}++// thin streaks of mist sliding by faster than the banks, a few behind the near bank and a few in front+function streaks(p, t, S, C, front) {+ // one tile a loop: the back streaks slide at 43 px/s, the front ones at 53+ const F = field(S * 7 + 20 + front, 256, 128), drift = (256 * t) / D, sx = front ? 0.4 : 0.5, y0 = front ? -40 : -96, y1 = front ? 6 : -30;+ rows(p, meta, y0, y1, (y, R) => {+ const env = smooth(y0, y0 + 10, y) * (1 - smooth(y1 - 10, y1, y));+ for (let i = 0; i < W; i++) {+ const x = i - 160 + 0.5, s = (sample(F, x * sx + drift, y * 6.5 + 30) - 0.64) * 3 * env;+ if (s <= 0.05) continue;+ R.c[i] = s > 0.35 ? C[5] : C[4];+ R.a[i] = Math.min(0.4, s);+ R.b[i] = 1;+ R.l[i] = C[5];+ R.k[i] = s * 0.05;+ }+ });}diff --git a/src/fx/weather/god-rays.js b/src/fx/weather/god-rays.jsindex 25eed44..5902f1d 100644--- a/src/fx/weather/god-rays.js+++ b/src/fx/weather/god-rays.js@@ -1,64 +1,117 @@-import { ramp, rng, clamp, TAU } from "../../core/index.js";-import { box, clip } from "./_lib.js";+// The banded light (posterized steps from a hot core to the edges, fine strands through it, light laid over the top)+// is adapted from Sprite Fusion's open-source holy light (https://www.spritefusion.com/pixel-art-vfx/holy-light),+// MIT License, Copyright (c) 2026 Hugo Duprez.+import { fit, clamp, rand, mix, TAU, WHITE } from "../../core/index.js";+import { clip, rows } 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,+ desc: "Shafts of light slant down from high on the left, breathing and swaying, pooling on the floor, as drifting dust motes light up whenever they cross a beam.",+ tags: ["weather", "god rays", "light", "sunbeam", "dust", "ambient", "loop"],+ size: [320, 180],+ origin: [160, 170],+ duration: 10,loop: true,fps: 30,- bg: "dark",- options: { palette: ["#3a2a14", "#7a5a28", "#c8a050", "#f4dc96", "#fff8e0"], count: 40, seed: 131 },+ bg: "sky",+ options: {+ palette: ["#1a1208", "#3a2810", "#7a5a24", "#c89a44", "#f2d27a", "#fff2c4", "#ffffff"],+ seed: 3,+ },};-// shafts: [offset across, width, strength, breathing phase]+const D = 10, W = 320, SX = -230, SY = -300;+// the fan's axis (down and to the right) and its normal; a pixel's place across the fan is its angle from it+const AX = Math.cos(0.94), AY = Math.sin(0.94), NX = -AY, NY = AX;+// the shafts: angle off the axis, half width (radians), strength, breathing (cycles a loop), swayconst SHAFTS = [- [-30, 7, 0.8, 0],- [-14, 12, 1, 1.7],- [6, 5, 0.6, 3.1],- [20, 9, 0.85, 4.4],+ { c: -0.27, h: 0.03, k: 0.65, b: 1, sw: 0.006 },+ { c: -0.17, h: 0.022, k: 0.55, b: 2, sw: 0.005 },+ { c: -0.07, h: 0.05, k: 1, b: 1, sw: 0.008 },+ { c: 0.03, h: 0.018, k: 0.6, b: 3, sw: 0.004 },+ { c: 0.12, h: 0.042, k: 0.85, b: 2, sw: 0.007 },+ { c: 0.23, h: 0.026, k: 0.6, b: 1, sw: 0.005 },];+const STR = new Float32Array(512);-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;+// light at a point: the shafts it's in, softened at their edges, fading with distance, threaded with strands+function lightAt(x, y, sh) {+ const dx = x - SX, dy = y - SY, r = dx * AX + dy * AY, ang = (dx * NX + dy * NY) / r;+ let e = 0;+ for (const s of sh) {+ const q = Math.abs(ang - s.c) / s.h;+ if (q < 1) e += s.k * (1 - q * q) ** 1.5;+ }+ if (e <= 0) return 0;+ const strand = STR[clamp(Math.floor((ang + 0.36) * 700), 0, 511)], fall = clamp(1.25 - (r - 230) / 420);+ return e * fall * (0.7 + 0.45 * strand);+}++export function drawBack(p, t, o) {+ const q = clip(p, meta), S = o.seed, C = fit(o.palette, 7);+ const sh = shafts(t, S);+ // dark air the light falls through, a dark floor it lands on; each beam posterized into a white-hot core, a+ // gold body and a soft translucent edge, brightest near the sun and fading as it falls+ const L = C.map((c) => mix(C[0], c, 0.75));+ const n = sh.length, SC = new Float32Array(n), SI = new Float32Array(n), SK = new Float32Array(n);+ sh.forEach((s, j) => ((SC[j] = s.c), (SI[j] = 1 / s.h), (SK[j] = s.k)));+ rows(p, meta, -170, 9, (y, R) => {+ const floor = y > 0, dy = y - SY, air = floor ? 0.8 : 0.66, boost = floor ? 1.6 : 1;+ let r = (-160 + 0.5 - SX) * AX + dy * AY, nn = (-160 + 0.5 - SX) * NX + dy * NY;+ R.a.fill(air);+ R.b.fill(1);+ R.c.fill(C[0]);+ for (let i = 0; i < W; i++, r += AX, nn += NX) {+ const ang = nn / r;+ let e = 0;+ for (let j = 0; j < n; j++) {+ const q2 = (ang - SC[j]) * SI[j];+ if (q2 > -1 && q2 < 1) {+ const w = 1 - q2 * q2;+ e += SK[j] * w * Math.sqrt(w);+ }+ }+ if (e <= 0) continue;+ const fall = 1.35 - (r - 200) / 330, si = ((ang + 0.36) * 700) | 0;+ e *= (fall > 1 ? 1 : fall < 0 ? 0 : fall) * (0.7 + 0.45 * STR[si < 0 ? 0 : si > 511 ? 511 : si]) * boost;+ if (e < 0.06) continue;+ const lv = e > 1.05 ? 6 : e > 0.78 ? 5 : e > 0.52 ? 4 : e > 0.3 ? 3 : 2;+ R.c[i] = floor ? C[lv] : L[lv];+ R.a[i] = floor ? 0.85 : Math.min(0.78, 0.12 + e * 0.5);+ R.l[i] = C[4];+ R.k[i] = e * (floor ? 0.32 : 0.26);}- // 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]);+ // the sun's glare where the beams come in+ q.glow(-168, -178, 130, C[3], 0.3);+ q.glow(-168, -178, 50, C[5], 0.35);+ motes(q, t, S, C, sh, false);+}++export function draw(p, t, o) {+ const q = clip(p, meta), S = o.seed, C = fit(o.palette, 7);+ motes(q, t, S, C, shafts(t, S), true);+}++// each shaft breathes and sways on whole cycles; the strands drift slowly across the beams+function shafts(t, S) {+ for (let i = 0; i < 512; i++) {+ const a = i / 512;+ STR[i] = 0.5 + 0.5 * Math.sin(a * 190 + Math.sin((TAU * t) / D) * 2 + S) * Math.sin(a * 77 - (TAU * t) / D + S * 2);+ }+ return SHAFTS.map((s, i) => ({ c: s.c + s.sw * Math.sin((TAU * t) / D + i * 1.3), h: s.h * (1 + 0.15 * Math.sin((TAU * s.b * t) / D + i)), k: s.k * (0.72 + 0.28 * Math.sin((TAU * s.b * t) / D + i * 2.1)) }));+}++// dust motes drifting slowly, invisible in the dark, catching the light as they cross a beam+function motes(q, t, S, C, sh, front) {+ for (let i = front ? 0 : 50; i < (front ? 50 : 160); i++) {+ const R = (k) => rand(S, i, k), n1 = 1 + Math.floor(R(1) * 2), n2 = 1 + Math.floor(R(2) * 2);+ const x = -170 + R(3) * 340 + (8 + R(4) * 14) * Math.sin((TAU * n1 * t) / D + R(5) * TAU), y = -170 + R(6) * 172 + (6 + R(7) * 10) * Math.sin((TAU * n2 * t) / D + R(8) * TAU) + 4 * Math.sin((TAU * 3 * t) / D + i);+ const e = lightAt(x, y, sh);+ if (e < 0.12) continue;+ const big = front && R(9) < 0.5, k = Math.min(1, e);+ q.px(x, y, k > 0.6 ? WHITE : k > 0.3 ? C[5] : C[4]);+ if (big && k > 0.5) (q.px(x + 1, y, C[4]), q.px(x, y + 1, C[4]));+ q.glow(x, y, big ? 6 : 4, C[4], 0.4 * k);}}diff --git a/src/fx/weather/hail.js b/src/fx/weather/hail.jsdeleted file mode 100644index 6a83f8a..0000000--- a/src/fx/weather/hail.js+++ /dev/null@@ -1,49 +0,0 @@-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.jsdeleted file mode 100644index 614afef..0000000--- a/src/fx/weather/heat-haze.js+++ /dev/null@@ -1,51 +0,0 @@-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.jsindex 2bb9c9c..20fe94b 100644--- a/src/fx/weather/rain.js+++ b/src/fx/weather/rain.js@@ -1,48 +1,158 @@-import { ramp, lerp, TAU } from "../../core/index.js";-import { box, clip, drift } from "./_lib.js";+// The rain recipe (depth layers of two-tone streaks, far drops that end in the air, near ones that splash and+// throw droplets, mist low on the ground) is adapted from Sprite Fusion's open-source rain+// (https://www.spritefusion.com/pixel-art-vfx/rain), MIT License, Copyright (c) 2026 Hugo Duprez.+import { fit, clamp, smooth, rand, wrap, mix, WHITE } from "../../core/index.js";+import { clip, pass, field, sample, trips, crown, bayer } 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,+ desc: "Slanted rain at four depths: far drops fade into the dark, near ones glint and splash, drops ring the puddles and a low mist drifts over the wet floor.",+ tags: ["weather", "rain", "storm", "water", "ambient", "loop"],+ size: [320, 180],+ origin: [160, 170],+ duration: 8,loop: true,fps: 30,- bg: "ground",- options: { palette: ["#1c2c48", "#2e4a72", "#4c78a8", "#86b6de", "#cfe8fa"], count: 60, slant: 0.28, seed: 71 },+ bg: "sky",+ options: {+ palette: ["#0e1322", "#1a2440", "#283a5e", "#3a5482", "#5674a8", "#84a6d6", "#c0dcf8", "#f2f8ff"],+ density: 1,+ seed: 4,+ },};-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]);+const D = 8, SLANT = -0.2, UX = SLANT / Math.hypot(SLANT, 1), UY = 1 / Math.hypot(SLANT, 1);+// the depths, far to near: how many, falls a loop (speed), streak length, colors (tail, body, head), where+// they end (in the air, or on the floor at depth z), how big their splash+const LAYERS = [+ { n: 200, m: [10, 13], len: 2, col: [2, 2, 3], stop: [-80, -6] },+ { n: 150, m: [14, 17], len: 4, col: [2, 3, 4], stop: [-45, -2] },+ { n: 96, m: [19, 23], len: 7, col: [3, 4, 5], z: [0, 1.4], size: [0.15, 0.4] },+ { n: 42, m: [25, 29], len: 13, col: [3, 5, 7], z: [2, 6.5], size: [0.6, 1], near: true },+];++// puddles on the wet floor: long thin strips that hold the sky, at depth y, from x0 to x1+function pools(S) {+ return Array.from({ length: 5 }, (_, i) => {+ const x = -150 + i * 66 + rand(S, i, 61) * 30, w = 16 + rand(S, i, 63) * 26;+ return { x0: x, x1: x + w, y: 3 + Math.floor(rand(S, i, 62) * 3) };+ });+}+const poolAt = (P, x, y) => P.find((p) => x >= p.x0 + 2 && x <= p.x1 - 2 && Math.abs(y - p.y) < 1.5);++export function drawBack(p, t, o) {+ t = Math.round(t * 3e4) / 3e4;+ const q = clip(p, meta), S = o.seed, C = fit(o.palette, 8), P = pools(S);+ // an overcast haze, thicker toward the ground, that hides the stars+ const haze = mix(C[0], C[1], 0.6);+ pass(p, meta, -170, -0.5, (x, y, out) => {+ out.c = haze;+ out.a = 0.3 + 0.26 * smooth(-170, 0, y);+ out.b = 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;+ floor(q, t, S, C, P);+ for (let L = 0; L < 3; L++) layer(q, t, S, C, P, L, o.density);+ mist(p, t, S, C);+}++export function draw(p, t, o) {+ t = Math.round(t * 3e4) / 3e4;+ const q = clip(p, meta), S = o.seed, C = fit(o.palette, 8), P = pools(S);+ layer(q, t, S, C, P, 3, o.density);+}++// one depth of rain: each slot falls a whole number of times a loop, somewhere new each time+function layer(q, t, S, C, P, L, density) {+ const Ly = LAYERS[L], sd = S * 11 + L, [c0, c1, c2] = Ly.col.map((i) => C[i]), len = Ly.len;+ const n = Math.round(Ly.n * density), G = field(S + 21, 256, 128, [4, 8, 16]), sweep = (256 * t) / D;+ trips(t, D, n, sd, Ly.m[0], Ly.m[1], (u, k, m, i) => {+ const j = wrap(k, m);+ // gusts: sheets of heavier and lighter rain sweep across with the wind+ if (L < 2 && rand(sd, i, j, 7) > 0.35 + 1.3 * (sample(G, (-166 + rand(sd, i, j, 2) * 332) * 0.8 + sweep, 9 + L * 40) - 0.32)) return;+ const end = Ly.z ? Ly.z[0] + rand(sd, i, j, 1) * (Ly.z[1] - Ly.z[0]) : Ly.stop[0] + rand(sd, i, j, 1) * (Ly.stop[1] - Ly.stop[0]);+ const y0 = -172 - len, y = y0 + (end - y0) * u, x = -166 + rand(sd, i, j, 2) * 332 - (end - y) * SLANT;+ // far drops thin out before they end; near ones are whole+ const a = Ly.z ? 1 : Math.min(1, (1 - u) * 5);+ if (len <= 2) q.dot(x, y, c2, a), q.dot(x - UX, y - UY, c1, a * 0.8);+ else {+ q.line(x - UX * len, y - UY * len, x - UX * len * 0.45, y - UY * len * 0.45, c0, (v) => a * (0.35 + 0.65 * v));+ q.line(x - UX * len * 0.45, y - UY * len * 0.45, x - UX, y - UY, c1, a);+ q.dot(x, y, c2, a);}- // 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]);+ // near drops catch the light+ if (Ly.near) q.glow(x, y - 2, 4, C[5], 0.12);+ if (!Ly.z) return;+ // the drops before this one landed: a crown on the ground, or rings sliding apart along a puddle+ const dur = D / m;+ for (let back = 1; back < 4; back++) {+ const age = u * dur + (back - 1) * dur;+ if (age > 0.7) break;+ const jp = wrap(k - back, m), z = Ly.z[0] + rand(sd, i, jp, 1) * (Ly.z[1] - Ly.z[0]), xp = -166 + rand(sd, i, jp, 2) * 332;+ if (rand(sd, i, jp, 5) > (Ly.near ? 1 : 0.7)) continue;+ const size = Ly.size[0] + ((z - Ly.z[0]) / (Ly.z[1] - Ly.z[0])) * (Ly.size[1] - Ly.size[0]), pool = Ly.near && poolAt(P, xp, z);+ if (pool) rings(q, xp, pool, age, C);+ else if (crown(q, xp, z, age, size, { hot: C[6], cool: C[4], white: WHITE }, rand(sd, i, jp, 4)) && Ly.near && age < 0.1) q.glow(xp, z - 1, 5, C[5], 0.3 * (1 - age / 0.1));}- 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);+ });+}++// a drop in a puddle: a bright point, then rings seen edge-on, so two short dashes sliding apart, twice+function rings(q, x, pool, age, C) {+ const X = Math.round(x), y = pool.y;+ if (age < 0.05) q.px(X, y, C[7]);+ for (let r = 0; r < 2; r++) {+ const a = age - r * 0.16, u = a / 0.5;+ if (u <= 0 || u >= 1) continue;+ const w = Math.round(1 + 7 * Math.sqrt(u)), c = u < 0.4 && !r ? C[6] : C[5];+ for (const s of [-1, 1])+ for (let d = 0; d < (u < 0.6 ? 2 : 1); d++) {+ const px = X + s * (w - d);+ if (px > pool.x0 && px < pool.x1) q.px(px, y, c);+ }+ }+}++// the wet floor: a clean wet edge (a lit lip over a dark line), a dark sheen, puddle strips holding the sky+function floor(q, t, S, C, P) {+ pass(q, meta, 0, 9.5, (x, y, out) => {+ if (y < 1) return void ((out.c = C[4]), (out.l = C[5]), (out.k = 0.08));+ if (y < 2) return void (out.c = C[1]);+ out.c = C[0];+ out.a = 0.55;+ out.b = 1;+ for (const p of P)+ if (x >= p.x0 && x < p.x1 && Math.floor(y) === p.y) {+ const edge = x < p.x0 + 2 || x >= p.x1 - 2;+ out.c = edge ? C[3] : C[4];+ out.a = 1;+ out.b = 0;+ out.l = C[5];+ out.k = 0.06;+ }+ });+ // a glint that slides slowly along each puddle+ P.forEach((p, i) => {+ const gx = Math.round(p.x0 + 3 + (p.x1 - p.x0 - 6) * (0.5 + 0.5 * Math.sin((Math.PI * 2 * t) / D + i * 1.9)));+ q.px(gx, p.y, C[6]);+ q.glow(gx, p.y, 4, C[5], 0.2);+ });+}++// mist kicked up by the rain, drifting low along the ground: soft bands with lit crests+function mist(p, t, S, C) {+ const M = field(S + 9, 256, 128, [4, 8, 16, 32]), drift = (256 * t) / D, crest = mix(C[4], C[5], 0.5);+ const dens = (x, y) => {+ const prof = smooth(-22, -4, y) * (1 - smooth(7, 10, y));+ return prof * (0.62 + (sample(M, x * 0.45 + drift, y * 4 + 30) - 0.5) * 2);+ };+ pass(p, meta, -20, 9, (x, y, out) => {+ const d = dens(x, y);+ if (d < 0.28) return;+ const th = bayer(x, y) * 0.06;+ out.b = 1;+ if (d > 0.46 + th && dens(x, y - 1) < 0.43) (out.c = crest), (out.a = 0.5);+ else (out.c = d > 0.58 + th ? C[4] : C[3]), (out.a = clamp((d - 0.28) * 1.6) * 0.5);+ out.l = C[4];+ out.k = (d - 0.3) * 0.1;});}diff --git a/src/fx/weather/sandstorm.js b/src/fx/weather/sandstorm.jsdeleted file mode 100644index cd43bba..0000000--- a/src/fx/weather/sandstorm.js+++ /dev/null@@ -1,53 +0,0 @@-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.jsindex 98e78ad..292d444 100644--- a/src/fx/weather/shooting-stars.js+++ b/src/fx/weather/shooting-stars.js@@ -1,58 +1,121 @@-import { ramp, rng, seg, ease, lerp, clamp, TAU } from "../../core/index.js";-import { box, clip } from "./_lib.js";+// The glints (a cross of rays with a white heart and soft light, little twinkling stars around it) are adapted from+// Sprite Fusion's open-source sparkle (https://www.spritefusion.com/pixel-art-vfx/sparkle), MIT License,+// Copyright (c) 2026 Hugo Duprez.+import { fit, clamp, smooth, rand, wrap, mix, at, TAU, WHITE, sparkle } from "../../core/index.js";+import { clip, rows, box } 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,+ desc: "Meteors burn across a starry sky, white heads trailing gold and rose; the big ones flare and break up, and each leaves a glowing train that twists and fades.",+ tags: ["weather", "meteor", "shooting star", "night", "sky", "stars", "ambient", "loop"],+ size: [320, 180],+ origin: [160, 180],+ duration: 10,loop: true,fps: 30,bg: "sky",- options: { palette: ["#1c2a5a", "#3a5aa8", "#7ca4e8", "#c8e0ff", "#fff8e8", "#ffffff"], seed: 113 },+ options: {+ palette: ["#3a1e5a", "#7a3a8a", "#e0607a", "#ffa86a", "#ffe6a8", "#ffffff"],+ sky: ["#141428", "#2a2a4a", "#4c4c7c", "#8e8ec4", "#dcdcff"],+ seed: 4,+ },};-// meteors: [start time, start x, start y, angle, speed, trail length]+const D = 10;+// the meteors: when, where they start, which way, how fast, how long they burn, how big; the last flaresconst 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],+ { t0: 0.5, x: 60, y: -170, a: 2.45, v: 260, life: 0.55, s: 0.6 },+ { t0: 1.9, x: -40, y: -176, a: 2.2, v: 220, life: 0.7, s: 0.8 },+ { t0: 3.4, x: 150, y: -150, a: 2.62, v: 300, life: 0.45, s: 0.5 },+ { t0: 4.6, x: 130, y: -178, a: 2.35, v: 240, life: 1.05, s: 1.4, flare: true },+ { t0: 6.7, x: -90, y: -168, a: 2.05, v: 200, life: 0.6, s: 0.7 },+ { t0: 7.9, x: 20, y: -160, a: 2.5, v: 280, life: 0.5, s: 0.6 },+ { t0: 9.2, x: -10, y: -176, a: 2.28, v: 230, life: 0.8, s: 1, flare: true },];-const LIFE = 0.5;+const TRAIN = 1.6;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]);+ const q = clip(p, meta), B = box(meta), S = o.seed, C = fit(o.palette, 6), K = fit(o.sky, 5);+ sky(p, q, t, S, K);+ METEORS.forEach((m, i) => meteor(q, wrap(t - m.t0, D), m, i, S, C));+}++// the starfield: a faint milky band across the sky, dim specks, steady stars, a few that twinkle with a glint+function sky(p, q, t, S, K) {+ rows(p, meta, -180, -1, (y, R) => {+ for (let i = 0; i < 320; i++) {+ const x = i - 160 + 0.5, d = Math.abs((y + 110) - (x * -0.32)) / 36;+ if (d >= 1) continue;+ const k = (1 - d) * (1 - d);+ R.l[i] = K[2];+ R.k[i] = 0.1 * k;+ if (rand(i, Math.floor(y), S, 5) < 0.05 * k) (R.c[i] = K[2]), (R.a[i] = 0.7);+ }+ });+ for (let i = 0; i < 130; i++) {+ const x = -160 + rand(S, i, 1) * 320, y = -180 + rand(S, i, 2) * 178, r = rand(S, i, 3), c = 1 + Math.floor(rand(S, i, 4) * 4);+ const tw = 0.5 + 0.5 * Math.sin((TAU * c * t) / D + rand(S, i, 5) * TAU);+ if (r < 0.6) q.dot(x, y, K[3], 0.35 + 0.5 * tw);+ else if (r < 0.94) (q.px(x, y, r < 0.8 ? K[4] : WHITE), q.glow(x + 0.5, y + 0.5, 3, K[3], 0.22 * tw));+ else sparkle(q, x, y, 1 + Math.round(tw * 2), K[4], K[3], 0.3 * tw);+ }+}++// one meteor, age seconds after it lights: a head that brightens and burns out, a trail cooling down the ramp+// behind it, a flare and fragments for the big ones, and the train it leaves glowing and twisting as it fades+function meteor(q, age, m, i, S, C) {+ const ca = Math.cos(m.a), sa = Math.sin(m.a), end = m.life + (m.flare ? 0.5 : 0) + TRAIN;+ if (age > end) return;+ const pos = (tt) => [m.x + ca * m.v * tt, m.y + sa * m.v * tt], burn = Math.min(age, m.life), [hx, hy] = pos(burn);+ // the train: the whole path it has burned, lingering, widening, drifting and twisting+ const trainK = age < m.life ? 1 : 1 - (age - m.life) / (TRAIN + (m.flare ? 0.5 : 0));+ if (trainK > 0) {+ const len = m.v * burn, nx = -sa, ny = ca;+ for (let d = 0; d < len; d += 1) {+ const passed = age - d / m.v;+ if (passed < 0.08) continue;+ const g = trainK * Math.min(1, (passed - 0.08) * 4) * (0.35 + 0.65 * Math.sin((Math.PI * d) / len)) * m.s, tw = Math.sin(d * 0.09 + passed * 1.7) * Math.min(4, passed * 3);+ const x = m.x + ca * d + nx * tw + passed * 4, y = m.y + sa * d + ny * tw;+ q.dot(x, y, passed < 0.6 ? C[2] : C[1], g * 0.75);+ if (d % 6 === 0) q.glow(x, y, 6 + passed * 4, C[1], 0.12 * g);+ }}- 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));+ if (age > m.life + (m.flare ? 0.5 : 0)) return;+ // the head brightens fast, holds, and burns out; the big ones flare as they go+ const u = age / m.life, k = age < m.life ? Math.min(1, u * 6) * (u > 0.75 ? 1 - (u - 0.75) / 0.25 : 1) : 0;+ if (k > 0) {+ const L = (24 + 40 * m.s) * Math.min(1, u * 3);+ for (let d = 0; d <= L; d += 0.5) {+ const v = d / L, x = hx - ca * d, y = hy - sa * d;+ q.dot(x, y, v < 0.08 ? WHITE : at(C.slice(1).reverse(), v * 0.95), k * (v < 0.6 ? 1 : (1 - v) / 0.4));+ if (m.s > 0.9 && v < 0.4) q.dot(x - sa * 0.9, y + ca * 0.9, v < 0.15 ? C[4] : C[3], k * (1 - v / 0.4));}+ q.px(hx, hy, WHITE);+ if (m.s > 0.9) (q.px(hx + 1, hy, WHITE), q.px(hx, hy + 1, C[4]));+ q.glow(hx, hy, 8 + 10 * m.s, C[4], 0.45 * k);+ q.glow(hx - ca * L * 0.3, hy - sa * L * 0.3, 10 + 8 * m.s, C[3], 0.2 * k);+ }+ if (!m.flare || age < m.life * 0.82) return;+ // the flare: a burst of light and rays, fragments carrying on and fading+ const f = (age - m.life * 0.82) / (m.life * 0.18 + 0.5), [fx, fy] = pos(m.life * 0.86);+ if (f < 0.35) {+ sparkle(q, fx, fy, 9 * Math.sin((Math.PI * f) / 0.35) + 2, C[4], C[3], 0.6);+ q.glow(fx, fy, 40, C[3], 0.5 * (1 - f / 0.35));+ }+ // little stars scattered round the burst, each twinkling once and gone+ for (let j = 0; j < 7; j++) {+ const ang = rand(S, i, j, 5) * TAU, r = 5 + rand(S, i, j, 6) * 16, d0 = rand(S, i, j, 7) * 0.3, g = (f - d0) / 0.45;+ if (g <= 0 || g >= 1) continue;+ const sx = fx + Math.cos(ang) * r * (0.6 + g * 0.5), sy = fy + Math.sin(ang) * r * (0.6 + g * 0.5) - g * 3, arm = Math.round(2.5 * Math.sin(Math.PI * g));+ if (arm >= 1) sparkle(q, sx, sy, arm, j % 3 ? C[4] : WHITE, C[3], 0.3 * (1 - g));+ else q.px(sx, sy, C[4]);+ }+ for (let j = 0; j < 4; j++) {+ const da = (rand(S, i, j, 1) - 0.5) * 0.5, sp = m.v * (0.5 + rand(S, i, j, 2) * 0.4), tt = f * (m.life * 0.18 + 0.5), g = 1 - f;+ const x = fx + Math.cos(m.a + da) * sp * tt, y = fy + Math.sin(m.a + da) * sp * tt;+ if (g <= 0) continue;+ q.line(x - Math.cos(m.a + da) * 5 * g, y - Math.sin(m.a + da) * 5 * g, x, y, C[3], g);+ q.px(x, y, g > 0.5 ? WHITE : C[4]);+ q.glow(x, y, 5, C[3], 0.35 * g);}}diff --git a/src/fx/weather/snow.js b/src/fx/weather/snow.jsindex 2d8c962..b1307a4 100644--- a/src/fx/weather/snow.js+++ b/src/fx/weather/snow.js@@ -1,43 +1,128 @@-import { ramp, lerp, TAU } from "../../core/index.js";-import { box, clip, drift } from "./_lib.js";+// The snow recipe (depth layers falling at their own speeds with a sway, a gusty wind, flakes that settle on a+// drift for a while) is adapted from Sprite Fusion's open-source snow (https://www.spritefusion.com/pixel-art-vfx/snow),+// MIT License, Copyright (c) 2026 Hugo Duprez.+import { fit, clamp, smooth, rand, wrap, mix, TAU, WHITE } from "../../core/index.js";+import { clip, pass, trips } 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.",+ desc: "Snow at three depths in a gusty breeze: far specks, drifting flakes, big near crystals that spin and glow; they settle on a sparkling drift and melt away.",tags: ["weather", "snow", "winter", "cold", "ambient", "loop"],- size: [128, 72],- origin: [64, 36],- duration: 6,+ size: [320, 180],+ origin: [160, 170],+ duration: 12,loop: true,fps: 30,bg: "sky",- options: { palette: ["#3a4660", "#6a7a98", "#a8b8d0", "#e4eef8", "#ffffff"], count: 80, seed: 79 },+ options: {+ palette: ["#0c1020", "#161d36", "#24304f", "#3a4a72", "#5f74a3", "#93abd6", "#cfe0fa", "#ffffff"],+ seed: 6,+ },};-const FLAKE = [".a.", "aba", ".a."];-const BIG = ["..a..", ".aba.", "abcba", ".aba.", "..a.."];+const D = 12;+// the drift's top edge, and the gusts: a sway of the whole snowfall, periodic so the loop closes+const bank = (x) => -3 + 1.6 * Math.sin(x * 0.045 + 1.3) + 1.1 * Math.sin(x * 0.12 + 0.4) + 0.6 * Math.sin(x * 0.31 + 2);+const gust = (t) => 10 * Math.sin((TAU * t) / D + 0.6) + 4 * Math.sin((TAU * 2 * t) / D + 2.1);+// far to near: how many, falls a loop, share of a fall spent in the air (the rest lying on the drift), sway, wind+const LAYERS = [+ { n: 230, m: [1, 2], air: 1, sway: [1, 3], wind: 3, gust: 0.4 },+ { n: 140, m: [2, 3], air: 0.8, sway: [3, 7], wind: 6, gust: 0.7 },+ { n: 24, m: [2, 3], air: 0.74, sway: [8, 15], wind: 9, gust: 1 },+];-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]);+export function drawBack(p, t, o) {+ const q = clip(p, meta), S = o.seed, C = fit(o.palette, 8);+ // a cold haze, thicker low down, so the sky's stars don't read as snow+ const haze = mix(C[1], C[2], 0.4);+ pass(p, meta, -170, 9, (x, y, out) => {+ out.c = haze;+ out.a = 0.26 + 0.22 * smooth(-170, 0, y);+ out.b = 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]);+ layer(q, t, S, C, 0);+ drift(q, t, S, C);+ layer(q, t, S, C, 1);+}++export function draw(p, t, o) {+ const q = clip(p, meta), S = o.seed, C = fit(o.palette, 8);+ layer(q, t, S, C, 2);+}++function layer(q, t, S, C, L) {+ const Ly = LAYERS[L], sd = S * 13 + L;+ trips(t, D, Ly.n, sd, Ly.m[0], Ly.m[1], (u, k, m, i) => {+ const j = wrap(k, m), dur = D / m, R = (n) => rand(sd, i, j, n);+ const tf = dur * Ly.air, age = Math.min(u * dur, tf), sw = Ly.sway[0] + R(3) * (Ly.sway[1] - Ly.sway[0]), f = 0.25 + R(4) * 0.35, ph = R(5) * TAU;+ const xAt = (a) => -175 + R(2) * 350 + Ly.wind * a + (gust(t - u * dur + a) - gust(t - u * dur)) * Ly.gust + sw * Math.sin(TAU * f * a + ph);+ const x = xAt(age), xl = xAt(tf), y0 = -176, y1 = L ? bank(xl) - 0.5 : -110 + R(1) * 106;+ const y = y0 + (y1 - y0) * (age / tf), rest = u * dur - tf;+ if (L === 0) {+ // far: a speck, thinning out before it's gone+ const a = Math.min(1, (1 - u) * 6);+ q.dot(x, y, R(6) < 0.5 ? C[4] : C[5], a);+ return;+ }+ const fade = rest > 0 ? 1 - rest / (dur - tf) : 1;+ if (L === 1) {+ // a drifting flake: a point with a smaller one beside it, a plus when it's big+ const big = R(6) < 0.3;+ if (rest > 0) return void q.dot(xl, y1, C[7], fade * 0.9);+ q.px(x, y, big ? WHITE : C[7]);+ if (big) for (const [dx, dy] of [[1, 0], [-1, 0], [0, 1], [0, -1]]) q.px(x + dx, y + dy, C[5]);+ else (q.px(x + 1, y, C[6]), q.px(x, y + 1, C[6]), q.px(x + 1, y + 1, C[5]));+ return;+ }+ // a near crystal: six arms with side branches, spinning, a white heart, a cold glow; it lies down on the drift+ const r = R(6) < 0.4 ? 3 : R(6) < 0.8 ? 4 : 5, spin = 1.5 + R(7) * 2.5;+ if (rest > 0) {+ q.dot(xl - 1, y1, C[6], fade);+ q.dot(xl, y1, WHITE, fade);+ q.dot(xl + 1, y1, C[6], fade);+ q.glow(xl, y1, 5, C[5], 0.25 * fade);+ return;+ }+ crystal(q, x, y, r, Math.floor(age * spin + R(8) * 2) % 2, C);});- // 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);+}++// a near crystal, kept crisp: long arms on one set of four directions, short ones on the other, nubs near the+// tips; turning means trading which set is long. Plates are a ring round a bright heart.+const AXIS = [[1, 0], [-1, 0], [0, 1], [0, -1]], DIAG = [[1, 1], [-1, -1], [1, -1], [-1, 1]];+function crystal(q, x, y, r, turn, C) {+ const X = Math.round(x), Y = Math.round(y), long = turn ? DIAG : AXIS, short = turn ? AXIS : DIAG, R = turn ? r - 1 : r;+ // long arms with a white-blue tip; nubs only where they can't touch the next arm, so the gaps stay open+ for (const [dx, dy] of long) {+ for (let d = 1; d <= R; d++) q.px(X + dx * d, Y + dy * d, d === R ? WHITE : C[6]);+ const nubs = turn ? (R >= 3 ? [R - 1] : []) : R >= 5 ? [R - 1, R - 2] : R >= 4 ? [R - 1] : [];+ for (const n of nubs) {+ const ox = turn ? dx : dy, oy = turn ? -dy : -dx;+ q.px(X + dx * n + (turn ? 0 : ox), Y + dy * n + (turn ? oy : oy), C[4]);+ q.px(X + dx * n + (turn ? -dx : -ox) + (turn ? dx : 0), Y + dy * n + (turn ? dy * 0 : -oy), C[4]);+ }+ }+ for (const [dx, dy] of short) for (let d = 1; d <= (turn ? 1 : Math.max(1, Math.floor(R / 2))); d++) q.px(X + dx * d, Y + dy * d, d === 1 ? C[6] : C[5]);+ q.px(X, Y, WHITE);+ // a faint halo, wide enough not to fill the gaps between the arms+ q.glow(X + 0.5, Y + 0.5, r * 2.5 + 5, C[5], 0.13);+ q.light(X, Y, C[6], 0.4);+}++// the drift on the floor: a lumpy bank with a white crest, blue shade below, and glints that twinkle+function drift(q, t, S, C) {+ pass(q, meta, -7, 9, (x, y, out) => {+ const top = bank(x), d = y - top;+ if (d < 0) return;+ out.c = d < 1 ? WHITE : d < 2 ? C[7] : d < 3.5 ? C[6] : d < 6 ? C[5] : C[4];+ if (d < 1) (out.l = C[6]), (out.k = 0.12);});+ for (let i = 0; i < 18; i++) {+ const x = -156 + rand(S, i, 81) * 312, c = 1 + Math.floor(rand(S, i, 82) * 3), tw = Math.sin((TAU * c * t) / D + rand(S, i, 83) * TAU);+ if (tw < 0.55) continue;+ const y = Math.ceil(bank(x)) + Math.floor(rand(S, i, 84) * 3), k = (tw - 0.55) / 0.45;+ q.px(x, y, WHITE);+ if (k > 0.5) for (const [dx, dy] of [[1, 0], [-1, 0], [0, -1]]) q.px(x + dx, y + dy, C[6]);+ q.glow(x + 0.5, y + 0.5, 6, C[6], 0.35 * k);+ }}diff --git a/src/fx/weather/storm.js b/src/fx/weather/storm.jsindex 75c30af..b6fb1b1 100644--- a/src/fx/weather/storm.js+++ b/src/fx/weather/storm.js@@ -1,79 +1,384 @@-import { ramp, at, lerp, clamp, seg, rng, bolt, forks, tileFbm, hex } from "../../core/index.js";-import { box, clip, drift } from "./_lib.js";+// The bolt (a branching path, a stepped leader, strokes that flicker frame by frame, light along the channel) and+// the rain (streaks with lit heads, splashes that throw droplets) are adapted from Sprite Fusion's open-source+// lightning (https://www.spritefusion.com/pixel-art-vfx/lightning), MIT License, Copyright (c) 2026 Hugo Duprez.+import { Particles, P, Rng, fit, clamp, smooth, rand, wrap, TAU, WHITE, hex, mix, scale } from "../../core/index.js";+import { clip, pass, box, field, sample, trips, tree, wave, bayer, splash } 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.",+ desc: "Driving rain at two depths under a churning cloud deck; a forked bolt strikes in a double flash that lights the sky and the rain, then sheet lightning glows in the clouds.",tags: ["weather", "storm", "rain", "lightning", "thunder", "ambient", "loop"],- size: [128, 72],- origin: [64, 36],- duration: 3,+ size: [320, 180],+ origin: [160, 170],+ duration: 10,loop: true,fps: 30,bg: "sky",options: {- palette: ["#0c0e16", "#161a26", "#222838", "#30384c", "#434d66", "#5e6a86", "#8a98b6", "#cfdcf2"],- bolt: ["#3a56c8", "#8cb4ff", "#ffffff"],- count: 90,- seed: 73,+ palette: ["#09080f", "#121120", "#1b1a30", "#262541", "#363a5c", "#4f5d8c", "#7790c6", "#c2d6ff"],+ bolt: ["#2a1a6e", "#4835c2", "#6a6cff", "#78b8ff", "#c6ebff", "#ffffff"],+ seed: 5,},};-// 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;+const D = 10, SLANT = 0.42;+// the strike: a stepped leader feels its way down, the first stroke, a restrike down the same channel+const T_LEAD = 2.62, T1 = 3.0, T2 = 3.3, T_SHEET = 6.4, T_FAR = 8.6;+const BX0 = 62, BY0 = -136, BX1 = 52, BY1 = 3;+const F1 = [1, 0.62, 0.95, 0.4, 0.7, 0.22], F2 = [0.92, 0.5, 0.8, 0.3, 0.12];+const env = (t, t0, E) => {+ const i = Math.floor((t - t0) * 30 + 1e-3);+ return i >= 0 && i < E.length ? E[i] : 0;+};+const flashAt = (t) => Math.max(env(t, T1, F1), env(t, T2, F2));++// sheet lightning: light that swells inside the clouds with no bolt to see, twice; and a far flicker+function sheetAt(t) {+ const a = t - T_SHEET;+ if (a < 0 || a > 0.9) return 0;+ const p1 = Math.exp(-(((a - 0.08) / 0.05) ** 2)), p2 = Math.exp(-(((a - 0.3) / 0.09) ** 2)), tail = a > 0.3 ? Math.exp(-(a - 0.3) * 6) * 0.5 : 0;+ return Math.min(1, 0.7 * p1 + p2 + tail) * (Math.floor(a * 30) % 3 === 1 ? 0.75 : 1);+}+const blink = (a, k) => (a < 0 || a > 0.3 ? 0 : k * (Math.exp(-(((a - 0.06) / 0.04) ** 2)) + 0.65 * Math.exp(-(((a - 0.18) / 0.05) ** 2))));+const farAt = (t) => blink(t - T_FAR, 0.45), far2At = (t) => blink(t - 0.9, 0.3);++// times are snapped so a runtime's accumulated float time (2.9999999) lands on the frame it means+const snap = (t) => Math.round(t * 3e4) / 3e4;++export function drawBack(p, t, o) {+ t = snap(t);+ const q = clip(p, meta), B = box(meta), S = o.seed, C = fit(o.palette, 8), V = fit(o.bolt, 6);+ const f = flashAt(t), sh = sheetAt(t), far = farAt(t), lead = t > T_LEAD && t < T1 ? 0.25 + 0.2 * Math.sin(t * 70) : 0;+ const pre = t > T_LEAD - 0.5 && t < T_LEAD ? 0.12 * Math.max(0, Math.sin((t - T_LEAD) * 41)) : 0;+ // what lights the clouds from inside: the bolt's root, the sheet lightning, the far flicker+ const srcs = [];+ if (f + lead + pre > 0) srcs.push([BX0, BY0 - 6, 150, f + lead * 0.5 + pre]);+ if (sh > 0) srcs.push([-96, -146, 120, sh]);+ if (far > 0) srcs.push([128, -156, 80, far]);+ if (far2At(t) > 0) srcs.push([-40, -160, 70, far2At(t)]);+ const litAt = (x, y) => {+ let L = 0;+ for (const [sx, sy, R, k] of srcs) {+ const d = Math.hypot(x - sx, (y - sy) * 1.5) / R;+ if (d < 1) L += k * (1 - d) * (1 - d);+ }+ return Math.min(1, L);+ };+ sky(p, t, f, V);+ if (sh > 0.05) pass(p, meta, -170, 0, (x, y, out) => {+ const d = Math.hypot(x + 96, (y + 150) * 1.3) / 170;+ if (d < 1) (out.l = V[2]), (out.k = sh * 0.3 * (1 - d) * (1 - d));+ });+ veil(p, t, S, C, V, f);+ // far rain behind the bolt; the bolt's root disappears up into the cloud+ rain(q, t, S, C, V, f, 0);+ if (t > T_LEAD && t < T2 + 0.7) bolt(q, t, S, V);+ deck(q, B, t, S, C, V, litAt, srcs.length > 0);+ crawler(q, t, S, V);+ floor(q, B, t, S, C, V, f);+ strike(q, t, S, C, V);}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]);+ t = snap(t);+ const q = clip(p, meta), S = o.seed, C = fit(o.palette, 8), V = fit(o.bolt, 6), f = flashAt(t);+ rain(q, t, S, C, V, f, 1);+}++// the whole sky lights up with each stroke, most near the bolt+function sky(p, t, f, V) {+ const k = f * 0.36;+ if (k <= 0.01) return;+ const c = mix(V[2], V[3], 0.6);+ pass(p, meta, -170, 9, (x, y, out) => {+ const d = Math.abs(x - (BX0 + BX1) / 2) / 230;+ out.l = c;+ out.k = k * (0.2 + 0.8 * Math.max(0, 1 - d) ** 2.2);+ });+}++// the cloud deck, seen from below in perspective: rows of rolls, the nearest and biggest at the top, each row+// further off hanging a little lower, smaller and hazier. Every roll swells, drifts on the wind and dissolves on+// its own clock (born once a loop), so the underside churns with no seam. Each row's lower edge catches a 1 px+// rim of light and throws a line of shadow on the row behind it.+const ROWS = [+ { base: -161, wob: 3, n: 18, rx: [16, 30], ry: 0.8, drift: 15, life: [4, 7], tone: [1, 2, 3, 4], tex: 1 },+ { base: -150, wob: 3, n: 22, rx: [10, 20], ry: 0.85, drift: 10, life: [3.5, 6.5], tone: [1, 2, 3, 5], tex: 1 },+ { base: -140, wob: 3, n: 26, rx: [7, 14], ry: 0.9, drift: 6, life: [3, 6], tone: [2, 2, 3, 5], tex: 0, haze: true },+];+// the storm cell hangs lowest over the strike+const sag = (x) => 9 * Math.exp(-(((x - 40) / 95) ** 2)) - 3;+// each roll pushes down out of its row, drifts on the wind and draws back up, on its own clock (born once a loop)+function rolls(S, t) {+ return ROWS.map((Rw, j) => {+ const out = [];+ for (let i = 0; i < Rw.n; i++) {+ const L = Rw.life[0] + rand(S, j, i, 1) * (Rw.life[1] - Rw.life[0]), age = wrap(t - rand(S, j, i, 2) * D, D);+ if (age >= L) continue;+ const u = age / L, g = Math.sin(Math.PI * u) ** 0.6;+ const rx = Rw.rx[0] + rand(S, j, i, 3) * (Rw.rx[1] - Rw.rx[0]), ry = rx * Rw.ry, x = -200 + rand(S, j, i, 4) * 400 + Rw.drift * (age - L / 2);+ out.push({ x, h: ry * g * (0.6 + 0.4 * rand(S, j, i, 5)), rx: rx * (0.8 + 0.2 * g) });+ }+ return out;});- 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]));+}+// sheets of rain sweeping across on the gusts: a translucent haze, streaked along the rain, that hides the stars+// and catches the flash where it's thickest+function veil(p, t, S, C, V, f) {+ const F = field(S + 11, 256, 128, [4, 8, 16]), shift = (256 * 2 * t) / D, glow = mix(C[3], V[3], 0.5);+ pass(p, meta, -170, -0.5, (x, y, out) => {+ const n = sample(F, (x - y * SLANT) * 1.9 - shift, y * 0.16 + 7), dens = clamp(0.45 + (n - 0.5) * 2.6);+ out.c = f > 0.05 ? mix(C[1], glow, Math.min(1, f * dens * 0.7 * Math.max(0.25, 1 - Math.abs(x - BX1) / 220))) : C[1];+ out.a = 0.4 + 0.38 * dens;+ out.b = 1;});- // 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]);+}++function deck(q, B, t, S, C, V, litAt, lit) {+ const R = rolls(S, t), F = field(S * 3 + 1, 256, 128), drift = (256 * t) / D, n = ROWS.length, mo = Math.cos((Math.PI * t) / D) ** 2;+ const RAMP = [C[0], C[1], C[2], C[3], C[4], C[5], C[6], V[4], WHITE];+ const top = new Float32Array(n), bot = new Float32Array(n), bulge = new Float32Array(n);+ for (let x = B.x0; x < B.x1; x++) {+ const cx = x + 0.5;+ let low = -170;+ // each row hangs as a curtain: a wavy base with rolls bulging out of it+ for (let j = 0; j < n; j++) {+ const Rw = ROWS[j];+ const und = (sample(F, cx * 0.55 + j * 91, 3) * mo + sample(F, cx * 0.55 + j * 91, 60) * (1 - mo) - 0.5) * 2;+ const c = Rw.base + sag(cx) * (0.4 + j * 0.3) + 7 * und + Rw.wob * 2 * (sample(F, cx * 1.8 + j * 61 - drift * (0.5 - j * 0.1), 20 + j * 17) - 0.5);+ let bump = 0;+ for (const b of R[j]) {+ const dx = (cx - b.x) / b.rx;+ if (dx * dx < 1) bump = Math.max(bump, b.h * Math.sqrt(1 - dx * dx));+ }+ const y1 = c + bump;+ top[j] = -999;+ bot[j] = y1;+ bulge[j] = bump;+ low = Math.max(low, y1);+ }+ let prev = -1, prevBot = -999;+ for (let y = B.y0; y < low; y++) {+ const cy = y + 0.5;+ let j = 0;+ while (j < n && !(cy >= top[j] && cy < bot[j])) j++;+ if (j >= n) {+ prev = -1;+ continue;+ }+ if (j !== prev) {+ if (prev >= 0 && prev < j) prevBot = cy;+ prev = j;+ }+ const Rw = ROWS[j], d = bot[j] - cy, tone = Rw.tone, th = bayer(x, y);+ // light catches the lower edge of each row, most on the big bulges, and fades up into a dark core+ let i;+ if (d < 1) i = bulge[j] > 3 ? tone[3] : tone[3] - 1;+ else if (cy - prevBot < 1.5 && j > 0) i = Math.max(0, tone[0] - 1); // shadow under the row in front+ else if (d < 2 + bulge[j] * 0.25 + th * 2) i = tone[2];+ else if (d < 6 + bulge[j] * 0.4 + th * 3) i = tone[1];+ else {+ const nn = sample(F, cx * 0.9 + j * 77 - drift * (0.6 - j * 0.12), cy * 1.7 + j * 31);+ i = tone[0] + (Rw.tex && nn > 0.6 ? 1 : 0);+ }+ let lk = 0;+ if (lit) {+ const Lv = litAt(cx, cy);+ if (Lv > 0.02) {+ i = Math.min(8, i + Math.round(Lv * (d < 1 ? 4.4 : d < 4 ? 3.8 : 3.1)));+ lk = Lv;+ }+ }+ if (Rw.haze && !lk && d >= 1) q.blend(x, y, RAMP[i], 0.75);+ else q.px(x, y, RAMP[Math.max(0, i)]);+ if (lk > 0.03) q.light(x, y, V[3], lk * (d < 3 ? 0.4 : 0.22));}- 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));+}++// the rain: far drops thin and dim, near drops long with bright heads; the flash lights every drop+function rain(q, t, S, C, V, f, near) {+ const litAt = (x) => {+ const L = f * (0.3 + 0.7 * Math.max(0, 1 - Math.abs(x - BX1) / 170));+ return L > 0.45 ? 2 : L > 0.15 ? 1 : 0;+ };+ if (!near) {+ const BODY = [C[4], C[4], C[5]], HEAD = [C[5], C[6], C[6]];+ trips(t, D, 300, S * 7 + 1, 22, 28, (u, k, m, i) => {+ const j = wrap(k, m), stop = -14 - rand(S, i, j, 1) * 90, y = -176 + (stop + 176) * u, x = -170 + rand(S, i, j, 2) * 360 - (stop - y) * SLANT;+ const L = 3 + rand(S, i, j, 3) * 2, ux = SLANT / Math.hypot(SLANT, 1), uy = 1 / Math.hypot(SLANT, 1), lit = litAt(x), body = BODY[lit], head = HEAD[lit];+ q.line(x - ux * L, y - uy * L, x - ux * L * 0.4, y - uy * L * 0.4, body);+ q.line(x - ux * L * 0.4, y - uy * L * 0.4, x, y, head);});+ return;}- if (sheet > 0) p.glow(sx, B.y0 + 8, 30, BO[1], 0.25 * sheet);+ const BODY = [C[6], C[6], V[4]], HEAD = [C[7], WHITE, WHITE], TAIL = [C[4], C[5], V[3]];+ trips(t, D, 84, S * 7 + 2, 30, 38, (u, k, m, i) => {+ const j = wrap(k, m), z = 1 + rand(S, i, j, 1) * 4, y = -180 + (z + 180) * u, x = -175 + rand(S, i, j, 2) * 370 - (z - y) * SLANT;+ const L = 9 + rand(S, i, j, 3) * 5, ux = SLANT / Math.hypot(SLANT, 1), uy = 1 / Math.hypot(SLANT, 1), lit = litAt(x), body = BODY[lit], head = HEAD[lit], tail = TAIL[lit];+ q.line(x - ux * L, y - uy * L, x - ux * L * 0.55, y - uy * L * 0.55, tail);+ q.line(x - ux * L * 0.55, y - uy * L * 0.55, x - ux, y - uy, body);+ q.px(x, y, head);+ // the drop before this one landed: splash+ const dur = D / m, age = u * dur;+ if (age < 0.4) {+ const jp = wrap(k - 1, m), zp = 1 + rand(S, i, jp, 1) * 4, xp = -175 + rand(S, i, jp, 2) * 370;+ const lit = litAt(xp);+ splash(q, xp, zp, age, 0.25 + (zp - 1) / 5.3, { hot: lit ? WHITE : C[7], cool: [C[5], C[6], V[4]][lit] }, rand(S, i, jp, 4));+ }+ });+}++// the channel: a jagged trunk, three long forks peeling off it (alternating sides), each with twigs of its own+function channel(S) {+ const R = new Rng(S * 31 + 1), P = tree(R, BX0, BY0, BX1, BY1, 0.26, 0.18), pts = P[0].pts, side = R.sign();+ [0.2, 0.38, 0.55].forEach((u, i) => {+ const k = Math.floor(u * (pts.length - 1)), [ax, ay] = pts[k], [bx, by] = pts[Math.min(pts.length - 1, k + 3)];+ const a = Math.atan2(by - ay, bx - ax) + (i % 2 ? -side : side) * R.range(0.6, 1.0), l = R.range(36, 56) * (1 - u * 0.45);+ P.push(...tree(R, ax, ay, ax + Math.cos(a) * l, ay + Math.sin(a) * l, 0.3, 0.5, 0.6, 1));+ });+ return P;+}++function bolt(q, t, S, V) {+ const P1 = channel(S);+ if (t < T1) {+ const reach = BY0 + (BY1 - BY0) * Math.pow(Math.floor(((t - T_LEAD) / (T1 - T_LEAD)) * 9) / 9, 1.25);+ for (const p of P1)+ for (let i = 0; i < p.pts.length - 1; i++) {+ const [ax, ay] = p.pts[i], [bx, by] = p.pts[i + 1];+ if (by > reach) break;+ q.line(ax, ay, bx, by, p.w >= 1 ? V[2] : V[1]);+ if (i % 4 === 0) q.glow(ax, ay, 6, V[3], 0.22 * p.w);+ }+ return;+ }+ // the restrike runs down the same channel, with fewer, shorter forks+ const P2 = [P1[0], ...tree(new Rng(S * 31 + 2), BX0, BY0, BX1, BY1, 0.3, 0.3).slice(1).filter((_, i) => i < 2)];+ const s = t >= T2 ? 2 : 1, a = t - (s === 2 ? T2 : T1), k = env(t, s === 2 ? T2 : T1, s === 2 ? F2 : F1), paths = s === 2 ? P2 : P1;+ if (k > 0) stroke(q, paths, k, V);+ else if (a < 0.5) {+ const g = 1 - a / 0.5;+ for (const p of paths) if (p.w >= 1) for (const [x, y] of p.pts) q.dot(x, y, V[1], g * 0.9);+ }+}++// spider lightning crawling along the cloud base while the sheet lightning glows: drawn a frame at a time, the+// crawl reaching a little further each frame, then gone+function crawler(q, t, S, V) {+ const a = t - T_SHEET - 0.22;+ if (a < 0 || a > 0.17) return;+ const P = tree(new Rng(S * 7 + 3), -150, -138, -26, -134, 0.2, 0.7), reach = -150 + 130 * Math.min(1, (Math.floor(a * 30) + 1) / 3), k = a < 0.1 ? 1 : 0.5;+ for (const p of P)+ for (let i = 0; i < p.pts.length - 1; i++) {+ const [ax, ay] = p.pts[i], [bx, by] = p.pts[i + 1];+ if (ax > reach) break;+ q.line(ax, ay, bx, by, p.w >= 1 && k > 0.6 ? V[4] : V[3]);+ if (p.w >= 1) q.dot(ax, ay + 1, V[2], k);+ if (i % 3 === 0) q.glow(ax, ay, 10, V[3], 0.35 * k * p.w);+ }+}++// a stroke: a violet sheath, a pale blue body, a white-hot core (two pixels wide at the peak), light all along+function stroke(q, paths, k, V) {+ for (const pass of [0, 1, 2])+ for (const p of paths) {+ const trunk = p.w >= 1;+ if (!trunk && (k < 0.4 || (pass === 0 && p.w < 0.5))) continue;+ for (let i = 0; i < p.pts.length - 1; i++) {+ const [ax, ay] = p.pts[i], [bx, by] = p.pts[i + 1], l = Math.max(1, Math.hypot(bx - ax, by - ay));+ for (let d = 0; d <= l; d += 0.5) {+ const x = ax + ((bx - ax) * d) / l, y = ay + ((by - ay) * d) / l;+ if (pass === 0) q.circle(x, y, trunk ? (k > 0.6 ? 2.3 : 1.7) : 1.2, k > 0.6 ? V[2] : V[1]);+ else if (pass === 1) q.circle(x, y, trunk ? (k > 0.6 ? 1.4 : 0.9) : 0.6, trunk ? V[4] : V[3]);+ else if (trunk) {+ q.px(x, y, k > 0.3 ? WHITE : V[4]);+ if (k > 0.85) q.px(x + 1, y, WHITE);+ } else if (p.w > 0.4 && k > 0.6) q.px(x, y, V[4]);+ }+ if (pass === 0 && i % 3 === 0) q.glow(ax, ay, trunk ? 18 : 8, V[3], (trunk ? 0.5 : 0.3) * k * p.w);+ }+ }+}++// where the bolt lands: a blinding hit, sparks that skip off the wet floor, steam, a glow that cools+function strike(q, t, S, C, V) {+ const a = t - T1;+ if (a < 0 || a > 1.8) return; // the last spray is gone by 1.6 s+ const k = flashAt(t);+ if (k > 0) {+ // arcs skitter out along the wet floor, new ones every frame+ const fr = Math.floor(t * 30 + 1e-3), Rc = new Rng(S * 977 + fr);+ for (let i = 0; i < 4; i++) {+ const side = i % 2 ? 1 : -1, l = Rc.range(10, 30) * (0.6 + 0.4 * k);+ for (const p of tree(Rc, BX1 + side, BY1 - 1, BX1 + side * l, BY1 + Rc.range(-2, 3), 0.35, 0.5, 0.6, 1)) {+ q.polyline(p.pts, k > 0.6 && p.w > 0.5 ? V[4] : V[3]);+ q.glow(p.pts[p.pts.length >> 1][0], p.pts[p.pts.length >> 1][1], 8, V[3], 0.3 * k);+ }+ }+ q.circle(BX1, BY1 - 1, 2 + 3 * k, V[4]);+ q.circle(BX1, BY1 - 1, 1 + 2 * k, WHITE);+ q.glow(BX1, BY1 - 12, 95, V[2], 0.55 * k);+ q.glow(BX1, BY1 - 4, 40, V[3], 0.5 * k);+ q.glow(BX1, BY1 - 2, 14, WHITE, 0.6 * k);+ }+ const ps = new Particles({ rng: new Rng(S * 13 + 5), ground: () => 4, sparks: [WHITE, V[4], V[3], V[2]], haze: V[2] }), R = ps.R, steam = mix(C[4], V[3], 0.3);+ const burst = (n, pow) => {+ for (let i = 0; i < n; i++) {+ const an = -Math.PI / 2 + R.range(-1.35, 1.35), sp = R.range(110, 420) * pow;+ ps.spawn(P.SPARK, BX1, BY1 - 1, Math.cos(an) * sp, Math.sin(an) * sp, R.range(0.18, 0.6));+ }+ // a skirt of spray and steam blown out along the floor+ for (let i = 0; i < 6 * pow; i++) {+ const sd = R.sign();+ ps.spawn(P.VAPOUR, BX1 + sd * R.range(2, 8), BY1 - R.range(1, 3), sd * R.range(30, 90), -R.range(4, 16), R.range(0.6, 1.2), steam, R.range(2.5, 4.5), R.range(0, 0.08));+ }+ };+ burst(48, 1);+ let tt = 0, second = false;+ for (const dt = 1 / 120; tt + dt <= a; tt += dt) {+ if (!second && tt >= T2 - T1) (second = true), burst(16, 0.7);+ ps.update(dt);+ }+ ps.draw(q);+ if (a < 1.6) q.glow(BX1, BY1, 16, V[2], 0.4 * (1 - a / 1.6) ** 2);+}++// the wet floor: a dark sheen, a broken lip of light, pools that reflect the sky and flash with it, mist kicked+// up by the rain drifting along the ground+function floor(q, B, t, S, C, V, f) {+ const F = field(S + 3, 256, 128), M = field(S + 4, 256, 128, [4, 8, 16]), wind = (256 * 3 * t) / D;+ pass(q, meta, -14, -0.5, (x, y, out) => {+ const m = sample(M, x * 1.1 - wind, y * 4 + 9) - 0.4;+ if (m <= 0) return;+ out.c = f > 0.1 ? mix(C[4], V[3], f) : C[4];+ out.a = Math.min(0.3, m * 0.9) * (1 + y / 14);+ out.b = 1;+ });+ pass(q, meta, 0, 9, (x, y, out) => {+ const pool = (yy) => sample(F, x * 1.3 + 31, yy * 9) > 0.6 - yy * 0.006;+ const wet = pool(y), lip = wet && !pool(y - 1);+ out.b = 1;+ out.c = C[1];+ out.a = 0.5;+ if (y < 1) {+ out.c = sample(F, x * 2, 50) > 0.5 ? C[4] : C[3];+ out.a = 1;+ out.b = 0;+ } else if (wet) {+ const d = Math.abs(x - BX1) / 150;+ if (f > 0.06) {+ out.c = (d < 0.25 && f > 0.5) || lip ? V[4] : V[3];+ out.a = clamp(f * (1.35 - d) * (lip ? 1.4 : 1));+ out.b = 0;+ } else {+ out.c = lip ? C[5] : C[3];+ out.a = lip ? 1 : 0.7;+ }+ out.l = V[3];+ out.k = f * 0.25 * Math.max(0, 1 - d);+ }+ });+ // the bolt's reflection in the pools, broken by ripples+ if (f > 0.2) for (let y = 1; y < 10; y++) if (rand(y, Math.floor(t * 30), 3) < 0.8) q.dot(BX1 + Math.sin(y * 1.7 + t * 40) * 1.2, y, y < 4 ? WHITE : V[4], f * (1.1 - y / 12));}diff --git a/src/fx/weather/twinkling-stars.js b/src/fx/weather/twinkling-stars.jsdeleted file mode 100644index 1b137d8..0000000--- a/src/fx/weather/twinkling-stars.js+++ /dev/null@@ -1,51 +0,0 @@-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/lib/fxlib.mjs b/tools/lib/fxlib.mjsindex cd81632..6a8f1a6 100644--- a/tools/lib/fxlib.mjs+++ b/tools/lib/fxlib.mjs@@ -59,6 +59,7 @@ export function renderFrames(fx, opts = {}) {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 fade = m === 0 && !isScreen(meta);const frames = [];for (let i = 0; i < n; i++) {if (i > 0) inst.update(1 / fps);@@ -69,6 +70,7 @@ export function renderFrames(fx, opts = {}) {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");+ if (fade) (edgeFade(bare), edgeFade(shown));frames.push({t: i / fps,color: composite(shown, new Uint8ClampedArray(w * h * 4), bg),@@ -80,6 +82,28 @@ export function renderFrames(fx, opts = {}) {return { w, h, fps, n, frames, margin: m };}+/** Full-screen effects (transitions, weather, impact frames): 16:9 and at least 320 wide. They fill the screen. */+export const isScreen = (meta) => meta.size[0] >= 320 && Math.abs(meta.size[0] / meta.size[1] - 16 / 9) < 0.05;++/**+ * A glow cut off by the canvas edge shows as a box once a frame sits in a game. Ease the light out over the last+ * E pixels of the canvas, in place. Colour is left alone.+ */+export function edgeFade(f, E = 8) {+ const { w, h, light: L } = f;+ for (let y = 0; y < h; y++) {+ const ey = Math.min(y, h - 1 - y);+ for (let x = 0; x < w; x++) {+ const e = Math.min(ey, x, w - 1 - x);+ if (e >= E) { x = w - 1 - E; continue; }+ const i = y * w + x, l = L[i];+ if (!(l & 0xffffff)) continue;+ const u = (e + 0.5) / E, k = u * u * (3 - 2 * u);+ L[i] = (l & 0xff000000) | Math.round((l & 255) * k) | (Math.round(((l >>> 8) & 255) * k) << 8) | (Math.round(((l >>> 16) & 255) * k) << 16);+ }+ }+}+/** Nearest-neighbour upscale of RGBA. */export function upscale(rgba, w, h, k) {if (k === 1) return rgba;diff --git a/tools/montage.mjs b/tools/montage.mjsindex 73b9fc8..4b030d4 100644--- a/tools/montage.mjs+++ b/tools/montage.mjs@@ -42,9 +42,10 @@ 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];+ // a canvas that fits is centred; a bigger one is cropped round its anchor, keeping a strip of floor in view+ const [w, h] = m.size, [ox, oy] = m.origin;+ const x = w <= CW ? Math.floor((CW - w) / 2) + ox : Math.round(CW / 2 + ox - w / 2);+ const y = h <= CH ? Math.floor((CH - h) / 2) + oy : CH - Math.min(h - oy, Math.round(CH * 0.16));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 });}