Last active
March 7, 2018 10:25
-
-
Save pomle/9c917229023c14ce1654f5ca78a8bf93 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function between(subject, options = {}) { | |
const {rigidity, alias} = Object.assign({ | |
rigidity: 10, | |
alias: new Map(), | |
}, options); | |
const keys = Object.keys(subject); | |
let last = Object.assign({}, subject); | |
let intended = subject; | |
function refresh() { | |
for (const key of keys) { | |
last[key] = last[key] + (intended[key] - last[key]) / rigidity; | |
subject[key] = last[key]; | |
} | |
requestAnimationFrame(refresh); | |
} | |
refresh(); | |
return function update(values) { | |
intended = alias.has(values) ? alias.get(values) : values; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment