This commit is contained in:
BuckarooBanzay 2022-03-27 19:37:58 +02:00
parent 1056bca3ad
commit 5e281482b4
4 changed files with 30 additions and 13 deletions

16
context/cylinder.lua Normal file
View File

@ -0,0 +1,16 @@
function mtscad.Context:cylinder(radius, height, hollow)
radius = math.floor(radius + 0.5)
local min_radius, max_radius = radius * (radius - 1), radius * (radius + 1)
for z = -radius, radius do
for y = 0, height-1 do
for x = -radius, radius do
local squared = x * x + z * z
if squared <= max_radius and (not hollow or squared >= min_radius) then
self
:translate(x, y, z)
:set_node()
end
end
end
end
end

View File

@ -1,13 +1,13 @@
function mtscad.Context:dome(radius, hollow)
local min_radius, max_radius = radius * (radius - 1), radius * (radius + 1)
local min_radius, max_radius = radius * (radius - 1), radius * (radius + 1)
for z = -radius, radius do
for y = 0, radius do
for x = -radius, radius do
local squared = x * x + y * y + z * z
if squared <= max_radius and (not hollow or squared >= min_radius) then
self
:translate(x, y, z)
:set_node()
self
:translate(x, y, z)
:set_node()
end
end
end

View File

@ -1,15 +1,15 @@
function mtscad.Context:sphere(radius, hollow)
local min_radius, max_radius = radius * (radius - 1), radius * (radius + 1)
for z = -radius, radius do
for y = -radius, radius do
for x = -radius, radius do
local squared = x * x + y * y + z * z
if squared <= max_radius and (not hollow or squared >= min_radius) then
for z = -radius, radius do
for y = -radius, radius do
for x = -radius, radius do
local squared = x * x + y * y + z * z
if squared <= max_radius and (not hollow or squared >= min_radius) then
self
:translate(x, y, z)
:set_node()
end
end
end
end
end
end
end
end
end

View File

@ -11,5 +11,6 @@ dofile(MP .. "/context/cube.lua")
dofile(MP .. "/context/sphere.lua")
dofile(MP .. "/context/dome.lua")
dofile(MP .. "/context/slope.lua")
dofile(MP .. "/context/cylinder.lua")
dofile(MP .. "/util.lua")
dofile(MP .. "/load.lua")