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; } } } }
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); }