This is a simple library for smoothing out the rough edges in interactions. It is basically just a convenient interface for a bunch of normalized one pole lowpass filters that you can use to smooth movements or fade colors.
download traer.animation library for processing, unzip it and put it in /processing/libraries/
feel free to email with questions, comments, suggestions for the library or this documentation or to show me something cool you made with this at traer at cs.princeton.edu, my name is jeff.
If you wanna know how all this works have a look at this section on one pole filters in julius smith's book on digital filters.
In order of complexity:
A smoother is just a normalized one pole filter. It has a smoothness between 0 and less than 1, a target, and a value. The target is where you want it to go, the value is where it is and the smoothness determines how long it takes to get there. 0 smoothness is not smooth at all, i usually use 0.9 which is nice and smooth but the faster your framerate the smoother you will have to make it.
void setSmoothness( float smoothness ) void setTarget( float target ) void setValue( float smoothness ) Smoother2D is made of 2 smoothers to smooth 2D movements
void setSmoothness( float smoothness ) void setTarget( float xTarget, float yTarget ) void setValue( float xValue, float yValue ) Smoother3D is made of 3 smoothers to smooth 3D movements
void setSmoothness( float smoothness ) void setTarget( float xTarget, float yTarget, float zTarget ) void setXTarget( float xTarget ) void setYTarget( float yTarget ) void setZTarget( float zTarget ) void setValue( float xValue, float yValue, float zValue ) The animator controls all the smoothers. You use it to make smoothers for you and then you tick the animator in draw() to advance time for all the smoothers.
new Animator( float smoothness ) void setSmoothness( float smoothness ) Smoother makeSmoother() Smoother2D make2DSmoother() Smoother3D make3DSmoother() void tick()Examples
Smoother
float getSmoothness()
float getTarget()
It will get to the target eventually
float getValue()
Setting the value makes it jump to this value immediately
Smoother2D
float getSmoothness()
void setXTarget( float xTarget )
void setYTarget( float yTarget )
float getXTarget()
float getYTarget()
float x()
float y()
void setX()
void setY()
Smoother3D
float getSmoothness()
float getXTarget()
float getYTarget()
float getZTarget()
float x()
float y()
float z()
void setX()
void setY()
void setZ()
Animator
make a new animator with some smoothness
Set the smoothness for all the smoothers
Make a new 1D smoother starting at zero, you can set the value after.
Make a new 2D smoother starting at zero, you can set the value after.
Make a new 3D smoother starting at zero, you can set the value after.
advance time for all the smoothers. you'll want to put this in draw.