From 290a6ee2c65e8c67d65455cb31b62e82ee2b50fc Mon Sep 17 00:00:00 2001 From: Bram van der Veen <96aa48@gmail.com> Date: Thu, 11 Aug 2016 13:35:36 +0200 Subject: [PATCH] Made several changes and added stations and more --- index.js | 5 +++-- map.js | 3 +++ planet.js | 62 +++++++++++++++++++++++++++++++++++++++++-------------- star.js | 26 ++++++++++++++++++++--- 4 files changed, 76 insertions(+), 20 deletions(-) create mode 100644 map.js diff --git a/index.js b/index.js index b8b85ca..eddea0c 100644 --- a/index.js +++ b/index.js @@ -11,6 +11,7 @@ var planets = []; function generate(seed, amount) { if (!amount) amount = 1000; 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 = { badwords: 0, duplicates: 0 @@ -37,8 +38,8 @@ function generate(seed, amount) { // assign to a spiral arm theta += pseudoRandom.range(0, spiral_arms - 1) * Math.PI * 2 / spiral_arms; position = { - x: Math.cos(theta) * r * 100, - y: Math.sin(theta) * r * 100, + x: (Math.cos(theta) * r) * 100, + y: (Math.sin(theta) * r) * 100, z: pseudoRandom.gaussrandom(thickness * 0.5) * 100 }; stars.push(new Star(new_name,pseudoRandom.range(1, 100000),position)); diff --git a/map.js b/map.js new file mode 100644 index 0000000..8c4ff08 --- /dev/null +++ b/map.js @@ -0,0 +1,3 @@ +const PRNG = require('./prng'); + +var seed = 411234; diff --git a/planet.js b/planet.js index 0ee05d4..f5d2249 100644 --- a/planet.js +++ b/planet.js @@ -1,43 +1,75 @@ const PRNG = require('./prng'); const utils = require('./utils'); -function Planet(name, seed, orbitalRadius, insolation) { - var pseudoRandom = new PRNG(this.seed); +function Planet(name, seed, orbitalRadius, insolation, hasStation) { + var pseudoRandom = new PRNG(this.seed), + template = pseudoRandom.pick(planetTypes, [insolation * 100, 10, 1]); 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.temperature = this.blackbodyK - 273.15; + this.classification = template.classification; + this.radius = pseudoRandom.range(template.radius[0], template.radius[1]) / 2200; + this.density = pseudoRandom.realRange(template.density[0], 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); - if (this.HI == 2) this.habitable = true; + this.hydrographics = template.hydrographics(pseudoRandom, this.insolation, this.radius, this.density); + this.atmosphere = template.atmosphere(pseudoRandom, this.insolation, this.radius, this.density, this.hydrographics); + this.HI = template.HI(this.insolation, this.radius, this.density, this.hydrographics, this.atmosphere); + 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; } +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 = [ { classification: "rocky", radius: [1000, 15000], density: [2, 8], - hydrographics: function(pnrg, insolation, radius, density) { + hydrographics: function(prng, insolation, radius, density) { var g = utils.gravity(radius, density), 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); 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 { - 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) { diff --git a/star.js b/star.js index 2723b1c..d2c0f10 100644 --- a/star.js +++ b/star.js @@ -16,6 +16,7 @@ function Star(name, seed, position) { this.luminosity = stellarTemplate.luminosity * (4 / (spectralIndex + 2)) * 50; this.radius = Math.sqrt(this.luminosity); 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.color = stellarTemplate.color; this.planets = this.generatePlanets(); @@ -23,20 +24,39 @@ function Star(name, seed, position) { return this; } -Star.prototype.generatePlanets = function() { +Star.prototype.generatePlanets = function () { var planets = [], pseudoRandom = new PRNG(this.planetSeed), radius_min = 0.4 * pseudoRandom.realRange(0.5, 2), radius_max = 50 * pseudoRandom.realRange(0.5, 2), 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++) { 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; } +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;