https://github.com/kinetictactic/orbits
2D newtonian gravity sandbox.
https://github.com/kinetictactic/orbits
cpp gravity raylib sandbox simulation
Last synced: 5 months ago
JSON representation
2D newtonian gravity sandbox.
- Host: GitHub
- URL: https://github.com/kinetictactic/orbits
- Owner: KineticTactic
- License: mit
- Created: 2025-06-21T07:31:26.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2025-06-22T16:51:18.000Z (7 months ago)
- Last Synced: 2025-06-22T17:36:06.244Z (7 months ago)
- Topics: cpp, gravity, raylib, sandbox, simulation
- Language: C
- Homepage: https://kinetictactic.github.io/orbits/
- Size: 2.63 MB
- Stars: 4
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Orbits! - A Newtonian Gravity Sandbox
**Orbits!** is a 2D gravity simulation built in C++ using [raylib](https://www.raylib.com/). It simulates Newtonian gravitational interactions between multiple bodies and visualizes their motion and orbital paths in real time. It uses **Velocity Verlet** integration for stable, energy-preserving orbits.

# Controls
- **Left Click Drag** to add a body and set its velocity. **Scroll** to change the mass of the body.
- **Right Click Drag** to pan the view.
- **Scroll** to zoom in and out.
- **Space** to pause the simulation.
### Touch controls:
- Use buttons for selecting modes.
- In PAN mode, drag to pan the view and pinch to zoom.
- In ADD mode, tap to add a body and drag to set its velocity. Pinch to change the mass of the body.
# Building
Use CMake to build the project. Raylib is automatically downloaded and built as a dependency.
```bash
mkdir build
cmake -B build -S . # -G "MinGW Makefiles"
cmake --build build # or make or mingw32-make
```
orbits.exe will be created in the build directory.
### Building for WebAssembly
To build the project for WebAssembly, you need to use the Emscripten toolchain. First, make sure you have Emscripten installed and set up correctly. Then, you can create a build using the following commands:
```bash
mkdir buildweb
emcmake cmake -B buildweb -S .
cmake --build buildweb
emrun --no_browser --port 8080 buildweb/index.html # to run the server
```
This will generate a WebAssembly version of the project that can be run in a web browser.