ForeverDev

Untitled

Sep 29th, 2014
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.63 KB | None | 0 0
  1. local conf = function(obj, ...)
  2.     for _, property in ipairs({...}) do
  3.         obj[property[1]] = property[2]
  4.     end
  5.     return obj
  6. end
  7.  
  8. local grid = 100
  9. local size = 6
  10. local ticks = 0
  11.  
  12. local minHill, maxHill = grid / 2, grid
  13.  
  14. local terrain = Instance.new("Model", Workspace)
  15.  
  16. local parts = {}
  17.  
  18. for x = -0.5 * (grid * size), 0.5 * (grid * size), size do
  19.     for z = -0.5 * (grid * size), 0.5 * (grid * size), size do
  20.         ticks = ticks + 1
  21.         if ticks % 200 == 0 then
  22.             wait()
  23.         end
  24.         table.insert(parts, conf(
  25.             Instance.new("Part", terrain),
  26.             {"FormFactor", Enum.FormFactor.Custom},
  27.             {"Position", Vector3.new(x, 0, z)},
  28.             {"Size", Vector3.new(size, 10, size)},
  29.             {"Anchored", true},
  30.             {"TopSurface", Enum.SurfaceType.Smooth}
  31.         ))
  32.     end
  33. end
  34.    
  35. for i = 1, grid do
  36.     wait()
  37.     local rand = parts[math.random(#parts)]
  38.     local radius = math.random(minHill, maxHill)
  39.     for _, part in ipairs(parts) do
  40.         if (rand.Position - part.Position).magnitude < radius then
  41.             part.Size = part.Size + Vector3.new(0, radius - (rand.Position - part.Position).magnitude, 0)
  42.         end
  43.     end
  44. end
  45.  
  46. --normalize
  47. local high, low = 0, 2^16
  48.  
  49. for _, part in ipairs(parts) do
  50.     if part.Size.Y < low then
  51.         low = part.Size.Y
  52.     elseif part.Size.Y > high then
  53.         high = part.Size.Y
  54.     end
  55. end
  56.  
  57. local ticks = 0
  58.  
  59. for _, part in ipairs(parts) do
  60.     ticks = ticks + 1
  61.     if ticks % grid == 0 then
  62.         wait()
  63.     end
  64.     part.Size = Vector3.new(size, (grid * 2) * (part.Size.Y - low) / (high - low), size)
  65.     if part.Size.Y <= 0.3 then
  66.         part.BrickColor = BrickColor.new("Bright blue")
  67.     else
  68.         part.BrickColor = BrickColor.new("Camo")
  69.         part.Material = Enum.Material.Grass
  70.     end
  71. end
Advertisement
Add Comment
Please, Sign In to add comment