xxxxxxxxxx
51
var gravity = 0.1;
function Particle(x, y) {
this.x = x;
this.y = y;
this.yspeed = 0;
this.history = [];
}
Particle.prototype.update = function() {
this.y += this.yspeed;
this.yspeed += gravity;
if (this.y > height) {
this.y = height;
this.yspeed *= -0.9;
}
var v = createVector(this.x, this.y);
this.history.push(v);
};
Particle.prototype.show = function() {
stroke(0);
fill(18, 168, 18);
ellipse(this.x, this.y, 24, 24);
for (var i = 0; i < this.history.length; i++) {
var pos = this.history[i];
ellipse(pos.x, pos.y, 8, 8);
}
if (this.history.length > 25) {
this.history.splice(0, 1);
}
};
var particle;
setup = function() {
createCanvas(400, 400);
particle = new Particle(100, 100);
}
draw = function() {
background(200);
particle.update();
particle.show();
};