Functions
User-defined functions let you organize scripts and reuse logic across multiple call sites.
Declaration
function smoothCurve(t, gamma) {
return pow(t, gamma);
}
Functions can take zero or more arguments and return any value (number, object, or tuple).
Calling
result = smoothCurve(0.5, 2.0);
Functions can be called from anywhere in the script after they're declared, including from inside other functions.
Returning multiple values
Like top-level scripts, functions can return tuples:
function polar(x, y) {
return (hypot(x, y), atan2(y, x));
}
Calling from the GUI
Functions can be wired to GUI buttons via the //!gui:button directive (see GUI directives):
//!gui:button label="Reset" func="resetState"
function resetState() {
state.i = 0;
state.prevErr = 0;
return 0;
}