Example #1
0
        private Color RybAsUColor(Color color)
        {
            RYB   rybColor   = Khroma.RgbToRyb(color);
            Color rybAsColor = new Color(rybColor.R, rybColor.Y, rybColor.B, rybColor.Alpha);

            return(rybAsColor);
        }
Example #2
0
        public static RYB RgbToRyb(Color rgba)
        {
            // Remove the white from the color
            float white = Mathf.Min(rgba.r, rgba.g, rgba.b);

            float r = rgba.r - white;
            float g = rgba.g - white;
            float b = rgba.b - white;

            float maxG = Mathf.Max(r, g, b);

            // Get the yellow out of the red+green

            float y = Mathf.Min(r, g);

            r -= y;
            g -= y;

            // If this unfortunate conversion combines blue and green, then cut each in half to
            // preserve the value's maximum range.
            if (b > 0 && g > 0)
            {
                b /= 2f;
                g /= 2f;
            }

            // Redistribute the remaining green.
            y += g;
            b += g;

            // Normalize to values.
            float maxY = Mathf.Max(r, y, b);

            if (maxY > 0)
            {
                float iN = maxG / maxY;

                r *= iN;
                y *= iN;
                b *= iN;
            }

            // Add the white back in.
            r += white;
            y += white;
            b += white;

            RYB ryb = new RYB(r, y, b, rgba.a);

            return(ryb);
        }
Example #3
0
        public static Color RybToRgb(RYB ryba)
        {
            // Remove the whiteness from the color.
            float white = Mathf.Min(ryba.R, ryba.Y, ryba.B);

            float r = ryba.R - white;
            float y = ryba.Y - white;
            float b = ryba.B - white;

            float maxY = Mathf.Max(r, y, b);

            // Get the green out of the yellow and blue
            float g = Mathf.Min(y, b);

            y -= g;
            b -= g;

            if (b > 0 && g > 0)
            {
                b *= 2f;
                g *= 2f;
            }

            // Redistribute the remaining yellow.
            r += y;
            g += y;

            // Normalize to values.
            float maxG = Mathf.Max(r, g, b);

            if (maxG > 0)
            {
                var iN = maxY / maxG;

                r *= iN;
                g *= iN;
                b *= iN;
            }

            // Add the white back in.
            r += white;
            g += white;
            b += white;

            Color rgb = new Color(r, g, b, ryba.Alpha);

            return(rgb);
        }
Example #4
0
        private RYB RybAsUColorReverse(Color rgb)
        {
            RYB color = new RYB(rgb.r, rgb.g, rgb.b, rgb.a);

            return(color);
        }