Beispiel #1
0
        public static Color Layout(Color color)
        {
            EditorGUILayout.BeginHorizontal();

            if (IconButton.Layout("colorInvertRotate", '<', "Rotate hue -15°"))
            {
                color = color.ToHSV().Rotate(-15).RGB;
            }
            if (IconButton.Layout("complementaryColor", 'C', "Change to complementary color"))
            {
                color = color.ToHSV().Invert().RGB;
            }
            if (IconButton.Layout("triad", '3', "Cycle to triad"))
            {
                color = color.ToHSV().Triad().RGB;
            }

            color = EditorGUILayout.ColorField(color);

            if (IconButton.Layout("colorRotate", '>', "Rotate hue 15°"))
            {
                color = color.ToHSV().Rotate(15).RGB;
            }
            EditorGUILayout.EndHorizontal();
            return(color);
        }
    public void setModeColor(Color color)
    {
        switch (currentMode)
        {
        case ButtonState.Base:
            buttonColors.baseColor = color;
            baseButtonGraphic.GetFeatureData <CustomVectorChannelData>().value = color.ToHSV();
            break;

        case ButtonState.Pressed:
            buttonColors.pressedColor = color;
            pressedButtonGraphic.GetFeatureData <CustomVectorChannelData>().value = color.ToHSV();
            break;

        case ButtonState.Hovering:
            buttonColors.hoveringColor = color;
            hoveringButtonGraphic.GetFeatureData <CustomVectorChannelData>().value = color.ToHSV();
            break;

        case ButtonState.Toggled:
            buttonColors.toggledColor = color;
            toggledButtonGraphic.GetFeatureData <CustomVectorChannelData>().value = color.ToHSV();
            break;
        }
    }
Beispiel #3
0
 void Analogous()
 {
     for (int i = 0; i < 5; i++)
     {
         targetPalette.colors[i].rgb = baseColor.ToHSV().ShiftHue(15 * (i - 2)).ToColor();
         if ((i + 1) % 2 == 0)
         {
             ColorHelper.ColorHSV hsv = targetPalette.colors[i].rgb.ToHSV();
             hsv.s *= 0.8f;
             hsv.v  = Mathf.Min(hsv.v * 1.2f, 1f);
             targetPalette.colors[i].rgb = hsv.ToColor();
         }
     }
 }
Beispiel #4
0
        public static Color HueShift(this Color color, float amount)
        {
            var hsv = color.ToHSV();

            hsv.r = (hsv.r + amount) % 1f;

            return(hsv.ToRGB());
        }
 public ColorChangedEventArgs(RoutedEvent routedEvent, Color prevColor, Color oldColor, Color newColor, UpdatedColorReason reason) : base(routedEvent)
 {
     PreviewColor  = prevColor;
     OldColor      = oldColor;
     NewColor      = newColor;
     NewColorAsHSV = newColor.ToHSV();
     Reason        = reason;
 }
Beispiel #6
0
        private void GetGradientColors(Color baseColor, out Color topColor, out Color bottomColor)
        {
            double h, s, v;

            baseColor.ToHSV(out h, out s, out v);

            bottomColor = ColorExtensions.FromHSV(h, s, 0.8 * v);
            topColor    = ColorExtensions.FromHSV(h, 0.5 * s, Math.Min(1, 1.5 * v + 0.1));
        }
Beispiel #7
0
        protected void SelectNewColor(Color color, UpdatedColorReason reason)
        {
            var hsv = color.ToHSV();

            H = hsv.H;
            S = hsv.S;
            V = hsv.V;

            R = color.R;
            G = color.G;
            B = color.B;
            A = color.A;

            Debug.WriteLine(hsv.ToString());

            var oldColor = SelectedColor;

            SelectedColor = color;

            switch (reason)
            {
            case UpdatedColorReason.AChanged:
                UpdateHexText();
                Debug.WriteLine("alpha changed");
                break;

            case UpdatedColorReason.HueChanged:
                UpdateHexText();
                Debug.WriteLine("hue changed");
                break;

            case UpdatedColorReason.ValueAndSaturationChanged:
                UpdateHexText();
                Debug.WriteLine("value or saturation changed");
                break;

            case UpdatedColorReason.HexChanged:
                UpdateAlphaSlider();
                UpdateHueSlider();
                UpdateSaturationValuePicker();
                Debug.WriteLine("hex changed");
                break;

            case UpdatedColorReason.ColorPickerInitializated:
                UpdateHexText();
                UpdateAlphaSlider();
                UpdateHueSlider();
                UpdateSaturationValuePicker();
                Debug.WriteLine("Initalized Correctly");
                break;
            }

            var args = new ColorChangedEventArgs(ColorChangedEvent, PreviewColor, oldColor, color, reason);

            RaiseEvent(args);
        }
