From b3d8ca7f10ac8122043ef27dd71a90d6cce73874 Mon Sep 17 00:00:00 2001 From: Tangent Date: Wed, 19 Aug 2026 17:17:37 -0600 Subject: [PATCH] a more reasonable temperature range to START from --- src/main.lua | 5 ++- src/map_nextgen.lua | 89 ++++++++------------------------------------- 2 files changed, 20 insertions(+), 74 deletions(-) diff --git a/src/main.lua b/src/main.lua index 86f9c45..08f84fa 100644 --- a/src/main.lua +++ b/src/main.lua @@ -3,11 +3,14 @@ math.randomseed(os.time()) local map_generator = require "map_nextgen" local lovebird = require "lib.lovebird" local lume = require "lib.lume" +local simplex_map = require "lib.simplex_map" local map love.load = function() map = map_generator.generate() + map.temperature.min = simplex_map.min(map.temperature) + map.temperature.max = simplex_map.max(map.temperature) print("Temperature Range", map.temperature.min, map.temperature.max) -- if true then return end @@ -73,7 +76,7 @@ love.draw = function() local value = map.temperature[x][y] if value then -- love.graphics.setColor(value) - love.graphics.setColor( (value + 89.2) / (89.2 + 56.7) , 0, 0, 1) + love.graphics.setColor( (value + map.temperature.max) / (map.temperature.max + math.abs(map.temperature.min)) , 0, 0, 1) love.graphics.rectangle("fill", x * map.tile_size, y * map.tile_size, map.tile_size, map.tile_size) end end diff --git a/src/map_nextgen.lua b/src/map_nextgen.lua index 1a781f3..cbb2909 100644 --- a/src/map_nextgen.lua +++ b/src/map_nextgen.lua @@ -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