From d4794c34b3b57a7a80638ec025c3371a45e25318 Mon Sep 17 00:00:00 2001 From: thermodynamicallyunfavored Date: Thu, 12 Nov 2015 14:41:34 -0500 Subject: [PATCH 1/7] pvectors changed it to pvectors --- BouncingWithVectors/BouncingWithVectors.pde | 39 +++++++++++---------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/BouncingWithVectors/BouncingWithVectors.pde b/BouncingWithVectors/BouncingWithVectors.pde index 2683b50..d33de69 100644 --- a/BouncingWithVectors/BouncingWithVectors.pde +++ b/BouncingWithVectors/BouncingWithVectors.pde @@ -1,16 +1,18 @@ //declare variables -float x, y, velX, velY, diam; +//float loc.loc.x, loc.y, velloc.loc.x, vel.y, diam; +float diam = 80; +//float loc.loc.x,loc.y +PVector loc, vel; // replaces loc.loc.x,loc.y, velloc.loc.x, vel.y, + 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); + loc = new PVector (width/2, height/2); + vel = new PVector (random(-5, 5), random(-5, 5)); + } void draw() { @@ -18,20 +20,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; + //add velocitloc.y to position + 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 loc.x velocitloc.y 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 loc.x velocitloc.y 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 562e3286dea6427b59a71490ecae49bfdf2aab58 Mon Sep 17 00:00:00 2001 From: thermodynamicallyunfavored Date: Thu, 12 Nov 2015 14:51:30 -0500 Subject: [PATCH 2/7] added pvectors together --- BouncingWithVectors/BouncingWithVectors.pde | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/BouncingWithVectors/BouncingWithVectors.pde b/BouncingWithVectors/BouncingWithVectors.pde index d33de69..daa9295 100644 --- a/BouncingWithVectors/BouncingWithVectors.pde +++ b/BouncingWithVectors/BouncingWithVectors.pde @@ -1,6 +1,7 @@ //declare variables //float loc.loc.x, loc.y, velloc.loc.x, vel.y, diam; float diam = 80; + //float loc.loc.x,loc.y PVector loc, vel; // replaces loc.loc.x,loc.y, velloc.loc.x, vel.y, @@ -11,7 +12,7 @@ void setup() { //initialize variables loc = new PVector (width/2, height/2); - vel = new PVector (random(-5, 5), random(-5, 5)); + vel = PVector.random2D(); } @@ -23,8 +24,7 @@ void draw() { ellipse(loc.x, loc.y, diam, diam); //add velocitloc.y 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) { From 9e1bf1c0ce8a255507e448867af7c896b84f6b64 Mon Sep 17 00:00:00 2001 From: thermodynamicallyunfavored Date: Mon, 16 Nov 2015 14:09:29 -0500 Subject: [PATCH 3/7] added arrays added arrays to code --- BouncingWithVectors/BouncingWithVectors.pde | 61 ++++++++++++--------- 1 file changed, 35 insertions(+), 26 deletions(-) diff --git a/BouncingWithVectors/BouncingWithVectors.pde b/BouncingWithVectors/BouncingWithVectors.pde index daa9295..ef57187 100644 --- a/BouncingWithVectors/BouncingWithVectors.pde +++ b/BouncingWithVectors/BouncingWithVectors.pde @@ -1,40 +1,49 @@ +int count = 80; //makes 60 balls + //declare variables -//float loc.loc.x, loc.y, velloc.loc.x, vel.y, diam; -float diam = 80; -//float loc.loc.x,loc.y -PVector loc, vel; // replaces loc.loc.x,loc.y, velloc.loc.x, vel.y, +float [] diam = new float [count]; //diameter + + +//float loc.x, loc.y +PVector [] loc = new PVector [count]; +PVector [] vel = new PVector [count]; // replaces x,y, vel[i]x, vel[i]y, void setup() { //set size of canvas size(800, 600); - - //initialize variables - loc = new PVector (width/2, height/2); - vel = PVector.random2D(); - + for (int i = 0; i < count; i ++) { //for arrays + //initialize variables + loc [i] = new PVector (random(350,450), height/2); //starts ellipse off in a random position from 350-450, middle of screen + vel[i] = PVector.random2D(); //gives speed magnitude of one + vel[i].mult(random(5,8)); //increased speed + diam [i] = random(3,88); //diameter + } } void draw() { //draw background to cover previous frame background(0); - - //draw ball - ellipse(loc.x, loc.y, diam, diam); - - //add velocitloc.y to position - 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 loc.x velocitloc.y 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 loc.x velocitloc.y 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); + for (int i = 0; i < count; i ++) { //for arrays + strokeWeight(3); // increased stroke weight + stroke(random(206), random(235), random(245)); //gives random stroke + //draw ball + ellipse(loc[i].x, loc[i].y, diam[i], diam[i]); + + //add vel[i]ocitloc.y to position + 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 loc.x vel[i]ocitloc.y 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 loc.x vel[i]ocitloc.y 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 8deec2a2b68be82b37bec38c2e80e36d659bd7a6 Mon Sep 17 00:00:00 2001 From: thermodynamicallyunfavored Date: Wed, 18 Nov 2015 13:43:48 -0500 Subject: [PATCH 4/7] fixed wanderer --- Wanderer/Wanderer.pde | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/Wanderer/Wanderer.pde b/Wanderer/Wanderer.pde index b6ce247..868d594 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 aa143cc4e4350576ca2789c71542fbd1ce217b03 Mon Sep 17 00:00:00 2001 From: thermodynamicallyunfavored Date: Wed, 18 Nov 2015 13:51:21 -0500 Subject: [PATCH 5/7] some changes added arrays, pvectors --- Wanderer/Wanderer.pde | 53 +++++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/Wanderer/Wanderer.pde b/Wanderer/Wanderer.pde index 868d594..71e7f20 100644 --- a/Wanderer/Wanderer.pde +++ b/Wanderer/Wanderer.pde @@ -1,38 +1,43 @@ +int count = 8; + //declare variables -float x, y, velX, velY, diam; +PVector [] loc = new PVector [count]; +; +PVector [] vel = new PVector [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); + for (int i = 0; i < count; i++) { + //initialize variables + loc [i] = new PVector (width/2, height/2); + diam [i] = 80; + vel [i] = PVector.random2D(); + vel[i].mult(5); + } } void draw() { //draw background to cover previous frame background(0); + for (int i = 0; i < count; i ++) { + //draw ball + ellipse(loc[i].x, loc[i].y, diam[i], diam[i]); - //draw ball - ellipse(x, y, diam, diam); + //add velocity to position + loc[i].add(vel[i]); - //add velocity to position - x += velX; - y += velY; - - //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 ; + //wrap the ball's position + if (loc[i].x >= width) { + loc[i].x = 0; + } else if (loc[i].x <= 0) { + loc[i].x = width ; + } + 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 7e7c8d7a6dd0dd67331e30984a22849ea73d9f0d Mon Sep 17 00:00:00 2001 From: thermodynamicallyunfavored Date: Wed, 18 Nov 2015 14:35:16 -0500 Subject: [PATCH 6/7] wanderer wanders added acceleration, limited velocity, need to figure out array issue --- Wanderer/Wanderer.pde | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/Wanderer/Wanderer.pde b/Wanderer/Wanderer.pde index 71e7f20..285e808 100644 --- a/Wanderer/Wanderer.pde +++ b/Wanderer/Wanderer.pde @@ -2,8 +2,8 @@ int count = 8; //declare variables PVector [] loc = new PVector [count]; -; PVector [] vel = new PVector [count]; +PVector [] a = new PVector [count]; float [] diam = new float [count]; void setup() { @@ -11,22 +11,31 @@ void setup() { size(800, 600); for (int i = 0; i < count; i++) { //initialize variables - loc [i] = new PVector (width/2, height/2); - diam [i] = 80; - vel [i] = PVector.random2D(); - vel[i].mult(5); + loc [i] = new PVector (random(width), random(height)); + diam [i] = random(10, 80); + vel[i] = PVector.random2D(); + vel[i].mult(1); } } void draw() { - //draw background to cover previous frame - background(0); for (int i = 0; i < count; i ++) { + + //draw background to cover previous frame + background(204, 240, 229); + stroke(random(237), random(250), random(246)); + strokeWeight(3); + //draw ball ellipse(loc[i].x, loc[i].y, diam[i], diam[i]); + a[i] = PVector.random2D(); + a[i].mult(0.1); //add velocity to position loc[i].add(vel[i]); + vel[i].add(a[i]); + vel[i].limit(10); //limits velocity to + //wrap the ball's position if (loc[i].x >= width) { From ec1bba4f60a6660e8acf20589829169e16a09319 Mon Sep 17 00:00:00 2001 From: thermodynamicallyunfavored Date: Wed, 18 Nov 2015 14:40:47 -0500 Subject: [PATCH 7/7] only one ball shows up --- Wanderer/Wanderer.pde | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Wanderer/Wanderer.pde b/Wanderer/Wanderer.pde index 285e808..29ffeac 100644 --- a/Wanderer/Wanderer.pde +++ b/Wanderer/Wanderer.pde @@ -14,13 +14,14 @@ void setup() { loc [i] = new PVector (random(width), random(height)); diam [i] = random(10, 80); vel[i] = PVector.random2D(); - vel[i].mult(1); + vel[i].mult(1); + } } void draw() { for (int i = 0; i < count; i ++) { - + println("x" + i + " = " + loc[i].x + ", y" + i + " = " + loc[i].y); //draw background to cover previous frame background(204, 240, 229); stroke(random(237), random(250), random(246));