Well… You have 2 options from my point of view.
The first easy (and kinda lazy one) is numerical integration. Basically you have a single force acting on the projectile, which creates a constant acceleration (gravity, of an acceleration of around 9.81 m.s-2).
You could store position (as a PVector) as well as speed (as a PVector as well), then add onto velocity your acceleration times a small time step, and then add to your position your velocity times the same small time step. Here is a simple example (press enter to start it) :
PVector pos;
PVector speed;
float dt = 1./60.0;
ArrayList<PVector> trace;
boolean started = false;
void setup() {
size(1280, 720);
frameRate(60);
pos = new PVector(10, height-10);
speed = new PVector(90, -200);
trace = new ArrayList<PVector>();
trace.add(pos.copy());
}
void keyPressed(){
if(key == ENTER) started = true;
}
void draw() {
background(255);
if(started){
speed.add(PVector.mult(new PVector(0, 60), dt));
pos.add(PVector.mult(speed, dt));
trace.add(pos.copy());
}
noFill();
stroke(0, 100);
strokeWeight(2);
beginShape();
for(PVector v: trace){
vertex(v.x, v.y);
}
endShape();
fill(255, 0, 0);
noStroke();
ellipse(pos.x, pos.y, 10, 10);
stroke(0);
strokeWeight(1);
line(pos.x, pos.y, pos.x, pos.y+0.4*speed.y);
line(pos.x, pos.y, pos.x+0.4*speed.x, pos.y);
strokeWeight(2);
line(pos.x, pos.y, pos.x+0.4*speed.x, pos.y+0.4*speed.y);
}
This should work fine, and what is cool with integration is that you could as simply add all other types of forces (let’s say air resistance for example).
This is pretty imprecise though (as dt gets smaller, the precision gets better but the calculation time gets worse).
If you plan to only implement simple cases (constant acceleration or simple forms of air resistance) I advise to analytically integrate acceleration. In this case it is very easy and the solution is a linear function for x and a parabola for y. Here is the mathematical integration without air resistance:
Suppose p(t) is the position of the projectile at time t, given that p’’(t) = a = (0, ay), that p(0) = (px0, py0), and that p’(t) = (vx0, vy0), the first integration yields p’(t) = (vx0, ay * t + vy0) and the second,
p(t) = (vx0 * t + px0, ay * t^2 / 2 + vy0 * t + py0) (this last line is your projectile position, the one before is the projectile acceleration. You can in processing code speed and position functions, that are exactly defined as these two, and then either call them with increasing times or even go to any time.
If you want a more complex model, I advise to look this up for the analytical integration : Projectile motion - Wikipedia
Good luck ! :3