Beispiel #8
0
        void ColorChanged(Base control, EventArgs args)
        {
            IColorPicker picker = control as IColorPicker;
            Color        c      = picker.SelectedColor;
            HSV          hsv    = c.ToHSV();
            String       text   = String.Format("Color changed: RGB: {0:X2}{1:X2}{2:X2} HSV: {3:F1} {4:F2} {5:F2}",
                                                c.R, c.G, c.B, hsv.h, hsv.s, hsv.v);

            UnitPrint(text);
        }
Beispiel #9
0
        private void SetColor(Color color)
        {
            HSV hsv = color.ToHSV();

            m_SelectedDist = (int)(hsv.h / 360 * Height);

            if (ColorChanged != null)
            {
                ColorChanged.Invoke(this, EventArgs.Empty);
            }
        }
Beispiel #10
0
        public void SetColor(Color color, bool doEvents = true)
        {
            HSV hsv = color.ToHSV();

            m_SelectedDist = (int)(hsv.H / 360 * ActualHeight);

            if (doEvents && ColorChanged != null)
            {
                ColorChanged.Invoke(this, EventArgs.Empty);
            }
        }
Beispiel #11
0
        public static ColorHSV GetGasColor(SimHashes elementId, Color primaryColor, float pressureFraction, float mass)
        {
            var color = ScaleColorToPressure(primaryColor.ToHSV(), pressureFraction, elementId);

            if (mass >= ImprovedGasOverlayConfig.EarPopPressure)
            {
                color = MarkEarDrumPopPressure(color, elementId);
            }

            return(color.Clamp());
        }
Beispiel #12
0
        /// <summary>
        /// This is a helper method that sets the light's colors based on the color passed in
        /// </summary>
        public static void GetLightColors(out Color ambient, out Color front, out Color back, Color color)
        {
            ColorHSV hsv = color.ToHSV();

            //<AmbientLight x:Name="ambientLight" Color="#696969" />
            //<DirectionalLight x:Name="frontDirectional" Color="#FFFFFF" Direction="-1,-1,-1" />
            //<DirectionalLight x:Name="backDirectional" Color="#303030" Direction="1,1,1" />

            ambient = UtilityWPF.HSVtoRGB(color.A, hsv.H, hsv.S, hsv.V * .41d);
            front   = color;
            back    = UtilityWPF.HSVtoRGB(color.A, hsv.H, hsv.S, hsv.V * .19d);
        }
Beispiel #13
0
        private async void SetColorHSV(Color value)
        {
            double hue, saturation, brightness;

            value.ToHSV(out hue, out saturation, out brightness);

            await this.SetLightColorAsync((uint)hue);

            await this.SetBrightnessAsync((uint)brightness);

            await this.SetSaturationAsync((uint)saturation);
        }
Beispiel #14
0
        //[[nodiscard]] std::optional<QColor> Colorize(
        //		const QColor &color,
        //		const Colorizer &colorizer)
        //{
        //    auto hue = 0;
        //    auto saturation = 0;
        //    auto lightness = 0;
        //    color.getHsv(&hue, &saturation, &lightness);
        //    const auto result = Colorize(
        //        Colorizer::Color{ hue, saturation, lightness },
        //		colorizer);
        //    if (!result)
        //    {
        //        return std::nullopt;
        //    }
        //    const auto &fields = *result;
        //    return QColor::fromHsv(fields.hue, fields.saturation, fields.value);
        //}

        public Color Colorize(Color color)
        {
            var hsv    = color.ToHSV();
            var result = Colorize(hsv);

            if (result == null)
            {
                return(color);
            }

            return(result.Value.ToRGB());
        }
