Current File : /home/jeshor13/11bsouth.com/DataBounce/Bubble.js |
function Bubble(x, y) {
this.x = x;
this.y = y;
this.r = 10
this.col = 255;
this.velocityX = random(-(speed), (speed))
this.velocityY = 1
this.hits = 0
this.display = function() {
stroke(255);
fill(this.col,0,0, 100);
ellipse(this.x, this.y, this.r * 2, this.r * 2);
}
this.update = function() {
this.x = this.x + this.velocityX;
this.y = this.y + this.velocityY;
}
this.changeColor = function() {
this.col = color(random(this.hits), 0, 0);
}
this.intersects = function(other) {
var d = dist(this.x, this.y, other.x, other.y);
if (d < this.r + other.r + .5) {
this.hits++
return true;
} else {
return false;
}
}
// this.intersectsSideX = function() {
// if (this.x > width * 0.95 || this.x < width * 0.05) {
// return true;
// } else {
// return false;
// }
// }
// this.intersectsSideY = function() {
// if (this.y > height * 0.95 || this.y < height * 0.05) {
// return true;
// } else {
// return false;
// }
// }
this.changeDirectionX = function() {
this.velocityX = this.velocityX * -1
this.hits++
}
this.changeDirectionY = function() {
this.velocityY = this.velocityY * -1
this.hits++
}
}