## Reference

This info is generated from the function reference inside Mad Tea Lab

#### Helper:

• out(c, […]) – text output
• dirt(x) – Low amp. Noise
• marker(x,a)
• F(text) – Create Function
• sample(function,range)
• aToF(array [,filter,begin,end])
• aToFn(array [,filter])

#### Periodic:

• saw(x [,n=1]) – 0 to 1
• saw0(x, [,n=1]) – -1 to 1
• tri(x, [,n=1]) – 0 to 1
• tri0(x, [,n=1]) – -1 to 1

#### Decimate:

• round(x [,decimals] )
• floor(x) – Floor function
• ceil(x) – Ceiling function
• int(x) – Integer function
• sgn(x) – Sign
• H(x) – Heaviside step

#### Number Generation:

• rnd0() – Range -1 <1
• rnd() – Range 0 <1
• rndi(c) – Integer, 0
• rand() – Integer, 0 <232
• randn() – Normal dist.
• intHash(x) – Integer Hash
• hash(x) – 0 – <1
• hash0(x) – -1 – <1

#### Basic Math:

• sqr(x) – x2 (Square)
• cube(x) – x3 (Cube)
• sqrFlip(x) – 1-(1-x)2
• cubeFlip(x) – 1-(1-x)3
• sqrt(x) – Square Root
• pow(b,x) – bx
• exp(x) – ex
• exp2(x) – 2x
• log(x) – Logarithm (e)
• log10(x) – Logarithm (10)
• log2(x) – Logarithm (2)
• logx(b,x) – Logarithm (b)

#### Trigonometry:

• sin(x) – Sine
• cos(x) – Cosine
• tan(x) – Tangent
• abs(x) – Absolute value
• acos(x) – Inverse cosine
• asin(x) – Inverse sine
• atan(x) – Inverse tangent
• atan2(y,x) – Inverse tangent
• sinh(x) – Sine Hyperholic
• cosh(x) – Cosine Hyperholic

### Helper:

#### out

out(c, […]) text output
Write text to the output box

#### dirt

dirt(x) Low amp. Noise
A hash-based, uniformly distributed noise, with a scaling of 1/32

#### marker

marker(x,a)
GUI helper, just a function that is very steep at (a)

#### F

F(text) Create Function
Creates a function from string, arguments are assumed to be (x,y,z)

#### sample

sample(function,range)
Samples a function N times and returns an array with the sampled data, range is specified as an array [begin_value, end_value, N]

#### aToF

aToF(array [,filter,begin,end])
Array-To-Function, filter can be nearest, linear (default), hermite, quadratic or cubic. Default value of begin is 0. Default value of end is array.length-1

#### aToFn

aToFn(array [,filter])
Array-To-Function, same as aToF but with hardwired begin=0 and end=1

### Periodic:

#### saw

saw(x [,n=1]) 0 to 1
Period n, out values 0 to 1

#### saw0

saw0(x, [,n=1]) -1 to 1
Period n, out values -1 to 1

#### tri

tri(x, [,n=1]) 0 to 1
Period n*2, out values 0 to 1

#### tri0

tri0(x, [,n=1]) -1 to 1
Period n*2, out values -1 to 1

### Graphics:

#### point

point(x,y,z,size)
Draw a Point

#### rect

rect(x,y,width,height)
Draw a 2D rectangle
Wikipedia on Rectangle

#### ellipse

ellipse(x,y,width,height)
Draw an ellipse
Wikipedia on Ellipse

#### circle

Draw a circle
Wikipedia on Circle

#### line

line( coords * 2 )
Draw a line segment, both 2D and 3D coordinates are accepted
Wikipedia on Line segment

#### triangle

triangle( coords * 3 )
Draw a triangle, both 2D and 3D coordinates are accepted
Wikipedia on Triangle

Draw a quadrilateral, both 2D and 3D coordinates are accepted

#### beginShape

beginShape([primitive])
Begin shape drawing, primitives are LINE_STRIP (default), LINES, TRIANGLES and QUADS

#### vertex

vertex( coord )
Must be called within calls to beginShape/endShape

#### endShape

endShape([CLOSE])
End (and draw) a shape, for the LINE_STRIP primitive, passing CLOSE to the function will close the shape

#### screenSpace

screenSpace()
Set drawing coordinates to be related to canvas pixels

#### plotSpace

plotSpace()
Set drawing coordinates to be related to the current view of the graph

#### scale

