xxxxxxxxxx
56
var gravity = 0.1;
var particles = [];
function setup() {
createCanvas(400, 400);
// particles.push(new Particle(width/2-50, 50,col));
}
function draw() {
background(250);
for(let particle of particles){
particle.show();
particle.update();
// console.log(particle.yspeed, particle.yspeeddec);
}
}
function mousePressed(){
var col = random(10,100);
var diameter = random(10,100);
particles.push(new Particle(mouseX, mouseY, diameter, col));
}
class Particle{
constructor(x, y, d, c){
this.x = x;
this.y = y;
this.d = d;
this.c = c;
this.yspeed = 0;
this.yspeedacc = 1;
this.mass = map(this.d,10,100,0.0001,0.001);
// this.histroy = [];
}
update(){
this.y += this.yspeed;
this.yspeed += gravity;
if(this.y > height-this.d/2){
this.y = height-this.d/2;
this.yspeed *= -0.9 * this.yspeedacc;
}
if(this.yspeedacc>0){
this.yspeedacc -= this.mass;
}
}
show(){
// fill(50);
fill(this.c, this.c, this.c,180);
noStroke();
ellipse(this.x, this.y, this.d, this.d);
}
}