コード例 #1
0
        private void SetPickedColor(Color pColor)
        {
            Bitmap cView = new Bitmap(colorBox.Width, colorBox.Height);

            using (Graphics g = Graphics.FromImage(cView))
            {
                g.Clear(pColor);
                using (SolidBrush sb = new SolidBrush(ColorUtils.Invert(pColor)))
                {
                    using (Pen p = new Pen(sb, 1))
                    {
                        g.DrawRectangle(p, new Rectangle(1, 1, cView.Width - 3, cView.Height - 3));
                    }
                }
            }

            HSLColor hlc = HSLColor.FromColor(pColor);
            HSVColor hvc = HSVColor.FromColor(pColor);
            RGBColor rgc = RGBColor.FromColor(pColor);
            HEXColor hxc = HEXColor.FromColor(pColor);

            lbl_HTML.Text = hxc.ToString();
            lbl_RGB.Text  = rgc.ToString();
            lbl_HSL.Text  = hlc.ToString();
            lbl_HSV.Text  = hvc.ToString();

            colorBox.Image?.Dispose();
            colorBox.Image = cView;
        }
コード例 #2
0
        public void TestHSLColorCanProduceAProperStringRepresentation()
        {
            var hslColor = new HSLColor(348, 0.91, 0.5);

            hslColor.ToString().Should().BeEquivalentTo("hsl(348°, 91%, 50%)");
        }
コード例 #3
0
    //TODO THIS FUNCTION

    public void UpdateFromColor(Color aColor)
    {
        //ColorImages

        ColorA = aColor;

        if (ColorAImage != null)
        {
            ColorAImage.color = aColor;
        }



        //Event

        OnColorChange.Invoke();



        //HUE VARIABLES

        HSLColor newColor = aColor;

        HSLColor saturatedColorHSL = aColor;

        saturatedColorHSL.s = 1.0f;

        Color saturatedColorRGB = saturatedColorHSL;

        saturatedColorHSL = saturatedColorRGB;



        RectTransform rtColorWheel = ColorWheel.GetComponent <RectTransform> ();

        RectTransform rtColorTriangle = ColorTriangle.GetComponent <RectTransform> ();

        RectTransform rtColorHue = ColorHue.GetComponent <RectTransform> ();

        KUIColorTriangle KCT = ColorTriangle.gameObject.GetComponent <KUIColorTriangle> ();



        RectTransform rtColorWheelCursor = ColorWheel.imageCursor.GetComponent <RectTransform> ();

        RectTransform rtColorTriangleCursor = ColorTriangle.imageCursor.GetComponent <RectTransform> ();

        RectTransform rtColorHueCursor = ColorHue.imageCursor.GetComponent <RectTransform> ();



        //Hue Cursor

        float w = rtColorHue.rect.width;

        Vector3 p = rtColorHue.position;

        p.x = p.x - w * 0.5f + w * newColor.h / 360.0f;

        rtColorHueCursor.position = p;



        //Triangle Cursor

        w = rtColorTriangle.rect.width;

        float h = rtColorTriangle.rect.height;

        p = rtColorTriangle.position;

        p.x = p.x - w * 0.5f + w * newColor.s;

        p.y = p.y - h * 0.5f + h * newColor.l;

        rtColorTriangleCursor.position = p;



        //Triangle Point position and Color

        KCT.color3 = saturatedColorRGB;

        KCT.pointCenter = saturatedColorHSL.l;

        KCT.SetVerticesDirty();



        //Wheel

        w = rtColorWheel.rect.width;

        h = rtColorWheel.rect.height;

        p = rtColorWheel.position;

        p.x = p.x + Mathf.Cos((newColor.h + 30.0f) * Mathf.Deg2Rad) * w * 0.5f * newColor.s;

        p.y = p.y + Mathf.Sin((newColor.h + 30.0f) * Mathf.Deg2Rad) * h * 0.5f * newColor.s;

        rtColorWheelCursor.position = p;



        //Text

        ColorText.text = newColor.ToString();
    }