Created
July 8, 2023 17:59
-
-
Save Abhimanyu14/88168237661acee2b6ba8fd72211c935 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
suspend fun changeFloatValueOverTime( | |
initialValue: Float, | |
targetValue: Float, | |
durationMillis: Int, | |
onUpdate: (Float) -> Unit, | |
) { | |
val startTime = System.currentTimeMillis() | |
while (System.currentTimeMillis() - startTime < durationMillis) { | |
val elapsedTime = System.currentTimeMillis() - startTime | |
val fraction = elapsedTime.toFloat() / durationMillis | |
val interpolatedValue = lerp(initialValue, targetValue, fraction) | |
onUpdate(interpolatedValue) | |
delay(16) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment