Last active
February 15, 2017 23:06
-
-
Save Takhion/71008ea66cab61e7c181dfa675e516b4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.animation.TimeInterpolator; | |
/** | |
* Interpolator that produces a decaying sine wave oscillating around zero. | |
*/ | |
public class ShakeInterpolator implements TimeInterpolator { | |
private static final double AMP, FREQ = 5, DECAY = 6; | |
static { | |
// calculate AMP so that the max of the function is 1 | |
final double k = 2d * Math.PI * FREQ; // 31.41592653589793 | |
final double max = 1d / k * Math.atan(k / DECAY); // 0.04399306738001356 | |
AMP = 1d / (Math.sin(max * FREQ * Math.PI * 2d) / Math.exp(max * DECAY)); // 1.3256083323146437 | |
} | |
@Override | |
public float getInterpolation(float input) { | |
// see http://www.motionscript.com/articles/bounce-and-overshoot.html [Overshoot in Detail] | |
return (float)(AMP * Math.sin(input * 2d * Math.PI * FREQ) / Math.exp(input * DECAY)); | |
// y = 1.3256083323146437 * Math.sin(x * 2 * Math.PI * 5) / Math.exp(x * 6) | |
// Wolfram: plot | 1.3256083323146437 sin(x 2 pi 5) / e^(x 6) | x = 0 to 1 | y = -1 to 1 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment