Skip to content

brunopozzebon/gravity-simulator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Gravity Simulator

This project is a 3D browser application, that uses ThreeJS to create an awesome gravity simulator.

new

📁 Requirements

  1. Node
  2. Yarn or Npm

🚀 How to run it

# Clone this repository
git clone https://github.com/brunopozzebon/gravity-simulator.git

# Go into the repository
cd gravity-simulator

# If you are using Yarn
yarn install 

# Run locally, on localhost:3000
yarn run start

# If you are using npm, replace the yarn command to npm

⚙️ How to use it

The program begins with the file starter.js.

let renderer = new Renderer();

const planets = Generator.generateRandomPlanets(10,20);
const simulation = new Simulation(planets);

let animate = function () {
	requestAnimationFrame(animate);
	simulation.update();
	renderer.update(simulation.getScene())
};
animate();

To change the simulation, you can chose a different method of Generator.

Generator.generatePlanets(quantity, spread) 
#It'll create 'quantity' planets, with random position, radius and velocity, 
#The spread will affect the distance among these planets
Generator.generateDualPlanets() 
#It'll create an planet in the center, and another one orbiting it.
Generator.generateStableSystem() 
#It'll create an system, with one 'planet' in the center, two 'satellites' orbiting it, and an asteroid, orbiting the last 'moon'.

To a most flexible implementation, you can create your own array of objects, adding the final array to the Simulation constructor, as the following code

const planets = new Array();
planets.push(new Body(0,0,0,2,0,20,20))
planets.push(new Body(0,100,0,10,10,10,0))
//Each body will be a "planet" on the simulation
//Body(ini_pos_x, ini_pos_y, ini_pos_z, radious, ini_vel_x, ini_vel_y, ini_vel_z )
const simulation = new Simulation(planets);

Controls

Zoom - Scrolling wheel
Pan - Mouse, right button pressed
Rotate - Mouse, left button pressed

✌️ Acknowledgment

This project is based in a 2D version of Ivan Seidel, called BigBangJs, he created an awesome video explaining all the math concepts about the gravity theory on Youtube(I really recomment it). I was inspired for his work, so i need to thank him for publishing his code on Github. Below, the links for his video and his respository;
Ivan´s Youtube Video - BigBangJs Github Repository

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages