Re-maps a number from one range to another.


  # 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)


linmap(value, start1, stop1, start2, stop2, [withinBounds])


the incoming value to be converted


lower bound of the current range


higher bound of the current range


lower bound of the newly mapped range


higher bound of the newly mapped range


boolean that specifies the behavior of the method if the mapped value is out of the bounds [start2, stop2]


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.

Find these documents helpful? Let the people who made them help your child learn to code at Strivemath!

We'd love to hear your Feedback/Comments here.

Last updated