Beispiel #15
0
        private void OnColorChanged()
        {
            if (!(bool)_spinButtonR.Tag)
            {
                _spinButtonR.Value = R;
            }

            if (!(bool)_sliderR.Tag)
            {
                _sliderR.Value = R;
            }

            if (!(bool)_spinButtonG.Tag)
            {
                _spinButtonG.Value = G;
            }

            if (!(bool)_sliderG.Tag)
            {
                _sliderG.Value = G;
            }

            if (!(bool)_spinButtonB.Tag)
            {
                _spinButtonB.Value = B;
            }

            if (!(bool)_sliderB.Tag)
            {
                _sliderB.Value = B;
            }

            if (!(bool)_spinButtonA.Tag)
            {
                _spinButtonA.Value = A;
            }

            if (!(bool)_sliderA.Tag)
            {
                _sliderA.Value = A;
            }

            if (!(bool)_textFieldHex.Tag)
            {
                _textFieldHex.Text = Color.ToHexString().Substring(1);
            }

            if (!_suppressHSV)
            {
                SetHSV(Color.ToHSV());
            }
        }
        public override bool Contains(Color colour)
        {
            bool hsv = false;
            bool rgb = false;

            HSV h = colour.ToHSV();
            if ((h.H > 0 & h.H < 35 & h.S > 0.23d & h.S < 0.68) | Contains(h))
                hsv = true;

            rgb = skinColourLabels[colour.R, colour.G, colour.B];

            return rgb | hsv;
        }
Beispiel #17
0
        /// <summary>
        /// Make a gradient between two colors using HSV (Returns a list of colors blended from startColor to endColor).
        /// </summary>
        /// <returns>A list of colors blended from startColor to endColor.</returns>
        /// <param name="startColor">Start color.</param>
        /// <param name="endColor">End color.</param>
        /// <param name="blendColors>Number of blended colors in the middle (returned list's length will be this value plus two).</param>
        public static List <Color> MakeGradientHSV(Color startColor, Color endColor, int blendColors)
        {
            List <Color> gradient       = new List <Color>();
            float        startHue       = startColor.ToHSV().h;
            float        endHue         = endColor.ToHSV().h;
            float        startSat       = startColor.ToHSV().s;
            float        endSat         = endColor.ToHSV().s;
            float        startVal       = startColor.ToHSV().v;
            float        endVal         = endColor.ToHSV().v;
            float        degreesPerStep = (endHue - startHue);

            if (degreesPerStep > 180f)
            {
                degreesPerStep = degreesPerStep - 360f;
            }
            if (degreesPerStep < -180f)
            {
                degreesPerStep = degreesPerStep + 360f;
            }
            float saturationPerStep = (endSat - startSat);
            float valuePerStep      = (endVal - startVal);

            degreesPerStep    /= (float)(blendColors + 1);
            saturationPerStep /= (float)(blendColors + 1);
            valuePerStep      /= (float)(blendColors + 1);
            gradient.Add(startColor);
            ColorHSV colorHSV = startColor.ToHSV();

            for (int i = 0; i < blendColors; i++)
            {
                colorHSV.ShiftHue(degreesPerStep);
                colorHSV.s += saturationPerStep;
                colorHSV.v += valuePerStep;
                gradient.Add(colorHSV.ToColor());
            }
            gradient.Add(endColor);
            return(gradient);
        }
Beispiel #18
0
        /// <summary>
        /// Make a rainbow from the start color, shifting the hue until it reaches the end hue. (Returns a list of Colors).
        /// </summary>
        /// <param name="startColor">Start color.</param>
        /// <param name="endColor">Hue to stop shifting at (will only use the hue of this color, not value or saturation).</param>
        /// <param name="length">Desired length of the list.</param>
        public static List <Color> Rainbowify(Color startColor, Color endColor, int length)
        {
            List <Color> rainbow  = new List <Color>();
            float        startHue = startColor.ToHSV().h;
            float        endHue   = endColor.ToHSV().h;

            if (endHue < startHue)
            {
                endHue += 360f;
            }
            float degreesPerStep = (endHue - startHue);

            degreesPerStep /= (float)length - 1;
            rainbow.Add(startColor);
            ColorHSV colorHSV = startColor.ToHSV();

            for (int i = 0; i < length - 1; i++)
            {
                colorHSV.ShiftHue(degreesPerStep);
                rainbow.Add(colorHSV.ToColor());
            }
            return(rainbow);
        }
