Advertisement
Guest User

Untitled

a guest
Dec 6th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.21 KB | None | 0 0
  1. // C Implementation for Boundary Filling Algorithm
  2. #include <graphics.h>
  3.  
  4. // Function for 4 connected Pixels
  5. void boundaryFill4(int x, int y, int fill_color,int boundary_color)
  6. {
  7.     if(getpixel(x, y) != boundary_color &&
  8.     getpixel(x, y) != fill_color)
  9.     {
  10.         putpixel(x, y, fill_color);
  11.         boundaryFill4(x + 1, y, fill_color, boundary_color);
  12.         boundaryFill4(x, y + 1, fill_color, boundary_color);
  13.         boundaryFill4(x - 1, y, fill_color, boundary_color);
  14.         boundaryFill4(x, y - 1, fill_color, boundary_color);
  15.     }
  16. }
  17.  
  18. //driver code
  19. int main()
  20. {
  21.     // gm is Graphics mode which is
  22.     // a computer display mode that
  23.     // generates image using pixels.
  24.     // DETECT is a macro defined in
  25.     // "graphics.h" header file
  26.     int gd = DETECT, gm;
  27.  
  28.     // initgraph initializes the
  29.     // graphics system by loading a
  30.     // graphics driver from disk
  31.     initgraph(&gd, &gm, "");
  32.  
  33.     int x = 250, y = 200, radius = 50;
  34.  
  35.     // circle function
  36.     circle(x, y, radius);
  37.  
  38.     // Function calling
  39.     boundaryFill4(x, y, 6, 15);
  40.  
  41.     delay(10000);
  42.  
  43.     getch();
  44.  
  45.     // closegraph function closes the
  46.     // graphics mode and deallocates
  47.     // all memory allocated by
  48.     // graphics system .
  49.     closegraph();
  50.  
  51.     return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement