From 4df63e5d6ce262377a6ef59c16a8ad949e89970b Mon Sep 17 00:00:00 2001 From: Woof-Rawr Date: Thu, 12 Nov 2015 14:45:32 -0500 Subject: [PATCH 1/7] Fixing --- BouncingWithVectors/BouncingWithVectors.pde | 45 +++++++++++++-------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/BouncingWithVectors/BouncingWithVectors.pde b/BouncingWithVectors/BouncingWithVectors.pde index 2683b50..8bbc1e2 100644 --- a/BouncingWithVectors/BouncingWithVectors.pde +++ b/BouncingWithVectors/BouncingWithVectors.pde @@ -1,16 +1,26 @@ //declare variables -float x, y, velX, velY, diam; +float diam; + +//float x, y +PVector loc; //replaces x and y + +//float velX and velY +PVector vel = new PVector(2, 2); void setup() { //set size of canvas size(800, 600); //initialize variables - x = width/2; - y = height/2; + //x = width/2; + //y = height/2; + loc = new PVector(width/2, height/2); + diam = 80; - velX = random(-5, 5); - velY = random(-5, 5); + + //velX = random(-5, 5): + //velY = random(-5, 5); + vel = new PVector(random(-5, 5), random(-5,5)); } void draw() { @@ -18,20 +28,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 75796678155a4bff74bdeb06de861241dabd947c Mon Sep 17 00:00:00 2001 From: Woof-Rawr Date: Thu, 12 Nov 2015 14:48:38 -0500 Subject: [PATCH 2/7] mishap --- BouncingWithVectors/BouncingWithVectors.pde | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/BouncingWithVectors/BouncingWithVectors.pde b/BouncingWithVectors/BouncingWithVectors.pde index 8bbc1e2..f4cd655 100644 --- a/BouncingWithVectors/BouncingWithVectors.pde +++ b/BouncingWithVectors/BouncingWithVectors.pde @@ -36,9 +36,9 @@ void draw() { //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 + vel.x = -abs(vel.x); //if the ball hits the right wall, assign loc.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 loc.x velocitloc.y the positive version of itself + vel.x = abs(vel.x); //if the ball hits the left wall, assign loc.x velocity the positive version of itself } if (loc.y + diam/2 >= height) { vel.y = -abs(vel.y); From 907cc27e5428a41009a0a1bb41ca382b73bb3bea Mon Sep 17 00:00:00 2001 From: Woof-Rawr Date: Thu, 12 Nov 2015 14:51:24 -0500 Subject: [PATCH 3/7] woof --- BouncingWithVectors/BouncingWithVectors.pde | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/BouncingWithVectors/BouncingWithVectors.pde b/BouncingWithVectors/BouncingWithVectors.pde index f4cd655..aad7d98 100644 --- a/BouncingWithVectors/BouncingWithVectors.pde +++ b/BouncingWithVectors/BouncingWithVectors.pde @@ -20,7 +20,8 @@ void setup() { //velX = random(-5, 5): //velY = random(-5, 5); - vel = new PVector(random(-5, 5), random(-5,5)); + vel = PVector.random2D(); + vel.mult(5); } void draw() { @@ -30,10 +31,11 @@ void draw() { //draw ball ellipse(loc.x, loc.y, diam, diam); - //add velocitloc.y to position - loc.x += vel.x; - loc.y += vel.y; - + //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 loc.x velocity the negative version of itself From 85b1f23f7895e9c757afbe6e027529d910809f22 Mon Sep 17 00:00:00 2001 From: Woof-Rawr Date: Wed, 18 Nov 2015 13:44:22 -0500 Subject: [PATCH 4/7] Fixed Wanderer Does not leave and wraps around, --- Wanderer/Wanderer.pde | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/Wanderer/Wanderer.pde b/Wanderer/Wanderer.pde index b6ce247..95ccadb 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 e0970ab77ca6e7180ed81e7dc4c6e83038b8320a Mon Sep 17 00:00:00 2001 From: Woof-Rawr Date: Wed, 18 Nov 2015 13:52:05 -0500 Subject: [PATCH 5/7] Added Vectors PVectors added; x and y replaced with loc.y and loc.x; velY and VelX replaced with vel..... --- Wanderer/Wanderer.pde | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/Wanderer/Wanderer.pde b/Wanderer/Wanderer.pde index 95ccadb..7038a30 100644 --- a/Wanderer/Wanderer.pde +++ b/Wanderer/Wanderer.pde @@ -1,16 +1,24 @@ //declare variables -float x, y, velX, velY, diam; +//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; + //x = width/2; + //y = height/2; + loc = new PVector(width/2,height/2); + diam = 80; - velX = random(-5, 5); - velY = random(-5, 5); + //velX = random(-5, 5); + //velY = random(-5, 5); + vel = PVector.random2D(); + vel.mult(5); } void draw() { @@ -18,21 +26,22 @@ 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; + //x += velX; + //y += velY; + loc.add(vel); //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 0ab942762d58ed8df43164c334982a19afed7cd4 Mon Sep 17 00:00:00 2001 From: Woof-Rawr Date: Wed, 18 Nov 2015 14:33:37 -0500 Subject: [PATCH 6/7] Added acceleration --- Wanderer/Wanderer.pde | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/Wanderer/Wanderer.pde b/Wanderer/Wanderer.pde index 7038a30..8f6098e 100644 --- a/Wanderer/Wanderer.pde +++ b/Wanderer/Wanderer.pde @@ -1,8 +1,7 @@ //declare variables //float x, y, velX, velY, diam; float diam; -PVector loc; -PVector vel = new PVector(2,2); +PVector loc, vel, acc; void setup() { @@ -14,19 +13,30 @@ void setup() { //y = height/2; loc = new PVector(width/2,height/2); - diam = 80; //velX = random(-5, 5); //velY = random(-5, 5); vel = PVector.random2D(); - vel.mult(5); + vel.mult(1); + acc = PVector.random2D(); + acc.mult(.01); + + diam = 80; } void draw() { + //pick a random acceleration + acc = PVector.random2D(); + acc.mult(.1); + //draw background to cover previous frame background(0); //draw ball ellipse(loc.x, loc.y, diam, diam); + + //add acceleration to velocity + vel.add(acc); + vel.limit(35); //add velocity to position //x += velX; From ea9388c5ef972cad0c32dc555065c633b4946b3f Mon Sep 17 00:00:00 2001 From: Woof-Rawr Date: Wed, 18 Nov 2015 14:42:37 -0500 Subject: [PATCH 7/7] Fun, fun, fun Added color + fill edited vel.limit number --- Wanderer/Wanderer.pde | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Wanderer/Wanderer.pde b/Wanderer/Wanderer.pde index 8f6098e..bf25869 100644 --- a/Wanderer/Wanderer.pde +++ b/Wanderer/Wanderer.pde @@ -4,9 +4,12 @@ float diam; PVector loc, vel, acc; + void setup() { //set size of canvas size(800, 600); + background(0); + colorMode(HSB, 360, 100, 100, 95); //initialize variables //x = width/2; @@ -23,20 +26,25 @@ void setup() { diam = 80; } + + void draw() { + fill(frameCount%360, 75, 85); //pick a random acceleration acc = PVector.random2D(); acc.mult(.1); //draw background to cover previous frame - background(0); + //background(0); //draw ball ellipse(loc.x, loc.y, diam, diam); //add acceleration to velocity vel.add(acc); - vel.limit(35); + + //limit velocity to avoid being unable to overcome large velocity with small acceleration + vel.limit(15); //add velocity to position //x += velX;