You are not logged in.
Pages: 1
This is a simple bit of code, but it helps to have it pre-written and tested rather then typing it in when you need it and getting the sign wrong. It takes a value, then maps that value from one range of real numbers to another range. There is a check for division-by-zero, which returns zero.
///Map(input, old_max, old_min, new_max, new_min)
var inputValue, oldMax, oldMin, newMax, newMin;
inputValue = argument0;
oldMax = argument1;
oldMin = argument2;
newMax = argument3;
newMin = argument4;
if (!(oldMax - oldMin = 0))
{
return (((inputValue - oldMin)/(oldMax - oldMin))*(newMax - newMin)) + newMin;
}
else return 0;
Offline
Thanks for posting this. Someone else has already submitted something like this, I think. I'll see how they compare, maybe combine them. I'll be making a couple of minor changes but this looks good.
Abusing forum power since 1986.
Offline
Pages: 1