Exemplo n.º 1
0
 private void put4pitxel(int x, int y, Graphics g)
 {
     ToaDo.putpixel(new Point(tam.X + x, tam.Y + y), g, this.mau);
     ToaDo.putpixel(new Point(tam.X - x, tam.Y + y), g, this.mau);
     ToaDo.putpixel(new Point(tam.X - x, tam.Y - y), g, this.mau);
     ToaDo.putpixel(new Point(tam.X + x, tam.Y - y), g, this.mau);
 }
Exemplo n.º 2
0
 public int netdut(Point p, Graphics g, Color c, int length)
 {
     if (length % 7 >= 0 && length % 7 < 5)
     {
         ToaDo.putpixel(p, g, this.mau);
     }
     length++;
     return(length);
 }
Exemplo n.º 3
0
 public void Drawn8Point(int x, int y, Graphics g, Color color)
 {
     ToaDo.putpixel(new Point(x + tam.X, y + tam.Y), g, color);
     ToaDo.putpixel(new Point(y + tam.X, x + tam.Y), g, color);
     ToaDo.putpixel(new Point(-x + tam.X, -y + tam.Y), g, color);
     ToaDo.putpixel(new Point(-y + tam.X, -x + tam.Y), g, color);
     ToaDo.putpixel(new Point(-x + tam.X, y + tam.Y), g, color);
     ToaDo.putpixel(new Point(-y + tam.X, x + tam.Y), g, color);
     ToaDo.putpixel(new Point(x + tam.X, -y + tam.Y), g, color);
     ToaDo.putpixel(new Point(y + tam.X, -x + tam.Y), g, color);
 }
Exemplo n.º 4
0
        public void vedthang(Graphics g)
        {
            //Này xài thuật toán Breshenhem nha
            int   x, y;
            float p;
            float c2 = 0;
            float c  = 0;

            int x1 = this.diemdau.X;
            int y1 = this.diemdau.Y;
            int x2 = this.diemcuoi.X;
            int y2 = this.diemcuoi.Y;


            float Dx = Math.Abs(x2 - x1);
            float Dy = Math.Abs(y2 - y1);

            c  = Dx - Dy;
            c2 = 2 * c;
            x  = x1;
            p  = 2 * Dy - Dx;
            y  = y1;

            int x_unit = 5, y_unit = 5;

            if (x2 - x1 < 0)
            {
                x_unit = -x_unit;
            }
            if (y2 - y1 < 0)
            {
                y_unit = -y_unit;
            }
            ToaDo.putpixel(new Point(x, y), g, this.mau);
            if (x1 == x2)   // duong thang dung
            {
                while (y != y2)
                {
                    y += y_unit;
                    ToaDo.putpixel(new Point(x, y), g, this.mau);
                }
            }

            else if (y1 == y2)  // duong ngang
            {
                while (x != x2)
                {
                    x += x_unit;
                    ToaDo.putpixel(new Point(x, y), g, this.mau);
                }
            }

            else if (x1 != x2 && y1 != y2)  // duong xien
            {
                if ((Math.Abs(y2 - y1)) <= 25)
                {
                    while (x != x2)
                    {
                        if (p < 0)
                        {
                            p += 2 * Dy;
                        }
                        else
                        {
                            p += 2 * (Dy - Dx);
                            y += y_unit;
                        }
                        x += x_unit;
                        ToaDo.putpixel(new Point(x, y), g, this.mau);
                    }
                }
                else
                {
                    if (x2 >= x1)
                    {
                        // var sign=5;
                        // (y2>y1)? sign=5:sign=-5;
                        while (!(x == x2 + 5 || y == y2))
                        {
                            c2 = 2 * c;
                            if (c2 > -Dy)
                            {
                                c = c - Dy;
                                x = x + x_unit;
                            }
                            if (c2 < Dx)
                            {
                                c = c + Dx;
                                y = y + y_unit;
                            }
                            ToaDo.putpixel(new Point(x, y), g, this.mau);
                        }
                    }
                    if (x2 < x1)
                    {
                        // var sign=5;
                        // (y2>y1)? sign=+5:sign=-5;
                        while (!(x == x2 - 5 || y == y2))
                        {
                            c2 = 2 * c;
                            if (c2 > -Dy)
                            {
                                c = c - Dy;
                                x = x + x_unit;
                            }
                            if (c2 < Dx)
                            {
                                c = c + Dx;
                                y = y + y_unit;
                            }
                            ToaDo.putpixel(new Point(x, y), g, this.mau);
                        }
                    }
                }
            }
        }
Exemplo n.º 5
0
        public void veelip(Graphics g)
        {
            //code ve elip
            //Elip su dung thuat toan midpoint
            int x, y, cx, cy;

            cx = tam.X; cy = tam.Y;
            x  = 0; y = this.b;
            int A, B;

            A = a * a;
            B = b * b;
            double p = B + A / 4 - A * b;

            x = 0;
            y = b;
            int Dx = 0;
            int Dy = 2 * A * y;

            put4pitxel(x, y, g);

            while (Dx < Dy)
            {
                x++;
                Dx += 2 * B;
                if (p < 0)
                {
                    p += B + Dx;
                }
                else
                {
                    y--;
                    Dy -= 2 * A;
                    p  += B + Dx - Dy;
                }
                if (x % 5 == 0)
                {
                    put4pitxel(x, ToaDo.round(y), g);
                }
            }
            p = Math.Round(B * (x + 0.5f) * (x + 0.5f) + A * (y - 1) * (y - 1) - A * B);
            while (y > 0)
            {
                y--;
                Dy -= A * 2;
                if (p > 0)
                {
                    p += A - Dy;
                }
                else
                {
                    x++;
                    Dx += B * 2;
                    p  += A - Dy + Dx;
                }
                if (x % 5 == 0)
                {
                    put4pitxel(x, ToaDo.round(y), g);
                }
            }
        }
Exemplo n.º 6
0
        public void venetdut_elip(Graphics g)
        {
            int x, y, cx, cy, a, b;

            cx = this.tam.X;
            cy = this.tam.Y;
            a  = this.a;
            b  = this.b;
            x  = 0;
            y  = b;
            int A, B;

            A = a * a;
            B = b * b;
            double p = B + A / 4 - A * b;

            x = 0;
            y = b;
            int Dx = 0;
            int Dy = 2 * A * y;

            put4pitxel_3D(x, y, g);

            while (Dx <= Dy)
            {
                x  += 1;
                Dx += 2 * B;
                if (p < 0)
                {
                    p += B + Dx;
                }
                else
                {
                    y  -= 1;
                    Dy -= 2 * A;
                    p  += B + Dx - Dy;
                }
                if (x % 5 == 0)
                {
                    put4pitxel_3D(x, ToaDo.round(y), g);
                }
            }
            p = Math.Round(B * (x + 0.5f) * (x + 0.5f) + A * (y - 1) * (y - 1) - A * B);
            while (y >= 0)
            {
                y  -= 1;
                Dy -= A * 2;
                if (p > 0)
                {
                    p += A - Dy;
                }
                else
                {
                    x  += 1;
                    Dx += B * 2;
                    p  += A - Dy + Dx;
                }
                if (x % 5 == 0)
                {
                    put4pitxel_3D(x, ToaDo.round(y), g);
                }
            }
        }