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