博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
android-各种动画加速器,各种插值器
阅读量:4291 次
发布时间:2019-05-27

本文共 7773 字,大约阅读时间需要 25 分钟。

import android.view.animation.Interpolator;public class BackInterpolator implements Interpolator {	private int type;	private float overshot;	public BackInterpolator(int type, float overshot) {		this.type = type;		this.overshot = overshot;	}	public float getInterpolation(float t) {		if (type == EasingType.IN) {			return in(t, overshot);		} else		if (type == EasingType.OUT) {			return out(t, overshot);		} else		if (type == EasingType.INOUT) {			return inout(t, overshot);		}		return 0;	}	private float in(float t, float o) {		if (o == 0) {			o = 1.70158f;		}		return t*t*((o+1)*t - o);	}	private float out(float t, float o) {		if (o == 0) {			o = 1.70158f;		}		return ((t-=1)*t*((o+1)*t + o) + 1);	}		private float inout(float t, float o) {		if (o == 0) {			o = 1.70158f;		}		t *= 2;		if (t < 1) {			return 0.5f*(t*t*(((o*=(1.525))+1)*t - o));		} else {			return 0.5f*((t-=2)*t*(((o*=(1.525))+1)*t + o) + 2);		}	}}

public class BounceInterpolator implements Interpolator {	private int type;	public BounceInterpolator(int type) {		this.type = type;	}	public float getInterpolation(float t) {		if (type == EasingType.IN) {			return in(t);		} else		if (type == EasingType.OUT) {			return out(t);		} else		if (type == EasingType.INOUT) {			return inout(t);		}		return 0;	}	private float out(float t) {		if (t < (1/2.75)) {			return 7.5625f*t*t;		} else		if (t < 2/2.75) {			return 7.5625f*(t-=(1.5/2.75))*t + .75f;		} else		if (t < 2.5/2.75) {			return 7.5625f*(t-=(2.25/2.75))*t + .9375f;		} else {			return 7.5625f*(t-=(2.625/2.75))*t + .984375f;		}	}	private float in(float t) {		return 1 - out(1-t);	}	private float inout(float t) {		if (t < 0.5f) {			return in(t*2) * .5f;		} else {			return out(t*2-1) * .5f + .5f;		}	}}

public class CircInterpolator implements Interpolator {	private int type;	public CircInterpolator(int type) {		this.type = type;	}	public float getInterpolation(float t) {		if (type == EasingType.IN) {			return in(t);		} else		if (type == EasingType.OUT) {			return out(t);		} else		if (type == EasingType.INOUT) {			return inout(t);		}		return 0;	}	private float in(float t) {		return (float) -(Math.sqrt(1 - t*t) - 1);	}	private float out(float t) {		return (float) Math.sqrt(1 - (t-=1)*t);	}	private float inout(float t) {		t *= 2;		if (t < 1) {			return (float) (-0.5f * (Math.sqrt(1 - t*t) - 1));		} else {			return (float) (0.5f * (Math.sqrt(1 - (t-=2)*t) + 1));		}	}}

public class CubicInterpolator implements Interpolator {	private int type;	public CubicInterpolator(int type) {		this.type = type;	}	public float getInterpolation(float t) {		if (type == EasingType.IN) {			return in(t);		} else		if (type == EasingType.OUT) {			return out(t);		} else		if (type == EasingType.INOUT) {			return inout(t);		}		return 0;	}	private float in(float t) {		return t*t*t;	}	private float out(float t) {		return (t-=1)*t*t + 1;	}	private float inout(float t) {		t *= 2;		if (t < 1) {			return 0.5f*t*t*t;		} else {			return 0.5f*((t-=2)*t*t + 2);		}	}}

public class ElasticInterpolator implements Interpolator {	private int type;	private float amplitude;	private float period;	public ElasticInterpolator(int type, float amplitude, float period) {		this.type = type;		this.amplitude = amplitude;		this.period = period;	}	public float getInterpolation(float t) {		if (type == EasingType.IN) {			return in(t, amplitude, period);		} else		if (type == EasingType.OUT) {			return out(t, amplitude, period);		} else		if (type == EasingType.INOUT) {			return inout(t, amplitude, period);		}		return 0;	}	private float in(float t, float a, float p) {		if (t == 0) {			return 0;		}		if (t >= 1) {			return 1;		}		if (p == 0) {			p = 0.3f;		}		float s;		if (a == 0 || a < 1) {			a = 1;			s = p / 4;		}		else {			s = (float) (p/(2*Math.PI) * Math.asin(1/a));		}		return (float) (-(a*Math.pow(2,10*(t-=1)) * Math.sin((t-s)*(2*Math.PI)/p)));	}	private float out(float t, float a, float p) {		if (t == 0) {			return 0;		}		if (t >= 1) {			return 1;		}		if (p == 0) {			p = 0.3f;		}		float s;		if (a == 0 || a < 1) {			a = 1;			s = p / 4;		}		else {			s = (float) (p/(2*Math.PI) * Math.asin(1/a));		}		return (float) (a*Math.pow(2,-10*t) * Math.sin((t-s)*(2*Math.PI)/p) + 1);	}		private float inout(float t, float a, float p) {		if (t == 0) {			return 0;		}		if (t >= 1) {			return 1;		}		if (p == 0) {			p = .3f*1.5f;		}		float s;		if (a == 0 || a < 1) {			a = 1;			s = p / 4;		}		else {			s = (float) (p/(2*Math.PI) * Math.asin(1/a));		}		t *= 2;		if (t < 1) {			return (float) (-.5*(a*Math.pow(2,10*(t-=1)) * Math.sin((t-s)*(2*Math.PI)/p)));		} else {			return (float) (a*Math.pow(2,-10*(t-=1)) * Math.sin((t-s)*(2*Math.PI)/p)*.5 + 1);		}	}}

public class ExpoInterpolator implements Interpolator {			private int type;			public ExpoInterpolator(int type) {				this.type = type;			}			public float getInterpolation(float t) {				if (type == EasingType.IN) {			return in(t);		} else		if (type == EasingType.OUT) {			return out(t);		} else		if (type == EasingType.INOUT) {			return inout(t);		}		return 0;	}	private float in(float t) {		return (float) ((t==0) ? 0 : Math.pow(2, 10 * (t - 1)));	}	private float out(float t) {		return (float) ((t>=1) ? 1 : (-Math.pow(2, -10 * t) + 1));	}	private float inout(float t) {		if (t == 0) {			return 0;		}		if (t >= 1) {			return 1;		}		t *= 2;		if (t < 1) {			return (float) (0.5f * Math.pow(2, 10 * (t - 1)));		} else {			return (float) (0.5f * (-Math.pow(2, -10 * --t) + 2));		}	}}

public class QuadInterpolator implements Interpolator {	private int type;	public QuadInterpolator(int type) {		this.type = type;	}	public float getInterpolation(float t) {		if (type == EasingType.IN) {			return in(t);		} else		if (type == EasingType.OUT) {			return out(t);		} else		if (type == EasingType.INOUT) {			return inout(t);		}		return 0;	}	private float in(float t) {		return t*t;	}	private float out(float t) {		return -(t)*(t-2);	}	private float inout(float t) {		t *= 2;		if (t < 1) {			return 0.5f*t*t;		} else {			return -0.5f * ((--t)*(t-2) - 1);		}	}}

public class QuartInterpolator implements Interpolator {	private int type;	public QuartInterpolator(int type) {		this.type = type;	}	public float getInterpolation(float t) {		if (type == EasingType.IN) {			return in(t);		} else		if (type == EasingType.OUT) {			return out(t);		} else		if (type == EasingType.INOUT) {			return inout(t);		}		return 0;	}	private float in(float t) {		return t*t*t*t;	}	private float out(float t) {		return -((t-=1)*t*t*t - 1);	}	private float inout(float t) {		t *= 2;		if (t < 1) {			return 0.5f*t*t*t*t;		} else {			return -0.5f * ((t-=2)*t*t*t - 2);		}	}}

public class QuintInterpolator implements Interpolator {	private int type;	public QuintInterpolator(int type) {		this.type = type;	}	public float getInterpolation(float t) {		if (type == EasingType.IN) {			return in(t);		} else		if (type == EasingType.OUT) {			return out(t);		} else		if (type == EasingType.INOUT) {			return inout(t);		}		return 0;	}	private float in(float t) {		return t*t*t*t*t;	}	private float out(float t) {		return ((t-=1)*t*t*t*t + 1);	}	private float inout(float t) {		t *= 2;		if (t < 1) {			return 0.5f*t*t*t*t*t;		} else {			return 0.5f*((t-=2)*t*t*t*t + 2);		}	}}

public class SineInterpolator implements Interpolator {	private int type;	public SineInterpolator(int type) {		this.type = type;	}	public float getInterpolation(float t) {		if (type == EasingType.IN) {			return in(t);		} else		if (type == EasingType.OUT) {			return out(t);		} else		if (type == EasingType.INOUT) {			return inout(t);		}		return 0;	}	private float in(float t) {		return (float) (-Math.cos(t * (Math.PI/2)) + 1);	}	private float out(float t) {		return (float) Math.sin(t * (Math.PI/2));	}	private float inout(float t) {		return (float) (-0.5f * (Math.cos(Math.PI*t) - 1));	}}

转载地址:http://ldegi.baihongyu.com/

你可能感兴趣的文章
Spring 中Bean 的生命周期
查看>>
为什么要用枚举实现单例模式(避免反射、序列化问题)
查看>>
微服务架构下的分布式限流方案思考
查看>>
全网最详细的一篇SpringCloud总结
查看>>
消息中间件中的有序消息,其实是排队但是不能插队
查看>>
mysql为什么使用B+树作为索引的结构
查看>>
mysql索引总结(1)-mysql 索引类型以及创建(文章写的不错!!!)
查看>>
聊聊CAS - 面试官最喜欢问的并发编程专题
查看>>
Spring Boot 中使用一个注解轻松将 List 转换为 Excel 下载
查看>>
高并发环境下,先操作数据库还是先操作缓存?
查看>>
MySQL Explain详解
查看>>
一直搞不清楚什么是读写分离,主从复制的原理,今天总算搞懂了
查看>>
消息队列 mq 必会面试题
查看>>
线程池的工作原理是啥?能手写一个线程池吗?
查看>>
Java程序内存的简单分析
查看>>
Javascript单例模式概念与实例
查看>>
SQL NULL 函数
查看>>
多例设计模式
查看>>
WebView的JavaScript与本地代码三种交互方式
查看>>
WebView的JavaScript与本地代码三种交互方式
查看>>