int a = 20;
int columns = 10;
int rows = 30;
int[] h = new int[columns];
void setup(){
size(200, 600); // size should be a * (columns, rows)
smooth();
frameRate(10);
//Draw grids
stroke(0,200,0);
for (int j = 0; j < rows; j++){
for (int i = 0; i < columns; i++){
rect(i*a,j*a,a,a);
}
}
// display();
}
void draw() {
drop();
display();
generate();
display();
}
void display() {
for (int i = 0; i < columns; i++){ // i runs 0 to columns-1 (columns)
for (int j = 0; j < h[i]; j++){ // j runs 0 to h[i]-1 ( h[i] )
fill(0);
rect((i)*a,(rows-1-j)*a,a,a);
}
for (int j = h[i]; j < rows-1; j++){ // j runs h[i] to rows -1 ( rows-h[i])
fill(255);
rect(i*a,(rows-1-j)*a,a,a);
}
}
}
void generate() {
// int next[] = new int[columns];
for (int i = 0; i < columns-1; i++){
if (h[i] - h[i+1] > 2){
h[i] = h[i]-1;
h[i+1] = h[i+1] +1;
}
}
if (h[columns-1] > 2){
h[columns-1] = h[columns-1]-1;
}
}
void drop(){
h[0] +=1;
//if (mousePressed == true){
//h[int(mouseX/a)] +=1;
// }
}
void mousePressed(){
noLoop();
save("slope2.png");
}
//void mouseReleased() {
//loop();
//}