/******************************************************************************* | |
* Copyright (c) 2010 IBM Corporation and others. | |
* All rights reserved. This program and the accompanying materials | |
* are made available under the terms of the Eclipse Public License v1.0 | |
* which accompanies this distribution, and is available at | |
* http://www.eclipse.org/legal/epl-v10.html | |
* | |
* Contributors: | |
* IBM Corporation - initial API and implementation | |
*******************************************************************************/ | |
package org.eclipse.xwt.animation; | |
import org.eclipse.xwt.XWTException; | |
/** | |
* | |
* @author yyang | |
*/ | |
public class ExponentialEase extends EasingFunctionBase { | |
private double exponent = 2; | |
public double getExponent() { | |
return exponent; | |
} | |
public void setExponent(double exponent) { | |
this.exponent = exponent; | |
} | |
public double ease(double normalizedTime) { | |
switch (getEasingMode()) { | |
case EaseIn: | |
return easeValue(normalizedTime); | |
case EaseOut: | |
return 1 - easeValue(1 - normalizedTime); | |
case EaseInOut: | |
normalizedTime /= 0.5; | |
if (normalizedTime < 1) | |
return easeValue(normalizedTime) / 2; | |
return (2 - easeValue(2 - normalizedTime)) / 2; | |
default: | |
throw new XWTException(getEasingMode().name() + " is supported."); | |
} | |
} | |
protected double easeValue(double normalizedTime) { | |
return (Math.exp(normalizedTime * getExponent()) - 1) | |
/ (Math.exp(getExponent()) - 1); | |
} | |
} |