summaryrefslogtreecommitdiff
path: root/2.10/przem-apply-waves-effect.scm
blob: 52effbaab10e793c7c9128bc7e98785d961ab327 (plain)
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
; apply-waves-effect - Script-fu dodający efekt fali
; author: PRP
; licencja: Public Domain
; Gdańsk - 26-02-2025
; ver. 1.250226-0

;(define (przem-apply-waves-effect image drawable amplitude wavelength phase type)
;(define (przem-apply-waves-effect image drawable)

;  (let* (
;         (width (car (gimp-image-width image)))
;         (height (car (gimp-image-height image)))
 ;        (amplitude 10)  ; Amplituda fal
 ;        (wavelength 50) ; Długość fali
 ;        (type 0)        ; Typ fali (0 - sinusoidalna, 1 - trójkątna, 2 - prostokątna)
 ;        (phase 0)       ; Faza fali
;        )
 ;   (plug-in-waves RUN-NONINTERACTIVE image drawable amplitude wavelength type phase)
 ; )
;)
(define (przem-apply-waves-effect image drawable amplitude frequency phase)
	(let* (
         (width (car (gimp-image-width image)))
         (height (car (gimp-image-height image)))
         (new-image (car (gimp-image-duplicate image)))
         (new-drawable (car (gimp-image-get-active-drawable new-image)))
		 (pixw (cons-array 3 'byte))
		 (resize-y 0)
		 (resize-x 0)
		 (y 0)
		 (x 0))
	
		 (aset pixw 0 255)
		 (aset pixw 1 255)
		 (aset pixw 2 255)
	;(gimp-image-insert-layer new-image new-drawable 0 -1)
	(gimp-selection-none new-image)


    (gimp-context-push)
    (gimp-context-set-defaults)

	; symulacja
	(while (< y  height)
      (while (< x width)
		  (set! resize-x (+ x (* amplitude (sin (+ (* frequency x) phase)))))
          (set! resize-y (+ y (* amplitude (cos (+ (* frequency y) phase)))))
		  (set! x (+ x 1))
	   )
	   (set! x 0)
	   (set! y (+ y 1)) 
     )
     
     
    (gimp-image-scale new-image resize-x resize-y)
    (set! new-drawable (car (gimp-image-get-active-drawable new-image)))

	(set! x 0)
	(set! y 0)
	
    ; Przejdź przez każdy piksel obrazu
    (while (< y  height)
      (while (< x width)
        (let* (
          (new-x (+ x (* amplitude (sin (+ (* frequency x) phase)))))
          (new-y (+ y (* amplitude (cos (+ (* frequency y) phase)))))
          (color (cdr (gimp-image-pick-color image drawable x y FALSE FALSE 1))) 
		  ;(pre-pixel (vector (gimp-drawable-get-pixel drawable x y)))
		  ;(pixel0 (vector-ref pre-pixel 0) )
		  ;(pixel1 (vector-ref pre-pixel 1) )
		  ;(pixel2 (vector-ref pre-pixel 2) )
		  (type (car (gimp-drawable-get-pixel drawable x y)))
		  (pixel (cdr (gimp-drawable-get-pixel drawable x y)))
		  )
          (gimp-drawable-set-pixel new-drawable new-x new-y 3 color)
		  (gimp-message "Test image saved.")
		  (display "pixel: ")        (displayln pixel)
		) 
		(set! x (+ x 1))
	  )
	    (set! x 0)
		(set! y (+ y 1)) 
	)
    ;(gimp-image-set-resolution image newdpi newdpi)


    (gimp-context-pop)
    (gimp-display-new new-image)

	(gimp-selection-none new-image)

	(gimp-displays-flush)
	
) ) 
 
(define displayln (lambda (obj) (display obj) (display "\n")))


(script-fu-register "przem-apply-waves-effect"
  _"Apply a waves effect to the image."
  _"Dodaje efekt fali do zdjęcia"
  "Przenmysław R. Pietraszczyk"
  "Public Domain"
  "2025-02-23"
  "RGB*, GRAY*"
  SF-IMAGE "Image" 0
  SF-DRAWABLE "Drawable" 0
  ;SF-ADJUSTMENT "Amplitude" '(10 0 100 1 10 0 0)
  ;SF-ADJUSTMENT "Wave Length" '(50 0 100 1 10 0 0)
  ;SF-ADJUSTMENT "Phase Wave" '(0 0 100 1 10 0 0)
  ;SF-OPTION "Type" '("Sinusoidal" "Triangle" "Rectangular")
  SF-VALUE "Amplitude" "10"
  SF-VALUE "Frequency" "0.1"
  SF-VALUE "Phase" "0"

)

(script-fu-menu-register "przem-apply-waves-effect" "<Image>/Filters/PIETRASZCZYK")