-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add
isogen.draw_map(pos1, pos2)
(#3)
* add `isogen.draw_map(pos1, pos2)` * draw_map test --------- Co-authored-by: BuckarooBanzay <BuckarooBanzay@users.noreply.github.com>
- Loading branch information
1 parent
b532b1f
commit ee35b4e
Showing
6 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
|
||
function isogen.draw_map(pos1, pos2) | ||
pos1, pos2 = vector.sort(pos1, pos2) | ||
|
||
minetest.load_area(pos1, pos2) | ||
|
||
local height = pos2.z - pos1.z + 1 | ||
local width = pos2.x - pos1.x + 1 | ||
|
||
local canvas = isogen.create_canvas(width, height) | ||
|
||
-- left-right | ||
for x=pos1.x,pos2.x do | ||
-- top-down | ||
for z=pos1.z,pos2.z do | ||
local list = {} | ||
|
||
-- up-down | ||
for y=pos2.y,pos1.y,-1 do | ||
local pos = vector.new(x, y, z) | ||
local node = minetest.get_node(pos) | ||
local color = isogen.get_color(node) | ||
if color then | ||
table.insert(list, color) | ||
if not color.a or color.a == 255 then | ||
break | ||
end | ||
end | ||
end | ||
|
||
-- draw from bottom-up (transparency) | ||
if #list > 0 then | ||
local pos = vector.new(x, 0, z) | ||
for i=#list,1,-1 do | ||
local rel_pos = vector.subtract(pos, pos1) | ||
local cx = width - rel_pos.x - 1 -- inverted x axis | ||
local cy = rel_pos.z | ||
canvas:add_pixel(cx, cy, list[i]) | ||
end | ||
end | ||
end | ||
end | ||
|
||
return canvas:png() | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
local pos1 = vector.new(200,100,100) | ||
local pos2 = vector.add(pos1, 15) | ||
|
||
mtt.emerge_area(pos1, pos2) | ||
|
||
mtt.register("draw_map", function(callback) | ||
minetest.load_area(pos1, pos2) | ||
|
||
minetest.set_node(pos1, { name = "mapgen_stone" }) | ||
minetest.set_node(vector.add(pos1, vector.new(1, 0, 0)), { name = "mapgen_stone" }) | ||
minetest.set_node(vector.add(pos1, vector.new(2, 0, 0)), { name = "mapgen_stone" }) | ||
minetest.set_node(vector.add(pos1, vector.new(0, 0, 1)), { name = "mapgen_water_source" }) | ||
minetest.set_node(vector.add(pos1, vector.new(1, 0, 1)), { name = "mapgen_water_source" }) | ||
|
||
-- sanity tests | ||
local node = minetest.get_node(pos1) | ||
assert(node.name ~= "air") | ||
assert(node.name ~= "ignore") | ||
|
||
local png = isogen.draw_map(pos1, pos2) | ||
local path = minetest.get_worldpath() .. "/test_map.png" | ||
minetest.safe_file_write(path, png) | ||
|
||
print("png saved: " .. #png .. " bytes") | ||
|
||
callback() | ||
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters