File: ripply-anim.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 (128 lines) | stat: -rw-r--r-- 4,488 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
; "Rippling Image" animation generator (ripply-anim.scm)
; Adam D. Moss (adam@foxbox.org)
; 97/05/18
;
; Designed to be used in conjunction with a plugin capable
; of saving animations (i.e. the GIF plugin).
;

(define (copy-layer-ripple dest-image dest-drawable source-image source-drawable)
  (gimp-selection-all dest-image)
  (gimp-edit-clear dest-drawable)
  (gimp-selection-none dest-image)
  (gimp-selection-all source-image)
  (gimp-edit-copy source-drawable)
  (gimp-selection-none source-image)
      (let ((floating-sel (car (gimp-edit-paste dest-drawable FALSE))))
	(gimp-floating-sel-anchor floating-sel)))

(define (script-fu-ripply-anim img drawable displacement num-frames edge-type)
  (let* ((width (car (gimp-drawable-width drawable)))
	 (height (car (gimp-drawable-height drawable)))
	 (ripple-image (car (gimp-image-new width height GRAY)))
	 (ripple-layer (car (gimp-layer-new ripple-image width height GRAY-IMAGE "Ripple Texture" 100 NORMAL-MODE)))
     (rippletiled-ret)
     (rippletiled-image)
     (rippletiled-layer)
     (remaining-frames)
     (xpos)
     (ypos)
     (xoffset)
     (yoffset)
     )

 ; this script generates its own displacement map

    (gimp-context-push)

    (gimp-image-undo-disable ripple-image)
    (gimp-context-set-background '(127 127 127) )
    (gimp-image-add-layer ripple-image ripple-layer 0)
    (gimp-edit-fill ripple-layer BACKGROUND-FILL)
    (plug-in-noisify 1 ripple-image ripple-layer FALSE 1.0 1.0 1.0 0.0)
    ; tile noise
    (set! rippletiled-ret (plug-in-tile 1 ripple-image ripple-layer (* width 3) (* height 3) TRUE))
    (gimp-image-undo-enable ripple-image)
    (gimp-image-delete ripple-image)

    (set! rippletiled-image (car rippletiled-ret))
    (set! rippletiled-layer (cadr rippletiled-ret))
    (gimp-image-undo-disable rippletiled-image)

    ; process tiled noise into usable displacement map
    (plug-in-gauss-iir 1 rippletiled-image rippletiled-layer 35 TRUE TRUE)
    (gimp-equalize rippletiled-layer TRUE)
    (plug-in-gauss-rle 1 rippletiled-image rippletiled-layer 5 TRUE TRUE)
    (gimp-equalize rippletiled-layer TRUE)

    ; displacement map is now in rippletiled-layer of rippletiled-image

    ; loop through the desired frames

    (set! remaining-frames num-frames)
    (set! xpos (/ width 2))
    (set! ypos (/ height 2))
    (set! xoffset (/ width num-frames))
    (set! yoffset (/ height num-frames))

    (let* (
          (out-imagestack (car (gimp-image-new width height RGB)))
          (dup-image)
          (dup-layer)
          (layer-name)
          (this-layer)
          )

      (gimp-image-undo-disable out-imagestack)
      
      (while (> remaining-frames 0)
	     (set! dup-image (car (gimp-image-duplicate rippletiled-image)))
	     (gimp-image-undo-disable dup-image)
	     (gimp-image-crop dup-image width height xpos ypos)
	     
	     (set! layer-name (string-append "Frame "
			(number->string (- num-frames remaining-frames) 10)
			" (replace)"))
	     (set! this-layer (car (gimp-layer-new out-imagestack
						   width height RGB
						   layer-name 100 NORMAL-MODE)))
	     (gimp-image-add-layer out-imagestack this-layer 0)
	     
	     (copy-layer-ripple out-imagestack this-layer img drawable)
	     
	     (set! dup-layer (car (gimp-image-get-active-layer dup-image)))
	     (plug-in-displace 1 out-imagestack this-layer
			       displacement displacement
			       TRUE TRUE dup-layer dup-layer edge-type)
	     
	     (gimp-image-undo-enable dup-image)
	     (gimp-image-delete dup-image)
	     
	     (set! remaining-frames (- remaining-frames 1))
	     (set! xpos (+ xoffset xpos))
	     (set! ypos (+ yoffset ypos)))
      
      (gimp-image-undo-enable rippletiled-image)
      (gimp-image-delete rippletiled-image)
      (gimp-image-undo-enable out-imagestack)
      (gimp-display-new out-imagestack))

    (gimp-context-pop)))

(script-fu-register "script-fu-ripply-anim"
		    _"_Rippling..."
		    "Ripple any image by creating animation frames as layers"
		    "Adam D. Moss (adam@foxbox.org)"
		    "Adam D. Moss"
		    "1997"
		    "RGB* GRAY*"
		    SF-IMAGE       "Image to animage"    0
		    SF-DRAWABLE    "Drawable to animate" 0
		    SF-ADJUSTMENT _"Rippling strength"   '(3 0 256 1 10 1 0)
		    SF-ADJUSTMENT _"Number of frames"    '(15 0 256 1 10 0 1)
		    SF-OPTION     _"Edge behaviour"      '(_"Wrap"
							   _"Smear"
							   _"Black"))

(script-fu-menu-register "script-fu-ripply-anim"
			 _"<Image>/Script-Fu/Animators")