#include #include /* void putpixel(int x,int y,int v) { printf(" %6d %6d ",x,y); getch(); v=v; } */ #define line(a,b,c,d) lin(320+(a),240-(b),320+(c),240-(d)) void swap(int *x1,int *x2,int *y1,int *y2) { int t; t=*x1;*x1=*x2;*x2=t; t=*y1;*y1=*y2;*y2=t; } void lin(int x1,int y1,int x2,int y2) { double slope; int d,cas,a,b, incxg[]={ 1, 0, 1, 1}, incyg[]={ 1, 1, 0,-1}, incxl[]={ 1, 1, 1, 0}, incyl[]={ 0, 1,-1,-1}, starta[]={ 2, 1, 2, 1}, startb[]={ 1, 2,-1,-2}, incag[]={ 2, 0, 2, 2}, incbg[]={ 2, 2, 0,-2}, incal[]={ 2, 2, 2, 0}, incbl[]={ 0, 2,-2,-2} ; if(x1>x2) swap(&x1,&x2,&y1,&y2); if(!(x2-x1)) x2++; //vertical lines are also approximated //note that in our LAB question, the user can't enter INF. slope=1.0*(y2-y1)/(x2-x1); a=y2-y1; b=x1-x2; if(slope>=0 && slope<1) cas=0; if(slope>=1) cas=1; if(slope>=-1 && slope<0) cas=2; if(slope<-1) cas=3; d = starta[cas]*a + startb[cas]*b; while(x1<=x2) { putpixel(x1,y1,WHITE); if(d>0) { x1+=incxg[cas]; y1+=incyg[cas]; d+=incag[cas]*a + incbg[cas]*b; } else { x1+=incxl[cas]; y1+=incyl[cas]; d+=incal[cas]*a + incbl[cas]*b; } } //getch(); } void linethick(int x1,int y1,int x2,int y2,int th) { double sl=1.0*(y2-y1)/(x2-x1); int i; if(!sl) { for(i=1;i<=th;i++) { line(x1,y1,x2,y2); y1--; y2--; } } else { for(i=1;i<=th;i++) { line(x1,y1,x2,y2); x1++; x2++; //y2=sl*(y1-x1)+x2; } } } void polyline(int *x,int *y,int cnt,int thick) { int i; if(cnt==1) { putpixel(x[0],y[0],WHITE); return; } for(i=0;i