Thats the code I used:
ArrayList<PVector> pts = new ArrayList<PVector>();
final float minDist = 10;
void setup() {
size(640, 480);
background(255);
strokeWeight(10);
stroke(255, 0, 0, 50);
pts.add(new PVector(0, 0));
}
void draw() {
int lastPt = pts.size() - 1;
if (dist(pts.get(lastPt).x, pts.get(lastPt).y, mouseX, mouseY) > minDist) {
pts.add(new PVector(mouseX, mouseY));
}
background(255);
beginShape();
for (int i = 0; i < pts.size(); i++) {
vertex(pts.get(i).x, pts.get(i).y);
}
endShape();
}