adding animations lib
parent
b0151f8202
commit
3edf1db4a3
|
@ -0,0 +1,34 @@
|
|||
USING: help.markup help.syntax ;
|
||||
IN: extra.animations
|
||||
|
||||
HELP: animate ( quot duration -- )
|
||||
{ $values
|
||||
{ "quot" "a quot which uses " { $link progress } }
|
||||
{ "duration" "a duration of time" }
|
||||
}
|
||||
{ $description { $link animate } " calls " { $link reset-progress } " , then continously calls the given quot until the duration of time has elapsed. The quot should use " { $link progress } " at least once." }
|
||||
{ $example
|
||||
"USING: extra.animations calendar threads prettyprint ;"
|
||||
"[ 1 sleep progress unparse write \" ms elapsed\" print ] 1/20 seconds animate ;"
|
||||
"46 ms elapsed\n17 ms elapsed"
|
||||
} ;
|
||||
|
||||
HELP: reset-progress ( -- )
|
||||
{ $description "Initiates the timer. Call this before using a loop which makes use of " { $link progress } "." } ;
|
||||
|
||||
HELP: progress ( -- time )
|
||||
{ $values { "time" "an integer" } }
|
||||
{ $description "Gives the time elapsed since the last time this word was called, in milliseconds." }
|
||||
{ $example
|
||||
"USING: extra.animations threads prettyprint ;"
|
||||
"reset-progress 3 [ 1 sleep progress unparse write \"ms elapsed\" print ] times ;"
|
||||
"31 ms elapsed\n18 ms elapsed\n16 ms elapsed"
|
||||
} ;
|
||||
|
||||
ARTICLE: "extra.animations" "Animations"
|
||||
"Provides a lightweight framework for properly simulating continuous functions of real time. This framework helps one create animations that use rates which do not change across platforms. The speed of the computer should correlate with the smoothness of the animation, not the speed of the animation!"
|
||||
{ $subsection animate }
|
||||
{ $subsection reset-progress }
|
||||
{ $subsection progress }
|
||||
{ $link progress } " specifically provides the length of time since " { $link reset-progress } " was called, and also calls " { $link reset-progress } " as its last action. This can be directly used when one's quote runs for a specific number of iterations, instead of a length of time. If the animation is like most, and is expected to run for a specific length of time, " { $link animate } " should be used." ;
|
||||
ABOUT: "extra.animations"
|
|
@ -0,0 +1,12 @@
|
|||
! Small library for cross-platform continuous functions of real time
|
||||
|
||||
USING: kernel shuffle system locals
|
||||
prettyprint math io namespaces threads calendar ;
|
||||
IN: extra.animations
|
||||
|
||||
SYMBOL: last-loop
|
||||
: reset-progress ( -- ) millis last-loop set ;
|
||||
: progress ( -- progress ) millis last-loop get - reset-progress ;
|
||||
: set-end ( duration -- end-time ) dt>milliseconds millis + ;
|
||||
: loop ( quot end -- ) dup millis > [ [ dup call ] dip loop ] [ 2drop ] if ;
|
||||
: animate ( quot duration -- ) reset-progress set-end loop ;
|
|
@ -0,0 +1 @@
|
|||
Reginald Keith Ford II
|
Loading…
Reference in New Issue