let types = ['ice', 'ice', 'ice', 'desert', 'desert', 'desert', 'dry tundra', 'moist tundra', 'wet tundra', 'rain tundra', 'desert', 'dry scrub', 'moist forest', 'wet forest', 'rain forest', 'desert', 'desert scrub', 'steppe', 'moist forest', 'wet forest', 'rain forest', 'desert', 'desert scrub', 'thorn steppe', 'dry forest', 'moist forest', 'wet forest', 'rain forest', 'desert', 'desert scrub', 'thorn woodland', 'very dry forest', 'dry forest', 'moist forest', 'wet forest', 'rain forest'];
let zones = ['super-arid', 'per-arid', 'arid', 'semi-arid', 'sub-humid', 'humid', 'per-humid', 'super-humid'];
let regions = ['polar', 'sub-polar', 'boreal', 'cool temperate', 'warm temperate', 'sub-tropical', 'tropical'];
let belts = ['alvar', 'alpine', 'subalpine', 'montane', 'lower montane', 'premontane'];
let highlight, nohighlight;
for (let i = 0; i < 14; i += 1) {
photos.push(loadImage('biome' + i + '.jpg'));
createCanvas(windowWidth, windowHeight);
dim = (height / sqrt(3) / 2) / 4;
textAlign(CENTER, CENTER);
highlight = color(134, 219, 255, 230);
nohighlight = color(255, 255, 255, 230);
evapc = color(0, 0, 0, 200);
precipc = color(0, 0, 0, 200);
for (let row = 0; row < 8; row++) {
for (let col = 0; col < 1 + row; col++) {
let y = (-5.5 * dim) + row * (height / 8);
let pos = createVector(x + shift, y);
let c = map((row + 1) * (col + 1), 0, 50, 0, 1);
biomes.push(new Biome(pos, r, c, n));
rect(0, height / 2 + dim / 2, width, dim);
let b = 2 * height / sqrt(3);
for (let l = 0; l <= 8; l++) {
line(x - xs, -height / 2 + ys, x - (b / 2), height / 2);
translate(x - xs, -height / 2 + ys);
text(precip, dim / 4, 0);
line(-(x - xs), -height / 2 + ys, -(x - (b / 2)), height / 2);
translate(-(x - xs), -height / 2 + ys);
textAlign(RIGHT, BOTTOM);
text(transpo.toFixed(3), -dim / 4, 0);
textAlign(CENTER, CENTER);
if (z < zones.length) text(zones[z], (l - 3.5) * b / 8, height / 2 + dim / 3);
line(-b / 2, height / 2, b / 2, height / 2);
text("Annual Precipitation (in mm)", 0, 0);
translate(-5.5 * dim, 0);
text("Potential Evapotranspiration Ratio", 0, 0);
translate(0, height / 2 + dim);
text("Humidity Provinces", 0, 0);
text('Latitude Zones', -boundary, -height / 8);
textAlign(RIGHT, BOTTOM);
text('Altitude Belts', boundary, -height / 8);
for (let i = 0; i < 7; i++) {
let y = -height / 16 + height / 8 * i;
if (regions[i] == 'warm temperate') y -= height / 16;
if (regions[i] == 'sub-tropical') y -= height / 8;
if (regions[i] == 'tropical') y -= 3 * height / 16;
line(-boundary, y, boundary, y);
if (i < regions.length) text(regions[i], -boundary, y);
textAlign(RIGHT, BOTTOM);
if (i < regions.length - 1) text(belts[i], boundary, y);
translate(width / 2, height / 2);
image(photos[pindex], 0, 0);
if (b.contains(mouseX - width / 2, mouseY - height / 2)) b.tbulge = 1.2;
textAlign(CENTER, CENTER);
text('Life Zones', 0, -height / 2 - dim);
let eci = map(mouseX, width/3, 2*width/3, 0, 1);
evapc = lerpColor(highlight, nohighlight, eci);
precipc = lerpColor(highlight, nohighlight, 1-eci);
if (keyCode == UP_ARROW) tsc += 0.1;
if (keyCode == DOWN_ARROW && tsc > 0.3) tsc -= 0.1;
function mousePressed() {
if (b.contains(mouseX - width / 2, mouseY - height / 2)) {
if (b.n == 'ice') pindex = 0;
else if (b.n.includes('dry tundra')) pindex = 10;
else if (b.n.includes('scrub')) pindex = 3;
else if (b.n.includes('desert')) pindex = 1;
else if (b.n.includes('moist tundra')) pindex = 13;
else if (b.n.includes('wet tundra')) pindex = 12;
else if (b.n.includes('tundra')) pindex = 2;
else if (b.n.includes('scrub')) pindex = 4;
else if (b.n.includes('dry forest')) pindex = 8;
else if (b.n.includes('wet forest')) pindex = 11;
else if (b.n.includes('forest') && !b.n.includes('rain')) pindex = 5;
else if (b.n.includes('rain')) pindex = 6;
else if (b.n.includes('steppe')) pindex = 7;
else if (b.n.includes('woodland')) pindex = 9;