-
Notifications
You must be signed in to change notification settings - Fork 5
/
easie.coffee
225 lines (176 loc) · 7.59 KB
/
easie.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
###
Easie.coffee (https://github.com/jimjeffers/Easie)
Project created by J. Jeffers
Robert Penner's Easing Equations in CoffeeScript
http://robertpenner.com/easing/
DISCLAIMER: Software provided as is with no warranty of any type.
Don't do bad things with this :)
###
class @Easie
# Back Easing
# -----------------------------------------------------
@backIn: (time,begin,change,duration,overshoot=1.70158) ->
change*(time/=duration)*time*((overshoot+1)*time - overshoot) + begin;
@backOut: (time,begin,change,duration,overshoot=1.70158) ->
change*((time=time/duration-1)*time*((overshoot+1)*time + overshoot) + 1) + begin
@backInOut: (time,begin,change,duration,overshoot=1.70158) ->
if ((time = time/(duration/2)) < 1)
return change/2*(time*time*(((overshoot*=(1.525))+1)*time - overshoot)) + begin
else
return change/2*((time-=2)*time*(((overshoot*=(1.525))+1)*time + overshoot) + 2) + begin
# Bounce Easing
# -----------------------------------------------------
@bounceOut: (time,begin,change,duration) ->
if (time /= duration) < 1/2.75
return change * (7.5625*time*time) + begin
else if time < 2/2.75
return change * (7.5625*(time -= (1.5/2.75)) * time + 0.75) + begin
else if time < 2.5/2.75
return change * (7.5625*(time -= (2.25/2.75)) * time + 0.9375) + begin
else
return change * (7.5625*(time -= (2.625/2.75)) * time + 0.984375) + begin
@bounceIn: (time,begin,change,duration) ->
return change - Easie.bounceOut(duration-time, 0, change, duration) + begin
@bounceInOut: (time,begin,change,duration) ->
if time < duration/2
return Easie.bounceIn(time*2, 0, change, duration) * 0.5 + begin
else
return Easie.bounceOut(time*2-duration, 0, change, duration) * 0.5 + change*0.5 + begin
# Circ Easing
# -----------------------------------------------------
@circIn: (time,begin,change,duration) ->
-change * (Math.sqrt(1 - (time = time/duration) * time) - 1) + begin
@circOut: (time,begin,change,duration) ->
change * Math.sqrt(1 - (time = time/duration-1) * time) + begin
@circInOut: (time,begin,change,duration) ->
if (time = time / (duration/2)) < 1
return -change/2 * (Math.sqrt(1 - time*time) - 1) + begin
else
return change/2 * (Math.sqrt(1 - (time -= 2) * time) + 1) + begin
# Cubic Easing
# -----------------------------------------------------
@cubicIn: (time,begin,change,duration) ->
change * (time/=duration)*time*time + begin
@cubicOut: (time,begin,change,duration) ->
change * ((time=time/duration-1)*time*time + 1) + begin
@cubicInOut: (time,begin,change,duration) ->
if (time = time/(duration/2)) < 1
return change/2 * time*time*time + begin
else
return change/2 * ((time -= 2)*time*time + 2) + begin
# Elastic Easing
# -----------------------------------------------------
@elasticOut: (time,begin,change,duration,amplitude=null,period=null) ->
if time == 0
return begin
else if (time=time/duration) == 1
return begin+change
else
if !period?
period = duration*0.3
if !amplitude? or amplitude < Math.abs(change)
amplitude = change
overshoot = period/4
else
overshoot = period/(2*Math.PI) * Math.asin(change/amplitude)
(amplitude*Math.pow(2,-10*time)) * Math.sin((time*duration-overshoot)*(2*Math.PI)/period)+change+begin
@elasticIn: (time,begin,change,duration,amplitude=null,period=null) ->
if time == 0
return begin
else if (time=time/duration) == 1
return begin+change
else
if !period?
period = duration*0.3
if !amplitude? or amplitude < Math.abs(change)
amplitude = change
overshoot = period/4
else
overshoot = period/(2*Math.PI) * Math.asin(change/amplitude)
time -= 1
-(amplitude*Math.pow(2,10*time)) * Math.sin((time*duration-overshoot)*(2*Math.PI)/period)+begin
@elasticInOut: (time,begin,change,duration,amplitude=null,period=null) ->
if time == 0
return begin
else if (time = time/(duration/2)) == 2
return begin+change
else
if !period?
period = duration*(0.3*1.5)
if !amplitude? or amplitude < Math.abs(change)
amplitude = change
overshoot = period/4
else
overshoot = period/(2*Math.PI)*Math.asin(change/amplitude)
if time < 1
return -0.5*(amplitude*Math.pow(2,10*(time-=1))) * Math.sin((time*duration-overshoot)*((2*Math.PI)/period)) + begin
else
return amplitude * Math.pow(2,-10*(time-=1)) * Math.sin((time*duration-overshoot)*(2*Math.PI)/period) + change + begin
# Exponential Easing
# -----------------------------------------------------
@expoIn: (time,begin,change,duration) ->
return begin if time == 0
change * Math.pow(2, 10*(time/duration-1))+begin
@expoOut: (time,begin,change,duration) ->
return begin+change if time == duration
change * (-Math.pow(2,-10*time/duration)+1)+begin
@expoInOut: (time,begin,change,duration) ->
if time == 0
return begin
else if time == duration
return begin+change
else if (time = time/(duration/2)) < 1
return change/2 * Math.pow(2,10*(time-1)) + begin
else
change/2*(-Math.pow(2,-10*(time-1))+2)+begin;
# Linear
# -----------------------------------------------------
@linearNone: (time,begin,change,duration) ->
change*time/duration + begin
@linearIn: (time,begin,change,duration) ->
Easie.linearNone(time,begin,change,duration)
@linearOut: (time,begin,change,duration) ->
Easie.linearNone(time,begin,change,duration)
@linearInOut: (time,begin,change,duration) ->
Easie.linearNone(time,begin,change,duration)
# Quad Easing
# -----------------------------------------------------
@quadIn: (time,begin,change,duration) ->
change * (time = time/duration)*time + begin
@quadOut: (time,begin,change,duration) ->
-change * (time = time/duration)*(time-2) + begin
@quadInOut: (time,begin,change,duration) ->
if (time = time/(duration/2)) < 1
return change/2 * time*time + begin
else
return -change/2 * ((time -= 1)*(time-2)-1) + begin
# Quart Easing
# -----------------------------------------------------
@quartIn: (time,begin,change,duration) ->
change * (time = time/duration)*time*time*time + begin
@quartOut: (time,begin,change,duration) ->
-change * ((time = time/duration - 1)*time*time*time - 1) + begin
@quartInOut: (time,begin,change,duration) ->
if (time = time/(duration/2)) < 1
return change/2 * time*time*time*time + begin
else
return -change/2 * ((time -= 2)*time*time*time - 2) + begin
# Quint Easing
# -----------------------------------------------------
@quintIn: (time,begin,change,duration) ->
change * (time = time/duration)*time*time*time*time + begin
@quintOut: (time,begin,change,duration) ->
change * ((time = time/duration-1)*time*time*time*time + 1) + begin
@quintInOut: (time,begin,change,duration) ->
if (time = time/(duration/2)) < 1
return change/2 * time*time*time*time*time + begin
else
return change/2 * ((time -= 2)*time*time*time*time + 2) + begin
# Sine Easing
# -----------------------------------------------------
@sineIn: (time,begin,change,duration) ->
-change * Math.cos(time/duration * (Math.PI/2)) + change + begin
@sineOut: (time,begin,change,duration) ->
change * Math.sin(time/duration * (Math.PI/2)) + begin
@sineInOut: (time,begin,change,duration) ->
-change/2 * (Math.cos(Math.PI*time/duration) - 1) + begin