PageRenderTime 39ms CodeModel.GetById 32ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/unmaintained/animations/animations.factor

http://github.com/abeaumont/factor
Unknown | 17 lines | 14 code | 3 blank | 0 comment | 0 complexity | c7ad7945860e9115cebb8a6a224bb314 MD5 | raw file
 1! Small library for cross-platform continuous functions of real time
 2
 3USING: kernel shuffle system locals
 4prettyprint math io namespaces threads calendar ;
 5IN: animations
 6
 7SYMBOL: last-loop
 8SYMBOL: sleep-period
 9
10: reset-progress ( -- ) millis last-loop set ;
11! : my-progress ( -- progress ) millis 
12: progress ( -- time ) millis last-loop get - reset-progress ;
13: progress-peek ( -- progress ) millis last-loop get - ;
14: set-end ( duration -- end-time ) duration>milliseconds millis + ;
15: loop ( quot end -- ) dup millis > [ [ dup call ] dip loop ] [ 2drop ] if ; inline
16: animate ( quot duration -- ) reset-progress set-end loop ; inline
17: sample ( revs quot -- avg ) reset-progress dupd times progress swap / ; inline