The "interp" Function
interp(a, b, amount, ease);
|a||real||The value to interpolate from|
|b||real||The value to interpolate to|
|amount||real (0-1)||The percentage to interpolate between values|
|ease||integer/macro||The ease mode to calculate interpolation|
Returns a value interpolated between the two input values with optional easing methods to create a smooth start and/or end to animations created using this script.
Example: interp(10, 20, 0.5, ease_none);
In this example, the script would return the number 15, as 15 is 50% of the value between 10 and 20. With easing disabled, this is precisely the same functionality as the built-in lerp (linear interpolation) function in GameMaker Studio.
Where interp differs is that it offers not just linear interpolation, but support for approx. 30 ease modes (sometimes referred to as “tweening”) which alters the acceleration between values without altering the overall duration (i.e. 0% is always value A and 100% is always value B). These ease modes can be thought of as curves, where different modes are organized from shallowest to steepest curve. For example:
On the left a series of points is drawn with standard linear interpolation using the ease_none setting, and on the right the same series is drawn using ease_quart_in_out. Both lines are drawn with the same two-second duration, but the latter is distributed differently across time. This is visible in the curvature and gaps between points, beginning quite close together and then spreading out in the middle before once again bunching up at the end. The first line, on the other hand, is evenly spaced across the entire animation.
See Macros & Keywords for a full list of available ease modes.