This commit is contained in:
BuckarooBanzay 2024-05-16 19:15:01 +02:00
commit 4b2916754a
6 changed files with 101 additions and 0 deletions

17
.luacheckrc Normal file
View File

@ -0,0 +1,17 @@
globals = {
"isogen"
}
read_globals = {
-- Stdlib
string = {fields = {"split", "trim"}},
table = {fields = {"copy", "getn"}},
-- Minetest
"minetest", "vector", "ItemStack",
"dump", "dump2",
"VoxelArea",
-- deps
"mtt"
}

49
draw.lua Normal file
View File

@ -0,0 +1,49 @@
-- x and y are 0-based
local function get_index(w, x, y)
return (w * y) + x + 1
end
function isogen.draw_cube(data, width, cube_len, x_offset, y_offset, color1, color2, color3)
assert(cube_len % 4 == 0, "cube_len must be divisible by 4")
assert(cube_len > 4, "cube_len must be greater than 4")
local half_len_zero_indexed = (cube_len/2)-1
local quarter_len = cube_len / 4
-- left/right part
local yo = 0
for x=0,half_len_zero_indexed do
for y=0,half_len_zero_indexed do
-- left
local index = get_index(width, x_offset+x, y_offset+y+quarter_len+yo)
data[index] = color1
-- right
index = get_index(width, x_offset+cube_len-1-x, y_offset+y+quarter_len+yo)
data[index] = color2
end
if x % 2 == 0 then
yo = yo + 1
end
end
-- upper part
yo = 0
local yl = 1
for x=0,half_len_zero_indexed-1 do
for y=0,yl do
-- left
local index = get_index(width, x_offset+1+x, y_offset+quarter_len-1-yo+y)
data[index] = color3
-- right
index = get_index(width, x_offset+cube_len-2-x, y_offset+quarter_len-1-yo+y)
data[index] = color3
end
if x % 2 ~= 0 then
yo = yo + 1
yl = yl + 2
end
end
end
-- image width: (x * cube_len / 2) + (z * cube_len / 2)
-- image height: (y * cube_len) - (cube_len / 2) -- XXX

26
draw.spec.lua Normal file
View File

@ -0,0 +1,26 @@
mtt.register("draw cube", function(callback)
local red = { a=255, r=255, g=0, b=0 }
local green = { a=255, r=0, g=255, b=0 }
local blue = { a=255, r=0, g=0, b=255 }
local transparent = { a=0, r=0, g=0, b=0 }
local width = 800
local height = 600
local png_data = {}
for i=1,width*height do
png_data[i] = transparent
end
isogen.draw_cube(png_data, width, 96, 0, 0, red, green, blue)
local png = minetest.encode_png(width, height, png_data)
local path = minetest.get_worldpath() .. "/test.png"
minetest.safe_file_write(path, png)
print("png saved: " .. #png .. " bytes")
callback()
end)

8
init.lua Normal file
View File

@ -0,0 +1,8 @@
isogen = {}
local MP = minetest.get_modpath("isogen")
dofile(MP.."/draw.lua")
if minetest.get_modpath("mtt") and mtt.enabled then
dofile(MP.."/draw.spec.lua")
end

1
mod.conf Normal file
View File

@ -0,0 +1 @@
name = isogen

0
readme.md Normal file
View File