From 619710ffd6d11f9a4386f06d89346c8cb9de301f Mon Sep 17 00:00:00 2001 From: jessgannon13 Date: Thu, 12 Nov 2015 14:37:59 -0500 Subject: [PATCH 1/6] Vectors --- BouncingWithVectors/BouncingWithVectors.pde | 42 +++++++++++++-------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/BouncingWithVectors/BouncingWithVectors.pde b/BouncingWithVectors/BouncingWithVectors.pde index 2683b50..24250af 100644 --- a/BouncingWithVectors/BouncingWithVectors.pde +++ b/BouncingWithVectors/BouncingWithVectors.pde @@ -1,16 +1,25 @@ //declare variables -float x, y, velX, velY, diam; +float diam; +//float x,y +PVector loc; //replaces x and y + +//float velx, vely +PVector vel; + 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 +27,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 1ff582ca75dc66e8de4043c6004194461e6f31da Mon Sep 17 00:00:00 2001 From: jessgannon13 Date: Thu, 12 Nov 2015 14:51:33 -0500 Subject: [PATCH 2/6] .add --- BouncingWithVectors/BouncingWithVectors.pde | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/BouncingWithVectors/BouncingWithVectors.pde b/BouncingWithVectors/BouncingWithVectors.pde index 24250af..e5cea2e 100644 --- a/BouncingWithVectors/BouncingWithVectors.pde +++ b/BouncingWithVectors/BouncingWithVectors.pde @@ -19,7 +19,8 @@ void setup() { diam = 80; //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,8 +31,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 40f2610c5f98818d97a71c85a39ac5f4be32a2ee Mon Sep 17 00:00:00 2001 From: jessgannon13 Date: Wed, 18 Nov 2015 13:38:33 -0500 Subject: [PATCH 3/6] arrays --- BouncingWithVectors/BouncingWithVectors.pde | 70 +++++++++++---------- 1 file changed, 37 insertions(+), 33 deletions(-) diff --git a/BouncingWithVectors/BouncingWithVectors.pde b/BouncingWithVectors/BouncingWithVectors.pde index e5cea2e..29bbdd0 100644 --- a/BouncingWithVectors/BouncingWithVectors.pde +++ b/BouncingWithVectors/BouncingWithVectors.pde @@ -1,49 +1,53 @@ //declare variables -float diam; +int count= 30; +float [] diam = new float [count]; + //float x,y -PVector loc; //replaces x and y +PVector [] loc = new PVector [count]; //replaces x and y //float velx, vely -PVector vel; +PVector [] vel = new PVector [count]; 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= PVector.random2D(); - vel.mult(5); + for (int i=0; i < count; i++) { + //initialize variables + //x=width/2 + //y=height/2 + loc [i] = new PVector(width/2, height/2); + + diam [i] = random(80); + //velX = random(-5, 5); + // velY = random(-5, 5); + vel[i]= PVector.random2D(); + vel[i].mult(5); + } } void draw() { //draw background to cover previous frame background(0); - - //draw ball - 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) { - 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.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= 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[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 be1fe9508c50f6c7f1ea7a0d021bb613b2d92aa1 Mon Sep 17 00:00:00 2001 From: jessgannon13 Date: Wed, 18 Nov 2015 13:43:47 -0500 Subject: [PATCH 4/6] fixed basic code --- Wanderer/Wanderer.pde | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/Wanderer/Wanderer.pde b/Wanderer/Wanderer.pde index b6ce247..16557f4 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 12e57ca6df400b2cc46b813dfa7c427f9a5105db Mon Sep 17 00:00:00 2001 From: jessgannon13 Date: Wed, 18 Nov 2015 13:50:52 -0500 Subject: [PATCH 5/6] adding vectors --- Wanderer/Wanderer.pde | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/Wanderer/Wanderer.pde b/Wanderer/Wanderer.pde index 16557f4..081b3a5 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, +float diam; +PVector loc; +PVector vel; 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,21 +23,23 @@ 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.x += vel.x; + loc.y += vel.y; //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 17f13a29340107576d5f6e512518f950aeeeef01 Mon Sep 17 00:00:00 2001 From: jessgannon13 Date: Fri, 20 Nov 2015 13:47:09 -0500 Subject: [PATCH 6/6] adding acc. and finalizing wanderer --- Wanderer/Wanderer.pde | 41 ++++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/Wanderer/Wanderer.pde b/Wanderer/Wanderer.pde index 081b3a5..88cb3f0 100644 --- a/Wanderer/Wanderer.pde +++ b/Wanderer/Wanderer.pde @@ -4,36 +4,55 @@ float diam; PVector loc; PVector vel; +PVector acc; + + void setup() { //set size of canvas size(800, 600); //initialize variables - // x = width/2; + + // x = width/2; //y = height/2; + //velX = random(-5, 5); + // velY = random(-5, 5); + //vel = PVector.random2D(); + //vel.mult(0); 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)); -} + vel = PVector.random2D(); + vel.mult(1); + acc =PVector.random2D(); + acc.mult(.01); -void draw() { //draw background to cover previous frame background(0); //draw ball + + colorMode(HSB, 360, 100, 100, 100); + noStroke(); +} + + +void draw() { + fill(frameCount%360, 70, 80); ellipse(loc.x, loc.y, diam, diam); + //add acc to velocity + vel.add(acc); + vel.limit(5); + loc.add(vel); //add velocity to position - // x += velX; - // y += velY; - loc.x += vel.x; - loc.y += vel.y; + + // x += velX; + // y += velY; + //wrap the ball's position if (loc.x >= width) { - loc.x = 0; + loc.x = 0; } else if (loc.x <= 0) { loc.x = width; }