YOUR ACCOUNT

Both Map Script and Curve Script components allow you to add custom inputs such as sliders, checkboxes, etc. via the Input Editor dialog. Each input type has a corresponding function that allows you to query the value of a particular input of this type from the script. Inputs are identified by their Script Identifiers specified in the Input Editor. Mappable inputs such as Color Map, Grayscale Map or Curve must be sampled from script's get_sample() function, while numeric inputs such as Slider and Checkbox must be queried from script's prepare() function. This table summarizes the information on input types and their corresponding functions:

Input Type Function Call From
Color Map Inputs r, g, b, a = get_sample_map(x, y, input_id) get_sample()
Grayscale Map Inputs v = get_sample_grayscale(x, y, input_id) get_sample()
Slider Inputs value = get_slider_input(input_id) prepare()
Angle Inputs angle = get_angle_input(input_id) prepare()
Integer Slider Inputs value = get_intslider_input(input_id) prepare()
Checkbox Inputs state = get_checkbox_input(input_id) prepare()
Curve Inputs c = get_sample_curve(x, y, t, input_id) get_sample()

Color Map Inputs

Color Map inputs are sampled by calling the get_sample_map() function with the sample coordinates and input's Script Identifier as arguments. The function returns an RGBA color:

r, g, b, a = get_sample_map(x, y, input_id)

Calls to get_sample_map() must be made from script's get_sample() function. If you call it from script's prepare() function, the script will terminate with an error.

The following example script samples two color map inputs, with Script Identifiers of COLOR1 and COLOR2, and returns their averaged color:

function prepare()
end;

function get_sample(x, y)
	r1,  g1, b1, a1 = get_sample_map(x, y, COLOR1)
	r2,  g2, b2, a2 = get_sample_map(x, y, COLOR2)
	return (r1+r2)/2, (g1+g2)/2, (b1+b2)/2, (a1+a2)/2
end;

Grayscale Map Inputs

Grayscale Map inputs are sampled by calling the get_sample_grayscale() function with the sample coordinates and input's Script Identifier as arguments. The function returns a single numeric value:

v = get_sample_grayscale(x, y, input_id)

Calls to get_sample_grayscale() must be made from script's get_sample() function. If you call it from script's prepare() function, the script will terminate with an error.

The following example script samples two grayscale map inputs, with Script Identifiers of GRAY1 and GRAY2, and mixes the returned grayscale values into the RGB channels of the final color:

function prepare()
end;

function get_sample(x, y)
	v1 = get_sample_grayscale(x, y, GRAY1)
	v2 = get_sample_grayscale(x, y, GRAY2)
	return v1, v2, (v1+v2)/2, 1
end;

Slider Inputs

Slider inputs are queried by calling the get_slider_input() function with the input's Script Identifier as an argument. The function returns the current value of the slider as a number within the range of 0…1:

value = get_slider_input(input_id)

This function must be called from script's prepare() function. If you call it from the get_sample() function, the script will terminate with an error. When storing the returned value in a variable, make sure that the variable is not declared as local, otherwise you won't be able to access its value from script's get_sample() function.

The following example script obtains the value of the slider input with the Script Identifier of SLYDER from within script's prepare() function, stores the result in a variable named v, and uses the variable within the get_sample() function to return a flat color with the brightness matching the slider value:

function prepare()
	v = get_slider_input(SLYDER)
end;

function get_sample(x, y)
	return v, v, v, 1
end;

Angle Inputs

Angle inputs are queried by calling the get_angle_input() function with the input's Script Identifier as an argument. The function returns the value of the input as a number within the range of 0…360:

angle = get_angle_input(input_id)

This function must be called from script's prepare() function. If you call it from the get_sample() function, the script will terminate with an error. When storing the returned value in a variable, make sure that the variable is not declared as local, otherwise you won't be able to access its value from script's get_sample() function.

The following example script obtains the value of the angle input with the Script Identifier of ANGIE from within script's prepare() function, divides it by 360 to bring it into the range of 0…1, stores the result in a variable named a, and uses the variable within the get_sample() function to return a flat color with the brightness defined by the value of the angle input:

function prepare()
	a  = get_angle_input(ANGIE) / 360
end;

function get_sample(x, y)
	return a, a, a, 1
end;

Integer Slider Inputs

Integer slider inputs are queried by calling the get_intslider_input() function with the input's Script Identifier as an argument. The function returns the current value of the slider as a number:

value = get_intslider_input(input_id)

This function must be called from script's prepare() function. If you call it from the get_sample() function, the script will terminate with an error. When storing the returned value in a variable, make sure that the variable is not declared as local, otherwise you won't be able to access its value from script's get_sample() function.

The following example script obtains the value of the integer slider input with the Script Identifier of STEPS from within script's prepare() function, stores the result in a variable named steps, and uses the variable within the get_sample() function to produce a linear gradient with flat steps:

function prepare()
	steps = get_intslider_input(STEPS)
end;

function get_sample(x, y)
	level = 1 / ( steps + 1  )
	v = math.floor( x /  level ) * level
	return v, v, v, 1
end;

Checkbox Inputs

Checkbox inputs are queried by calling the get_checkbox_input() function with the input's Script Identifier as an argument. The function returns true or false, depending on the state of the checkbox control.

state = get_checkbox_input(input_id)

This function must be called from script's prepare() function. If you call it from the get_sample() function, the script will terminate with an error. When storing the returned value in a variable, make sure that the variable is not declared as local, otherwise you won't be able to access its value from script's get_sample() function.

The following example script queries the state of a checkbox input with the Script Identifier of TICK from within script's prepare() function, stores the result in a variable named chk, and reads the value of the variable within the get_sample() function:

function prepare()
	chk = get_checkbox_input(TICK)
end;

function get_sample(x, y)
	if chk then
		return  1, 1, 1, 1
	else
    	return  0, 0, 0, 1
	end;
end;

Curve Inputs

Curve inputs are sampled by calling the get_sample_curve() function with the sample coordinates, curve argument value and input's Script Identifier as arguments:

c = get_sample_curve(x, y, t, input_id)

Calls to get_sample_curve() must be made from the script's get_sample() function. If you call it from the prepare() function, the script will terminate with an error.

The following example script samples a curve input with the Script Identifier of PROFILE and produces a remapped radial gradient. Don't forget to connect a curve component to the input when running this example:

function prepare()
end;

function get_sample(x, y)
	distance = math.sqrt  (x*x + y*y)
c = get_sample_curve(x, y, distance, PROFILE) return c, c, c, 1 end;