android-各种动画加速器,各种插值器



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);
		}
	}
}
</pre><pre name="code" class="java">
</pre><p></p><p></p><p></p><p></p><p></p><pre name="code" class="java">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));
	}
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值