程序代码:
#include"graphics.h" void MidpointLine(int x0,int y0,int x1,int y1,int color) { int a,b,dalte1,dalte2,d,x,y; a=y0-y1; b=x1-x0; dalte1=a+a; dalte2=a+a+b+b; d=a+a+b; x=x0; y=y0; putpixel(x,y,color); while(x0<x1) { if(d<0) { x++; y++; d+=dalte2; } else { x++; d+=dalte1; } x0++; putpixel(x,y,color); /*改了这*/ } } int main() { int graphdriver=DETECT; int graphmode=0; initgraph(&graphdriver,&graphmode,"d:\\win-tc\\projects"); /*换回自己模板*/ MidpointLine(10,20,400,300,2); getch(); closegraph(); return 0; }