package com.view.coverflow;

class InterpolatedAnimator extends Animator {
	float start, end, startt, endt, one_over_dt, prev_x;
	String functionName;

	public InterpolatedAnimator(float start, float end, float dt,
			String functionName) {

		this.start = start;
		this.end = end;

		this.startt = _time;
		this.endt = startt + dt;
		
		this.one_over_dt = 1.f / (endt - startt);
		this.prev_x = 0;
		this.functionName = functionName;

	}

	public void setVal(float val) {
		this.start = getVal();
		this.end = val;
		float diff = endt - startt;
		this.startt = _time;
		this.endt = (startt + diff);

	}

	public float getVal() {
        
		float t = Anim.constant((_time - startt) * one_over_dt);

		float x = this.calculatorXval(t, functionName);
		dx = x - this.prev_x;

		this.prev_x = x;
		dv = dx * this.one_over_dt;
		return x;
	}

	private float calculatorXval(float t, String functionName) {
		double s = 0;
		if (functionName.equalsIgnoreCase("back")) {

			s = Anim.ease_out_back(t);
		}
		if (functionName.equalsIgnoreCase("circ")) {

			s = Anim.ease_out_circ(t);
		}
		if (functionName.equalsIgnoreCase("sine")) {

			s = Anim.sine(t);
		}
		if (functionName.equalsIgnoreCase("tial")) {

			s = Anim.exponential(t);
		}
		return (float) ((end - start) * s + start);
	}

}
