Dunno if this is what y want:
Code:int screen_width = 1000 ;
int screen_height = 800 ;
int m_rad = 200; // mouse pointer circle radius
float av = 0.05 ; // accelation value
//points
int p_number = 50 ; // points number
int p_dist = 10 ; // distance between points
int p_x0 = 250 ; // begining point (x,y)
int p_y0 = 400 ;
PVector[] p = new PVector[p_number];
void setup()
{
size(screen_width, screen_height);
background(255);
//points position
for(int i=0; i < p_number; i++)
{
p[i] = new PVector(p_x0 + p_dist*i, p_y0) ;
}
}
void draw()
{
background(255);
smooth();
//points and mouse pointer
stroke(100);
strokeWeight(3);
for(int i=0; i < p_number; i++)
{
point(p[i].x, p[i].y);
}
noFill();
stroke(200);
strokeWeight(1);
ellipse(mouseX, mouseY, m_rad*2, m_rad*2);
for (int j=15;--j>0;) { // We need to do this a few times
//point position
for( int i = 0; i < p_number; i++ )
{
// between point and mouse
float angleA = atan2( p[i].y - mouseY, p[i].x - mouseX);
float distanceA = dist( p[i].x, p[i].y, mouseX, mouseY );
float moveA = m_rad - distanceA ;
if(distanceA < m_rad)
{
p[i].x += moveA * cos(angleA) * av ;
p[i].y += moveA * sin(angleA) * av ;
}
}
for (int i=p.length;--i>1;) { //Loop through points
PVector p1=p[i]; //First
PVector p2=p[i-1]; // Second, 1-point distance
PVector p3=p[i-2]; // Third, 2-points distance
keepDist(p1,p2,p_dist); //Keep distance between 1-2
keepDist(p2,p3,p_dist); //Kepp distance between 2-3
keepDist(p1,p3,p_dist*2); //Keep distance(double) between 1-3;
}
}
}
// The infamous keepdist routine. Essentially relaxation.
void keepDist(PVector p1, PVector p2, float D) {
float dx,dy,dz,lx,ly,lz,L;
dx=p2.x-p1.x;
dy=p2.y-p1.y;
dz=p2.z-p1.z;
L = sqrt(dx*dx+dy*dy+dz*dz);
L=.5*(1-(D/L));
lx=L*dx;
ly=L*dy;
lz=L*dz;
p1.x+=lx;
p1.y+=ly;
p1.z+=lz;
p2.x-=lx;
p2.y-=ly;
p2.z-=lz;
}
Ive added essentially a relaxation loop to keep the distance between the points.
Or you could use a physics/point-spring solver to make your life easier prolly...