acomputerdog

VoxelWrite Cave Generator

Nov 6th, 2013
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var caveBlockColor = 0x6E6E6E; //Sets the color of the block to generate, in this case grey
  2. var caveRadiusMin = 2; //The minimum radius of a section of cave
  3. var caveRadiusMax = 4; //The maximum radius of a section of cave
  4. var volatility1 = 4; //Determines the randomness of the cave
  5. var volatility2 = 2; //Determines the randomness of the cave
  6. var caveLength = 100; //The maximum length of the cave
  7. var caveStartX = 0; //The x-coord to start generating at.
  8. var caveStartY = 0; //The y-coord to start generating at.
  9. var caveStartZ = 0; //The z-coord to start generating at.
  10. var flatCave = false; //If true the cave's z axis will not be adjusted
  11. var passes = 2; //How many passes to perform.  Each pass generates a separate cave.
  12. var randomizeVolatility = true; //If true to volatility is randomised as the cave is generated.
  13.  
  14. passes = Math.abs(passes);
  15. caveLength = Math.abs(caveLength);
  16.  
  17. var x = caveStartX;
  18. var y = caveStartY;
  19. var z = caveStartZ;
  20. var radius = random(caveRadiusMin,caveRadiusMax);
  21. var length = 0;
  22. var xAngle = random(-1*altVolatility,altVolatility);
  23. var yAngle = random(-1*altVolatility,altVolatility);
  24. var zAngle = random(-1*altVolatility,altVolatility);
  25. var currAngleDistance = 1;
  26. var currPasses = 0;
  27. var caveVolatility = volatility1;
  28. var altVolatility = volatility2;
  29.  
  30. while (currPasses < passes){
  31.     if(randomizeVolatility){
  32.         caveVolatility += random(-1,1);
  33.         altVolatility += random(-1,1);
  34.     }
  35.     x = caveStartX;
  36.     y = caveStartY;
  37.     z = caveStartZ;
  38.     radius = random(caveRadiusMin,caveRadiusMax);
  39.     length = 0;
  40.     xAngle = random(-1*altVolatility,altVolatility);
  41.     yAngle = random(-1*altVolatility,altVolatility);
  42.     zAngle = random(-1*altVolatility,altVolatility);
  43.     currAngleDistance = 1;
  44.     while (length<caveLength){
  45.         caveVolatility = Math.min(radius, volatility1);
  46.         altVolatility = Math.min(radius, volatility2);
  47.        
  48.         gProject.putBlocks(ball(x,y,z,radius,caveBlockColor));
  49.         if(currAngleDistance>0){
  50.             x += xAngle;
  51.             y += yAngle;
  52.             if(!flatCave){
  53.                 z = Math.max(z + zAngle, radius + 1);
  54.             }else{
  55.                 z = radius+caveStartZ;
  56.             }
  57.             currAngleDistance--;
  58.             length++;
  59.             radius = random(caveRadiusMin,caveRadiusMax);
  60.         }else{
  61.             currAngleDistance = random(1, Math.abs(caveVolatility - radius));
  62.             xAngle = random(-1*altVolatility,altVolatility);
  63.             yAngle = random(-1*altVolatility,altVolatility);
  64.             if(z>currAngleDistance){
  65.                 zAngle = random(-1*altVolatility,altVolatility);
  66.             }else{
  67.                 zAngle = 1;
  68.             }      
  69.         }        
  70.     }
  71.     currPasses++;
  72. }
  73. function random(min, max){
  74.     return Math.round(Math.random() * (max - min)) + min;
  75. }
  76.  
  77. cullProjectOccludedBlocks();
  78. gEditor.requestRender();
Add Comment
Please, Sign In to add comment