polygon program for graphics
#include #include #include #include #include void line(int xa,int ya,int xb,int yb) { int dx,dy,s,k; float xi,yi,x,y; int gd=DETECT,gm; initgraph(&gd,&gm, ""); dx=xb-xa; dy=yb-ya; if(abs(dx)>abs(dy)) s=abs(dx); else s=abs(dy); xi=dx/s; yi=dy/s; x=xa; y=ya; putpixel(ceil(x),ceil(y),1); for(k=0;k { x=x+xi; y=y+yi; putpixel(ceil(x),ceil(y),1); } } void main() { int v[10][2]; int x,y,n,i,x1,y1,x2,y2; printf("ENTER THE NO OF EDGES"); scanf("%d",&n); printf("ENTER THE VERTICES"); for(i=0;i { scanf("%d",&v[i][0]); scanf("%d",&v[i][1]); } for(i=0;i { if(i!=n-1) { x1=v[i][0]; y1=v[i][1]; x2=v[i+1][0]; y2=v[i+1][1]; } else { x1=v[i][0]; y1=v[i][1]; x2=v[0][0]; y2=v[0][1]; } line(x1,y1,x2,y2); } getch(); }