Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
29b558e04a | ||
|
|
2868009227 | ||
|
|
7569a43e7e |
@@ -4,7 +4,7 @@ Eventually, it's supposed to be a survival/crafting game with space travel. Henc
|
|||||||
Using the heightmap generator from here: https://github.com/TangentFoxy/heightmap
|
Using the heightmap generator from here: https://github.com/TangentFoxy/heightmap
|
||||||
|
|
||||||
## Tasks
|
## Tasks
|
||||||
- [ ] Make a GitHub mirror for this repo.
|
- [x] Make a GitHub mirror for this repo.
|
||||||
- [ ] Remove heightmap library
|
- [ ] Remove heightmap library
|
||||||
- [ ] Update ReadMe
|
- [ ] Update ReadMe
|
||||||
- [ ] ReadMe should also point out where the simplex implementation comes from
|
- [ ] ReadMe should also point out where the simplex implementation comes from
|
||||||
|
|||||||
@@ -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,
|
||||||
|
}
|
||||||
@@ -27,6 +27,11 @@ simplex_map.max = function(map)
|
|||||||
return r
|
return r
|
||||||
end
|
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)
|
simplex_map.normalize = function(map, new_min, new_max)
|
||||||
local minimum = simplex_map.min(map)
|
local minimum = simplex_map.min(map)
|
||||||
local initialRange = simplex_map.max(map) - minimum
|
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
|
map[i][j] = (map[i][j] - minimum) / initialRange * finalRange + new_min
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
map.min = simplex_map.min(map)
|
simplex_map.recalculate_range(map)
|
||||||
map.max = simplex_map.max(map)
|
|
||||||
return map -- superfluous
|
return map -- superfluous
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
+7
-7
@@ -1,6 +1,6 @@
|
|||||||
math.randomseed(os.time())
|
math.randomseed(os.time())
|
||||||
|
|
||||||
local map_generator = require "map_nextgen"
|
local map_generator = require "final_map"
|
||||||
local lovebird = require "lib.lovebird"
|
local lovebird = require "lib.lovebird"
|
||||||
local lume = require "lib.lume"
|
local lume = require "lib.lume"
|
||||||
local running_average = require "lib.running_average"
|
local running_average = require "lib.running_average"
|
||||||
@@ -10,8 +10,6 @@ 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("Min Temperature", map.temperature.min, "Average", running_average.track("minT", map.temperature.min))
|
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))
|
print("Max Temperature", map.temperature.max, "Average", running_average.track("maxT", map.temperature.max))
|
||||||
|
|
||||||
@@ -74,11 +72,11 @@ love.draw = function()
|
|||||||
|
|
||||||
for x = 1, map.size do
|
for x = 1, map.size do
|
||||||
for y = 1, map.size do
|
for y = 1, map.size do
|
||||||
-- local value = map.biome[x][y]
|
local value = map.biome[x][y]
|
||||||
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 + map.temperature.max) / (map.temperature.max + math.abs(map.temperature.min)) , 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
|
||||||
@@ -90,6 +88,8 @@ love.keypressed = function(key)
|
|||||||
love.event.quit()
|
love.event.quit()
|
||||||
elseif key == "r" then
|
elseif key == "r" then
|
||||||
love.load()
|
love.load()
|
||||||
|
elseif key == "t" then
|
||||||
|
print(running_average.count("minT"))
|
||||||
elseif key == "=" then
|
elseif key == "=" then
|
||||||
map.tile_size = map.tile_size * 2
|
map.tile_size = map.tile_size * 2
|
||||||
elseif key == "-" then
|
elseif key == "-" then
|
||||||
|
|||||||
+18
-4
@@ -5,6 +5,13 @@ local simplex_map = require "lib.simplex_map"
|
|||||||
|
|
||||||
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
|
||||||
|
[800] = {
|
||||||
|
name = "sea ice",
|
||||||
|
altitude = {min = -math.huge, max = 0},
|
||||||
|
temperature = {min = -math.huge, max = -2},
|
||||||
|
rainfall = {min = -math.huge, max = math.huge},
|
||||||
|
color = {0.6, 0.6, 1, 1},
|
||||||
|
},
|
||||||
[900] = {
|
[900] = {
|
||||||
name = "deep ocean",
|
name = "deep ocean",
|
||||||
altitude = {min = -math.huge, max = -5000},
|
altitude = {min = -math.huge, max = -5000},
|
||||||
@@ -19,6 +26,13 @@ local biomes = {
|
|||||||
rainfall = {min = -math.huge, max = math.huge},
|
rainfall = {min = -math.huge, max = math.huge},
|
||||||
color = {0, 0, 0.5, 1},
|
color = {0, 0, 0.5, 1},
|
||||||
},
|
},
|
||||||
|
[1500] = {
|
||||||
|
name = "frozen (definition, 0 C)",
|
||||||
|
altitude = {min = -math.huge, max = math.huge},
|
||||||
|
temperature = {min = -math.huge, max = 0},
|
||||||
|
rainfall = {min = -math.huge, max = math.huge},
|
||||||
|
color = {1, 1, 1, 1},
|
||||||
|
},
|
||||||
[2000] = {
|
[2000] = {
|
||||||
name = "snowline (middle estimate)",
|
name = "snowline (middle estimate)",
|
||||||
altitude = {min = 4000, max = math.huge},
|
altitude = {min = 4000, max = math.huge},
|
||||||
@@ -59,8 +73,8 @@ local generate = function()
|
|||||||
}
|
}
|
||||||
map.temperature = simplex_map.generate{ -- in celsius
|
map.temperature = simplex_map.generate{ -- in celsius
|
||||||
-- -20 to 45 chosen by looking at the temperature range shown on https://openclimatemap.org/
|
-- -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
|
size = map.size, scale = 0.005, min = 20, max = 65, -- approximate target extremes of -89.2 to 56.7
|
||||||
octaves = 1, lacunarity = 2, gain = 0.5,
|
octaves = 2, lacunarity = 2, gain = 0.5,
|
||||||
}
|
}
|
||||||
map.rainfall = simplex_map.generate{ -- in millimeters of rainfall
|
map.rainfall = simplex_map.generate{ -- in millimeters of rainfall
|
||||||
size = map.size, scale = 0.005, -- min = 18, max = 3240,
|
size = map.size, scale = 0.005, -- min = 18, max = 3240,
|
||||||
@@ -103,8 +117,8 @@ local generate = function()
|
|||||||
temperature = temperature + altitude / 1000 -- -1 C / km (deep water adjustment)
|
temperature = temperature + altitude / 1000 -- -1 C / km (deep water adjustment)
|
||||||
end
|
end
|
||||||
-- modify temperature by latitude
|
-- modify temperature by latitude
|
||||||
local polar_distance = math.abs(y - (map.size / 2))^1.1 -- experimenting with slight non-linearity
|
local polar_distance = math.abs(y - (map.size / 2))^1.3 -- experimenting with slight non-linearity
|
||||||
local max_temperature_delta = 40
|
local max_temperature_delta = 10
|
||||||
temperature = temperature - (polar_distance / map.size * 2 * max_temperature_delta)
|
temperature = temperature - (polar_distance / map.size * 2 * max_temperature_delta)
|
||||||
-- 'save' temperature changes
|
-- 'save' temperature changes
|
||||||
map.temperature[x][y] = temperature
|
map.temperature[x][y] = temperature
|
||||||
|
|||||||
Reference in New Issue
Block a user