This is the source code for celestialsimulator.kagof.com, a 3D celestial orbit simulator for the browser, written using Three.js.
To run it locally, simply run:
npm i
npm run devand open localhost:4000 in your browser.
to build a production bundle, run:
npm run buildto run a production preview, run:
npm run previewand to clean up the files created, run:
npm run cleanThe simulation is created in a basic static HTML webpage. The simulation is written in Three.js. Textures & normal maps were taken from NASA's Scientific Visualization Studio. Colors for the webpage are based on the Catppuccin Mocha palette. Vite is used for bundling & as a local dev server.
The simulator calculations changes in acceleration using the general equation for Newtonian gravity:
-
$m_k$ is the mass of body$k$ -
$\mathbf{q}_k$ is the position of body$k$ -
$G$ is the gravitational constant -
$\lVert\mathbf{q}_l-\mathbf{q}_k\rVert$ is the magnitude of the Euclidean distance between bodies$k$ and$l$
The simulator currently features:
- Newtonian gravity between n objects
- Live adjustable gravitational constant G
- Lighting with shadows & normals
- Adjustable body size, density, rotation, shininess, initial velocity & position (though not exposed to the end user yet)
I intend to add:
- elastic collisions between bodies
- fading trails behind bodies
- camera controls/following
- customizable number of bodies
- customization of bodies' starting properties (size, color, density, rotation, initial velocity & position)
- randomizer
- import/export setup to/from JSON
