1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2025-03-03 14:53:01 +02:00

added project shape function

This commit is contained in:
James Gillham 2017-08-14 09:38:14 +01:00
parent 6e377a8adb
commit 9b9448ca76
2 changed files with 51 additions and 1 deletions

View File

@ -182,6 +182,43 @@ function choose(condition, true_shape, false_shape)
end
end
function linear_grow(shape, size)
local half_size = size / 2
return function (local_x, local_y, world_x, world_y)
local t = math.ceil((local_y / size) + 0.5)
local n = math.ceil((math.sqrt(8 * t + 1) - 1) / 2)
local t_upper = n * (n + 1) * 0.5
local t_lower = t_upper - n
local y = (local_y - size * (t_lower + n / 2 - 0.5)) / n
local x = local_x / n
return shape(x, y, world_x, world_y)
end
end
function project(shape, size, r)
local half_size = size / 2
local ln_r = math.log(r)
local r2 = 1 / (r - 1)
local a = 1 / size
return function(local_x, local_y, world_x, world_y)
local sn = math.ceil((local_y / size) + 0.5)
local n = math.ceil(math.log((r-1) * sn * a + 1) / ln_r - 1)
local c = r ^ n
local sn_upper = size * (r ^ (n + 1) - 1) * r2
local c2 = 1 / c
local x = local_x * c2
local y = (local_y - size * (sn_upper - 0.5 * c - 0.5 )) * c2
return shape(x, y, world_x, world_y)
end
end
-- ore generation.
-- builder is the shape of the ore patch.
@ -249,6 +286,8 @@ function grid_pattern_builder(pattern, columns, rows, width, height)
end
end
-- tile converters
function change_tile(builder, old_tile, new_tile)

View File

@ -1,6 +1,7 @@
require "locale.gen_combined.grilledham_map_gen.map_gen"
require "locale.gen_combined.grilledham_map_gen.builders"
--[[
local square = rectangle_builder(32,32)
local circle = circle_builder(16)
local path = path_builder(8)
@ -26,4 +27,14 @@ map = scale(map, 4, 4)
map = change_map_gen_collision_tile(map, "water-tile", "grass")
return map
return map
--]]
local shape = rectangle_builder(5, 5)
shape = project(shape, 5, 3)
--shape = scale(shape, 1, 1)
return shape