popmotion
Version:
The animator's toolbox
20 lines (17 loc) • 619 B
JavaScript
import { smoothFrame } from './smooth-frame.mjs';
import { getFrameData } from 'framesync';
const smooth = (strength = 50) => {
let previousValue = 0;
let lastUpdated = 0;
return (v) => {
const currentFramestamp = getFrameData().timestamp;
const timeDelta = currentFramestamp !== lastUpdated ? currentFramestamp - lastUpdated : 0;
const newValue = timeDelta
? smoothFrame(previousValue, v, timeDelta, strength)
: previousValue;
lastUpdated = currentFramestamp;
previousValue = newValue;
return newValue;
};
};
export { smooth };