Built-in Functions

Complex Numbers

Complex numbers have type ri:2.

arg(x)
Returns the argument of the complex value x == ri:[re,im], which is atan(im/re).
conj(x)
Returns the conjugate complex of x == ri:[re,im], which is ri:[re,-im].

Vectors and Matrices

Only matrices of dimensions 2x2 and 3x3 are supported. They must have the types m2x2:4 and m3x3:9, respectively.

dotp(x,y)
Returns the scalar (inner) product of x and y
crossp(x,y)
Returns the cross (outer) product of x and y, which must both have the length 3.
det(m)
Returns the determinant of matrix m.
normalize(v)
Returns a vector with the same direction as v but with length 1. For example, normalize([2,0,0]) yields [1,0,0].
abs(x)
Returns the absolute value of x. This works with complex numbers and vectors.
sum(t)
Returns the sum of all elements of the tuple t.

Trigonometry

Trigonometric functions work with radians on real and complex numbers.

deg2rad(x)
Returns the value x converted from degrees to radians.
rad2deg(x)
Returns the value x converted from radians to degrees.
sin(x)
Returns the sine of x.
cos(x)
Returns the cosine of x.
tan(x)
Returns the tangens of x.
asin(x)
Returns the arc-sine of x.
acos(x)
Returns the arc-cosine of x.
atan(x)
Returns the arc-tangent of x.
atan(y,x)
Returns the arc tangent of x and y which is the same as atan(y/x), except that the signs of x and y are used to determine the quadrant of the result.

Hyperbolic Functions

Hyperbolic functions work on real and complex numbers.

sinh(x)
Returns the hyperbolic sine of x.
cosh(x)
Returns the hyperbolic cosine of x.
tanh(x)
Returns the hyperbolic tangent of x.
asinh(x)
Returns the hyperbolic arc-sine of x.
acosh(x)
Returns the hyperbolic arc-cosine of x.
atanh(x)
Returns the hyperbolic arc-tangent of x.

Various Mathematical Functions

Functions work on and return tuples of length 1 unless noted otherwise.

exp(x)
Returns e^x. Works on real and complex numbers.
log(x)
Returns the natural logarithm of x. Works on real and complex numbers.
gamma(x)
Returns the value of the gamma function for x.
pmod(x,y)
Returns the modulo of x and y as a positive value, even if x is negative.
sign(x)
Returns -1 if x < 0, 0 if x = 0 and 1 if x > 0. Works on two tuples of the same length.
floor(x)
Returns the largest integer which is less or equal to x.
min(x,y)
Returns x if x < y, y otherwise. Works on two tuples of the same arbitrary length.
max(x,y)
Returns x if x > y, y otherwise. Works on two tuples of the same arbitrary length.
clamp(x,l,u)
Clamps each element of x to be between the corresponding elements of l and u and returns the result. All three tuples must have the same tag and the same arbitrary length.
lerp(t,a,b)
Returns a*(1-t)+b*t. t must have length 1. a and b must have the same tag and the same arbitrary length.
scale(x,fl,fu,tl,tu)
Returns ((x-fl)/(fu-fl))*(tu-tl).
inintv(a,x,y)
Returns 1 if x <= a <= y, 0 otherwise.

Pseudo-Random Numbers

rand(x,y)
Returns a random number a with x <= a <= y. Successive random numbers are evenly distributed within the interval.
noise(coord)
Returns the value of a solid noise function at coordinate coord. coord must have length 3. The returned value is in the interval -1 to 1.

Colors

Colors must have types rgba:4 or hsva:4, depending on whether they are in the RGB or the HSV color space.

red(p)
Returns the red component of p, which is 0 <= red(p) <= 1.
green(p)
Returns the green component of p, which is 0 <= green(p) <= 1.
blue(p)
Returns the blue component of p, which is 0 <= blue(p) <= 1.
alpha(p)
Returns the alpha component of p, which is 0 <= alpha(p) <= 1.
gray(p)
Returns the luminance of p, which is 0 <= gray(p) <= 1.
toRGBA(c)
Transforms the color c to RGBA. Returns an rgba:4 tuple.
toHSVA(c)
Transforms the color c to HSVA. Returns an hsva:4 tuple.
rgbColor(r,g,b)
Returns the rgba value of a pixel with red component r, green component g, blue component b and alpha component 1. This function is provided for compatibility.
rgbaColor(r,g,b,a)
Returns the rgba value of a pixel with red component r, green component g, blue component b and alpha component a. This function is provided for compatibility.
grayColor(g)
Returns the rgba value of a pixel with luminance g and alpha component 1.
grayaColor(g,a)
Returns the rgba value of a pixel with luminance g and alpha component a.

Input Images

origVal(coord)
Returns the rgba value of the pixel at coordinate coord. coord may be of type xy:2 or ra:2.
origVal(coord,image)
Returns the rgba value of the pixel at coordinate coord in the image image. coord may be of type xy:2 or ra:2. image must be of type image:1 and must be a value returned by user_image.
origValXY(x,y)
Returns the pixel value of the pixel at the cartesian position (x,y). This function is provided for compatibility.
origValRA(r,a)
Returns the pixel value of the pixel at the polar position (r,a). This function is provided for compatibility.