Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 202 lines (155 sloc) 9.025 kB
95b60ec @dleslie Updated readmes
authored
1 <?xml version="1.0" encoding="UTF-8" ?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
3 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
4
5 <html xmlns="http://www.w3.org/1999/xhtml">
6
7 <head>
8 <title>README.md</title>
9
10 </head>
11
12 <body>
13
14 <h1>Tween Egg</h1>
15
16 <p>Provides a (loose) port of Tween.js for Chicken Scheme. Other Schemes may work, though perhaps with some minor alterations.</p>
17
18 <h2>General Functions</h2>
19
20 <p><strong>(factorial n)</strong></p>
21
22 <p>Memoized implementation of the factorial method. Provides O(n) computation, albeit with an O(1) average case. Requires O(n) memory.</p>
23
24 <p>You may reset the memory by whiping out the cache: <code>(set! factorial* (make-vector 1 1))</code></p>
25
26 <p><strong>(rationalize count value #!optional (epsilon 0))</strong></p>
27
28 <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>
29
30 <p>Note that it is <em>not</em> a function to force a number to a particular number of significant digits.</p>
31
32 <p><strong>(tween easing-function direction start stop percent)</strong></p>
33
34 <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>
35
36 <p><code>direction</code> may be one of the following symbols:
37 * in
38 * out
39 * inout</p>
40
41 <p><code>percent</code> must be a value between 0.0 and 1.0.</p>
42
43 <p><code>start</code> and <code>stop</code> must be numbers.</p>
44
45 <p><code>easing-function</code> be of the form <code>direction -&gt; percent -&gt; percent</code>.</p>
46
47 <p><strong>(interpolate selector-function value-vector percent)</strong></p>
48
49 <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>
50
51 <p><code>value-vector</code> must be a vector of numbers.</p>
52
53 <p><code>percent</code> must be a value between 0.0 and 1.0.</p>
54
55 <p><code>selector-function</code> must be of the form <code>value-vector -&gt; percent -&gt; number</code></p>
56
57 <h2>Easing Functions</h2>
58
59 <p>The following easing functions are available:</p>
60
61 <ul>
62 <li>linear-ease </li>
63 <li>quadratic-ease </li>
64 <li>cubic-ease </li>
65 <li>quartic-ease </li>
66 <li>quintic-ease </li>
67 <li>sinusoidal-ease </li>
68 <li>exponential-ease </li>
69 <li>circular-ease </li>
70 <li>elastic-ease </li>
71 <li>back-ease </li>
72 <li>bounce-ease</li>
73 </ul>
74
75 <h2>Interpolation Functions</h2>
76
77 <p>The following interpolation functions are available:</p>
78
79 <ul>
80 <li>linear-select</li>
81 <li>bezier-select</li>
82 <li>catmullrom-select</li>
83 </ul>
84
85 <h2>Example</h2>
86
87 <p>```scheme
88 (define test-percents '(0.0 0.1 0.2 0.3 0.4 0.5 0.66 0.75 0.95 1.0))</p>
89
90 <p>(define (test-ease ease start stop)
91 (let ((in '())
92 (out '())
93 (inout '()))
94 (map (lambda (p)
95 (set! in (cons (rationalize 2 (tween ease 'in start stop p)) in))
96 (set! out (cons (rationalize 2 (tween ease 'out start stop p)) out))
97 (set! inout (cons (rationalize 2 (tween ease 'inout start stop p)) inout))
98 )
99 (reverse test-percents))
100 `((in . ,in) (out . ,out) (inout . ,inout))))</p>
101
102 <p>;; Tests tweens for values between 0 and 10
103 (map (lambda (e) (display (list e 0 10 (test-ease e 0 10))) (newline))
104 (list linear-ease quadratic-ease cubic-ease quartic-ease quintic-ease sinusoidal-ease exponential-ease circular-ease elastic-ease back-ease bounce-ease))</p>
105
106 <p>;; Tests interpolation for values in the given set
107 (let ((v '(0 1 2 3 4 5 10 15 20 25 30 35 40 45 50)))
108 (map (lambda (s) (display (list s v (test-select s (list->vector v)))))
109 (list linear-select bezier-select catmullrom-select)))</p>
110
111 <p>;; Tween test produces:
112 (#<procedure (tween#linear-ease direction118 percent119)> 0 10
113 ((in 0.0 1.0 2.0 3.0 4.0 5.0 6.6 7.5 9.5 10.0)
114 (out 0.0 1.0 2.0 3.0 4.0 5.0 6.6 7.5 9.5 10.0)
115 (inout 0.0 1.0 2.0 3.0 4.0 5.0 6.6 7.5 9.5 10.0)))
116 (#<procedure (tween#quadratic-ease direction123 percent124)> 0 10
117 ((in 0.0 0.1 0.4 0.89 1.6 2.5 4.35 5.62 9.02 10.0)
118 (out 0.0 1.89 3.6 5.09 6.4 7.5 8.84 9.37 9.97 10.0)
119 (inout 0.0 0.05 0.2 0.44 0.8 5.0 7.68 8.75 9.94 10.0)))
120 (#<procedure (tween#cubic-ease direction138 percent139)> 0 10
121 ((in 0.0 0.01 0.08 0.26 0.64 1.25 2.87 4.21 8.57 10.0)
122 (out 0.0 2.7 4.87 6.57 7.83 8.75 9.6 9.84 9.99 10.0)
123 (inout 0.0 0.04 0.32 1.07 2.56 5.0 8.42 9.37 9.99 10.0)))
124 (#<procedure (tween#quartic-ease direction154 percent155)> 0 10
125 ((in 0.0 0.0 0.01 0.08 0.25 0.62 1.89 3.16 8.14 10.0)
126 (out 0.0 3.43 5.9 7.59 8.7 9.37 9.86 9.96 9.99 10.0)
127 (inout 0.0 0.0 0.12 0.64 2.04 5.0 8.93 9.68 9.99 10.0)))
128 (#<procedure (tween#quintic-ease direction170 percent171)> 0 10
129 ((in 0.0 0.0 0.0 0.02 0.1 0.31 1.25 2.37 7.73 10.0)
130 (out 0.0 4.09 6.72 8.31 9.22 9.68 9.95 9.99 9.99 10.0)
131 (inout 0.0 0.0 0.05 0.38 1.63 5.0 9.27 9.84 9.99 10.0)))
132 (#<procedure (tween#sinusoidal-ease direction186 percent187)> 0 10
133 ((in 0.0 0.12 0.48 1.08 1.9 2.92 4.9 6.17 9.21 9.99)
134 (out 0.0 1.56 3.09 4.53 5.87 7.07 8.6 9.23 9.96 10.0)
135 (inout 0.0 0.24 0.95 2.06 3.45 4.99 7.4 8.53 9.93 10.0)))
136 (#<procedure (tween#exponential-ease direction201 percent202)> 0 10
137 ((in 0 0.01 0.03 0.07 0.15 0.31 0.94 1.76 7.07 10.0)
138 (out 0.0 5.0 7.5 8.75 9.37 9.68 9.89 9.94 9.98 10)
139 (inout 0 0.01 0.07 0.31 1.25 5.0 9.45 9.84 9.99 10)))
140 (#<procedure (tween#circular-ease direction217 percent218)> 0 10
141 ((in 0.0 0.05 0.2 0.46 0.83 1.33 2.48 3.38 6.87 10.0)
142 (out 0.0 4.35 5.99 7.14 8.0 8.66 9.4 9.68 9.98 10.0)
143 (inout 0.0 0.1 0.41 0.99 2.0 5.0 8.66 9.33 9.97 10.0)))
144 (#<procedure (tween#elastic-ease direction236 percent237 . tmp235238)> 0 10
145 ((in 0 0.0 0.03 0 0 0.0 0.55 0 5.0 10)
146 (out 0 9.99 10 10 9.37 9.99 10 9.96 10 10)
147 (inout 0 0.01 0 0.31 0 9.0 10 10 10 10)))
148 (#<procedure (tween#back-ease direction280 percent281 . tmp279282)> 0 10
149 ((in 0.0 0 0 0 0 0 0.35 1.82 7.8 9.99)
150 (out 0.0 4.08 7.05 9.07 10 10 10 10 10 10.0)
151 (inout 0.0 0 0 0 0.89 5.0 10 10 10 10.0)))
152 (#<procedure (tween#bounce-ease direction308 percent309)> 0 10
153 ((in 0.0 0.11 0.6 0.69 2.27 2.34 1.25 5.27 9.81 10.0)
154 (out 0.0 0.75 3.02 6.8 9.09 7.65 8.49 9.72 9.84 10.0)
155 (inout 0.0 0.3 1.13 0.45 3.48 5.0 8.87 8.82 9.94 10.0)))</p>
156
157 <p>;; Interpolation test produces:
158 (#<procedure (tween#linear-select v50 p51)>
159 (0 1 2 3 4 5 10 15 20 25 30 35 40 45 50)
160 (0.0 1.4 2.8 4.2 8.0 15.0 26.2 32.5 46.49 50.0))
161 (#<procedure (tween#bezier-select v67 p68)>
162 (0 1 2 3 4 5 10 15 20 25 30 35 40 45 50)
163 (0.0 1.4 3.03 5.61 9.8 15.5 26.22 32.5 46.5 50.0))
164 (#<procedure (tween#catmullrom-select v83 p84)>
165 (0 1 2 3 4 5 10 15 20 25 30 35 40 45 50)
166 (0.0 1.72 4.08 4.37 11.4 15.0 26.77 35.0 47.1 50.0))
167 ```</p>
168
169 <h2>License</h2>
170
171 <pre><code>Copyright 2012 Daniel J. Leslie. All rights reserved.
172
173 The contact email address for Daniel J. Leslie is dan@ironoxide.ca
174
175 Redistribution and use in source and binary forms, with or without modification, are
176 permitted provided that the following conditions are met:
177
178 1. Redistributions of source code must retain the above copyright notice, this list of
179 conditions and the following disclaimer.
180
181 2. Redistributions in binary form must reproduce the above copyright notice, this list
182 of conditions and the following disclaimer in the documentation and/or other materials
183 provided with the distribution.
184
185 THIS SOFTWARE IS PROVIDED BY DANIEL J. LESLIE ''AS IS'' AND ANY EXPRESS OR IMPLIED
186 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
187 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DANIEL J. LESLIE OR
188 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
189 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
190 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
191 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
192 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
193 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
194
195 The views and conclusions contained in the software and documentation are those of the
196 authors and should not be interpreted as representing official policies, either expressed
197 or implied, of Daniel J. Leslie.
198 </code></pre>
199
200 </body>
201 </html>
Something went wrong with that request. Please try again.