sorry i not go into your code too much, just show you a other way you might be interested to study:
ArrayList<PVector> p = new ArrayList<PVector>();
int many =50;
boolean circ = true;
void setup() {
size(300, 300);
println("use mouseClick to make points, key [c] to show circles \nlimit points is "+many);
}
void draw() {
background(0, 0, 80);
linedots();
}
void linedots() {
noFill();
stroke(0, 200, 0);
strokeWeight(2);
beginShape();
if ( p.size() >= 1 ) {
curveVertex( p.get(0).x, p.get(0).y ); // control point
for (int i=0; i < p.size(); i++ ) {
if ( circ ) circle(i);
curveVertex( p.get(i).x, p.get(i).y );
}
if ( p.size() > 1 ) curveVertex( p.get(p.size()-1).x, p.get(p.size()-1).y ); // control point
endShape();
}
}
void circle(int i) {
push();
stroke(200, 0, 200);
fill(0, 200, 200);
circle(p.get(i).x, p.get(i).y, 15);
pop();
}
void mousePressed() {
p.add( new PVector(mouseX, mouseY) );
if ( p.size() > many ) p.remove(0); // erase oldest sample
}
void keyPressed() {
if ( key == 'c' ) circ = ! circ;
}
https://processing.org/reference/ArrayList.html
hope you get some ideas… or just have fun to play