Module: Easing

Defined in:
TDD Easing/easing_addons/quad.rb,
TDD Easing/easing_addons/back.rb,
TDD Easing/easing_addons/expo.rb,
TDD Easing/easing_addons/cubic.rb,
TDD Easing/easing_addons/linear.rb,
TDD Easing/easing_addons/bounce.rb,
TDD Easing/easing_addons/elastic.rb,
TDD Easing/easing_addons/circular.rb

Overview

** Easing EXTENSION


Extended for: TDD Easing Script

This extension adds 3 new easing methods to the Easing module:

  • CIRC_IN

  • CIRC_OUT

  • CIRC_IN_OUT

How to use:

Use Game_Picture.easing = Easing::CIRC_IN (or any of the other three methods listed above) to apply before performing moving or tinting of the Game_Picture class.

Credit:

  • Galenmereth / Tor Damian Design

License:

Free for non-commercial and commercial use. Credit greatly appreciated but not required. Share script freely with everyone, but please retain this description area unless you change the script completely. Thank you.

Constant Summary

QUAD_IN =
"quad_in"
QUAD_OUT =
"quad_out"
QUAD_IN_OUT =
"quad_in_out"
BACK_IN =
"back_in"
BACK_OUT =
"back_out"
BACK_IN_OUT =
"back_in_out"
SLING =

This is the intensity of the back “sling” effect. Higher = stronger

1.70158
EXPO_IN =
"expo_in"
EXPO_OUT =
"expo_out"
EXPO_IN_OUT =
"expo_in_out"
CUBIC_IN =
"cubic_in"
CUBIC_OUT =
"cubic_out"
CUBIC_IN_OUT =
"cubic_in_out"
LINEAR =
"linear"
BOUNCE_IN =
"bounce_in"
BOUNCE_OUT =
"bounce_out"
BOUNCE_IN_OUT =
"bounce_in_out"
ELASTIC_IN =
"elastic_in"
ELASTIC_OUT =
"elastic_out"
ELASTIC_IN_OUT =
"elastic_in_out"
CIRC_IN =
"circ_in"
CIRC_OUT =
"circ_out"
CIRC_IN_OUT =
"circ_in_out"

Class Method Summary (collapse)

Class Method Details

+ (Object) back_in(t, b, c, d)



35
36
37
38
39
# File 'TDD Easing/easing_addons/back.rb', line 35

def self.back_in(t, b, c, d)
  s = SLING
  d = d.to_f
  return c*(t/=d)*t*((s+1)*t - s) + b
end

+ (Object) back_in_out(t, b, c, d)



47
48
49
50
51
52
53
54
55
56
# File 'TDD Easing/easing_addons/back.rb', line 47

def self.back_in_out(t, b, c, d)
  s = SLING
  c = c.to_f
  d = d.to_f
  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

+ (Object) back_out(t, b, c, d)



41
42
43
44
45
# File 'TDD Easing/easing_addons/back.rb', line 41

def self.back_out(t, b, c, d)
  s = SLING
  d = d.to_f
  return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b
end

+ (Object) bounce_in(t, b, c, d)



32
33
34
# File 'TDD Easing/easing_addons/bounce.rb', line 32

def self.bounce_in(t, b, c, d)
  return c - self::bounce_out(d-t, 0, c, d) + b
end

+ (Object) bounce_in_out(t, b, c, d)



48
49
50
51
52
53
54
# File 'TDD Easing/easing_addons/bounce.rb', line 48

def self.bounce_in_out(t, b, c, d)
  if t < d.to_f/2
    return bounce_in(t*2, 0, c, d) * 0.5 + b
  else
    return bounce_out(t*2-d, 0, c, d) * 0.5 + c*0.5 + b
  end
end

+ (Object) bounce_out(t, b, c, d)



36
37
38
39
40
41
42
43
44
45
46
# File 'TDD Easing/easing_addons/bounce.rb', line 36

