Functions Index :: A :: ArrayOpArrayFunc

[<< up one level]

Module:

array :: operators

Definition:

ArrayOpArrayFunc(string array1, string array2, string func, string "args")

Description:

Performs an operation of a function onto all pairs of corresponding elements of two arrays (ie func(array1[i], array2[i], ...)) and returns the resulting array.

Arguments:

array1: The array who's elements will be the first argument of func.

array2: The array who's elements will be the second argument of func.

func: The name of a function that accepts two required arguments and possibly an arbitrary number of optional arguments (see args, below).

"args" (Optional, defaults to ""): A string in the form of a function call argument list (ie a comma delimited list of values) containing additional arguments to be passed to the func function.

Notes and conditions on arguments relations:

1] func must accept two required argument with types compatible to array1 and array2 elements' type(s). The arguments must be the first in func's argument list. An arbitrary number of other (possibly optional) arguments is allowed, but if any of them is not optional it must always be specified in args.

2] The types of array1 and array2 elements need not be the same. The only requirement is that func can accept them.

3] The args argument list string can only contain value literals and global names (expressions of them are supported also). Use the String() function to convert local variables to value literals.

Examples:

Function xrot(int x, int y, float angle) {

return Round(x*Cos(angle) - y*Sin(angle))

}

Function yrot(int x, int y, float angle) {

return Round(x*Sin(angle) + y*Cos(angle))

}

# lets define a curve and rotate it by 30 degrees

xs = "0,40,80,120,160,200,240"

ys = "0,40,120,220,280,320,340"

xs_30 = ArrayOpArrayFunc(xs, ys, "xrot", String(Pi()/6))

ys_30 = ArrayOpArrayFunc(xs, ys, "yrot", String(Pi()/6))

...

# function to extract a number of frames from a clip

Function mytrim(clip c, int frames) { return c.Trim(0, -frames) }

# lets create arrays of clips and frames

# and then perform a batch Trim on all clips

ac = ArrayCreate(AVISource(.1.), ..., AVISource(.8.))

fn = "400,300,400,500,1200,600,400,900"

ac_trim = ArrayOpArrayFunc(ac, fn, "mytrim") # done

 

[<< top]

 

More examples and in-depth explanation of operator functions can be found at the "Container operators" tutorial.