From 625ab53bdc9e80046fa40af620d4a51245047c38 Mon Sep 17 00:00:00 2001 From: JoeHom73 Date: Thu, 12 Nov 2015 14:38:36 -0500 Subject: [PATCH 1/7] added vectors --- BouncingWithVectors/BouncingWithVectors.pde | 34 ++++++++++----------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/BouncingWithVectors/BouncingWithVectors.pde b/BouncingWithVectors/BouncingWithVectors.pde index 2683b50..69f4197 100644 --- a/BouncingWithVectors/BouncingWithVectors.pde +++ b/BouncingWithVectors/BouncingWithVectors.pde @@ -1,16 +1,15 @@ //declare variables -float x, y, velX, velY, diam; - +float diam; +PVector loc; +PVector vel = new PVector(2, 2); void setup() { //set size of canvas size(800, 600); //initialize variables - x = width/2; - y = height/2; + loc = new PVector(width/2, height/2); diam = 80; - velX = random(-5, 5); - velY = random(-5, 5); + vel = new PVector(random(-5, 5), random(-5,5)); } void draw() { @@ -18,20 +17,21 @@ void draw() { background(0); //draw ball - ellipse(x, y, diam, diam); + ellipse(loc.x, loc.y, diam, diam); //add velocity to position - x += velX; - y += velY; + loc.x += vel.x; + loc.y += vel.y; //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 (loc.x + diam/2 >= width) { + vel.x = -abs(vel.x); //if the ball hits the right wall, assign x velocity the negative version of itself + } else if (loc.x - diam/2 <= 0) { + vel.x = abs(vel.x); //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 (loc.y + diam/2 >= height) { + vel.y = -abs(vel.y); + } else if (loc.y - diam/2 <= 0) { + vel.y = abs(vel.y); } +} \ No newline at end of file From f82cc7ff2b0ee1858956cd8b733e157c916a1fa1 Mon Sep 17 00:00:00 2001 From: JoeHom73 Date: Thu, 12 Nov 2015 14:51:49 -0500 Subject: [PATCH 2/7] stuff --- BouncingWithVectors/BouncingWithVectors.pde | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/BouncingWithVectors/BouncingWithVectors.pde b/BouncingWithVectors/BouncingWithVectors.pde index 69f4197..c823301 100644 --- a/BouncingWithVectors/BouncingWithVectors.pde +++ b/BouncingWithVectors/BouncingWithVectors.pde @@ -9,7 +9,8 @@ void setup() { //initialize variables loc = new PVector(width/2, height/2); diam = 80; - vel = new PVector(random(-5, 5), random(-5,5)); + vel = PVector.random2D(); + } void draw() { @@ -20,9 +21,9 @@ void draw() { ellipse(loc.x, loc.y, diam, diam); //add velocity to position - loc.x += vel.x; - loc.y += vel.y; - + //loc.x += vel.x; + //loc.y += vel.y; + loc.add(vel); //bounce ball if it hits walls if (loc.x + diam/2 >= width) { vel.x = -abs(vel.x); //if the ball hits the right wall, assign x velocity the negative version of itself From 382683b11bfc7d2d564ded25e7e5a02100c144d1 Mon Sep 17 00:00:00 2001 From: JoeHom73 Date: Mon, 16 Nov 2015 14:46:47 -0500 Subject: [PATCH 3/7] vectors added vectors and arrays making cool shapes --- BouncingWithVectors/BouncingWithVectors.pde | 60 ++++++++++++--------- 1 file changed, 34 insertions(+), 26 deletions(-) diff --git a/BouncingWithVectors/BouncingWithVectors.pde b/BouncingWithVectors/BouncingWithVectors.pde index c823301..147f442 100644 --- a/BouncingWithVectors/BouncingWithVectors.pde +++ b/BouncingWithVectors/BouncingWithVectors.pde @@ -1,38 +1,46 @@ //declare variables -float diam; -PVector loc; -PVector vel = new PVector(2, 2); +float g; +int count = 3000; +PVector[] loc = new PVector [count]; +float []diam = new float [count]; +PVector[] vel = new PVector [count]; +float []x = new float [count]; void setup() { //set size of canvas + frameRate(150); size(800, 600); - - //initialize variables - loc = new PVector(width/2, height/2); - diam = 80; - vel = PVector.random2D(); - + for (int i=0; i < count; i++) { + //initialize variables + loc[i] = new PVector(width/2, height/2); + diam[i] = random(4, 6); + vel[i] = PVector.random2D(); + g =.1; + } } void draw() { //draw background to cover previous frame background(0); + for (int i=0; i < count; i++) { + //draw ball + fill(255, 0, 0); + ellipse(loc[i].x, loc[i].y, diam[i], diam[i]); - //draw ball - ellipse(loc.x, loc.y, diam, diam); - - //add velocity to position - //loc.x += vel.x; - //loc.y += vel.y; - loc.add(vel); - //bounce ball if it hits walls - if (loc.x + diam/2 >= width) { - vel.x = -abs(vel.x); //if the ball hits the right wall, assign x velocity the negative version of itself - } else if (loc.x - diam/2 <= 0) { - vel.x = abs(vel.x); //if the ball hits the left wall, assign x velocity the positive version of itself - } - if (loc.y + diam/2 >= height) { - vel.y = -abs(vel.y); - } else if (loc.y - diam/2 <= 0) { - vel.y = abs(vel.y); + //add velocity to position + //loc.x += vel.x; + //loc.y += vel.y; + loc[i].add(vel[i]); + //bounce ball if it hits walls + if (loc[i].x + diam[i]/2 >= width) { + vel[i].x = -abs(vel[i].x); //if the ball hits the right wall, assign x velocity the negative version of itself + + } else if (loc[i].x - diam[i]/2 <= 0) { + vel[i].x = abs(vel[i].x); //if the ball hits the left wall, assign x velocity the positive version of itself + } + if (loc[i].y + diam[i]/2 >= height) { + vel[i].y = -abs(vel[i].y); + } else if (loc[i].y - diam[i]/2 <= 0) { + vel[i].y = abs(vel[i].y); + } } } \ No newline at end of file From 278b84911d13cc139b1fd211836fe13bb545a95d Mon Sep 17 00:00:00 2001 From: JoeHom73 Date: Wed, 18 Nov 2015 13:44:22 -0500 Subject: [PATCH 4/7] fixed wanderers --- Wanderer/Wanderer.pde | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/Wanderer/Wanderer.pde b/Wanderer/Wanderer.pde index b6ce247..df3dbcc 100644 --- a/Wanderer/Wanderer.pde +++ b/Wanderer/Wanderer.pde @@ -25,13 +25,14 @@ void draw() { y += velY; //wrap the ball's position - if (x + diam/2 >= width) { - x = -diam/2; - } else if (x - diam/2 <= 0) { - x = width + diam/2; + if (x >= width) { + x = 0; + } else if (x <= 0) { + x = width; } - if (y + diam/2 >= height) { - y = -diam/2; - } else if (y - diam/2 <= 0) { - y = height + diam/2; + if (y >= height) { + y = 0; + } else if (y <= 0) { + y = height; } +} \ No newline at end of file From 6347538538551f581ca483b8fcca61ae55b77f1f Mon Sep 17 00:00:00 2001 From: JoeHom73 Date: Wed, 18 Nov 2015 14:10:39 -0500 Subject: [PATCH 5/7] arrays + spazing out balls --- Wanderer/Wanderer.pde | 59 +++++++++++++++++++++++++------------------ 1 file changed, 35 insertions(+), 24 deletions(-) diff --git a/Wanderer/Wanderer.pde b/Wanderer/Wanderer.pde index df3dbcc..b265fee 100644 --- a/Wanderer/Wanderer.pde +++ b/Wanderer/Wanderer.pde @@ -1,38 +1,49 @@ //declare variables -float x, y, velX, velY, diam; - +int count = 2; +PVector[] loc = new PVector [count]; +float []diam = new float [count]; +PVector[] vel = new PVector [count]; +//float []x = 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); + for (int i=0; i < count; i++) { + //initialize variables + loc[i] = new PVector(width/2, height/2); + diam[i] = 30; + vel[i] = PVector.random2D().mult(3); + background(0); + + + } } void draw() { //draw background to cover previous frame - background(0); - + //background(0); +for (int i=0; i < count; i++) { //draw ball - ellipse(x, y, diam, diam); + noStroke(); + fill(random(255), random(255), random(255)); + vel[i] = PVector.random2D().mult(random(8)); + ellipse(loc[i].x, loc[i].y, diam[i], diam[i]); //add velocity to position - x += velX; - y += velY; + loc[i].add(vel[i]); //wrap the ball's position - if (x >= width) { - x = 0; - } else if (x <= 0) { - x = width; - } - if (y >= height) { - y = 0; - } else if (y <= 0) { - y = height; - } + + if (loc[i].x >= width) { + loc[i].x = 0; //if the ball hits the right wall go to left wall + + } else if (loc[i].x <= 0) { + loc[i].x = width; //if the ball hits the left wall go to right wall + } + if (loc[i].y >= height) { + loc[i].y = 0; + } else if (loc[i].y <= 0) { + loc[i].y = height ; + } +} } \ No newline at end of file From bf0ff701f7204c8e25b371e56e7cede8dcca2819 Mon Sep 17 00:00:00 2001 From: JoeHom73 Date: Wed, 18 Nov 2015 14:33:51 -0500 Subject: [PATCH 6/7] acceleration --- Wanderer/Wanderer.pde | 50 ++++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/Wanderer/Wanderer.pde b/Wanderer/Wanderer.pde index b265fee..548f3c5 100644 --- a/Wanderer/Wanderer.pde +++ b/Wanderer/Wanderer.pde @@ -1,42 +1,48 @@ //declare variables -int count = 2; +int count = 5; +int colors = 0; +PVector []acc = new PVector [count]; PVector[] loc = new PVector [count]; float []diam = new float [count]; PVector[] vel = new PVector [count]; + //float []x = new float [count]; void setup() { //set size of canvas - + size(800, 600); for (int i=0; i < count; i++) { //initialize variables loc[i] = new PVector(width/2, height/2); - diam[i] = 30; - vel[i] = PVector.random2D().mult(3); - background(0); - - + diam[i] = 50; + vel[i] =PVector.random2D(); + vel[i].mult(1); + acc[i] = PVector.random2D(); + acc[i].mult(.001); + background(0); } } void draw() { //draw background to cover previous frame - //background(0); -for (int i=0; i < count; i++) { - //draw ball - noStroke(); - fill(random(255), random(255), random(255)); - vel[i] = PVector.random2D().mult(random(8)); - ellipse(loc[i].x, loc[i].y, diam[i], diam[i]); + background(0); + for (int i=0; i < count; i++) { + //draw ball + + vel[i].add(acc[i]); + noStroke(); + //. fill(random(255), random(255), random(255)); + //vel[i] = PVector.random2D().mult(random(8)); + ellipse(loc[i].x, loc[i].y, diam[i], diam[i]); - //add velocity to position - loc[i].add(vel[i]); + //add velocity to position + loc[i].add(vel[i]); + vel[i].limit(5); - //wrap the ball's position - - if (loc[i].x >= width) { - loc[i].x = 0; //if the ball hits the right wall go to left wall - + //wrap the ball's position + + if (loc[i].x >= width) { + loc[i].x = 0; //if the ball hits the right wall go to left wall } else if (loc[i].x <= 0) { loc[i].x = width; //if the ball hits the left wall go to right wall } @@ -45,5 +51,5 @@ for (int i=0; i < count; i++) { } else if (loc[i].y <= 0) { loc[i].y = height ; } -} + } } \ No newline at end of file From 4286c5a169511d6e4399d777eb509a9a911fc701 Mon Sep 17 00:00:00 2001 From: JoeHom73 Date: Wed, 18 Nov 2015 14:51:24 -0500 Subject: [PATCH 7/7] finish --- Wanderer/Wanderer.pde | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/Wanderer/Wanderer.pde b/Wanderer/Wanderer.pde index 548f3c5..8450a69 100644 --- a/Wanderer/Wanderer.pde +++ b/Wanderer/Wanderer.pde @@ -1,5 +1,5 @@ //declare variables -int count = 5; +int count = 15; int colors = 0; PVector []acc = new PVector [count]; PVector[] loc = new PVector [count]; @@ -19,37 +19,44 @@ void setup() { vel[i].mult(1); acc[i] = PVector.random2D(); acc[i].mult(.001); - background(0); + background(0, 0, 0, 10); } } void draw() { //draw background to cover previous frame - background(0); + // background(0, 0,0, 10); +fill(frameCount%255, 0, 0); +// background(0); for (int i=0; i < count; i++) { //draw ball - + acc[i] = PVector.random2D(); + acc[i].mult(.3); vel[i].add(acc[i]); noStroke(); - //. fill(random(255), random(255), random(255)); + //. fill(random(255), random(255), random(255)); //vel[i] = PVector.random2D().mult(random(8)); ellipse(loc[i].x, loc[i].y, diam[i], diam[i]); //add velocity to position loc[i].add(vel[i]); - vel[i].limit(5); + vel[i].limit(3); //wrap the ball's position if (loc[i].x >= width) { - loc[i].x = 0; //if the ball hits the right wall go to left wall + loc[i].x = width/2; //if the ball hits the right wall go to left wall + loc[i].y = height/2 ; } else if (loc[i].x <= 0) { - loc[i].x = width; //if the ball hits the left wall go to right wall + loc[i].x = width/2; //if the ball hits the left wall go to right wall + loc[i].y = height/2 ; } if (loc[i].y >= height) { - loc[i].y = 0; + loc[i].y = height/2; + loc[i].x = width/2; } else if (loc[i].y <= 0) { - loc[i].y = height ; + loc[i].y = height/2 ; + loc[i].x = width/2; } } } \ No newline at end of file