Advertisement
skaramicke

gizma.com easing function correction wrapper

Apr 10th, 2015
334
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. - (double)reversibleEaseInOut:(double)t b:(double)b c:(double)c d:(double)d {
  2.     // The alotted time has passed, stop doing weird maths:
  3.     if (t>d) return c;
  4.    
  5.     // Going the "wrong" direction, needs to be fixed
  6.     BOOL reverse = NO;
  7.     if (c < b) {
  8.         reverse = YES;
  9.         double newc = b;
  10.         b = c;
  11.         c = newc;
  12.     }
  13.  
  14.     double result = [self easeInOut:t b:b c:c d:d];
  15.    
  16.     if (reverse) result = c - result;
  17.    
  18.     return result;
  19. }
  20.  
  21.  
  22. // Source: http://gizma.com/easing/#quad3
  23. - (double)easeInOut:(double)t b:(double)b c:(double)c d:(double)d {
  24.     t /= d/2;
  25.     if (t < 1) return c/2*t*t + b;
  26.     t--;
  27.     return -c/2 * (t*(t-2) - 1) + b;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement