Ejemplo n.º 1
0
        //Method to find the approximate color
        public async Task <string> getClosestColor()
        {
            //Create an object to store the raw color data
            RgbData rgbData = await getRgbData();

            //Create a variable to store the closest color. Black by default.
            KnownColor closestColor = colorList[7];
            //Create a variable to store the minimum Euclidean distance between 2 colors
            double minDiff = double.MaxValue;

            //For every known color, check the Euclidean distance and store the minimum distance
            foreach (var color in colorList)
            {
                Color  colorValue = color.colorValue;
                double diff       = Math.Pow((colorValue.R - rgbData.Red), 2) +
                                    Math.Pow((colorValue.G - rgbData.Green), 2) +
                                    Math.Pow((colorValue.B - rgbData.Blue), 2);
                diff = (int)Math.Sqrt(diff);
                if (diff < minDiff)
                {
                    minDiff      = diff;
                    closestColor = color;
                }
            }
            //Write the approximate color to the debug console
            Debug.WriteLine("Approximate color: " + closestColor.colorName + " - "
                            + closestColor.colorValue.ToString());

            //Return the approximate color
            return(closestColor.colorName);
        }
Ejemplo n.º 2
0
        //Method to read the RGB data
        public async Task <RgbData> getRgbData()
        {
            //Create an object to store the raw color data
            RgbData rgbData = new RgbData();

            //First get the raw color data


            //Check if clear data is received


            //Write the RGB values to the debug console


            //Return the data
            return(rgbData);
        }
Ejemplo n.º 3
0
        //Method to read the RGB data
        public async Task <RgbData> getRgbData()
        {
            //Create an object to store the raw color data
            RgbData rgbData = new RgbData();

            //First get the raw color data
            ColorData colorData = await getRawData();

            //Check if clear data is received
            if (colorData.Clear > 0)
            {
                //Find the RGB values from the raw data using the clear data as reference
                rgbData.Red   = (colorData.Red * 255 / colorData.Clear);
                rgbData.Blue  = (colorData.Blue * 255 / colorData.Clear);
                rgbData.Green = (colorData.Green * 255 / colorData.Clear);
            }
            //Write the RGB values to the debug console
            Debug.WriteLine("RGB Data - red: {0}, green: {1}, blue: {2}", rgbData.Red, rgbData.Green, rgbData.Blue);

            //Return the data
            return(rgbData);
        }
Ejemplo n.º 4
0
        //Method to read the RGB data
        public async Task<RgbData> getRgbData()
        {
            //Create an object to store the raw color data
            RgbData rgbData = new RgbData();

            //First get the raw color data
            

            //Check if clear data is received


            //Write the RGB values to the debug console
            

            //Return the data
            return rgbData;
        }
Ejemplo n.º 5
0
        //Method to read the RGB data
        public async Task<RgbData> getRgbData()
        {
            //Create an object to store the raw color data
            RgbData rgbData = new RgbData();

            //First get the raw color data
            ColorData colorData = await getRawData();
            //Check if clear data is received
            if (colorData.Clear > 0)
            {
                //Find the RGB values from the raw data using the clear data as reference
                rgbData.Red = (colorData.Red * 255 / colorData.Clear);
                rgbData.Blue = (colorData.Blue * 255 / colorData.Clear);
                rgbData.Green = (colorData.Green * 255 / colorData.Clear);
            }
            //Write the RGB values to the debug console
            Debug.WriteLine("RGB Data - red: {0}, green: {1}, blue: {2}", rgbData.Red, rgbData.Green, rgbData.Blue);

            //Return the data
            return rgbData;
        }