Marble Machine
A handcrafted wooden marble machine on a workshop bench: a crank-driven lift wheel feeds glass marbles into a spiral, zig-zag rails, a copper vortex, a counterweight tipper and a glowing xylophone, filmed by a camera that follows one marble.
Made in Claude Code (Claude subscription) with claude-opus-5.5. The agent wrote code, looked at the preview and fixed it over several iterations. This is not a single-shot result: comparisons on this site show models in one attempt.
Starting prompt
Build "Marble Machine": a real-time 3D film of a handcrafted wooden marble machine, a Rube Goldberg-style kinetic toy standing on a workshop bench, that runs forever. It should look like a photograph of a real object and be beautiful from the first frame. Single self-contained HTML file; Three.js and its addons from a CDN via an import map are fine; build everything procedurally (canvas textures are fine), no external models or image files. The machine (units of about 10 cm, y up; about 7.5 units wide and 3.5 tall, on a maple base board on a walnut plank bench): - The lift wheel, on the left: a cherry-wood wheel about 3.2 units across, with a rim, six spokes and a hub with a brass pulley, turning slowly clockwise. Ten brass pegs on its face push the marbles up the left side along a fixed curved brass guide band. A leather belt runs from the hub pulley to a small brass pulley with a crank handle on its own stand, which turns about three times faster than the wheel. - The high rail: from the top of the wheel, a long track of two brass wires with small cross ties, held by wooden brackets from a tall oak back board, runs across the whole machine. - The spiral: two and a half turns down around a maple pole with a brass ball on top, held by thin radial arms. - The zig-zag: three switchback rails on the back board, joined by two C-shaped curved brass turns. - The vortex: a polished copper funnel on three brass legs, with a gravity-well profile (almost flat at the rim, steep near the hole). The marble enters along the rim and circles inwards about three times, faster and faster, then drops through the neck. - The counterweight: under the neck, a brass trough on a lever with a brass counterweight. The marble's weight tips the trough and the marble rolls out; the counterweight swings it back onto a felt pad with a small bounce. - The xylophone: the marble rolls across eight rainbow-anodised metal bars of decreasing length, on felt and walnut rails. Each bar glows, and a small coloured light flashes, when the marble rolls over it. - The return: a curved rail back to the bottom of the wheel, where the marbles queue for the next peg. The marbles: about 30 glass marbles (radius 0.085) with cat's-eye swirls: clear, faintly tinted glass (MeshPhysicalMaterial with transmission, ior about 1.5) around three thin twisted coloured vanes, so the swirl is seen through the refraction. Eight colour palettes, plus one featured marble in ruby and gold. The physics: - Build the run as two smooth paths sampled by arc length: from the top of the wheel to the funnel neck, and from the tipped cup to the bottom of the wheel. - Each marble has a position and a speed along its path: gravity along the slope (5/7 g for a rolling ball), a little rolling friction and air drag. Marbles never overlap; they bump into each other and queue. - A marble waits at the end of a path until the counterweight cup or the next wheel peg is ready. The wheel picks up the front marble whenever a peg passes the bottom and releases it at the top. - Each marble spins about the correct axis at the speed it rolls (angular velocity = contact normal × velocity / radius). - Before the first frame, run the simulation for about 90 seconds so the machine is already in full swing. One lap takes about 40 seconds. The look: a warm workshop. - Canvas wood-grain textures: walnut planks for the bench, maple, cherry, oak for the back board, and dark horizontal boards on the wall behind. A small engraved brass maker's plaque on the back board. - Polished brass and copper with an environment map. Soft shadows from a warm key light, plus a cool rim light and a warm fill. - In the background, softly out of focus: a shelf with jars and a string of warm bulbs on the wall. - A shallow depth of field focused on the featured marble, ACES tone mapping, subtle bloom only on the bulbs and the glowing bars, and a soft vignette. The camera: a film that follows the featured marble and cuts to a new shot at each part of the machine. 1. A slow, wide establishing shot of the whole machine while the marble rides the wheel. 2. A tracking shot beside it along the high rail. 3. A slow arc around the spiral at the marble's height. 4. Looking down along the zig-zag board. 5. High over the funnel, also showing the counterweight below it. 6. A low tracking shot along the xylophone and back to the queue at the wheel. Camera moves are smoothed. Drag to orbit and scroll or pinch to zoom; the camera glides back to the film about four seconds after the last input. Interface: the title with a small subtitle; a caption naming the current part of the machine (the lift wheel, the high rail, the spiral, the zig-zag, the vortex, the counterweight, the xylophone, back to the wheel) with one short line about it; and a counter of the marbles lifted so far. Everything starts automatically and is visibly moving from the first frame, without any interaction. The page must also work in a sandboxed iframe without same-origin access, so do not use localStorage. The layout works on a phone: on a portrait screen, pull the camera back and widen the field of view. Engineering rules (the page must work on the first load, with no fixes): - Use Three.js r170 and only methods that exist on each of its classes. Give every custom ShaderMaterial `fog: false`, and declare every uniform, constant and varying its shaders use. - Declare each identifier once. Inside one calculation, never reuse a shared scratch vector for two values that are both still needed; use local vectors. - Guard every animated value against NaN. - Answer with the complete file exactly once, in a single ```html code block: no drafts, partial snippets or notes. Keep planning brief and write the code. Aim for roughly 700 to 1,000 lines, compact and well structured.