It is currently Tue Jul 23, 2024 10:30 pm


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: Randomly Choosing colors from a palette for script [solved]
PostPosted: Wed Dec 12, 2012 12:21 am  (#1) 
Offline
Script Coder
User avatar

Joined: Feb 18, 2011
Posts: 4827
Location: Bendigo Vic. Australia
GIMP Version: 2.6.11
Operating System: Windows
OS Version: XP - SP3
GIMP Experience: Beginner Level



I've been trying hard all day to randomly select a color from a palette, but with no success and little help from Wilbur (sometimes I try his patience)

I tried (set! list (cadr (gimp-palette-get-colors "Default") to create a list and then to pick from that list but somewhere me and Wilbur clashed when I tried to

(set! color (car list))
.
If anyone knows of a routine that could help please let me know but don't tell Wilbur, I'll surprise him/her

_________________
Image
No matter how much you push the envelope, it'll still be stationery.


Last edited by Graechan on Wed Dec 12, 2012 7:46 pm, edited 1 time in total.

Share on Facebook Share on Twitter Share on Orkut Share on Digg Share on MySpace Share on Delicious Share on Technorati
Top
 Post subject: Re: Randomly Choosing colors from a palette for script
PostPosted: Wed Dec 12, 2012 1:48 am  (#2) 
Offline
GimpChat Member
User avatar

Joined: Sep 22, 2012
Posts: 2089
Location: US
Try this.

(set! nextcolour (list (+ (rand 254) 1) (+ (rand 254) 1) (+ (rand 254) 1))) ;Random colour - not B, W or flagcoulor
(while (= (listeql? nextcolour inFlagColour) TRUE)
(set! nextcolour (list (+ (rand 254) 1) (+ (rand 254) 1) (+ (rand 254) 1)))
)
)
(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
)


That's from Rob's script.
I won't tell him. Her. I mean Wilber. Not Rob.


Top
 Post subject: Re: Randomly Choosing colors from a palette for script
PostPosted: Wed Dec 12, 2012 2:22 am  (#3) 
Offline
Script Coder
User avatar

Joined: Feb 18, 2011
Posts: 4827
Location: Bendigo Vic. Australia
Thank you K1TesseraEna what was the name of RobA's script the routine came from

_________________
Image
No matter how much you push the envelope, it'll still be stationery.


Top
 Post subject: Re: Randomly Choosing colors from a palette for script
PostPosted: Wed Dec 12, 2012 3:07 am  (#4) 
Offline
Global Moderator
User avatar

Joined: Nov 16, 2011
Posts: 5128
Location: Metro Vancouver, BC
Graechan wrote:
Thank you K1TesseraEna what was the name of RobA's script the routine came from
I think it's, Multifill Flatting Tools.
http://registry.gimp.org/node/14051

_________________
Image
Gimp 2.8.18, Linux, median user
Gimp Chat Tutorials Index
Spirit Bear (Kermode)


Top
 Post subject: Re: Randomly Choosing colors from a palette for script
PostPosted: Wed Dec 12, 2012 4:00 am  (#5) 
Offline
Script Coder
User avatar

Joined: Apr 23, 2010
Posts: 1553
Location: not from Guildford after all
The following expression will return a random color from the Default palette:
(let ((vec (cadr (gimp-palette-get-colors "Default"))))
  (vector-ref vec (random (vector-length vec))) )



As an aside, you should generally avoid redefining 'list' because that is one of Scheme's standard procedures (perhaps use 'lis' or 'lyst' or 'lst').

_________________
Any sufficiently primitive technology is indistinguishable from a rock.


Top
 Post subject: Re: Randomly Choosing colors from a palette for script
PostPosted: Wed Dec 12, 2012 8:13 am  (#6) 
Offline
GimpChat Member
User avatar

Joined: Sep 22, 2012
Posts: 2089
Location: US
Sorry, yes, Odin got it right, thats Rob's Flatting Tools.
Did it help?


Top
 Post subject: Re: Randomly Choosing colors from a palette for script [solved]
PostPosted: Wed Dec 12, 2012 7:26 pm  (#7) 
Offline
Script Coder
User avatar

Joined: Feb 18, 2011
Posts: 4827
Location: Bendigo Vic. Australia
Thank you with everyones help I came up with this

(set! num-colors (car (gimp-palette-get-colors "Default")))
    (set! entry-num (random  num-colors))
    (set! bkg-color (car (gimp-palette-entry-get-color "Default" entry-num)))
and shortened it to
(set! bkg-color (car (gimp-palette-entry-get-color  "Default" (random  (car (gimp-palette-get-colors  "Default"))))))

To create this

Image

_________________
Image
No matter how much you push the envelope, it'll still be stationery.


Top
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 5 hours [ DST ]


   Similar Topics   Replies 
No new posts Attachment(s) Palette To Gradient

4

No new posts palette not saving

0

No new posts Attachment(s) More Wood Palette

4

No new posts Attachment(s) Creating palette from image

9

No new posts Attachment(s) lock the colours in a palette

8



* Login  



Powered by phpBB3 © phpBB Group