From 65205104c90e6e8d5334244eb7459747aca75df7 Mon Sep 17 00:00:00 2001 From: cburns14 Date: Mon, 9 Nov 2015 12:59:11 -0500 Subject: [PATCH 1/2] Added Gravity to Ball --- GravityBallCode/GravityBallCode.pde | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/GravityBallCode/GravityBallCode.pde b/GravityBallCode/GravityBallCode.pde index df2493b..7d5081f 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, grav; void setup() { //set size of canvas @@ -7,22 +7,24 @@ void setup() { //initialize variables x = width/2; - y = height/2; + y = height * .1; diam = 80; velX = random(-5, 5); velY = random(-5, 5); + grav = .3; } void draw() { //draw background to cover previous frame - background(0); +background(0); //draw ball ellipse(x, y, diam, diam); //add velocity to position - x += velX; + velY += grav; y += velY; + //bounce ball if it hits walls if (x + diam/2 >= width) { From 4743dfdd0ba9f4b60921c9cf0964644b9ac4b7ef Mon Sep 17 00:00:00 2001 From: cburns14 Date: Fri, 13 Nov 2015 12:13:59 -0500 Subject: [PATCH 2/2] Changed X values of balls --- GravityBallCode/GravityBallCode.pde | 65 ++++++++++++++++------------- 1 file changed, 37 insertions(+), 28 deletions(-) diff --git a/GravityBallCode/GravityBallCode.pde b/GravityBallCode/GravityBallCode.pde index 7d5081f..d4d8915 100644 --- a/GravityBallCode/GravityBallCode.pde +++ b/GravityBallCode/GravityBallCode.pde @@ -1,40 +1,49 @@ -//declare variables -float x, y, velX, velY, diam, grav; +float[] x = new float[30]; +float[] y = new float[30]; +float[] diam = new float[30]; +float[] velX = new float[30]; +float[] velY = new float[30]; +float[] grav = new float[30]; void setup() { //set size of canvas size(800, 600); + textSize(25); //initialize variables - x = width/2; - y = height * .1; - diam = 80; - velX = random(-5, 5); - velY = random(-5, 5); - grav = .3; + for (int i = 0; i < 30; i++) { + x[i] = random(0, width); + y[i] = height * .1; + diam[i] = 80; + velX[i] = random(-5, 5); + velY[i] = random(-5, 5); + grav[i] = .3; + } } void draw() { //draw background to cover previous frame -background(0); - - //draw ball - ellipse(x, y, diam, diam); - - //add velocity to position - velY += grav; - 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); + background(0); + for (int i = 0; i < 30; i++) { + //draw ball + ellipse(x[i], y[i], diam[i], diam[i]); + //add velocity to position + velY[i] += grav[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]); + } else if (y[i] - diam[i]/2 <= 0) { + velY[i] = abs(velY[i]); + } + if(dist(x[i], y[i], mouseX, mouseY) < (40)){ + fill(random(255), random(255), random(255)); + text("This shouldn't have been as hard as I made it...", 100, 100); + } } } \ No newline at end of file