xxxxxxxxxx
48
class Ball {
constructor(tempX = 200, tempY = 300, tempXspeed = 9, tempYspeed = -3) {
this.x = tempX;
this.y = tempY;
this.xspeed = tempXspeed;
this.yspeed = tempYspeed;
}
move() {
this.x = this.x + this.xspeed;
this.y = this.y + this.yspeed;
}
display() {
stroke(0);
strokeWeight(0);
//Ball colors
var r = map(sin(frameCount), -1, 1, 50, 255);
var g = map(cos(frameCount / 2), -1, 1, 50, 255);
var b = map(sin(frameCount / 9), -1, 1, 50, 255);
fill(r, g, b);
//creating ball/ ellipse
ellipse(this.x, this.y, 24, 24);
//adding second beam on click
let count = 0;
if(mouseIsPressed)
{
count += 24
}
for (let i = 0; i < 12 + count; i += 24) {
ellipse(this.x + i/4 , this.y + i * 2, 24, 24);
}
}
bounce() {
if (this.x > width || this.x < 0) {
this.xspeed = this.xspeed * -1;
}
if (this.y > height || this.y < 0) {
this.yspeed = this.yspeed * -1;
}
}
}