doudang9147 2013-08-15 23:12
浏览 156
已采纳

为用户生成不同的颜色(日历中的颜色日期)[关闭]

I have a only one calendar and many users who create events in that calendar. Each user shall have an unique color as background for all the events he creates.

Users are unlimited, but in any case less than ffffff(16777215) users. So i just need an algorithm that creates an unique color for each user that is added to the calendar. The less users the calendar has the more diffrent should the colors be; e.g. red, green, blue, yellow for 4 users, but for 50 users of course the colors become more close to each other.

  • 写回答

1条回答 默认 最新

  • douyulv6921 2013-08-15 23:33
    关注

    Technically you can't use all colors, a large range of those colors will clash with your design, and even worse, another large range will make the text on top hard to read, unless you also apply an algorithm to color the text in each cell to ensure higher contrast. Additionally, you need a pretty huge variance between the different colors to make them distinct. Overall it seems like too much effort for something that isn't going to look or work all that well.

    I would suggest instead giving each user a randomly generated icon and displaying that icon in small to the left of their events. See the icons that Stack Overflow has? They use Gravatar. Gravatar provides several forms of randomly generated icons based on user email, and users are also free to create a Gravatar account and upload their own icon. I would strongly consider doing this instead. You could have it implemented in less than 5 minutes and be done with it.

    That said, if you insist on trying it, I think the best way would be to come up with a formula that takes the auto-incremented user ID and splits up the spectrum automatically distributing the color choices as widely as possible by dividing the allowed spectrum in half repeatedly. This way the first 50 users will have the most variance in color, you will be able to predictably determine each user's color at any time, and it will otherwise be pretty random.

    Regarding an algorithm for coloring text to give high contrast, that's a whole other thing. I'm sure Google would yield some good results. A simple method would be to set a threshold where a color is considered light or dark, and just test the color against that - if it's light use black font, if it's dark use white font. Drop shadows could also help with legibility.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计