Functions and Constants (Studio)

Top  Previous  Next

 

 

PixelScript provides numerous functions that can be used to manipulate values, in addition to some constants.

 

 

real myNumber = abs(-5);

debug(myNumber);

 

Functions operate like in other C-style languages, with the arguments of the function supplied within parenthesis after the function name.  In this example the abs function finds the absolute value of "-5".  The number "5" is therefore printed to the debug pane when the script is run.

 

real a = 2;

real b = 3;

debug(max(a, b));

If a function takes multiple arguments, they are separated by commas.  The max function finds the larger of two values, causing "3" to be printed in this example.

 

 

 

General Math Functions

 

 

Function

Description

abs(x)

Returns the absolute value of the supplied number.  For example, abs(-5) returns 5.

pow(x, y)

Returns x raised to the power of y.

sqr(x)

Returns x squared.

sqrt(x)

Returns the square root of x.

log(x, b)

Returns the logarithm of x for the base b.

log(x)

Returns the natural (base e) logarithm of x.

min(x, y)

Returns the smaller of x and y.

max(x, y)

Returns the larger of x and y.

round(x)

Rounds x to the nearest whole number. In case of two equidistant solutions, the nearest even number will be selected.

trunc(x)

Returns the integer portion of x.

ceil(x)

Returns the smallest integer that is greater than or equal to x.

floor(x)

Returns the largest integer that is less than or equal to x.

noise(x, y, z, w)

Samples a multi-dimensional field of random values.  Sampling the same coordinates will always return the same value.  The function's last two arguments are optional.  This function only accepts arguments of type int, so real values will need to be cast before use with (int).  To see this function in action, try this script: result = noise((int)(x*8), (int)(y*8));

lerp(x, y, weight)

Returns an interpolated (weighted average) of the two values, with a weight of 0 returning x, and a weight of 1 returning y.

 

 

 

Trigonometric Functions

 

 

Function

Description

sin(x)

Returns the sine of x.

asin(x)

Returns the angle whose sine is x.

cos(x)

Returns the cosine of x.

acos(x)

Returns the angle whose cosine is x.

tan(x)

Returns the tangent of x.

atan(x)

Returns the angle whose tangent is x.

atan2(x, y)

Returns the arc tangent of y/x, taking into account which quadrant the point (x, y) is in.

sinh(x)

Returns the hyperbolic sine of x.

asinh(x)

Returns the angle whose hyperbolic sine is x.

cosh(x)

Returns the hyperbolic cosine of x.

acosh(x)

Returns the angle whose hyperbolic cosine is x.

tanh(x)

Returns the hyperbolic tangent of x.

atanh(x)

Returns the angle whose hyperbolic tangent is x.

 

 

 

Value Test Functions

 

 

Function

Description

isNan(x)

Returns whether x is not a number.

isInfinity(x)

Returns whether x is either positive or negative infinity.

isPosInfinity(x)

Returns whether x in positive infinity.

isNegInfinity(x)

Returns whether x is negative infinity.

 

 

 

Constants

 

 

Constant

Description

e

Euler's number.

pi

Pi.

 

 

Next, learn how to access the node's inputs in PixelScript.

 

 

 


Page URL: http://www.spiralgraphics.biz/genetica/help/index.htm?pixelscript_functions.htm