public static SplitComplementaryColorScheme FromColor(ColorRGB color)
        {
            var swatches = new Swatch[] {
                new Swatch(PrimaryColorID, ColorHSL.Empty),
                new Swatch(SecondaryColorID, ColorHSL.Empty),
                new Swatch(TertiaryColorID, ColorHSL.Empty)
            };

            var primary = ColorHSL.FromColor(color);
            var h       = primary.H;
            var s       = primary.S;
            var l       = primary.L;

            swatches[0].Color = primary;

            var secondary = new ColorHSL(h, s, l);

            secondary.H      += 0.416666666666667;
            swatches[1].Color = secondary;

            var tertiary = new ColorHSL(h, s, l);

            tertiary.H        = h + 0.5 + 0.0833333333333333;
            swatches[2].Color = tertiary;

            return(new SplitComplementaryColorScheme(swatches));
        }
        public static AnalogousColorScheme FromColor(ColorRGB color)
        {
            var swatches = new Swatch[] {
                new Swatch(TertiaryColorID, ColorHSL.Empty),
                new Swatch(PrimaryColorID, ColorHSL.Empty),
                new Swatch(SecondaryColorID, ColorHSL.Empty)
            };

            var primary = ColorHSL.FromColor(color);
            var h       = primary.H;
            var s       = primary.S;
            var l       = primary.L;

            // Teriary
            var tertiary = new ColorHSL(h, s, l);

            tertiary.H       -= 0.0833333333333333;
            swatches[0].Color = tertiary;

            // Primary
            swatches[1].Color = primary;

            // Secondary
            var secondary = new ColorHSL(h, s, l);

            secondary.H      += 0.0833333333333333;
            swatches[2].Color = secondary;

            return(new AnalogousColorScheme(swatches));
        }
Beispiel #3
0
        public static RectangleColorScheme FromColor(ColorRGB color)
        {
            var swatches = new Swatch[] {
                new Swatch(QuaternaryColorID, ColorHSL.Empty),
                new Swatch(PrimaryColorID, ColorHSL.Empty),
                new Swatch(SecondaryColorID, ColorHSL.Empty),
                new Swatch(TertiaryColorID, ColorHSL.Empty)
            };

            var primary = ColorHSL.FromColor(color);
            var h       = primary.H;
            var s       = primary.S;
            var l       = primary.L;

            // quaternary
            var quaternary = new ColorHSL(h, s, l);

            quaternary.H     -= 0.166666666666667;
            swatches[0].Color = quaternary;

            // Primary
            swatches[1].Color = primary;

            // secondary
            swatches[2].Color = quaternary.Complementary();

            // tertiary
            swatches[3].Color = primary.Complementary();

            return(new RectangleColorScheme(swatches));
        }
        private TestColor TestColorHSL()
        {
            var color  = ColorHSL.FromColor(testColor);
            var color2 = (ColorRGB)color.ToRgb();

            // debug line
            //color2 = (ColorRGB)ColorHSL.ToColor (253, .464, .569);

            var nativeValue = string.Format("H:{0:0.00#} S:{1:0.00#} L:{2:0.00#}", color.H, color.S, color.L);

            return(new TestColor {
                Name = "HSL", Value = color2.ToHex(), NativeValue = nativeValue
            });
        }
        public void RGBtoHSLConversion()
        {
            var rgb          = ColorRGB.FromHex("#6653B2");
            var hsl          = (ColorHSL)ColorHSL.FromColor(rgb);
            var rgbConverter = (ColorRGB)hsl.ToRgb();

            // HSL
            Assert.AreEqual(hsl.Hue, 252);
            Assert.AreEqual(hsl.Saturation, 38.15);
            Assert.AreEqual(hsl.Luminance, 51.18);

            // RGB Converted
            Assert.AreEqual(rgbConverter.Red, 102);
            Assert.AreEqual(rgbConverter.Green, 83);
            Assert.AreEqual(rgbConverter.Blue, 178);
        }
        public static TriadicColorScheme FromColor(ColorRGB color)
        {
            var hsl = ColorHSL.FromColor(color);

            var divisor = 1d / 3d;

            hsl.H -= divisor;

            var swatches = new Swatch[] {
                new Swatch(TertiaryColorID, ColorHSL.Empty),
                new Swatch(PrimaryColorID, ColorHSL.Empty),
                new Swatch(SecondaryColorID, ColorHSL.Empty)
            };

            for (var i = 0; i < swatches.Length; i++)
            {
                swatches[i].Color = hsl.ToRgb();
                hsl.H            += divisor;
            }

            return(new TriadicColorScheme(swatches));
        }
Beispiel #7
0
    IEnumerator Start()
    {
        // PART 1: NAMED COLORS
        // The new Colors class has lots of ready to use color definitions
        Color red   = Colors.Crimson;
        Color green = Colors.Chartreuse;
        Color blue  = Colors.CornflowerBlue;
        Color pink  = Colors.Pink;

        // PART 2: HSL COLORS
        // ColorTools adds a new color structure that complements the Color and Color32
        // structs that ship with Unity. Its called ColorHSL and is an implementation
        // of the HSL color space. HSL works differently to the RGB colors you may be used
        // to, and makes reasoning about color much more simple!

        // A quick breakdown of the three values and their ranges
        ColorHSL lightBlueHSL = new ColorHSL();

        // The hue value represents the shade of our color.
        // Values close to 0 are red, 0.3 are green and 0.6 are blue
        lightBlueHSL.h = 0.55f;
        // Saturation represents how strong a color is. values close to 0 are totally
        // desaturated to gray. Values close to 1 are totally vivid!
        lightBlueHSL.s = 1;
        // Finally we have Lightness. As it moves towards 0, the color will tend towards
        // black. Values closer to 1 tend towards white.
        lightBlueHSL.l = 0.8f;
        // It is recommended you run the demo scene and play with the color picker to
        // familiarise yourself with these values!

        // Its easy to convert HSL colors to unity colors so we can uses them.
        Color lightBlue = ColorHSL.ToColor(lightBlueHSL);
        // We can also go the other way
        ColorHSL pinkHSL = ColorHSL.FromColor(pink);
        // ColorTools also implements implicit operators, which automatically converts
        // between Color and HSLColor
        ColorHSL greenHsl = Colors.Green;
        Color    green2   = greenHsl;

        // PART 3: COLOR TOOLS
        Color target = Colors.Blue;

        target = target.Lighten(0.25f);         // Get a lighter blue. This converts blue to a HSL
                                                // color and adds 0.25f to its Lightness

        target = target.Darken(0.25f);          // darken back to the origonal color

        target = target.LightenRelative(0.25f); // This converts blue to a HSL and lightens it
        // Rather than adding the value directly to lightness,
        // this adds a proportional amount. Has a stronger effect
        // on dark colors than already light colors.

        // There are Saturate/Desaturate versions of these methods.

        Color grayScale = target.Grayscale();   // Converts a color to its grayscale representation
                                                // by setting its Saturation to 0.

        float luminosity = target.Luminosity(); // Returns a float that tells us how bight the color is.
        // values close to 0 are dark and values close to 1 are light.

        var contrast = target.SelectContrasting(Colors.White, Colors.Black); // Returns which of the

        // two provided colors contrasts the most. This can be
        // useful for things like making sure text is readable
        // over a background color.

        if (target.IsSimilar(lightBlue)) // Returns true if the other color has a similar hue.
        {
            target = target.InvertHue(); // Inverts the colors Hue
        }

        // The static ColorHelper class has a bunch of methods for generating random colors
        // See DemoRandomColors() for some simple examples. Every second it randomizes the colors
        // in the RandomBrightColors, RandomPastelColors and RandomDarkColors arrays. Check their
        // contents in the inspector!
        InvokeRepeating("DemoRandomColors", 0, 1);

        // We can also use ColorHelper to animate a color over time.
        // We have to provide LerpOverTime with a delegate so it knows how to update a color.
        ColorHelper.LerpOverTime(c => lerpTarget = c, Colors.CornflowerBlue, Colors.HotPink, 10);
        // If your unfamilier with the syntax show above, you can also use a regular method ()
        ColorHelper.LerpOverTime(UpdateLerpTerget, Colors.CornflowerBlue, Colors.HotPink, 10);
        // If you want to be able to cancel a call to LerpOverTime, keep a reference to the IEnumerator
        // it returns to you. This can be used to cancel it.
        var handle = ColorHelper.LerpOverTime(UpdateLerpTerget, Colors.CornflowerBlue, Colors.HotPink, 10);

        ColorHelper.CancelLerpOverTime(handle);

        // We can also lerp an entire  list or array of colors over time
        Color[] from = new Color[5]; for (int i = 0; i < 5; i++)
        {
            from[i] = Colors.White;
        }
        Color[] to = new Color[5]; for (int i = 0; i < 5; i++)
        {
            to[i] = ColorHelper.RandomBrightColor();
        }
        LerpOverTimeTargets = new Color[5];
        ColorHelper.LerpOverTime(LerpOverTimeTargets, from, to, 10);

        // Finally, ColorTools supports Photoshop like colour blending
        while (true)
        {
            // You can set colours in BlendA/BlendB and change BlendStyle in the inspector to
            // see how the blend effects the resulting color.
            BlendResult = ColorHelper.Blend(BlendA, BlendB, BlendStyle);

            yield return(null);
        }
    }