xxxxxxxxxx
68
class Cir{
constructor(x, y, index, size, cc, ls, r, g, b){
this.index = index;
this.pos = createVector(x, y);
this.size = size;
this.rad = 0;
this.other = undefined;
this.dist = createVector(1, 0);
this.nf = 0;
this.nnf = 0;
this.nscale = 500;
this.chance = 0;
this.cc = cc;
if(this.cc < 0) this.cc = 0;
this.r = r;
if(this.r > 255) this.r = 255;
if(this.r < 0) this.r = 0;
this.g = g;
if(this.g > 255) this.g = 255;
if(this.g < 0) this.g = 0;
this.b = b;
if(this.b > 255) this.b = 255;
if(this.b < 0) this.b = 0;
this.ols = ls;
this.ls = this.ols - cirs.length * 0.1;
}
update(){
if(this.ls < 0){
this.size = this.size - 0.1;
if(this.size < 1) cirs[this.index] = undefined;
}
this.ls = this.ls - 1;
this.chance = random(1000);
if(this.chance > 999){
this.ls = this.ols - cirs.length * 0.5;
cirs[cirs.length] = new Cir(this.pos.x + random(-1, 1), this.pos.y + random(-1, 1), cirs.length, this.size + random(-2, 2), this.cc + floor(random(-1, 2)), this.ols + random(-20, 20), this.r + random(-20, 20), this.g + random(-20, 20), this.b + random(-20, 20));
}
// this.nf = (noise(this.pos.x / this.nscale, this.pos.y / this.nscale))
// this.nnf = map(this.nf, 0, 1, -1, 1);
// this.size = this.nf * 50;
stroke(this.r - 20, this.g - 20, this.b - 20);
strokeWeight(2);
fill(this.r, this.g, this.b);
circle(this.pos.x, this.pos.y, this.size);
for(this.i = 0; this.i < this.cc; this.i++){
noFill();
circle(this.pos.x, this.pos.y, (this.size / (this.cc + 1) * this.i));
}
for(this.i = 0; this.i < cirs.length; this.i++){
if(cirs[this.i] !== undefined){
if (this.i !== this.index){
this.other = cirs[this.i];
this.dist = p5.Vector.sub(this.pos, this.other.pos);
if(this.dist.mag() < this.size / 2 + this.other.size / 2){
this.dist.setMag(1);
this.pos.add(this.dist);
}
}
}
}
}
}