# Marble Run — `marble-run@1.0.0`

Glass marbles rolling round a wooden roller-coaster track, speeding down slopes and slowing over crests. Loops perfectly.

Glossy glass marbles rolling round a wooden track that rises and falls in hills and swings through bends, held up on slender posts. The track is a closed circuit, so the marbles never stop: each one accelerates down every slope and slows over every crest, with its speed worked out from the height of the track, and together they make exactly one lap of the circuit per loop. Choose the number of marbles, the track layout (gentle, rollercoaster or figure), the wood (oak, walnut or birch), the laps per loop, the backdrop colour and whether the camera sways.

- Kind: object; status: published; digest sha256:a5cfaafa510ef54e32b150797e02b3f2d3eb33f0c8b4fe168ae9c66248b90688
- Role: Object (3D, three.js): a satisfying toy-physics scene for kids' content, games and playful product videos.
- Implementation: three; entry `src/marble-run.js`
- Files: https://aipixelwizard.com/registry/marble-run/1.0.0/<path> (`LICENSE`, `asset.json`, `demo.js`, `index.html`, `src/marble-run.js`)
- Manifest JSON: https://aipixelwizard.com/api/v1/visuals/marble-run/versions/1.0.0
- Runnable demo: https://aipixelwizard.com/registry/marble-run/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
- `createMarbleRun({ marbles?, track?, wood?, laps? }) => { group, setProgress(progress), dispose() }` — The wooden circuit with its posts and marbles, about 12 across, resting on y = 0; needs an environment map.
- `TRACKS: { gentle, rollercoaster, figure }` — Layouts: radius and the hills and bends round the circuit.
- `MARBLES: string[]` — Marble colours.

## Parameters
- `marbles` (integer 1–6, default 4) — Marbles
- `track` (select one of gentle | rollercoaster | figure, default "rollercoaster") — Track
- `wood` (select one of oak | walnut | birch, default "oak") — Wood
- `laps` (integer 1–2, default 1) — Laps per loop
- `background` (color, default "#d6d2cc") — Backdrop
- `orbit` (boolean, default true) — Camera sway

## Composition
- Inputs: Time within the loop; the marbles, track, wood, laps, backdrop and camera sway.
- Outputs: A full frame rendered in 3D with a studio environment.
- Coordinates: The circuit is centred on the origin, 9–12 across, rising to about 6.5 above the floor; marbles of radius 0.3 roll in the trough; the camera looks down at 29°.
- Lighting: A warm key light with a shadow map, a shadow-catching floor and the studio environment.
- Timing: setProgress(progress) places each marble from a precomputed time table of the circuit; frames render in any order.
- Works with: chrome-material, orbit-camera, kinetic-title, number-reveal
- The marbles' speed follows sqrt(top height − height), tabulated once; marbles spaced evenly in loop time.

## Output and loop
- 1080×1080, 30 fps, 16 s, procedural
- Seamless loop: yes — The marbles make a whole number of laps of the closed circuit per loop with their speed set by the track's height, each marble turns a whole number of times per lap 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 createMarbleRun().group and call run.setProgress(progress) each frame.

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

Reuse ideas:
- Toy brand: Oak rollercoaster.
- Soft: Birch, gentle.
- Busy: Walnut, six marbles.

## Limitations
- The marbles' speed follows height but is not a rigid-body simulation: they do not leave the track.
- Marbles do not collide with each other.

## 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/marble-run (MIT) and rebuilt for AI Pixel Wizard in October 2026 as an original studio object: a closed wooden roller-coaster circuit swept from a space curve, with marbles whose speed is tabulated from the track's height, on an exact loop.

