Visualizations
141 / 500

141 · Games

Pool Trick Shots

Billiards with real spin physics and an AI that plans by simulating every shot.

Every ball carries a velocity and a full 3D spin, and the cloth acts on the slip of the contact point: sliding friction slows the ball and turns its spin toward natural roll at the same time, which is all it takes for draw, follow and stun, while a raised cue tips the spin axis so the ball bends in a masse curve. Ball collisions add a little friction for throw, and cushions are struck above the ball's equator, so english changes the rebound angle and the rubber visibly gives. The AI lists candidate shots with ghost-ball geometry and mirrored pockets for banks, finds masse aims by bisection along a curving path, then plays dozens of speed and spin variations through the same deterministic physics and keeps the shot that pots its ball and leaves the easiest next one. Every third shot it shows off with a bank or a curve.

Try it. Press anywhere, drag back away from the cue ball and release to shoot, with the predicted paths updating as you aim. Set the tip position on the cue ball diagram, and raise the cue with the slider beside it for a masse. Click the view, then use the arrow keys for english, M to raise the cue, space to hand the shot to the AI, or R to rerack.

  • Sliding and rolling friction with 3D spin
  • Impulse collisions with friction
  • Planning by deterministic simulation
  • Per-pixel ball rendering

View the source · one module, plus a small shared runtime for sizing, the animation loop and input

Build your own

Paste this into Claude Code, Codex or any coding agent to get a simple version running, then take it wherever you like.

Build an overhead pool table with real spin physics, using JavaScript and the HTML canvas element. Put everything in a single index.html file with no libraries or build step, so I can open it directly in a browser.

Start simple:
- Make a canvas that fills the window, stays sharp on high-DPI screens (scale by devicePixelRatio), and resizes with the window. Draw a felt table with rails and six pockets.
- Give each ball a 2D velocity and a 3D angular velocity. Each fixed time step, compute the slip of the contact point with the cloth, u = v + w x (0, 0, -R). While it slips, apply sliding friction against u to both v and w; once it rolls, apply a small rolling resistance and keep w locked to rolling.
- Resolve ball collisions with an impulse along the line of centres, and bounce off the cushions with some energy loss. Drop balls that reach a pocket.
- Let me drag back from the cue ball and release to shoot, and set the tip offset (side and top or bottom) on a small cue ball diagram. Compute the starting spin from the impulse at that point on the ball.
- Draw and follow shots should now come back or keep rolling after a straight hit on its own.

Once that works, make it beautiful:
- Shade the balls with highlights and give the cue ball red dots so you can see it spin.
- Show a predicted path by running the same physics ahead of time on a copy of the table.
- Add a simple AI: for each ball and pocket, place a ghost ball where the cue ball must touch, simulate a few speeds, and play the shot that pots and leaves the cue ball best placed.

Explain the key ideas in short code comments. When you're done, tell me how to open it and suggest three directions I could take it next, such as masse shots with a raised cue, bank shots found by mirroring pockets in the cushions, or a two-player game with real rules.
PreviousEcholocationA bat hunts moths in a black cave that exists only as the echoes of its calls. NextTuring MachineA brass Turing machine runs busy beavers, including all 47 million steps of BB(5).

Related visualizations

  • Bubble Bank ShooterGames A pastel bubble shooter whose AI traces 640 bank shots before every throw.
  • Procedural PinballRetro Generated pinball tables in perspective, played by an AI that simulates its flips.
  • Dynamical BilliardsPhysics A fan of 1,000 balls in reshapable tables, linked live to the Birkhoff phase map.
  • Marble LabyrinthGames A wooden tilt maze where a careful AI steers a steel ball between the holes.
  • Ball PitPhysics Hundreds of colorful balls tumble, stack and bounce off each other.
  • Spinning TopsPhysics Rigid-body tops precess, wobble and clash in a steel dish, then topple as they slow.
  • BreakoutGames The arcade classic, with sparks, screen shake and an autopilot.
  • Vector BallsRetro 512 chrome spheres, depth sorted, morphing from a torus knot to DNA to a smiling face.
  • Siteswap JugglerMath Juggling notation made physical: true parabolas, a ladder diagram and the state graph.

Use ← and → to move between demos. While the canvas has focus, keys go to the demo instead.

← More from Emergent Mind Labs