上传者: 28811329
|
上传时间: 2019-12-21 20:38:02
|
文件大小: 2KB
|
文件类型: txt
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(dy0){
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;
}
}