Link to source code.
let quads = [];
function setup(){
createCanvas(800,800);
append(quads,new SqSample(0,0,width/2,8, color(random(255),random(255),random(255))));
append(quads,new SqSample(width/2,0.0,width/2,8, color(random(255),random(255),random(255))));
append(quads,new SqSample(width/2,height/2,width/2,8,color(random(255),random(255),random(255))));
append(quads,new SqSample(0,height/2,width/2,8, color(random(255),random(255),random(255))));
}
function draw(){
background(0);
for(let i = 0; i < quads.length; i++){
let sq = quads[i];
sq.display();
}
}
class SqSample{
constructor( xpos,ypos,size,ct,c ) {
this.x = xpos;
this.y = ypos;
this.w = size;
this.sc = c;
this.counter = ct-1;
this.gs = 0;
this.gslimit = random(80)+20;
this.gstop = 0;
}
display(){
noStroke();
fill(this.sc);
rect(this.x,this.y,this.w,this.w);
this.gs++;
if(this.gs > this.gslimit && this.gstop == 0 && this.counter > 0){
append(quads,new SqSample(this.x,this.y,this.w/2,this.counter, color(random(255),random(255),random(255))));
append(quads,new SqSample(this.x+this.w/2,this.y,this.w/2,this.counter, color(random(255),random(255),random(255))));
append(quads,new SqSample(this.x+this.w/2,this.y+this.w/2,this.w/2,this.counter, color(random(255),random(255),random(255))));
append(quads,new SqSample(this.x,this.y+this.w/2,this.w/2,this.counter, color(random(255),random(255),random(255))));
this.gstop = 1;
}
}
}