Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #===============================================================================
- # * [ACE] Smooth Animation Module
- #===============================================================================
- # * Made by: Sixth (www.rpgmakervxace.net, www.forums.rpgmakerweb.com)
- # * Version: 1.0
- # * Updated: 07/10/2016
- # * Requires: -------
- #-------------------------------------------------------------------------------
- # * < Change Log >
- #-------------------------------------------------------------------------------
- # * Version 1.0 (07/10/2016)
- # - Initial release.
- #-------------------------------------------------------------------------------
- # * < Description >
- #-------------------------------------------------------------------------------
- # * This script contains all the easing types of the animations.
- # You can add new ones by yourself if you want.
- #-------------------------------------------------------------------------------
- # * < Installation >
- #-------------------------------------------------------------------------------
- # * Place this script between Materials and Main!
- #-------------------------------------------------------------------------------
- # * < Compatibility Info >
- #-------------------------------------------------------------------------------
- # * No known incompatibilities.
- #-------------------------------------------------------------------------------
- # * < Known Issues >
- #-------------------------------------------------------------------------------
- # * No known issues.
- #-------------------------------------------------------------------------------
- # * < Terms of Use >
- #-------------------------------------------------------------------------------
- # * Free to use for whatever purposes you want.
- # * Credit me (Sixth) in your game, pretty please! :P
- # * Most of this module uses Robert Penner's easing methods, so you should also
- # credit him for this module! I guess...
- # * Posting modified versions of this script is allowed as long as you notice me
- # about it with a link to it!
- #===============================================================================
- $imported = {} if $imported.nil?
- $imported["SixthABSSmoothAnimMod"] = true
- #===============================================================================
- # Settings:
- #
- # You can create your own type of animations by making new methods inside the
- # below module. After making your new methods, you can use them by using their
- # names either as a symbol or string in the script calls provided in the
- # Smooth Animation System script
- #
- # Do NOT make duplicate method names!
- #
- # The argument of these methods look like this:
- # b(ase): Base (starting) value of the attribute.
- # c(hange): Difference (change) to the target value.
- # t(ime): Elapsed animation time.
- # d(uration): Total animation time.
- #
- # Won't explain how the already included methods work, but if you are
- # interested, you can learn about that here: http://robertpenner.com/easing/
- # The default methods are based on Robert Penner's Easing methods!
- #===============================================================================
- module SmoothAnim
- # Random type selection
- # Add all effects to the array below!
- def self.rand_anim(*types)
- if types.empty?
- types = [
- :linear,
- :quad_in, :quad_out, :quad_in_out,
- :cubic_in, :cubic_out, :cubic_in_out,
- :quart_in, :quart_out, :quart_in_out,
- :quint_in, :quint_out, :quint_in_out,
- :sine_in, :sine_out, :sine_in_out,
- :exp_in, :exp_out, :exp_in_out,
- :circ_in, :circ_out, :circ_in_out,
- :bounce_in, :bounce_out, :bounce_in_out,
- :back_in, :back_out, :back_in_out,
- :elastic_in, :elastic_out,
- :sinus,
- ]
- end
- return types.sample
- end
- # Random changes - chaotic, not usable! It is here for testing purposes only!
- def random(b, c, t, d)
- method(rand_anim).call(b, c, t, d)
- end
- # Linear (simple move/change - default)
- def self.linear(b, c, t, d)
- return c * t / d + b
- end
- def self.quad_in(b, c, t, d)
- return c*(t/=d)*t + b
- end
- def self.quad_out(b, c, t, d)
- return -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
- def self.cubic_in(b, c, t, d)
- return c*(t/=d)*t*t + b
- end
- def self.cubic_out(b, c, t, d)
- return 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
- def self.quart_in(b, c, t, d)
- return c*(t/=d)*t*t*t + b
- end
- def self.quart_out(b, c, t, d)
- return -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
- def self.quint_in(b, c, t, d)
- return c*(t/=d)*t*t*t*t + b
- end
- def self.quint_out(b, c, t, d)
- return 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
- def self.sine_in(b, c, t, d)
- return -c * Math.cos(t/d * (Math::PI/2)) + c + b
- end
- def self.sine_out(b, c, t, d)
- return c * Math.sin(t/d * (Math::PI/2)) + b
- end
- def self.sine_in_out(b, c, t, d)
- return -c/2 * (Math.cos(Math::PI*t/d) - 1) + b
- end
- def self.exp_in(b, c, t, d)
- return (t==0) ? b : c * (2 ** (10 * (t/d - 1))) + b
- end
- def self.exp_out(b, c, t, d)
- return (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
- def self.circ_in(b, c, t, d)
- return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b
- end
- def self.circ_out(b, c, t, d)
- return 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
- def self.bounce_in(b, c, t, d)
- return c - bounce_out(0, c, d-t, d) + b
- end
- def self.bounce_out(b, c, t, d)
- if (t /= d) < (1/2.75)
- return c * 7.5625*t*t + b
- elsif t < (2/2.75)
- return c * (7.5625 * (t -= (1.5 / 2.75)) * t + 0.75) + b
- elsif t < (2.5/2.75)
- return c * (7.5625 * (t -= (2.25 / 2.75)) * t + 0.9375) + b
- else
- return c * (7.5625 * (t -= (2.625 / 2.75)) * t + 0.984375) + b
- end
- end
- def self.bounce_in_out(b, c, t, d)
- if(t < d/2)
- return bounce_in(0, c, t*2, d) * 0.5 + b
- else
- return bounce_out(0, c, t*2 - d, d) * 0.5 + c*0.5 + b
- end
- end
- def self.back_in(b, c, t, d)
- s = 1.70158
- return c * (t/=d) * t * ((s+1) * t - s) + b
- end
- def self.back_out(b, c, t, d)
- s = 1.70158
- return 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
- return c / 2 * (t * t * (((s *= (1.525)) + 1) * t - s)) + b
- else
- return c / 2 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2) + b
- end
- end
- 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
- return -(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
- return a * (2 ** (-10 * t)) * Math.sin((t * d - s) * (2 * Math::PI) / x) + c + b
- end
- # Custom animations:
- def self.sinus(b, c, t, d)
- ts = (t /= d) * t
- tc = ts * t
- return b+c*(-17*tc*ts + 42.5*ts*ts + -51*tc + 34*ts + -7.5*t)
- end
- def self.high_out(b, c, t, d)
- ts = (t /= d) * t
- tc = ts * t
- return b+c*(11.85*tc*ts + -40.85*ts*ts + 52.6*tc + -33.9*ts + 11.3*t)
- end
- end
- #==============================================================================
- # !!END OF SCRIPT - OHH, NOES!!
- #==============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement