Skip to content

Instantly share code, notes, and snippets.

@tkh44
Last active March 8, 2017 17:54
Show Gist options
  • Save tkh44/a3d4446841fe75530a3c7612d5a5d2b2 to your computer and use it in GitHub Desktop.
Save tkh44/a3d4446841fe75530a3c7612d5a5d2b2 to your computer and use it in GitHub Desktop.
Found this on a react-motion issue. It will create a spring values based on duration for react-motion's spring.
// tl;dr ...set the duration of a spring animation
export const configw = (sec, overdamping) => {
const s = overdamping <= 0
? 1 - overdamping
: 1 / Math.sqrt(1 + Math.pow(2 * Math.PI / Math.log(1 / (overdamping * overdamping)), 2))
const ks = (2 * Math.PI / sec) / Math.max(Math.sqrt(1 - s * s), 0.5)
const c = 2 * ks * s
return [ks * ks, c]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment