From 286800922776032895ab35268e895c924634bf2f Mon Sep 17 00:00:00 2001 From: Rose Liverman Date: Tue, 1 Sep 2026 23:41:30 -0600 Subject: [PATCH] redo with whatever numbers it spits out --- src/final_map.lua | 166 ++++++++++++++++++++++++++++++++++++++++ src/lib/simplex_map.lua | 8 +- src/main.lua | 4 +- 3 files changed, 173 insertions(+), 5 deletions(-) create mode 100644 src/final_map.lua diff --git a/src/final_map.lua b/src/final_map.lua new file mode 100644 index 0000000..7b94017 --- /dev/null +++ b/src/final_map.lua @@ -0,0 +1,166 @@ +local lume = require "lib.lume" +local simplex_map = require "lib.simplex_map" + +local biomes_list = { + -- checked in order, first candidate always selected + [800] = { + name = "sea ice", + altitude = {min = -math.huge, max = 0.1}, + temperature = {min = -math.huge, max = -1.8}, + rainfall = {min = -math.huge, max = math.huge}, + color = {0.6, 0.6, 1, 1}, + }, + [900] = { + name = "deep ocean", + altitude = {min = -math.huge, max = -0.09}, + temperature = {min = -math.huge, max = math.huge}, + rainfall = {min = -math.huge, max = math.huge}, + color = {0, 0, 0.25, 1}, + }, + [950] = { + name = "shallow ocean", + altitude = {min = 0.05, max = 0.1}, + temperature = {min = -math.huge, max = math.huge}, + rainfall = {min = -math.huge, max = math.huge}, + color = {0.1, 0.1, 0.6, 1}, + }, + -- [2050] = { -- this was too inappropriately placed every time + -- name = "fresh water lake", -- NOTE experimental + -- altitude = {min = 0.1, max = math.huge}, + -- temperature = {min = -math.huge, max = math.huge}, + -- rainfall = {min = 0.9, max = math.huge}, + -- color = {1, 0, 0, 1}, -- TEMP red to stand out, should be 0.1, 0.1, 1, 1 + -- }, + [1000] = { + name = "ocean", + altitude = {min = -math.huge, max = 0.1}, + temperature = {min = -math.huge, max = math.huge}, + rainfall = {min = -math.huge, max = math.huge}, + color = {0, 0, 0.5, 1}, + }, + [1010] = { + name = "sandy beach", + altitude = {min = 0.1, max = 0.12}, + temperature = {min = -1.4, max = math.huge}, + rainfall = {min = -0.5, max = math.huge}, + color = {1, 1, 0.33, 1}, + }, + [1500] = { + name = "frozen", -- NOTE probably temporary? (will be overwritten by higher priority subdivisions) + altitude = {min = -math.huge, max = math.huge}, + temperature = {min = -math.huge, max = -1.85}, + rainfall = {min = -math.huge, max = math.huge}, + color = {1, 1, 1, 1}, + }, + [2000] = { + name = "snowline", + altitude = {min = 0.515, max = math.huge}, + temperature = {min = -math.huge, max = -1.85}, + rainfall = {min = -math.huge, max = math.huge}, + color = {1, 1, 1, 1}, + }, + [2100] = { + name = "alpine zone", + altitude = {min = 0.52, max = math.huge}, + temperature = {min = -math.huge, max = math.huge}, + rainfall = {min = -math.huge, max = math.huge}, + color = {0.8, 0.8, 0.8, 1}, + }, + [2200] = { + name = "subalpine zone", + altitude = {min = 0.48, max = math.huge}, + temperature = {min = -math.huge, max = math.huge}, + rainfall = {min = -math.huge, max = math.huge}, + color = {0.67, 0.67, 0.67, 1}, + }, + [2300] = { + name = "montane zone", + altitude = {min = 0.4, max = math.huge}, + temperature = {min = -math.huge, max = math.huge}, + rainfall = {min = -math.huge, max = math.huge}, + color = {0.67, 0.67, 0.5, 1}, + }, + [9999] = { + name = "template", + altitude = {min = -math.huge, max = math.huge}, + temperature = {min = -math.huge, max = math.huge}, + rainfall = {min = -math.huge, max = math.huge}, + color = {0, 0, 0, 1}, + }, +} + +local generate = function() + local map = {} + map.size = 500 + map.tile_size = 1 -- TODO should be in rendering, not map, the map doesn't care about tile_size + map.altitude = simplex_map.generate{ + size = map.size, scale = 0.004, -- min = 0, max = 1, -- TEMP min/max range set to representable values + octaves = 5, lacunarity = 2.01, gain = 0.51, + } + map.temperature = simplex_map.generate{ + size = map.size, scale = 0.005, -- min = 0, max = 1, -- TEMP range adjusted for easy representation + octaves = 3, lacunarity = 1.99, gain = 0.49, + } + map.rainfall = simplex_map.generate{ + size = map.size, scale = 0.006, -- min = 0, max = 1, -- TEMP easy representation range + octaves = 1, + } + + local biome_order = {} + for order in pairs(biomes_list) do + biome_order[#biome_order + 1] = order + end + table.sort(biome_order) + + local map_center, radius_squared = map.size / 2, (map.size / 2)^2 + map.biome = {} + for x = 1, map.size do + map.biome[x] = {} + for y = 1, map.size do + if lume.distance(x, y, map_center, map_center, 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 + temperature = temperature - 2 * altitude + + -- modify temperature based on latitude + local polar_distance = math.abs(y - map_center)^1.5 + local max_temperature_delta = 0.2 + temperature = temperature - (polar_distance / map.size * 2 * max_temperature_delta) + map.temperature[x][y] = temperature + + -- choose biome + for _, order in ipairs(biome_order) do + local biome = biomes_list[order] + if altitude >= biome.altitude.min and altitude <= biome.altitude.max then + if temperature >= biome.temperature.min and temperature <= biome.temperature.max then + if rainfall >= biome.rainfall.min and rainfall <= biome.rainfall.max then + map.biome[x][y] = biome.color + -- map.biome[x][y] = {rainfall, rainfall, rainfall, 1} -- TEMP what does the map actually look like? + break + end + end + end + end + else + -- clear non-planet area + -- NOTE this potentially leaves behind empty x tables + map.altitude[x][y] = nil + map.temperature[x][y] = nil + map.rainfall[x][y] = nil + end + end + end + + simplex_map.recalculate_range(map.altitude) + simplex_map.recalculate_range(map.temperature) + simplex_map.recalculate_range(map.rainfall) + + return map +end + +return { + generate = generate, +} diff --git a/src/lib/simplex_map.lua b/src/lib/simplex_map.lua index a197122..ffa3a86 100644 --- a/src/lib/simplex_map.lua +++ b/src/lib/simplex_map.lua @@ -27,6 +27,11 @@ simplex_map.max = function(map) return r end +simplex_map.recalculate_range = function(map) + map.min = simplex_map.min(map) + map.max = simplex_map.max(map) +end + simplex_map.normalize = function(map, new_min, new_max) local minimum = simplex_map.min(map) local initialRange = simplex_map.max(map) - minimum @@ -36,8 +41,7 @@ simplex_map.normalize = function(map, new_min, new_max) 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) + simplex_map.recalculate_range(map) return map -- superfluous end diff --git a/src/main.lua b/src/main.lua index 112a70c..02457bc 100644 --- a/src/main.lua +++ b/src/main.lua @@ -1,6 +1,6 @@ math.randomseed(os.time()) -local map_generator = require "map_nextgen" +local map_generator = require "final_map" local lovebird = require "lib.lovebird" local lume = require "lib.lume" local running_average = require "lib.running_average" @@ -10,8 +10,6 @@ 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("Min Temperature", map.temperature.min, "Average", running_average.track("minT", map.temperature.min)) print("Max Temperature", map.temperature.max, "Average", running_average.track("maxT", map.temperature.max))