在可能实现的基础上,尽量完善了一个预置效果功能。希望大家多多共享效果。
复制内容到剪贴板
代码:
#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;
win.fun.other.n1.e.enabled =false;
win.fun.other.n1.s.enabled =false;
win.fun.other.n2.enabled =true;
}
}
//预置方案格式(不需要或为0的可留空):名称, x,y,j,k,x表达式,y表达式,j表达式,k表达式,x缩放,y缩放,j步数,k步数,总步数,是否固定步数(1表示yes/0表示no),是否闭合(1表示yes/0表示no)
var sn =new Array();
sn[0]="正弦曲线,,,.1,,j*100,Math.sin(j)*100,j+.1,,,,1,,,0,0";
sn[1]="半径100的圆(360边形近似),,,1,,100*Math.cos(j*Math.PI/180),100*Math.sin(j*Math.PI/180),j+1,,,,1,,359,1,1";
sn[2]="渐开线,,,.1,,5*j*Math.cos(j),5*j*Math.sin(j),j+.1,,,,1,,1000,1,0";
sn[3]="3叶玫瑰线,,,.01,,250*Math.sin(3*j)*Math.cos(j),250*Math.sin(3*j)*Math.sin(j),j+.01,,,,1,,315,1,1";
sn[4]="五角星,,,,,200*Math.cos(j*Math.PI/180),200*Math.sin(j*Math.PI/180),j+360/5*3,,,,1,,5,1,1";
sn[5]="初速度80,45度角抛物线,,,,,x+80*Math.cos(45*Math.PI/180),y-(80*Math.sin(45*Math.PI/180) - 9.8*j),j+1,,,,1,,,0,0";
sn[6]="随机震荡线(幅度100),,,,,x+3,Math.random()*100,,,,,,,,,";
sn[7]="渐开波纹线,,,,,x+1,Math.sin(Math.sqrt(j))*Math.sqrt(j)*10,j+1,,,,1,,,0,0";
sn[8]="9齿平槽齿轮,,,,20,(100+k)*Math.cos(j*Math.PI/180),(100+k)*Math.sin(j*Math.PI/180),j+10,-k,,,1,2,36,1,1";
sn[9]="怪异齿轮,,,,30,(100+k)*Math.cos(j*Math.PI/180),(100+k)*Math.sin(j*Math.PI/180),j+10,-k,,,3,2,108,1,1";
sn[10]="海星?,,,,,250*Math.sin(5*j)*Math.cos(j),250*Math.sin(5*j)*Math.sin(j),j+.9,,,,1,,720,1,0";
sn[11]="挂坠?,,,1,,Math.sin(j*2)*Math.cos(j)*200,Math.c