Guest User

Untitled

a guest
Jan 23rd, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. /*
  2. Title: Boundary Fill Algorithm
  3. Description: A C Program to draw any shape and fill color in it using Boundary Fill Algorithm's either 4-connected or 8-connected approach
  4. Author: Saideep Dicholkar
  5. */
  6.  
  7. #include<stdio.h>
  8. #include<conio.h>
  9. #include<graphics.h>
  10. void convex(int,int);
  11. void concave(int,int);
  12. void bfill(int,int,int,int,int);
  13. void main()
  14. {
  15. int gd=DETECT,gm;
  16. int x,y,ch;
  17. initgraph(&gd,&gm,"C:\\tc\\bgi");
  18. cleardevice();
  19. printf("1.Convex Polygon\n2.Concave Polygon\nEnter Choice: ");
  20. scanf("%\d",&ch);
  21. x=(100+152)/2;
  22. y=(100+152)/2;
  23. switch(ch)
  24. {
  25. case 1:convex(x,y);
  26. break;
  27. case 2:concave(x,y);
  28. break;
  29. }
  30. getch();
  31. closegraph();
  32. restorecrtmode();
  33. }
  34. void convex(int x,int y)
  35. {
  36. line(100,100,150,100);
  37. line(150,100,150,150);
  38. line(150,150,100,150);
  39. line(100,150,100,100);
  40. bfill(x,y,15,11,0);
  41. }
  42. void concave(int x,int y)
  43. {
  44. line(100,100,125,125);
  45. line(125,125,150,100);
  46. line(150,100,150,150);
  47. line(150,150,100,150);
  48. line(100,150,100,100);
  49. bfill(x,y,15,12,1);
  50. }
  51. void bfill(int x,int y,int bcolor,int fcolor,int c)
  52. {
  53. int current=getpixel(x,y);
  54. if(current!=bcolor && current!=fcolor)
  55. {
  56. delay(2);
  57. putpixel(x,y,fcolor);
  58. if(c==1)
  59. {
  60. bfill(x+1,y,bcolor,fcolor,1);
  61. bfill(x-1,y,bcolor,fcolor,1);
  62. bfill(x,y+1,bcolor,fcolor,1);
  63. bfill(x,y-1,bcolor,fcolor,1);
  64. }
  65. else
  66. {
  67. bfill(x+1,y,bcolor,fcolor,0);
  68. bfill(x-1,y,bcolor,fcolor,0);
  69. bfill(x,y+1,bcolor,fcolor,0);
  70. bfill(x,y-1,bcolor,fcolor,0);
  71. bfill(x+1,y+1,bcolor,fcolor,0);
  72. bfill(x-1,y+1,bcolor,fcolor,0);
  73. bfill(x+1,y-1,bcolor,fcolor,0);
  74. bfill(x-1,y-1,bcolor,fcolor,0);
  75. }
  76. }
  77. }
Add Comment
Please, Sign In to add comment