Rotation and Easing

@phoebus , i could not stop play with that excellent idea,
but i could not solve the problem, but thanks to
@brunoruchiga can now show this version:

// https://discourse.processing.org/t/rotation-and-easing/5704
PVector myMouse = new PVector();
float rot = 0, alpha, dalpha, easing = 0.03;
//__________________________________________________________
void setup() {
  size(600, 600);
  stroke(120,120,120);
}
//__________________________________________________________
void draw() {
  myMouse.set( mouseX, mouseY, 0);
  myMouse.sub(width/2, height/2, 0);
  alpha = myMouse.heading();
  dalpha = (alpha-rot)/PI;
  if      ( dalpha < -1)       rot -= TWO_PI;  // @brunoruchiga
  else if ( dalpha > 1 )       rot += TWO_PI;
  rot += (alpha -rot) * easing;                // @phoebus
  // draw
  background(0, 0, 50);
  translate(width/2, height/2); 
  fill(170, 170, 0);
  ellipse(0, 0, 400, 400);
  rotate (rot);
  fill(170, 170, 170);
  ellipse(150, 0, 100, 100);
}

4 Likes