private void CalcCoordsAndUpdate(HSV HSV)
        {
            // Convert color to real-world coordinates and then calculate the various points. HSV.Hue represents the degrees (0 to 360),
            // HSV.Saturation represents the radius. This procedure doesn't draw anything--it simply updates class-level variables. The UpdateDisplay
            // procedure uses these values to update the screen.

            // Given the angle (HSV.Hue), and distance from the center (HSV.Saturation), and the center, calculate the point corresponding to
            // the selected color, on the color wheel.
            colorPoint = GetPoint((double)HSV.Hue / 255 * 360, (double)HSV.Saturation / 255 * radius, centerPoint);

            // Given the brightness (HSV.value), calculate the point corresponding to the brightness indicator.
            brightnessPoint = CalcBrightnessPoint(HSV.Value);

            // Store information about the selected color.
            brightness    = HSV.Value;
            selectedColor = ColorHelper.HSVtoColor(HSV);
            RGB           = ColorHelper.HSVtoRGB(HSV);

            // The full color is the same as HSV, except that the brightness is set to full (255). This is the top-most
            // color in the brightness gradient.
            fullColor = ColorHelper.HSVtoColor(HSV.Hue, HSV.Saturation, 255);
        }
 protected void OnColorChanged(RGB RGB, HSV HSV)
 {
     ColorChanged(this, new ColorChangedEventArgs(RGB, HSV));
 }
 protected void OnColorChanged(RGB RGB, HSV HSV)
 {
     //ColorChanged(this, new ColorChangedEventArgs(selectedColor));
 }
Beispiel #4
0
 public ColorChangedEventArgs(RGB RGB, HSV HSV)
 {
     mRGB = RGB;
     mHSV = HSV;
 }
        public static RGB HSVtoRGB(HSV hsv)
        {
            // HSV contains values scaled as in the color wheel: that is, all from 0 to 255.
            // for ( this code to work, HSV.Hue needs to be scaled from 0 to 360 (it//s the angle of the selected
            // point within the circle). HSV.Saturation and HSV.value must be scaled to be between 0 and 1.
            double h = 0D, s = 0D, v = 0D;
            double r = 0D, g = 0D, b = 0D;

            // Scale Hue to be between 0 and 360. Saturation and value scale to be between 0 and 1.
            h = ((double)hsv.Hue / 255 * 360) % 360;
            s = (double)hsv.Saturation / 255;
            v = (double)hsv.Value / 255;

            if (s == 0)
            {
                // If s is 0, all colors are the same. This is some flavor of gray.
                r = v;
                g = v;
                b = v;
            }
            else
            {
                double p = 0D, q = 0D, t = 0D;

                double fractionalSector;
                double sectorPos;
                int    sectorNumber;

                // The color wheel consists of 6 sectors. Figure out which sector you//re in.
                sectorPos    = h / 60;
                sectorNumber = (int)(Math.Floor(sectorPos));

                // get the fractional part of the sector. That is, how many degrees into the sector are you?
                fractionalSector = sectorPos - sectorNumber;

                // Calculate values for the three axes of the color.
                p = v * (1 - s);
                q = v * (1 - (s * fractionalSector));
                t = v * (1 - (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 = v;
                    g = t;
                    b = p;
                    break;

                case 1:
                    r = q;
                    g = v;
                    b = p;
                    break;

                case 2:
                    r = p;
                    g = v;
                    b = t;
                    break;

                case 3:
                    r = p;
                    g = q;
                    b = v;
                    break;

                case 4:
                    r = t;
                    g = p;
                    b = v;
                    break;

                case 5:
                    r = v;
                    g = p;
                    b = q;
                    break;
                }
            }
            // return an RGB structure, with values scaled to be between 0 and 255.
            return(new RGB((byte)(r * 255), (byte)(g * 255), (byte)(b * 255)));
        }
        public static Color HSVtoColor(HSV hsv)
        {
            RGB rgb = HSVtoRGB(hsv);

            return(Color.FromArgb(rgb.Red, rgb.Green, rgb.Blue));
        }