Glad I've been able to make up for my previous badly implemented example
The current version on OpenProcessing looks OK to me: the particle I pick up isn't influenced by other particles (i.e. doesn't drift) though it does still have influence on them. You could check to ensure both particles have 'affected' set to true before applying forces to them if you wanted to avoid this...
One thing I just noticed: in each loop you process the forces twice:
Code:for(int i=0; i<numparticles; i++) {
for(int j=0; j<numparticles; j++) {
float ijdist = dist(particles[i].xpos, particles[i].ypos, particles[j].xpos, particles[j].ypos);
}
}
e.g. when i=0 and j=3 you compare the same two particles as when i=3 and j=0. Another useful nugget I've seen posted by Quark: start j at the current value of i:
Code:for(int i=0; i<numparticles; i++) {
for(int j=i; j<numparticles; j++) {
float ijdist = dist(particles[i].xpos, particles[i].ypos, particles[j].xpos, particles[j].ypos);
}
}
It all still works; though you may find the reactions are less strong since you're only applying them once and not twice each frame