Gear geometry worked out from tooth counts (spacing and mesh phase) and exact speed ratios.
Gear geometry worked out from tooth counts (spacing and mesh phase) and exact speed ratios.
No runs posted yet. Be the first: post yours and tag @wikiwayne.
GEAR TRAIN: Seven Meshing Gears
HOOK OBJECT: window.__gears
Build "GEAR TRAIN": a chain of seven meshing gears drawn in pure SVG (no canvas, no libraries). The first gear is turned by a hand crank, and every gear after it turns at exactly the speed its tooth count demands, so you can see small gears spin fast and big gears turn slowly while every tooth fits the gap of the next one.
LOOK
- Style: brushed brass and dark steel on a blueprint-blue workbench. Background gradient #10243F (top) to #0A1626 (bottom) with a faint grid of lines #1C3A5E every 40 px. Gears in this order, each with a different fill: #E0B25C, #C9825A, #8FB7D9, #D9D3C6, #7BC0A0, #D68FA8, #B79CE0. Each gear has a darker hub circle, 4 or 5 spoke cut-outs, and one bright red dot (#FF4B4B, 6 px across) near its rim as a turn marker, placed at whatever rim angle the gear's starting phase gives.
- Tooth counts, in chain order: 12, 24, 16, 32, 20, 40, 14. All gears use the same tooth size (the same module), so a gear's pitch radius is proportional to its tooth count: pitch radius = teeth x 3.4 px at 1280x720 (scale with the screen). Each tooth is a simple trapezoid of height 0.35 x the tooth pitch.
- Place the seven gears in a zig-zag chain (each gear touching the next one) so the whole train, with the crank, fills about 75% of the screen height; gears that are not neighbors must not overlap. Each pair of neighbors has its centers exactly the sum of their two pitch radii apart. Starting phase: tooth k of a gear with N teeth at rotation angle t sits at t + k x 360 / N degrees. For neighbors A then B, where phi is the angle of the line from A's center to B's center, let fA = ((phi - t_A) mod (360 / N_A)) / (360 / N_A) and fB = ((phi + 180 - t_B) mod (360 / N_B)) / (360 / N_B). The teeth mesh when fA + fB = 0.5 (mod 1), so a tooth of one gear lands in a gap of the other. Start with t = 0 for gear 1 and choose each next gear's t_B to satisfy that, working along the chain.
- A crank handle (a 70 px arm with a knob) is fixed to the first gear's hub.
- A bottom strip shows seven color chips in the same order as the gears; each chip shows the tooth count and the live speed in rpm (for example "12T 30.0 rpm"). The strip never overlaps the gears.
- FIRST FRAME (t = 0, no input): the whole train in view, gear 1 already turning clockwise at 30 rpm, the markers wherever each gear's tooth phase puts them (no marker needs to be at 12 o'clock), the chips showing the right numbers.
MOTION / PLAY
- Gear 1 (12 teeth) is the driver. Each next gear turns the opposite way, and the speed of gear n+1 equals the speed of gear n times teeth(n) divided by teeth(n+1). With 30 rpm on gear 1, gear 2 turns 15 rpm the other way, gear 3 turns 22.5 rpm, and so on. The teeth must interlock: at the contact point between two gears, a tooth of one sits in the gap of the other (within 5 degrees), for the whole run, never overlapping.
- Controls: drag the crank (or the first gear) in circles to turn the train by hand, and let go to let it coast to a stop in 1 s. A speed slider and a direction button (each at least 48 px) set the driver to between 5 and 90 rpm, clockwise or counter-clockwise. Arrow keys left/right change the speed by 5 rpm. setView(zoom) zooms from 1x to 1.8x.
- When you reverse the direction, all seven gears reverse together within 1 frame.
- ATTRACT MODE: with no input, a hands-free demo starts on load and loops every 25–30 s, showing every main feature (30 rpm clockwise for 8 s, speeding up to 60 rpm over the next 4 s, a direction reversal at about 13 s, 45 rpm counter-clockwise for 9 s, then slowing and reversing back clockwise to 30 rpm). Any input takes over; the demo resumes after 8 s with no input.
SOUND
- A soft steady mechanical whir whose pitch follows the driver's speed.
- A small wooden "tick" every time a marker dot passes the top of its gear (higher pitch for the faster gears).
- A heavier "clunk" when the direction reverses.
COUNTERS
stats() returns { fps, turns, reversals, driverTurns }.
- turns: an array of seven numbers (one per gear, in chain order); each goes +1 exactly when that gear's red marker dot passes the 12 o'clock position, in either direction. Never at t = 0.
- reversals: +1 exactly when the driver's direction visibly changes.
- driverTurns: +1 each time the crank's marker passes the top (always equal to turns[0]).
- On screen: the turn counts appear on the chips in the bottom strip, and the reversals count at the top-left, readable in a paused frame and never over a gear.
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. There are exactly 7 gears with 12, 24, 16, 32, 20, 40 and 14 teeth, each neighboring pair has its centers apart by the sum of its pitch radii within 0.5 px, and the train is at least 60% of the screen height.
2. After advance(10) at 30 rpm, the measured rotation of every gear matches 30 x teeth(1) / teeth(n) rpm within 0.5%, and the directions alternate clockwise and counter-clockwise.
3. At the contact point of every neighboring pair, a tooth of one gear sits in the gap of the other (within 5 degrees), at t = 0 and again after advance(10).
4. turns equals floor(rotation / 360 degrees) for every gear (within 1) after advance(20), and reversing the driver makes all seven gears turn the other way within 1 frame and adds exactly 1 to reversals.
5. A 28 s attract loop shows at least 1 reversal, driverTurns of at least 10, and 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 chip strip on a blank page, because one script error stopped the scene.
- Gears whose teeth overlap or sit tooth-on-tooth instead of tooth-in-gap.
- Gears that all turn the same direction, or at the same speed, or at speeds that do not match their tooth counts.
- Neighboring gears with gaps or overlaps between them, or gears that are not the sizes their tooth counts imply.
- Using a canvas, an image file or a library instead of plain SVG.
- A reversal where some gears keep going the old way for a moment.
- Counters that tick on a timer instead of when a marker dot passes the top.
- A bottom strip or label drawn over the gears.
- 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