Gary Stidston-Broadbent

libease

libease is a shared library written in the c programming language containing easing algorithms that can be used for graphical effects or mathematical calculations.

Easing methods

Currently libease contains 10 easing methods for you to use. In order to represent the methods to you, I have created charts of each of the methods getting them to ease from an initial value of zero, up to a value of 100, taking 100 steps to get there. The methods are as follows:

  1. easeNone

    none (linear)

  2. easeIn

    in

  3. easeOut

    out

  4. easeIo

    io

  5. easeOi

    oi

  6. easeBounceIn

    bounce in

  7. easeBounceOut

    bounce out

  8. easeBackIn

    back in

  9. easeBackOut

    back out

  10. easeBackIo

    back in out

Installing the library

  1. Download a compressed version (tar.bz2) from SourceForge or if you prefer subversion, you can check it out anonymously at http://www.stroppytux.net/svn/libease/ (WSVN).

  2. Once you have a copy of libease extract it by typing ”tar -jxf libease.0.0.4.tar.bz2“

Installing libease

Single dimension easing

Incorporating libease into your project is a relatively trivial task.

/* Ease structure */
typedef struct {
	int duration;
	int time;
	int difference;
	int initial;
	float overshot;
	int value;
	int (*fpoint)();
	int (*type)();
} Ease;

The following code creates an ease structure to call the easeIn method. We start at zero and take 25 steps to get up to 100. At each step, we call show_step to print the value on the screen.

/* vim: set ts=4 sw=4 nowrap: */
/* compile:	gcc -Wall -g -c test.c -o test.o
			gcc -g -o test test.o -I/usr/include -L/usr/lib -lease
*/

/* Include the header files we need, especially ease.h */
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <ease.h>

/* A test function to show our easing values at each step.
We pass in va_list ap to allow us to receive misc variables
from our wrapper. These can then be passed into the call
you are using the ease value on. */
int show_step(Ease *testEase, va_list ap)
{
	printf("%s: %d\n", va_arg(ap,char*), testEase->value);
	return 0;
}

/* Our main function called on program execution */
int main()
{
	/* Register an int for the return value and create a string
	that we will use as an example of passing arbitrary variables
	into our ease function. This value will then get passed into
	whatever we set our callback function to at each step of the
	easing process. */
	register int retval;
	char *test_str = "Value";

	/* Create the Ease structure and populate it. For more info
	on what the values are, please read the description of the
	Ease structure above. */
	Ease example;
	example.type			= &easeIn;
	example.initial			= 0;
	example.duration		= 25;
	example.difference		= 100;
	example.fpoint			= show_step;

	/* Execute the ease wrapper passing in a pointer to our ease
	structure. We also pass in the test string that we defined to
	demonstrate how to pass variables into the ease wrapper and
	then pull them out at the other side. Any quantity of variables
	can be passed in and recalled from the wrapper. */
	retval					= ease(&example, test_str);
	return(retval);
}

Multi dimension easing

Following are some examples of using the multi dimension easing wrapper:

/* Ease_Multi structure */
typedef struct {
	Ease dimension[MULTI_MAX];
	int (*fpoint)();
} Ease_Multi;
/* vim: set ts=4 sw=4 nowrap: */
/* compile:	gcc -Wall -g -c multi_test.c -o multi_test.o
			gcc -g -o multi multi.o -I/usr/include -L/usr/lib -lease
*/

/* Include the header files we need, especially ease.h */
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <ease.h>

/* Ease_Multi version of our callback function */
int show_step_multi(Ease_Multi *testEase, va_list ap)
{
	printf("%s: x=%d y=%d\n",
		va_arg(ap,char*),
		testEase->dimension[0].value,
		testEase->dimension[1].value);
	return 0;
}

/* Our main function called on program execution */
int main()
{
	/* Register variables. */
	register int retval;
	char *test_str = "Value";

	/* In this example we use the Ease_Multi structure */
	Ease_Multi example;
	register int t;
	for (t=0; t<MULTI_MAX; ++t) example.dimension[t].type = '\0';

	/* Set the callback method */
	example.fpoint						= show_step_multi;

	/* X dimension */
	example.dimension[0].type			= &easeBackIo;
	example.dimension[0].initial		= 10;
	example.dimension[0].duration		= 20;
	example.dimension[0].difference		= 50;

	/* Y dimension */
	example.dimension[1].type			= &easeIn;
	example.dimension[1].initial		= 0;
	example.dimension[1].duration		= 10;
	example.dimension[1].difference		= 20;

	/* Execute the ease_multi wrapper */
	retval								= ease_multi(&example, test_str);
	return(retval);
}
  1. back io, back out, back in

    none (linear)

  2. none, io, back in

    in

  3. back oi, oi, none

    in