Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- easing functions
- -- reference: easings.net
- local easings = {
- directions = {};
- type = {}
- }
- local pi = math.pi
- local cos = math.cos
- local sin = math.sin
- -- idk why we needed this one -> local backConst1 = 1.70158
- local backConst1 = 1.70158 * 1.525
- local elasticConst1 = (2 * pi) / 4.5;
- -- functions
- function factPowEasingType(ex)
- -- for quad, quint extera
- return function(x)
- return x < .5 and
- (2 ^ (ex - 1)) * x ^ ex or
- 1 - (-2 * x + 2) ^ ex / 2;
- end
- end
- -- easing types
- function easings.type.sine(x)
- return -(cos(x * pi) - 1) / 2
- end
- easings.type.quad = factPowEasingType(2)
- easings.type.cubic = factPowEasingType(3)
- easings.type.quart = factPowEasingType(4)
- easings.type.quint = factPowEasingType(5)
- function easings.type.exponential(x)
- return x == 0 and 0 or
- x == 1 and 1 or
- x < 0.5 and 2 ^ (20 * x - 10) / 2 or
- (2 - (2 ^ -20 * x + 10)) / 2;
- end
- function easings.type.circular(x)
- return x < 0.5 and (1 - (1 - (2 * x) ^ 2) ^ .5) / 2 or
- ((1 - (-2 * x + 2) ^ 2) ^.5 + 1) / 2
- end
- function easings.type.back(x)
- return x < 0.5 and ((2 * x) ^ 2 * ((backConst1 + 1) * 2 * x - backConst1)) / 2 or
- ((2 * x - 2) ^ 2 * ((backConst1 + 1) * (x * 2 - 2) + backConst1) + 2) / 2;
- end
- function easings.type.elastic(x)
- return x == 0 and 0 or
- x == 1 and 1 or
- x < 0.5 and -(2 ^ ( 20 * x - 10) * sin((20 * x - 11.125) * elasticConst1)) / 2 or
- (2 ^ ( -20 * x + 10) * sin((20 * x - 11.125) * elasticConst1)) / 2 + 1;
- end
- function easings.type.bounce(x)
- return x < 0.5 and (1 - easings.type.bounce(1 - 2 * x)) / 2 or
- (1 + easings.type.bounce(2 * x - 1)) / 2;
- end
- -- directions
- function easings.directions.inOut(func, x)
- -- pretty easy, just return normally
- return func(x)
- end
- function easings.directions.in_(func, x)
- -- take the first half (more specifically the bottom left corner) of the function then expand it by two
- return func(x / 2) * 2
- end
- function easings.directions.out(func, x)
- -- ditto with in except we take the second half (top right corner)
- return func(x / 2 + .5) * 2 - 1
- end
- return easings
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement