public ColorHSV this[int colorNumber]
 {
     get
     {
         return colors[colorNumber];
     }
     set
     {
         if (colorNumber == 0)
         {
             // central color has been moved: move it and compute laterals again
             colors[0] = value;
             computeLaterals();
         }
         else
         {
             // lateral color has been moved: change the angle accordingly and compute the other lateral.
             int factor = getFactor(colorNumber);
             var diffAngle = value.H - colors[0].H;
             var normalizedDiffAngle = diffAngle > 180 ? -(360 - diffAngle) : diffAngle;
             hueAngle = normalizedDiffAngle / factor;
             colors[0] = new ColorHSV(colors[0].H, value.S, value.V);
             computeLaterals();
         }
     }
 }
Esempio n. 2
0
 /// <summary>
 /// Create a new Arrow object.
 /// </summary>
 /// <param name="parent">The parent (container) of this object.</param>
 /// <param name="arrowsColorSetter">Interface to set the colors in the parent object.</param>
 /// <param name="index">Index of this arrow in his parent.</param>
 /// <param name="color">The represented color.</param>
 public Arrow(Arrows parent, IArrowsColorSetter arrowsColorSetter, int index, ColorHSV color)
 {
     this.parent = parent;
     this.arrowsColorSetter = arrowsColorSetter;
     this.index = index;
     this.color = color;
     this.parent.SetArrowColorSetter(index, new ArrowColorSetter(this));
 }
 /// <summary>
 /// Creates a new AnalogousBaseColorSystem, with a hue angle of 30 degrees.
 /// </summary>
 /// <param name="mainColor">The first color.</param>
 /// <param name="count">The number of colors.</param>
 public AnalogousBaseColorSystem(ColorHSV mainColor, int count)
 {
     Count = count;
     colors = new ColorHSV[Count];
     colors[0] = mainColor;
     hueAngle = 30;
     computeLaterals();
 }
Esempio n. 4
0
 /// <summary>
 /// Create an instance of a color system.
 /// </summary>
 /// <param name="kind">The kind of color system to create.</param>
 /// <param name="mainColor">The main color of this system.</param>
 /// <returns>The created color system.</returns>
 public static IColorSystem Create(ColorSystemKind kind, ColorHSV mainColor)
 {
     switch (kind)
     {
         case ColorSystemKind.AnalogousThree:
             return new AnalogousThreeColorSystem(mainColor);
         case ColorSystemKind.AnalogousFive:
             return new AnalogousFiveColorSystem(mainColor);
         case ColorSystemKind.Triad:
             return new TriadColorSystem(mainColor);
         default:
             throw new ArgumentException("kind");
     }
 }
Esempio n. 5
0
 /// <summary>
 /// Compute the two other colors of a triad starting from the one of them.
 /// </summary>
 /// <param name="i">The index of the color to use as a base to compute the other two.</param>
 private void computeColorsFrom(int i)
 {
     var c = colors[i];
     for (var j = 1; j < 3; j++)
         colors[(i + j) % 3] = new ColorHSV(Helper.NormalizeAngle(c.H + j * 120), c.S, c.V);
 }
Esempio n. 6
0
 public TriadColorSystem(ColorHSV mainColor)
 {
     colors = new ColorHSV[3];
     colors[0] = mainColor;
     computeColorsFrom(0);
 }
Esempio n. 7
0
        private void Convert_Button_Click(object sender, EventArgs e)
        {
            switch (((Button)sender).Name)
            {
                case "RGB_Button":
                    try
                    {
                        if (RGBSpace != RGBSpaceName.ICC) ColRGB = new ColorRGB(RGBSpace, RGB[0], RGB[1], RGB[2]);
                        else ColRGB = new ColorRGB(RGB_ICC, RGB[0], RGB[1], RGB[2]);
                        Conversion(ColRGB);
                    }
                    catch (FormatException) { MessageBox.Show("Not a number!"); }
                    catch (Exception ex) { MessageBox.Show("Error:" + Environment.NewLine + ex.Message); }
                    break;

                case "XYZ_Button":
                    try { ColXYZ = new ColorXYZ(XYZwp, XYZ[0], XYZ[1], XYZ[2]); Conversion(ColXYZ); }
                    catch (FormatException) { MessageBox.Show("Not a number!"); }
                    catch (Exception ex) { MessageBox.Show("Error:" + Environment.NewLine + ex.Message); }
                    break;

                case "Lab_Button":
                    try { ColLab = new ColorLab(Labwp, Lab[0], Lab[1], Lab[2]); Conversion(ColLab); }
                    catch (FormatException) { MessageBox.Show("Not a number!"); }
                    catch (Exception ex) { MessageBox.Show("Error:" + Environment.NewLine + ex.Message); }
                    break;

                case "Luv_Button":
                    try { ColLuv = new ColorLuv(Luvwp, Luv[0], Luv[1], Luv[2]); Conversion(ColLuv); }
                    catch (FormatException) { MessageBox.Show("Not a number!"); }
                    catch (Exception ex) { MessageBox.Show("Error:" + Environment.NewLine + ex.Message); }
                    break;

                case "Yxy_Button":
                    try { ColYxy = new ColorYxy(Yxywp, Yxy[0], Yxy[1], Yxy[2]); Conversion(ColYxy); }
                    catch (FormatException) { MessageBox.Show("Not a number!"); }
                    catch (Exception ex) { MessageBox.Show("Error:" + Environment.NewLine + ex.Message); }
                    break;

                case "LCHab_Button":
                    try { ColLCHab = new ColorLCHab(LCHabwp, LCHab[0], LCHab[1], LCHab[2]); Conversion(ColLCHab); }
                    catch (FormatException) { MessageBox.Show("Not a number!"); }
                    catch (Exception ex) { MessageBox.Show("Error:" + Environment.NewLine + ex.Message); }
                    break;

                case "LCHuv_Button":
                    try { ColLCHuv = new ColorLCHuv(LCHuvwp, LCHuv[0], LCHuv[1], LCHuv[2]); Conversion(ColLCHuv); }
                    catch (FormatException) { MessageBox.Show("Not a number!"); }
                    catch (Exception ex) { MessageBox.Show("Error:" + Environment.NewLine + ex.Message); }
                    break;

                case "LCH99_Button":
                    try { ColLCH99 = new ColorLCH99(LCH99[0], LCH99[1], LCH99[2]); Conversion(ColLCH99); }
                    catch (FormatException) { MessageBox.Show("Not a number!"); }
                    catch (Exception ex) { MessageBox.Show("Error:" + Environment.NewLine + ex.Message); }
                    break;

                case "LCH99b_Button":
                    try { ColLCH99b = new ColorLCH99b(LCH99b[0], LCH99b[1], LCH99b[2]); Conversion(ColLCH99b); }
                    catch (FormatException) { MessageBox.Show("Not a number!"); }
                    catch (Exception ex) { MessageBox.Show("Error:" + Environment.NewLine + ex.Message); }
                    break;

                case "LCH99c_Button":
                    try { ColLCH99c = new ColorLCH99c(LCH99c[0], LCH99c[1], LCH99c[2]); Conversion(ColLCH99c); }
                    catch (FormatException) { MessageBox.Show("Not a number!"); }
                    catch (Exception ex) { MessageBox.Show("Error:" + Environment.NewLine + ex.Message); }
                    break;

                case "LCH99d_Button":
                    try { ColLCH99d = new ColorLCH99d(LCH99d[0], LCH99d[1], LCH99d[2]); Conversion(ColLCH99d); }
                    catch (FormatException) { MessageBox.Show("Not a number!"); }
                    catch (Exception ex) { MessageBox.Show("Error:" + Environment.NewLine + ex.Message); }
                    break;

                case "HSV_Button":
                    try
                    {
                        if (HSVSpace != RGBSpaceName.ICC) ColHSV = new ColorHSV(HSVSpace, HSV[0], HSV[1], HSV[2]);
                        else ColHSV = new ColorHSV(HSV_ICC, HSV[0], HSV[1], HSV[2]);
                        Conversion(ColHSV);
                    }
                    catch (FormatException) { MessageBox.Show("Not a number!"); }
                    catch (Exception ex) { MessageBox.Show("Error:" + Environment.NewLine + ex.Message); }
                    break;

                case "HSL_Button":
                    try
                    {
                        if (HSLSpace != RGBSpaceName.ICC) ColHSL = new ColorHSL(HSLSpace, HSL[0], HSL[1], HSL[2]);
                        else ColHSL = new ColorHSL(HSL_ICC, HSL[0], HSL[1], HSL[2]);
                        Conversion(ColHSL);
                    }
                    catch (FormatException) { MessageBox.Show("Not a number!"); }
                    catch (Exception ex) { MessageBox.Show("Error:" + Environment.NewLine + ex.Message); }
                    break;

                case "CMY_Button":
                    try { ColCMY = new ColorCMY(CMY_ICC, CMY[0], CMY[1], CMY[2]); Conversion(ColCMY); }
                    catch (FormatException) { MessageBox.Show("Not a number!"); }
                    catch (Exception ex) { MessageBox.Show("Error:" + Environment.NewLine + ex.Message); }
                    break;

                case "CMYK_Button":
                    try { ColCMYK = new ColorCMYK(CMYK_ICC, CMYK[0], CMYK[1], CMYK[2], CMYK[3]); Conversion(ColCMYK); }
                    catch (FormatException) { MessageBox.Show("Not a number!"); }
                    catch (Exception ex) { MessageBox.Show("Error:" + Environment.NewLine + ex.Message); }
                    break;

                case "Gray_Button":
                    try
                    {
                        if (Gray_ICC != null) ColGray = new ColorGray(Gray_ICC, Gray[0]);
                        else ColGray = new ColorGray(Gray[0]);
                        Conversion(ColGray);
                    }
                    catch (FormatException) { MessageBox.Show("Not a number!"); }
                    catch (Exception ex) { MessageBox.Show("Error:" + Environment.NewLine + ex.Message); }
                    break;

                case "YCbCr_Button":
                    try
                    {
                        if (YCbCrSpace == YCbCrSpaceName.ICC) ColYCbCr = new ColorYCbCr(YCbCr_ICC, YCbCr[0], YCbCr[1], YCbCr[2]);
                        else ColYCbCr = new ColorYCbCr(YCbCrSpace, YCbCr[0], YCbCr[1], YCbCr[2]);
                        Conversion(ColYCbCr);
                    }
                    catch (FormatException) { MessageBox.Show("Not a number!"); }
                    catch (Exception ex) { MessageBox.Show("Error:" + Environment.NewLine + ex.Message); }
                    break;

                case "XColor_Button":
                    try { ColX = new ColorX(XColor_ICC, XColor.Take(XColor_Channels).ToArray()); Conversion(ColX); }
                    catch (Exception ex) { MessageBox.Show("Error:" + Environment.NewLine + ex.Message); }
                    break;

                case "DEF_Button":
                    try { ColDEF = new ColorDEF(DEFwp, DEF[0], DEF[1], DEF[2]); Conversion(ColDEF); }
                    catch (FormatException) { MessageBox.Show("Not a number!"); }
                    catch (Exception ex) { MessageBox.Show("Error:" + Environment.NewLine + ex.Message); }
                    break;

                case "Bef_Button":
                    try { ColBef = new ColorBef(Befwp, Bef[0], Bef[1], Bef[2]); Conversion(ColBef); }
                    catch (FormatException) { MessageBox.Show("Not a number!"); }
                    catch (Exception ex) { MessageBox.Show("Error:" + Environment.NewLine + ex.Message); }
                    break;

                case "BCH_Button":
                    try { ColBCH = new ColorBCH(BCHwp, BCH[0], BCH[1], BCH[2]); Conversion(ColBCH); }
                    catch (FormatException) { MessageBox.Show("Not a number!"); }
                    catch (Exception ex) { MessageBox.Show("Error:" + Environment.NewLine + ex.Message); }
                    break;
            }
        }
