php - Generate different colors for users (color dates in calendar) -


i have 1 calendar , many users create events in calendar. each user shall have unique color background events creates.

users unlimited, in case less ffffff(16777215) users. need algorithm creates unique color each user added calendar. less users calendar has more diffrent should colors be; e.g. red, green, blue, yellow 4 users, 50 users of course colors become more close each other.

technically can't use colors, large range of colors clash design, , worse, large range make text on top hard read, unless apply algorithm color text in each cell ensure higher contrast. additionally, need pretty huge variance between different colors make them distinct. overall seems effort isn't going or work well.

i suggest instead giving each user randomly generated icon , displaying icon in small left of events. see icons stack overflow has? use gravatar. gravatar provides several forms of randomly generated icons based on user email, , users free create gravatar account , upload own icon. consider doing instead. have implemented in less 5 minutes , done it.

that said, if insist on trying it, think best way come formula takes auto-incremented user id , splits spectrum automatically distributing color choices possible dividing allowed spectrum in half repeatedly. way first 50 users have variance in color, able predictably determine each user's color @ time, , otherwise pretty random.

regarding algorithm coloring text give high contrast, that's whole other thing. i'm sure google yield results. simple method set threshold color considered light or dark, , test color against - if it's light use black font, if it's dark use white font. drop shadows legibility.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -