; Script-Fu Twist_Various_Creations_1.scm
; Download : http://gimpchat.com/viewtopic.php?f=9&t=6781
;
;	Copyright (C) 2013 samj ( http://aljacom.com/~gmic/ )
;
;	Licence GPL
;		Ce fichier est le Script-Fu "Twist_Various_Creations_1.scm" pour Gimp. 
;		Ce Script-Fu "Twist_Various_Creations_1.scm" est un logiciel libre ; vous pouvez le redistribuer ou le modifier suivant les termes de la GNU General Public License
;		telle que publiée par la Free Software Foundation ; soit la version 3 de la licence, soit (à votre gré) toute version ultérieure.
;		Ce Script-Fu "Twist_Various_Creations_1.scm" est distribué dans l'espoir qu'il sera utile, mais SANS AUCUNE GARANTIE ; 
;		pas même la garantie implicite de COMMERCIABILISABILITÉ ni d'ADÉQUATION à UN OBJECTIF PARTICULIER.
;		Consultez la GNU General Public License pour plus de détails.
;		Vous devez avoir reçu une copie de la GNU General Public License en même temps que GIMP ; si ce n'est pas le cas, consultez <http://www.gnu.org/licenses>
;
;	Ce fichier Twist_Various_Creations_1.scm est édité avec Notepad++    http://notepad-plus-plus.org/
;
;	Version 20130327  corrections  (if (= Choose_an_object_to_create 5) (set! Choose_an_object_to_create_En_Texte "F  Gradient" ) ) et menu 
;	Version 20130323 (origine)
;
;
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;
;	Ce script est un exemple employant le filtre "Twist" version 2.1 Download http://gimpchat.com/viewtopic.php?f=7&t=6732
;
;	Accès sur l'image par :
;
;	Filtres > Misc > Concept > Twist Various Creations 1 ...
;	Filters > Misc > Concept > Twist Various Creations 1 ...
;
;	Ce script-fu est l'application d'un *concept* qui permet de créer des motifs, des brosses statiques ou dynamiques à partir d'une image.
;	Les brosses et les motifs sont sauvegardés dans le répertoire des préférences si l'option de sauvegarde est validée : "Save pattern or brush". 
;	Lors de la sauvegarde un message s'affiche pour visualiser les caractéristiques de la sauvegarde. 
;	L'utilisateur peut à tout moment supprimer les objets créés.
;	Le dégradé n'est pas obtenu en utilisant le plug-in Twist.
;
;	Ce *concept* permet d'obtenir des outils aux couleurs de l'image, par exemple, créer des feuillages riches en couleurs. 
;
;	This script-fu is the application of a concept for creating patterns, static or dynamic brushes from an image.
;	Brushes and patterns are saved in the “preferences directory” if the backup option is enabled.
;	This script-fu uses the plug-in "Twist version 2.1". 
;	Download   http://gimpchat.com/viewtopic.php?f=7&t=6732
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;
;

		
(define	
	(
		Twist_Various_Creations_1_samj
		image
		drawable
		Choose_an_object_to_create
		Use_the_image_or_color
		Color_of_the_object
		Back_Ground_Color
		Effects
		Selection_Type
		Selection_Size
		Parameter_2
		Add_an_alpha_channel
		Niveau_Blur
		Object_Name
		Backup_pattern_or_brush
		Spacing_of_the_brush
		Spacing_of_the_dynamic_brush
		Display_Filter_Settings
		
		
	)
	(let* 
		(

			(message (car (gimp-message-get-handler)))
			(old_context_transform_direction (car (gimp-context-get-transform-direction)))
			(old_context_interpolation (car (gimp-context-get-interpolation)))
			(old_context_recursion (car (gimp-context-get-transform-recursion)))
			(old_context_transform_resize (car (gimp-context-get-transform-resize)))
			(old-fg (car (gimp-context-get-foreground)))
			(old-bg (car (gimp-context-get-background)))

			(width (car (gimp-image-width image)))
			(height (car (gimp-image-height image)))

			(transparence (car (gimp-drawable-has-alpha drawable)))



			(H_origine 0)
			(V_origine 0)

			(Nb_Boucles_H 0)
			(Nb_Boucles_V 0)

			(Index_H 0)
			(Index_V 0)

			; Twist
			(run_mode 1)
			(Parameter_1 0)
			;;;;(Parameter_2 0)
			(Parameter_3 0)
			(Parameter_4 0)
			(Parameter_5 0)
			(Parameter_6 0)
			(Parameter_7 0)
			(Parameter_8 0)
			(Use_cutoff 0)
			(r_The_cutoff_radius 1)
			(dr_The_falloff_radius 1)
			(The_current_function 0)			
			(operating_mode 0)

			(Parameter_3_dyn 0)
			(Parameter_4_dyn 0)	

			(calque_pattern)
			(nouvelle_image)

			(width_1 0)
			(height_1 0)
			(copier_visible)
			(buffer-name "copier_visible")
			(selection_en_cours)

			; répertoire + nom de fichier motif
			(path)

			(NB_Images_GIH 16)
			(calque_pattern_boucle)
			(calque_pattern_1)
			(calque_pattern_2)
			(calque_pattern_3)
			(calque_pattern_4)
			(calque_pattern_5)
			(calque_pattern_6)
			(calque_pattern_7)
			(calque_pattern_8)
			(calque_pattern_9)
			(calque_pattern_10)
			(calque_pattern_11)
			(calque_pattern_12)
			(calque_pattern_13)
			(calque_pattern_14)
			(calque_pattern_15)
			(calque_pattern_16)

			(ranks)

			(decalage_H 0)
			(decalage_V 0)

			(Choose_an_object_to_create_En_Texte)
			(Use_the_image_or_color_En_Texte)

			(Nb_segments 32)
			(segment -1)
			(gradient_name Object_Name)
			(degrade)


		)




		(gimp-context-set-transform-direction TRANSFORM-FORWARD)
		(gimp-context-set-interpolation 2)
		(gimp-context-set-transform-recursion 3)
		(gimp-context-set-transform-resize TRANSFORM-RESIZE-ADJUST)
		
		(gimp-undo-push-group-start image)

		(gimp-selection-none image)

;******************************************************************************************************
; message, paramètres
;******************************************************************************************************



		(if (= Display_Filter_Settings 1)
			(begin
					;; sélectionner la console erreurs pour envoyer un message
					(gimp-message-set-handler 2)

					(if (= Choose_an_object_to_create 0) (set! Choose_an_object_to_create_En_Texte "A  Pattern and Save" ) )
					(if (= Choose_an_object_to_create 1) (set! Choose_an_object_to_create_En_Texte "B  Fill the image with a pattern" ) )
					(if (= Choose_an_object_to_create 2) (set! Choose_an_object_to_create_En_Texte "C  Brush and Save" ) )
					(if (= Choose_an_object_to_create 3) (set! Choose_an_object_to_create_En_Texte "D  Dynamic Brush and Save" ) )
					(if (= Choose_an_object_to_create 4) (set! Choose_an_object_to_create_En_Texte "E  An effect on the entire image (very slow)" ) )
					(if (= Choose_an_object_to_create 5) (set! Choose_an_object_to_create_En_Texte "F  Gradient" ) ) ; Version 20130327

					(if (= Use_the_image_or_color 0) (set! Use_the_image_or_color_En_Texte "Use Image" ) )
					(if (= Use_the_image_or_color 1) (set! Use_the_image_or_color_En_Texte "Use Color" ) )


					(gimp-message 
						(string-append "-- Twist Various Creations 1 Parameters --\n" 
							"Choose an object to create : " Choose_an_object_to_create_En_Texte "\n"
							"Use the image or color : " Use_the_image_or_color_En_Texte "\n"
							"Effects : " (number->string Effects) "\n"
							"Selection Type : " (number->string Selection_Type) "\n"
							"Selection Size : " (number->string Selection_Size) "\n"
							"Spokes : " (number->string Parameter_2) "\n"
							"Add an alpha channel : " (number->string Add_an_alpha_channel) "\n"
							"Blur : " (number->string Niveau_Blur) "\n"
							"Object Name to save : " Object_Name "\n"
							"Save pattern or brush : " (number->string Backup_pattern_or_brush) "\n"
							"Spacing of the brush : " (number->string Spacing_of_the_brush) "\n"
							"Spacing of the dynamic brush : " (number->string Spacing_of_the_dynamic_brush) "\n"
							"\n------------------------------------------\n"			
						)
					)
			)
		)



;******************************************************************************************************
; paramètres
;******************************************************************************************************


		(if (or (= Effects 0) (= Effects 4) )
			(begin
				(set! run_mode 1)
				(set! Parameter_1 1)
				(set! Parameter_2 (- 0 Parameter_2) )
				(set! Parameter_3 0)
				(set! Parameter_4 0)
				(set! Parameter_5 0)
				(set! Parameter_6 0)
				(set! Parameter_7 0)
				(set! Parameter_8 0)
				(set! Use_cutoff 0)
				(set! r_The_cutoff_radius 0.5)
				(set! dr_The_falloff_radius 0.2)
				(set! The_current_function 3)
				(set! operating_mode 0)
			)
		)


		(if (= Effects 1)
			(begin
				(set! run_mode 1)
				(set! Parameter_1 0.7)
				(set! Parameter_2 (- 0 Parameter_2) )
				(set! Parameter_3 0)
				(set! Parameter_4 0)
				(set! Parameter_5 0)
				(set! Parameter_6 0)
				(set! Parameter_7 0)
				(set! Parameter_8 0)
				(set! Use_cutoff 0)
				(set! r_The_cutoff_radius 0.5)
				(set! dr_The_falloff_radius 0.2)
				(set! The_current_function 3)
				(set! operating_mode 0)
			)
		)


		(if (= Effects 2)
			(begin
				(set! run_mode 1)
				(set! Parameter_1 -7)
				(set! Parameter_2 Parameter_2 )
				(set! Parameter_3 2)
				(set! Parameter_4 1)
				(set! Parameter_5 0)
				(set! Parameter_6 0)
				(set! Parameter_7 0)
				(set! Parameter_8 0)
				(set! Use_cutoff 0)
				(set! r_The_cutoff_radius 0.5)
				(set! dr_The_falloff_radius 0.2)
				(set! The_current_function 3)
				(set! operating_mode 0)
			)
		)


		(if (= Effects 3)
			(begin
				(set! run_mode 1)
				(set! Parameter_1 -7)
				(set! Parameter_2 Parameter_2 )
				(set! Parameter_3 2)
				(set! Parameter_4 1)
				(set! Parameter_5 0)
				(set! Parameter_6 0)
				(set! Parameter_7 0)
				(set! Parameter_8 0)
				(set! Use_cutoff 1)
				(set! r_The_cutoff_radius 0)
				(set! dr_The_falloff_radius 1)
				(set! The_current_function 3)
				(set! operating_mode 0)
			)
		)


;******************************************************************************************************
; "A Pattern" | début "C Brush" 
;******************************************************************************************************

		(if (or (= Choose_an_object_to_create 0) (= Choose_an_object_to_create 2) )
			(begin

				(gimp-context-set-background Back_Ground_Color)
				(gimp-context-set-foreground Color_of_the_object)
				
				(if (= Use_the_image_or_color 0) ; utiliser l'image
					(begin

						(set! copier_visible (car (gimp-edit-named-copy-visible image buffer-name)))

						; créer une nouvelle image rgb
						(set! nouvelle_image (car (gimp-image-new width height 0)))

						(gimp-undo-push-group-start nouvelle_image)

						; créer le premier calque
						(set! calque_pattern (car (gimp-layer-new nouvelle_image width height 0 "calque_pattern" 100 0)))

						(gimp-image-insert-layer nouvelle_image calque_pattern -1 0)

						(gimp-image-select-rectangle nouvelle_image 0  width height 0 0 )

						(set! selection_en_cours (car (gimp-edit-named-paste calque_pattern copier_visible 0)))

						(gimp-floating-sel-anchor selection_en_cours)

						(gimp-selection-none nouvelle_image)

						(gimp-layer-add-alpha calque_pattern)

						(gimp-layer-scale calque_pattern Selection_Size Selection_Size 1)

						(gimp-layer-resize calque_pattern Selection_Size Selection_Size 0 0)
						; ajuster taille image à la taille des calques
						(gimp-image-resize-to-layers nouvelle_image)

						(gimp-item-set-visible calque_pattern TRUE)

					)
					;else utiliser la couleur
					(begin

						; créer une nouvelle image rgb
						(set! nouvelle_image (car (gimp-image-new Selection_Size Selection_Size 0)))

						(gimp-undo-push-group-start nouvelle_image)

						; créer le premier calque
						(set! calque_pattern (car (gimp-layer-new nouvelle_image Selection_Size Selection_Size 0 "calque_pattern" 100 0)))

						(gimp-image-insert-layer nouvelle_image calque_pattern -1 0)

						(gimp-layer-add-alpha calque_pattern)

						(gimp-item-set-visible calque_pattern TRUE)

						(gimp-drawable-fill calque_pattern 0)
					)
				)

				(if (= Selection_Type 0) ; sélection = carré 
					(begin
						(gimp-image-select-rectangle nouvelle_image 0 0 0 Selection_Size Selection_Size)
					)
				)

				(if (= Selection_Type 1) ; sélection = cercle
					(begin
						(gimp-image-select-ellipse nouvelle_image 0 0 0 Selection_Size Selection_Size)
					)
				)

				(plug-in-Twist 
					run_mode				;      GIMP_PDB_INT32, run_mode, Interactive, non-interactive
					nouvelle_image			;      GIMP_PDB_IMAGE, image, Input image
					calque_pattern			;      GIMP_PDB_DRAWABLE, drawable, Input drawable
					Parameter_1				;      GIMP_PDB_FLOAT, a1, float parameter #1
					Parameter_2				;      GIMP_PDB_FLOAT, a2, float parameter #2
					Parameter_3				;      GIMP_PDB_FLOAT, a3, float parameter #3
					Parameter_4				;      GIMP_PDB_FLOAT, a4, float parameter #4
					Parameter_5				;      GIMP_PDB_FLOAT, a5, float parameter #5
					Parameter_6				;      GIMP_PDB_FLOAT, a6, float parameter #6
					Parameter_7				;      GIMP_PDB_FLOAT, a7, float parameter #7
					Parameter_8				;      GIMP_PDB_FLOAT, a8, float parameter #8
					"unused"				;      GIMP_PDB_STRING , lettering01, lettering #1
					"unused"				;      GIMP_PDB_STRING , lettering02, lettering #2
					"unused"				;      GIMP_PDB_STRING , lettering03, lettering #3
					"unused"				;      GIMP_PDB_STRING , lettering04, lettering #4
					"unused"				;      GIMP_PDB_STRING , lettering05, lettering #5
					"unused"				;      GIMP_PDB_STRING , lettering06, lettering #6
					"unused"				;      GIMP_PDB_STRING , lettering07, lettering #7
					"unused"				;      GIMP_PDB_STRING , lettering08, lettering #8
					Use_cutoff				;      GIMP_PDB_INT32, use_cutoff, Use cutoff or not
					r_The_cutoff_radius		;      GIMP_PDB_FLOAT, r, The cutoff radius
					dr_The_falloff_radius	;      GIMP_PDB_FLOAT, dr, The falloff radius
					The_current_function	;      GIMP_PDB_INT32, current_function, The current function
														; "R(r) - 4th order poly"	0
														; "R(phi) - cosine"			1
														; "Phi(r) - 4th order poly"	2
														; "Phi(phi) - cosine"		3
														; "R(r)Phi(phi)"			4
														; "R(r)R(phi)"				5
														; "Cosines"					6
														; "Gauss"					7
														; "XY 4th Order"			8
					operating_mode			;      GIMP_PDB_INT32, operating_mode ( 0=normal 1=mémorisation des valeurs )
				)

				(if (= Effects 4)
					(begin

						(plug-in-Twist 
							run_mode				;      GIMP_PDB_INT32, run_mode, Interactive, non-interactive
							nouvelle_image			;      GIMP_PDB_IMAGE, image, Input image
							calque_pattern			;      GIMP_PDB_DRAWABLE, drawable, Input drawable
							0.3				;      GIMP_PDB_FLOAT, a1, float parameter #1
							10				;      GIMP_PDB_FLOAT, a2, float parameter #2
							Parameter_3				;      GIMP_PDB_FLOAT, a3, float parameter #3
							Parameter_4				;      GIMP_PDB_FLOAT, a4, float parameter #4
							Parameter_5				;      GIMP_PDB_FLOAT, a5, float parameter #5
							Parameter_6				;      GIMP_PDB_FLOAT, a6, float parameter #6
							Parameter_7				;      GIMP_PDB_FLOAT, a7, float parameter #7
							Parameter_8				;      GIMP_PDB_FLOAT, a8, float parameter #8
							"unused"				;      GIMP_PDB_STRING , lettering01, lettering #1
							"unused"				;      GIMP_PDB_STRING , lettering02, lettering #2
							"unused"				;      GIMP_PDB_STRING , lettering03, lettering #3
							"unused"				;      GIMP_PDB_STRING , lettering04, lettering #4
							"unused"				;      GIMP_PDB_STRING , lettering05, lettering #5
							"unused"				;      GIMP_PDB_STRING , lettering06, lettering #6
							"unused"				;      GIMP_PDB_STRING , lettering07, lettering #7
							"unused"				;      GIMP_PDB_STRING , lettering08, lettering #8
							Use_cutoff				;      GIMP_PDB_INT32, use_cutoff, Use cutoff or not
							r_The_cutoff_radius		;      GIMP_PDB_FLOAT, r, The cutoff radius
							dr_The_falloff_radius	;      GIMP_PDB_FLOAT, dr, The falloff radius
							The_current_function	;      GIMP_PDB_INT32, current_function, The current function
																; "R(r) - 4th order poly"	0
																; "R(phi) - cosine"			1
																; "Phi(r) - 4th order poly"	2
																; "Phi(phi) - cosine"		3
																; "R(r)Phi(phi)"			4
																; "R(r)R(phi)"				5
																; "Cosines"					6
																; "Gauss"					7
																; "XY 4th Order"			8
							operating_mode			;      GIMP_PDB_INT32, operating_mode ( 0=normal 1=mémorisation des valeurs )
						)

					)
				)

				(gimp-selection-none nouvelle_image)
				
				(if (= Add_an_alpha_channel 0)
					(begin
						(gimp-image-flatten nouvelle_image)
					)
				)

				(if (> Niveau_Blur 0)
					(begin
						(plug-in-gauss 1 nouvelle_image (car (gimp-image-get-active-layer nouvelle_image)) Niveau_Blur Niveau_Blur 1)
					)
				)
				;          ---------------------------------------------------
				;                         FIN de la première partie de "C Brush" 
				;          ---------------------------------------------------
				(if (= Choose_an_object_to_create 0) ; pattern
					(begin

						(plug-in-make-seamless 1 nouvelle_image (car (gimp-image-get-active-layer nouvelle_image))  )

						(if (= Backup_pattern_or_brush 1)
							(begin
								; déterminer le chemin complet du motif à sauvegarder
								(set! path (string-append gimp-directory "/patterns/" (strcat Object_Name "_" (number->string Selection_Size) ".pat") ) )

								; sauvegarder le motif sous :  "Object_Name"_"Selection_Size".pat
								(file-pat-save 1 nouvelle_image (car (gimp-image-get-active-layer nouvelle_image)) path path (strcat Object_Name "_" (number->string Selection_Size) ) )

								; mettre à jour les motifs dans Gimp
								(gimp-patterns-refresh)

								; choisir le motif comme motif actif
								(gimp-context-set-pattern (strcat Object_Name "_" (number->string Selection_Size) ) )

								(gimp-image-delete nouvelle_image)

								(gimp-message (string-append "Pattern Path :\n" path "\nPattern Name:\n" Object_Name "_" (number->string Selection_Size) ) )
							)
							;else
							(begin
								(gimp-undo-push-group-end nouvelle_image)

								(gimp-display-new nouvelle_image)
							)
						)
					)
				)

			)
		)


;******************************************************************************************************
; "B Fill the image with the pattern" 
;******************************************************************************************************


		(if (= Choose_an_object_to_create 1)
			(begin

				(gimp-context-set-background Back_Ground_Color)
				(gimp-context-set-foreground Color_of_the_object)
				
				(if (= Use_the_image_or_color 0) ; utiliser l'image
					(begin

						(set! copier_visible (car (gimp-edit-named-copy-visible image buffer-name)))

						; créer une nouvelle image rgb
						(set! nouvelle_image (car (gimp-image-new width height 0)))

						(gimp-undo-push-group-start nouvelle_image)

						; créer le premier calque
						(set! calque_pattern (car (gimp-layer-new nouvelle_image width height 0 "calque_pattern" 100 0)))

						(gimp-image-insert-layer nouvelle_image calque_pattern -1 0)

						(gimp-image-select-rectangle nouvelle_image 0  width height 0 0 )

						(set! selection_en_cours (car (gimp-edit-named-paste calque_pattern copier_visible 0)))

						(gimp-floating-sel-anchor selection_en_cours)

						(gimp-selection-none nouvelle_image)

						(gimp-layer-add-alpha calque_pattern)

						(gimp-layer-scale calque_pattern Selection_Size Selection_Size 1)

						(gimp-layer-resize calque_pattern Selection_Size Selection_Size 0 0)
						; ajuster taille image à la taille des calques
						(gimp-image-resize-to-layers nouvelle_image)

						(gimp-item-set-visible calque_pattern TRUE)

					)
					;else utiliser la couleur
					(begin

						; créer une nouvelle image rgb
						(set! nouvelle_image (car (gimp-image-new Selection_Size Selection_Size 0)))

						(gimp-undo-push-group-start nouvelle_image)

						; créer le premier calque
						(set! calque_pattern (car (gimp-layer-new nouvelle_image Selection_Size Selection_Size 0 "calque_pattern" 100 0)))

						(gimp-image-insert-layer nouvelle_image calque_pattern -1 0)

						(gimp-layer-add-alpha calque_pattern)

						(gimp-item-set-visible calque_pattern TRUE)

						(gimp-drawable-fill calque_pattern 0)
					)
				)

				(if (= Selection_Type 0) ; sélection = carré 
					(begin
						(gimp-image-select-rectangle nouvelle_image 0 0 0 Selection_Size Selection_Size)
					)
				)

				(if (= Selection_Type 1) ; sélection = cercle
					(begin
						(gimp-image-select-ellipse nouvelle_image 0 0 0 Selection_Size Selection_Size)
					)
				)

				(plug-in-Twist 
					run_mode				;      GIMP_PDB_INT32, run_mode, Interactive, non-interactive
					nouvelle_image			;      GIMP_PDB_IMAGE, image, Input image
					calque_pattern			;      GIMP_PDB_DRAWABLE, drawable, Input drawable
					Parameter_1				;      GIMP_PDB_FLOAT, a1, float parameter #1
					Parameter_2				;      GIMP_PDB_FLOAT, a2, float parameter #2
					Parameter_3				;      GIMP_PDB_FLOAT, a3, float parameter #3
					Parameter_4				;      GIMP_PDB_FLOAT, a4, float parameter #4
					Parameter_5				;      GIMP_PDB_FLOAT, a5, float parameter #5
					Parameter_6				;      GIMP_PDB_FLOAT, a6, float parameter #6
					Parameter_7				;      GIMP_PDB_FLOAT, a7, float parameter #7
					Parameter_8				;      GIMP_PDB_FLOAT, a8, float parameter #8
					"unused"				;      GIMP_PDB_STRING , lettering01, lettering #1
					"unused"				;      GIMP_PDB_STRING , lettering02, lettering #2
					"unused"				;      GIMP_PDB_STRING , lettering03, lettering #3
					"unused"				;      GIMP_PDB_STRING , lettering04, lettering #4
					"unused"				;      GIMP_PDB_STRING , lettering05, lettering #5
					"unused"				;      GIMP_PDB_STRING , lettering06, lettering #6
					"unused"				;      GIMP_PDB_STRING , lettering07, lettering #7
					"unused"				;      GIMP_PDB_STRING , lettering08, lettering #8
					Use_cutoff				;      GIMP_PDB_INT32, use_cutoff, Use cutoff or not
					r_The_cutoff_radius		;      GIMP_PDB_FLOAT, r, The cutoff radius
					dr_The_falloff_radius	;      GIMP_PDB_FLOAT, dr, The falloff radius
					The_current_function	;      GIMP_PDB_INT32, current_function, The current function
														; "R(r) - 4th order poly"	0
														; "R(phi) - cosine"			1
														; "Phi(r) - 4th order poly"	2
														; "Phi(phi) - cosine"		3
														; "R(r)Phi(phi)"			4
														; "R(r)R(phi)"				5
														; "Cosines"					6
														; "Gauss"					7
														; "XY 4th Order"			8
					operating_mode			;      GIMP_PDB_INT32, operating_mode ( 0=normal 1=mémorisation des valeurs )
				)

				(if (= Effects 4)
					(begin

						(plug-in-Twist 
							run_mode				;      GIMP_PDB_INT32, run_mode, Interactive, non-interactive
							nouvelle_image			;      GIMP_PDB_IMAGE, image, Input image
							calque_pattern			;      GIMP_PDB_DRAWABLE, drawable, Input drawable
							0.3				;      GIMP_PDB_FLOAT, a1, float parameter #1
							10				;      GIMP_PDB_FLOAT, a2, float parameter #2
							Parameter_3				;      GIMP_PDB_FLOAT, a3, float parameter #3
							Parameter_4				;      GIMP_PDB_FLOAT, a4, float parameter #4
							Parameter_5				;      GIMP_PDB_FLOAT, a5, float parameter #5
							Parameter_6				;      GIMP_PDB_FLOAT, a6, float parameter #6
							Parameter_7				;      GIMP_PDB_FLOAT, a7, float parameter #7
							Parameter_8				;      GIMP_PDB_FLOAT, a8, float parameter #8
							"unused"				;      GIMP_PDB_STRING , lettering01, lettering #1
							"unused"				;      GIMP_PDB_STRING , lettering02, lettering #2
							"unused"				;      GIMP_PDB_STRING , lettering03, lettering #3
							"unused"				;      GIMP_PDB_STRING , lettering04, lettering #4
							"unused"				;      GIMP_PDB_STRING , lettering05, lettering #5
							"unused"				;      GIMP_PDB_STRING , lettering06, lettering #6
							"unused"				;      GIMP_PDB_STRING , lettering07, lettering #7
							"unused"				;      GIMP_PDB_STRING , lettering08, lettering #8
							Use_cutoff				;      GIMP_PDB_INT32, use_cutoff, Use cutoff or not
							r_The_cutoff_radius		;      GIMP_PDB_FLOAT, r, The cutoff radius
							dr_The_falloff_radius	;      GIMP_PDB_FLOAT, dr, The falloff radius
							The_current_function	;      GIMP_PDB_INT32, current_function, The current function
																; "R(r) - 4th order poly"	0
																; "R(phi) - cosine"			1
																; "Phi(r) - 4th order poly"	2
																; "Phi(phi) - cosine"		3
																; "R(r)Phi(phi)"			4
																; "R(r)R(phi)"				5
																; "Cosines"					6
																; "Gauss"					7
																; "XY 4th Order"			8
							operating_mode			;      GIMP_PDB_INT32, operating_mode ( 0=normal 1=mémorisation des valeurs )
						)

					)
				)

				(gimp-selection-none nouvelle_image)
				
				(if (= Add_an_alpha_channel 0)
					(begin
						(gimp-image-flatten nouvelle_image)
					)
				)

				(if (> Niveau_Blur 0)
					(begin
						(plug-in-gauss 1 nouvelle_image (car (gimp-image-get-active-layer nouvelle_image)) Niveau_Blur Niveau_Blur 1)
					)
				)
				
				(plug-in-make-seamless 1 nouvelle_image (car (gimp-image-get-active-layer nouvelle_image))  )

				;;;(gimp-display-new nouvelle_image)

				;;;(gimp-undo-push-group-end nouvelle_image)

				;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

				; copier le motif
				(gimp-edit-copy-visible nouvelle_image)

				; astuce de RobA  http://www.gimpchat.com/viewtopic.php?f=8&t=1221&start=40 pour que le presse-papiers devienne le motif sans avoir à choisir le nom qui varie selon les langues de Gimp
				(gimp-context-set-pattern (list-ref (cadr (gimp-patterns-get-list "")) 0)) ; set patten to clipboard (first in list)

				; créer une sélection rectangulaire
				(gimp-image-select-rectangle
					image	; image 
					0		; operation 
					0		; x 
					0		; y 
					width	; width 
					height	; height
				)

				; remplir la sélection de motif	
				(gimp-bucket-fill 
					drawable	; drawable 
					2			; fill-mode 
					0			; paint-mode 
					100			; opacity 
					0			; threshold 
					TRUE		; sample-merged 
					0			; x 
					0			; y
				)

				(gimp-selection-none image)
				
				(gimp-image-delete nouvelle_image)
			)
		)





;******************************************************************************************************
; "C Brush" , le début est dans "A Pattern"
;******************************************************************************************************


		(if (= Choose_an_object_to_create 2)
			(begin

						(if (= Backup_pattern_or_brush 1)
							(begin
								; déterminer le chemin complet de la brosse à sauvegarder
								(set! path (string-append gimp-directory "/brushes/" (strcat Object_Name "_" (number->string Selection_Size) ".gbr") ) )

								; sauvegarder la brosse sous :  "Object_Name"_"Selection_Size".gbr
								(file-gbr-save			
									1															; GIMP_PDB_INT32,    "run-mode",     "The run mode { RUN-INTERACTIVE (0), RUN-NONINTERACTIVE (1) }"
									nouvelle_image												; GIMP_PDB_IMAGE,    "image",        "Input image"
									(car (gimp-image-get-active-layer nouvelle_image))			; GIMP_PDB_DRAWABLE, "drawable",     "Drawable to save"
									path														; GIMP_PDB_STRING,   "filename",     "The name of the file to save the image in"
									path														; GIMP_PDB_STRING,   "raw-filename", "The name of the file to save the image in"
									Spacing_of_the_brush										; GIMP_PDB_INT32,    "spacing",      "Spacing of the brush"
									(strcat Object_Name "_" (number->string Selection_Size) )	; GIMP_PDB_STRING,   "description",  "Short description of the brush"
								)

								; mettre à jour les brosses dans Gimp
								(gimp-brushes-refresh)

								; choisir la brosse comme brosse active
								(gimp-context-set-brush (strcat Object_Name "_" (number->string Selection_Size) ) )

								(gimp-image-delete nouvelle_image)

								(gimp-message (string-append "Brush Path :\n" path "\nBrush Name:\n" Object_Name "_" (number->string Selection_Size) ) )
							)
							;else
							(begin
								(gimp-undo-push-group-end nouvelle_image)

								(gimp-display-new nouvelle_image)
							)
						)



			)
		)




;******************************************************************************************************
; "D Dynamic Brush"
;******************************************************************************************************


		(if (= Choose_an_object_to_create 3)
			(begin

				(gimp-context-set-background Back_Ground_Color)
				(gimp-context-set-foreground Color_of_the_object)
				
				(if (= Use_the_image_or_color 0) ; utiliser l'image
					(begin

						(set! copier_visible (car (gimp-edit-named-copy-visible image buffer-name)))

						; créer une nouvelle image rgb
						(set! nouvelle_image (car (gimp-image-new width height 0)))

						(gimp-undo-push-group-start nouvelle_image)

						; créer le premier calque
						(set! calque_pattern (car (gimp-layer-new nouvelle_image width height 0 "calque_pattern" 100 0)))

						(gimp-image-insert-layer nouvelle_image calque_pattern -1 0)

						(gimp-image-select-rectangle nouvelle_image 0  width height 0 0 )

						(set! selection_en_cours (car (gimp-edit-named-paste calque_pattern copier_visible 0)))

						(gimp-floating-sel-anchor selection_en_cours)

						(gimp-selection-none nouvelle_image)

						(gimp-layer-add-alpha calque_pattern)

						(gimp-layer-scale calque_pattern Selection_Size Selection_Size 1)

						(gimp-layer-resize calque_pattern Selection_Size Selection_Size 0 0)
						; ajuster taille image à la taille des calques
						(gimp-image-resize-to-layers nouvelle_image)

						(gimp-item-set-visible calque_pattern TRUE)

					)
					;else utiliser la couleur
					(begin

						; créer une nouvelle image rgb
						(set! nouvelle_image (car (gimp-image-new Selection_Size Selection_Size 0)))

						(gimp-undo-push-group-start nouvelle_image)

						; créer le premier calque
						(set! calque_pattern (car (gimp-layer-new nouvelle_image Selection_Size Selection_Size 0 "calque_pattern" 100 0)))

						(gimp-image-insert-layer nouvelle_image calque_pattern -1 0)

						(gimp-layer-add-alpha calque_pattern)

						(gimp-item-set-visible calque_pattern TRUE)

						(gimp-drawable-fill calque_pattern 0)
					)
				)

				;; copier le calque calque_pattern sur les 15 autres calques
				(set! copier_visible (car (gimp-edit-named-copy-visible nouvelle_image buffer-name)))




				(while
					(> NB_Images_GIH 0)
						(begin

							(set! calque_pattern_boucle (string-append "calque_pattern_" (number->string NB_Images_GIH) )  )

							(set! calque_pattern_boucle (car (gimp-layer-new nouvelle_image Selection_Size Selection_Size 0 "calque_pattern_boucle" 100 0)))

							(gimp-image-insert-layer nouvelle_image calque_pattern_boucle -1 0)

							(gimp-image-select-rectangle nouvelle_image 0  Selection_Size Selection_Size 0 0 )

							(set! selection_en_cours (car (gimp-edit-named-paste calque_pattern_boucle copier_visible 0)))

							(gimp-floating-sel-anchor selection_en_cours)

							(gimp-selection-none nouvelle_image)

							(gimp-layer-add-alpha calque_pattern_boucle)

							(gimp-item-set-visible calque_pattern_boucle TRUE)




							(if (= Selection_Type 0) ; sélection = carré 
								(begin
									(gimp-image-select-rectangle nouvelle_image 0 0 0 Selection_Size Selection_Size)
								)
							)

							(if (= Selection_Type 1) ; sélection = cercle
								(begin
									(gimp-image-select-ellipse nouvelle_image 0 0 0 Selection_Size Selection_Size)
								)
							)

							(plug-in-Twist 
								run_mode				;      GIMP_PDB_INT32, run_mode, Interactive, non-interactive
								nouvelle_image			;      GIMP_PDB_IMAGE, image, Input image
								calque_pattern_boucle			;      GIMP_PDB_DRAWABLE, drawable, Input drawable
								Parameter_1				;      GIMP_PDB_FLOAT, a1, float parameter #1
								Parameter_2				;      GIMP_PDB_FLOAT, a2, float parameter #2
								Parameter_3_dyn				;      GIMP_PDB_FLOAT, a3, float parameter #3
								Parameter_4_dyn				;      GIMP_PDB_FLOAT, a4, float parameter #4
								Parameter_5				;      GIMP_PDB_FLOAT, a5, float parameter #5
								Parameter_6				;      GIMP_PDB_FLOAT, a6, float parameter #6
								Parameter_7				;      GIMP_PDB_FLOAT, a7, float parameter #7
								Parameter_8				;      GIMP_PDB_FLOAT, a8, float parameter #8
								"unused"				;      GIMP_PDB_STRING , lettering01, lettering #1
								"unused"				;      GIMP_PDB_STRING , lettering02, lettering #2
								"unused"				;      GIMP_PDB_STRING , lettering03, lettering #3
								"unused"				;      GIMP_PDB_STRING , lettering04, lettering #4
								"unused"				;      GIMP_PDB_STRING , lettering05, lettering #5
								"unused"				;      GIMP_PDB_STRING , lettering06, lettering #6
								"unused"				;      GIMP_PDB_STRING , lettering07, lettering #7
								"unused"				;      GIMP_PDB_STRING , lettering08, lettering #8
								Use_cutoff				;      GIMP_PDB_INT32, use_cutoff, Use cutoff or not
								r_The_cutoff_radius		;      GIMP_PDB_FLOAT, r, The cutoff radius
								dr_The_falloff_radius	;      GIMP_PDB_FLOAT, dr, The falloff radius
								The_current_function	;      GIMP_PDB_INT32, current_function, The current function
																	; "R(r) - 4th order poly"	0
																	; "R(phi) - cosine"			1
																	; "Phi(r) - 4th order poly"	2
																	; "Phi(phi) - cosine"		3
																	; "R(r)Phi(phi)"			4
																	; "R(r)R(phi)"				5
																	; "Cosines"					6
																	; "Gauss"					7
																	; "XY 4th Order"			8
								operating_mode			;      GIMP_PDB_INT32, operating_mode ( 0=normal 1=mémorisation des valeurs )
							)

							(if (= Effects 4)
								(begin

									(plug-in-Twist 
										run_mode				;      GIMP_PDB_INT32, run_mode, Interactive, non-interactive
										nouvelle_image			;      GIMP_PDB_IMAGE, image, Input image
										calque_pattern_boucle			;      GIMP_PDB_DRAWABLE, drawable, Input drawable
										0.3				;      GIMP_PDB_FLOAT, a1, float parameter #1
										10				;      GIMP_PDB_FLOAT, a2, float parameter #2
										Parameter_3				;      GIMP_PDB_FLOAT, a3, float parameter #3
										Parameter_4				;      GIMP_PDB_FLOAT, a4, float parameter #4
										Parameter_5				;      GIMP_PDB_FLOAT, a5, float parameter #5
										Parameter_6				;      GIMP_PDB_FLOAT, a6, float parameter #6
										Parameter_7				;      GIMP_PDB_FLOAT, a7, float parameter #7
										Parameter_8				;      GIMP_PDB_FLOAT, a8, float parameter #8
										"unused"				;      GIMP_PDB_STRING , lettering01, lettering #1
										"unused"				;      GIMP_PDB_STRING , lettering02, lettering #2
										"unused"				;      GIMP_PDB_STRING , lettering03, lettering #3
										"unused"				;      GIMP_PDB_STRING , lettering04, lettering #4
										"unused"				;      GIMP_PDB_STRING , lettering05, lettering #5
										"unused"				;      GIMP_PDB_STRING , lettering06, lettering #6
										"unused"				;      GIMP_PDB_STRING , lettering07, lettering #7
										"unused"				;      GIMP_PDB_STRING , lettering08, lettering #8
										Use_cutoff				;      GIMP_PDB_INT32, use_cutoff, Use cutoff or not
										r_The_cutoff_radius		;      GIMP_PDB_FLOAT, r, The cutoff radius
										dr_The_falloff_radius	;      GIMP_PDB_FLOAT, dr, The falloff radius
										The_current_function	;      GIMP_PDB_INT32, current_function, The current function
																			; "R(r) - 4th order poly"	0
																			; "R(phi) - cosine"			1
																			; "Phi(r) - 4th order poly"	2
																			; "Phi(phi) - cosine"		3
																			; "R(r)Phi(phi)"			4
																			; "R(r)R(phi)"				5
																			; "Cosines"					6
																			; "Gauss"					7
																			; "XY 4th Order"			8
										operating_mode			;      GIMP_PDB_INT32, operating_mode ( 0=normal 1=mémorisation des valeurs )
									)

								)
							)

							(gimp-selection-none nouvelle_image)









							(set! Parameter_3_dyn (- (/ (random 200) 100) 1)    ) ; de -1 à +1
							(set! Parameter_4_dyn (- (/ (random 100) 100) 0.5)  ) ; de -0.5 à + 0.5

							(set! NB_Images_GIH (- NB_Images_GIH 1))

						)
				)

				(gimp-image-remove-layer nouvelle_image calque_pattern)

				;;;;;;;;;;;;;;;;

				(if (= Backup_pattern_or_brush 1)
					(begin
						; déterminer le chemin complet de la brosse à sauvegarder
						(set! path (string-append gimp-directory "/brushes/" (strcat Object_Name "_" (number->string Selection_Size) ".gih") ) )

						; sauvegarder la brosse sous :  "Object_Name"_"Selection_Size".gih

						(set! ranks (cons-array 1 'byte))
						(vector-set! ranks 0 16)

						(file-gih-save 
							1															; GIMP_PDB_INT32       "run-mode"     "The run mode { RUN-INTERACTIVE (0) RUN-NONINTERACTIVE (1) }"
							nouvelle_image												; GIMP_PDB_IMAGE       "image"        "Input image"
							(car (gimp-image-get-active-layer nouvelle_image))			; GIMP_PDB_DRAWABLE    "drawable"     "Drawable to save"
							path														; GIMP_PDB_STRING      "filename"     "The name of the file to save the brush pipe in"
							path														; GIMP_PDB_STRING      "raw-filename" "The name of the file to save the brush pipe in"
							Spacing_of_the_dynamic_brush								; GIMP_PDB_INT32       "spacing"      "Spacing of the brush"
							(strcat Object_Name "_" (number->string Selection_Size) )	; GIMP_PDB_STRING      "description"  "Short description of the brush pipe"
							Selection_Size												; GIMP_PDB_INT32       "cell-width"   "Width of the brush cells"
							Selection_Size												; GIMP_PDB_INT32       "cell-height"  "Width of the brush cells"
							1															; GIMP_PDB_INT8        "display-cols" "Display column number"
							1															; GIMP_PDB_INT8        "display-rows" "Display row number"
							1															; GIMP_PDB_INT32       "dimension"    "Dimension of the brush pipe"
							ranks														; GIMP_PDB_INT8ARRAY   "rank"         "Ranks of the dimensions" The number of rank and sel args depend on the dimension
							1															; GIMP_PDB_INT32       "dimension"    "Dimension (again)"
							'("random")													; GIMP_PDB_STRINGARRAY "sel"          "Selection modes" }
						)





						; mettre à jour les brosses dans Gimp
						(gimp-brushes-refresh)
						
						; choisir la brosse comme brosse active
						(gimp-context-set-brush (strcat Object_Name "_" (number->string Selection_Size) ) )
						
						(gimp-image-delete nouvelle_image)
						
						(gimp-message (string-append "Brush Path :\n" path "\nBrush Name:\n" Object_Name "_" (number->string Selection_Size) ) )
					)
					;else
					(begin
						(gimp-undo-push-group-end nouvelle_image)

						(gimp-display-new nouvelle_image)
					)
				)





			)
		)




;******************************************************************************************************
; "E An effect on the entire image (very slow)"
;******************************************************************************************************



		(if (= Choose_an_object_to_create 4)
			(begin

				(if (= Add_an_alpha_channel 1)
					(begin
						(if (= transparence 0) ; pas de canal alpha
							(begin
								(set! transparence 1)
								(gimp-layer-add-alpha (car (gimp-image-get-active-drawable image)))
							)
						)
					)
				)

				(set! Nb_Boucles_H (truncate (/ width Selection_Size) ) )
				(set! Nb_Boucles_V (truncate (/ height Selection_Size) ) )

				(if (= width (* Nb_Boucles_H  Selection_Size  ) )
					(begin
						(set! decalage_H 0)
					)
					;else
					(begin
						(set! decalage_H  (round (/ (modulo width Selection_Size ) 2 ) ) )
					)
				)

				(if (= height (* Nb_Boucles_V  Selection_Size  ) )
					(begin
						(set! decalage_V 0)
					)
					;else
					(begin
						(set! decalage_V  (round (/ (modulo height Selection_Size )  2 ) ) )
					)
				)

				; (gimp-message (string-append (number->string Nb_Boucles_H ) "\n"  (number->string Nb_Boucles_V ) "\n" (number->string decalage_H ) "\n" (number->string decalage_V )  ) )

					(while
						(< Index_H Nb_Boucles_H)
							(begin
										(while (< Index_V Nb_Boucles_V)
											(begin
												(set! V_origine (* Index_V Selection_Size) )

												(if (= Selection_Type 0) ; sélection = carré 
													(begin
														(gimp-image-select-rectangle image 0 (+ H_origine decalage_H ) (+ V_origine decalage_V ) Selection_Size Selection_Size)
													)
												)

												(if (= Selection_Type 1) ; sélection = cercle
													(begin
														(gimp-image-select-ellipse image 0 (+ H_origine decalage_H ) (+ V_origine decalage_V ) Selection_Size Selection_Size)
													)
												)

												(plug-in-Twist 
													run_mode				;      GIMP_PDB_INT32, run_mode, Interactive, non-interactive
													image					;      GIMP_PDB_IMAGE, image, Input image
													drawable				;      GIMP_PDB_DRAWABLE, drawable, Input drawable
													Parameter_1				;      GIMP_PDB_FLOAT, a1, float parameter #1
													Parameter_2				;      GIMP_PDB_FLOAT, a2, float parameter #2
													Parameter_3				;      GIMP_PDB_FLOAT, a3, float parameter #3
													Parameter_4				;      GIMP_PDB_FLOAT, a4, float parameter #4
													Parameter_5				;      GIMP_PDB_FLOAT, a5, float parameter #5
													Parameter_6				;      GIMP_PDB_FLOAT, a6, float parameter #6
													Parameter_7				;      GIMP_PDB_FLOAT, a7, float parameter #7
													Parameter_8				;      GIMP_PDB_FLOAT, a8, float parameter #8
													"unused"				;      GIMP_PDB_STRING , lettering01, lettering #1
													"unused"				;      GIMP_PDB_STRING , lettering02, lettering #2
													"unused"				;      GIMP_PDB_STRING , lettering03, lettering #3
													"unused"				;      GIMP_PDB_STRING , lettering04, lettering #4
													"unused"				;      GIMP_PDB_STRING , lettering05, lettering #5
													"unused"				;      GIMP_PDB_STRING , lettering06, lettering #6
													"unused"				;      GIMP_PDB_STRING , lettering07, lettering #7
													"unused"				;      GIMP_PDB_STRING , lettering08, lettering #8
													Use_cutoff				;      GIMP_PDB_INT32, use_cutoff, Use cutoff or not
													r_The_cutoff_radius		;      GIMP_PDB_FLOAT, r, The cutoff radius
													dr_The_falloff_radius	;      GIMP_PDB_FLOAT, dr, The falloff radius
													The_current_function	;      GIMP_PDB_INT32, current_function, The current function
																						; "R(r) - 4th order poly"	0
																						; "R(phi) - cosine"			1
																						; "Phi(r) - 4th order poly"	2
																						; "Phi(phi) - cosine"		3
																						; "R(r)Phi(phi)"			4
																						; "R(r)R(phi)"				5
																						; "Cosines"					6
																						; "Gauss"					7
																						; "XY 4th Order"			8
													operating_mode			;      GIMP_PDB_INT32, operating_mode ( 0=normal 1=mémorisation des valeurs )
												)

												(if (= Effects 4)
													(begin

														(plug-in-Twist 
															run_mode				;      GIMP_PDB_INT32, run_mode, Interactive, non-interactive
															image					;      GIMP_PDB_IMAGE, image, Input image
															drawable				;      GIMP_PDB_DRAWABLE, drawable, Input drawable
															0.3				;      GIMP_PDB_FLOAT, a1, float parameter #1
															10				;      GIMP_PDB_FLOAT, a2, float parameter #2
															Parameter_3				;      GIMP_PDB_FLOAT, a3, float parameter #3
															Parameter_4				;      GIMP_PDB_FLOAT, a4, float parameter #4
															Parameter_5				;      GIMP_PDB_FLOAT, a5, float parameter #5
															Parameter_6				;      GIMP_PDB_FLOAT, a6, float parameter #6
															Parameter_7				;      GIMP_PDB_FLOAT, a7, float parameter #7
															Parameter_8				;      GIMP_PDB_FLOAT, a8, float parameter #8
															"unused"				;      GIMP_PDB_STRING , lettering01, lettering #1
															"unused"				;      GIMP_PDB_STRING , lettering02, lettering #2
															"unused"				;      GIMP_PDB_STRING , lettering03, lettering #3
															"unused"				;      GIMP_PDB_STRING , lettering04, lettering #4
															"unused"				;      GIMP_PDB_STRING , lettering05, lettering #5
															"unused"				;      GIMP_PDB_STRING , lettering06, lettering #6
															"unused"				;      GIMP_PDB_STRING , lettering07, lettering #7
															"unused"				;      GIMP_PDB_STRING , lettering08, lettering #8
															Use_cutoff				;      GIMP_PDB_INT32, use_cutoff, Use cutoff or not
															r_The_cutoff_radius		;      GIMP_PDB_FLOAT, r, The cutoff radius
															dr_The_falloff_radius	;      GIMP_PDB_FLOAT, dr, The falloff radius
															The_current_function	;      GIMP_PDB_INT32, current_function, The current function
																								; "R(r) - 4th order poly"	0
																								; "R(phi) - cosine"			1
																								; "Phi(r) - 4th order poly"	2
																								; "Phi(phi) - cosine"		3
																								; "R(r)Phi(phi)"			4
																								; "R(r)R(phi)"				5
																								; "Cosines"					6
																								; "Gauss"					7
																								; "XY 4th Order"			8
															operating_mode			;      GIMP_PDB_INT32, operating_mode ( 0=normal 1=mémorisation des valeurs )
														)

													)
												)

												(gimp-selection-none image)

												(set! Index_V (+ Index_V 1))
											)
										)
								(set! Index_V 0)
								(set! V_origine 0)
								(set! Index_H (+ Index_H 1))
								(set! H_origine (* Index_H Selection_Size) )
							)	
					)


			)
		)



;******************************************************************************************************
; "F Gradient"
;******************************************************************************************************



		(if (= Choose_an_object_to_create 5)
			(begin


						(set! copier_visible (car (gimp-edit-named-copy-visible image buffer-name)))

						; créer une nouvelle image rgb
						(set! nouvelle_image (car (gimp-image-new width height 0)))

						(gimp-undo-push-group-start nouvelle_image)

						; créer le premier calque
						(set! calque_pattern (car (gimp-layer-new nouvelle_image width height 0 "calque_pattern" 100 0)))

						(gimp-image-insert-layer nouvelle_image calque_pattern -1 0)

						(gimp-image-select-rectangle nouvelle_image 0  width height 0 0 )

						(set! selection_en_cours (car (gimp-edit-named-paste calque_pattern copier_visible 0)))

						(gimp-floating-sel-anchor selection_en_cours)

						(gimp-selection-none nouvelle_image)

						(gimp-layer-add-alpha calque_pattern)

						(gimp-layer-scale calque_pattern 32 32 1)

						(gimp-layer-resize calque_pattern 32 32 0 0)
						; ajuster taille image à la taille des calques
						(gimp-image-resize-to-layers nouvelle_image)

						(gimp-item-set-visible calque_pattern TRUE)

						(plug-in-gauss 1 nouvelle_image (car (gimp-image-get-active-layer nouvelle_image)) 5 5 1)

						(gimp-undo-push-group-end nouvelle_image)

						; (gimp-display-new nouvelle_image)

						; paramètres du dégradé *******************************************************************************		

							; créer le dégradé degrade
							(set! degrade (car (gimp-gradient-new gradient_name)))

							; rendre degrade actif
							(gimp-context-set-gradient degrade)

							; diviser le dégradé en x segments égaux
							(gimp-gradient-segment-range-split-uniform 
										degrade ; name 
										0 ; start-segment	The index of the first segment to operate on (start-segment >= 0)
										(- Nb_segments 1) ; end-segment	The index of the last segment to operate on. If negative, the selection will extend to the end of the string.
										Nb_segments ; split-parts	The number of uniform divisions to split each segment to (2 <= split-parts <= 1024)
							)

							; positionner segment
							(set! segment -1)


							; boucle pour créer les segments
							(while 
								(< segment (- Nb_segments 1)) 
									(begin

										(set! segment (+ 1 segment))

										; segment partie gauche
										(gimp-gradient-segment-set-left-color 
													degrade ; name 
													segment ; segment	The index of the segment within the gradient (segment >= 0)
													(car (gimp-image-pick-color nouvelle_image calque_pattern segment segment FALSE FALSE 0)) ; color	 The color to set
													(truncate (+ 11 (random 90))) ; opacity
										)

										; segment partie droite
										(gimp-gradient-segment-set-right-color 
													degrade ; name 
													segment ; segment 
													(car (gimp-image-pick-color nouvelle_image calque_pattern segment segment FALSE FALSE 0)) ; color	 The color to set
													(truncate (+ 11 (random 90))) ; opacity
										)
									)
							)

						(gimp-gradient-segment-range-split-uniform degrade 1 2 (truncate (+ 2 (random 17) ) ) )
						(gimp-gradient-segment-range-split-uniform degrade 3 4 (truncate (+ 2 (random 17) ) ) )
						(gimp-gradient-segment-range-split-uniform degrade 5 6 (truncate (+ 2 (random 17) ) ) )
						(gimp-gradient-segment-range-split-uniform degrade 7 8 (truncate (+ 2 (random 17) ) ) )
						(gimp-gradient-segment-range-split-uniform degrade 9 10 (truncate (+ 2 (random 17) ) ) )
						(gimp-gradient-segment-range-split-uniform degrade 11 12 (truncate (+ 2 (random 17) ) ) )
						(gimp-gradient-segment-range-split-uniform degrade 13 14 (truncate (+ 2 (random 17) ) ) )
						(gimp-gradient-segment-range-split-uniform degrade 15 16 (truncate (+ 2 (random 17) ) ) )
						(gimp-gradient-segment-range-split-uniform degrade 17 18 (truncate (+ 2 (random 17) ) ) )
						(gimp-gradient-segment-range-split-uniform degrade 19 20 (truncate (+ 2 (random 17) ) ) )
						(gimp-gradient-segment-range-split-uniform degrade 21 22 (truncate (+ 2 (random 17) ) ) )
						(gimp-gradient-segment-range-split-uniform degrade 23 24 (truncate (+ 2 (random 17) ) ) )
						(gimp-gradient-segment-range-split-uniform degrade 25 26 (truncate (+ 2 (random 17) ) ) )
						(gimp-gradient-segment-range-split-uniform degrade 27 28 (truncate (+ 2 (random 17) ) ) )
						(gimp-gradient-segment-range-split-uniform degrade 25 26 (truncate (+ 2 (random 17) ) ) )
						(gimp-gradient-segment-range-split-uniform degrade 27 28 (truncate (+ 2 (random 17) ) ) )					

						(gimp-gradients-set-active degrade)

						;*******************************************************************************************


						(gimp-image-delete nouvelle_image)

			)
		)












;******************************************************************************************************

		;; rétablir le mode message
		(gimp-message-set-handler message)

		(gimp-context-set-transform-direction old_context_transform_direction )
		(gimp-context-set-interpolation old_context_interpolation)
		(gimp-context-set-transform-recursion old_context_recursion)
		(gimp-context-set-transform-resize old_context_transform_resize)
		(gimp-context-set-background old-bg)
		(gimp-context-set-foreground old-fg)

		(gimp-undo-push-group-end image)
		(gimp-displays-flush)


	)
)





(script-fu-register "Twist_Various_Creations_1_samj"
                    _"<Image>/Filters/Misc/Concept/Twist Various Creations 1 ..."
                    "Concept for creating patterns, static or dynamic brushes, etc... from an image."
                    "samj"
                    "samj"
                    "20130326"
                    "RGB*"
                    SF-IMAGE    "Image"     0
                    SF-DRAWABLE "Drawable"  0
					SF-OPTION "Choose an object to create " '("A  Pattern and Save" "B  Fill the image with a pattern" "C  Brush and Save" "D  Dynamic Brush and Save" "E  An effect on the entire image (very slow)" "F  Gradient")
					SF-OPTION "Use the image or color " '("Use Image" "Use Color" )
					SF-COLOR "Color of the object " '(222 22 222)
					SF-COLOR "Back Ground Color " '(255 255 255)
					SF-OPTION "Effects " '("1  Alpha" "2  Beta" "3  Gamma" "4  Delta" "5  Epsilon")
					SF-OPTION "Selection Type (used by Twist plug-in) " '("Square" "Circle") ; sélection utilisée par Twist
					SF-ADJUSTMENT "Selection Size " '(128 16 1024 1 10 0 1)
					SF-ADJUSTMENT "Spokes / 2 " '(5 1 40 1 2 0 1)
					SF-TOGGLE "Add an alpha channel " TRUE
					SF-ADJUSTMENT "Blur " '(0 0 20 1 2 2 1)
					SF-STRING "Object Name to save (DO NOT PUT SPACES) "    "Creation_Twist"
					SF-TOGGLE "Save pattern or brush " TRUE
					SF-ADJUSTMENT "Spacing of the brush (Pixels) " '(64 8 1024 1 10 0 1)
					SF-ADJUSTMENT "Spacing of the dynamic brush (%) " '(50 1 100 1 10 0 1)
					SF-TOGGLE "Display Filter Settings" FALSE



)

;; FIN





