C#实现的曲线方法

类:

csharp 复制代码
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;
		}
	}
}
相关推荐
辞旧 lekkk1 小时前
【Qt】信号和槽
linux·开发语言·数据库·qt·学习·mysql·萌新
zc.z1 小时前
JAVA实现:纯PCM格式音频转换成BASE64
java·音视频·pcm
mask哥2 小时前
力扣算法java实现汇总整理(上)
java·算法·leetcode
2zcode2 小时前
运动模糊图像复原的MATLAB仿真与优化
开发语言·matlab
袁雅倩19972 小时前
当吸尘器、筋膜枪都用上Type-C,供电方案该怎么选?浅谈PD取电芯片ECP5702的应用
c语言·开发语言·支持向量机·动态规划·推荐算法·最小二乘法·图搜索算法
如果'\'真能转义说3 小时前
OOXML 文档格式剖析:哈希、ZIP结构与识别
xml·算法·c#·哈希算法
我是唐青枫3 小时前
终于不用手搓两级缓存了!C#.NET HybridCache 详解:L1 L2、标签失效与防击穿实战
redis·缓存·c#·.net
Aaswk3 小时前
Java Lambda 表达式与流处理
java·开发语言·python
是宇写的啊3 小时前
Spring AOP
java·spring
万邦科技Lafite3 小时前
京东item_get接口实战案例:实时商品价格监控全流程解析
java·开发语言·数据库·python·开放api·淘宝开放平台