I don’t think I fully understand easing. Maybe it’s my math, but I don’t see why the two ellipses, end up in the same position with the ‘* easing’ part.
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).
Easing means to move something slowly, in a soft way to a position.
So instead of moving the 2nd ellipse to the mouse ellipse at once, we do it in a more soft and organic way.
This would be the code for moving it straight away:
float x = 0.0;
void setup() {
size(1100, 900);
}
void draw() {
background(0);
// ellipse at mouse pos
ellipse(mouseX, 30, 40, 40);
// second ellipse
x += mouseX - x; // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
ellipse(x, 70,
40, 40);
}
As you can see, this line moves the 2nd ellipse: x += mouseX - x;
it says: Add to x the current difference between the mouse and the old x. Which brings you to the new position of the mouse-ellipse. This line you need to keep in mind.
Easing
Now with easing you want to add the current difference but not the full amount but only let’s say 1 % or so.
And this reads like this:
x += (mouseX - x) * easing;
We don’t add the full amount of the difference (which is (mouseX - x) ) but with the expression * easing (and easing being 0.1 or being 0.05), we make it much smaller add only this small percentage of it.
Since draw() runs 60 times per second the new difference is calculated throughout, made smaller by saying * easing and added.
Eventually the 2nd ellipse reaches the first since we always add a amount however small. (Having said that due to rounding errors this doesn’t always work, so sometimes I just put ellipse 2 directly to ellipse 1 when the distance is very small).