Normalize
Map a value from any range to 0–1
Normalization converts a value from an arbitrary range into a number between 0 and 1. It answers the question: "Where does this value sit within its range?"
Given a minimum and maximum, the formula calculates the relative position of any value. A value at the minimum returns 0, at the maximum returns 1, and halfway returns 0.5. This is the inverse operation of linear interpolation (lerp).
Normalization is the starting point for almost every creative coding operation. It lets you work with proportions instead of absolute values — making your code independent of specific ranges and easy to compose with other functions.
function normalize(min: number, max: number, value: number): number {
return (value - min) / (max - min);
}