Simple 3d simulation of Newton's law of universal gravitation with sample Three.js project.
## Usage ##
Consists of two main classes: Univers and Body in app/
and a sample project with Three.js in app/sampleProject
.
require( ['gravitation/Univers'], function( Univers ){
var univers = new Univers() // see app/Univers.js#+options for different options
univers.buildBody({ // see app/Univers.js#buildRandomBody as an example
position: [ 0, 0, 0],
velocity: [ 1, 2, 3 ],
rotation: [ 3, 4, 5 ]
})
univers.bodies // your bodies instances are here
var update = function( ){
univers.step()
requestAnimationFrame(update)
}
update()
})
or just read app/sampleProject/SampleGravitationProject.js
See cagosta.github.io/gravitation
## Install ##
gravitation is coded as AMD module but can be installed with npm, bower or old-fashioned src=".min.js".
bower install gravitation
Point gravitation
to [bower_components_path]/gravitation/app/gravitation.js
into your requirejs path config
and load it with requirejs:
require(['gravitation/gravitation'], function( gravitation ){
})
Inside the dist
folder, download latest standalone minified version or development version and include it in your html page:
<script src="[path_to_source]/gravitation-latest-standalone-min.js%>"></script>
The module is available via the scope
window.gravitation
## Documentation ##
See jsdoc-generated documentation in /documentation
app -> development files
|- bower_components -> [bower](https://github.com/bower/bower) front-end packages
|- main.js -> main file for browser and node.js, handle AMD config
|- gravitation -> main AMD module
test -> unit tests
|
tasks -> [Grunt](http://gruntjs.com/) tasks, see [generator-mangrove-module](https://github.com/cagosta/generator-mangrove-module)
|
dist -> distribution & build files
|
node_modules -> node packages
|
documentation -> [jsdoc](http://usejsdoc.org/about-jsdoc3.html) generated documentation
Run grunt test:browser
and open test/
on your browser.
#### On a headless browser ####
grunt test:headless
will run your tests in a headless browser, with phantomjs and mocha
grunt test:node
will run your tests with node and mocha.
Because of requirejs, the mocha
command does not work.
Beta: run your tests with saucelabs and sauce connect:
- add your saucelabs credentials into .credentials.json
{
"saucelabs": {
"username": "",
"key": ""
}
}
- configure the browser your want your tests to run on in
config.json
- and run your tests with:
grunt test:sauce
This project uses Node.js, Grunt and Require.js for the build process. If for some reason you need to build a custom version install Node.js, npm install
and run:
grunt build
## Yeoman Mangrove module Generator ##
This module is based on a Yeoman generator: Generator-mangrove-module
Check it for task-related references such as build, deploy etc ..