You can play around with the brightness and saturation levels:
Code:
function rgbToHsv(r, g, b){
r = r/255, g = g/255, b = b/255;
var max = Math.max(r, g, b), min = Math.min(r, g, b);
var h, s, v = max;
var d = max - min;
s = max == 0 ? 0 : d / max;
if(max == min){
h = 0; // achromatic
}else{
switch(max){
case r: h = (g - b) / d + (g < b ? 6 : 0); break;
case g: h = (b - r) / d + 2; break;
case b: h = (r - g) / d + 4; break;
}
h /= 6;
}
return [h, s, v];
}
function changeMaskColors() {
app.beginUndoGroup ( "Change Mask Colors");
if (!app.project || !(app.project.activeItem instanceof CompItem) || app.project.activeItem.selectedLayers < 1) {
alert ("Please select at least one layer");
return;
}
var curItem = app.project.activeItem; // current composition
var curLayers = curItem.selectedLayers; // currently selected layers
var curLayer;
var numMasks;
var colorR, colorG, colorB;
var saturation = .7; // set values 0 to 1
var brightness = .7; // set values .01 to .99
var myHsl = [];
var maskColor;
var maskHue = [0,0,0];
if (saturation < 0 || saturation > 1) {
alert ("Invalid saturation number");
return;
}
if (brightness <= 0 || brightness >= 1) {
alert ("Invalid brightness number");
return;
}
for (i = 0; i < curLayers.length; i++) {
curLayer = curLayers[i];
numMasks = curLayer.Masks.numProperties; // number of masks on the current layer
for (j = 1; j <= numMasks; j++) {
if (j > 1) {
maskColor = curLayer.property("Masks").property(j-1).color;
maskHue = rgbToHsl(maskColor[0], maskColor[1], maskColor[2]);
}
colorR = colorG = colorB = 0;
myHsl = [0,0,0];
while (myHsl[2] < brightness || myHsl[1] < saturation || Math.abs(myHsl[0] - maskHue[0]) < 1/numMasks ) {
colorR = Math.round( Math.random()*254);
colorG = Math.round( Math.random()*254);
colorB = Math.round( Math.random()*254);
myHsl = rgbToHsv (colorR, colorG, colorB);
}
curLayer.property("Masks").property(j).color = [colorR/255,colorG/255,colorB/255];
}
}
app.endUndoGroup ();
}
changeMaskColors();