Ejemplo n.º 1
0
 private void _set(CadKit.Color.RGB rgb)
 {
     int[] hsv = CadKit.Color.HSV._convert(rgb);
     if (null != hsv && 3 == hsv.Length)
     {
         h = hsv[0];
         s = hsv[1];
         v = hsv[2];
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Generate colors along the circumference.
 /// </summary>
 private static System.Drawing.Color[] _makeColors(int num, int value)
 {
     System.Drawing.Color[] colors = new System.Drawing.Color[num];
     for (int i = 0; i < num; ++i)
     {
         float            u   = ((float)i) / (num - 1);
         float            hue = u * 255;
         CadKit.Color.HSV hsv = new CadKit.Color.HSV((int)hue, 255, value);
         CadKit.Color.RGB rgb = new CadKit.Color.RGB(hsv);
         colors[i] = System.Drawing.Color.FromArgb(rgb.r, rgb.g, rgb.b);
     }
     return(colors);
 }
Ejemplo n.º 3
0
            /// <summary>
            /// Adapted from: http://msdn.microsoft.com/msdnmag/issues/03/07/GDIColorPicker/
            /// </summary>
            private static int[] _convert(CadKit.Color.RGB rgb)
            {
                // In this function, R, G, and B values must be scaled
                // to be between 0 and 1.
                // HSV.Hue will be a value between 0 and 360, and
                // HSV.Saturation and value are between 0 and 1.
                // The code must scale these to be between 0 and 255 for
                // the purposes of this application.

                double min;
                double max;
                double delta;

                double r = ( double )rgb.r / 255;
                double g = ( double )rgb.g / 255;
                double b = ( double )rgb.b / 255;

                double h;
                double s;
                double v;

                min   = System.Math.Min(System.Math.Min(r, g), b);
                max   = System.Math.Max(System.Math.Max(r, g), b);
                v     = max;
                delta = max - min;
                if (max == 0 || delta == 0)
                {
                    // R, G, and B must be 0, or all the same.
                    // In this case, S is 0, and H is undefined.
                    // Using H = 0 is as good as any...
                    s = 0;
                    h = 0;
                }
                else
                {
                    s = delta / max;
                    if (r == max)
                    {
                        // Between Yellow and Magenta
                        h = (g - b) / delta;
                    }
                    else if (g == max)
                    {
                        // Between Cyan and Yellow
                        h = 2 + (b - r) / delta;
                    }
                    else
                    {
                        // Between Magenta and Cyan
                        h = 4 + (r - g) / delta;
                    }
                }
                // Scale h to be between 0 and 360.
                // This may require adding 360, if the value
                // is negative.
                h *= 60;
                if (h < 0)
                {
                    h += 360;
                }

                // Scale to the requirements of this
                // application. All values are between 0 and 255.
                return(new int[] { ( int )(h / 360 * 255), ( int )(s * 255), ( int )(v * 255) });
            }
Ejemplo n.º 4
0
 public HSV(CadKit.Color.RGB rgb)
 {
     this._set(rgb);
 }