Math functions
| Function | Notes |
|---|---|
Math.abs, acos, asin, atan, ceil, cos, exp, floor, sin, sqrt, tan, trunc, sign | One number. |
Math.log | Natural log. Also Math.log10, Math.log2. |
Math.round | Rounds .5 up, as JavaScript does. |
Math.atan2(y, x), Math.pow(a, b) | Two numbers. |
Math.hypot, Math.max, Math.min | Any number of numbers. |
Math.random() | 0–1, repeatable per frame. |
Angles in Math functions are radians; use degreesToRadians() / radiansToDegrees().
Constants
Math.PI, Math.E, Math.LN2, Math.LN10, Math.LOG2E, Math.LOG10E, Math.SQRT2, Math.SQRT1_2.
Conversion
| Function | What it does |
|---|---|
Number(x) | A number from a string or true/false; anything else gives NaN. |
String(x) | Text from a value. |
isNaN(x) | true if x isn't a number. |
n.toFixed(d) | A number as text with d decimals (0–20). |
s.toUpperCase(), s.toLowerCase() |
Examples
// bob up and down
value + [0, Math.sin(time * 2 * Math.PI) * 20]
// round a slider for display
Math.round(effect("Slider Control")("Slider"))