• C#实现的曲线方法


    在这里插入图片描述
    类:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace YEngine
    {
    	public class CurveUtils
    	{
    		public static float EaseInOutBounce(float t)
    		{
    			if (t < 0.5f)
    				return 0.5f * EaseInBounce(t * 2.0f);
    			else
    				return 0.5f * EaseOutBounce(t * 2.0f - 1.0f) + 0.5f;
    		}
    
    		public static float EaseInBounce(float t)
    		{
    			return 1.0f - EaseOutBounce(1.0f - t);
    		}
    
    		public static float EaseOutBounce(float t)
    		{
    			const float n1 = 7.5625f;
    			const float d1 = 2.75f;
    
    			if (t < 1.0f / d1)
    			{
    				return n1 * t * t;
    			}
    			else if (t < 2.0f / d1)
    			{
    				return n1 * (t -= 1.5f / d1) * t + 0.75f;
    			}
    			else if (t < 2.5f / d1)
    			{
    				return n1 * (t -= 2.25f / d1) * t + 0.9375f;
    			}
    			else
    			{
    				return n1 * (t -= 2.625f / d1) * t + 0.984375f;
    			}
    		}
    		public static float EaseInElastic(float t)
    		{
    			const float c4 = (2 * (float)Math.PI) / 3.0f;
    
    			if (t == 0)
    				return 0;
    			if (t == 1)
    				return 1;
    
    			return -(float)Math.Pow(2, 10 * t - 10) * (float)Math.Sin((t * 10 - 10.75) * c4);
    		}
    
    		public static float EaseOutElastic(float t)
    		{
    			const float c4 = (2 * (float)Math.PI) / 3.0f;
    
    			if (t == 0)
    				return 0;
    			if (t == 1)
    				return 1;
    
    			return (float)Math.Pow(2, -10 * t) * (float)Math.Sin((t * 10 - 0.75) * c4) + 1;
    		}
    
    		public static float EaseInOutElastic(float t)
    		{
    			const float c5 = (2 * (float)Math.PI) / 4.5f;
    
    			if (t == 0)
    				return 0;
    			if (t == 1)
    				return 1;
    
    			if (t < 0.5)
    				return -(float)(0.5 * Math.Pow(2, 20 * t - 10) * Math.Sin((20 * t - 11.125) * c5));
    			else
    				return (float)(0.5 * Math.Pow(2, -20 * t + 10) * Math.Sin((20 * t - 11.125) * c5)) + 1;
    		}
    		public static float EaseInBack(float t)
    		{
    			const float c1 = 1.70158f;
    			const float c3 = c1 + 1;
    
    			return c3 * t * t * t - c1 * t * t;
    		}
    
    		public static float EaseOutBack(float t)
    		{
    			const float c1 = 1.70158f;
    			const float c3 = c1 + 1;
    
    			return 1 + c3 * (float)Math.Pow(t - 1, 3) + c1 * (float)Math.Pow(t - 1, 2);
    		}
    
    		public static float EaseInOutBack(float t)
    		{
    			const float c1 = 1.70158f;
    			const float c2 = c1 * 1.525f;
    
    			if (t < 0.5)
    				return 0.5f * ((2 * t) * (2 * t) * ((c2 + 1) * 2 * t - c2));
    			else
    				return 0.5f * ((2 * t - 2) * (2 * t - 2) * ((c2 + 1) * (t * 2 - 2) + c2) + 2);
    		}
    
    		public static float EaseInCirc(float t)
    		{
    			return 1 - (float)Math.Sqrt(1 - t * t);
    		}
    
    		public static float EaseOutCirc(float t)
    		{
    			return (float)Math.Sqrt(1 - (t - 1) * (t - 1));
    		}
    
    		public static float EaseInOutCirc(float t)
    		{
    			if (t < 0.5)
    				return 0.5f * (1 - (float)Math.Sqrt(1 - 4 * t * t));
    			else
    				return 0.5f * ((float)Math.Sqrt(-((2 * t - 3) * (2 * t - 1))) + 1);
    		}
    
    		public static float EaseInExpo(float t)
    		{
    			return (float)Math.Pow(2, 10 * (t - 1));
    		}
    
    		public static float EaseOutExpo(float t)
    		{
    			return -(float)Math.Pow(2, -10 * t) + 1;
    		}
    
    		public static float EaseInOutExpo(float t)
    		{
    			if (t == 0)
    				return 0;
    			if (t == 1)
    				return 1;
    
    			if (t < 0.5)
    				return 0.5f * (float)Math.Pow(2, 20 * t - 10);
    			else
    				return -0.5f * (float)Math.Pow(2, -20 * t + 10) + 1;
    		}
    
    		public static float EaseInQuint(float t)
    		{
    			return t * t * t * t * t;
    		}
    
    		public static float EaseOutQuint(float t)
    		{
    			return 1 + (float)Math.Pow(t - 1, 5);
    		}
    
    		public static float EaseInOutQuint(float t)
    		{
    			if (t < 0.5)
    				return 16 * t * t * t * t * t;
    			else
    				return 1 + 16 * (float)Math.Pow(t - 1, 5);
    		}
    
    		public static float EaseInQuart(float t)
    		{
    			return t * t * t * t;
    		}
    
    		public static float EaseOutQuart(float t)
    		{
    			return 1 - (float)Math.Pow(t - 1, 4);
    		}
    
    		public static float EaseInOutQuart(float t)
    		{
    			if (t < 0.5)
    				return 8 * t * t * t * t;
    			else
    				return 1 - 8 * (float)Math.Pow(t - 1, 4);
    		}
    
    		public static float EaseInCubic(float t)
    		{
    			return t * t * t;
    		}
    
    		public static float EaseOutCubic(float t)
    		{
    			return (float)Math.Pow(t - 1, 3) + 1;
    		}
    
    		public static float EaseInOutCubic(float t)
    		{
    			if (t < 0.5)
    				return 4 * t * t * t;
    			else
    				return 1 + 4 * (float)Math.Pow(t - 1, 3);
    		}
    
    		public static float EaseInQuad(float t)
    		{
    			return t * t;
    		}
    
    		public static float EaseOutQuad(float t)
    		{
    			return 1 - (1 - t) * (1 - t);
    		}
    
    		public static float EaseInOutQuad(float t)
    		{
    			if (t < 0.5)
    				return 2 * t * t;
    			else
    				return 1 - (float)Math.Pow(-2 * t + 2, 2) / 2;
    		}
    
    		public static float EaseInSine(float t)
    		{
    			return 1 - (float)Math.Cos(t * (Math.PI / 2));
    		}
    
    		public static float EaseOutSine(float t)
    		{
    			return (float)Math.Sin(t * (Math.PI / 2));
    		}
    
    		public static float EaseInOutSine(float t)
    		{
    			return -0.5f * ((float)Math.Cos(Math.PI * t) - 1);
    		}
    
    		public static float EaseLinear(float t)
    		{
    			return t;
    		}
    	}
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163
    • 164
    • 165
    • 166
    • 167
    • 168
    • 169
    • 170
    • 171
    • 172
    • 173
    • 174
    • 175
    • 176
    • 177
    • 178
    • 179
    • 180
    • 181
    • 182
    • 183
    • 184
    • 185
    • 186
    • 187
    • 188
    • 189
    • 190
    • 191
    • 192
    • 193
    • 194
    • 195
    • 196
    • 197
    • 198
    • 199
    • 200
    • 201
    • 202
    • 203
    • 204
    • 205
    • 206
    • 207
    • 208
    • 209
    • 210
    • 211
    • 212
    • 213
    • 214
    • 215
    • 216
    • 217
    • 218
    • 219
    • 220
    • 221
    • 222
    • 223
    • 224
    • 225
    • 226
    • 227
    • 228
    • 229
    • 230
    • 231
    • 232
    • 233
    • 234
    • 235
    • 236
    • 237
    • 238
    • 239
    • 240
    • 241
    • 242
    • 243
    • 244
    • 245
  • 相关阅读:
    Mysql视图特性&&用户管理
    Modbus协议详解2:通信方式、地址规则、主从机通信状态
    PowerShell禁止运行脚本
    相机图像质量研究(32)常见问题总结:图像处理对成像的影响--振铃效应
    C盘满了,应该清理哪些地方
    Cpolar - 本地 WebUI 账号登录失败解决方案
    SSM - Springboot - MyBatis-Plus 全栈体系(二十一)
    大数据flink篇之二-基础实例wordcount
    医疗服务全面升级,这个方法绝了!
    (CI/CD)docker中安装GitLab
  • 原文地址:https://blog.csdn.net/u010778229/article/details/136349155