为手机号创建自定义颜色。

huangapple go评论68阅读模式
英文:

Creating custom color for a phone number

问题

我正在制作一个聊天应用,在我的聊天中,我想用从电话号码生成的独特颜色来突出显示姓名和电话号码。

到目前为止,我的实现相当简单:

float alpha = 电话号码 / 9999999999.0d /*电话号码有10位,因此这会产生一个在(0-1)范围内的标准化值*/

Color color = new Color((int)(255 * alpha), (int)(200 * alpha), (int)(225 * alpha)); /*随机值只是为了创建一些变化*/

但是对于类似的电话号码(这种情况经常发生),我得到相同的颜色。

对于如何使每个电话号码看起来与众不同且鲜明,就像 WhatsApp 中那样,您有什么建议吗?同一个电话号码每次都必须返回相同的颜色。

英文:

I am making a chat application and in my chats I want to highlight the name and phone number with an unique color generated from the phone number.

So far my implementation is quite naive

float alpha=phone number/9999999999.0d /*phone number is 10 digits so this yeild a normalised value from (0-1)*/

Color color=new Color((int)(255*alpha),(int)(200*alpha),(int)(225*alpha)):/*the random values are just to create some varity*/

But with similar phone numbers (which occurs quite often) I get the same color.

Any suggestions on how to make each phone number appear distinct and bright like in whatsapp for example?the same phone number must give back the same color every time.

答案1

得分: 2

创建一系列颜色,作为你的“调色板”,然后对数字进行mod()计算,将其用作索引来访问调色板。

英文:

create a series of colors that is your 'palette'
then do a mod() calculation on the number and use that as an index into the palette.

huangapple
  • 本文由 发表于 2020年4月6日 23:05:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/61062825.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定