Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.72 KB | None | 0 0
  1. /*Graphics algorithm to impliment the BOUNDARY-FILL-4 Algorithm */
  2.  
  3. #include<dos.h>
  4. #include<stdio.h>
  5. #include<conio.h>
  6. #include<graphics.h>
  7. void drawpolygon(int n,int arr[][2],int color);
  8. void boundfill4(int x,int y,int fill,int boundary);
  9. void main()
  10. {
  11. int arr[10][2],n,x,y;
  12. printf("Enter the number of edges : ");
  13. scanf("%d",&n);
  14. for(int i=0;i<n;i++)
  15. {
  16. printf("Enter the X and Y position for %d edge : ",i+1);
  17. scanf("%d %d",&arr[i][0],&arr[i][1]);
  18. }
  19. printf("Enter X and Y co-ordinates of the point from where you want n");
  20. printf("to start BOUNDARY-FILL : ");
  21. scanf("%d %d",&x,&y);
  22. int gd=DETECT,gm;
  23. initgraph(&gd,&gm,"c:\tc\bgi");
  24. drawpolygon(n,arr,RED);
  25. getch();
  26. boundfill4(x,y,BLUE,RED);
  27. getch();
  28. closegraph();
  29. restorecrtmode();
  30. }
  31. void drawpolygon(int n,int arr[][2],int color)
  32. {
  33. setcolor(color);
  34. for(int i=0;i<n;i++)
  35. {
  36. if( i == n-1 )
  37. line(arr[i][0],arr[i][1],arr[0][0],arr[0][1]);
  38. else
  39. line(arr[i][0],arr[i][1],arr[i+1][0],arr[i+1][1]);
  40. }
  41. }
  42. void boundfill4(int x,int y,int fill,int boundary) //boundary=RED
  43. { //fill=BLUE
  44. int current;
  45. current = getpixel(x,y);
  46. if( (current != boundary) && (current != fill) )
  47. {
  48. delay(2);
  49. putpixel(x,y,fill);
  50. boundfill4(x+1,y,fill,boundary);
  51. boundfill4(x-1,y,fill,boundary);
  52. boundfill4(x,y+1,fill,boundary);
  53. boundfill4(x,y-1,fill,boundary);
  54. }
  55. }
  56.  
  57.  
  58.  
  59.  
  60. /*Graphics algorithm to impliment the BOUNDARY-FILL-8 Algorithm */
  61.  
  62. #include<dos.h>
  63. #include<stdio.h>
  64. #include<conio.h>
  65. #include<graphics.h>
  66. void boundfill8(int x,int y,int fill,int boundary);
  67. void main()
  68. {
  69. int r,x1,y1,x2,y2;
  70. printf("Enter Left and Top co-ordinates to draw a SQUARE : ");
  71. scanf("%d %d",&x1,&y1);
  72. printf("Enter Right and Bottom co-ordinates to draw a SQUARE : ");
  73. scanf("%d %d",&x2,&y2);
  74.  
  75. int gd=DETECT,gm;
  76. initgraph(&gd,&gm,"c:\tc\bgi");
  77. setcolor(RED);
  78. rectangle(x1,y1,x2,y2);
  79. getch();
  80. printf("Enter X and Y co-ordinates to Fill a circle using BOUNDRY-FILL : ");
  81. scanf("%d %d",&x1,&y1);
  82. boundfill8(x1,y1,BLUE,RED);
  83. getch();
  84. closegraph();
  85. restorecrtmode();
  86. }
  87. void boundfill8(int x,int y,int fill,int boundary)
  88. {
  89. int current;
  90. current = getpixel(x,y);
  91. if( (current != boundary) && (current != fill) )
  92. {
  93.  
  94. putpixel(x,y,fill);
  95. delay(2);
  96. boundfill8(x-1,y-1,fill,boundary);
  97. boundfill8(x,y-1,fill,boundary);
  98. boundfill8(x+1,y-1,fill,boundary);
  99. boundfill8(x-1,y,fill,boundary);
  100. boundfill8(x+1,y,fill,boundary);
  101. boundfill8(x-1,y+1,fill,boundary);
  102. boundfill8(x,y+1,fill,boundary);
  103. boundfill8(x+1,y+1,fill,boundary);
  104.  
  105. }
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement