From d1762306f4952918c113a18ed538aabfbbe6da50 Mon Sep 17 00:00:00 2001 From: Mandzy Date: Thu, 12 Nov 2015 14:38:11 -0500 Subject: [PATCH 1/7] put in vectors --- BouncingWithVectors/BouncingWithVectors.pde | 36 ++++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/BouncingWithVectors/BouncingWithVectors.pde b/BouncingWithVectors/BouncingWithVectors.pde index 2683b50..6338e16 100644 --- a/BouncingWithVectors/BouncingWithVectors.pde +++ b/BouncingWithVectors/BouncingWithVectors.pde @@ -1,16 +1,19 @@ //declare variables -float x, y, velX, velY, diam; +float diam; +//float x, y +PVector loc; +//float velX, velY +PVector vel; + 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 +21,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 e978cdd56f439c9228199c8119b4024f21f322b8 Mon Sep 17 00:00:00 2001 From: Mandzy Date: Thu, 12 Nov 2015 14:52:29 -0500 Subject: [PATCH 2/7] changed things --- BouncingWithVectors/BouncingWithVectors.pde | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/BouncingWithVectors/BouncingWithVectors.pde b/BouncingWithVectors/BouncingWithVectors.pde index 6338e16..51a3352 100644 --- a/BouncingWithVectors/BouncingWithVectors.pde +++ b/BouncingWithVectors/BouncingWithVectors.pde @@ -13,7 +13,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(); + vel.mult(5); } void draw() { @@ -24,8 +25,7 @@ void draw() { 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) { From 87677fe57cf100d50f3ba325a6e73ff7f4cd5791 Mon Sep 17 00:00:00 2001 From: Mandzy Date: Mon, 16 Nov 2015 14:11:32 -0500 Subject: [PATCH 3/7] added arrays --- BouncingWithVectors/BouncingWithVectors.pde | 39 ++++++++++++--------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/BouncingWithVectors/BouncingWithVectors.pde b/BouncingWithVectors/BouncingWithVectors.pde index 51a3352..dec24e3 100644 --- a/BouncingWithVectors/BouncingWithVectors.pde +++ b/BouncingWithVectors/BouncingWithVectors.pde @@ -1,9 +1,10 @@ //declare variables -float diam; +int count = 50; +float []diam = new float [count]; //float x, y -PVector loc; +PVector []loc = new PVector[count]; //float velX, velY -PVector vel; +PVector []vel = new PVector[count]; void setup() { @@ -11,10 +12,12 @@ void setup() { size(800, 600); //initialize variables - loc = new PVector (width/2, height/2); - diam = 80; - vel = PVector.random2D(); - vel.mult(5); + for (int i = 0; i < count; i ++) { + loc[i] = new PVector (width/2, height/2); + diam[i] = random(0,100); + vel[i] = PVector.random2D(); + vel[i].mult(5); + } } void draw() { @@ -22,20 +25,22 @@ void draw() { background(0); //draw ball - ellipse(loc.x, loc.y, diam, diam); + for(int i = 0; i < count; i++){ + ellipse(loc[i].x, loc[i].y, diam[i], diam[i]); //add velocity to position - loc.add(vel); + loc[i].add(vel[i]); //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[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.y + diam/2 >= height) { - vel.y = -abs(vel.y); - } else if (loc.y - diam/2 <= 0) { - vel.y = abs(vel.y); + 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 b03afba80189a665610f12433d97466b94b21c8a Mon Sep 17 00:00:00 2001 From: Mandzy Date: Wed, 18 Nov 2015 13:44:15 -0500 Subject: [PATCH 4/7] Fixed code --- Wanderer/Wanderer.pde | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/Wanderer/Wanderer.pde b/Wanderer/Wanderer.pde index b6ce247..9e50362 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 2a8f7463f74cf1fd7473eb50c3596f60a95df141 Mon Sep 17 00:00:00 2001 From: Mandzy Date: Wed, 18 Nov 2015 13:51:46 -0500 Subject: [PATCH 5/7] added vectors --- Wanderer/Wanderer.pde | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/Wanderer/Wanderer.pde b/Wanderer/Wanderer.pde index 9e50362..da73cdd 100644 --- a/Wanderer/Wanderer.pde +++ b/Wanderer/Wanderer.pde @@ -1,16 +1,17 @@ //declare variables -float x, y, velX, velY, diam; +float diam; +PVector loc; +PVector vel; void setup() { //set size of canvas size(800, 600); //initialize variables - x = width/2; - y = height/2; + loc = new PVector (width/2, height/2); + vel = new PVector (random(-10, 10), random (-10,10)); + diam = 80; - velX = random(-5, 5); - velY = random(-5, 5); } void draw() { @@ -18,21 +19,20 @@ 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.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 80fcf158f4c9da34f0ba7493cb492933216ebd85 Mon Sep 17 00:00:00 2001 From: Mandzy Date: Wed, 18 Nov 2015 14:51:54 -0500 Subject: [PATCH 6/7] added acceleration - move to correct branch Friday --- Wanderer/Wanderer.pde | 49 +++++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/Wanderer/Wanderer.pde b/Wanderer/Wanderer.pde index b6ce247..df165c2 100644 --- a/Wanderer/Wanderer.pde +++ b/Wanderer/Wanderer.pde @@ -1,37 +1,50 @@ //declare variables -float x, y, velX, velY, diam; +float diam; +PVector loc; +PVector vel; +PVector acc; void setup() { //set size of canvas size(800, 600); - + colorMode(HSB, 360, 100, 100, 100); //initialize variables - x = width/2; - y = height/2; + loc = new PVector (width/2, height/2); + vel = new PVector( 5, 3); + vel.mult(0); + acc = PVector.random2D(); + acc.mult(.1); + diam = 80; - velX = random(-5, 5); - velY = random(-5, 5); } void draw() { //draw background to cover previous frame - background(0); + //background(0); + fill (frameCount%360, 20, 100); + stroke(frameCount%360, 80, 100); + acc = PVector.random2D(); + acc.mult(.1); + //draw ball - ellipse(x, y, diam, diam); + ellipse(loc.x, loc.y, diam, diam); + //add velocity to position - x += velX; - y += velY; + vel.add(acc); + vel.limit(1); + loc.add(vel); //wrap the ball's position - if (x + diam/2 >= width) { - x = -diam/2; - } else if (x - diam/2 <= 0) { - x = width + diam/2; + if (loc.x >= width) { + loc.x = 0; + } else if (loc.x <= 0) { + loc.x = width; } - if (y + diam/2 >= height) { - y = -diam/2; - } else if (y - diam/2 <= 0) { - y = height + diam/2; + if (loc.y >= height) { + loc.y = 0; + } else if (loc.y <= 0) { + loc.y = height; } +} \ No newline at end of file From 839a4f58fa60e4970346e0699a3b6be8520cc11c Mon Sep 17 00:00:00 2001 From: Mandzy Date: Fri, 20 Nov 2015 13:53:05 -0500 Subject: [PATCH 7/7] added eyes --- Wanderer/Wanderer.pde | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Wanderer/Wanderer.pde b/Wanderer/Wanderer.pde index 338b4d8..c93c970 100644 --- a/Wanderer/Wanderer.pde +++ b/Wanderer/Wanderer.pde @@ -1,5 +1,6 @@ //declare variables float diam; +float diam1; PVector loc; PVector vel; @@ -20,11 +21,14 @@ void setup() { diam = 80; + diam1 = 20; } void draw() { //draw background to cover previous frame //background(0); + + fill (frameCount%360, 20, 100); stroke(frameCount%360, 80, 100); acc = PVector.random2D(); @@ -33,6 +37,9 @@ void draw() { //draw ball ellipse(loc.x, loc.y, diam, diam); + fill (0); + ellipse(loc.x - 15, loc.y - 15, diam1, diam1); + ellipse(loc.x + 15, loc.y - 15, diam1, diam1);