示例#1
0
        private void swapColorBoxes(int index1, int index2)
        {
            // avoid unnecessary work
            if (index1 == index2)
            {
                return;
            }

            // make sure indices are valid
            if (index1 < 0 || index2 < 0 || index1 > colorBoxes.Length || index2 > colorBoxes.Length)
            {
                return;
            }

            // avoid swapping non-movable boxes
            if (!colorBoxes[index1].movable || !colorBoxes[index2].movable)
            {
                return;
            }

            // swap that shit
            colorBox c = colorBoxes[index1];

            colorBoxes[index1] = colorBoxes[index2];
            colorBoxes[index2] = c;
        }
示例#2
0
        private void initializeColorBoxes()
        {
            selectedBox = -1;

            colorBoxes = new colorBox[rows * cols];


            for (int x = 0; x < cols; x++)
            {
                for (int y = 0; y < rows; y++)
                {
                    int r1 = (cols - x - 1) * colorTopLeft.R / (cols - 1) + x * colorTopRight.R / (cols - 1);
                    int r2 = (cols - x - 1) * colorBottomLeft.R / (cols - 1) + x * colorBottomRight.R / (cols - 1);
                    int r  = (rows - y - 1) * r1 / (rows - 1) + (y * r2) / (rows - 1);

                    int g1 = (cols - x - 1) * colorTopLeft.G / (cols - 1) + x * colorTopRight.G / (cols - 1);
                    int g2 = (cols - x - 1) * colorBottomLeft.G / (cols - 1) + x * colorBottomRight.G / (cols - 1);
                    int g  = (rows - y - 1) * g1 / (rows - 1) + (y * g2) / (rows - 1);

                    int b1 = (cols - x - 1) * colorTopLeft.B / (cols - 1) + x * colorTopRight.B / (cols - 1);
                    int b2 = (cols - x - 1) * colorBottomLeft.B / (cols - 1) + x * colorBottomRight.B / (cols - 1);
                    int b  = (rows - y - 1) * b1 / (rows - 1) + (y * b2) / (rows - 1);

                    if (y * cols + x == selectedBox)
                    {
                        r = b = g = 0;
                    }

                    int  index   = y * cols + x;
                    bool movable = (x != 0 && x != cols - 1) || (y != 0 && y != rows - 1);

                    colorBoxes[index] = new colorBox(Color.FromArgb(r, g, b), movable, index);
                }
            }
        }
示例#3
0
 public Form1()
 {
     InitializeComponent();
     label1.Text = trackBar1.Value.ToString();
     label2.Text = trackBar2.Value.ToString();
     label3.Text = trackBar3.Value.ToString();
     box         = new colorBox(trackBar1.Value, trackBar2.Value, trackBar3.Value, panel1);
 }
示例#4
0
        private void initializeColorBoxes()
        {
            // create color list for corners
            colorList = new Color[] {
                Color.FromArgb(0xFF, 0x00, 0x00),
                Color.FromArgb(0x00, 0xFF, 0x00),
                Color.FromArgb(0x00, 0x00, 0xFF),
                Color.FromArgb(0x00, 0xFF, 0xFF),
                Color.FromArgb(0xFF, 0xFF, 0x00),
                Color.FromArgb(0xFF, 0x00, 0xFF)
            };

            colorList = randomize <Color>(colorList);

            Color colorTopLeft     = colorList[0];
            Color colorTopRight    = colorList[1];
            Color colorBottomLeft  = colorList[2];
            Color colorBottomRight = colorList[3];


            // create color boxes
            selectedBox = -1;

            colorBoxes = new colorBox[rows * cols];


            for (int x = 0; x < cols; x++)
            {
                for (int y = 0; y < rows; y++)
                {
                    int r1 = (cols - x - 1) * colorTopLeft.R / (cols - 1) + x * colorTopRight.R / (cols - 1);
                    int r2 = (cols - x - 1) * colorBottomLeft.R / (cols - 1) + x * colorBottomRight.R / (cols - 1);
                    int r  = (rows - y - 1) * r1 / (rows - 1) + (y * r2) / (rows - 1);

                    int g1 = (cols - x - 1) * colorTopLeft.G / (cols - 1) + x * colorTopRight.G / (cols - 1);
                    int g2 = (cols - x - 1) * colorBottomLeft.G / (cols - 1) + x * colorBottomRight.G / (cols - 1);
                    int g  = (rows - y - 1) * g1 / (rows - 1) + (y * g2) / (rows - 1);

                    int b1 = (cols - x - 1) * colorTopLeft.B / (cols - 1) + x * colorTopRight.B / (cols - 1);
                    int b2 = (cols - x - 1) * colorBottomLeft.B / (cols - 1) + x * colorBottomRight.B / (cols - 1);
                    int b  = (rows - y - 1) * b1 / (rows - 1) + (y * b2) / (rows - 1);

                    if (y * cols + x == selectedBox)
                    {
                        r = b = g = 0;
                    }

                    int  index   = y * cols + x;
                    bool movable = (x != 0 && x != cols - 1) || (y != 0 && y != rows - 1);

                    colorBoxes[index] = new colorBox(Color.FromArgb(r, g, b), movable, index);
                }
            }
        }