Color scripts are used to define the behaviour of the script brush tool and the "run a color script" color action. They describe a color to color transformation.
Note:
They may be written to produce side effects, though this will adversely impact performance.
How color scripts must be structured to be accepted by the program
In addition to being valid DeltaScript scripts, color scripts must take a single color
parameter1, 2 and return a color
. Thus, the head function of a color script should be of the following form3:
(color c -> color) {
// contents here...
}
Note:
1 - The parameter name c
is merely used as an example.
2 - The parameter represented by c
can optionally be declared as immutable by prepending final
or ~
to the declaration. For example:
(~ color c -> color) { /* contents here... */ }
3 - Color scripts do not need to have complex function bodies { ... }
. For example, the following color script is valid:
(color c -> color) -> rgb(c.r, 0, c.b / 2)
(~ color c -> color) {
~ int total = c.r + c.g + c.b;
~ int avg = total / 3;
return rgba(avg, avg, avg, c.a);
}
This script takes the input color c
and returns a shade of grey with the same lightness as c
(black or white in extreme cases). This is done by averaging out c
's red, green and blue color channels.
This script does not utilize any functions from the scripting API.
However, it makes use of the rgba(int r, int g, int b, int alpha) -> color
function from the DeltaScript base language standard library.
SEE ALSO