コード例 #1
0
ファイル: ColorWheel.cs プロジェクト: RGKaizen/DoubleRainbow
        private void CalcCoordsAndUpdate(DRColor.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_norm.
            // 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 = DRColor.HSVtoColor(HSV);
            RGB           = new DRColor.RGB(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 = DRColor.HSVtoColor(new DRColor.HSV(HSV.Hue, HSV.Saturation, 255));
        }
コード例 #2
0
ファイル: ColorWheel.cs プロジェクト: RGKaizen/DoubleRainbow
 public void Draw(Graphics g, DRColor.HSV HSV)
 {
     // Given HSV values, update the screen.
     this._g  = g;
     this.HSV = HSV;
     CalcCoordsAndUpdate(this.HSV);
     UpdateDisplay();
 }
コード例 #3
0
ファイル: ColorWheel.cs プロジェクト: RGKaizen/DoubleRainbow
 public void Draw(Graphics g, DRColor.RGB RGB)
 {
     // Given RGB values, calculate HSV and then update the screen.
     this._g  = g;
     this.HSV = new DRColor.HSV(RGB);
     CalcCoordsAndUpdate(this.HSV);
     UpdateDisplay();
 }
コード例 #4
0
        public void Animate()
        {
            // Color Generation
            DRColor.HSV color_gen = _huey.getNextColor((float)Slider1Value, (float)Slider2Value, (float)Slider3Value);
            DRColor.RGB new_color = new DRColor.RGB(color_gen);

            // Position Generation
            Rainbow.Kai[23] = new_color;
            Rainbow.Kai[24] = new_color;
            Push();
            RainbowUtils.update();
            Thread.Sleep(refreshRate);
        }
コード例 #5
0
 public static DRColor.RGB increaseBrightness(DRColor.RGB rgb, int amt)
 {
     DRColor.HSV hsv = new DRColor.HSV(rgb);
     hsv.Value = hsv.Value + amt > 256 ? 256 : hsv.Value + amt;
     return(new DRColor.RGB(hsv));
 }
コード例 #6
0
 private DRColor.RGB AdjustVal(DRColor.RGB rgb, double perc)
 {
     DRColor.HSV hsv = new DRColor.HSV(rgb);
     hsv.Value = (int)(hsv.Value * perc);
     return new DRColor.RGB(hsv);
 }
コード例 #7
0
ファイル: DRColor.cs プロジェクト: RGKaizen/DoubleRainbow
            public RGB(DRColor.HSV hsv)
            {
                if (hsv == null)
                {
                    _red   = 0;
                    _green = 0;
                    _blue  = 0;
                    return;
                }

                // HSV contains values scaled as in the color wheel:
                // that is, all from 0 to 128.

                // 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;
                double s;
                double v;

                double r = 0;
                double g = 0;
                double b = 0;

                // 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;
                    double q;
                    double t;

                    double fractionalSector;
                    int    sectorNumber;
                    double sectorPos;

                    // 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 radius_norm, _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.
                this.setRed((int)(r * 128));
                this.setGreen((int)(g * 128));
                this.setBlue((int)(b * 128));
            }
コード例 #8
0
 public static DRColor.RGB increaseBrightness(DRColor.RGB rgb, int amt)
 {
     DRColor.HSV hsv = new DRColor.HSV(rgb);
     hsv.Value = hsv.Value + amt > 256 ? 256 : hsv.Value + amt;
     return new DRColor.RGB(hsv);
 }
コード例 #9
0
ファイル: ColorWheel.cs プロジェクト: RGKaizen/DoubleRainbow
        public ColorWheel(Rectangle colorRectangle, Rectangle brightnessRectangle, Rectangle selectedColorRectangle, DRColor.HSV default_color)
        {
            // Caller must provide locations for color wheel
            // (colorRectangle), brightness "strip" (brightnessRectangle)
            // and location to display selected color (selectedColorRectangle).

            using (GraphicsPath path = new GraphicsPath())
            {
                // Store away locations for later use.
                this.colorRectangle         = colorRectangle;
                this.brightnessRectangle    = brightnessRectangle;
                this.selectedColorRectangle = selectedColorRectangle;

                // Calculate the center of the circle.
                // Start with the location, then offset
                // the point by the radius_norm.
                // Use the smaller of the width and height of
                // the colorRectangle value.
                this.radius      = (int)Math.Min(colorRectangle.Width, colorRectangle.Height) / 2;
                this.centerPoint = colorRectangle.Location;
                this.centerPoint.Offset(radius, radius);

                // Start the pointer in the center.
                this.colorPoint = this.centerPoint;

                // Create angle region corresponding to the color circle.
                // Code uses this later to determine if angle specified
                // point is within the region, using the IsVisible
                // method.
                path.AddEllipse(colorRectangle);
                _colorRegion = new Region(path);

                // set { the range for the brightness selector.
                this.brightnessMin = this.brightnessRectangle.Top;
                this.brightnessMax = this.brightnessRectangle.Bottom;

                // Create angle region corresponding to the
                // brightness rectangle, with angle little extra
                // "breathing room".

                path.AddRectangle(new Rectangle(brightnessRectangle.Left, brightnessRectangle.Top - 10, brightnessRectangle.Width + 10, brightnessRectangle.Height + 20));
                // Create region corresponding to brightness
                // rectangle. Later code uses this to
                // determine if angle specified point is within
                // the region, using the IsVisible method.
                _brightnessRegion = new Region(path);

                // Set the location for the brightness indicator "marker".
                // Also calculate the scaling factor, scaling the height
                // to be between 0 and 255.
                brightnessX       = brightnessRectangle.Left + brightnessRectangle.Width;
                brightnessScaling = (double)255 / (brightnessMax - brightnessMin);

                // Calculate the location of the brightness
                // pointer. Assume it's at the highest position.
                brightnessPoint = new Point(brightnessX, brightnessMax);

                // Create the bitmap that contains the circular gradient.
                CreateGradient();

                CalcCoordsAndUpdate(default_color);
            }
        }
コード例 #10
0
 public ColorChangedEventArgs(DRColor.RGB RGB, DRColor.HSV HSV)
 {
     mRGB = RGB;
     mHSV = HSV;
 }
コード例 #11
0
ファイル: ColorWheel.cs プロジェクト: RGKaizen/DoubleRainbow
        protected void OnColorChanged(DRColor.RGB RGB, DRColor.HSV HSV)
        {
            ColorChangedEventArgs e = new ColorChangedEventArgs(RGB, HSV);

            ColorChanged(this, e);
        }
コード例 #12
0
 private DRColor.RGB AdjustVal(DRColor.RGB rgb, double perc)
 {
     DRColor.HSV hsv = new DRColor.HSV(rgb);
     hsv.Value = (int)(hsv.Value * perc);
     return(new DRColor.RGB(hsv));
 }
コード例 #13
0
 // If the H, S, or V values change, use this
 // code to update the RGB values and invalidate
 // the color wheel (so it updates the pointers).
 // Check the isInUpdate flag to avoid recursive events
 // when you update the NumericUpdownControls.
 private void HandleHSVScroll(object sender, ScrollEventArgs e)
 {
     _changeType = ChangeStyle.HSV;
     HSV = new DRColor.HSV(hsbHue.Value, hsbSaturation.Value, hsbBrightness.Value);
     SetRGB(new DRColor.RGB(HSV));
     SetHSVLabels(HSV);
     this.Invalidate();
     RainbowUtils.fillBoth(RGB);
 }
コード例 #14
0
        private void ColorChooser_Load(object sender, System.EventArgs e)
        {
            DRColor.HSV default_color = new DRColor.HSV(127, 256, 82);

            // Turn on double-buffering, so the form looks better.
            this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            this.SetStyle(ControlStyles.UserPaint, true);
            this.SetStyle(ControlStyles.DoubleBuffer, true);

            // These properties are set in design view, as well, but they
            // have to be set to false in order for the Paint
            // event to be able to display their contents.
            // Never hurts to make sure they're invisible.
            pnlSelectedColor.Visible = false;
            pnlBrightness.Visible = false;
            pnlColor.Visible = false;

            // Calculate the coordinates of the three
            // required regions on the form.
            Rectangle SelectedColorRectangle =  new Rectangle(pnlSelectedColor.Location, pnlSelectedColor.Size);
            Rectangle BrightnessRectangle = new Rectangle(pnlBrightness.Location, pnlBrightness.Size);
            Rectangle ColorRectangle = new Rectangle(pnlColor.Location, pnlColor.Size);

            // Create the new ColorWheel class, indicating
            // the locations of the color wheel itself, the
            // brightness area, and the position of the selected color.
            myColorWheel = new ColorWheel(ColorRectangle, BrightnessRectangle, SelectedColorRectangle, default_color);
            myColorWheel.ColorChanged += new ColorWheel.ColorChangedEventHandler(this.colorWheel_Changed);

            // Set the RGB and HSV values
            // of the NumericUpDown controls.
            SetRGB(new DRColor.RGB(default_color));
            SetHSV(default_color);
        }
コード例 #15
0
ファイル: ColorWheel.cs プロジェクト: RGKaizen/DoubleRainbow
 public void Draw(Graphics g, DRColor.HSV HSV)
 {
     // Given HSV values, update the screen.
     this._g = g;
     this.HSV = HSV;
     CalcCoordsAndUpdate(this.HSV);
     UpdateDisplay();
 }
コード例 #16
0
ファイル: ColorWheel.cs プロジェクト: RGKaizen/DoubleRainbow
 public void Draw(Graphics g, DRColor.RGB RGB)
 {
     // Given RGB values, calculate HSV and then update the screen.
     this._g = g;
     this.HSV = new DRColor.HSV(RGB);
     CalcCoordsAndUpdate(this.HSV);
     UpdateDisplay();
 }
コード例 #17
0
 public ColorChangedEventArgs(DRColor.RGB RGB, DRColor.HSV HSV)
 {
     mRGB = RGB;
     mHSV = HSV;
 }