Exemple #1
0
 public Color3(HlsColor color)
 {
     this.A     = (float)color.H / 100f;
     this.B     = (float)color.L / 1000f;
     this.C     = (float)color.S / 1000f;
     this.Count = 1;
 }
        public static Color HlsToRgb(HlsColor hls)
        {
            double h = (double)hls.H / 100f;
            double l = (double)hls.L / 1000f;
            double s = (double)hls.S / 1000f;

            double p2;

            if (l <= 0.5f)
            {
                p2 = l * (1f + s);
            }
            else
            {
                p2 = l + s - l * s;
            }
            double p1 = 2f * l - p2;

            if (s == 0f)
            {
                int c = (int)(l * 255f);
                return(Color.FromArgb(c, c, c));
            }
            return(Color.FromArgb(
                       (int)(ColorTransform.QqhToRgb(p1, p2, h + 120f) * 255f),
                       (int)(ColorTransform.QqhToRgb(p1, p2, h) * 255f),
                       (int)(ColorTransform.QqhToRgb(p1, p2, h - 120f) * 255f)
                       ));
        }
        public static Color DarkColor(Color color, int percent)
        {
            HlsColor hls = ColorTransform.RgbToHls(color);

            float l = (float)hls.L / 1000f;

            l = l - ((l * (float)percent) / 100f);
            if (l < 0f)
            {
                l = 0f;
            }
            if (l > 1f)
            {
                l = 1f;
            }
            hls.L = (short)(l * 1000f);

            return(ColorTransform.HlsToRgb(hls));
        }