landspace of randomness
@author
void setup(){
size(500, 500);
noFill();
mousePressed();
}
void draw(){}
void mousePressed(){
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(100, 200);
} else if(y == height - 1){
float vleft = values[x - 1][y];
float v = vleft + random(-30, 30);
v = constrain(v, 0, 255);
values[x][y] = v;
if(v < vleft){
stroke(map(vleft - v, 0, 30, 0, 50));
} else {
stroke(v);
}
} else if(x == 0){
float vdown = values[x][y + 1];
float v = vdown + random(-30, 30);
v = constrain(v, 0, 255);
values[x][y] = v;
if(v < vdown){
stroke(map(vdown - v, 0, 30, 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 += random(-30, 30);
v = constrain(v, 0, 255);
values[x][y] = v;
if(v < vleft || v < vdown){
if(vleft < vdown){
stroke(map(vdown - v, 0, 30, 0, 50));
} else {
stroke(map(vleft - v, 0, 30, 0, 50));
}
} else {
stroke(v);
}
}
point(x, y);
}
}
}