-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,9 +4,11 @@ | |
require | ||
"base.rkt" | ||
"invert.rkt" | ||
"polynomial.rkt" | ||
|
||
|
||
provide | ||
all-from-out | ||
"base.rkt" | ||
"invert.rkt" | ||
"polynomial.rkt" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#lang sweet-exp racket/base | ||
|
||
require racket/contract/base | ||
|
||
provide | ||
contract-out | ||
polynomial-ease (-> (>/c 0) proper-ease/c) | ||
symmetric-polynomial-ease (-> (>/c 0) proper-ease/c) | ||
|
||
require "base.rkt" | ||
|
||
module+ test | ||
require racket/list | ||
rackunit | ||
"invert.rkt" | ||
|
||
|
||
(define ((polynomial-ease degree) x) | ||
(expt x degree)) | ||
|
||
|
||
module+ test | ||
(define (quadratic-ease x) (* x x)) | ||
(check-equal? (ease-real (polynomial-ease 1) 0 100 5) | ||
(ease-real linear-ease 0 100 5)) | ||
(check-equal? (ease-real (polynomial-ease 2) 0 100 5) | ||
(ease-real quadratic-ease 0 100 5)) | ||
|
||
|
||
(define ((symmetric-polynomial-ease degree) x) | ||
(define x^d (expt x degree)) | ||
(/ x^d (+ x^d (expt (- 1 x) degree)))) | ||
|
||
module+ test | ||
(check-equal? (ease-real (symmetric-polynomial-ease 1) 0 100 5) | ||
(ease-real (ease-invert (symmetric-polynomial-ease 1)) 0 100 5)) | ||
(check-true (< (second (ease-real (symmetric-polynomial-ease 2) 0 100 5)) | ||
(second (ease-real (symmetric-polynomial-ease 1) 0 100 5)))) | ||
(check-true (> (fourth (ease-real (symmetric-polynomial-ease 2) 0 100 5)) | ||
(fourth (ease-real (symmetric-polynomial-ease 1) 0 100 5)))) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#lang scribble/manual | ||
|
||
@(require "util/doc.rkt") | ||
|
||
|
||
@defproc[(polynomial-ease [degree (>/c 0)]) proper-ease/c]{ | ||
Returns an easing function that starts out proportionally slow, | ||
then speeds up. The slope of this acceleration is determined by | ||
@racket[degree]. When graphed, the resulting easing is a polynomial | ||
curve of the given degree. | ||
@ease-examples[ | ||
(ease-real (polynomial-ease 1) 0 1000 5) | ||
(ease-real (polynomial-ease 2) 0 1000 5) | ||
(ease-real (polynomial-ease 3) 0 1000 5) | ||
]} | ||
|
||
@defproc[(symmetric-polynomial-ease [degree (>/c 0)]) proper-ease/c]{ | ||
Like @racket[polynomial-ease], but the returned easing is symmetric. | ||
It starts out slow, speeds up towards the middle, then slows down | ||
as it approaches the end. | ||
@ease-examples[ | ||
(map exact->inexact (ease-real (symmetric-polynomial-ease 1) 0 1000 4)) | ||
(map exact->inexact (ease-real (symmetric-polynomial-ease 2) 0 1000 4)) | ||
(map exact->inexact (ease-real (symmetric-polynomial-ease 5) 0 1000 4)) | ||
]} |