Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tag: 1.0
Fetching contributors…

Cannot retrieve contributors at this time

202 lines (155 sloc) 9.025 kb
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>README.md</title>
</head>
<body>
<h1>Tween Egg</h1>
<p>Provides a (loose) port of Tween.js for Chicken Scheme. Other Schemes may work, though perhaps with some minor alterations.</p>
<h2>General Functions</h2>
<p><strong>(factorial n)</strong></p>
<p>Memoized implementation of the factorial method. Provides O(n) computation, albeit with an O(1) average case. Requires O(n) memory.</p>
<p>You may reset the memory by whiping out the cache: <code>(set! factorial* (make-vector 1 1))</code></p>
<p><strong>(rationalize count value #!optional (epsilon 0))</strong></p>
<p>Sometimes its useful to truncate the number of decimal places a floating point number is exact to. Sometimes it's also useful to do so after applying an epsilon value to smudge for floating point computation errors. This function can perform both operations.</p>
<p>Note that it is <em>not</em> a function to force a number to a particular number of significant digits.</p>
<p><strong>(tween easing-function direction start stop percent)</strong></p>
<p>Given an <code>easing-function</code> and a <code>direction</code>, this produces a value between <code>start</code> and <code>stop</code> that is representative of the provided <code>percent</code>.</p>
<p><code>direction</code> may be one of the following symbols:
* in
* out
* inout</p>
<p><code>percent</code> must be a value between 0.0 and 1.0.</p>
<p><code>start</code> and <code>stop</code> must be numbers.</p>
<p><code>easing-function</code> be of the form <code>direction -&gt; percent -&gt; percent</code>.</p>
<p><strong>(interpolate selector-function value-vector percent)</strong></p>
<p>Given a <code>selector-function</code> this produces a value within the range of values defined in <code>value-vector</code> that is representative of the provided <code>percent</code>.</p>
<p><code>value-vector</code> must be a vector of numbers.</p>
<p><code>percent</code> must be a value between 0.0 and 1.0.</p>
<p><code>selector-function</code> must be of the form <code>value-vector -&gt; percent -&gt; number</code></p>
<h2>Easing Functions</h2>
<p>The following easing functions are available:</p>
<ul>
<li>linear-ease </li>
<li>quadratic-ease </li>
<li>cubic-ease </li>
<li>quartic-ease </li>
<li>quintic-ease </li>
<li>sinusoidal-ease </li>
<li>exponential-ease </li>
<li>circular-ease </li>
<li>elastic-ease </li>
<li>back-ease </li>
<li>bounce-ease</li>
</ul>
<h2>Interpolation Functions</h2>
<p>The following interpolation functions are available:</p>
<ul>
<li>linear-select</li>
<li>bezier-select</li>
<li>catmullrom-select</li>
</ul>
<h2>Example</h2>
<p>```scheme
(define test-percents '(0.0 0.1 0.2 0.3 0.4 0.5 0.66 0.75 0.95 1.0))</p>
<p>(define (test-ease ease start stop)
(let ((in '())
(out '())
(inout '()))
(map (lambda (p)
(set! in (cons (rationalize 2 (tween ease 'in start stop p)) in))
(set! out (cons (rationalize 2 (tween ease 'out start stop p)) out))
(set! inout (cons (rationalize 2 (tween ease 'inout start stop p)) inout))
)
(reverse test-percents))
`((in . ,in) (out . ,out) (inout . ,inout))))</p>
<p>;; Tests tweens for values between 0 and 10
(map (lambda (e) (display (list e 0 10 (test-ease e 0 10))) (newline))
(list linear-ease quadratic-ease cubic-ease quartic-ease quintic-ease sinusoidal-ease exponential-ease circular-ease elastic-ease back-ease bounce-ease))</p>
<p>;; Tests interpolation for values in the given set
(let ((v '(0 1 2 3 4 5 10 15 20 25 30 35 40 45 50)))
(map (lambda (s) (display (list s v (test-select s (list->vector v)))))
(list linear-select bezier-select catmullrom-select)))</p>
<p>;; Tween test produces:
(#<procedure (tween#linear-ease direction118 percent119)> 0 10
((in 0.0 1.0 2.0 3.0 4.0 5.0 6.6 7.5 9.5 10.0)
(out 0.0 1.0 2.0 3.0 4.0 5.0 6.6 7.5 9.5 10.0)
(inout 0.0 1.0 2.0 3.0 4.0 5.0 6.6 7.5 9.5 10.0)))
(#<procedure (tween#quadratic-ease direction123 percent124)> 0 10
((in 0.0 0.1 0.4 0.89 1.6 2.5 4.35 5.62 9.02 10.0)
(out 0.0 1.89 3.6 5.09 6.4 7.5 8.84 9.37 9.97 10.0)
(inout 0.0 0.05 0.2 0.44 0.8 5.0 7.68 8.75 9.94 10.0)))
(#<procedure (tween#cubic-ease direction138 percent139)> 0 10
((in 0.0 0.01 0.08 0.26 0.64 1.25 2.87 4.21 8.57 10.0)
(out 0.0 2.7 4.87 6.57 7.83 8.75 9.6 9.84 9.99 10.0)
(inout 0.0 0.04 0.32 1.07 2.56 5.0 8.42 9.37 9.99 10.0)))
(#<procedure (tween#quartic-ease direction154 percent155)> 0 10
((in 0.0 0.0 0.01 0.08 0.25 0.62 1.89 3.16 8.14 10.0)
(out 0.0 3.43 5.9 7.59 8.7 9.37 9.86 9.96 9.99 10.0)
(inout 0.0 0.0 0.12 0.64 2.04 5.0 8.93 9.68 9.99 10.0)))
(#<procedure (tween#quintic-ease direction170 percent171)> 0 10
((in 0.0 0.0 0.0 0.02 0.1 0.31 1.25 2.37 7.73 10.0)
(out 0.0 4.09 6.72 8.31 9.22 9.68 9.95 9.99 9.99 10.0)
(inout 0.0 0.0 0.05 0.38 1.63 5.0 9.27 9.84 9.99 10.0)))
(#<procedure (tween#sinusoidal-ease direction186 percent187)> 0 10
((in 0.0 0.12 0.48 1.08 1.9 2.92 4.9 6.17 9.21 9.99)
(out 0.0 1.56 3.09 4.53 5.87 7.07 8.6 9.23 9.96 10.0)
(inout 0.0 0.24 0.95 2.06 3.45 4.99 7.4 8.53 9.93 10.0)))
(#<procedure (tween#exponential-ease direction201 percent202)> 0 10
((in 0 0.01 0.03 0.07 0.15 0.31 0.94 1.76 7.07 10.0)
(out 0.0 5.0 7.5 8.75 9.37 9.68 9.89 9.94 9.98 10)
(inout 0 0.01 0.07 0.31 1.25 5.0 9.45 9.84 9.99 10)))
(#<procedure (tween#circular-ease direction217 percent218)> 0 10
((in 0.0 0.05 0.2 0.46 0.83 1.33 2.48 3.38 6.87 10.0)
(out 0.0 4.35 5.99 7.14 8.0 8.66 9.4 9.68 9.98 10.0)
(inout 0.0 0.1 0.41 0.99 2.0 5.0 8.66 9.33 9.97 10.0)))
(#<procedure (tween#elastic-ease direction236 percent237 . tmp235238)> 0 10
((in 0 0.0 0.03 0 0 0.0 0.55 0 5.0 10)
(out 0 9.99 10 10 9.37 9.99 10 9.96 10 10)
(inout 0 0.01 0 0.31 0 9.0 10 10 10 10)))
(#<procedure (tween#back-ease direction280 percent281 . tmp279282)> 0 10
((in 0.0 0 0 0 0 0 0.35 1.82 7.8 9.99)
(out 0.0 4.08 7.05 9.07 10 10 10 10 10 10.0)
(inout 0.0 0 0 0 0.89 5.0 10 10 10 10.0)))
(#<procedure (tween#bounce-ease direction308 percent309)> 0 10
((in 0.0 0.11 0.6 0.69 2.27 2.34 1.25 5.27 9.81 10.0)
(out 0.0 0.75 3.02 6.8 9.09 7.65 8.49 9.72 9.84 10.0)
(inout 0.0 0.3 1.13 0.45 3.48 5.0 8.87 8.82 9.94 10.0)))</p>
<p>;; Interpolation test produces:
(#<procedure (tween#linear-select v50 p51)>
(0 1 2 3 4 5 10 15 20 25 30 35 40 45 50)
(0.0 1.4 2.8 4.2 8.0 15.0 26.2 32.5 46.49 50.0))
(#<procedure (tween#bezier-select v67 p68)>
(0 1 2 3 4 5 10 15 20 25 30 35 40 45 50)
(0.0 1.4 3.03 5.61 9.8 15.5 26.22 32.5 46.5 50.0))
(#<procedure (tween#catmullrom-select v83 p84)>
(0 1 2 3 4 5 10 15 20 25 30 35 40 45 50)
(0.0 1.72 4.08 4.37 11.4 15.0 26.77 35.0 47.1 50.0))
```</p>
<h2>License</h2>
<pre><code>Copyright 2012 Daniel J. Leslie. All rights reserved.
The contact email address for Daniel J. Leslie is dan@ironoxide.ca
Redistribution and use in source and binary forms, with or without modification, are
permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of
conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list
of conditions and the following disclaimer in the documentation and/or other materials
provided with the distribution.
THIS SOFTWARE IS PROVIDED BY DANIEL J. LESLIE ''AS IS'' AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DANIEL J. LESLIE OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The views and conclusions contained in the software and documentation are those of the
authors and should not be interpreted as representing official policies, either expressed
or implied, of Daniel J. Leslie.
</code></pre>
</body>
</html>
Jump to Line
Something went wrong with that request. Please try again.