- 精华
- 活跃值
-
- 积分
- 50
- 违规
-
- 印币
-
- 鲜花值
-
- 在线时间
- 小时
累计签到:5 天 连续签到:1 天
|
//Randomize Colors.
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的数值(数值越大,明度越小)\n";
var line2 = "2) 要随机轮廓色,输入1-100的数值并以英文“S”结尾(数值越大,明度越大)\n";
var line3 = "3) 要随机不透明度,输入1-100的最小值和最大值,如30,100\n";
var data = prompt(line1+line2+line3, "");
if ( data == null || data.length ==0 )
{
//User canceled process or didn't enter anything, so do nothing and end nicely.
} else{
if (data.indexOf(",")>0) {
action = data.split(",");
} else {
action = data.split(" ");
}
//if the 's' is it's own value in the array, detect and snip
if (action[action.length-1] == "s") {
action.length = action.length-1;
strokes = true;
}
// or, detect and snip the 's' from the last number in the array
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)
//alert(action);
strokes = true;
}
var baseVal = action[0];
for (j=0; j<len; j++) {
//
//change OPACITY here
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);
//
//Change COLOR here:
} 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 {
//break
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) {
//do nothing
} else if (obj.typename == "RGBColor") {
//alert("RGB");
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") {
//alert("Spot");
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") {
//alert("Gray");
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") {
//alert("CMYK");
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.");
} else {
//alert("Nuthin...");
}
}
-------------------------------
AI随机填色脚本,复制以上代码到文本,另存为JS格式文件,在AI中脚本调用即可。这个挺老了不知道论坛里有没有
|
|