Skip to content
Reference > Methods

scale(value,source1,target1,source2,target2,moreSourcesAndTargets)

Definition

Double scale(Number value, Number source1, Number target1, Number source2, Number target2, Number ... moreSourcesAndTargets)

Description

Requires a value and a list of number_from=number_to pairs. It will return a Double that properly represents the supplied value. For example, given the pairs 1=10 and 2=20, 1 will return 10, 1.5 returns 15 and 2 returns 20. Values greater than the max number_from will return the corresponding number_to (same for minimum). Ex 3 will return 20. At least 2 pairs are required but additional pairs can be provided in the var args parameter.

Parameter Definition

Name Type Description
value Number Value to return number for
source1 Number Input Value 1 associated with return value 1
target1 Number return value 1 associated with value 1
source2 Number Input Value 2 associated with return value 2
target2 Number return value 2 associated with Input value 2
moreSourcesAndTargets Number... Additional number/number pairs, must be even number of elements, where even elements are a number and odd elements are a return number

Examples

1
2
3
4
Double r1 = scale(0.5D,0,10,1,20,2,100); // r1 == 15.0
Double r2 = scale(1.5D,0,10,1,20,2,100); // r2 == 60.0
Double r3 = scale(2.5D,0,10,1,20,2,100); // r3 == 100.0
Double r4 = scale(-0.5D,0,10,1,20,2,100); // r4 == 10.0