Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The PVector object is used to handle the coordinates and the simple math operations.

Code Block
PVector posmousePos;
PVector
targetPos;
float  easingFactor = 0.1;
   
void setup() {
  size(8001000, 600);
   fill(0);
  pos = new PVector(0, 0);
  targetPos = new PVector(0, 0);
}  mousePos = new PVector(width/2, height/2);
}

void draw() { 
  background(255);
  targetPos.set(mouseX,mouseYmousePos); 
  targetPos = PVector.sub(targetPos, pos);  // find the distance between mouse and ellipse position on the x
an y axis
  targetPos = PVector.mult(targetPos, easingFactor.2); // multiplyeach thestep distance byin the easingFactoranimation towill slowmove itthis downpercentage of  if(targetPos.mag() > .5) { 
//magnitude is always an absolute number, so we don't need to use the abs() function the distance to the target position
  pos = PVector.add(pos,targetPos);
  } 
  ellipse(pos.x, pos.y, 60, 60);
}

void mousePressed() {
  mousePos.set(mouseX, mouseY);
};