# brainrot 005: rube goldberg loop Live: https://brainrot.runfridge.dev/005/ Source: https://github.com/hwhang0917/brainrot/tree/main/005 License: MIT (see LICENSE at repo root); attribution only, no warranty. ## What it is A self-running Rube Goldberg machine in a portrait frame: 12 coloured balls leave a cleated lift at the top, roll down a chute past a timed gate, ride over a pair of meshing brass gears onto a belt, tip a seesaw, get swept by paddle spinners, hit by a swinging pendulum hammer, carried by a sliding shuttle, kicked by pinball bumpers that flash, run along a floor conveyor into the boot cup, and are carried back up by the lift, forever. Nothing to click except 馃摵 CRT and the eye (hide controls). No sound, no URL params. ## How it was built - pixi.js 8 for drawing: static ramps/walls and the lift body drawn once into one `Graphics`, all moving parts redrawn each frame into another. The world is a fixed 900脳1500 portrait box scaled and centred to fit the window. - Physics (machine.ts) is plain CPU code, 8 substeps per frame, gravity 1500, restitution 0.15. Balls are circles; everything else is a segment or a circle with a surface velocity, so one routine, `contactCircle`, handles ramps, belts (surface speed along the segment), gears and their teeth, spinner blades and the seesaw (surface velocity of a spinning body), cleats, bumpers (restitution 1.4), the pendulum bob and the shuttle. Balls collide pairwise. - Kinematic parts are functions of time: pendulum angle = amp路sin(2蟺hz路t), shuttle x = amp路sin(2蟺hz路t), gates closed except `open` seconds per `period`. The seesaw is the one dynamic body: torque from the balls on it, spring back to level, damping, clamped at 卤0.45 rad. The lift is a belt along the upper face of two pulleys with cleats walking a path (bottom arc, straight run, top arc) and a housing + cup that funnels dropped balls back in. - A ball that leaves the world is reset to the top. Ball "rolling" is faked with air-drag-like friction (marked `ponytail:`). - From the git history: three commits on day one: the base loop (ramps, gears, belts, cleated lift), then a timed gate, seesaw, paddle spinner and bumpers, then a pendulum hammer, shuttle, second spinner and gate, floor conveyor and 12 balls. Code comments record tuning lessons, e.g. the lower spinner runs with the flow because against it it trapped balls for half a minute, bumpers sit clear of the wall so nothing perches. - Vibe coded: prompted into existence with a coding agent, iterated commit by commit. ## Files - 005/index.html: page shell, meta, CSS, back link, CRT button. - 005/main.ts: Pixi setup, fit-to-window, static and per-frame drawing of every part, ticker (dt clamped to 0.05 s); its own numeric `hsl()` for ball colours; imports `mountCrt` (lib/crt.ts), `mountHud` (lib/hud.ts). - 005/machine.ts: pure machine layout (`create()`), part types, contact routines, `step()`; exports geometry helpers the renderer reuses (`liftFrame`, `cleat`, `seesawEnds`, `bladeEnd`, `pendulumBob`, `shuttlePos`, `gateClosed`). - 005/machine.test.ts: runs 200 s at 60 Hz and asserts no ball escapes and every ball covers 60% of the height in every 40 s window after the first (nothing gets stuck). ## Extending it - Run: `npm install && npm run dev`, open http://localhost:5173/005/ . Tests: `npm test`. Typecheck+build: `npm run build`. - Physics knobs are the constants at the top of machine.ts; the layout (every segment, gear, gate, spinner, bumper, pendulum, shuttle position) is the literal in `create()`. Colours and line widths at the top of main.ts. - To add a part: add a type + field on `Machine`, a contact call inside the substep loop in `step()`, an entry in `create()`, and drawing in `draw()`. Reuse `contactCircle`/`contactSpinningSegment` rather than writing new collision code. - The lapping test is the guard for layout changes: any new obstacle must not trap balls or launch them out of the world. Run `npm test` after every move of a part. - Gears that mesh need matching surface speed (gear 2's omega = 鈭扜EAR_OMEGA路70/50). - Conventions: keep pure simulation in its own module with a `node --test` file beside it; match the surrounding code style; Conventional Commits `type(005): message`.