From 77c2b109d908b0bf5bbac59a5e1b8d25f0923b6f Mon Sep 17 00:00:00 2001 From: Yong Bakos Date: Thu, 14 Feb 2013 15:24:37 -0700 Subject: [PATCH] Replacing heading2D with heading for all Nature of Code examples. #1627 --- .../NOC_10_02_SeekingNeural/Vehicle.pde | 30 +++++++++---------- .../Crawler.pde | 18 +++++------ .../NOC_3_03_pointing_velocity/Mover.pde | 6 ++-- .../NOC_4_08_ParticleSystemSmoke.pde | 6 ++-- .../NOC_4_08_ParticleSystemSmoke_b.pde | 6 ++-- .../CollisionsEqualMass/drawVector.pde | 2 +- .../Exercise_6_04_Wander/Vehicle.pde | 12 ++++---- .../Exercise_6_09_AngleBetween.pde | 6 ++-- .../chp6_agents/NOC_6_01_Seek/Vehicle.pde | 14 ++++----- .../NOC_6_01_Seek_trail/Vehicle.pde | 18 +++++------ .../chp6_agents/NOC_6_02_Arrive/Vehicle.pde | 12 ++++---- .../NOC_6_03_StayWithinWalls/Vehicle.pde | 14 ++++----- .../Vehicle.pde | 20 ++++++------- .../NOC_6_04_Flow_Figures/FlowField.pde | 4 +-- .../NOC_6_04_Flow_Figures/Vehicle.pde | 2 +- .../NOC_6_04_Flowfield/FlowField.pde | 2 +- .../NOC_6_04_Flowfield/Vehicle.pde | 2 +- .../NOC_6_05_PathFollowingSimple/Vehicle.pde | 2 +- .../NOC_6_06_PathFollowing/Vehicle.pde | 2 +- .../chp6_agents/NOC_6_09_Flocking/Boid.pde | 4 +-- .../chp6_agents/StayWithinCircle/Vehicle.pde | 14 ++++----- .../chp6_agents/flocking_sliders/Boid.pde | 4 +-- .../chp8_fractals/Tree2/Branch.pde | 12 ++++---- .../chp8_fractals/Tree3/Branch.pde | 6 ++-- .../chp9_ga/EvolveFlowField/Rocket.pde | 8 ++--- .../Rocket.pde | 6 ++-- .../chp9_ga/NOC_9_03_SmartRockets/Rocket.pde | 6 ++-- 27 files changed, 119 insertions(+), 119 deletions(-) diff --git a/java/examples/Books/Nature of Code/chp10_nn/NOC_10_02_SeekingNeural/Vehicle.pde b/java/examples/Books/Nature of Code/chp10_nn/NOC_10_02_SeekingNeural/Vehicle.pde index efd9bf287..fc6a83b6c 100644 --- a/java/examples/Books/Nature of Code/chp10_nn/NOC_10_02_SeekingNeural/Vehicle.pde +++ b/java/examples/Books/Nature of Code/chp10_nn/NOC_10_02_SeekingNeural/Vehicle.pde @@ -4,10 +4,10 @@ // The "Vehicle" class class Vehicle { - + // Vehicle now has a brain! Perceptron brain; - + PVector location; PVector velocity; PVector acceleration; @@ -34,7 +34,7 @@ class Vehicle { location.add(velocity); // Reset accelerationelertion to 0 each cycle acceleration.mult(0); - + location.x = constrain(location.x,0,width); location.y = constrain(location.y,0,height); } @@ -43,48 +43,48 @@ class Vehicle { // We could add mass here if we want A = F / M acceleration.add(force); } - + // Here is where the brain processes everything void steer(ArrayList targets) { // Make an array of forces PVector[] forces = new PVector[targets.size()]; - + // Steer towards all targets for (int i = 0; i < forces.length; i++) { forces[i] = seek(targets.get(i)); } - + // That array of forces is the input to the brain PVector result = brain.feedforward(forces); - + // Use the result to steer the vehicle applyForce(result); - + // Train the brain according to the error PVector error = PVector.sub(desired, location); brain.train(forces,error); - + } - + // A method that calculates a steering force towards a target // STEER = DESIRED MINUS VELOCITY PVector seek(PVector target) { PVector desired = PVector.sub(target,location); // A vector pointing from the location to the target - + // Normalize desired and scale to maximum speed desired.normalize(); desired.mult(maxspeed); // Steering = Desired minus velocity PVector steer = PVector.sub(desired,velocity); steer.limit(maxforce); // Limit to maximum steering force - + return steer; } - + void display() { - + // Draw a triangle rotated in the direction of velocity - float theta = velocity.heading2D() + PI/2; + float theta = velocity.heading() + PI/2; fill(175); stroke(0); strokeWeight(1); diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/AttractionArrayWithOscillation/Crawler.pde b/java/examples/Books/Nature of Code/chp3_oscillation/AttractionArrayWithOscillation/Crawler.pde index 7c03641ee..5739cd300 100644 --- a/java/examples/Books/Nature of Code/chp3_oscillation/AttractionArrayWithOscillation/Crawler.pde +++ b/java/examples/Books/Nature of Code/chp3_oscillation/AttractionArrayWithOscillation/Crawler.pde @@ -12,9 +12,9 @@ class Crawler { PVector vel; PVector acc; float mass; - + Oscillator osc; - + Crawler() { acc = new PVector(); vel = new PVector(random(-1,1),random(-1,1)); @@ -22,9 +22,9 @@ class Crawler { mass = random(8,16); osc = new Oscillator(mass*2); } - + void applyForce(PVector force) { - PVector f = force.get(); + PVector f = force.get(); f.div(mass); acc.add(f); } @@ -35,13 +35,13 @@ class Crawler { loc.add(vel); // Multiplying by 0 sets the all the components to 0 acc.mult(0); - + osc.update(vel.mag()/10); } - + // Method to display void display() { - float angle = vel.heading2D(); + float angle = vel.heading(); pushMatrix(); translate(loc.x,loc.y); rotate(angle); @@ -49,10 +49,10 @@ class Crawler { stroke(0); fill(175,100); ellipse(0,0,mass*2,mass*2); - + osc.display(loc); popMatrix(); - + } } diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_03_pointing_velocity/Mover.pde b/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_03_pointing_velocity/Mover.pde index 399d93a4d..e5a951a56 100644 --- a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_03_pointing_velocity/Mover.pde +++ b/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_03_pointing_velocity/Mover.pde @@ -35,7 +35,7 @@ class Mover { } void display() { - float theta = velocity.heading2D(); + float theta = velocity.heading(); stroke(0); strokeWeight(2); @@ -52,14 +52,14 @@ class Mover { if (location.x > width) { location.x = 0; - } + } else if (location.x < 0) { location.x = width; } if (location.y > height) { location.y = 0; - } + } else if (location.y < 0) { location.y = height; } diff --git a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_08_ParticleSystemSmoke/NOC_4_08_ParticleSystemSmoke.pde b/java/examples/Books/Nature of Code/chp4_systems/NOC_4_08_ParticleSystemSmoke/NOC_4_08_ParticleSystemSmoke.pde index 61a662565..d5e72c0f3 100644 --- a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_08_ParticleSystemSmoke/NOC_4_08_ParticleSystemSmoke.pde +++ b/java/examples/Books/Nature of Code/chp4_systems/NOC_4_08_ParticleSystemSmoke/NOC_4_08_ParticleSystemSmoke.pde @@ -22,7 +22,7 @@ void setup() { void draw() { background(0); - + // Calculate a "wind" force based on mouse horizontal position float dx = map(mouseX,0,width,-0.2,0.2); PVector wind = new PVector(dx,0); @@ -31,7 +31,7 @@ void draw() { for (int i = 0; i < 2; i++) { ps.addParticle(); } - + // Draw an arrow representing the wind force drawVector(wind, new PVector(width/2,50,0),500); @@ -45,7 +45,7 @@ void drawVector(PVector v, PVector loc, float scayl) { translate(loc.x,loc.y); stroke(255); // Call vector heading function to get direction (note that pointing up is a heading of 0) and rotate - rotate(v.heading2D()); + rotate(v.heading()); // Calculate length of vector & scale it to be bigger or smaller if necessary float len = v.mag()*scayl; // Draw three lines to make an arrow (draw pointing up since we've rotate to the proper direction) diff --git a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_08_ParticleSystemSmoke_b/NOC_4_08_ParticleSystemSmoke_b.pde b/java/examples/Books/Nature of Code/chp4_systems/NOC_4_08_ParticleSystemSmoke_b/NOC_4_08_ParticleSystemSmoke_b.pde index 61a662565..d5e72c0f3 100644 --- a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_08_ParticleSystemSmoke_b/NOC_4_08_ParticleSystemSmoke_b.pde +++ b/java/examples/Books/Nature of Code/chp4_systems/NOC_4_08_ParticleSystemSmoke_b/NOC_4_08_ParticleSystemSmoke_b.pde @@ -22,7 +22,7 @@ void setup() { void draw() { background(0); - + // Calculate a "wind" force based on mouse horizontal position float dx = map(mouseX,0,width,-0.2,0.2); PVector wind = new PVector(dx,0); @@ -31,7 +31,7 @@ void draw() { for (int i = 0; i < 2; i++) { ps.addParticle(); } - + // Draw an arrow representing the wind force drawVector(wind, new PVector(width/2,50,0),500); @@ -45,7 +45,7 @@ void drawVector(PVector v, PVector loc, float scayl) { translate(loc.x,loc.y); stroke(255); // Call vector heading function to get direction (note that pointing up is a heading of 0) and rotate - rotate(v.heading2D()); + rotate(v.heading()); // Calculate length of vector & scale it to be bigger or smaller if necessary float len = v.mag()*scayl; // Draw three lines to make an arrow (draw pointing up since we've rotate to the proper direction) diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/CollisionsEqualMass/drawVector.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/CollisionsEqualMass/drawVector.pde index 141c06960..3f60ddae8 100644 --- a/java/examples/Books/Nature of Code/chp5_physicslibraries/CollisionsEqualMass/drawVector.pde +++ b/java/examples/Books/Nature of Code/chp5_physicslibraries/CollisionsEqualMass/drawVector.pde @@ -9,7 +9,7 @@ void drawVector(PVector v, PVector loc, float scayl) { translate(loc.x,loc.y); stroke(0); // Call vector heading function to get direction (note that pointing up is a heading of 0) and rotate - rotate(v.heading2D()); + rotate(v.heading()); // Calculate length of vector & scale it to be bigger or smaller if necessary float len = v.mag()*scayl; // Draw three lines to make an arrow (draw pointing up since we've rotate to the proper direction) diff --git a/java/examples/Books/Nature of Code/chp6_agents/Exercise_6_04_Wander/Vehicle.pde b/java/examples/Books/Nature of Code/chp6_agents/Exercise_6_04_Wander/Vehicle.pde index fb979e8c5..31b824b87 100644 --- a/java/examples/Books/Nature of Code/chp6_agents/Exercise_6_04_Wander/Vehicle.pde +++ b/java/examples/Books/Nature of Code/chp6_agents/Exercise_6_04_Wander/Vehicle.pde @@ -52,16 +52,16 @@ class Vehicle { circleloc.normalize(); // Normalize to get heading circleloc.mult(wanderD); // Multiply by distance circleloc.add(location); // Make it relative to boid's location - - float h = velocity.heading2D(); // We need to know the heading to offset wandertheta + + float h = velocity.heading(); // We need to know the heading to offset wandertheta PVector circleOffSet = new PVector(wanderR*cos(wandertheta+h),wanderR*sin(wandertheta+h)); PVector target = PVector.add(circleloc,circleOffSet); seek(target); - // Render wandering circle, etc. + // Render wandering circle, etc. if (debug) drawWanderStuff(location,circleloc,target,wanderR); - } + } void applyForce(PVector force) { // We could add mass here if we want A = F / M @@ -86,7 +86,7 @@ class Vehicle { void display() { // Draw a triangle rotated in the direction of velocity - float theta = velocity.heading2D() + radians(90); + float theta = velocity.heading() + radians(90); fill(127); stroke(0); pushMatrix(); @@ -112,7 +112,7 @@ class Vehicle { // A method just to draw the circle associated with wandering void drawWanderStuff(PVector location, PVector circle, PVector target, float rad) { - stroke(0); + stroke(0); noFill(); ellipseMode(CENTER); ellipse(circle.x,circle.y,rad*2,rad*2); diff --git a/java/examples/Books/Nature of Code/chp6_agents/Exercise_6_09_AngleBetween/Exercise_6_09_AngleBetween.pde b/java/examples/Books/Nature of Code/chp6_agents/Exercise_6_09_AngleBetween/Exercise_6_09_AngleBetween.pde index aec7e814f..60460740d 100644 --- a/java/examples/Books/Nature of Code/chp6_agents/Exercise_6_09_AngleBetween/Exercise_6_09_AngleBetween.pde +++ b/java/examples/Books/Nature of Code/chp6_agents/Exercise_6_09_AngleBetween/Exercise_6_09_AngleBetween.pde @@ -15,7 +15,7 @@ void draw() { // A "vector" (really a point) to store the mouse location and screen center location PVector mouseLoc = new PVector(mouseX, mouseY); - PVector centerLoc = new PVector(width/2, height/2); + PVector centerLoc = new PVector(width/2, height/2); // Aha, a vector to store the displacement between the mouse and center PVector v = PVector.sub(mouseLoc, centerLoc); @@ -43,10 +43,10 @@ void drawVector(PVector v, PVector loc, float scayl) { stroke(0); strokeWeight(2); // Call vector heading function to get direction (pointing up is a heading of 0) - rotate(v.heading2D()); + rotate(v.heading()); // Calculate length of vector & scale it to be bigger or smaller if necessary float len = v.mag()*scayl; - // Draw three lines to make an arrow + // Draw three lines to make an arrow line(0, 0, len, 0); line(len, 0, len-arrowsize, +arrowsize/2); line(len, 0, len-arrowsize, -arrowsize/2); diff --git a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_01_Seek/Vehicle.pde b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_01_Seek/Vehicle.pde index dfb311c92..722879b31 100644 --- a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_01_Seek/Vehicle.pde +++ b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_01_Seek/Vehicle.pde @@ -7,7 +7,7 @@ // The "Vehicle" class class Vehicle { - + PVector location; PVector velocity; PVector acceleration; @@ -44,20 +44,20 @@ class Vehicle { // STEER = DESIRED MINUS VELOCITY void seek(PVector target) { PVector desired = PVector.sub(target,location); // A vector pointing from the location to the target - + // Normalize desired and scale to maximum speed desired.normalize(); desired.mult(maxspeed); // Steering = Desired minus velocity PVector steer = PVector.sub(desired,velocity); steer.limit(maxforce); // Limit to maximum steering force - + applyForce(steer); } - + void display() { // Draw a triangle rotated in the direction of velocity - float theta = velocity.heading2D() + PI/2; + float theta = velocity.heading() + PI/2; fill(127); stroke(0); strokeWeight(1); @@ -70,8 +70,8 @@ class Vehicle { vertex(r, r*2); endShape(CLOSE); popMatrix(); - - + + } } diff --git a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_01_Seek_trail/Vehicle.pde b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_01_Seek_trail/Vehicle.pde index d0b33d652..f8f81e829 100644 --- a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_01_Seek_trail/Vehicle.pde +++ b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_01_Seek_trail/Vehicle.pde @@ -32,7 +32,7 @@ class Vehicle { location.add(velocity); // Reset accelerationelertion to 0 each cycle acceleration.mult(0); - + history.add(location.get()); if (history.size() > 100) { history.remove(0); @@ -48,17 +48,17 @@ class Vehicle { // STEER = DESIRED MINUS VELOCITY void seek(PVector target) { PVector desired = PVector.sub(target,location); // A vector pointing from the location to the target - + // Normalize desired and scale to maximum speed desired.normalize(); desired.mult(maxspeed); // Steering = Desired minus velocity PVector steer = PVector.sub(desired,velocity); steer.limit(maxforce); // Limit to maximum steering force - + applyForce(steer); } - + void display() { beginShape(); stroke(0); @@ -68,10 +68,10 @@ class Vehicle { vertex(v.x,v.y); } endShape(); - - + + // Draw a triangle rotated in the direction of velocity - float theta = velocity.heading2D() + PI/2; + float theta = velocity.heading() + PI/2; fill(127); stroke(0); strokeWeight(1); @@ -84,8 +84,8 @@ class Vehicle { vertex(r, r*2); endShape(CLOSE); popMatrix(); - - + + } } diff --git a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_02_Arrive/Vehicle.pde b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_02_Arrive/Vehicle.pde index 72fe089b8..512b357d1 100644 --- a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_02_Arrive/Vehicle.pde +++ b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_02_Arrive/Vehicle.pde @@ -5,7 +5,7 @@ // The "Vehicle" class class Vehicle { - + PVector location; PVector velocity; PVector acceleration; @@ -57,11 +57,11 @@ class Vehicle { steer.limit(maxforce); // Limit to maximum steering force applyForce(steer); } - + void display() { - + // Draw a triangle rotated in the direction of velocity - float theta = velocity.heading2D() + PI/2; + float theta = velocity.heading() + PI/2; fill(127); stroke(0); strokeWeight(1); @@ -74,8 +74,8 @@ class Vehicle { vertex(r, r*2); endShape(CLOSE); popMatrix(); - - + + } } diff --git a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_03_StayWithinWalls/Vehicle.pde b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_03_StayWithinWalls/Vehicle.pde index 9a507181c..f815cce9a 100644 --- a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_03_StayWithinWalls/Vehicle.pde +++ b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_03_StayWithinWalls/Vehicle.pde @@ -13,7 +13,7 @@ class Vehicle { float maxspeed; float maxforce; - + Vehicle(float x, float y) { acceleration = new PVector(0, 0); velocity = new PVector(3, -2); @@ -46,17 +46,17 @@ class Vehicle { if (location.x < d) { desired = new PVector(maxspeed, velocity.y); - } + } else if (location.x > width -d) { desired = new PVector(-maxspeed, velocity.y); - } + } if (location.y < d) { desired = new PVector(velocity.x, maxspeed); - } + } else if (location.y > height-d) { desired = new PVector(velocity.x, -maxspeed); - } + } if (desired != null) { desired.normalize(); @@ -65,7 +65,7 @@ class Vehicle { steer.limit(maxforce); applyForce(steer); } - } + } void applyForce(PVector force) { // We could add mass here if we want A = F / M @@ -75,7 +75,7 @@ class Vehicle { void display() { // Draw a triangle rotated in the direction of velocity - float theta = velocity.heading2D() + radians(90); + float theta = velocity.heading() + radians(90); fill(127); stroke(0); pushMatrix(); diff --git a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_03_StayWithinWalls_trail/Vehicle.pde b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_03_StayWithinWalls_trail/Vehicle.pde index 0d94054a4..1d9bac9cc 100644 --- a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_03_StayWithinWalls_trail/Vehicle.pde +++ b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_03_StayWithinWalls_trail/Vehicle.pde @@ -14,7 +14,7 @@ class Vehicle { float maxspeed; float maxforce; - + Vehicle(float x, float y) { acceleration = new PVector(0, 0); velocity = new PVector(3, -2); @@ -39,7 +39,7 @@ class Vehicle { location.add(velocity); // Reset accelertion to 0 each cycle acceleration.mult(0); - + history.add(location.get()); if (history.size() > 500) { history.remove(0); @@ -52,17 +52,17 @@ class Vehicle { if (location.x < d) { desired = new PVector(maxspeed, velocity.y); - } + } else if (location.x > width -d) { desired = new PVector(-maxspeed, velocity.y); - } + } if (location.y < d) { desired = new PVector(velocity.x, maxspeed); - } + } else if (location.y > height-d) { desired = new PVector(velocity.x, -maxspeed); - } + } if (desired != null) { desired.normalize(); @@ -71,7 +71,7 @@ class Vehicle { steer.limit(maxforce); applyForce(steer); } - } + } void applyForce(PVector force) { // We could add mass here if we want A = F / M @@ -88,10 +88,10 @@ class Vehicle { vertex(v.x,v.y); } endShape(); - - + + // Draw a triangle rotated in the direction of velocity - float theta = velocity.heading2D() + radians(90); + float theta = velocity.heading() + radians(90); fill(127); stroke(0); pushMatrix(); diff --git a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_04_Flow_Figures/FlowField.pde b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_04_Flow_Figures/FlowField.pde index 75b471b29..b6da8c9d2 100644 --- a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_04_Flow_Figures/FlowField.pde +++ b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_04_Flow_Figures/FlowField.pde @@ -49,7 +49,7 @@ class FlowField { pushMatrix(); //translate(i*resolution+arrow.width/2,j*resolution+arrow.height/2); translate(i*resolution,j*resolution); - rotate(field[i][j].heading2D()); + rotate(field[i][j].heading()); imageMode(CENTER); //scale(0.2); image(a,0,0); @@ -69,7 +69,7 @@ class FlowField { translate(x,y); stroke(0,100); // Call vector heading function to get direction (note that pointing up is a heading of 0) and rotate - rotate(v.heading2D()); + rotate(v.heading()); // Calculate length of vector & scale it to be bigger or smaller if necessary float len = v.mag()*scayl; // Draw three lines to make an arrow (draw pointing up since we've rotate to the proper direction) diff --git a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_04_Flow_Figures/Vehicle.pde b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_04_Flow_Figures/Vehicle.pde index 2326a1e7c..82484f3ed 100644 --- a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_04_Flow_Figures/Vehicle.pde +++ b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_04_Flow_Figures/Vehicle.pde @@ -61,7 +61,7 @@ class Vehicle { void display() { // Draw a triangle rotated in the direction of velocity - float theta = velocity.heading2D() + radians(90); + float theta = velocity.heading() + radians(90); fill(175); stroke(0); pushMatrix(); diff --git a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_04_Flowfield/FlowField.pde b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_04_Flowfield/FlowField.pde index 08bf7eb23..fedf64418 100644 --- a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_04_Flowfield/FlowField.pde +++ b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_04_Flowfield/FlowField.pde @@ -54,7 +54,7 @@ class FlowField { translate(x,y); stroke(0,100); // Call vector heading function to get direction (note that pointing up is a heading of 0) and rotate - rotate(v.heading2D()); + rotate(v.heading()); // Calculate length of vector & scale it to be bigger or smaller if necessary float len = v.mag()*scayl; // Draw three lines to make an arrow (draw pointing up since we've rotate to the proper direction) diff --git a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_04_Flowfield/Vehicle.pde b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_04_Flowfield/Vehicle.pde index 2326a1e7c..82484f3ed 100644 --- a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_04_Flowfield/Vehicle.pde +++ b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_04_Flowfield/Vehicle.pde @@ -61,7 +61,7 @@ class Vehicle { void display() { // Draw a triangle rotated in the direction of velocity - float theta = velocity.heading2D() + radians(90); + float theta = velocity.heading() + radians(90); fill(175); stroke(0); pushMatrix(); diff --git a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_05_PathFollowingSimple/Vehicle.pde b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_05_PathFollowingSimple/Vehicle.pde index 109d7d658..4a8fc9e72 100644 --- a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_05_PathFollowingSimple/Vehicle.pde +++ b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_05_PathFollowingSimple/Vehicle.pde @@ -136,7 +136,7 @@ class Vehicle { void render() { // Draw a triangle rotated in the direction of velocity - float theta = velocity.heading2D() + radians(90); + float theta = velocity.heading() + radians(90); fill(175); stroke(0); pushMatrix(); diff --git a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_06_PathFollowing/Vehicle.pde b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_06_PathFollowing/Vehicle.pde index b705abaf2..4e7e4c428 100644 --- a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_06_PathFollowing/Vehicle.pde +++ b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_06_PathFollowing/Vehicle.pde @@ -167,7 +167,7 @@ class Vehicle { void render() { // Draw a triangle rotated in the direction of velocity - float theta = velocity.heading2D() + radians(90); + float theta = velocity.heading() + radians(90); fill(175); stroke(0); pushMatrix(); diff --git a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_09_Flocking/Boid.pde b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_09_Flocking/Boid.pde index 194dfc362..ddde2f204 100644 --- a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_09_Flocking/Boid.pde +++ b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_09_Flocking/Boid.pde @@ -73,10 +73,10 @@ class Boid { steer.limit(maxforce); // Limit to maximum steering force return steer; } - + void render() { // Draw a triangle rotated in the direction of velocity - float theta = velocity.heading2D() + radians(90); + float theta = velocity.heading() + radians(90); fill(175); stroke(0); pushMatrix(); diff --git a/java/examples/Books/Nature of Code/chp6_agents/StayWithinCircle/Vehicle.pde b/java/examples/Books/Nature of Code/chp6_agents/StayWithinCircle/Vehicle.pde index 7bc96d2fa..d05cfda0d 100644 --- a/java/examples/Books/Nature of Code/chp6_agents/StayWithinCircle/Vehicle.pde +++ b/java/examples/Books/Nature of Code/chp6_agents/StayWithinCircle/Vehicle.pde @@ -11,7 +11,7 @@ class Vehicle { float maxspeed; float maxforce; - + Vehicle(float x, float y) { acceleration = new PVector(0, 0); velocity = new PVector(1,0); @@ -41,13 +41,13 @@ class Vehicle { void boundaries() { PVector desired = null; - + // Predict location 25 (arbitrary choice) frames ahead PVector predict = velocity.get(); predict.mult(25); PVector futureLocation = PVector.add(location, predict); float distance = PVector.dist(futureLocation,circleLocation); - + if (distance > circleRadius) { PVector toCenter = PVector.sub(circleLocation,location); toCenter.normalize(); @@ -62,11 +62,11 @@ class Vehicle { steer.limit(maxforce); applyForce(steer); } - + fill(255,0,0); ellipse(futureLocation.x,futureLocation.y,4,4); - - } + + } void applyForce(PVector force) { // We could add mass here if we want A = F / M @@ -76,7 +76,7 @@ class Vehicle { void display() { // Draw a triangle rotated in the direction of velocity - float theta = velocity.heading2D() + radians(90); + float theta = velocity.heading() + radians(90); fill(175); stroke(0); pushMatrix(); diff --git a/java/examples/Books/Nature of Code/chp6_agents/flocking_sliders/Boid.pde b/java/examples/Books/Nature of Code/chp6_agents/flocking_sliders/Boid.pde index 808b7c6d5..dec740f1f 100644 --- a/java/examples/Books/Nature of Code/chp6_agents/flocking_sliders/Boid.pde +++ b/java/examples/Books/Nature of Code/chp6_agents/flocking_sliders/Boid.pde @@ -82,10 +82,10 @@ class Boid { return steer; } - + void render() { // Draw a triangle rotated in the direction of velocity - float theta = vel.heading2D() + radians(90); + float theta = vel.heading() + radians(90); fill(175); stroke(0); pushMatrix(); diff --git a/java/examples/Books/Nature of Code/chp8_fractals/Tree2/Branch.pde b/java/examples/Books/Nature of Code/chp8_fractals/Tree2/Branch.pde index f75ac71c9..e6db3e3df 100644 --- a/java/examples/Books/Nature of Code/chp8_fractals/Tree2/Branch.pde +++ b/java/examples/Books/Nature of Code/chp8_fractals/Tree2/Branch.pde @@ -7,7 +7,7 @@ // A class for one branch in the system class Branch { - // Each has a location, velocity, and timer + // Each has a location, velocity, and timer // We could implement this same idea with different data PVector loc; PVector vel; @@ -20,12 +20,12 @@ class Branch { timerstart = n; timer = timerstart; } - + // Move location void update() { loc.add(vel); } - + // Draw a dot at location void render() { fill(0); @@ -33,7 +33,7 @@ class Branch { ellipseMode(CENTER); ellipse(loc.x,loc.y,2,2); } - + // Did the timer run out? boolean timeToBranch() { timer--; @@ -47,7 +47,7 @@ class Branch { // Create a new branch at the current location, but change direction by a given angle Branch branch(float angle) { // What is my current heading - float theta = vel.heading2D(); + float theta = vel.heading(); // What is my current speed float mag = vel.mag(); // Turn me @@ -57,5 +57,5 @@ class Branch { // Return a new Branch return new Branch(loc,newvel,timerstart*0.66f); } - + } diff --git a/java/examples/Books/Nature of Code/chp8_fractals/Tree3/Branch.pde b/java/examples/Books/Nature of Code/chp8_fractals/Tree3/Branch.pde index 7c5e8b9c8..21e494375 100644 --- a/java/examples/Books/Nature of Code/chp8_fractals/Tree3/Branch.pde +++ b/java/examples/Books/Nature of Code/chp8_fractals/Tree3/Branch.pde @@ -7,7 +7,7 @@ // A class for one branch in the system class Branch { - // Each has a location, velocity, and timer + // Each has a location, velocity, and timer // We could implement this same idea with different data PVector start; PVector end; @@ -44,7 +44,7 @@ class Branch { if (timer < 0 && growing) { growing = false; return true; - } + } else { return false; } @@ -53,7 +53,7 @@ class Branch { // Create a new branch at the current location, but change direction by a given angle Branch branch(float angle) { // What is my current heading - float theta = vel.heading2D(); + float theta = vel.heading(); // What is my current speed float mag = vel.mag(); // Turn me diff --git a/java/examples/Books/Nature of Code/chp9_ga/EvolveFlowField/Rocket.pde b/java/examples/Books/Nature of Code/chp9_ga/EvolveFlowField/Rocket.pde index 7bc8a0524..a10c48c5b 100644 --- a/java/examples/Books/Nature of Code/chp9_ga/EvolveFlowField/Rocket.pde +++ b/java/examples/Books/Nature of Code/chp9_ga/EvolveFlowField/Rocket.pde @@ -34,7 +34,7 @@ class Rocket { recordDist = width; } - // FITNESS FUNCTION + // FITNESS FUNCTION // distance = distance from target // finish = what order did i finish (first, second, etc. . .) // f(distance,finish) = (1.0f / finish^1.5) * (1.0f / distance^6); @@ -121,7 +121,7 @@ class Rocket { //fill(0,150); //stroke(0); //ellipse(location.x,location.y,r,r); - float theta = velocity.heading2D() + PI/2; + float theta = velocity.heading() + PI/2; fill(200,100); stroke(0); pushMatrix(); @@ -133,8 +133,8 @@ class Rocket { vertex(r, r*2); endShape(); popMatrix(); - - + + } float getFitness() { diff --git a/java/examples/Books/Nature of Code/chp9_ga/NOC_9_02_SmartRockets_superbasic/Rocket.pde b/java/examples/Books/Nature of Code/chp9_ga/NOC_9_02_SmartRockets_superbasic/Rocket.pde index 2456856e4..bbfa3af6a 100644 --- a/java/examples/Books/Nature of Code/chp9_ga/NOC_9_02_SmartRockets_superbasic/Rocket.pde +++ b/java/examples/Books/Nature of Code/chp9_ga/NOC_9_02_SmartRockets_superbasic/Rocket.pde @@ -24,7 +24,7 @@ class Rocket { int geneCounter = 0; boolean hitTarget = false; // Did I reach the target - + //constructor Rocket(PVector l, DNA dna_) { acceleration = new PVector(); @@ -58,7 +58,7 @@ class Rocket { float d = dist(location.x, location.y, target.x, target.y); if (d < 12) { hitTarget = true; - } + } } void applyForce(PVector f) { @@ -72,7 +72,7 @@ class Rocket { } void display() { - float theta = velocity.heading2D() + PI/2; + float theta = velocity.heading() + PI/2; fill(200, 100); stroke(0); pushMatrix(); diff --git a/java/examples/Books/Nature of Code/chp9_ga/NOC_9_03_SmartRockets/Rocket.pde b/java/examples/Books/Nature of Code/chp9_ga/NOC_9_03_SmartRockets/Rocket.pde index 5ce1b313b..188cbdcc3 100644 --- a/java/examples/Books/Nature of Code/chp9_ga/NOC_9_03_SmartRockets/Rocket.pde +++ b/java/examples/Books/Nature of Code/chp9_ga/NOC_9_03_SmartRockets/Rocket.pde @@ -39,7 +39,7 @@ class Rocket { recordDist = 10000; // Some high number that will be beat instantly } - // FITNESS FUNCTION + // FITNESS FUNCTION // distance = distance from target // finish = what order did i finish (first, second, etc. . .) // f(distance,finish) = (1.0f / finish^1.5) * (1.0f / distance^6); @@ -80,7 +80,7 @@ class Rocket { if (target.contains(location) && !hitTarget) { hitTarget = true; - } + } else if (!hitTarget) { finishTime++; } @@ -108,7 +108,7 @@ class Rocket { void display() { //background(255,0,0); - float theta = velocity.heading2D() + PI/2; + float theta = velocity.heading() + PI/2; fill(200, 100); stroke(0); strokeWeight(1);