Created
June 13, 2018 02:45
-
-
Save EsProgram/50886ee90275816eed6bc84906c3312e to your computer and use it in GitHub Desktop.
Easing
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
//=================================================================================================/ | |
/// <summary> | |
/// Easing関数 | |
/// https://easings.net/ja | |
/// https://gist.github.com/gre/1650294 | |
/// </summary> | |
//=================================================================================================/ | |
public static class Easing | |
{ | |
//=================================================================================================/ | |
/// <summary> | |
/// t -> t | |
/// </summary> | |
/// <param name="t">[0, 1]をとる値</param> | |
/// <returns>変換後の値[0, 1]</returns> | |
//=================================================================================================/ | |
public static float Linear(float t) | |
{ | |
return t; | |
} | |
//=================================================================================================/ | |
/// <summary> | |
/// t -> t^2 | |
/// </summary> | |
/// <param name="t">[0, 1]をとる値</param> | |
/// <returns>変換後の値[0, 1]</returns> | |
//=================================================================================================/ | |
public static float EaseInQuad(float t) | |
{ | |
return t * t; | |
} | |
//=================================================================================================/ | |
/// <summary> | |
/// t -> (2 - t)t | |
/// </summary> | |
/// <param name="t">[0, 1]をとる値</param> | |
/// <returns>変換後の値[0, 1]</returns> | |
//=================================================================================================/ | |
public static float EaseOutQuad(float t) | |
{ | |
return t * (2f - t); | |
} | |
//=================================================================================================/ | |
/// <summary> | |
/// t -> 2t^2 | t < 0.5 | |
/// t -> -1 + 4t - 2t^2 | 0.5 <= t | |
/// </summary> | |
/// <param name="t">[0, 1]をとる値</param> | |
/// <returns>変換後の値[0, 1]</returns> | |
//=================================================================================================/ | |
public static float EaseInOutQuad(float t) | |
{ | |
return t < 0.5f ? 2f * t * t : -1f + (4f - 2f * t) * t; | |
} | |
//=================================================================================================/ | |
/// <summary> | |
/// t -> t^3 | |
/// </summary> | |
/// <param name="t">[0, 1]をとる値</param> | |
/// <returns>変換後の値[0, 1]</returns> | |
//=================================================================================================/ | |
public static float EaseInCubic(float t) | |
{ | |
return t * t * t; | |
} | |
//=================================================================================================/ | |
/// <summary> | |
/// t -> (t - 1)^3 + 1 | |
/// </summary> | |
/// <param name="t">[0, 1]をとる値</param> | |
/// <returns>変換後の値[0, 1]</returns> | |
//=================================================================================================/ | |
public static float EaseOutCubic(float t) | |
{ | |
return (--t) * t * t + 1f; | |
} | |
//=================================================================================================/ | |
/// <summary> | |
/// t -> 4t^3 | t < 0.5 | |
/// t -> (t - 1)(2t - 2)^2 + 1 | 0.5 <= t | |
/// </summary> | |
/// <param name="t">[0, 1]をとる値</param> | |
/// <returns>変換後の値[0, 1]</returns> | |
//=================================================================================================/ | |
public static float EaseInOutCubic(float t) | |
{ | |
return t < 0.5f ? 4f * t * t * t : (t - 1f) * (2f * t - 2f) * (2f * t - 2f) + 1f; | |
} | |
//=================================================================================================/ | |
/// <summary> | |
/// t -> t^4 | |
/// </summary> | |
/// <param name="t">[0, 1]をとる値</param> | |
/// <returns>変換後の値[0, 1]</returns> | |
//=================================================================================================/ | |
public static float EaseInQuart(float t) | |
{ | |
return t * t * t * t; | |
} | |
//=================================================================================================/ | |
/// <summary> | |
/// t -> 1 - (t - 1)^4 | |
/// </summary> | |
/// <param name="t">[0, 1]をとる値</param> | |
/// <returns>変換後の値[0, 1]</returns> | |
//=================================================================================================/ | |
public static float EaseOutQuart(float t) | |
{ | |
return 1f - (--t) * t * t * t; | |
} | |
//=================================================================================================/ | |
/// <summary> | |
/// t -> 8t^4 | t < 0.5 | |
/// t -> 1 - 8(t - 1)^4 | 0.5 <= t | |
/// </summary> | |
/// <param name="t">[0, 1]をとる値</param> | |
/// <returns>変換後の値[0, 1]</returns> | |
//=================================================================================================/ | |
public static float EaseInOutQuart(float t) | |
{ | |
return t < 0.5f ? 8f * t * t * t * t : 1f - 8f * (--t) * t * t * t; | |
} | |
//=================================================================================================/ | |
/// <summary> | |
/// t -> t^5 | |
/// </summary> | |
/// <param name="t">[0, 1]をとる値</param> | |
/// <returns>変換後の値[0, 1]</returns> | |
//=================================================================================================/ | |
public static float EaseInQuint(float t) | |
{ | |
return t * t * t * t * t; | |
} | |
//=================================================================================================/ | |
/// <summary> | |
/// t -> 1 + (t - 1)^5 | |
/// </summary> | |
/// <param name="t">[0, 1]をとる値</param> | |
/// <returns>変換後の値[0, 1]</returns> | |
//=================================================================================================/ | |
public static float EaseOutQuint(float t) | |
{ | |
return 1f + (--t) * t * t * t * t; | |
} | |
//=================================================================================================/ | |
/// <summary> | |
/// t -> 16t^5 | t < 0.5 | |
/// t -> 1 + 16(t - 1)^5 | |
/// </summary> | |
/// <param name="t">[0, 1]をとる値</param> | |
/// <returns>変換後の値[0, 1]</returns> | |
//=================================================================================================/ | |
public static float EaseInOutQuint(float t) | |
{ | |
return t < 0.5f ? 16f * t * t * t * t * t : 1f + 16f * (--t) * t * t * t * t; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment