never executed always true always false
1 {-|
2 Copyright : Written by David Himmelstrup
3 License : Unlicense
4 Maintainer : lemmih@gmail.com
5 Stability : experimental
6 Portability : POSIX
7 -}
8 module Reanimate.Transition
9 ( Transition
10 , signalT
11 , mapT
12 , overlapT
13 , chainT
14 , effectT
15 , fadeT
16 ) where
17
18 import Reanimate.Animation
19 import Reanimate.Ease
20 import Reanimate.Effect
21
22 -- | A transition transforms one animation into another.
23 type Transition = Animation -> Animation -> Animation
24
25 -- | Apply a signal to the timing of a transition.
26 signalT :: Signal -> Transition -> Transition
27 signalT = mapT . signalA
28
29 -- | Map the result of a transition.
30 mapT :: (Animation -> Animation) -> Transition -> Transition
31 mapT fn t a b = fn (t a b)
32
33 -- | Apply transition only to @N@ seconds of the first
34 -- animation and to the last @N@ seconds of the second animation.
35 --
36 -- Example:
37 --
38 -- > overlapT 0.5 fadeT drawBox drawCircle
39 --
40 -- <<docs/gifs/doc_overlapT.gif>>
41 overlapT :: Double -> Transition -> Transition
42 overlapT overlap t a b =
43 aBefore `seqA` t aOverlap bOverlap `seqA` bAfter
44 where
45 aBefore = takeA (duration a - overlap) a
46 aOverlap = lastA overlap a
47 bOverlap = takeA overlap b
48 bAfter = dropA overlap b
49
50
51 -- | Create a transition between two animations by applying an effect to each respective animation.
52 effectT :: Effect -- ^ Effect to be applied to the first animation.
53 -> Effect -- ^ Effect to be applied to the second animation.
54 -> Transition
55 effectT eA eB a b = applyE eA a `parA` applyE eB b
56
57 -- | Combine a list of animations using a given transition.
58 --
59 -- Example:
60 --
61 -- > chainT (overlapT 0.5 fadeT) [drawBox, drawCircle, drawProgress]
62 --
63 -- <<docs/gifs/doc_chainT.gif>>
64 chainT :: Transition -> [Animation] -> Animation
65 chainT _ [] = pause 0
66 chainT t (x:xs) = foldl t x xs
67
68 -- | Fade out left-hand-side animation while fading in right-hand-side animation.
69 --
70 -- Example:
71 --
72 -- > drawBox `fadeT` drawCircle
73 --
74 -- <<docs/gifs/doc_fadeT.gif>>
75 fadeT :: Transition
76 fadeT = effectT fadeOutE fadeInE