We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexDiscussionGeneral Discussion,  Status › different lerps
Page Index Toggle Pages: 1
different lerps? (Read 1039 times)
different lerps?
Feb 11th, 2010, 11:38am
 
I am wondering if there is a processing library with different lerps (quintic, quadratic, sine, etc.)?  Anyone know?  Thanks.
Re: different lerps?
Reply #1 - Feb 12th, 2010, 8:51am
 
i think this is posted in the wrong topic, however...

here's your basic lerp (where "l" stands for Linear):

float lerp(float a, float b, float t) {
 return a + (b - a) * t;
}

to convert it to some OTHER response, simply modify t accordingly:

float lerp(float a, float b, float t) {
 t = f(t); // now go define what f() does...
 return a + (b - a) * t;
}

...where f() is some function (preferrably continuous!) giving f(0)=0 and f(1)=1, for example...

for quadratic response:
float f(float t) { return t*t; }

for quintic response:
float f(float t) { return t*t*t*t*t; }

for "circular" response:
float f(float t) { return 1.0-sqrt(1.0-t*t); }

for half-cosine ease-in response:
float f(float t) { return 0.5-cos(t*HALF_PI)*0.5; }

for full-cosine ease-in-out response:
float f(float t) { return 1.0-cos(t*PI); }

keep exploring, you can even use processing's bezier/curve functions:
float f(t) { return bezierPoint(0,0,1,1,t); }
float f(t) { return curvePoint(0,0,1,1,t); }

etcetera
Page Index Toggle Pages: 1