如何从调色板中产生颜色渐变

发布于 2024-11-05 07:34:53 字数 623 浏览 0 评论 0原文

我正在研究的这个算法的目标是从一些提供的颜色中输出颜色渐变。我所说的颜色渐变是指在两种颜色(颜色 A、颜色 B)之间创建“淡入淡出”效果,并存储其间的每个颜色值((R,G,B)元组)。

例如,如果提供的是全黑 A = (0,0,0) 和全白 B = (255,255,255),则级数结果将为:

P = ((0,0,0),(1,1,1),(2,2,2), .... ,(253,253,253),(254,254,254),(255,255,255)

这样我们一开始是白色,然后逐渐变成黑色,当然,使用白色和黑色非常简单(只需将 RGB 每一步增加 255 次)。像 A = (180,69,1) 和 B = (233,153,0)??

重要提示:如果使用十六进制(或任何其他类型的颜色表示法),它会更容易实现,我也可以使用它,只是指定哪种类型(考虑到我正在研究 PIL(Python 成像库),所以如果它兼容我就很好)

显然它必须是尽可能均匀的分布,进展必须是同质的。

我需要弄清楚这个算法,以便我可以在我的分形生成器(Mandelbrot Set,如果需要的话可以谷歌一下)中使用它,所以重要的是进展尽可能柔和,没有打嗝。

提前致谢。

My goal with this algorithm I'm working on is to output a color progression out of some provided colors. By color progression I mean creating the "fade" effect between two colors (color A, color B) and store every color value ((R,G,B) tuple) in between.

For example, if what is provided is total black A = (0,0,0) and total white B = (255,255,255) the progression resultant would be:

P = ((0,0,0),(1,1,1),(2,2,2), .... ,(253,253,253),(254,254,254),(255,255,255)

So that we get white at first and it progressively turns into black. It is, of course, very easy with white and black (just increase RGB by one each step for 255 times). But what if I want to do this procedure with two arbitrary colors, like A = (180,69,1) and B = (233,153,0)??

IMPORTANT NOTE: If with hexadecimal (or any other kind of color notation) it would be easier to achieve, I could work with that too, just specify which type is (take into account that I'm working on PIL (Python Imaging Library), so if it's compatible with that I'm fine)

Obviously it has to be an as even as possible distribution, the progression must be homogeneous.

I need to figure out this algorithm so that I can use it in my Fractal Generator (Mandelbrot Set, google it if you want), so it is important for the progression to be as soft as possible, no hiccups.

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

予囚 2024-11-12 07:34:53

将 RGB 坐标转换为 HSL 或 HSV 并逐步执行它们,一路转换回 RGB。

Convert your RGB coordinates to HSL or HSV and step through them, converting back to RGB along the way.

梦魇绽荼蘼 2024-11-12 07:34:53

我只是独立地插值 RGB 值。请参阅此主题

I would just interpolate the RGB values independently. See this thread.

删除会话 2024-11-12 07:34:53

我对标题为 伪彩色范围值 的问题的回答可能会有所帮助因为它向您展示了一种生成特定颜色渐变的方法(您所说的颜色渐变的通用名称)。

通常,您可以通过计算每种颜色的分量之间的差异或增量值,在任何色彩空间中的任意两种颜色之间进行插值,然后将其除以所需的中间步骤数,以获得每个分量在每个分量之后应用的分数增量量。步。

然后,从第一颜色的每个分量的值开始,可以反复将相应的分数添加到其上以确定每个中间阶跃颜色。或者,可以通过将(step_number/total_steps)*fractional_delta添加到起始颜色的初始颜色分量值来减少该方法中固有的算术误差。

我相信这也是@Jim Clay 在他的回答中所说的。如果您想要一些示例代码,请在评论中说明。

My answer to the SO question titled Range values to pseudocolor might be helpful to you because it shows one way to generate a specific color gradient (the common name of what you referred to as a color progression).

Generally you can interpolate between any two colors in any colorspace by computing the difference, or delta value, between the components of each color, and then divide those by the number of intermediate steps desired to get a fractional delta amount per component to apply after each step.

Then, starting from the value of each of the first color's components, the corresponding fractional amount can be added to it over-and-over to determine each intermediate step color. Alternatively, the arithmetic error inherent in that approach can be reduced by instead adding (step_number/total_steps) * fractional_delta to the initial color component values of the starting color.

I believe this is what @Jim Clay is also saying in his answer. If you'd like some sample code, say so in a comment.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文