Esempio n. 8
0
        private void Conversion(Color inColor)
        {
            Color inColor2 = inColor;
            if (inColor.IsICCcolor && !inColor.IsPCScolor) { inColor2 = Converter.ToICC(inColor); }

            if (inColor.Model != ColorModel.CIEXYZ) ColXYZ = Converter.ToXYZ(inColor2, XYZwp);
            if (inColor.Model != ColorModel.CIELab) ColLab = Converter.ToLab(inColor2, Labwp);
            if (inColor.Model != ColorModel.CIELuv) ColLuv = Converter.ToLuv(inColor2, Luvwp);
            if (inColor.Model != ColorModel.CIELCHab) ColLCHab = Converter.ToLCHab(inColor2, LCHabwp);
            if (inColor.Model != ColorModel.CIELCHuv) ColLCHuv = Converter.ToLCHuv(inColor2, LCHuvwp);
            if (inColor.Model != ColorModel.CIEYxy) ColYxy = Converter.ToYxy(inColor2, Yxywp);
            if (inColor.Model != ColorModel.LCH99) ColLCH99 = Converter.ToLCH99(inColor2);
            if (inColor.Model != ColorModel.LCH99b) ColLCH99b = Converter.ToLCH99b(inColor2);
            if (inColor.Model != ColorModel.LCH99c) ColLCH99c = Converter.ToLCH99c(inColor2);
            if (inColor.Model != ColorModel.LCH99d) ColLCH99d = Converter.ToLCH99d(inColor2);
            if (inColor.Model != ColorModel.DEF) ColDEF = Converter.ToDEF(inColor2);
            if (inColor.Model != ColorModel.Bef) ColBef = Converter.ToBef(inColor2);
            if (inColor.Model != ColorModel.BCH) ColBCH = Converter.ToBCH(inColor2);

            if (inColor.Model != ColorModel.RGB)
            {
                if (RGBSpace != RGBSpaceName.ICC) ColRGB = Converter.ToRGB(inColor2, RGBSpace);
                else ColRGB = (ColorRGB)Converter.ToICC(Converter.ToICC_PCS(inColor2, RGB_ICC), RGB_ICC);
            }
            if (inColor.Model != ColorModel.HSV)
            {
                if (HSVSpace != RGBSpaceName.ICC) ColHSV = Converter.ToHSV(inColor2, HSVSpace);
                else ColHSV = (ColorHSV)Converter.ToICC(Converter.ToICC_PCS(inColor2, HSV_ICC), HSV_ICC);
            }
            if (inColor.Model != ColorModel.HSL)
            {
                if (HSLSpace != RGBSpaceName.ICC) ColHSL = Converter.ToHSL(inColor2, HSLSpace);
                else ColHSL = (ColorHSL)Converter.ToICC(Converter.ToICC_PCS(inColor2, HSL_ICC), HSL_ICC);
            }
            if (inColor.Model != ColorModel.CMY && CMY_ICC != null) ColCMY = (ColorCMY)Converter.ToICC(Converter.ToICC_PCS(inColor2, CMY_ICC), CMY_ICC);
            if (inColor.Model != ColorModel.CMYK && CMYK_ICC != null) ColCMYK = (ColorCMYK)Converter.ToICC(Converter.ToICC_PCS(inColor2, CMYK_ICC), CMYK_ICC);
            if (inColor.Model != ColorModel.YCbCr)
            {
                if (YCbCrSpace != YCbCrSpaceName.ICC) ColYCbCr = Converter.ToYCbCr(inColor2, YCbCrSpace);
                else ColYCbCr = (ColorYCbCr)Converter.ToICC(Converter.ToICC_PCS(inColor2, YCbCr_ICC), YCbCr_ICC);
            }
            if (inColor.Model != ColorModel.Gray)
            {
                if (CMY_ICC != null) ColGray = (ColorGray)Converter.ToICC(Converter.ToICC_PCS(inColor2, Gray_ICC), Gray_ICC);
                else ColGray = Converter.ToGray(inColor2);
            }
            if (!IsXColor(inColor.Model) && XColor_ICC != null) ColX = (ColorX)Converter.ToICC(Converter.ToICC_PCS(inColor2, XColor_ICC), XColor_ICC);

            FillFields();
        }
 /// <summary>
 /// Creates a new AnalogousColorSystem, with a hue angle of 30 degrees.
 /// </summary>
 /// <param name="mainColor">The first color.</param>
 public AnalogousThreeColorSystem(ColorHSV mainColor)
     : base(mainColor, 3)
 {
 }
 /// <summary>
 /// Compute lateral colors from main color.
 /// </summary>
 private void computeLaterals()
 {
     var c = colors[0];
     for (int i = 1; i < Count; i++)
         colors[i] = new ColorHSV(Helper.NormalizeAngle(getFactor(i) * hueAngle + c.H), c.S, c.V);
 }
Esempio n. 11
0
 public void SetColor(ColorHSV newColor)
 {
     var oldColor = parent.color;
     parent.color = newColor;
     parent.sendChanged(oldColor, newColor);
 }
Esempio n. 12
0
 /// <summary>
 /// Set given color and launch notifies the necessary changes.
 /// </summary>
 /// <param name="newColor">The new color to set.</param>
 private void setColorAndNotify(ColorHSV newColor)
 {
     if (color != newColor)
     {
         var oldColor = color;
         color = newColor;
         arrowsColorSetter.SetColor(index, newColor);
         sendChanged(oldColor, newColor);
     }
 }
Esempio n. 13
0
 /// <summary>
 /// Send PropertyChanged events according to what changed in the colors.
 /// </summary>
 /// <param name="oldColor">The old color.</param>
 /// <param name="newColor">The new color.</param>
 private void sendChanged(ColorHSV oldColor, ColorHSV newColor)
 {
     if (oldColor == newColor)
         return;
     var pe = PropertyChanged;
     if (pe == null)
         return;
     pe(this, new PropertyChangedEventArgs("Color"));
     if ((oldColor == null) != (newColor == null))
     {
         pe(this, new PropertyChangedEventArgs("Enabled"));
         pe(this, new PropertyChangedEventArgs("Angle"));
         pe(this, new PropertyChangedEventArgs("NormalizedLength"));
         return;
     }
     if (oldColor.H != newColor.H)
     {
         pe(this, new PropertyChangedEventArgs("Angle"));
     }
     if (oldColor.S != newColor.S)
     {
         pe(this, new PropertyChangedEventArgs("NormalizedLength"));
     }
 }
 /// <summary>
 /// Creates a new AnalogousColorSystem, with a hue angle of 30 degrees.
 /// </summary>
 /// <param name="mainColor">The first color.</param>
 public AnalogousFiveColorSystem(ColorHSV mainColor)
     : base(mainColor, 5)
 {
 }
Esempio n. 15
0
 public void SetColor(int index, ColorHSV newColor)
 {
     parent.colorSystem[index] = newColor;
     for (int i = 0; i < parent.colorSystem.Count; i++)
         if (i != index)
             parent.setArrowFromColorSystem(i);
 }