xxxxxxxxxx
41
class Ball {
constructor(x, y) {
this.x = x;
this.y = y;
this.speed = 3;
this.gravity = 0.1;
this.diameter = (dist(x, y)) * 0.4;
this.ax = random(-this.speed, this.speed);
this.ay = random(-this.speed, this.speed);
this.colour = random (['#FF0000','#FF8300','#FFF600','#3DEA12',
'#1253EA','#7C05B7', '#FF4470']);
}
update() {
this.diameter = this.diameter - 0.15;
this.x += this.ax / 2;
this.y += this.ay / 2;
this.x += random(-this.speed / 2, this.speed / 2);
this.y += random(-this.speed / 2, this.speed / 2);
}
ballisFinished() {
if (this.diameter < 0) {
return true;
}
}
render() {
//print(this.colour);
noStroke();
if (this.diameter > 0) {
fill(this.colour);
ellipse(this.x, this.y, this.diameter, this.diameter);
}
}
}