; The GIMP -- an image manipulation program ; Copyright (C) 1995 Spencer Kimball and Peter Mattis ; ; Dotted Chaos --- create an dotted chaos ; Copyright (C) 2001 Iccii ; ; -------------------------------------------------------------------- ; - Changelog - ; version 0.1 2001/05/18 iccii ; - Initial relase (Beta1) ; version 0.2 2001/05/18 iccii ; - Add the Force in chaos type (Beta2) ; version 0.2a 2001/05/20 iccii ; - Make better (Beta3) ; version 0.3 2001/06/13 iccii ; - Now I can change color and gradient (Beta4) ; - Use gimp-drawable-set-pixel instead of gimp-pencil... thanks, Kajiyama ; version 0.4 2001/05/18 iccii ; - Add the 2th and Circle2 in chaos type (Beta5) ; version 0.4a 2001/06/13 iccii ; - Add the "Use Gradient?" option to creat black/white image ; version 0.4b 2001/06/15 iccii ; - Add the link of refarence book ; version 0.5 2004/09 Raymond Ostertag ; - ported to Gimp2 ; -------------------------------------------------------------------- ; Reference Book ; http://www.saiensu.co.jp/books-htm/ISBN4-7819-0729-6.htm ; -------------------------------------------------------------------- ; ; 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-chaos-dotted chaos-type ;; カオスの種類 image-size ;; 画像の大きさ bg-color ;; 背景色 gradient ;; グラデーションでカオスに色付け use-gradient ;; グラデーションを使うかどうか iteration ;; 繰り返し回数 scale ;; 画像の拡大率 a ;; パラメータ a c ;; パラメータ c ) (let* ( (modulo fmod) ;; in R4RS way (REPEAT_MAX 1000) ;; 画像更新時の繰り返し回数 (count 0) ;; 点描画を何回繰り返したかをカウントする (color-change (/ iteration 255)) ;; 色 (u0 (/ image-size 2)) ;; 画像の中央の X 座標 (v0 (/ image-size 2)) ;; 画像の中央の Y 座標 (slx (/ u0 scale)) ;; X 方向のスケール (sly (/ v0 scale)) ;; Y 方向のスケール (old-fg (car (gimp-palette-get-foreground))) (old-grad (car (gimp-gradients-get-gradient))) (width image-size) (height image-size) (img (car (gimp-image-new width height RGB))) (bg-layer (car (gimp-layer-new img width height RGB-IMAGE "Background" 100 NORMAL-MODE))) (layer (car (gimp-layer-new img width height RGBA-IMAGE "Chaos" 100 NORMAL-MODE))) (pixel (cons-array 4 'byte)) ) ; end variable definition ;; カオスの種類毎に異なる初期値、関数 f(x,y) をセット (cond ((equal? chaos-type 0) ;; 回転のカオス ;(set! a -1.98) (set! x00 4.0) (set! y00 0.0) (define (next-value x0 y0 a) (let* ((x (+ y0 (* a x0) (/ 2.0 (+ 1.0 (* x0 x0)) ) )) (y (- x0))) (list x y)))) ((equal? chaos-type 1) ;; 網目状のカオス ;(set! a -1.32) (set! x00 3.0) (set! y00 0.0) (define (next-value x0 y0 a) (let* ((x (+ y0 (* a x0) (/ (* 3.0 x0) (+ 1.0 (* x0 x0)) )) ) (y (- x0))) (list x y)))) ((equal? chaos-type 2) ;; 円環状カオスと閉曲線群 ;(set! a -1.32) (set! x00 3.0) (set! y00 0.0) (define (next-value x0 y0 a) (let* ((x (+ y0 (* a x0) (/ 2.0 (+ 1.0 (* x0 x0)) )) ) (y (- x0))) (list x y)))) ((equal? chaos-type 3) ;; 強制系のカオス ;(set! a -1.32) (set! x00 1.1) (set! y00 0.0) ;(set! slx (* (/ slx scale) 5)) ;; ここだけスケールが桁違いになるので二乗している ;(set! sly (* (/ sly scale) 5)) (define (next-value x0 y0 a) (let* ((x (+ y0 (* a x0) (/ 3.0 (+ 1.0 (* x0 x0)) )) ) (y (+ (- x0) 5.0)) (x0 x) (y0 y) (x (+ y0 (* a x0) (/ 3.0 (+ 1.0 (* x0 x0)) )) ) (y (- (- x0) 5.0))) (list x y)))) ((equal? chaos-type 4) ;; 二次の多項式のカオス (gimp-message "Sorry, don't use this type!") ;(set! a -1.32) (set! x00 3.0) (set! y00 0.0) (define (next-value x0 y0 a) (let* ((x (+ y0 (* 0.48 x0) (* x0 x0) )) (y (- x0))) (list x y)))) ((equal? chaos-type 5) ;; 円環状カオスの別の例 (gimp-message "Sorry, don't use this type!") ;(set! a -1.32) (set! x00 3.0) (set! y00 0.0) (define (next-value x0 y0 a c) (let* ((tita (- c (* 3 (exp (- (+ (* x0 x0) (* y0 y0))) )))) (x (+ a (* x0 (cos tita)) (- (* y0 (sin tita))))) (y (+ (* x0 (sin tita)) (* y0 (cos tita))))) (list x y)))) ) ;; cond による条件分岐の終わり (set! x0 x00) (set! y0 y00) (gimp-image-undo-disable img) (gimp-palette-set-foreground bg-color) (gimp-gradients-set-gradient gradient) (gimp-drawable-fill bg-layer FOREGROUND-FILL) (gimp-drawable-fill layer TRANSPARENT-FILL) (gimp-image-add-layer img bg-layer -1) (gimp-image-add-layer img layer -1) ;; こっから点描画のループが始まる (while (< count iteration) (set! listed-xy (next-value x0 y0 a c)) (set! x (car listed-xy)) (set! y (cadr listed-xy)) (let* ((color (if (eqv? use-gradient TRUE) (modulo (/ count color-change) 255) 255)) (u (+ u0 (* slx (/ (+ x y) (sqrt (- 2.0 a)))))) (v (- v0 (* sly (/ (- x y) (sqrt (+ 2.0 a))))))) (aset pixel 0 color) (aset pixel 1 color) (aset pixel 2 color) (aset pixel 3 255) (if (and (<= 0 u) (<= u (- image-size 1)) (<= 0 v) (<= v (- image-size 1))) (gimp-drawable-set-pixel layer u v 4 pixel))) ;; 発散していきそうだったら初期値に戻す (if (> (+ (abs x) (abs y)) 500) (begin ;(gimp-message "Divergence!") (set! x x00) (set! y y00) )) (set! x0 x) (set! y0 y) (set! count (+ count 1)) ) ; 点描画のループ終り ;; 後始末もやらなきゃね (gimp-layer-set-preserve-trans layer TRUE) (if (eqv? use-gradient TRUE) (plug-in-gradmap 1 img layer)) (gimp-layer-set-preserve-trans layer FALSE) (gimp-palette-set-foreground old-fg) (gimp-gradients-set-gradient old-grad) (gimp-image-undo-enable img) (gimp-display-new img) (gimp-displays-flush) ) ) ;; 登録っす (script-fu-register "script-fu-chaos-dotted" "/Xtns/Script-Fu/Patterns/Chaos..." "create an chaos dotted" "Iccii " "Iccii" "Jun, 2001" "" SF-OPTION _"Chaos Type" '( ;; 面積を変えない写像のカオス "Rotate" ;; 回転のカオス "Stitch" ;; 網目状のカオス "Circle" ;; 円環状カオスと閉曲線群 "Force" ;; 強制系のカオス "2th" ;; 二次の多項式のカオス "Circle2" ;; 円環状カオスの別の例 ) SF-ADJUSTMENT _"Image Size" '(256 1 1024 1 10 0 1) SF-COLOR _"Background Color" '(0 0 0) SF-GRADIENT _"Gradient" "Blue_Green" SF-TOGGLE _"Use Gradient?" TRUE SF-ADJUSTMENT _"Iteration" '(2000 1 50000 10 100 0 0) SF-ADJUSTMENT _"Scale Factor" '(16 0.1 40 0.2 1 1 0) SF-ADJUSTMENT _"Parameter a" '(-1.81 -2 2 0.1 0.5 2 0) SF-ADJUSTMENT _"Parameter c" '(-1.81 -2 2 0.1 0.5 2 0) )