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:
parent
77ebc61180
commit
5c5aca14f1
@ -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)
|
||||
|
40
locale/gen_combined/grilledham_map_gen/presets/test.lua
Normal file
40
locale/gen_combined/grilledham_map_gen/presets/test.lua
Normal file
@ -0,0 +1,40 @@
|
||||
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)
|
||||
path = change_tile(path, true, "water")
|
||||
|
||||
square = compound_or({square, path})
|
||||
circle = compound_or({circle, path})
|
||||
|
||||
local pattern =
|
||||
{
|
||||
{square, circle},
|
||||
{circle, square}
|
||||
}
|
||||
|
||||
local map = grid_pattern_builder(pattern, 2, 2, 64, 64)
|
||||
map = rotate(map, degrees(45))
|
||||
|
||||
local start = rectangle_builder(48,48)
|
||||
|
||||
map = choose(start, start, map)
|
||||
|
||||
map = scale(map, 4, 4)
|
||||
|
||||
map = change_map_gen_collision_tile(map, "water-tile", "grass")
|
||||
|
||||
return map
|
||||
|
||||
--]]
|
||||
|
||||
|
||||
|
||||
local shape = rectangle_builder(5, 5)
|
||||
shape = project(shape, 5, 3)
|
||||
--shape = scale(shape, 1, 1)
|
||||
|
||||
return shape
|
Loading…
x
Reference in New Issue
Block a user