Generated pinball tables in perspective, played by an AI that simulates its flips.
Every table is generated from a seed: features such as a pop bumper cluster, a flared ramp, drop targets, a spinner lane and rollover lanes are placed by rejection sampling, aimed at the opposite flipper, and the table is kept only if test balls dropped from a grid across the playfield all find the drain, so it has no pockets or ledges. The ball runs at a fixed 600 Hz with swept collision tests, a ray against every wall grown into a capsule of the ball's radius, so it cannot tunnel, and the tapered flippers push it with their true surface velocity. The playfield art is painted once flat and warped into perspective row by row, while the ball, flippers, bumpers and the clear ramp are projected point by point. In attract mode the AI snapshots the table, simulates the same physics forward for up to two dozen flip timings (including a hold that traps the ball, then a drop and re-flip to aim), scores each future by what it hits, and commits to the best; the dotted line and the bar chart show its plan.
Try it. Z or the left arrow flips left, M or the right arrow flips right, and on a touch screen tap either half. Hold space (or press and hold) to pull the plunger. Press N for a new table. The AI takes over again after six idle seconds.
Paste this into Claude Code, Codex or any coding agent to get a simple version running, then take it wherever you like.
Build a small pinball game with 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 and stays sharp on high-DPI screens. Draw a tall table in its own coordinate system (say 560 by 1000 units) and scale it to fit.
- Describe the walls as a list of line segments: two side walls, a curved top made of short segments, and two slanted guides that lead down to the flippers.
- Give the ball a position and velocity, add gravity pointing down the table, and step the physics many times per frame (for example 600 small steps per second) so a fast ball never jumps through a wall.
- For each segment, find the closest point to the ball. If it is nearer than the radius, push the ball out along the normal and reflect the velocity with some bounce (velocity minus 1.6 times its normal component).
- Add two flippers as thick line segments that rotate quickly to an up angle while a key is held (Z and M) and fall back when released. When the ball touches one, add the flipper's own surface velocity at that point (angular speed times the distance from the pivot) to the bounce, so flips really launch the ball.
- Add three round pop bumpers that kick the ball away at a fixed speed, and respawn the ball at the top when it falls out of the bottom.
Once that works, make it beautiful:
- Paint the playfield with a bold retro gradient, sunburst stripes and glowing inserts, and give the ball a shiny highlight and a short trail.
- Light up bumpers when hit, keep score, and show it in big blocky dot-matrix digits.
- Add a simple AI for when nobody is playing: when the ball comes near a flipper, simulate the next second of physics for a few different flip times and pick the one that sends the ball highest.
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 a ramp the ball rides on a separate layer, drawing the table in perspective, or generating random table layouts.