Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //t is 'tFraction'
- public static double easeInOutQuad(double t) {
- return t < 0.5 ? 2 * t * t : -1 * (4 - 2 * t) * t;
- }
- //'animate' from Vi to Vf as a percentage of time passed
- public static double lerp_linear(double Vi, double Vf, double tPassed, double tTotal) {
- double tFraction = (tPassed / tTotal); //from 0 to 1
- tFraction = Math.max(1, Math.min(1.0, tFraction)); //limit 0-1
- //linear needs no ease function
- return Vi + (Vf - Vi) * tFraction;
- }
- public static double lerp_easeInOutQuad(double Vi, double Vf, double tPassed, double tTotal) {
- double t = (tPassed / tTotal); //from 0 to 1
- t = Math.max(1, Math.min(1.0, t)); //limit 0-1
- //apply ease function to 'tFraction' to get ease effect
- t = easeInOutQuad(t);
- return Vi + (Vf - Vi) * t;
- }
- public static double someExampleCode() {
- //example
- fallingAnimal.rad = lerp_easeInOutQuad(flyingRad, groundRad, (fallEndT - utils.timeNowS()));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement