From e233f66252aea39c33dfeb5a42e213eaccd640bc Mon Sep 17 00:00:00 2001 From: elizabethebui Date: Mon, 9 Nov 2015 12:44:19 -0500 Subject: [PATCH 1/4] Gave y velocity an acceleration --- GravityBallCode/GravityBallCode.pde | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/GravityBallCode/GravityBallCode.pde b/GravityBallCode/GravityBallCode.pde index df2493b..472bb36 100644 --- a/GravityBallCode/GravityBallCode.pde +++ b/GravityBallCode/GravityBallCode.pde @@ -1,5 +1,5 @@ //declare variables -float x, y, velX, velY, diam; +float x, y, velX, velY, diam, g; void setup() { //set size of canvas @@ -11,6 +11,7 @@ void setup() { diam = 80; velX = random(-5, 5); velY = random(-5, 5); + g = 1; } void draw() { @@ -21,9 +22,12 @@ void draw() { ellipse(x, y, diam, diam); //add velocity to position + velY += g; x += velX; y += velY; + + //bounce ball if it hits walls if (x + diam/2 >= width) { velX = -abs(velX); //if the ball hits the right wall, assign x velocity the negative version of itself From eb8af4c7fbbeb1d64f67229cff810407da3078a3 Mon Sep 17 00:00:00 2001 From: elizabethebui Date: Mon, 9 Nov 2015 12:58:47 -0500 Subject: [PATCH 2/4] Made 30 balls using arrays --- GravityBallCode/GravityBallCode.pde | 50 +++++++++++++++++------------ 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/GravityBallCode/GravityBallCode.pde b/GravityBallCode/GravityBallCode.pde index 472bb36..5152b41 100644 --- a/GravityBallCode/GravityBallCode.pde +++ b/GravityBallCode/GravityBallCode.pde @@ -1,42 +1,52 @@ //declare variables -float x, y, velX, velY, diam, g; +int count = 30; +float [] x = new float[count]; +float [] y = new float[count]; +float []velX = new float[count]; +float []velY = new float[count]; +float []diam = new float[count]; +float g; void setup() { //set size of canvas size(800, 600); //initialize variables - x = width/2; - y = height/2; - diam = 80; - velX = random(-5, 5); - velY = random(-5, 5); - g = 1; + for(int i = 0; i = width) { - velX = -abs(velX); //if the ball hits the right wall, assign x velocity the negative version of itself - } else if (x - diam/2 <= 0) { - velX = abs(velX); //if the ball hits the left wall, assign x velocity the positive version of itself + if (x[i] + diam[i]/2 >= width) { + velX[i] = -abs(velX[i]); //if the ball hits the right wall, assign x velocity the negative version of itself + } else if (x[i] - diam[i]/2 <= 0) { + velX[i] = abs(velX[i]); //if the ball hits the left wall, assign x velocity the positive version of itself } - if (y + diam/2 >= height) { - velY = -abs(velY); - } else if (y - diam/2 <= 0) { - velY = abs(velY); + if (y[i] + diam[i]/2 >= height) { + velY[i] = -abs(velY[i]); + } else if (y[i] - diam[i]/2 <= 0) { + velY[i] = abs(velY[i]); } +} } \ No newline at end of file From bccabec2e6f3633f13c018c3b4cf11da8bd8f948 Mon Sep 17 00:00:00 2001 From: elizabethebui Date: Mon, 9 Nov 2015 13:12:30 -0500 Subject: [PATCH 3/4] Added air resistance to prevent ball from bouncing too high --- GravityBallCode/GravityBallCode.pde | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/GravityBallCode/GravityBallCode.pde b/GravityBallCode/GravityBallCode.pde index 5152b41..2a7edf0 100644 --- a/GravityBallCode/GravityBallCode.pde +++ b/GravityBallCode/GravityBallCode.pde @@ -16,8 +16,8 @@ void setup() { x[i] = width/2; y[i] = height/2; diam[i] = 80; - velX[i] = random(-5, 5); - velY[i] = random(-5, 5); + velX[i] = random(-5,5); + velY[i] = random(-5,5); g = 2; } } @@ -31,12 +31,12 @@ void draw() { //add velocity to position velY[i] += g; + velY[i] *= 0.99; x[i] += velX[i]; y[i] += velY[i]; - - + //bounce ball if it hits walls if (x[i] + diam[i]/2 >= width) { velX[i] = -abs(velX[i]); //if the ball hits the right wall, assign x velocity the negative version of itself @@ -45,6 +45,7 @@ void draw() { } if (y[i] + diam[i]/2 >= height) { velY[i] = -abs(velY[i]); + y[i] = height - diam[i]/2; } else if (y[i] - diam[i]/2 <= 0) { velY[i] = abs(velY[i]); } From dacb18aa8754c24bf71b8ca8eaac87f7bbcfd579 Mon Sep 17 00:00:00 2001 From: elizabethebui Date: Tue, 10 Nov 2015 12:53:18 -0500 Subject: [PATCH 4/4] Mouse recognition and color change/diameter change --- GravityBallCode/GravityBallCode.pde | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/GravityBallCode/GravityBallCode.pde b/GravityBallCode/GravityBallCode.pde index 2a7edf0..706436c 100644 --- a/GravityBallCode/GravityBallCode.pde +++ b/GravityBallCode/GravityBallCode.pde @@ -26,8 +26,14 @@ void draw() { //draw background to cover previous frame background(0); for(int i = 0; i