( begin auto-generated from map.xml ) Re-maps a number from one range to another. In the example above, the number '25' is converted from a value in the range 0..100 into a value that ranges from the left edge (0) to the right edge (width) of the screen. Numbers outside the range are no
(float value,
float start1, float stop1,
float start2, float stop2)
| 5066 | * @see PApplet#lerp(float, float, float) |
| 5067 | */ |
| 5068 | static public final float map(float value, |
| 5069 | float start1, float stop1, |
| 5070 | float start2, float stop2) { |
| 5071 | float outgoing = |
| 5072 | start2 + (stop2 - start2) * ((value - start1) / (stop1 - start1)); |
| 5073 | String badness = null; |
| 5074 | if (outgoing != outgoing) { |
| 5075 | badness = "NaN (not a number)"; |
| 5076 | |
| 5077 | } else if (outgoing == Float.NEGATIVE_INFINITY || |
| 5078 | outgoing == Float.POSITIVE_INFINITY) { |
| 5079 | badness = "infinity"; |
| 5080 | } |
| 5081 | if (badness != null) { |
| 5082 | final String msg = |
| 5083 | String.format("map(%s, %s, %s, %s, %s) called, which returns %s", |
| 5084 | nf(value), nf(start1), nf(stop1), |
| 5085 | nf(start2), nf(stop2), badness); |
| 5086 | PGraphics.showWarning(msg); |
| 5087 | } |
| 5088 | return outgoing; |
| 5089 | } |
| 5090 | |
| 5091 | |
| 5092 | /* |
no test coverage detected