illustrator外掛--常用功能開發--隨機填色--js指令碼開發--AI外掛
阿新 • • 發佈:2020-12-29
技術標籤:Adobe Illustrate外掛開發illustrator外掛常用功能開發隨機填色js指令碼開發AI外掛
illustrator是向量編輯軟體,畫板是繪製處理的重要容器,在印刷方面的一個重要功能就是顏色處理,開發一個隨機填充顏色功能,以下功能僅用於學習交流,請勿用於非法用途和商業用途,原始碼如下所示:
len = app.activeDocument.selection.length;
gradAlert = 0;
strokes = false;
if (len == 0) {
alert("Please select one or more objects. Grouped objects will not be affected." );
} else {
ob = app.activeDocument.selection;
var line1 = "1. 要隨機填充色,輸入1-100的數值(數值越大,明度越小) ";
var line2 = "2.要隨機輪廓色,輸入1-100的數值並以英文“S”結尾(數值越大,明度越大) ";
var line3 = "3.要隨機不透明度,輸入1-100的最小值和最大值,如30,100 ";
var data = prompt(line1 + line2 + line3, "");
if (data == null || data.length == 0) {
} else {
if (data.indexOf(",") > 0) {
action = data.split(",");
} else {
action = data.split(" ");
}
if (action[action.length - 1] == "s") {
action. length = action.length - 1;
strokes = true;
}
if (action[action.length - 1].charAt(action[action.length - 1].length - 1) == "s") {
action[action.length - 1] = action[action.length - 1].substr(0, action[action.length - 1].length - 1);
strokes = true;
}
var baseVal = action[0];
for (var j = 0; j < len; j += 1) {
if (isNumber(action[0]) && isNumber(action[1]) && action.length == 2) {
calcNum = (action[0] * 1) + (Math.random(1) * (action[1] - action[0]));
ob[j].opacity = setLegal(calcNum);
} else if (isNumber(action[0], 255) && action.length == 1) {
if (app.activeDocument.documentColorSpace == "DocumentColorSpace.RGB") {
action[0] = Math.round(baseVal * 2.55);
}
if (strokes == false) {
if (ob[j].filled == true) {
setColor(ob[j].fillColor, setLegal(action[0], 255));
}
} else {
if (ob[j].stroked == true) {
setColor(ob[j].strokeColor, setLegal(action[0], 255));
}
}
} else {
j = len;
error(action[0]);
}
}
}
}
function error(val) {
alert(val + " 數值與指令碼不符,應控制在1-100之間!");
}
function isNumber(num, max) {
if (max == undefined) {
max = 100;
}
if (num >= 0 && num <= max) {
return true;
}
return false;
}
function setLegal(num, max) {
if (max == undefined) {
max = 100;
}
if (num < 0) {
return -num % max;
} else if (num > max) {
return max - (num % max);
} else {
return num;
}
}
function setColor(obj, dev) {
var d = Math.round(Math.random(1) * dev);
if (obj == undefined) {
} else if (obj.typename == "RGBColor") {
d = Math.round(Math.random(1) * dev);
var r = obj.red;
obj.red = setLegal((r - dev) + (d * 2), 255);
d = Math.round(Math.random(1) * dev);
var g = obj.green;
obj.green = setLegal((g - dev) + (d * 2), 255);
d = Math.round(Math.random(1) * dev);
var b = obj.blue;
obj.blue = setLegal((b - dev) + (d * 2), 255);
} else if (obj.typename == "SpotColor") {
var d = Math.round(Math.random(1) * dev);
var t = obj.tint;
obj.tint = setLegal((t - dev) + (d * 2), 100);
} else if (obj.typename == "GrayColor") {
var d = Math.round(Math.random(1) * dev);
var t = obj.gray;
obj.gray = setLegal((t - dev) + (d * 2), 100);
} else if (obj.typename == "CMYKColor") {
d = Math.round(Math.random(1) * dev);
var c = obj.cyan;
obj.cyan = setLegal((c - dev) + (d * 2), 100);
d = Math.round(Math.random(1) * dev);
var m = obj.magenta;
obj.magenta = setLegal((m - dev) + (d * 2), 100);
d = Math.round(Math.random(1) * dev);
var y = obj.yellow;
obj.yellow = setLegal((y - dev) + (d * 2), 100);
d = Math.round(Math.random(1) * dev);
var k = obj.black;
obj.black = setLegal((k - dev) + (d * 2), 100);
} else {
if (gradAlert != 1 && obj.typename == "PatternColor" || obj.typename == "GradientColor") {
gradAlert = 1;
alert("Patterns and Gradients will not be transformed.");
}
}
}
合理的指令碼程式碼可以有效的提高工作效率,減少重複勞動。
歡迎光臨知了軟體開發網路平臺,本公司定製開發各類軟體,主要方向為桌面專業軟體開發和外掛定製開發,桌面軟體主要包括文字圖形識別類軟體,資訊管理類軟體,3D列印類軟體,視訊類軟體以及其它涉及專業的各類圖形影象處理軟體。外掛包含AE外掛,AI外掛,PS外掛,PDF外掛,3DMAX外掛以及Word,Excel等Office外掛開發。詳情請諮詢,微信QQ:312117271,手機:18928899728,郵箱: [email protected]
公司網址:http://www.zhiliaos.com