Skip to content

Commit 5cc3501

Browse files
authored
Merge pull request #3 from elm-community/0.19
Upgrade to 0.19
2 parents 0f309ec + 6810657 commit 5cc3501

File tree

7 files changed

+191
-92
lines changed

7 files changed

+191
-92
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
elm-stuff
2+
elm-package.json
3+
.DS_Store

Ease.elm

+63-33
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
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+
)
217

318
{-| An easing function is used in animation to make a transition between two values appear more lifelike or interesting.
419
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
722
happens at the start of the transition, easing "out" at the end, and "inOut" on both sides. The functions provided here
823
are meant to match the graphical examples on [easings.net](http://easings.net/).
924
10-
```elm
11-
import Ease
12-
n = 10
25+
import Ease
26+
n = 10
1327
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]
1635
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-
```
2036
2137
# 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+
3553
3654
# Combining easing functions
37-
@docs reverse, flip , inOut, retour
55+
56+
@docs reverse, flip, inOut, retour
57+
3858
-}
3959

4060

@@ -54,6 +74,7 @@ linear =
5474
{-| A cubic bezier function using 4 parameters: x and y position of first control point, and x and y position of second control point.
5575
5676
See [here](http://greweb.me/glsl-transition/example/ "glsl-transitions") for examples or [here](http://cubic-bezier.com/ "tester") to test.
77+
5778
-}
5879
bezier : Float -> Float -> Float -> Float -> Easing
5980
bezier x1 y1 x2 y2 time =
@@ -73,7 +94,7 @@ bezier x1 y1 x2 y2 time =
7394
List.map2 (\x y -> pair lerp x y time) xs (Maybe.withDefault [] (List.tail xs))
7495
|> casteljau
7596
in
76-
casteljau [ ( 0, 0 ), ( x1, y1 ), ( x2, y2 ), ( 1, 1 ) ]
97+
casteljau [ ( 0, 0 ), ( x1, y1 ), ( x2, y2 ), ( 1, 1 ) ]
7798

7899

79100
{-| -}
@@ -172,6 +193,7 @@ inExpo time =
172193
if time == 0.0 then
173194
0.0
174195
-- exact zero instead of 2^-10
196+
175197
else
176198
2 ^ (10 * (time - 1))
177199

@@ -246,14 +268,17 @@ outBounce time =
246268
t4 =
247269
time - (2.625 / 2.75)
248270
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
257282

258283

259284
{-| -}
@@ -267,6 +292,7 @@ inElastic : Easing
267292
inElastic time =
268293
if time == 0.0 then
269294
0.0
295+
270296
else
271297
let
272298
s =
@@ -278,7 +304,7 @@ inElastic time =
278304
t =
279305
time - 1
280306
in
281-
-((2 ^ (10 * t)) * sin ((t - s) * (2 * pi) / p))
307+
-((2 ^ (10 * t)) * sin ((t - s) * (2 * pi) / p))
282308

283309

284310
{-| -}
@@ -299,13 +325,15 @@ inOut : Easing -> Easing -> Easing
299325
inOut e1 e2 time =
300326
if time < 0.5 then
301327
e1 (time * 2) / 2
328+
302329
else
303330
0.5 + e2 ((time - 0.5) * 2) / 2
304331

305332

306333
{-| Flip an easing function. A transition that starts fast and continues slow now starts slow and continues fast.
307334
308335
Graphically, this flips the function around x = 0.5 and then around y = 0.5.
336+
309337
-}
310338
flip : Easing -> Easing
311339
flip easing time =
@@ -316,6 +344,7 @@ flip easing time =
316344
retraces exactly the same path, backwards.
317345
318346
Graphically, this flips the function around x = 0.5.
347+
319348
-}
320349
reverse : Easing -> Easing
321350
reverse easing time =
@@ -329,6 +358,7 @@ retour : Easing -> Easing
329358
retour easing time =
330359
if time < 0.5 then
331360
easing (time * 2)
361+
332362
else
333363
(time - 0.5)
334364
* 2

elm-package.json

-16
This file was deleted.

elm.json

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"type": "package",
3+
"name": "elm-community/easing-functions",
4+
"summary": "Easing functions for animations.",
5+
"license": "BSD-3-Clause",
6+
"version": "1.0.2",
7+
"exposed-modules": [
8+
"Ease"
9+
],
10+
"elm-version": "0.19.0 <= v < 0.20.0",
11+
"dependencies": {
12+
"elm/core": "1.0.0 <= v < 2.0.0"
13+
},
14+
"test-dependencies": {}
15+
}

test/Test.elm

+87-28
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
module Test exposing (..)
1+
module Test exposing (main)
22

33
import Ease exposing (..)
4-
import Collage exposing (..)
5-
import Element exposing (toHtml)
6-
import Text
7-
import Color exposing (gray, black)
4+
import Svg exposing (Svg)
5+
import Svg.Attributes as SvgAttributes
86

