예제 #1
0
        private Color randNonSecretColor()
        {
            Color randColor;
            bool  badRand = true;

            while (badRand)
            {
                byte randR = (byte)rand.Next(0, 255);
                byte randG = (byte)rand.Next(0, 255);
                byte randB = (byte)rand.Next(0, 255);

                bool tooClose = false;
                for (int i = 0; i < secretColors.Count; i++)
                {
                    Color  secret    = secretColors[i];
                    CIELab secretLab = XYZtoLab(RGBtoXYZ(secret.R, secret.G, secret.B));
                    CIELab randLab   = XYZtoLab(RGBtoXYZ(randR, randG, randB));
                    double delta     = delta1994(randLab.L, randLab.A, randLab.B, secretLab.L, secretLab.A, secretLab.B);
                    if (delta <= 25)
                    {
                        tooClose = true;
                        break;
                    }
                }
                if (!tooClose)
                {
                    badRand   = false;
                    randColor = Color.FromArgb(255, randR, randG, randB);
                }
            }
            return(randColor);
        }
예제 #2
0
        /// <summary>
        /// Converts CIEXYZ to CIELab.
        /// </summary>
        public CIELab XYZtoLab(CIEXYZ xyz)
        {
            CIELab lab = CIELab.Empty;

            lab.L = 116.0 * Fxyz(xyz.Y / CIEXYZ.D65.Y) - 16;
            lab.A = 500.0 * (Fxyz(xyz.X / CIEXYZ.D65.X) - Fxyz(xyz.Y / CIEXYZ.D65.Y));
            lab.B = 200.0 * (Fxyz(xyz.Y / CIEXYZ.D65.Y) - Fxyz(xyz.Z / CIEXYZ.D65.Z));

            return(lab);
        }