Processing has a function map
that
Re-maps a number from one range to another.
For example
int ans = map(5, 0, 10, 0, 100);
ans
will be 50
as 5
is halfway between 0
and 10
and halfway between 0
and 100
is 50
.
If there is no built in function how would I write my own one?
Processing is open source, and you can view the source for the map()
function here.
Specifically, this is the line you care about:
float outgoing =
start2 + (stop2 - start2) * ((value - start1) / (stop1 - start1));
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments