---
name: "physics-reel"
description: "Make satisfying physics-simulation Shorts in code: a double pendulum that welds every block it touches, a triangle that chips its corners on a ramp until it rolls like a wheel, a ball that speeds up with every line it breaks, jaws that crush balls which come back as more until the hexagon overflows, each with a hook line, a live counter, a climax and a clean ending. Sound is synthesized from the simulation's own events (collisions, welds, chips) and public-domain melodies written out note by note. Free and local: the physics runs at a fixed timestep with seeded randomness in headless Chromium, ffmpeg encodes 1080x1920 30 fps H.264 + AAC at -14 LUFS. Every look is a JSON preset. Use when the user asks for an oddly satisfying physics video, a simulation Short, a 'watch it until it ...' loop, or this physics-reel style."
argument-hint: "[preset name or idea] [seed]"
---
# physics-reel
You make 25-45 s vertical Shorts where a small physics simulation builds to a payoff: every block sticks until all are welded, every hard corner breaks until the shape is a wheel. The video is the simulation itself. There is no voice: the words on screen are a hook at the top (the question), a live counter, and a banner at the climax (the answer). The sound comes from the run: each weld, chip or hit triggers a synthesized sound, and the main events play the next note of a public-domain tune, so the tune emerges at the speed of the physics.
Everything runs through `bin/physics-reel.mjs` in this skill folder. Call it `PR="node <this skill dir>/bin/physics-reel.mjs"`. A look is one JSON file: the shipped ones are in `presets/`, your own can live anywhere.
## 0. Setup check
`$PR doctor` checks Node, ffmpeg, Playwright + Chromium, the fonts and whether the GPU is used. It prints the fix for anything missing.
## 1. Pick or make a look
- `$PR list` shows the presets. Each one has a `kind` (the simulation) and everything else is the look: palette, hook, counter, banner, tune, sounds and the sim settings.
- `$PR new pieces/my-look.json --from triangle-wheel` copies a preset. Change the hook text, colours, tune (`audio.melody.tune`) or physics (`sim`), keep the `kind`.
- Hook: two lines, small then big, under about 24 characters each. Ask a question the run answers ("HOW MANY CORNERS BREAK / BEFORE IT ROLLS?"). The banner answers it with `{n}` = the final count ("{n} SIDES LATER / IT'S A WHEEL!").
## 2. Plan the run (fast, no drawing)
- `$PR plan <preset>` prints the length, the climax time and the final count. `$PR plan <preset> --seeds 1-20` tries 20 seeds; pick one whose climax lands at 25-45 s and put it in the preset (`"seed"`).
- Same preset + same seed = the same video, frame for frame and sound for sound.
- `$PR tune <preset> --set sim.key=value` runs the sim in Node for quick tuning (prints the counter every 2 s). The browser run is the reference for the real video; numbers can differ slightly between the two.
## 3. Look, check, export
- `$PR still <preset> auto sheet.png` renders 8 frames (start, build-up, the climax and the end) on one sheet. Look at it. Fix overlaps of the sim with the hook or counter by moving `counter.y`, `hook.y` or the sim's screen position.
- `$PR check <preset>` must say `text: PASS` and `deterministic: true`. It flags text outside the Shorts safe zone (top 7.5%, bottom 20%, the button column on the right of the lower half) and overlaps, and re-runs the whole sim in a fresh page to compare every event and three frames.
- `$PR export <preset> out.mp4` renders 1080x1920 at 30 fps (two workers by default), synthesizes the audio from the run's events, normalises to -14 LUFS (two-pass loudnorm, true peak -1.5 dB) and runs `verify` (H.264, yuv420p, AAC 48 kHz, 30 fps, loudness). On a laptop iGPU it takes 19-25 ms a frame: a 37 s Short exports in about 40 s.
- You can't hear the mix. Say so and ask the user to listen once.
## 4. Deliver
Give the MP4 path, the climax time and final count, the tune used, and a still sheet. Never post anywhere without the user's go-ahead.
## Kinds (simulations)
- **pendulum-weld**: a double pendulum (two rigid bodies, Lagrange equations, RK4 at 240 Hz) swings through floating blocks. A block it touches welds on where it hit: mass and inertia are added to that arm and the generalised momentum is kept, then an energy keeper holds the energy per unit mass so the swing stays lively. Blocks float in over time (`visible`, `spawnEvery`) and drift inward if they wait too long, so the run always ends. Climax: the last block. Counter: blocks welded. Main event `weld` (fields `n`, `v` = contact speed, `x`).
- **triangle-wheel**: a polygon tumbles down an endless ramp (one rigid body with exact polygon mass and inertia against a half-plane, sequential impulses with restitution and friction at 300 Hz). A corner that arrives hard enough for how sharp it is (relative to the average corner) breaks off: the corner is cut, the chip flies, the shape settles a little toward round (`relax`). The run follows an exponential side-count curve that reaches `maxSides` at `climaxAt`, but every break happens on a real impact. Climax: `maxSides`. Counter: sides. Events `hit` (`u` = impact speed), `chip` (`n`, `u`, `size`).
- **speed-lines**: a ball runs a long serpentine track packed with stacks of thin lines. Speed = `v0 + accel x lines`, so the count grows exponentially inside a stack; `stacks` (sizes) and `gap` shape the timeline. It bounces between the walls at `angle`, the camera zooms out with speed (`zoomK`, `zoomMin`), and after the last line it smashes the end wall (climax) and the camera pulls back over the whole track. Events `line` (`n`, `v`), `wall`. Curve `speed`.
- **hex-jaws**: verlet balls in a turning hexagon with weak gravity toward the middle. Two jointed arms on a gear spin (`jawSpin`) and snap shut into a hexagonal cage (`cage` size, `period` shortening by `speedUp`); every ball inside is crushed and comes back as `spawn` balls of the next colour. At `burstAt` balls the walls fly off and each ball pops into `burstSplit` more (climax). Counts jump fast near the end, so try a few seeds. Events `crush` (`n`, `gen`), `bite`, `tap` (wall hits). Curve `count`.
<!-- ‹guest · 2026-12-04› -->
More kinds are planned (see README, "Roadmap"). A new kind is a file in `engine/sims/` that exports `create({ preset, W, H, fps })` returning `{ t, count, countAt, climax, events, curves, step(), draw(ctx, info), checksum() }`; read `pendulum-weld.js` first.
## Preset reference
- Top level: `name`, `kind`, `about`, `seed`, `fps` (30), `maxDuration` (hard stop), `tail` (seconds after the climax, 4-5).
- `background`: `stops` (top to bottom colours), `glow`, `glowAt` [x, y], `glowSize`, `glowAlpha`, `vignette`, `dots`, `dotAlpha`, `grid` { size, alpha }.
- `bloom`: { `strength` 0-1, `radius` }. Neon looks 0.6-0.9, solid looks 0-0.3.
- `hook`: `lines` [small, big], `colors`, `sizes` (px at 1080 wide), `y` (top of the first line, fraction of the height).
- `counter`: `label` (may use `{n}`), `y` (baseline, fraction), `size`, `labelSize`, `color`, `labelColor`, `glow`, `climaxColor`, `format` ("int" or "percent").
- `end`: `banner` [small, big] with `{n}`, `colors`, `sizes`, `delay`, `fadeOut`.
- `palette`: colours used by the kind (see the preset files).
- `audio.melody`: `tune` (below), `on` (event type: one note per event) or `follow` (a curve name: continuous playback whose tempo follows it, with `followRef`, `followPow`, `maxTempo`), `instrument` (`bell`, `glock`, `marimba`, `pluck`, `bass`), `transpose` (semitones), `gain` (dB), `velFrom` + `velRef` (loudness from an event field), `max` (notes per second), `harmony` (second pass adds the lower octave).
- `audio.sfx`: list of { `on`, `sound` (`tick`, `pop`, `thud`, `crunch`, `chip`, `splash`), `pitch` Hz, `vary`, `gain`, `max` per second, `velFrom`, `velRef`, `scale` + `base` (walk a musical scale) }.
- `audio.beds`: { `type`: `pad` (`notes` MIDI) or `whoosh` / `rumble` / `water` (noise that follows `curve` / `ref`) , `gain` }.
- `audio.climax`: a riser into the climax, a low boom and a bright chord in the tune's key ({ `gain`, `rise` }).
- Tunes (`tools/melodies.mjs`, all public domain, written out by hand): `jingle-bells` (Pierpont, 1857), `deck-the-halls` (traditional Welsh), `mountain-king` (Grieg, 1875), `entertainer` (Joplin, 1902), `ode-to-joy` (Beethoven, 1824), `turkish-march` (Mozart, 1783), `twinkle` (traditional French, 1761), `greensleeves` (traditional English), `canon` (Pachelbel). Add only tunes whose composer died more than 100 years ago, or traditional tunes. Never modern songs, film, TV, game or anime themes.
## Gotchas
- Determinism: sims use the seeded `RNG` from `engine/core/rng.js` and a fixed substep. Never `Math.random()`, the clock or anything that depends on frame timing. Effects (sparks, chips) use their own forked stream so they don't change the physics. `check` catches a broken run.
- The physics runs once to plan the video (length, climax, sound events), then again while drawing. A still at 30 s simulates the first 30 s first; that is fast (under 0.2 s for the shipped kinds).
- 9:16 only for now. Layout values are fractions of the frame; keep the sim between the hook (top ~19%) and the counter, and everything above the bottom 20%.
- The counter uses fixed-width digits so it doesn't jitter. Keep labels short (one word).
این نسخه با نشانهگذاری اختصاصی حساب شما نمایش داده میشود. برای نصب سریع، به تب نصب و راهاندازی بروید.