Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
213 views4 pages

BOUNDARY-FILL Algorithm in C

The document contains C code to implement boundary fill algorithms. It defines functions to draw a polygon, perform boundary fill using 4 neighbors, and perform boundary fill using 8 neighbors. The main function gets user input to draw a polygon and fill it, and also draws a square and fills it using the 8 neighbor algorithm.

Uploaded by

Darshan Sharma
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
213 views4 pages

BOUNDARY-FILL Algorithm in C

The document contains C code to implement boundary fill algorithms. It defines functions to draw a polygon, perform boundary fill using 4 neighbors, and perform boundary fill using 8 neighbors. The main function gets user input to draw a polygon and fill it, and also draws a square and fills it using the 8 neighbor algorithm.

Uploaded by

Darshan Sharma
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

BOUNDARY-FILL algorithm in C /*Graphics algorithm to impliment the BOUNDARY-FILL-4 Algorithm */ #include<dos.h> #include<stdio.h> #include<conio.h> #include<graphics.

h> void drawpolygon(int n,int arr[][2],int color); void boundfill4(int x,int y,int fill,int boundary); void main() { int arr[10][2],n,x,y; printf("Enter the number of edges : "); scanf("%d",&n); for(int i=0;i<n;i++) { printf("Enter the X and Y position for %d edge : ",i+1); scanf("%d %d",&arr[i][0],&arr[i][1]); } printf("Enter X and Y co-ordinates of the point from where you want \n"); printf("to start BOUNDARY-FILL : "); scanf("%d %d",&x,&y); int gd=DETECT,gm; initgraph(&gd,&gm,"c:\\tc\\bgi"); drawpolygon(n,arr,RED); getch(); boundfill4(x,y,BLUE,RED); getch();

closegraph(); restorecrtmode(); } void drawpolygon(int n,int arr[][2],int color) { setcolor(color); for(int i=0;i<n;i++) { if( i == n-1 ) line(arr[i][0],arr[i][1],arr[0][0],arr[0][1]); else line(arr[i][0],arr[i][1],arr[i+1][0],arr[i+1][1]); } } void boundfill4(int x,int y,int fill,int boundary) //boundary=RED { //fill=BLUE int current; current = getpixel(x,y); if( (current != boundary) && (current != fill) ) { delay(2); putpixel(x,y,fill); boundfill4(x+1,y,fill,boundary); boundfill4(x-1,y,fill,boundary); boundfill4(x,y+1,fill,boundary); boundfill4(x,y-1,fill,boundary); } }

/*Graphics algorithm to impliment the BOUNDARY-FILL-8 Algorithm */ #include<dos.h> #include<stdio.h> #include<conio.h> #include<graphics.h> void boundfill8(int x,int y,int fill,int boundary); void main() { int r,x1,y1,x2,y2; printf("Enter Left and Top co-ordinates to draw a SQUARE : "); scanf("%d %d",&x1,&y1); printf("Enter Right and Bottom co-ordinates to draw a SQUARE : "); scanf("%d %d",&x2,&y2); int gd=DETECT,gm; initgraph(&gd,&gm,"c:\\tc\\bgi"); setcolor(RED); rectangle(x1,y1,x2,y2); getch(); printf("Enter X and Y co-ordinates to Fill a circle using BOUNDRY-FILL : "); scanf("%d %d",&x1,&y1); boundfill8(x1,y1,BLUE,RED); getch(); closegraph(); restorecrtmode(); }

void boundfill8(int x,int y,int fill,int boundary) { int current; current = getpixel(x,y); if( (current != boundary) && (current != fill) ) { putpixel(x,y,fill); delay(2); boundfill8(x-1,y-1,fill,boundary); boundfill8(x,y-1,fill,boundary); boundfill8(x+1,y-1,fill,boundary); boundfill8(x-1,y,fill,boundary); boundfill8(x+1,y,fill,boundary); boundfill8(x-1,y+1,fill,boundary); boundfill8(x,y+1,fill,boundary); boundfill8(x+1,y+1,fill,boundary); } }

You might also like