CharlieW112
CharlieW112

Reputation: 61

Is there a Processing 'map()' equivalent for python?

I need an equivalent of Processing's 'map()' function in order to map a integer that can have a range of 0, 1000 to a range of 255, 0. It doesn't necessarily have to be a universal function, it can be a hard-coded expression suited purely to this range.

Upvotes: 2

Views: 924

Answers (2)

Gunjan Paul
Gunjan Paul

Reputation: 531

you can use for to solve such expression with using map function. please cross check my line. thank you

Upvotes: 0

Davis Yoshida
Davis Yoshida

Reputation: 1785

There's no such builtin, but you can use the following:

def map_range(value, start1, stop1, start2, stop2):
   return (value - start1) / (stop1 - start1) * (stop2 - start2) + start2

Upvotes: 1

Related Questions