From 5ddb166caac45e1a89f38a2e7e8bccd55bb935ae Mon Sep 17 00:00:00 2001 From: Rex Ford Date: Sat, 2 Aug 2008 13:57:17 -0400 Subject: [PATCH 1/4] renamed some defs --- extra/math/newtons-method/newtons-method.factor | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/extra/math/newtons-method/newtons-method.factor b/extra/math/newtons-method/newtons-method.factor index b2778a2d85..5bf71deac8 100644 --- a/extra/math/newtons-method/newtons-method.factor +++ b/extra/math/newtons-method/newtons-method.factor @@ -1,4 +1,4 @@ -! Copyright © 2008 Reginald Keith Ford II +! Copyright © 2008 Reginald Keith Ford II ! Newton's Method of approximating roots USING: kernel math math.derivatives ; @@ -6,6 +6,6 @@ IN: math.newtons-method -: newton-method ( guess function -- x ) newton-precision [ [ newton-step ] keep ] times drop ; +: newtons-method ( guess function -- x ) newton-precision [ [ newton-step ] keep ] times drop ; From 0e34b0259ad48aae467a67494ba3c7c1fd94a438 Mon Sep 17 00:00:00 2001 From: Rex Ford Date: Sat, 2 Aug 2008 13:57:59 -0400 Subject: [PATCH 2/4] Now with statistically unbiased approx. --- extra/math/derivatives/derivatives.factor | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/extra/math/derivatives/derivatives.factor b/extra/math/derivatives/derivatives.factor index fef93cabc4..d92066efaf 100644 --- a/extra/math/derivatives/derivatives.factor +++ b/extra/math/derivatives/derivatives.factor @@ -3,7 +3,8 @@ USING: kernel math math.points math.function-tools ; IN: math.derivatives -: small-amount ( -- n ) 1.0e-12 ; -: near ( x -- y ) small-amount + ; -: derivative ( x function -- m ) 2dup [ near ] dip [ eval ] 2bi@ slope ; +: small-amount ( -- n ) 1.0e-14 ; +: some-more ( x -- y ) small-amount + ; +: some-less ( x -- y ) small-amount - ; +: derivative ( x function -- m ) [ [ some-more ] dip eval ] [ [ some-less ] dip eval ] 2bi slope ; : derivative-func ( function -- function ) [ derivative ] curry ; \ No newline at end of file From 2b2a91db0adc08c8465d00f02a4c68a0b5f6821a Mon Sep 17 00:00:00 2001 From: Rex Ford Date: Sat, 2 Aug 2008 14:02:33 -0400 Subject: [PATCH 3/4] erased extra vocabs, added inversed function support --- extra/math/function-tools/function-tools.factor | 3 ++- extra/math/secant-method/secant-method.factor | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/extra/math/function-tools/function-tools.factor b/extra/math/function-tools/function-tools.factor index 042b5f0897..802bf9e14e 100644 --- a/extra/math/function-tools/function-tools.factor +++ b/extra/math/function-tools/function-tools.factor @@ -1,8 +1,9 @@ ! Copyright © 2008 Reginald Keith Ford II ! Tools for quickly comparing, transforming, and evaluating mathematical Factor functions -USING: kernel math arrays ; +USING: kernel math arrays sequences sequences.lib ; IN: math.function-tools : difference-func ( func func -- func ) [ bi - ] 2curry ; : eval ( x func -- pt ) dupd call 2array ; +: eval-inverse ( y func -- pt ) dupd call swap 2array ; : eval3d ( x y func -- pt ) [ 2dup ] dip call 3array ; diff --git a/extra/math/secant-method/secant-method.factor b/extra/math/secant-method/secant-method.factor index 2089dde848..e039b42bbd 100644 --- a/extra/math/secant-method/secant-method.factor +++ b/extra/math/secant-method/secant-method.factor @@ -7,8 +7,8 @@ IN: math.secant-method -: secant-method ( left right function -- x ) secant-precision [ secant-step ] times drop v+ 2 v*n ; +: secant-method ( left right function -- x ) secant-precision [ secant-step ] times drop + 2 / ; ! : close-enough? ( a b -- t/f ) - abs tiny-amount < ; ! : secant-method2 ( left right function -- x ) 2over close-enough? [ drop average ] [ secant-step secant-method ] if ; \ No newline at end of file From 3edf1db4a34f9018d5e9c9e2ceb447c349e696f2 Mon Sep 17 00:00:00 2001 From: Rex Ford Date: Tue, 5 Aug 2008 16:30:47 -0500 Subject: [PATCH 4/4] adding animations lib --- extra/animations/animations-docs.factor | 34 +++++++++++++++++++++++++ extra/animations/animations.factor | 12 +++++++++ extra/animations/authors.txt | 1 + 3 files changed, 47 insertions(+) create mode 100644 extra/animations/animations-docs.factor create mode 100644 extra/animations/animations.factor create mode 100644 extra/animations/authors.txt diff --git a/extra/animations/animations-docs.factor b/extra/animations/animations-docs.factor new file mode 100644 index 0000000000..6a1e89a28e --- /dev/null +++ b/extra/animations/animations-docs.factor @@ -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" \ No newline at end of file diff --git a/extra/animations/animations.factor b/extra/animations/animations.factor new file mode 100644 index 0000000000..7efd618bbf --- /dev/null +++ b/extra/animations/animations.factor @@ -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 ; \ No newline at end of file diff --git a/extra/animations/authors.txt b/extra/animations/authors.txt new file mode 100644 index 0000000000..dac0cb42fe --- /dev/null +++ b/extra/animations/authors.txt @@ -0,0 +1 @@ +Reginald Keith Ford II \ No newline at end of file