Skip to content

Instantly share code, notes, and snippets.

@alexanderson1993
Created August 26, 2019 20:57
Show Gist options
  • Save alexanderson1993/f52352ec512aaca811091d299c5d13d8 to your computer and use it in GitHub Desktop.
Save alexanderson1993/f52352ec512aaca811091d299c5d13d8 to your computer and use it in GitHub Desktop.
// animationValue is a number from 0 to 1, generated by a tweener
// In this case, I'm using a useAnimation hook.
function calculateAnimationValue(animationValue, arcLength, arcStart) {
// Figure out where the animation starts
const animationStart = arcStart / 360;
// If our arc starts after where the animation currently is, return 0
// This renders an invisible arc.
if (animationValue < animationStart) {
return 0;
}
// If the animation value is after the arc's end, show the entire arc.
if (animationValue >= animationStart + arcLength / 360) {
return 1;
}
// Return the tweened value scoped to this arc.
return (animationValue - animationStart) / (arcLength / 360);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment