public Color (ColorHSB hsb) : this() { float r = 0; float g = 0; float b = 0; if (hsb.S == 0) { r = g = b = 0; } else { // the color wheel consists of 6 sectors. Figure out which sector // you're in. float sectorPos = hsb.H / 60.0f; int sectorNumber = (int)(Math.Floor (sectorPos)); // get the fractional part of the sector float fractionalSector = sectorPos - sectorNumber; // calculate values for the three axes of the color. float p = hsb.B * (1.0f - hsb.S); float q = hsb.B * (1.0f - (hsb.S * fractionalSector)); float t = hsb.B * (1.0f - (hsb.S * (1 - fractionalSector))); // assign the fractional colors to r, g, and b based on the sector // the angle is in. switch (sectorNumber) { case 0: r = hsb.B; g = t; b = p; break; case 1: r = q; g = hsb.B; b = p; break; case 2: r = p; g = hsb.B; b = t; break; case 3: r = p; g = q; b = hsb.B; break; case 4: r = t; g = p; b = hsb.B; break; case 5: r = hsb.B; g = p; b = q; break; } } this.R = r; this.G = g; this.B = b; this.A = hsb.A; }
public Color(ColorHSB hsb) : this(hsb.ToColor()) { }
public static float Distance (ColorHSB value1, ColorHSB value2) { return (float)Math.Sqrt (Math.Pow ((value1.H - value2.H) / 360f, 2) + Math.Pow (value1.S - value2.S, 2) + Math.Pow (value1.B - value2.B, 2)); }