Skip to content

Instantly share code, notes, and snippets.

@rlieberman
Created November 10, 2014 02:55
Show Gist options
  • Save rlieberman/f9a4a0f09603fe2ce136 to your computer and use it in GitHub Desktop.
Save rlieberman/f9a4a0f09603fe2ce136 to your computer and use it in GitHub Desktop.
var x = 180;
var y = 180;
var xspeed = 9;
var yspeed = 10;
function setup() {
createCanvas(windowWidth, windowHeight);
background (25);
}
function draw() {
//distance from center of the screen
var d = dist(windowWidth/2, windowHeight/2, mouseX, mouseY);
fill (random(200, 250), random(200, 250), random(200, 250));
ellipse (x, y, d, d);
//bouncing horizontally
x = x + xspeed;
if (x > windowWidth || x < 0) {
xspeed = -xspeed;
}
//bouncing veritcally
y = y + yspeed;
if (y > windowHeight || y < 0) {
yspeed = -yspeed;
}
}
@asherjawad
Copy link

Can you please explain simple ball bounce

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment