動畫/插畫製作中,同一顏色的高光/陰影變體需求頻繁。此腳本自動根據當前填色,按預設或自訂偏移量生成「基礎色、高光色、陰影色」三色票,極大加速配色流程。
/////////////////////////////////////////////////////////////////
//Add Highlight And Shadow Swatches v.1 -- CS, CS2
//>=--------------------------------------
// A simple script for Animators. Takes current fill color from color pallate.
// a prompt will ask you to name the color, then it adds it to the swatch palate,
// along with the highlight and shadow for that color.
////
// feel free to tweak the values to get whatever percentages work best for you.
////
//>=--------------------------------------
// JS code (c) copyright: John Wundes ( john@wundes.com ) www.wundes.com
//copyright full text here: https://www.wundes.com/js4ai/copyright.txt
/////////////////////////////////////////////////////////////////
var docRef = app.activeDocument;
if (app.documents.length > 0) {
// RGB 高光/陰影偏移值
RGBdarkenBy = -35;
RGBlightenBy = 75; // 原碼 75, 文中說 +35, 以代碼為準
// CMYK 高光/陰影偏移值
CMYKdarkenBy = 10;
CMYKlightenBy = -18;
defName = "";
nameMsg = "該填充色及其高光和陰影將被添加到色板中。默認RGB高光所有值+75、陰影-35;CMYK高光所有值-18%、陰影+10%。現在請為該填充色命名:";
// 獲取顏色空間名稱
t = [];
t = ((activeDocument.documentColorSpace)+"").split(".");
colSpace = t[1];
try{
var fill = docRef.defaultFillColor;
if(docRef.defaultFilled == false){
throw ("抱歉,沒有找到填充色,請重新選擇。");
}
if (fill.typename != "SpotColor" && fill.typename != "RGBColor" && fill.typename != "CMYKColor") {
throw("Sorry, "+fill.typename+" Objects are not currently supported.\nPlease convert the color to "+colSpace+".");
}
if(fill.typename == "SpotColor"){
nameMsg += "■警告■你選擇了一個專色,該顏色會被轉換到當前文檔的顏色空間中。";
fill = docRef.defaultFillColor.spot.color;
defName = colSpace+"("+docRef.defaultFillColor.spot.name+")";
}
if(fill.typename == "RGBColor"){
fr = roundHack(fill.red);
fg = roundHack(fill.green);
fb = roundHack(fill.blue);
if (defName.length < 1) { defName = "r="+fr+" g="+fg+" b="+fb; }
colName = getName();
makeColor([fr,fg,fb], RGBlightenBy, colName+" 的高光");
makeColor([fr,fg,fb], 0, colName);
makeColor([fr,fg,fb], RGBdarkenBy, colName+" 的陰影");
} else if(fill.typename == "CMYKColor"){
fc = roundHack(fill.cyan);
fm = roundHack(fill.magenta);
fy = roundHack(fill.yellow);
fk = roundHack(fill.black);
if (defName.length < 1) { defName = "c="+fc+" m="+fm+" y="+fy+" k="+fk; }
colName = getName();
makeColor([fc,fm,fy,fk], CMYKlightenBy, colName+" 的高光");
makeColor([fc,fm,fy,fk], 0, colName);
makeColor([fc,fm,fy,fk], CMYKdarkenBy, colName+" 的陰影");
}
}
catch(e) { alert("請確認:\n"+e); }
}
function getName(){
x = prompt(nameMsg, defName);
if (x == null) { throw "操作被取消!"; }
return x;
}
function makeColor(arr, offset, cname){
for (each in arr) {
arr[each] = parseInt(arr[each]);
arr[each] += offset;
}
if(arr.length == 3){
var nc = new RGBColor();
nc.red = limit(arr[0], 255);
nc.green = limit(arr[1], 255);
nc.blue = limit(arr[2], 255);
} else if (arr.length == 4){
var nc = new CMYKColor();
nc.cyan = limit(arr[0], 100);
nc.magenta = limit(arr[1], 100);
nc.yellow = limit(arr[2], 100);
nc.black = limit(arr[3], 100);
}
var col = docRef.swatches.add();
col.name = cname;
col.color = nc;
}
function roundHack(n){
n = n +""; ta = n.split("."); return ta[0];
}
function limit(num, max){
if (num <= 0) return 0;
else if(num > max) return max;
else return num;
}

將重複的色值計算交給腳本,設計師專注於色彩決策本身。