Beispiel #19
0
        /// <summary>
        /// Make a rainbow from the start color, shifting the hue a specified number of degrees each step (Returns a list of Colors).
        /// </summary>
        /// <param name="startColor">Start color.</param>
        /// <param name="degreesPerStep">Degrees to shift the hue per step.</param>
        /// <param name="length">Desired length of the list.</param>
        public static List <Color> Rainbowify(Color startColor, float degreesPerStep, int length)
        {
            List <Color> rainbow = new List <Color>();

            rainbow.Add(startColor);
            ColorHSV colorHSV = startColor.ToHSV();

            for (int i = 0; i < length - 1; i++)
            {
                colorHSV.ShiftHue(degreesPerStep);
                rainbow.Add(colorHSV.ToColor());
            }
            return(rainbow);
        }
Beispiel #20
0
            private static ColorHSV GetGasColor(SimHashes elementID, Color primaryColor, float pressureFraction, float mass)
            {
                ColorHSV colorHSV = primaryColor.ToHSV();

                colorHSV = ScaleColorToPressure(colorHSV, pressureFraction, elementID);

                if (ImprovedGasOverlayConfig.ShowEarDrumPopMarker)
                {
                    colorHSV = MarkEarDrumPopPressure(colorHSV, mass, elementID);
                }

                colorHSV = colorHSV.Clamp();

                return(colorHSV);
            }
        /// <summary>
        /// Sets the selected color.
        /// </summary>
        /// <param name="value">Value to set.</param>
        /// <param name="onlyHue">Deetrmines whether to only set H value (not SV).</param>
        public void SetColor(Color value, bool onlyHue) /*true*/
        {
            HSV hsv = value.ToHSV();
            m_Hue = hsv.h;

            if (!onlyHue)
            {
                m_CursorPos.X = (int)(hsv.s * Width);
                m_CursorPos.Y = (int)((1 - hsv.v) * Height);
            }
            Invalidate();

            if (ColorChanged != null)
                ColorChanged.Invoke(this);
        }
Beispiel #22
0
        public ColorSelectDialog(Vector2 windowTalePosition, UColor currentColor) : this()
        {
            Color currentWColor = currentColor.ToColor();

            this.windowTalePosition = windowTalePosition;
            this.oldColor           = currentColor;
            this.selectedHsv        = currentWColor.ToHSV();

            ColorBox_SV.Effect  = colorEditor_SV_Shader = new Shader_ColorEditor_SV();
            ColorBox_Hue.Effect = new Shader_ColorEditor_H();

            CurrentColorIndicator.Fill = currentWColor.ToBrush();

            Opacity = 0d;
        }
Beispiel #23
0
        private void UpdateColorByHex(object value)
        {
            if (onEditTextEvent)
            {
                return;
            }

            string hex = (string)EditText_Hex.EditableValue;

            try {
                Color color = hex.ToColor();
                selectedHsv = color.ToHSV();
            } catch {
            }
            OnValueChanged_SelectedHsv();
        }
Beispiel #24
0
        private void UpdateColorByRGB(object value)
        {
            if (onEditTextEvent)
            {
                return;
            }

            try {
                Color color = Color.FromArgb(255,
                                             (byte)Mathf.Clamp(EditText_R.IntValue, 0, 255),
                                             (byte)Mathf.Clamp(EditText_G.IntValue, 0, 255),
                                             (byte)Mathf.Clamp(EditText_B.IntValue, 0, 255));
                selectedHsv = color.ToHSV();
            } catch {
            }
            OnValueChanged_SelectedHsv();
        }
Beispiel #25
0
        static void Main()
        {
            const int rectWidth  = 200;
            const int rectHeight = 20;
            const int space      = 5;

            // sorted per HSV colorspace
            List <(Color Color, string Name)> colors = GetKnownColors()
                                                       .Select(c => (c, c.Color.ToHSV()))
                                                       .OrderBy(cc => cc.Item2[0])
                                                       .ThenBy(cc => cc.Item2[1])
                                                       .ThenBy(cc => cc.Item2[2])
                                                       .Select(cc => cc.c)
                                                       .ToList();

            const int surfaceWidth  = rectWidth + 2 * space;
            int       surfaceHeight = (rectHeight + space) * (colors.Count + 1);

            using (var surface = new SvgSurface("known_colors.svg", surfaceWidth, surfaceHeight))
                using (var context = new Context(surface))
                {
                    context.LineWidth = 0.35;
                    context.SelectFontFace("Arial", FontSlant.Normal, FontWeight.Normal);
                    context.SetFontSize(10);

                    for (int i = 0; i < colors.Count; ++i)
                    {
                        int y = 10 + i * (rectHeight + space);

                        context.Rectangle(10, y, rectWidth, rectHeight);
                        context.Color = colors[i].Color;
                        context.FillPreserve();

                        context.Color = new Color(0, 0, 0);
                        context.Stroke();

                        string name      = colors[i].Name;
                        double textWidth = context.GetTextWidth(name);

                        context.Color = colors[i].Color.GetInverseColor();
                        context.MoveTo((surfaceWidth - textWidth) / 2, y + context.FontExtents.Height);
                        context.ShowText(name);
                    }
                }
        }
Beispiel #26
0
    public void setGraphicColor(Color color)
    {
        if (graphic == null)
        {
            graphic = GetComponent <LeapGraphic>();
            if (graphic == null)
            {
                graphic = GetComponentInParent <LeapGraphic>();
            }
        }

        if (graphicColor == null)
        {
            graphicColor = graphic.GetFeatureData <CustomVectorChannelData>();
        }

        graphicColor.value = color.ToHSV();
    }
Beispiel #27
0
        /// <summary>
        /// Sets the selected color.
        /// </summary>
        /// <param name="value">Value to set.</param>
        /// <param name="onlyHue">Deetrmines whether to only set H value (not SV).</param>
        public void SetColor(Color value, bool onlyHue = true)
        {
            HSV hsv = value.ToHSV();

            hue = hsv.h;

            if (!onlyHue)
            {
                cursorPos.X = (int)(hsv.s * Width);
                cursorPos.Y = (int)((1 - hsv.v) * Height);
            }
            Invalidate();

            if (ColorChanged != null)
            {
                ColorChanged.Invoke(this, EventArgs.Empty);
            }
        }
Beispiel #28
0
        /// <summary>
        /// Sets the selected color.
        /// </summary>
        /// <param name="value">Value to set.</param>
        /// <param name="onlyHue">Deetrmines whether to only set H value (not SV).</param>
        public void SetColor(Color value, bool onlyHue = true, bool doEvents = true)
        {
            HSV hsv = value.ToHSV();

            m_Hue = hsv.H;

            if (!onlyHue)
            {
                m_CursorPos.X = (int)(hsv.S * ActualWidth);
                m_CursorPos.Y = (int)((1 - hsv.V) * ActualHeight);
            }
            InvalidateTexture();

            if (doEvents && ColorChanged != null)
            {
                ColorChanged.Invoke(this, EventArgs.Empty);
            }
        }
Beispiel #29
0
        public static void DrawBackground(Graphics g, Color timerColor, Color settingsColor1, Color settingsColor2,
                                          float width, float height, DeltasGradientType gradientType)
        {
            var background1 = settingsColor1;
            var background2 = settingsColor2;

            if (gradientType == DeltasGradientType.PlainWithDeltaColor ||
                gradientType == DeltasGradientType.HorizontalWithDeltaColor ||
                gradientType == DeltasGradientType.VerticalWithDeltaColor)
            {
                double h, s, v;
                timerColor.ToHSV(out h, out s, out v);
                var newColor = ColorExtensions.FromHSV(h, s * 0.5, v * 0.25);

                if (gradientType == DeltasGradientType.PlainWithDeltaColor)
                {
                    background1 = Color.FromArgb(timerColor.A * 7 / 12, newColor);
                }
                else
                {
                    background1 = Color.FromArgb(timerColor.A / 6, newColor);
                    background2 = Color.FromArgb(timerColor.A, newColor);
                }
            }
            if (background1.A > 0 ||
                gradientType != DeltasGradientType.Plain &&
                background2.A > 0)
            {
                var gradientBrush = new LinearGradientBrush(
                    new PointF(0, 0),
                    gradientType == DeltasGradientType.Horizontal ||
                    gradientType == DeltasGradientType.HorizontalWithDeltaColor
                            ? new PointF(width, 0)
                            : new PointF(0, height),
                    background1,
                    gradientType == DeltasGradientType.Plain ||
                    gradientType == DeltasGradientType.PlainWithDeltaColor
                            ? background1
                            : background2);
                g.FillRectangle(gradientBrush, 0, 0, width, height);
            }
        }
            private static ColorHSV GetGasColor(SimHashes elementID, Color primaryColor, float pressureFraction, float mass)
            {
                ColorHSV colorHSV = primaryColor.ToHSV();

                colorHSV = ScaleColorToPressure(colorHSV, pressureFraction, elementID);

                if (ONI_Common.State.ConfiguratorState.ShowEarDrumPopMarker)
                {
                    colorHSV = MarkEarDrumPopPressure(colorHSV, mass, elementID);
                }

                if (ONI_Common.State.ConfiguratorState.AdvancedGasOverlayDebugging)
                {
                    colorHSV.CheckAndLogOverflow(elementID, pressureFraction);
                }

                colorHSV = colorHSV.Clamp();

                return(colorHSV);
            }
