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)); stars.push(new Star(new_name,pseudoRandom.range(1, 100000),position));
} }
for (star of stars) {
Object.assign(star, star.description());
}
return stars; return stars;
} }

107
planet.js
View file

@ -2,81 +2,72 @@ const PRNG = require('./prng');
const utils = require('./utils'); const utils = require('./utils');
function Planet(name, seed, orbitalRadius, insolation) { function Planet(name, seed, orbitalRadius, insolation) {
this.name = name; var pseudoRandom = new PRNG(this.seed);
this.seed = seed;
this.orbitalRadius = orbitalRadius * 10; this.name = name;
this.insolation = insolation; this.seed = seed;
return this; 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 = [ var planetTypes = [
{ {
classification: "rocky", classification: "rocky",
radius: [1000, 15000], radius: [1000, 15000],
density: [2, 8], density: [2, 8],
hydrographics: function(pnrg, insolation, radius, density) { hydrographics: function(pnrg, insolation, radius, density) {
var g = utils.gravity(radius, density), var g = utils.gravity(radius, density),
tempK = utils.blackbody(insolation, 0); tempK = utils.blackbody(insolation, 0);
return Math.clamp(pnrg.realRange(-50, 150 - Math.abs(tempK - 270)) * g - Math.abs(density - 5.5) * 10, 0, 100); return Math.clamp(pnrg.realRange(-50, 150 - Math.abs(tempK - 270)) * g - Math.abs(density - 5.5) * 10, 0, 100);
}, },
atmosphere: function(pnrg, insolation, radius, density, hydrographics) { atmosphere: function(pnrg, insolation, radius, density, hydrographics) {
var g = utils.gravity(radius, density); var g = utils.gravity(radius, density);
if (hydrographics > 0 && insolation > 0.25 && insolation < 2) { if (hydrographics > 0 && insolation > 0.25 && insolation < 2) {
return pnrg.pick(['Breathable', 'Filterable', 'Inert', 'Toxic', 'Corrosive', 'Trace'], [1, 2, 2, 1, 1, 1]); return pnrg.pick(['Breathable', 'Filterable', 'Inert', 'Toxic', 'Corrosive', 'Trace'], [1, 2, 2, 1, 1, 1]);
} else { } else {
return pnrg.pick(['Breathable', 'Filterable', 'Inert', 'Toxic', 'Corrosive', 'Trace'], [1, 2, 3, 4, 5, 5]); return pnrg.pick(['Breathable', 'Filterable', 'Inert', 'Toxic', 'Corrosive', 'Trace'], [1, 2, 3, 4, 5, 5]);
} }
}, },
HI: function(insolation, radius, density, hydrographics, atmosphere) { HI: function(insolation, radius, density, hydrographics, atmosphere) {
var g = utils.gravity(radius, density), var g = utils.gravity(radius, density),
tempK = utils.blackbody(insolation, 0); tempK = utils.blackbody(insolation, 0);
if (atmosphere === "Breathable" && hydrographics > 0 && g < 1.25 && tempK > 230 && tempK < 280) { if (atmosphere === "Breathable" && hydrographics > 0 && g < 1.25 && tempK > 230 && tempK < 280) {
return 1; return 1;
} else if ((atmosphere === "Breathable" || atmosphere === 'Filterable') && g < 2 && tempK > 200 && tempK < 310) { } else if ((atmosphere === "Breathable" || atmosphere === 'Filterable') && g < 2 && tempK > 200 && tempK < 310) {
return 2; return 2;
} else if (atmosphere === "Corrosive" || g > 2 || tempK > 400) { } else if (atmosphere === "Corrosive" || g > 2 || tempK > 400) {
return tempK > 1000 ? 5 : 4; return tempK > 1000 ? 5 : 4;
} else { } else {
return 3; return 3;
} }
} }
}, },
{ {
classification: "gas giant", classification: "gas giant",
radius: [15000, 120000], radius: [15000, 120000],
density: [0.6, 2.0], density: [0.6, 2.0],
hydrographics: utils.fixed_value(0), hydrographics: utils.fixed_value(0),
atmosphere: utils.fixed_value("Crushing"), atmosphere: utils.fixed_value("Crushing"),
HI: utils.fixed_value(4) HI: utils.fixed_value(4)
}, },
{ {
classification: "brown dwarf", classification: "brown dwarf",
radius: [120000, 250000], radius: [120000, 250000],
density: [0.6, 2.0], density: [0.6, 2.0],
hydrographics: utils.fixed_value(0), hydrographics: utils.fixed_value(0),
atmosphere: utils.fixed_value("Crushing"), atmosphere: utils.fixed_value("Crushing"),
HI: utils.fixed_value(5) HI: utils.fixed_value(5)
}]; }];

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.numberOfPlanets = pseudoRandom.range(stellarTemplate.planets[0], stellarTemplate.planets[1]);
this.planetSeed = pseudoRandom.range(0, 1000000); this.planetSeed = pseudoRandom.range(0, 1000000);
this.color = stellarTemplate.color; this.color = stellarTemplate.color;
this.planets = this.generatePlanets();
return this; return this;
} }
Star.prototype.planets = function() { Star.prototype.generatePlanets = function() {
var planets = [], var planets = [],
pseudoRandom = new PRNG(this.planetSeed), pseudoRandom = new PRNG(this.planetSeed),
radius_min = 0.4 * pseudoRandom.realRange(0.5, 2), radius_min = 0.4 * pseudoRandom.realRange(0.5, 2),
@ -38,17 +39,4 @@ Star.prototype.planets = function() {
return planets; 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; module.exports = Star;