using System;
using System.Drawing;
namespace Microsoft.Windows.Forms
{
///
/// 随机颜色生成器
///
public class RandomColor
{
///
/// 黄金分割比例
///
private const float GOLDEN_RATIO = 0.618033988749895f;
///
/// 随机颜色,Hue 起始值
///
private float? m_Hue;
///
/// 获取随机颜色
///
/// 饱和度[0-1]
/// 亮度[0-1]
/// 颜色
public Color Next(float saturation, float brightness)
{
if (this.m_Hue == null)
{
Random random = new Random(unchecked((int)DateTime.Now.Ticks));
this.m_Hue = (float)random.NextDouble();
}
float hue = this.m_Hue.Value;
hue += GOLDEN_RATIO;
hue %= 1;
this.m_Hue = hue;
return RenderEngine.FromHsv(hue, saturation, brightness);
}
///
/// 获取随机颜色
///
/// 颜色
public Color Next()
{
return this.Next(0.5f, 0.99f);
}
}
}