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 -- @
   39 -- 'overlapT' 0.5 'fadeT' 'Reanimate.Builtin.Documentation.drawBox' 'Reanimate.Builtin.Documentation.drawCircle'
   40 -- @
   41 --
   42 --   <<docs/gifs/doc_overlapT.gif>>
   43 overlapT :: Double -> Transition -> Transition
   44 overlapT overlap t a b =
   45     aBefore `seqA` t aOverlap bOverlap `seqA` bAfter
   46   where
   47     aBefore  = takeA (duration a - overlap) a
   48     aOverlap = lastA overlap a
   49     bOverlap = takeA overlap b
   50     bAfter   = dropA overlap b
   51 
   52 
   53 -- | Create a transition between two animations by applying an effect to each respective animation.
   54 effectT :: Effect -- ^ Effect to be applied to the first animation.
   55         -> Effect -- ^ Effect to be applied to the second animation.
   56         -> Transition
   57 effectT eA eB a b = applyE eA a `parA` applyE eB b
   58 
   59 -- | Combine a list of animations using a given transition.
   60 --
   61 --   Example:
   62 --
   63 -- @
   64 -- 'chainT' ('overlapT' 0.5 'fadeT') ['Reanimate.Builtin.Documentation.drawBox', 'Reanimate.Builtin.Documentation.drawCircle', 'Reanimate.Builtin.Documentation.drawProgress']
   65 -- @
   66 --
   67 --   <<docs/gifs/doc_chainT.gif>>
   68 chainT :: Transition -> [Animation] -> Animation
   69 chainT _ [] = pause 0
   70 chainT t (x:xs) = foldl t x xs
   71 
   72 -- | Fade out left-hand-side animation while fading in right-hand-side animation.
   73 --
   74 --   Example:
   75 --
   76 -- @
   77 -- 'Reanimate.Builtin.Documentation.drawBox' `'fadeT'` 'Reanimate.Builtin.Documentation.drawCircle'
   78 -- @
   79 --
   80 --   <<docs/gifs/doc_fadeT.gif>>
   81 fadeT :: Transition
   82 fadeT = effectT fadeOutE fadeInE