Three-body problem, 2D

Three gravitating bodies in 2D, with five fixed presets. Vite, TypeScript, Canvas or SVG.

Prompt
Build a polished 2D Three-Body Problem simulator as a Vite web app.

Use:
- Vite as the project setup.
- TypeScript if possible.
- Plain Canvas or SVG for rendering, whichever gives the smoothest animation.
- A clean component structure and readable code.

Goal:
Create a small but high-quality interactive web app that simulates three gravitational bodies in 2D. The app should feel smooth, visually clean, responsive, and physically credible. It will be used as a benchmark to test how well models can build interactive scientific simulations.

Core requirements:
- Smooth real-time animation.
- Accurate and stable physics behavior.
- Clean modern UI.
- Responsive layout for desktop and mobile.
- No unnecessary heavy frameworks or bloated dependencies.
- The app should work immediately after install and run with Vite.

Presets:
Include exactly these presets and make them selectable from the UI:

1. Figure-8 Orbit
   - The classic stable figure-eight three-body choreography.
   - Three equal bodies following the same path.

2. Lagrange Triangle
   - Three bodies forming a rotating equilateral triangle.
   - Should appear stable and symmetric.

3. Binary Star With Planet
   - Two heavier bodies orbiting each other.
   - A smaller third body orbiting around or near the binary system.

4. Chaotic Encounter
   - Three bodies starting close enough to create an unstable chaotic interaction.
   - Should visibly demonstrate sensitive motion without immediately exploding numerically.

Preset behavior:
- Each preset must have fixed initial positions, velocities, and masses.
- Reset should restore the selected preset exactly.
- Switching presets should immediately reset the simulation to that preset.
- Presets should be tuned so they look good visually and remain usable for a reasonable amount of time.

Controls:
Add controls for:
- Play / pause.
- Reset.
- Speed control.
- Zoom in / zoom out.
- Pan the view.
- Toggle trails on/off.
- Clear trails.
- Trail length control.
- Body size scaling.
- Show/hide labels.
- Optional: follow center of mass.
- Optional: show basic simulation stats.

Physics expectations:
- Use a stable numerical integration approach suitable for orbital simulation.
- Avoid obvious numerical explosions.
- Keep motion smooth and believable.
- Handle close encounters gracefully.
- Use sensible default scaling so all presets look good when loaded.
- The simulation should not depend on the screen size for physics correctness.

UI expectations:
- Modern dark UI.
- Clear preset selector.
- Simple control panel.
- Canvas/viewport should take most of the screen.
- Controls should be usable on mobile.
- Each body should have a distinct color.
- Trails should fade or be visually elegant.
- Use clean spacing, readable labels, and no clutter.

Implementation expectations:
- Create the full Vite project structure.
- Include all necessary source files.
- Keep code modular:
  - physics logic separated from rendering.
  - presets separated from simulation engine.
  - UI controls separated from core simulation state.
- Include comments only where useful.
- Make it easy to add new presets later.
- Make sure the app runs with:
  npm install
  npm run dev

Deliverables:
- Provide the complete code for the app.
- Explain briefly how to run it.
- Mention any important design choices.
- Do not leave TODO placeholders for core features.

Anthropic

Google

OpenAI

Zhipu