Advertisement
skaramicke

Easing to zero - fail

Apr 10th, 2015
370
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. - (void)testEasing {
  2.     double steps = 10;
  3.  
  4.     double start = 0;
  5.     double end = 100;
  6.     NSLog(@"Test %0.f to %0.f", start, end);
  7.     for (double i = 0; i < steps; i++) {
  8.         [self easeInOut:i b:start c:end d:steps];
  9.     }
  10.    
  11.     start = 100;
  12.     end = 0;
  13.     NSLog(@"Test %0.f to %0.f", start, end);
  14.     for (double i = 0; i < steps; i++) {
  15.         [self easeInOut:i b:start c:end d:steps];
  16.     }
  17.    
  18. }
  19.  
  20. // Source: http://gizma.com/easing/
  21. - (double)easeInOut:(double)t b:(double)b c:(double)c d:(double)d {
  22.     NSInteger logStep = (NSInteger)t;
  23.     if (t>d) return c;
  24.     double result;
  25.     t /= d/2;
  26.     if (t < 1) {
  27.         result = c/2*t*t*t + b;
  28.         NSLog(@"%ld: %f = %f/2*%f*%f*%f + %f", (long)logStep, result, c, t, t, t, b);
  29.         return result;
  30.     };
  31.     t -= 2;
  32.     result = c/2*(t*t*t + 2) + b;
  33.     NSLog(@"%ld: %f = %f/2*(%f*%f*%f + 2) + %f", (long)logStep, result, c, t, t, t, b);
  34.     return result;
  35. }
  36.  
  37. // Resulting output
  38. //
  39. // Test 0 to 100
  40. // 0: 0.000000 = 100.000000/2*0.000000*0.000000*0.000000 + 0.000000
  41. // 1: 0.400000 = 100.000000/2*0.200000*0.200000*0.200000 + 0.000000
  42. // 2: 3.200000 = 100.000000/2*0.400000*0.400000*0.400000 + 0.000000
  43. // 3: 10.800000 = 100.000000/2*0.600000*0.600000*0.600000 + 0.000000
  44. // 4: 25.600000 = 100.000000/2*0.800000*0.800000*0.800000 + 0.000000
  45. // 5: 50.000000 = 100.000000/2*(-1.000000*-1.000000*-1.000000 + 2) + 0.000000
  46. // 6: 74.400000 = 100.000000/2*(-0.800000*-0.800000*-0.800000 + 2) + 0.000000
  47. // 7: 89.200000 = 100.000000/2*(-0.600000*-0.600000*-0.600000 + 2) + 0.000000
  48. // 8: 96.800000 = 100.000000/2*(-0.400000*-0.400000*-0.400000 + 2) + 0.000000
  49. // 9: 99.600000 = 100.000000/2*(-0.200000*-0.200000*-0.200000 + 2) + 0.000000
  50. //
  51. // Test 100 to 0
  52. // 0: 100.000000 = 0.000000/2*0.000000*0.000000*0.000000 + 100.000000
  53. // 1: 100.000000 = 0.000000/2*0.200000*0.200000*0.200000 + 100.000000
  54. // 2: 100.000000 = 0.000000/2*0.400000*0.400000*0.400000 + 100.000000
  55. // 3: 100.000000 = 0.000000/2*0.600000*0.600000*0.600000 + 100.000000
  56. // 4: 100.000000 = 0.000000/2*0.800000*0.800000*0.800000 + 100.000000
  57. // 5: 100.000000 = 0.000000/2*(-1.000000*-1.000000*-1.000000 + 2) + 100.000000
  58. // 6: 100.000000 = 0.000000/2*(-0.800000*-0.800000*-0.800000 + 2) + 100.000000
  59. // 7: 100.000000 = 0.000000/2*(-0.600000*-0.600000*-0.600000 + 2) + 100.000000
  60. // 8: 100.000000 = 0.000000/2*(-0.400000*-0.400000*-0.400000 + 2) + 100.000000
  61. // 9: 100.000000 = 0.000000/2*(-0.200000*-0.200000*-0.200000 + 2) + 100.000000
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement