; FP-Retro-Background script ; This is an updated version of the default GIMP line nova script. ; The purpose for modifying it was to create a simple retro-style background. ; I've add options for setting the foreground/background colors so that it will automatically ; create the retro background with the user's chosen colors. The default settings work pretty ; well for most image sizes, but above 1024X768, things get a little unusual. I don't quite ; understand the underlying math for most of the script, so at the moment, I can't change that. ; However, a future goal for this script is to allow the user to choose the center point for the rays ; and allow it to work well on any image size. ; I also modified the script to allow it to work better with the Undo option. The original script ; added a line in the "let* block" to turn turn off any existing selection and save it to a channel. ; By doing this, it was impossible to Undo everything in one step. I moved that command out from the ; "let* block" and into the script itself. ; ; Updated 1/11/2008: ; ; Gives user the option to save the selection created by the script as a channel for use later on. Default for ; this option is to save the selection. Thanks to ClayOgre (http://clayogre.deviantart.com/) for the suggestion. ; ; Also, told the script to add its own layer to make the background from, rather than requiring the user to do so ; beforehand. Thanks Photocomix (http://photocomix-resources.deviantart.com/) for the suggestion. ; Updated 5/19/2008: Added option to let user place the center point of the "sunburst" at any location. Also added ; ability to use almost size of image to create selection. Previous script was limited in that regard. ; ; Updated script on October 5, 2008 to ensure compliance with GIMP 2.6 standards. (define (fp-retro-background img drw center CX CY num-of-lines corn-deg offset variation fg-color trans-bg bg-color save-select addSun sunRadius) (let* ( (*points* (cons-array (* 3 2) 'double)) (modulo fmod) ; in R4RS way (pi/2 (/ *pi* 2)) (pi/4 (/ *pi* 4)) (pi3/4 (* 3 pi/4)) (pi5/4 (* 5 pi/4)) (pi3/2 (* 3 pi/2)) (pi7/4 (* 7 pi/4)) (2pi (* 2 *pi*)) (rad/deg (/ 2pi 360)) (variation/2 (/ variation 2)) (drw-width (car (gimp-drawable-width drw))) (drw-height (car (gimp-drawable-height drw))) (drw-offsets (gimp-drawable-offsets drw)) (old-selection 0) (radius (* 20 (max drw-height drw-width))) (index 0) (dir-deg/line (/ 360 num-of-lines)) (retro-layer 0) ) (define (draw-vector beg-x beg-y direction) (define (set-point! index x y) (aset *points* (* 2 index) x) (aset *points* (+ (* 2 index) 1) y) ) (define (deg->rad rad) (* (modulo rad 360) rad/deg) ) (define (set-marginal-point beg-x beg-y direction) (let ( (dir1 (deg->rad (+ direction corn-deg))) (dir2 (deg->rad (- direction corn-deg))) ) (define (aux dir index) (set-point! index (+ beg-x (* (cos dir) radius)) (+ beg-y (* (sin dir) radius))) ) (aux dir1 1) (aux dir2 2) ) ) (let ( (dir0 (deg->rad direction)) (off (+ offset (- (modulo (rand) variation) variation/2))) ) (set-point! 0 (+ beg-x (* off (cos dir0))) (+ beg-y (* off (sin dir0))) ) (set-marginal-point beg-x beg-y direction) (gimp-free-select img 6 *points* CHANNEL-OP-ADD TRUE ; antialias FALSE ; feather 0 ; feather radius ) ) ) ; Allow for the GIMP settings to be restored prior to running the script (gimp-context-push) (gimp-image-undo-group-start img) (set! old-selection (car (gimp-selection-save img))) (gimp-selection-none img) (srand (realtime)) ; Create new layer for the Retro Background, add it to the image, and fill it with color (set! retro-layer (car (gimp-layer-new img drw-width drw-height RGBA-IMAGE "Retro Background Layer" 100 NORMAL-MODE))) (gimp-image-add-layer img retro-layer -1) (gimp-drawable-fill retro-layer TRANSPARENT-FILL) (gimp-context-set-foreground fg-color) (gimp-context-set-background bg-color) (if (= trans-bg FALSE) (gimp-edit-fill retro-layer BACKGROUND-FILL) ) (while (< index num-of-lines) (if (= center TRUE) (begin (set! CX (/ drw-width 2)) (set! CY (/ drw-height 2)) ) ) (draw-vector (+ (nth 0 drw-offsets) CX) (+ (nth 1 drw-offsets) CY) (* index dir-deg/line) ) (set! index (+ index 1)) ) (if (= addSun TRUE) (begin (gimp-ellipse-select img (- CX (* 0.5 sunRadius)) (- CY (* 0.5 sunRadius)) sunRadius sunRadius CHANNEL-OP-ADD TRUE FALSE 0) ) ) (gimp-edit-fill retro-layer FOREGROUND-FILL) (if (= save-select TRUE) (gimp-selection-save img) ) (gimp-image-set-active-layer img retro-layer) (if old-selection (begin (gimp-selection-load old-selection) (gimp-image-remove-channel img old-selection) ) ) (gimp-displays-flush) (gimp-image-undo-group-end img) ; Return GIMP settings back to those used prior to script (gimp-context-pop) ) ) (script-fu-register "fp-retro-background" "/Filters/Render/FP Retro Background..." "Create a Retro Style Background with Chosen Colors" "Art Wade" "Art Wade" "October 5, 2008" "RGB*" SF-IMAGE "Image" 0 SF-DRAWABLE "Drawable" 0 SF-TOGGLE "Place sunburst at center of image?" TRUE SF-ADJUSTMENT "Center X Coordinate" '(10 0 9999 1 1 0 1) SF-ADJUSTMENT "Center Y Coordinate" '(10 0 9999 1 1 0 1) SF-ADJUSTMENT "Number of lines" '(10 10 1000 1 1 0 1) SF-ADJUSTMENT "Sharpness (degrees)" '(8 0.0 10.0 0.1 1 1 1) SF-ADJUSTMENT "Offset radius" '(0 0 2000 1 1 0 1) SF-ADJUSTMENT "Randomness" '(1 1 2000 1 1 0 1) SF-COLOR "Foreground Color" '(0 0 0) SF-TOGGLE "Transparent Background?" FALSE SF-COLOR "Background Color" '(255 255 255) SF-TOGGLE "Save selection created by script in a channel?" TRUE SF-TOGGLE "Add Sun?" FALSE SF-ADJUSTMENT "Sun Radius" '(10 10 9999 1 1 0 1) )