Exemplo n.º 1
0
        private float GenerateScore(Swatch swatch, Target target)
        {
            float[] hsl             = swatch.GetHsl();
            float   saturationScore = 0;
            float   luminanceScore  = 0;
            float   populationScore = 0;
            int     maxPopulation   = _dominantSwatch?.GetPopulation() ?? 1;

            if (target.GetSaturationWeight() > 0)
            {
                saturationScore = target.GetSaturationWeight()
                                  * (1f - Math.Abs(hsl[1] - target.GetTargetSaturation()));
            }
            if (target.GetLightnessWeight() > 0)
            {
                luminanceScore = target.GetLightnessWeight()
                                 * (1f - Math.Abs(hsl[2] - target.GetTargetLightness()));
            }
            if (target.GetPopulationWeight() > 0)
            {
                populationScore = target.GetPopulationWeight()
                                  * (swatch.GetPopulation() / (float)maxPopulation);
            }
            return(saturationScore + luminanceScore + populationScore);
        }
Exemplo n.º 2
0
 private bool ShouldBeScoredForTarget(Swatch swatch, Target target)
 {
     // Check whether the HSL values are within the correct ranges, and this color hasn't
     // been used yet.
     float[] hsl = swatch.GetHsl();
     return(hsl[1] >= target.GetMinimumSaturation() && hsl[1] <= target.GetMaximumSaturation() &&
            hsl[2] >= target.GetMinimumLightness() && hsl[2] <= target.GetMaximumLightness() &&
            !_usedColors.Get(swatch.GetArgb()));
 }