Takes an existing stream/subscription src and attaches new subscription which interpolates between incoming values from src using the given mix function.
remarks
The returned construct produces values at a rate controlled by the clock stream or frequency. If omitted, clock defaults to fromRAF (~60Hz). If the clock is given as number, creates a fromInterval or else uses the given clock stream directly. In general, the frequency of the clock should always be higher than that of src or else interpolation will have undefined behavior.
If stop is given as well, no values will be passed downstream if that function returns true. This can be used to limit traffic once the tween target value has been reached.
The returned subscription closes automatically when either src or clock are exhausted.
example
val = stream();
tween(
// consume from `val` stream
val,
// initial start value to interpolate from0,
// interpolation fn (LERP)(a, b) => a + (b - a) * 0.5,
// stop emitting values if difference to previous result < 0.01(a, b) =>Math.abs(a - b) < 0.01
).subscribe(trace("tweened"))
a.next(10)
// 5// 7.5// ...// 9.98046875
a.next(100)
// 55// 77.5// ...// 99.989013671875
Takes an existing stream/subscription
src
and attaches new subscription which interpolates between incoming values fromsrc
using the givenmix
function.The returned construct produces values at a rate controlled by the
clock
stream or frequency. If omitted,clock
defaults to fromRAF (~60Hz). If theclock
is given as number, creates a fromInterval or else uses the givenclock
stream directly. In general, the frequency of theclock
should always be higher than that ofsrc
or else interpolation will have undefined behavior.If
stop
is given as well, no values will be passed downstream if that function returns true. This can be used to limit traffic once the tween target value has been reached.The returned subscription closes automatically when either
src
orclock
are exhausted.val = stream(); tween( // consume from `val` stream val, // initial start value to interpolate from 0, // interpolation fn (LERP) (a, b) => a + (b - a) * 0.5, // stop emitting values if difference to previous result < 0.01 (a, b) => Math.abs(a - b) < 0.01 ).subscribe(trace("tweened")) a.next(10) // 5 // 7.5 // ... // 9.98046875 a.next(100) // 55 // 77.5 // ... // 99.989013671875