Domanda

I have a given color and want to create variations of it in terms of hue, saturation and lightness.

I found a webpage which creates variations the way I would like it (See http://coloreminder.com/). However, I do not entirely understand how these variations are created for an arbitrary color. 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.

Hence, I wanted to ask if anybody knows an approach for creating these variations, or ideally knows where to get a peace of code to adopt this kind of color variations creation in my own program?

I am using c++ and QT.

Thank you for your help, Marc

EDIT: Thank you for your replies! Actually the variations of the given homepage really only varies the HSL values separately in 10% steps. I got confused since I compared the values with HSV values in color picker of my program.

È stato utile?

Soluzione

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.

Really? The interface seems to be clear enough about what modifications it makes. You can select "hue", "saturation" or "luminance" and it shows 9 variations on that channel. The following MATLAB script will plot the different variations in a similar way (although in the HSV color space, not 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

Using the "goldenrod" sample color, as:

colorwheel('daa520', 9);

I get:sample output

The first row is a variation on hue, the second on saturation and the third on value. The outputs don't correspond exactly to the ones on the coloreminder.com, but this is explained by the difference in color space and exact value used in permutations.

Altri suggerimenti

Have you read through the documentation for QColor?

The QColor class itself provides plenty of useful functions for manipulating colors in pretty much any way you can think of, and the documentation itself explains some basic color theory as well.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top