打印

[作品] 发一个函数脚本 -- 4月10日更新(添加预置效果,方便储存)

本主题由 System 于 2008-6-8 05:00 解除限时高亮
脚本是挺好玩的。也试着搞了一个 (不知道cs3以下版本能不能用)

发现了一些问题,后来查明是 ps 一条路径最多只能有1000个节点的原因(或者是数组限制~) 现已修正。

有心情的朋友帮忙继续测试一下,毕竟一个人想到得很有限。
(拷贝jsx文件到 "ps安装目录\Presets\Scripts" 目录下 或者 "ps安装目录/预置/脚本"目录下~~ 即可从 "菜单-文件-脚本" 里面找到这个脚本)

尚待完善中~~~ 希望多提宝贵意见 ~

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 更新

1、添加了一个变量k ,可以加入更多变化。当然和j一样,不用的话也可以空置。
2、增加了直接闭合路径的选择,可以自动闭合路径首尾。
3、为变量j,k 增加了循环步数设定,可以设定为循环n次才计算一次。(方便画齿轮了)
4、增加整体缩放控制,轻松控制路径尺寸 及镜像路径(取负值即为镜像)。
5、添加预置功能,方便修改。可以把你自己喜欢的配置写到脚本里(用记事本编辑脚本文件即可),下次就可以直接使用了。

~~~~~~~~~ ps:由于没找到调用和编写文件的方法,所以只能通过手工修改脚本来实现了。麻烦了点
本想做保存/删除等功能的~ 可能不太现实了。
希望大家把自己觉得漂亮的表达式串(写法规则脚本里面有)粘贴出来,大家共享,资源就多多了





~~~~~~~~~~~~~~~~~~~~~~~~~~~~~以下为参考效果





















[ 本帖最后由 wonton 于 2008-4-10 14:31 编辑 ]
附件: 您所在的用户组无法下载或查看附件,您需要注册/登录后才能查看!
本帖最近评分记录
  • liuxinghonglei 威望 +5 馄钝MM这个研究的精神值得鼓励啊 2008-3-7 17:59
发帖前请搜索,回帖前请仔细看清楼上每一层。大家的批评意见要虚心接受。有错误要积极承认。 论坛的交流气氛要和谐!内容重复和无实际意义的帖子要少发。
忘了说了,表达式的写法要用 javascript 标准的。

而且要包含变量 j 或者x,y表达式 ,不然不会有变化.

附上 Math 对象的介绍 :http://www.w3class.com/js/jsref_obj_math.asp

~~~~~~~~~~~~~
不设定步数的时候 ,要让xy 往超出画布尺寸的正方向发展 ~
也就是 xy 的值要尽量为正,且慢慢超出画布。

因为现在跳出循环的判断依据是 “x/y坐标 超出了画布右侧/下侧”

或者改为一个循环步数~ 用人为设定。

~~~~~~~~~~~~

另外画布尺寸只有在当前没有文档,自动新建时才有效,

否则就在当前文档上直接画路径了。

可以在当前文档连续生成,修改表达式直到你满意~

~~~~~~~~~~~~

路径所有节点 都是角点,也就是不平滑的点。

所以如果感觉曲线不舒服的话,就要适当的调节增量 或者控制参数使曲线在当前尺度上看起来圆滑

[ 本帖最后由 wonton 于 2008-3-7 17:14 编辑 ]
发帖前请搜索,回帖前请仔细看清楼上每一层。大家的批评意见要虚心接受。有错误要积极承认。 论坛的交流气氛要和谐!内容重复和无实际意义的帖子要少发。
这么高深?用在什么时候呢?

回复 #3 zy19801021 的帖子

看有没有需要了,效果要靠表达式写出来的~ 生成的是路径,可以拿来描边等等~



主要是对ps功能的一个扩展。



[ 本帖最后由 wonton 于 2008-3-7 10:32 编辑 ]
附件: 您所在的用户组无法下载或查看附件,您需要注册/登录后才能查看!
发帖前请搜索,回帖前请仔细看清楼上每一层。大家的批评意见要虚心接受。有错误要积极承认。 论坛的交流气氛要和谐!内容重复和无实际意义的帖子要少发。

TOP

还在为头像烦恼?还在为不能关注好友动态烦忧?快来蓝色理想家园吧!
cs3的好高级,我机子速度还只能是7.0的。
那些函数真是看得晕忽忽的。
年关了...
土匪又浩浩荡荡的进城了.

TOP

我也玩了一会 本来说玩一会就要干活的 玩着玩着就6点了

[ 本帖最后由 liuxinghonglei 于 2008-3-7 18:10 编辑 ]
附件: 您所在的用户组无法下载或查看附件,您需要注册/登录后才能查看!
能动手的 ,就别吵吵

TOP

PS有直接函数编写界面么??
银子博客
经典站长QQ群:16719484
第三届经典论坛灌水王选举(12月1日-12月31日) 敬请期待

TOP

回复 #7 wuleying 的帖子

ps脚本可以编写界面;还可以调用 flashUI,可以做得很漂亮。

不过flash 我就玩不转了。
发帖前请搜索,回帖前请仔细看清楼上每一层。大家的批评意见要虚心接受。有错误要积极承认。 论坛的交流气氛要和谐!内容重复和无实际意义的帖子要少发。

TOP

顶馄饨    能不能附带点 方程式  ?  
老百姓都是猪和兔子,公务员都是鸭子 大师是乌龟!

TOP

回复 #9 No01 的帖子

弄了几个基础的,都放在1楼截图里面了~

