Advertisement
QuantumWarpCode

Menger Sponge Creator in Roblox

Jul 19th, 2014
474
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.89 KB | None | 0 0
  1. size = 1 --Change this to the size of each part.
  2.  
  3. function createPart(name,x1,y1,z1,parent1)
  4.     --Sets the properties of part.
  5.     part = Instance.new("Part",parent1)
  6.     part.Name = name
  7.     part.FormFactor = "Custom"
  8.     part.Size = Vector3.new(size,size,size)
  9.     part.Position = Vector3.new(x1,y1,z1)
  10.     part.Anchored = true
  11.     part.BottomSurface = 10
  12.     part.TopSurface = 10
  13.     part.RightSurface = 10
  14.     part.LeftSurface = 10
  15.     part.FrontSurface = 10
  16.     part.BackSurface = 10
  17. end
  18.  
  19. function spongeClone(model,iteration)
  20.     adjustment = 3^(iteration-1)*size
  21.     print(adjustment)
  22.     --Then a bunch of lines for the pattern.
  23.     newModel1 = model:clone()
  24.     newModel1.Parent = game.Workspace
  25.     adjustParts(newModel1,adjustment,0,0)
  26.    
  27.     newModel2 = model:clone()
  28.     newModel2.Parent = game.Workspace
  29.     adjustParts(newModel2,adjustment*2,0,0)
  30.    
  31.     newModel3 = model:clone()
  32.     newModel3.Parent = game.Workspace
  33.     adjustParts(newModel3,0,adjustment,0)
  34.    
  35.     newModel4 = model:clone()
  36.     newModel4.Parent = game.Workspace
  37.     adjustParts(newModel4,0,adjustment*2,0)
  38.    
  39.     newModel5 = model:clone()
  40.     newModel5.Parent = game.Workspace
  41.     adjustParts(newModel5,0,0,-1*adjustment)
  42.    
  43.     newModel6 = model:clone()
  44.     newModel6.Parent = game.Workspace
  45.     adjustParts(newModel6,0,0,-1*(adjustment*2))
  46.    
  47.     newModel7 = model:clone()
  48.     newModel7.Parent = game.Workspace
  49.     adjustParts(newModel7,0,adjustment*2,-1*adjustment)
  50.    
  51.     newModel8 = model:clone()
  52.     newModel8.Parent = game.Workspace
  53.     adjustParts(newModel8,0,adjustment*2,-1*(adjustment*2))
  54.    
  55.     newModel9 = model:clone()
  56.     newModel9.Parent = game.Workspace
  57.     adjustParts(newModel9,0,adjustment,-1*(adjustment*2))
  58.    
  59.     newModel10 = model:clone()
  60.     newModel10.Parent = game.Workspace
  61.     adjustParts(newModel10,adjustment,adjustment*2,0)
  62.    
  63.     newModel12 = model:clone()
  64.     newModel12.Parent = game.Workspace
  65.     adjustParts(newModel12,adjustment*2,adjustment*2,0)
  66.    
  67.     newModel13 = model:clone()
  68.     newModel13.Parent = game.Workspace
  69.     adjustParts(newModel13,adjustment*2,adjustment,0)
  70.    
  71.     newModel14 = model:clone()
  72.     newModel14.Parent = game.Workspace
  73.     adjustParts(newModel14,adjustment*2,0,-1*adjustment)
  74.    
  75.     newModel15 = model:clone()
  76.     newModel15.Parent = game.Workspace
  77.     adjustParts(newModel15,adjustment*2,0,-1*(adjustment*2))
  78.  
  79.     newModel16 = model:clone()
  80.     newModel16.Parent = game.Workspace
  81.     adjustParts(newModel16,adjustment*2,adjustment*2,-1*adjustment)
  82.    
  83.     newModel17 = model:clone()
  84.     newModel17.Parent = game.Workspace
  85.     adjustParts(newModel17,adjustment*2,adjustment*2,-1*(adjustment*2))
  86.    
  87.     newModel18 = model:clone()
  88.     newModel18.Parent = game.Workspace
  89.     adjustParts(newModel18,adjustment*2,adjustment,-1*(adjustment*2))
  90.    
  91.     newModel19 = model:clone()
  92.     newModel19.Parent = game.Workspace
  93.     adjustParts(newModel19,adjustment,0,-1*(adjustment*2))
  94.    
  95.     newModel20 = model:clone()
  96.     newModel20.Parent = game.Workspace
  97.     adjustParts(newModel20,adjustment,adjustment*2,-1*(adjustment*2))
  98.    
  99.     --Combine them all to the same model.
  100.     combineModels(Model)
  101.    
  102.     passingModel = game.Workspace.Model
  103.    
  104.    
  105.     --Set the generations to 1 or 2 if you dont want lag. On 3 it will take a minute to create and higher numbers cause lag and may crash the game.
  106.     if iteration < 3 then --This number is how many generations.
  107.         spongeClone(passingModel,iteration + 1)
  108.     end
  109. end
  110.  
  111. function adjustParts(model2,x2,y2,z2)
  112.     --Gets the children.
  113.     local c = model2:GetChildren()
  114.     for index, child in pairs(c) do
  115.         --Adjusts by addition.
  116.         child.Position = child.Position + Vector3.new(x2,y2,z2)
  117.     end
  118. end
  119.  
  120. function combineModels(name)
  121.     local c = game.Workspace:GetChildren()
  122.     NewModel = Instance.new("Model",game.Workspace)
  123.     for index, child in pairs(c) do
  124.         if child.className == "Model" then
  125.             local d = child:GetChildren()
  126.             for index, children in pairs(d) do
  127.                 children.Parent = NewModel
  128.             end
  129.             child:remove()
  130.         end
  131.     end
  132. end
  133.  
  134. BaseModel = Instance.new("Model",game.Workspace)
  135.  
  136. createPart("Block",0,0,0,BaseModel)
  137. spongeClone(BaseModel,1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement