From 9465c1e70dc40b5f3f6240e1bf49abac50c0bf5b Mon Sep 17 00:00:00 2001 From: JoeHom73 Date: Wed, 11 Nov 2015 14:07:37 -0500 Subject: [PATCH 1/4] creating arrays little guy + lots of gravity balls --- GravityBallCode/GravityBallCode.pde | 90 +++++++++++++++++++++-------- 1 file changed, 65 insertions(+), 25 deletions(-) diff --git a/GravityBallCode/GravityBallCode.pde b/GravityBallCode/GravityBallCode.pde index df2493b..7c93d26 100644 --- a/GravityBallCode/GravityBallCode.pde +++ b/GravityBallCode/GravityBallCode.pde @@ -1,38 +1,78 @@ //declare variables -float x, y, velX, velY, diam; - +float g; +int count = 8000; +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]; 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); + size(800, 600); + for (int i=0; i < count; i++) { + //initialize variables + x[i] = width/2; + y[i] = height/2; + diam[i] = 5; + velX[i] = random(5); + velY[i]= random(10); + g =.1; + } } void draw() { //draw background to cover previous frame background(0); + + + for (int i=0; i < count; i++) { //for statement adding arrays - //draw ball - ellipse(x, y, diam, diam); + //draw ball + velY[i]= velY[i] + g; //adding gravity + fill(255, 0, 0); //red + noStroke(); //no line + ellipse(x[i], y[i], diam[i], diam[i]); //draw ellipse - //add velocity to position - x += velX; - y += velY; + //add velocity to position + x[i] += velX[i]; + y[i] += velY[i]; - //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); + + + //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 + velY[i] = abs(velY[i])*2; + } 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 + velY[i] = abs(velY[i])*2; + } + if (y[i] + diam[i]/2 >= height) { //bounce at bottom + velY[i] = -abs(velY[i])*.65; // reduce velY + } else if (y[i] - diam[i]/2 <= 0) { //bounce at top + velY[i] = abs(velY[i]); + } + if (y[i] + diam[i]/2 >= height && velY[i] > 0) { //slowing velY at botom + velY[i] = 0; + g = 0; + } + if (y[i] + diam[i]/2 >= height && velY[i] > 0 && velX[i] > 0) { //slowing velX at bottom + velY[i] = 0; + g=0; + velX[i] = velX[i] *.5; + } + if (y[i] > height+2) { + y[i]= height -1; + velX[i]= velX[i]*.25; + } } -} \ No newline at end of file + fill(255); + ellipse(400, 300, 75, 75); + ellipse(400, 350, 65,150); + fill(0); + ellipse(375, 305, 10, 10); + ellipse(410, 305, 10, 10); + ellipse(390, 315, 25, 5); +} + \ No newline at end of file From de9ff222133a7173a4ea140b0c176cee43fc8efd Mon Sep 17 00:00:00 2001 From: JoeHom73 Date: Wed, 11 Nov 2015 14:22:33 -0500 Subject: [PATCH 2/4] more edits --- GravityBallCode/GravityBallCode.pde | 34 +++++++++++++++++------------ 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/GravityBallCode/GravityBallCode.pde b/GravityBallCode/GravityBallCode.pde index 7c93d26..c3ae1ef 100644 --- a/GravityBallCode/GravityBallCode.pde +++ b/GravityBallCode/GravityBallCode.pde @@ -14,23 +14,25 @@ void setup() { //initialize variables x[i] = width/2; y[i] = height/2; - diam[i] = 5; - velX[i] = random(5); + diam[i] = 8; + velX[i] = random(-5, 5); velY[i]= random(10); g =.1; + ellipse(375, 305, 10, 10); + ellipse(410, 305, 10, 10); } } void draw() { //draw background to cover previous frame background(0); - - + + for (int i=0; i < count; i++) { //for statement adding arrays //draw ball velY[i]= velY[i] + g; //adding gravity - fill(255, 0, 0); //red + fill(255, 0, random(0, 25)); //red noStroke(); //no line ellipse(x[i], y[i], diam[i], diam[i]); //draw ellipse @@ -49,7 +51,7 @@ void draw() { velY[i] = abs(velY[i])*2; } if (y[i] + diam[i]/2 >= height) { //bounce at bottom - velY[i] = -abs(velY[i])*.65; // reduce velY + velY[i] = -abs(velY[i])*.65; // reduce velY } else if (y[i] - diam[i]/2 <= 0) { //bounce at top velY[i] = abs(velY[i]); } @@ -62,17 +64,21 @@ void draw() { g=0; velX[i] = velX[i] *.5; } - if (y[i] > height+2) { + if (y[i] > height+2) { //keeps balls from going off screen y[i]= height -1; velX[i]= velX[i]*.25; } } - fill(255); + fill(255); ellipse(400, 300, 75, 75); - ellipse(400, 350, 65,150); + ellipse(400, 350, 65, 150); fill(0); - ellipse(375, 305, 10, 10); - ellipse(410, 305, 10, 10); - ellipse(390, 315, 25, 5); -} - \ No newline at end of file + stroke(50); + strokeWeight(5); + line(365, 305, 380, 305); + line(400, 305, 415, 305); + // ellipse(375, 305, 10, 10); + // ellipse(410, 305, 10, 10); + strokeWeight(2); + ellipse(390, 315, 25, 5); +} \ No newline at end of file From 2b78c892d12edfc69adf41a8588337bcf79586dd Mon Sep 17 00:00:00 2001 From: JoeHom73 Date: Wed, 11 Nov 2015 14:41:06 -0500 Subject: [PATCH 3/4] fun changes --- GravityBallCode/GravityBallCode.pde | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/GravityBallCode/GravityBallCode.pde b/GravityBallCode/GravityBallCode.pde index c3ae1ef..82870bc 100644 --- a/GravityBallCode/GravityBallCode.pde +++ b/GravityBallCode/GravityBallCode.pde @@ -1,6 +1,6 @@ //declare variables float g; -int count = 8000; +int count = 9880; float []x = new float [count]; float []y= new float [count]; float []velX = new float [count]; @@ -14,7 +14,7 @@ void setup() { //initialize variables x[i] = width/2; y[i] = height/2; - diam[i] = 8; + diam[i] = random(8); velX[i] = random(-5, 5); velY[i]= random(10); g =.1; @@ -27,7 +27,7 @@ void draw() { //draw background to cover previous frame background(0); - +mouseClicked(); { for (int i=0; i < count; i++) { //for statement adding arrays //draw ball @@ -69,6 +69,7 @@ void draw() { velX[i]= velX[i]*.25; } } + } fill(255); ellipse(400, 300, 75, 75); ellipse(400, 350, 65, 150); From ef0e5d24c2dbb891923043979a380d765b360bf2 Mon Sep 17 00:00:00 2001 From: JoeHom73 Date: Thu, 12 Nov 2015 13:35:01 -0500 Subject: [PATCH 4/4] little change --- GravityBallCode/GravityBallCode.pde | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/GravityBallCode/GravityBallCode.pde b/GravityBallCode/GravityBallCode.pde index 82870bc..1a0e62d 100644 --- a/GravityBallCode/GravityBallCode.pde +++ b/GravityBallCode/GravityBallCode.pde @@ -1,6 +1,6 @@ //declare variables float g; -int count = 9880; +int count = 2880; float []x = new float [count]; float []y= new float [count]; float []velX = new float [count]; @@ -15,8 +15,8 @@ void setup() { x[i] = width/2; y[i] = height/2; diam[i] = random(8); - velX[i] = random(-5, 5); - velY[i]= random(10); + velX[i] = random(-1,1); + velY[i]= random(5); g =.1; ellipse(375, 305, 10, 10); ellipse(410, 305, 10, 10);