Advertisement
ekgame

VoxelWright MC Terrain #1

Feb 5th, 2013
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function placeTree(x, y, z, height, array)
  2. {
  3.     var leavesColor = 0x1C9C3E;
  4.     for (var i = 0; i < height; i++)
  5.     {
  6.         array.push([x,y,z+i,0x825E41]);
  7.     }
  8.    
  9.     for (var xx = -2; xx < 3; xx++)
  10.         for (var yy = -2; yy < 3; yy++)
  11.             for (var zz = 0; zz < 2; zz++)
  12.                 array.push([x + xx, y +yy, z + height + zz, leavesColor]);
  13.                
  14.     for (var xx = -1; xx < 2; xx++)
  15.         for (var yy = -1; yy < 2; yy++)
  16.             for (var zz = 0; zz < 2; zz++)
  17.             {
  18.                 if (zz == 1)
  19.                 {
  20.                     if (!((xx == -1 && yy == -1) || (xx == 1 && yy == -1) || (xx == -1 && yy == 1) || (xx == 1 && yy == 1)))
  21.                        array.push([x + xx, y + yy, z + height + 2 + zz, leavesColor]);
  22.                 }
  23.                 else
  24.                     array.push([x + xx, y + yy, z + height + 2 + zz, leavesColor]);
  25.             }
  26. }
  27.  
  28. function getColor(x, y)
  29. {
  30.     return Math.round(80 + 100 * colorPerlin.noise(x/colorSmoothness,y/colorSmoothness,5)) << 8;
  31. }
  32.  
  33. var b=[];
  34. var size = 258;
  35. var height = 5;
  36. var waveHeight = 10;
  37.  
  38. var terrainPerlin = new Perlin('A seed!');
  39. var terrainSmoothness = 30;
  40. var colorPerlin = new Perlin('Another seed!');
  41. var colorSmoothness = 60;
  42.  
  43. for(var x = 0; x < size; x++)
  44. {
  45.     for(var y = 0; y < size ; y++)
  46.     {
  47.         for(var z = 0; z < height + waveHeight + 1; z++)
  48.         {
  49.             var h = height + Math.round(waveHeight * terrainPerlin.noise(x/terrainSmoothness,y/terrainSmoothness,5));
  50.             if (z < h)
  51.             {
  52.                 b.push([x,y,z,0x777777]);
  53.             }
  54.             else if (z < h + 1)
  55.             {
  56.                 var color = getColor(x, y);
  57.                 b.push([x,y,z,color]);
  58.                 if (Math.random() < 0.001)
  59.                 {
  60.                     placeTree(x, y, z, 3 + Math.round(Math.random() * 3), b);
  61.                 }
  62.             }
  63.         }
  64.     }
  65. }
  66. gProject.putBlocks(b);
  67. gEditor.requestRender();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement