Created
June 14, 2024 19:57
-
-
Save PreyeaRegmi/0f65a1b3a73b82e3af16440be81091fe to your computer and use it in GitHub Desktop.
verticalscroll-gauss-compose
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
fun getFactor(index: Int, draggedIndex: Int): Float { | |
val distance = Math.abs(index - draggedIndex).toFloat() | |
val sigma = 1f // Adjust the sigma for the width of the bell curve | |
val max = .9f | |
// Gaussian function | |
val bellCurve = exp((-distance.pow(2)) / (2 * sigma.pow(2))) | |
// Scale the bell curve to be in the range 0f to 0.8f | |
val scaledValue = bellCurve * max | |
// Ensure the value is within the desired range | |
return if (scaledValue > max) max else scaledValue.toFloat() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment