1

我有一个给定的颜色,并想在色调、饱和度和亮度方面创建它的变化。

我找到了一个网页,它可以按照我想要的方式创建变化(参见http://coloreminder.com/)。但是,我并不完全理解这些变化是如何为任意颜色创建的。从我在此主页上考虑创建的变体可以看出,简单地单独更改 HSL 值以创建变体似乎是不够的。

因此,我想问是否有人知道创建这些变化的方法,或者理想情况下知道在哪里获得代码的平静以在我自己的程序中采用这种颜色变化创建?

我正在使用 c++ 和 QT。

谢谢你的帮助,马克

编辑:感谢您的回复!实际上,给定主页的变化实际上仅以 10% 的步长分别改变 HSL 值。我很困惑,因为我在程序的颜色选择器中将这些值与 HSV 值进行了比较。

4

2 回答 2

1

您是否阅读过QColor的文档?

QColor 类本身提供了很多有用的函数,可以用你能想到的任何方式来处理颜色,文档本身也解释了一些基本的颜色理论。

于 2011-09-21T14:46:12.293 回答
1

从我在此主页上考虑创建的变体可以看出,简单地单独更改 HSL 值以创建变体似乎是不够的。

真的吗?该界面似乎很清楚它所做的修改。您可以选择“色调”、“饱和度”或“亮度”,它会在该通道上显示 9 种变化。以下 MATLAB 脚本将以类似的方式绘制不同的变化(尽管在 HSV 颜色空间中,而不是 HSL)。

% display n variations of HTML-style color code.
function [] = colorwheel ( hex, n )
      % parse color code.
    rgb = hex2rgb(hex);
      % render all variations.
    h = figure();
    for j = 1 : 3,
          % build n variations on current channel.
        colors = variantsof(rgb, j, n);
          % display variations.
        for i = 1 : n,
              % generate patch of specified color.
            I = zeros(128, 128, 3);
            I(:,:,1) = colors(i, 1);
            I(:,:,2) = colors(i, 2);
            I(:,:,3) = colors(i, 3);
              % render patches side-by-side to show progression.
            imshow(I, 'parent', ...
                subplot(3, n, (j-1)*n+i, 'parent', h));
        end
    end
end

% parse HTML-style color code.
function [ rgb ] = hex2rgb ( hex )
    r = double(hex2dec(hex(1:2))) / 255;
    g = double(hex2dec(hex(3:4))) / 255;
    b = double(hex2dec(hex(5:6))) / 255;
    rgb = [r g b];
end

% generate n variants of color on j-th channel.
function [ colors ] = variantsof ( rgb, j, n )
    colors = zeros(n, 3);
    for i = 1 : n,
          % convert to HSV.
        color = rgb2hsv(rgb);
          % apply variation to selected channel.
        color(j) = color(j) + ((i-1) / n);
        if color(j) > 1.0,
            color(j) = color(j) - 1.0;
        end
          % convert to RGB.
        colors(i,:) = hsv2rgb(color);
    end
      % order colors with respect to channel.
    if j > 1,
        colors = sortrows(colors, j);
    end
end

使用“goldenrod”样本颜色,如:

colorwheel('daa520', 9);

我得到:样本输出

第一行是色调的变化,第二行是饱和度,第三行是值。输出与 coloreminder.com 上的输出不完全对应,但这可以通过颜色空间的差异和排列中使用的精确值来解释。

于 2011-09-21T15:23:43.067 回答