more 'definitions' to experiment with - I think I need to start over with normalized values BEFORE expanding
This commit is contained in:
+137
-78
@@ -5,107 +5,166 @@ local lume = require "lib.lume"
|
|||||||
local map = {}
|
local map = {}
|
||||||
|
|
||||||
local biomes = {
|
local biomes = {
|
||||||
[5] = {
|
-- [5] = {
|
||||||
name = "ocean",
|
-- name = "ocean",
|
||||||
altitude = {min = 0, max = 0.2}, -- bottom of world is the only part that matters
|
-- altitude = {min = 0, max = 0.2}, -- bottom of world is the only part that matters
|
||||||
temperature = {min = 0, max = 1},
|
-- temperature = {min = 0, max = 1},
|
||||||
humidity = {min = 0, max = 1},
|
-- humidity = {min = 0, max = 1},
|
||||||
color = {0, 0, 0.67, 1},
|
-- color = {0, 0, 0.67, 1},
|
||||||
|
-- },
|
||||||
|
-- [6] = {
|
||||||
|
-- name = "beach",
|
||||||
|
-- altitude = {min = 0.2, max = 0.205}, -- just above ocean
|
||||||
|
-- temperature = {min = 0, max = 1},
|
||||||
|
-- humidity = {min = 0, max = 0.8}, -- excluding upper humidity for swamp
|
||||||
|
-- color = {1, 1, 0.33, 1}, -- brighter yellow to distinguish from sand
|
||||||
|
-- },
|
||||||
|
-- [8] = {
|
||||||
|
-- name = "swamp", -- fun idea, but generates between ocean and water too often?
|
||||||
|
-- altitude = {min = 0, max = 1},
|
||||||
|
-- temperature = {min = 0.5, max = 1},
|
||||||
|
-- humidity = {min = 0.95, max = 1},
|
||||||
|
-- color = {0, 0.5, 0.33, 1},
|
||||||
|
-- },
|
||||||
|
-- [10] = {
|
||||||
|
-- name = "water",
|
||||||
|
-- altitude = {min = 0, max = 0.9}, -- top excluded because it should've gone downhill
|
||||||
|
-- temperature = {min = 0.1, max = 0.9}, -- bottom should be ice, top should evaporate
|
||||||
|
-- humidity = {min = 0.8, max = 1}, -- only the wettest places
|
||||||
|
-- color = {0, 0, 1, 1},
|
||||||
|
-- },
|
||||||
|
-- [20] = {
|
||||||
|
-- name = "sand",
|
||||||
|
-- altitude = {min = 0.2, max = 0.9}, -- top falls down, bottom is underwater
|
||||||
|
-- temperature = {min = 0, max = 1},
|
||||||
|
-- humidity = {min = 0, max = 0.2}, -- only where dry makes more sense for a desert
|
||||||
|
-- color = {1, 1, 0, 1},
|
||||||
|
-- },
|
||||||
|
-- [30] = {
|
||||||
|
-- name = "grass",
|
||||||
|
-- altitude = {min = 0.3, max = 0.9}, -- top of the world not enough air, bottom too wet / leaving space for others
|
||||||
|
-- temperature = {min = 0.2, max = 0.8}, -- not very sensitive to temperature
|
||||||
|
-- humidity = {min = 0.2, max = 0.6}, -- not very sensitive to humidity; but excluded from the worst
|
||||||
|
-- color = {0, 1, 0, 1},
|
||||||
|
-- },
|
||||||
|
-- [40] = {
|
||||||
|
-- name = "trees",
|
||||||
|
-- altitude = {min = 0.4, max = 0.7}, -- more sensitive than grass
|
||||||
|
-- temperature = {min = 0, max = 0.7},
|
||||||
|
-- humidity = {min = 0.3, max = 0.8}, -- these are not desert trees, they need more water
|
||||||
|
-- color = {0, 0.67, 0, 1},
|
||||||
|
-- },
|
||||||
|
-- [60] = {
|
||||||
|
-- name = "stone",
|
||||||
|
-- altitude = {min = 0, max = 1},
|
||||||
|
-- temperature = {min = 0, max = 1},
|
||||||
|
-- humidity = {min = 0, max = 1},
|
||||||
|
-- color = {0.67, 0.67, 0.67, 1},
|
||||||
|
-- },
|
||||||
|
-- [50] = {
|
||||||
|
-- name = "ice",
|
||||||
|
-- altitude = {min = 0, max = 1},
|
||||||
|
-- temperature = {min = 0, max = 0.01},
|
||||||
|
-- humidity = {min = 0.2, max = 1},
|
||||||
|
-- color = {1, 1, 1, 1},
|
||||||
|
-- },
|
||||||
|
[900] = {
|
||||||
|
name = "deep ocean",
|
||||||
|
altitude = {min = -math.huge, max = -400},
|
||||||
|
temperature = {min = -math.huge, max = math.huge},
|
||||||
|
humidity = {min = -math.huge, max = math.huge},
|
||||||
|
color = {0, 0, 0.25, 1},
|
||||||
},
|
},
|
||||||
[6] = {
|
[1000] = {
|
||||||
name = "beach",
|
name = "ocean (definition, 0 meters)",
|
||||||
altitude = {min = 0.2, max = 0.205}, -- just above ocean
|
altitude = {min = -math.huge, max = 0},
|
||||||
temperature = {min = 0, max = 1},
|
temperature = {min = -math.huge, max = math.huge},
|
||||||
humidity = {min = 0, max = 0.8}, -- excluding upper humidity for swamp
|
humidity = {min = -math.huge, max = math.huge},
|
||||||
color = {1, 1, 0.33, 1}, -- brighter yellow to distinguish from sand
|
color = {0, 0, 0.5, 1},
|
||||||
},
|
},
|
||||||
[8] = {
|
[2000] = {
|
||||||
name = "swamp", -- fun idea, but generates between ocean and water too often?
|
name = "snowline (middle estimate)",
|
||||||
altitude = {min = 0, max = 1},
|
altitude = {min = 4000, max = math.huge},
|
||||||
temperature = {min = 0.5, max = 1},
|
temperature = {min = -math.huge, max = math.huge},
|
||||||
humidity = {min = 0.95, max = 1},
|
humidity = {min = -math.huge, max = math.huge},
|
||||||
color = {0, 0.5, 0.33, 1},
|
color = {1, 1, 1, 1},
|
||||||
},
|
},
|
||||||
[10] = {
|
[2100] = {
|
||||||
name = "water",
|
name = "alpine zone",
|
||||||
altitude = {min = 0, max = 0.9}, -- top excluded because it should've gone downhill
|
altitude = {min = 3500, max = math.huge},
|
||||||
temperature = {min = 0.1, max = 0.9}, -- bottom should be ice, top should evaporate
|
temperature = {min = -math.huge, max = math.huge},
|
||||||
humidity = {min = 0.8, max = 1}, -- only the wettest places
|
humidity = {min = -math.huge, max = math.huge},
|
||||||
color = {0, 0, 1, 1},
|
color = {0.8, 0.8, 0.8, 1},
|
||||||
},
|
},
|
||||||
[20] = {
|
[2200] = {
|
||||||
name = "sand",
|
name = "subalpine zone",
|
||||||
altitude = {min = 0.2, max = 0.9}, -- top falls down, bottom is underwater
|
altitude = {min = 3000, max = math.huge},
|
||||||
temperature = {min = 0, max = 1},
|
temperature = {min = -math.huge, max = math.huge},
|
||||||
humidity = {min = 0, max = 0.2}, -- only where dry makes more sense for a desert
|
humidity = {min = -math.huge, max = math.huge},
|
||||||
color = {1, 1, 0, 1},
|
|
||||||
},
|
|
||||||
[30] = {
|
|
||||||
name = "grass",
|
|
||||||
altitude = {min = 0.3, max = 0.9}, -- top of the world not enough air, bottom too wet / leaving space for others
|
|
||||||
temperature = {min = 0.2, max = 0.8}, -- not very sensitive to temperature
|
|
||||||
humidity = {min = 0.2, max = 0.6}, -- not very sensitive to humidity; but excluded from the worst
|
|
||||||
color = {0, 1, 0, 1},
|
|
||||||
},
|
|
||||||
[40] = {
|
|
||||||
name = "trees",
|
|
||||||
altitude = {min = 0.4, max = 0.7}, -- more sensitive than grass
|
|
||||||
temperature = {min = 0, max = 0.7},
|
|
||||||
humidity = {min = 0.3, max = 0.8}, -- these are not desert trees, they need more water
|
|
||||||
color = {0, 0.67, 0, 1},
|
|
||||||
},
|
|
||||||
[60] = {
|
|
||||||
name = "stone",
|
|
||||||
altitude = {min = 0, max = 1},
|
|
||||||
temperature = {min = 0, max = 1},
|
|
||||||
humidity = {min = 0, max = 1},
|
|
||||||
color = {0.67, 0.67, 0.67, 1},
|
color = {0.67, 0.67, 0.67, 1},
|
||||||
},
|
},
|
||||||
[50] = {
|
[2300] = {
|
||||||
name = "ice",
|
name = "montane zone",
|
||||||
altitude = {min = 0, max = 1},
|
altitude = {min = 2500, max = math.huge},
|
||||||
temperature = {min = 0, max = 0.01},
|
temperature = {min = -math.huge, max = math.huge},
|
||||||
humidity = {min = 0.2, max = 1},
|
humidity = {min = -math.huge, max = math.huge},
|
||||||
color = {1, 1, 1, 1},
|
color = {0.67, 0.67, 0.5, 1},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
love.load = function()
|
love.load = function()
|
||||||
map.size = 500
|
map.size = 500
|
||||||
map.tile_size = 1
|
map.tile_size = 1
|
||||||
map.altitude = heightmap.create(map.size, map.size, 0, 1)
|
map.altitude = heightmap.create(map.size, map.size, -440, 8849) -- meters
|
||||||
map.temperature = heightmap.create(map.size, map.size, 0, 1)
|
map.temperature = heightmap.create(map.size, map.size, -89.2, 56.7) -- celsius
|
||||||
map.humidity = heightmap.create(map.size, map.size, 0, 1)
|
map.humidity = heightmap.create(map.size, map.size, 18, 3240) -- millimeters rainfall
|
||||||
|
|
||||||
|
local function altitude_ocean_bias(altitude)
|
||||||
|
local bias = 3.5 -- higher -> more ocean
|
||||||
|
local normalized_altitude = (altitude - -400) / (8849 - -440)
|
||||||
|
return -440 + normalized_altitude^bias * (8849 - -440)
|
||||||
|
end
|
||||||
|
local min, max = math.huge, -math.huge
|
||||||
|
for x = 0, map.size do
|
||||||
|
for y = 0, map.size do
|
||||||
|
local value = altitude_ocean_bias(map.altitude[x][y])
|
||||||
|
if value > max then max = value end
|
||||||
|
if value < min then min = value end
|
||||||
|
map.altitude[x][y] = value
|
||||||
|
end
|
||||||
|
end
|
||||||
|
print("Altitude", "Min: ", min, "Max:", max)
|
||||||
|
|
||||||
-- if true then return end
|
-- if true then return end
|
||||||
|
|
||||||
-- lower temperature by half height
|
-- lower temperature by half height
|
||||||
-- NOTE ruins "normalization" but that's fine once we have "real" numbers to work with
|
-- NOTE ruins "normalization" but that's fine once we have "real" numbers to work with
|
||||||
for x = 0, map.temperature.w do
|
-- for x = 0, map.temperature.w do
|
||||||
for y = 0, map.temperature.h do
|
-- for y = 0, map.temperature.h do
|
||||||
map.temperature[x][y] = math.max(0, map.temperature[x][y] - map.altitude[x][y] / 2)
|
-- map.temperature[x][y] = math.max(0, map.temperature[x][y] - map.altitude[x][y] / 2)
|
||||||
end
|
-- end
|
||||||
end
|
-- end
|
||||||
heightmap.normalize(map.temperature, 0, 1)
|
-- heightmap.normalize(map.temperature, -89.2, 56.7)
|
||||||
|
|
||||||
-- modify temperature by latitude
|
-- modify temperature by latitude
|
||||||
-- TODO would be more efficient to calculate Y in outer loop, since X does not change the distance
|
-- TODO would be more efficient to calculate Y in outer loop, since X does not change the distance
|
||||||
-- NOTE only subtracts temperature, which further "ruins normalization" and makes everything too cold:
|
-- NOTE only subtracts temperature, which further "ruins normalization" and makes everything too cold:
|
||||||
local center_y = map.size / 2
|
-- local center_y = map.size / 2
|
||||||
for x = 0, map.temperature.w do
|
-- for x = 0, map.temperature.w do
|
||||||
for y = 0, map.temperature.h do
|
-- for y = 0, map.temperature.h do
|
||||||
local distance = math.abs(y - center_y)
|
-- local distance = math.abs(y - center_y)
|
||||||
map.temperature[x][y] = lume.clamp(map.temperature[x][y] - distance / map.size, 0, 1)
|
-- map.temperature[x][y] = lume.clamp(map.temperature[x][y] - distance / map.size, 0, 1)
|
||||||
end
|
-- end
|
||||||
end
|
-- end
|
||||||
heightmap.normalize(map.temperature, 0, 1)
|
-- heightmap.normalize(map.temperature, -89.2, 56.7)
|
||||||
|
|
||||||
-- increase humidity by half temperature
|
-- increase humidity by half temperature
|
||||||
for x = 0, map.humidity.w do
|
-- for x = 0, map.humidity.w do
|
||||||
for y = 0, map.humidity.h do
|
-- for y = 0, map.humidity.h do
|
||||||
map.humidity[x][y] = math.min(1, map.humidity[x][y] + map.temperature[x][y] / 2)
|
-- map.humidity[x][y] = math.min(1, map.humidity[x][y] + map.temperature[x][y] / 2)
|
||||||
end
|
-- end
|
||||||
end
|
-- end
|
||||||
|
-- heightmap.normalize(map.humidity, 18, 3240)
|
||||||
|
|
||||||
-- planetizer!
|
-- planetizer!
|
||||||
local biome_order = {}
|
local biome_order = {}
|
||||||
|
|||||||
Reference in New Issue
Block a user