Advertisement
Cookie042

drawLine

Apr 7th, 2019
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.56 KB | None | 0 0
  1.        private void DrawLine(int x0, int y0, int x1, int y1, Color color)
  2.         {
  3.             int dx = Mathf.Abs(x1 - x0), sx = x0 < x1 ? 1 : -1;
  4.             int dy = Mathf.Abs(y1 - y0), sy = y0 < y1 ? 1 : -1;
  5.             int err = (dx > dy ? dx : -dy) / 2, e2;
  6.             for (; ; )
  7.             {
  8.                 colors[x0 + y0 * textureSize] = color;
  9.                 if (x0 == x1 && y0 == y1) break;
  10.                 e2 = err;
  11.                 if (e2 > -dx) { err -= dy; x0 += sx; }
  12.                 if (e2 < dy) { err += dx; y0 += sy; }
  13.             }
  14.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement