Copyright | (C) 2018 Francesco Ariis |
---|---|
License | BSD3 (see LICENSE file) |
Maintainer | Francesco Ariis <fa-ml@ariis.it> |
Stability | provisional |
Portability | portable |
Safe Haskell | Safe |
Language | Haskell2010 |
Timers and timed resources (animations, etc.) utilities for tick-based programs.
- creaTimer :: a -> a -> Integer -> Timed a
- creaBoolTimer :: Integer -> Timed Bool
- data Timed a
- creaTimedRes :: Loop -> [(Integer, a)] -> Timed a
- data Loop
- data ExpBehaviour
- tick :: Timed a -> Timed a
- ticks :: Integer -> Timed a -> Timed a
- reset :: Timed a -> Timed a
- isLive :: Timed a -> Bool
- isExpired :: Timed a -> Bool
- fetchFrame :: Timed a -> a
- getFrames :: Timed a -> [(Integer, a)]
Simple timers
creaTimer :: a -> a -> Integer -> Timed a Source #
A simple off/on timer expiring in fixed number of ticks.
Example:
timer = creaTimer Nothing (Just "Over!") 4 test t | isExpired t = print (fetchFrame t) | otherwise = do print (fetchFrame t) test (tick t) -- λ> test timer -- Nothing -- Nothing -- Nothing -- Nothing -- Just "Over"!
Timed Resources
A timed resource is a timer which, at any given moment, points to a specific item (like an animation).
Example:
timer = creaTimedRes (Times 1 Elapse) [(2, "a "), (1, "b "), (2, "c ")] test t | isExpired t = putStrLn "Fine." | otherwise = do putStr (fetchFrame t) test (tick t) -- λ> test timer -- a a b c c Fine.
creaTimedRes :: Loop -> [(Integer, a)] -> Timed a Source #
Most generic way to create a time-based resource (like an animation).
Loop
controls the expiring behaviour, [(Integer, a)]
is a list of
frames and their duration.
Number of times to repeat the animation.
AlwaysLoop | Loops forever, never expires. |
Times Integer ExpBehaviour | Repeats the cycle for a fixed number of times. |
data ExpBehaviour Source #
Expire behaviour.
Use
Query
isExpired :: Timed a -> Bool Source #
Checks wheter the timer is expired (an expired timer will not
respond to tick
).
fetchFrame :: Timed a -> a Source #
Fetches the current resource of the timer.