Another Ease Function

I had been thinking about making an ease function that eases a transition in a way similar to the way group94 sometimes uses for their transitions. After some time of sleeping on it, I took some time to write it out.

I have left the following code unmodified to illustrate my process.

The initial function I wrote:

Note that the order of parameters of this function are not standard.

function group94EaseOut(t:Number, d:Number, c:Number, b:Number):Number {
	if((t/=d) < 0.1){
		//ease here later, but for now linear
		//trace(t);
		return t/0.1*c*0.9+b;
	} else {
		//trace(t);
		return (t-0.1)/0.9*c*0.1+c*0.9+b;
	}
}

The idea is to distribute a greater part of the change over a lesser portion of the duration as the first part of the tween, and to distribute the remaining change over the remaining duration. The condition which determines which equation to use is the portion of the duration we distribute the first part of change over.

I realized that the coefficient that determined the distribution could be parameterized, so I added r. The initial function will execute faster, but the following function is more robust.

function group94EaseOut(t:Number, d:Number, c:Number, b:Number, r:Number=0.1):Number {
	if((t/=d) < r){
		return t/r*c*(1-r)+b;
	} else {
		return (t-r)/(1-r)*c*r+c*(1-r)+b;
	}
}

I then used sine easing to ease in for the first part of the tween, and sine easing to ease out for the second part of the tween.

Here is the final function:

function easeG94(t:Number, b:Number, c:Number, d:Number, r:Number=0.1):Number {
	return (t/=d) < r?
		(1-Math.cos(t/r*Math.PI/2))*c*(1-r)+b:
		Math.sin((t-r)/(1-r)*Math.PI/2)*c*r+c*(1-r)+b;
}

Here is a working example of the final function:

Click anywhere on the stage to move the ball. The red line is the curve of the current distribution, which is displayed in the top right corner. Press up and down arrows to change the distribution.

I realize that any of Robert Penners easing functions could be used to ease in and out of the two parts of this function, but that much computation may hinder the smoothness of the transition. I do however have something in the works that should improve the performance of all ease functions. That I will write about soon.

Another thing to note, with r=0.5, using any of the standard easeIn and easeOut functions should have the curve of their corresponding easeInOut function.

0 Response to “Another Ease Function”


  • No Comments

Leave a Reply