Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void pixtoline(int x, int y)
- {
- int xabs = Math.Abs( lastX-x);
- int yabs = Math.Abs(lastY-y);
- if (xabs > yabs)
- {
- double d = (double)(yabs / xabs);
- int j = 0;
- for (int i = 1; i < yabs; i++)
- {
- j += (int)d;
- if (lastX-x>0 & lastY-y>0)
- mainpoint.Add(new Point(lastX+i,lastY+(int)Math.Floor((decimal)j)));
- else if(lastX-x>0)
- mainpoint.Add(new Point(lastX + i, lastY - (int)Math.Floor((decimal)j)));
- else if(lastY-y>0)
- mainpoint.Add(new Point(lastX - i, lastY + (int)Math.Floor((decimal)j)));
- else
- mainpoint.Add(new Point(lastX - i, lastY - (int)Math.Floor((decimal)j)));
- if (mainpoint.Count > 0)
- painter.DrawEllipse(new Pen(Color.Blue), mainpoint[mainpoint.Count - 1].X, mainpoint[mainpoint.Count - 1].Y, 1, 1);
- }
- }
- else
- {
- double d = (double)(xabs / yabs);
- int j = 0;
- for (int i = 1; i < xabs; i++)
- {
- j += (int)d;
- if (x - lastX > 0 & y - lastY > 0)
- mainpoint.Add(new Point(lastX + (int)Math.Floor((decimal)j), lastY + i));
- else if (x - lastX > 0)
- mainpoint.Add(new Point(lastX + (int)Math.Floor((decimal)j), lastY - i));
- else if (y - lastY >= 0)
- mainpoint.Add(new Point(lastX - (int)Math.Floor((decimal)j), lastY+ i));
- else
- mainpoint.Add(new Point(lastX - (int)Math.Floor((decimal)j), lastY - i));
- if (mainpoint.Count > 0)
- painter.DrawEllipse(new Pen(Color.Blue), mainpoint[mainpoint.Count - 1].X, mainpoint[mainpoint.Count - 1].Y, 5, 5);
- }
- }
- }
Add Comment
Please, Sign In to add comment