;; pattern-swirly.scm -*-scheme-*- ;; Inspired by Swirly-Pattern by Federico Mena Quintero (Quartic) ;; but has been completely rewritten (more than once) by Alan Horkan. ;; compare and contrast different types of 'invert'/flip/rotate (define (script-fu-transform image drawable) (gimp-flip drawable 0) ; fast and effecient ;; original, invert colour, suitable only for black and white. ;(gimp-invert drawable)) ;; invert by flipping, works because of the specific pattern ;(gimp-flip drawable 0)) ;(gimp-flip drawable 1)) ;; not invert, but interesting ;; swap position of the two colours by rotating 270 degrees instead of inverting ;; gimp-rotate, built-in, gauranteed to be there, probably not optimal for *90 rotations ;(gimp-rotate drawable FALSE (* (/ 3 2) *pi*)) ) ;; plug-in-rotate, probably a matrix transformation optimized for *90 degree rotations ;(plug-in-rotate 1 image drawable 3 FALSE)) ) ;; must whirl at least once (define (script-fu-whirl-pinch-repeat image drawable angle times) (plug-in-whirl-pinch 1 image drawable angle 0.0 1.0) (if (> times 0) (script-fu-whirl-pinch-repeat image drawable angle (- times 1))) ) ;; input image and drawable are ignored, not the most elegant code but it'll do (define (script-fu-pattern-swirly image drawable block-size angle times) (let* ( (height (car (gimp-drawable-height drawable))) (width (car (gimp-drawable-width drawable))) (temp-size (* 2 block-size)) (temp-image (car (gimp-image-new temp-size temp-size RGB))) (temp-drawable (car (gimp-layer-new temp-image temp-size temp-size RGB "Swirly Pattern" 100 NORMAL))) ) ;; disable undo, dont need it here (gimp-image-undo-disable temp-image) (gimp-image-add-layer temp-image temp-drawable 0) (gimp-layer-add-alpha temp-drawable) ;; Render checkerboard, current foreground and background colours used (plug-in-checkerboard 1 temp-image temp-drawable 0 block-size) ;; do the whirl (script-fu-whirl-pinch-repeat temp-image temp-drawable angle times) (set! tile-size (* 2 temp-size)) (gimp-image-resize temp-image tile-size tile-size 0 0) (define (copy-add-offset image drawable x y) (set! new-layer (car (gimp-layer-copy drawable TRUE))) (gimp-image-add-layer image new-layer -1) (gimp-layer-set-offsets new-layer x y) ) ;; lower right quadrant (same as top left) (copy-add-offset temp-image temp-drawable temp-size temp-size) ;; create a second drawable (set! temp-drawable2 (car (gimp-layer-copy temp-drawable TRUE))) ;; upper right quadrant (copy-add-offset temp-image temp-drawable2 temp-size 0) (set! active-drawable (car (gimp-image-get-active-drawable temp-image))) ;; version 2.x is stricter, must add drawable to an image before flip ;(gimp-flip temp-drawable2 0) (script-fu-transform temp-image active-drawable) ;; lower left quadrant (same as upper right) (copy-add-offset temp-image active-drawable 0 temp-size ) (set! temp-drawable (car (gimp-image-flatten temp-image))) (gimp-image-undo-enable temp-image) ;; do not remove, useful for testing ;(gimp-display-new temp-image) ;(gimp-displays-flush) ;; make undoable in one step. (gimp-image-undo-group-start image) (gimp-edit-copy temp-drawable) (set! pattern (car (gimp-edit-paste drawable FALSE))) (gimp-layer-set-offsets pattern 0 0) (gimp-floating-sel-to-layer pattern) (plug-in-tile 1 image pattern width height FALSE) (gimp-drawable-set-name pattern "Swirly Pattern") (gimp-image-undo-group-end image) (gimp-displays-flush) ) ) (script-fu-register "script-fu-pattern-swirly" _"/Filters/Render/Pattern/Swirly..." "Creates a pattern made from four Swirls. Uses the current Foreground and Background colours. For best results use strongly contrasting colours. For example Black & White, Red & Cyan, Green & Magenta, Blue & Yellow. Block Size is 1/8 of size of the generated pattern. Requires plug-in-whirl-pinch and plug-in-tile. " "Alan Horkan. Federico Mena Quintero (Quartic). " ; author(s) "Alan Horkan. Public Domain. " ; rights "2004 08 12 UTC" ; date "" ; supports all types SF-IMAGE "Image" 0 SF-DRAWABLE "Drawable" 0 ; bugfix, minimum must be at least 1 pixel or script fails SF-ADJUSTMENT _"Block Size" '(20 1 2048 1 10 0 1) SF-ADJUSTMENT _"Whirl Angle" '(90 0 360 1 10 0 0) SF-ADJUSTMENT _"Whirl Times" '(4 1 128 1 10 0 1) ) (script-fu-register "script-fu-whirl-pinch-repeat" _"/Filters/Distorts/Whirl Repeat..." "Whirl repeatedly. Script to compensate for Whirl-Pinch plugin not supporting Rotations greater than 360 degrees. Part of the Swirly Pattern script. If you don't like this please fix Whirl-Pinch so this can be removed. Doesn't work perfectly, cannot inlcude a (gimp-displays-flush) without breaking other script. " "" "" "" "" SF-IMAGE "Image" 0 SF-DRAWABLE "Drawable" 0 SF-ADJUSTMENT _"Whirl Angle" '(90 -360 360 1 10 0 0) SF-ADJUSTMENT _"Whirl Times" '(4 1 128 1 10 0 1) ) ;; DONE script uses the current background and foreground colours, ;; instead of just hardcoded black and white. ;; DONE colours swap positions (rotate 270) instead of invert ;; DONE abstracted the invert/transform, changed it to flip horizontal instead ;; DONE gimp-flip fix. version 2.x is stricter, drawable must be added to image ;; before it could be flipped. ;; Whirling is time consuming, particularly when repeated multiple times. ;; Copy+Transform is more efficient than whirling from scratch. ;; Rewrote script to make it ~3-4 orders of magnitude more effecient ;; This also means less annoying progress bars. ;; TODO use just the selection not the whole drawable