|

楼主 |
发表于 2003-7-2 14:49:15
|
显示全部楼层
script-fu就是一系列gimp动作,会photoshop的兄弟会说我们可以在ps里面用action同样可以记录动作而且狠方便,调节度也很大。但是script-fu作为从lisp衍生出来的一种东东,功能远不止是批处理。
你可以在script里面实现数学计算,if,while流程控制,甚至是子程序调用。下面看看怎么用了哦。NOW WE CAN START REAL ROCK&ROLL。HEI HEI
下面这个代码是一个简单的递归调用绘制一个分形图案 ( PS卫道者要吐血了 ),很久不写程序了各位学CS的大哥不要因为丑陋的代码来砍我。
还是拷贝到那个目录,然后更新script-fu,这里我随便插一句,你每次改动了你的脚本的时候都要更新script,才可以在gimp里面生效。
- ; 下面这个小routine是从yahoo的script-fu group抄来的
- ; 有一些小改动, 注意这个里面使用了浮点数组, 嘿嘿
- ; script 强吧. yahoo那个group不错, 可以看看
- (define (script-drawline img xcoord ycoord xcoord2 ycoord2)
- (set! thecoords (cons-array 6 'double))
- (aset thecoords 0 xcoord)
- (aset thecoords 1 ycoord)
- (aset thecoords 2 xcoord2)
- (aset thecoords 3 ycoord2)
- (gimp-pencil (car (gimp-image-active-drawable img)) 4 thecoords)
- ; 这里的 (car (gimp-image-active-drawable img)) 狠有用
- ; 是从当前image提取drawable, 我还不太明白啥是drawable
- ; 但是有这个语句就无所谓了.
- (gimp-displays-flush)
- )
- (define (draw-edge image sx sy fx fy)
- (let* ( ; 下面是一堆付值和计算, 当笑话看吧,
- (distance (sqrt (+ (pow (- sx fx) 2)
- (pow (- fy sy) 2))))
- (xstep (/ (- fx sx) 3))
- (ystep (/ (- fy sy) 3))
- (c1x (+ sx xstep))
- (c1y (+ sy ystep))
- (vertexx (- (+ c1x (/ xstep 2)) (* ystep 0.86603)))
- (vertexy (+ (+ c1y (/ ystep 2)) (* xstep 0.86603)))
- (c2x (+ c1x xstep))
- (c2y (+ c1y ystep))
- )
- (if (> distance 1)
- ; if是一个狠tricky的语句, 费了我不少心思figure out 文档太少了 :(
- ; if 后面的是 逻辑判断, 一目了然, TRUE或者1 FALSE或者0
- ; 逻辑判断后面的 ( ) 是如果为真的时候执行的语句
- ; 不是象有一个xx文档说的是好几条, 只能有一条哦.
- ; (begin .... ) 的结构是符合语句
- ; 然后在后面第二个 ( ) 是else时候执行的.
- (begin
- (script-drawline image c1x c1y sx sy)
- (script-drawline image c2x c2y fx fy)
- (draw-edge image vertexx vertexy c2x c2y)
- (draw-edge image c1x c1y vertexx vertexy)
- ; 调用画线的程序和递归.
- ))
- )
- )
- (define (doooom-fractal-art width)
- (let* ((image (car (gimp-image-new width (/ width 3) RGB)))
- (layer (car (gimp-layer-new image width (/ width 3)
- RGB-IMAGE "foobar" 100 NORMAL-MODE))) )
- (gimp-drawable-fill layer BG-IMAGE-FILL)
- (gimp-image-add-layer image layer 0)
- (gimp-display-new image)
- ; 前面这一部分也是抄的, 建立一个新图象, 加一个新layer
- ; 具体可以参见那个文档,你肯定从google里面找到了
- ; 因为一共就那么几个文档, 呵呵
- (draw-edge image 0 4 (- width 1) 4 )
- (gimp-displays-flush)
- )
- )
- ; =====================================
- ; <toolbox> 是注册在主菜单的意思, 后面随意
- (script-fu-register "doooom-fractal-art"
- "<Toolbox>/Xtns/Script-Fu/Linuxsir/Fractal Art..."
- "Draw some fractal art blah blah"
- "doooom at linuxsir"
- "doooom"
- "June 2003"
- ""
- SF-VALUE "Canvas Width" "300"
- )
复制代码
执行的时候,在菜单选择 xtns 》 script-fu 》linuxsir 》fractal art,然后指定想要的图片宽度,还有就是指定好颜色和画笔,建议用小点的笔头哦。
执行结果:
|
|