文件名称:用Bresenham算法画任意斜率的线
文件大小:2KB
文件格式:TXT
更新时间:2018-06-27 12:45:27
Bresenham
void Bresenham(int x0,int y0,int x1,int y1){ int dx,dy,d,up,down,x,y; if(x0>x1){ x=x1;x1=x0;x0=x; y=y1;y1=y0;y0=y; } dx=x1-x0;dy=y1-y0; d=dx-2*dy; up=2*dx-2*dy; down=-2*dy; if(dy>0&&abs(dy)-abs(dx)>0){ x=x0;x0=y0;y0=x0; y=x1;x1=y1;y1=x1; } if(dy<0&&abs(dy)-abs(dx)>0){ x=x0;x0=-y0;y0=x0; y=x1;x1=-y1;y1=x1; } if(dy<0&&abs(dy)-abs(dx)<0){ x0=-x0; x1=-x1; } while(x0<=x1){ putpixel(x0,y0); x0 ++; if(d<0){ y0 ++; d+=up; } else d+=down; } }