Beispiel #31
0
    public void DocsColor128()
    {
        /// :CodeSample: Color Color.HSV
        // You can create a color using Red, Green, Blue, Alpha values,
        // but it's often a great recipe for making a bad color.
        Color color = new Color(1, 0, 0, 1);      // Red

        // Hue, Saturation, Value, Alpha is a more natural way of picking
        // colors. The commentdocs have a list of important values for Hue,
        // to make it a little easier to pick the hue you want.
        color = Color.HSV(0, 1, 1, 1);         // Red

        // And there's a few static colors available if you need 'em.
        color = Color.White;

        // You can also implicitly convert Color to a Color32!
        Color32 color32 = color;
        /// :End:

        /// :CodeSample: Color.HSV Color.ToHSV Color.LAB Color.ToLAB
        // Desaturating a color can be done quite nicely with the HSV
        // functions
        Color red      = new Color(1, 0, 0, 1);
        Vec3  colorHSV = red.ToHSV();

        colorHSV.y *= 0.5f;         // Drop saturation by half
        Color desaturatedRed = Color.HSV(colorHSV, red.a);

        // LAB color space is excellent for modifying perceived
        // brightness, or 'Lightness' of a color.
        Color green    = new Color(0, 1, 0, 1);
        Vec3  colorLAB = green.ToLAB();

        colorLAB.x *= 0.5f;         // Drop lightness by half
        Color darkGreen = Color.LAB(colorLAB, green.a);
        /// :End:
    }
 /// <summary>
 /// Make a gradient between two colors using HSV (Returns a list of colors blended from startColor to endColor).
 /// </summary>
 /// <returns>A list of colors blended from startColor to endColor.</returns>
 /// <param name="startColor">Start color.</param>
 /// <param name="endColor">End color.</param>
 /// <param name="blendColors>Number of blended colors in the middle (returned list's length will be this value plus two).</param>
 public static List<Color> MakeGradientHSV(Color startColor, Color endColor, int blendColors)
 {
     List<Color> gradient = new List<Color>();
     float startHue = startColor.ToHSV().h;
     float endHue = endColor.ToHSV().h;
     float startSat = startColor.ToHSV().s;
     float endSat = endColor.ToHSV().s;
     float startVal = startColor.ToHSV().v;
     float endVal = endColor.ToHSV().v;
     float degreesPerStep = (endHue - startHue);
     if (degreesPerStep > 180f) {
         degreesPerStep = degreesPerStep - 360f;
     }
     if (degreesPerStep < -180f) {
         degreesPerStep = degreesPerStep + 360f;
     }
     float saturationPerStep = (endSat - startSat);
     float valuePerStep = (endVal - startVal);
     degreesPerStep /= (float)(blendColors + 1);
     saturationPerStep /= (float)(blendColors + 1);
     valuePerStep /= (float)(blendColors + 1);
     gradient.Add(startColor);
     ColorHSV colorHSV = startColor.ToHSV();
     for (int i = 0; i < blendColors; i++) {
         colorHSV.ShiftHue(degreesPerStep);
         colorHSV.s += saturationPerStep;
         colorHSV.v += valuePerStep;
         gradient.Add(colorHSV.ToColor());
     }
     gradient.Add(endColor);
     return gradient;
 }
 /// <summary>
 /// Make a rainbow from the start color, shifting the hue a specified number of degrees each step (Returns a list of Colors).
 /// </summary>
 /// <param name="startColor">Start color.</param>
 /// <param name="degreesPerStep">Degrees to shift the hue per step.</param>
 /// <param name="length">Desired length of the list.</param>
 public static List<Color> Rainbowify(Color startColor, float degreesPerStep, int length)
 {
     List<Color> rainbow = new List<Color>();
     rainbow.Add(startColor);
     ColorHSV colorHSV = startColor.ToHSV();
     for (int i = 0; i < length - 1; i++) {
         colorHSV.ShiftHue(degreesPerStep);
         rainbow.Add(colorHSV.ToColor());
     }
     return rainbow;
 }
