commit 4b2916754a0dcbefd1f12c26d6a9af02821eb16a Author: BuckarooBanzay Date: Thu May 16 19:15:01 2024 +0200 init diff --git a/.luacheckrc b/.luacheckrc new file mode 100644 index 0000000..3f53700 --- /dev/null +++ b/.luacheckrc @@ -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" +} diff --git a/draw.lua b/draw.lua new file mode 100644 index 0000000..32d2b8e --- /dev/null +++ b/draw.lua @@ -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 diff --git a/draw.spec.lua b/draw.spec.lua new file mode 100644 index 0000000..9a1ccc4 --- /dev/null +++ b/draw.spec.lua @@ -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) \ No newline at end of file diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..3842d99 --- /dev/null +++ b/init.lua @@ -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 \ No newline at end of file diff --git a/mod.conf b/mod.conf new file mode 100644 index 0000000..a09b136 --- /dev/null +++ b/mod.conf @@ -0,0 +1 @@ +name = isogen diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..e69de29