- #include<iostream.h>
- #include<conio.h>
- #include<graphics.h>
- #include<stdio.h>
- #include<dos.h>
- void fill_right(int x,int y); void fill_left(int x,int y); void main()
- {
- int x,y,a[10][10]; int gd,gm,n,i; detectgraph(&gd,&gm);
- initgraph(&gd,&gm,"C:\\TC\\BGI"); cout<<"Enter no of edges of polygon:"; cin>>n;
- cout<<"\n Enter the coordinates of polygon"; for(i=0;i<n;i++)
- {
- cin>>a[i][0]>>a[i][1];
- }
- a[n][0]=a[0][0];
- a[n][1]=a[0][1];
- cout<<"\n Enter the seed point"; cin>>x>>y;
- cleardevice(); setcolor(WHITE); for(i=0;i<n;i++)
- {
- line(a[i][0],a[i][1],a[i+1][0],a[i+1][1]);
- }
- fill_right(x,y); fill_left(x-1,y); getch();
- }
- void fill_right(int x,int y) //Right fill
- {
- if((getpixel(x,y) != WHITE) && (getpixel(x,y) != RED))
- {
- delay(1); putpixel(x,y,RED); fill_right(++x,y); x=x-1; fill_right(x,y+1); fill_right(x,y-1);
- }
- }
- void fill_left(int x,int y) //left fill
- {
- if((getpixel(x,y) != WHITE) && (getpixel(x,y) != RED))
- {
- putpixel(x,y,RED); delay(1); fill_left(--x,y); x=x+1; fill_left(x,y-1); fill_left(x,y+1);
- }
- }
Thursday, June 21, 2018
Implementation of polygon filling algorithm
Subscribe to:
Post Comments (Atom)


No comments:
Post a Comment