Reworked the planet and star classes for better datasets

This commit is contained in:
Bram van der Veen 2016-06-28 23:01:39 +02:00
parent 8b9517d991
commit f809518bb6
3 changed files with 51 additions and 76 deletions

View file

@ -46,10 +46,6 @@ function generate(seed, amount) {
stars.push(new Star(new_name,pseudoRandom.range(1, 100000),position));
}
for (star of stars) {
Object.assign(star, star.description());
}
return stars;
}

View file

@ -2,34 +2,25 @@ const PRNG = require('./prng');
const utils = require('./utils');
function Planet(name, seed, orbitalRadius, insolation) {
var pseudoRandom = new PRNG(this.seed);
this.name = name;
this.seed = seed;
this.orbitalRadius = orbitalRadius * 10;
this.insolation = insolation;
this.blackbodyK = utils.blackbody(this.insolation);
this.template = pseudoRandom.pick(planetTypes, [this.insolation * 100, 10, 1]);
this.classification = this.template.classification;
this.radius = pseudoRandom.range(this.template.radius[0], this.template.radius[1]) / 2200;
this.density = pseudoRandom.realRange(this.template.density[0], this.template.density[1]);
this.gravity = utils.gravity(this.radius, this.density);
this.hydrographics = this.template.hydrographics(pseudoRandom, this.insolation, this.radius, this.density);
this.atmosphere = this.template.atmosphere(pseudoRandom, this.insolation, this.radius, this.density, this.hydrographics);
this.HI = this.template.HI(this.insolation, this.radius, this.density, this.hydrographics, this.atmosphere);
return this;
}
Planet.prototype.detail = function() {
var pseudoRandom = new PRNG(this.seed), detail = {}, template;
detail.name = this.name;
detail.orbitalRadius = this.orbitalRadius;
detail.insolation = this.insolation;
detail.blackbodyK = utils.blackbody(detail.insolation);
template = pseudoRandom.pick(planetTypes, [detail.insolation * 100, 10, 1]);
detail.classification = template.classification;
detail.radius = pseudoRandom.range(template.radius[0], template.radius[1]) / 2200;
detail.density = pseudoRandom.realRange(template.density[0], template.density[1]);
detail.gravity = utils.gravity(detail.radius, detail.density);
detail.hydrographics = template.hydrographics(pseudoRandom, detail.insolation, detail.radius, detail.density);
detail.atmosphere = template.atmosphere(pseudoRandom, detail.insolation, detail.radius, detail.density, detail.hydrographics);
detail.HI = template.HI(detail.insolation, detail.radius, detail.density, detail.hydrographics, detail.atmosphere);
return detail;
};
Planet.prototype.description = function() {
return this.detail();
};
var planetTypes = [
{
classification: "rocky",

16
star.js
View file

@ -18,11 +18,12 @@ function Star(name, seed, position) {
this.numberOfPlanets = pseudoRandom.range(stellarTemplate.planets[0], stellarTemplate.planets[1]);
this.planetSeed = pseudoRandom.range(0, 1000000);
this.color = stellarTemplate.color;
this.planets = this.generatePlanets();
return this;
}
Star.prototype.planets = function() {
Star.prototype.generatePlanets = function() {
var planets = [],
pseudoRandom = new PRNG(this.planetSeed),
radius_min = 0.4 * pseudoRandom.realRange(0.5, 2),
@ -38,17 +39,4 @@ Star.prototype.planets = function() {
return planets;
}
Star.prototype.description = function() {
let planets = [];
for (planet of this.planets()) {
planet.description = planet.description();
planets.push(planet);
}
return {
"planets": planets
}
}
module.exports = Star;