-
Notifications
You must be signed in to change notification settings - Fork 2
/
tweencurve.coffee
155 lines (126 loc) · 2.87 KB
/
tweencurve.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# Special thanks to:
#
# http://gizma.com/easing/
#
Tween =
# LINEAR
linear: (t, b, c, d) ->
c*t/d + b
# QUADRATIC
easeInQuad: (t, b, c, d) ->
t /= d
c*t*t + b
easeOutQuad: (t, b, c, d) ->
t /= d
-c * t*(t-2) + b
easeInOutQuad: (t, b, c, d) ->
t /= d/2
if t < 1
c/2*t*t + b
else
t--
-c/2 * (t*(t-2) - 1) + b
# CUBIC
easeInCubic: (t, b, c, d) ->
t /= d
c*t*t*t + b
easeOutCubic: (t, b, c, d) ->
t /= d
t--
c*(t*t*t + 1) + b
easeInOutCubic: (t, b, c, d) ->
t /= d/2
if t < 1
c/2*t*t*t + b
else
t -= 2
c/2*(t*t*t + 2) + b
# QUARTIC
easeInQuart: (t, b, c, d) ->
t /= d
c*t*t*t*t + b
easeOutQuart: (t, b, c, d) ->
t /= d
t--
-c * (t*t*t*t - 1) + b
easeInOutQuart: (t, b, c, d) ->
t /= d/2
if t < 1
c/2*t*t*t*t + b
else
t -= 2
-c/2 * (t*t*t*t - 2) + b
# QUINTIC
easeInQuint: (t, b, c, d) ->
t /= d
c*t*t*t*t*t + b
easeOutQuint: (t, b, c, d) ->
t /= d
t--
c*(t*t*t*t*t + 1) + b
easeInOutQuint: (t, b, c, d) ->
t /= d/2
if t < 1
c/2*t*t*t*t*t + b
else
t -= 2;
c/2*(t*t*t*t*t + 2) + b
# SINE
easeInSine: (t, b, c, d) ->
-c * Math.cos(t/d * (Math.PI/2)) + c + b
easeOutSine: (t, b, c, d) ->
c * Math.sin(t/d * (Math.PI/2)) + b
easeInOutSine: (t, b, c, d) ->
-c/2 * (Math.cos(Math.PI*t/d) - 1) + b
# EXPONENTIAL
easeInExpo: (t, b, c, d) ->
c * Math.pow( 2, 10 * (t/d - 1) ) + b
easeOutExpo: (t, b, c, d) ->
c * ( -Math.pow( 2, -10 * t/d ) + 1 ) + b
easeInOutExpo: (t, b, c, d) ->
t /= d/2
if t < 1
c/2 * Math.pow( 2, 10 * (t - 1) ) + b
else
t--
c/2 * ( -Math.pow( 2, -10 * t) + 2 ) + b
# CIRCULAR
easeInCirc: (t, b, c, d) ->
t /= d
-c * (Math.sqrt(1 - t*t) - 1) + b
easeOutCirc: (t, b, c, d) ->
t /= d
t--
c * Math.sqrt(1 - t*t) + b
easeInOutCirc: (t, b, c, d) ->
t /= d/2
if t < 1
-c/2 * (Math.sqrt(1 - t*t) - 1) + b
else
t -= 2
c/2 * (Math.sqrt(1 - t*t) + 1) + b
# Aliases
Tween.low = Tween.easeInSine
Tween.high = Tween.easeOutSine
Tween.ease = Tween.easeInOutSine
Tween.low2 = Tween.easeInQuad
Tween.high2 = Tween.easeOutQuad
Tween.ease2 = Tween.easeInOutQuad
Tween.low3 = Tween.easeInCubic
Tween.high3 = Tween.easeOutCubic
Tween.ease3 = Tween.easeInOutCubic
Tween.low4 = Tween.easeInQuart
Tween.high4 = Tween.easeOutQuart
Tween.ease4 = Tween.easeInOutQuart
Tween.low5 = Tween.easeInQuint
Tween.high5 = Tween.easeOutQuint
Tween.ease5 = Tween.easeInOutQuint
# Setup Curve
Curve = {}
for own name, fn of Tween
do (name, fn) ->
Curve[name] = (n) ->
fn n, 0, 1, 1
scope = window || module.exports
scope.Tween = Tween
scope.Curve = Curve