| 1 |
// name: map.ck |
| 2 |
// desc: mapping a number in one range to a second range, using |
| 3 |
// Math.map( float value, float x1, float x2, |
| 4 |
// float y1, float y2 ) |
| 5 |
// |
| 6 |
// version: need chuck-1.5.0.0 or higher |
| 7 |
// |
| 8 |
// NOTE: Math.map(...) allows 'value' to be outside range [x1,x2] |
| 9 |
// whereas Math.map2(...) clamps 'value' to range [x1,x2] |
| 10 |
// |
| 11 |
// uncomment this line to print Math library API |
| 12 |
// Math.help(); |
| 13 |
// |
| 14 |
// author: Ge Wang |
| 15 |
// date: Spring 2023 |
| 16 |
|
| 17 |
// map 2.5 from [2,4] to [0,1] |
| 18 |
<<< Math.map( 2.5, 2, 4, 0, 1 ), "" >>>; |
| 19 |
// map 5 from [1,10] to [-1,1] |
| 20 |
<<< Math.map( 5, 1, 10, -1, 1 ), "" >>>; |
| 21 |
// map 5 from [10,1] to [-1,1] |
| 22 |
<<< Math.map( 5, 10, 1, -1, 1 ), "" >>>; |
| 23 |
// map 1 from [2,3] to [0,100] |
| 24 |
<<< Math.map( 1, 2, 3, 0, 100 ), "(not clamped)" >>>; |
| 25 |
// clampf() and map() |
| 26 |
<<< Math.map2( Math.clampf(1,2,3), 2, 3, 0, 100 ), "(clamped using Math.clampf())" >>>; |
| 27 |
// same as Math.map2() |
| 28 |
<<< Math.map2( 1, 2, 3, 0, 100 ), "(clamped using Math.map2())" >>>; |