问题
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?
回答1:
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));
来源:https://stackoverflow.com/questions/43683041/c-equivalent-of-processings-map-function