// Attraction // Daniel Shiffman // A class to describe a currency in our world, has vectors for location, velocity, and acceleration // Also includes scalar values for mass, maximum velocity, and elasticity class Currency { PVector loc; PVector vel; PVector acc; float mass; float max_vel; float bounce = 1.0; // How "elastic" is the object String name; PImage bill; color c; Currency(PVector a, PVector v, PVector l, float m_, String n ) { acc = a.get(); vel = v.get(); loc = l.get(); mass = m_; name = n; max_vel = 16.0; //println(name + ".jpg"); bill = loadImage(name + ".jpg"); //load the image c = bill.get(50, 25); //get the color exactly in the middle of the image bill.resize(int(mass), 0); //resize according to mass } PVector getLoc() { return loc; } PVector getVel() { return vel; } float getMass() { return mass; } void applyForce(PVector force) { force.div(mass); acc.add(force); if (!showVectors) { drawVector(force,loc,1000); } } // Main method to operate object void go() { update(); render(); } // Method to update location void update() { vel.add(acc); vel.limit(max_vel); loc.add(vel); // Multiplying by 0 sets the all the components to 0 acc.mult(0); } // Method to display void render() { ellipseMode(CENTER); stroke(255); fill(255,100); //ellipse(loc.x,loc.y,mass*2,mass*2); if (!showVectors) { drawVector(vel,loc,20); } if (showCrosshairs == true) { //showSparkles = false; //to make sure we never have the two showing at the same time //showMoney = false; stroke(c, 255); //draw the crosshairs line(loc.x, 0, loc.x, height); line(0, loc.y, width, loc.y); //line(loc.x, width, loc.y, height); //line(loc.y, 0, loc.x, height); //line(0,0, loc.x, loc.y); //line(width, 0, loc.x, loc.y); //line (0, height, loc.x, loc.y); //line (width, height, loc.x, loc.y); }//end if if (showSparkles == true) { //showCrosshairs = false; //to make sure we never have the two showing at the same time //showMoney = false; pushMatrix(); //rotate it translate(loc.x,loc.y); rotate(vel.heading2D()); stroke(c, 255); //draw the crosshairs line(0, -200, 0, 200); line(200, 0, -200, 0); popMatrix(); }//end if if (showMoney == true) { //showSparkles = false; //to make sure we never have the two showing at the same time //showCrosshairs = false; pushMatrix(); //rotate it translate(loc.x,loc.y); rotate(vel.heading2D()); imageMode(CENTER); image(bill, 0, 0); popMatrix(); }//end else if (showName == true) { fill(0); //display the name of the item textFont(cFont, 10); text(name, loc.x,loc.y); } } }