Clean, steady click timing in a five-ball cradle, with the resting balls staying perfectly still.
Clean, steady click timing in a five-ball cradle, with the resting balls staying perfectly still.
No runs posted yet. Be the first: post yours and tag @wikiwayne.
STEEL CRADLE: Five Balls, Clean Clicks
HOOK OBJECT: window.__cradle
Build "STEEL CRADLE": a glossy desktop executive-toy cradle of five polished steel balls in Canvas 2D (no libraries). Lift one, two or three balls from either end and let go: the same number of balls swing out from the other end with a crisp click every time, forever. Treat it as an ideal cradle: no sloppy bouncing, just perfectly timed swings.
LOOK
- Style: polished metal and dark wood, studio lighting. Background gradient #1A1D26 (top) to #0C0E14 (bottom), a soft table glow. Frame: dark walnut base #4A2F1F and two chrome rails #C9D2DC. Balls: radial gradients from #FFFFFF through #AEB9C6 to #3C4552 with a bright highlight; each ball is 68 px across at 1280x720 (scale with the screen), hung from the top rail by two thin wires #8A94A0 in a V shape.
- Five balls in a row, touching when at rest, wire length 380 px from rail to ball center.
- A soft shadow ellipse under each ball on the base. A small counter strip at the bottom-left.
- FIRST FRAME (t = 0, no input): five balls centered, the four right balls hanging at rest and the leftmost ball already lifted 35 degrees and just about to fall. The frame and balls fill at least 65% of the screen height.
MOTION / PLAY
- Model it as an ideal cradle: a lifted group swings as a simple pendulum with period T = 1.55 s (angle = A x cos(2 pi t / T)). When the group reaches the resting balls at the bottom, a strike happens: exactly the same number of balls leave from the other end with the same amplitude A, while all other balls stay completely still. The group then swings out, stops at A, and swings back, and so on. Lose at most 1% of amplitude per strike.
- Controls: drag the leftmost or rightmost ball outward to lift a group, then let go from the angle you pulled to (capped at 60 degrees). A small "1 2 3" button row (each button at least 48 px) sets how many balls the next lift grabs (default 1). While you drag, the lifted balls follow the pointer, the other balls stay still, and the number of lifted balls shows on screen. setView(zoom) zooms from 1x to 1.6x.
- ATTRACT MODE: with no input, a hands-free demo starts on load and loops every 25–30 s: it lifts 1 ball from the left, then 2 balls from the right, then 3 balls from the left, then 2 balls from the left, each for about 7 s (28 s in all), then repeats. Any input takes over; the demo resumes after 8 s with no input.
SOUND
- A crisp metallic "click" for every strike: louder for 1 ball, slightly lower and fuller for 2 and 3 balls.
- A very quiet wire "creak" when a group is lifted.
- A soft "whoosh" proportional to the swing speed.
COUNTERS
stats() returns { fps, strikes, swings, lifts }.
- strikes: +1 exactly when a swinging group hits the resting balls and the click sound is triggered.
- swings: +1 exactly when a swinging group reaches the top of its arc and stops for a moment.
- lifts: +1 exactly when you (or the demo) release a lifted group.
- On screen: the three counters in a small row at the bottom-left, readable in a paused frame and never over the balls.
CHECKS for ?test=1
With ?test=1, run an accelerated self-test that measures real positions and real events (not self-set flags) and logs "TEST n PASS" or "TEST n FAIL: reason" to the console and to window.__testResults:
Each check starts from a fresh load; advance() steps in 1/60 s increments.
1. With five balls at rest (use a setup call or a quick release from 0 degrees), the gap between neighbors is 0 within 1 px, and the whole cradle is at least 65% of the screen height.
2. Lift 1 ball to 35 degrees and release: the first strike happens at T / 4 = 0.3875 s after release (within 3%), exactly 1 ball leaves the other end reaching 34.6 degrees or more, and the middle three balls never move more than 0.5 px.
3. Lift 3 balls and release: exactly 3 balls leave the other end, and the 2 that were not lifted never move more than 0.5 px.
4. Over 6 strikes in a row, consecutive strikes are T / 2 = 0.775 s apart (within 3%), and the amplitude never gets bigger than the starting amplitude.
5. In a 28 s attract loop: strikes is at least 12, lifts is at least 4, strikes equals the number of click sounds triggered, and there are zero console errors.
KEEP IT SHORT
- Keep the whole file under about 1,500 lines (soft target) so you can write it in one pass and finish well inside 15 minutes.
- Save lines with helpers, loops and instancing, not by dropping features. Everything above must really work: no placeholders, no TODOs.
BUILD RULES (all required):
- Deliver ONE self-contained HTML file: inline CSS and JS, no build step, no local assets. Libraries only from a CDN. If you use Three.js, use exactly this import map: {"imports":{"three":"https://cdn.jsdelivr.net/npm/three@0.160.0/build/three.module.js","three/addons/":"https://cdn.jsdelivr.net/npm/three@0.160.0/examples/jsm/"}}
- It must open straight from disk in desktop Chrome and on an iPhone (Safari), fill the full screen, handle resize and touch, and stay smooth (target 60 fps).
- It must look stunning in the very FIRST frame: no black screen, no loading wait, no tiny subject. The main subject fills at least 50% of the screen height.
- SOUND (required): all sound is made in code with Web Audio (no audio files). Show a small "🔊 TAP FOR SOUND" chip; on the first tap create ONE AudioContext, route everything through a master gain of 0.6 into a DynamicsCompressor, and hide the chip. Also expose enableAudio() on the hook object named at the top.
- Expose the hook object named at the top with: setCameraOrbit(azimuthDeg, elevationDeg, distance) (or an equivalent camera setter), advance(seconds) that steps the simulation exactly that much for still captures, enableAudio(), and stats() returning {fps, ...the counters named above}. Use a fixed random seed of 360 so every run is the same.
- Every on-screen counter must count a real event you can see happen. No fake numbers.
- No text overlapping the subject; any label must be readable in a paused frame.
- No brand logos, no real people, no copyrighted characters, brand names or logos.
FAILURE MODES TO AVOID
- A blank page, or only the HUD on a dark page, because one script error killed the scene.
- Balls that overlap each other, drift sideways, or hang with gaps at rest.
- The middle balls swinging when they should stay still.
- The wrong number of balls leaving the other end, or a delay between the strike and the swing.
- Swing timing that speeds up, slows down or drifts so the clicks are not evenly spaced.
- A click sound that plays at the wrong time, or not at all, or counters that tick on a timer.
- Balls that fly off the frame, or wires that stretch or detach from the balls.
- Metal that looks flat gray instead of polished steel with a bright highlight.
- The same variable declared twice, or methods called on objects that don't exist yet.
SELF-TEST LOOP
- If you can run code: build the file, open it, read the console, run ?test=1, and take screenshots at 3 s, 10 s and 30 s at 1280x720 and 390x844. Look at the screenshots and fix what looks wrong. Fix and retest until all 5 checks pass with zero console errors. Mark anything you could not run as UNMEASURED; never invent results.
- If you are chat-only: go through this prompt line by line, check your code against each line, and fix anything that would fail. Then write one corrected, complete file.
- Final answer: ONE complete HTML file in ONE code block, then the 5 checks marked PASS, FAIL or UNMEASURED. No snippets, no "rest unchanged".
Built one? Post it on X and tag @wikiwaynePost on X