QQ登录

只需一步,快速开始

查看: 5134|回复: 0
收起左侧

AI随机填充色、轮廓色、不透明度脚本

[复制链接]
累计签到:5 天
连续签到:1 天
发表于 2022-8-22 20:14:11 | 显示全部楼层 |阅读模式
//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中脚本调用即可。这个挺老了不知道论坛里有没有

华印网相关搜索

您需要登录后才可以回帖 登录 | 注册帐号

本版积分规则

关闭

注意注意注意:必看上一条 /1 下一条

华印网 - 华印社区
Share More 周一至周日:09:00 - 21:00
华印网旗下的设计印刷制作类专业技术站点
请勿发布违反国家法律法规的内容,会员观点不代表本站立场
企鹅群号:119572101

华印网汇集印前印后技术、PDF拼版、防伪包装、数码印刷、合版印刷、图文设计、平面设计、数码印刷及CTP等最新印刷技术,提供软件汉化、插件汉化、cdr插件、ai插件、ps插件、pdf插件、印刷流程、ctp输出、印刷软件、印能捷、esko、CorelDRAW、InDesign、Illustrator、CTP、CDR以及PDF软件下载的综合性印刷论坛社区!

Powered by Discuz! X3.4 © 2001-2021,Tencent Cloud.

站点地图|小黑屋|手机版|Archiver|华印 ( 粤ICP备19020152号-1 )

GMT+8, 2024-11-22 04:28 , Processed in 0.028806 second(s), 20 queries , Gzip On, Yac On.

快速回复 返回顶部 返回列表