如何获得两种颜色之间的颜色?

编程入门 行业动态 更新时间:2024-10-09 13:31:42
本文介绍了如何获得两种颜色之间的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

有两种颜色:

#15293E #012549

如何找到它们之间的一半的颜色?有没有办法做这个计算?

解决方案

正如李斯特先生刚才说的,很容易通过任何编程自动计算语言:

  • 将 Red,Green,Blue :(r1,g1,b1)and(r2,g2,b2)。
    • 例如#15293E,#012549成为(15,29,3E),(01,25,49) $ b $
    • 将每个颜色字符串转换为整数,明确指定您正在解析基于十六进制的表示数字。
      • 例如(15,29,3E)变成(21,41,62) br />
    • 计算平均值(r',g',b')=((r1 + r2)/ 2, g1 + g2)/ 2,(b1 + b2)/ 2。
      • 例如((21 + 1)/ 2,(41 + 37)/ 2,(62 + 73)/ 2)= ,67) $ b $bÚ
    • 将它们再次转换为字符串,明确指定您正在生成两位数字十六进制表示(必要时,填充为零)。
      • 例如(11,39,67) - >(0B,27,43)
    • 连接一个尖锐字符,后跟3个字符串
      • 例如(0B,27,43) - > #0B2743
      li>

      编辑:实施并不像我刚才说的那样很容易。我花时间写了几种语言的代码 on Programming-Idioms 。

      I have two colors:

      #15293E #012549

      How can I find the color that is half way in between them? Is there some way to do this calculation?

      解决方案

      As Mr Lister just said, it is easy to automate the calculation with any programming language :

    • Separate your two colors into their 3 color numbers for Red, Green, Blue : (r1,g1,b1) and (r2,g2,b2).
      • For example #15293E, #012549 become ("15", "29", "3E"), ("01", "25", "49")
    • Convert each color string into an integer, specifying explicitly that you are parsing a hexadecimal-based representation of a number.
      • For example ("15", "29", "3E") becomes (21, 41, 62)
    • Calculate the average (r',g',b') = ( (r1+r2)/2, (g1+g2)/2, (b1+b2)/2 ).
      • For example ( (21+1)/2, (41+37)/2, (62+73)/2) = (11, 39, 67)
    • Convert them again to strings , specifying explicitly that you are generating two-digit hexadecimal representations (pad with a zero when necessary).
      • For example (11, 39, 67) -> ("0B", "27", "43")
    • Concatenate a sharp character followed by the 3 strings
      • For example ("0B", "27", "43") -> "#0B2743"
    • Edit : Implementation is not "very easy" as I initially stated. I took the time to write the code in several languages on Programming-Idioms .

  • 更多推荐

    如何获得两种颜色之间的颜色?

    本文发布于:2023-11-28 21:52:50,感谢您对本站的认可!
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:颜色   两种   如何获得

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!