稍微修改修改就有无数变化。

也希望大家把漂亮的算式都贴上来
发帖前请搜索,回帖前请仔细看清楼上每一层。大家的批评意见要虚心接受。有错误要积极承认。 论坛的交流气氛要和谐!内容重复和无实际意义的帖子要少发。

TOP

弄了几个 越弄越强大
附件: 您所在的用户组无法下载或查看附件,您需要注册/登录后才能查看!
能动手的 ,就别吵吵

TOP

这很像以前搞的FLASH AS 百行代码编写效果
心在天山,身老沧州。

TOP

引用:
原帖由 onlyme 于 2008-3-7 19:28 发表
这很像以前搞的FLASH AS 百行代码编写效果
多谢你还记得,哈哈~
好像03的事了
不过要求不是百行代码
是生成的swf不超过2003各字节
把无知当武器?
http://byjog.com/blog重新开张啦

TOP

好厉害,数学学得真好啊,我函数都忘光了

TOP

发现ctrl+r打开标尺,然后把0,0点拖动到画面中心,就不用修正 x,y 坐标了。

不然的话生成的路径常常在画面左上角。

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 顺便补充一些方程供参考

///////////////////////////////////////////////////////////////

j=0
~~~~~~~~~~~~~~~~~~~~~~
x=Math.random()*200*Math.sin(j*Math.PI/180)
y=x*Math.tan(j*Math.PI/180)
j=j+1



///////////////////////////////////////////////////////////////

x=1
j=0
~~~~~~~~~~~~~~~~~~~~~~
x=x+2
y=Math.random()*200*Math.sin(j*Math.PI/180)
j=j+1



///////////////////////////////////////////////////////////////

j=0
~~~~~~~~~~~~~~~~~~~~~~
x=(Math.random()*100+100)*Math.cos(j*Math.PI/180)
y=x*Math.tan(j*Math.PI/180)
j=j+1



///////////////////////////////////////////////////////////////

j=0
~~~~~~~~~~~~~~~~~~~~~~
x=100*Math.cos(j*Math.PI/180)+Math.cos(j)*100
y=100*Math.sin(j*Math.PI/180)+Math.sin(j)*100
j=j+.25



///////////////////////////////////////////////////////////////

j=0
~~~~~~~~~~~~~~~~~~~~~~
x=200*Math.cos(j*Math.PI/200)-Math.cos(j)*160
y=100*Math.sin(j*Math.PI/260)*Math.cos(j)*3
j=j+.5



///////////////////////////////////////////////////////////////

j=0
~~~~~~~~~~~~~~~~~~~~~~
x=200*Math.cos(j*Math.PI/180)
y=200*Math.sin(j*Math.PI/180)
j=j+360/5*3
~~~~~~~~~~~~~~~~~~~~~~
6 times



///////////////////////////////////////////////////////////////

j=0
k=30
~~~~~~~~~~~~~~~~~~~~~~
x=(100+k)*Math.cos(j*Math.PI/180)
y=(100+k)*Math.sin(j*Math.PI/180)
j=j+10       (每3步)
k=-k       (每2步)
~~~~~~~~~~~~~~~~~~~~~~
循环108 times ,闭合



///////////////////////////////////////////////////////////////

j=0
~~~~~~~~~~~~~~~~~~~~~~
x=x+1
y=Math.sin(Math.sqrt(j))*Math.sqrt(j)*10
j=j+1



///////////////////////////////////////////////////////////////

j=0
~~~~~~~~~~~~~~~~~~~~~~
x=x+80*Math.cos(45*Math.PI/180)
y=y-(80*Math.sin(45*Math.PI/180) - 9.8*j)
j=j+1
~~~~~~~~~~~~~~~~~~~~~~

说明:初速度80,45度角射出的物体轨迹。 重力加速度9.8,步数表示时间

///////////////////////////////////////////////////////////////

[ 本帖最后由 wonton 于 2008-3-9 14:28 编辑 ]
附件: 您所在的用户组无法下载或查看附件,您需要注册/登录后才能查看!
发帖前请搜索,回帖前请仔细看清楼上每一层。大家的批评意见要虚心接受。有错误要积极承认。 论坛的交流气氛要和谐!内容重复和无实际意义的帖子要少发。

TOP

以后PS跟FL一样开始用起脚本语言后(pscript cs5),WONTON就是ADOBE的大恩人~ 
专带小提琴抢银行!

TOP

回复 #16 ruinsky 的帖子

惭愧,其实早就有很多人在搞了.用脚本丰富ps各个方面的功能,

尤其是重复运算处理和需要判断方面的问题
发帖前请搜索,回帖前请仔细看清楼上每一层。大家的批评意见要虚心接受。有错误要积极承认。 论坛的交流气氛要和谐!内容重复和无实际意义的帖子要少发。

TOP

烧麦斑斑这个东西确实是太好了~~
圆通快递是垃圾!

TOP

馄饨最好能把PS的脚本指南翻译出本书,最好不过了
技术+创意+审美+细心=设计成功的法宝

TOP

  很好,很实用。能出非常漂亮的结果/

TOP

哦,我得妈呀,太遥远了,函数都出来了。了~了·~了~(回声)

TOP

让我回想起在学习机上用海龟画图的时代……
◆下载 ColorKey Xp 解决色彩问题
我和你之间的距离是你和我的距离

TOP

针对有的朋友反映输入麻烦的问题,

在可能实现的基础上,尽量完善了一个预置效果功能。希望大家多多共享效果。
复制内容到剪贴板
代码:
#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;
      &