landscape of perlin noise
@author
void setup(){
size(500, 500);
noFill();
mousePressed();
}
void draw(){}
void mousePressed(){
float noiseX = random(10000);
float noiseY = random(10000);
float[][] values = new float[width][height];
for(int x = 0; x < width; x++){
for(int y = height - 1; y >= 0; y--){
if(x == 0 && y == height - 1){
values[x][y] = random(150, 200);
} else if(y == height - 1){
float vleft = values[x - 1][y];
float v = vleft;
v += map(noise(x * 0.1 + noiseX, y * 0.1 + noiseY), 0, 1, -10, 10);
v = constrain(v, 50, 255);
values[x][y] = v;
if(v < vleft){
stroke(v - map(vleft - v, 0, 10, 0, 50));
} else {
stroke(v);
}
} else if(x == 0){
float vdown = values[x][y + 1];
float v = vdown;
v += map(noise(x * 0.1 + noiseX, y * 0.1 + noiseY), 0, 1, -10, 10);
v = constrain(v, 50, 255);
values[x][y] = v;
if(v < vdown){
stroke(v - map(vdown - v, 0, 10, 0, 50));
} else {
stroke(v);
}
} else {
float vleft = values[x - 1][y];
float vdown = values[x][y + 1];
float v = (vleft + vdown) / 2.0;
v += map(noise(x * 0.1 + noiseX, y * 0.1 + noiseY), 0, 1, -10, 10);
v = constrain(v, 50, 255);
values[x][y] = v;
if(v < vleft || v < vdown){
if(vleft < vdown){
stroke(v - map(vdown - v, 0, 10, 0, 50));
} else {
stroke(v - map(vleft - v, 0, 10, 0, 50));
}
} else {
stroke(v);
}
}
point(x, y);
}
}
}