a more reasonable temperature range to START from

This commit is contained in:
2026-08-19 17:17:37 -06:00
parent 44e67966f0
commit b3d8ca7f10
2 changed files with 20 additions and 74 deletions
+16 -73
View File
@@ -1,75 +1,7 @@
-- NOTE the API of this file should probably change?
local lume = require "lib.lume"
local simplex = require "lib.simplex"
local simplex_map = {}
simplex_map.min = function(map)
local r = map[1][1]
for i=1,#map do
for j=1,#map[1] do
if r > map[i][j] then r = map[i][j] end
end
end
return r
end
simplex_map.max = function(map)
local r = map[1][1]
for i=1,#map do
for j=1,#map[1] do
if r < map[i][j] then r = map[i][j] end
end
end
return r
end
simplex_map.normalize = function(map, new_min, new_max)
local minimum = simplex_map.min(map)
local initialRange = simplex_map.max(map) - minimum
local finalRange = new_max - new_min
for i = 1, #map do
for j = 1, #map[1] do
map[i][j] = (map[i][j] - minimum) / initialRange * finalRange + new_min
end
end
map.min = simplex_map.min(map)
map.max = simplex_map.max(map)
return map -- superfluous
end
simplex_map.generate = function(size, scale, min, max, octaves, lacunarity, gain)
if type(size) == "table" then
scale = size.scale
min = size.min
max = size.max
octaves = size.octaves
lacunarity = size.lacunarity
gain = size.gain
size = size.size
end
simplex.Seed(math.random())
local map = {}
map.size = size
scale = scale or 0.005
for x = 1, map.size do
map[x] = {}
for y = 1, map.size do
map[x][y] = simplex.FractalBrownianMotion2D(x * scale, y * scale, octaves, lacunarity, gain)
end
end
if min or max then
min = min or 0
max = max or 1
simplex_map.normalize(map, min, max)
end
return map
end
local simplex_map = require "lib.simplex_map"
local biomes = {
-- biomes are checked in order, with the first candidate always being selected
@@ -126,7 +58,8 @@ local generate = function()
octaves = 7, lacunarity = 2, gain = 0.5,
}
map.temperature = simplex_map.generate{ -- in celsius
size = map.size, scale = 0.005, min = -89.2, max = 56.7,
-- -20 to 45 chosen by looking at the temperature range shown on https://openclimatemap.org/
size = map.size, scale = 0.005, min = -20, max = 45, -- approximate target extremes of -89.2 to 56.7
octaves = 1, lacunarity = 2, gain = 0.5,
}
map.rainfall = simplex_map.generate{ -- in millimeters of rainfall
@@ -159,13 +92,23 @@ local generate = function()
map.biome[x] = {}
for y = 1, map.size do
if lume.distance(x, y, map.size / 2, map.size / 2, true) < radius_squared then
local altitude = map.altitude[x][y]
local temperature = map.temperature[x][y]
local rainfall = map.rainfall[x][y]
-- modify temperature based on altitude
if altitude > 0 then
temperature = temperature - 0.0065 * altitude -- -6.5 C / km
else
temperature = temperature + altitude / 1000 -- -1 C / km (deep water adjustment)
end
map.temperature[x][y] = temperature
-- choose biome
for _, order in ipairs(biome_order) do
local biome = biomes[order]
local altitude = map.altitude[x][y]
if altitude >= biome.altitude.min and altitude <= biome.altitude.max then
local temperature = map.temperature[x][y]
if temperature >= biome.temperature.min and temperature <= biome.temperature.max then
local rainfall = map.rainfall[x][y]
if rainfall >= biome.rainfall.min and rainfall <= biome.rainfall.max then
map.biome[x][y] = biome.color
break