Re-maps a number from one range to another.
For example, calling map(2, 0, 10, 0, 100) returns 20. The first three arguments set the original value to 2 and the original range from 0 to 10. The last two arguments set the target range from 0 to 100. 20's position in the target range [0, 100] is proportional to 2's position in the original range [0, 10].
The sixth parameter, withinBounds, is optional. By default, map() can return values outside of the target range. For example, map(11, 0, 10, 0, 100) returns 110. Passing true as the sixth parameter constrains the remapped value to the target range. For example, map(11, 0, 10, 0, 100, true) returns 100.
map() can also be used in shaders with p5.strands. The following example uses map() to remap time values to color in a shader.
Examples
Syntax
map(value, start1, stop1, start2, stop2, [withinBounds])