How can I re-map a number from one range to another in pygame or python ?
eg: If I want to map to map x=25 with range 0-100 to a new range from 0-20.. the new value of x would be 5.
How can I re-map a number from one range to another in pygame or python ?
eg: If I want to map to map x=25 with range 0-100 to a new range from 0-20.. the new value of x would be 5.
Write a function which maps from a range [a, b] to a range [c, d]:
def maprange(x, a, b, c, d):
w = (x-a) / (b-a)
y = c + w * (d-c)
return y
y = maprange(25, 0, 100, 0, 20)