xxxxxxxxxx
33
// Generates a color based off the input values.
let waterLevel = 1.2
function terrain(elevation, moisture, heat) {
let curColor;
if (elevation < moisture || elevation < waterLevel) { // is water
curColor = '#'+rgbToHex(80)+
rgbToHex(ceil(heat * 5) * 40)+
rgbToHex(255);
} else if (moisture - elevation > elevation * -0.35) { // is sand
curColor = '#'+rgbToHex(200)+
rgbToHex(ceil(moisture * 4) * 30 + 100)+
rgbToHex(100);
} else if (elevation > 0.6) { // is tall
curColor = '#'+rgbToHex((ceil(elevation * 4) * 30) + ceil( heat * 2) * 50) +
rgbToHex(100 + ceil(elevation * 4) * 30) +
rgbToHex((ceil(elevation * 4) * 25) + ceil( moisture * 2) * 60);
} else { // is land
curColor = '#'+rgbToHex(30 + ceil(heat * 2) * 50) +
rgbToHex(ceil(moisture * 4) * 40 + 90) +
rgbToHex(ceil(elevation * 8) * 10);
}
if(!curColor){
errorLogger.push('terrain, mapGen.js: Invalid Color, (e,m,h) = ( ' + elevation + ', ' + moisture + ', ' + heat + ' ) ' );
}
return curColor;
}
var rgbToHex = function (rgb) {
var hex = Number(rgb).toString(16);
if (hex.length < 2) {
hex = "0" + hex;
}
return hex;
};