// Modified from: // Attraction // Daniel Shiffman // A class for a draggable attractive body in our world class Attractor { float mass; // Mass, tied to size PVector location; // Location float g; Attractor() { location = new PVector(width/2,height/2); //location = new PVector(width/5,height/2); mass = 100; g = 3; //The Attractor has to be quite attractive to compete with the wind's // acceleration, especially over time } PVector attract(Particle m) { PVector force = PVector.sub(location,m.pH); // Calculate direction of force float distance = force.mag(); // Distance between objects distance = constrain(distance,5.0,25.0); // Limiting the distance to eliminate "extreme" results //for very close or very far objects force.normalize(); // Normalize vector (distance doesn't matter here, //we just want this vector for direction) float strength = (g * mass * m.mass) / (distance * distance); // Calculate gravitional force magnitude force.mult(strength); // Get force vector --> magnitude * direction return force; } // Method to display void display() { stroke(0); fill(0); ellipse(location.x,location.y,mass*2,mass*2); } }