Example #1
0
        public static int GetPairNumberFromColor(Colors.ColorPair pair)

        {
            // Find the major color in the array and get the index

            int majorIndex = -1;

            for (int i = 0; i < Colors.colorMapMajor.Length; i++)

            {
                if (Colors.colorMapMajor[i] == pair.majorColor)

                {
                    majorIndex = i;

                    break;
                }
            }



            // Find the minor color in the array and get the index

            int minorIndex = -1;

            for (int i = 0; i < Colors.colorMapMinor.Length; i++)

            {
                if (Colors.colorMapMinor[i] == pair.minorColor)

                {
                    minorIndex = i;

                    break;
                }
            }

            // If colors can not be found throw an exception

            if (majorIndex == -1 || minorIndex == -1)

            {
                throw new ArgumentException(

                          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 * Colors.colorMapMinor.Length) + (minorIndex + 1));
        }
Example #2
0
        public static void Tostring()
        {
            int number = 0;

            for (int i = 1; i < Colors.colorMapMinor.Length; i++)
            {
                for (int j = 1; j < Colors.colorMapMinor.Length; j++)
                {
                    Console.Write("[In]Pair Number: {0}", ++number);
                    Colors.ColorPair testPairs = new Colors.ColorPair()
                    {
                        majorColor = Colors.colorMapMajor[i], minorColor = Colors.colorMapMinor[j]
                    };
                    Console.WriteLine("[Out] Colors: {0}\n", testPairs);
                }
            }
        }
        public static Colors.ColorPair GetColorFromPairNumber(int pairNumber)

        {
            // The function supports only 1 based index. Pair numbers valid are from 1 to 25

            int minorSize = Colors.colorMapMinor.Length;

            int majorSize = Colors.colorMapMajor.Length;

            if (pairNumber < 1 || pairNumber > minorSize * majorSize)

            {
                throw new ArgumentOutOfRangeException(

                          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

            Colors.ColorPair pair = new Colors.ColorPair()
            {
                majorColor = Colors.colorMapMajor[majorIndex],

                minorColor = Colors.colorMapMinor[minorIndex]
            };



            // return the value

            return(pair);
        }
Example #4
0
        private static void Main(string[] args)

        {
            int pairNumber = 3;

            Colors.ColorPair testPair1 = ColorFromPairNumber.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.Green);



            pairNumber = 5;

            testPair1 = ColorFromPairNumber.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 = ColorFromPairNumber.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);



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

            pairNumber = PairNumberFromColor.GetPairNumberFromColor(testPair2);

            Console.WriteLine("[In]Colors: {0}, [Out] PairNumber: {1}\n", testPair2, pairNumber);

            Debug.Assert(pairNumber == 18);



            testPair2 = new Colors.ColorPair()
            {
                majorColor = Color.Red, minorColor = Color.Blue
            };

            pairNumber = PairNumberFromColor.GetPairNumberFromColor(testPair2);

            Console.WriteLine("[In]Colors: {0}, [Out] PairNumber: {1}", testPair2, pairNumber);

            Debug.Assert(pairNumber == 6);

            manual.Tostring();
        }