Created
August 26, 2019 20:57
-
-
Save alexanderson1993/f52352ec512aaca811091d299c5d13d8 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
// 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