上传者: qq_28811329
|
上传时间:2023/7/30 4:08:38
|
文件大小:2KB
|
文件类型:txt
用Bresenham算法画任意斜率的线
voidBresenham(intx0,inty0,intx1,inty1){ intdx,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; } elsed+=down; }}
本软件ID:8782101