xxxxxxxxxx
62
let n = 20;
let rects = [];
let speed = 48;
const fps = 60;
function setup() {
createCanvas(windowWidth, windowHeight);
frameRate(fps);
colorMode(HSB, 360, 100, 100, 100);
angleMode(DEGREES);
rectMode(CENTER);
noStroke();
for(var i=0;i<n;i++){
let location = createVector(random(width),random(height));
let col = color(255);
let size = random(10,windowWidth/3.5);
rects[i] = new randomRect(location,size,col);
}
}
function draw() {
blendMode(BLEND);
background(214,100,45);
blendMode(DIFFERENCE);
for(let i=0;i<rects.length;i++){
if(!rects[i].isDead){
rects[i].draw();
rects[i].decrease();
if(rects[i].size<=0) {
rects[i].isDead = true;
let location = createVector(random(width),random(height));
let col = color(255);
let size = random(10,windowWidth/3.5);
rects.push(new randomRect(location,size,col));
}
}
}
blendMode(MULTIPLY);
background(325,100,100,100);
}
class randomRect{
constructor(_location,_size,_col){
this.x = _location.x;
this.y = _location.y;
this.size = _size;
this.col = _col;
this.isDead = false;
}
draw(){
fill(this.col);
rect(this.x,this.y,this.size,this.size);
}
decrease(){
this.size-=speed/fps;
}
}