Skip to content

pencil.js / math / map

Function: map() ​

ts
function map(
   value, 
   fromMin, 
   fromMax, 
   toMin?, 
   toMax?
): number;

Defined in: math.ts:124

Return the equivalent of a value from a scale to another

Parameters ​

ParameterTypeDefault valueDescription
valuenumberundefinedValue to use
fromMinnumberundefinedStart of the origin scale
fromMaxnumberundefinedEnd of the origin scale
toMin?number0Start of the target scale
toMax?number1End of the target scale

Returns ​

number

Example ​

ts
map(5, 0, 10, 100, 200); // => 150

Released under the MIT License.