]> gitweb.factorcode.org Git - factor-unmaintained.git/blobdiff - animations/animations.factor
unmaintained: New home for misfit Factor vocabularies.
[factor-unmaintained.git] / animations / animations.factor
diff --git a/animations/animations.factor b/animations/animations.factor
new file mode 100644 (file)
index 0000000..8f416dc
--- /dev/null
@@ -0,0 +1,17 @@
+! Small library for cross-platform continuous functions of real time
+
+USING: kernel shuffle system locals
+prettyprint math io namespaces threads calendar ;
+IN: animations
+
+SYMBOL: last-loop
+SYMBOL: sleep-period
+
+: reset-progress ( -- ) millis last-loop set ;
+! : my-progress ( -- progress ) millis 
+: progress ( -- time ) millis last-loop get - reset-progress ;
+: progress-peek ( -- progress ) millis last-loop get - ;
+: set-end ( duration -- end-time ) duration>milliseconds millis + ;
+: loop ( quot end -- ) dup millis > [ [ dup call ] dip loop ] [ 2drop ] if ; inline
+: animate ( quot duration -- ) reset-progress set-end loop ; inline
+: sample ( revs quot -- avg ) reset-progress dupd times progress swap / ; inline