@jimmyrichardson.co/lerp
v0.1.1
Published
Some of my favorite linear interpolation helpers.
Downloads
2
Maintainers
Readme
Lerp JS
Some of my personal favorite linear interpolation helpers, borrowed from Trys Mumford.
Installation
npm install @jimmyrichardson.co/lerp
Usage
This package has 4 helpers:
- Lerp: Returns any midpoint from any two numbers when specified between 0 and 1.
- Invlerp: Returns the decimal midpoint from any two numbers, from 0 to 1.
- Clamp: Adds a floor and a ceiling to your math for more predictable behavior.
- Range: Returns any midpoint from any 2 sets of numbers, not just a decimal between 0 and 1. The midpoint argument comes from the first set of numbers.
Lerp Example
import { lerp } from '@jimmyrichardson.co/lerp';
console.log( lerp(0, 100, 0.5) ); // returns 50
InvLerp Example
import { invlerp } from '@jimmyrichardson.co/lerp';
console.log( invlerp(20, 100, 9999) ); // returns 1
Clamp Example
import { clamp } from '@jimmyrichardson.co/lerp';
console.log( clamp(9999, 20, 30) ); // returns 30
Range Example
import { range } from '@jimmyrichardson.co/lerp';
console.log( range(1, 10, 500, 5000, 5) ); // returns 2500