Guest User

Untitled

a guest
Apr 22nd, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.10 KB | None | 0 0
  1. void pixtoline(int x, int y)
  2.         {
  3.             int xabs = Math.Abs( lastX-x);
  4.             int yabs = Math.Abs(lastY-y);
  5.             if (xabs > yabs)
  6.             {
  7.                 double d = (double)(yabs / xabs);
  8.                 int j = 0;
  9.                 for (int i = 1; i < yabs; i++)
  10.                 {
  11.                     j += (int)d;
  12.                     if (lastX-x>0 & lastY-y>0)
  13.                         mainpoint.Add(new Point(lastX+i,lastY+(int)Math.Floor((decimal)j)));
  14.                     else if(lastX-x>0)
  15.                         mainpoint.Add(new Point(lastX + i, lastY - (int)Math.Floor((decimal)j)));
  16.                     else if(lastY-y>0)
  17.                         mainpoint.Add(new Point(lastX - i, lastY + (int)Math.Floor((decimal)j)));
  18.                     else
  19.                         mainpoint.Add(new Point(lastX - i, lastY - (int)Math.Floor((decimal)j)));
  20.                     if (mainpoint.Count > 0)
  21.                         painter.DrawEllipse(new Pen(Color.Blue), mainpoint[mainpoint.Count - 1].X, mainpoint[mainpoint.Count - 1].Y, 1, 1);
  22.                 }
  23.             }
  24.             else
  25.             {
  26.                 double d = (double)(xabs / yabs);
  27.                 int j = 0;
  28.                 for (int i = 1; i < xabs; i++)
  29.                 {
  30.                     j += (int)d;
  31.                     if (x - lastX > 0 & y - lastY > 0)
  32.                         mainpoint.Add(new Point(lastX + (int)Math.Floor((decimal)j), lastY + i));
  33.                     else if (x - lastX > 0)
  34.                         mainpoint.Add(new Point(lastX + (int)Math.Floor((decimal)j), lastY - i));
  35.                     else if (y - lastY >= 0)
  36.                         mainpoint.Add(new Point(lastX - (int)Math.Floor((decimal)j), lastY+ i));
  37.                     else
  38.                         mainpoint.Add(new Point(lastX - (int)Math.Floor((decimal)j), lastY - i));
  39.                     if (mainpoint.Count > 0)
  40.                         painter.DrawEllipse(new Pen(Color.Blue), mainpoint[mainpoint.Count - 1].X, mainpoint[mainpoint.Count - 1].Y, 5, 5);
  41.                    
  42.                 }
  43.             }
  44.         }
Add Comment
Please, Sign In to add comment