Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*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);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement