本文介绍了如何在C#中以编程方式创建柔和的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据所需的颜色数量生成等间距的图像。如果为指定的计数指定了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)

推荐答案

等间隔颜色几乎总是意味着等间隔的色调。所以,对于[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.

现在你有一个色调,你只需要找到pastel版本的那个色调。对我来说,这意味着对颜色的饱和度。我会说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.

链接:

这篇关于如何在C#中以编程方式创建柔和的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 19:00