the curve is made up of many line segments. each of which is created using pairs of vertices.
here i’ve increased the line segment length by increasing the distance between vertices. i have also highlighted each vertex with an ellipse.
ArrayList<Particle> particles;
void setup() {
size(640, 480);
noFill();
strokeWeight(2);
particles = new ArrayList<Particle>();
}
void draw() {
background(255);
for(int i = particles.size() - 1; i >= 0; i--) {
Particle p = particles.get(i);
p.update();
//if(p.pos.x < -100 || p.pos.x > width+100 || p.pos.y < -100 || p.pos.y > height+100)
//particles.remove(i);
p.present();
}
}
void mousePressed() {
Particle p = new Particle(mouseX, mouseY);
p.addForce(random(-1, 1), random(-1, 1));
particles.add(p);
}
class Particle {
PVector pos;
PVector vel;
PVector acc;
ArrayList<PVector> history;
int maxHistory;
float maxWander;
float maxSpeed;
Particle(float x, float y) {
this.pos = new PVector(x, y);
this.vel = new PVector();
this.acc = new PVector();
this.history = new ArrayList<PVector>();
this.history.add(this.pos.copy());
this.maxHistory = 50;
this.maxWander = 45 * (PI / 180);
this.maxSpeed = 2;
}
void addForce(float fx, float fy) {
this.acc.x += fx;
this.acc.y += fy;
}
void update() {
//add some wander to the particle to make it more interesting
float heading = this.vel.heading();
heading += random(-this.maxWander, this.maxWander);
this.addForce(cos(heading), sin(heading));
this.vel.add(this.acc);
this.vel.limit(this.maxSpeed);
this.acc.mult(0);
this.pos.add(this.vel);
float dist = PVector.dist(this.pos, this.history.get(this.history.size() - 1));
//this controls the length of the line segments or the resolution if you like of the curve which is made up of line segments
if(dist > 25) {
this.history.add(this.pos.copy());
if(this.history.size() > this.maxHistory) {
this.history.remove(0);
}
}
}
void present() {
float k = (float)this.history.size();
for(int i = 1; i < this.history.size(); i++) {
stroke(0, (i / k) * 255);
PVector p1 = this.history.get(i - 1);
PVector p2 = this.history.get(i);
ellipse(p2.x, p2.y, 8, 8);
line(p1.x, p1.y, p2.x, p2.y);
}
}
}
you can see the resolution of the curve is controlled by the distance between each vertex and the smaller the distance the smoother the curve. i feel like there is a misunderstanding on one or both of our ends. i cannot see where you are calculating that there is multiple lines drawn. if you could demonstrate how you arrive at that conclusion i can look further into it but until then i am unsure if there is an issue.
perhaps someone else will weigh in with a solution?