This section demonstrates the physics behind the Bouncing Ball simulation.
This ball moves in a [2-D] two-dimensional space with horizontal and vertical velocity components. The direction of motion is determined by the sign of these components.
let x = 100, y = 100;
let vx = 2.5, vy = 2;
function draw(){
x += vx;
y += vy;
// Check for collision with walls
if(x <= 0 || x >= canvasWidth) {
vx = -vx; // Reverse X velocity
}
if(y <= 0 || y >= canvasHeight) {
vy = -vy; // Reverse Y velocity
}
}| Parameter | Description | Example Value |
|---|---|---|
| Velocity X | Controls the ball's speed in the horizontal direction. | 2.5 |
| Velocity Y | Controls the ball's speed in the vertical direction. | 2.0 |
| Ball Size | Defines the radius or diameter of the ball. | 48 |