lerp

Calculates a value that is a linear combination of two other values based on the interpolation factor.

Installation

npm install @madeinhaus/utils

Import

import { lerp } from '@madeinhaus/utils';

Parameters

  • a (number): The start value.
  • b (number): The end value.
  • t (number): The interpolation factor between 0 and 1.

Returns

  • (number): The interpolated value between a and b.

Usage

import { lerp } from '@madeinhaus/utils';
 
const startValue = 0;
const endValue = 100;
const interpolationFactor = 0.5;
const interpolatedValue = lerp(startValue, endValue, interpolationFactor); // 50

In this example, we import the lerp function from the @madeinhaus/utils package and use it to linearly interpolate between two values.