Permalink
Browse files

live update mass

  • Loading branch information...
Jeremy Heminger Jeremy Heminger
Jeremy Heminger authored and Jeremy Heminger committed Nov 29, 2018
1 parent 7422c5b commit 5db35b2b5268c94e7cebf87f73e3d1d41365c43c
Showing with 37 additions and 5 deletions.
  1. +4 −1 js/eventhandles.js
  2. +11 −0 js/general.js
  3. +22 −4 js/gravity.js
@@ -17,11 +17,14 @@ document.getElementById("BOOLACCRETION").addEventListener('change', toggleAccret
document.getElementById("RENDERLINES").addEventListener('change', toggleDrawLines, false);
classEvent("accordion","click",toggleAccordion);
document.getElementById("SOLARMASS").addEventListener('keyup', toggleSolarMass, false);
document.getElementById("PLANETMASS").addEventListener('keyup', togglePlanetMass, false);
classEvent("accordion","click",toggleAccordion);
function classEvent(_class,_event,_function) {
let elems = document.getElementsByClassName(_class);
for(let i=0; i<elems.length; i++) {
@@ -33,6 +33,17 @@ function toggleAccretion() {
BOOLACCRETION = document.getElementById("BOOLACCRETION").checked;
Gravity.toggleAccretion(BOOLACCRETION);
}
function toggleSolarMass() {
SOLARMASS = parseInt(document.getElementById("SOLARMASS").value);
_objects[0].set('mass',SOLARMASS);
}
function togglePlanetMass() {
PLANETMASS = parseInt(document.getElementById("PLANETMASS").value);
for(let i=1; i<_objects.length; i++) {
_objects[i].set('mass',_objects[i].get().r + PLANETMASS);
}
}
/**
*
* @function distance
@@ -6,10 +6,15 @@ var Gravity = (function(){
var boolaccretion = false;
/**
* @param {Object}
* @param {Object}
* */
var calc = function(a,b) {
a = a.get();
b = b.get();
b.v = new Vector(b.x,b.y);
if(undefined === a.x) {
@@ -73,7 +78,10 @@ var Gravity = (function(){
a.y += a.speed.y;
}
//
/**
* @param {Array}
* @param {Function}
* */
var calcAll = function(objects,callback) {
for(let x = 0; x < objects.length; x++) {
if(objects[x].get().alive) {
@@ -94,7 +102,10 @@ var Gravity = (function(){
}
callback(haserror);
}
//
/**
* @param {Object}
* @param {Object}
* */
var checkCollision = function(a,b) {
let v = new Vector(0,0);
let d = distance(a.get().x,a.get().y,b.get().x,b.get().y);
@@ -117,11 +128,18 @@ var Gravity = (function(){
}
}
}
//
// ---- SETTERS
/**
* @param {Boolean}
* */
var toggleCollision = function(b) {
boolcollision = b;
}
//
/**
* @param {Boolean}
* */
var toggleAccretion = function(b) {
boolaccretion = b;
}

0 comments on commit 5db35b2

Please sign in to comment.