// Go back and forth between 0 and 1 by 0.1 letpp = percentPingPong(0.1); continuously(() => { // Get position in ping-pong constamt = pp.next().value; // interpolate between Math.PI and Math.PI*2 constv = interpolate(amt, Math.PI, Math.PI*2); // do something with v... }).start();
If two parameters are given, it instead returns a function which interpolates:
consti = interpolate(100, 200); i(0.5); // 150
// Compared to: interpolate(0.5, 100, 200); // 150
This is useful if you want to reuse the interpolator with fixed a and b values.
Usually interpolation amount is on a 0...1 scale, inclusive. What is the interpolation result
if this scale is exceeded? By default it is clamped to 0..1, so the return value is always between a and b (inclusive).
Alternatively, set the limits option to process amount:
'wrap': wrap amount, eg 1.5 is the same as 0.5, 2 is the same as 1
'ignore': allow exceeding values. eg 1.5 will yield b*1.5.
'clamp': default behaviour of clamping interpolation amount to 0..1
Interpolation can be non-linear using 'easing' option or 'transform' funciton.
Interpolates between
a
andb
byamount
. Akalerp
.ixfx Guide on Interpolation
Example: Get the halfway point between 30 and 60
Interpolation is often used for animation. In that case,
amount
would start at 0 and you would keep interpolating up to1
Example
See also interpolatorStepped and interpolatorInterval for functions which help to manage progression from A->B over steps or interval.
If two parameters are given, it instead returns a function which interpolates:
This is useful if you want to reuse the interpolator with fixed
a
andb
values.Usually interpolation amount is on a 0...1 scale, inclusive. What is the interpolation result if this scale is exceeded? By default it is clamped to 0..1, so the return value is always between
a
andb
(inclusive).Alternatively, set the
limits
option to processamount
:Interpolation can be non-linear using 'easing' option or 'transform' funciton.
To interpolate certain types: Visual.Colour.interpolator, Points.interpolate.