scale(x [,y,z])
Scale the drawing space for future drawing, scale(2) will scale x,y,z by 2 (uniformly)

#### translate

translate(x,y [,z])
Offset the drawing space for future rendering

#### rotate

rotate(a)
Rotates the drawing space (x,y) for future rendering

#### rotateX

rotateX(a)
Rotates the drawing space (y,z) for future rendering

#### rotateY

rotateY(a)
Rotates the drawing space (x,z) for future rendering

#### fill

fill(color [,alpha])
Color can be supplied as r,g,b (range 0 to 255), gray (0 to 255), [r,b,g] (range 0 to 1) or hex. Alpha is in range 0 to 255.

#### stroke

stroke(color [,alpha])
Color can be supplied as r,g,b (range 0 to 255), gray (0 to 255), [r,b,g] (range 0 to 1) or hex. Alpha is in range 0 to 255.

noFill()
Disable Fill

#### noStroke

noStroke()
Disable Stroke

Load image to browser cache and display thumbnail

#### imageMode

imageMode(mode)
Sets mode for function image(), valid modes are CORNER (default), CORNERS and CENTER

image(x,y,w,h)
Draws an image

### Color Processing:

#### toHSV

toHSV(rgb)
Input is [R,G,B] each in range 0 to 1, output is [H,S,V] each in range 0 to 1
Wikipedia on HSL and HSV

#### fromHSV

fromHSV(hsv)
Input is [H,S,V] each in range 0 to 1, output is [R,G,B] each in range 0 to 1
Wikipedia on HSL and HSV

#### toHSL

toHSL(rgb)
Input is [R,G,B] each in range 0 to 1, output is [H,S,L] each in range 0 to 1
Wikipedia on HSL and HSV

#### fromHSL

fromHSL(hsl)
Input is [H,S,L] each in range 0 to 1, output is [R,G,B] each in range 0 to 1
Wikipedia on HSL and HSV

#### toYUV

toYUV(rgb [,Kr,Kb,Sr,Sb])
Input is [R,G,B] each in range 0 to 1, output is [Y,U,V] each in range 0 to 1
Wikipedia on YUV

#### fromYUV

fromYUV(yuv [,Kr,Kb,Sr,Sb])
Input is [Y,U,V] each in range 0 to 1, output is [R,G,B] each in range 0 to 1
Wikipedia on YUV

Generates [R,G,B] the gradient gray-red-yellow-green-cyan-blue-purple-gray between color 0 and 1 (it is periodic, so any value can be supplied), brigthness is in range 0 (black) to 1 (white)

#### forEachChannel

forEachChannel(…)
Iterates each color-channel, c is the color value (range 0 to 255)

#### forEachChannelXY

forEachChannelXY(…)
Iterates each color-channel, c is the color value (range 0 to 255)

#### forEachChannelA

forEachChannelA(…)
Iterates each color-channel and gives access to nearby pixels, parameters for func are (destinationArray,sourceArray,index,strideY,strideX)

#### forEachPixel

forEachPixel(…)
Iterates each pixel, r,g,b,a is the color component values (range 0 to 255)

#### forEachPixelXY

forEachPixelXY(…)
Iterates each pixel, c is the color value (range 0 to 255)

#### forEachPixelA

forEachPixelA(…)
Iterates each pixel and gives access to nearby pixels, parameters for callback are (destinationArray,sourceArray,index,strideY,strideX), color order is always RGBA

### Generators:

#### gensin

gensin(x)
Sine wave generator, Period 1, out values -1 to 1
Wikipedia on Sine wave

#### gencos

gencos(x)
Cosine wave generator, Period 1, out values -1 to 1
Wikipedia on Sine wave

#### gentri

gentri(x[,n]) n for bandlim.
Triangle wave generator, Period 1, out values -1 to 1
Wikipedia on Triangle wave

#### gensaw

gensaw(x[,n]) n for bandlim.
Sawtooth wave generator, Period 1, out values -1 to 1
Wikipedia on Sawtooth wave

#### gensqr

gensqr(x[,n]) n for bandlim.
Square wave generator, Period 1, out values -1 to 1
Wikipedia on Square wave

#### genpul

genpul(x,d[,n]) n for bandlim.
Pulse wave generator, Period 1, d is the duty cycle, out values -1 to 1
Wikipedia on Pulse wave

#### genrnd

genrnd(x)
Random generator, period 1, out values -1 to 1

#### genrndl

