The problem is caused because we're adding acceleration
even at the moment of the bounce.
Gravity causes things to accelerate. But not everything. For example, not chairs sitting on the floor.
At the instant the ball is bouncing, there should be no acceleration added.
We can reflect this in the code by changing
this.velocity_y = this.velocity_y + gravity;
and
if (this.y + this.MyImg.height > myCanvas.height) {this.velocity_y= -this.velocity_y}
to become
if (this.y + this.MyImg.height > myCanvas.height) {
// bounce
this.velocity_y= -this.velocity_y;
}
else {
// accelerate by gravity
this.velocity_y = this.velocity_y + gravity;
}
In other words,
if we're at the bottom then bounce. If we're not at the bottom, then add some acceleration due to gravity.
Now we're bouncing perfectly.