//cylinder y 28 10 default:glass
//cylinder z -12 3 mesecons:mesecon
//cylinder ? 2 4 stone
+
+### //spiral <size> <node>
+
+Add Spiral at WorldEdit position 1 with size <size>, composed of <node>.
+
+ //spiral 8 dirt
+ //spiral 5 default:glass
+ //spiral 2 stone
+
### //copy x/y/z/? <amount>
Returns the number of nodes added.
+### worldedit.spiral(pos, size, nodename)
+
+Adds a Spiral at `pos` with size `size`.
+
+Returns the number of nodes changed.
+
### worldedit.copy(pos1, pos2, axis, amount)
Copies the region defined by positions `pos1` and `pos2` along the `axis` axis ("x" or "y" or "z") by `amount` nodes.
Basically, this means everyone is free to use, modify, and distribute the files, as long as these modifications are also licensed the same way.
-Most importantly, the Affero variant of the GPL requires you to publish your modifications in source form, even if the mod is run only on the server, and not distributed.
\ No newline at end of file
+Most importantly, the Affero variant of the GPL requires you to publish your modifications in source form, even if the mod is run only on the server, and not distributed.
+dofile(minetest.get_modpath("worldedit") .. "/spirals.lua")\r
--modifies positions `pos1` and `pos2` so that each component of `pos1` is less than or equal to its corresponding conent of `pos2`, returning two new positions\r
worldedit.sort_pos = function(pos1, pos2)\r
pos1 = {x=pos1.x, y=pos1.y, z=pos1.z}\r
return count\r
end\r
\r
+--adds a spiral at `pos` with size `size`, returning the number of nodes changed\r
+worldedit.spiral = function(pos, size, nodename)\r
+ local shift_x,shift_y\r
+ sa = spiralt(size)\r
+ shift_y = #sa -- "Height" of the Array\r
+ local fe = sa[1]\r
+ shift_x = #fe -- "Width" of the Array\r
+ fe = nil\r
+ \r
+ local count = 0\r
+ for x,v in ipairs(sa) do\r
+ for y, z in ipairs(v) do\r
+ minetest.env:add_node({x=pos.x-shift_x+x,y=pos.y-shift_y+y,z=pos.z+z}, {name=nodename})\r
+ count = count + 1\r
+ end\r
+ end\r
+ \r
+ return count\r
+end\r
+\r
--copies the region defined by positions `pos1` and `pos2` along the `axis` axis ("x" or "y" or "z") by `amount` nodes, returning the number of nodes copied\r
worldedit.copy = function(pos1, pos2, axis, amount)\r
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)\r
count = count + 1\r
end\r
return count\r
-end
\ No newline at end of file
+end\r
end,\r
})\r
\r
+\r
+minetest.register_chatcommand("/spiral", {\r
+ params = "<size> <node>",\r
+ description = "Add Spiral at WorldEdit position 1 with size <size>, composed of <node>",\r
+ privs = {worldedit=true},\r
+ func = function(name, param)\r
+ local pos = worldedit.pos1[name]\r
+ if pos == nil then\r
+ minetest.chat_send_player(name, "No WorldEdit region selected")\r
+ return\r
+ end\r
+\r
+ local found, _, size, nodename = param:find("(%d+)%s+([^%s]+)$")\r
+ if found == nil then\r
+ minetest.chat_send_player(name, "Invalid usage: " .. param)\r
+ return\r
+ end\r
+ if axis == "?" then\r
+ axis = worldedit.player_axis(name)\r
+ end\r
+ if not worldedit.node_is_valid(pos, nodename) then\r
+ minetest.chat_send_player(name, "Invalid node name: " .. param)\r
+ return\r
+ end\r
+\r
+ local count = worldedit.spiral(pos, tonumber(size), nodename)\r
+ minetest.chat_send_player(name, count .. " nodes changed")\r
+ end,\r
+})\r
+\r
minetest.register_chatcommand("/cylinder", {\r
params = "x/y/z/? <length> <radius> <node>",\r
description = "Add cylinder at WorldEdit position 1 along the x/y/z/? axis with length <length> and radius <radius>, composed of <node>",\r
\r
minetest.chat_send_player(name, count .. " nodes loaded")\r
end,\r
-})
\ No newline at end of file
+})\r
--- /dev/null
+av, sn = math.abs, function(s) return s~=0 and s/av(s) or 0 end
+function sindex(y, x) -- returns the value at (x, y) in a spiral that starts at 1 and goes outwards
+ if y == -x and y >= x then return (2*y+1)^2 end
+ local l = math.max(av(y), av(x))
+ return (2*l-1)^2+4*l+2*l*sn(x+y)+sn(y^2-x^2)*(l-(av(y)==l and sn(y)*x or sn(x)*y)) -- OH GOD WHAT
+end
+
+function spiralt(side)
+ local ret, start, stop = {}, math.floor((-side+1)/2), math.floor((side-1)/2)
+ for i = 1, side do
+ ret[i] = {}
+ for j = 1, side do
+ ret[i][j] = side^2 - sindex(stop - i + 1,start + j - 1) --moves the coordinates so (0,0) is at the center of the spiral
+ end
+ end
+ return ret
+end