Joa*_*nge 14 .net c# algorithm colors
根据所需的颜色数量等间距生成它们.如果指定的计数为8,则看起来像这样:
List<Color> GeneratePastelColors (int count)
Run Code Online (Sandbox Code Playgroud)

Tha*_*tos 11
如果您使用HSV而不是RGB,您会发现在这些问题中颜色更容易使用.
"等间距颜色"几乎总是意味着"等距色调".因此,对于[0,360]的色调,你只需平均划分该范围即可.
现在你有一个色调,你只需要找到那个色调的"粉彩"版本.对我来说,这意味着稍微去饱和颜色.我会说80%的初学者已经饱和了.
在我的测试中,我使用100%的价值.然后转换为RGB.这是我一直在玩的东西:
<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 + "%);'> </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>
Run Code Online (Sandbox Code Playgroud)
不是C#,我知道,但只是试着指甲并坐下来.
否则,您可以查看样本颜色,并查看HSV/HSL值中是否存在任何相关性,并尝试从中派生算法.如果您绘制S/H和V/H,您会看到图中的灰色大幅下降---它似乎是一个异常值.(从左下方开始排在第三位.)忽略该值,S约为75%,值略低于90%.使用这些值可能会给出最好的结果.
您还可以查看Rich Newman的HSLColor类.他有一系列博客文章,从这一篇开始.
使用此代码,我能够在色轮周围均匀地生成一系列颜色,但如果要包含灰色阴影,则必须添加其他逻辑.
private void button1_Click(object sender, EventArgs e)
{
listView1.Items.Clear();
int step = 240 / 8;
for (int i = 0; i < 240; i += step)
{
HSLColor color = new HSLColor((double)i, 240, 160);
listView1.Items.Add(i.ToString()).BackColor = color;
}
}
Run Code Online (Sandbox Code Playgroud)