97

108
width =
@@ -15,37 +13,98 @@ height =
1513
64
1614

1715

18-
plot : Int -> ( Easing, String ) -> Form
16+
plot : Int -> ( Easing, String ) -> Svg a
1917
plot i ( f, name ) =
20-
group
21-
[ rect width 1 |> filled gray
22-
, rect width 1 |> filled gray |> moveY height
23-
, List.map
24-
(toFloat >> (\x -> ( x - width / 2, f (x / width) * height )))
25-
(List.range 0 (round width))
26-
|> path
27-
|> traced (solid black)
28-
--|> (\ls -> {ls | width = 3}),
29-
, Text.fromString name |> text |> moveY (height + 8)
18+
Svg.g
19+
[ SvgAttributes.transform
20+
("translate("
21+
++ String.fromInt ((width + 10) * modBy 6 i)
22+
++ ","
23+
++ String.fromInt ((height + 50) * (i // 6))
24+
++ ")"
25+
)
3026
]
31-
|> move ( (width + 10) * (i % 6) |> toFloat, (-height - 20) * (i // 6) |> toFloat )
27+
[ Svg.rect
28+
[ SvgAttributes.width (String.fromInt width)
29+
, SvgAttributes.height (String.fromInt 1)
30+
, SvgAttributes.fill "gray"
31+
]
32+
[]
33+
, Svg.rect
34+
[ SvgAttributes.width (String.fromInt width)
35+
, SvgAttributes.height (String.fromInt 1)
36+
, SvgAttributes.y (String.fromInt height)
37+
, SvgAttributes.fill "gray"
38+
]
39+
[]
40+
, Svg.path
41+
[ List.map
42+
(toFloat
43+
>> (\x ->
44+
( x
45+
, height - f (x / width) * height
46+
)
47+
)
48+
)
49+
(List.range 0 (round width))
50+
|> path
51+
|> SvgAttributes.d
52+
, SvgAttributes.stroke "black"
53+
, SvgAttributes.strokeWidth "2"
54+
, SvgAttributes.fill "transparent"
55+
]
56+
[]
57+
, Svg.text_
58+
[ SvgAttributes.y (String.fromInt -15)
59+
, SvgAttributes.x (String.fromInt 30)
60+
, SvgAttributes.style "font: 14px sans-serif;"
61+
]
62+
[ Svg.text name ]
63+
]
64+
65+
66+
path : List ( Float, Float ) -> String
67+
path list =
68+
case list of
69+
( x, y ) :: tail ->
70+
"M"
71+
++ String.fromFloat x
72+
++ ","
73+
++ String.fromFloat y
74+
++ String.join ""
75+
(List.map
76+
(\( a, b ) ->
77+
"L"
78+
++ String.fromFloat a
79+
++ ","
80+
++ String.fromFloat b
81+
)
82+
tail
83+
)
3284

85+
_ ->
86+
""
3387

88+
89+
title : Svg a
3490
title =
35-
Text.fromString "This is a replication of easings.net for testing purposes. You can see the plots are nearly identical."
36-
|> text
37-
|> move ( 200, height + 30 )
91+
Svg.text_
92+
[ SvgAttributes.y "-60"
93+
, SvgAttributes.x "80"
94+
, SvgAttributes.style "font: 14px sans-serif;"
95+
]
96+
[ Svg.text "This is a replication of easings.net for testing purposes. You can see the plots are nearly identical." ]
3897

3998

99+
main : Svg a
40100
main =
41-
let
42-
forms =
43-
title :: List.indexedMap plot easingFunctions
44-
45-
grouped =
46-
group forms |> move ( -200, 300 )
47-
in
48-
collage 1000 1000 [ grouped ] |> toHtml
101+
Svg.svg
102+
[ SvgAttributes.width "850"
103+
, SvgAttributes.height "650"
104+
, SvgAttributes.viewBox "-10 -60 840 590"
105+
, SvgAttributes.style "display:block;margin:auto;"
106+
]
107+
(title :: List.indexedMap plot easingFunctions)
49108

50109

51110
easingFunctions =

test/elm-package.json

-15
This file was deleted.

test/elm.json

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"type": "application",
3+
"source-directories": [
4+
".",
5+
".."
6+
],
7+
"elm-version": "0.19.0",
8+
"dependencies": {
9+
"direct": {
10+
"elm/core": "1.0.0",
11+
"elm/svg": "1.0.0"
12+
},
13+
"indirect": {
14+
"elm/json": "1.0.0",
15+
"elm/html": "1.0.0",
16+
"elm/virtual-dom": "1.0.0"
17+
}
18+
},
19+
"test-dependencies": {
20+
"direct": {},
21+
"indirect": {}
22+
}
23+
}

0 commit comments

Comments
 (0)