Skip to content

Instantly share code, notes, and snippets.

@Adidea
Last active March 1, 2016 23:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Adidea/14bfd4b43ffa719058c6 to your computer and use it in GitHub Desktop.
Save Adidea/14bfd4b43ffa719058c6 to your computer and use it in GitHub Desktop.
Generate a Menger Sponge from the selected cube
function MakePartCube(cube)
local cubes = {}
local holes = {
[5]=true,
[11]=true,
[13]=true,
[14]=true,
[15]=true,
[17]=true,
[23]=true
}
local size = cube.Size.X/3
local position = cube.Position - ((cube.Size/2) + Vector3.new(size/2, size/2, size/2))
local i = 1
for x = 1, 3 do
for y = 1, 3 do
for z = 1, 3 do
if not holes[i] then
local part = Instance.new("Part")
part.Anchored = true
part.TopSurface = "Smooth"
part.BottomSurface = "Smooth"
part.Size = Vector3.new(size, size, size)
part.BrickColor = cube.BrickColor
part.Material = cube.Material
part.CFrame = CFrame.new(x*size, y*size, z*size) + position
part.Parent = cube.Parent
cubes[i] = part
end
i = i + 1
end
end
end
cube:Destroy()
return cubes
end
function MengerSponge(cubes, n, count)
local count = count or 1
for i,v in pairs(cubes) do
if count <= n then
MengerSponge(MakePartCube(v), n, count + 1)
end
end
end
MengerSponge(game.Selection:Get(), 2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment