util.easing.lerp
Shared
Linearly interpolates between two values by a progress factor
Syntax
local result = util.easing.lerp(
from,
to,
progress
)util.easing.lerp is the standard pairing for all easing functions.
- Pair with any easing curve — wrap
progressin anyutil.easing.*function to drive the interpolation. - Best for — animating positions, sizes, colors, or any numeric value between two points.
Parameters
| Type | Name | Description |
|---|---|---|
float | from | Start value |
float | to | End value |
float | progress | Interpolation factor, typically in the range [0, 1] |
Returns
| Type | Name | Description |
|---|---|---|
float | result | Interpolated value between from and to |
Examples
local result = util.easing.lerp(0, 100, 0.5)
core.engine.print("info", result) -- 50.0local result = util.easing.lerp(0, 100, util.easing.cubic_in_out(0.5))
core.engine.print("info", result)local resolution = core.engine.get_resolution()
local duration = 2.0
local start_tick = core.engine.get_tick()
util.event.on("sandbox:draw", function()
local elapsed = (core.engine.get_tick() - start_tick) / 1000.0
local t = math.min(elapsed / duration, 1.0)
local x = util.easing.lerp(0, resolution[1], util.easing.sine_in_out(t))
core.engine.draw_circle({x, resolution[2]*0.5}, 16, {1, 1, 1, 1})
end)