xxxxxxxxxx
57
class Objet {
constructor(x, y, i) {
this.pos = createVector( x, y ) ;
this.vel = createVector( random(-1,1), random(-1,1) ) ;
this.color = color( palette[ i % palette.length ] );
this.color.setAlpha(175) ;
this.size = createVector( random(10, 100), random(10, 100) ) ;
this.noiseMax = random(10) ;
this.rMax = random(25, 150) ;
}
update() {
this.pos.x += this.vel.x;
this.pos.y += this.vel.y;
if (this.pos.x < 0 || this.pos.x > width ) {
this.vel.x = - this.vel.x ;
this.pos.x += this.vel.x;
}
if (this.pos.y < 0 || this.pos.y > height ) {
this.vel.y = - this.vel.y ;
this.pos.y += this.vel.y;
}
}
show() {
fill( this.color ) ;
beginShape();
for (let a = 0; a <= TWO_PI; a += inc) {
let xoff = map(cos(a), -1, 1, 0, this.noiseMax);
let yoff = map(sin(a), -1, 1, 0, this.noiseMax);
let r = map(noise(xoff, yoff, zoff), 0, 1, 20, this.rMax);
let x = this.pos.x + r * cos(a);
let y = this.pos.y + r * sin(a);
vertex(x, y);
}
endShape(CLOSE);
// rect( this.pos.x, this.pos.y, this.size.x, this.size.y ) ;
}
}