genrndl(x) linear interp.
Random generator, linear interpolation, period 1, out values -1 to 1

#### genrndq

Random generator, quadratic interpolation, Period 1, out values -1 to 1

#### genrndc

genrndc(x) cubic interp.
Random generator, cubic interpolation, Period 1, out values -1 to 1

#### gen

gen(x [,which, n]) all-in-one
Interpolated sequence of generators, Period 1, out values -1 to 1

#### genn

genn(x [,which, n]) 0 to 1
Interpolated sequence of generators, Period 1, out values 0 to 1

### Restrict:

#### min

min(a,b […])
Returns the input that has the lowest value

#### max

max(a,b […])
Returns the input that has the highest value

#### clamp

clamp(x [,min=0,max=1])
Restrict values within an interval (default interval 0 to 1)

#### clampg

clampg(x [,min=0,max=1])
Restrict values within an interval using gaussian distribution

#### clampw

clampw(x [,min=0,max=1])
Restrict values within an interval, wrap if outside

#### clampm

clampm(x [,min=0,max=1])
Restrict values within an interval, mirror if outside

#### clip

clip(x [,min=-1,max=1])
Restrict values within an interval (default interval -1 to 1)

#### clipg

clipg(x [,min=-1,max=1])
Restrict values within an interval using gaussian distribution

#### clipw

clipw(x [,min=-1,max=1])
Restrict values within an interval, wrap if outside

#### clipm

clipm(x [,min=-1,max=1])
Restrict values within an interval, mirror if outside

### Decimate:

#### round

round(x [,decimals] )
Rounding function, rounds to nearest integer (or decimal if defined)
Wikipedia on Rounding

#### floor

floor(x) Floor function
Floor function, rounds down to the integer below
Wikipedia on Floor function

#### ceil

ceil(x) Ceiling function
Ceiling function, rounds up to the integer above
Wikipedia on Ceiling function

#### int

int(x) Integer function

#### sgn

sgn(x) Sign
Sign function,
returns the sign of the value
sgn(x) = -1 if x<0
sgn(x) = 0 if x=0
sgn(x) = 1 if x>0
Wikipedia on Sign Function

#### H

H(x) Heaviside step
Heaviside step function
H(x) = 0 if x<0
H(x) = 1/2 if x=0
H(x) = 1 if x>0
Wikipedia on Heaviside step function

### Number Generation:

#### rnd0

rnd0() Range -1 <1
Random values, [Uniform distribution], interval -1 to <1
Wikipedia on Random number generation

#### rnd

(Alias: random() )

rnd() Range 0 <1
Random values, [Uniform distribution], interval 0 to <1
Wikipedia on Random number generation

#### rndi

rndi(c) Integer, 0 Random integer values, [Uniform distribution], interval 0 to Mad Tea Lab Example
Wikipedia on Random number generation

#### rand

rand() Integer, 0 <232
Random integer values, [Uniform distribution], interval 0 to <2^32 (32 bits)
Wikipedia on Random number generation

#### randn

randn() Normal dist.
Normally distributed random values, Gaussian noise
Wikipedia on Gaussian noise

#### intHash

intHash(x) Integer Hash
Hash function, Integer input, out values 0 to <2^31, based on Bob Jenkins 32 bit hash
Wikipedia on Hash function

#### hash

hash(x) 0 – <1
The intHash() function scaled to the range 0 to <1

#### hash0

hash0(x) -1 – <1
The intHash() function scaled to the range -1 to <1

### Basic Math:

#### sqr

sqr(x) x2 (Square)
Square x
Wikipedia on Square (algebra)

#### cube

cube(x) x3 (Cube)
Cube x
Wikipedia on Cube (algebra)

#### sqrFlip

sqrFlip(x) 1-(1-x)2
Square x Flipped

#### cubeFlip

cubeFlip(x) 1-(1-x)3
Cube x Flipped

#### sqrt

sqrt(x) Square Root
Square Root
Wikipedia on Square Root

#### pow

pow(b,x) bx
Power of, raise b to the power of x
Wikipedia on Exponentiation

#### exp

exp(x) ex
Exponentiation, raise e to the power x
Wikipedia on Exponentiation

#### exp2

exp2(x) 2x
Powers of two, raise 2 to the power of x
Wikipedia on Exponentiation

#### log

(Alias: ln(x) )

log(x) Logarithm (e)
Natural Logarithm, base e logarithm
Wikipedia on Logarithm

