コード例 #1
0
 /// <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
0
 /// <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;
 }
コード例 #3
0
 /// <summary>
 /// Make a rainbow from the start color, shifting the hue a specified number of degrees each step (Returns a list of Colors).
 /// </summary>
 /// <param name="startColor">Start color.</param>
 /// <param name="degreesPerStep">Degrees to shift the hue per step.</param>
 /// <param name="length">Desired length of the list.</param>
 public static List<Color> Rainbowify(Color startColor, float degreesPerStep, int length)
 {
     List<Color> rainbow = new List<Color>();
     rainbow.Add(startColor);
     ColorHSV colorHSV = startColor.ToHSV();
     for (int i = 0; i < length - 1; i++) {
         colorHSV.ShiftHue(degreesPerStep);
         rainbow.Add(colorHSV.ToColor());
     }
     return rainbow;
 }