Re-maps a number from one range to another. In the first example above, the number 25 is converted from a value in the range of 0 to 100 into a value that ranges from the left edge of the window (0) to the right edge (width). As shown in the second example, numbers outside
(float value,
float start1, float stop1,
float start2, float stop2)
| 4644 | * @see PApplet#lerp(float, float, float) |
| 4645 | */ |
| 4646 | static public final float map(float value, |
| 4647 | float start1, float stop1, |
| 4648 | float start2, float stop2) { |
| 4649 | float outgoing = |
| 4650 | start2 + (stop2 - start2) * ((value - start1) / (stop1 - start1)); |
| 4651 | String badness = null; |
| 4652 | if (outgoing != outgoing) { |
| 4653 | badness = "NaN (not a number)"; |
| 4654 | |
| 4655 | } else if (outgoing == Float.NEGATIVE_INFINITY || |
| 4656 | outgoing == Float.POSITIVE_INFINITY) { |
| 4657 | badness = "infinity"; |
| 4658 | } |
| 4659 | if (badness != null) { |
| 4660 | final String msg = |
| 4661 | String.format("map(%s, %s, %s, %s, %s) called, which returns %s", |
| 4662 | nf(value), nf(start1), nf(stop1), |
| 4663 | nf(start2), nf(stop2), badness); |
| 4664 | PGraphics.showWarning(msg); |
| 4665 | } |
| 4666 | return outgoing; |
| 4667 | } |
| 4668 | |
| 4669 | |
| 4670 | /* |
no test coverage detected