Skip to content

Marble Sorter

A glass marble machine that sorts marbles by colour through three channels, then lifts them back to the top. Loops perfectly.

3D object, V2 Objects3DSeamless loop, verified117 lines of codev1.0.0

In Machines & clockwork, Toys, games & parties

Next: Ball ClockSurprise me

Marble Sorter preview
Starting live preview…
00:00:00:00 / 00:00:00:01

Live, running the real source at reduced resolution.

Your current settings go with it. Combine several clips and hand them over together from your sequence.

Effect controls

Presets

12

Marbles in circulation, in threes.

1

The preview runs the same code your AI receives. These settings travel with the hand-off.

Info

What it is

A machine that sorts marbles by colour, forever. Mixed marbles drop from the top into a glass tube that splits into three channels; brass gates flick open to send each colour down its own lane; the lanes rejoin, a conveyor carries the marbles to the foot of a lift and the lift raises them back to the top. Choose the number of marbles, the colours (primary, candy, forest or mono), the trips round the circuit per loop, glass or brass tubes, the backdrop colour and whether the camera sways.

Reuse it in your own idea

  • Toy brand: Primary, glass.
  • Soft: Candy, many.
  • Industrial: Forest, brass tubes.

Which part is reusable

src/marble-sorter.js is the ingredient your AI reuses. demo.js is only the example scene around it, and uses chrome-material only for the demo.

Good to know

  • Marbles move at a steady speed along their lane rather than accelerating down slopes.
  • The gates are decorative: marbles follow their lanes whatever the gates do.

Technical details

Technical details
Implementation
Three.js 0.185.1 (WebGL) · ES module src/marble-sorter.js
Exports
  • createMarbleSorter({ marbles?, palette?, trips?, tubes? }) => { group, setProgress(progress), dispose() }
  • PALETTES: { primary, candy, forest, mono }
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.
How it fits a scene

Coordinates: The machine stands in the xy plane (x from −3.5 to 5.5, y from 0 to 6.7) in front of a board at z = −0.7; the camera looks at (2.7, 3.5).

Lighting: A warm key light with a shadow map and the studio environment.

Timing: setProgress(progress) places each marble along its lane's curve and sets the gates; frames render in any order.

Output
1080×1080, 30 fps, 16 s · procedural (computed from the frame number) · seamless loop — Every marble makes a whole number of trips round its closed circuit per loop with the marbles spaced evenly in time, each gate's opening is a function of the marbles passing it, and the camera sway is a sine of the loop, so the last frame meets the first.
Tested
Rendered 480 frames on 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)). Same frame twice from fresh pages: identical. Loop: Frame 0 vs end state (progress 1): mean |Δ| 0.0000, max |Δ| 0 of 255.
Performance
Tubes of about 25 000 triangles and up to 24 marbles with a shadow map: about a millisecond a frame on an integrated Intel GPU. Software WebGL renders in about two seconds a frame.
Export a video yourself
Download the source, then in the folder: npm install npm run render -- marble-sorter/1.0.0 --out my-video.mp4Needs Node 18+, ffmpeg and Chrome/Chromium. Add --params my-settings.json (from Copy settings) for your own settings.
Version
1.0.0 · sha256:13e4de7339249b86…
Files
License
MIT. Copyright (c) 2026 AI Pixel Wizard. Released under the MIT License. See LICENSE in this folder. License details
Provenance
Adapted from the owner's threejs-sketches/objects-scenes/marble-sorter (MIT) and rebuilt for AI Pixel Wizard in October 2026 as an original studio object: three closed lane curves through glass tubes with marbles sorted by colour, gates opening as the marbles pass and a lift back to the top, on an exact loop.
BinMore like this

Ball Clock

3D object3DSeamless loop16 seconds

Hourglass

3D object3DSeamless loop16 seconds