30 lines
710 B
JavaScript
30 lines
710 B
JavaScript
export class MassObject {
|
|
index = undefined;
|
|
mass = 0;
|
|
density = 1;
|
|
position = {x: undefined, y: undefined};
|
|
velocity = {x: 0, y: 0};
|
|
color = {r: undefined, g: undefined, b: undefined};
|
|
created = undefined;
|
|
|
|
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);
|
|
}
|
|
}
|
|
|