xxxxxxxxxx
97
function setup() {
createCanvas(900, 900);
cols = ["#1fbfff","#1fdaff","#2ceef2","#8ccfb9","#d2b04b","#ffb01f","#fd8f21","#fc6722","#ea4334","#d7474c"];
rects = [];
rects[0] = new Rect(0, 0, width, height, 0, 0, 0);
noFill();
// strokeWeight(0.25);
noStroke();
}
function draw() {
background(220);
for(i = 0; i < rects.length; i++){
rects[i].update();
}
}
class Rect{
constructor(x, y, w, h, index, parent, quadrant){
this.pos = createVector(x, y);
this.ow = w;
this.oh = h;
this.cw = w;
this.ch = h;
this.w = w;
this.h = h;
this.index = index;
this.col = color(cols[this.index % cols.length])
this.parent = parent;
this.children = 0;
this.quadrant = quadrant;
if(this.quadrant == 0 && this.index > 0){
this.pos = createVector(rects[this.parent].pos.x, rects[this.parent].pos.y);
} else if(this.quadrant == 1){
this.pos = createVector(rects[this.parent].pos.x + this.ow, rects[this.parent].pos.y);
} else if(this.quadrant == 2){
this.pos = createVector(rects[this.parent].pos.x, rects[this.parent].pos.y + this.oh);
} else if(this.quadrant == 3){
this.pos = createVector(rects[this.parent].pos.x + this.ow, rects[this.parent].pos.y + this.oh);
}
}
update(){
this.w = noise(this.index, frameCount * 0.001 + this.index );
this.h = noise(this.index + rects.length, frameCount * noise(this.index, frameCount * 0.001) * 0.001 + this.index );
fill(this.col);
if(this.quadrant == 0 && this.index > 0){
this.cw = rects[this.parent].w * rects[this.parent].cw;
this.iw = (1 - rects[this.parent].w) * rects[this.parent].cw;
this.ch = rects[this.parent].h * rects[this.parent].ch;
this.ih = (1 - rects[this.parent].h) * rects[this.parent].ch;
this.pos = createVector(rects[this.parent].pos.x, rects[this.parent].pos.y);
rect(this.pos.x, this.pos.y, this.cw, this.ch);
} else if(this.quadrant == 1){
this.cw = rects[this.parent].w * rects[this.parent].cw;
this.iw = (1 - rects[this.parent].w) * rects[this.parent].cw;
this.ch = rects[this.parent].h * rects[this.parent].ch;
this.ih = (1 - rects[this.parent].h) * rects[this.parent].ch
this.pos = createVector(rects[this.parent].pos.x + this.cw, rects[this.parent].pos.y);
rect(this.pos.x, this.pos.y, this.iw, this.ch);
this.cw = this.iw;
} else if(this.quadrant == 2){
this.cw = rects[this.parent].w * rects[this.parent].cw;
this.iw = (1 - rects[this.parent].w) * rects[this.parent].cw;
this.ch = rects[this.parent].h * rects[this.parent].ch;
this.ih = (1 - rects[this.parent].h) * rects[this.parent].ch
this.pos = createVector(rects[this.parent].pos.x, rects[this.parent].pos.y + this.ch);
rect(this.pos.x, this.pos.y, this.cw, this.ih);
this.ch = this.ih;
} else if(this.quadrant == 3){
this.cw = rects[this.parent].w * rects[this.parent].cw;
this.iw = (1 - rects[this.parent].w) * rects[this.parent].cw;
this.ch = rects[this.parent].h * rects[this.parent].ch;
this.ih = (1 - rects[this.parent].h) * rects[this.parent].ch
this.pos = createVector(rects[this.parent].pos.x + this.cw, rects[this.parent].pos.y + this.ch);
rect(this.pos.x, this.pos.y, this.iw, this.ih);
this.cw = this.iw;
this.ch = this.ih;
}
// rect(this.pos.x, this.pos.y, this.cw, this.ch);
if(this.ow > 20 && this.children < 4){
rects[rects.length] = new Rect(this.pos.x, this.pos.y, this.ow / 2, this.oh / 2, rects.length, this.index, this.children);
this.children++;
rects[rects.length] = new Rect(this.pos.x, this.pos.y, this.ow / 2, this.oh / 2, rects.length, this.index, this.children);
this.children++;
rects[rects.length] = new Rect(this.pos.x, this.pos.y, this.ow / 2, this.oh / 2, rects.length, this.index, this.children);
this.children++;
rects[rects.length] = new Rect(this.pos.x, this.pos.y, this.ow / 2, this.oh / 2, rects.length, this.index, this.children);
this.children++;
}
}
}