#### log10

(Alias: lg(x) )

log10(x) Logarithm (10)
Common Logarithm, base 10 logarithm
Wikipedia on Logarithm

#### log2

(Alias: lb(x) )

log2(x) Logarithm (2)
Binary Logarithm, base 2 logarithm
Wikipedia on Logarithm

#### logx

logx(b,x) Logarithm (b)
The inverse of the pow function (using the same base), calculated log(x)/log(b)
Wikipedia on Logarithm

### Math:

#### isPrime

isPrime(a)
Checks if a number is a prime
Wikipedia on Prime number

#### primes

primes(n)
Returns an array with all the primes in the range 0 to n
Wikipedia on Prime number

#### factor

factor(n) Prime factorization
Returns an array with the integer prime factors of n
Wikipedia on Prime factorization

#### gcd

gcd(u,v) Greatest com. div
The Greatest common divisor of two non-zero integers, is the largest positive integer that divides both numbers without remainder.
Wikipedia on Greatest common divisor

#### lcm

lcm(u,v) Least com. mul
The Least common multiple of two integers a and b is the smallest positive integer that is a multiple both of a and of b.
Wikipedia on Least common multiple

#### fact

fact(n) Factorial
Factorials n>22 are not correct due to precision
Wikipedia on Factorial

#### fibo

fibo(n) Fibonacci nr
Fibonacci numbers, n>70 are not correct due to precision
Wikipedia on Fibonacci number

#### erf

erf(x) Error function
aka Gauss Error function
Wikipedia on Error function

#### erfi

erfi(x) Inverse Error f.
The Inverse of the Gauss Error function
Wikipedia on Error function

#### pascalTriangle

pascalTriangle(rowCount)
Generates a number of rows of Pascals Triangle
Wikipedia on Pascals Triangle

#### ruler

ruler(x,m) (Integers)
The Ruler function, aka Thomaes function, popcorn function, raindrop function, Riemann function
Wikipedia on Ruler function

#### gamma

gamma(x)
The Gamma function (Real values)
Wikipedia on Gamma function

### Trigonometry:

#### sin

sin(x) Sine
Sine
Wikipedia on Sine

#### cos

cos(x) Cosine
Cosine
Wikipedia on Cosine

#### tan

tan(x) Tangent
Tangent
Wikipedia on Trigonometric functions#Tangent

#### abs

abs(x) Absolute value
Absolute Value

|x| = abs(x)
Wikipedia on Absolute value

#### acos

acos(x) Inverse cosine
Inverse Cosine, or Arc Cosine
Wikipedia on Inverse cosine

#### asin

asin(x) Inverse sine
Inverse Sine, or Arc Sine
Wikipedia on Inverse sine

#### atan

atan(x) Inverse tangent
Inverse Tangent, or Arc Tangent
Wikipedia on Inverse tangent

#### atan2

atan2(y,x) Inverse tangent
Inverse Tangent, 2 arguments
Wikipedia on Inverse tangent

#### sinh

sinh(x) Sine Hyperholic
Hyperholic Sine
Wikipedia on Hyperbolic function

#### cosh

cosh(x) Cosine Hyperholic
Hyperholic Cosine
Wikipedia on Hyperbolic function

### Complex Math:

Wikipedia on Complex number

#### cmul

cmul(a,b) a * b
Complex Multiplication
Wikipedia on Complex number

#### csub

csub(a,b) a – b
Complex Subtraction
Wikipedia on Complex number

#### cdiv

cdiv(a,b) a / b
Complex Division
Wikipedia on Complex number

cpow(a,b) ab
Complex Power of

cneg(z) -z
Complex Negation

cinv(z) 1 / z
Complex Inverse

csqr(z) z2
Complex Square

#### cexp

cexp(z) ez
Complex Exponentiation
Wikipedia on Exponential function#On the complex plane

#### clog

clog(z) log(z)
Complex Natural Logarothm
Wikipedia on Complex logarithm

#### cabs

cabs(z) |z|
Complex Absolute value, Magnitude
Wikipedia on Absolute value#Complex numbers

csin(z) sin
Complex Sine

ccos(z) cos
Complex Cosine

#### cconj

cconj(z) Conjugate
Complex Conjugate
Wikipedia on Complex conjugate

### Time:

year()
Get Current Year

#### month

month()
Get Current Month

day()
Get Current Day

hour()
Get Current Hour

#### minute

minute()
Get Current Minute