简单的 PHP 函数将数字转换为热图 HTML 背景颜色?
我的问题与 将任何正整数转换为的算法有关RGB 值 但实际上这不是同一个问题——那家伙主要有数据标准化问题,而我实际上更多的是审美颜色选择问题。
我有一堆 -1.0 到 +1.0 之间的数字。我需要创建一个覆盖有文本的热图。
使用 PHP 将每个数字转换为 HTML 颜色(#rrggbb)的最简单方法是什么,这样得到的颜色不仅直观地与温度相关(即最冷的是最蓝,最热的是最红,还有一些平滑的颜色)之间的过渡)而且它也适合作为黑色文本的背景颜色?
My question is related to Algorithm to convert any positive integer to an RGB value but really it's not the same question -- that guy has mostly a data normalization problem, I actually have more of an aesthetic color selection problem.
I have a bunch of numbers between -1.0 and +1.0. I need to create a heatmap overlaid with text.
What is the simplest way, using PHP, to convert each number into an HTML color (#rrggbb), in such way that the resulting color not only is intuitively related to temperature (i.e. bluest for coldest and reddest for the hottest, with some smooth transition in between) but also that it's suitable as a background color for black-color text?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我将使用 将其实现为红色和蓝色分量之间的简单线性渐变
sprintf
函数编码为十六进制值:您可以在 http://jsfiddle.net/9QQkU/。对应的值为 -1、-0.75、0、0.75 和 1。
I would implement it as a simple linear gradient between the red and blue components, using the
sprintf
function to encode to a hex value:You can see how the range of colors looks at http://jsfiddle.net/9QQkU/. The corresponding values are -1, -0.75, 0, 0.75, and 1.