Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #==============================================================================
- # Iavra Animate Everything - Easing Library
- # -----------------------------------------------------------------------------
- # Description:
- # Implementation of the Robert Penner easing functions. I decided to split this
- # from the actual animation logic, since it's just a lot of stuff that clutters
- # the script. Also, you can delete some of those methods to free up memory or
- # provide your own implementations.
- # -----------------------------------------------------------------------------
- # How to Use:
- # Simply put this script anywhere, either above or below Animate Everything.
- # The method names directly translate to symbols, that can be passed to the
- # IAVRA::ANIMATE.start method.
- # -----------------------------------------------------------------------------
- # Also see:
- # http://robertpenner.com/easing/
- #==============================================================================
- module IAVRA
- module ANIMATE
- module EASING
- #========================================================================
- # Quad
- #========================================================================
- def self.quad_in(b, c, t, d)
- c*(t/=d)*t + b
- end
- def self.quad_out(b, c, t, d)
- -c*(t/=d)*(t-2) + b
- end
- def self.quad_in_out(b, c, t, d)
- return c/2*t*t + b if ((t/=d/2) < 1)
- return -c/2 * ((t-=1)*(t-2) - 1) + b
- end
- #========================================================================
- # Cubic
- #========================================================================
- def self.cubic_in(b, c, t, d)
- c*(t/=d)*t*t + b
- end
- def self.cubic_ou(b, c, t, d)
- c*((t=t/d-1)*t*t + 1) + b
- end
- def self.cubic_in_out(b, c, t, d)
- return c/2*t*t*t + b if ((t/=d/2) < 1)
- return c/2*((t-=2)*t*t + 2) + b
- end
- #========================================================================
- # Quartic
- #========================================================================
- def self.quart_in(b, c, t, d)
- c*(t/=d)*t*t*t + b
- end
- def self.quart_out(b, c, t, d)
- -c * ((t=t/d-1)*t*t*t - 1) + b
- end
- def self.quart_in_out(b, c, t, d)
- return c/2*t*t*t*t + b if ((t/=d/2) < 1)
- return -c/2 * ((t-=2)*t*t*t - 2) + b
- end
- #========================================================================
- # Quintic
- #========================================================================
- def self.quint_in(b, c, t, d)
- c*(t/=d)*t*t*t*t + b
- end
- def self.quint_out(b, c, t, d)
- c*((t=t/d-1)*t*t*t*t + 1) + b
- end
- def self.quint_in_out(b, c, t, d)
- return c/2*t*t*t*t*t + b if ((t/=d/2) < 1)
- return c/2*((t-=2)*t*t*t*t + 2) + b
- end
- #========================================================================
- # Sine
- #========================================================================
- def self.sine_in(b, c, t, d)
- -c * Math.cos(t/d * (Math::PI/2)) + c + b
- end
- def self.sine_out(b, c, t, d)
- c * Math.sin(t/d * (Math::PI/2)) + b
- end
- def self.sine_in_out(b, c, t, d)
- -c/2 * (Math.cos(Math::PI*t/d) - 1) + b
- end
- #========================================================================
- # Exponential
- #========================================================================
- def self.exp_in(b, c, t, d)
- (t==0) ? b : c * (2 ** (10 * (t/d - 1))) + b
- end
- def self.exp_out(b, c, t, d)
- (t==d) ? b+c : c * (-2**(-10 * t/d) + 1) + b
- end
- def self.exp_in_out(b, c, t, d)
- return b if t == 0
- return b + c if t == d
- return (c/2) * 2**(10 * (t-1)) + b if ((t /= d/2) < 1)
- return (c/2) * (-2**(-10 * t-=1) + 2) + b
- end
- #========================================================================
- # Circular
- #========================================================================
- def self.circ_in(b, c, t, d)
- -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b
- end
- def self.circ_out(b, c, t, d)
- c * Math.sqrt(1 - (t=t/d-1)*t) + b
- end
- def self.circ_in_out(b, c, t, d)
- return -c/2 * (Math.sqrt(1 - t*t) - 1) + b if ((t/=d/2) < 1)
- return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b
- end
- #========================================================================
- # Bounce
- #========================================================================
- def self.bounce_out(b, c, t, d)
- if (t /= d) < (1/2.75)
- c * 7.5625*t*t + b
- elsif t < (2/2.75)
- c * (7.5625 * (t -= (1.5 / 2.75)) * t + 0.75) + b
- elsif t < (2.5/2.75)
- c * (7.5625 * (t -= (2.25 / 2.75)) * t + 0.9375) + b
- else
- c * (7.5625 * (t -= (2.625 / 2.75)) * t + 0.984375) + b
- end
- end
- def self.bounce_in(b, c, t, d)
- c - bounce_out(0, c, d-t, d) + b
- end
- def self.bounce_in_out(b, c, t, d)
- if(t < d/2)
- bounce_in(0, c, t*2, d) * 0.5 + b
- else
- bounce_out(0, c, t*2 - d, d) * 0.5 + c*0.5 + b
- end
- end
- #========================================================================
- # Back
- #========================================================================
- def self.back_in(b, c, t, d)
- s = 1.70158
- c * (t/=d) * t * ((s+1) * t - s) + b
- end
- def self.back_out(b, c, t, d)
- s = 1.70158
- c * ((t=t/d-1) * t * ((s+1) * t + s) + 1) + b
- end
- def self.back_in_out(b, c, t, d)
- s = 1.70158
- if (t /= d/2) < 1
- c / 2 * (t * t * (((s *= (1.525)) + 1) * t - s)) + b
- else
- c / 2 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2) + b
- end
- end
- #========================================================================
- # Elastic
- #========================================================================
- def self.elastic_in(b, c, t, d)
- a, x, s = 5.0, d * 0.3, 0.0
- return b if (t == 0)
- return b + c if ((t /= d) >= 1)
- if(a < c.abs)
- a = c
- s = x / 4.0
- else
- s = x / (2 * Math::PI) * Math.asin(c / a)
- end
- -(a * (2 ** (10 * (t -= 1))) * Math.sin((t * d - s) * (2 * Math::PI) / x)) + b
- end
- def self.elastic_out(b, c, t, d)
- a, x, s = 0.1, d * 0.3, 0.0
- return b if (t == 0)
- return b + c if ((t /= d) >= 1)
- if(a < c.abs)
- a = c
- s = x / 4.0
- else
- s = x / (2 * Math::PI) * Math.asin(c / a)
- end
- a * (2 ** (-10 * t)) * Math.sin((t * d - s) * (2 * Math::PI) / x) + c + b
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement