Skip to content

Commit

Permalink
location is now position everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
shiffman committed Jul 1, 2016
1 parent 5d19bd5 commit 4195df9
Show file tree
Hide file tree
Showing 211 changed files with 1,089 additions and 1,099 deletions.
16 changes: 8 additions & 8 deletions chp01_vectors/NOC_1_10_motion101_acceleration/Mover.pde
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,41 @@

class Mover {

// The Mover tracks location, velocity, and acceleration
PVector location;
// The Mover tracks position, velocity, and acceleration
PVector position;
PVector velocity;
PVector acceleration;
// The Mover's maximum speed
float topspeed;

Mover() {
// Start in the center
location = new PVector(width/2,height/2);
position = new PVector(width/2,height/2);
velocity = new PVector(0,0);
topspeed = 5;
}

void update() {

// Compute a vector that points from location to mouse
// Compute a vector that points from position to mouse
PVector mouse = new PVector(mouseX,mouseY);
PVector acceleration = PVector.sub(mouse,location);
PVector acceleration = PVector.sub(mouse,position);
// Set magnitude of acceleration
acceleration.setMag(0.2);

// Velocity changes according to acceleration
velocity.add(acceleration);
// Limit the velocity by topspeed
velocity.limit(topspeed);
// Location changes by velocity
location.add(velocity);
// position changes by velocity
position.add(velocity);
}

void display() {
stroke(0);
strokeWeight(2);
fill(127);
ellipse(location.x,location.y,48,48);
ellipse(position.x,position.y,48,48);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ void setup() {
void draw() {
background(255);

// Update the location
// Update the position
mover.update();
// Display the Mover
mover.display();
Expand Down
16 changes: 8 additions & 8 deletions chp01_vectors/NOC_1_11_motion101_acceleration_array/Mover.pde
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@

class Mover {

// The Mover tracks location, velocity, and acceleration
PVector location;
// The Mover tracks position, velocity, and acceleration
PVector position;
PVector velocity;
PVector acceleration;
// The Mover's maximum speed
float topspeed;

Mover() {
// Start in the center
location = new PVector(random(width),random(height));
position = new PVector(random(width),random(height));
velocity = new PVector(0,0);
topspeed = 5;
}

void update() {

// Compute a vector that points from location to mouse
// Compute a vector that points from position to mouse
PVector mouse = new PVector(mouseX,mouseY);
acceleration = PVector.sub(mouse,location);
acceleration = PVector.sub(mouse,position);
// Set magnitude of acceleration
//acceleration.setMag(0.2);
acceleration.normalize();
Expand All @@ -32,15 +32,15 @@ class Mover {
velocity.add(acceleration);
// Limit the velocity by topspeed
velocity.limit(topspeed);
// Location changes by velocity
location.add(velocity);
// position changes by velocity
position.add(velocity);
}

void display() {
stroke(0);
strokeWeight(2);
fill(127,200);
ellipse(location.x,location.y,48,48);
ellipse(position.x,position.y,48,48);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// http://natureofcode.com

// Demonstration of the basics of motion with vector.
// A "Mover" object stores location, velocity, and acceleration as vectors
// A "Mover" object stores position, velocity, and acceleration as vectors
// The motion is controlled by affecting the acceleration (in this case towards the mouse)

Mover[] movers = new Mover[20];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ void draw() {
background(255);


// Add the current speed to the location.
// Add the current speed to the position.
x = x + xspeed;
y = y + yspeed;

Expand All @@ -29,7 +29,7 @@ void draw() {
}


// Display circle at x location
// Display circle at x position
stroke(0);
strokeWeight(2);
fill(127);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
// http://natureofcode.com

// Example 1-2: Bouncing Ball, with PVector!
PVector location;
PVector position;
PVector velocity;

void setup() {
size(200,200);
background(255);
location = new PVector(100,100);
position = new PVector(100,100);
velocity = new PVector(2.5,5);
}

Expand All @@ -18,20 +18,20 @@ void draw() {
fill(255,10);
rect(0,0,width,height);

// Add the current speed to the location.
location.add(velocity);
// Add the current speed to the position.
position.add(velocity);

if ((location.x > width) || (location.x < 0)) {
if ((position.x > width) || (position.x < 0)) {
velocity.x = velocity.x * -1;
}
if ((location.y > height) || (location.y < 0)) {
if ((position.y > height) || (position.y < 0)) {
velocity.y = velocity.y * -1;
}

// Display circle at x location
// Display circle at x position
stroke(0);
fill(175);
ellipse(location.x,location.y,16,16);
ellipse(position.x,position.y,16,16);
}


16 changes: 8 additions & 8 deletions chp01_vectors/NOC_1_2_bouncingball_vectors_object/Ball.pde
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
class Ball {
PVector location;
PVector position;
PVector velocity;

Ball() {
location = new PVector(100, 100);
position = new PVector(100, 100);
velocity = new PVector(2.5, 5);
}

void update() {
// Add the current speed to the location.
location.add(velocity);
if ((location.x > width) || (location.x < 0)) {
// Add the current speed to the position.
position.add(velocity);
if ((position.x > width) || (position.x < 0)) {
velocity.x = velocity.x * -1;
}
if ((location.y > height) || (location.y < 0)) {
if ((position.y > height) || (position.y < 0)) {
velocity.y = velocity.y * -1;
}
}
void display() {
// Display circle at x location
// Display circle at x position
stroke(0);
fill(175);
ellipse(location.x, location.y, 16, 16);
ellipse(position.x, position.y, 16, 16);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,18 @@
// Example 1-3: Vector subtraction

void setup() {
size(640,360);
size(640, 360);
}

void draw() {
background(255);
PVector mouse = new PVector(mouseX,mouseY);
PVector center = new PVector(width/2,height/2);

PVector mouse = new PVector(mouseX, mouseY);
PVector center = new PVector(width/2, height/2);
mouse.sub(center);
translate(width/2,height/2);

translate(width/2, height/2);
strokeWeight(2);
stroke(0);
line(0,0,mouse.x,mouse.y);

}


line(0, 0, mouse.x, mouse.y);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ void setup() {
void draw() {
background(255);

// A vector that points to the mouse location
// A vector that points to the mouse position
PVector mouse = new PVector(mouseX,mouseY);
// A vector that points to the center of the window
PVector center = new PVector(width/2,height/2);
Expand Down
24 changes: 12 additions & 12 deletions chp01_vectors/NOC_1_7_motion101/Mover.pde
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,39 @@

class Mover {

PVector location;
PVector position;
PVector velocity;

Mover() {
location = new PVector(random(width), random(height));
position = new PVector(random(width), random(height));
velocity = new PVector(random(-2, 2), random(-2, 2));
}

void update() {
location.add(velocity);
position.add(velocity);
}

void display() {
stroke(0);
strokeWeight(2);
fill(127);
ellipse(location.x, location.y, 48, 48);
ellipse(position.x, position.y, 48, 48);
}

void checkEdges() {

if (location.x > width) {
location.x = 0;
if (position.x > width) {
position.x = 0;
}
else if (location.x < 0) {
location.x = width;
else if (position.x < 0) {
position.x = width;
}

if (location.y > height) {
location.y = 0;
if (position.y > height) {
position.y = 0;
}
else if (location.y < 0) {
location.y = height;
else if (position.y < 0) {
position.y = height;
}
}
}
Expand Down
24 changes: 12 additions & 12 deletions chp01_vectors/NOC_1_8_motion101_acceleration/Mover.pde
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

class Mover {

PVector location;
PVector position;
PVector velocity;
PVector acceleration;
float topspeed;

Mover() {
location = new PVector(width/2, height/2);
position = new PVector(width/2, height/2);
velocity = new PVector(0, 0);
acceleration = new PVector(-0.001, 0.01);
topspeed = 10;
Expand All @@ -19,30 +19,30 @@ class Mover {
void update() {
velocity.add(acceleration);
velocity.limit(topspeed);
location.add(velocity);
position.add(velocity);
}

void display() {
stroke(0);
strokeWeight(2);
fill(127);
ellipse(location.x, location.y, 48, 48);
ellipse(position.x, position.y, 48, 48);
}

void checkEdges() {

if (location.x > width) {
location.x = 0;
if (position.x > width) {
position.x = 0;
}
else if (location.x < 0) {
location.x = width;
else if (position.x < 0) {
position.x = width;
}

if (location.y > height) {
location.y = 0;
if (position.y > height) {
position.y = 0;
}
else if (location.y < 0) {
location.y = height;
else if (position.y < 0) {
position.y = height;
}
}
}
Expand Down
Loading

0 comments on commit 4195df9

Please sign in to comment.