Design.dev design.dev
3D · Component Template

Ball Pit

A heap of glossy balls under a giant headline, lit like a product render. Push them aside, pick one up, and throw it.

Live demo

Output of this prompt · Claude Fable 5.2 · WebGL

Push the balls around, pick one up and throw it, or drop them all again.

The Prompt 1,150 words

Build a hero that looks like a product render and behaves like a toy. A warm white wall carries the headline in enormous black letters, and against it lies a heap of glossy balls in seven colors: cobalt, tomato, butter, mint, lilac, ink and white. They fall in when the page opens, bounce, settle and lean on one another. The pointer shoulders them aside; press on one and it comes with you, and when you let go it flies. What makes it look expensive is the light: every ball casts a soft shadow on the wall, on the lettering and on its neighbors, darkens the creases where it touches them, and throws a little of its own color onto whatever is beside it. All of that is computed per pixel with no ray marching and no textures except the headline. The studio is fictional: Good Company Studio. The headline: "Serious about play."

Match my project's existing stack, conventions, and design tokens. If there are none, output a single HTML file with inline CSS and JavaScript and zero dependencies.

LOOK
Wall #efece6, ink #16181d. Top left the studio name at weight 600; top right one gray line of help ("Push them. Pick one up. Throw it."); bottom right a black pill, "Drop them again", with a small download arrow, which turns cobalt on hover. The headline is not DOM text: paint it white on black into a canvas the size of the drawing buffer (weight 900, letter-spacing -0.045em, two lines on wide screens and three on tall ones, shrunk to fit with 3% margins) and give that canvas to the shader as the wall's paint. A visually hidden h1 holds the same words.
Ball colors: #2447f9, #ff4b2b, #ffc83d, #74d6ab, #b7a6ff, #16181d, #fbfaf6.

PHYSICS
The world is one unit tall. Thirty-six balls: eleven with radii from 0.128 down to 0.058 and the rest between 0.036 and 0.058; on screens narrower than 4:5 only twenty-two take part, at about three quarters of the size. Every ball rests against the back wall, so its center is one radius out from it. That one rule means circles that do not overlap in the picture are spheres that do not intersect, and the physics can be flat.
- Three substeps a frame. Gravity 2.6; velocity kept at 99.85% per substep.
- Seven passes of contact resolution per substep: push each overlapping pair apart in inverse proportion to mass (mass = radius^1.5), and where they are approaching, apply an impulse with restitution 0.32 for hard hits (closing faster than 0.35) and none for soft ones, so a resting heap goes quiet.
- Walls left and right return 40% of the speed; the floor returns 38% above a speed of 0.5 and nothing below it.
- The pointer is an invisible ball of radius 0.07 with its own velocity: balls are pushed out of it and take 120% of its approach speed.
- Pressing on a ball makes it immovable to the others and sets its velocity to 22 × the distance to the pointer, so it follows without teleporting. On release it keeps the pointer's velocity, capped at 6.
- When the fastest ball is nearly still for 90 frames, stop the loop. Every 5.2 seconds, if nothing has happened, one ball hops. Any pointer event wakes it.

LIGHT
One fragment shader. The balls arrive as an array of 36 vec4 (x, y, radius, color index); work in linear color and convert at the end.
- Which ball is this pixel? Loop over all of them; where the pixel is inside a circle, the height of that sphere here is r + sqrt(r² − d²). Keep the highest, so two balls pressed together still read as solids.
- A point on a ball has position (x, y, height) and normal (dx, dy, sqrt(r² − d²)) / r. A point on the wall has height 0, normal straight out, and the headline's paint as its color.
- One shading function for both. Loop over every other ball and collect three things. Shadow: with the key light up, left and toward the viewer (−0.42, 0.62, 0.64, leaning a little with the mouse), take the ball's distance from the ray toward the light minus its radius, divide by (distance along the ray × 0.16), and smoothstep from −1 to 1: a soft shadow whose penumbra widens with distance. Occlusion: max(n · direction to the ball, 0) × r² / distance², subtracted at 85%. Bounce: the same factor times that ball's color, added at 55%.
- Color = albedo × (hemisphere light, warm gray below to white above, at 0.5 × occlusion + key light 0.86 × n·L × shadow + bounce).
- Gloss, on balls only: reflect the view direction and compare it with the light. A softbox is a rounded rectangle in that space (half-size 0.10 × 0.15, corner 0.035) with a faint halo; a strip light is a narrow vertical band at x = 0.72; and the wall comes up in the rim at (1 − n.z)^4 × 0.34. Dim highlights where the ball is in shadow.
- On the outermost two pixels of a ball, also shade the wall behind it and blend, so edges are soft without multisampling.
- Finish with a 22% vignette and a little grain. Fade in from the wall color over 600ms.

BEHAVIOR
- On load the balls start above the view at random heights and fall in.
- "Drop them again" lifts them all back up and lets go.
- On resize, repaint the headline at the new size and let the walls push the heap in.
- Render at min(devicePixelRatio, 1.75) × a quality factor that falls by 0.1 after twenty slow frames (to 0.5) and recovers after 240 fast ones.

ACCESSIBILITY
The canvas is hidden from assistive technology; a hidden h1 gives the headline and a hidden paragraph says what is on screen and what can be done with it. The one control is a real button. With prefers-reduced-motion the heap is already settled when the page appears (run the simulation ahead of time), nothing hops, and "Drop them again" produces a new settled heap at once; pushing and throwing still work because the visitor is doing them. If WebGL is unavailable, or the device allows fewer than 64 uniform vectors, draw the same simulation with Canvas 2D: flat circles with a highlight over the same painted headline.

NEVER
- Never fake the shadows with one blurred blob per ball. The soft edge has to grow with distance and fall on the neighbors too.
- Never let a ball pass through another or sink into the floor; add solver passes before adding balls.
- Never keep animating a heap that has come to rest.
- Never make the headline unreadable: keep the heap below roughly 40% of the height.
- No images, no fonts, no libraries, no network requests.
  1. CopyThe full prompt, one click.
  2. PasteInto Cursor, Claude Code, or any agent.
  3. CompareAgainst the live demo above.
Ball Pit
Copied to clipboard