Optional
l?: numberThe initial starting position.
See criticallyDamped.
The initial target position. Can be updated when calling next().
Optional
precision?: numberSee criticallyDamped.
An iterator whose next
method accepts an optional new lTarget
.
The iterator yields an object containing successive values for:
l
)v
)t
)If you never need to update the target you can use a for await loop:
const iterator = newCriticallyDampedAnimationIterator({
l: 10,
lTarget: 100,
lag: 1500
});
for await (const { l, v, t } of iterator) {
console.log({ l, v, t });
}
If you do need to update the target, then call next
explicitly:
const iterator = newCriticallyDampedAnimationIterator({
l: 10,
lTarget: 100,
lag: 1500
});
let { value: { l, v, t } } = await iterator.next();
({ value: { l, v, t } } = await iterator.next()); // updated
({ value: { l, v, t } } = await iterator.next(200)); // updated towards a new target
Returns an animation iterator based on criticallyDamped that starts at the given position
l
, with velocityv = 0
and timet = 0
and yields the new position and velocity, and total time at every animation frame.