# Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

### Code Snippets / [DBP] - Basic interpolation functions. Simple value animation.

Message
Posted: 11th Aug 2015 20:35 Edited at: 11th Aug 2015 20:43
As demonstrated in my WIP a few months ago, the following functions can be used to gradually change one value, from a starting value, to an ending value, over a given period or coefficient; useful for animating the user interface or game mechanics where 3DMath is not ideal.

The two simple functions are used by passing the starting or current value, the end value or next value; followed by the ratio between the two, counting from 0.0 to 1.0.

Lerp( 0, 10, 0.5) will return 5 because that is half way between the two values, since 0.5 is half of 1.0 (50% of 1.0). In turn 150 is returned by Lerp(100, 200, 0.5) because that is half way between 100 and 200.

Smooth#(0, 10, 0.5) will perform otherwise with a smoother transition between the two values; but the value return will match the target value when 1.0 is passed as the coefficient.

Smooth is more suitable for visual animation because the values accelerate and decelerate, and can be smoothed further by interpolating the ratio parameter.

Lerp is better for stepping through an iteration or linear transition but most suitable for quickly determining the result of a ratio between two measurements.

Posted: 18th Sep 2015 04:41
handy and simple, my favorite combination

Posted: 19th Sep 2015 13:40
Thanks.