One Line

One_Line

 

In this assignment I was trying to make a line that waves when it touches the mouse. The line would be following the mouse but when the mouse moves quickly the line would need time to catch up with the mouse.

float n = 8;
float m = 0;
float x;
float y;
float easing = 0.05;

void setup() {
  size(500, 500);  
}

void draw() { 
  background(255);
  follow();
}

void follow(){
    float followX = mouseX;
    float distanceX = followX - x;
    float followY = mouseY;
    float distanceY = followY - y;
  if(abs(distanceX)<=1 && abs(distanceY)<=1){
    noFill();
    beginShape();
    for(int i=1; i<n; i++){         m = random(-20,20);         curveVertex(x + m, y + i * 40 / n );     }     endShape();   }   else{     if(abs(distanceX) > 1) {
      x += distanceX * easing;
    }
    if(abs(distanceY) > 1) {
      y += distanceY * easing;
    }
    line(x, y-20, x, y+20);
  }
}

IMG_20141001_145621

Comments are closed.