|Assigning random colors per session, for chat||#1|
I have an AJAX chat system that I(m working on and so far I have it working. One thing I want to do is have it so when the user name is displayed on screen, it is a unique color (like in an AIM window). How would I generate a random color to assign to the user(s name for the particular session they are logged in for?
The color would have to be something that is darker as it on white background and as they are generated, they can(t be too similar to the colors that other current users have been assigned.
EDIT Thanks, I guess a predefined list would be the easiest way. If I have this list in a config file and I assign a color when the user logs in, how should I go about making sure that no two logged in users have the same color?
posted date: 2009-04-11 16:45:00
|Re: Assigning random colors per session, for chat||#3|
posted date: 2009-04-11 16:48:00
|Re: Assigning random colors per session, for chat||#4|
Create a list of colors (by hand) that are dark enough and easily distinguishable, and then choose one randomly.
posted date: 2009-04-11 16:49:00
|Re: Assigning random colors per session, for chat||#5|
You don(t want to go too random with colors if you also want them to contrast with each other and be on the dark side of white. It may be better to predefine an array of colors, and cycle through them from a random starting position, so none will be repeated until the whole set has been assigned.
posted date: 2009-04-11 16:56:00
|Re: Assigning random colors per session, for chat||#6|
A good starting point could be the label colors in gmail - they're easily distinguishable and designed to work on a light background. There may not be enough of them though.
posted date: 2009-04-11 17:10:00
|Re: Assigning random colors per session, for chat||#7|
here is a good list of web colors to choose from: december.com/html/spec/colorhslhex10.html
posted date: 2009-04-11 17:20:00
|select page: « 1 »|