def self.bounce_out(t, b, c, d)
  if (t/=d.to_f) < (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

+ (Object) circ_in(t, b, c, d)



32
33
34
# File 'TDD Easing/easing_addons/circular.rb', line 32

def self.circ_in(t, b, c, d)
  return -c * (Math.sqrt(1 - (t/=d.to_f)*t) - 1) + b
end

+ (Object) circ_in_out(t, b, c, d)



40
41
42
43
44
45
46
47
48
# File 'TDD Easing/easing_addons/circular.rb', line 40

def self.circ_in_out(t, b, c, d)
  d = d.to_f
  c = c.to_f
  if (t/=d/2) < 1
    return -c/2 * (Math.sqrt(1 - t*t) - 1) + b
  else
    return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b
  end
end

+ (Object) circ_out(t, b, c, d)



36
37
38
# File 'TDD Easing/easing_addons/circular.rb', line 36

def self.circ_out(t, b, c, d)
  return c * Math.sqrt(1 - (t=t/d.to_f-1)*t) + b
end

+ (Object) cubic_in(t, b, c, d)



32
33
34
35
# File 'TDD Easing/easing_addons/cubic.rb', line 32

def self.cubic_in(t, b, c, d)
  t /= d.to_f
  return c*t*t*t + b
end

+ (Object) cubic_in_out(t, b, c, d)



43
44
45
46
47
48
49
# File 'TDD Easing/easing_addons/cubic.rb', line 43

def self.cubic_in_out(t, b, c, d)
  c = c.to_f
  t /= d.to_f/2
  return c/2*t*t*t + b if t < 1
  t -= 2
  return c/2*(t*t*t + 2) + b
end

+ (Object) cubic_out(t, b, c, d)



37
38
39
40
41
# File 'TDD Easing/easing_addons/cubic.rb', line 37

def self.cubic_out(t, b, c, d)
  t /= d.to_f
  t -= 1
  return c*(t*t*t + 1) + b
end

+ (Object) elastic_in(t, b, c, d)



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'TDD Easing/easing_addons/elastic.rb', line 32

def self.elastic_in(t, b, c, d)
  d=d.to_f
  c=c.to_f
  s=1.70158
  p=0
  a=c
  return b if t==0
  return b+c if ((t/=d)==1)
  p=d*0.3 if p==0
  if a < c.abs
    a=c
    s=p/4
  else
    s = p/(2*Math::PI) * Math.asin(c/(a.nonzero? || 1))
  end
  return -(a*(2**(10*(t-=1))) * Math.sin( (t*d-s)*(2*Math::PI)/p )) + b
end

+ (Object) elastic_in_out(t, b, c, d)



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'TDD Easing/easing_addons/elastic.rb', line 68

def self.elastic_in_out(t, b, c, d)
  d=d.to_f
  c=c.to_f
  s=1.70158
  p=0
  a=c
  return b if t==0
  return b+c if ((t/=d/2)==2)
  p=d*(0.3*1.5) if p==0
  if a < c.abs
    a=c
    s=p/4
  else
    s = p/(2*Math::PI) * Math.asin(c/(a.nonzero? || 1))
  end
  return a*(2**(-10*(t-=1))) * Math.sin( (t*d-s)*(2*Math::PI)/p )*0.5 + c + b
end

+ (Object) elastic_out(t, b, c, d)



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'TDD Easing/easing_addons/elastic.rb', line 50

def self.elastic_out(t, b, c, d)
  d=d.to_f
  c=c.to_f
  s=1.70158
  p=0
  a=c
  return b if t==0
  return b+c if ((t/=d)==1)
  p = d*0.3 if p==0
  if a < c.abs
    a=c
    s=p/4
  else
    s = p/(2*Math::PI) * Math.asin(c/(a.nonzero? || 1))
  end
  return a*(2**(-10*t)) * Math.sin( (t*d-s)*(2*Math::PI)/p ) + c + b
end

+ (Object) expo_in(t, b, c, d)



32
33
34
# File 'TDD Easing/easing_addons/expo.rb', line 32

def self.expo_in(t, b, c, d)
  return (t==0) ? b : c * (2**(10 * (t/d.to_f - 1))) + b
end

+ (Object) expo_in_out(t, b, c, d)



40
41
42
43
44
45
46
47
48
49
50
# File 'TDD Easing/easing_addons/expo.rb', line 40

def self.expo_in_out(t, b, c, d)
  c = c.to_f
  d = d.to_f
  return b if t==0
  return b+c if t==d
  if (t/=d/2) < 1
    return c/2 * (2**(10 * (t - 1))) + b
  else
    return c/2 * (-(2**(-10 * (t-=1))) + 2) + b
  end
end

+ (Object) expo_out(t, b, c, d)



36
37
38
# File 'TDD Easing/easing_addons/expo.rb', line 36

def self.expo_out(t, b, c, d)
  return (t==d) ? b+c : c * (-(2**(-10 * t/d.to_f)) + 1) + b
end

+ (Object) linear(t, b, c, d)

t = Current time (frame) b = Start value c = Desired change in value d = Duration total (frames) Returns: Value modified by t



34
35
36
# File 'TDD Easing/easing_addons/linear.rb', line 34

def self.linear(t, b, c, d)
  return c*t/d.to_f + b
end

+ (Object) quad_in(t, b, c, d)



32
33
34
35
# File 'TDD Easing/easing_addons/quad.rb', line 32

def self.quad_in(t, b, c, d)
  t /= d.to_f
  return c*t*t + b
end

+ (Object) quad_in_out(t, b, c, d)



43
44
45
46
47
48
49
# File 'TDD Easing/easing_addons/quad.rb', line 43

def self.quad_in_out(t, b, c, d)
  c = c.to_f
  t /= d.to_f/2
  return c/2*t*t + b if t < 1
  t -= 1
  return -c/2 * (t*(t-2) - 1) + b
end

+ (Object) quad_out(t, b, c, d)



37
38
39
40
41
# File 'TDD Easing/easing_addons/quad.rb', line 37

def self.quad_out(t, b, c, d)
  c = c.to_f
  t /= d.to_f
  return -c * t*(t-2) + b;
end