Module: Easing

Extended by:
Easing
Included in:
Easing
Defined in:
lib/easing.rb,
lib/easing/version.rb

Constant Summary collapse

VERSION =
"0.1.0"

Instance Method Summary collapse

Instance Method Details

#ease_in_circ(t, b, c, d) ⇒ Object



129
130
131
132
133
# File 'lib/easing.rb', line 129

def ease_in_circ(t, b, c, d)
  t = t.to_f; b = b.to_f; c = c.to_f; d = d.to_f

  return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b
end

#ease_in_cubic(t, b, c, d) ⇒ Object



33
34
35
36
37
# File 'lib/easing.rb', line 33

def ease_in_cubic(t, b, c, d)
  t = t.to_f; b = b.to_f; c = c.to_f; d = d.to_f

  return c*(t/=d)*t*t + b
end

#ease_in_expo(t, b, c, d) ⇒ Object



108
109
110
111
112
# File 'lib/easing.rb', line 108

def ease_in_expo(t, b, c, d)
  t = t.to_f; b = b.to_f; c = c.to_f; d = d.to_f

  return (t==0) ? b : c * (2 ** (10 * (t/d - 1))) + b
end

#ease_in_out_circ(t, b, c, d) ⇒ Object



141
142
143
144
145
146
# File 'lib/easing.rb', line 141

def ease_in_out_circ(t, b, c, d)
  t = t.to_f; b = b.to_f; c = c.to_f; d = d.to_f

  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

#ease_in_out_cubic(t, b, c, d) ⇒ Object



45
46
47
48
49
50
# File 'lib/easing.rb', line 45

def ease_in_out_cubic(t, b, c, d)
  t = t.to_f; b = b.to_f; c = c.to_f; d = d.to_f

  return c/2*t*t*t + b if ((t/=d/2) < 1)
  return c/2*((t-=2)*t*t + 2) + b
end

#ease_in_out_expo(t, b, c, d) ⇒ Object



120
121
122
123
124
125
126
127
# File 'lib/easing.rb', line 120

def ease_in_out_expo(t, b, c, d)
  t = t.to_f; b = b.to_f; c = c.to_f; d = d.to_f

  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

#ease_in_out_quad(t, b, c, d) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/easing.rb', line 24

def ease_in_out_quad(t, b, c, d)
  t = t.to_f; b = b.to_f; c = c.to_f; d = d.to_f

  t /= d / 2
  return c / 2*t*t + b if (t < 1)
  t -= 1
  return -c/2 * (t*(t-2) - 1) + b
end

#ease_in_out_quart(t, b, c, d) ⇒ Object



64
65
66
67
68
69
# File 'lib/easing.rb', line 64

def ease_in_out_quart(t, b, c, d)
  t = t.to_f; b = b.to_f; c = c.to_f; d = d.to_f

  return c/2*t*t*t*t + b if ((t/=d/2) < 1)
  return -c/2 * ((t-=2)*t*t*t - 2) + b
end

#ease_in_out_quint(t, b, c, d) ⇒ Object



83
84
85
86
87
88
# File 'lib/easing.rb', line 83

def ease_in_out_quint(t, b, c, d)
  t = t.to_f; b = b.to_f; c = c.to_f; d = d.to_f

  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

#ease_in_out_sine(t, b, c, d) ⇒ Object



102
103
104
105
106
# File 'lib/easing.rb', line 102

def ease_in_out_sine(t, b, c, d)
  t = t.to_f; b = b.to_f; c = c.to_f; d = d.to_f

  return -c/2 * (Math.cos(Math::PI*t/d) - 1) + b
end

#ease_in_quad(t, b, c, d) ⇒ Object



12
13
14
15
16
# File 'lib/easing.rb', line 12

def ease_in_quad(t, b, c, d)
  t = t.to_f; b = b.to_f; c = c.to_f; d = d.to_f

  return c*(t/=d)*t + b;
end

#ease_in_quart(t, b, c, d) ⇒ Object



52
53
54
55
56
# File 'lib/easing.rb', line 52

def ease_in_quart(t, b, c, d)
  t = t.to_f; b = b.to_f; c = c.to_f; d = d.to_f

  return c*(t/=d)*t*t*t + b
end

#ease_in_quint(t, b, c, d) ⇒ Object



71
72
73
74
75
# File 'lib/easing.rb', line 71

def ease_in_quint(t, b, c, d)
  t = t.to_f; b = b.to_f; c = c.to_f; d = d.to_f

  return c*(t/=d)*t*t*t*t + b
end

#ease_in_sine(t, b, c, d) ⇒ Object



90
91
92
93
94
# File 'lib/easing.rb', line 90

def ease_in_sine(t, b, c, d)
  t = t.to_f; b = b.to_f; c = c.to_f; d = d.to_f

  return -c * Math.cos(t/d * (Math::PI/2)) + c + b
end

#ease_out_circ(t, b, c, d) ⇒ Object



135
136
137
138
139
# File 'lib/easing.rb', line 135

def ease_out_circ(t, b, c, d)
  t = t.to_f; b = b.to_f; c = c.to_f; d = d.to_f

  return c * Math.sqrt(1 - (t=t/d-1)*t) + b
end

#ease_out_cubic(t, b, c, d) ⇒ Object



39
40
41
42
43
# File 'lib/easing.rb', line 39

def ease_out_cubic(t, b, c, d)
  t = t.to_f; b = b.to_f; c = c.to_f; d = d.to_f

  return c*((t=t/d-1)*t*t + 1) + b
end

#ease_out_expo(t, b, c, d) ⇒ Object



114
115
116
117
118
# File 'lib/easing.rb', line 114

def ease_out_expo(t, b, c, d)
  t = t.to_f; b = b.to_f; c = c.to_f; d = d.to_f

  return (t==d) ? b+c : c * (-2**(-10 * t/d) + 1) + b
end

#ease_out_quad(t, b, c, d) ⇒ Object



18
19
20
21
22
# File 'lib/easing.rb', line 18

def ease_out_quad(t, b, c, d)
  t = t.to_f; b = b.to_f; c = c.to_f; d = d.to_f

  return -c *(t/=d)*(t-2) + b;
end

#ease_out_quart(t, b, c, d) ⇒ Object



58
59
60
61
62
# File 'lib/easing.rb', line 58

def ease_out_quart(t, b, c, d)
  t = t.to_f; b = b.to_f; c = c.to_f; d = d.to_f

  return -c * ((t=t/d-1)*t*t*t - 1) + b
end

#ease_out_quint(t, b, c, d) ⇒ Object



77
78
79
80
81
# File 'lib/easing.rb', line 77

def ease_out_quint(t, b, c, d)
  t = t.to_f; b = b.to_f; c = c.to_f; d = d.to_f

  return c*((t=t/d-1)*t*t*t*t + 1) + b
end

#ease_out_sine(t, b, c, d) ⇒ Object



96
97
98
99
100
# File 'lib/easing.rb', line 96

def ease_out_sine(t, b, c, d)
  t = t.to_f; b = b.to_f; c = c.to_f; d = d.to_f

  return c * Math.sin(t/d * (Math::PI/2)) + b
end

#linear_tween(t, b, c, d) ⇒ Object



6
7
8
9
10
# File 'lib/easing.rb', line 6

def linear_tween(t, b, c, d)
  t = t.to_f; b = b.to_f; c = c.to_f; d = d.to_f

  c * t / d + b
end