I liked this problem and ended up writing a solution:
float height1, height2;
int numBoxes = 5;
void setup() {
size(800, 800);
background(255);
noLoop();
}
void draw() {
height1 = 0;
for (int i=0; i<numBoxes-1; i++) {
height2 = random(height1, height);
fill(random(255), random(255), random(255));
rect(0, height1, width, height2);
height1 = height2;
}
fill(random(255), random(255), random(255));
rect(0, height1, width, height);
}
If you are new to processing and/or Java can I suggest the following resources:
Dan Shiffman’s tutorials are excellent: https://www.youtube.com/channel/UCvjgXvBlbQiydffZU7m1_aw
And a great Java Course: https://learnjavathehardway.org/