# Ratchet Escapement — `ratchet-escapement@1.0.0`

The escapement of a mechanical watch, enlarged: a ratchet wheel, a rocking anchor with ruby pallets, a swinging balance and a following gear, ticking in sharp steps. Loops perfectly.

The heart of a mechanical watch, enlarged and laid bare. A sixteen-toothed escape wheel is held by the two jewelled pallets of an anchor; the anchor rocks to and fro, letting one tooth escape at every tick, and the wheel advances in a sharp little step each time. A balance wheel with a hairspring swings steadily above it, setting the pace, and a larger gear turned by the wheel follows at half its speed. Choose the metal (brass, steel, rose or blue steel), the whole turns of the escape wheel per loop, whether a dark bridge plate sits behind, the backdrop colour and whether the camera sways.

- Kind: object; status: published; digest sha256:b3b78447dcf7e48e4777eccb2ccc3c1b816601c746bf1787d69914dc9820c86c
- Role: Object (3D, three.js): a precise, hypnotic mechanical showpiece for watch, engineering and time-themed content.
- Implementation: three; entry `src/ratchet-escapement.js`
- Files: https://aipixelwizard.com/registry/ratchet-escapement/1.0.0/<path> (`LICENSE`, `asset.json`, `demo.js`, `index.html`, `src/ratchet-escapement.js`)
- Manifest JSON: https://aipixelwizard.com/api/v1/visuals/ratchet-escapement/versions/1.0.0
- Runnable demo: https://aipixelwizard.com/registry/ratchet-escapement/1.0.0/index.html (open over http; it imports sibling packages by relative path)
- Dependencies (exact): `three@0.185.1` (source) — Renderer, geometry and shader materials.; `chrome-material@1.1.0` (demo) — Studio environment light, backdrop and contact shadow.; `apw-runtime@1.0.0` (demo) — Demo harness.

## Exports
- `createEscapement({ metal?, turns?, plate? }) => { group, ticks, setProgress(progress), dispose() }` — The escape wheel, anchor, balance wheel with hairspring and follower gear, about 9 across, in the xy plane facing +z; `ticks` is the number of ticks per loop; needs an environment map.
- `METALS: { brass, steel, rose, blue }` — Metal finishes with colour and roughness.

## Parameters
- `metal` (select one of brass | steel | rose | blue, default "brass") — Metal
- `turns` (integer 1–3, default 1) — Wheel turns per loop: Whole turns of the escape wheel per loop, sixteen ticks each.
- `plate` (boolean, default true) — Bridge plate
- `background` (color, default "#1a1612") — Backdrop
- `orbit` (boolean, default true) — Camera sway

## Composition
- Inputs: Time within the loop; the metal, turns, plate, backdrop and camera sway.
- Outputs: A full frame rendered in 3D with a studio environment.
- Coordinates: The escape wheel (radius 2.05) is at the origin of the group; the anchor pivots 3.5 above it and the balance wheel sits 6 above it; the follower gear is 4.75 to the right.
- Lighting: A warm key light with a shadow map and the studio environment on the metal.
- Timing: setProgress(progress) sets every part's angle in closed form from the tick count; frames render in any order.
- Works with: chrome-material, orbit-camera, kinetic-title, number-reveal
- The wheel waits then steps in the second half of every tick; the anchor flips between its stops.

## Output and loop
- 1080×1080, 30 fps, 16 s, procedural
- Seamless loop: yes — The wheel advances a whole number of teeth per loop (sixteen ticks per turn, an even number so the anchor is back where it started), the balance swings in a sine of the ticks and the camera sway is a sine of the loop, so the last frame meets the first.
- Verified 2026-10-06 in Chrome 154.0.8037.97 headless on Linux 7.0.0-38-generic (x64), Node 22.14.0 (WebGL 2 via SwiftShader (software)); deterministic: yes; loop check: Frame 0 vs end state (progress 1): mean |Δ| 0.0000, max |Δ| 0 of 255.

## Use it
New project: Create a WebGLRenderer with a studio environment and a shadow-casting light, add createEscapement().group and call mech.setProgress(progress) each frame.

Existing project: Copy src/ratchet-escapement.js; add the group to your scene with an environment map.

Reuse ideas:
- Watch brand: Brass, one turn.
- Cool engineering: Steel, three turns.
- Luxury: Rose gold, no plate.

## Limitations
- The pallets do not truly lock against the teeth: the motion is timed by formula, not simulated.
- The follower gear's teeth only roughly mesh with the escape wheel.

## License
MIT. Copyright (c) 2026 AI Pixel Wizard. Released under the MIT License. See LICENSE in this folder.

Provenance: Adapted from the owner's threejs-sketches/objects-scenes/ratchet-escapement (MIT) and rebuilt for AI Pixel Wizard in October 2026 as an original studio object: an extruded sawtooth escape wheel, a ruby-pallet anchor, a balance wheel with hairspring and a follower gear, all timed from a whole tick count on an exact loop.

