0.1.1 • Published 11 months ago

@jimmyrichardson.co/lerp v0.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

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: 1. Lerp: Returns any midpoint from any two numbers when specified between 0 and 1. 2. Invlerp: Returns the decimal midpoint from any two numbers, from 0 to 1. 3. Clamp: Adds a floor and a ceiling to your math for more predictable behavior. 4. 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
0.1.1

11 months ago

0.1.0

11 months ago