Beispiel #34
0
        /// <summary>
        /// Sets the selected color.
        /// </summary>
        /// <param name="value">Value to set.</param>
        /// <param name="onlyHue">Deetrmines whether to only set H value (not SV).</param>
        public void SetColor(Color value, bool onlyHue = true)
        {
            HSV hsv = value.ToHSV();
            m_Hue = hsv.h;

            if (!onlyHue)
            {
                m_CursorPos.X = (int)(hsv.s * Width);
                m_CursorPos.Y = (int)((1 - hsv.v) * Height);
            }
            Invalidate();

            ColorChanged?.Invoke(this, EventArgs.Empty);
        }
        private void SetColor(Color color)
        {
            HSV hsv = color.ToHSV();

            m_SelectedDist = (int)(hsv.h / 360 * Height);

            if (ColorChanged != null)
                ColorChanged.Invoke(this, EventArgs.Empty);
        }
 /// <summary>
 /// Make a rainbow from the start color, shifting the hue until it reaches the end hue. (Returns a list of Colors).
 /// </summary>
 /// <param name="startColor">Start color.</param>
 /// <param name="endColor">Hue to stop shifting at (will only use the hue of this color, not value or saturation).</param>
 /// <param name="length">Desired length of the list.</param>
 public static List<Color> Rainbowify(Color startColor, Color endColor, int length)
 {
     List<Color> rainbow = new List<Color>();
     float startHue = startColor.ToHSV().h;
     float endHue = endColor.ToHSV().h;
     if (endHue < startHue) {
         endHue += 360f;
     }
     float degreesPerStep = (endHue - startHue);
     degreesPerStep /= (float)length - 1;
     rainbow.Add(startColor);
     ColorHSV colorHSV = startColor.ToHSV();
     for (int i = 0; i < length - 1; i++) {
         colorHSV.ShiftHue(degreesPerStep);
         rainbow.Add(colorHSV.ToColor());
     }
     return rainbow;
 }
