I'll build a domino chain reaction simulator. Let me plan the approach:
- Physics: Custom scripted physics (each domino tips when triggered by the previous one) — more reliable than full rigid-body physics for curved paths
- Path: Catmull-Rom spline through user click points, dominoes placed along the curve with perpendicular orientation
- Rendering: Canvas 2D with side-view perspective
- Replay: Record each domino's fall progress over time, then play back at any speed
Let me start by installing Matter.js (actually I'll skip it and use custom physics since scripted is cleaner for this use case), then build the app.
Now let me build the simulator. I'll structure it as a curve utility, a main simulator component, and update App.tsx.
Now the main Simulator component with the canvas, animation, and controls:
Let me rewrite the Simulator to fix the issues (duplicate animation loop, undefined ref ordering, unused vars):
Now let me update App.tsx to use the Simulator and update the title:
Let me build to verify everything works:
Let me verify the normal direction is correct (dominoes should stand "up" on screen for a rightward path):
Let me fix the rotation direction — the domino should tip forward, not backward:
Let me adjust the initial points to fit better on smaller screens:
Let me add proper reactivity for the Replay button and auto-finish the run when the chain completes:
Now let me update the animation loop to detect run completion and auto-transition, and update canReplay:
Let me improve the normal direction so dominoes always stand "up" in screen coordinates:
Let me add keyboard shortcuts for common actions:
Let me move the keyboard effect below the handlers:
Let me add a keyboard shortcuts hint to the sidebar:
Let me do a final review by reading key parts of the simulator to verify correctness:
The build is successful. Let me provide a summary of what was built.
Summary
I've built a Domino Chain Reaction Simulator with all the requested features:
🎯 Core features
- Click-to-place: Click anywhere on the canvas to add path points; click an existing point to remove it
- Curved path support: Uses Catmull-Rom splines through user points with arc-length parameterization, so dominoes are spaced evenly along any curve shape
- Adjustable spacing: Slider to control the distance between dominoes (15–100 px), with live preview updates
- Trigger button: Big amber "▶ Trigger chain" button that starts the cascade from the first (red-highlighted) domino
- Slow-motion replay:
- Speed slider (0.1× to 2×) affects both running and replay
- Preset speed buttons (0.25×, 0.5×, 1×, 1.5×, 2×)
- Scrub bar during replay to jump to any moment
- All progress snapshots recorded at 25 ms intervals during the run
🎨 Visual polish
- Dark zinc theme with amber accents
- Dominoes have gradient fills, edge highlights, and drop shadows that grow as they fall
- First domino is rendered in red with a pulsing selection ring in placing mode
- Subtle grid background with a radial amber glow around the path
- Dashed curve preview showing the spline through your points
⌨️ Extras
- Keyboard shortcuts:
Space/Enter to trigger, P to replay, R to reset, C to clear path, Z to undo
- Auto-transitions back to placing mode after the chain finishes
- Live stats panel showing domino count, point count, chain length, and replay duration
- Responsive canvas that resizes with the window
🏗️ Architecture
src/domino/curve.ts — Catmull-Rom spline + arc-length sampling + domino placement
src/domino/Simulator.tsx — Canvas renderer, animation loop, state management, UI
src/App.tsx — Minimal wrapper
The physics uses a scripted cascade (each domino tips when the previous one reaches a threshold) which gives reliable, visually-convincing chain reactions along any path shape — including loops, S-curves, and zig-zags.
Files built: src/domino/curve.ts, src/domino/Simulator.tsx, src/App.tsx, index.html