Created
November 10, 2014 02:55
-
-
Save rlieberman/f9a4a0f09603fe2ce136 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can you please explain simple ball bounce