-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdynamic_hydrosphere_algorithm.js
More file actions
37 lines (32 loc) · 1.4 KB
/
dynamic_hydrosphere_algorithm.js
File metadata and controls
37 lines (32 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Dynamic Hydrosphere Rendering Algorithm
// Calculates sea level from water volume and elevation map
// Enables realistic Mars terraforming with rising water levels
function renderDynamicHydrosphere(terrainMap) {
const elevations = terrainMap.elevation;
const waterVolume = terrainMap.water_volume;
const seaLevel = calculateSeaLevel(elevations, waterVolume);
for (let y = 0; y < height; y++) {
for (let x = 0; x < width; x++) {
const elevation = elevations[y][x];
const isUnderwater = elevation < seaLevel;
if (isUnderwater) {
// Water tile - depth based on elevation difference
const depth = seaLevel - elevation;
renderWaterTile(x, y, depth);
} else {
// Land tile - render terrain
renderTerrainTile(x, y, elevation);
// Add biosphere if land is well above water
if (terrainMap.biosphere && elevation > seaLevel + 0.05) {
renderBiosphereTile(x, y, terrainMap.biosphere);
}
}
}
}
}
function calculateSeaLevel(elevations, waterVolume) {
const sortedElevations = elevations.flat().sort((a,b) => a-b);
const totalTiles = sortedElevations.length;
const waterTiles = Math.round(waterVolume * totalTiles);
return sortedElevations[Math.max(0, waterTiles - 1)] || 0;
}