Esempio n. 1
0
        private void calcMovementUpDown()
        {
            imgToArray();
            BlackLines.Clear();

            bool lineStarted = false;
            int  x0 = 0, y0 = 0;
            bool goingDown = true;

            for (int x = 0; x < pxArrayWidth; x++)
            {
                for (int i = 0; i < pxArrayHeight - 1; i++)
                {
                    int y;
                    if (goingDown)
                    {
                        y = i;
                    }
                    else
                    {
                        y = pxArrayHeight - 1 - i;
                    }

                    if (!lineStarted && pixelArray[x, y]) //if this is the first black pixel in a new line
                    {
                        x0          = x;                  //saves coordinates for start of new line
                        y0          = y;
                        lineStarted = true;
                    }

                    int endY = y;
                    if (lineStarted)
                    {
                        if (goingDown && (!pixelArray[x, y + 1] || y >= pxArrayHeight - 2)) //next downward pixel is white OR current array location is beyond pixel height
                        {
                            if (pixelArray[x, y + 1])                                       //check the very last pixel as well
                            {
                                endY = y + 1;
                            }
                            lineStarted = false;                                                                                                                                                      //start a new line
                            BlackLines.Add(new TraceLine((x0 * ratioWidthToPx) + ImgMoveX, (y0 * ratioHeightToPx) + ImgMoveY, (x * ratioWidthToPx) + ImgMoveX, (endY * ratioHeightToPx) + ImgMoveY)); //saves coordinates of last pixel in the line
                        }
                        if (!goingDown && (!pixelArray[x, y - 1] || y <= 1))
                        {
                            if (pixelArray[x, y - 1]) //check the very last pixel as well
                            {
                                endY = y - 1;         //endY = y + 1;
                            }
                            lineStarted = false;
                            BlackLines.Add(new TraceLine((x0 * ratioWidthToPx) + ImgMoveX, (y0 * ratioHeightToPx) + ImgMoveY, (x * ratioWidthToPx) + ImgMoveX, (endY * ratioHeightToPx) + ImgMoveY));      //saves coordinates of last pixel in the line
                        }
                    }
                }
                goingDown = !goingDown;
            } //for x
        }
Esempio n. 2
0
        private void calcMovementSideToSide()
        {
            imgToArray();
            BlackLines.Clear();

            bool lineStarted = false;
            int  x0 = 0, y0 = 0;
            bool leftToRight = true;

            for (int y = 0; y < pxArrayHeight; y++)
            {
                for (int i = 0; i < pxArrayWidth - 1; i++)
                {
                    int x;
                    if (leftToRight)
                    {
                        x = i;
                    }
                    else
                    {
                        x = pxArrayWidth - 1 - i;
                    }

                    if (!lineStarted && pixelArray[x, y]) //if this is the first black pixel in a new line
                    {
                        x0          = x;                  //saves coordinates for start of new line
                        y0          = y;
                        lineStarted = true;
                    }

                    int endX = x;
                    if (lineStarted)
                    {
                        if (leftToRight && (!pixelArray[x + 1, y] || x >= pxArrayWidth - 2))
                        {
                            if (pixelArray[x + 1, y])    //check the very last pixel as well
                            {
                                endX = x + 1;
                            }
                            lineStarted = false;                                                                                                                                                      //start a new line
                            BlackLines.Add(new TraceLine((x0 * ratioWidthToPx) + ImgMoveX, (y0 * ratioHeightToPx) + ImgMoveY, (endX * ratioWidthToPx) + ImgMoveX, (y * ratioHeightToPx) + ImgMoveY)); //saves coordinates of last pixel in the line
                        }
                        if (!leftToRight && (!pixelArray[x - 1, y] || x <= 1))
                        {
                            if (pixelArray[x - 1, y])    //check the very last pixel as well
                            {
                                endX = x + 1;
                            }
                            lineStarted = false;
                            BlackLines.Add(new TraceLine((x0 * ratioWidthToPx) + ImgMoveX, (y0 * ratioHeightToPx) + ImgMoveY, (endX * ratioWidthToPx) + ImgMoveX, (y * ratioHeightToPx) + ImgMoveY));      //saves coordinates of last pixel in the line
                        }
                    }
                }
                leftToRight = !leftToRight;
            } //for y
        }