Advertisement
Derek1017

Terrain

May 25th, 2018
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.52 KB | None | 0 0
  1. -----------------------------------------------------
  2. ------------------- terrain generator ----------
  3. ------------------99% BY xLEGOx --------------
  4. ------------------Modified by JKM103----------
  5.  
  6. --- how varied the terrain should be
  7. variance = 3
  8.  
  9.  
  10.  
  11. _G.Terrain = {}
  12. for i = 1, 35 do
  13. Terrain[i] = {}
  14. for j = 1, 35 do
  15. Terrain[i][j] = {h = 0}
  16. end
  17. end
  18.  
  19. slope = 0.7
  20. num_itts = 0.1
  21.  
  22. function Diamond(x, y, eachside)
  23.     num_itts = num_itts + 1
  24.     --print(num_itts, "->", eachside)
  25.     --wait()
  26.     local h_mul = math.random(-slope*eachside, slope*eachside)
  27.     for _x_ = -eachside, eachside do
  28.     for _y_ = -eachside, eachside do
  29.         local _x, _y = _x_ + x, _y_ + y
  30.         local max = math.max(math.abs(_x_), math.abs(_y_))
  31.         local h_mod = 1.1 - (max / eachside)
  32.         Terrain[_x][_y].h = Terrain[_x][_y].h + h_mod * h_mul
  33.     end
  34.     end
  35.    
  36.     if eachside > 1 then
  37.         --[[]]Diamond(x + eachside/2, y + eachside/2, eachside/2)
  38.         Diamond(x - eachside/2, y - eachside/2, eachside/2)
  39.         Diamond(x - eachside/2, y + eachside/2, eachside/2)
  40.         Diamond(x + eachside/2, y - eachside/2, eachside/2)
  41.     end
  42. end
  43.  
  44. game.Players.ChildAdded:wait()
  45.  
  46. Diamond(17, 17, 17)
  47.  
  48. for x = 1, 35 do
  49.     for y = 1, 35 do
  50.         wait()
  51.         DrawTriangle(Vector3.new(x*10, Terrain[x][y].h*10, y*10), Vector3.new(x*10, Terrain[x][y+1].h*10, (y+1)*10), Vector3.new((x+1)*10, Terrain[x+1][y].h*10, y*10))
  52.         DrawTriangle(Vector3.new((x+1)*10, Terrain[x+1][y+1].h*10, (y+1)*10), Vector3.new(x*10, Terrain[x][y+1].h*10, (y+1)*10), Vector3.new((x+1)*10, Terrain[x+1][y].h*10, y*10))
  53.     end
  54. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement