Anonymous user
Bitmap/Bresenham's line algorithm: Difference between revisions
→{{header|C sharp|C#}}: making more like c version to avoid confusion
(→{{header|C sharp|C#}}: adding using statements) |
(→{{header|C sharp|C#}}: making more like c version to avoid confusion) |
||
Line 618:
.Save("line.png", ImageFormat.Png);
}
static Bitmap DrawLine(this Bitmap
{
int dx = Math.Abs(x1 - x0), sx = x0 < x1 ? 1 : -1;
int dy = Math.Abs(y1 - y0), sy = y0 < y1 ? 1 : -1;
int err = (dx > dy ? dx : -dy) / 2, e2;
e2 = err;
if (e2 > -dx) { err -= dy; x0 += sx; }
if (e2 < dy) { err += dx; y0 += sy; }
}
}
}</lang>
|