Last active
May 7, 2025 16:12
-
-
Save paulorenanmelo/6618b2b07e6ab47b0e2193d27025cbb8 to your computer and use it in GitHub Desktop.
Number Extensions
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
public static class NumberExtensions | |
{ | |
public static float Smooth(float amount, float start, float end) | |
{ | |
// Clamp to 0-1; | |
amount = (amount > 1f) ? 1f : amount; | |
amount = (amount < 0f) ? 0f : amount; | |
// Cubicly adjust the amount value. | |
amount = (amount * amount) * (3f - (2f * amount)); | |
return (start + ((end - start) * amount)); | |
} | |
public static float Remap(float val, float in1, float in2, float out1, float out2) | |
{ | |
return out1 + (val - in1) * (out2 - out1) / (in2 - in1); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment