# brainrot 001: bouncing ball escapes the rings Live: https://brainrot.runfridge.dev/001/ Source: https://github.com/hwhang0917/brainrot/tree/main/001 License: MIT (see LICENSE at repo root); attribution only, no warranty. ## What it is A ball falls under gravity inside a stack of concentric, spinning, shrinking rings, each with one gap. When the ball passes fully through the innermost ring's gap that ring is removed and the count goes up; when the innermost ring shrinks down to ball size it is GAME OVER. Every wall hit plays a triangle-wave blip from a C pentatonic scale (the note steps with the escape count). Any key or tap restarts after game over. Buttons: āˆž infinite mode (auto-restart 2 s after game over, saved in localStorage `brainrot-1-infinite`), šŸ“ŗ CRT overlay, mute, and an eye button that hides the controls. No URL params. ## How it was built - pixi.js 8 (`Application`, one `Graphics` redrawn each frame, one `Text` label). Physics runs in a virtual square 1000 units across the shorter screen side; the stage is centred and scaled to fit (`fit()` in main.ts). - Model (physics.ts): gravity 500 u/s², restitution 1, ball radius 12. Rings start at r=120, are spaced 60 apart, all shrink at the same 30 u/s and spin at 0.4–1.4 rad/s in a random direction; gap half-angle Ļ€/6. `refill()` keeps adding outer rings out to r=1100 so the screen corners are always covered. - Only the innermost ring is collision-checked. Inside the gap: if the ball is fully past the ring, the ring is shifted off. Outside the gap: reflect the outward velocity along the radial normal with a minimum bounce speed of 120, then clamp the ball inside. There is no gap-edge collision (marked `ponytail:`). - From the git history: early on rings shrank proportionally, which squeezed the spacing until the ball was trapped and looked frozen; the fix was a constant shrink rate plus the minimum bounce speed so a shrinking wall cannot pin the ball. Restart was changed to work only after game over. Later the ball got lighter, the gap wider, the shrink slower. A tiny hue printed in exponent notation threw inside Pixi's ticker and froze the page, which is why colours go through `lib/color.ts` `hsl()`. - Sound starts muted; the shared sound gate (play with sound / keep muted) is the gesture that creates the AudioContext. - Vibe coded: prompted into existence with a coding agent, iterated commit by commit. ## Files - 001/index.html: page shell, SEO/OG meta, inline CSS, the back link and the CRT / āˆž / mute buttons. - 001/main.ts: Pixi setup, fit-to-window, render loop, trail, blip audio, mute, infinite mode, restart; imports `hsl` (lib/color.ts), `mountCrt` (lib/crt.ts), `mountHud` (lib/hud.ts), `mountSoundGate` (lib/soundGate.ts). - 001/physics.ts: pure game state and integrator (`reset`, `step`, `World`, `BALL_R`, `RING_SPACING`, `MAX_RING_R`). - 001/physics.test.ts: node tests for bounce, escape + refill, game over, not pinned to the wall, constant spacing. ## Extending it - Run: `npm install && npm run dev`, open http://localhost:5173/001/ . Tests: `npm test`. Typecheck+build: `npm run build`. - Physics knobs are the constants at the top of physics.ts; look/sound knobs (ring width, trail length, hue speed, notes, MAX_DT 0.05, AUTO_RESTART_SECONDS) at the top of main.ts. - Invariants: every ring shrinks at the same rate (spacing must stay exactly RING_SPACING; a test checks it); MAX_RING_R must stay past the screen corners for WORLD=1000; keep the dt clamp so a backgrounded tab cannot tunnel the ball through a ring; `world.bounced` is the per-frame audio hook. - Buttons stop pointerdown/keydown propagation because any press restarts the game; do the same for new buttons. - Any colour string fed to Pixi must come from `hsl()` in lib/color.ts (an exception in the ticker stops the page). - Tests build small hand-made `World`s with a `world()` helper and step them with tiny dt. - Conventions: keep pure simulation in its own module with a `node --test` file beside it; match the surrounding code style; Conventional Commits `type(001): message`.