From 0750ae6fcb15c074a2bb33296df1eb4374facd6a Mon Sep 17 00:00:00 2001 From: Sconnda Date: Tue, 10 Nov 2015 13:12:10 -0500 Subject: [PATCH 1/2] Synced another directory --- README.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/README.md b/README.md index 6b5a058..905e628 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,3 @@ * On this branch, modify your code to have 30 of these gravity balls (or some other number in that range). Once again, remember to commit and sync * Merge this new branch back in to the master branch * You're done for the day! - - -##Acceleration -Just as _velocity_ is change in position over time, _acceleration_ is change in _velocity_ over time. Creating acceleration is going to be very similar to creating velocity. I recommend a variable - perhaps call it "gravity"? I also recommend a small value - perhaps somewhere around .1 From 639e9bde742bd9c0914518cedffedc964eee8993 Mon Sep 17 00:00:00 2001 From: Sconnda Date: Tue, 10 Nov 2015 13:15:50 -0500 Subject: [PATCH 2/2] Added my changes Sorry, I cloned the original file into the class repository. I didn't have permission to push my requests, so I cloned again and copied the file --- GravityBallCode/GravityBallCode.pde | 76 +++++++++++++++++++---------- 1 file changed, 50 insertions(+), 26 deletions(-) diff --git a/GravityBallCode/GravityBallCode.pde b/GravityBallCode/GravityBallCode.pde index df2493b..325ae2e 100644 --- a/GravityBallCode/GravityBallCode.pde +++ b/GravityBallCode/GravityBallCode.pde @@ -1,38 +1,62 @@ //declare variables -float x, y, velX, velY, diam; +int num = 100; +float [] x = new float[num]; +float [] y = new float[num]; +float [] velX = new float[num]; +float [] velY = new float[num]; +float [] diam = new float[num]; +color [] c = new color[num]; +float g = 1; void setup() { - //set size of canvas + //set size of canvas and background size(800, 600); + background(0); //initialize variables - x = width/2; - y = height/2; - diam = 80; - velX = random(-5, 5); - velY = random(-5, 5); + for(int i = 0; i < num; i++) { + c[i] = color(random(128,255),128); + diam[i] = random(20,50); + x[i] = random(diam[i]/2,width-diam[i]/2); + y[i] = random(diam[i]/2,height-diam[i]/2); + velX[i] = -2+round(random(0,1))*random(2, 10); //make sure velocity is never too small or 0 + velY[i] = -2+round(random(0,1))*random(2, 10); //make sure velocity is never too small or 0 + } } void draw() { - //draw background to cover previous frame - background(0); + //draw a translucent rectangle to cover previous frame + fill(0,100); + rect(-1,-1,width+2,height+2); + + strokeWeight(5); + stroke(255,0,0); + line(pmouseX,pmouseY,mouseX,mouseY); //draw a streak + + noStroke(); + for(int i = 0; i < num; i++) { + if(dist(x[i], round(y[i]), mouseX, mouseY) <= diam[i]/2) { + c[i] = color(255,0,0); //color the balls that the mouse touches red + } else { + c[i] = color(random(128,255),128); + } + + //draw ball + fill(c[i]); + ellipse(x[i], y[i], diam[i], diam[i]); - //draw ball - ellipse(x, y, diam, diam); - - //add velocity to position - 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); + //add velocity to position + x[i] += velX[i]; + y[i] += velY[i]; + + //bounce ball if it hits walls + if (x[i] + diam[i]/2 >= width || x[i] - diam[i]/2 <= 0) { + velX[i] *= -1; //if the ball hits the side wall, assign x velocity the negative version of itself + } + if (y[i] + diam[i]/2 >= height || y[i] - diam[i]/2 <= 0) { + velY[i] *= -1; //if the ball hits the top or bottom; assign x velocity the negative version of itself + } else { + velY[i] += g; + } } } \ No newline at end of file