-
Notifications
You must be signed in to change notification settings - Fork 70
/
Easing.coffee
71 lines (53 loc) · 1.67 KB
/
Easing.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
# ### Simple easing functions based on Robert Penner's functions.
class Easing
# ## Linear interpolation
# @param `t` current time or iteration
# @param `b` start value
# @param `c` change in value
# @param `d` duration time or total iteration
# @return interpolated value
@linear: (t, b, c, d) ->
return c * (t /= d) + b
@_linear:(t) -> Easing.linear(t, 0, 1, 1)
@quadIn: (t, b, c, d) ->
return c * (t /= d) * t + b
@_quadIn: (t) -> Easing.quadIn(t, 0, 1, 1)
@quadOut: (t, b, c, d) ->
return -c * (t /= d) * (t - 2) + b
@_quadOut: (t) -> Easing.quadOut(t, 0, 1, 1)
@cubicIn: (t, b, c, d) ->
t = t/d
return c * t * t * t + b
@_cubicIn: (t) -> Easing.cubicIn(t, 0, 1, 1)
@cubicOut: (t, b, c, d) ->
t = t/d
return c * ((t - 1) * t * t + 1) + b
@_cubicOut: (t) -> Easing.cubicOut(t, 0, 1, 1)
@elastic: (t, b, c, d, el=0.3) ->
s = 1.70158
p = d * el
a = c
if t == 0 then return b
t = t/d
if t == 1 then return b + c
if a < Math.abs(c)
a = c
s = p / 4
else if a != 0
s = p / Const.two_pi * Math.asin(c / a)
else
s = 0
return a * Math.pow(2, -10 * t) * Math.sin((t * d - s) * Const.two_pi / p) + c + b
@_elastic: (t) -> Easing.elastic(t, 0, 1, 1)
@bounce: (t, b, c, d) ->
if (t /= d) < (1 / 2.75)
return c * (7.5625 * t * t) + b
else if t < (2 / 2.75)
return c * (7.5625 * (t -= 1.5 / 2.75) * t + 0.75) + b
else if 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
@_bounce: (t) -> Easing.bounce(t, 0, 1, 1)
# namespace
this.Easing = Easing