Exemplo n.º 1
0
        private void picBox_MouseMove(object sender, MouseEventArgs e)
        {
            if (picBox.Image != null)
            {
                toolTip.SetToolTip(picBox, "X:" + e.X + " Y:" + e.Y);
            }
            if (polyflag == true && polyfirst == false)
            {
                picBox.Image = DrawLine.DDA((Bitmap)img, point.X, point.Y, e.X, e.Y, Color.Black);
            }
            else
            {
                if (flag == true && picBox.Image != null && polyflag == false)
                {
                    switch (this.Active)
                    {
                    case "Equação Real da Reta":
                        picBox.Image = DrawLine.RealLine((Bitmap)img, point.X, point.Y, e.X, e.Y, Color.Black);
                        break;

                    case "DDA":
                        picBox.Image = DrawLine.DDA((Bitmap)img, point.X, point.Y, e.X, e.Y, Color.Black);
                        break;

                    case "Bresenham":
                        picBox.Image = DrawLine.Bresenham((Bitmap)img, point.X, point.Y, e.X, e.Y, Color.Black);
                        break;

                    case "Trigonometria":
                        picBox.Image = DrawCircle.Trigonometry((Bitmap)img, point.X, point.Y, e.X, e.Y, Color.Black);
                        break;

                    case "Ponto Médio":
                        picBox.Image = DrawCircle.Midpoint((Bitmap)img, point.X, point.Y, e.X, e.Y, Color.Black);
                        break;

                    case "Ponto Médio Elipse":
                        picBox.Image = DrawEllipse.Midpoint((Bitmap)img, point.X, point.Y, e.X, e.Y, Color.Black);
                        break;

                    default:
                        picBox.Image = DrawCircle.RealCircle((Bitmap)img, point.X, point.Y, e.X, e.Y, Color.Black);
                        break;
                    }
                }
            }
        }
Exemplo n.º 2
0
 private void picBox_MouseDown(object sender, MouseEventArgs e)
 {
     if (e.Button == MouseButtons.Right)
     {
         img          = poly.ReDraw((Bitmap)img, Color.Black);
         picBox.Image = img;
         polys.Add(poly);
         polist.Items.Add(poly);
         Polygon p = poly.GetClone();
         VP             = p.ViewPort(VP, Color.Black, img.Width, img.Height, VP.Width, VP.Height);
         ViewPort.Image = VP;
         VPs.Add(p);
         polyflag  = false;
         polyfirst = true;
     }
     else
     {
         if (polyflag)
         {
             if (polyfirst)
             {
                 polyfirst = !polyfirst;
                 poly      = new Polygon();
                 poly.AddVertice(e.X, e.Y);
                 point = new Point(e.X, e.Y);
             }
             else
             {
                 img          = DrawLine.DDA((Bitmap)img, point.X, point.Y, e.X, e.Y, Color.Black);
                 picBox.Image = img;
                 poly.AddVertice(e.X, e.Y);
                 point = new Point(e.X, e.Y);
             }
         }
         else
         {
             if (flag == false && polyflag == false)
             {
                 point = new Point(e.X, e.Y);
                 flag  = true;
             }
         }
     }
 }
Exemplo n.º 3
0
        public static Bitmap Bresenham(Bitmap img, int x1, int y1, int x2, int y2, Color cor)
        {
            Bitmap btm = new Bitmap(img);
            int    declive;
            int    dx, dy, incE, incNE, d, x, y;

            dx = x2 - x1;
            dy = y2 - y1;
            if (Math.Abs(dx) > Math.Abs(dy))
            {
                if (x1 > x2)
                {
                    btm = DrawLine.Bresenham(btm, x2, y2, x1, y1, cor);
                }
                else
                {
                    if (dy < 0)
                    {
                        declive = -1;
                        dy      = -dy;
                    }
                    else
                    {
                        declive = 1;
                    }
                    incE  = 2 * dy;
                    incNE = 2 * dy - 2 * dx;
                    d     = 2 * dy - dx;
                    y     = y1;
                    for (x = x1; x <= x2; x++)
                    {
                        Paint.Draw(btm, x, y, cor);
                        if (d <= 0)
                        {
                            d += incE;
                        }
                        else
                        {
                            d += incNE;
                            y += declive;
                        }
                    }
                }
            }
            else
            {
                if (y1 > y2)
                {
                    btm = DrawLine.Bresenham(btm, x2, y2, x1, y1, cor);
                }
                else
                {
                    if (dx < 0)
                    {
                        declive = -1;
                        dx      = -dx;
                    }
                    else
                    {
                        declive = 1;
                    }
                    incE  = 2 * dx;
                    incNE = 2 * dx - 2 * dy;
                    d     = 2 * dx - dy;
                    x     = x1;
                    for (y = y1; y <= y2; y++)
                    {
                        Paint.Draw(btm, x, y, cor);
                        if (d <= 0)
                        {
                            d += incE;
                        }
                        else
                        {
                            d += incNE;
                            x += declive;
                        }
                    }
                }
            }
            return(btm);
        }