原理
dydx=常数 或者 ΔyΔx=y2−y1x2−x1
yi+1=yi+Δy
yi+1=yi+y2−y1x2−x1Δx
代码
void DDALine(int x0,int y0,int x1,int y1)
{
HWND myconsole = GetConsoleWindow();
HDC mydc = GetDC(myconsole);
COLORREF COLOR= RGB(255,0,0);
int dx,dy,epsl,k;
float x,y,xIncre,yIncre;
dx=x1-x0;
dy=y1-y0;
x=x0;
y=y0;
if(abs(dx)>abs(dy)) epsl=abs(dx);
else epsl=abs(dy);
xIncre=(float)dx/(float)epsl;
yIncre=(float)dy/(float)epsl;
for(k=0;k<=epsl;k++){
SetPixel(mydc,int(x+0.5),int(y+0.5),COLOR);
x+=xIncre;
y+=yIncre;
}
ReleaseDC(myconsole, mydc);
cin.ignore();
}