在可能实现的基础上,尽量完善了一个预置效果功能。希望大家多多共享效果。
复制内容到剪贴板
代码:
#target photoshop
app.bringToFront();
// v1.4 --------- 2008.4.10 wonton
var PRESOLUTION = 72; myPathNum=1;
var startRulerUnits = app.preferences.rulerUnits;
var startTypeUnits = app.preferences.typeUnits;
app.preferences.rulerUnits = Units.PIXELS;
app.preferences.typeUnits = TypeUnits.PIXELS;
res ="dialog { \
text:'XY方程式',\
fun: Group{orientation: 'column',alignChildren:'left',\
save:Group { orientation: 'row', \
s: StaticText { text:'选择预置'}, \
d:DropDownList { alignment:'left', itemSize: [200,16] },\
}, \
newSize:Panel {orientation: 'row',text:'新建文档',\
x: Group { orientation: 'row', \
s: StaticText {text:'图像宽度' }, \
e: EditText { preferredSize: [50, 20] } ,\
s1: StaticText { text:'px ' }, \
}, \
y: Group { orientation: 'row', \
s: StaticText { text:'图像高度' }, \
e: EditText { preferredSize: [50, 20] } ,\
s1: StaticText { text:'px' }, \
}, \
},\
numFirst:Panel {orientation: 'row',text:'初始值',\
x: Group { orientation: 'row', \
s: StaticText {text:'x=' }, \
e: EditText { preferredSize: [40, 20],text:'1'} ,\
}, \
y: Group { orientation: 'row', \
s: StaticText { text:'y=' }, \
e: EditText { preferredSize: [40, 20],text:'1'} ,\
}, \
j: Group { orientation: 'row', \
s: StaticText { text:'j=' }, \
e: EditText { preferredSize: [40, 20] } ,\
}, \
k: Group { orientation: 'row', \
s: StaticText { text:'k=' }, \
e: EditText { preferredSize: [40, 20] } ,\
}, \
},\
line:Panel {orientation: 'column',alignChildren:'left',text:'循环部分',\
xExp: Group { orientation: 'row', \
s: StaticText { text:'1、x=' }, \
e: EditText { preferredSize: [240, 20] } ,\
}, \
yExp: Group { orientation: 'row', \
s: StaticText { text:'2、y=' }, \
e: EditText { preferredSize: [240, 20] } ,\
}, \
point: Group { orientation: 'row', \
s: StaticText { text:'3、确定路径节点 | xy缩放系数:' }, \
ex: EditText { preferredSize: [30, 20],text:'1',helpTip:'x方向整体缩放路径 (x输出值将乘以该系数)' } ,\
ey: EditText { preferredSize: [30, 20],text:'1',helpTip:'y方向整体缩放路径 (y输出值将乘以该系数)' } ,\
}, \
jExp: Group { orientation: 'row', \
s: StaticText { text:'4、j=' }, \
e: EditText { preferredSize: [165, 20] } ,\
s1: StaticText { text:'/' }, \
e1: EditText { preferredSize: [30, 20] ,helpTip:'指定循环几次执行1次运算,留空或为0则不执行',text:'1'} ,\
s2: StaticText { text:'步' }, \
}, \
kExp: Group { orientation: 'row', \
s: StaticText { text:'5、k=' }, \
e: EditText { preferredSize: [165, 20] } ,\
s1: StaticText { text:'/' }, \
e1: EditText { preferredSize: [30, 20] ,helpTip:'指定循环几次执行1次运算,留空或为0则不执行',text:'1'} ,\
s2: StaticText { text:'步' }, \
}, \
}\
other:Panel {orientation: 'column',alignChildren:'left',text:'循环控制',\
n1: Group { orientation: 'row', \
c: Checkbox { text:' 指定步数',helpTip:'按照指定的步数执行,超出画布不作限制'} ,\
e: EditText { preferredSize: [50, 20] } ,\
s: StaticText { text:'步' }, \
}, \
n2: Group { orientation: 'row',\
c: Checkbox { text:' 超出提示',helpTip:'超出一定步数会提示是否中止'} ,\
e: EditText { preferredSize: [50, 20],text:'800' } ,\
s: StaticText { text:'步' }, \
}, \
},\
other1:Group {orientation: 'row',\
brush: Checkbox { text:' 直接用画笔描边路径'} ,\
close: Checkbox { text:' 闭合路径'} ,\
},\
},\
buttons: Group { orientation: 'row', alignment: 'right',\
Btnok: Button { text:'生成'}, \
Btncancel: Button { text:'退出' } \
} \
}";
win = new Window (res);
/////////// 初始化
win.fun.other.n2.c.value = true;
win.fun.other.n1.e.enabled =false;
win.fun.other.n1.s.enabled =false;
if (app.documents.length>0) {win.fun.newSize.enabled =false;}
//////////////
/////////////状态改变
win.fun.other.n1.c.onClick =function(){
if(win.fun.other.n1.e.enabled){
win.fun.other.n1.e.enabled =false;
win.fun.other.n1.s.enabled =false;
win.fun.other.n2.enabled =true;
}else{
win.fun.other.n1.e.enabled =true;
win.fun.other.n1.s.enabled =true;
win.fun.other.n2.enabled =false;
}
}
win.fun.other.n2.c.onClick =function(){
if(win.fun.other.n2.e.enabled){
win.fun.other.n2.e.enabled =false;
win.fun.other.n2.s.enabled =false;
}else{
win.fun.other.n2.e.enabled =true;
win.fun.other.n2.s.enabled =true;
}
}
/////////////
win.buttons.Btncancel.onClick = function () {
app.preferences.rulerUnits = startRulerUnits;
app.preferences.typeUnits = startTypeUnits;
this.parent.parent.close();
}
win.buttons.Btnok.onClick = function () {
var myWidth = Number(win.fun.newSize.x.e.text);
var myHeight = Number(win.fun.newSize.y.e.text);
if (app.documents.length==0) {var docRef = app.documents.add(myWidth, myHeight, 72, 'Simple Line')
}else{
var docRef = app.activeDocument;
myWidth = docRef.width;
myHeight = docRef.height;
}
var x = Number(win.fun.numFirst.x.e.text);
var y = Number(win.fun.numFirst.y.e.text);
var j = Number(win.fun.numFirst.j.e.text);
var k = Number(win.fun.numFirst.k.e.text);
var jNum = Number(win.fun.line.jExp.e1.text);
var kNum = Number(win.fun.line.kExp.e1.text);
var zoomx= Number(win.fun.line.point.ex.text);
zoomx=(zoomx==0 || isNaN(zoomx))?1:zoomx;
var zoomy= Number(win.fun.line.point.ey.text);
zoomy=(zoomy==0 || isNaN(zoomy))?1:zoomy;
var xExp=win.fun.line.xExp.e.text;
var yExp=win.fun.line.yExp.e.text;
var jExp=win.fun.line.jExp.e.text;
var kExp=win.fun.line.kExp.e.text;
var dudu= Number(win.fun.other.n2.e.text);
var i=0;du=0;okGo=true;j1=0;k1=0;
var lineArray = new Array();
while (okGo && i<1000) {
x=eval(xExp);
//x = (x>myWidth)?myWidth;
//x= (x<1)?1:x;
y=eval(yExp);
//var y=Math.sin(j)*100+200; //例子
//y = (y>myHeight)?myHeight:y;
//y = (y<1)?1:y;
lineArray[i] = new PathPointInfo ;
lineArray[i].kind = PointKind.CORNERPOINT ;
lineArray[i].anchor = Array(x*zoomx,y*zoomy) ;
lineArray[i].leftDirection = lineArray[i].anchor ;
lineArray[i].rightDirection = lineArray[i].anchor ;
du++;
i++;
j1++;
k1++;
if (j1>=jNum && jNum!=0){
j1=0;
j=eval(jExp);
}
if (k1>=kNum && kNum!=0){
k1=0;
k=eval(kExp);
}
if (win.fun.other.n1.c.value){
okGo = (i< Number(win.fun.other.n1.e.text));
}else{
okGo = (x<=myWidth && y<=myHeight);
if (win.fun.other.n2.c.value && du>=dudu && i<1000){
du=0;
okGo = confirm("已经执行了"+i+"遍,是否继续?");
}
}
}
//alert(lineArray[i-1].anchor)
if ( i==1000 && Number(win.fun.other.n1.e.text)!=1000) alert("运算超出PS路径上限1000个节点,程序将自动结束绘制!");
var lineSubPathArray = new Array() ;
lineSubPathArray[0] = new SubPathInfo() ;
lineSubPathArray[0].operation = ShapeOperation.SHAPEXOR ;
lineSubPathArray[0].closed = false;
if (win.fun.other1.close.value) lineSubPathArray[0].closed = true;
lineSubPathArray[0].entireSubPath = lineArray;
var myPathItem = docRef.pathItems.add('Line'+myPathNum, lineSubPathArray);
if (win.fun.other1.brush.value) myPathItem.strokePath(ToolType.BRUSH);
//myPathItem.deselect();
myPathNum++;
//this.parent.parent.close(); //执行一次以后自动关闭对话框
}
win.fun.save.d.onChange =function () {//预置应用函数
var i=win.fun.save.d.selection.index;
win.fun.numFirst.x.e.text =showlist[i][1];
win.fun.numFirst.y.e.text =showlist[i][2];
win.fun.numFirst.j.e.text =showlist[i][3];
win.fun.numFirst.k.e.text =showlist[i][4];
win.fun.line.xExp.e.text =showlist[i][5];
win.fun.line.yExp.e.text =showlist[i][6];
win.fun.line.jExp.e.text =showlist[i][7];
win.fun.line.kExp.e.text =showlist[i][8];
win.fun.line.point.ex.text =showlist[i][9];
win.fun.line.point.ey.text =showlist[i][10];
win.fun.line.jExp.e1.text =showlist[i][11];
win.fun.line.kExp.e1.text =showlist[i][12];
win.fun.other.n1.e.text =showlist[i][13];
win.fun.other1.close.value =Number(showlist[i][15]);
if(Number(showlist[i][14])){
win.fun.other.n1.c.value=true;
win.fun.other.n1.e.enabled =true;
win.fun.other.n1.s.enabled =true;
win.fun.other.n2.enabled =false;
}else{
win.fun.other.n1.c.value=false;
&