I think you can simplify further by using vertex and shape.
void setup() {
size(100, 100);
frameRate(5);
}
void draw() {
background(255);
noFill();
stroke(0);
beginShape();
vertex(random(5, 95), random(5, 95));
vertex(random(5, 95), random(5, 95));
vertex(random(5, 95), random(5, 95));
vertex(random(5, 95), random(5, 95));
endShape(CLOSE);
}
P.S.: You can add as many vertex as you want.
You got my brain kicking a bit, I’m sure there is a better way to do this, but you can do something like this to randomly add more lines or not, since it seemed you tried to do it in your original code, or I read everything wrong
but here you go:
int moreLines = 0;
void setup() {
size(100, 100);
frameRate(5);
}
void draw() {
background(255);
noFill();
stroke(0);
moreLines = int(random(0, 3));
beginShape();
vertex(random(5, 95), random(5, 95));
vertex(random(5, 95), random(5, 95));
vertex(random(5, 95), random(5, 95));
if (moreLines == 1) {
lineA();
}
if (moreLines == 2) {
lineB();
}
if (moreLines == 3) {
lineC();
}
endShape(CLOSE);
}
void lineA() {
vertex(random(5, 95), random(5, 95));
}
void lineB() {
vertex(random(5, 95), random(5, 95));
vertex(random(5, 95), random(5, 95));
}
void lineC() {
vertex(random(5, 95), random(5, 95));
vertex(random(5, 95), random(5, 95));
vertex(random(5, 95), random(5, 95));
}