运行之前也须自己设置好initgraph里面的图形驱动路径,如果是绝对路径的话,可以把前面的registerbgidriver(EGAVGA_driver);一句去掉,程序很简单,没什么好说的了。
#include<graphics.h>
main()
{int a,b,d,x0,y0,x1,y1,x,y;
int driver=DETECT,mode;
printf("Please input two point to draw the line between:\n");
printf("x0=");scanf("%d",&x0);
printf("y0=");scanf("%d",&y0);
printf("x1=");scanf("%d",&x1);
printf("y1=");scanf("%d",&y1);
a=y0-y1;b=x1-x0;d=2*a+b;
registerbgidriver(EGAVGA_driver);
initgraph(&driver,&mode,"");
for(x=x0,y=y0;x<=x1;)
{putpixel(x,y,14);
if(d>=0)
{x=x+1;
d=d+2*a;
}
else
{x=x+1;
y=y+1;
d=d+2*(a+b);
}
}
getch();
closegraph();
}
评论