123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303 |
- namespace Terminal.Gui.TextEffects;
- using System;
- public delegate float EasingFunction (float progressRatio);
- public static class Easing
- {
- public static float Linear (float progressRatio)
- {
- return progressRatio;
- }
- public static float InSine (float progressRatio)
- {
- return 1 - (float)Math.Cos ((progressRatio * Math.PI) / 2);
- }
- public static float OutSine (float progressRatio)
- {
- return (float)Math.Sin ((progressRatio * Math.PI) / 2);
- }
- public static float InOutSine (float progressRatio)
- {
- return -(float)(Math.Cos (Math.PI * progressRatio) - 1) / 2;
- }
- public static float InQuad (float progressRatio)
- {
- return progressRatio * progressRatio;
- }
- public static float OutQuad (float progressRatio)
- {
- return 1 - (1 - progressRatio) * (1 - progressRatio);
- }
- public static float InOutQuad (float progressRatio)
- {
- if (progressRatio < 0.5)
- {
- return 2 * progressRatio * progressRatio;
- }
- else
- {
- return 1 - (float)Math.Pow (-2 * progressRatio + 2, 2) / 2;
- }
- }
- public static float InCubic (float progressRatio)
- {
- return progressRatio * progressRatio * progressRatio;
- }
- public static float OutCubic (float progressRatio)
- {
- return 1 - (float)Math.Pow (1 - progressRatio, 3);
- }
- public static float InOutCubic (float progressRatio)
- {
- if (progressRatio < 0.5)
- {
- return 4 * progressRatio * progressRatio * progressRatio;
- }
- else
- {
- return 1 - (float)Math.Pow (-2 * progressRatio + 2, 3) / 2;
- }
- }
- public static float InQuart (float progressRatio)
- {
- return progressRatio * progressRatio * progressRatio * progressRatio;
- }
- public static float OutQuart (float progressRatio)
- {
- return 1 - (float)Math.Pow (1 - progressRatio, 4);
- }
- public static float InOutQuart (float progressRatio)
- {
- if (progressRatio < 0.5)
- {
- return 8 * progressRatio * progressRatio * progressRatio * progressRatio;
- }
- else
- {
- return 1 - (float)Math.Pow (-2 * progressRatio + 2, 4) / 2;
- }
- }
- public static float InQuint (float progressRatio)
- {
- return progressRatio * progressRatio * progressRatio * progressRatio * progressRatio;
- }
- public static float OutQuint (float progressRatio)
- {
- return 1 - (float)Math.Pow (1 - progressRatio, 5);
- }
- public static float InOutQuint (float progressRatio)
- {
- if (progressRatio < 0.5)
- {
- return 16 * progressRatio * progressRatio * progressRatio * progressRatio * progressRatio;
- }
- else
- {
- return 1 - (float)Math.Pow (-2 * progressRatio + 2, 5) / 2;
- }
- }
- public static float InExpo (float progressRatio)
- {
- if (progressRatio == 0)
- {
- return 0;
- }
- else
- {
- return (float)Math.Pow (2, 10 * progressRatio - 10);
- }
- }
- public static float OutExpo (float progressRatio)
- {
- if (progressRatio == 1)
- {
- return 1;
- }
- else
- {
- return 1 - (float)Math.Pow (2, -10 * progressRatio);
- }
- }
- public static float InOutExpo (float progressRatio)
- {
- if (progressRatio == 0)
- {
- return 0;
- }
- else if (progressRatio == 1)
- {
- return 1;
- }
- else if (progressRatio < 0.5)
- {
- return (float)Math.Pow (2, 20 * progressRatio - 10) / 2;
- }
- else
- {
- return (2 - (float)Math.Pow (2, -20 * progressRatio + 10)) / 2;
- }
- }
- public static float InCirc (float progressRatio)
- {
- return 1 - (float)Math.Sqrt (1 - progressRatio * progressRatio);
- }
- public static float OutCirc (float progressRatio)
- {
- return (float)Math.Sqrt (1 - (progressRatio - 1) * (progressRatio - 1));
- }
- public static float InOutCirc (float progressRatio)
- {
- if (progressRatio < 0.5)
- {
- return (1 - (float)Math.Sqrt (1 - (2 * progressRatio) * (2 * progressRatio))) / 2;
- }
- else
- {
- return ((float)Math.Sqrt (1 - (-2 * progressRatio + 2) * (-2 * progressRatio + 2)) + 1) / 2;
- }
- }
- public static float InBack (float progressRatio)
- {
- const float c1 = 1.70158f;
- const float c3 = c1 + 1;
- return c3 * progressRatio * progressRatio * progressRatio - c1 * progressRatio * progressRatio;
- }
- public static float OutBack (float progressRatio)
- {
- const float c1 = 1.70158f;
- const float c3 = c1 + 1;
- return 1 + c3 * (progressRatio - 1) * (progressRatio - 1) * (progressRatio - 1) + c1 * (progressRatio - 1) * (progressRatio - 1);
- }
- public static float InOutBack (float progressRatio)
- {
- const float c1 = 1.70158f;
- const float c2 = c1 * 1.525f;
- if (progressRatio < 0.5)
- {
- return ((2 * progressRatio) * (2 * progressRatio) * ((c2 + 1) * 2 * progressRatio - c2)) / 2;
- }
- else
- {
- return ((2 * progressRatio - 2) * (2 * progressRatio - 2) * ((c2 + 1) * (progressRatio * 2 - 2) + c2) + 2) / 2;
- }
- }
- public static float InElastic (float progressRatio)
- {
- const float c4 = (2 * (float)Math.PI) / 3;
- if (progressRatio == 0)
- {
- return 0;
- }
- else if (progressRatio == 1)
- {
- return 1;
- }
- else
- {
- return -(float)Math.Pow (2, 10 * progressRatio - 10) * (float)Math.Sin ((progressRatio * 10 - 10.75) * c4);
- }
- }
- public static float OutElastic (float progressRatio)
- {
- const float c4 = (2 * (float)Math.PI) / 3;
- if (progressRatio == 0)
- {
- return 0;
- }
- else if (progressRatio == 1)
- {
- return 1;
- }
- else
- {
- return (float)Math.Pow (2, -10 * progressRatio) * (float)Math.Sin ((progressRatio * 10 - 0.75) * c4) + 1;
- }
- }
- public static float InOutElastic (float progressRatio)
- {
- const float c5 = (2 * (float)Math.PI) / 4.5f;
- if (progressRatio == 0)
- {
- return 0;
- }
- else if (progressRatio == 1)
- {
- return 1;
- }
- else if (progressRatio < 0.5)
- {
- return -(float)Math.Pow (2, 20 * progressRatio - 10) * (float)Math.Sin ((20 * progressRatio - 11.125) * c5) / 2;
- }
- else
- {
- return ((float)Math.Pow (2, -20 * progressRatio + 10) * (float)Math.Sin ((20 * progressRatio - 11.125) * c5)) / 2 + 1;
- }
- }
- public static float InBounce (float progressRatio)
- {
- return 1 - OutBounce (1 - progressRatio);
- }
- public static float OutBounce (float progressRatio)
- {
- const float n1 = 7.5625f;
- const float d1 = 2.75f;
- if (progressRatio < 1 / d1)
- {
- return n1 * progressRatio * progressRatio;
- }
- else if (progressRatio < 2 / d1)
- {
- return n1 * (progressRatio - 1.5f / d1) * (progressRatio - 1.5f / d1) + 0.75f;
- }
- else if (progressRatio < 2.5 / d1)
- {
- return n1 * (progressRatio - 2.25f / d1) * (progressRatio - 2.25f / d1) + 0.9375f;
- }
- else
- {
- return n1 * (progressRatio - 2.625f / d1) * (progressRatio - 2.625f / d1) + 0.984375f;
- }
- }
- public static float InOutBounce (float progressRatio)
- {
- if (progressRatio < 0.5)
- {
- return (1 - OutBounce (1 - 2 * progressRatio)) / 2;
- }
- else
- {
- return (1 + OutBounce (2 * progressRatio - 1)) / 2;
- }
- }
- }
|