Easing, don't get it fully

Hello,

Work through this program.
You move 1/2 way with each key press.
And then modify the easing value and try it.
I used a fixed destination (width) instead of a moving one (mouseX).

The default frameRate is 60 fps so things move quickly each frame.
https://processing.org/reference/frameRate_.html

I slowed it down to only advance with a key press.

float x = 0.0;
float easing = 0.5;

float targetX;

void setup() 
  {
  size(500, 100);
  }
                 
void draw()   
  {
  background(0);
  targetX = width;

  
  ellipse(width, 30, 40, 40);
  ellipse(x, 70, 40, 40);
  }
  
  
void keyPressed()
  {
  x += (targetX - x) * easing;
  println(x, easing, targetX);
  }

println() is your friend when it comes to understanding and troubleshooting.
https://processing.org/reference/println_.html

Processing website example:
https://processing.org/examples/easing.html

:)

1 Like