; The GIMP -- an image manipulation program ; Copyright (C) 1995 Spencer Kimball and Peter Mattis ; ; Draw dotted imgae script for GIMP 1.2 ; Copyright (C) 2001 Iccii ; ; -------------------------------------------------------------------- ; version 0.1 by Iccii 2001/07/17 ; - Initial relase ; version 0.1a by Iccii 2001/07/18 ; - Add BG color/layer-opacity option ; version 0.1b by Iccii 2001/07/24 ; - Remove BG color/layer-opacity option ; - Optimize (speed up) ...thanks to Sakai ; version 0.1c by Iccii 2001/08/21 ; - Added this line: (define (list-ref l n) (nth n l)) ; version 0.2 by Iccii 2002/05/20 ; - Re-written all code (totally new algorithm) ; - Enable brush stroke, angle, coloring, etc ; version 0.3 Raymond Ostertag 2004/09 ; - Ported to Gimp2 ; - Changed menu entry ; -------------------------------------------------------------------- ; ; This program is free software; you can redistribute it and/or modify ; it under the terms of the GNU General Public License as published by ; the Free Software Foundation; either version 2 of the License, or ; (at your option) any later version. ; ; This program is distributed in the hope that it will be useful, ; but WITHOUT ANY WARRANTY; without even the implied warranty of ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ; GNU General Public License for more details. ; ; You should have received a copy of the GNU General Public License ; along with this program; if not, write to the Free Software ; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ; ;; 点描スクリプト (define (script-fu-paint-dot-image img ;; 対象画像 layer ;; 対象レイヤー tool-type ;; 描画ツールの種類 density ;; 描画の繰り返し回数 brush ;; 描画に使用するブラシの種類 lengths ;; ブラシストロークの長さ length-rand ;; ブラシストロークを変化させる angle ;; ブラシストロークの方向 angle-rand ;; ブラシストロークの方向を変化させる color-rand ;; 色を変化させる undo? ;; アンドゥを有効にするかどうか ) (define (list-ref l n) (nth n l)) (define dot-proc (cond ((= tool-type 0) gimp-pencil) ((= tool-type 1) gimp-airbrush-default) ((= tool-type 2) gimp-paintbrush-default) )) ;; min-val から max-val までのランダムな数を返す (define (get-random-number min-val max-val) (+ min-val (rand (- max-val min-val)))) ;; always 0 <= number <= 255 (define (color-round number) (min (max number 0) 255)) (define (sin-s ang) (sin (* 2 *pi* (/ ang 360)))) (define (cos-s ang) (cos (* 2 *pi* (/ ang 360)))) ;; [0 to 127, 128 to 255] ... noraml color range ;; [0 to 127,-128 to -1] ... color range which gimp-drawable-get-pixel returned (define (convert-numerical-region region color) (if (= region 0) ;; input : -128 <= color <= 127 ;; return: always 0 <= color <= 255 (let ((N (min (max color -128) 127))) (if (< N 0) (+ N 256) N)) ;; input : 0 <= color <= 255 ;; return: always -128 <= color <= 127 (let ((N (min (max color 0) 255))) (if (> N 127) (- N 256) N)))) (let* ( (strokes (cons-array 4 'double)) (old-brush (car (gimp-brushes-get-brush))) (old-fg (car (gimp-palette-get-foreground))) (old-bg (car (gimp-palette-get-background))) (width (car (gimp-drawable-width layer))) (height (car (gimp-drawable-height layer))) (dot-layer (car (gimp-layer-new img width height RGBA-IMAGE "Dot image" 100 NORMAL-MODE))) (x-coordinate '()) (y-coordinate '()) (color-list '()) (count 0) (dummy (gimp-brushes-set-brush (car brush))) (brush-info (gimp-brushes-get-brush)) (brush-area (* (+ lengths (* length-rand 0.5)) (cadr brush-info) (caddr brush-info))) (layer-area (* width height)) (iteration (* 0.125 density (/ layer-area brush-area))) ) ;; 前処理 (if (eqv? undo? TRUE) (gimp-image-undo-group-start img) (gimp-image-undo-disable img)) (gimp-edit-clear dot-layer) (gimp-image-add-layer img dot-layer -1) ;; 描画座標と描画色を求める (while (> iteration count) (let* ((x1 (get-random-number 0 (- width 1))) (y1 (get-random-number 0 (- height 1))) (angle-rand-angle (get-random-number (- angle-rand) angle-rand)) (length-rand-length (get-random-number 0 length-rand)) (x2 (+ x1 (* (+ lengths length-rand-length) (cos-s (+ angle angle-rand-angle))))) (y2 (+ y1 (* (+ lengths length-rand-length) (sin-s (+ angle angle-rand-angle))))) (pixel (cadr (gimp-drawable-get-pixel layer x1 y1))) (R (color-round (+ (convert-numerical-region 0 (aref pixel 0)) (get-random-number (- color-rand) color-rand)))) (G (color-round (+ (convert-numerical-region 0 (aref pixel 1)) (get-random-number (- color-rand) color-rand)))) (B (color-round (+ (convert-numerical-region 0 (aref pixel 2)) (get-random-number (- color-rand) color-rand)))) ) (set! x-coordinate (cons x1 x-coordinate)) (set! y-coordinate (cons y1 y-coordinate)) (set! x-coordinate (cons x2 x-coordinate)) (set! y-coordinate (cons y2 y-coordinate)) (set! color-list (cons (list R G B) color-list)) (set! count (+ count 1)) )) ; end of while (set! count 0) (set! length-max (length color-list)) ;; 本体 (描画処理) (while (> length-max count) (gimp-palette-set-foreground (list-ref color-list count)) (aset strokes 0 (list-ref x-coordinate (* 2 count))) (aset strokes 1 (list-ref y-coordinate (* 2 count))) (aset strokes 2 (list-ref x-coordinate (+ 1 (* 2 count)))) (aset strokes 3 (list-ref y-coordinate (+ 1 (* 2 count)))) (dot-proc dot-layer 4 strokes) (set! count (+ count 1)) ) ; end of while ;; 後処理 (gimp-brushes-set-brush old-brush) (gimp-palette-set-foreground old-fg) (gimp-palette-set-background old-bg) (if (eqv? undo? TRUE) (gimp-image-undo-group-end img) (gimp-image-undo-enable img)) (gimp-displays-flush) )) (script-fu-register "script-fu-paint-dot-image" "/Script-Fu/Alchemy/Paint Dot Image..." "Paint dot image" "Iccii " "Iccii" "2002, May" "RGB* GRAY*" SF-IMAGE "Image" 0 SF-DRAWABLE "Drawable" 0 SF-OPTION "Paint Tool" '("Pencil" "Airbrush" "Paintbrush") SF-ADJUSTMENT "Density (%)" '(50 1 200 1 10 0 0) SF-BRUSH "Use Brush" '("Circle Fuzzy (07)" 1.0 20 0) SF-ADJUSTMENT "Brush Length" '(9 0 30 1 1 0 0) SF-ADJUSTMENT "Length Randomize" '(5 0 20 1 1 0 0) SF-ADJUSTMENT "Brush Angle" '(45 0 360 1 15 0 0) SF-ADJUSTMENT "Angle Randomize" '(30 0 180 1 15 0 0) SF-ADJUSTMENT "Color Randomize" '(10 0 127 1 16 0 0) SF-TOGGLE "Enable Undo" FALSE )