Example #1
0
        public static IEnumerable <int> CreateHueTransitionViaRed(int leadColor, int tailColor, int totalNumber)
        {
            var leadHsv = ColorCalculation.GetHSVFromRgbValue(leadColor);
            var tailHsv = ColorCalculation.GetHSVFromRgbValue(tailColor);

            var leadHue = leadHsv.Item1;
            var tailHue = tailHsv.Item1;

            var startHsv = (leadHue > tailHue) ? leadHsv : tailHsv;
            var endHsv   = (leadHue > tailHue) ? tailHsv : leadHsv;

            var hueDifference        = 360.0 + endHsv.Item1 - startHsv.Item1;
            var saturationDifference = endHsv.Item2 - startHsv.Item2;
            var valueDifference      = endHsv.Item3 - startHsv.Item3;

            var numberOfPartitions = totalNumber - 1;
            var colors             = Enumerable.Range(1, (numberOfPartitions - 1)).
                                     Select(e => ColorCalculation.GetRgbValueFromHsv(GetPartingHue(startHsv.Item1, hueDifference, e, numberOfPartitions),
                                                                                     (startHsv.Item2 + saturationDifference * e / numberOfPartitions),
                                                                                     (startHsv.Item3 + valueDifference * e / numberOfPartitions))
                                            );

            if (leadHue <= tailHue)
            {
                colors = colors.Reverse();
            }

            return(colors);
        }
Example #2
0
        public static IEnumerable <int> CreateHueTransition(int leadColor, int tailColor, int totalNumber)
        {
            var leadHsv = ColorCalculation.GetHSVFromRgbValue(leadColor);
            var tailHsv = ColorCalculation.GetHSVFromRgbValue(tailColor);

            var hueDifference        = tailHsv.Item1 - leadHsv.Item1;
            var saturationDifference = tailHsv.Item2 - leadHsv.Item2;
            var valueDifference      = tailHsv.Item3 - leadHsv.Item3;

            var numberOfPartitions = totalNumber - 1;
            var colors             = Enumerable.Range(1, (numberOfPartitions - 1)).
                                     Select(e => ColorCalculation.GetRgbValueFromHsv((leadHsv.Item1 + hueDifference * e / numberOfPartitions),
                                                                                     (leadHsv.Item2 + saturationDifference * e / numberOfPartitions),
                                                                                     (leadHsv.Item3 + valueDifference * e / numberOfPartitions))
                                            );

            return(colors);
        }