a more reasonable temperature range to START from
This commit is contained in:
+4
-1
@@ -3,11 +3,14 @@ math.randomseed(os.time())
|
|||||||
local map_generator = require "map_nextgen"
|
local map_generator = require "map_nextgen"
|
||||||
local lovebird = require "lib.lovebird"
|
local lovebird = require "lib.lovebird"
|
||||||
local lume = require "lib.lume"
|
local lume = require "lib.lume"
|
||||||
|
local simplex_map = require "lib.simplex_map"
|
||||||
|
|
||||||
local map
|
local map
|
||||||
|
|
||||||
love.load = function()
|
love.load = function()
|
||||||
map = map_generator.generate()
|
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)
|
print("Temperature Range", map.temperature.min, map.temperature.max)
|
||||||
|
|
||||||
-- if true then return end
|
-- if true then return end
|
||||||
@@ -73,7 +76,7 @@ love.draw = function()
|
|||||||
local value = map.temperature[x][y]
|
local value = map.temperature[x][y]
|
||||||
if value then
|
if value then
|
||||||
-- love.graphics.setColor(value)
|
-- 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)
|
love.graphics.rectangle("fill", x * map.tile_size, y * map.tile_size, map.tile_size, map.tile_size)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
+16
-73
@@ -1,75 +1,7 @@
|
|||||||
-- NOTE the API of this file should probably change?
|
-- NOTE the API of this file should probably change?
|
||||||
|
|
||||||
local lume = require "lib.lume"
|
local lume = require "lib.lume"
|
||||||
local simplex = require "lib.simplex"
|
local simplex_map = require "lib.simplex_map"
|
||||||
|
|
||||||
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 biomes = {
|
local biomes = {
|
||||||
-- biomes are checked in order, with the first candidate always being selected
|
-- 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,
|
octaves = 7, lacunarity = 2, gain = 0.5,
|
||||||
}
|
}
|
||||||
map.temperature = simplex_map.generate{ -- in celsius
|
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,
|
octaves = 1, lacunarity = 2, gain = 0.5,
|
||||||
}
|
}
|
||||||
map.rainfall = simplex_map.generate{ -- in millimeters of rainfall
|
map.rainfall = simplex_map.generate{ -- in millimeters of rainfall
|
||||||
@@ -159,13 +92,23 @@ local generate = function()
|
|||||||
map.biome[x] = {}
|
map.biome[x] = {}
|
||||||
for y = 1, map.size do
|
for y = 1, map.size do
|
||||||
if lume.distance(x, y, map.size / 2, map.size / 2, true) < radius_squared then
|
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
|
for _, order in ipairs(biome_order) do
|
||||||
local biome = biomes[order]
|
local biome = biomes[order]
|
||||||
local altitude = map.altitude[x][y]
|
|
||||||
if altitude >= biome.altitude.min and altitude <= biome.altitude.max then
|
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
|
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
|
if rainfall >= biome.rainfall.min and rainfall <= biome.rainfall.max then
|
||||||
map.biome[x][y] = biome.color
|
map.biome[x][y] = biome.color
|
||||||
break
|
break
|
||||||
|
|||||||
Reference in New Issue
Block a user