init little circle planet
This commit is contained in:
+138
@@ -0,0 +1,138 @@
|
||||
local heightmap = require "lib.heightmap"
|
||||
local lovebird = require "lib.lovebird"
|
||||
local lume = require "lib.lume"
|
||||
|
||||
local map = {}
|
||||
|
||||
love.load = function()
|
||||
map.size = 150
|
||||
map.height = heightmap.create(map.size, map.size, 0, 1)
|
||||
map.temperature = heightmap.create(map.size, map.size, 0, 1)
|
||||
map.humidity = heightmap.create(map.size, map.size, 0, 1)
|
||||
|
||||
-- weird mixing idea test
|
||||
-- why does this average things out?
|
||||
-- trying to renormalize it now..
|
||||
local temporary_maps = {}
|
||||
for i = 1, 3 do
|
||||
temporary_maps[i] = heightmap.create(map.size, map.size, 0, 1)
|
||||
end
|
||||
for x = 0, map.height.w do
|
||||
for y = 0, map.height.h do
|
||||
map.height[x][y] = (map.height[x][y] + temporary_maps[1][x][y] + temporary_maps[2][x][y] + temporary_maps[3][x][y] ) / 4
|
||||
end
|
||||
end
|
||||
heightmap.normalize(map.height, 0, 1)
|
||||
|
||||
-- if true then return end
|
||||
|
||||
-- lower temperature by half height
|
||||
-- NOTE ruins "normalization" but that's fine once we have "real" numbers to work with
|
||||
for x = 0, map.temperature.w do
|
||||
for y = 0, map.temperature.h do
|
||||
map.temperature[x][y] = math.max(0, map.temperature[x][y] - map.height[x][y] / 2)
|
||||
end
|
||||
end
|
||||
|
||||
-- modify temperature by latitude
|
||||
-- TODO would be more efficient to calculate Y in outer loop, since X does not change the distance
|
||||
-- NOTE only subtracts temperature, which further "ruins normalization" and makes everything too cold:
|
||||
local center_y = map.size / 2
|
||||
for x = 0, map.temperature.w do
|
||||
for y = 0, map.temperature.h do
|
||||
local distance = math.abs(y - center_y)
|
||||
map.temperature[x][y] = lume.clamp(map.temperature[x][y] - distance / map.size / 2, 0, 1)
|
||||
end
|
||||
end
|
||||
|
||||
-- increase humidity by half temperature
|
||||
for x = 0, map.humidity.w do
|
||||
for y = 0, map.humidity.h do
|
||||
map.humidity[x][y] = math.min(1, map.humidity[x][y] + map.temperature[x][y] / 2)
|
||||
end
|
||||
end
|
||||
|
||||
-- planetizer!
|
||||
local radius = (map.size / 2)^2
|
||||
for x = 0, map.height.w do
|
||||
for y = 0, map.height.h do
|
||||
if lume.distance(x, y, map.size / 2, map.size / 2, true) > radius then
|
||||
map.height[x][y] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
love.update = function(dt)
|
||||
lovebird.update()
|
||||
end
|
||||
|
||||
love.draw = function()
|
||||
local tile_size = 2
|
||||
|
||||
for x = 0, map.height.w do
|
||||
for y = 0, map.height.h do
|
||||
-- raw heightmap
|
||||
-- NOTE will break with planetizer enabled!
|
||||
-- local value = map.height[x][y]
|
||||
-- love.graphics.setColor(value, value, value, 1)
|
||||
-- love.graphics.rectangle("fill", x * tile_size, y * tile_size, tile_size, tile_size)
|
||||
|
||||
-- even weighting between height and temperature
|
||||
-- local value = map.height[x][y] / 2 + map.temperature[x][y] / 2
|
||||
-- if value < 0.2 then
|
||||
-- love.graphics.setColor(0, 0, 1, 1)
|
||||
-- elseif value < 0.215 then
|
||||
-- love.graphics.setColor(1, 1, 0, 1)
|
||||
-- elseif value < 0.34 then
|
||||
-- love.graphics.setColor(0, 1, 0, 1)
|
||||
-- elseif value < 0.72 then
|
||||
-- love.graphics.setColor(0, 0.67, 0, 1)
|
||||
-- elseif value < 0.9 then
|
||||
-- love.graphics.setColor(0.67, 0.67, 0.67, 1)
|
||||
-- else
|
||||
-- -- love.graphics.setColor(0, 0, 0, 1) -- temporary nothing
|
||||
-- love.graphics.setColor(1, 1, 1, 1)
|
||||
-- end
|
||||
-- love.graphics.rectangle("fill", x * tile_size, y * tile_size, tile_size, tile_size)
|
||||
|
||||
-- temperature map
|
||||
local value = map.temperature[x][y]
|
||||
love.graphics.setColor(value, 0, 0, 1)
|
||||
love.graphics.rectangle("fill", map.size * tile_size + x * tile_size, y * tile_size, tile_size, tile_size)
|
||||
|
||||
-- humidity map
|
||||
local value = map.humidity[x][y]
|
||||
love.graphics.setColor(0, 0, value, 1)
|
||||
love.graphics.rectangle("fill", x * tile_size, map.size * tile_size + y * tile_size, tile_size, tile_size)
|
||||
|
||||
-- "naive" biomed map
|
||||
local value = map.height[x][y]
|
||||
if value then
|
||||
if value < 0.2 then
|
||||
love.graphics.setColor(0, 0, 1, 1)
|
||||
elseif value < 0.215 then
|
||||
love.graphics.setColor(1, 1, 0, 1)
|
||||
elseif value < 0.34 then
|
||||
love.graphics.setColor(0, 1, 0, 1)
|
||||
elseif value < 0.72 then
|
||||
love.graphics.setColor(0, 0.67, 0, 1)
|
||||
elseif value < 0.9 then
|
||||
love.graphics.setColor(0.67, 0.67, 0.67, 1)
|
||||
else
|
||||
-- love.graphics.setColor(0, 0, 0, 1) -- temporary nothing
|
||||
love.graphics.setColor(1, 1, 1, 1)
|
||||
end
|
||||
love.graphics.rectangle("fill", map.size * tile_size + x * tile_size, map.size * tile_size + y * tile_size, tile_size, tile_size)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
love.keypressed = function(key)
|
||||
if key == "escape" then
|
||||
love.event.quit()
|
||||
elseif key == "r" then
|
||||
love.load()
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user