Drawing the path of Mover under the influence of Attractor

Hi all,

I am trying to track the movement of a mover class that is moving based on the gravity of a couple of attractors. I need to show the trajectory of this movement using lines/points. Currently the ellipse movement location is determined using velocity/acceleration PVectors and ellipse redraws as it moves thru locations.

Any help is much appreciated.

Thanks!

class Mover {
  // ...
  ArrayList<PVector> prev_ps = new ArrayList();
  // ...
  void draw(){ // Or whenever it moves...
    // ...
    while( prev_ps.size) > 100) prev_ps.remove(0);
    prev_ps.add( new PVector( x, y, 0 ) );
    // ...
    for( int i = 0; i < prev_ps.size()-1; i++) line( prev_ps[i].x, prev_ps[i].y, prev_ps[i+1].x, prev_ps[i+1].y );
  }
  // ...
}

Untested code - Example only - YMMV

thanks! can you please help me with where to add this code in my mover per below?

class Mover {
PVector location;
PVector velocity;
PVector acceleration;
float mass;

Mover() {
mass = 1;
location = new PVector(30,30);
velocity = new PVector(0,0);
acceleration = new PVector(0,0);
}

void applyForce(PVector force1) {
PVector f1 = PVector.div(force1,mass);
acceleration.add(f1);
}
void applyFroce(PVector force2) {
PVector f2 = PVector.div(force2,mass);
acceleration.add(f2);
}
void update() {
velocity.add(acceleration);
location.add(velocity);
acceleration.mult(0);
}
void display() {
stroke(0);
fill(175);
ellipse(location.x,location.y,mass10,mass10);
}
void checkEdges() {
if (location.x > width) {
location.x = width;
velocity.x *= -1;
} else if (location.x < 0) {
velocity.x *= -1;
location.x = 0;
}

 if (location.y > height) {
   velocity.y *= -1;
   location.y = height;
 }

}
}

Mover m;
Attractor1 a1;
Attractor2 a2;

void setup() {
size(640,360);
m = new Mover();
a1 = new Attractor1();
a2 = new Attractor2();
}

void draw() {
background(255);

PVector force1 = a1.attract(m);
PVector force2 = a2.attract(m);
m.applyForce(force1);
m.applyForce(force2);
m.update();

a1.display();
a2.display();
m.display();
}

You could also do it with a secondary PGraphics where you draw the line on. Might be more direct.