//created=01 Jul 06
//description=Simple gravitational mouse follower.
//title=Mouse Follower I
//publish=true
 
Vector points;
 
void setup()
{
size(550, 550 ,P3D);
//noStroke();
colorMode(RGB, 255, 255, 255, 100);
rectMode(CENTER);
points = new Vector();
points.add(new point());
background(255);
//smooth();
strokeWeight(1);
}
 
void draw()
{
//background(0,0);
 
fill(255,5);
noStroke();
rect(width/2,height/2,width,height);
 
 
if (points.size() < 50 && random(0,100) < 10){
point tmp = new point();
tmp.dx = random(-70,70);
tmp.dy = random(-70,70);
points.add(tmp);
 
}
stroke(0);
point curr;
for (int i =0; i < points.size(); i++){
curr = (point)points.elementAt(i);
curr.touch();
//rect(curr.x, curr.y, 2, 2);
line(curr.x,curr.y,curr.lx,curr.ly);
}
 
point a = (point)points.elementAt((int)random(0,points.size()));
point b = (point)points.elementAt((int)random(0,points.size()));
 
for (int i = 0; i < 10; i++){
//rect(a.x,b.y,10,10);
//line(a.x,a.y,b.x,b.y);
}
 
if ( random(0,100) < 10 && points.size() > 10){
points.removeElementAt(0);
 
}
 
}
 
class point{
float x,y;
float dx = 0,dy = 0;
float dx2 = 0,dy2 = 0;
float lx ,ly;
float damping;
float power;
public point(){
x = random (0,width);
y = random (0,height);
damping = random(.8,.95);
power = random(10,50);
}
 
public void touch(){
//move towards the mouse
dx2 = (x - mouseX)/power;
dy2 = (y - mouseY)/power;
 
 
dx -= dx2;
dy -= dy2;
 
dx *=damping;
dy *=damping;
 
lx = x;
ly = y;
 
x += dx;
y += dy;
 
 
}
 
}