FizVizController/FizVizController/Views/BackgroundColorConfig.xaml.cs
/// <summary>
/// Generate an array of background colors that are a blend betwen the
/// user specified colors, at the specified angles
/// </summary>
/// <param name="colors"></param>
/// <returns></returns>
Generate an array of background colors that are a blend betwen the
user specified colors, at the specified angles
Generate an array of background colors that are a blend betwen the user specified colors at the specified angles
private bool GetBlend(IList<Color> colors)
        {
            double angle1, angle2, angle3;
            int color1Pixel, color2Pixel, color3Pixel;
            if (Color1ComboBox_Gradient.SelectedValue == null)
            {
                Color1ComboBox_Gradient.BorderBrush = new SolidColorBrush(Colors.Red);
                return false;
            }
            if (Color2ComboBox.SelectedValue == null)
            {
                Color2ComboBox.BorderBrush = new SolidColorBrush(Colors.Red);
                return false;
            }
            if (Color3ComboBox.SelectedValue == null)
            {
                Color3ComboBox.BorderBrush = new SolidColorBrush(Colors.Red);
                return false;
            }
            if (!ReadAngle(Angle1TextBox, out angle1))
                return false;
            if (!ReadAngle(Angle2TextBox, out angle2))
                return false;
            if (!ReadAngle(Angle3TextBox, out angle3))
                return false;
            if (angle1 >= angle2)
            {
                Angle1TextBox.BorderBrush = new SolidColorBrush(Colors.Red);
                Angle2TextBox.BorderBrush = new SolidColorBrush(Colors.Red);
                return false;
            }
            if (angle2 >= angle3)
            {
                Angle2TextBox.BorderBrush = new SolidColorBrush(Colors.Red);
                Angle3TextBox.BorderBrush = new SolidColorBrush(Colors.Red);
                return false;
            }
            color1Pixel = PixelForAngle(angle1);
            color2Pixel = PixelForAngle(angle2);
            color3Pixel = PixelForAngle(angle3);
            if (color3Pixel == 0)
            {
                color3Pixel = BackgroundColor.NEOPIXEL_COUNT - 1;
            }
            Color color1 = (Color) Color1ComboBox_Gradient.SelectedValue;
            Color color2 = (Color) Color2ComboBox.SelectedValue;
            Color color3 = (Color) Color3ComboBox.SelectedValue;
            int diffSize = color2Pixel - color1Pixel;
            for (int i = 0; i < diffSize; i++)
            {
                colors[color1Pixel + i] = Blend(i, diffSize, color1, color2);
            }
            diffSize = color3Pixel - color2Pixel;
            for (int i = 0; i < diffSize; i++)
            {
                colors[color2Pixel + i] = Blend(i, diffSize, color2, color3);
            }
            colors[color3Pixel] = color3;
            return true;
        }
private bool GetBlend ( IList < Color > colors ) { double angle1 , angle2 , angle3 ; int color1Pixel , color2Pixel , color3Pixel ; if ( Color1ComboBox_Gradient . SelectedValue == null ) { Color1ComboBox_Gradient . BorderBrush = new SolidColorBrush ( Colors . Red ) ; return false ; } if ( Color2ComboBox . SelectedValue == null ) { Color2ComboBox . BorderBrush = new SolidColorBrush ( Colors . Red ) ; return false ; } if ( Color3ComboBox . SelectedValue == null ) { Color3ComboBox . BorderBrush = new SolidColorBrush ( Colors . Red ) ; return false ; } if ( ! ReadAngle ( Angle1TextBox , out angle1 ) ) return false ; if ( ! ReadAngle ( Angle2TextBox , out angle2 ) ) return false ; if ( ! ReadAngle ( Angle3TextBox , out angle3 ) ) return false ; if ( angle1 >= angle2 ) { Angle1TextBox . BorderBrush = new SolidColorBrush ( Colors . Red ) ; Angle2TextBox . BorderBrush = new SolidColorBrush ( Colors . Red ) ; return false ; } if ( angle2 >= angle3 ) { Angle2TextBox . BorderBrush = new SolidColorBrush ( Colors . Red ) ; Angle3TextBox . BorderBrush = new SolidColorBrush ( Colors . Red ) ; return false ; } color1Pixel = PixelForAngle ( angle1 ) ; color2Pixel = PixelForAngle ( angle2 ) ; color3Pixel = PixelForAngle ( angle3 ) ; if ( color3Pixel == 0 ) { color3Pixel = BackgroundColor . NEOPIXEL_COUNT - 1 ; } Color color1 = ( Color ) Color1ComboBox_Gradient . SelectedValue ; Color color2 = ( Color ) Color2ComboBox . SelectedValue ; Color color3 = ( Color ) Color3ComboBox . SelectedValue ; int diffSize = color2Pixel - color1Pixel ; for ( int i = 0 ; i < diffSize ; i ++ ) { colors [ color1Pixel + i ] = Blend ( i , diffSize , color1 , color2 ) ; } diffSize = color3Pixel - color2Pixel ; for ( int i = 0 ; i < diffSize ; i ++ ) { colors [ color2Pixel + i ] = Blend ( i , diffSize , color2 , color3 ) ; } colors [ color3Pixel ] = color3 ; return true ; }
Generate an array of background colors that are a blend betwen the
user specified colors, at the specified angles
Generate an array of background colors that are a blend betwen the user specified colors at the specified angles
None
colors
IList<Color>
None