export class MassObject { index = undefined; mass = 0; density = 1; position = {x: undefined, y: undefined}; velocity = {x: 0, y: 0}; acceleration = {x: 0, y: 0}; color = {r: undefined, g: undefined, b: undefined}; created = undefined; forces = []; // [{x, y}] constructor(x, y, index) { this.index = index; this.position.x = x; this.position.y = y; this.color.r = Math.random() * 256; this.color.g = Math.random() * 256; this.color.b = Math.random() * 256; this.created = document.timeline.currentTime; } get age() { return document.timeline.currentTime - this.created; } get radius() { // radius should be proportional to cube root of mass return Math.pow(this.mass / this.density, 1/3); } getAcceleration() { let ax = 0; let ay = 0; for (let {x, y} of this.forces) { ax += x; ay += y; } return { x: ax / this.mass, y: ay / this.mass, }; } }