remove single pixel lakes

This commit is contained in:
Evan
2025-01-05 12:38:06 -08:00
parent ce60be9629
commit f7fda4fb48
3 changed files with 46 additions and 23 deletions
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+23
View File
@@ -60,6 +60,7 @@ export async function loadTerrainMap(): Promise<void> {
}
}
removeSmallLakes(terrain)
const shorelineWaters = processShore(terrain)
processDistToLand(shorelineWaters, terrain)
processOcean(terrain)
@@ -235,6 +236,28 @@ function processOcean(map: Terrain[][]) {
}
}
function removeSmallLakes(map: Terrain[][]) {
console.log(`removing lakes ${map.length}, ${map[0].length}`)
for (let x = 0; x < map.length; x++) {
for (let y = 0; y < map[0].length; y++) {
if (map[x][y].type != TerrainType.Water) {
continue
}
let allLand = true
for (const neighbor of neighbors(x, y, map)) {
if (neighbor.type != TerrainType.Land) {
allLand = false
}
}
if (allLand) {
map[x][y].type = TerrainType.Land
map[x][y].magnitude = 0
}
}
}
}
function logBinaryAsBits(data: Uint8Array, length: number = 8) {
const bits = Array.from(data.slice(0, length))
.map(b => b.toString(2).padStart(8, '0'))