本文整理汇总了C#中UnityEngine.Color.ToHSV方法的典型用法代码示例。如果您正苦于以下问题:C# Color.ToHSV方法的具体用法?C# Color.ToHSV怎么用?C# Color.ToHSV使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.Color
的用法示例。
在下文中一共展示了Color.ToHSV方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MakeGradientHSV
/// <summary>
/// Make a gradient between two colors using HSV (Returns a list of colors blended from startColor to endColor).
/// </summary>
/// <returns>A list of colors blended from startColor to endColor.</returns>
/// <param name="startColor">Start color.</param>
/// <param name="endColor">End color.</param>
/// <param name="blendColors>Number of blended colors in the middle (returned list's length will be this value plus two).</param>
public static List<Color> MakeGradientHSV(Color startColor, Color endColor, int blendColors)
{
List<Color> gradient = new List<Color>();
float startHue = startColor.ToHSV().h;
float endHue = endColor.ToHSV().h;
float startSat = startColor.ToHSV().s;
float endSat = endColor.ToHSV().s;
float startVal = startColor.ToHSV().v;
float endVal = endColor.ToHSV().v;
float degreesPerStep = (endHue - startHue);
if (degreesPerStep > 180f) {
degreesPerStep = degreesPerStep - 360f;
}
if (degreesPerStep < -180f) {
degreesPerStep = degreesPerStep + 360f;
}
float saturationPerStep = (endSat - startSat);
float valuePerStep = (endVal - startVal);
degreesPerStep /= (float)(blendColors + 1);
saturationPerStep /= (float)(blendColors + 1);
valuePerStep /= (float)(blendColors + 1);
gradient.Add(startColor);
ColorHSV colorHSV = startColor.ToHSV();
for (int i = 0; i < blendColors; i++) {
colorHSV.ShiftHue(degreesPerStep);
colorHSV.s += saturationPerStep;
colorHSV.v += valuePerStep;
gradient.Add(colorHSV.ToColor());
}
gradient.Add(endColor);
return gradient;
}
示例2: Rainbowify
/// <summary>
/// Make a rainbow from the start color, shifting the hue until it reaches the end hue. (Returns a list of Colors).
/// </summary>
/// <param name="startColor">Start color.</param>
/// <param name="endColor">Hue to stop shifting at (will only use the hue of this color, not value or saturation).</param>
/// <param name="length">Desired length of the list.</param>
public static List<Color> Rainbowify(Color startColor, Color endColor, int length)
{
List<Color> rainbow = new List<Color>();
float startHue = startColor.ToHSV().h;
float endHue = endColor.ToHSV().h;
if (endHue < startHue) {
endHue += 360f;
}
float degreesPerStep = (endHue - startHue);
degreesPerStep /= (float)length - 1;
rainbow.Add(startColor);
ColorHSV colorHSV = startColor.ToHSV();
for (int i = 0; i < length - 1; i++) {
colorHSV.ShiftHue(degreesPerStep);
rainbow.Add(colorHSV.ToColor());
}
return rainbow;
}