1
- module Ease exposing (Easing , reverse , retour , inOut , flip , bezier , linear , inQuad , outQuad , inOutQuad , inCubic , outCubic , inOutCubic , inQuart , outQuart , inOutQuart , inQuint , outQuint , inOutQuint , inSine , outSine , inOutSine , inExpo , outExpo , inOutExpo , inCirc , outCirc , inOutCirc , inBack , outBack , inOutBack , inBounce , outBounce , inOutBounce , inElastic , outElastic , inOutElastic )
1
+ module Ease exposing
2
+ ( Easing
3
+ , bezier
4
+ , linear
5
+ , inQuad, outQuad, inOutQuad
6
+ , inCubic, outCubic, inOutCubic
7
+ , inQuart, outQuart, inOutQuart
8
+ , inQuint, outQuint, inOutQuint
9
+ , inSine, outSine, inOutSine
10
+ , inExpo, outExpo, inOutExpo
11
+ , inCirc, outCirc, inOutCirc
12
+ , inBack, outBack, inOutBack
13
+ , inBounce, outBounce, inOutBounce
14
+ , inElastic, outElastic, inOutElastic
15
+ , reverse, flip, inOut, retour
16
+ )
2
17
3
18
{- | An easing function is used in animation to make a transition between two values appear more lifelike or interesting.
4
19
Easing functions can make sliding panels or bouncing menus appear to be physical objects.
@@ -7,34 +22,39 @@ All easing functions expect inputs to be bewteen zero and one, and will typicall
7
22
happens at the start of the transition, easing "out" at the end, and "inOut" on both sides. The functions provided here
8
23
are meant to match the graphical examples on [easings.net](http://easings.net/).
9
24
10
- ```elm
11
- import Ease
12
- n = 10
25
+ import Ease
26
+ n = 10
13
27
14
- List.map (\i -> Ease.inQuad (i/n)) [0..n]
15
- > [0, 0.01, 0.04, 0.09, 0.16, 0.25, 0.36, 0.49, 0.64, 0.81, 1]
28
+ List.map (\i -> Ease.inQuad (toFloat i / n)) (List.range 0 n)
29
+
30
+ --> [0, 0.01, 0.04, 0.09, 0.16, 0.25, 0.36, 0.49, 0.64, 0.81, 1]
31
+
32
+ List.map (\i -> Ease.outCubic (toFloat i / n)) (List.range 0 n)
33
+
34
+ --> [0, 0.271, 0.488, 0.657, 0.784, 0.875, 0.936, 0.973, 0.992, 0.999, 1]
16
35
17
- List.map (\i -> Ease.outCubic (i/n)) [0..n]
18
- > [0, 0.271, 0.488, 0.657, 0.784, 0.875, 0.936, 0.973, 0.992, 0.999, 1]
19
- ```
20
36
21
37
# Easing functions
22
- @docs Easing,
23
- bezier,
24
- linear,
25
- inQuad, outQuad, inOutQuad,
26
- inCubic, outCubic, inOutCubic,
27
- inQuart, outQuart, inOutQuart,
28
- inQuint, outQuint, inOutQuint,
29
- inSine, outSine, inOutSine,
30
- inExpo, outExpo, inOutExpo,
31
- inCirc, outCirc, inOutCirc,
32
- inBack, outBack, inOutBack,
33
- inBounce, outBounce, inOutBounce,
34
- inElastic, outElastic, inOutElastic
38
+
39
+ @docs Easing
40
+ @docs bezier
41
+ @docs linear
42
+ @docs inQuad, outQuad, inOutQuad
43
+ @docs inCubic, outCubic, inOutCubic
44
+ @docs inQuart, outQuart, inOutQuart
45
+ @docs inQuint, outQuint, inOutQuint
46
+ @docs inSine, outSine, inOutSine
47
+ @docs inExpo, outExpo, inOutExpo
48
+ @docs inCirc, outCirc, inOutCirc
49
+ @docs inBack, outBack, inOutBack
50
+ @docs inBounce, outBounce, inOutBounce
51
+ @docs inElastic, outElastic, inOutElastic
52
+
35
53
36
54
# Combining easing functions
37
- @docs reverse, flip , inOut, retour
55
+
56
+ @docs reverse, flip, inOut, retour
57
+
38
58
-}
39
59
40
60
@@ -54,6 +74,7 @@ linear =
54
74
{- | A cubic bezier function using 4 parameters: x and y position of first control point, and x and y position of second control point.
55
75
56
76
See [here](http://greweb.me/glsl-transition/example/ "glsl-transitions") for examples or [here](http://cubic-bezier.com/ "tester") to test.
77
+
57
78
-}
58
79
bezier : Float -> Float -> Float -> Float -> Easing
59
80
bezier x1 y1 x2 y2 time =
@@ -73,7 +94,7 @@ bezier x1 y1 x2 y2 time =
73
94
List . map2 ( \ x y -> pair lerp x y time) xs ( Maybe . withDefault [] ( List . tail xs))
74
95
|> casteljau
75
96
in
76
- casteljau [ ( 0 , 0 ) , ( x1, y1 ) , ( x2, y2 ) , ( 1 , 1 ) ]
97
+ casteljau [ ( 0 , 0 ) , ( x1, y1 ) , ( x2, y2 ) , ( 1 , 1 ) ]
77
98
78
99
79
100
{- | -}
@@ -172,6 +193,7 @@ inExpo time =
172
193
if time == 0.0 then
173
194
0.0
174
195
-- exact zero instead of 2^-10
196
+
175
197
else
176
198
2 ^ ( 10 * ( time - 1 ))
177
199
@@ -246,14 +268,17 @@ outBounce time =
246
268
t4 =
247
269
time - ( 2.625 / 2.75 )
248
270
in
249
- if time < 1 / 2.75 then
250
- a * time * time
251
- else if time < 2 / 2.75 then
252
- a * t2 * t2 + 0.75
253
- else if time < 2.5 / 2.75 then
254
- a * t3 * t3 + 0.9375
255
- else
256
- a * t4 * t4 + 0.984375
271
+ if time < 1 / 2.75 then
272
+ a * time * time
273
+
274
+ else if time < 2 / 2.75 then
275
+ a * t2 * t2 + 0.75
276
+
277
+ else if time < 2.5 / 2.75 then
278
+ a * t3 * t3 + 0.9375
279
+
280
+ else
281
+ a * t4 * t4 + 0.984375
257
282
258
283
259
284
{- | -}
@@ -267,6 +292,7 @@ inElastic : Easing
267
292
inElastic time =
268
293
if time == 0.0 then
269
294
0.0
295
+
270
296
else
271
297
let
272
298
s =
@@ -278,7 +304,7 @@ inElastic time =
278
304
t =
279
305
time - 1
280
306
in
281
- - (( 2 ^ ( 10 * t)) * sin (( t - s) * ( 2 * pi) / p))
307
+ - (( 2 ^ ( 10 * t)) * sin (( t - s) * ( 2 * pi) / p))
282
308
283
309
284
310
{- | -}
@@ -299,13 +325,15 @@ inOut : Easing -> Easing -> Easing
299
325
inOut e1 e2 time =
300
326
if time < 0.5 then
301
327
e1 ( time * 2 ) / 2
328
+
302
329
else
303
330
0.5 + e2 (( time - 0.5 ) * 2 ) / 2
304
331
305
332
306
333
{- | Flip an easing function. A transition that starts fast and continues slow now starts slow and continues fast.
307
334
308
335
Graphically, this flips the function around x = 0.5 and then around y = 0.5.
336
+
309
337
-}
310
338
flip : Easing -> Easing
311
339
flip easing time =
@@ -316,6 +344,7 @@ flip easing time =
316
344
retraces exactly the same path, backwards.
317
345
318
346
Graphically, this flips the function around x = 0.5.
347
+
319
348
-}
320
349
reverse : Easing -> Easing
321
350
reverse easing time =
@@ -329,6 +358,7 @@ retour : Easing -> Easing
329
358
retour easing time =
330
359
if time < 0.5 then
331
360
easing ( time * 2 )
361
+
332
362
else
333
363
( time - 0.5 )
334
364
* 2
0 commit comments