gpt4 book ai didi

c++ - 在 cpp 中创建颜色变化

转载 作者:行者123 更新时间:2023-11-30 04:32:39 28 4
gpt4 key购买 nike

我有一个给定的颜色,想根据色调、饱和度和亮度创建它的变体。

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

因此,我想问问是否有人知道创建这些变体的方法,或者最好知道从哪里获得一段代码以在我自己的程序中采用这种颜色变体创建?

我正在使用 C++ 和 QT。

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

最佳答案

From what I can tell from considering created variations at this home page, it seems not to be enough to simply change the HSL values seperately to create variations.

真的吗?该界面似乎很清楚它进行了哪些修改。您可以选择“色调”、“饱和度”或“亮度”,它会在该 channel 上显示 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);

我得到:sample output

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

关于c++ - 在 cpp 中创建颜色变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7501620/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com