Exemplo n.º 1
0
        private void DDA_Line1(Line line)
        {
            int   dY, step, absX, absY;
            float x, y, x_inc, y_inc;
            int   dX = line.getEndPoint().X - line.getStartPoint().Y;

            dY   = line.getEndPoint().Y - line.getStartPoint().Y;
            absX = Math.Abs(dX);
            absY = Math.Abs(dY);
            if (absX > absY)
            {
                step = absX;
            }
            else
            {
                step = absY;
            }
            x_inc = dX / step;
            y_inc = dY / step;
            x     = line.getStartPoint().X;
            y     = line.getStartPoint().Y;
            putpixel(round(line.getStartPoint().X), round(line.getStartPoint().Y), line.getColor());
            step--;
            int k = 1;

            while (step != -1)
            {
                x += x_inc;
                y += y_inc; //
                putpixel(round(x), round(y), line.getColor());
                k++;        //
                step--;     //
            }
        }
Exemplo n.º 2
0
        public void drawLinebyMidPoint(Line line, bool dottedLineFlag = false)
        {
            int x1 = round(line.getStartPoint().X);
            int y1 = round(line.getStartPoint().Y);
            int x2 = round(line.getEndPoint().X);
            int y2 = round(line.getEndPoint().Y);
            int Dx = round(x2 - x1);
            int Dy = round(y2 - y1);
            int x  = round(x1);
            int y  = round(y1);

            putpixel(x1, y1, line.getColor());
            float P     = 2 * Dy - Dx;
            float Q     = 2 * Dx - Dy;
            int   count = 0;

            while (x < x2 || y < y2)
            {
                if (y < y2)
                {
                    y++;
                    if (Q < 0)
                    {
                        Q = Q + 2 * Dx;
                    }
                    else
                    {
                        Q = Q + 2 * (Dx - Dy);
                        x++;
                    }
                }
                else
                {
                    x++;
                    if (P < 0)
                    {
                        P = P + 2 * Dy;
                    }
                    else
                    {
                        P = P + 2 * (Dy - Dx);
                        y++;
                    }
                }
                if (dottedLineFlag == false || (dottedLineFlag == true && count % 10 == 0))
                {
                    putpixel(round(x), round(y), line.getColor());
                }
                count++;
            }
        }
Exemplo n.º 3
0
        public void DDA_Line(Line line) // Ve duong thang co dinh dang mau
        {
            //Line line = (Line)s;
            int Dx, Dy, count, temp_1, temp_2, dem = 1, absX, absY;

            //int temp_3, temp_4;
            Dx   = line.getEndPoint().X - line.getStartPoint().Y;
            Dy   = line.getEndPoint().Y - line.getStartPoint().Y;
            absX = Math.Abs(Dx);
            absY = Math.Abs(Dy);
            if (absY > absX)
            {
                count = absY;
            }
            else
            {
                count = absX;
            }
            float x, y, delta_X, delta_Y;

            if (count > 0)
            {
                delta_X  = Dx;
                delta_X /= count;
                delta_Y  = Dy;
                delta_Y /= count;
                x        = line.getStartPoint().X;
                y        = line.getStartPoint().Y;
                do
                {
                    temp_1 = round(x);
                    temp_2 = round(y);
                    putpixel(temp_1, temp_2, line.getColor());
                    // temp_3 = temp_1;
                    // temp_4 = temp_2;
                    x += delta_X;
                    y += delta_Y;
                    --count;
                    dem++;
                } while (count != -1);
            }
        }
Exemplo n.º 4
0
        public void DDA_Line2(Line line)
        {
            int xInitial = line.getStartPoint().X, yInitial = line.getStartPoint().Y, xFinal = line.getEndPoint().X, yFinal = line.getEndPoint().Y;

            int dx = xFinal - xInitial, dy = yFinal - yInitial, steps, k, xf, yf;

            float xIncrement, yIncrement, x = xInitial, y = yInitial;

            if (Math.Abs(dx) > Math.Abs(dy))
            {
                steps = Math.Abs(dx);
            }

            else
            {
                steps = Math.Abs(dy);
            }
            xIncrement = dx / (float)steps;
            yIncrement = dy / (float)steps;
            //PixelFunc func = new PixelFunc(SetPixel);
            for (k = 0; k < steps; k++)
            {
                x += xIncrement;
                xf = (int)x;
                y += yIncrement;
                yf = (int)y;
                //try
                //{
                //pictureBox1.Invoke(func, xf, yf, Color.Blue);
                putpixel(round(x), round(y), line.getColor());
                //}
                //catch (InvalidOperationException)
                //{
                //    return;
                //}
            }
        }