7.9

## Easings

 (require ease) package: jack-ease

This library includes functions and forms for easing values from one state into another gradually.

source code: https://github.com/jackfirth/racket-ease

 procedure(ease-real easing start stop num-steps) → (listof real?) easing : ease/c start : real? stop : real? num-steps : real?
Returns a list of intermediate values between start and stop. The number of values is equal to num-steps plus one, and the difference between successive values is determined by easing.

Example:
 > (ease-real linear-ease 0 100 4) '(0 25 50 75 100)

 value
 value
Contracts for easings. An easing is a function mapping real numbers between one and zero to any real number. ease/c is equivalent to the following contract:

(-> (between/c 0 1) real?)

Easing functions map proportions of the ease finished to proportions of the distance travelled between start and stop. An easing function that returns exactly what was given to it is equivalent to easing linearly, the value of the halfway step returned by ease-real will be halfway between the start and stop values given to ease-real. If the easing function returns numbers smaller than that given to it, then ease-real’s steps will be proportionally smaller.

Examples:
 > (define (quadratic-ease x) (* x x)) > (ease-real quadratic-ease 0 100 4) '(0 25/4 25 225/4 100)

An easing function that returns a number less than zero will cause ease-real to return values less than its starting point during the easing, an easing function that returns a number greater than one will cause ease-real to return values greater than its stopping point. This is useful for "elastic" effects, for example an easing that moves an object just past a stopping position then bounces it back, but most easing functions will satisfy this contract:

(-> (between/c 0 1) (between/c 0 1))

An ease satisfying this more restrictive contract is a proper-ease/c.

 value
The simplest easing. Makes no changes at all to the relationship between step proportion and distance proportion. Equivalent to identity with a more restrictive contract.

Example:
 > (ease-real linear-ease 0 100 4) '(0 25 50 75 100)

procedure

 (ease-real/lens a-lens easing target stop num-steps) → list?
a-lens : (lens/c any/c real?)
easing : ease/c
target : any/c
stop : real?
num-steps : exact-positive-integer?
Similar to ease-real, but instead of returning a list of intermediate values, accepts a lens that specifies a view and a target, and returns a list of intermediate targets each with their view eased.

Examples:
> (require lens)
 > (ease-real/lens first-lens linear-ease '(0 a b) 10 4)

'((0 a b) (5/2 a b) (5 a b) (15/2 a b) (10 a b))

 procedure(ease-invert easing) → ease/c easing : ease/c
Returns an easing that is like easing, but with proportional changes inverted from easing. If easing starts out proportionally further along than linear-ease, then the returned easing will start out proportionally behind linear-ease.

Examples:
 > (define (quadratic-ease x) (* x x)) > (ease-real quadratic-ease 0 100 4) '(0 25/4 25 225/4 100) > (ease-real (ease-invert quadratic-ease) 0 100 4) '(0 175/4 75 375/4 100)

 procedure(ease-reverse easing) → ease/c easing : ease/c
Returns an easing that is like easing, but with its steps reversed.

Examples:
 > (ease-real linear-ease 0 100 4) '(0 25 50 75 100) > (ease-real (ease-reverse linear-ease) 0 100 4) '(100 75 50 25 0)

 procedure(polynomial-ease degree) → proper-ease/c degree : (>/c 0)
Returns an easing function that starts out proportionally slow, then speeds up. The slope of this acceleration is determined by degree. When graphed, the resulting easing is a polynomial curve of the given degree.

Examples:
 > (ease-real (polynomial-ease 1) 0 1000 4) '(0 250 500 750 1000) > (ease-real (polynomial-ease 2) 0 1000 4) '(0 125/2 250 1125/2 1000) > (ease-real (polynomial-ease 3) 0 1000 4) '(0 125/8 125 3375/8 1000)

 procedure degree : (>/c 0)
Like 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.

Examples:
 > (map exact->inexact (ease-real (symmetric-polynomial-ease 1) 0 1000 4)) '(0.0 250.0 500.0 750.0 1000.0) > (map exact->inexact (ease-real (symmetric-polynomial-ease 2) 0 1000 4)) '(0.0 100.0 500.0 900.0 1000.0) > (map exact->inexact (ease-real (symmetric-polynomial-ease 5) 0 1000 4)) '(0.0 4.098360655737705 500.0 995.9016393442623 1000.0)