package com.view.coverflow;

public class Anim {

	// Time handling functions
	static float constant(float t) {
		if (t < 0) {
			t = 0;
		} else if (t > 1) {
			t = 1;
		}
		return t;
	}

	static float extrapolate(float t) {
		return t;
	}

	static float repeat(float t) {
		if (t >= 1) {
			t = t - (int) Math.floor(t);
		} else if (t < 0) {
			t = 1 + t - (int) Math.floor(t);
		}
		return t;
	}

	static float reverse(float t) {
		if (t < 0) {
			t = -t;
		}
		if ((int) Math.floor(t) % 2 == 1) {
			t = 1 - (t - (int) Math.floor(t));
		} else {
			t = t - (int) Math.floor(t);
		}
		return t;
	}

	// Interpolation functions
	static float linear(float t) {
		return t;
	}

	static float cosine(float t) {
		return (float) (1 - Math.cos(t * Math.PI / 2));
	}

	static float sine(float t) {
		return (float) Math.sin(t * Math.PI / 2);
	}

	static float exponential(float t) {
		return (float) (Math.exp(t) - 1 / Math.exp(1) - 1);
	}

	static float ease_out(float t) {
		return (float) Math.sqrt(Math.sin(t * Math.PI / 2));
	}

	static float ease_in_elastic(float t, float a, float p) {
		float s;
		p = 0.3f;
		if (a < 1.0) {
			a = 1.0f;
			s = p / 4.0f;
		} else {
			s = (float) (p / (2 * Math.PI) * Math.asin(1.0 / a));
		}
		if (t == 0 || t == 1) {
			return t;
		}
		return (float) -(a * Math.pow(2, 10 * (t - 1)) * Math.sin(((t - 1) - s)
				* (2 * Math.PI) / p));
	}

	static float ease_out_back(float t) {
		float s = 1.70158f;
		t -= 1;
		return t * t * ((s + 1) * t + s) + 1;

	}

	static float ease_in_circ(float t) {
		return (float) (1 - Math.sqrt(1 - t * t));
	}

	static float ease_out_circ(float t) {
		t -= 1;
		return (float) Math.sqrt(1 - t * t);
	}
}
