dx decreases by 1% each time the last condition is satisfied ( if (y + dy > 290 || y + dy < 0) { )
this calculation can go on forever, but will lead to uneven results, since floating point accuracy errors will become a big factor compared to dx, so itβs better to stop the ball rebound when it is already slow, which is the test using Math-abs for you can read
if (Math.abs(dx) < 0.01)
as if the speed of the ball in the x direction is less than 0.01 then stop the ball
source share