Made several changes and added stations and more
This commit is contained in:
parent
cf369c166a
commit
290a6ee2c6
5
index.js
5
index.js
|
@ -11,6 +11,7 @@ var planets = [];
|
||||||
function generate(seed, amount) {
|
function generate(seed, amount) {
|
||||||
if (!amount) amount = 1000;
|
if (!amount) amount = 1000;
|
||||||
if (!seed) seed = 1234;
|
if (!seed) seed = 1234;
|
||||||
|
|
||||||
var spiral_arms = 2, spiral_angle_degrees = 360, min_radius = 0.05, max_radius = 0.9, thickness = 0.1, scatter_theta = Math.PI / spiral_arms * 0.2, scatter_radius = min_radius * 0.4, spiral_b = spiral_angle_degrees / Math.PI * min_radius / max_radius, start = (new Date()).getTime(), names = [], rejects = {
|
var spiral_arms = 2, spiral_angle_degrees = 360, min_radius = 0.05, max_radius = 0.9, thickness = 0.1, scatter_theta = Math.PI / spiral_arms * 0.2, scatter_radius = min_radius * 0.4, spiral_b = spiral_angle_degrees / Math.PI * min_radius / max_radius, start = (new Date()).getTime(), names = [], rejects = {
|
||||||
badwords: 0,
|
badwords: 0,
|
||||||
duplicates: 0
|
duplicates: 0
|
||||||
|
@ -37,8 +38,8 @@ function generate(seed, amount) {
|
||||||
// assign to a spiral arm
|
// assign to a spiral arm
|
||||||
theta += pseudoRandom.range(0, spiral_arms - 1) * Math.PI * 2 / spiral_arms;
|
theta += pseudoRandom.range(0, spiral_arms - 1) * Math.PI * 2 / spiral_arms;
|
||||||
position = {
|
position = {
|
||||||
x: Math.cos(theta) * r * 100,
|
x: (Math.cos(theta) * r) * 100,
|
||||||
y: Math.sin(theta) * r * 100,
|
y: (Math.sin(theta) * r) * 100,
|
||||||
z: pseudoRandom.gaussrandom(thickness * 0.5) * 100
|
z: pseudoRandom.gaussrandom(thickness * 0.5) * 100
|
||||||
};
|
};
|
||||||
stars.push(new Star(new_name,pseudoRandom.range(1, 100000),position));
|
stars.push(new Star(new_name,pseudoRandom.range(1, 100000),position));
|
||||||
|
|
62
planet.js
62
planet.js
|
@ -1,43 +1,75 @@
|
||||||
const PRNG = require('./prng');
|
const PRNG = require('./prng');
|
||||||
const utils = require('./utils');
|
const utils = require('./utils');
|
||||||
|
|
||||||
function Planet(name, seed, orbitalRadius, insolation) {
|
function Planet(name, seed, orbitalRadius, insolation, hasStation) {
|
||||||
var pseudoRandom = new PRNG(this.seed);
|
var pseudoRandom = new PRNG(this.seed),
|
||||||
|
template = pseudoRandom.pick(planetTypes, [insolation * 100, 10, 1]);
|
||||||
|
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.seed = seed;
|
this.seed = seed;
|
||||||
this.orbitalRadius = orbitalRadius * 10;
|
this.orbitalRadius = orbitalRadius * 10;
|
||||||
this.insolation = insolation;
|
this.insolation = insolation;
|
||||||
this.blackbodyK = utils.blackbody(this.insolation);
|
this.blackbodyK = utils.blackbody(this.insolation);
|
||||||
this.template = pseudoRandom.pick(planetTypes, [this.insolation * 100, 10, 1]);
|
this.temperature = this.blackbodyK - 273.15;
|
||||||
this.classification = this.template.classification;
|
this.classification = template.classification;
|
||||||
this.radius = pseudoRandom.range(this.template.radius[0], this.template.radius[1]) / 2200;
|
this.radius = pseudoRandom.range(template.radius[0], template.radius[1]) / 2200;
|
||||||
this.density = pseudoRandom.realRange(this.template.density[0], this.template.density[1]);
|
this.density = pseudoRandom.realRange(template.density[0], template.density[1]);
|
||||||
this.gravity = utils.gravity(this.radius, this.density);
|
this.gravity = utils.gravity(this.radius, this.density);
|
||||||
this.hydrographics = this.template.hydrographics(pseudoRandom, this.insolation, this.radius, this.density);
|
this.hydrographics = template.hydrographics(pseudoRandom, this.insolation, this.radius, this.density);
|
||||||
this.atmosphere = this.template.atmosphere(pseudoRandom, this.insolation, this.radius, this.density, this.hydrographics);
|
this.atmosphere = 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);
|
this.HI = template.HI(this.insolation, this.radius, this.density, this.hydrographics, this.atmosphere);
|
||||||
if (this.HI == 2) this.habitable = true;
|
this.habitable = this.HI == 2 && this.temperature > -60 && this.temperature < 60;
|
||||||
|
if (pseudoRandom.value() > .9) this.water = {
|
||||||
|
color: this.generateWaterColor(this.temperature, pseudoRandom)
|
||||||
|
}
|
||||||
|
|
||||||
|
this.color = this.generateColor(this.temperature, this.water, pseudoRandom);
|
||||||
|
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Planet.prototype.generateStation = function (prng) {
|
||||||
|
return {
|
||||||
|
size: prng.pick(['mini', 'small', 'medium', 'big'], [30, 40, 20, 10]),
|
||||||
|
economy: prng.pick(['mining', 'agricultural', 'military', 'tech', 'industrial', 'residential'], [15, 30, 10, 15, 10, 30])
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Planet.prototype.generateColor = function (temperature, water, prng) {
|
||||||
|
if (temperature < 0 && water) {
|
||||||
|
var color = Math.floor(prng.value() * 100) + 155;
|
||||||
|
return [color, color, color];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return [Math.floor(prng.value() * 100) + 125, Math.floor(prng.value() * 100) + 125, Math.floor(prng.value() * 100) + 125];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Planet.prototype.generateWaterColor = function (temperature, prng) {
|
||||||
|
if (temperature > 100) return false;
|
||||||
|
else {
|
||||||
|
return [Math.floor(prng.value() * 60) + 50, Math.floor(prng.value() * 60) + 50, Math.floor(prng.value() * 200) + 55]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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(prng, 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(prng.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(prng, 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 prng.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 prng.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) {
|
||||||
|
|
26
star.js
26
star.js
|
@ -16,6 +16,7 @@ function Star(name, seed, position) {
|
||||||
this.luminosity = stellarTemplate.luminosity * (4 / (spectralIndex + 2)) * 50;
|
this.luminosity = stellarTemplate.luminosity * (4 / (spectralIndex + 2)) * 50;
|
||||||
this.radius = Math.sqrt(this.luminosity);
|
this.radius = Math.sqrt(this.luminosity);
|
||||||
this.numberOfPlanets = pseudoRandom.range(stellarTemplate.planets[0], stellarTemplate.planets[1]);
|
this.numberOfPlanets = pseudoRandom.range(stellarTemplate.planets[0], stellarTemplate.planets[1]);
|
||||||
|
this.numberOfStations = pseudoRandom.range(0, this.numberOfPlanets / 8);
|
||||||
this.planetSeed = pseudoRandom.range(0, 1000000);
|
this.planetSeed = pseudoRandom.range(0, 1000000);
|
||||||
this.color = stellarTemplate.color;
|
this.color = stellarTemplate.color;
|
||||||
this.planets = this.generatePlanets();
|
this.planets = this.generatePlanets();
|
||||||
|
@ -23,20 +24,39 @@ function Star(name, seed, position) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Star.prototype.generatePlanets = 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),
|
||||||
radius_max = 50 * pseudoRandom.realRange(0.5, 2),
|
radius_max = 50 * pseudoRandom.realRange(0.5, 2),
|
||||||
total_weight = (Math.pow(this.numberOfPlanets, 2) + this.numberOfPlanets) * 0.5,
|
total_weight = (Math.pow(this.numberOfPlanets, 2) + this.numberOfPlanets) * 0.5,
|
||||||
r = radius_min;
|
r = radius_min
|
||||||
|
|
||||||
for (var i = 0; i < this.numberOfPlanets; i++) {
|
for (var i = 0; i < this.numberOfPlanets; i++) {
|
||||||
r += i / total_weight * pseudoRandom.realRange(0.5, 1) * (radius_max - radius_min);
|
r += i / total_weight * pseudoRandom.realRange(0.5, 1) * (radius_max - radius_min);
|
||||||
planets.push(new Planet(utils.kappatalize(this.name) + "-" + utils.romanNumeral(i + 1), pseudoRandom.range(0, 100000), r, this.luminosity / Math.pow(r, 2)));
|
planets.push(new Planet(utils.kappatalize(this.name) + "-" + utils.romanNumeral(i + 1), pseudoRandom.range(0, 1000000), r, this.luminosity / Math.pow(r, 2)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.divideStations(planets);
|
||||||
|
|
||||||
return planets;
|
return planets;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Star.prototype.divideStations = function (planets) {
|
||||||
|
var stations = this.numberOfStations || 0;
|
||||||
|
var i = planets.length - 1;
|
||||||
|
var pseudoRandom = new PRNG(this.seed);
|
||||||
|
|
||||||
|
for (i = 0; i < stations; i++) {
|
||||||
|
var arr = []
|
||||||
|
for (planet of planets) {
|
||||||
|
arr.push(100 / planets.length);
|
||||||
|
}
|
||||||
|
var planet = pseudoRandom.pick(planets, arr);
|
||||||
|
planet.station = planet.generateStation(pseudoRandom);
|
||||||
|
planet.station.seed = planet.seed;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = Star;
|
module.exports = Star;
|
||||||
|
|
Reference in a new issue