File: line-nova.scm

package info (click to toggle)
gimp 2.2.13-1etch4
  • links: PTS
  • area: main
  • in suites: etch
  • size: 94,832 kB
  • ctags: 47,113
  • sloc: ansic: 524,858; xml: 36,798; lisp: 9,870; sh: 9,409; makefile: 7,923; python: 2,674; perl: 2,589; yacc: 520; lex: 334
file content (87 lines) | stat: -rw-r--r-- 3,168 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
;;; line-nova.scm for gimp-1.1 -*-scheme-*-
;;; Time-stamp: <1998/11/25 13:26:44 narazaki@gimp.org>
;;; Author Shuji Narazaki <narazaki@gimp.org>
;;; Version 0.7

(define (script-fu-line-nova img drw num-of-lines corn-deg offset variation)
  (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 (if (eq? (car (gimp-selection-is-empty img)) TRUE)
			    #f
			    (car (gimp-selection-save img))))
	 (radius (max drw-height drw-width))
	 (index 0)
	 (dir-deg/line (/ 360 num-of-lines)))
    (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
			  )))

    (gimp-image-undo-group-start img)
    (gimp-selection-none img)
    (srand (realtime))
    (while (< index num-of-lines)
      (draw-vector (+ (nth 0 drw-offsets) (/ drw-width 2))
		   (+ (nth 1 drw-offsets) (/ drw-height 2))
		   (* index dir-deg/line))
      (set! index (+ index 1)))
    (gimp-edit-bucket-fill drw FG-BUCKET-FILL NORMAL-MODE 100 0 FALSE 0 0)
    (if old-selection
	(begin
	  (gimp-selection-load old-selection)
	  ;; (gimp-image-set-active-layer img drw)
	  ;; delete extra channel by Sven Neumann <neumanns@uni-duesseldorf.de>
	  (gimp-image-remove-channel img old-selection)))
    (gimp-image-undo-group-end img)
    (gimp-displays-flush)))

(script-fu-register "script-fu-line-nova"
		    _"Line _Nova..."
		    "Line Nova. Draw lines with Foreground color from the center of image to the edges. 1st undo cancels bucket-fill. 2nd undo gets orignal selection."
		    "Shuji Narazaki <narazaki@gimp.org>"
		    "Shuji Narazaki"
		    "1997,1998"
		    ""
		    SF-IMAGE       "Image"               0
		    SF-DRAWABLE    "Drawable"            0
		    SF-ADJUSTMENT _"Number of lines"     '(200 40 1000 1 1 0 1)
		    SF-ADJUSTMENT _"Sharpness (degrees)" '(1.0 0.0 10.0 0.1 1 1 1)
		    SF-ADJUSTMENT _"Offset radius"       '(100 0 2000 1 1 0 1)
		    SF-ADJUSTMENT _"Randomness"          '(30 0 2000 1 1 0 1))

(script-fu-menu-register "script-fu-line-nova"
			 _"<Image>/Script-Fu/Render")