Bresenham算法画线程序源代码
时间: 2023-05-11 10:04:09 浏览: 258
BRE.zip_Bresenham_drawing
以下是Bresenham算法画线程序的源代码:
```c
#include <stdio.h>
#include <graphics.h>
void bresenham(int x1, int y1, int x2, int y2)
{
int dx = x2 - x1;
int dy = y2 - y1;
int x = x1;
int y = y1;
int p = 2 * dy - dx;
while (x < x2)
{
if (p >= 0)
{
putpixel(x, y, WHITE);
y++;
p = p + 2 * dy - 2 * dx;
}
else
{
putpixel(x, y, WHITE);
p = p + 2 * dy;
}
x++;
}
}
int main()
{
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
bresenham(100, 100, 300, 300);
getch();
closegraph();
return 0;
}
```
希望能对您有所帮助!
阅读全文