home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2002 April / pcpro0402.iso / essentials / graphics / Gimp / gimp-src-20001226.exe / src / gimp / plug-ins / script-fu / scripts / test-sphere.scm < prev    next >
Encoding:
Text File  |  2000-05-01  |  8.5 KB  |  208 lines

  1. ; This is a slightly modified copy of the sphere script to show and test 
  2. ; the possibilities of the new Script-Fu API extensions.
  3. ;
  4. ; ----------------------------------------------------------------------
  5. ; SF-ADJUSTMENT 
  6. ; is only useful in interactive mode, if you call a script from
  7. ; the console, it acts just like a normal SF-VALUE
  8. ; In interactive mode it creates an adjustment widget in the dialog.
  9. ;
  10. ; Usage: 
  11. ; SF-ADJUSTMENT "label" '(value, lower, upper, step_inc, page_inc, digits, type) 
  12. ;
  13. ; type is one of: SF-SLIDER(0), SF-SPINNER(1)
  14. ; ----------------------------------------------------------------------
  15. ; SF-FONT
  16. ; creates a font-selection widget in the dialog. It returns a fontname as
  17. ; a string. There are two new gimp-text procedures to ease the use of this
  18. ; return parameter:
  19. ;
  20. ;  (gimp-text-fontname image drawable x-pos y-pos text border antialias size unit font)
  21. ;  (gimp-text-get-extents-fontname text size unit font))
  22. ;
  23. ; where font is the fontname you get. The size specified in the fontname 
  24. ; is silently ignored. It is only used in the font-selector. So you are asked to
  25. ; set it to a useful value (24 pixels is a good choice) when using SF-FONT.
  26. ;
  27. ; Usage:
  28. ; SF-FONT "label" "fontname"        
  29. ; ----------------------------------------------------------------------
  30. ;
  31. ; SF-BRUSH 
  32. ; is only useful in interactive mode. It will create a widget in the control
  33. ; dialog. The widget consists of a preview area (which when pressed will 
  34. ; produce a popup preview ) and a button with the "..." label. The button will
  35. ; popup a dialog where brushes can be selected and each of the 
  36. ; characteristics of the brush can be modified.
  37. ; The actual value returned when the script is invoked is a list 
  38. ; consisting of Brush name, opacity, spacing and brush mode in the same 
  39. ; units as passed in as the default value.
  40. ;
  41. ; Usage:-
  42. ; SF_BRUSH "Brush" '("Circle (03)" 1.0 44 0)
  43. ;
  44. ; Here the brush dialog will be popped up with a default brush of Circle (03)
  45. ; opacity 1.0, spacing 44 and paint mode of Normal (value 0).
  46. ; If this selection was unchanged the value passed to the function as a 
  47. ; paramater would be '("Circle (03)" 1.0 44 0). BTW the widget used
  48. ; is generally available in the libgimpui library for any plugin that
  49. ; wishes to select a brush.
  50. ; ----------------------------------------------------------------------
  51. ;
  52. ; SF-PATTERN
  53. ; Only useful in interactive mode. It will create a widget in the control
  54. ; dialog. The widget consists of a preview area (which when pressed will 
  55. ; produce a popup preview ) and a button with the "..." label. The button will
  56. ; popup a dialog where patterns can be selected.
  57. ;
  58. ; Usage:-
  59. ; SF-PATTERN "Pattern" "Maple Leaves"
  60. ;
  61. ; The value returned when the script is invoked is a string containing the 
  62. ; pattern name. If the above selection was not altered the string would 
  63. ; contain "Maple Leaves"
  64. ; ----------------------------------------------------------------------
  65. ;
  66. ; SF-GRADIENT
  67. ; Only useful in interactive mode. It will create a widget in the control
  68. ; dialog. The widget consists of a button containing a preview of the selected
  69. ; gradient. If the button is pressed a gradient selection dialog will popup.
  70. ;
  71. ; Usage:-
  72. ; SF-GRADIENT "Gradient" "Deep_Sea"
  73. ;
  74. ; The value returned when the script is invoked is a string containing the 
  75. ; gradient name. If the above selection was not altered the string would 
  76. ; contain "Deep_Sea"
  77. ;
  78. ; ----------------------------------------------------------------------
  79. ;
  80. ; SF-FILENAME
  81. ; Only useful in interactive mode. It will create a widget in the control
  82. ; dialog. The widget consists of a button containing the name of a file.
  83. ; If the button is pressed a file selection dialog will popup.
  84. ;
  85. ; Usage:-
  86. ; SF-FILENAME "Environment Map" (string-append "" gimp-data-dir "/scripts/beavis.jpg")
  87. ;
  88. ; The value returned when the script is invoked is a string containing the 
  89. ; filename.
  90. ; ----------------------------------------------------------------------
  91. ;
  92. ; SF-OPTION
  93. ; Only useful in interactive mode. It will create a widget in the control
  94. ; dialog. The widget is an option_menu showing the options that are passed
  95. ; as a list. The first option is the default choice. 
  96. ;
  97. ; Usage:-
  98. ; SF-OPTION "Orientation" '("Horzontal" "Vertical")
  99. ;
  100. ; The value returned when the script is invoked is the number of the
  101. ; choosen option, where the option first is counted as 0.
  102. ; ----------------------------------------------------------------------
  103. ;
  104.  
  105.  
  106. ;
  107. (define (script-fu-test-sphere radius 
  108.                    light 
  109.                    shadow 
  110.                    bg-color 
  111.                    sphere-color 
  112.                    brush 
  113.                    text 
  114.                    pattern 
  115.                    gradient 
  116.                    font 
  117.                    size 
  118.                    filename
  119.                    orientation)
  120.   (let* ((width (* radius 3.75))
  121.      (height (* radius 2.5))
  122.      (img (car (gimp-image-new width height RGB)))
  123.      (drawable (car (gimp-layer-new img width height RGB_IMAGE "Sphere Layer" 100 NORMAL)))
  124.      (radians (/ (* light *pi*) 180))
  125.      (cx (/ width 2))
  126.      (cy (/ height 2))
  127.      (light-x (+ cx (* radius (* 0.6 (cos radians)))))
  128.      (light-y (- cy (* radius (* 0.6 (sin radians)))))
  129.      (light-end-x (+ cx (* radius (cos (+ *pi* radians)))))
  130.      (light-end-y (- cy (* radius (sin (+ *pi* radians)))))
  131.      (offset (* radius 0.1))
  132.      (text-extents (gimp-text-get-extents-fontname text size PIXELS font))
  133.      (x-position (- cx (/ (car text-extents) 2)))
  134.      (y-position (- cy (/ (cadr text-extents) 2)))
  135.      (old-pattern (car (gimp-patterns-get-pattern)))
  136.      (old-gradient (car (gimp-gradients-get-active)))
  137.      (old-fg (car (gimp-palette-get-foreground)))
  138.      (old-bg (car (gimp-palette-get-background))))
  139.     (gimp-image-undo-disable img)
  140.     (gimp-image-add-layer img drawable 0)
  141.     (gimp-palette-set-foreground sphere-color)
  142.     (gimp-palette-set-background bg-color)
  143.     (gimp-edit-fill drawable BG-IMAGE-FILL)
  144.     (gimp-palette-set-background '(20 20 20))
  145.     (if (and
  146.      (or (and (>= light 45) (<= light 75)) (and (<= light 135) (>= light 105)))
  147.      (= shadow TRUE))
  148.     (let ((shadow-w (* (* radius 2.5) (cos (+ *pi* radians))))
  149.           (shadow-h (* radius 0.5))
  150.           (shadow-x cx)
  151.           (shadow-y (+ cy (* radius 0.65))))
  152.       (if (< shadow-w 0)
  153.           (prog1 (set! shadow-x (+ cx shadow-w))
  154.              (set! shadow-w (- shadow-w))))
  155.       (gimp-ellipse-select img shadow-x shadow-y shadow-w shadow-h REPLACE TRUE TRUE 7.5)
  156.       (gimp-patterns-set-pattern pattern)
  157.       (gimp-bucket-fill drawable PATTERN-BUCKET-FILL MULTIPLY 100 0 FALSE 0 0)))
  158.     (gimp-ellipse-select img (- cx radius) (- cy radius) (* 2 radius) (* 2 radius) REPLACE TRUE FALSE 0)
  159.     (gimp-blend drawable FG-BG-RGB NORMAL RADIAL 100 offset REPEAT-NONE
  160.         FALSE 0 0 light-x light-y light-end-x light-end-y)
  161.     (gimp-selection-none img)
  162.  
  163.     (gimp-gradients-set-active gradient)
  164.     (gimp-ellipse-select img 10 10 50 50 REPLACE TRUE FALSE 0)
  165.     (gimp-blend drawable CUSTOM NORMAL LINEAR 100 offset REPEAT-NONE
  166.         FALSE 0 0 10 10 30 60)
  167.     (gimp-selection-none img)
  168.  
  169.     (gimp-palette-set-foreground '(0 0 0))
  170.     (gimp-floating-sel-anchor (car (gimp-text-fontname img drawable
  171.                                x-position y-position
  172.                                text
  173.                                0 TRUE
  174.                                size PIXELS
  175.                                font)))
  176.  
  177.     (gimp-gradients-set-active old-gradient)
  178.     (gimp-patterns-set-pattern old-pattern)
  179.     (gimp-palette-set-background old-bg)
  180.     (gimp-palette-set-foreground old-fg)
  181.     (gimp-image-undo-enable img)
  182.     (gimp-display-new img)))
  183.  
  184. (script-fu-register "script-fu-test-sphere"
  185.             "<Toolbox>/Xtns/Script-Fu/Test/Sphere..."
  186.             "Simple script to test and show the usage of the new Script-Fu API extensions. \n\nNote the use of spinbuttons, sliders, the font, pattern, brush and gradient selectors and do not forget the about dialog..."
  187.             "Spencer Kimball, Sven Neumann"
  188.             "Spencer Kimball"
  189.             "1996, 1998"
  190.             ""
  191.             SF-ADJUSTMENT "Radius (in pixels)" '(100 1 5000 1 10 0 1)
  192.             SF-ADJUSTMENT "Lighting (degrees)" '(45 0 360 1 10 1 0)
  193.             SF-TOGGLE "Shadow" TRUE
  194.             SF-COLOR "Background Color" '(255 255 255)
  195.             SF-COLOR "Sphere Color" '(255 0 0)
  196.                 SF-BRUSH "Brush" '("Circle (03)" 1.0 44 0)
  197.             SF-STRING "Text" "Script-Fu rocks!"
  198.             SF-PATTERN "Pattern" "Maple Leaves"
  199.             SF-GRADIENT "Gradient" "Deep_Sea"
  200.             SF-FONT "Font" "-freefont-agate-normal-r-normal-*-24-*-*-*-p-*-*-*"
  201.                     SF-ADJUSTMENT "Font Size (pixels)" '(50 1 1000 1 10 0 1)
  202.             SF-FILENAME "Environment Map" (string-append "" gimp-data-dir "/scripts/beavis.jpg")
  203.             SF-OPTION "Orientation" '("Horzontal" "Vertical"))
  204.  
  205.  
  206.