123 Eng

### Engineering the engineers™

Home
Source Codes
Engineering Colleges

Training  Reports
Seminar Reports
Placement Papers

Forums

Computer Science / IT
Electronics
Electrical
Mechanical
Chemical
Civil

CAT / MBA

GMAT / Foreign MBA
Latest Jobs

Displaying  Source Code(s)

 Program to implement Polygon Filling Algorithm. -------------------------------------------------------------------------------- #include #include #include #include #include #include int gd=DETECT,gm; class myStack { private: int arr[10000][2],top; public: myStack() { top=-1; } void push(int x,int y) { if(top>10000) { printf(" a " Stack Full...:-(""); exit(0); } top++; arr[top][0]=x; arr[top][1]=y; } void pop(int &x,int &y) { x=arr[top][0]; y=arr[top][1]; top--; } int empty(void) { if(top==-1) return(1); else return(0); } }; void show_quadrant() { cleardevice(); rectangle(120,40,320,240); rectangle(320,40,520,240); rectangle(120,240,320,440); rectangle(320,240,520,440); for(int i=130;i<=510;i+=10) { if(i==320) continue; outtextxy(i,237,"+"); } for(i=50;i<=430;i+=10) { if(i==240) continue; outtextxy(317,i,"-"); } outtextxy(310,230,"O"); outtextxy(530,240,"X"); outtextxy(320,450,"-Y"); outtextxy(100,240,"-X"); outtextxy(320,30,"Y"); } int get_poly(int ed[20]) { int edg,i,j; clearviewport(); closegraph(); cout<<" " Enter No. Of Edges ":="; cin>>edg; for(i=0,j=1;i<2*edg;i+=2,j++) { cout<<" " Enter Vertex No. "<max) max=edge[i]; if(edge[i]max) max=edge[i]; if(edge[i]ed[k+3]) { max=ed[k+1]; min=ed[k+3]; } if(ed[k+1]min&&i=xmin&&xi[p]<=xmax) p++; } sort(xi,p); for(j=0;jxi[j+1]) { float temp; temp=xi[j]; xi[j]=xi[j+1]; xi[j+1]=temp; } } } } void edge_fill(int ed[20],int num) { int i,j,k,xmax,xmin,ymax,ymin,col; double xint; get_y(ymin,ymax,ed,num); get_x(xmin,xmax,ed,num); for(k=0;k<2*num;k+=2) { for(i=ymin;i<=ymax;i++) { if(ed[k+1]==ed[k+3]) continue; if(!check_mid(i,ed,k)) continue; xint = ed[k]+(((double)(i-ed[k+1])/(ed[k+1]-ed[k+3]))*(ed[k]-ed[k+2])); for(j=xmin;j<=xmax;j++) { if(j>xint) { col=getpixel(j,i); if(col==15) putpixel(j,i,0); if(col==0) putpixel(j,i,15); } } } } } void main() { clrscr(); char *mess[]={"-","=","["," ","P","o","l","y","g","o","n"," ", "F","i","l","l","i","n","g"," ","]","=","-",}; int xx=28,xxx=51,i,j; _setcursortype(_NOCURSOR); for(i=0,j=22;i<13,j>=11;i++,j--) { gotoxy(xx,1); cout<" Flood Fill ""; cout<<" 2:==>" Ordered Edge List Fill ""; cout<<" 3:==>" Edge Fill ""; cout<<" 4:==>" Exit ""; cout<<" " Enter Your Choice ":="; cin>>choice; initgraph(&gd,&gm,"..\bgi"); clearviewport(); switch(choice) { case 1: flood_fill(ed); getch(); break; case 2: num=get_poly(ed); scan_poly(ed,num); getch(); break; case 3: num=get_poly(ed); edge_fill(ed,num); getch(); break; case 4: exit(0); default: cout<<" a" Press A Valid Key...!!! ""; getch(); main(); break; } closegraph(); }

Contribute content or training reports / feedback / Comments
job placement papers