Sun Feb 27, 2011 1:07 am
(begin
(set! nextcolour (car (gimp-palette-entry-get-color inPalette palettecount))) ; next palette colour, - not B, W or flagcoulor
(while (or (= (+ (car nextcolour) (cadr nextcolour) (caddr nextcolour)) 765)
(= (+ (car nextcolour) (cadr nextcolour) (caddr nextcolour)) 0)
(= (listeql? nextcolour inFlagColour) TRUE))
(set! palettecount (modulo (+ palettecount 1) numcolours)) ; increment palette
(set! nextcolour (car (gimp-palette-entry-get-color inPalette palettecount)))
)
(set! palettecount (modulo (+ palettecount 1) numcolours)) ; increment palette
)
)
(gimp-context-set-foreground nextcolour)
)
(gimp-context-set-foreground inFlagColour)
)
)
Sun Feb 27, 2011 3:34 am
Sun Feb 27, 2011 3:44 am
Sun Feb 27, 2011 8:49 am
Sun Feb 27, 2011 9:31 am
mahvin wrote:1. Is it crucial to set a statement for the other options to be false, in order for the new pattern option to be true, or is simply adding another (begin (if (= inPatterns TRUE) sufficient? My thoughts are, I wouldn't want the user to be able to make 2 or 3 options to be true at the same time. Something to flag the user that they cannot use more than one option at a time.
SF-OPTION "Fill mode" '("Random colours" "Colours from palette" "Patterns from directory")
mahvin wrote:2. Could I continue using (nextcolour) in the same fashion with patterns as it is used in palettes and random colors, or would I need to make a new definition? (My gut says a new definition to assign patterns randomly is needed)
mahvin wrote:3. I am aware of (palettecount) so I would also need to establish a (patterncount).
mahvin wrote:4. I'm totally lost on how I would assign the script to look for a subset folder of patterns, and not the .gimp-2.6/patterns folder. I would want the ability to assign this value on the script menu, as the folder location could change for a different project.
SF-DIRNAME "Pattern directory" "/some/default/directory"
mahvin wrote:A menu to elaborate my intentions:
[snip]...
(patterns (cadr (file-glob (string-append inPatternDirectory DIR-SEPARATOR "*.pat"))))
(numpatterns (length patterns)) ; NOTE: should generate error if zero
(patterncount 0) ; index into list of patterns
(if (or (and (= inHowCheck 0)
(<= (- (cadddr bounds) (cadr bounds)) inIgnoreSize)
(<= (- (list-ref bounds 4) (caddr bounds)) inIgnoreSize) ) ; X and Y size
(and (= inHowCheck 1)
(<= (cadddr (gimp-histogram inLayer HISTOGRAM-VALUE 0 255)) inIgnoreSize) )) ; area
(begin
(gimp-context-set-foreground (list 0 0 0)) ; fill with black - will be ignored in flatten step
(gimp-edit-fill inLayer FOREGROUND-FILL) )
(if (or (and (= inHowCheck 0)
(> (- (cadddr bounds) (cadr bounds)) inFlagSize)
(> (- (list-ref bounds 4) (caddr bounds)) inFlagSize) ) ; X and Y size
(and (= inHowCheck 1)
(> (cadddr (gimp-histogram inLayer HISTOGRAM-VALUE 0 255)) inFlagSize) )) ; area
(cond
((= fill-type 0) ; Random color fill
(set! nextcolour inFlagColour) ; guarantees 'while' will loop at least once
(while (equal? nextcolour inFlagColour) ; random color must not be the flag color
(set! nextcolour (list (+ (rand 254) 1) ; not black or white either
(+ (rand 254) 1) ; hence color is ([1-254],[1-254],[1-254])
(+ (rand 254) 1) )))
(gimp-context-set-foreground nextcolour)
(gimp-edit-fill inLayer FOREGROUND-FILL)
)
((= fill-type 1) ; get color from palette
(set! nextcolour (car (gimp-palette-entry-get-color inPalette palettecount))) ; next palette colour, - not B, W or flagcoulor
(while (or (= (apply + nextcolour) 765)
(= (apply + nextcolour) 0)
(equal? nextcolour inFlagColour) )
(set! palettecount (modulo (+ palettecount 1) numcolours)) ; increment palette
(set! nextcolour (car (gimp-palette-entry-get-color inPalette palettecount))) )
(set! palettecount (modulo (+ palettecount 1) numcolours))
(gimp-context-set-foreground nextcolour)
(gimp-edit-fill inLayer FOREGROUND-FILL) )
((= fill-type 2) ; fill with a pattern from specified directory
(gimp-context-set-pattern (list-ref patterns patterncount))
(gimp-edit-fill inLayer PATTERN-FILL)
(set! patterncount (modulo (+ patterncount 1) numpatterns)) ))
(gimp-context-set-foreground inFlagColour) ))
Sun Feb 27, 2011 10:19 am
saulgoode wrote:mahvin wrote:3. I am aware of (palettecount) so I would also need to establish a (patterncount).
Correct. In the code below, I use a 'palettecount' variable to index into a list of all the .pat files in the specified directory. (Note: I did not attempt to randomly select patterns from the pattern directory. If you wish to provide support for such randomization, I would be glad to assist.)
Sun Feb 27, 2011 11:44 am
(set! patterns (map
(lambda (filename)
(let* ((port (open-input-file filename))
(ch #\a)
(magic " ")
(name "") )
(while (not (string=? magic "GPAT"))
(set! ch (read-char port))
(set! magic (string-append (substring magic 1)
(make-string 1 (if (equal? ch #\x0) #\space ch)) )))
(set! ch (read-char port))
(while (not (equal? ch #\x0))
(set! name (string-append name (make-string 1 ch)))
(set! ch (read-char port)) )
(close-input-port port)
name ))
(cadr (file-glob (string-append inPatternDirectory DIR-SEPARATOR "*.pat") 1))))
Sun Feb 27, 2011 2:58 pm
Sun Feb 27, 2011 3:16 pm
Sun Feb 27, 2011 3:22 pm
The following code will assign a list of pattern names to a variable 'patterns'. It is not very robust (it doesn't check for non-existent files and could stall if the file is corrupt or not a pattern), but it should be sufficient for initial experimentation. Of course, the pattern file must be in GIMP's search path for patterns in order that 'gimp-context-set-pattern' will be able to specify it as the current active pattern.
Sun Feb 27, 2011 4:55 pm
Sun Feb 27, 2011 5:34 pm
Sun Feb 27, 2011 6:49 pm
Sun Feb 27, 2011 8:08 pm
Sun Feb 27, 2011 10:03 pm
but I see a conflict between the ability to select your directory and declaring a directory name (at least I think it's a conflict).
Sun Feb 27, 2011 10:08 pm
Sun Feb 27, 2011 10:20 pm
Sun Feb 27, 2011 10:32 pm
Sun Feb 27, 2011 10:45 pm
mahvin wrote:Right now the script is telling me: Error: eval: unbound variable: inPatternDirectory with all his recommendations implemented. Menu pops ok, everything looks good til you try to run any option, doesn't matter which option you choose, same error.
Sun Feb 27, 2011 10:53 pm