#include
#include
#include
int zhixian(int x1,int y1,int x2,int y2,int color,int num)
{
int i,curx,cury,tx,ty,inc1,inc2,d;
int dx,dy,itag;
if(x1==x2&y1==y2)return 1;
else
itag=0;
dx=abs(x2-x1);
dy=abs(y2-y1);
if(dx {
itag=1;
iswap(&x1,&y1);
iswap(&x2,&y2);
iswap(&dx,&dy);
}
tx=(x2-x1)>0?1:-1;
ty=(y2-y1)>0?1:-1;
curx=x1;
cury=y1;
inc1=2*dy;
inc2=2*(dy-dx);
d=inc1-dx;
while(curx!=x2)
{
if(d<0)d+=inc1;
else
{
cury+=ty;
d+=inc2;
}
if(itag)
for(i=1;i<=num;i++)
putpixel(cury+i,curx,color);
else
for(i=1;i<=num;i++)
putpixel(curx,cury+i,color);
curx+=tx;
}
return 0;
}
iswap(int *a,int *b)
{
int tmp;
tmp=*a;
*a=*b;
*b=tmp;
}
main()
{
int num=1,x1,y1,x2,y2;
int color=6;
int gdriver=DETECT,gmode;
/*printf("Origin is in middle!\nyou can input '-' minusn");*/
printf("please input begin x1,y1 :");
scanf("%d %d",&x1,&y1);
printf("nplease input end x2,y2:");
scanf("%d %d",&x2,&y2);
printf("Enter a color number: ");
scanf("%d",&color);
printf("Enter Line Width :");
scanf("%d",&num);
initgraph(&gdriver,&gmode,"");
zhixian(x1+320,y1+240,x2+320,y2+240,color,num);
getch();
closegraph();
}
阅读(1381) | 评论(0) | 转发(0) |