linmap()
Re-maps a number from one range to another.
Example

# value to be mapped from the first range
x1 = round(min1+(max1-min1)*sin(frameCount/10)**2)
line(x1, 25, x1, 75)
text(str(x1), x1, 15)
# mapping the value to the second range
x2 = linmap(x1, min1, max1, min2, max2)
text(str(round(x2,2)), x2, 285)
line(x2, 225, x2, 275)
Syntax
linmap(value, start1, stop1, start2, stop2, [withinBounds])
value
the incoming value to be converted
start1
lower bound of the current range
stop1
higher bound of the current range
start2
lower bound of the newly mapped range
stop2
higher bound of the newly mapped range
withinBounds
boolean that specifies the behavior of the method if the mapped value is out of the bounds [start2, stop2]
Description
Maps a value from one range to another, such that the proportions are the same.
For example, number 2.5 is mapped from the range [0, 10] to number 25 in the range [0, 100]. Why? Because in both cases, the value is fourth the distance away from the starting point of the range, and three fourths away from the ending point.
Mapping 2.5 from the range [0, 10] to the range [10, 20] would give 12.5 for the same reason.
mapping 2.5 from the range [0, 10] to the range [10, 30] would give 15 for the same reason.
Last updated