Skip to content

Instantly share code, notes, and snippets.

@rlieberman
Created September 24, 2014 12:05
Show Gist options
  • Save rlieberman/b71287cc87f645dfd59f to your computer and use it in GitHub Desktop.
Save rlieberman/b71287cc87f645dfd59f to your computer and use it in GitHub Desktop.
//x position of circle
float circleX = 0;
//y position of circle
float circleY = 180;
//x-speed of circle
float xspeed = 5;
//y-speed of circle
float yspeed = random (10);
//boolean variable for the movement of the circle
boolean moving = false;
void setup () {
size (640,400);
background (50);
}
void draw () {
//distance from center of screen
float d = dist(width/2, height/2, mouseX, mouseY);
//maximum distance
float maxDist = dist(0, 0, width/2, height/2);
fill (random(200, 250), random (200, 250), random(200, 250));
ellipse (circleX, circleY, d, d);
//bouncing horizontally
circleX=circleX + xspeed;
if ((circleX > width) || (circleX <=0)) {
xspeed = -xspeed;
}
//bouncing vertically
circleY = circleY + yspeed;
if ((circleY > height) || (circleY<0)) {
yspeed = -yspeed;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment