public static ColorPairs GetColorFromPairNumber(int pairNumber)
        {
            // The function supports only 1 based index. Pair numbers valid are from 1 to 25
            int minorSize = Program.colorMapMinor.Length;
            int majorSize = Program.colorMapMajor.Length;

            if (pairNumber < 1 || pairNumber > minorSize * majorSize)
            {
                string.Format("Argument PairNumber:{0} is outside the allowed range", pairNumber);
            }

            // Find index of major and minor color from pair number
            int zeroBasedPairNumber = pairNumber - 1;
            int majorIndex          = zeroBasedPairNumber / minorSize;
            int minorIndex          = zeroBasedPairNumber % minorSize;

            // Construct the return val from the arrays
            ColorPairs pair = new ColorPairs()
            {
                majorColor = Program.colorMapMajor[majorIndex],
                minorColor = Program.colorMapMinor[minorIndex]
            };

            // return the value
            return(pair);
        }
示例#2
0
        public override string ToString()
        {
            int    totalCombinations = CopyOfColorMapMajor.Length * CopyOfColorMapMinor.Length;
            String Result            = null;

            for (int pairno = 1; pairno <= totalCombinations; pairno++)
            {
                ColorPairs pair = GetColorFromPairNumbers.GetColorFromPairNumber(pairno);
                Result += "Pair number: " + pairno.ToString() + " " + "Color Pair: " + pair.ToString() + '\n';
            }

            return(Result);
        }
示例#3
0
        private static void Main(string[] args)
        {
            int        pairNumber = 4;
            ColorPairs testPair1  = GetColorFromPairNumbers.GetColorFromPairNumber(pairNumber);

            Console.WriteLine("[In]Pair Number: {0},[Out] Colors: {1}\n", pairNumber, testPair1);
            Debug.Assert(testPair1.majorColor == Color.White);
            Debug.Assert(testPair1.minorColor == Color.Brown);

            pairNumber = 5;
            testPair1  = GetColorFromPairNumbers.GetColorFromPairNumber(pairNumber);
            Console.WriteLine("[In]Pair Number: {0},[Out] Colors: {1}\n", pairNumber, testPair1);
            Debug.Assert(testPair1.majorColor == Color.White);
            Debug.Assert(testPair1.minorColor == Color.SlateGray);

            pairNumber = 23;
            testPair1  = GetColorFromPairNumbers.GetColorFromPairNumber(pairNumber);
            Console.WriteLine("[In]Pair Number: {0},[Out] Colors: {1}\n", pairNumber, testPair1);
            Debug.Assert(testPair1.majorColor == Color.Violet);
            Debug.Assert(testPair1.minorColor == Color.Green);

            ColorPairs testPair2 = new ColorPairs()
            {
                majorColor = Color.Yellow, minorColor = Color.Green
            };

            pairNumber = GetPairNumberFromColors.GetPairNumberFromColor(testPair2);
            Console.WriteLine("[In]Colors: {0}, [Out] PairNumber: {1}\n", testPair2, pairNumber);
            Debug.Assert(pairNumber == 18);

            testPair2 = new ColorPairs()
            {
                majorColor = Color.Red, minorColor = Color.Blue
            };
            pairNumber = GetPairNumberFromColors.GetPairNumberFromColor(testPair2);
            Console.WriteLine("[In]Colors: {0}, [Out] PairNumber: {1}", testPair2, pairNumber);
            Debug.Assert(pairNumber == 6);

            ColorPairMap map = new ColorPairMap();

            Console.WriteLine(map.ToString());
        }
示例#4
0
        public static int GetPairNumberFromColor(ColorPairs pair)
        {
            // Find the major color in the array and get the index
            int majorIndex = -1;

            for (int i = 0; i < Program.colorMapMajor.Length; i++)
            {
                ColorPairs color = new ColorPairs();
                if (Program.colorMapMajor[i] == color.majorColor)
                {
                    majorIndex = i;
                    break;
                }
            }

            // Find the minor color in the array and get the index
            int minorIndex = -1;

            for (int i = 0; i < Program.colorMapMinor.Length; i++)
            {
                ColorPairs color = new ColorPairs();
                if (Program.colorMapMinor[i] == color.minorColor)
                {
                    minorIndex = i;
                    break;
                }
            }
            // If colors can not be found throw an exception
            if (majorIndex == -1 || minorIndex == -1)
            {
                string.Format("Unknown Colors: {0}", pair.ToString());
            }

            // Compute pair number and Return
            // (Note: +1 in compute is because pair number is 1 based, not zero)
            return((majorIndex * Program.colorMapMinor.Length) + (minorIndex + 1));
        }