Surprise Box
- group .........
- 3D and WebGL scenes
- source ........
- https://ui.aryank.space/components/surprise-box
- markdown ......
- /lab/surprise-box.md
- human .........
- /lab/surprise-box
── WHAT_IT_IS ────────────────────────────────────────────────────────────────────────────────
A wireframe shipping box alone on black that begs to be clicked. Each poke hops the box, rattles its top flaps, and pitches the poke sound up a step; land five pokes inside the combo window and the lid bursts open, firing waves of tumbling 3D cubes on real gravity. A pointer-transparent stencil of the box front is painted over the rising confetti, so cubes read as leaving from inside the box and only jump in front once they start falling. Inspired by workbox.sh.
── BEHAVIOUR ────────────────────────────────────────────────────────────────────────────────
* The scene is drawn twice
A second, pointer-transparent copy of just the front and right faces sits above the confetti layer. Cubes spawn behind it and are promoted in front only when their vertical velocity turns positive, so they read as leaving from inside the box on the way up and falling past it on the way down.
* Pokes stack, then give
Each click inside a 400ms combo window raises the poke count. Hop height, tilt, and flap rattle all scale with count over target, and the poke sample plays faster (with pitch correction off) so repeat clicks walk up a scale. Miss the window and the count resets to one.
* Confetti runs on real gravity
Cubes are six absolutely positioned faces in a preserve-3d wrapper, integrated at 1600px/s squared with a clamped timestep, tumbling on independent X and Y spin rates. The burst throws one immediate volley then eight more 85ms apart, and the loop stops itself once the last cube clears the floor.
* The lid opens fast and closes slow
Opening swaps the flap transition to an overshooting spring with no delay, so all four throw open together. Closing falls back to the base ease with the two long flaps delayed 280ms behind the short ones, so the box tucks its sides in first like real cardboard.