2

You know those mechanisms that moved or rotated, and then just a few millimeters near the end of the trajectory they oppose a bit of resistance and then clank to the final position.

I want to simulate that clank with an ease function that can be combined with the standard ease actions. The link is for reference to some examples of ease transition functions, but I just need the pseudocode like this:

float clankActionTime(float t) {
    if (t > 0.9)
        return (0.5*sin(10.0*t*2.0*M_PI)+2.0*10.0*t)/20.0;
    return t;
}

That is what I have so far, which gives this graph for t between 0 and 1.

enter image description here

But I want something more like this:

enter image description here

Where A and B are parameters passed to the ease function to indicate where to star the clank and how deep is the valley near the end of the curve, respectively.

rraallvv
  • 971
  • 5
  • 16

1 Answers1

1
clankTime(t, A, B) {
    float cT = 1.0-A;
    float t1 = cT+0.5*(1.0-B)*(1.0-cT);
    float t2 = cT+0.5*(1.0+B)*(1.0-cT);

    if (t > t1) {
        float m = (1.0-t2)/(1.0-t1);
        return m*(t-t1)+t2;
    }
    else if (t > cT) {
        float m = (t2-cT)/(t1-cT);
        return m*(t-cT)+cT;
    }
    return t;
}

Where A is the duration of the clank from where the movement starts slowing down until the end of the ease transition, and B is how deep is the valley measured on a line perpendicular to y=x that intersects the line at 0.5*A.

enter image description here

rraallvv
  • 971
  • 5
  • 16