FAQ
Cover
\
Build
\
Source
\
Bugs
\
Reference
\
Libraries
\
Tools
The bugs database has moved
here
.
Bug 1235 : enhancement
Last modified: 2009-10-19 09:39
P
roject:
processing
trash
Version:
unspecified
Co
m
ponent:
android
book
core
libraries
pde
reference
tools
web
Status:
RESOLVED
Resolution:
INVALID -
Pr
i
ority:
P2
Severity:
normal
Platform
All
O
S:
All
Windows
Mac OS
Linux
Other
Reporter:
awared
Assigned To:
REAS
Attachment
Type
Created
Size
Actions
Description
: Opened: 2009-05-02 00:11
It happens in a programer's life time where one has to scale a range to correspond with
another range (e.g. make the mouseX which is 0-width range correspond to fill value which is
0-255). There is a constrain function which provides a cap, thus limiting the max value, but
there is no way for providing a ratio of what to scale. I had to do this many times in Max/Msp
and I thought processing should have it too.
I googled and found a code and it works! so here is the function:
float scaleThis (float input, float oldMin, float oldMax, float newMin,float newMax){
//float result = input*newMax/(oldMax); //my naive version i tried to produce
float result = (input/((oldMax-oldMin)/(newMax-newMin)))+newMin; // what I found on the
web.
return (result);
I think this should be a must have. In Max this function is called "scale" but since it is
reserved for the sizing of object perhaps some other name like "range" or "scope" would be
more suitable. Notice I tried to produce my code but I it was very advance for my level of
math so I thought I should share my finding. I hope this is a useful suggestion.
Sincerely,
Awared.
Additional Comment
#1 From REAS 2009-10-19 09:39
We have a function called map() that does exactly this. We agree, it's
essential. Thanks for your time.