Simple terrain generator in Processing

Generated terrainHere is simple processing script for generating random terrains using Perlin noise. The good thing is that Processing has integrated noise() function and all you have to do is call it with the coordinates as parameters. Then assign the colors depending on the “height” of the point and add some randomness to the snow to make it look more dispersed.

float noiseScale=0.02;
int tsize = 250;

void setup() {
  size(640, 480, P3D);
  background(0);
  rotateX(radians(45));

  beginShape(POINTS);
  for(int x=0; x < tsize; x++) {
    for(int y=0; y < tsize; y++){
      float noiseVal = noise(x*noiseScale, y*noiseScale);
      int t = int(noiseVal*255);
      stroke(165, 80, 10);
      if (t >180 ){
        stroke(0, 0, t);  
      }
      // add some randomness to the snow to make it more realistic
      if (t <60 +random(20)){
        stroke(255, 255, 255);
      }
      vertex(width/2+x-tsize/2, height/2+y-tsize/2, -noiseVal*60);
    }
  }
  endShape();  
}

void draw(){
}

Comments

comments powered by Disqus