xxxxxxxxxx
63
class Particle {
constructor(x, y) {
this.pos = createVector(x, y);
this.vel = p5.Vector.random2D();
this.vel.mult(random(1, 2));
this.acc = createVector(0, 0);
this.r = 10;
this.lifetime = 255;
this.image= loadImage('Dan_grinning.png')
this.image2= loadImage('Asterisk_smile.png')
this.image3= loadImage('Equal_smile.png')
this.image4= loadImage('Rainbow_zany.png')
this.image5= loadImage('Square_smile.png')
this.image6= loadImage('ThisDot_smile.png')
}
finished() {
return this.lifetime < -20;
}
applyForce(force) {
this.acc.add(force);
}
edges() {
if (this.pos.y >= height - this.r) {
this.pos.y = height - this.r;
this.vel.y *= -1;
}
if (this.pos.x >= width - this.r) {
this.pos.x = width - this.r;
this.vel.x *= -1;
} else if (this.pos.x <= this.r) {
this.pos.x = this.r;
this.vel.x *= -1;
}
}
update() {
this.vel.add(this.acc);
this.pos.add(this.vel);
this.acc.set(0, 0);
this.lifetime -= 5;
}
show() {
stroke(255, this.lifetime);
strokeWeight(2);
fill(255, this.lifetime);
var rand= Math.round(random(1,6))
//print(rand)
image(this.image,this.pos.x, this.pos.y,this.r*2,this.r*2);
}
}