From 3494c11f4d2a4307de41182d3e5f7d27cd977514 Mon Sep 17 00:00:00 2001 From: lerazodiaz Date: Mon, 16 Nov 2015 13:47:26 -0500 Subject: [PATCH 1/9] added vel & loc vectors --- BouncingWithVectors/BouncingWithVectors.pde | 40 ++++++++++++--------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/BouncingWithVectors/BouncingWithVectors.pde b/BouncingWithVectors/BouncingWithVectors.pde index 2683b50..950de87 100644 --- a/BouncingWithVectors/BouncingWithVectors.pde +++ b/BouncingWithVectors/BouncingWithVectors.pde @@ -1,16 +1,23 @@ //declare variables -float x, y, velX, velY, diam; +float diam; +//float loc.x,loc.y +PVector loc; //replaces loc.x & loc.y + +//float vel.loc.x, vel.loc.y +PVector vel; //replaces vel.loc.x & vel.loc.y void setup() { //set size of canvas size(800, 600); //initialize variables - x = width/2; - y = height/2; + //loc.x = width/2 + //loc.y = height/2 + loc= new PVector(width/2, height/2); diam = 80; - velX = random(-5, 5); - velY = random(-5, 5); + //vel.loc.x= random(-5,5) + //vel.loc.y= random(-5,5) + vel = new PVector (random(-5, 5), random (-5, 5)); } void draw() { @@ -18,20 +25,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 loc.x velocityloc.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 velocityloc.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 cdd1ebe371591c81d99de0d31da1d2c26fa65f91 Mon Sep 17 00:00:00 2001 From: lerazodiaz Date: Mon, 16 Nov 2015 13:50:00 -0500 Subject: [PATCH 2/9] vector add --- BouncingWithVectors/BouncingWithVectors.pde | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/BouncingWithVectors/BouncingWithVectors.pde b/BouncingWithVectors/BouncingWithVectors.pde index 950de87..9bc496e 100644 --- a/BouncingWithVectors/BouncingWithVectors.pde +++ b/BouncingWithVectors/BouncingWithVectors.pde @@ -17,7 +17,7 @@ void setup() { diam = 80; //vel.loc.x= random(-5,5) //vel.loc.y= random(-5,5) - vel = new PVector (random(-5, 5), random (-5, 5)); + vel = PVector.random2D(); } void draw() { @@ -28,8 +28,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) { From 4c4167e040ebdeb91e6ef110af4bddf8613bdd90 Mon Sep 17 00:00:00 2001 From: lerazodiaz Date: Mon, 16 Nov 2015 13:51:13 -0500 Subject: [PATCH 3/9] vector add faster --- BouncingWithVectors/BouncingWithVectors.pde | 1 + 1 file changed, 1 insertion(+) diff --git a/BouncingWithVectors/BouncingWithVectors.pde b/BouncingWithVectors/BouncingWithVectors.pde index 9bc496e..7ad44c2 100644 --- a/BouncingWithVectors/BouncingWithVectors.pde +++ b/BouncingWithVectors/BouncingWithVectors.pde @@ -18,6 +18,7 @@ void setup() { //vel.loc.x= random(-5,5) //vel.loc.y= random(-5,5) vel = PVector.random2D(); + vel.mult(5); } void draw() { From 9028c26ed700a6e346260473c4a0e2790d2aeca0 Mon Sep 17 00:00:00 2001 From: lerazodiaz Date: Mon, 16 Nov 2015 14:47:15 -0500 Subject: [PATCH 4/9] not working array --- BouncingWithVectors/BouncingWithVectors.pde | 56 ++++++++++++--------- 1 file changed, 31 insertions(+), 25 deletions(-) diff --git a/BouncingWithVectors/BouncingWithVectors.pde b/BouncingWithVectors/BouncingWithVectors.pde index 7ad44c2..eaa1a01 100644 --- a/BouncingWithVectors/BouncingWithVectors.pde +++ b/BouncingWithVectors/BouncingWithVectors.pde @@ -1,10 +1,11 @@ //declare variables -float diam; +int count = 20; +float diam ; //float loc.x,loc.y -PVector loc; //replaces loc.x & loc.y +PVector[] loc = new float[count]; //replaces loc.x & loc.y //float vel.loc.x, vel.loc.y -PVector vel; //replaces vel.loc.x & vel.loc.y +PVector[] vel = new float[count]; //replaces vel.loc.x & vel.loc.y void setup() { //set size of canvas @@ -13,35 +14,40 @@ void setup() { //initialize variables //loc.x = width/2 //loc.y = height/2 - loc= new PVector(width/2, height/2); - diam = 80; - //vel.loc.x= random(-5,5) - //vel.loc.y= random(-5,5) - vel = PVector.random2D(); - vel.mult(5); + for (int i = 0; i= width) { - vel.x = -abs(vel.x); //if the ball hits the right wall, assign loc.x velocityloc.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 velocityloc.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); + //bounce ball if it hits walls + if (loc[i].x + diam/2 >= width) { + vel[i].x = -abs(vel[i].x); //if the ball hits the right wall, assign loc.x velocityloc.y the negative version of itself + } else if (loc[i].x - diam/2 <= 0) { + vel[i].x = abs(vel[i].x); //if the ball hits the left wall, assign loc.x velocityloc.y the positive version of itself + } + if (loc[i].y + diam/2 >= height) { + vel[i].y = -abs(vel[i].y); + } else if (loc[i].y - diam/2 <= 0) { + vel[i].y = abs(vel[i].y); + } } +} } \ No newline at end of file From 0155655d9eb6f2cb9c27b7233b5473edeadf60c3 Mon Sep 17 00:00:00 2001 From: lerazodiaz Date: Wed, 18 Nov 2015 13:47:08 -0500 Subject: [PATCH 5/9] fixed basic code4 --- Wanderer/Wanderer.pde | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/Wanderer/Wanderer.pde b/Wanderer/Wanderer.pde index b6ce247..7d92481 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 6a1db1b4d04556632208d62aad413cae8250a93a Mon Sep 17 00:00:00 2001 From: lerazodiaz Date: Wed, 18 Nov 2015 13:48:57 -0500 Subject: [PATCH 6/9] working array --- BouncingWithVectors/BouncingWithVectors.pde | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/BouncingWithVectors/BouncingWithVectors.pde b/BouncingWithVectors/BouncingWithVectors.pde index eaa1a01..253730f 100644 --- a/BouncingWithVectors/BouncingWithVectors.pde +++ b/BouncingWithVectors/BouncingWithVectors.pde @@ -2,10 +2,10 @@ int count = 20; float diam ; //float loc.x,loc.y -PVector[] loc = new float[count]; //replaces loc.x & loc.y +PVector[] loc = new PVector[count]; //replaces loc.x & loc.y //float vel.loc.x, vel.loc.y -PVector[] vel = new float[count]; //replaces vel.loc.x & vel.loc.y +PVector[] vel = new PVector[count]; //replaces vel.loc.x & vel.loc.y void setup() { //set size of canvas @@ -20,14 +20,13 @@ void setup() { //vel.loc.x= random(-5,5) //vel.loc.y= random(-5,5) vel[i] = PVector.random2D(); - vel.mult(5); } } void draw() { //draw background to cover previous frame background(0); - for (int i =20; i Date: Wed, 18 Nov 2015 13:59:31 -0500 Subject: [PATCH 7/9] added vector --- Wanderer/Wanderer.pde | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/Wanderer/Wanderer.pde b/Wanderer/Wanderer.pde index 7d92481..1e6e8a6 100644 --- a/Wanderer/Wanderer.pde +++ b/Wanderer/Wanderer.pde @@ -1,16 +1,21 @@ //declare variables -float x, y, velX, velY, diam; +//float x, y, velX, velY, diam; +float diam; + +PVector loc; +PVector vel; void setup() { //set size of canvas size(800, 600); - + loc= new PVector(width/2, height/2); //initialize variables - x = width/2; - y = height/2; + //x = width/2; + //y = height/2; diam = 80; - velX = random(-5, 5); - velY = random(-5, 5); + //velX = random(-5, 5); + // velY = random(-5, 5); + vel = PVector.random2D(); } void draw() { @@ -18,21 +23,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.x; //wrap the ball's position - if (x >= width) { - x = 0; - } else if (x <= 0) { - x = width ; + if (loc.x >= width) { + loc.x = 0; + } else if (loc.x <= 0) { + loc.x = width ; } - if (y >= height) { - y = 0 ; - } else if (y <= 0) { - y = height ; + if (loc.y >= height) { + loc.y = 0 ; + } else if (loc.y <= 0) { + loc.y = height ; } } \ No newline at end of file From 5f6e78669e0c5b8ab0b3ca87e1572a8d78e8b554 Mon Sep 17 00:00:00 2001 From: lerazodiaz Date: Wed, 18 Nov 2015 14:48:15 -0500 Subject: [PATCH 8/9] working wanderer + color --- Wanderer/Wanderer.pde | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/Wanderer/Wanderer.pde b/Wanderer/Wanderer.pde index 1e6e8a6..7f2771b 100644 --- a/Wanderer/Wanderer.pde +++ b/Wanderer/Wanderer.pde @@ -2,8 +2,7 @@ //float x, y, velX, velY, diam; float diam; -PVector loc; -PVector vel; +PVector loc, vel, acc; void setup() { //set size of canvas @@ -13,21 +12,30 @@ void setup() { //x = width/2; //y = height/2; diam = 80; - //velX = random(-5, 5); - // velY = random(-5, 5); vel = PVector.random2D(); + //vel.mult(0); + acc = PVector.random2D(); + acc.mult(.05); + + } void draw() { //draw background to cover previous frame - background(0); - + background(19,24,51); + + //add here for ellipse to wander + acc = PVector.random2D(); + acc.mult(.09); //draw ball + ellipse(loc.x, loc.y, diam, diam); - + fill(232,239,144); + vel.add(acc); + vel.limit(15); //limit v to avoid it from overcoming large velocities + //add velocity to position - loc.x += vel.x; - loc.y += vel.x; + loc.add(vel); //wrap the ball's position if (loc.x >= width) { From de81ed61aea1f24fd694553c40e37992fe815346 Mon Sep 17 00:00:00 2001 From: lerazodiaz Date: Wed, 18 Nov 2015 14:50:58 -0500 Subject: [PATCH 9/9] vel.mult --- Wanderer/Wanderer.pde | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Wanderer/Wanderer.pde b/Wanderer/Wanderer.pde index 7f2771b..1347e9e 100644 --- a/Wanderer/Wanderer.pde +++ b/Wanderer/Wanderer.pde @@ -11,7 +11,7 @@ void setup() { //initialize variables //x = width/2; //y = height/2; - diam = 80; + diam = 73; vel = PVector.random2D(); //vel.mult(0); acc = PVector.random2D(); @@ -26,8 +26,9 @@ void draw() { //add here for ellipse to wander acc = PVector.random2D(); - acc.mult(.09); + acc.mult(.099); //draw ball + vel.mult(1); ellipse(loc.x, loc.y, diam, diam); fill(232,239,144);