From d3ceb5a4eb04ce6f85d33f9a90afa8d6688b3de0 Mon Sep 17 00:00:00 2001 From: TwolfSoul Date: Thu, 12 Nov 2015 14:24:58 -0500 Subject: [PATCH 1/8] Er... --- BouncingWithVectors/BouncingWithVectors.pde | 26 +++++++++------------ 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/BouncingWithVectors/BouncingWithVectors.pde b/BouncingWithVectors/BouncingWithVectors.pde index 2683b50..b122c7a 100644 --- a/BouncingWithVectors/BouncingWithVectors.pde +++ b/BouncingWithVectors/BouncingWithVectors.pde @@ -1,11 +1,8 @@ -//declare variables float x, y, velX, velY, diam; -void setup() { - //set size of canvas +void setup() +{ size(800, 600); - - //initialize variables x = width/2; y = height/2; diam = 80; @@ -13,25 +10,24 @@ void setup() { velY = random(-5, 5); } -void draw() { - //draw background to cover previous frame +void draw() +{ background(0); - - //draw ball ellipse(x, y, diam, diam); - //add velocity to position x += velX; y += velY; - //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 + if (x + diam/2 >= width) + { + velX = -abs(velX); } else if (x - diam/2 <= 0) { - velX = abs(velX); //if the ball hits the left wall, assign x velocity the positive version of itself + velX = abs(velX); } - if (y + diam/2 >= height) { + if (y + diam/2 >= height) + { velY = -abs(velY); } else if (y - diam/2 <= 0) { velY = abs(velY); } +} \ No newline at end of file From 86b68e3698acac443272150f521c5a73b11b091c Mon Sep 17 00:00:00 2001 From: TwolfSoul Date: Thu, 12 Nov 2015 14:38:22 -0500 Subject: [PATCH 2/8] Change to Vectors --- BouncingWithVectors/BouncingWithVectors.pde | 32 ++++++++++----------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/BouncingWithVectors/BouncingWithVectors.pde b/BouncingWithVectors/BouncingWithVectors.pde index b122c7a..593e736 100644 --- a/BouncingWithVectors/BouncingWithVectors.pde +++ b/BouncingWithVectors/BouncingWithVectors.pde @@ -1,33 +1,33 @@ -float x, y, velX, velY, diam; +float diam; +PVector loc; +PVector vel; void setup() { size(800, 600); - 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() { background(0); - ellipse(x, y, diam, diam); + ellipse(loc.x, loc.y, diam, diam); - x += velX; - y += velY; + loc.x += vel.x; + loc.y += vel.y; - if (x + diam/2 >= width) + if (loc.x + diam/2 >= width) { - velX = -abs(velX); - } else if (x - diam/2 <= 0) { - velX = abs(velX); + vel.x = -abs(vel.x); + } else if (loc.x - diam/2 <= 0) { + vel.x = abs(vel.x); } - if (y + diam/2 >= height) + if (loc.y + diam/2 >= height) { - velY = -abs(velY); - } else if (y - diam/2 <= 0) { - velY = abs(velY); + vel.y = -abs(vel.y); + } else if (loc.y - diam/2 <= 0) { + vel.y = abs(vel.y); } } \ No newline at end of file From 774963a644870fb510ee8148ff7c3bb6274f9252 Mon Sep 17 00:00:00 2001 From: TwolfSoul Date: Thu, 12 Nov 2015 14:39:35 -0500 Subject: [PATCH 3/8] Color --- BouncingWithVectors/BouncingWithVectors.pde | 2 ++ 1 file changed, 2 insertions(+) diff --git a/BouncingWithVectors/BouncingWithVectors.pde b/BouncingWithVectors/BouncingWithVectors.pde index 593e736..a919269 100644 --- a/BouncingWithVectors/BouncingWithVectors.pde +++ b/BouncingWithVectors/BouncingWithVectors.pde @@ -13,6 +13,8 @@ void setup() void draw() { background(0); + noStroke(); + fill(random(255),random(255),random(255)); ellipse(loc.x, loc.y, diam, diam); loc.x += vel.x; From 9507b79cf78871a8f089fb905f161b1f6f575615 Mon Sep 17 00:00:00 2001 From: TwolfSoul Date: Thu, 12 Nov 2015 14:51:45 -0500 Subject: [PATCH 4/8] Continue Next Class --- BouncingWithVectors/BouncingWithVectors.pde | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/BouncingWithVectors/BouncingWithVectors.pde b/BouncingWithVectors/BouncingWithVectors.pde index a919269..78c1cc5 100644 --- a/BouncingWithVectors/BouncingWithVectors.pde +++ b/BouncingWithVectors/BouncingWithVectors.pde @@ -7,7 +7,8 @@ void setup() size(800, 600); diam = 80; loc = new PVector (width/2,height/2); - vel = new PVector (random(-5,5),random(-5,5)); + vel = PVector.random2D(); + vel.mult(5); } void draw() @@ -16,9 +17,8 @@ void draw() noStroke(); fill(random(255),random(255),random(255)); ellipse(loc.x, loc.y, diam, diam); - - loc.x += vel.x; - loc.y += vel.y; + + loc.add(vel); if (loc.x + diam/2 >= width) { From ea38e845730bb9101da24b471718572e3457e7c0 Mon Sep 17 00:00:00 2001 From: TwolfSoul Date: Mon, 16 Nov 2015 14:21:19 -0500 Subject: [PATCH 5/8] Arrays and Vectors, Woo hoo... Just added arrays. --- BouncingWithVectors/BouncingWithVectors.pde | 40 ++++++++++++--------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/BouncingWithVectors/BouncingWithVectors.pde b/BouncingWithVectors/BouncingWithVectors.pde index 78c1cc5..707a81d 100644 --- a/BouncingWithVectors/BouncingWithVectors.pde +++ b/BouncingWithVectors/BouncingWithVectors.pde @@ -1,35 +1,41 @@ -float diam; -PVector loc; -PVector vel; +int woof = 30; +float[] diam = new float[woof]; +PVector[] loc = new PVector[woof]; +PVector[] vel = new PVector[woof]; void setup() { size(800, 600); - diam = 80; - loc = new PVector (width/2,height/2); - vel = PVector.random2D(); - vel.mult(5); + for(int i = 0;i < woof; i++) + { + diam[i] = 80; + loc[i] = new PVector (width/2,height/2); + vel[i] = new PVector (random(-5,5),random(-5,5)); + } } void draw() { background(0); + for(int i = 0;i < woof; i++) +{ noStroke(); fill(random(255),random(255),random(255)); - ellipse(loc.x, loc.y, diam, diam); + ellipse(loc[i].x, loc[i].y, diam[i], diam[i]); - loc.add(vel); + loc[i].add(vel[i]); - if (loc.x + diam/2 >= width) + if (loc[i].x + diam[i]/2 >= width) { - vel.x = -abs(vel.x); - } else if (loc.x - diam/2 <= 0) { - vel.x = abs(vel.x); + vel[i].x = -abs(vel[i].x); + } else if (loc[i].x - diam[i]/2 <= 0) { + vel[i].x = abs(vel[i].x); } - if (loc.y + diam/2 >= height) + if (loc[i].y + diam[i]/2 >= height) { - vel.y = -abs(vel.y); - } else if (loc.y - diam/2 <= 0) { - vel.y = abs(vel.y); + 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 cbf0353b9996edb9e61847cb55f3989af12d1fb6 Mon Sep 17 00:00:00 2001 From: TwolfSoul Date: Mon, 16 Nov 2015 14:45:10 -0500 Subject: [PATCH 6/8] GLITCH TO FIX Added gravity vector, balls are sinking... --- BouncingWithVectors/BouncingWithVectors.pde | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/BouncingWithVectors/BouncingWithVectors.pde b/BouncingWithVectors/BouncingWithVectors.pde index 707a81d..ad5d2e2 100644 --- a/BouncingWithVectors/BouncingWithVectors.pde +++ b/BouncingWithVectors/BouncingWithVectors.pde @@ -2,6 +2,9 @@ int woof = 30; float[] diam = new float[woof]; PVector[] loc = new PVector[woof]; PVector[] vel = new PVector[woof]; +PVector[] grav = new PVector[woof]; +PVector[] fric = new PVector[woof]; +PVector[] finpos = new PVector[woof]; void setup() { @@ -9,8 +12,11 @@ void setup() for(int i = 0;i < woof; i++) { diam[i] = 80; - loc[i] = new PVector (width/2,height/2); + loc[i] = new PVector (random(width),random(height)); vel[i] = new PVector (random(-5,5),random(-5,5)); + grav[i] = new PVector (0,0.4); + fric[i] = new PVector (0.95,0); + finpos[i] = new PVector (loc[i].y, height-diam[i]/2); } } @@ -37,5 +43,13 @@ void draw() } else if (loc[i].y - diam[i]/2 <= 0) { vel[i].y = abs(vel[i].y); } + if (loc[i].y - diam[i]/2 > 0) + { + vel[i].add(grav[i]); + } + if (loc[i].y + diam[i]/2 > height) + { + loc[i] = finpos[i]; + } } } \ No newline at end of file From 4d8abb9d97197115ae1736f5221f23f134180d15 Mon Sep 17 00:00:00 2001 From: TwolfSoul Date: Fri, 20 Nov 2015 13:37:21 -0500 Subject: [PATCH 7/8] White Stroke --- Wanderer/Wanderer.pde | 65 ++++++++++++++++++++++++------------------- 1 file changed, 37 insertions(+), 28 deletions(-) diff --git a/Wanderer/Wanderer.pde b/Wanderer/Wanderer.pde index b6ce247..56a6b98 100644 --- a/Wanderer/Wanderer.pde +++ b/Wanderer/Wanderer.pde @@ -1,37 +1,46 @@ -//declare variables -float x, y, velX, velY, diam; +int woof = 10; +float[] diam = new float[woof]; +PVector[] loc = new PVector[woof]; +PVector[] vel = new PVector[woof]; +PVector[] accel = new PVector[woof]; 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); + background(0); +for(int i = 0;i < woof; i++) + { + diam[i] = 50; + loc[i] = new PVector (random(width),random(height)); + vel[i] = PVector.random2D(); + vel[i].mult(0); + accel[i] = PVector.random2D(); + accel[i].mult(0.1); + } } void draw() { - //draw background to cover previous frame - background(0); + for(int i = 0;i < woof; i++) +{ + stroke(255); + fill(random(255),random(255),random(255)); + ellipse(loc[i].x, loc[i].y, diam[i], diam[i]); + + accel[i] = PVector.random2D(); + accel[i].mult(0.1); + + vel[i].add(accel[i]); + vel[i].limit(5); + loc[i].add(vel[i]); - //draw ball - ellipse(x, y, diam, diam); - - //add velocity to position - x += velX; - 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 (loc[i].x >= width) { + loc[i].x = 0; + } else if (loc[i].x <= 0) { + loc[i].x = width; } - if (y + diam/2 >= height) { - y = -diam/2; - } else if (y - diam/2 <= 0) { - y = height + diam/2; + 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 2cef04059e7d01e470d647ed136a14c39db72229 Mon Sep 17 00:00:00 2001 From: TwolfSoul Date: Fri, 20 Nov 2015 13:47:36 -0500 Subject: [PATCH 8/8] Virus Wanderers Version --- Wanderer/Wanderer.pde | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Wanderer/Wanderer.pde b/Wanderer/Wanderer.pde index 56a6b98..02ace5b 100644 --- a/Wanderer/Wanderer.pde +++ b/Wanderer/Wanderer.pde @@ -1,4 +1,4 @@ -int woof = 10; +int woof = 40; float[] diam = new float[woof]; PVector[] loc = new PVector[woof]; PVector[] vel = new PVector[woof]; @@ -9,8 +9,8 @@ void setup() { background(0); for(int i = 0;i < woof; i++) { - diam[i] = 50; - loc[i] = new PVector (random(width),random(height)); + diam[i] = 5; + loc[i] = new PVector (width/2,height/2); vel[i] = PVector.random2D(); vel[i].mult(0); accel[i] = PVector.random2D(); @@ -21,8 +21,9 @@ for(int i = 0;i < woof; i++) void draw() { for(int i = 0;i < woof; i++) { - stroke(255); - fill(random(255),random(255),random(255)); + strokeWeight(1); + stroke(random(255),random(255),random(255)); + fill(0); ellipse(loc[i].x, loc[i].y, diam[i], diam[i]); accel[i] = PVector.random2D();