Beispiel #37
0
        //void Colorize(string name, ref byte r, ref byte g, ref byte b)
        //{
        //    if (ignoreKeys.Contains(name))
        //    {
        //        return;
        //    }

        //    const auto i = keepContrast.find(name);
        //    if (i == end(colorizer.keepContrast))
        //    {
        //        Colorize(r, g, b);
        //        return;
        //    }
        //    var check = i->second.first;
        //    var rgb = QColor(int(r), int(g), int(b));
        //    var changed = Colorize(rgb, colorizer);
        //    var checkez = Colorize(check, colorizer).value_or(check);
        //    double lightness(HSV hsv)
        //    {
        //        return hsv.V - (hsv.V * hsv.S) / 511;
        //    };
        //    var changedLightness = lightness(changed.value_or(rgb).toHsv());
        //    var checkedLightness = lightness(
        //        new HSV(checkez.hue, checkez.saturation, checkez.value));
        //    var delta = Math.Abs(changedLightness - checkedLightness);
        //    if (delta >= kEnoughLightnessForContrast)
        //    {
        //        if (changed)
        //        {
        //            FillColorizeResult(r, g, b, *changed);
        //        }
        //        return;
        //    }
        //    const auto replace = i->second.second;
        //    const auto result = Colorize(replace, colorizer).value_or(replace);
        //    FillColorizeResult(
        //        r,
        //        g,
        //        b,
        //        QColor::fromHsv(result.hue, result.saturation, result.value));
        //}

        public static ThemeColorizer FromTheme(TelegramThemeType type, Color accent, Color color)
        {
            var temp = (RGB)color;

            var result = new ThemeColorizer();

            //result.ignoreKeys = kColorizeIgnoredKeys;
            result._hueThreshold = 15;
            result._was          = accent.ToHSV();
            result._now          = color.ToHSV();
            switch (type)
            {
            case TelegramThemeType.Day:
                result._lightnessMax = 160d / 255d;
                break;

            case TelegramThemeType.Night:
                //                  result.keepContrast = base::flat_map<QLatin1String, Pair>{
                //                      {
                //                          //{ qstr("windowFgActive"), Pair{ cColor("5288c1"), cColor("17212b") } }, // windowBgActive
                //                          {
                //                              qstr("activeButtonFg"), Pair{ cColor("2f6ea5"), cColor("17212b") }
                //                          }, // activeButtonBg
                //	{ qstr("profileVerifiedCheckFg"), Pair{ cColor("5288c1"), cColor("17212b") } }, // profileVerifiedCheckBg
                //	{ qstr("overviewCheckFgActive"), Pair{ cColor("5288c1"), cColor("17212b") } }, // overviewCheckBgActive
                //	{ qstr("historyFileInIconFg"), Pair{ cColor("3f96d0"), cColor("182533") } }, // msgFileInBg, msgInBg
                //	{ qstr("historyFileInIconFgSelected"), Pair{ cColor("6ab4f4"), cColor("2e70a5") } }, // msgFileInBgSelected, msgInBgSelected
                //	{ qstr("historyFileInRadialFg"), Pair{ cColor("3f96d0"), cColor("182533") } }, // msgFileInBg, msgInBg
                //	{ qstr("historyFileInRadialFgSelected"), Pair{ cColor("6ab4f4"), cColor("2e70a5") } }, // msgFileInBgSelected, msgInBgSelected
                //	{ qstr("historyFileOutIconFg"), Pair{ cColor("4c9ce2"), cColor("2b5278") } }, // msgFileOutBg, msgOutBg
                //	{ qstr("historyFileOutIconFgSelected"), Pair{ cColor("58abf3"), cColor("2e70a5") } }, // msgFileOutBgSelected, msgOutBgSelected
                //	{ qstr("historyFileOutRadialFg"), Pair{ cColor("4c9ce2"), cColor("2b5278") } }, // msgFileOutBg, msgOutBg
                //	{ qstr("historyFileOutRadialFgSelected"), Pair{ cColor("58abf3"), cColor("2e70a5") } }, // msgFileOutBgSelected, msgOutBgSelected
                //}
                //                  };
                result._lightnessMin = 64d / 255d;
                break;

            case TelegramThemeType.Tinted:
                //                  result.keepContrast = base::flat_map<QLatin1String, Pair>{
                //                      {
                //                          //{ qstr("windowFgActive"), Pair{ cColor("3fc1b0"), cColor("282e33") } }, // windowBgActive, windowBg
                //                          { qstr("activeButtonFg"), Pair{ cColor("2da192"), cColor("282e33") } }, // activeButtonBg, windowBg
                //	{ qstr("profileVerifiedCheckFg"), Pair{ cColor("3fc1b0"), cColor("282e33") } }, // profileVerifiedCheckBg, windowBg
                //	{ qstr("overviewCheckFgActive"), Pair{ cColor("3fc1b0"), cColor("282e33") } }, // overviewCheckBgActive
                //	{ qstr("callIconFg"), Pair{ cColor("5ad1c1"), cColor("26282c") } }, // callAnswerBg, callBg
                //}
                //                  };
                result._lightnessMin = 64d / 255d;
                break;
            }
            var nowLightness     = temp.ToHSL().L;
            var limitedLightness = Math.Clamp(
                nowLightness,
                result._lightnessMin,
                result._lightnessMax);

            if (limitedLightness != nowLightness)
            {
                var temp1 = temp.ToHSL();
                var temp2 = new HSL(temp1.H, temp1.S, limitedLightness);
                var temp3 = temp2.ToRGB();

                result._now = temp3.ToHSV();
            }

            return(result);
        }
        /// <summary>
        /// This is a helper method that sets the light's colors based on the color passed in
        /// </summary>
        public static void GetLightColors(out Color ambient, out Color front, out Color back, Color color)
        {
            ColorHSV hsv = color.ToHSV();

            //<AmbientLight x:Name="ambientLight" Color="#696969" />
            //<DirectionalLight x:Name="frontDirectional" Color="#FFFFFF" Direction="-1,-1,-1" />
            //<DirectionalLight x:Name="backDirectional" Color="#303030" Direction="1,1,1" />

            ambient = UtilityWPF.HSVtoRGB(color.A, hsv.H, hsv.S, hsv.V * .41d);
            front = color;
            back = UtilityWPF.HSVtoRGB(color.A, hsv.H, hsv.S, hsv.V * .19d);
        }
 public HSV(Color c)
 {
     this = c.ToHSV();
 }