如何在C#编程方式创建柔和的色彩?柔和、色彩、方式、如何在

2023-09-04 01:45:27 作者:拍手叫好

要生成它们等距出根据颜色的数量想要的。一些看起来是这样,如果8给出了规定的次数:

To generate them equally spaced out based on the number of colors wanted. Something that looks like this if 8 is given for the count specified:

List<Color> GeneratePastelColors (int count)

推荐答案

您会发现颜色更容易与这些各种各样的问题,如果你使用,而不是RGB HSV工作。​​

You'll find colors easier to work with in these sorts of problems if you use HSV instead of RGB.

等间隔的色彩几乎总是意味着等距色调。因此,对于[0,360)的色调,你只是同样除以该范围同样的空间。

"equally spaced colors" almost always means "equally spaced hues". So, for [0,360) in hue, you just equally space by dividing that range equally.

现在你有一个色调,而你只需要找到柔和版的色调。对我来说,这意味着在去饱和颜色有点。我会说80%的饱和对于初学者。

Now you have a hue, and you just need to find the "pastel" version of that hue. To me, this means desaturating the color a bit. I'd say to 80% saturated for starters.

在我的测试中,我用100%的值。然后,只需转换为RGB。这是我一直在玩:

In my tests, I used 100% for value. Then just convert to RGB. Here's what I've been playing with:

<body>
<script>
// taken from http://ariya.blogspot.com/2008/07/converting-between-hsl-and-hsv.html
function hsv_to_hsl(s, v)
{
    var ss, ll;
    ll = (2. - s) * v;
    ss = 1. * s * v;
    ss /= (ll <= 1.) ? (ll) : 2. - ll;
    ll /= 2.;

    return [ss, ll];
}

function do_colors(sat, light)
{
    n = 15;
    document.write(n + " colors at " + sat + "% sat, " + light + "% lightness<br />");
    for(var x = 0; x < n; ++x)
    {
        hue = 360.0 / n * x;
        html_chunk = "<div style='width: 50px; height: 50px; display: inline-block; background: hsl(" + hue + ", " + sat + "%, " + light + "%);'>&nbsp;</div>";
        document.write(html_chunk);
    }
    document.write("<br />");
}

do_colors(100, 50);
do_colors(95, 75);
do_colors(75, 50);
do_colors(100, 35);

// rudimentary averages from your colors
sl = hsv_to_hsl(.7, .9);
s = sl[0] * 100;
l = sl[1] * 100;
do_colors(s, l);
do_colors(75, 60);
</script>
</body>

不是C#,我知道,但只是想钉灯和放大器;坐了下来。

Not C#, I know, but just trying to nail the light & sat down.

否则,你可以看看你的样品颜色,看看是否有在HSV / HSL值的任何相关性,并试图从中导出的算法。如果您绘制S / H和V / H,你会看到一个大沾在图中的灰色---这似乎是一个例外。 (左起第三个底部一行。)忽略该值,S是约在75%,价值不到90%。使用这些值可能给的最好的结果。

Otherwise, you could look at your sample colors, and see if there is any correlation in the HSV/HSL values, and try to derive an algorithm from that. If you plot S/H and V/H, you'll see a large dip in the graph at the grey color --- it seems to be an outlier. (Third from left on bottom row.) Ignoring that value, S is about at 75% and value is just under 90%. Using those values probably gave the nicest result.

链接: http://jsfiddle.net/ZHyAQ/

 
精彩推荐
图片推荐