From 116dd4dc62d8ee4bce0cc4f489d73e418a79cb6c Mon Sep 17 00:00:00 2001 From: ewang803 Date: Mon, 9 Nov 2015 13:00:55 -0500 Subject: [PATCH 1/6] Gravity Gravity variable added, ball bounces under gravity --- GravityBallCode/GravityBallCode.pde | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/GravityBallCode/GravityBallCode.pde b/GravityBallCode/GravityBallCode.pde index df2493b..5c55506 100644 --- a/GravityBallCode/GravityBallCode.pde +++ b/GravityBallCode/GravityBallCode.pde @@ -1,16 +1,17 @@ //declare variables -float x, y, velX, velY, diam; +float x, y, velX, velY, diam, gravity; void setup() { //set size of canvas size(800, 600); //initialize variables - x = width/2; - y = height/2; + x = 0; + y = 0; diam = 80; - velX = random(-5, 5); - velY = random(-5, 5); + velX = 0; + velY = 0; + gravity = 1; } void draw() { @@ -21,9 +22,13 @@ void draw() { ellipse(x, y, diam, diam); //add velocity to position + + velY += gravity; 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 @@ -35,4 +40,8 @@ void draw() { } else if (y - diam/2 <= 0) { velY = abs(velY); } + if (y == height - diam/2) { + velY = -abs(velY); + ; + } } \ No newline at end of file From bdc7517c39d573665eed29e28bc892c2580b2f9f Mon Sep 17 00:00:00 2001 From: ewang803 Date: Mon, 9 Nov 2015 13:12:36 -0500 Subject: [PATCH 2/6] Added 30 balls Created an array to make balls Air resistance to keep ball in gravity Force ball to stay at height after bouncing --- GravityBallCode/GravityBallCode.pde | 75 +++++++++++++++++------------ 1 file changed, 44 insertions(+), 31 deletions(-) diff --git a/GravityBallCode/GravityBallCode.pde b/GravityBallCode/GravityBallCode.pde index 5c55506..5de1aed 100644 --- a/GravityBallCode/GravityBallCode.pde +++ b/GravityBallCode/GravityBallCode.pde @@ -1,17 +1,27 @@ //declare variables -float x, y, velX, velY, diam, gravity; +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[] gravity = new float[count]; void setup() { //set size of canvas size(800, 600); //initialize variables - x = 0; - y = 0; - diam = 80; - velX = 0; - velY = 0; - gravity = 1; + for (int i=0; i < count; i++) { + x[i] = 0; + y[i] = 0; + diam[i] = 80; + velX[i] = random(-5, 5); + velY[i] = random(-5, 5); + gravity[i] = 1; + i++; + } } void draw() { @@ -19,29 +29,32 @@ void draw() { background(0); //draw ball - ellipse(x, y, diam, diam); - - //add velocity to position - - velY += gravity; - 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 - } 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 (y + diam/2 >= height) { - velY = -abs(velY); - } else if (y - diam/2 <= 0) { - velY = abs(velY); - } - if (y == height - diam/2) { - velY = -abs(velY); - ; + for (int i=0; i < count; i++) { + ellipse(x[i], y[i], diam[i], diam[i]); + + //add velocity to position + + velY[i] += gravity[i]; + 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 + } 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[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]); + } + if (y[i] == height - diam[i]/2) { + velY[i] = -abs(velY[i]); + ; + } } } \ No newline at end of file From 2ffbba8c920f657e1082797c604cab1d8922c750 Mon Sep 17 00:00:00 2001 From: ewang803 Date: Mon, 9 Nov 2015 13:13:10 -0500 Subject: [PATCH 3/6] Revert "Added 30 balls" This reverts commit bdc7517c39d573665eed29e28bc892c2580b2f9f. --- GravityBallCode/GravityBallCode.pde | 75 ++++++++++++----------------- 1 file changed, 31 insertions(+), 44 deletions(-) diff --git a/GravityBallCode/GravityBallCode.pde b/GravityBallCode/GravityBallCode.pde index 5de1aed..5c55506 100644 --- a/GravityBallCode/GravityBallCode.pde +++ b/GravityBallCode/GravityBallCode.pde @@ -1,27 +1,17 @@ //declare variables -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[] gravity = new float[count]; +float x, y, velX, velY, diam, gravity; void setup() { //set size of canvas size(800, 600); //initialize variables - for (int i=0; i < count; i++) { - x[i] = 0; - y[i] = 0; - diam[i] = 80; - velX[i] = random(-5, 5); - velY[i] = random(-5, 5); - gravity[i] = 1; - i++; - } + x = 0; + y = 0; + diam = 80; + velX = 0; + velY = 0; + gravity = 1; } void draw() { @@ -29,32 +19,29 @@ void draw() { background(0); //draw ball - for (int i=0; i < count; i++) { - ellipse(x[i], y[i], diam[i], diam[i]); - - //add velocity to position - - velY[i] += gravity[i]; - 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 - } 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[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]); - } - if (y[i] == height - diam[i]/2) { - velY[i] = -abs(velY[i]); - ; - } + ellipse(x, y, diam, diam); + + //add velocity to position + + velY += gravity; + 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 + } 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 (y + diam/2 >= height) { + velY = -abs(velY); + } else if (y - diam/2 <= 0) { + velY = abs(velY); + } + if (y == height - diam/2) { + velY = -abs(velY); + ; } } \ No newline at end of file From d6b8a1c03d40e27ce53085fef2e1ec407c606663 Mon Sep 17 00:00:00 2001 From: ewang803 Date: Mon, 9 Nov 2015 13:13:37 -0500 Subject: [PATCH 4/6] Revert "Revert "Added 30 balls"" This reverts commit 2ffbba8c920f657e1082797c604cab1d8922c750. --- GravityBallCode/GravityBallCode.pde | 75 +++++++++++++++++------------ 1 file changed, 44 insertions(+), 31 deletions(-) diff --git a/GravityBallCode/GravityBallCode.pde b/GravityBallCode/GravityBallCode.pde index 5c55506..5de1aed 100644 --- a/GravityBallCode/GravityBallCode.pde +++ b/GravityBallCode/GravityBallCode.pde @@ -1,17 +1,27 @@ //declare variables -float x, y, velX, velY, diam, gravity; +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[] gravity = new float[count]; void setup() { //set size of canvas size(800, 600); //initialize variables - x = 0; - y = 0; - diam = 80; - velX = 0; - velY = 0; - gravity = 1; + for (int i=0; i < count; i++) { + x[i] = 0; + y[i] = 0; + diam[i] = 80; + velX[i] = random(-5, 5); + velY[i] = random(-5, 5); + gravity[i] = 1; + i++; + } } void draw() { @@ -19,29 +29,32 @@ void draw() { background(0); //draw ball - ellipse(x, y, diam, diam); - - //add velocity to position - - velY += gravity; - 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 - } 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 (y + diam/2 >= height) { - velY = -abs(velY); - } else if (y - diam/2 <= 0) { - velY = abs(velY); - } - if (y == height - diam/2) { - velY = -abs(velY); - ; + for (int i=0; i < count; i++) { + ellipse(x[i], y[i], diam[i], diam[i]); + + //add velocity to position + + velY[i] += gravity[i]; + 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 + } 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[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]); + } + if (y[i] == height - diam[i]/2) { + velY[i] = -abs(velY[i]); + ; + } } } \ No newline at end of file From d0e9cd060ffbc36d0385ebd2d9af75a2ee3103ed Mon Sep 17 00:00:00 2001 From: ewang803 Date: Tue, 10 Nov 2015 12:43:17 -0500 Subject: [PATCH 5/6] mouse reactivity --- GravityBallCode/GravityBallCode.pde | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/GravityBallCode/GravityBallCode.pde b/GravityBallCode/GravityBallCode.pde index 5de1aed..79f4227 100644 --- a/GravityBallCode/GravityBallCode.pde +++ b/GravityBallCode/GravityBallCode.pde @@ -19,7 +19,7 @@ void setup() { diam[i] = 80; velX[i] = random(-5, 5); velY[i] = random(-5, 5); - gravity[i] = 1; + gravity[i] = .5; i++; } } @@ -30,13 +30,16 @@ void draw() { //draw ball for (int i=0; i < count; i++) { + noStroke(); + fill(x[i], y[i], random(255), 70); ellipse(x[i], y[i], diam[i], diam[i]); + //add velocity to position velY[i] += gravity[i]; velY[i] *= 0.99; - + x[i] += velX[i]; y[i] += velY[i]; @@ -56,5 +59,9 @@ void draw() { velY[i] = -abs(velY[i]); ; } + if (dist(x[i], y[i], mouseX, mouseY) <= diam[i]/2) { + fill(255); + ellipse(x[i], y[i], 2*diam[i], 2*diam[i]); + } } } \ No newline at end of file From 5ce427e80d9d2593ac880256e983cf9df4870ba8 Mon Sep 17 00:00:00 2001 From: ewang803 Date: Tue, 10 Nov 2015 13:12:46 -0500 Subject: [PATCH 6/6] Additional spices mouse near makes ball bigger, duck spotlight, and bounce added color --- GravityBallCode/GravityBallCode.pde | 30 ++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/GravityBallCode/GravityBallCode.pde b/GravityBallCode/GravityBallCode.pde index 79f4227..7e5e7f2 100644 --- a/GravityBallCode/GravityBallCode.pde +++ b/GravityBallCode/GravityBallCode.pde @@ -31,7 +31,8 @@ void draw() { //draw ball for (int i=0; i < count; i++) { noStroke(); - fill(x[i], y[i], random(255), 70); + fill(x[i], y[i], 900, 80); + colorMode(HSB, 900); ellipse(x[i], y[i], diam[i], diam[i]); @@ -62,6 +63,33 @@ void draw() { if (dist(x[i], y[i], mouseX, mouseY) <= diam[i]/2) { fill(255); ellipse(x[i], y[i], 2*diam[i], 2*diam[i]); + translate (-27, -20); + fill(235, 235, 0); + stroke(240, 230, 140); + ellipse(x[i], y[i], 50, 50); + + fill(235, 235, 0); + stroke(240, 230, 140); + arc(x[i]+50, y[i]+20, 70, 75, 0, PI); + + fill(235, 235, 0); + stroke(0, 0, 0); + arc(x[i]+50, y[i]+35, 25, 20, 0, PI); + + noStroke(); + fill(255, 162, 0); + triangle(x[i]-20, y[i]+15, x[i]-35, y[i]+10, x[i]-25, y[i]); + + fill(235, 235, 0); + stroke(240, 230, 140); + ellipse(x[i], y[i], 50, 50); + + fill(0, 0, 0); + noStroke(); + ellipse(x[i]-7, y[i]-3, 5, 5); + velY[i]=-15; + resetMatrix(); } + } } \ No newline at end of file