home *** CD-ROM | disk | FTP | other *** search
/ PC World 2001 February / PCWorld_2001-02_cd.bin / Software / Topware / gimp / gimp-setup-20001226.exe / Main / sphere.scm < prev    next >
Encoding:
Text File  |  2000-12-27  |  2.6 KB  |  64 lines

  1. ;  Create a 3D sphere with optional shadow
  2. ;  The sphere's principle color will be the foreground
  3. ;  Parameters:
  4. ;   bg-color: background color
  5. ;   sphere-color: color of sphere
  6. ;   radius: radius of the sphere in pixels
  7. ;   light:  angle of light source in degrees
  8. ;   shadow: whather to create a shadow as well
  9.  
  10. (define (script-fu-sphere radius light shadow bg-color sphere-color)
  11.   (let* ((width (* radius 3.75))
  12.      (height (* radius 2.5))
  13.      (img (car (gimp-image-new width height RGB)))
  14.      (drawable (car (gimp-layer-new img width height RGB_IMAGE "Sphere Layer" 100 NORMAL)))
  15.      (radians (/ (* light *pi*) 180))
  16.      (cx (/ width 2))
  17.      (cy (/ height 2))
  18.      (light-x (+ cx (* radius (* 0.6 (cos radians)))))
  19.      (light-y (- cy (* radius (* 0.6 (sin radians)))))
  20.      (light-end-x (+ cx (* radius (cos (+ *pi* radians)))))
  21.      (light-end-y (- cy (* radius (sin (+ *pi* radians)))))
  22.      (offset (* radius 0.1))
  23.      (old-fg (car (gimp-palette-get-foreground)))
  24.      (old-bg (car (gimp-palette-get-background))))
  25.     (gimp-image-undo-disable img)
  26.     (gimp-image-add-layer img drawable 0)
  27.     (gimp-palette-set-foreground sphere-color)
  28.     (gimp-palette-set-background bg-color)
  29.     (gimp-edit-fill drawable BG-IMAGE-FILL)
  30.     (gimp-palette-set-background '(20 20 20))
  31.     (if (and
  32.      (or (and (>= light 45) (<= light 75)) (and (<= light 135) (>= light 105)))
  33.      (= shadow TRUE))
  34.     (let ((shadow-w (* (* radius 2.5) (cos (+ *pi* radians))))
  35.           (shadow-h (* radius 0.5))
  36.           (shadow-x cx)
  37.           (shadow-y (+ cy (* radius 0.65))))
  38.       (if (< shadow-w 0)
  39.           (prog1 (set! shadow-x (+ cx shadow-w))
  40.              (set! shadow-w (- shadow-w))))
  41.       (gimp-ellipse-select img shadow-x shadow-y shadow-w shadow-h REPLACE TRUE TRUE 7.5)
  42.      (gimp-bucket-fill drawable BG-BUCKET-FILL MULTIPLY 100 0 FALSE 0 0)))
  43.     (gimp-ellipse-select img (- cx radius) (- cy radius) (* 2 radius) (* 2 radius) REPLACE TRUE FALSE 0)
  44.     (gimp-blend drawable FG-BG-RGB NORMAL RADIAL 100 offset REPEAT-NONE
  45.         FALSE 0 0 light-x light-y light-end-x light-end-y)
  46.     (gimp-selection-none img)
  47.     (gimp-palette-set-background old-bg)
  48.     (gimp-palette-set-foreground old-fg)
  49.     (gimp-image-undo-enable img)
  50.     (gimp-display-new img)))
  51.  
  52. (script-fu-register "script-fu-sphere"
  53.             _"<Toolbox>/Xtns/Script-Fu/Misc/Sphere..."
  54.             "Simple sphere with a drop shadow"
  55.             "Spencer Kimball"
  56.             "Spencer Kimball"
  57.             "1996"
  58.             ""
  59.             SF-ADJUSTMENT _"Radius (pixels)" '(100 5 500 1 10 0 1)
  60.             SF-ADJUSTMENT _"Lighting (degrees)" '(45 0 360 1 10 0 0)
  61.             SF-TOGGLE _"Shadow" TRUE
  62.             SF-COLOR  _"Background Color" '(255 255 255)
  63.             SF-COLOR  _"Sphere Color" '(255 0 0))
  64.