Skip to content

A very simple, basic simulation of gravity between different points, inspired by particles.js

License

Notifications You must be signed in to change notification settings

AxelGoetz/gravity-simulation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

2D Gravity Simulator

A very simple, basic simulation of gravity between different points, inspired by particles.js. Essentially, it calculates the gravitational force between all nodes and changes the velocity accordingly.

For a demo, click here.

Usage

First, you will need to define a canvas element with an ID and set its background to something else than white. Next, the function startSimulation is responsible for starting the simulation. It has various different options:

  • id - The id of your canvas element.
  • size - How big the canvas should be.
  • amountOfObjects - How many objects will be rendered initially. I recommend to not have more than 100.
  • g - The gravitational constant. The higher it is, the more attracted the objects will be to each other.
  • slowDown - If g is too high, the velocity of some nodes might be really high. Hence, the animation can be slowed down with this factor.

Then to stop the simulation, call the stopSimulation function.

About

A very simple, basic simulation of gravity between different points, inspired by particles.js

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published