bruzed_transmutation/Mover.pde
class Mover 
{
	
	PVector location;
	  PVector velocity;
	  PVector acceleration;
	  float r;
	  float wandertheta;
	  float maxforce;    // Maximum steering force
	  float maxspeed;    // Maximum speed

	  Mover(float x, float y) {
	    acceleration = new PVector(0,0);
	    velocity = new PVector(0,0);
	    location = new PVector(x,y);
	    r = 40;
	    wandertheta = 0;
	    maxspeed = 2;
	    maxforce = 0.05;
	  }

	  void run() {
	    update();
	    borders();
	    display();
	  }

	  // Method to update location
	  void update() {
	    // Update velocity
	    velocity.add(acceleration);
	    // Limit speed
	    velocity.limit(maxspeed);
	    location.add(velocity);
	    // Reset accelertion to 0 each cycle
	    acceleration.mult(0);
	  }

	  void wander() {
	    float wanderR = 25;         // Radius for our "wander circle"
	    float wanderD = 40;         // Distance for our "wander circle"
	    float change = 0.6;
	    wandertheta += random(-change,change);     // Randomly change wander theta

	    // Now we have to calculate the new location to steer towards on the wander circle
	    PVector circleloc = velocity.get();    // Start with velocity
	    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

	    PVector circleOffSet = new PVector(wanderR*cos(wandertheta+h),wanderR*sin(wandertheta+h));
	    PVector target = PVector.add(circleloc,circleOffSet);
	    seek(target);

	    // 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
	    acceleration.add(force);
	  }


	  // A method that calculates and applies a steering force towards a target
	  // 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() + radians(90);
		noStroke();
	    pushMatrix();
	    translate(location.x,location.y);
	    rotate(theta);
		imageMode(CENTER);
		image(redTriangle, 0, 0, r*2, r*2);
		image(greenTriangle, 0, 0, r*1.5, r*1.5);
		image(whiteTriangle, 0, 0, r, r);
	    popMatrix();
	  }

	  // Wraparound
	  void borders() {
	    if (location.x < -r) location.x = width+r;
	    if (location.y < -r) location.y = height + r;
	    if (location.x > width+r) location.x = -r;
	    if (location.y > height + r) location.y = -r;
	  }

}
