Ejemplo n.º 1
0
 public static Color HsvToRgb(HsvColor hsv)
 {
     var h = hsv.Hue;
     if (h >= 360f)
         h = 0f;
     else
         h /= 60f;
     var s = hsv.Saturation;
     var v = hsv.Value;
     if (Math.Abs(s - 0) < float.Epsilon)
     {
         // achromatic (grey)
         return Color.FromScRgb(1f, (float)v, (float)v, (float)v);
     }
     var i = (int)Math.Floor(h);
     var f = h - i;			// factorial part of h
     var p = (v * (1f - s));
     var q = (v * (1f - s * f));
     var t = (v * (1f - s * (1f - f)));
     switch (i)
     {
         case 0:
             return Color.FromScRgb((float)hsv.Alpha, (float)v, (float)t, (float)p);
         case 1:
             return Color.FromScRgb((float)hsv.Alpha, (float)q, (float)v, (float)p);
         case 2:
             return Color.FromScRgb((float)hsv.Alpha, (float)p, (float)v, (float)t);
         case 3:
             return Color.FromScRgb((float)hsv.Alpha, (float)p, (float)q, (float)v);
         case 4:
             return Color.FromScRgb((float)hsv.Alpha, (float)t, (float)p, (float)v);
         default:		// case 5:
             return Color.FromScRgb((float)hsv.Alpha, (float)v, (float)p, (float)q);
     }
 }
Ejemplo n.º 2
0
 public static int Binary(HsvColor color)
 {
     // Easiest way to do it currently
     return ((Color)color).Intify();
 }
Ejemplo n.º 3
0
 public static HsvColor ColorBetween(HsvColor first,
                                     HsvColor second,
                                     double factor)
 {
     return new HsvColor(
         first.Alpha + ((second.Alpha - first.Alpha) * factor),
         first.Hue + ((second.Hue - first.Hue) * factor),
         first.Saturation + ((second.Saturation - first.Saturation) * factor),
         first.Value + ((second.Value - first.Value) * factor)
         );
 }
Ejemplo n.º 4
0
 public static int Binary(HsvColor color)
 {
     // Easiest way to do it currently
     return(((Color)color).Intify());
 }