|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
return progressend return progress < 0.5 and (progress * 2) or (2 - (progress * 2))end return progress ^ powerend return 1 - ((1 - progress) ^ power)end if progress < 0.5 then return ((progress * 2) ^ power) * 0.5 end return 1 - (((1 - progress) * 2) ^ power) * 0.5endendendendendendendendendendendendendend if progress <= 0.5 then endend if progress < 0.5 then return ((progress * 2) ^ exponent) * 0.5 end return 1 - (((1 - progress) * 2) ^ exponent) * 0.5end if progress < 0.5 then return (1 - ((1 - (2 * progress)) ^ exponent)) * 0.5 end return (((progress - 0.5) * 2) ^ exponent) * 0.5 + 0.5end if exponent == 1 then -- Linear interpolator. end -- Eased interpolator. return function(progress) endend if exponent == 1 then -- Linear interpolator. end -- Eased interpolator. return function(progress) endend if x1 == y1 and x2 == y2 then end return function(progress) endenddo local P = 1.57 --The actual zoom level we use to size things does not go linearly from min to max. Going linearly causes the zoom to feel like it is moving very fast to start --and then moving more and more slowly as we reach max zoom. To counteract this we treat the progression from min to max as a curve that increases more slowly to --start and then faster later. Research has shown that the curve y=e^px best matches human expectations of an even zoom speed with a p value of 6^0.25 ~= 1.57. We --normalized this curve so that y goes from 0 to 1 as x goes from 0 to 1 since we operate on a normalized value between min and max zoom. endend-- progress values must have at least two values in it:-- {0, 1} generates a line from 0 to 1-- {0, 1, 0} generates a line from 0 to 1 (at progress=0.5) back to 0 if not internalassert(#progressValues >= 2, "piecewise ease needs at least two values to ease between") then end local inBetweenSize = #progressValues - 1 local inBetweenModulo = 1 / inBetweenSize return function(progress) local nextValue = progressValues[nextIndex] local previousValue = progressValues[nextIndex - 1] local percentBetweenValues = (progress % inBetweenModulo) * inBetweenSize endend |