This repository has been archived by the owner on May 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.scm
208 lines (150 loc) · 7.84 KB
/
test.scm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
(use tween)
(assert (= 3628800 (factorial 10)))
(assert (= 1.0 (rationalize 4 0.99999998 0.0001)))
;; Linear ease
(assert (= (tween linear-ease 'in 0 10 0) 0))
(assert (= (tween linear-ease 'in 0 10 1) 10))
(assert (= (tween linear-ease 'in 0 10 0.5) 5))
(assert (= (tween linear-ease 'out 0 10 0) 0))
(assert (= (tween linear-ease 'out 0 10 1) 10))
(assert (= (tween linear-ease 'out 0 10 0.5) 5))
(assert (= (tween linear-ease 'inout 0 10 0) 0))
(assert (= (tween linear-ease 'inout 0 10 1) 10))
(assert (= (tween linear-ease 'inout 0 10 0.5) 5))
;; Quadratic ease
(assert (= (tween quadratic-ease 'in 0 10 0) 0))
(assert (= (tween quadratic-ease 'in 0 10 1) 10))
(assert (= (tween quadratic-ease 'in 0 10 0.5) 2.5))
(assert (= (tween quadratic-ease 'out 0 10 0) 0))
(assert (= (tween quadratic-ease 'out 0 10 1) 10))
(assert (= (tween quadratic-ease 'out 0 10 0.5) 7.5))
(assert (= (tween quadratic-ease 'inout 0 10 0) 0))
(assert (= (tween quadratic-ease 'inout 0 10 1) 10))
(assert (= (tween quadratic-ease 'inout 0 10 0.5) 5.0))
;; Cubic ease
(assert (= (tween cubic-ease 'in 0 10 0) 0))
(assert (= (tween cubic-ease 'in 0 10 1) 10))
(assert (= (tween cubic-ease 'in 0 10 0.5) 1.25))
(assert (= (tween cubic-ease 'out 0 10 0) 0))
(assert (= (tween cubic-ease 'out 0 10 1) 10))
(assert (= (tween cubic-ease 'out 0 10 0.5) 8.75))
(assert (= (tween cubic-ease 'inout 0 10 0) 0))
(assert (= (tween cubic-ease 'inout 0 10 1) 10))
(assert (= (tween cubic-ease 'inout 0 10 0.5) 5.0))
;; Quartic ease
(assert (= (tween quartic-ease 'in 0 10 0) 0))
(assert (= (tween quartic-ease 'in 0 10 1) 10))
(assert (= (tween quartic-ease 'in 0 10 0.5) 0.625))
(assert (= (tween quartic-ease 'out 0 10 0) 0))
(assert (= (tween quartic-ease 'out 0 10 1) 10))
(assert (= (tween quartic-ease 'out 0 10 0.5) 9.375))
(assert (= (tween quartic-ease 'inout 0 10 0) 0))
(assert (= (tween quartic-ease 'inout 0 10 1) 10))
(assert (= (tween quartic-ease 'inout 0 10 0.5) 5.0))
;; Quintic ease
(assert (= (tween quintic-ease 'in 0 10 0) 0))
(assert (= (tween quintic-ease 'in 0 10 1) 10))
(assert (= (tween quintic-ease 'in 0 10 0.5) 0.3125))
(assert (= (tween quintic-ease 'out 0 10 0) 0))
(assert (= (tween quintic-ease 'out 0 10 1) 10))
(assert (= (tween quintic-ease 'out 0 10 0.5) 9.6875))
(assert (= (tween quintic-ease 'inout 0 10 0) 0))
(assert (= (tween quintic-ease 'inout 0 10 1) 10))
(assert (= (tween quintic-ease 'inout 0 10 0.5) 5.0))
;; Sinusoidal ease
(assert (= (tween sinusoidal-ease 'in 0 10 0) 0))
(assert (= (rationalize 4 (tween sinusoidal-ease 'in 0 10 1) 0.00001) 10))
(assert (= (rationalize 4 (tween sinusoidal-ease 'in 0 10 0.5) 0.00001) 2.9289))
(assert (= (tween sinusoidal-ease 'out 0 10 0) 0))
(assert (= (rationalize 4 (tween sinusoidal-ease 'out 0 10 1) 0.00001) 10))
(assert (= (rationalize 4 (tween sinusoidal-ease 'out 0 10 0.5) 0.00001) 7.0710))
(assert (= (tween sinusoidal-ease 'inout 0 10 0) 0))
(assert (= (rationalize 4 (tween sinusoidal-ease 'inout 0 10 1) 0.00001) 10))
(assert (= (rationalize 4 (tween sinusoidal-ease 'inout 0 10 0.5) 0.00001) 5.0))
;; Exponential ease
(assert (= (tween exponential-ease 'in 0 10 0) 0))
(assert (= (rationalize 4 (tween exponential-ease 'in 0 10 1) 0.00001) 10))
(assert (= (rationalize 4 (tween exponential-ease 'in 0 10 0.5) 0.00001) 0.3125))
(assert (= (tween exponential-ease 'out 0 10 0) 0))
(assert (= (rationalize 4 (tween exponential-ease 'out 0 10 1) 0.00001) 10))
(assert (= (rationalize 4 (tween exponential-ease 'out 0 10 0.5) 0.00001) 9.6875))
(assert (= (tween exponential-ease 'inout 0 10 0) 0))
(assert (= (rationalize 4 (tween exponential-ease 'inout 0 10 1) 0.00001) 10))
(assert (= (rationalize 4 (tween exponential-ease 'inout 0 10 0.5) 0.00001) 5.0))
;; Circular ease
(assert (= (tween circular-ease 'in 0 10 0) 0))
(assert (= (rationalize 4 (tween circular-ease 'in 0 10 1) 0.00001) 10))
(assert (= (rationalize 4 (tween circular-ease 'in 0 10 0.5) 0.00001) 1.3397))
(assert (= (tween circular-ease 'out 0 10 0) 0))
(assert (= (rationalize 4 (tween circular-ease 'out 0 10 1) 0.00001) 10))
(assert (= (rationalize 4 (tween circular-ease 'out 0 10 0.5) 0.00001) 8.6602))
(assert (= (tween circular-ease 'inout 0 10 0) 0))
(assert (= (rationalize 4 (tween circular-ease 'inout 0 10 1) 0.00001) 10))
(assert (= (rationalize 4 (tween circular-ease 'inout 0 10 0.5) 0.00001) 5.0))
;; Elastic ease
(assert (= (tween elastic-ease 'in 0 10 0) 0))
(assert (= (rationalize 4 (tween elastic-ease 'in 0 10 1) 0.00001) 10))
(assert (= (rationalize 4 (tween elastic-ease 'in 0 10 0.5) 0.00001) 0.0))
(assert (= (tween elastic-ease 'out 0 10 0) 0))
(assert (= (rationalize 4 (tween elastic-ease 'out 0 10 1) 0.00001) 10))
(assert (= (rationalize 4 (tween elastic-ease 'out 0 10 0.5) 0.00001) 10.0))
(assert (= (tween elastic-ease 'inout 0 10 0) 0))
(assert (= (rationalize 4 (tween elastic-ease 'inout 0 10 1) 0.00001) 10))
(assert (= (rationalize 4 (tween elastic-ease 'inout 0 10 0.5) 0.00001) 9.0066))
;; Back ease
(assert (= (tween back-ease 'in 0 10 0) 0))
(assert (= (rationalize 4 (tween back-ease 'in 0 10 1) 0.00001) 10))
(assert (= (rationalize 4 (tween back-ease 'in 0 10 0.5) 0.00001) 0.0))
(assert (= (tween back-ease 'out 0 10 0) 0))
(assert (= (rationalize 4 (tween back-ease 'out 0 10 1) 0.00001) 10))
(assert (= (rationalize 4 (tween back-ease 'out 0 10 0.5) 0.00001) 10.0))
(assert (= (tween back-ease 'inout 0 10 0) 0))
(assert (= (rationalize 4 (tween back-ease 'inout 0 10 1) 0.00001) 10))
(assert (= (rationalize 4 (tween back-ease 'inout 0 10 0.5) 0.00001) 5.0))
;; Bounce ease
(assert (= (tween bounce-ease 'in 0 10 0) 0))
(assert (= (rationalize 4 (tween bounce-ease 'in 0 10 1) 0.00001) 10))
(assert (= (rationalize 4 (tween bounce-ease 'in 0 10 0.5) 0.00001) 2.3437))
(assert (= (tween bounce-ease 'out 0 10 0) 0))
(assert (= (rationalize 4 (tween bounce-ease 'out 0 10 1) 0.00001) 10))
(assert (= (rationalize 4 (tween bounce-ease 'out 0 10 0.5) 0.00001) 7.6562))
(assert (= (tween bounce-ease 'inout 0 10 0) 0))
(assert (= (rationalize 4 (tween bounce-ease 'inout 0 10 1) 0.00001) 10))
(assert (= (rationalize 4 (tween bounce-ease 'inout 0 10 0.5) 0.00001) 5.0))
;; Selectors
(define test-set (list->vector '(0 1 2 3 4 5 6 7 8 9 10)))
;; Linear select
(assert (= (linear-select test-set 0) 0))
(assert (= (linear-select test-set 0.5) 5.0))
(assert (= (linear-select test-set 1) 10.0))
;; Bezier select
(assert (= (bezier-select test-set 0) 0))
(assert (= (bezier-select test-set 0.5) 5.0))
(assert (= (bezier-select test-set 1) 10.0))
;; Catmullrom select
(assert (= (catmullrom-select test-set 0) 0))
(assert (= (catmullrom-select test-set 0.5) 5.0))
(assert (= (catmullrom-select test-set 1) 10.0))
;; Test everything!
(define test-percents '(0.0 0.1 0.2 0.3 0.4 0.5 0.66 0.75 0.95 1.0))
(define test-eases (list linear-ease quadratic-ease cubic-ease quartic-ease quintic-ease sinusoidal-ease exponential-ease circular-ease elastic-ease back-ease bounce-ease))
(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))))
(define (test-select selector values)
(map (lambda (p)
(rationalize 2 (interpolate selector values p)))
test-percents))
(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))
(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)))